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

(-)a/C4/Overdues.pm (-1 / +23 lines)
Lines 36-41 use Koha::DateUtils; Link Here
36
use Koha::Account::Lines;
36
use Koha::Account::Lines;
37
use Koha::Account::Offsets;
37
use Koha::Account::Offsets;
38
use Koha::Libraries;
38
use Koha::Libraries;
39
use Koha::Recalls;
39
40
40
use vars qw(@ISA @EXPORT);
41
use vars qw(@ISA @EXPORT);
41
42
Lines 243-248 sub CalcFine { Link Here
243
                'fine',
244
                'fine',
244
                'overduefinescap',
245
                'overduefinescap',
245
                'cap_fine_to_replacement_price',
246
                'cap_fine_to_replacement_price',
247
                'recall_overdue_fine',
246
            ]
248
            ]
247
        }
249
        }
248
    );
250
    );
Lines 262-268 sub CalcFine { Link Here
262
        # If chargeperiod_charge_at = 1, we charge a fine at the start of each charge period
264
        # If chargeperiod_charge_at = 1, we charge a fine at the start of each charge period
263
        # if chargeperiod_charge_at = 0, we charge at the end of each charge period
265
        # if chargeperiod_charge_at = 0, we charge at the end of each charge period
264
        $charge_periods = defined $issuing_rule->{chargeperiod_charge_at} && $issuing_rule->{chargeperiod_charge_at} == 1 ? ceil($charge_periods) : floor($charge_periods);
266
        $charge_periods = defined $issuing_rule->{chargeperiod_charge_at} && $issuing_rule->{chargeperiod_charge_at} == 1 ? ceil($charge_periods) : floor($charge_periods);
265
        $amount = $charge_periods * $issuing_rule->{fine};
267
268
        # check if item has been recalled. recall should have been marked Overdue by cronjob, so only look at overdue recalls
269
        # only charge using recall_overdue_fine if there is an item-level recall for this particular item, OR a biblio-level recall
270
        my @recalls = Koha::Recalls->search({ biblionumber => $item->{biblionumber}, old => undef, status => 'O' });
271
        my $bib_level_recall = 0;
272
        $bib_level_recall = 1 if scalar @recalls > 0;
273
        foreach my $recall ( @recalls ) {
274
            if ( $recall->item_level_recall and $recall->itemnumber == $item->{itemnumber} and $issuing_rule->{recall_overdue_fine} ) {
275
                $bib_level_recall = 0;
276
                $amount = $charge_periods * $issuing_rule->{recall_overdue_fine};
277
                last;
278
            }
279
        }
280
        if ( $bib_level_recall and $issuing_rule->{recall_overdue_fine} ) {
281
            # biblio-level recall
282
            $amount = $charge_periods * $issuing_rule->{recall_overdue_fine};
283
        }
284
        if ( scalar @recalls == 0 ) {
285
            # no recall, use normal fine amount
286
            $amount = $charge_periods * $issuing_rule->{fine};
287
        }
266
    } # else { # a zero (or null) chargeperiod or negative units_minus_grace value means no charge. }
288
    } # else { # a zero (or null) chargeperiod or negative units_minus_grace value means no charge. }
267
289
268
    $amount = $issuing_rule->{overduefinescap} if $issuing_rule->{overduefinescap} && $amount > $issuing_rule->{overduefinescap};
290
    $amount = $issuing_rule->{overduefinescap} if $issuing_rule->{overduefinescap} && $amount > $issuing_rule->{overduefinescap};
(-)a/misc/cronjobs/recalls/expire_recalls.pl (+68 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2020 Aleisha Amohia <aleisha@catalyst.net.nz>
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
BEGIN {
23
    # find Koha's Perl modules
24
    # test carefully before changing this
25
    use FindBin;
26
    eval { require "$FindBin::Bin/../kohalib.pl" };
27
}
28
29
# set overdue recalls as overdue. This includes:
30
# - recalls that have been requested and not fulfilled and have passed their expiration date
31
# - recalls that have been awaiting pickup for longer than the specified recall_shelf_time circulation rule, or the RecallsMaxPickUpDelay if circ rule is unset
32
33
use Koha::Script -cron;
34
use Koha::DateUtils;
35
use Koha::Recalls;
36
use C4::Log;
37
38
cronlogaction();
39
40
my @recalls = Koha::Recalls->search({ old => undef });
41
foreach my $recall (@recalls) {
42
    if ( ( $recall->requested or $recall->overdue ) and $recall->expirationdate and dt_from_string( $recall->expirationdate ) < dt_from_string() ){
43
        # recall is requested or overdue and has surpassed the specified expiration date
44
        $recall->set_expired({ interface => 'COMMANDLINE' });
45
    }
46
    if ( $recall->waiting ) {
47
        my $recall_shelf_time = Koha::CirculationRules->get_effective_rule({
48
            categorycode => $recall->patron->categorycode,
49
            itemtype => $recall->item->effective_itemtype,
50
            branchcode => $recall->branchcode,
51
            rule_name => 'recall_shelf_time',
52
        });
53
        my $waitingdate = dt_from_string( $recall->waitingdate );
54
        my $now = dt_from_string();
55
        my $days_waiting = $now->subtract_datetime( $waitingdate );
56
        if ( defined $recall_shelf_time and $recall_shelf_time->rule_value > 0 ) {
57
            if ( $days_waiting->days > $recall_shelf_time->rule_value ) {
58
                # recall has been awaiting pickup for longer than the circ rules allow
59
                $recall->set_expired({ interface => 'COMMANDLINE' });
60
            }
61
        } else {
62
            if ( $days_waiting->days > C4::Context->preference('RecallsMaxPickUpDelay') ) {
63
                # recall has been awaiting pickup for longer than the syspref allows
64
                $recall->set_expired({ interface => 'COMMANDLINE' });
65
            }
66
        }
67
    }
68
}
(-)a/misc/cronjobs/recalls/overdue_recalls.pl (+44 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2020 Aleisha Amohia <aleisha@catalyst.net.nz>
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
BEGIN {
23
    # find Koha's Perl modules
24
    # test carefully before changing this
25
    use FindBin;
26
    eval { require "$FindBin::Bin/../kohalib.pl" };
27
}
28
29
# set overdue recalls as overdue
30
31
use Koha::Script -cron;
32
use Koha::DateUtils;
33
use Koha::Checkouts;
34
use Koha::Recalls;
35
use C4::Log;
36
37
cronlogaction();
38
39
my @recalls = Koha::Recalls->search({ status => 'R' });
40
foreach my $recall (@recalls){
41
    if ( $recall->should_be_overdue ){
42
        $recall->set_overdue({ interface => 'COMMANDLINE' });
43
    }
44
}
(-)a/t/db_dependent/Circulation/CalcFine.t (-2 / +55 lines)
Lines 2-8 Link Here
2
2
3
use Modern::Perl;
3
use Modern::Perl;
4
4
5
use Test::More tests => 3;
5
use Test::More tests => 4;
6
6
7
use C4::Context;
7
use C4::Context;
8
use C4::Overdues;
8
use C4::Overdues;
Lines 204-209 subtest 'Test cap_fine_to_replacement_pricew with overduefinescap' => sub { Link Here
204
    teardown();
204
    teardown();
205
};
205
};
206
206
207
subtest 'Recall overdue fines' => sub {
208
    plan tests => 2;
209
210
    Koha::CirculationRules->set_rules(
211
        {
212
            branchcode   => undef,
213
            categorycode => undef,
214
            itemtype     => undef,
215
            rules        => {
216
                fine                          => '1.00',
217
                lengthunit                    => 'days',
218
                finedays                      => 0,
219
                firstremind                   => 0,
220
                chargeperiod                  => 1,
221
                recall_overdue_fine           => '5.00',
222
            },
223
        }
224
    );
225
226
    my $start_dt = DateTime->new(
227
        year       => 2000,
228
        month      => 1,
229
        day        => 1,
230
    );
231
232
    my $end_dt = DateTime->new(
233
        year       => 2000,
234
        month      => 1,
235
        day        => 6,
236
    );
237
238
    my $recall = Koha::Recall->new({
239
        borrowernumber => $patron->{borrowernumber},
240
        recalldate => dt_from_string,
241
        biblionumber => $item->{biblionumber},
242
        branchcode => $branch->{branchcode},
243
        status => 'R',
244
        itemnumber => $item->{itemnumber},
245
        expirationdate => undef,
246
        item_level_recall => 1
247
    })->store;
248
    $recall->set_overdue;
249
250
    my ($amount) = CalcFine( $item, $patron->{categorycode}, $branch->{branchcode}, $start_dt, $end_dt );
251
    is( int($amount), 25, 'Use recall fine amount specified in circulation rules' );
252
253
    $recall->set_finished;
254
    ($amount) = CalcFine( $item, $patron->{categorycode}, $branch->{branchcode}, $start_dt, $end_dt );
255
    is( int($amount), 5, 'With no recall, use normal fine amount' );
256
257
258
    teardown();
259
};
260
207
sub teardown {
261
sub teardown {
208
    $dbh->do(q|DELETE FROM circulation_rules|);
262
    $dbh->do(q|DELETE FROM circulation_rules|);
209
}
263
}
210
- 

Return to bug 19532