Address Launchpad Bug 793550. user/dyrcona/lp793550_rel_2_2
authorJason Stephenson <jstephenson@mvlc.org>
Mon, 1 Oct 2012 15:32:15 +0000 (11:32 -0400)
committerJason Stephenson <jstephenson@mvlc.org>
Mon, 1 Oct 2012 19:04:36 +0000 (15:04 -0400)
Check for stop fines reason of CHECKIN or RENEW before closing a circulation
transaction when the balance reaches zero.

Also, if the stop fines reason is LOST, then check a new ou setting,
circ.lost.xact_finish_on_zero, to determine if the transaction is closed or
kept open.  The setting is checked for the circulation copy's circ_lib.

Signed-off-by: Jason Stephenson <jstephenson@mvlc.org>
Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Money.pm
Open-ILS/src/sql/Pg/950.data.seed-values.sql
Open-ILS/src/sql/Pg/upgrade/XXXX.data.coust_lost_xact_finish_on_zero.sql [new file with mode: 0644]

index f8c276d..998c215 100644 (file)
@@ -333,9 +333,33 @@ sub make_payments {
             $credit += $cred;
             my $circ = $e->retrieve_action_circulation($transid);
 
-            if(!$circ || $circ->stop_fines) {
-                # If this is a circulation, we can't close the transaction
-                # unless stop_fines is set.
+            # Whether or not we close the transaction:
+            my $close = 0;
+
+            if (!$circ) {
+                # Close if we have no circulation.
+                $close = 1;
+            } elsif ($circ->stop_fines) {
+                my $reason = $circ->stop_fines;
+                # We definitely want to close if this circulation was
+                # checked in or renewed.
+                if ($reason eq "CHECKIN" || $reason eq "RENEW") {
+                    $close = 1;
+                } elsif ($reason eq "LOST") {
+                    # Check the copy circ_lib to see if they close
+                    # transactions when lost are paid.
+                    my $copy = $e->retrieve_asset_copy($circ->target_copy);
+                    if ($copy) {
+                        $close = $U->ou_ancestor_setting_value(
+                            $copy->circ_lib,
+                            'circ.lost.xact_finish_on_zero',
+                            $e
+                        );
+                    }
+                }
+            }
+
+            if ($U->is_true($close)) {
                 $trans = $e->retrieve_money_billable_transaction($transid);
                 $trans->xact_finish("now");
                 if (!$e->update_money_billable_transaction($trans)) {
index b7689d4..dc76c37 100644 (file)
@@ -11597,3 +11597,22 @@ INSERT INTO config.org_unit_setting_type ( name, label, description, datatype, g
     );
 
 
+INSERT INTO config.org_unit_setting_type
+    (name, grp, label, description, datatype)
+    VALUES (
+        'circ.lost.xact_finish_on_zero',
+        'finance',
+        oils_i18n_gettext(
+            'circ.lost.xact_finish_on_zero',
+            'Close transaction when lost balance equals zero',
+            'coust',
+            'label'
+        ),
+        oils_i18n_gettext(
+            'circ.lost.xact_finish_on_zero',
+            'Close transaction when lost balance equals zero.  This removes the lost copy from the patron record when it is paid',
+            'coust',
+            'description'
+        ),
+        'bool'
+    );
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.data.coust_lost_xact_finish_on_zero.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.data.coust_lost_xact_finish_on_zero.sql
new file mode 100644 (file)
index 0000000..45b270e
--- /dev/null
@@ -0,0 +1,25 @@
+BEGIN;
+
+SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+
+INSERT INTO config.org_unit_setting_type
+    (name, grp, label, description, datatype)
+    VALUES (
+        'circ.lost.xact_finish_on_zero',
+        'finance',
+        oils_i18n_gettext(
+            'circ.lost.xact_finish_on_zero',
+            'Close transaction when lost balance equals zero',
+            'coust',
+            'label'
+        ),
+        oils_i18n_gettext(
+            'circ.lost.xact_finish_on_zero',
+            'Close transaction when lost balance equals zero.  This removes the lost copy from the patron record when it is paid',
+            'coust',
+            'description'
+        ),
+        'bool'
+    );
+
+COMMIT;