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 );
87 if ( $temp eq 'no'||$temp eq 'yes'||$temp eq 'wo') {
88 my $borrowernumber = $input->param( $names[ $i + 5 ] );
89 my $accountno = $input->param( $names[ $i + 6 ] );
90 my $note = $input->param( $names[ $i + 10 ] );
91 ModNote( $borrowernumber, $accountno, $note );
95 my $total = $input->param('total') || '';
98 recordpayment( $borrowernumber, $total );
101 my ( $total, $accts, $numaccts) = GetMemberAccountRecords( $borrowernumber );
104 my @notify = NumberNotifyId($borrowernumber);
106 my $numberofnotify = scalar(@notify);
107 for ( my $j = 0 ; $j < scalar(@notify) ; $j++ ) {
109 my ( $total , $accts, $numaccts) =
110 GetBorNotifyAcctRecord( $borrowernumber, $notify[$j] );
111 for ( my $i = 0 ; $i < $numaccts ; $i++ ) {
113 if ( $accts->[$i]{'amountoutstanding'} != 0 ) {
114 $accts->[$i]{'amount'} += 0.00;
115 $accts->[$i]{'amountoutstanding'} += 0.00;
116 $line{i} = $j . "" . $i;
117 $line{itemnumber} = $accts->[$i]{'itemnumber'};
118 $line{accounttype} = $accts->[$i]{'accounttype'};
119 $line{amount} = sprintf( "%.2f", $accts->[$i]{'amount'} );
120 $line{amountoutstanding} =
121 sprintf( "%.2f", $accts->[$i]{'amountoutstanding'} );
122 $line{borrowernumber} = $borrowernumber;
123 $line{accountno} = $accts->[$i]{'accountno'};
124 $line{description} = $accts->[$i]{'description'};
125 $line{note} = $accts->[$i]{'note'};
126 $line{title} = $accts->[$i]{'title'};
127 $line{notify_id} = $accts->[$i]{'notify_id'};
128 $line{notify_level} = $accts->[$i]{'notify_level'};
129 $line{net_balance} = 1 if($accts->[$i]{'amountoutstanding'} > 0); # you can't pay a credit.
130 push( @loop_pay, \%line );
134 my $totalnotify = AmountNotify( $notify[$j], $borrowernumber );
135 ( $totalnotify = '0' ) if ( $totalnotify =~ /^0.00/ );
138 'loop_pay' => \@loop_pay,
139 'notify' => $notify[$j],
140 'total' => sprintf( "%.2f",$totalnotify),
145 if ( $data->{'category_type'} eq 'C') {
146 my ( $catcodes, $labels ) = GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
147 my $cnt = scalar(@$catcodes);
148 $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
149 $template->param( 'catcode' => $catcodes->[0]) if $cnt == 1;
152 $template->param( adultborrower => 1 ) if ( $data->{'category_type'} eq 'A' );
153 my ($picture, $dberror) = GetPatronImage($data->{'cardnumber'});
154 $template->param( picture => 1 ) if $picture;
157 allfile => \@allfile,
158 firstname => $data->{'firstname'},
159 surname => $data->{'surname'},
160 borrowernumber => $borrowernumber,
161 cardnumber => $data->{'cardnumber'},
162 categorycode => $data->{'categorycode'},
163 category_type => $data->{'category_type'},
164 categoryname => $data->{'description'},
165 address => $data->{'address'},
166 address2 => $data->{'address2'},
167 city => $data->{'city'},
168 state => $data->{'state'},
169 zipcode => $data->{'zipcode'},
170 country => $data->{'country'},
171 phone => $data->{'phone'},
172 email => $data->{'email'},
173 branchcode => $data->{'branchcode'},
174 branchname => GetBranchName($data->{'branchcode'}),
175 is_child => ($data->{'category_type'} eq 'C'),
176 total => sprintf( "%.2f", $total )
178 output_html_with_http_headers $input, $cookie, $template->output;
184 my @name = $input->param;
185 for ( my $i = 0 ; $i < @name ; $i++ ) {
186 my $test = $input->param( $name[$i] );
187 if ( $test eq 'wo' ) {
188 my $temp = $name[$i];
189 $temp =~ s/payfine//;
190 $inp{ $name[$i] } = $temp;
194 while ( my ( $key, $value ) = each %inp ) {
196 my $accounttype = $input->param("accounttype$value");
197 $borrowernumber = $input->param("borrowernumber$value");
198 my $itemno = $input->param("itemnumber$value");
199 my $amount = $input->param("amount$value");
200 my $accountno = $input->param("accountno$value");
201 writeoff( $borrowernumber, $accountno, $itemno, $accounttype, $amount );
203 $borrowernumber = $input->param('borrowernumber');
204 print $input->redirect(
205 "/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber");
209 my ( $borrowernumber, $accountnum, $itemnum, $accounttype, $amount ) = @_;
210 my $user = $input->remote_user;
211 my $dbh = C4::Context->dbh;
212 undef $itemnum unless $itemnum; # if no item is attached to fine, make sure to store it as a NULL
215 "Update accountlines set amountoutstanding=0 where accountno=? and borrowernumber=?"
217 $sth->execute( $accountnum, $borrowernumber );
219 $sth = $dbh->prepare("select max(accountno) from accountlines");
221 my $account = $sth->fetchrow_hashref;
223 $account->{'max(accountno)'}++;
224 $sth = $dbh->prepare(
225 "insert into accountlines (borrowernumber,accountno,itemnumber,date,amount,description,accounttype)
226 values (?,?,?,now(),?,'Writeoff','W')"
228 $sth->execute( $borrowernumber, $account->{'max(accountno)'},
231 UpdateStats( $branch, 'writeoff', $amount, '', '', '',