use OpenSRF::Application;
use OpenSRF::Utils::SettingsClient;
use OpenILS::Utils::Fieldmapper;
-use OpenSRF::Utils;
+use OpenSRF::Utils qw/:datetime/;
use DateTime;
use DateTime::Format::ISO8601;
use Data::Dumper;
while (!$req->failed && (my $res = $req->recv)) {
my $c = $res->content;
- print "ARG! Overdue circulation ".$c->id.
+ my $due_dt = $parser->parse_datetime( clense_ISO8601( $c->due_date ) );
+
+ my $due = $due_dt->epoch;
+ my $now = time;
+ my $fine_interval = interval_to_seconds( $c->fine_interval );
+
+ if ( interval_to_seconds( $c->fine_interval ) >= interval_to_seconds('1d') ) {
+ my $tz_offset_s = 0;;
+ if ($due_dt->strftime('%z') =~ /(-|\+)(\d{2}):?(\d{2})/) {
+ $tz_offset_s = $1 . interval_to_seconds( "${2}h ${3}m");
+ }
+
+ $due -= ($due % $fine_interval) + $tz_offset_s;
+ $now -= ($now % $fine_interval) + $tz_offset_s;
+ }
+
+ print "\nARG! Overdue circulation ".$c->id.
" for item ".$c->target_copy.
- " (user ".$c->usr.")".
- " : it was due at ".$c->due_date."\n";
+ " (user ".$c->usr.").\n".
+ "\tItem was due on or before: ".localtime($due)."\n";
my $fine = $session->request(
'open-ils.storage.direct.money.billing.search.xact',
$c->id, { order_by => 'billing_ts DESC', limit => '1' }
)->gather(1);
- my $now = time;
- my $fine_interval = OpenSRF::Utils->interval_to_seconds( $c->fine_interval );
-
my $last_fine;
if ($fine) {
- $last_fine = $parser->parse_datetime( OpenSRF::Utils->clense_ISO8601( $fine->billing_ts ) )->epoch;
+ $last_fine = $parser->parse_datetime( clense_ISO8601( $fine->billing_ts ) )->epoch;
} else {
- # Use Date::Manip here
- $last_fine = $parser->parse_datetime( OpenSRF::Utils->clense_ISO8601( $c->due_date ) )->epoch;
- $last_fine += $fine_interval if ($grace);
+ $last_fine = $due;
+ $last_fine += $fine_interval * $grace;
}
my $pending_fine_count = int( ($now - $last_fine) / $fine_interval );
- next unless($pending_fine_count);
+ unless($pending_fine_count) {
+ print "\tNo fines to create. ";
+ if ($grace && $now < $due + $fine_interval * $grace) {
+ print "Still inside grace period of: ".
+ seconds_to_interval( $fine_interval * $grace)."\n";
+ } else {
+ print "Last fine generated for: ".localtime($last_fine)."\n";
+ }
+ next;
+ }
print "\t$pending_fine_count pending fine(s)\n";
if ($total && $total->balance_owed > $c->max_fine) {
$c->stop_fines('MAXFINES');
-
- $session->request(
- 'open-ils.storage.direct.action.circulation.update',
- $c
- )->gather(1);
-
+ $session->request( 'open-ils.storage.direct.action.circulation.update', $c )->gather(1);
+ print "\tMaximum fine level of ".$c->max_fine." reached for this circulation.\n\tNo more fines will be generated.\n";
last;
}
$billing->xact( $c->id );
$billing->note( "Overdue Fine" );
$billing->amount( $c->recuring_fine );
+
$billing->billing_ts(
- DateTime->from_epoch(
- epoch => $last_fine + $fine_interval * $bill
- )->strftime('%FT%T%z')
+ DateTime->from_epoch( epoch => $last_fine + $fine_interval * $bill )->strftime('%FT%T%z')
);
- $session->request(
- 'open-ils.storage.direct.money.billing.create',
- $billing
- )->gather(1);
+ print "\t\tCreating fine of ".$billing->amount." for period starting ".
+ localtime(
+ $parser->parse_datetime(
+ clense_ISO8601( $billing->billing_ts )
+ )->epoch
+ )."\n";
+ $session->request( 'open-ils.storage.direct.money.billing.create', $billing )->gather(1);
}
}
-
} catch Error with {
my $e = shift;
die "Error processing overdue circulations:\n\n$e\n";