Added copyright statement to all .pl and .pm files
[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::Format;
23 use C4::InterfaceCDK;
24 use C4::Accounts2;
25 use strict;
26
27 require Exporter;
28 use DBI;
29 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
30   
31 # set the version for version checking
32 $VERSION = 0.01;
33     
34 @ISA = qw(Exporter);
35 @EXPORT = qw(&accountsdialog);
36 %EXPORT_TAGS = ( );     # eg: TAG => [ qw!name1 name2! ],
37                   
38 # your exported package globals go here,
39 # as well as any optionally exported functions
40
41 @EXPORT_OK   = qw($Var1 %Hashit);
42 # non-exported package globals go here
43 use vars qw(@more $stuff);
44         
45 # initalize package globals, first exported ones
46
47 my $Var1   = '';
48 my %Hashit = ();
49                     
50 # then the others (which are still accessible as $Some::Module::stuff)
51 my $stuff  = '';
52 my @more   = ();
53         
54 # all file-scoped lexicals must be created before
55 # the functions below that use them.
56                 
57 # file-private lexicals go here
58 my $priv_var    = '';
59 my %secret_hash = ();
60                             
61 # here's a file-private function as a closure,
62 # callable as &$priv_func;  it cannot be prototyped.
63 my $priv_func = sub {
64   # stuff goes here.
65 };
66                                                     
67 # make all your functions, whether exported or not;
68
69
70   
71 sub accountsdialog {
72   my ($env,$title,$borrower,$accountlines,$amountowing)=@_;
73   my $titlepanel = titlepanel($env,$env->{'sysarea'},"Money Owing");
74   my @borinfo;
75   my $reason;
76   #$borinfo[0]  = "$borrower->{'cardnumber'}";
77   #$borinfo[1] = "$borrower->{'surname'}, $borrower->{'title'} $borrower->{'firstname'} ";
78   #$borinfo[2] = "$borrower->{'streetaddress'}, $borrower->{'city'}";
79   #$borinfo[3] = "<R>Total Due:  </B>".fmtdec($env,$amountowing,"52");
80   #my $borpanel = 
81   #  new Cdk::Label ('Message' =>\@borinfo, 'Ypos'=>4, 'Xpos'=>"RIGHT");
82   my $borpanel = borrowerbox($env,$borrower,$amountowing);
83   $borpanel->draw();
84   my @sel = ("N ","Y ");
85   my $acctlist = new Cdk::Selection ('Title'=>"Outstanding Items",
86       'List'=>\@$accountlines,'Choices'=>\@sel,'Height'=>12,'Width'=>80,
87       'Xpos'=>1,'Ypos'=>10);
88   my @amounts=$acctlist->activate();
89   my $accountno;
90   my $amount2;
91   my $count=@amounts;
92   my $amount;
93   my $check=0;
94   for (my $i=0;$i<$count;$i++){
95     if ($amounts[$i] == 1){
96       $check=1;
97       if ($accountlines->[$i]=~ /(^[0-9]+)/){
98         $accountno=$1;
99       }
100       if ($accountlines->[$i]=~/([0-9]+\.[0-9]+)/){
101         $amount2=$1;
102       }
103       my $borrowerno=$borrower->{'borrowernumber'};
104       makepayment($borrowerno,$accountno,$amount2);
105       $amount+=$amount2;
106     }
107     
108   }
109   my $amountentry = new Cdk::Entry('Label'=>"Amount:  ",
110      'Max'=>"10",'Width'=>"10",
111      'Xpos'=>"1",'Ypos'=>"3",
112      'Type'=>"INT");
113   $amountentry->preProcess ('Function' => sub{preamt(@_,$env,$acctlist);});
114   #
115   
116   if ($amount eq ''){
117     $amount =$amountentry->activate();                                                                
118   } else {
119     $amountentry->set('Value'=>$amount);
120     $amount=$amountentry->activate();
121   }
122 #  debug_msg($env,"accounts $amount barcode=$accountno");
123   if (!defined $amount) {
124      #debug_msg($env,"escaped");
125      #$reason="Finished user";
126   }
127   $borpanel->erase();
128   $acctlist->erase();
129   $amountentry->erase();
130   undef $acctlist;
131   undef $borpanel;
132   undef $borpanel;
133   undef $titlepanel;
134   if ($check == 1){
135     $amount=0;
136   }
137   return($amount,$reason);
138 }
139
140 sub preamt {
141   my ($input,$env,$acctlist)= @_;
142   my $key_tab  = chr(9);
143   if ($input eq $key_tab) {
144     actlist ($env,$acctlist);
145     return 0;
146   }
147   return 1;
148 }
149
150 sub actlist {
151   my ($env,$acctlist) = @_;
152   $acctlist->activate();
153 }
154
155
156 END { }       # module clean-up code here (global destructor)