Added POD.
[koha.git] / pay.pl
1 #!/usr/bin/perl
2
3 #wrriten 11/1/2000 by chris@katipo.oc.nz
4 #part of the koha library system, script to facilitate paying off fines
5
6
7 # Copyright 2000-2002 Katipo Communications
8 #
9 # This file is part of Koha.
10 #
11 # Koha is free software; you can redistribute it and/or modify it under the
12 # terms of the GNU General Public License as published by the Free Software
13 # Foundation; either version 2 of the License, or (at your option) any later
14 # version.
15 #
16 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
17 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
18 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License along with
21 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
22 # Suite 330, Boston, MA  02111-1307 USA
23
24 use strict;
25 use C4::Output;
26 use CGI;
27 use C4::Search;
28 use C4::Accounts2;
29
30 use C4::Database;
31 use C4::Stats;
32 my $input=new CGI;
33
34 #print $input->header;
35 my $bornum=$input->param('bornum');
36 if ($bornum eq ''){
37   $bornum=$input->param('bornum0');
38 }
39 #get borrower details
40 my $data=borrdata('',$bornum);
41 my $user=$input->remote_user;
42
43 #get account details
44 my %bor;
45 $bor{'borrowernumber'}=$bornum;                            
46
47
48 my @names=$input->param;
49 my %inp;
50 my $check=0;
51 for (my $i=0;$i<@names;$i++){
52   my$temp=$input->param($names[$i]);
53   if ($temp eq 'wo'){
54     $inp{$names[$i]}=$temp;
55     $check=1;
56   }
57   if ($temp eq 'yes'){
58     $user=~ s/Levin/C/i;
59     $user=~ s/Foxton/F/i;
60     $user=~ s/Shannon/S/i;
61     my $amount=$input->param($names[$i+4]);
62     my $bornum=$input->param($names[$i+5]);
63     my $accountno=$input->param($names[$i+6]);
64     makepayment($bornum,$accountno,$amount,$user);
65     $check=2;
66   }
67 }
68 my %env;
69     $user=~ s/Levin/C/i;
70     $user=~ s/Foxton/F/i;
71     $user=~ s/Shannon/S/i;
72
73 $env{'branchcode'}=$user;
74 my $total=$input->param('total');
75 if ($check ==0){
76   print $input->header;
77   if ($total ne ''){
78     recordpayment(\%env,$bornum,$total);
79   }
80   my ($numaccts,$accts,$total)=getboracctrecord('',\%bor);     
81
82   print startpage();
83   print startmenu('member');
84   print <<printend
85   <FONT SIZE=6><em>Pay Fines for $data->{'firstname'} $data->{'surname'}</em></FONT><P>
86   <center>
87   <p>
88   <TABLE  CELLSPACING=0  CELLPADDING=5 border=1 >
89   <TR VALIGN=TOP>
90   <td  bgcolor="99cc33" background="/images/background-mem.gif" colspan=4><B>FINES & CHARGES</TD>
91   <td  bgcolor="99cc33" background="/images/background-mem.gif" colspan=4><B>AMOUNT OWING</TD>
92   </TR>
93   <form action=/cgi-bin/koha/pay.pl method=post>
94   <input type=hidden name=bornum value=$bornum>
95 printend
96 ;
97   for (my $i=0;$i<$numaccts;$i++){
98     if ($accts->[$i]{'amountoutstanding'} > 0){
99       $accts->[$i]{'amount'}+=0.00;
100       $accts->[$i]{'amountoutstanding'}+=0.00;
101       print <<printend
102       <tr VALIGN=TOP  >
103       <TD><input type=radio name=payfine$i value=no checked>Unpaid
104       <input type=radio name=payfine$i value=yes>Pay
105       <input type=radio name=payfine$i value=wo>Writeoff
106       <input type=hidden name=itemnumber$i value=$accts->[$i]{'itemnumber'}>
107       <input type=hidden name=accounttype$i value=$accts->[$i]{'accounttype'}>
108       <input type=hidden name=amount$i value=$accts->[$i]{'amount'}>
109       <input type=hidden name=out$i value=$accts->[$i]{'amountoutstanding'}>
110       <input type=hidden name=bornum$i value=$bornum>
111       <input type=hidden name=accountno$i value=$accts->[$i]{'accountno'}>
112       </td>
113       <TD>$accts->[$i]{'description'} $accts->[$i]{'title'}</td>
114       <TD>$accts->[$i]{'accounttype'}</td>
115       <td>$accts->[$i]{'amount'}</td>
116       <TD>$accts->[$i]{'amountoutstanding'}</td>
117
118       </tr>
119 printend
120 ;
121     }
122   }
123   print <<printend
124   <tr VALIGN=TOP  >
125   <TD></td>
126   <TD colspan=2><b>Total Due</b></td>
127   <TD><b>$total</b></td>
128   </tr>
129   <tr VALIGN=TOP  >
130   <TD colspan=5 align=right>
131   <INPUT TYPE="image" name="submit"  VALUE="pay" height=42  WIDTH=187 BORDER=0 src="/images/pay-fines.gif"></td>
132   </tr>
133   </form>
134   </table>
135   <br clear=all>
136   <p> &nbsp; </p>
137
138 printend
139 ;
140   print endmenu('member');
141   print endpage();
142
143 } else {
144 #  my $quety=$input->query_string;
145 #  print $input->redirect("/cgi-bin/koha/sec/writeoff.pl?$quety");
146     my%inp;    
147     my @name=$input->param;
148     for (my $i=0;$i<@name;$i++){
149         my $test=$input->param($name[$i]);
150         if ($test eq 'wo'){
151             my $temp=$name[$i];
152             $temp=~ s/payfine//;
153             $inp{$name[$i]}=$temp;
154         }
155     }
156     my $bornum;
157     while ( my ($key, $value) = each %inp){
158         #  print $key,$value;
159         my $accounttype=$input->param("accounttype$value");
160         $bornum=$input->param("bornum$value");
161         my $itemno=$input->param("itemnumber$value");
162         my $amount=$input->param("amount$value");
163         if ($accounttype eq 'Res'){
164             my $accountno=$input->param("accountno$value");
165             writeoff($bornum,$accountno,$itemno,$accounttype,$amount);
166         } else {
167             writeoff($bornum,'',$itemno,$accounttype,$amount);
168         }
169     }
170     $bornum=$input->param('bornum');
171     print $input->redirect("/cgi-bin/koha/pay.pl?bornum=$bornum");
172 }
173
174
175 sub writeoff{
176     my ($bornum,$accountnum,$itemnum,$accounttype,$amount)=@_;
177     my $user=$input->remote_user;
178     $user=~ s/Levin/C/;
179     $user=~ s/Foxton/F/;
180     $user=~ s/Shannon/S/;
181     my $dbh=C4Connect;
182     my $env;
183     my $query="Update accountlines set amountoutstanding=0 where ";
184     if ($accounttype eq 'Res'){
185         $query.="accounttype='Res' and accountno='$accountnum' and borrowernumber='$bornum'";
186     } else {
187         $query.="accounttype='$accounttype' and itemnumber='$itemnum' and borrowernumber='$bornum'";
188     }
189     my $sth=$dbh->prepare($query);
190     #  print $query;
191     $sth->execute;
192     $sth->finish;
193     $query="select max(accountno) from accountlines";
194     $sth=$dbh->prepare($query);
195     $sth->execute;
196     my $account=$sth->fetchrow_hashref;
197     $sth->finish;
198     $account->{'max(accountno)'}++;
199     $query="insert into accountlines (borrowernumber,accountno,itemnumber,date,amount,description,accounttype)
200     values ('$bornum','$account->{'max(accountno)'}','$itemnum',now(),'$amount','Writeoff','W')";
201     $sth=$dbh->prepare($query);
202     $sth->execute;
203     $sth->finish;
204 #  print $query;
205     $dbh->disconnect;
206     UpdateStats($env,$user,'writeoff',$amount,'','','',$bornum);
207 }