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

(-)a/C4/Overdues.pm (-18 / +28 lines)
Lines 254-282 or "Final Notice". But CalcFine never defined any value. Link Here
254
sub CalcFine {
254
sub CalcFine {
255
    my ( $item, $bortype, $branchcode, $due_dt, $end_date  ) = @_;
255
    my ( $item, $bortype, $branchcode, $due_dt, $end_date  ) = @_;
256
    my $start_date = $due_dt->clone();
256
    my $start_date = $due_dt->clone();
257
    my $dbh = C4::Context->dbh;
258
    my $amount = 0;
259
    my $charge_duration;
260
    # get issuingrules (fines part will be used)
257
    # get issuingrules (fines part will be used)
261
    my $data = C4::Circulation::GetIssuingRule($bortype, $item->{itemtype}, $branchcode);
258
    my $data = C4::Circulation::GetIssuingRule($bortype, $item->{itemtype}, $branchcode);
262
    if(C4::Context->preference('finesCalendar') eq 'noFinesWhenClosed') {
263
        my $calendar = Koha::Calendar->new( branchcode => $branchcode );
264
        $charge_duration = $calendar->days_between( $start_date, $end_date );
265
    } else {
266
        $charge_duration = $end_date - $start_date;
267
    }
268
    # correct for grace period.
269
    my $fine_unit = $data->{lengthunit};
259
    my $fine_unit = $data->{lengthunit};
270
    $fine_unit ||= 'days';
260
    $fine_unit ||= 'days';
271
    my $chargeable_units;
261
272
    if ($fine_unit eq 'hours') {
262
    my $chargeable_units = _get_chargeable_units($fine_unit, $start_date, $end_date, $branchcode);
273
        $chargeable_units = $charge_duration->hours(); # TODO closed times???
274
    }
275
    else {
276
        $chargeable_units = $charge_duration->days;
277
    }
278
    my $days_minus_grace = $chargeable_units - $data->{firstremind};
263
    my $days_minus_grace = $chargeable_units - $data->{firstremind};
279
    if ($data->{'chargeperiod'}  && $days_minus_grace  ) {
264
    my $amount = 0;
265
    if ($data->{'chargeperiod'}  && $days_minus_grace  ) { 
280
        $amount = int($chargeable_units / $data->{'chargeperiod'}) * $data->{'fine'};# TODO fine calc should be in cents
266
        $amount = int($chargeable_units / $data->{'chargeperiod'}) * $data->{'fine'};# TODO fine calc should be in cents
281
    } else {
267
    } else {
282
        # a zero (or null)  chargeperiod means no charge.
268
        # a zero (or null)  chargeperiod means no charge.
Lines 288-293 sub CalcFine { Link Here
288
    # FIXME: chargename is NEVER populated anywhere.
274
    # FIXME: chargename is NEVER populated anywhere.
289
}
275
}
290
276
277
sub _get_chargeable_units {
278
    my ($unit, $dt1, $dt2, $branchcode) = @_;
279
    my $charge_units = 0;
280
    my $charge_duration;
281
    if ($unit eq 'hours') {
282
        if(C4::Context->preference('finesCalendar') eq 'noFinesWhenClosed') {
283
            my $calendar = Koha::Calendar->new( branchcode => $branchcode );
284
            $charge_duration = $calendar->hours_between( $dt1, $dt2 );
285
        } else {
286
            $charge_duration = $dt2->delta_ms( $dt1 );
287
        }
288
        return $charge_duration->in_units('hours');
289
    }
290
    else { # days
291
        if(C4::Context->preference('finesCalendar') eq 'noFinesWhenClosed') {
292
            my $calendar = Koha::Calendar->new( branchcode => $branchcode );
293
            $charge_duration = $calendar->days_between( $dt1, $dt2 );
294
        } else {
295
            $charge_duration = $dt2->delta_days( $dt1 );
296
        }
297
        return $charge_duration->in_units('days');
298
    }
299
}
300
291
301
292
=head2 GetSpecialHolidays
302
=head2 GetSpecialHolidays
293
303
(-)a/Koha/Calendar.pm (-4 / +20 lines)
Lines 168-178 sub days_between { Link Here
168
    my $self     = shift;
168
    my $self     = shift;
169
    my $start_dt = shift;
169
    my $start_dt = shift;
170
    my $end_dt   = shift;
170
    my $end_dt   = shift;
171
    $start_dt->truncate( to => 'hours' );
172
    $end_dt->truncate( to => 'hours' );
173
171
174
    # start and end should not be closed days
172
    # start and end should not be closed days
175
    my $duration = $end_dt - $start_dt;
173
    my $duration = $end_dt->delta_days($start_dt);
176
    $start_dt->truncate( to => 'days' );
174
    $start_dt->truncate( to => 'days' );
177
    $end_dt->truncate( to => 'days' );
175
    $end_dt->truncate( to => 'days' );
178
    while ( DateTime->compare( $start_dt, $end_dt ) == -1 ) {
176
    while ( DateTime->compare( $start_dt, $end_dt ) == -1 ) {
Lines 185-190 sub days_between { Link Here
185
183
186
}
184
}
187
185
186
sub hours_between {
187
    my ($self, $start_dt, $end_dt) = @_;
188
    my $duration = $end_dt->delta_ms($start_dt);
189
    $start_dt->truncate( to => 'days' );
190
    $end_dt->truncate( to => 'days' );
191
    # NB this is a kludge in that it assumes all days are 24 hours
192
    # However for hourly loans the logic should be expanded to
193
    # take into account open/close times then it would be a duration
194
    # of library open hours
195
    while ( DateTime->compare( $start_dt, $end_dt ) == -1 ) {
196
        $start_dt->add( days => 1 );
197
        if ( $self->is_holiday($start_dt) ) {
198
            $duration->subtract( hours => 24 );
199
        }
200
    }
201
    return $duration;
202
203
}
204
188
sub _mockinit {
205
sub _mockinit {
189
    my $self = shift;
206
    my $self = shift;
190
    $self->{weekly_closed_days} = [ 1, 0, 0, 0, 0, 0, 0 ];    # Sunday only
207
    $self->{weekly_closed_days} = [ 1, 0, 0, 0, 0, 0, 0 ];    # Sunday only
191
- 

Return to bug 7852