Removed trailing whitespace.
[koha.git] / sec / writeoff.pl
1 #!/usr/bin/perl
2
3 #written 11/1/2000 by chris@katipo.co.nz
4 #script to write off accounts
5
6
7 # Copyright 2000-2002 Katipo Communications
8 #
9 # This file is part of Koha.
10 #
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
14 # version.
15 #
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.
19 #
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
23
24 use strict;
25 use CGI;
26 use C4::Context;
27 use C4::Stats;
28 my $input=new CGI;
29
30 #print $input->header;
31 #print $input->dump;
32
33 my%inp;
34
35 my @name=$input->param;
36 for (my $i=0;$i<@name;$i++){
37   my $test=$input->param($name[$i]);
38   if ($test eq 'wo'){
39     my $temp=$name[$i];
40     $temp=~ s/payfine//;
41     $inp{$name[$i]}=$temp;
42   }
43 }
44 my $bornum;
45 while ( my ($key, $value) = each %inp){
46 #  print $key,$value;
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);
54   } else {
55     writeoff($bornum,'',$itemno,$accounttype,$amount);
56   }
57 }
58 #print $input->header;
59 $bornum=$input->param('bornum');
60 print $input->redirect("/cgi-bin/koha/pay.pl?bornum=$bornum");
61
62 #needs to be shifted to a module when time permits
63 sub writeoff{
64   my ($bornum,$accountnum,$itemnum,$accounttype,$amount)=@_;
65   my $user=$input->remote_user;
66   $user=~ s/Levin/C/;
67   $user=~ s/Foxton/F/;
68   $user=~ s/Shannon/S/;
69   my $dbh = C4::Context->dbh;
70   my $env;
71   my $query="Update accountlines set amountoutstanding=0 where ";
72   if ($accounttype eq 'Res'){
73     $query.="accounttype='Res' and accountno='$accountnum' and borrowernumber='$bornum'";
74   } else {
75     $query.="accounttype='$accounttype' and itemnumber='$itemnum' and borrowernumber='$bornum'";
76   }
77   my $sth=$dbh->prepare($query);
78 #  print $query;
79   $sth->execute;
80   $sth->finish;
81   $query="select max(accountno) from accountlines";
82   $sth=$dbh->prepare($query);
83   $sth->execute;
84   my $account=$sth->fetchrow_hashref;
85   $sth->finish;
86   $account->{'max(accountno)'}++;
87   $query="insert into accountlines (borrowernumber,accountno,itemnumber,date,amount,description,accounttype)
88   values ('$bornum','$account->{'max(accountno)'}','$itemnum',now(),'$amount','Writeoff','W')";
89   $sth=$dbh->prepare($query);
90   $sth->execute;
91   $sth->finish;
92 #  print $query;
93   UpdateStats($env,$user,'writeoff',$amount,'','','',$bornum);
94 }