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

(-)a/C4/Circulation.pm (-5 / +52 lines)
Lines 59-64 use Koha::RefundLostItemFeeRules; Link Here
59
use Koha::Account::Lines;
59
use Koha::Account::Lines;
60
use Koha::Account::Offsets;
60
use Koha::Account::Offsets;
61
use Koha::Config::SysPrefs;
61
use Koha::Config::SysPrefs;
62
use Koha::Fees;
62
use Carp;
63
use Carp;
63
use List::MoreUtils qw( uniq any );
64
use List::MoreUtils qw( uniq any );
64
use Scalar::Util qw( looks_like_number );
65
use Scalar::Util qw( looks_like_number );
Lines 670-682 sub CanBookBeIssued { Link Here
670
    my $onsite_checkout     = $params->{onsite_checkout}     || 0;
671
    my $onsite_checkout     = $params->{onsite_checkout}     || 0;
671
    my $override_high_holds = $params->{override_high_holds} || 0;
672
    my $override_high_holds = $params->{override_high_holds} || 0;
672
673
673
    my $item = GetItem(undef, $barcode );
674
    my $item_object = Koha::Items->find( { barcode => $barcode } );
675
674
    # MANDATORY CHECKS - unless item exists, nothing else matters
676
    # MANDATORY CHECKS - unless item exists, nothing else matters
675
    unless ( $item ) {
677
    unless ( $item_object ) {
676
        $issuingimpossible{UNKNOWN_BARCODE} = 1;
678
        $issuingimpossible{UNKNOWN_BARCODE} = 1;
677
    }
679
    }
678
    return ( \%issuingimpossible, \%needsconfirmation ) if %issuingimpossible;
680
    return ( \%issuingimpossible, \%needsconfirmation ) if %issuingimpossible;
679
681
682
    my $item = $item_object->unblessed;
683
    $item->{itype} = $item_object->effective_itemtype(); # set the correct itype
684
680
    my $issue = Koha::Checkouts->find( { itemnumber => $item->{itemnumber} } );
685
    my $issue = Koha::Checkouts->find( { itemnumber => $item->{itemnumber} } );
681
    my $biblio = Koha::Biblios->find( $item->{biblionumber} );
686
    my $biblio = Koha::Biblios->find( $item->{biblionumber} );
682
    my $biblioitem = $biblio->biblioitem;
687
    my $biblioitem = $biblio->biblioitem;
Lines 684-689 sub CanBookBeIssued { Link Here
684
    my $dbh             = C4::Context->dbh;
689
    my $dbh             = C4::Context->dbh;
685
    my $patron_unblessed = $patron->unblessed;
690
    my $patron_unblessed = $patron->unblessed;
686
691
692
    my $library = Koha::Libraries->find( _GetCircControlBranch($item, $patron_unblessed) );
687
    #
693
    #
688
    # DUE DATE is OK ? -- should already have checked.
694
    # DUE DATE is OK ? -- should already have checked.
689
    #
695
    #
Lines 694-705 sub CanBookBeIssued { Link Here
694
    unless ( $duedate ) {
700
    unless ( $duedate ) {
695
        my $issuedate = $now->clone();
701
        my $issuedate = $now->clone();
696
702
697
        my $branch = _GetCircControlBranch($item, $patron_unblessed);
703
        my $branch = $library->id;
698
        $duedate = CalcDateDue( $issuedate, $effective_itemtype, $branch, $patron_unblessed );
704
        $duedate = CalcDateDue( $issuedate, $effective_itemtype, $branch, $patron_unblessed );
699
705
700
        # Offline circ calls AddIssue directly, doesn't run through here
706
        # Offline circ calls AddIssue directly, doesn't run through here
701
        #  So issuingimpossible should be ok.
707
        #  So issuingimpossible should be ok.
702
    }
708
    }
709
710
    my $fees = Koha::Fees->new(
711
        {
712
            patron    => $patron,
713
            library   => $library,
714
            item      => $item_object,
715
            to_date   => $duedate,
716
        }
717
    );
718
703
    if ($duedate) {
719
    if ($duedate) {
704
        my $today = $now->clone();
720
        my $today = $now->clone();
705
        $today->truncate( to => 'minute');
721
        $today->truncate( to => 'minute');
Lines 1312-1317 sub AddIssue { Link Here
1312
            );
1328
            );
1313
        }
1329
        }
1314
        else {
1330
        else {
1331
            unless ($datedue) {
1332
                my $itype = $item_object->effective_itemtype;
1333
                $datedue = CalcDateDue( $issuedate, $itype, $branch, $borrower );
1334
1335
            }
1336
            $datedue->truncate( to => 'minute' );
1337
1338
            my $patron = Koha::Patrons->find( $borrower );
1339
            my $library = Koha::Libraries->find( $branch );
1340
            my $fees = Koha::Fees->new(
1341
                {
1342
                    patron    => $patron,
1343
                    library   => $library,
1344
                    item      => $item_object,
1345
                    to_date   => $datedue,
1346
                }
1347
            );
1348
1315
            # it's NOT a renewal
1349
            # it's NOT a renewal
1316
            if ( $actualissue and not $switch_onsite_checkout ) {
1350
            if ( $actualissue and not $switch_onsite_checkout ) {
1317
                # This book is currently on loan, but not to the person
1351
                # This book is currently on loan, but not to the person
Lines 1429-1435 sub AddIssue { Link Here
1429
1463
1430
            my $itemtype = Koha::ItemTypes->find( $item_object->effective_itemtype );
1464
            my $itemtype = Koha::ItemTypes->find( $item_object->effective_itemtype );
1431
            if ( $itemtype ) {
1465
            if ( $itemtype ) {
1432
                my $daily_charge = $itemtype->calc_rental_charge_daily( { from => $issuedate, to => $datedue } );
1466
                my $daily_charge = $fees->rental_charge_daily();
1433
                if ( $daily_charge > 0 ) {
1467
                if ( $daily_charge > 0 ) {
1434
                    AddIssuingCharge( $issue, $daily_charge, 'Daily rental' ) if $daily_charge > 0;
1468
                    AddIssuingCharge( $issue, $daily_charge, 'Daily rental' ) if $daily_charge > 0;
1435
                    $charge += $daily_charge;
1469
                    $charge += $daily_charge;
Lines 2851-2856 sub AddRenewal { Link Here
2851
    my $patron = Koha::Patrons->find( $borrowernumber ) or return; # FIXME Should do more than just return
2885
    my $patron = Koha::Patrons->find( $borrowernumber ) or return; # FIXME Should do more than just return
2852
    my $patron_unblessed = $patron->unblessed;
2886
    my $patron_unblessed = $patron->unblessed;
2853
2887
2888
    my $library = Koha::Libraries->find( $branch );
2889
2890
2854
    if ( C4::Context->preference('CalculateFinesOnReturn') && $issue->is_overdue ) {
2891
    if ( C4::Context->preference('CalculateFinesOnReturn') && $issue->is_overdue ) {
2855
        _CalculateAndUpdateFine( { issue => $issue, item => $item, borrower => $patron_unblessed } );
2892
        _CalculateAndUpdateFine( { issue => $issue, item => $item, borrower => $patron_unblessed } );
2856
    }
2893
    }
Lines 2868-2873 sub AddRenewal { Link Here
2868
        $datedue =  CalcDateDue($datedue, $itemtype, _GetCircControlBranch($item, $patron_unblessed), $patron_unblessed, 'is a renewal');
2905
        $datedue =  CalcDateDue($datedue, $itemtype, _GetCircControlBranch($item, $patron_unblessed), $patron_unblessed, 'is a renewal');
2869
    }
2906
    }
2870
2907
2908
2909
    my $fees = Koha::Fees->new(
2910
        {
2911
            patron    => $patron,
2912
            library   => $library,
2913
            item      => $item_object,
2914
            to_date   => dt_from_string( $datedue ),
2915
        }
2916
    );
2917
2871
    # Update the issues record to have the new due date, and a new count
2918
    # Update the issues record to have the new due date, and a new count
2872
    # of how many times it has been renewed.
2919
    # of how many times it has been renewed.
2873
    my $renews = $issue->renewals + 1;
2920
    my $renews = $issue->renewals + 1;
Lines 2910-2916 sub AddRenewal { Link Here
2910
    # Charge a new daily rental fee, if applicable
2957
    # Charge a new daily rental fee, if applicable
2911
    my $itemtype = Koha::ItemTypes->find( $item_object->effective_itemtype );
2958
    my $itemtype = Koha::ItemTypes->find( $item_object->effective_itemtype );
2912
    if ( $itemtype ) {
2959
    if ( $itemtype ) {
2913
        my $daily_charge = $itemtype->calc_rental_charge_daily( { from => dt_from_string($lastreneweddate), to => $datedue } );
2960
        my $daily_charge = $fees->rental_charge_daily();
2914
        if ( $daily_charge > 0 ) {
2961
        if ( $daily_charge > 0 ) {
2915
            my $type_desc = "Renewal of Daily Rental Item " . $biblio->title . " $item->{'barcode'}";
2962
            my $type_desc = "Renewal of Daily Rental Item " . $biblio->title . " $item->{'barcode'}";
2916
            AddIssuingCharge( $issue, $daily_charge, $type_desc )
2963
            AddIssuingCharge( $issue, $daily_charge, $type_desc )
(-)a/Koha/Fees.pm (+186 lines)
Line 0 Link Here
1
package Koha::Fees;
2
3
# Copyright 2018 ByWater Solutions
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
use Carp qw( confess );
23
24
use Koha::Calendar;
25
use Koha::DateUtils qw( dt_from_string );
26
use Koha::Exceptions;
27
28
=head1 NAME
29
30
Koha::Feess - Module calculating fees in Koha
31
32
=head3 new
33
34
Koha::Fees->new(
35
    {
36
        patron    => $patron,
37
        library   => $library,
38
        item      => $item,
39
        to_date   => $to_dt,
40
        [ from_date => $from_dt, ]
41
    }
42
);
43
44
=cut
45
46
sub new {
47
    my ( $class, $params ) = @_;
48
49
    Koha::Exceptions::MissingParameter->throw("Missing mandatory parameter: patron")
50
        unless $patron;
51
    Koha::Exceptions::MissingParameter->throw("Missing mandatory parameter: library")
52
        unless $library;
53
    Koha::Exceptions::MissingParameter->throw("Missing mandatory parameter: item")
54
        unless $item;
55
    Koha::Exceptions::MissingParameter->throw("Missing mandatory parameter: to_date")
56
        unless $to_date;
57
58
    Carp::confess("Key 'patron' is not a Koha::Patron object!")
59
      unless $params->{patron}->isa('Koha::Patron');
60
    Carp::confess("Key 'library' is not a Koha::Library object!")
61
      unless $params->{library}->isa('Koha::Library');
62
    Carp::confess("Key 'item' is not a Koha::Item object!")
63
      unless $params->{item}->isa('Koha::Item');
64
    Carp::confess("Key 'to_date' is not a DateTime object!")
65
      unless $params->{to_date}->isa('DateTime');
66
67
    if ( $params->{from_date} ) {
68
        Carp::croak("Key 'from_date' is not a DateTime object!")
69
          unless $params->{from_date}->isa('DateTime');
70
    }
71
    else {
72
        $params->{from_date} = dt_from_string();
73
    }
74
75
    return bless( $params, $class );
76
}
77
78
=head3 rental_charge_daily
79
80
    my $fee = $self->rental_charge_daily();
81
82
    This method calculates the daily rental fee for a given itemtype for a given
83
    period of time passed in as a pair of DateTime objects.
84
85
=cut
86
87
sub rental_charge_daily {
88
    my ( $self, $params ) = @_;
89
90
    my $itemtype = Koha::ItemTypes->find( $self->item->effective_itemtype );
91
    my $rental_charge_daily = $itemtype->rental_charge_daily;
92
93
    return undef unless $rental_charge_daily && $rental_charge_daily > 0;
94
95
    my $duration;
96
    if ( C4::Context->preference('finesCalendar') eq 'noFinesWhenClosed' ) {
97
        my $calendar = Koha::Calendar->new( branchcode => $self->library->id );
98
        $duration = $calendar->days_between( $self->from_date, $self->to_date );
99
    }
100
    else {
101
        $duration = $self->to_date->delta_days($self->from_date);
102
    }
103
    my $days = $duration->in_units('days');
104
105
    my $charge = $rental_charge_daily * $days;
106
107
    return $charge;
108
}
109
110
=head3 patron
111
112
my $patron = $fees->patron( $patron );
113
114
=cut
115
116
sub patron {
117
    my ( $self, $patron ) = @_;
118
119
    $self->{patron} = $patron if $patron && $patron->isa('Koha::Patron');
120
121
    return $self->{patron};
122
}
123
124
=head3 library
125
126
my $library = $fees->library( $library );
127
128
=cut
129
130
sub library {
131
    my ( $self, $library ) = @_;
132
133
    $self->{library} = $library if $library && $library->isa('Koha::Library');
134
135
    return $self->{library};
136
}
137
138
=head3 item
139
140
my $item = $fees->item( $item );
141
142
=cut
143
144
sub item {
145
    my ( $self, $item ) = @_;
146
147
    $self->{item} = $item if $item && $item->isa('Koha::Item');
148
149
    return $self->{item};
150
}
151
152
=head3 to_date
153
154
my $to_date = $fees->to_date( $to_date );
155
156
=cut
157
158
sub to_date {
159
    my ( $self, $to_date ) = @_;
160
161
    $self->{to_date} = $to_date if $to_date && $to_date->isa('DateTime');
162
163
    return $self->{to_date};
164
}
165
166
=head3 from_date
167
168
my $from_date = $fees->from_date( $from_date );
169
170
=cut
171
172
sub from_date {
173
    my ( $self, $from_date ) = @_;
174
175
    $self->{from_date} = $from_date if $from_date && $from_date->isa('DateTime');
176
177
    return $self->{from_date};
178
}
179
180
=head1 AUTHOR
181
182
Kyle M Hall <kyle.m.hall@gmail.com>
183
184
=cut
185
186
1;
(-)a/Koha/ItemType.pm (-35 lines)
Lines 102-142 sub translated_descriptions { Link Here
102
    } @translated_descriptions ];
102
    } @translated_descriptions ];
103
}
103
}
104
104
105
=head3 calc_rental_charge_daily
106
107
    my $fee = $itemtype->calc_rental_charge_daily( { from => $dt_from, to => $dt_to } );
108
109
    This method calculates the daily rental fee for a given itemtype for a given
110
    period of time passed in as a pair of DateTime objects.
111
112
=cut
113
114
sub calc_rental_charge_daily {
115
    my ( $self, $params ) = @_;
116
117
    my $rental_charge_daily = $self->rental_charge_daily;
118
    return 0 unless $rental_charge_daily;
119
120
    my $from_dt = $params->{from};
121
    my $to_dt   = $params->{to};
122
123
    my $duration;
124
    if ( C4::Context->preference('finesCalendar') eq 'noFinesWhenClosed' ) {
125
        my $branchcode = C4::Context->userenv->{branch};
126
        my $calendar = Koha::Calendar->new( branchcode => $branchcode );
127
        $duration = $calendar->days_between( $from_dt, $to_dt );
128
    }
129
    else {
130
        $duration = $to_dt->delta_days($from_dt);
131
    }
132
    my $days = $duration->in_units('days');
133
134
    my $charge = $rental_charge_daily * $days;
135
136
    return $charge;
137
}
138
139
140
=head3 can_be_deleted
105
=head3 can_be_deleted
141
106
142
my $can_be_deleted = Koha::ItemType->can_be_deleted();
107
my $can_be_deleted = Koha::ItemType->can_be_deleted();
(-)a/t/db_dependent/Circulation.t (-4 / +4 lines)
Lines 18-24 Link Here
18
use Modern::Perl;
18
use Modern::Perl;
19
use utf8;
19
use utf8;
20
20
21
use Test::More tests => 125;
21
use Test::More tests => 126;
22
use Test::MockModule;
22
use Test::MockModule;
23
23
24
use Data::Dumper;
24
use Data::Dumper;
Lines 3049-3055 subtest 'Koha::ItemType::calc_rental_charge_daily tests' => sub { Link Here
3049
    $accountline->delete();
3049
    $accountline->delete();
3050
    AddRenewal( $patron->id, $item->id, $library->id, $dt_to_renew, $dt_to );
3050
    AddRenewal( $patron->id, $item->id, $library->id, $dt_to_renew, $dt_to );
3051
    $accountline = Koha::Account::Lines->find({ itemnumber => $item->id });
3051
    $accountline = Koha::Account::Lines->find({ itemnumber => $item->id });
3052
    is( $accountline->amount, '6.000000', "Daily rental charge calculated correctly with finesCalendar = ignoreCalendar, for renewal" );
3052
    is( $accountline->amount, '13.000000', "Daily rental charge calculated correctly with finesCalendar = ignoreCalendar, for renewal" );
3053
    $accountline->delete();
3053
    $accountline->delete();
3054
    $issue->delete();
3054
    $issue->delete();
3055
3055
Lines 3060-3066 subtest 'Koha::ItemType::calc_rental_charge_daily tests' => sub { Link Here
3060
    $accountline->delete();
3060
    $accountline->delete();
3061
    AddRenewal( $patron->id, $item->id, $library->id, $dt_to_renew, $dt_to );
3061
    AddRenewal( $patron->id, $item->id, $library->id, $dt_to_renew, $dt_to );
3062
    $accountline = Koha::Account::Lines->find({ itemnumber => $item->id });
3062
    $accountline = Koha::Account::Lines->find({ itemnumber => $item->id });
3063
    is( $accountline->amount, '6.000000', "Daily rental charge calculated correctly with finesCalendar = noFinesWhenClosed, for renewal" );
3063
    is( $accountline->amount, '13.000000', "Daily rental charge calculated correctly with finesCalendar = noFinesWhenClosed, for renewal" );
3064
    $accountline->delete();
3064
    $accountline->delete();
3065
    $issue->delete();
3065
    $issue->delete();
3066
3066
Lines 3076-3082 subtest 'Koha::ItemType::calc_rental_charge_daily tests' => sub { Link Here
3076
    $accountline->delete();
3076
    $accountline->delete();
3077
    AddRenewal( $patron->id, $item->id, $library->id, $dt_to_renew, $dt_to );
3077
    AddRenewal( $patron->id, $item->id, $library->id, $dt_to_renew, $dt_to );
3078
    $accountline = Koha::Account::Lines->find({ itemnumber => $item->id });
3078
    $accountline = Koha::Account::Lines->find({ itemnumber => $item->id });
3079
    is( $accountline->amount, '5.000000', "Daily rental charge calculated correctly with finesCalendar = noFinesWhenClosed and closed Wednesdays, for renewal" );
3079
    is( $accountline->amount, '11.000000', "Daily rental charge calculated correctly with finesCalendar = noFinesWhenClosed and closed Wednesdays, for renewal" );
3080
    $accountline->delete();
3080
    $accountline->delete();
3081
    $issue->delete();
3081
    $issue->delete();
3082
3082
(-)a/t/db_dependent/Koha/Fees.t (+126 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
#
3
# Copyright 2018 ByWater Solutions
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
22
use Test::More tests => 2;
23
24
use t::lib::Mocks;
25
use t::lib::TestBuilder;
26
27
use Data::Dumper;
28
29
use C4::Calendar;
30
use Koha::DateUtils qw(dt_from_string);
31
32
BEGIN {
33
    use_ok('Koha::Fees');
34
}
35
36
my $builder = t::lib::TestBuilder->new();
37
38
my $patron_category = $builder->build_object(
39
    {
40
        class => 'Koha::Patron::Categories',
41
        value => {
42
            category_type => 'P',
43
            enrolmentfee  => 0,
44
        }
45
    }
46
);
47
my $library = $builder->build_object(
48
    {
49
        class => 'Koha::Libraries',
50
    }
51
);
52
my $biblio = $builder->build_object(
53
    {
54
        class => 'Koha::Biblios',
55
    }
56
);
57
my $itemtype = $builder->build_object(
58
    {
59
        class => 'Koha::ItemTypes',
60
        value => {
61
            rental_charge_daily => '0.00',
62
            rentalcharge        => '0.00',
63
            processfee          => '0.00',
64
            defaultreplacecost  => '0.00',
65
        },
66
    }
67
);
68
my $item = $builder->build_object(
69
    {
70
        class => 'Koha::Items',
71
        value => {
72
            biblionumber  => $biblio->id,
73
            homebranch    => $library->id,
74
            holdingbranch => $library->id,
75
            itype         => $itemtype->id,
76
        }
77
    }
78
);
79
my $patron = $builder->build_object(
80
    {
81
        class => 'Koha::Patrons',
82
        value => {
83
            dateexpiry   => '9999-12-31',
84
            categorycode => $patron_category->id,
85
        }
86
    }
87
);
88
89
my $dt_from = dt_from_string();
90
my $dt_to = dt_from_string()->add( days => 6 );
91
92
my $fees = Koha::Fees->new(
93
    {
94
        patron    => $patron,
95
        library   => $library,
96
        item      => $item,
97
        to_date   => $dt_to,
98
        from_date => $dt_from,
99
    }
100
);
101
102
subtest 'Koha::ItemType::rental_charge_daily tests' => sub {
103
    plan tests => 4;
104
105
    $itemtype->rental_charge_daily(1.00);
106
    $itemtype->store();
107
    is( $itemtype->rental_charge_daily,
108
        1.00, 'Daily return charge stored correctly' );
109
110
    t::lib::Mocks::mock_preference( 'finesCalendar', 'ignoreCalendar' );
111
    my $charge = $fees->rental_charge_daily();
112
    is( $charge, 6.00, 'Daily rental charge calculated correctly with finesCalendar = ignoreCalendar' );
113
114
    t::lib::Mocks::mock_preference( 'finesCalendar', 'noFinesWhenClosed' );
115
    $charge = $fees->rental_charge_daily();
116
    is( $charge, 6.00, 'Daily rental charge calculated correctly with finesCalendar = noFinesWhenClosed' );
117
118
    my $calendar = C4::Calendar->new( branchcode => $library->id );
119
    $calendar->insert_week_day_holiday(
120
        weekday     => 3,
121
        title       => 'Test holiday',
122
        description => 'Test holiday'
123
    );
124
    $charge = $fees->rental_charge_daily();
125
    is( $charge, 5.00, 'Daily rental charge calculated correctly with finesCalendar = noFinesWhenClosed and closed Wednesdays' );
126
};
(-)a/t/db_dependent/Koha/ItemTypes.t (-44 / +1 lines)
Lines 20-26 Link Here
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Data::Dumper;
22
use Data::Dumper;
23
use Test::More tests => 25;
23
use Test::More tests => 24;
24
24
25
use t::lib::Mocks;
25
use t::lib::Mocks;
26
use t::lib::TestBuilder;
26
use t::lib::TestBuilder;
Lines 155-200 $biblioitem->delete; Link Here
155
155
156
is ( $item_type->can_be_deleted, 1, 'The item type that was being used by the removed item and biblioitem can now be deleted' );
156
is ( $item_type->can_be_deleted, 1, 'The item type that was being used by the removed item and biblioitem can now be deleted' );
157
157
158
subtest 'Koha::ItemType::calc_rental_charge_daily tests' => sub {
159
    plan tests => 4;
160
161
    my $library = Koha::Libraries->search()->next();
162
    my $module = new Test::MockModule('C4::Context');
163
    $module->mock('userenv', sub { { branch => $library->id } });
164
165
    my $itemtype = Koha::ItemType->new(
166
        {
167
            itemtype            => 'type4',
168
            description         => 'description',
169
            rental_charge_daily => 1.00,
170
            rentalcharge        => '0.00',
171
            processfee          => '0.00',
172
            defaultreplacecost  => '0.00',
173
        }
174
    )->store;
175
176
    is( $itemtype->rental_charge_daily, 1.00, 'Daily rental charge stored and retreived correctly' );
177
178
    my $dt_from = dt_from_string();
179
    my $dt_to = dt_from_string()->add( days => 6 );
180
181
    t::lib::Mocks::mock_preference('finesCalendar', 'ignoreCalendar');
182
    my $charge = $itemtype->calc_rental_charge_daily( { from => $dt_from, to => $dt_to } );
183
    is( $charge, 6.00, "Daily rental charge calculated correctly with finesCalendar = ignoreCalendar" );
184
185
    t::lib::Mocks::mock_preference('finesCalendar', 'noFinesWhenClosed');
186
    $charge = $itemtype->calc_rental_charge_daily( { from => $dt_from, to => $dt_to } );
187
    is( $charge, 6.00, "Daily rental charge calculated correctly with finesCalendar = noFinesWhenClosed" );
188
189
    my $calendar = C4::Calendar->new( branchcode => $library->id );
190
    $calendar->insert_week_day_holiday(
191
        weekday     => 3,
192
        title       => 'Test holiday',
193
        description => 'Test holiday'
194
    );
195
    $charge = $itemtype->calc_rental_charge_daily( { from => $dt_from, to => $dt_to } );
196
    is( $charge, 5.00, "Daily rental charge calculated correctly with finesCalendar = noFinesWhenClosed and closed Wednesdays" );
197
198
};
199
200
$schema->txn_rollback;
158
$schema->txn_rollback;
201
- 

Return to bug 20912