From 667a96b9b8aaa8426a5dcf54a01f3035730dbfcc Mon Sep 17 00:00:00 2001 From: Stefan Berndtsson Date: Thu, 30 Sep 2021 15:11:59 +0200 Subject: [PATCH] Bug 20262: Add ability to refund lost item fees without creating credits Some libraries handle refunding of paid lost fees at a financial office and not within Koha. To facilitate this, it would be good for Koha to have the option to not generate lost returned credits by skipping fully paid lost items, and only refunding the outstanding balance on partially paid lost fees. Test Plan: 1) Apply this patch 2) Set your lost item refund on return policies to 'Only if unpaid' 3) Mark an item lost, charging the lost fee 4) Return the item, a full refund should ocurr 5) Mark another item lost, charging the lost fee 6) Make a partial payment on this lost fee 7) Return the item 8) The remaining balance of that fee should be 0, but the patron should not recieve a credit for the already paid balance 8) Mark another item lost, charging the lost fee 9) Fully pay the lost fee 10) Return the item. The paid lost fee should be unaffected. --- Koha/Item.pm | 29 ++++++++++++++----- .../prog/en/modules/admin/smart-rules.tt | 24 +++++++++++++++ 2 files changed, 45 insertions(+), 8 deletions(-) diff --git a/Koha/Item.pm b/Koha/Item.pm index 60d80a5c3e..2ffbdbfdac 100644 --- a/Koha/Item.pm +++ b/Koha/Item.pm @@ -997,14 +997,26 @@ sub _set_found_trigger { if ( $patron ) { my $account = $patron->account; - my $total_to_refund = 0; - # Use cases - if ( $lost_charge->amount > $lost_charge->amountoutstanding ) { + # Credit outstanding amount + my $credit_total = $lost_charge->amountoutstanding; + # Use cases + if ( + $lost_charge->amount > $lost_charge->amountoutstanding && + $lostreturn_policy ne "refund_unpaid" + ) { # some amount has been cancelled. collect the offsets that are not writeoffs # this works because the only way to subtract from this kind of a debt is # using the UI buttons 'Pay' and 'Write off' + + # We don't credit any payments if return policy is + # "refund_unpaid" + # + # In that case only unpaid/outstanding amount + # will be credited wich settles the debt without + # creating extra credits + my $credit_offsets = $lost_charge->debit_offsets( { 'credit_id' => { '!=' => undef }, @@ -1013,13 +1025,14 @@ sub _set_found_trigger { { join => 'credit' } ); - $total_to_refund = ( $credit_offsets->count > 0 ) - ? $credit_offsets->total * -1 # credits are negative on the DB - : 0; + my $total_to_refund = ( $credit_offsets->count > 0 ) + ? $credit_offsets->total * -1 # credits are negative on the DB + : 0; + # Credit the outstanding amount, then add what has been + # paid to create a net credit for this amount + $credit_total += $total_to_refund; } - my $credit_total = $lost_charge->amountoutstanding + $total_to_refund; - my $credit; if ( $credit_total > 0 ) { my $branchcode = diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt index 172e546f8a..97c968f0ee 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt @@ -810,26 +810,37 @@ [% IF ( current_branch == '*' ) %] [% IF ( defaultRefundRule == 'refund' ) %] + + + + + [% ELSIF ( defaultRefundRule == 'refund_unpaid' ) %] + + [% ELSIF ( defaultRefundRule == 'charge' ) %] + [% ELSIF ( defaultRefundRule == 'restore' ) %] + [% ELSIF ( defaultRefundRule == 0 ) %] + [% ELSE %] + @@ -843,6 +854,8 @@ [% END %] [% IF defaultRefundRule == 'refund' %] Use default (Refund lost item charge) + [% ELSIF defaultRefundRule == 'refund_unpaid' %] + Use default (Refund lost item charge (only if unpaid)) [% ELSIF defaultRefundRule == 'charge' %] Use default (Refund lost item charge and restore overdue fine) [% ELSIF defaultRefundRule == 'restore' %] @@ -853,27 +866,38 @@ [% IF ( not refundLostItemFeeRule ) %] + [% ELSE %] [% IF ( refundLostItemFeeRule.rule_value == 'refund' ) %] + + [% ELSIF ( refundLostItemFeeRule.rule_value == 'refund_unpaid' ) %] + + + + + [% ELSIF ( refundLostItemFeeRule.rule_value == 'charge' ) %] + [% ELSIF ( refundLostItemFeeRule.rule_value == 'restore' ) %] + [% ELSIF ( refundLostItemFeeRule.rule_value == 0 ) %] + -- 2.20.1