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 circ ".$c->id.
30 " for item ".$c->target_copy.
31 " : was due at ".$c->due_date."\n";
33 my $fine = $session->request(
34 'open-ils.storage.direct.money.billing.search.xact',
35 $c->id, { order_by => 'billing_ts DESC' }
39 my $fine_interval = OpenSRF::Utils->interval_to_seconds( $c->fine_interval );
43 $last_fine = $parser->parse_datetime( OpenSRF::Utils->clense_ISO8601( $fine->billing_ts ))->epoch;
45 # Use Date::Manip here
46 $last_fine = $parser->parse_datetime( OpenSRF::Utils->clense_ISO8601( $c->due_date ))->epoch;
47 $last_fine += $fine_interval if ($grace);
50 my $pending_fine_count = int( ($now - $last_fine) / $fine_interval );
51 next unless($pending_fine_count);
53 print "Circ ".$c->id." has $pending_fine_count pending fine(s).\n";
55 for my $bill (1 .. $pending_fine_count) {
57 my $total = $session->request(
58 'open-ils.storage.money.billing.billable_transaction_summary',
62 if ($total && $total->{balance_owed} > $c->max_fine) {
63 $c->stop_fines('MAXFINES');
66 'open-ils.storage.direct.action.circulation.update',
73 my $billing = new Fieldmapper::money::billing;
74 $billing->xact( $c->id );
75 $billing->note( "Overdue Fine" );
76 $billing->amount( $c->recuring_fine );
79 epoch => $last_fine + $fine_interval * $bill
80 )->strftime('%FT%T%z')
84 'open-ils.storage.direct.money.billing.create',
93 die "Error processing overdue circulations:\n\n$e\n";