From 59dadd1a4ce3a213e0a2367ef0ce2f0accdd480b Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Tue, 11 Jun 2013 13:22:33 -0400 Subject: [PATCH] Fix Lp bug 965656 WRT back dated checkins with fines. * Move _check_open_xact from OpenILS::Application::Circ::Money to OpenILS::Application::AppUtils so it can be called from wherever. * Modify OpenILS::Application::Circ::Money to use check_open_xact from OpenILS::Application::AppUtils. * Modify finish_fines_and_voiding in OpenILS::Application::Circ::Circulate to use check_open_xact instead of reopen_xact. Signed-off-by: Jason Stephenson Signed-off-by: Ben Shum Conflicts: Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm --- .../lib/OpenILS/Application/AppUtils.pm | 42 +++++++++++++++++ .../lib/OpenILS/Application/Circ/Circulate.pm | 4 +- .../lib/OpenILS/Application/Circ/Money.pm | 45 ++----------------- 3 files changed, 47 insertions(+), 44 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm index e9f1a2ce26..00d7bf2009 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm @@ -2138,5 +2138,47 @@ sub unique_unnested_numbers { ); } +# Check if a transaction should be left open or closed. Close the +# transaction if it should be closed or open it otherwise. Returns +# undef on success or a failure event. +sub check_open_xact { + my( $self, $editor, $xactid, $xact ) = @_; + + # Grab the transaction + $xact ||= $editor->retrieve_money_billable_transaction($xactid); + return $editor->event unless $xact; + $xactid ||= $xact->id; + + # grab the summary and see how much is owed on this transaction + my ($summary) = $self->fetch_mbts($xactid, $editor); + + # grab the circulation if it is a circ; + my $circ = $editor->retrieve_action_circulation($xactid); + + # If nothing is owed on the transaction but it is still open + # and this transaction is not an open circulation, close it + if( + ( $summary->balance_owed == 0 and ! $xact->xact_finish ) and + ( !$circ or $circ->stop_fines )) { + + $logger->info("closing transaction ".$xact->id. ' because balance_owed == 0'); + $xact->xact_finish('now'); + $editor->update_money_billable_transaction($xact) + or return $editor->event; + return undef; + } + + # If money is owed or a refund is due on the xact and xact_finish + # is set, clear it (to reopen the xact) and update + if( $summary->balance_owed != 0 and $xact->xact_finish ) { + $logger->info("re-opening transaction ".$xact->id. ' because balance_owed != 0'); + $xact->clear_xact_finish; + $editor->update_money_billable_transaction($xact) + or return $editor->event; + return undef; + } + return undef; +} + 1; diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm index 2e5924e898..fd90e27bd2 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm @@ -2779,8 +2779,8 @@ sub finish_fines_and_voiding { return $self->bail_on_events($evt) if $evt; - # make sure the circ isn't closed if we just voided some fines - $evt = OpenILS::Application::Circ::CircCommon->reopen_xact($self->editor, $self->circ->id); + # Make sure the circ is open or closed as necessary. + $evt = $U->check_open_xact($self->editor, $self->circ->id); return $self->bail_on_events($evt) if $evt; return undef; diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Money.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Money.pm index eb1ac40587..ec9f052df8 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Money.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Money.pm @@ -599,7 +599,7 @@ sub create_grocery_bill { $apputils->commit_db_session($session); my $e = new_editor(xact=>1); - $evt = _check_open_xact($e, $transid); + $evt = $U->check_open_xact($e, $transid); return $evt if $evt; $e->commit; @@ -706,7 +706,7 @@ sub billing_items_create { my $evt = OpenILS::Utils::Penalty->calculate_penalties($e, $xact->usr, $U->xact_org($xact->id,$e)); return $evt if $evt; - $evt = _check_open_xact($e, $xact->id, $xact); + $evt = $U->check_open_xact($e, $xact->id, $xact); return $evt if $evt; $e->commit; @@ -755,7 +755,7 @@ sub void_bill { $bill->void_time('now'); $e->update_money_billing($bill) or return $e->die_event; - my $evt = _check_open_xact($e, $bill->xact, $xact); + my $evt = $U->check_open_xact($e, $bill->xact, $xact); return $evt if $evt; } @@ -836,45 +836,6 @@ sub edit_payment_note { return 1; } -sub _check_open_xact { - my( $editor, $xactid, $xact ) = @_; - - # Grab the transaction - $xact ||= $editor->retrieve_money_billable_transaction($xactid); - return $editor->event unless $xact; - $xactid ||= $xact->id; - - # grab the summary and see how much is owed on this transaction - my ($summary) = $U->fetch_mbts($xactid, $editor); - - # grab the circulation if it is a circ; - my $circ = $editor->retrieve_action_circulation($xactid); - - # If nothing is owed on the transaction but it is still open - # and this transaction is not an open circulation, close it - if( - ( $summary->balance_owed == 0 and ! $xact->xact_finish ) and - ( !$circ or $circ->stop_fines )) { - - $logger->info("closing transaction ".$xact->id. ' becauase balance_owed == 0'); - $xact->xact_finish('now'); - $editor->update_money_billable_transaction($xact) - or return $editor->event; - return undef; - } - - # If money is owed or a refund is due on the xact and xact_finish - # is set, clear it (to reopen the xact) and update - if( $summary->balance_owed != 0 and $xact->xact_finish ) { - $logger->info("re-opening transaction ".$xact->id. ' becauase balance_owed != 0'); - $xact->clear_xact_finish; - $editor->update_money_billable_transaction($xact) - or return $editor->event; - return undef; - } - return undef; -} - __PACKAGE__->register_method ( method => 'fetch_mbts', -- 2.43.2