From 9eee24c9a24275dcd5e49710c13a5581e75ade3c Mon Sep 17 00:00:00 2001 From: rangi Date: Wed, 9 May 2001 23:29:00 +0000 Subject: [PATCH] Changed the way a lost book being returned is handled. If the book has already been paid for a credit is added to their account. And offset against any current charges --- C4/Circulation/Circ2.pm | 48 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/C4/Circulation/Circ2.pm b/C4/Circulation/Circ2.pm index ce86f54c67..d724fc8cbf 100755 --- a/C4/Circulation/Circ2.pm +++ b/C4/Circulation/Circ2.pm @@ -419,7 +419,48 @@ sub returnbook { my $usth = $dbh->prepare($uquery); $usth->execute(); $usth->finish; + #check if any credit is left if so writeoff other accounts] my $nextaccntno = getnextacctno($env,$data->{'borrowernumber'},$dbh); + if ($amountleft < 0){ + $amountleft*=-1; + } + if ($amountleft > 0){ +# print $amountleft; + my $query = "select * from accountlines + where (borrowernumber = '$data->{'borrowernumber'}') and (amountoutstanding >0) + order by date"; + my $sth = $dbh->prepare($query); + $sth->execute; + # offset transactions + my $newamtos; + my $accdata; + while (($accdata=$sth->fetchrow_hashref) and ($amountleft>0)){ + if ($accdata->{'amountoutstanding'} < $amountleft) { + $newamtos = 0; + $amountleft = $amountleft - $accdata->{'amountoutstanding'}; + } else { + $newamtos = $accdata->{'amountoutstanding'} - $amountleft; + $amountleft = 0; + } + my $thisacct = $accdata->{accountno}; + my $updquery = "update accountlines set amountoutstanding= '$newamtos' + where (borrowernumber = '$data->{'borrowernumber'}') and (accountno='$thisacct')"; + my $usth = $dbh->prepare($updquery); + $usth->execute; + $usth->finish; + $updquery = "insert into accountoffsets + (borrowernumber, accountno, offsetaccount, offsetamount) + values + ($data->{'borrowernumber'},$accdata->{'accountno'},$nextaccntno,$newamtos)"; + my $usth = $dbh->prepare($updquery); + $usth->execute; + $usth->finish; + } + } + if ($amountleft > 0){ + $amountleft*=-1; + } + $sth->finish; my $desc="Book Returned ".$iteminformation->{'barcode'}; $uquery = "insert into accountlines (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding) @@ -462,13 +503,18 @@ sub patronflags { my %flags; my ($env,$patroninformation,$dbh) = @_; my $amount = checkaccount($env,$patroninformation->{'borrowernumber'}, $dbh); - if ($amount>0) { + if ($amount > 0) { my %flaginfo; $flaginfo{'message'}=sprintf "Patron owes \$%.02f", $amount; if ($amount>5) { $flaginfo{'noissues'}=1; } $flags{'CHARGES'}=\%flaginfo; + } elsif ($amount < 0){ + my %flaginfo; + $amount=$amount*-1; + $flaginfo{'message'}=sprintf "Patron has credit of \$%.02f", $amount; + $flags{'CHARGES'}=\%flaginfo; } if ($patroninformation->{'gonenoaddress'} == 1) { my %flaginfo; -- 2.39.2