Lines 254-293
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; |
257 |
# get issuingrules (fines part will be used) |
258 |
my $amount = 0; |
258 |
my $data; |
259 |
my $charge_duration; |
259 |
if($item->{itemtype}){ |
260 |
# get issuingrules (fines part will be used) |
260 |
$data = C4::Circulation::GetIssuingRule($bortype, $item->{itemtype}, $branchcode); |
261 |
my $data = C4::Circulation::GetIssuingRule($bortype, $item->{itemtype}, $branchcode); |
261 |
} |
262 |
if(C4::Context->preference('finesCalendar') eq 'noFinesWhenClosed') { |
262 |
else{ |
263 |
my $calendar = Koha::Calendar->new( branchcode => $branchcode ); |
263 |
$data = C4::Circulation::GetIssuingRule($bortype, $item->{itype}, $branchcode); |
264 |
$charge_duration = $calendar->days_between( $start_date, $end_date ); |
|
|
265 |
} else { |
266 |
$charge_duration = $end_date - $start_date; |
267 |
} |
264 |
} |
268 |
# correct for grace period. |
|
|
269 |
my $fine_unit = $data->{lengthunit}; |
265 |
my $fine_unit = $data->{lengthunit}; |
270 |
$fine_unit ||= 'days'; |
266 |
$fine_unit ||= 'days'; |
271 |
my $chargeable_units; |
267 |
|
272 |
if ($fine_unit eq 'hours') { |
268 |
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}; |
269 |
my $days_minus_grace = $chargeable_units - $data->{firstremind}; |
|
|
270 |
my $amount = 0; |
271 |
|
279 |
if ($data->{'chargeperiod'} && $days_minus_grace ) { |
272 |
if ($data->{'chargeperiod'} && $days_minus_grace ) { |
280 |
$amount = int($chargeable_units / $data->{'chargeperiod'}) * $data->{'fine'};# TODO fine calc should be in cents |
273 |
$amount = int($chargeable_units / $data->{'chargeperiod'}) * $data->{'fine'};# TODO fine calc should be in cents |
281 |
} else { |
274 |
} else { |
282 |
# a zero (or null) chargeperiod means no charge. |
275 |
# a zero (or null) chargeperiod means no charge. |
283 |
} |
276 |
} |
284 |
if(C4::Context->preference('maxFine') && ( $amount > C4::Context->preference('maxFine'))) { |
277 |
if(C4::Context->preference('maxFine') && ( $amount > C4::Context->preference('maxFine'))) { |
285 |
$amount = C4::Context->preference('maxFine'); |
278 |
$amount = C4::Context->preference('maxFine'); |
286 |
} |
279 |
} |
287 |
return ($amount, $data->{chargename}, $days_minus_grace); |
280 |
return ($amount, $data->{chargename}, $days_minus_grace); |
288 |
# FIXME: chargename is NEVER populated anywhere. |
281 |
# FIXME: chargename is NEVER populated anywhere. |
289 |
} |
282 |
} |
290 |
|
283 |
|
|
|
284 |
sub _get_chargeable_units { |
285 |
my ($unit, $dt1, $dt2, $branchcode) = @_; |
286 |
my $charge_units = 0; |
287 |
my $charge_duration; |
288 |
if ($unit eq 'hours') { |
289 |
if(C4::Context->preference('finesCalendar') eq 'noFinesWhenClosed') { |
290 |
my $calendar = Koha::Calendar->new( branchcode => $branchcode ); |
291 |
$charge_duration = $calendar->hours_between( $dt1, $dt2 ); |
292 |
} else { |
293 |
$charge_duration = $dt2->delta_ms( $dt1 ); |
294 |
} |
295 |
if($charge_duration->in_units('hours') == 0 && $charge_duration->in_units('seconds') > 0){ |
296 |
return 1; |
297 |
} |
298 |
return $charge_duration->in_units('hours'); |
299 |
} |
300 |
else { # days |
301 |
if(C4::Context->preference('finesCalendar') eq 'noFinesWhenClosed') { |
302 |
my $calendar = Koha::Calendar->new( branchcode => $branchcode ); |
303 |
$charge_duration = $calendar->days_between( $dt1, $dt2 ); |
304 |
} else { |
305 |
$charge_duration = $dt2->delta_days( $dt1 ); |
306 |
} |
307 |
return $charge_duration->in_units('days'); |
308 |
} |
309 |
} |
291 |
|
310 |
|
292 |
=head2 GetSpecialHolidays |
311 |
=head2 GetSpecialHolidays |
293 |
|
312 |
|