Escaping the $title in the regexes with \Q and \E to handle nested quantifiers, cheer...
[koha.git] / members / pay.pl
bloba1213bbd2a2fd0ed85c785dae83b786d21636b63
1 #!/usr/bin/perl
3 # Copyright 2000-2002 Katipo Communications
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
10 # version.
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 USA
21 =head1 pay.pl
23 written 11/1/2000 by chris@katipo.oc.nz
24 part of the koha library system, script to facilitate paying off fines
26 =cut
28 use strict;
29 use C4::Context;
30 use C4::Auth;
31 use C4::Output;
32 use CGI;
33 use C4::Members;
34 use C4::Accounts;
35 use C4::Stats;
36 use C4::Koha;
37 use C4::Overdues;
38 use C4::Branch; # GetBranches
40 my $input = new CGI;
42 my $borrowernumber = $input->param('borrowernumber');
43 if ( $borrowernumber eq '' ) {
44 $borrowernumber = $input->param('borrowernumber0');
47 # get borrower details
48 my $data = GetMember( $borrowernumber,'borrowernumber' );
49 my $user = $input->remote_user;
51 # get account details
52 my $branches = GetBranches();
53 my $branch = GetBranch( $input, $branches );
55 my @names = $input->param;
56 my %inp;
57 my $check = 0;
58 for ( my $i = 0 ; $i < @names ; $i++ ) {
59 my $temp = $input->param( $names[$i] );
60 if ( $temp eq 'wo' ) {
61 $inp{ $names[$i] } = $temp;
62 $check = 1;
64 if ( $temp eq 'yes' ) {
66 # FIXME : using array +4, +5, +6 is dirty. Should use arrays for each accountline
67 my $amount = $input->param( $names[ $i + 4 ] );
68 my $borrowernumber = $input->param( $names[ $i + 5 ] );
69 my $accountno = $input->param( $names[ $i + 6 ] );
70 makepayment( $borrowernumber, $accountno, $amount, $user, $branch );
71 $check = 2;
74 my $total = $input->param('total');
75 if ( $check == 0 ) {
76 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
78 template_name => "members/pay.tmpl",
79 query => $input,
80 type => "intranet",
81 authnotrequired => 0,
82 flagsrequired => { borrowers => 1 },
83 debug => 1,
86 if ( $total ne '' ) {
87 recordpayment( $borrowernumber, $total );
90 my ( $total, $accts, $numaccts) = GetMemberAccountRecords( $borrowernumber );
92 my @allfile;
93 my @notify = NumberNotifyId($borrowernumber);
95 my $numberofnotify = scalar(@notify);
96 for ( my $j = 0 ; $j < scalar(@notify) ; $j++ ) {
97 my @loop_pay;
98 my ( $total , $accts, $numaccts) =
99 GetBorNotifyAcctRecord( $borrowernumber, $notify[$j] );
100 for ( my $i = 0 ; $i < $numaccts ; $i++ ) {
101 my %line;
102 if ( $accts->[$i]{'amountoutstanding'} != 0 ) {
103 $accts->[$i]{'amount'} += 0.00;
104 $accts->[$i]{'amountoutstanding'} += 0.00;
105 $line{i} = $j . "" . $i;
106 $line{itemnumber} = $accts->[$i]{'itemnumber'};
107 $line{accounttype} = $accts->[$i]{'accounttype'};
108 $line{amount} = sprintf( "%.2f", $accts->[$i]{'amount'} );
109 $line{amountoutstanding} =
110 sprintf( "%.2f", $accts->[$i]{'amountoutstanding'} );
111 $line{borrowernumber} = $borrowernumber;
112 $line{accountno} = $accts->[$i]{'accountno'};
113 $line{description} = $accts->[$i]{'description'};
114 $line{title} = $accts->[$i]{'title'};
115 $line{notify_id} = $accts->[$i]{'notify_id'};
116 $line{notify_level} = $accts->[$i]{'notify_level'};
119 push( @loop_pay, \%line );
122 my $totalnotify = AmountNotify( $notify[$j], $borrowernumber );
123 ( $totalnotify = '0' ) if ( $totalnotify =~ /^0.00/ );
124 push @allfile,
126 'loop_pay' => \@loop_pay,
127 'notify' => $notify[$j],
128 'total' => sprintf( "%.2f",$totalnotify),
133 my $borrowercategory = GetBorrowercategory( $data->{'categorycode'} );
134 my $category_type = $borrowercategory->{'category_type'};
135 ( $template->param( adultborrower => 1 ) ) if ( $category_type eq 'A' );
137 $template->param(
138 allfile => \@allfile,
139 firstname => $data->{'firstname'},
140 surname => $data->{'surname'},
141 borrowernumber => $borrowernumber,
142 cardnumber => $data->{'cardnumber'},
143 categorycode => $data->{'categorycode'},
144 category_type => $data->{'category_type'},
145 category_description => $data->{'description'},
146 address => $data->{'address'},
147 address2 => $data->{'address2'},
148 city => $data->{'city'},
149 zipcode => $data->{'zipcode'},
150 phone => $data->{'phone'},
151 email => $data->{'email'},
152 branchcode => $data->{'branchcode'},
153 total => sprintf( "%.2f", $total )
155 output_html_with_http_headers $input, $cookie, $template->output;
158 else {
160 my %inp;
161 my @name = $input->param;
162 for ( my $i = 0 ; $i < @name ; $i++ ) {
163 my $test = $input->param( $name[$i] );
164 if ( $test eq 'wo' ) {
165 my $temp = $name[$i];
166 $temp =~ s/payfine//;
167 $inp{ $name[$i] } = $temp;
170 my $borrowernumber;
171 while ( my ( $key, $value ) = each %inp ) {
173 my $accounttype = $input->param("accounttype$value");
174 $borrowernumber = $input->param("borrowernumber$value");
175 my $itemno = $input->param("itemnumber$value");
176 my $amount = $input->param("amount$value");
177 my $accountno = $input->param("accountno$value");
178 writeoff( $borrowernumber, $accountno, $itemno, $accounttype, $amount );
180 $borrowernumber = $input->param('borrowernumber');
181 print $input->redirect(
182 "/cgi-bin/koha/members/moremember.pl?borrowernumber=$borrowernumber");
185 sub writeoff {
186 my ( $borrowernumber, $accountnum, $itemnum, $accounttype, $amount ) = @_;
187 my $user = $input->remote_user;
188 my $dbh = C4::Context->dbh;
189 my $sth =
190 $dbh->prepare(
191 "Update accountlines set amountoutstanding=0 where (accounttype='Res' OR accounttype='FU' OR accounttype ='IP' OR accounttype='CH' OR accounttype='N' OR accounttype='F' OR accounttype='A' OR accounttype='M' OR accounttype='L' OR accounttype='RE' OR accounttype='RL') and accountno=? and borrowernumber=?"
193 $sth->execute( $accountnum, $borrowernumber );
194 $sth->finish;
195 $sth = $dbh->prepare("select max(accountno) from accountlines");
196 $sth->execute;
197 my $account = $sth->fetchrow_hashref;
198 $sth->finish;
199 $account->{'max(accountno)'}++;
200 $sth = $dbh->prepare(
201 "insert into accountlines (borrowernumber,accountno,itemnumber,date,amount,description,accounttype)
202 values (?,?,?,now(),?,'Writeoff','W')"
204 $sth->execute( $borrowernumber, $account->{'max(accountno)'},
205 $itemnum, $amount );
206 $sth->finish;
207 UpdateStats( $branch, 'writeoff', $amount, '', '', '',
208 $borrowernumber );