use OpenILS::Utils::Penalty;
use POSIX qw(ceil);
use OpenILS::Application::Circ::CircCommon;
+my $CC = "OpenILS::Application::Circ::CircCommon";
use OpenILS::Application::AppUtils;
my $U = "OpenILS::Application::AppUtils";
return undef unless ($id);
my $c_table = action::circulation->table;
my $b_table = money::billing->table;
+ my $p_table = money::void_payment->table;
$log->debug("Retrieving patron summary for id $id", DEBUG);
my $select = <<" SQL";
SELECT COUNT(DISTINCT c.id), SUM( COALESCE(b.amount,0) )
FROM $c_table c
- LEFT OUTER JOIN $b_table b ON (c.id = b.xact AND b.voided = FALSE)
+ LEFT OUTER JOIN $b_table b ON (c.id = b.xact)
+ LEFT OUTER JOIN $p_table p ON (b.id = p.billing)
WHERE c.usr = ?
AND c.xact_finish IS NULL
AND (
c.stop_fines NOT IN ('CLAIMSRETURNED','LOST')
OR c.stop_fines IS NULL
)
+ AND p IS NULL
SQL
return action::survey->db_Main->selectrow_arrayref($select, {}, $id);
" (user ".$c->usr.").\n".
"\tItem was due on or before: ".localtime($due)."\n");
- my @fines = money::billing->search_where(
- { xact => $c->id,
- btype => 1,
- billing_ts => { '>' => $c->$due_date_method } },
- { order_by => 'billing_ts DESC'}
- );
+ # Retrieve the bill_payment_map for the circulation transaction.
+ my $bill_payment_map = $CC->bill_payment_map_for_xact(undef, $c);
- my $f_idx = 0;
- my $fine = $fines[$f_idx] if (@fines);
- if ($overbill) {
- $fine = $fines[++$f_idx] while ($fine and $fine->voided);
- }
+ # Pull out those entries for overdue bills in reverse date order.
+ my @fine_map = sort { $b->bill->billing_ts() <=> $a->bill->billing_ts() }
+ grep { $_->bill->btype() == 1 && $_->bill->billing_ts() > $c->$due_date_method }
+ @{$bill_payment_map};
+ my $f_idx = 0;
my $current_fine_total = 0;
- $current_fine_total += int($_->amount * 100) for (grep { $_ and !$_->voided } @fines);
+ my $fine;
+ if (@fine_map) {
+ if ($overbill) {
+ while ($fine_map[$f_idx] and $fine_map[$f_idx]->void_amount() >= $fine_map[$f_idx]->bill_amount()) {
+ $f_idx++;
+ }
+ }
+ # Set the $fine to be used for $last_fine below.
+ $fine = $fine_map[$f_idx]->bill() if ($fine_map[$f_idx]);
+ # Calculate the current fine total using the modified bill amounts from the bill payment map.
+ map { $current_fine_total += int($_->bill->amount() * 100) }
+ grep { $_->bill_amount() < $_->void_amount() } @fine_map;
+ }
my $last_fine;
if ($fine) {
$log->info( "Potential first billing for circ ".$c->id );
$last_fine = $due;
- $grace_period = OpenILS::Application::Circ::CircCommon->extend_grace_period($c->$circ_lib_method->to_fieldmapper->id,$c->$due_date_method,$grace_period,undef,$hoo{$c->$circ_lib_method});
+ $grace_period = $CC->extend_grace_period($c->$circ_lib_method->to_fieldmapper->id,$c->$due_date_method,$grace_period,undef,$hoo{$c->$circ_lib_method});
}
return if ($last_fine > $now);