- my $daystocharge;
- # get issuingrules (fines part will be used)
- $debug and warn sprintf("CalcFine calling GetIssuingRule(%s, %s, %s)", $bortype, $item->{'itemtype'}, $branchcode);
- my $data = C4::Circulation::GetIssuingRule($bortype, $item->{'itemtype'}, $branchcode);
- if($difference) {
- # if $difference is supplied, the difference has already been calculated, but we still need to adjust for the calendar.
- # use copy-pasted functions from calendar module. (deprecated -- these functions will be removed from C4::Overdues ).
- my $countspecialday = &GetSpecialHolidays($dues,$item->{itemnumber});
- my $countrepeatableday = &GetRepeatableHolidays($dues,$item->{itemnumber},$difference);
- my $countalldayclosed = $countspecialday + $countrepeatableday;
- $daystocharge = $difference - $countalldayclosed;
- } else {
- # if $difference is not supplied, we have C4::Dates objects giving us the date range, and we use the calendar module.
- if(C4::Context->preference('finesCalendar') eq 'noFinesWhenClosed') {
- my $calendar = C4::Calendar->new( branchcode => $branchcode );
- $daystocharge = $calendar->daysBetween( $start_date, $end_date );
- } else {
- $daystocharge = Date_to_Days(split('-',$end_date->output('iso'))) - Date_to_Days(split('-',$start_date->output('iso')));
- }
- }
- # correct for grace period.
- my $days_minus_grace = $daystocharge - $data->{'firstremind'};
- if ($data->{'chargeperiod'} > 0 && $days_minus_grace > 0 ) {
- $amount = int($daystocharge / $data->{'chargeperiod'}) * $data->{'fine'};
+ my $charge_duration;
+ # get issuingrules (fines part will be used)
+ my $data = C4::Circulation::GetIssuingRule($bortype, $item->{itemtype}, $branchcode);
+ if(C4::Context->preference('finesCalendar') eq 'noFinesWhenClosed') {
+ my $calendar = Koha::Calendar->new( branchcode => $branchcode );
+ $charge_duration = $calendar->days_between( $start_date, $end_date );
+ } else {
+ $charge_duration = $end_date - $start_date;
+ }
+ # correct for grace period.
+ my $fine_unit = $data->{lengthunit};
+ $fine_unit ||= 'days';
+ my $chargeable_units;
+ if ($fine_unit eq 'hours') {
+ $chargeable_units = $charge_duration->hours(); # TODO closed times???
+ }
+ else {
+ $chargeable_units = $charge_duration->days;
+ }
+ my $days_minus_grace = $chargeable_units - $data->{firstremind};
+ if ($data->{'chargeperiod'} && $days_minus_grace ) {
+ $amount = int($chargeable_units / $data->{'chargeperiod'}) * $data->{'fine'};# TODO fine calc should be in cents