@@ -, +, @@ --- Koha/Account.pm | 3 + Koha/Patron/Debarments.pm | 38 ++++++++++ admin/restrictions.pl | 10 ++- .../prog/en/modules/admin/restrictions.tt | 34 +++++++++ .../intranet-tmpl/prog/js/restrictiontypes.js | 3 +- t/db_dependent/Patron/Borrower_Debarments.t | 76 ++++++++++++++++++- 6 files changed, 160 insertions(+), 4 deletions(-) --- a/Koha/Account.pm +++ a/Koha/Account.pm @@ -36,6 +36,7 @@ use Koha::Account::DebitTypes; use Koha::Exceptions; use Koha::Exceptions::Account; use Koha::Plugins; +use Koha::Patron::Debarments; =head1 NAME @@ -102,6 +103,8 @@ sub pay { } ); + Koha::Patron::Debarments::del_restrictions_after_payment({ borrowernumber => $self->{patron_id} }); + # NOTE: Pay historically always applied as much credit as it could to all # existing outstanding debits, whether passed specific debits or otherwise. if ( $payment->amountoutstanding ) { --- a/Koha/Patron/Debarments.pm +++ a/Koha/Patron/Debarments.pm @@ -21,6 +21,8 @@ use Modern::Perl; use C4::Context; +use Koha::Patron::Restriction::Types; + our ( @ISA, @EXPORT_OK ); BEGIN { @@ -270,6 +272,42 @@ sub UpdateBorrowerDebarmentFlags { return $dbh->do( "UPDATE borrowers SET debarred = ?, debarredcomment = ? WHERE borrowernumber = ?", {}, ( $expiration, $comment, $borrowernumber ) ); } +=head2 del_restrictions_after_payment + +my $success = del_restrictions_after_payment({ + borrowernumber => $borrowernumber, +}); + +Deletes any restrictions from patron by following the rules +defined in "Patron restrictions". + +=cut + +sub del_restrictions_after_payment { + my ($params) = @_; + + my $borrowernumber = $params->{'borrowernumber'}; + return unless ( $borrowernumber ); + + my $patron_restrictions = GetDebarments( { borrowernumber => $borrowernumber } ); + return unless ( $patron_restrictions ); + + my $patron = Koha::Patrons->find( $borrowernumber ); + return unless ( $patron ); + + my $lines = Koha::Account::Lines->search({ borrowernumber => $borrowernumber }); + my $total_due = $lines->total_outstanding; + + foreach my $patron_restriction (@{ $patron_restrictions }){ + my $restriction = Koha::Patron::Restriction::Types->find({ + code => $patron_restriction->{type} + }); + if($restriction->lift_after_payment && $total_due <= $restriction->fee_limit){ + DelDebarment($patron_restriction->{'borrower_debarment_id'}); + } + } +} + =head2 _GetBorrowernumberByDebarmentId my $borrowernumber = _GetBorrowernumberByDebarmentId( $borrower_debarment_id ); --- a/admin/restrictions.pl +++ a/admin/restrictions.pl @@ -54,6 +54,8 @@ if ( $op eq 'add_form') { } elsif ( $op eq 'add_validate' ) { my $display_text = $input->param('display_text'); + my $lift_after_payment = $input->param('lift_after_payment'); + my $fee_limit = $input->param('fee_limit'); my $is_a_modif = $input->param("is_a_modif"); if ($is_a_modif) { @@ -61,13 +63,15 @@ if ( $op eq 'add_form') { my $dupe = Koha::Patron::Restriction::Types->find({ display_text => $display_text }); - if ($dupe) { + if ($dupe && $dupe->unblessed->{code} ne $code) { push @messages, { type => 'error', code => 'duplicate_display_text' }; } else { my $restriction = Koha::Patron::Restriction::Types->find($code); $restriction->display_text($display_text); + $restriction->lift_after_payment($lift_after_payment); + $restriction->fee_limit($fee_limit); $restriction->store; push @messages, { type => 'message', code => 'update_success' }; } @@ -81,7 +85,9 @@ if ( $op eq 'add_form') { } else { my $restriction = Koha::Patron::Restriction::Type->new({ code => $code, - display_text => $display_text + display_text => $display_text, + lift_after_payment => $lift_after_payment, + fee_limit => $fee_limit }); $restriction->store; push @messages, { type => 'message', code => 'add_success' }; --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/restrictions.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/restrictions.tt @@ -117,6 +117,19 @@ Required +