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

(-)a/C4/Circulation.pm (-5 / +30 lines)
Lines 977-982 sub CanBookBeIssued { Link Here
977
977
978
    if ( $rentalConfirmation ){
978
    if ( $rentalConfirmation ){
979
        my ($rentalCharge) = GetIssuingCharges( $item->{'itemnumber'}, $patron->borrowernumber );
979
        my ($rentalCharge) = GetIssuingCharges( $item->{'itemnumber'}, $patron->borrowernumber );
980
        my $itemtype = Koha::ItemTypes->find( $item->{itype} ); # GetItem sets effective itemtype
981
        $rentalCharge += $itemtype->calc_rental_charge_daily( { from => dt_from_string(), to => $duedate } );
980
        if ( $rentalCharge > 0 ){
982
        if ( $rentalCharge > 0 ){
981
            $needsconfirmation{RENTALCHARGE} = $rentalCharge;
983
            $needsconfirmation{RENTALCHARGE} = $rentalCharge;
982
        }
984
        }
Lines 1419-1430 sub AddIssue { Link Here
1419
            ModDateLastSeen( $item->{'itemnumber'} );
1421
            ModDateLastSeen( $item->{'itemnumber'} );
1420
1422
1421
           # If it costs to borrow this book, charge it to the patron's account.
1423
           # If it costs to borrow this book, charge it to the patron's account.
1422
            my ( $charge, $itemtype ) = GetIssuingCharges( $item->{'itemnumber'}, $borrower->{'borrowernumber'} );
1424
            my ( $charge ) = GetIssuingCharges( $item->{'itemnumber'}, $borrower->{'borrowernumber'} );
1423
            if ( $charge > 0 ) {
1425
            if ( $charge > 0 ) {
1424
                AddIssuingCharge( $issue, $charge );
1426
                AddIssuingCharge( $issue, $charge );
1425
                $item->{'charge'} = $charge;
1427
                $item->{'charge'} = $charge;
1426
            }
1428
            }
1427
1429
1430
            my $itemtype = Koha::ItemTypes->find( $item_object->effective_itemtype );
1431
            if ( $itemtype ) {
1432
                my $daily_charge = $itemtype->calc_rental_charge_daily( { from => $issuedate, to => $datedue } );
1433
                if ( $daily_charge > 0 ) {
1434
                    AddIssuingCharge( $issue, $daily_charge, 'Daily rental' ) if $daily_charge > 0;
1435
                    $charge += $daily_charge;
1436
                    $item->{charge} = $charge;
1437
                }
1438
            }
1439
1428
            # Record the fact that this book was issued.
1440
            # Record the fact that this book was issued.
1429
            &UpdateStats(
1441
            &UpdateStats(
1430
                {
1442
                {
Lines 2870-2876 sub AddRenewal { Link Here
2870
    $renews = $item->{renewals} + 1;
2882
    $renews = $item->{renewals} + 1;
2871
    ModItem( { renewals => $renews, onloan => $datedue->strftime('%Y-%m-%d %H:%M')}, $item->{biblionumber}, $itemnumber, { log_action => 0 } );
2883
    ModItem( { renewals => $renews, onloan => $datedue->strftime('%Y-%m-%d %H:%M')}, $item->{biblionumber}, $itemnumber, { log_action => 0 } );
2872
2884
2873
    # Charge a new rental fee, if applicable?
2885
    # Charge a new rental fee, if applicable
2874
    my ( $charge, $type ) = GetIssuingCharges( $itemnumber, $borrowernumber );
2886
    my ( $charge, $type ) = GetIssuingCharges( $itemnumber, $borrowernumber );
2875
    if ( $charge > 0 ) {
2887
    if ( $charge > 0 ) {
2876
        my $accountno = C4::Accounts::getnextacctno( $borrowernumber );
2888
        my $accountno = C4::Accounts::getnextacctno( $borrowernumber );
Lines 2895-2900 sub AddRenewal { Link Here
2895
        )->store();
2907
        )->store();
2896
    }
2908
    }
2897
2909
2910
    # Charge a new daily rental fee, if applicable
2911
    my $itemtype = Koha::ItemTypes->find( $item_object->effective_itemtype );
2912
    if ( $itemtype ) {
2913
        my $daily_charge = $itemtype->calc_rental_charge_daily( { from => dt_from_string($lastreneweddate), to => $datedue } );
2914
        if ( $daily_charge > 0 ) {
2915
            my $type_desc = "Renewal of Daily Rental Item " . $biblio->title . " $item->{'barcode'}";
2916
            AddIssuingCharge( $issue, $daily_charge, $type_desc )
2917
        }
2918
        $charge += $daily_charge;
2919
    }
2920
2898
    # Send a renewal slip according to checkout alert preferencei
2921
    # Send a renewal slip according to checkout alert preferencei
2899
    if ( C4::Context->preference('RenewalSendNotice') eq '1' ) {
2922
    if ( C4::Context->preference('RenewalSendNotice') eq '1' ) {
2900
        my $circulation_alert = 'C4::ItemCirculationAlertPreference';
2923
        my $circulation_alert = 'C4::ItemCirculationAlertPreference';
Lines 3212-3223 sub _get_discount_from_rule { Link Here
3212
3235
3213
=head2 AddIssuingCharge
3236
=head2 AddIssuingCharge
3214
3237
3215
  &AddIssuingCharge( $checkout, $charge )
3238
  &AddIssuingCharge( $checkout, $charge, [$type] )
3216
3239
3217
=cut
3240
=cut
3218
3241
3219
sub AddIssuingCharge {
3242
sub AddIssuingCharge {
3220
    my ( $checkout, $charge ) = @_;
3243
    my ( $checkout, $charge, $type ) = @_;
3244
3245
    $type ||= 'Rental';
3221
3246
3222
    # FIXME What if checkout does not exist?
3247
    # FIXME What if checkout does not exist?
3223
3248
Lines 3238-3244 sub AddIssuingCharge { Link Here
3238
            amountoutstanding => $charge,
3263
            amountoutstanding => $charge,
3239
            manager_id        => $manager_id,
3264
            manager_id        => $manager_id,
3240
            branchcode        => $branchcode,
3265
            branchcode        => $branchcode,
3241
            description       => 'Rental',
3266
            description       => $type,
3242
            accounttype       => 'Rent',
3267
            accounttype       => 'Rent',
3243
            date              => \'NOW()',
3268
            date              => \'NOW()',
3244
        }
3269
        }
(-)a/Koha/ItemType.pm (+33 lines)
Lines 102-107 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
}
105
138
106
139
107
=head3 can_be_deleted
140
=head3 can_be_deleted
(-)a/admin/itemtypes.pl (-13 / +17 lines)
Lines 72-77 if ( $op eq 'add_form' ) { Link Here
72
    my $itemtype     = Koha::ItemTypes->find($itemtype_code);
72
    my $itemtype     = Koha::ItemTypes->find($itemtype_code);
73
    my $description  = $input->param('description');
73
    my $description  = $input->param('description');
74
    my $rentalcharge = $input->param('rentalcharge');
74
    my $rentalcharge = $input->param('rentalcharge');
75
    my $rental_charge_daily = $input->param('rental_charge_daily');
75
    my $defaultreplacecost = $input->param('defaultreplacecost');
76
    my $defaultreplacecost = $input->param('defaultreplacecost');
76
    my $processfee = $input->param('processfee');
77
    my $processfee = $input->param('processfee');
77
    my $image = $input->param('image') || q||;
78
    my $image = $input->param('image') || q||;
Lines 92-97 if ( $op eq 'add_form' ) { Link Here
92
    if ( $itemtype and $is_a_modif ) {    # it's a modification
93
    if ( $itemtype and $is_a_modif ) {    # it's a modification
93
        $itemtype->description($description);
94
        $itemtype->description($description);
94
        $itemtype->rentalcharge($rentalcharge);
95
        $itemtype->rentalcharge($rentalcharge);
96
        $itemtype->rental_charge_daily($rental_charge_daily);
95
        $itemtype->defaultreplacecost($defaultreplacecost);
97
        $itemtype->defaultreplacecost($defaultreplacecost);
96
        $itemtype->processfee($processfee);
98
        $itemtype->processfee($processfee);
97
        $itemtype->notforloan($notforloan);
99
        $itemtype->notforloan($notforloan);
Lines 112-130 if ( $op eq 'add_form' ) { Link Here
112
        }
114
        }
113
    } elsif ( not $itemtype and not $is_a_modif ) {
115
    } elsif ( not $itemtype and not $is_a_modif ) {
114
        my $itemtype = Koha::ItemType->new(
116
        my $itemtype = Koha::ItemType->new(
115
            {   itemtype           => $itemtype_code,
117
            {
116
                description        => $description,
118
                itemtype            => $itemtype_code,
117
                rentalcharge       => $rentalcharge,
119
                description         => $description,
118
                defaultreplacecost => $defaultreplacecost,
120
                rentalcharge        => $rentalcharge,
119
                processfee         => $processfee,
121
                rental_charge_daily => $rental_charge_daily,
120
                notforloan         => $notforloan,
122
                defaultreplacecost  => $defaultreplacecost,
121
                imageurl           => $imageurl,
123
                processfee          => $processfee,
122
                summary            => $summary,
124
                notforloan          => $notforloan,
123
                checkinmsg         => $checkinmsg,
125
                imageurl            => $imageurl,
124
                checkinmsgtype     => $checkinmsgtype,
126
                summary             => $summary,
125
                sip_media_type     => $sip_media_type,
127
                checkinmsg          => $checkinmsg,
126
                hideinopac         => $hideinopac,
128
                checkinmsgtype      => $checkinmsgtype,
127
                searchcategory     => $searchcategory,
129
                sip_media_type      => $sip_media_type,
130
                hideinopac          => $hideinopac,
131
                searchcategory      => $searchcategory,
128
            }
132
            }
129
        );
133
        );
130
        eval { $itemtype->store; };
134
        eval { $itemtype->store; };
(-)a/catalogue/moredetail.pl (-1 lines)
Lines 128-134 my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_l Link Here
128
128
129
$data->{'itemtypename'} = $itemtypes->{ $data->{'itemtype'} }->{'translated_description'}
129
$data->{'itemtypename'} = $itemtypes->{ $data->{'itemtype'} }->{'translated_description'}
130
  if $data->{itemtype} && exists $itemtypes->{ $data->{itemtype} };
130
  if $data->{itemtype} && exists $itemtypes->{ $data->{itemtype} };
131
$data->{'rentalcharge'} = sprintf( "%.2f", $data->{'rentalcharge'} || 0); # Price formatting should be done template-side
132
foreach ( keys %{$data} ) {
131
foreach ( keys %{$data} ) {
133
    $template->param( "$_" => defined $data->{$_} ? $data->{$_} : '' );
132
    $template->param( "$_" => defined $data->{$_} ? $data->{$_} : '' );
134
}
133
}
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/itemtypes.tt (-5 / +17 lines)
Lines 138-144 Item types administration Link Here
138
                            [% END %]
138
                            [% END %]
139
                        [% END %]
139
                        [% END %]
140
                    </select>
140
                    </select>
141
                    (Options are defined as the authorized values for the ITEMTYPECAT category)
141
                    <span class="hint">Options are defined as the authorized values for the ITEMTYPECAT category.</span>
142
                </li>
142
                </li>
143
                [% IF Koha.Preference('noItemTypeImages') %]
143
                [% IF Koha.Preference('noItemTypeImages') %]
144
                    <li>
144
                    <li>
Lines 218-224 Item types administration Link Here
218
                    [% ELSE %]
218
                    [% ELSE %]
219
                        <input type="checkbox" id="hideinopac" name="hideinopac" value="1" />
219
                        <input type="checkbox" id="hideinopac" name="hideinopac" value="1" />
220
                    [% END %]
220
                    [% END %]
221
                    (if checked, items of this type will be hidden as filters in OPAC's advanced search)
221
                    <span class="hint">If checked, items of this type will be hidden as filters in OPAC's advanced search.</span>
222
                </li>
222
                </li>
223
                <li>
223
                <li>
224
                    <label for="notforloan">Not for loan: </label>
224
                    <label for="notforloan">Not for loan: </label>
Lines 227-237 Item types administration Link Here
227
                        [% ELSE %]
227
                        [% ELSE %]
228
                            <input type="checkbox" id="notforloan" name="notforloan" value="1" />
228
                            <input type="checkbox" id="notforloan" name="notforloan" value="1" />
229
                        [% END %]
229
                        [% END %]
230
                      (if checked, no item of this type can be issued. If not checked, every item of this type can be issued unless notforloan is set for a specific item)
230
                        <span class="hint">If checked, no item of this type can be issued. If not checked, every item of this type can be issued unless notforloan is set for a specific item.</span>
231
                </li>
231
                </li>
232
                <li>
232
                <li>
233
                    <label for="rentalcharge">Rental charge: </label>
233
                    <label for="rentalcharge">Rental charge: </label>
234
                    <input type="text" id="rentalcharge" name="rentalcharge" size="10" value="[% itemtype.rentalcharge | html %]" />
234
                    <input type="text" id="rentalcharge" name="rentalcharge" size="10" value="[% itemtype.rentalcharge | $Price %]" />
235
                    <span class="hint">This fee is charged once per checkout/renewal per item</span>
236
                </li>
237
                <li>
238
                    <label for="rental_charge_daily">Daily rental charge: </label>
239
                    <input type="text" id="rental_charge_daily" name="rental_charge_daily" size="10" value="[% itemtype.rental_charge_daily | $Price %]" />
240
                    <span class="hint">This fee is charged a checkout/renewal time for each day between the checkout/renewal date and due date.</span>
235
                </li>
241
                </li>
236
                <li>
242
                <li>
237
                    <label for="defaultreplacecost">Default replacement cost: </label>
243
                    <label for="defaultreplacecost">Default replacement cost: </label>
Lines 330-336 Item types administration Link Here
330
            <th>Search category</th>
336
            <th>Search category</th>
331
            <th>Not for loan</th>
337
            <th>Not for loan</th>
332
            <th>Hide in OPAC</th>
338
            <th>Hide in OPAC</th>
333
            <th>Charge</th>
339
            <th>Rental charge</th>
340
            <th>Daily rental charge</th>
334
            <th>Default replacement cost</th>
341
            <th>Default replacement cost</th>
335
            <th>Processing fee (when lost)</th>
342
            <th>Processing fee (when lost)</th>
336
            <th>Checkin message</th>
343
            <th>Checkin message</th>
Lines 372-377 Item types administration Link Here
372
              [% itemtype.rentalcharge | $Price %]
379
              [% itemtype.rentalcharge | $Price %]
373
            [% END %]
380
            [% END %]
374
            </td>
381
            </td>
382
            <td>
383
            [% UNLESS ( itemtype.notforloan ) %]
384
              [% itemtype.rental_charge_daily | $Price %]
385
            [% END %]
386
            </td>
375
            <td>[% itemtype.defaultreplacecost | $Price %]</td>
387
            <td>[% itemtype.defaultreplacecost | $Price %]</td>
376
            <td>[% itemtype.processfee | $Price %]</td>
388
            <td>[% itemtype.processfee | $Price %]</td>
377
            <td>[% itemtype.checkinmsg | html_line_break | $raw %]</td>
389
            <td>[% itemtype.checkinmsg | html_line_break | $raw %]</td>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/moredetail.tt (-1 / +3 lines)
Lines 1-4 Link Here
1
[% USE raw %]
1
[% USE raw %]
2
[% USE Price %]
2
[% USE Asset %]
3
[% USE Asset %]
3
[% USE Koha %]
4
[% USE Koha %]
4
[% USE Branches %]
5
[% USE Branches %]
Lines 32-38 Link Here
32
        [% UNLESS ( item_level_itypes ) %]
33
        [% UNLESS ( item_level_itypes ) %]
33
        <li><span class="label">Item type:</span> [% itemtypename | html %]&nbsp;</li>
34
        <li><span class="label">Item type:</span> [% itemtypename | html %]&nbsp;</li>
34
        [% END %]
35
        [% END %]
35
        [% IF ( rentalcharge ) %]<li><span class="label">Rental charge:</span>[% rentalcharge | html %]&nbsp;</li>[% END %]
36
        [% IF ( rentalcharge ) %]<li><span class="label">Rental charge:</span>[% rentalcharge | $Price %]&nbsp;</li>[% END %]
37
        [% IF ( rental_charge_daily ) %]<li><span class="label">Daily rental charge:</span>[% rental_charge_daily | $Price %]&nbsp;</li>[% END %]
36
        <li><span class="label">ISBN:</span> [% isbn | html %]&nbsp;</li>
38
        <li><span class="label">ISBN:</span> [% isbn | html %]&nbsp;</li>
37
        <li><span class="label">Publisher:</span>[% place | html %] [% publishercode | html %] [% publicationyear | html %]&nbsp;</li>
39
        <li><span class="label">Publisher:</span>[% place | html %] [% publishercode | html %] [% publicationyear | html %]&nbsp;</li>
38
        [% IF ( volumeddesc ) %]<li><span class="label">Volume:</span> [% volumeddesc | html %]</li>[% END %]
40
        [% IF ( volumeddesc ) %]<li><span class="label">Volume:</span> [% volumeddesc | html %]</li>[% END %]
(-)a/t/db_dependent/Circulation.t (-3 / +102 lines)
Lines 68-75 my $library2 = $builder->build({ Link Here
68
    source => 'Branch',
68
    source => 'Branch',
69
});
69
});
70
my $itemtype = $builder->build(
70
my $itemtype = $builder->build(
71
    {   source => 'Itemtype',
71
    {
72
        value  => { notforloan => undef, rentalcharge => 0, defaultreplacecost => undef, processfee => undef }
72
        source => 'Itemtype',
73
        value  => {
74
            notforloan          => undef,
75
            rentalcharge        => 0,
76
            rental_charge_daily => 0,
77
            defaultreplacecost  => undef,
78
            processfee          => undef
79
        }
73
    }
80
    }
74
)->{itemtype};
81
)->{itemtype};
75
my $patron_category = $builder->build(
82
my $patron_category = $builder->build(
Lines 2980-2983 sub test_debarment_on_checkout { Link Here
2980
        $expected_expiration_date, 'Test at line ' . $line_number );
2987
        $expected_expiration_date, 'Test at line ' . $line_number );
2981
    Koha::Patron::Debarments::DelUniqueDebarment(
2988
    Koha::Patron::Debarments::DelUniqueDebarment(
2982
        { borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } );
2989
        { borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } );
2983
}
2990
};
2991
2992
subtest 'Koha::ItemType::calc_rental_charge_daily tests' => sub {
2993
    plan tests => 8;
2994
2995
    t::lib::Mocks::mock_preference('item-level_itypes', 1);
2996
2997
    my $library = $builder->build_object( { class => 'Koha::Libraries' } )->store;
2998
2999
    my $module = new Test::MockModule('C4::Context');
3000
    $module->mock('userenv', sub { { branch => $library->id } });
3001
3002
    my $patron = $builder->build_object(
3003
        {
3004
            class => 'Koha::Patrons',
3005
            value => { categorycode => $patron_category->{categorycode} }
3006
        }
3007
    )->store;
3008
3009
    my $itemtype = $builder->build_object(
3010
        {
3011
            class => 'Koha::ItemTypes',
3012
            value  => {
3013
                notforloan          => undef,
3014
                rentalcharge        => 0,
3015
                rental_charge_daily => 1.000000
3016
            }
3017
        }
3018
    )->store;
3019
3020
    my $biblioitem = $builder->build( { source => 'Biblioitem' } );
3021
    my $item = $builder->build_object(
3022
        {
3023
            class => 'Koha::Items',
3024
            value => {
3025
                homebranch       => $library->id,
3026
                holdingbranch    => $library->id,
3027
                notforloan       => 0,
3028
                itemlost         => 0,
3029
                withdrawn        => 0,
3030
                itype            => $itemtype->id,
3031
                biblionumber     => $biblioitem->{biblionumber},
3032
                biblioitemnumber => $biblioitem->{biblioitemnumber},
3033
            }
3034
        }
3035
    )->store;
3036
3037
    is( $itemtype->rental_charge_daily, '1.000000', 'Daily rental charge stored and retreived correctly' );
3038
    is( $item->effective_itemtype, $itemtype->id, "Itemtype set correctly for item");
3039
3040
    my $dt_from = dt_from_string();
3041
    my $dt_to = dt_from_string()->add( days => 7 );
3042
    my $dt_to_renew = dt_from_string()->add( days => 13 );
3043
3044
    t::lib::Mocks::mock_preference('finesCalendar', 'ignoreCalendar');
3045
    my $issue = AddIssue( $patron->unblessed, $item->barcode, $dt_to, undef, $dt_from );
3046
    my $accountline = Koha::Account::Lines->find({ itemnumber => $item->id });
3047
    is( $accountline->amount, '7.000000', "Daily rental charge calulated correctly with finesCalendar = ignoreCalendar" );
3048
    $accountline->delete();
3049
    AddRenewal( $patron->id, $item->id, $library->id, $dt_to_renew, $dt_to );
3050
    $accountline = Koha::Account::Lines->find({ itemnumber => $item->id });
3051
    is( $accountline->amount, '6.000000', "Daily rental charge calulated correctly with finesCalendar = ignoreCalendar, for renewal" );
3052
    $accountline->delete();
3053
    $issue->delete();
3054
3055
    t::lib::Mocks::mock_preference('finesCalendar', 'noFinesWhenClosed');
3056
    $issue = AddIssue( $patron->unblessed, $item->barcode, $dt_to, undef, $dt_from );
3057
    $accountline = Koha::Account::Lines->find({ itemnumber => $item->id });
3058
    is( $accountline->amount, '7.000000', "Daily rental charge calulated correctly with finesCalendar = noFinesWhenClosed" );
3059
    $accountline->delete();
3060
    AddRenewal( $patron->id, $item->id, $library->id, $dt_to_renew, $dt_to );
3061
    $accountline = Koha::Account::Lines->find({ itemnumber => $item->id });
3062
    is( $accountline->amount, '6.000000', "Daily rental charge calulated correctly with finesCalendar = noFinesWhenClosed, for renewal" );
3063
    $accountline->delete();
3064
    $issue->delete();
3065
3066
    my $calendar = C4::Calendar->new( branchcode => $library->id );
3067
    $calendar->insert_week_day_holiday(
3068
        weekday     => 3,
3069
        title       => 'Test holiday',
3070
        description => 'Test holiday'
3071
    );
3072
    $issue = AddIssue( $patron->unblessed, $item->barcode, $dt_to, undef, $dt_from );
3073
    $accountline = Koha::Account::Lines->find({ itemnumber => $item->id });
3074
    is( $accountline->amount, '6.000000', "Daily rental charge calulated correctly with finesCalendar = noFinesWhenClosed and closed Wednesdays" );
3075
    $accountline->delete();
3076
    AddRenewal( $patron->id, $item->id, $library->id, $dt_to_renew, $dt_to );
3077
    $accountline = Koha::Account::Lines->find({ itemnumber => $item->id });
3078
    is( $accountline->amount, '5.000000', "Daily rental charge calulated correctly with finesCalendar = noFinesWhenClosed and closed Wednesdays, for renewal" );
3079
    $accountline->delete();
3080
    $issue->delete();
3081
3082
};
(-)a/t/db_dependent/Koha/ItemTypes.t (-5 / +48 lines)
Lines 19-32 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 24;
23
use Data::Dumper;
22
use Data::Dumper;
24
use Koha::Database;
23
use Test::More tests => 25;
24
25
use t::lib::Mocks;
25
use t::lib::Mocks;
26
use Koha::Items;
27
use Koha::Biblioitems;
28
use t::lib::TestBuilder;
26
use t::lib::TestBuilder;
29
27
28
use C4::Calendar;
29
use Koha::Biblioitems;
30
use Koha::Libraries;
31
use Koha::Database;
32
use Koha::DateUtils qw(dt_from_string);;
33
use Koha::Items;
34
30
BEGIN {
35
BEGIN {
31
    use_ok('Koha::ItemType');
36
    use_ok('Koha::ItemType');
32
    use_ok('Koha::ItemTypes');
37
    use_ok('Koha::ItemTypes');
Lines 144-147 $biblioitem->delete; Link Here
144
149
145
is ( $item_type->can_be_deleted, 1, 'The item type that was being used by the removed item and biblioitem can now be deleted' );
150
is ( $item_type->can_be_deleted, 1, 'The item type that was being used by the removed item and biblioitem can now be deleted' );
146
151
152
subtest 'Koha::ItemType::calc_rental_charge_daily tests' => sub {
153
    plan tests => 4;
154
155
    my $library = Koha::Libraries->search()->next();
156
    my $module = new Test::MockModule('C4::Context');
157
    $module->mock('userenv', sub { { branch => $library->id } });
158
159
    my $itemtype = Koha::ItemType->new(
160
        {
161
            itemtype            => 'type4',
162
            description         => 'description',
163
            rental_charge_daily => 1.00,
164
        }
165
    )->store;
166
167
    is( $itemtype->rental_charge_daily, 1.00, 'Daily rental charge stored and retreived correctly' );
168
169
    my $dt_from = dt_from_string();
170
    my $dt_to = dt_from_string()->add( days => 7 );
171
172
    t::lib::Mocks::mock_preference('finesCalendar', 'ignoreCalendar');
173
    my $charge = $itemtype->calc_rental_charge_daily( { from => $dt_from, to => $dt_to } );
174
    is( $charge, 7.00, "Daily rental charge calulated correctly with finesCalendar = ignoreCalendar" );
175
176
    t::lib::Mocks::mock_preference('finesCalendar', 'noFinesWhenClosed');
177
    $charge = $itemtype->calc_rental_charge_daily( { from => $dt_from, to => $dt_to } );
178
    is( $charge, 7.00, "Daily rental charge calulated correctly with finesCalendar = noFinesWhenClosed" );
179
180
    my $calendar = C4::Calendar->new( branchcode => $library->id );
181
    $calendar->insert_week_day_holiday(
182
        weekday     => 3,
183
        title       => 'Test holiday',
184
        description => 'Test holiday'
185
    );
186
    $charge = $itemtype->calc_rental_charge_daily( { from => $dt_from, to => $dt_to } );
187
    is( $charge, 6.00, "Daily rental charge calulated correctly with finesCalendar = noFinesWhenClosed and closed Wednesdays" );
188
189
};
190
147
$schema->txn_rollback;
191
$schema->txn_rollback;
148
- 

Return to bug 20912