From 736b86e63b94facabf1a44aca31f65bf5700d7dd Mon Sep 17 00:00:00 2001 From: miker Date: Thu, 14 Jul 2005 21:29:42 +0000 Subject: [PATCH] basic fine generator is now operational! git-svn-id: svn://svn.open-ils.org/ILS/trunk@1190 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../OpenILS/Application/Storage/Publisher.pm | 1 + Open-ILS/src/sql/Postgres/080.schema.money.sql | 2 +- Open-ILS/src/support-scripts/generate-fines.pl | 54 ++++++++++++++++++++-- 3 files changed, 53 insertions(+), 4 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher.pm b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher.pm index c88351eefb..8ce47d42a6 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher.pm @@ -309,6 +309,7 @@ use OpenILS::Application::Storage::Publisher::asset; use OpenILS::Application::Storage::Publisher::biblio; use OpenILS::Application::Storage::Publisher::config; use OpenILS::Application::Storage::Publisher::metabib; +use OpenILS::Application::Storage::Publisher::money; use OpenILS::Application::Storage::Publisher::permission; '; diff --git a/Open-ILS/src/sql/Postgres/080.schema.money.sql b/Open-ILS/src/sql/Postgres/080.schema.money.sql index 37a38b48bc..ccca385a67 100644 --- a/Open-ILS/src/sql/Postgres/080.schema.money.sql +++ b/Open-ILS/src/sql/Postgres/080.schema.money.sql @@ -40,7 +40,7 @@ CREATE OR REPLACE VIEW money.usr_billable_summary_xact AS SUM(COALESCE(debit.amount,0) - COALESCE(credit.amount,0)) AS balance_owed FROM money.billable_xact xact JOIN money.billing debit ON (xact.id = debit.xact) - JOIN money.payment credit ON (xact.id = credit.xact) + LEFT JOIN money.payment credit ON (xact.id = credit.xact) WHERE xact.xact_finish IS NULL GROUP BY 1,2; diff --git a/Open-ILS/src/support-scripts/generate-fines.pl b/Open-ILS/src/support-scripts/generate-fines.pl index e2cae470c5..78c6320cc2 100755 --- a/Open-ILS/src/support-scripts/generate-fines.pl +++ b/Open-ILS/src/support-scripts/generate-fines.pl @@ -6,10 +6,13 @@ use OpenSRF::Application; use OpenSRF::Utils::SettingsClient; use OpenILS::Utils::Fieldmapper; use OpenSRF::Utils; -use Time::Local ('timegm_nocheck'); +use DateTime; +use DateTime::Format::ISO8601; +use Data::Dumper; die "USAGE:\n\t$0 config_file [grace?]\n" unless @ARGV; +my $parser = DateTime::Format::ISO8601->new; # hard coded for now, option later @@ -28,15 +31,60 @@ try { " : was due at ".$c->due_date."\n"; my $fine = $session->request( - 'open-ils.storage.direct.money.billing.xact', + 'open-ils.storage.direct.money.billing.search.xact', $c->id, { order_by => 'billing_ts DESC' } )->gather(1); + my $now = time; + my $fine_interval = OpenSRF::Utils->interval_to_seconds( $c->fine_interval ); + my $last_fine; if ($fine) { - $last_fine = $fine->billing_ts; + $last_fine = $parser->parse_datetime( OpenSRF::Utils->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); + } + + my $pending_fine_count = int( ($now - $last_fine) / $fine_interval ); + next unless($pending_fine_count); + + print "Circ ".$c->id." has $pending_fine_count pending fine(s).\n"; + + for my $bill (1 .. $pending_fine_count) { + + my $total = $session->request( + 'open-ils.storage.money.billing.billable_transaction_summary', + $c->id + )->gather(1); + + if ($total && $total->{balance_owed} > $c->max_fine) { + $c->stop_fines('MAXFINES'); + + $session->request( + 'open-ils.storage.direct.action.circulation.update', + $c + )->gather(1); + + last; + } + + my $billing = new Fieldmapper::money::billing; + $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') + ); + + $session->request( + 'open-ils.storage.direct.money.billing.create', + $billing + )->gather(1); + } } -- 2.11.0