[Koha-patches] [PATCH] C4::Circulation::FixOverduesOnReturn now handles dropbox mode.

Ryan Higgins rch at balrog.liblime.com
Mon May 12 12:29:38 CEST 2008


---
 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 1711181..5712c0e 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 ffeaabc..196c641 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 88ebe0a..e2d28a6 100755
--- a/misc/cronjobs/fines-ll.pl
+++ b/misc/cronjobs/fines-ll.pl
@@ -104,6 +104,7 @@ for (my $i=0;$i<scalar(@$data);$i++){
 	# Don't update the fine if today is a holiday.  
   	# This ensures that dropbox mode will remove the correct amount of fine.
 	if( ! $isHoliday ) {
+		# FIXME - $type is always null, afaict.
 		UpdateFine($data->[$i]->{'itemnumber'},$data->[$i]->{'borrowernumber'},$amount,$type,$due) if( $amount > 0 ) ;
  	}
 	if($delays1  and $delays2  and $delays3)  {
-- 
1.5.4.2




More information about the Koha-patches mailing list