3 use OpenSRF::EX qw/:try/;
5 use OpenSRF::Application;
6 use OpenSRF::Utils::SettingsClient;
7 use OpenILS::Utils::Fieldmapper;
10 use DateTime::Format::ISO8601;
13 die "USAGE:\n\t$0 config_file [grace?]\n" unless @ARGV;
15 my $parser = DateTime::Format::ISO8601->new;
17 # hard coded for now, option later
19 OpenSRF::System->bootstrap_client( config_file => $ARGV[0] );
20 my $session = OpenSRF::AppSession->create('open-ils.storage');
25 my $req = $session->request( 'open-ils.storage.action.circulation.overdue',$grace );
26 while (!$req->failed && (my $res = $req->recv)) {
27 my $c = $res->content;
29 print "ARG! Overdue circulation ".$c->id.
30 " for item ".$c->target_copy.
31 " (user ".$c->usr.")".
32 " : it was due at ".$c->due_date."\n";
34 my $fine = $session->request(
35 'open-ils.storage.direct.money.billing.search.xact',
36 $c->id, { order_by => 'billing_ts DESC', limit => '1' }
40 my $fine_interval = OpenSRF::Utils->interval_to_seconds( $c->fine_interval );
44 $last_fine = $parser->parse_datetime( OpenSRF::Utils->clense_ISO8601( $fine->billing_ts ) )->epoch;
46 # Use Date::Manip here
47 $last_fine = $parser->parse_datetime( OpenSRF::Utils->clense_ISO8601( $c->due_date ) )->epoch;
48 $last_fine += $fine_interval if ($grace);
51 my $pending_fine_count = int( ($now - $last_fine) / $fine_interval );
52 next unless($pending_fine_count);
54 print "\t$pending_fine_count pending fine(s)\n";
56 for my $bill (1 .. $pending_fine_count) {
58 my $total = $session->request(
59 'open-ils.storage.direct.money.billable_transaction_summary.retrieve',
63 if ($total && $total->balance_owed > $c->max_fine) {
64 $c->stop_fines('MAXFINES');
67 'open-ils.storage.direct.action.circulation.update',
74 my $billing = new Fieldmapper::money::billing;
75 $billing->xact( $c->id );
76 $billing->note( "Overdue Fine" );
77 $billing->amount( $c->recuring_fine );
80 epoch => $last_fine + $fine_interval * $bill
81 )->strftime('%FT%T%z')
85 'open-ils.storage.direct.money.billing.create',
94 die "Error processing overdue circulations:\n\n$e\n";