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
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
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 written 11/1/2000 by chris@katipo.oc.nz
24 part of the koha library system, script to facilitate paying off fines
40 use C4
::Branch
; # GetBranches
44 my ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
46 template_name
=> "members/pay.tmpl",
50 flagsrequired
=> { borrowers
=> 1, updatecharges
=> 1 },
55 my $borrowernumber = $input->param('borrowernumber');
56 if ( $borrowernumber eq '' ) {
57 $borrowernumber = $input->param('borrowernumber0');
60 # get borrower details
61 my $data = GetMember
( borrowernumber
=> $borrowernumber );
62 my $user = $input->remote_user;
65 my $branches = GetBranches
();
66 my $branch = GetBranch
( $input, $branches );
68 my @names = $input->param;
71 for ( my $i = 0 ; $i < @names ; $i++ ) {
72 my $temp = $input->param( $names[$i] );
73 if ( $temp eq 'wo' ) {
74 $inp{ $names[$i] } = $temp;
77 if ( $temp eq 'yes' ) {
79 # FIXME : using array +4, +5, +6 is dirty. Should use arrays for each accountline
80 my $amount = $input->param( $names[ $i + 4 ] );
81 my $borrowernumber = $input->param( $names[ $i + 5 ] );
82 my $accountno = $input->param( $names[ $i + 6 ] );
83 makepayment
( $borrowernumber, $accountno, $amount, $user, $branch );
87 my $total = $input->param('total') || '';
90 recordpayment
( $borrowernumber, $total );
93 my ( $total, $accts, $numaccts) = GetMemberAccountRecords
( $borrowernumber );
96 my @notify = NumberNotifyId
($borrowernumber);
98 my $numberofnotify = scalar(@notify);
99 for ( my $j = 0 ; $j < scalar(@notify) ; $j++ ) {
101 my ( $total , $accts, $numaccts) =
102 GetBorNotifyAcctRecord
( $borrowernumber, $notify[$j] );
103 for ( my $i = 0 ; $i < $numaccts ; $i++ ) {
105 if ( $accts->[$i]{'amountoutstanding'} != 0 ) {
106 $accts->[$i]{'amount'} += 0.00;
107 $accts->[$i]{'amountoutstanding'} += 0.00;
108 $line{i
} = $j . "" . $i;
109 $line{itemnumber
} = $accts->[$i]{'itemnumber'};
110 $line{accounttype
} = $accts->[$i]{'accounttype'};
111 $line{amount
} = sprintf( "%.2f", $accts->[$i]{'amount'} );
112 $line{amountoutstanding
} =
113 sprintf( "%.2f", $accts->[$i]{'amountoutstanding'} );
114 $line{borrowernumber
} = $borrowernumber;
115 $line{accountno
} = $accts->[$i]{'accountno'};
116 $line{description
} = $accts->[$i]{'description'};
117 $line{title
} = $accts->[$i]{'title'};
118 $line{notify_id
} = $accts->[$i]{'notify_id'};
119 $line{notify_level
} = $accts->[$i]{'notify_level'};
120 $line{net_balance
} = 1 if($accts->[$i]{'amountoutstanding'} > 0); # you can't pay a credit.
121 push( @loop_pay, \
%line );
125 my $totalnotify = AmountNotify
( $notify[$j], $borrowernumber );
126 ( $totalnotify = '0' ) if ( $totalnotify =~ /^0.00/ );
129 'loop_pay' => \
@loop_pay,
130 'notify' => $notify[$j],
131 'total' => sprintf( "%.2f",$totalnotify),
136 if ( $data->{'category_type'} eq 'C') {
137 my ( $catcodes, $labels ) = GetborCatFromCatType
( 'A', 'WHERE category_type = ?' );
138 my $cnt = scalar(@
$catcodes);
139 $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
140 $template->param( 'catcode' => $catcodes->[0]) if $cnt == 1;
143 $template->param( adultborrower
=> 1 ) if ( $data->{'category_type'} eq 'A' );
144 my ($picture, $dberror) = GetPatronImage
($data->{'cardnumber'});
145 $template->param( picture
=> 1 ) if $picture;
148 allfile
=> \
@allfile,
149 firstname
=> $data->{'firstname'},
150 surname
=> $data->{'surname'},
151 borrowernumber
=> $borrowernumber,
152 cardnumber
=> $data->{'cardnumber'},
153 categorycode
=> $data->{'categorycode'},
154 category_type
=> $data->{'category_type'},
155 categoryname
=> $data->{'description'},
156 address
=> $data->{'address'},
157 address2
=> $data->{'address2'},
158 city
=> $data->{'city'},
159 zipcode
=> $data->{'zipcode'},
160 country
=> $data->{'country'},
161 phone
=> $data->{'phone'},
162 email
=> $data->{'email'},
163 branchcode
=> $data->{'branchcode'},
164 branchname
=> GetBranchName
($data->{'branchcode'}),
165 is_child
=> ($data->{'category_type'} eq 'C'),
166 total
=> sprintf( "%.2f", $total )
168 output_html_with_http_headers
$input, $cookie, $template->output;
174 my @name = $input->param;
175 for ( my $i = 0 ; $i < @name ; $i++ ) {
176 my $test = $input->param( $name[$i] );
177 if ( $test eq 'wo' ) {
178 my $temp = $name[$i];
179 $temp =~ s/payfine//;
180 $inp{ $name[$i] } = $temp;
184 while ( my ( $key, $value ) = each %inp ) {
186 my $accounttype = $input->param("accounttype$value");
187 $borrowernumber = $input->param("borrowernumber$value");
188 my $itemno = $input->param("itemnumber$value");
189 my $amount = $input->param("amount$value");
190 my $accountno = $input->param("accountno$value");
191 writeoff
( $borrowernumber, $accountno, $itemno, $accounttype, $amount );
193 $borrowernumber = $input->param('borrowernumber');
194 print $input->redirect(
195 "/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber");
199 my ( $borrowernumber, $accountnum, $itemnum, $accounttype, $amount ) = @_;
200 my $user = $input->remote_user;
201 my $dbh = C4
::Context
->dbh;
202 undef $itemnum unless $itemnum; # if no item is attached to fine, make sure to store it as a NULL
205 "Update accountlines set amountoutstanding=0 where accountno=? and borrowernumber=?"
207 $sth->execute( $accountnum, $borrowernumber );
209 $sth = $dbh->prepare("select max(accountno) from accountlines");
211 my $account = $sth->fetchrow_hashref;
213 $account->{'max(accountno)'}++;
214 $sth = $dbh->prepare(
215 "insert into accountlines (borrowernumber,accountno,itemnumber,date,amount,description,accounttype)
216 values (?,?,?,now(),?,'Writeoff','W')"
218 $sth->execute( $borrowernumber, $account->{'max(accountno)'},
221 UpdateStats
( $branch, 'writeoff', $amount, '', '', '',