removing unused script
[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 $sth;
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);
75   } else {
76     $sth=$dbh->prepare("Update accountlines set amountoutstanding=0 where accounttype=? and itemnumber=? and borrowernumber=?");
77     $sth->execute($accounttype,$itemnum,$bornum);
78   }
79   $sth->finish;
80   $sth=$dbh->prepare("select max(accountno) from accountlines");
81   $sth->execute;
82   my $account=$sth->fetchrow_hashref;
83   $sth->finish;
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);
88   $sth->finish;
89 #  print $query;
90   UpdateStats($env,$user,'writeoff',$amount,'','','',$bornum);
91 }