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

(-)a/C4/Overdues.pm (-11 / +6 lines)
Lines 306-312 sub get_chargeable_units { Link Here
306
306
307
    my $charge_units = 0;
307
    my $charge_units = 0;
308
    my $charge_duration;
308
    my $charge_duration;
309
    if ($unit eq 'hours') {
310
        if(C4::Context->preference('finesCalendar') eq 'noFinesWhenClosed') {
309
        if(C4::Context->preference('finesCalendar') eq 'noFinesWhenClosed') {
311
            my $calendar = Koha::Calendar->new( branchcode => $branchcode );
310
            my $calendar = Koha::Calendar->new( branchcode => $branchcode );
312
            $charge_duration = $calendar->hours_between( $date_due, $date_returned );
311
            $charge_duration = $calendar->hours_between( $date_due, $date_returned );
Lines 316-331 sub get_chargeable_units { Link Here
316
        if($charge_duration->in_units('hours') == 0 && $charge_duration->in_units('seconds') > 0){
315
        if($charge_duration->in_units('hours') == 0 && $charge_duration->in_units('seconds') > 0){
317
            return 1;
316
            return 1;
318
        }
317
        }
319
        return $charge_duration->in_units('hours');
318
320
    }
319
    my $hours = $charge_duration->in_units('hours');
321
    else { # days
320
    if ($unit eq 'hours') {
322
        if(C4::Context->preference('finesCalendar') eq 'noFinesWhenClosed') {
321
        return $hours;
323
            my $calendar = Koha::Calendar->new( branchcode => $branchcode );
322
    } else {
324
            $charge_duration = $calendar->days_between( $date_due, $date_returned );
323
        return ( $hours > 0 ? ceil($hours / 24) : 0 );
325
        } else {
326
            $charge_duration = $date_returned->delta_days( $date_due );
327
        }
328
        return $charge_duration->in_units('days');
329
    }
324
    }
330
}
325
}
331
326
(-)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-135 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
156
135
# C4::Context->userenv
157
# C4::Context->userenv
136
- 

Return to bug 14293