3 #written 11/1/2000 by chris@katipo.co.nz
4 #script to write off accounts
7 # Copyright 2000-2002 Katipo Communications
9 # This file is part of Koha.
11 # Koha is free software; you can redistribute it and/or modify it under the
12 # terms of the GNU General Public License as published by the Free Software
13 # Foundation; either version 2 of the License, or (at your option) any later
16 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
17 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
18 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License along with
21 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
22 # Suite 330, Boston, MA 02111-1307 USA
30 #print $input->header;
35 my @name=$input->param;
36 for (my $i=0;$i<@name;$i++){
37 my $test=$input->param($name[$i]);
41 $inp{$name[$i]}=$temp;
45 while ( my ($key, $value) = each %inp){
47 my $accounttype=$input->param("accounttype$value");
48 $bornum=$input->param("bornum$value");
49 my $itemno=$input->param("itemnumber$value");
50 my $amount=$input->param("amount$value");
51 if ($accounttype eq 'Res'){
52 my $accountno=$input->param("accountno$value");
53 writeoff($bornum,$accountno,$itemno,$accounttype,$amount);
55 writeoff($bornum,'',$itemno,$accounttype,$amount);
58 #print $input->header;
59 $bornum=$input->param('bornum');
60 print $input->redirect("/cgi-bin/koha/pay.pl?bornum=$bornum");
62 #needs to be shifted to a module when time permits
64 my ($bornum,$accountnum,$itemnum,$accounttype,$amount)=@_;
65 my $user=$input->remote_user;
69 my $dbh = C4::Context->dbh;
72 if ($accounttype eq 'Res'){
73 $sth=$dbh->prepare("Update accountlines set amountoutstanding=0 where accounttype='Res' and accountno=? and borrowernumber=?");
74 $sth->execute($accountnum,$bornum);
76 $sth=$dbh->prepare("Update accountlines set amountoutstanding=0 where accounttype=? and itemnumber=? and borrowernumber=?");
77 $sth->execute($accounttype,$itemnum,$bornum);
80 $sth=$dbh->prepare("select max(accountno) from accountlines");
82 my $account=$sth->fetchrow_hashref;
84 $account->{'max(accountno)'}++;
85 $sth=$dbh->prepare("insert into accountlines (borrowernumber,accountno,itemnumber,date,amount,description,accounttype)
86 values (?,?,?,now(),?,'Writeoff','W')");
87 $sth->execute($bornum,$account->{'max(accountno)'},$itemnum,$amount);
90 UpdateStats($env,$user,'writeoff',$amount,'','','',$bornum);