added logic to make sure the transaction is not already closed when applying lost...
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 3 Jan 2007 15:42:22 +0000 (15:42 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 3 Jan 2007 15:42:22 +0000 (15:42 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/branches/rel_1_0@6720 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Application/Circ.pm

index 362147d..a0a91e1 100644 (file)
@@ -332,14 +332,34 @@ sub _set_circ_lost {
 sub _make_bill {
        my( $session, $amount, $type, $xactid ) = @_;
 
-       $logger->activity("The system is charging $amount ".
+       $logger->info("The system is charging $amount ".
                " [$type] for lost materials on circulation $xactid");
 
-       my $bill = Fieldmapper::money::billing->new;
+   # -----------------------------------------------------------------
+   # make sure the transaction is not closed
+   my $e = new_editor(xact=>1);
+   my $xact = $e->retrieve_money_billable_transaction($xactid)
+      or return $e->die_event;
+
+   if( $xact->xact_finish ) {
+      my ($mbts) = $U->fetch_mbts($xactid, $e);
+      if( ($mbts->balance_owed + $amount) != 0 ) {
+         $logger->info("re-opening xact $xactid");
+         $xact->clear_xact_finish;
+         $e->update_money_billable_transaction($xact)
+            or return $e->die_event;
+         $e->commit;
+      } 
+   }
+
+   $e->rollback; # has no effect if it's already been comitted
+   # -----------------------------------------------------------------
 
+
+       my $bill = Fieldmapper::money::billing->new;
        $bill->xact($xactid);
        $bill->amount($amount);
-       $bill->billing_type($type); # - XXX these strings should be configurable some day
+       $bill->billing_type($type); 
        $bill->note('SYSTEM GENERATED');
 
        my $id = $session->request(