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

(-)a/Koha/Account.pm (+3 lines)
Lines 35-40 use Koha::Account::Offsets; Link Here
35
use Koha::Account::DebitTypes;
35
use Koha::Account::DebitTypes;
36
use Koha::Exceptions;
36
use Koha::Exceptions;
37
use Koha::Exceptions::Account;
37
use Koha::Exceptions::Account;
38
use Koha::Patron::Debarments;
38
39
39
=head1 NAME
40
=head1 NAME
40
41
Lines 101-106 sub pay { Link Here
101
        }
102
        }
102
    );
103
    );
103
104
105
    Koha::Patron::Debarments::DelDebarmentsAfterPayment({ borrowernumber => $self->{patron_id} });
106
104
    # NOTE: Pay historically always applied as much credit as it could to all
107
    # NOTE: Pay historically always applied as much credit as it could to all
105
    # existing outstanding debits, whether passed specific debits or otherwise.
108
    # existing outstanding debits, whether passed specific debits or otherwise.
106
    if ( $payment->amountoutstanding ) {
109
    if ( $payment->amountoutstanding ) {
(-)a/Koha/Patron/Debarments.pm (+65 lines)
Lines 20-25 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;
26
27
use YAML::XS;
23
28
24
our ( @ISA, @EXPORT_OK );
29
our ( @ISA, @EXPORT_OK );
25
30
Lines 286-291 sub UpdateBorrowerDebarmentFlags { Link Here
286
    return $dbh->do( "UPDATE borrowers SET debarred = ?, debarredcomment = ? WHERE borrowernumber = ?", {}, ( $expiration, $comment, $borrowernumber ) );
291
    return $dbh->do( "UPDATE borrowers SET debarred = ?, debarredcomment = ? WHERE borrowernumber = ?", {}, ( $expiration, $comment, $borrowernumber ) );
287
}
292
}
288
293
294
=head2 DelDebarmentsAfterPayment
295
296
my $success = DelDebarmentsAfterPayment({
297
    borrowernumber => $borrowernumber,
298
});
299
300
Deletes any debarments from Borrower by following the rules
301
defined in system preference DebarmentsToLiftAfterPayment
302
303
Debarments are defined in the system preference by comment.
304
305
=cut
306
307
sub DelDebarmentsAfterPayment {
308
    my ($params) = @_;
309
310
    my $borrowernumber = $params->{'borrowernumber'};
311
    return unless ( $borrowernumber );
312
313
    my $debarments = GetDebarments( { borrowernumber => $borrowernumber } );
314
    return unless ( $debarments );
315
316
    my $liftDebarmentRules = C4::Context->preference("DebarmentsToLiftAfterPayment");
317
    return unless ( $liftDebarmentRules );
318
319
    my $borrower = Koha::Patrons->find( $borrowernumber );
320
    return unless ( $borrower );
321
322
    $liftDebarmentRules = YAML::XS::Load(
323
                            Encode::encode(
324
                                'UTF-8',
325
                                $liftDebarmentRules,
326
                                Encode::FB_CROAK
327
    ));
328
329
    my $lines = Koha::Account::Lines->search({ borrowernumber  => $borrowernumber });
330
    my $total_due = $lines->total_outstanding;
331
332
    foreach my $debarment (@{ $debarments }){
333
        if (exists $liftDebarmentRules->{$debarment->{'comment'}}) {
334
            # Delete debarment IF:
335
            # 1. there is no maximum outstanding fines defined for the liftDebarmentRule
336
            #    and there is no outstanding fines.
337
            # 2. there is a maximum outstanding fines amount defined
338
            #    and total_due is smaller or equal than the defined maximum outstanding amount
339
            # Otherwise, do not lift the debarment.
340
            if (not defined $liftDebarmentRules->{$debarment->{'comment'}}->{'outstanding'}){
341
                if ($total_due <= 0) {
342
                    DelDebarment($debarment->{'borrower_debarment_id'});
343
                }
344
            }
345
            else {
346
                if ($total_due <= $liftDebarmentRules->{$debarment->{'comment'}}->{'outstanding'}) {
347
                    DelDebarment($debarment->{'borrower_debarment_id'});
348
                }
349
            }
350
        }
351
    }
352
}
353
289
=head2 _GetBorrowernumberByDebarmentId
354
=head2 _GetBorrowernumberByDebarmentId
290
355
291
my $borrowernumber = _GetBorrowernumberByDebarmentId( $borrower_debarment_id );
356
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 151-156 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
151
('CustomCoverImages','0',NULL,'If enabled, the custom cover images will be displayed in the staff interface. CustomCoverImagesURL must be defined.','YesNo'),
151
('CustomCoverImages','0',NULL,'If enabled, the custom cover images will be displayed in the staff interface. CustomCoverImagesURL must be defined.','YesNo'),
152
('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'),
152
('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'),
153
('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'),
153
('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'),
154
('DebarmentsToLiftAfterPayment', '', '', 'Lift these debarments after Borrower has paid his/her fees', 'textarea'),
154
('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'),
155
('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'),
155
('decreaseLoanHighHolds','0','','Decreases the loan period for items with number of holds above the threshold specified in decreaseLoanHighHoldsValue','YesNo'),
156
('decreaseLoanHighHolds','0','','Decreases the loan period for items with number of holds above the threshold specified in decreaseLoanHighHoldsValue','YesNo'),
156
('decreaseLoanHighHoldsControl', 'static', 'static|dynamic', "Chooses between static and dynamic high holds checking", 'Choice'),
157
('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 (-1 / +11 lines)
Lines 106-112 Patrons: Link Here
106
           class: integer
106
           class: integer
107
         - days. Leave empty to disable this behavior.
107
         - days. Leave empty to disable this behavior.
108
         - "<br><strong>NOTE:</strong> This system preference requires the misc/cronjobs/cleanup_database.pl cronjob. Ask your system administrator to schedule it."
108
         - "<br><strong>NOTE:</strong> This system preference requires the misc/cronjobs/cleanup_database.pl cronjob. Ask your system administrator to schedule it."
109
109
     -
110
         - pref: DebarmentsToLiftAfterPayment
111
           type: textarea
112
           class: code
113
         - Lift these debarments after Borrower has paid his/her fees
114
         - "<p>Example, debarment is lifted after all fees are paid:</p>"
115
         - "<pre>Debarment message:</pre>
116
            <pre>  outstanding: 0</pre>"
117
         - "<p>Example, debarment is lifted after payment with outstanding fees less or equal than 5:</p>"
118
         - "<pre>Another debarment:</pre>
119
            <pre>  outstanding: 5.00</pre>"
110
    Membership expiry:
120
    Membership expiry:
111
     -
121
     -
112
         - When renewing borrowers, base the new expiry date on
122
         - 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