From: erickson Date: Wed, 3 Jan 2007 15:42:22 +0000 (+0000) Subject: added logic to make sure the transaction is not already closed when applying lost... X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=a74f6901625ddba6f3e3288961b300f6defb6679;p=Evergreen.git added logic to make sure the transaction is not already closed when applying lost materials fees git-svn-id: svn://svn.open-ils.org/ILS/trunk@6720 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Circ.pm b/Open-ILS/src/perlmods/OpenILS/Application/Circ.pm index 362147d694..a0a91e1e04 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Circ.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Circ.pm @@ -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(