Kumara - predecessor to Koha
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
1.9 KiB

  1. #!/usr/bin/perl
  2. #written 11/1/2000 by chris@katipo.co.nz
  3. #script to write off accounts
  4. use strict;
  5. use CGI;
  6. use C4::Database;
  7. my $input=new CGI;
  8. #print $input->header;
  9. #print $input->dump;
  10. my%inp;
  11. my @name=$input->param;
  12. for (my $i=0;$i<@name;$i++){
  13. my $test=$input->param($name[$i]);
  14. if ($test eq 'wo'){
  15. my $temp=$name[$i];
  16. $temp=~ s/payfine//;
  17. $inp{$name[$i]}=$temp;
  18. }
  19. }
  20. my $bornum;
  21. while ( my ($key, $value) = each %inp){
  22. # print $key,$value;
  23. my $accounttype=$input->param("accounttype$value");
  24. $bornum=$input->param("bornum$value");
  25. my $itemno=$input->param("itemnumber$value");
  26. my $amount=$input->param("amount$value");
  27. if ($accounttype eq 'Res'){
  28. my $accountno=$input->param("accountno$value");
  29. writeoff($bornum,$accountno,$itemno,$accounttype,$amount);
  30. } else {
  31. writeoff($bornum,'',$itemno,$accounttype,$amount);
  32. }
  33. }
  34. #print $input->header;
  35. print $input->redirect("/cgi-bin/koha/pay.pl?bornum=$bornum");
  36. #needs to be shifted to a module when time permits
  37. sub writeoff{
  38. my ($bornum,$accountnum,$itemnum,$accounttype,$amount)=@_;
  39. my $dbh=C4Connect;
  40. my $query="Update accountlines set amountoutstanding=0 where ";
  41. if ($accounttype eq 'Res'){
  42. $query.="accounttype='Res' and accountno='$accountnum' and borrowernumber='$bornum'";
  43. } else {
  44. $query.="accounttype='$accounttype' and itemnumber='$itemnum' and borrowernumber='$bornum'";
  45. }
  46. my $sth=$dbh->prepare($query);
  47. # print $query;
  48. $sth->execute;
  49. $sth->finish;
  50. $query="select max(accountno) from accountlines";
  51. $sth=$dbh->prepare($query);
  52. $sth->execute;
  53. my $account=$sth->fetchrow_hashref;
  54. $sth->finish;
  55. $account->{'max(accountno)'}++;
  56. $query="insert into accountlines (borrowernumber,accountno,itemnumber,date,amount,description,accounttype)
  57. values ('$bornum','$account->{'max(accountno)'}','$itemnum',now(),'$amount','Writeoff','W')";
  58. $sth=$dbh->prepare($query);
  59. $sth->execute;
  60. $sth->finish;
  61. # print $query;
  62. $dbh->disconnect;
  63. }