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

(-)a/C4/Circulation.pm (-16 / +32 lines)
Lines 975-980 sub CanBookBeIssued { Link Here
975
975
976
    if ( $rentalConfirmation ){
976
    if ( $rentalConfirmation ){
977
        my ($rentalCharge) = GetIssuingCharges( $item->{'itemnumber'}, $patron->borrowernumber );
977
        my ($rentalCharge) = GetIssuingCharges( $item->{'itemnumber'}, $patron->borrowernumber );
978
        my $itemtype = Koha::ItemTypes->find( $item->{itype} ); # GetItem sets effective itemtype
979
        $rentalCharge += $itemtype->calc_rental_charge_daily( { from => dt_from_string(), to => $duedate } );
978
        if ( $rentalCharge > 0 ){
980
        if ( $rentalCharge > 0 ){
979
            $needsconfirmation{RENTALCHARGE} = $rentalCharge;
981
            $needsconfirmation{RENTALCHARGE} = $rentalCharge;
980
        }
982
        }
Lines 1407-1418 sub AddIssue { Link Here
1407
            ModDateLastSeen( $item->{'itemnumber'} );
1409
            ModDateLastSeen( $item->{'itemnumber'} );
1408
1410
1409
           # If it costs to borrow this book, charge it to the patron's account.
1411
           # If it costs to borrow this book, charge it to the patron's account.
1410
            my ( $charge, $itemtype ) = GetIssuingCharges( $item->{'itemnumber'}, $borrower->{'borrowernumber'} );
1412
            my ( $charge ) = GetIssuingCharges( $item->{'itemnumber'}, $borrower->{'borrowernumber'} );
1411
            if ( $charge > 0 ) {
1413
            if ( $charge > 0 ) {
1412
                AddIssuingCharge( $issue, $charge );
1414
                AddIssuingCharge( $issue, $charge );
1413
                $item->{'charge'} = $charge;
1415
                $item->{'charge'} = $charge;
1414
            }
1416
            }
1415
1417
1418
            my $itemtype = Koha::ItemTypes->find( $item_object->effective_itemtype );
1419
            if ( $itemtype ) {
1420
                my $daily_charge = $itemtype->calc_rental_charge_daily( { from => $issuedate, to => $datedue } );
1421
                if ( $daily_charge > 0 ) {
1422
                    AddIssuingCharge( $issue, $daily_charge, 'Daily rental' ) if $daily_charge > 0;
1423
                    $charge += $daily_charge;
1424
                    $item->{charge} = $charge;
1425
                }
1426
            }
1427
1416
            # Record the fact that this book was issued.
1428
            # Record the fact that this book was issued.
1417
            &UpdateStats(
1429
            &UpdateStats(
1418
                {
1430
                {
Lines 2844-2864 sub AddRenewal { Link Here
2844
    $renews = $item->{renewals} + 1;
2856
    $renews = $item->{renewals} + 1;
2845
    ModItem( { renewals => $renews, onloan => $datedue->strftime('%Y-%m-%d %H:%M')}, $item->{biblionumber}, $itemnumber, { log_action => 0 } );
2857
    ModItem( { renewals => $renews, onloan => $datedue->strftime('%Y-%m-%d %H:%M')}, $item->{biblionumber}, $itemnumber, { log_action => 0 } );
2846
2858
2847
    # Charge a new rental fee, if applicable?
2859
    # Charge a new rental fee, if applicable
2848
    my ( $charge, $type ) = GetIssuingCharges( $itemnumber, $borrowernumber );
2860
    my ( $charge, $type ) = GetIssuingCharges( $itemnumber, $borrowernumber );
2849
    if ( $charge > 0 ) {
2861
    if ( $charge > 0 ) {
2850
        my $accountno = getnextacctno( $borrowernumber );
2862
        my $accountno = getnextacctno( $borrowernumber );
2851
        my $manager_id = 0;
2863
        my $type_desc = "Renewal of Rental Item " . $biblio->title . " $item->{'barcode'}";
2852
        $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; 
2864
        AddIssuingCharge( $issue, $charge, $type_desc )
2853
        $sth = $dbh->prepare(
2865
    }
2854
                "INSERT INTO accountlines
2866
2855
                    (date, borrowernumber, accountno, amount, manager_id,
2867
    # Charge a new daily rental fee, if applicable
2856
                    description,accounttype, amountoutstanding, itemnumber)
2868
    my $itemtype = Koha::ItemTypes->find( $item->{itype} ); # GetItem sets effective itemtype
2857
                    VALUES (now(),?,?,?,?,?,?,?,?)"
2869
    if ( $itemtype ) {
2858
        );
2870
        my $daily_charge = $itemtype->calc_rental_charge_daily( { from => dt_from_string($lastreneweddate), to => $datedue } );
2859
        $sth->execute( $borrowernumber, $accountno, $charge, $manager_id,
2871
        if ( $daily_charge > 0 ) {
2860
            "Renewal of Rental Item " . $biblio->title . " $item->{'barcode'}",
2872
            my $type_desc = "Renewal of Daily Rental Item " . $biblio->title . " $item->{'barcode'}";
2861
            'Rent', $charge, $itemnumber );
2873
            AddIssuingCharge( $issue, $daily_charge, $type_desc )
2874
        }
2875
        $charge += $daily_charge;
2862
    }
2876
    }
2863
2877
2864
    # Send a renewal slip according to checkout alert preferencei
2878
    # Send a renewal slip according to checkout alert preferencei
Lines 3178-3189 sub _get_discount_from_rule { Link Here
3178
3192
3179
=head2 AddIssuingCharge
3193
=head2 AddIssuingCharge
3180
3194
3181
  &AddIssuingCharge( $checkout, $charge )
3195
  &AddIssuingCharge( $checkout, $charge, [$type] )
3182
3196
3183
=cut
3197
=cut
3184
3198
3185
sub AddIssuingCharge {
3199
sub AddIssuingCharge {
3186
    my ( $checkout, $charge ) = @_;
3200
    my ( $checkout, $charge, $type ) = @_;
3201
3202
    $type ||= 'Rental';
3187
3203
3188
    # FIXME What if checkout does not exist?
3204
    # FIXME What if checkout does not exist?
3189
3205
Lines 3201-3207 sub AddIssuingCharge { Link Here
3201
            amount            => $charge,
3217
            amount            => $charge,
3202
            amountoutstanding => $charge,
3218
            amountoutstanding => $charge,
3203
            manager_id        => $manager_id,
3219
            manager_id        => $manager_id,
3204
            description       => 'Rental',
3220
            description       => $type,
3205
            accounttype       => 'Rent',
3221
            accounttype       => 'Rent',
3206
            date              => \'NOW()',
3222
            date              => \'NOW()',
3207
        }
3223
        }
(-)a/Koha/ItemType.pm (+33 lines)
Lines 89-94 sub translated_descriptions { Link Here
89
    } @translated_descriptions ];
89
    } @translated_descriptions ];
90
}
90
}
91
91
92
=head3 calc_rental_charge_daily
93
94
    my $fee = $itemtype->calc_rental_charge_daily( { from => $dt_from, to => $dt_to } );
95
96
    This method calculates the daily rental fee for a given itemtype for a given
97
    period of time passed in as a pair of DateTime objects.
98
99
=cut
100
101
sub calc_rental_charge_daily {
102
    my ( $self, $params ) = @_;
103
104
    my $rental_charge_daily = $self->rental_charge_daily;
105
    return 0 unless $rental_charge_daily;
106
107
    my $from_dt = $params->{from};
108
    my $to_dt   = $params->{to};
109
110
    my $duration;
111
    if ( C4::Context->preference('finesCalendar') eq 'noFinesWhenClosed' ) {
112
        my $branchcode = C4::Context->userenv->{branch};
113
        my $calendar = Koha::Calendar->new( branchcode => $branchcode );
114
        $duration = $calendar->days_between( $from_dt, $to_dt );
115
    }
116
    else {
117
        $duration = $to_dt->delta_days($from_dt);
118
    }
119
    my $days = $duration->in_units('days');
120
121
    my $charge = $rental_charge_daily * $days;
122
123
    return $charge;
124
}
92
125
93
126
94
=head3 can_be_deleted
127
=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 125-131 my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_l Link Here
125
125
126
$data->{'itemtypename'} = $itemtypes->{ $data->{'itemtype'} }->{'translated_description'}
126
$data->{'itemtypename'} = $itemtypes->{ $data->{'itemtype'} }->{'translated_description'}
127
  if $data->{itemtype} && exists $itemtypes->{ $data->{itemtype} };
127
  if $data->{itemtype} && exists $itemtypes->{ $data->{itemtype} };
128
$data->{'rentalcharge'} = sprintf( "%.2f", $data->{'rentalcharge'} || 0); # Price formatting should be done template-side
129
foreach ( keys %{$data} ) {
128
foreach ( keys %{$data} ) {
130
    $template->param( "$_" => defined $data->{$_} ? $data->{$_} : '' );
129
    $template->param( "$_" => defined $data->{$_} ? $data->{$_} : '' );
131
}
130
}
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/itemtypes.tt (-6 / +20 lines)
Lines 139-145 Item types administration Link Here
139
                            [% END %]
139
                            [% END %]
140
                        [% END %]
140
                        [% END %]
141
                    </select>
141
                    </select>
142
                    (Options are defined as the authorized values for the ITEMTYPECAT category)
142
                    <span class="hint">Options are defined as the authorized values for the ITEMTYPECAT category.</span>
143
                </li>
143
                </li>
144
                [% IF Koha.Preference('noItemTypeImages') %]
144
                [% IF Koha.Preference('noItemTypeImages') %]
145
                    <li>
145
                    <li>
Lines 219-225 Item types administration Link Here
219
                    [% ELSE %]
219
                    [% ELSE %]
220
                        <input type="checkbox" id="hideinopac" name="hideinopac" value="1" />
220
                        <input type="checkbox" id="hideinopac" name="hideinopac" value="1" />
221
                    [% END %]
221
                    [% END %]
222
                    (if checked, items of this type will be hidden as filters in OPAC's advanced search)
222
                    <span class="hint">If checked, items of this type will be hidden as filters in OPAC's advanced search.</span>
223
                </li>
223
                </li>
224
                <li>
224
                <li>
225
                    <label for="notforloan">Not for loan: </label>
225
                    <label for="notforloan">Not for loan: </label>
Lines 228-238 Item types administration Link Here
228
                        [% ELSE %]
228
                        [% ELSE %]
229
                            <input type="checkbox" id="notforloan" name="notforloan" value="1" />
229
                            <input type="checkbox" id="notforloan" name="notforloan" value="1" />
230
                        [% END %]
230
                        [% END %]
231
                      (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)
231
                        <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>
232
                </li>
232
                </li>
233
                <li>
233
                <li>
234
                    <label for="rentalcharge">Rental charge: </label>
234
                    <label for="rentalcharge">Rental charge: </label>
235
                    <input type="text" id="rentalcharge" name="rentalcharge" size="10" value="[% itemtype.rentalcharge %]" />
235
                    <input type="text" id="rentalcharge" name="rentalcharge" size="10" value="[% itemtype.rentalcharge %]" />
236
                    <span class="hint">This fee is charged once per checkout/renewal per item</span>
237
                </li>
238
                <li>
239
                    <label for="rental_charge_daily">Daily rental charge: </label>
240
                    <input type="text" id="rental_charge_daily" name="rental_charge_daily" size="10" value="[% itemtype.rental_charge_daily %]" />
241
                    <span class="hint">This fee is charged a checkout/renewal time for each day between the checkout/renewal date and due date.</span>
236
                </li>
242
                </li>
237
                <li>
243
                <li>
238
                    <label for="defaultreplacecost">Default replacement cost: </label>
244
                    <label for="defaultreplacecost">Default replacement cost: </label>
Lines 277-284 Item types administration Link Here
277
                <li>
283
                <li>
278
                    <label for="summary">Summary: </label>
284
                    <label for="summary">Summary: </label>
279
                   <textarea id="summary" name="summary" cols="55" rows="5">[% itemtype.summary %]</textarea>
285
                   <textarea id="summary" name="summary" cols="55" rows="5">[% itemtype.summary %]</textarea>
280
                    <p>Enter a summary that will overwrite the default one in search results lists. Example, for a website itemtype : </p>
286
                    <p class="hint">
281
                    <p><b>&lt;a href="[856u]"&gt;open site&lt;/a&gt;</b> will show the link just below the title</p>
287
                        Enter a summary that will overwrite the default one in search results lists. For example, for a website itemtype,
288
                        <b>&lt;a href="[856u]"&gt;open site&lt;/a&gt;</b> will show the link just below the title.
289
                    </p>
282
                </li>
290
                </li>
283
            </ol>
291
            </ol>
284
        </fieldset>
292
        </fieldset>
Lines 331-337 Item types administration Link Here
331
            <th>Search category</th>
339
            <th>Search category</th>
332
            <th>Not for loan</th>
340
            <th>Not for loan</th>
333
            <th>Hide in OPAC</th>
341
            <th>Hide in OPAC</th>
334
            <th>Charge</th>
342
            <th>Rental charge</th>
343
            <th>Daily rental charge</th>
335
            <th>Default replacement cost</th>
344
            <th>Default replacement cost</th>
336
            <th>Processing fee (when lost)</th>
345
            <th>Processing fee (when lost)</th>
337
            <th>Checkin message</th>
346
            <th>Checkin message</th>
Lines 373-378 Item types administration Link Here
373
              [% itemtype.rentalcharge | $Price %]
382
              [% itemtype.rentalcharge | $Price %]
374
            [% END %]
383
            [% END %]
375
            </td>
384
            </td>
385
            <td>
386
            [% UNLESS ( itemtype.notforloan ) %]
387
              [% itemtype.rental_charge_daily | $Price %]
388
            [% END %]
389
            </td>
376
            <td>[% itemtype.defaultreplacecost | $Price %]</td>
390
            <td>[% itemtype.defaultreplacecost | $Price %]</td>
377
            <td>[% itemtype.processfee | $Price %]</td>
391
            <td>[% itemtype.processfee | $Price %]</td>
378
            <td>[% itemtype.checkinmsg | html | html_line_break %]</td>
392
            <td>[% itemtype.checkinmsg | html | html_line_break %]</td>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/moredetail.tt (-1 / +3 lines)
Lines 1-3 Link Here
1
[% USE Price %]
1
[% USE Asset %]
2
[% USE Asset %]
2
[% USE Koha %]
3
[% USE Koha %]
3
[% USE Branches %]
4
[% USE Branches %]
Lines 31-37 Link Here
31
        [% UNLESS ( item_level_itypes ) %]
32
        [% UNLESS ( item_level_itypes ) %]
32
        <li><span class="label">Item type:</span> [% itemtypename %]&nbsp;</li>
33
        <li><span class="label">Item type:</span> [% itemtypename %]&nbsp;</li>
33
        [% END %]
34
        [% END %]
34
        [% IF ( rentalcharge ) %]<li><span class="label">Rental charge:</span>[% rentalcharge %]&nbsp;</li>[% END %]
35
        [% IF ( rentalcharge ) %]<li><span class="label">Rental charge:</span>[% rentalcharge | $Price %]&nbsp;</li>[% END %]
36
        [% IF ( rental_charge_daily ) %]<li><span class="label">Daily rental charge:</span>[% rental_charge_daily | $Price %]&nbsp;</li>[% END %]
35
        <li><span class="label">ISBN:</span> [% isbn | html %]&nbsp;</li>
37
        <li><span class="label">ISBN:</span> [% isbn | html %]&nbsp;</li>
36
        <li><span class="label">Publisher:</span>[% place %] [% publishercode |html %] [% publicationyear %]&nbsp;</li>
38
        <li><span class="label">Publisher:</span>[% place %] [% publishercode |html %] [% publicationyear %]&nbsp;</li>
37
        [% IF ( volumeddesc ) %]<li><span class="label">Volume:</span> [% volumeddesc %]</li>[% END %]
39
        [% IF ( volumeddesc ) %]<li><span class="label">Volume:</span> [% volumeddesc %]</li>[% END %]
(-)a/t/db_dependent/Circulation.t (-4 / +103 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 118;
20
use Test::More tests => 119;
21
21
22
use DateTime;
22
use DateTime;
23
use POSIX qw( floor );
23
use POSIX qw( floor );
Lines 64-71 my $library2 = $builder->build({ Link Here
64
    source => 'Branch',
64
    source => 'Branch',
65
});
65
});
66
my $itemtype = $builder->build(
66
my $itemtype = $builder->build(
67
    {   source => 'Itemtype',
67
    {
68
        value  => { notforloan => undef, rentalcharge => 0, defaultreplacecost => undef, processfee => undef }
68
        source => 'Itemtype',
69
        value  => {
70
            notforloan          => undef,
71
            rentalcharge        => 0,
72
            rental_charge_daily => 0,
73
            defaultreplacecost  => undef,
74
            processfee          => undef
75
        }
69
    }
76
    }
70
)->{itemtype};
77
)->{itemtype};
71
my $patron_category = $builder->build(
78
my $patron_category = $builder->build(
Lines 2416-2419 sub test_debarment_on_checkout { Link Here
2416
        $expected_expiration_date, 'Test at line ' . $line_number );
2423
        $expected_expiration_date, 'Test at line ' . $line_number );
2417
    Koha::Patron::Debarments::DelUniqueDebarment(
2424
    Koha::Patron::Debarments::DelUniqueDebarment(
2418
        { borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } );
2425
        { borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } );
2419
}
2426
};
2427
2428
subtest 'Koha::ItemType::calc_rental_charge_daily tests' => sub {
2429
    plan tests => 8;
2430
2431
    t::lib::Mocks::mock_preference('item-level_itypes', 1);
2432
2433
    my $library = $builder->build_object( { class => 'Koha::Libraries' } )->store;
2434
2435
    my $module = new Test::MockModule('C4::Context');
2436
    $module->mock('userenv', sub { { branch => $library->id } });
2437
2438
    my $patron = $builder->build_object(
2439
        {
2440
            class => 'Koha::Patrons',
2441
            value => { categorycode => $patron_category->{categorycode} }
2442
        }
2443
    )->store;
2444
2445
    my $itemtype = $builder->build_object(
2446
        {
2447
            class => 'Koha::ItemTypes',
2448
            value  => {
2449
                notforloan          => undef,
2450
                rentalcharge        => 0,
2451
                rental_charge_daily => 1.000000
2452
            }
2453
        }
2454
    )->store;
2455
2456
    my $biblioitem = $builder->build( { source => 'Biblioitem' } );
2457
    my $item = $builder->build_object(
2458
        {
2459
            class => 'Koha::Items',
2460
            value => {
2461
                homebranch       => $library->id,
2462
                holdingbranch    => $library->id,
2463
                notforloan       => 0,
2464
                itemlost         => 0,
2465
                withdrawn        => 0,
2466
                itype            => $itemtype->id,
2467
                biblionumber     => $biblioitem->{biblionumber},
2468
                biblioitemnumber => $biblioitem->{biblioitemnumber},
2469
            }
2470
        }
2471
    )->store;
2472
2473
    is( $itemtype->rental_charge_daily, '1.000000', 'Daily rental charge stored and retreived correctly' );
2474
    is( $item->effective_itemtype, $itemtype->id, "Itemtype set correctly for item");
2475
2476
    my $dt_from = dt_from_string();
2477
    my $dt_to = dt_from_string()->add( days => 7 );
2478
    my $dt_to_renew = dt_from_string()->add( days => 13 );
2479
2480
    t::lib::Mocks::mock_preference('finesCalendar', 'ignoreCalendar');
2481
    my $issue = AddIssue( $patron->unblessed, $item->barcode, $dt_to, undef, $dt_from );
2482
    my $accountline = Koha::Account::Lines->find({ itemnumber => $item->id });
2483
    is( $accountline->amount, '7.000000', "Daily rental charge calulated correctly with finesCalendar = ignoreCalendar" );
2484
    $accountline->delete();
2485
    AddRenewal( $patron->id, $item->id, $library->id, $dt_to_renew, $dt_to );
2486
    $accountline = Koha::Account::Lines->find({ itemnumber => $item->id });
2487
    is( $accountline->amount, '6.000000', "Daily rental charge calulated correctly with finesCalendar = ignoreCalendar, for renewal" );
2488
    $accountline->delete();
2489
    $issue->delete();
2490
2491
    t::lib::Mocks::mock_preference('finesCalendar', 'noFinesWhenClosed');
2492
    $issue = AddIssue( $patron->unblessed, $item->barcode, $dt_to, undef, $dt_from );
2493
    $accountline = Koha::Account::Lines->find({ itemnumber => $item->id });
2494
    is( $accountline->amount, '7.000000', "Daily rental charge calulated correctly with finesCalendar = noFinesWhenClosed" );
2495
    $accountline->delete();
2496
    AddRenewal( $patron->id, $item->id, $library->id, $dt_to_renew, $dt_to );
2497
    $accountline = Koha::Account::Lines->find({ itemnumber => $item->id });
2498
    is( $accountline->amount, '6.000000', "Daily rental charge calulated correctly with finesCalendar = noFinesWhenClosed, for renewal" );
2499
    $accountline->delete();
2500
    $issue->delete();
2501
2502
    my $calendar = C4::Calendar->new( branchcode => $library->id );
2503
    $calendar->insert_week_day_holiday(
2504
        weekday     => 3,
2505
        title       => 'Test holiday',
2506
        description => 'Test holiday'
2507
    );
2508
    $issue = AddIssue( $patron->unblessed, $item->barcode, $dt_to, undef, $dt_from );
2509
    $accountline = Koha::Account::Lines->find({ itemnumber => $item->id });
2510
    is( $accountline->amount, '6.000000', "Daily rental charge calulated correctly with finesCalendar = noFinesWhenClosed and closed Wednesdays" );
2511
    $accountline->delete();
2512
    AddRenewal( $patron->id, $item->id, $library->id, $dt_to_renew, $dt_to );
2513
    $accountline = Koha::Account::Lines->find({ itemnumber => $item->id });
2514
    is( $accountline->amount, '5.000000', "Daily rental charge calulated correctly with finesCalendar = noFinesWhenClosed and closed Wednesdays, for renewal" );
2515
    $accountline->delete();
2516
    $issue->delete();
2517
2518
};
(-)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