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

(-)a/C4/Overdues.pm (-20 / +45 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???
263
    my $units_minus_grace = $chargeable_units - $data->{firstremind};
274
    }
264
    my $amount = 0;
275
    else {
265
    if ($data->{'chargeperiod'}  && $units_minus_grace  ) {
276
        $chargeable_units = $charge_duration->days;
277
    }
278
    my $days_minus_grace = $chargeable_units - $data->{firstremind};
279
    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 284-294 sub CalcFine { Link Here
284
    if(C4::Context->preference('maxFine') && ( $amount > C4::Context->preference('maxFine'))) {
270
    if(C4::Context->preference('maxFine') && ( $amount > C4::Context->preference('maxFine'))) {
285
        $amount = C4::Context->preference('maxFine');
271
        $amount = C4::Context->preference('maxFine');
286
    }
272
    }
287
    return ($amount, $data->{chargename}, $days_minus_grace);
273
    return ($amount, $data->{chargename}, $units_minus_grace);
288
    # FIXME: chargename is NEVER populated anywhere.
274
    # FIXME: chargename is NEVER populated anywhere.
289
}
275
}
290
276
291
277
278
=head2 _get_chargeable_units
279
280
    _get_chargeable_units($unit, $start_date_ $end_date, $branchcode);
281
282
return integer value of units between C<$start_date> and C<$end_date>, factoring in holidays for C<$branchcode>.
283
284
C<$unit> is 'days' or 'hours' (default is 'days').
285
286
C<$start_date> and C<$end_date> are the two DateTimes to get the number of units between.
287
288
C<$branchcode> is the branch whose calendar to use for finding holidays.
289
290
=cut
291
292
sub _get_chargeable_units {
293
    my ($unit, $dt1, $dt2, $branchcode) = @_;
294
    my $charge_units = 0;
295
    my $charge_duration;
296
    if ($unit eq 'hours') {
297
        if(C4::Context->preference('finesCalendar') eq 'noFinesWhenClosed') {
298
            my $calendar = Koha::Calendar->new( branchcode => $branchcode );
299
            $charge_duration = $calendar->hours_between( $dt1, $dt2 );
300
        } else {
301
            $charge_duration = $dt2->delta_ms( $dt1 );
302
        }
303
        return $charge_duration->in_units('hours');
304
    }
305
    else { # days
306
        if(C4::Context->preference('finesCalendar') eq 'noFinesWhenClosed') {
307
            my $calendar = Koha::Calendar->new( branchcode => $branchcode );
308
            $charge_duration = $calendar->days_between( $dt1, $dt2 );
309
        } else {
310
            $charge_duration = $dt2->delta_days( $dt1 );
311
        }
312
        return $charge_duration->in_units('days');
313
    }
314
}
315
316
292
=head2 GetSpecialHolidays
317
=head2 GetSpecialHolidays
293
318
294
    &GetSpecialHolidays($date_dues,$itemnumber);
319
    &GetSpecialHolidays($date_dues,$itemnumber);
(-)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