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); |