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

(-)a/C4/Overdues.pm (-17 / +27 lines)
Lines 226-253 or "Final Notice". But CalcFine never defined any value. Link Here
226
sub CalcFine {
226
sub CalcFine {
227
    my ( $item, $bortype, $branchcode, $due_dt, $end_date  ) = @_;
227
    my ( $item, $bortype, $branchcode, $due_dt, $end_date  ) = @_;
228
    my $start_date = $due_dt->clone();
228
    my $start_date = $due_dt->clone();
229
    my $dbh = C4::Context->dbh;
230
    my $amount = 0;
231
    my $charge_duration;
232
    # get issuingrules (fines part will be used)
229
    # get issuingrules (fines part will be used)
233
    my $data = C4::Circulation::GetIssuingRule($bortype, $item->{itemtype}, $branchcode);
230
    my $data = C4::Circulation::GetIssuingRule($bortype, $item->{itemtype}, $branchcode);
234
    if(C4::Context->preference('finesCalendar') eq 'noFinesWhenClosed') {
235
        my $calendar = Koha::Calendar->new( branchcode => $branchcode );
236
        $charge_duration = $calendar->days_between( $start_date, $end_date );
237
    } else {
238
        $charge_duration = $end_date - $start_date;
239
    }
240
    # correct for grace period.
241
    my $fine_unit = $data->{lengthunit};
231
    my $fine_unit = $data->{lengthunit};
242
    $fine_unit ||= 'days';
232
    $fine_unit ||= 'days';
243
    my $chargeable_units;
233
244
    if ($fine_unit eq 'hours') {
234
    my $chargeable_units = _get_chargeable_units($fine_unit, $start_date, $end_date, $branchcode);
245
        $chargeable_units = $charge_duration->hours(); # TODO closed times???
246
    }
247
    else {
248
        $chargeable_units = $charge_duration->days;
249
    }
250
    my $days_minus_grace = $chargeable_units - $data->{firstremind};
235
    my $days_minus_grace = $chargeable_units - $data->{firstremind};
236
    my $amount = 0;
251
    if ($data->{'chargeperiod'}  && $days_minus_grace  ) { 
237
    if ($data->{'chargeperiod'}  && $days_minus_grace  ) { 
252
        $amount = int($chargeable_units / $data->{'chargeperiod'}) * $data->{'fine'};# TODO fine calc should be in cents
238
        $amount = int($chargeable_units / $data->{'chargeperiod'}) * $data->{'fine'};# TODO fine calc should be in cents
253
    } else {
239
    } else {
Lines 260-265 sub CalcFine { Link Here
260
    # FIXME: chargename is NEVER populated anywhere.
246
    # FIXME: chargename is NEVER populated anywhere.
261
}
247
}
262
248
249
sub _get_chargeable_units {
250
    my ($unit, $dt1, $dt2, $branchcode) = @_;
251
    my $charge_units = 0;
252
    my $charge_duration;
253
    if ($unit eq 'hours') {
254
        if(C4::Context->preference('finesCalendar') eq 'noFinesWhenClosed') {
255
            my $calendar = Koha::Calendar->new( branchcode => $branchcode );
256
            $charge_duration = $calendar->hours_between( $dt1, $dt2 );
257
        } else {
258
            $charge_duration = $dt2->delta_ms( $dt1 );
259
        }
260
        return $charge_duration->in_units('hours');
261
    }
262
    else { # days
263
        if(C4::Context->preference('finesCalendar') eq 'noFinesWhenClosed') {
264
            my $calendar = Koha::Calendar->new( branchcode => $branchcode );
265
            $charge_duration = $calendar->days_between( $dt1, $dt2 );
266
        } else {
267
            $charge_duration = $dt2->delta_days( $dt1 );
268
        }
269
        return $charge_duration->in_units('days');
270
    }
271
}
272
263
273
264
=head2 GetSpecialHolidays
274
=head2 GetSpecialHolidays
265
275
(-)a/Koha/Calendar.pm (-4 / +20 lines)
Lines 167-177 sub days_between { Link Here
167
    my $self     = shift;
167
    my $self     = shift;
168
    my $start_dt = shift;
168
    my $start_dt = shift;
169
    my $end_dt   = shift;
169
    my $end_dt   = shift;
170
    $start_dt->truncate( to => 'hours' );
171
    $end_dt->truncate( to => 'hours' );
172
170
173
    # start and end should not be closed days
171
    # start and end should not be closed days
174
    my $duration = $end_dt - $start_dt;
172
    my $duration = $end_dt->delta_days($start_dt);
175
    $start_dt->truncate( to => 'days' );
173
    $start_dt->truncate( to => 'days' );
176
    $end_dt->truncate( to => 'days' );
174
    $end_dt->truncate( to => 'days' );
177
    while ( DateTime->compare( $start_dt, $end_dt ) == -1 ) {
175
    while ( DateTime->compare( $start_dt, $end_dt ) == -1 ) {
Lines 184-189 sub days_between { Link Here
184
182
185
}
183
}
186
184
185
sub hours_between {
186
    my ($self, $start_dt, $end_dt) = @_;
187
    my $duration = $end_dt->delta_ms($start_dt);
188
    $start_dt->truncate( to => 'days' );
189
    $end_dt->truncate( to => 'days' );
190
    # NB this is a kludge in that it assumes all days are 24 hours
191
    # However for hourly loans the logic should be expanded to
192
    # take into account open/close times then it would be a duration
193
    # of library open hours
194
    while ( DateTime->compare( $start_dt, $end_dt ) == -1 ) {
195
        $start_dt->add( days => 1 );
196
        if ( $self->is_holiday($start_dt) ) {
197
            $duration->subtract( hours => 24 );
198
        }
199
    }
200
    return $duration;
201
202
}
203
187
sub _mockinit {
204
sub _mockinit {
188
    my $self = shift;
205
    my $self = shift;
189
    $self->{weekly_closed_days} = [ 1, 0, 0, 0, 0, 0, 0 ];    # Sunday only
206
    $self->{weekly_closed_days} = [ 1, 0, 0, 0, 0, 0, 0 ];    # Sunday only
190
- 

Return to bug 7852