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