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

(-)a/C4/Overdues.pm (-1 / +23 lines)
Lines 33-38 use Koha::Logger; Link Here
33
use Koha::Account::Lines;
33
use Koha::Account::Lines;
34
use Koha::Account::Offsets;
34
use Koha::Account::Offsets;
35
use Koha::Libraries;
35
use Koha::Libraries;
36
use Koha::Recalls;
36
37
37
our (@ISA, @EXPORT_OK);
38
our (@ISA, @EXPORT_OK);
38
BEGIN {
39
BEGIN {
Lines 236-241 sub CalcFine { Link Here
236
                'fine',
237
                'fine',
237
                'overduefinescap',
238
                'overduefinescap',
238
                'cap_fine_to_replacement_price',
239
                'cap_fine_to_replacement_price',
240
                'recall_overdue_fine',
239
            ]
241
            ]
240
        }
242
        }
241
    );
243
    );
Lines 255-261 sub CalcFine { Link Here
255
        # If chargeperiod_charge_at = 1, we charge a fine at the start of each charge period
257
        # If chargeperiod_charge_at = 1, we charge a fine at the start of each charge period
256
        # if chargeperiod_charge_at = 0, we charge at the end of each charge period
258
        # if chargeperiod_charge_at = 0, we charge at the end of each charge period
257
        $charge_periods = defined $issuing_rule->{chargeperiod_charge_at} && $issuing_rule->{chargeperiod_charge_at} == 1 ? ceil($charge_periods) : floor($charge_periods);
259
        $charge_periods = defined $issuing_rule->{chargeperiod_charge_at} && $issuing_rule->{chargeperiod_charge_at} == 1 ? ceil($charge_periods) : floor($charge_periods);
258
        $amount = $charge_periods * $issuing_rule->{fine};
260
261
        # check if item has been recalled. recall should have been marked Overdue by cronjob, so only look at overdue recalls
262
        # only charge using recall_overdue_fine if there is an item-level recall for this particular item, OR a biblio-level recall
263
        my @recalls = Koha::Recalls->search({ biblionumber => $item->{biblionumber}, old => undef, status => 'O' });
264
        my $bib_level_recall = 0;
265
        $bib_level_recall = 1 if scalar @recalls > 0;
266
        foreach my $recall ( @recalls ) {
267
            if ( $recall->item_level_recall and $recall->itemnumber == $item->{itemnumber} and $issuing_rule->{recall_overdue_fine} ) {
268
                $bib_level_recall = 0;
269
                $amount = $charge_periods * $issuing_rule->{recall_overdue_fine};
270
                last;
271
            }
272
        }
273
        if ( $bib_level_recall and $issuing_rule->{recall_overdue_fine} ) {
274
            # biblio-level recall
275
            $amount = $charge_periods * $issuing_rule->{recall_overdue_fine};
276
        }
277
        if ( scalar @recalls == 0 ) {
278
            # no recall, use normal fine amount
279
            $amount = $charge_periods * $issuing_rule->{fine};
280
        }
259
    } # else { # a zero (or null) chargeperiod or negative units_minus_grace value means no charge. }
281
    } # else { # a zero (or null) chargeperiod or negative units_minus_grace value means no charge. }
260
282
261
    $amount = $issuing_rule->{overduefinescap} if $issuing_rule->{overduefinescap} && $amount > $issuing_rule->{overduefinescap};
283
    $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 qw( CalcFine );
8
use C4::Overdues qw( CalcFine );
Lines 196-201 subtest 'Test cap_fine_to_replacement_pricew with overduefinescap' => sub { Link Here
196
    teardown();
196
    teardown();
197
};
197
};
198
198
199
subtest 'Recall overdue fines' => sub {
200
    plan tests => 2;
201
202
    Koha::CirculationRules->set_rules(
203
        {
204
            branchcode   => undef,
205
            categorycode => undef,
206
            itemtype     => undef,
207
            rules        => {
208
                fine                          => '1.00',
209
                lengthunit                    => 'days',
210
                finedays                      => 0,
211
                firstremind                   => 0,
212
                chargeperiod                  => 1,
213
                recall_overdue_fine           => '5.00',
214
            },
215
        }
216
    );
217
218
    my $start_dt = DateTime->new(
219
        year       => 2000,
220
        month      => 1,
221
        day        => 1,
222
    );
223
224
    my $end_dt = DateTime->new(
225
        year       => 2000,
226
        month      => 1,
227
        day        => 6,
228
    );
229
230
    my $recall = Koha::Recall->new({
231
        borrowernumber => $patron->{borrowernumber},
232
        recalldate => dt_from_string,
233
        biblionumber => $item->{biblionumber},
234
        branchcode => $branch->{branchcode},
235
        status => 'R',
236
        itemnumber => $item->{itemnumber},
237
        expirationdate => undef,
238
        item_level_recall => 1
239
    })->store;
240
    $recall->set_overdue;
241
242
    my ($amount) = CalcFine( $item, $patron->{categorycode}, $branch->{branchcode}, $start_dt, $end_dt );
243
    is( int($amount), 25, 'Use recall fine amount specified in circulation rules' );
244
245
    $recall->set_finished;
246
    ($amount) = CalcFine( $item, $patron->{categorycode}, $branch->{branchcode}, $start_dt, $end_dt );
247
    is( int($amount), 5, 'With no recall, use normal fine amount' );
248
249
250
    teardown();
251
};
252
199
sub teardown {
253
sub teardown {
200
    $dbh->do(q|DELETE FROM circulation_rules|);
254
    $dbh->do(q|DELETE FROM circulation_rules|);
201
}
255
}
202
- 

Return to bug 19532