Bugzilla – Attachment 104399 Details for
Bug 16223
Automatically remove any borrower debarments after a payment
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 16223: Automatically remove any borrower debarments after a payment
0001-Bug-16223-Automatically-remove-any-borrower-debarmen.patch (text/plain), 10.80 KB, created by
Emmi Takkinen
on 2020-05-06 06:52:42 UTC
(
hide
)
Description:
Bug 16223: Automatically remove any borrower debarments after a payment
Filename:
MIME Type:
Creator:
Emmi Takkinen
Created:
2020-05-06 06:52:42 UTC
Size:
10.80 KB
patch
obsolete
>From ec352a03d37024e6439f8e38e74e4df87ca800e5 Mon Sep 17 00:00:00 2001 >From: Lari Taskula <larit@student.uef.fi> >Date: Thu, 7 Apr 2016 11:47:02 +0000 >Subject: [PATCH 1/2] Bug 16223: Automatically remove any borrower debarments > after a payment > >Some libraries debar Patrons at the end of the year for having unpaid fines, >like in Bug 15157. Currently librarians have to manually remove this type of >debarments after Patron has paid his/her fines. Add a system preference to >define debarments that should be automatically removed after a payment is made, >and add functionality to actually remove the defined debarments from Patron. >Also let libraries to define the amount of outstanding fines after payment >after which the debarment will be removed. > >This patch introduces a system preference DebarmentsToLiftAfterPayment, which >allows libraries to define rules for removing debarments after paying fines. >The system preference uses YAML and is defined as follows: > >Debarment with this comments will be removed: > outstanding: 5 > >Which means that if a Patron has a debarment "Debarment with this comment will >be removed", and he pays his fines and charges until his outstanding fees are >equal or less than 5.00, this debarment will be lifted. The parameter outstanding >is optional - if not given, the debarment will be lifted until Patron has paid >all of his outstanding fees (in other words, equal to "outstanding: 0"). > >To test: >1. Set a debarment to a Patron >2. Set a fine for Patron >3. Define rule(s) for removing debarment(s) in system preference > DebarmentsToLiftAfterPayment >4. Pay the fine you set in step 2 >5. Note that the debarment is now lifted >--- > Koha/Account.pm | 3 + > Koha/Patron/Debarments.pm | 65 +++++++++++++++++++ > ...any_borrower_debarments_after_a_payment.pl | 17 +++++ > installer/data/mysql/sysprefs.sql | 1 + > .../en/modules/admin/preferences/patrons.pref | 11 ++++ > t/db_dependent/Patron/Borrower_Debarments.t | 23 ++++++- > 6 files changed, 119 insertions(+), 1 deletion(-) > create mode 100644 installer/data/mysql/atomicupdate/Bug_16223_-_Automatically_remove_any_borrower_debarments_after_a_payment.pl > >diff --git a/Koha/Account.pm b/Koha/Account.pm >index de251c52da..059316a973 100644 >--- a/Koha/Account.pm >+++ b/Koha/Account.pm >@@ -37,6 +37,7 @@ use Koha::Account::DebitTypes; > use Koha::DateUtils qw( dt_from_string ); > use Koha::Exceptions; > use Koha::Exceptions::Account; >+use Koha::Patron::Debarments; > > =head1 NAME > >@@ -288,6 +289,8 @@ sub pay { > } > ); > >+ Koha::Patron::Debarments::DelDebarmentsAfterPayment({ borrowernumber => $self->{patron_id} }); >+ > if ( C4::Context->preference("FinesLog") ) { > logaction( > "FINES", 'CREATE', >diff --git a/Koha/Patron/Debarments.pm b/Koha/Patron/Debarments.pm >index 9fc2724b55..dff813b773 100644 >--- a/Koha/Patron/Debarments.pm >+++ b/Koha/Patron/Debarments.pm >@@ -20,7 +20,11 @@ package Koha::Patron::Debarments; > use Modern::Perl; > > use C4::Context; >+use C4::Members; >+use Koha::Patrons; >+use Koha::Account::Lines; > >+use YAML::XS; > use parent qw( Exporter ); > > our @EXPORT = qw( >@@ -33,6 +37,7 @@ our @EXPORT = qw( > AddUniqueDebarment > DelUniqueDebarment > >+ DelDebarmentsAfterPayment > ); > > =head1 Koha::Patron::Debarments >@@ -245,6 +250,66 @@ sub DelUniqueDebarment { > return DelDebarment( $debarment->{'borrower_debarment_id'} ); > } > >+=head2 DelDebarmentsAfterPayment >+ >+my $success = DelDebarmentsAfterPayment({ >+ borrowernumber => $borrowernumber, >+}); >+ >+Deletes any debarments from Borrower by following the rules >+defined in system preference DebarmentsToLiftAfterPayment >+ >+Debarments are defined in the system preference by comment. >+ >+=cut >+ >+sub DelDebarmentsAfterPayment { >+ my ($params) = @_; >+ >+ my $borrowernumber = $params->{'borrowernumber'}; >+ return unless ( $borrowernumber ); >+ >+ my $debarments = GetDebarments( { borrowernumber => $borrowernumber } ); >+ return unless ( $debarments ); >+ >+ my $liftDebarmentRules = C4::Context->preference("DebarmentsToLiftAfterPayment"); >+ return unless ( $liftDebarmentRules ); >+ >+ my $borrower = Koha::Patrons->find( $borrowernumber ); >+ return unless ( $borrower ); >+ >+ $liftDebarmentRules = YAML::XS::Load( >+ Encode::encode( >+ 'UTF-8', >+ $liftDebarmentRules, >+ Encode::FB_CROAK >+ )); >+ >+ my $lines = Koha::Account::Lines->search({ borrowernumber => $borrowernumber }); >+ 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'}); >+ } >+ } >+ else { >+ if ($total_due <= $liftDebarmentRules->{$debarment->{'comment'}}->{'outstanding'}) { >+ DelDebarment($debarment->{'borrower_debarment_id'}); >+ } >+ } >+ } >+ } >+} >+ > =head2 _UpdateBorrowerDebarmentFlags > > my $success = _UpdateBorrowerDebarmentFlags( $borrowernumber ); >diff --git a/installer/data/mysql/atomicupdate/Bug_16223_-_Automatically_remove_any_borrower_debarments_after_a_payment.pl b/installer/data/mysql/atomicupdate/Bug_16223_-_Automatically_remove_any_borrower_debarments_after_a_payment.pl >new file mode 100644 >index 0000000000..63f18a7d8b >--- /dev/null >+++ b/installer/data/mysql/atomicupdate/Bug_16223_-_Automatically_remove_any_borrower_debarments_after_a_payment.pl >@@ -0,0 +1,17 @@ >+#! /usr/bin/perl >+ >+use strict; >+use warnings; >+use C4::Context; >+use Koha::AtomicUpdater; >+ >+my $dbh = C4::Context->dbh; >+my $atomicUpdater = Koha::AtomicUpdater->new(); >+ >+unless($atomicUpdater->find('Bug16223')) { >+ # Add system preference >+ $dbh->do("INSERT INTO systempreferences (variable, value, options, explanation, type) >+ VALUES ('DebarmentsToLiftAfterPayment', '', '', 'Lift these debarments after Borrower has paid his/her fees', 'textarea')"); >+ >+ print "Upgrade done (Bug 16623: Automatically remove any borrower debarments after a payment)\n"; >+} >diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql >index cc4d797471..dcd70c33ec 100644 >--- a/installer/data/mysql/sysprefs.sql >+++ b/installer/data/mysql/sysprefs.sql >@@ -140,6 +140,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` > ('CustomCoverImages','0',NULL,'If enabled, the custom cover images will be displayed in the staff client. CustomCoverImagesURL must be defined.','YesNo'), > ('CustomCoverImagesURL','',NULL,'Define an URL serving book cover images, using the following patterns: %issn%, %isbn%, FIXME ADD MORE (use it with CustomCoverImages and/or OPACCustomCoverImages)','free'), > ('dateformat','us','metric|us|iso|dmydot','Define global date format (us mm/dd/yyyy, metric dd/mm/yyy, ISO yyyy-mm-dd, dmydot dd.mm.yyyy)','Choice'), >+('DebarmentsToLiftAfterPayment', '', '', 'Lift these debarments after Borrower has paid his/her fees', 'textarea'), > ('DebugLevel','2','0|1|2','Define the level of debugging information sent to the browser when errors are encountered (set to 0 in production). 0=none, 1=some, 2=most','Choice'), > ('decreaseLoanHighHolds',NULL,'','Decreases the loan period for items with number of holds above the threshold specified in decreaseLoanHighHoldsValue','YesNo'), > ('decreaseLoanHighHoldsControl', 'static', 'static|dynamic', "Chooses between static and dynamic high holds checking", 'Choice'), >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 b9a0ee6261..195d3ce9dc 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 >@@ -85,6 +85,17 @@ Patrons: > yes: Allow patrons > no: Allow only staff > - "to allow/disallow auto renewal for account. If allowed a patron will be able to update their own account to allow/disallow auto renewals" >+ - >+ - pref: DebarmentsToLiftAfterPayment >+ type: textarea >+ class: code >+ - Lift these debarments after Borrower has paid his/her fees >+ - "<p>Example, debarment is lifted after all fees are paid:</p>" >+ - "<pre>Debarment message:</pre> >+ <pre> outstanding: 0</pre>" >+ - "<p>Example, debarment is lifted after payment with outstanding fees less or equal than 5:</p>" >+ - "<pre>Another debarment:</pre> >+ <pre> outstanding: 5.00</pre>" > Membership expiry: > - > - When renewing borrowers, base the new expiry date on >diff --git a/t/db_dependent/Patron/Borrower_Debarments.t b/t/db_dependent/Patron/Borrower_Debarments.t >index 144de3479e..b6ae4d7c61 100755 >--- a/t/db_dependent/Patron/Borrower_Debarments.t >+++ b/t/db_dependent/Patron/Borrower_Debarments.t >@@ -8,7 +8,7 @@ use Koha::Patrons; > > use t::lib::TestBuilder; > >-use Test::More tests => 31; >+use Test::More tests => 33; > > use_ok('Koha::Patron::Debarments'); > >@@ -161,3 +161,24 @@ is( Koha::Patrons->find( $borrowernumber )->is_debarred, undef, 'A patron withou > > $dbh->do(q|UPDATE borrowers SET debarred = '9999-12-31'|); # Note: Change this test before the first of January 10000! > is( Koha::Patrons->find( $borrowernumber )->is_debarred, '9999-12-31', 'A patron with a debarred date in the future is debarred' ); >+ >+my $debarmentsRulesPref = C4::Context->preference("DebarmentsToLiftAfterPayment"); >+C4::Context->set_preference("DebarmentsToLiftAfterPayment", "Test debarment:\n outstanding: 0\nTest debarment 2:"); >+ >+AddDebarment({ >+ borrowernumber => $borrowernumber, >+ comment => 'Test debarment', >+}); >+AddDebarment({ >+ borrowernumber => $borrowernumber, >+ comment => 'Test debarment 2', >+}); >+ >+$debarments = GetDebarments({ borrowernumber => $borrowernumber }); >+is( @$debarments, 2, "GetDebarments returns 2 debarments before payment" ); >+ >+DelDebarmentsAfterPayment({ borrowernumber => $borrowernumber }); >+C4::Context->set_preference("DebarmentsToLiftAfterPayment", $debarmentsRulesPref); >+ >+$debarments = GetDebarments({ borrowernumber => $borrowernumber }); >+is( @$debarments, 0, "GetDebarments returns 0 debarments after payment" ); >\ No newline at end of file >-- >2.17.1 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 16223
:
50078
|
50084
|
99697
|
99698
|
104399
|
104400
|
114272
|
114273
|
118526
|
118572
|
118574
|
118575
|
122768
|
122769
|
127252
|
128005
|
132284
|
132285
|
132286
|
132287
|
143388
|
143389
|
143390
|
143462
|
143670
|
143671
|
143672
|
143688
|
143689
|
143690
|
143765
|
143766
|
143767
|
143768
|
143769
|
143770
|
143936
|
146051
|
146052
|
146053
|
146054
|
146055
|
146056
|
146057
|
148307
|
148308
|
148309
|
148310
|
148311
|
148312
|
148313
|
150024
|
150025
|
150026
|
150027
|
150028
|
150029
|
153024
|
153025
|
153026
|
153027
|
153028
|
153029
|
155644
|
155645
|
155646
|
155647
|
155648
|
155649
|
155650
|
156841
|
156842
|
156843
|
156844
|
156845
|
156846
|
156847
|
156848
|
156849
|
156850