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

(-)a/Koha/Charges/Fees.pm (-2 / +2 lines)
Lines 112-118 sub accumulate_rentalcharge { Link Here
112
    my $calendar = Koha::Calendar->new( branchcode => $self->library->id );
112
    my $calendar = Koha::Calendar->new( branchcode => $self->library->id );
113
113
114
    if ( $units eq 'hours' ) {
114
    if ( $units eq 'hours' ) {
115
        if ( $itemtype->rentalcharge_hourly_calendar && C4::Context->preference('finesCalendar') eq 'noFinesWhenClosed' ) {
115
        if ( $itemtype->rentalcharge_hourly_calendar ) {
116
            $duration = $calendar->hours_between(
116
            $duration = $calendar->hours_between(
117
                $self->from_date->truncate( to => 'minute' ),
117
                $self->from_date->truncate( to => 'minute' ),
118
                $self->to_date->truncate( to => 'minute' )
118
                $self->to_date->truncate( to => 'minute' )
Lines 124-130 sub accumulate_rentalcharge { Link Here
124
        }
124
        }
125
    }
125
    }
126
    else {
126
    else {
127
        if ( $itemtype->rentalcharge_daily_calendar && C4::Context->preference('finesCalendar') eq 'noFinesWhenClosed' ) {
127
        if ( $itemtype->rentalcharge_daily_calendar ) {
128
            $duration =
128
            $duration =
129
              $calendar->days_between( $self->from_date, $self->to_date );
129
              $calendar->days_between( $self->from_date, $self->to_date );
130
        }
130
        }
(-)a/installer/data/mysql/atomicupdate/bug_21443.perl (+4 lines)
Lines 16-21 if( CheckVersion( $DBversion ) ) { Link Here
16
        });
16
        });
17
    }
17
    }
18
18
19
    my $finesCalendar = C4::Context->preference('finesCalendar');
20
    my $value = $finesCalendar eq 'noFinesWhenClosed' ? 1 : 0;
21
    $dbh->do("UPDATE itemtypes SET rentalcharge_hourly_calendar = $value, rentalcharge_daily_calendar = $value");
22
19
    # Always end with this (adjust the bug info)
23
    # Always end with this (adjust the bug info)
20
    SetVersion( $DBversion );
24
    SetVersion( $DBversion );
21
    print "Upgrade to $DBversion done (Bug 21443: Add ability to exclude holidays when calculating rentals fees by time period)\n";
25
    print "Upgrade to $DBversion done (Bug 21443: Add ability to exclude holidays when calculating rentals fees by time period)\n";
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/itemtypes.tt (-2 / +2 lines)
Lines 248-254 Item types administration Link Here
248
                        [% ELSE %]
248
                        [% ELSE %]
249
                            <input type="checkbox" id="rentalcharge_daily_calendar" name="rentalcharge_daily_calendar" value="1" />
249
                            <input type="checkbox" id="rentalcharge_daily_calendar" name="rentalcharge_daily_calendar" value="1" />
250
                        [% END %]
250
                        [% END %]
251
                        <span class="hint">If checked, daily charge will be calculated based on the value of the system preference <i>finesCalendar</i>. If not checked, the fee will be calculated based on the number of days until due, directly.</span>
251
                        <span class="hint">If checked, daily charge will be calculated using the calendar to exclude holidays. If not checked, the fee will be calculated based on the number of days until due, directly.</span>
252
                </li>
252
                </li>
253
                <li>
253
                <li>
254
                    <label for="rentalcharge_hourly">Hourly rental charge: </label>
254
                    <label for="rentalcharge_hourly">Hourly rental charge: </label>
Lines 262-268 Item types administration Link Here
262
                        [% ELSE %]
262
                        [% ELSE %]
263
                            <input type="checkbox" id="rentalcharge_hourly_calendar" name="rentalcharge_hourly_calendar" value="1" />
263
                            <input type="checkbox" id="rentalcharge_hourly_calendar" name="rentalcharge_hourly_calendar" value="1" />
264
                        [% END %]
264
                        [% END %]
265
                        <span class="hint">If checked, hourly charge will be calculated based on the value of the system preference <i>finesCalendar</i>. If not checked, the fee will be calculated based on the number of hours until due, directly.</span>
265
                        <span class="hint">If checked, hourly charge will be calculated using the calendar to exclude holidays. If not checked, the fee will be calculated based on the number of hours until due, directly.</span>
266
                </li>
266
                </li>
267
                <li>
267
                <li>
268
                    <label for="defaultreplacecost">Default replacement cost: </label>
268
                    <label for="defaultreplacecost">Default replacement cost: </label>
(-)a/t/db_dependent/Koha/Charges/Fees.t (-4 / +3 lines)
Lines 408-418 subtest 'accumulate_rentalcharge tests' => sub { Link Here
408
        }
408
        }
409
    );
409
    );
410
410
411
    t::lib::Mocks::mock_preference( 'finesCalendar', 'ignoreCalendar' );
411
    $itemtype->rentalcharge_hourly_calendar(0)->store();
412
    $charge = $fees->accumulate_rentalcharge();
412
    $charge = $fees->accumulate_rentalcharge();
413
    is( $charge, 24.00, 'Hourly rental charge calculated correctly (96h * 0.25u)' );
413
    is( $charge, 24.00, 'Hourly rental charge calculated correctly (96h * 0.25u)' );
414
414
415
    t::lib::Mocks::mock_preference( 'finesCalendar', 'noFinesWhenClosed' );
415
    $itemtype->rentalcharge_hourly_calendar(1)->store();
416
    $charge = $fees->accumulate_rentalcharge();
416
    $charge = $fees->accumulate_rentalcharge();
417
    is( $charge, 18.00,
417
    is( $charge, 18.00,
418
"Hourly rental charge calculated correctly with finesCalendar = noFinesWhenClosed and closed $dayname (96h - 24h * 0.25u)"
418
"Hourly rental charge calculated correctly with finesCalendar = noFinesWhenClosed and closed $dayname (96h - 24h * 0.25u)"
Lines 423-430 subtest 'accumulate_rentalcharge tests' => sub { Link Here
423
    is( $charge, 24.00,
423
    is( $charge, 24.00,
424
"Hourly rental charge calculated correctly with finesCalendar = noFinesWhenClosed and closed $dayname (96h - 24h * 0.25u) and rentalcharge_hourly_calendar = 0"
424
"Hourly rental charge calculated correctly with finesCalendar = noFinesWhenClosed and closed $dayname (96h - 24h * 0.25u) and rentalcharge_hourly_calendar = 0"
425
    );
425
    );
426
    $itemtype->rentalcharge_hourly_calendar(1)->store();
427
426
427
    $itemtype->rentalcharge_hourly_calendar(1)->store();
428
    $calendar->delete_holiday( weekday => $closed_day );
428
    $calendar->delete_holiday( weekday => $closed_day );
429
    $charge = $fees->accumulate_rentalcharge();
429
    $charge = $fees->accumulate_rentalcharge();
430
    is( $charge, 24.00, 'Hourly rental charge calculated correctly with finesCalendar = noFinesWhenClosed (96h - 0h * 0.25u)' );
430
    is( $charge, 24.00, 'Hourly rental charge calculated correctly with finesCalendar = noFinesWhenClosed (96h - 0h * 0.25u)' );
431
- 

Return to bug 21443