LP1786312 Due date extension honors max fine user/berick/lp1786312-due-date-extend-exceed-max-fines
authorBill Erickson <berickxx@gmail.com>
Mon, 19 Oct 2020 21:04:35 +0000 (17:04 -0400)
committerBill Erickson <berickxx@gmail.com>
Mon, 19 Oct 2020 21:24:29 +0000 (17:24 -0400)
When calculating the amount billed to a patron in overdue fines, inspect
all such fines on the transaction, regardless of billing timestamp.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/CircCommon.pm

index 73b79a3..f89fa43 100644 (file)
@@ -447,7 +447,6 @@ sub generate_fines {
 
     my $handling_resvs = 0;
     for my $c (@$circs) {
-
         my $ctype = ref($c);
 
         if (!$ctype) { # we received only an idlist, not objects
@@ -525,20 +524,31 @@ sub generate_fines {
                 "\tItem was due on or before: ".localtime($due)."\n") if $conn;
     
             my @fines = @{$e->search_money_billing([
-                { xact => $c->id,
-                  btype => 1,
-                  billing_ts => { '>' => $c->$due_date_method } },
+                { xact => $c->id, btype => 1 },
                 { order_by => {mb => 'billing_ts DESC'},
                   flesh => 1,
                   flesh_fields => {mb => ['adjustments']} }
             ])};
 
-            my $f_idx = 0;
-            my $fine = $fines[$f_idx] if (@fines);
+            # Calcuate fine totals using all overdue fines, regardless
+            # of billing creation time.
             my $current_fine_total = 0;
             $current_fine_total += $_->amount * 100 for (grep { $_ and !$U->is_true($_->voided) } @fines);
             $current_fine_total -= $_->amount * 100 for (map { @{$_->adjustments} } @fines);
+
+            $logger->info(
+                sprintf("Current overdue fine total for xact %d is %0.2f",
+                $c->id, ($current_fine_total / 100)));
+
+            # Determine the billing period of the next fine to generate
+            # based on the billing time of the most recent fine *which
+            # occurred after the current due date*.  Otherwise, when a 
+            # due date changes, the fine generator will back-fill billings
+            # for a period of time where the item was not technically overdue.
+            @fines = grep { $_->billing_ts > $c->$due_date_method } @fines;
     
+            my $f_idx = 0;
+            my $fine = $fines[$f_idx] if (@fines);
             my $last_fine;
             if ($fine) {
                 $conn->respond( "Last billing time: ".$fine->billing_ts." (clensed format: ".clean_ISO8601( $fine->billing_ts ).")") if $conn;