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

(-)a/C4/Overdues.pm (-11 / +6 lines)
Lines 292-298 sub get_chargeable_units { Link Here
292
292
293
    my $charge_units = 0;
293
    my $charge_units = 0;
294
    my $charge_duration;
294
    my $charge_duration;
295
    if ($unit eq 'hours') {
296
        if(C4::Context->preference('finesCalendar') eq 'noFinesWhenClosed') {
295
        if(C4::Context->preference('finesCalendar') eq 'noFinesWhenClosed') {
297
            my $calendar = Koha::Calendar->new( branchcode => $branchcode );
296
            my $calendar = Koha::Calendar->new( branchcode => $branchcode );
298
            $charge_duration = $calendar->hours_between( $date_due, $date_returned );
297
            $charge_duration = $calendar->hours_between( $date_due, $date_returned );
Lines 302-317 sub get_chargeable_units { Link Here
302
        if($charge_duration->in_units('hours') == 0 && $charge_duration->in_units('seconds') > 0){
301
        if($charge_duration->in_units('hours') == 0 && $charge_duration->in_units('seconds') > 0){
303
            return 1;
302
            return 1;
304
        }
303
        }
305
        return $charge_duration->in_units('hours');
304
306
    }
305
    my $hours = $charge_duration->in_units('hours');
307
    else { # days
306
    if ($unit eq 'hours') {
308
        if(C4::Context->preference('finesCalendar') eq 'noFinesWhenClosed') {
307
        return $hours;
309
            my $calendar = Koha::Calendar->new( branchcode => $branchcode );
308
    } else {
310
            $charge_duration = $calendar->days_between( $date_due, $date_returned );
309
        return ( $hours > 0 ? ceil($hours / 24) : 0 );
311
        } else {
312
            $charge_duration = $date_returned->delta_days( $date_due );
313
        }
314
        return $charge_duration->in_units('days');
315
    }
310
    }
316
}
311
}
317
312
(-)a/t/db_dependent/Circulation/IssuingRules/maxsuspensiondays.t (-3 / +24 lines)
Lines 1-5 Link Here
1
use Modern::Perl;
1
use Modern::Perl;
2
use Test::More tests => 3;
2
use Test::More tests => 5;
3
3
4
use MARC::Record;
4
use MARC::Record;
5
use MARC::Field;
5
use MARC::Field;
Lines 119-125 $builder->build( Link Here
119
    }
119
    }
120
);
120
);
121
121
122
$daysafter10 = dt_from_string->add_duration(DateTime::Duration->new(days => 10));
123
AddIssue( $borrower, $barcode, $daysago20 );
122
AddIssue( $borrower, $barcode, $daysago20 );
124
AddReturn( $barcode, $branchcode );
123
AddReturn( $barcode, $branchcode );
125
$debarments = GetDebarments({borrowernumber => $borrower->{borrowernumber}});
124
$debarments = GetDebarments({borrowernumber => $borrower->{borrowernumber}});
Lines 130-133 is( Link Here
130
);
129
);
131
DelDebarment( $debarments->[0]->{borrower_debarment_id} );
130
DelDebarment( $debarments->[0]->{borrower_debarment_id} );
132
131
132
my $yesterday = dt_from_string->subtract_duration(DateTime::Duration->new( days => 1 ));
133
my $daysafter2 = dt_from_string->add_duration(DateTime::Duration->new( days => 2 ));
134
AddIssue( $borrower, $barcode, $yesterday);
135
AddReturn( $barcode, $branchcode );
136
$debarments = GetDebarments({borrowernumber => $borrower->{borrowernumber}});
137
is(
138
    $debarments->[0]->{expiration},
139
    output_pref({ dt => $daysafter2, dateformat => 'iso', dateonly => 1 }),
140
    'calculate suspension with lengthunit hours.'
141
);
142
DelDebarment( $debarments->[0]->{borrower_debarment_id} );
143
144
my $hoursago2= dt_from_string->subtract_duration(DateTime::Duration->new(hours => 2));
145
AddIssue( $borrower, $barcode, $hoursago2);
146
AddReturn( $barcode, $branchcode );
147
$debarments = GetDebarments({borrowernumber => $borrower->{borrowernumber}});
148
is(
149
    $debarments->[0]->{expiration},
150
    output_pref({ dt => $daysafter2, dateformat => 'iso', dateonly => 1 }),
151
    'calculate suspension with lengthunit hours.'
152
);
153
DelDebarment( $debarments->[0]->{borrower_debarment_id} );
154
133
$schema->storage->txn_rollback;
155
$schema->storage->txn_rollback;
134
- 

Return to bug 14293