aggregate billings from a single session
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Sun, 3 Sep 2006 23:30:00 +0000 (23:30 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Sun, 3 Sep 2006 23:30:00 +0000 (23:30 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@5904 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/action.pm

index e405ce9..751ae16 100644 (file)
@@ -543,7 +543,8 @@ sub generate_fines {
                        }
        
                        $client->respond( "\t$pending_fine_count pending fine(s)\n" );
-       
+
+                       my ($latest_billing_ts, $latest_amount);
                        for (my $bill = 1; $bill <= $pending_fine_count; $bill++) {
        
                                if ($current_fine_total > $c->max_fine) {
@@ -573,20 +574,23 @@ sub generate_fines {
                                );
                                next if (@cl);
        
-                               my $billing = money::billing->create(
-                                       { xact          => ''.$c->id,
-                                         note          => "System Generated Overdue Fine",
-                                         billing_type  => "Overdue materials",
-                                         amount        => ''.$c->recuring_fine,
-                                         billing_ts    => $timestamptz,
-                                       }
-                               );
-
-                               $current_fine_total += $billing->amount;
+                               $current_fine_total += $c->recuring_fine;
+                               $latest_amount += $c->recuring_fine;
+                               $latest_billing_ts = $timestamptz;
        
-                               $client->respond( "\t\tCreating fine of ".$billing->amount." for period starting ".$billing->billing_ts."\n" );
+                               $client->respond( "\t\tAdding aggregate fine of ".$c->recuring_fine." for period starting ".$$timestamptz."\n" );
                        }
 
+                       money::billing->create(
+                               { xact          => ''.$c->id,
+                                 note          => "System Generated Overdue Fine",
+                                 billing_type  => "Overdue materials",
+                                 amount        => ''.$latest_amount
+                                 billing_ts    => $latest_billing_ts,
+                               }
+                       ) if ($latest_billing_ts and $latest_amount > 0.0);
+
+
                        $self->method_lookup('open-ils.storage.transaction.commit')->run;
 
                        $penalty->request(