View | Details | Raw Unified | Return to bug 16223
Collapse All | Expand All

(-)a/Koha/Account.pm (+3 lines)
Lines 37-42 use Koha::Account::DebitTypes; Link Here
37
use Koha::DateUtils qw( dt_from_string );
37
use Koha::DateUtils qw( dt_from_string );
38
use Koha::Exceptions;
38
use Koha::Exceptions;
39
use Koha::Exceptions::Account;
39
use Koha::Exceptions::Account;
40
use Koha::Patron::Debarments;
40
41
41
=head1 NAME
42
=head1 NAME
42
43
Lines 288-293 sub pay { Link Here
288
        }
289
        }
289
    );
290
    );
290
291
292
    Koha::Patron::Debarments::DelDebarmentsAfterPayment({ borrowernumber => $self->{patron_id} });
293
291
    if ( C4::Context->preference("FinesLog") ) {
294
    if ( C4::Context->preference("FinesLog") ) {
292
        logaction(
295
        logaction(
293
            "FINES", 'CREATE',
296
            "FINES", 'CREATE',
(-)a/Koha/Patron/Debarments.pm (+65 lines)
Lines 20-26 package Koha::Patron::Debarments; Link Here
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use C4::Context;
22
use C4::Context;
23
use C4::Members;
24
use Koha::Patrons;
25
use Koha::Account::Lines;
23
26
27
use YAML::XS;
24
use parent qw( Exporter );
28
use parent qw( Exporter );
25
29
26
our @EXPORT = qw(
30
our @EXPORT = qw(
Lines 33-38 our @EXPORT = qw( Link Here
33
  AddUniqueDebarment
37
  AddUniqueDebarment
34
  DelUniqueDebarment
38
  DelUniqueDebarment
35
39
40
  DelDebarmentsAfterPayment
36
);
41
);
37
42
38
=head1 Koha::Patron::Debarments
43
=head1 Koha::Patron::Debarments
Lines 282-287 sub UpdateBorrowerDebarmentFlags { Link Here
282
    return $dbh->do( "UPDATE borrowers SET debarred = ?, debarredcomment = ? WHERE borrowernumber = ?", {}, ( $expiration, $comment, $borrowernumber ) );
287
    return $dbh->do( "UPDATE borrowers SET debarred = ?, debarredcomment = ? WHERE borrowernumber = ?", {}, ( $expiration, $comment, $borrowernumber ) );
283
}
288
}
284
289
290
=head2 DelDebarmentsAfterPayment
291
292
my $success = DelDebarmentsAfterPayment({
293
    borrowernumber => $borrowernumber,
294
});
295
296
Deletes any debarments from Borrower by following the rules
297
defined in system preference DebarmentsToLiftAfterPayment
298
299
Debarments are defined in the system preference by comment.
300
301
=cut
302
303
sub DelDebarmentsAfterPayment {
304
    my ($params) = @_;
305
306
    my $borrowernumber = $params->{'borrowernumber'};
307
    return unless ( $borrowernumber );
308
309
    my $debarments = GetDebarments( { borrowernumber => $borrowernumber } );
310
    return unless ( $debarments );
311
312
    my $liftDebarmentRules = C4::Context->preference("DebarmentsToLiftAfterPayment");
313
    return unless ( $liftDebarmentRules );
314
315
    my $borrower = Koha::Patrons->find( $borrowernumber );
316
    return unless ( $borrower );
317
318
    $liftDebarmentRules = YAML::XS::Load(
319
                            Encode::encode(
320
                                'UTF-8',
321
                                $liftDebarmentRules,
322
                                Encode::FB_CROAK
323
    ));
324
325
    my $lines = Koha::Account::Lines->search({ borrowernumber  => $borrowernumber });
326
    my $total_due = $lines->total_outstanding;
327
328
    foreach my $debarment (@{ $debarments }){
329
        if (exists $liftDebarmentRules->{$debarment->{'comment'}}) {
330
            # Delete debarment IF:
331
            # 1. there is no maximum outstanding fines defined for the liftDebarmentRule
332
            #    and there is no outstanding fines.
333
            # 2. there is a maximum outstanding fines amount defined
334
            #    and total_due is smaller or equal than the defined maximum outstanding amount
335
            # Otherwise, do not lift the debarment.
336
            if (not defined $liftDebarmentRules->{$debarment->{'comment'}}->{'outstanding'}){
337
                if ($total_due <= 0) {
338
                    DelDebarment($debarment->{'borrower_debarment_id'});
339
                }
340
            }
341
            else {
342
                if ($total_due <= $liftDebarmentRules->{$debarment->{'comment'}}->{'outstanding'}) {
343
                    DelDebarment($debarment->{'borrower_debarment_id'});
344
                }
345
            }
346
        }
347
    }
348
}
349
285
=head2 _GetBorrowernumberByDebarmentId
350
=head2 _GetBorrowernumberByDebarmentId
286
351
287
my $borrowernumber = _GetBorrowernumberByDebarmentId( $borrower_debarment_id );
352
my $borrowernumber = _GetBorrowernumberByDebarmentId( $borrower_debarment_id );
(-)a/installer/data/mysql/atomicupdate/Bug_16223-Automatically_remove_any_borrower_debarments_after_a_payment.perl (+10 lines)
Line 0 Link Here
1
$DBversion = 'XXX'; # will be replaced by the RM
2
if( CheckVersion( $DBversion ) ) {
3
    # you can use $dbh here like:
4
    # $dbh->do( "ALTER TABLE biblio ADD COLUMN badtaste int" );
5
6
    $dbh->do("INSERT INTO systempreferences (variable, value, options, explanation, type) VALUES ('DebarmentsToLiftAfterPayment', '', '', 'Lift these debarments after Borrower has paid his/her fees', 'textarea')");
7
8
    # Always end with this (adjust the bug info)
9
    NewVersion( $DBversion, 16223, "Automatically remove any borrower debarments after a payment");
10
}
(-)a/installer/data/mysql/mandatory/sysprefs.sql (+1 lines)
Lines 146-151 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
146
('CustomCoverImages','0',NULL,'If enabled, the custom cover images will be displayed in the staff interface. CustomCoverImagesURL must be defined.','YesNo'),
146
('CustomCoverImages','0',NULL,'If enabled, the custom cover images will be displayed in the staff interface. CustomCoverImagesURL must be defined.','YesNo'),
147
('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'),
147
('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'),
148
('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'),
148
('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'),
149
('DebarmentsToLiftAfterPayment', '', '', 'Lift these debarments after Borrower has paid his/her fees', 'textarea'),
149
('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'),
150
('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'),
150
('decreaseLoanHighHolds','0','','Decreases the loan period for items with number of holds above the threshold specified in decreaseLoanHighHoldsValue','YesNo'),
151
('decreaseLoanHighHolds','0','','Decreases the loan period for items with number of holds above the threshold specified in decreaseLoanHighHoldsValue','YesNo'),
151
('decreaseLoanHighHoldsControl', 'static', 'static|dynamic', "Chooses between static and dynamic high holds checking", 'Choice'),
152
('decreaseLoanHighHoldsControl', 'static', 'static|dynamic', "Chooses between static and dynamic high holds checking", 'Choice'),
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref (+11 lines)
Lines 100-105 Patrons: Link Here
100
               1: Allow patrons
100
               1: Allow patrons
101
               0: Allow only staff
101
               0: Allow only staff
102
         - "to allow/disallow auto-renewal for account. If allowed a patron will be able to update their own account to allow/disallow auto-renewal."
102
         - "to allow/disallow auto-renewal for account. If allowed a patron will be able to update their own account to allow/disallow auto-renewal."
103
     -
104
         - pref: DebarmentsToLiftAfterPayment
105
           type: textarea
106
           class: code
107
         - Lift these debarments after Borrower has paid his/her fees
108
         - "<p>Example, debarment is lifted after all fees are paid:</p>"
109
         - "<pre>Debarment message:</pre>
110
            <pre>  outstanding: 0</pre>"
111
         - "<p>Example, debarment is lifted after payment with outstanding fees less or equal than 5:</p>"
112
         - "<pre>Another debarment:</pre>
113
            <pre>  outstanding: 5.00</pre>"
103
    Membership expiry:
114
    Membership expiry:
104
     -
115
     -
105
         - When renewing borrowers, base the new expiry date on
116
         - When renewing borrowers, base the new expiry date on
(-)a/t/db_dependent/Patron/Borrower_Debarments.t (-2 / +23 lines)
Lines 8-14 use Koha::Patrons; Link Here
8
8
9
use t::lib::TestBuilder;
9
use t::lib::TestBuilder;
10
10
11
use Test::More tests => 33;
11
use Test::More tests => 35;
12
12
13
use_ok('Koha::Patron::Debarments');
13
use_ok('Koha::Patron::Debarments');
14
14
Lines 194-196 is( Koha::Patrons->find($borrowernumber3)->debarred, Link Here
194
    $debarreddate2, 'Koha::Patron->merge_with() transfers well debarred' );
194
    $debarreddate2, 'Koha::Patron->merge_with() transfers well debarred' );
195
is( Koha::Patrons->find($borrowernumber3)->debarredcomment,
195
is( Koha::Patrons->find($borrowernumber3)->debarredcomment,
196
    $debarredcomment2, 'Koha::Patron->merge_with() transfers well debarredcomment' );
196
    $debarredcomment2, 'Koha::Patron->merge_with() transfers well debarredcomment' );
197
- 
197
198
# Test removing debartments after payment
199
my $debarmentsRulesPref = C4::Context->preference("DebarmentsToLiftAfterPayment");
200
C4::Context->set_preference("DebarmentsToLiftAfterPayment", "Test debarment:\n  outstanding: 0\nTest debarment 2:");
201
202
AddDebarment({
203
    borrowernumber => $borrowernumber,
204
    comment => 'Test debarment',
205
});
206
AddDebarment({
207
    borrowernumber => $borrowernumber,
208
    comment => 'Test debarment 2',
209
});
210
211
$debarments = GetDebarments({ borrowernumber => $borrowernumber });
212
is( @$debarments, 2, "GetDebarments returns 2 debarments before payment" );
213
214
DelDebarmentsAfterPayment({ borrowernumber => $borrowernumber });
215
C4::Context->set_preference("DebarmentsToLiftAfterPayment", $debarmentsRulesPref);
216
217
$debarments = GetDebarments({ borrowernumber => $borrowernumber });
218
is( @$debarments, 0, "GetDebarments returns 0 debarments after payment" );

Return to bug 16223