From e9f5985c12740d8d2755f33b18923068e13ab60e Mon Sep 17 00:00:00 2001 From: Lari Taskula Date: Fri, 8 Apr 2016 13:26:26 +0000 Subject: [PATCH 2/2] Bug 16223: Enable regex match for rules of debarment removals Rebased-by: Emmi Takkinen Signed-off-by: Katariina Hanhisalo Signed-off-by: Katariina Hanhisalo --- Koha/Patron/Debarments.pm | 36 +++++++++++-------- .../en/modules/admin/preferences/patrons.pref | 9 ++--- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/Koha/Patron/Debarments.pm b/Koha/Patron/Debarments.pm index 36cd70eb5b..144f01ac97 100644 --- a/Koha/Patron/Debarments.pm +++ b/Koha/Patron/Debarments.pm @@ -326,22 +326,28 @@ sub DelDebarmentsAfterPayment { my $total_due = $lines->total_outstanding; foreach my $debarment (@{ $debarments }){ - if (exists $liftDebarmentRules->{$debarment->{'comment'}}) { - # Delete debarment IF: - # 1. there is no maximum outstanding fines defined for the liftDebarmentRule - # and there is no outstanding fines. - # 2. there is a maximum outstanding fines amount defined - # and total_due is smaller or equal than the defined maximum outstanding amount - # Otherwise, do not lift the debarment. - if (not defined $liftDebarmentRules->{$debarment->{'comment'}}->{'outstanding'}){ - if ($total_due <= 0) { - DelDebarment($debarment->{'borrower_debarment_id'}); - } + my $rule; + + foreach my $liftRule (keys %{ $liftDebarmentRules }){ + my $comment = $debarment->{'comment'}; + $rule = $liftRule if $comment =~ $liftRule; + } + next unless $rule; + + # Delete debarment IF: + # 1. there is no maximum outstanding fines defined for the liftDebarmentRule + # and there is no outstanding fines. + # 2. there is a maximum outstanding fines amount defined + # and total_due is smaller or equal than the defined maximum outstanding amount + # Otherwise, do not lift the debarment. + if (not defined $liftDebarmentRules->{$rule}->{'outstanding'}){ + if ($total_due <= 0) { + DelDebarment($debarment->{'borrower_debarment_id'}); } - else { - if ($total_due <= $liftDebarmentRules->{$debarment->{'comment'}}->{'outstanding'}) { - DelDebarment($debarment->{'borrower_debarment_id'}); - } + } + else { + if ($total_due <= $liftDebarmentRules->{$rule}->{'outstanding'}) { + DelDebarment($debarment->{'borrower_debarment_id'}); } } } diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref index 780eef670a..2f522ba2c2 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref @@ -110,13 +110,14 @@ Patrons: - pref: DebarmentsToLiftAfterPayment type: textarea class: code - - Lift these debarments after Borrower has paid his/her fees - - "

Example, debarment is lifted after all fees are paid:

" + - Lift these debarments after Borrower has paid his/her fees. Matches dynamic content in debarment comment. + - "

Example, debarments with comment (either exact match or dynamic content, e.g. 'Debarment message for Patron 123') that match 'Debarment message' are lifted after all fees are paid:

" - "
Debarment message:
  outstanding: 0
" - - "

Example, debarment is lifted after payment with outstanding fees less or equal than 5:

" - - "
Another debarment:
+ - "

Example, debarment with message of exactly 'Debarment message' is lifted after payment with outstanding fees less or equal than 5:

" + - "
^Debarment message$:
  outstanding: 5.00
" + - You can use regex in the definitions to match your needs. Membership expiry: - - When renewing borrowers, base the new expiry date on -- 2.25.1