From b54401ac66071ff009f804627220c61133ca0def Mon Sep 17 00:00:00 2001 From: Ryan Higgins Date: Mon, 12 May 2008 05:29:38 -0500 Subject: [PATCH] C4::Circulation::FixOverduesOnReturn now handles dropbox mode. Signed-off-by: Joshua Ferraro --- C4/Circulation.pm | 31 +++++++++++++++++++++++++++---- C4/Overdues.pm | 19 +++++++++---------- misc/cronjobs/fines-ll.pl | 1 + 3 files changed, 37 insertions(+), 14 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 1711181001..5712c0e4c1 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -1429,18 +1429,21 @@ sub MarkIssueReturned { =head2 FixOverduesOnReturn - &FixOverduesOnReturn($brn,$itm, $exemptfine); + &FixOverduesOnReturn($brn,$itm, $exemptfine, $dropboxmode); C<$brn> borrowernumber C<$itm> itemnumber +C<$exemptfine> BOOL -- remove overdue charge associated with this issue. +C<$dropboxmode> BOOL -- remove lastincrement on overdue charge associated with this issue. + internal function, called only by AddReturn =cut sub FixOverduesOnReturn { - my ( $borrowernumber, $item, $exemptfine ) = @_; + my ( $borrowernumber, $item, $exemptfine, $dropbox ) = @_; my $dbh = C4::Context->dbh; # check for overdue fine @@ -1453,10 +1456,30 @@ sub FixOverduesOnReturn { # alter fine to show that the book has been returned my $data; if ($data = $sth->fetchrow_hashref) { - my $uquery =($exemptfine)? "update accountlines set accounttype='FFOR', amountoutstanding=0":"update accountlines set accounttype='F' "; + my $uquery; + my @bind = ($borrowernumber,$item ,$data->{'accountno'}); + if ($exemptfine) { + $uquery = "update accountlines set accounttype='FFOR', amountoutstanding=0"; + if (C4::Context->preference("FinesLog")) { + &logaction("FINES", 'MODIFY',$borrowernumber,"Overdue forgiven: item $item"); + } + } elsif ($dropbox && $data->{lastincrement}) { + my $outstanding = $data->{amountoutstanding} - $data->{lastincrement} ; + my $amt = $data->{amount} - $data->{lastincrement} ; + if (C4::Context->preference("FinesLog")) { + &logaction("FINES", 'MODIFY',$borrowernumber,"Dropbox adjustment $amt, item $item"); + } + $uquery = "update accountlines set accounttype='F' "; + if($outstanding >= 0 && $amt >=0) { + $uquery .= ", amount = ? , amountoutstanding=? "; + unshift @bind, ($amt, $outstanding) ; + } + } else { + $uquery = "update accountlines set accounttype='F' "; + } $uquery .= " where (borrowernumber = ?) and (itemnumber = ?) and (accountno = ?)"; my $usth = $dbh->prepare($uquery); - $usth->execute($borrowernumber,$item ,$data->{'accountno'}); + $usth->execute(@bind); $usth->finish(); } diff --git a/C4/Overdues.pm b/C4/Overdues.pm index ffeaabc202..196c641646 100644 --- a/C4/Overdues.pm +++ b/C4/Overdues.pm @@ -207,12 +207,13 @@ but retain these for backwards-comptibility with extant fines scripts. Fines scripts should just supply the date range over which to calculate the fine. -C<&CalcFine> returns a list of three values: +C<&CalcFine> returns a list of four values: C<$amount> is the fine owed by the patron (see above). C<$chargename> is the chargename field from the applicable record in the categoryitem table, whatever that is. +FIXME - What is chargename supposed to be ? C<$message> is a text message, either "First Notice", "Second Notice", or "Final Notice". @@ -451,21 +452,19 @@ sub UpdateFine { if ( my $data = $sth->fetchrow_hashref ) { - # I think this if-clause deals with the case where we're updating - # an existing fine. - # print "in accounts ..."; + # we're updating an existing fine. if ( $data->{'amount'} != $amount ) { - # print "updating"; my $diff = $amount - $data->{'amount'}; my $out = $data->{'amountoutstanding'} + $diff; + my $increment = -1 * $diff; my $sth2 = $dbh->prepare( "UPDATE accountlines SET date=now(), amount=?, - amountoutstanding=?,accounttype='FU' WHERE + amountoutstanding=?, lastincrement=? , accounttype='FU' WHERE borrowernumber=? AND itemnumber=? AND (accounttype='FU' OR accounttype='O') AND description LIKE ?" ); - $sth2->execute( $amount, $out, $data->{'borrowernumber'}, + $sth2->execute( $amount, $out, $increment, $data->{'borrowernumber'}, $data->{'itemnumber'}, "%$due%" ); $sth2->finish; } @@ -498,12 +497,12 @@ sub UpdateFine { my $sth2 = $dbh->prepare( "INSERT INTO accountlines (borrowernumber,itemnumber,date,amount, - description,accounttype,amountoutstanding,accountno) VALUES - (?,?,now(),?,?,'FU',?,?)" + description,accounttype,amountoutstanding,lastincrement,accountno) VALUES + (?,?,now(),?,?,'FU',?,?,?)" ); $sth2->execute( $borrowernumber, $itemnum, $amount, "$type $title->{'title'} $due", - $amount, $nextaccntno); + $amount,$amount, $nextaccntno); $sth2->finish; } # logging action diff --git a/misc/cronjobs/fines-ll.pl b/misc/cronjobs/fines-ll.pl index 88ebe0a5a0..e2d28a6c6d 100755 --- a/misc/cronjobs/fines-ll.pl +++ b/misc/cronjobs/fines-ll.pl @@ -104,6 +104,7 @@ for (my $i=0;$i[$i]->{'itemnumber'},$data->[$i]->{'borrowernumber'},$amount,$type,$due) if( $amount > 0 ) ; } if($delays1 and $delays2 and $delays3) { -- 2.39.5