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 with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 USA
24 written 11/1/2000 by chris@katipo.oc.nz
25 part of the koha library system, script to facilitate paying off fines
39 use C4::Branch; # GetBranches
43 my $borrowernumber = $input->param('borrowernumber');
44 if ( $borrowernumber eq '' ) {
45 $borrowernumber = $input->param('borrowernumber0');
48 # get borrower details
49 my $data = borrdata( '', $borrowernumber );
50 my $user = $input->remote_user;
54 $bor{'borrowernumber'} = $borrowernumber;
55 my $branches = GetBranches();
56 my $printers = GetPrinters();
57 my $branch = GetBranch( $input, $branches );
59 my @names = $input->param;
62 for ( my $i = 0 ; $i < @names ; $i++ ) {
63 my $temp = $input->param( $names[$i] );
64 if ( $temp eq 'wo' ) {
65 $inp{ $names[$i] } = $temp;
68 if ( $temp eq 'yes' ) {
70 # FIXME : using array +4, +5, +6 is dirty. Should use arrays for each accountline
71 my $amount = $input->param( $names[ $i + 4 ] );
72 my $borrowernumber = $input->param( $names[ $i + 5 ] );
73 my $accountno = $input->param( $names[ $i + 6 ] );
74 makepayment( $borrowernumber, $accountno, $amount, $user, $branch );
78 my $total = $input->param('total');
80 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
82 template_name => "members/pay.tmpl",
86 flagsrequired => { borrowers => 1 },
91 recordpayment( $borrowernumber, $total );
94 my ( $numaccts, $accts, $total ) = getboracctrecord( '', \%bor );
96 # creation d'une fonction qui va nous retourner le notify_id dans un tableau
99 my @notify = NumberNotifyId($borrowernumber);
101 my $numberofnotify = scalar(@notify);
102 for ( my $j = 0 ; $j < scalar(@notify) ; $j++ ) {
104 my ( $numaccts, $accts, $total ) =
105 GetBorNotifyAcctRecord( '', \%bor, $notify[$j] );
106 for ( my $i = 0 ; $i < $numaccts ; $i++ ) {
108 if ( $accts->[$i]{'amountoutstanding'} > 0 ) {
109 $accts->[$i]{'amount'} += 0.00;
110 $accts->[$i]{'amountoutstanding'} += 0.00;
111 $line{i} = $j . "" . $i;
112 $line{itemnumber} = $accts->[$i]{'itemnumber'};
113 $line{accounttype} = $accts->[$i]{'accounttype'};
114 $line{amount} = sprintf( "%.2f", $accts->[$i]{'amount'} );
115 $line{amountoutstanding} =
116 sprintf( "%.2f", $accts->[$i]{'amountoutstanding'} );
117 $line{borrowernumber} = $borrowernumber;
118 $line{accountno} = $accts->[$i]{'accountno'};
119 $line{description} = $accts->[$i]{'description'};
120 $line{title} = $accts->[$i]{'title'};
121 $line{notify_id} = $accts->[$i]{'notify_id'};
122 $line{notify_level} = $accts->[$i]{'notify_level'};
125 push( @loop_pay, \%line );
128 my $totalnotify = AmountNotify( $notify[$j] );
129 ( $totalnotify = '0' ) if ( $totalnotify =~ /^0.00/ );
132 'loop_pay' => \@loop_pay,
133 'notify' => $notify[$j],
134 'total' => $totalnotify
139 allfile => \@allfile,
140 firstname => $data->{'firstname'},
141 surname => $data->{'surname'},
142 borrowernumber => $borrowernumber,
143 total => sprintf( "%.2f", $total )
145 print "Content-Type: text/html\n\n", $template->output;
151 my @name = $input->param;
152 for ( my $i = 0 ; $i < @name ; $i++ ) {
153 my $test = $input->param( $name[$i] );
154 if ( $test eq 'wo' ) {
155 my $temp = $name[$i];
156 $temp =~ s/payfine//;
157 $inp{ $name[$i] } = $temp;
161 while ( my ( $key, $value ) = each %inp ) {
163 my $accounttype = $input->param("accounttype$value");
164 $borrowernumber = $input->param("borrowernumber$value");
165 my $itemno = $input->param("itemnumber$value");
166 my $amount = $input->param("amount$value");
167 my $accountno = $input->param("accountno$value");
168 writeoff( $borrowernumber, $accountno, $itemno, $accounttype, $amount );
170 $borrowernumber = $input->param('borrowernumber');
171 print $input->redirect(
172 "/cgi-bin/koha/members/moremember.pl?borrowernumber=$borrowernumber");
176 my ( $borrowernumber, $accountnum, $itemnum, $accounttype, $amount ) = @_;
177 my $user = $input->remote_user;
178 my $dbh = C4::Context->dbh;
181 "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=?"
183 $sth->execute( $accountnum, $borrowernumber );
185 $sth = $dbh->prepare("select max(accountno) from accountlines");
187 my $account = $sth->fetchrow_hashref;
189 $account->{'max(accountno)'}++;
190 $sth = $dbh->prepare(
191 "insert into accountlines (borrowernumber,accountno,itemnumber,date,amount,description,accounttype)
192 values (?,?,?,now(),?,'Writeoff','W')"
194 $sth->execute( $borrowernumber, $account->{'max(accountno)'},
197 UpdateStats( $branch, 'writeoff', $amount, '', '', '',