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

(-)a/Koha/Account.pm (+3 lines)
Lines 36-41 use Koha::Account::DebitTypes; Link Here
36
use Koha::Exceptions;
36
use Koha::Exceptions;
37
use Koha::Exceptions::Account;
37
use Koha::Exceptions::Account;
38
use Koha::Plugins;
38
use Koha::Plugins;
39
use Koha::Patron::Debarments;
39
40
40
=head1 NAME
41
=head1 NAME
41
42
Lines 102-107 sub pay { Link Here
102
        }
103
        }
103
    );
104
    );
104
105
106
    Koha::Patron::Debarments::del_restrictions_after_payment({ borrowernumber => $self->{patron_id} });
107
105
    # NOTE: Pay historically always applied as much credit as it could to all
108
    # NOTE: Pay historically always applied as much credit as it could to all
106
    # existing outstanding debits, whether passed specific debits or otherwise.
109
    # existing outstanding debits, whether passed specific debits or otherwise.
107
    if ( $payment->amountoutstanding ) {
110
    if ( $payment->amountoutstanding ) {
(-)a/Koha/Patron/Debarments.pm (+38 lines)
Lines 21-26 use Modern::Perl; Link Here
21
21
22
use C4::Context;
22
use C4::Context;
23
23
24
use Koha::Patron::Restriction::Types;
25
24
our ( @ISA, @EXPORT_OK );
26
our ( @ISA, @EXPORT_OK );
25
27
26
BEGIN {
28
BEGIN {
Lines 286-291 sub UpdateBorrowerDebarmentFlags { Link Here
286
    return $dbh->do( "UPDATE borrowers SET debarred = ?, debarredcomment = ? WHERE borrowernumber = ?", {}, ( $expiration, $comment, $borrowernumber ) );
288
    return $dbh->do( "UPDATE borrowers SET debarred = ?, debarredcomment = ? WHERE borrowernumber = ?", {}, ( $expiration, $comment, $borrowernumber ) );
287
}
289
}
288
290
291
=head2 del_restrictions_after_payment
292
293
my $success = del_restrictions_after_payment({
294
    borrowernumber => $borrowernumber,
295
});
296
297
Deletes any restrictions from patron by following the rules
298
defined in "Patron restrictions".
299
300
=cut
301
302
sub del_restrictions_after_payment {
303
    my ($params) = @_;
304
305
    my $borrowernumber = $params->{'borrowernumber'};
306
    return unless ( $borrowernumber );
307
308
    my $patron_restrictions = GetDebarments( { borrowernumber => $borrowernumber } );
309
    return unless ( $patron_restrictions );
310
311
    my $patron = Koha::Patrons->find( $borrowernumber );
312
    return unless ( $patron );
313
314
    my $lines = Koha::Account::Lines->search({ borrowernumber  => $borrowernumber });
315
    my $total_due = $lines->total_outstanding;
316
317
    foreach my $patron_restriction (@{ $patron_restrictions }){
318
        my $restriction = Koha::Patron::Restriction::Types->find({
319
            code => $patron_restriction->{type}
320
        });
321
        if($restriction->lift_after_payment && $total_due <= $restriction->fee_limit){
322
            DelDebarment($patron_restriction->{'borrower_debarment_id'});
323
        }
324
    }
325
}
326
289
=head2 _GetBorrowernumberByDebarmentId
327
=head2 _GetBorrowernumberByDebarmentId
290
328
291
my $borrowernumber = _GetBorrowernumberByDebarmentId( $borrower_debarment_id );
329
my $borrowernumber = _GetBorrowernumberByDebarmentId( $borrower_debarment_id );
(-)a/admin/restrictions.pl (-2 / +8 lines)
Lines 54-59 if ( $op eq 'add_form') { Link Here
54
} elsif ( $op eq 'add_validate' ) {
54
} elsif ( $op eq 'add_validate' ) {
55
55
56
    my $display_text = $input->param('display_text');
56
    my $display_text = $input->param('display_text');
57
    my $lift_after_payment = $input->param('lift_after_payment');
58
    my $fee_limit = $input->param('fee_limit');
57
    my $is_a_modif = $input->param("is_a_modif");
59
    my $is_a_modif = $input->param("is_a_modif");
58
60
59
    if ($is_a_modif) {
61
    if ($is_a_modif) {
Lines 61-73 if ( $op eq 'add_form') { Link Here
61
        my $dupe = Koha::Patron::Restriction::Types->find({
63
        my $dupe = Koha::Patron::Restriction::Types->find({
62
            display_text => $display_text
64
            display_text => $display_text
63
        });
65
        });
64
        if ($dupe) {
66
        if ($dupe && $dupe->unblessed->{code} ne $code) {
65
            push @messages, {
67
            push @messages, {
66
                type => 'error', code => 'duplicate_display_text'
68
                type => 'error', code => 'duplicate_display_text'
67
            };
69
            };
68
        } else {
70
        } else {
69
            my $restriction = Koha::Patron::Restriction::Types->find($code);
71
            my $restriction = Koha::Patron::Restriction::Types->find($code);
70
            $restriction->display_text($display_text);
72
            $restriction->display_text($display_text);
73
            $restriction->lift_after_payment($lift_after_payment);
74
            $restriction->fee_limit($fee_limit);
71
            $restriction->store;
75
            $restriction->store;
72
            push @messages, { type => 'message', code => 'update_success' };
76
            push @messages, { type => 'message', code => 'update_success' };
73
        }
77
        }
Lines 81-87 if ( $op eq 'add_form') { Link Here
81
        } else {
85
        } else {
82
            my $restriction = Koha::Patron::Restriction::Type->new({
86
            my $restriction = Koha::Patron::Restriction::Type->new({
83
                code => $code,
87
                code => $code,
84
                display_text => $display_text
88
                display_text => $display_text,
89
                lift_after_payment => $lift_after_payment,
90
                fee_limit => $fee_limit
85
            });
91
            });
86
            $restriction->store;
92
            $restriction->store;
87
            push @messages, { type => 'message', code => 'add_success' };
93
            push @messages, { type => 'message', code => 'add_success' };
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/restrictions.tt (+34 lines)
Lines 113-118 Link Here
113
                        <input type="text" value="[% restriction.display_text | html %]" name="display_text" id="display_text" size="50" maxlength="50" class="required" required="required" />
113
                        <input type="text" value="[% restriction.display_text | html %]" name="display_text" id="display_text" size="50" maxlength="50" class="required" required="required" />
114
                        <span class="required">Required</span>
114
                        <span class="required">Required</span>
115
                    </li>
115
                    </li>
116
                    <li>
117
                        <label for="lift_after_payment" class="required">Lift after payment: </label>
118
                        <select type="text" name="lift_after_payment" id="lift_after_payment" class="required" required="required" />
119
                            <option value="1" selected="selected">Yes</option>
120
                            <option value="0">No</option>
121
                        </select>
122
                        <span class="required">Required</span>
123
                    </li>
124
                    <li>
125
                        <label for="fee_limit" class="required">Fee limit: </label>
126
                        <input type="text" value="[% restriction.fee_limit | html %]" inputmode="decimal" pattern="^\d+(\.\d{2})?$" min="0" name="fee_limit" id="fee_limit" class="required" required="required" />
127
                        <span class="required">Required</span>
128
                    </li>
116
                [% ELSE %]
129
                [% ELSE %]
117
                    <li>
130
                    <li>
118
                        <label for="code" class="required">Code: </label>
131
                        <label for="code" class="required">Code: </label>
Lines 124-129 Link Here
124
                        <input type="text" name="display_text" id="display_text" size="50" maxlength="50" class="required" required="required" />
137
                        <input type="text" name="display_text" id="display_text" size="50" maxlength="50" class="required" required="required" />
125
                        <span class="required">Required</span>
138
                        <span class="required">Required</span>
126
                    </li>
139
                    </li>
140
                    <li>
141
                        <label for="lift_after_payment" class="required">Lift after payment: </label>
142
                        <select type="text" name="lift_after_payment" id="lift_after_payment" class="required" required="required" />
143
                            <option value="1" selected="selected">Yes</option>
144
                            <option value="0">No</option>
145
                        </select>
146
                        <span class="required">Required</span>
147
                    </li>
148
                    <li>
149
                        <label for="fee_limit" class="required">Fee limit: </label>
150
                        <input type="text" inputmode="decimal" pattern="^\d+(\.\d{2})?$" min="0" name="fee_limit" id="fee_limit" class="required" required="required" />
151
                        <span class="required">Required</span>
152
                    </li>
127
                [% END %]
153
                [% END %]
128
            </ol>
154
            </ol>
129
        </fieldset>
155
        </fieldset>
Lines 171-176 Link Here
171
                    <th scope="col">Code</th>
197
                    <th scope="col">Code</th>
172
                    <th scope="col">Label</th>
198
                    <th scope="col">Label</th>
173
                    <th scope="col">Default</th>
199
                    <th scope="col">Default</th>
200
                    <th scope="col">Lift after payment?</th>
201
                    <th scope="col">Fee limit</th>
174
                    <th scope="col">Actions</th>
202
                    <th scope="col">Actions</th>
175
                </tr>
203
                </tr>
176
            </thead>
204
            </thead>
Lines 186-191 Link Here
186
                        <td>
214
                        <td>
187
                            [% IF restriction.is_default %]Yes[% END %]
215
                            [% IF restriction.is_default %]Yes[% END %]
188
                        </td>
216
                        </td>
217
                        <td>
218
                            [% IF restriction.lift_after_payment %]Yes[% END %]
219
                        </td>
220
                        <td>
221
                            [% IF restriction.fee_limit %][% restriction.fee_limit %][% END %]
222
                        </td>
189
                        <td class="actions">
223
                        <td class="actions">
190
                            <a class="btn btn-default btn-xs" href="/cgi-bin/koha/admin/restrictions.pl?op=add_form&amp;code=[% restriction.code | uri %]"><i class="fa fa-pencil"></i> Edit</a>
224
                            <a class="btn btn-default btn-xs" href="/cgi-bin/koha/admin/restrictions.pl?op=add_form&amp;code=[% restriction.code | uri %]"><i class="fa fa-pencil"></i> Edit</a>
191
                            [% IF !restriction.is_system && !restriction.is_default %]
225
                            [% IF !restriction.is_system && !restriction.is_default %]
(-)a/koha-tmpl/intranet-tmpl/prog/js/restrictiontypes.js (-1 / +2 lines)
Lines 9-15 jQuery.validator.addMethod( "restrictionDisplayText", function(value){ Link Here
9
    var ex = Object.values(existing).map(function(el) {
9
    var ex = Object.values(existing).map(function(el) {
10
        return el.toLowerCase();
10
        return el.toLowerCase();
11
    });
11
    });
12
    return (value.length > 0 && ex.indexOf(value.toLowerCase()) > -1) ?
12
    var code = $('input[name="code"]').val();
13
    return (value.length > 0 && ex.indexOf(value.toLowerCase()) > -1) && existing[code] != value ?
13
        false :
14
        false :
14
        true;
15
        true;
15
}, MSG_DUPLICATE_DISPLAY_TEXT);
16
}, MSG_DUPLICATE_DISPLAY_TEXT);
(-)a/t/db_dependent/Patron/Borrower_Debarments.t (-2 / +75 lines)
Lines 5-14 use Modern::Perl; Link Here
5
use C4::Context;
5
use C4::Context;
6
use Koha::Database;
6
use Koha::Database;
7
use Koha::Patrons;
7
use Koha::Patrons;
8
use Koha::Account;
8
9
9
use t::lib::TestBuilder;
10
use t::lib::TestBuilder;
10
11
11
use Test::More tests => 33;
12
use Test::More tests => 37;
12
13
13
use_ok('Koha::Patron::Debarments');
14
use_ok('Koha::Patron::Debarments');
14
15
Lines 194-196 is( Koha::Patrons->find($borrowernumber3)->debarred, Link Here
194
    $debarreddate2, 'Koha::Patron->merge_with() transfers well debarred' );
195
    $debarreddate2, 'Koha::Patron->merge_with() transfers well debarred' );
195
is( Koha::Patrons->find($borrowernumber3)->debarredcomment,
196
is( Koha::Patrons->find($borrowernumber3)->debarredcomment,
196
    $debarredcomment2, 'Koha::Patron->merge_with() transfers well debarredcomment' );
197
    $debarredcomment2, 'Koha::Patron->merge_with() transfers well debarredcomment' );
197
- 
198
199
# Test removing debartments after payment
200
$builder->build(
201
    {
202
        source => 'RestrictionType',
203
        value  => {
204
            code               => 'TEST',
205
            display_text       => 'This is a test.',
206
            is_system          => 0,
207
            is_default         => 0,
208
            lift_after_payment => 1,
209
            fee_limit          => 5
210
        }
211
    }
212
);
213
214
$builder->build(
215
    {
216
        source => 'RestrictionType',
217
        value  => {
218
            code               => 'TEST2',
219
            display_text       => 'This too is a test.',
220
            is_system          => 0,
221
            is_default         => 0,
222
            lift_after_payment => 1,
223
            fee_limit          => 0
224
        }
225
    }
226
);
227
228
my $borrowernumber4 = Koha::Patron->new(
229
    {
230
        firstname    => 'First',
231
        surname      => 'Sur',
232
        categorycode => $patron_category->{categorycode},
233
        branchcode   => $library->{branchcode},
234
    }
235
)->store->borrowernumber;
236
237
my $account = Koha::Account->new({ patron_id => $borrowernumber4 });
238
my $line1 = $account->add_debit({ type => 'ACCOUNT', amount => 10, interface => 'commandline' });
239
240
Koha::Patron::Debarments::AddDebarment(
241
    {
242
        borrowernumber => $borrowernumber4,
243
        expiration     => '9999-06-10',
244
        type           => 'TEST',
245
        comment        => 'Test delete'
246
    }
247
);
248
249
Koha::Patron::Debarments::AddDebarment(
250
    {
251
        borrowernumber => $borrowernumber4,
252
        expiration     => '9999-10-10',
253
        type           => 'TEST2',
254
        comment        => 'Test delete again',
255
    }
256
);
257
258
$debarments = Koha::Patron::Debarments::GetDebarments({ borrowernumber => $borrowernumber4 });
259
260
is( @$debarments, 2, "GetDebarments returns 2 debarments before payment" );
261
262
$account->pay({amount => 5});
263
264
$debarments = Koha::Patron::Debarments::GetDebarments({ borrowernumber => $borrowernumber4 });
265
is( @$debarments, 1, "GetDebarments returns 1 debarment after paying half of the fee" );
266
is( @$debarments[0]->{type}, "TEST2", "Debarment left has type value 'TEST2'" );
267
268
$account->pay({amount => 5});
269
$debarments = Koha::Patron::Debarments::GetDebarments({ borrowernumber => $borrowernumber4 });
270
is( @$debarments, 0, "GetDebarments returns 0 debarments after paying all fees" );

Return to bug 16223