3 # Copyright 2000-2002 Katipo Communications
4 # Copyright 2010 BibLibre
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along
18 # with Koha; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 written 11/1/2000 by chris@katipo.oc.nz
25 part of the koha library system, script to facilitate paying off fines
41 use C4::Branch; # GetBranches
45 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
47 template_name => "members/pay.tmpl",
51 flagsrequired => { borrowers => 1, updatecharges => 1 },
56 my $borrowernumber = $input->param('borrowernumber');
57 if ( $borrowernumber eq '' ) {
58 $borrowernumber = $input->param('borrowernumber0');
61 # get borrower details
62 my $data = GetMember( borrowernumber => $borrowernumber );
63 my $user = $input->remote_user;
66 my $branches = GetBranches();
67 my $branch = GetBranch( $input, $branches );
69 my @names = $input->param;
72 for ( my $i = 0 ; $i < @names ; $i++ ) {
73 my $temp = $input->param( $names[$i] );
74 if ( $temp eq 'wo' ) {
75 $inp{ $names[$i] } = $temp;
78 if ( $temp eq 'yes' ) {
80 # FIXME : using array +4, +5, +6 is dirty. Should use arrays for each accountline
81 my $amount = $input->param( $names[ $i + 4 ] );
82 my $borrowernumber = $input->param( $names[ $i + 5 ] );
83 my $accountno = $input->param( $names[ $i + 6 ] );
84 makepayment( $borrowernumber, $accountno, $amount, $user, $branch );
88 my $total = $input->param('total') || '';
91 recordpayment( $borrowernumber, $total );
94 my ( $total, $accts, $numaccts) = GetMemberAccountRecords( $borrowernumber );
97 my @notify = NumberNotifyId($borrowernumber);
99 my $numberofnotify = scalar(@notify);
100 for ( my $j = 0 ; $j < scalar(@notify) ; $j++ ) {
102 my ( $total , $accts, $numaccts) =
103 GetBorNotifyAcctRecord( $borrowernumber, $notify[$j] );
104 for ( my $i = 0 ; $i < $numaccts ; $i++ ) {
106 if ( $accts->[$i]{'amountoutstanding'} != 0 ) {
107 $accts->[$i]{'amount'} += 0.00;
108 $accts->[$i]{'amountoutstanding'} += 0.00;
109 $line{i} = $j . "" . $i;
110 $line{itemnumber} = $accts->[$i]{'itemnumber'};
111 $line{accounttype} = $accts->[$i]{'accounttype'};
112 $line{amount} = sprintf( "%.2f", $accts->[$i]{'amount'} );
113 $line{amountoutstanding} =
114 sprintf( "%.2f", $accts->[$i]{'amountoutstanding'} );
115 $line{borrowernumber} = $borrowernumber;
116 $line{accountno} = $accts->[$i]{'accountno'};
117 $line{description} = $accts->[$i]{'description'};
118 $line{title} = $accts->[$i]{'title'};
119 $line{notify_id} = $accts->[$i]{'notify_id'};
120 $line{notify_level} = $accts->[$i]{'notify_level'};
121 $line{net_balance} = 1 if($accts->[$i]{'amountoutstanding'} > 0); # you can't pay a credit.
122 push( @loop_pay, \%line );
126 my $totalnotify = AmountNotify( $notify[$j], $borrowernumber );
127 ( $totalnotify = '0' ) if ( $totalnotify =~ /^0.00/ );
130 'loop_pay' => \@loop_pay,
131 'notify' => $notify[$j],
132 'total' => sprintf( "%.2f",$totalnotify),
137 if ( $data->{'category_type'} eq 'C') {
138 my ( $catcodes, $labels ) = GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
139 my $cnt = scalar(@$catcodes);
140 $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
141 $template->param( 'catcode' => $catcodes->[0]) if $cnt == 1;
144 $template->param( adultborrower => 1 ) if ( $data->{'category_type'} eq 'A' );
145 my ($picture, $dberror) = GetPatronImage($data->{'cardnumber'});
146 $template->param( picture => 1 ) if $picture;
149 allfile => \@allfile,
150 firstname => $data->{'firstname'},
151 surname => $data->{'surname'},
152 borrowernumber => $borrowernumber,
153 cardnumber => $data->{'cardnumber'},
154 categorycode => $data->{'categorycode'},
155 category_type => $data->{'category_type'},
156 categoryname => $data->{'description'},
157 address => $data->{'address'},
158 address2 => $data->{'address2'},
159 city => $data->{'city'},
160 zipcode => $data->{'zipcode'},
161 country => $data->{'country'},
162 phone => $data->{'phone'},
163 email => $data->{'email'},
164 branchcode => $data->{'branchcode'},
165 branchname => GetBranchName($data->{'branchcode'}),
166 is_child => ($data->{'category_type'} eq 'C'),
167 total => sprintf( "%.2f", $total )
169 output_html_with_http_headers $input, $cookie, $template->output;
175 my @name = $input->param;
176 for ( my $i = 0 ; $i < @name ; $i++ ) {
177 my $test = $input->param( $name[$i] );
178 if ( $test eq 'wo' ) {
179 my $temp = $name[$i];
180 $temp =~ s/payfine//;
181 $inp{ $name[$i] } = $temp;
185 while ( my ( $key, $value ) = each %inp ) {
187 my $accounttype = $input->param("accounttype$value");
188 $borrowernumber = $input->param("borrowernumber$value");
189 my $itemno = $input->param("itemnumber$value");
190 my $amount = $input->param("amount$value");
191 my $accountno = $input->param("accountno$value");
192 writeoff( $borrowernumber, $accountno, $itemno, $accounttype, $amount );
194 $borrowernumber = $input->param('borrowernumber');
195 print $input->redirect(
196 "/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber");
200 my ( $borrowernumber, $accountnum, $itemnum, $accounttype, $amount ) = @_;
201 my $user = $input->remote_user;
202 my $dbh = C4::Context->dbh;
203 undef $itemnum unless $itemnum; # if no item is attached to fine, make sure to store it as a NULL
206 "Update accountlines set amountoutstanding=0 where accountno=? and borrowernumber=?"
208 $sth->execute( $accountnum, $borrowernumber );
210 $sth = $dbh->prepare("select max(accountno) from accountlines");
212 my $account = $sth->fetchrow_hashref;
214 $account->{'max(accountno)'}++;
215 $sth = $dbh->prepare(
216 "insert into accountlines (borrowernumber,accountno,itemnumber,date,amount,description,accounttype)
217 values (?,?,?,now(),?,'Writeoff','W')"
219 $sth->execute( $borrowernumber, $account->{'max(accountno)'},
222 UpdateStats( $branch, 'writeoff', $amount, '', '', '',