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

(-)a/C4/Overdues.pm (-3 / +19 lines)
Lines 93-106 sub Getoverdues { Link Here
93
    if ( C4::Context->preference('item-level_itypes') ) {
93
    if ( C4::Context->preference('item-level_itypes') ) {
94
        $statement = "
94
        $statement = "
95
   SELECT issues.*, items.itype as itemtype, items.homebranch, items.barcode, items.itemlost, items.replacementprice, items.biblionumber, items.holdingbranch
95
   SELECT issues.*, items.itype as itemtype, items.homebranch, items.barcode, items.itemlost, items.replacementprice, items.biblionumber, items.holdingbranch
96
     FROM issues 
96
     FROM issues
97
LEFT JOIN items       USING (itemnumber)
97
LEFT JOIN items       USING (itemnumber)
98
    WHERE date_due < NOW()
98
    WHERE date_due < NOW()
99
";
99
";
100
    } else {
100
    } else {
101
        $statement = "
101
        $statement = "
102
   SELECT issues.*, biblioitems.itemtype, items.itype, items.homebranch, items.barcode, items.itemlost, replacementprice, items.biblionumber, items.holdingbranch
102
   SELECT issues.*, biblioitems.itemtype, items.itype, items.homebranch, items.barcode, items.itemlost, replacementprice, items.biblionumber, items.holdingbranch
103
     FROM issues 
103
     FROM issues
104
LEFT JOIN items       USING (itemnumber)
104
LEFT JOIN items       USING (itemnumber)
105
LEFT JOIN biblioitems USING (biblioitemnumber)
105
LEFT JOIN biblioitems USING (biblioitemnumber)
106
    WHERE date_due < NOW()
106
    WHERE date_due < NOW()
Lines 222-227 sub CalcFine { Link Here
222
    # Skip calculations if item is not overdue
222
    # Skip calculations if item is not overdue
223
    return ( 0, 0, 0 ) unless ( DateTime->compare( $due_dt, $end_date ) == -1 );
223
    return ( 0, 0, 0 ) unless ( DateTime->compare( $due_dt, $end_date ) == -1 );
224
224
225
    # Call the plugin hook overwrite_calc_fine of all plugins and return
226
    # the first defined fine.
227
    my @fines = Koha::Plugins->call(
228
        'overwrite_calc_fine',
229
        {
230
            itemnumber   => $item->{itemnumber},
231
            categorycode => $bortype,
232
            branchcode   => $branchcode,
233
            due_date     => $due_dt,
234
            end_date     => $end_date,
235
        }
236
    );
237
    foreach my $fine (@fines) {
238
        return @$fine if ( defined $fine );
239
    }
240
225
    my $start_date = $due_dt->clone();
241
    my $start_date = $due_dt->clone();
226
242
227
    # get issuingrules (fines part will be used)
243
    # get issuingrules (fines part will be used)
Lines 655-661 C<$itemnum> is item number Link Here
655
671
656
C<$borrowernumber> is the borrowernumber
672
C<$borrowernumber> is the borrowernumber
657
673
658
=cut 
674
=cut
659
675
660
sub GetFine {
676
sub GetFine {
661
    my ( $itemnum, $borrowernumber ) = @_;
677
    my ( $itemnum, $borrowernumber ) = @_;
(-)a/t/db_dependent/Koha/Plugins/Overdues.t (+111 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it under the
6
# terms of the GNU General Public License as published by the Free Software
7
# Foundation; either version 3 of the License, or (at your option) any later
8
# version.
9
#
10
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License along
15
# with Koha; if not, see <http://www.gnu.org/licenses>.
16
17
use Modern::Perl;
18
19
use Test::NoWarnings;
20
use Test::More tests => 6;
21
22
use C4::Overdues qw(CalcFine);
23
24
use File::Basename;
25
26
use t::lib::Mocks;
27
use t::lib::TestBuilder;
28
29
BEGIN {
30
    # Mock pluginsdir before loading Plugins module
31
    my $path = dirname(__FILE__) . '/../../../lib/plugins';
32
    t::lib::Mocks::mock_config( 'pluginsdir', $path );
33
34
    use_ok('C4::Overdues');
35
    use_ok('Koha::Plugins');
36
    use_ok('Koha::Plugins::Handler');
37
    use_ok('Koha::Plugin::Test');
38
}
39
40
t::lib::Mocks::mock_config( 'enable_plugins', 1 );
41
42
my $builder = t::lib::TestBuilder->new;
43
44
my $branch = $builder->build(
45
    {
46
        source => 'Branch',
47
    }
48
);
49
50
my $category = $builder->build(
51
    {
52
        source => 'Category',
53
    }
54
);
55
56
my $item = $builder->build_sample_item;
57
58
subtest 'overwrite_calc_fine hook tests' => sub {
59
    plan tests => 6;
60
61
    my $schema = Koha::Database->new->schema;
62
    $schema->storage->txn_begin;
63
64
    my $plugins = Koha::Plugins->new;
65
    $plugins->InstallPlugins;
66
    Koha::Plugin::Test->new->enable;
67
68
    Koha::CirculationRules->set_rules(
69
        {
70
            branchcode   => undef,
71
            categorycode => undef,
72
            itemtype     => undef,
73
            rules        => {
74
                fine                          => '2.00',
75
                lengthunit                    => 'days',
76
                finedays                      => 0,
77
                firstremind                   => 0,
78
                chargeperiod                  => 1,
79
                overduefinescap               => '0',
80
                cap_fine_to_replacement_price => 0,
81
            }
82
        },
83
    );
84
85
    my $due_date = DateTime->new(
86
        year  => 2000,
87
        month => 1,
88
        day   => 1,
89
    );
90
    my $end_date = DateTime->new(
91
        year  => 2000,
92
        month => 1,
93
        day   => 30,
94
    );
95
96
    my ( $amount, $units, $chargable_units ) = CalcFine( $item->{itemnumber}, undef, undef, $due_date, $end_date );
97
98
    is( $amount,          87, 'Amount is calculated correctly with custom function' );
99
    is( $units,           29, 'Units are calculated correctly with custom function' );
100
    is( $chargable_units, 27, 'Chargable units are calculated correctly with custom function' );
101
102
    ( $amount, $units, $chargable_units ) =
103
        CalcFine( $item->{itemnumber}, $category->{categorycode}, $branch->{branchcode}, $due_date, $end_date );
104
105
    is( $amount,          58, 'Amount is calculated correctly with original function' );
106
    is( $units,           29, 'Units are calculated correctly with original function' );
107
    is( $chargable_units, 29, 'Chargable units are calculated correctly with original function' );
108
109
    Koha::Plugins->RemovePlugins;
110
    $schema->storage->txn_rollback;
111
};
(-)a/t/lib/plugins/Koha/Plugin/Test.pm (-1 / +10 lines)
Lines 448-453 sub auth_client_get_user { Link Here
448
    return;
448
    return;
449
}
449
}
450
450
451
sub overwrite_calc_fine {
452
    my ( $self, $params ) = @_;
453
454
    my $days = $params->{end_date}->delta_days( $params->{due_date} )->delta_days;
455
456
    return $params->{categorycode} && $params->{branchcode}
457
        ? undef
458
        : [ 3 * $days, $days, $days - 2 ];
459
}
460
451
sub _private_sub {
461
sub _private_sub {
452
    return "";
462
    return "";
453
}
463
}
454
- 

Return to bug 39405