$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)) {
'bool'
);
+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'
+ );
--- /dev/null
+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;