Added a couple of comments.
[koha.git] / C4 / Interface / AccountsCDK.pm
1 package C4::Interface::AccountsCDK; #asummes C4/Interface/AccountsCDK
2
3 #uses Newt
4
5 # Copyright 2000-2002 Katipo Communications
6 #
7 # This file is part of Koha.
8 #
9 # Koha is free software; you can redistribute it and/or modify it under the
10 # terms of the GNU General Public License as published by the Free Software
11 # Foundation; either version 2 of the License, or (at your option) any later
12 # version.
13 #
14 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License along with
19 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
20 # Suite 330, Boston, MA  02111-1307 USA
21
22 use C4::InterfaceCDK;
23 use C4::Accounts2;
24 use strict;
25
26 require Exporter;
27 use DBI;
28 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
29   
30 # set the version for version checking
31 $VERSION = 0.01;
32     
33 @ISA = qw(Exporter);
34 @EXPORT = qw(&accountsdialog);
35 %EXPORT_TAGS = ( );     # eg: TAG => [ qw!name1 name2! ],
36                   
37 # your exported package globals go here,
38 # as well as any optionally exported functions
39
40 @EXPORT_OK   = qw($Var1 %Hashit);
41 # non-exported package globals go here
42 use vars qw(@more $stuff);
43         
44 # initalize package globals, first exported ones
45
46 my $Var1   = '';
47 my %Hashit = ();
48                     
49 # then the others (which are still accessible as $Some::Module::stuff)
50 my $stuff  = '';
51 my @more   = ();
52         
53 # all file-scoped lexicals must be created before
54 # the functions below that use them.
55                 
56 # file-private lexicals go here
57 my $priv_var    = '';
58 my %secret_hash = ();
59                             
60 # here's a file-private function as a closure,
61 # callable as &$priv_func;  it cannot be prototyped.
62 my $priv_func = sub {
63   # stuff goes here.
64 };
65                                                     
66 # make all your functions, whether exported or not;
67
68
69   
70 sub accountsdialog {
71   my ($env,$title,$borrower,$accountlines,$amountowing)=@_;
72   my $titlepanel = titlepanel($env,$env->{'sysarea'},"Money Owing");
73   my @borinfo;
74   my $reason;
75   #$borinfo[0]  = "$borrower->{'cardnumber'}";
76   #$borinfo[1] = "$borrower->{'surname'}, $borrower->{'title'} $borrower->{'firstname'} ";
77   #$borinfo[2] = "$borrower->{'streetaddress'}, $borrower->{'city'}";
78   #$borinfo[3] = "<R>Total Due:  </B>".fmtdec($env,$amountowing,"52");
79   #my $borpanel = 
80   #  new Cdk::Label ('Message' =>\@borinfo, 'Ypos'=>4, 'Xpos'=>"RIGHT");
81   my $borpanel = borrowerbox($env,$borrower,$amountowing);
82   $borpanel->draw();
83   my @sel = ("N ","Y ");
84   my $acctlist = new Cdk::Selection ('Title'=>"Outstanding Items",
85       'List'=>\@$accountlines,'Choices'=>\@sel,'Height'=>12,'Width'=>80,
86       'Xpos'=>1,'Ypos'=>10);
87   my @amounts=$acctlist->activate();
88   my $accountno;
89   my $amount2;
90   my $count=@amounts;
91   my $amount;
92   my $check=0;
93   for (my $i=0;$i<$count;$i++){
94     if ($amounts[$i] == 1){
95       $check=1;
96       if ($accountlines->[$i]=~ /(^[0-9]+)/){
97         $accountno=$1;
98       }
99       if ($accountlines->[$i]=~/([0-9]+\.[0-9]+)/){
100         $amount2=$1;
101       }
102       my $borrowerno=$borrower->{'borrowernumber'};
103       makepayment($borrowerno,$accountno,$amount2);
104       $amount+=$amount2;
105     }
106     
107   }
108   my $amountentry = new Cdk::Entry('Label'=>"Amount:  ",
109      'Max'=>"10",'Width'=>"10",
110      'Xpos'=>"1",'Ypos'=>"3",
111      'Type'=>"INT");
112   $amountentry->preProcess ('Function' => sub{preamt(@_,$env,$acctlist);});
113   #
114   
115   if ($amount eq ''){
116     $amount =$amountentry->activate();                                                                
117   } else {
118     $amountentry->set('Value'=>$amount);
119     $amount=$amountentry->activate();
120   }
121 #  debug_msg($env,"accounts $amount barcode=$accountno");
122   if (!defined $amount) {
123      #debug_msg($env,"escaped");
124      #$reason="Finished user";
125   }
126   $borpanel->erase();
127   $acctlist->erase();
128   $amountentry->erase();
129   undef $acctlist;
130   undef $borpanel;
131   undef $borpanel;
132   undef $titlepanel;
133   if ($check == 1){
134     $amount=0;
135   }
136   return($amount,$reason);
137 }
138
139 sub preamt {
140   my ($input,$env,$acctlist)= @_;
141   my $key_tab  = chr(9);
142   if ($input eq $key_tab) {
143     actlist ($env,$acctlist);
144     return 0;
145   }
146   return 1;
147 }
148
149 sub actlist {
150   my ($env,$acctlist) = @_;
151   $acctlist->activate();
152 }
153
154
155 END { }       # module clean-up code here (global destructor)