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

(-)a/C4/Overdues.pm (-1 / +22 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 = 1 if scalar @recalls > 0;
272
        foreach my $recall ( @recalls ) {
273
            if ( $recall->item_level_recall and $recall->itemnumber == $item->{itemnumber} and $issuing_rule->{recall_overdue_fine} ) {
274
                $bib_level_recall = 0;
275
                $amount = $charge_periods * $issuing_rule->{recall_overdue_fine};
276
                last;
277
            }
278
        }
279
        if ( $bib_level_recall and $issuing_rule->{recall_overdue_fine} ) {
280
            # biblio-level recall
281
            $amount = $charge_periods * $issuing_rule->{recall_overdue_fine};
282
        }
283
        if ( scalar @recalls == 0 ) {
284
            # no recall, use normal fine amount
285
            $amount = $charge_periods * $issuing_rule->{fine};
286
        }
266
    } # else { # a zero (or null) chargeperiod or negative units_minus_grace value means no charge. }
287
    } # else { # a zero (or null) chargeperiod or negative units_minus_grace value means no charge. }
267
288
268
    $amount = $issuing_rule->{overduefinescap} if $issuing_rule->{overduefinescap} && $amount > $issuing_rule->{overduefinescap};
289
    $amount = $issuing_rule->{overduefinescap} if $issuing_rule->{overduefinescap} && $amount > $issuing_rule->{overduefinescap};
(-)a/misc/cronjobs/recalls/expire_recalls.pl (+63 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
BEGIN {
21
    # find Koha's Perl modules
22
    # test carefully before changing this
23
    use FindBin;
24
    eval { require "$FindBin::Bin/../kohalib.pl" };
25
}
26
27
# set overdue recalls as overdue. This includes:
28
# - recalls that have been requested and not fulfilled and have passed their expiration date
29
# - recalls that have been awaiting pickup for longer than the specified recall_shelf_time circulation rule, or the RecallMaxPickUpDelay if circ rule is unset
30
31
use Koha::Script -cron;
32
use Koha::DateUtils;
33
use Koha::Recalls;
34
use C4::Log;
35
36
cronlogaction();
37
38
my @recalls = Koha::Recalls->search({ old => undef });
39
foreach my $recall (@recalls) {
40
    if ( ( $recall->requested or $recall->overdue ) and $recall->expirationdate and dt_from_string( $recall->expirationdate ) < dt_from_string() ){
41
        $recall->set_expired({ interface => 'COMMANDLINE' });
42
    }
43
    if ( $recall->is_waiting ) {
44
        my $recall_shelf_time = Koha::CirculationRules->get_effective_rule({
45
            categorycode => $recall->patron->categorycode,
46
            itemtype => $recall->item->effective_itemtype,
47
            branchcode => $recall->branchcode,
48
            rule_name => 'recall_shelf_time',
49
        });
50
        my $waitingdate = dt_from_string( $recall->waitingdate );
51
        my $now = dt_from_string();
52
        my $days_waiting = $now->subtract_datetime( $waitingdate );
53
        if ( defined $recall_shelf_time and $recall_shelf_time->rule_value > 0 ) {
54
            if ( $days_waiting->days > $recall_shelf_time->rule_value ) {
55
                $recall->set_expired({ interface => 'COMMANDLINE' });
56
            }
57
        } else {
58
            if ( $days_waiting->days > C4::Context->preference('RecallMaxPickUpDelay') ) {
59
                $recall->set_expired({ interface => 'COMMANDLINE' });
60
            }
61
        }
62
    }
63
}
(-)a/misc/cronjobs/recalls/overdue_recalls.pl (+41 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
BEGIN {
21
    # find Koha's Perl modules
22
    # test carefully before changing this
23
    use FindBin;
24
    eval { require "$FindBin::Bin/../kohalib.pl" };
25
}
26
27
# set overdue recalls as overdue
28
29
use Koha::Script -cron;
30
use Koha::DateUtils;
31
use Koha::Recalls;
32
use C4::Log;
33
34
cronlogaction();
35
36
my @recalls = Koha::Recalls->search({ status => 'R' });
37
foreach my $recall (@recalls){
38
    if ( $recall->checkout && dt_from_string( $recall->checkout->date_due ) <= dt_from_string() ){
39
        $recall->set_overdue;
40
    }
41
}
(-)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