Patrons may pay their fines in instalments
[wip/koha-chris_n.git] / members / pay.pl
1 #!/usr/bin/perl
2 # WARNING: Not enough context to figure out the correct tabstop size
3 # WARNING: Assume that this file uses 4-character tabs
4
5 # $Id$
6
7 #written 11/1/2000 by chris@katipo.oc.nz
8 #part of the koha library system, script to facilitate paying off fines
9
10
11 # Copyright 2000-2002 Katipo Communications
12 #
13 # This file is part of Koha.
14 #
15 # Koha is free software; you can redistribute it and/or modify it under the
16 # terms of the GNU General Public License as published by the Free Software
17 # Foundation; either version 2 of the License, or (at your option) any later
18 # version.
19 #
20 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
21 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
22 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
23 #
24 # You should have received a copy of the GNU General Public License along with
25 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
26 # Suite 330, Boston, MA  02111-1307 USA
27
28 use strict;
29 use C4::Context;
30 use C4::Auth;
31 use C4::Interface::CGI::Output;
32 use CGI;
33 use C4::Search;
34 use C4::Accounts2;
35 use C4::Stats;
36 use C4::Members;
37
38 my $input=new CGI;
39 my ($template, $loggedinuser, $cookie)
40                 = get_template_and_user ({ template_name => "members/pay.tmpl",
41                                            query => $input,
42                                            type => "intranet",
43                                            authnotrequired => 0,
44                                            flagsrequired => {borrowers => 1},
45                                            debug => 1,
46                                          });
47
48 my $bornum=$input->param('bornum');
49 if ($bornum eq ''){
50         $bornum=$input->param('bornum0');
51 }
52 #get borrower details
53 my $data=borrdata('',$bornum);
54 my $user=C4::Context->preference('defaultBranch');
55 my $me=borrdata('',$loggedinuser);
56 my $accountant=$me->{'firstname'}.' '.$me->{'surname'};
57 #get account details
58 my %bor;
59 $bor{'borrowernumber'}=$bornum;
60
61 my @names=$input->param;
62 my %inp;
63 my $check=0;
64 my $type;
65 my $totalamount;
66 my $totaldesc;
67 my $totalaccounttype;
68
69 for (my $i=0;$i<@names;$i++){
70         my$temp=$input->param($names[$i]);
71         if ($temp eq 'wo'){
72                 $type="W";
73                 $check=2;
74         }
75 if ($temp eq 'yes'){
76                 $type="Pay";
77                 $check=2;
78         }
79         if ($temp eq 'yes' || $temp eq 'wo'){
80                 
81                 my $desc=$input->param($names[$i+7]);
82                 my $accounttype=$input->param($names[$i+2]);
83                 my $amount=$input->param($names[$i+4]);
84                 my $bornum=$input->param($names[$i+5]);
85                 my $accountno=$input->param($names[$i+6]);
86                 my $amounttopay=$input->param($names[$i+8]);
87
88                 makepayment($bornum,$accountno,$amounttopay,$accountant, $type);
89                 $totalamount=$totalamount+$amounttopay;
90                 $totaldesc .="<br> ".$desc."-  Fee:".$amounttopay;
91                 $totalaccounttype .="<br> ".$accounttype;
92                 $check=2;
93         }
94 }
95 if ($type eq "Pay" || $type eq "W"){
96 print $input->redirect("/cgi-bin/koha/members/payprint.pl?bornum=$bornum&accounttype=$totalaccounttype&amount=$totalamount&desc=$totaldesc");
97 }
98 my %env;
99    
100
101 $env{'branchcode'}=C4::Context->preference('defaultBranch');
102 my $total=$input->param('total');
103 if ($check ==0){
104         
105         if ($total ne ''){
106                 recordpayment(\%env,$bornum,$total);
107         }
108         my ($numaccts,$accts,$total)=getboracctrecord('',\%bor);
109
110         my @loop_pay;
111         for (my $i=0;$i<$numaccts;$i++){
112                 if ($accts->[$i]{'amountoutstanding'} > 0){
113                         $accts->[$i]{'amount'}+=0.00;
114                         $accts->[$i]{'amountoutstanding'}+=0.00;
115                         my %line;
116                         $line{i}=$i;
117                         $line{itemnumber} = $accts->[$i]{'itemnumber'};
118                         $line{accounttype} = $accts->[$i]{'accounttype'};
119                         $line{amount} = sprintf("%.2f",$accts->[$i]{'amount'});
120                         $line{amountoutstanding} = sprintf("%.2f",$accts->[$i]{'amountoutstanding'});
121                         $line{bornum} = $bornum;
122                         $line{accountno} = $accts->[$i]{'accountno'};
123                         $line{description} = $accts->[$i]{'description'};
124                         $line{title} = $accts->[$i]{'title'};
125                         push(@loop_pay, \%line);
126                 }
127         }
128         $template->param(firstname => $data->{'firstname'},
129                                                         surname => $data->{'surname'},
130                                                         bornum => $bornum,
131                                                         loop_pay => \@loop_pay,
132                                                         total => sprintf("%.2f",$total),
133                                                         totalamountopay => sprintf("%.2f",$total));
134 output_html_with_http_headers $input, $cookie, $template->output;
135
136 } else {
137         my%inp;
138         my @name=$input->param;
139         for (my $i=0;$i<@name;$i++){
140                 my $test=$input->param($name[$i]);
141                 if ($test eq 'wo'){
142                 my $temp=$name[$i];
143                 $temp=~ s/payfine//;
144                 $inp{$name[$i]}=$temp;
145                 }
146         }
147         my $bornum;
148         while ( my ($key, $value) = each %inp){
149                 #  print $key,$value;
150                 my $accounttype=$input->param("accounttype$value");
151                 $bornum=$input->param("bornum$value");
152                 my $itemno=$input->param("itemnumber$value");
153                 my $amount=$input->param("amount$value");
154                 
155         }
156         $bornum=$input->param('bornum');
157         print $input->redirect("/cgi-bin/koha/members/pay.pl?bornum=$bornum");
158 }
159
160
161
162
163 # Local Variables:
164 # tab-width: 4
165 # End: