From 31a20099a8a01ea522aa30418dafd4c2f6ee585f Mon Sep 17 00:00:00 2001 From: miker Date: Fri, 15 Jul 2005 00:38:26 +0000 Subject: [PATCH] updating money handling; adding readonly fieldmapper classes (views); allow fields other than "id" to be the pkey git-svn-id: svn://svn.open-ils.org/ILS/trunk@1192 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../perlmods/OpenILS/Application/Storage/CDBI.pm | 3 +- .../OpenILS/Application/Storage/CDBI/money.pm | 16 +++ .../OpenILS/Application/Storage/Driver/Pg/dbi.pm | 58 ++++++++++ .../OpenILS/Application/Storage/Publisher.pm | 127 +++++++++++---------- Open-ILS/src/perlmods/OpenILS/Utils/Fieldmapper.pm | 20 ++++ Open-ILS/src/sql/Postgres/080.schema.money.sql | 14 ++- Open-ILS/src/support-scripts/generate-fines.pl | 17 +-- 7 files changed, 177 insertions(+), 78 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI.pm b/Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI.pm index 9176210d2c..de9b419cad 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI.pm @@ -134,7 +134,8 @@ sub retrieve { my $self = shift; my $arg = shift; if (ref($arg) and UNIVERSAL::isa($arg => 'Fieldmapper')) { - $arg = $arg->id; + my $col = $arg->primary_column; + $arg = $arg->$col; } $log->debug("Retrieving $self with $arg", INTERNAL); my $rec; diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI/money.pm b/Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI/money.pm index f80062542c..d0d961aea5 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI/money.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI/money.pm @@ -14,6 +14,22 @@ __PACKAGE__->columns(Essential => qw/xact_start usr/); __PACKAGE__->columns(Others => qw/xact_finish/); #------------------------------------------------------------------------------- +package money::user_summary; +use base qw/money/; +__PACKAGE__->table('money_user_summary'); +__PACKAGE__->columns(Primary => 'usr'); +__PACKAGE__->columns(Essential => qw/total_paid total_owed balance_owed/); +#------------------------------------------------------------------------------- + +package money::billable_transaction_summary; +use base qw/money/; +__PACKAGE__->table('money_billable_transaction_summary'); +__PACKAGE__->columns(Primary => 'id'); +__PACKAGE__->columns(Essential => qw/xact_start usr xact_finish total_paid + last_payment_ts total_owed last_billing_ts + balance_owed/); +#------------------------------------------------------------------------------- + package money::billing; use base qw/money/; __PACKAGE__->table('money_billing'); diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/dbi.pm b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/dbi.pm index 4d518345a8..c8af7de19c 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/dbi.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/dbi.pm @@ -1,11 +1,69 @@ { #--------------------------------------------------------------------- + package money::billable_transaction; + + money::billable_transaction->table( 'money.billable_transaction' ); + money::billable_transaction->sequence( 'money.billable_transaction_id_seq' ); + + #--------------------------------------------------------------------- package money::billing; money::billing->table( 'money.billing' ); money::billing->sequence( 'money.billing_id_seq' ); #--------------------------------------------------------------------- + package money::payment; + + money::payment->table( 'money.payment' ); + money::payment->sequence( 'money.payment_id_seq' ); + + #--------------------------------------------------------------------- + package money::cash_payment; + + money::cash_payment->table( 'money.cash_payment' ); + money::cash_payment->sequence( 'money.payment_id_seq' ); + + #--------------------------------------------------------------------- + package money::check_payment; + + money::check_payment->table( 'money.check_payment' ); + money::check_payment->sequence( 'money.payment_id_seq' ); + + #--------------------------------------------------------------------- + package money::credit_payment; + + money::credit_payment->table( 'money.credit_payment' ); + money::credit_payment->sequence( 'money.payment_id_seq' ); + + #--------------------------------------------------------------------- + package money::credit_card_payment; + + money::credit_card_payment->table( 'money.credit_card_payment' ); + money::credit_card_payment->sequence( 'money.payment_id_seq' ); + + #--------------------------------------------------------------------- + package money::work_payment; + + money::work_payment->table( 'money.work_payment' ); + money::work_payment->sequence( 'money.payment_id_seq' ); + + #--------------------------------------------------------------------- + package money::forgive_payment; + + money::forgive_payment->table( 'money.forgive_payment' ); + money::forgive_payment->sequence( 'money.payment_id_seq' ); + + #--------------------------------------------------------------------- + package money::billable_transaction_summary; + + money::billable_transaction_summary->table( 'money.billable_xact_summary' ); + + #--------------------------------------------------------------------- + package money::user_summary; + + money::billable_transaction_summary->table( 'money.usr_summary' ); + + #--------------------------------------------------------------------- package action::circulation; action::circulation->table( 'action.circulation' ); diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher.pm b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher.pm index 8ce47d42a6..1e7fe4d1dd 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher.pm @@ -481,76 +481,77 @@ for my $fmclass ( (Fieldmapper->classes) ) { } - # Create the create method - unless ( __PACKAGE__->is_registered( $api_prefix.'.create' ) ) { - __PACKAGE__->register_method( - api_name => $api_prefix.'.create', - method => 'create_node', - api_level => 1, - cdbi => $cdbi, - ); - } + unless ($fmclass->is_readonly) { + # Create the create method + unless ( __PACKAGE__->is_registered( $api_prefix.'.create' ) ) { + __PACKAGE__->register_method( + api_name => $api_prefix.'.create', + method => 'create_node', + api_level => 1, + cdbi => $cdbi, + ); + } - # Create the batch create method - unless ( __PACKAGE__->is_registered( $api_prefix.'.batch.create' ) ) { - __PACKAGE__->register_method( - api_name => $api_prefix.'.batch.create', - method => 'batch_call', - api_level => 1, - cdbi => $cdbi, - ); - } + # Create the batch create method + unless ( __PACKAGE__->is_registered( $api_prefix.'.batch.create' ) ) { + __PACKAGE__->register_method( + api_name => $api_prefix.'.batch.create', + method => 'batch_call', + api_level => 1, + cdbi => $cdbi, + ); + } - # Create the update method - unless ( __PACKAGE__->is_registered( $api_prefix.'.update' ) ) { - __PACKAGE__->register_method( - api_name => $api_prefix.'.update', - method => 'update_node', - api_level => 1, - cdbi => $cdbi, - ); - } + # Create the update method + unless ( __PACKAGE__->is_registered( $api_prefix.'.update' ) ) { + __PACKAGE__->register_method( + api_name => $api_prefix.'.update', + method => 'update_node', + api_level => 1, + cdbi => $cdbi, + ); + } - # Create the batch update method - unless ( __PACKAGE__->is_registered( $api_prefix.'.batch.update' ) ) { - __PACKAGE__->register_method( - api_name => $api_prefix.'.batch.update', - method => 'batch_call', - api_level => 1, - cdbi => $cdbi, - ); - } + # Create the batch update method + unless ( __PACKAGE__->is_registered( $api_prefix.'.batch.update' ) ) { + __PACKAGE__->register_method( + api_name => $api_prefix.'.batch.update', + method => 'batch_call', + api_level => 1, + cdbi => $cdbi, + ); + } - # Create the delete method - unless ( __PACKAGE__->is_registered( $api_prefix.'.delete' ) ) { - __PACKAGE__->register_method( - api_name => $api_prefix.'.delete', - method => 'delete_node', - api_level => 1, - cdbi => $cdbi, - ); - } + # Create the delete method + unless ( __PACKAGE__->is_registered( $api_prefix.'.delete' ) ) { + __PACKAGE__->register_method( + api_name => $api_prefix.'.delete', + method => 'delete_node', + api_level => 1, + cdbi => $cdbi, + ); + } - # Create the batch delete method - unless ( __PACKAGE__->is_registered( $api_prefix.'.batch.delete' ) ) { - __PACKAGE__->register_method( - api_name => $api_prefix.'.batch.delete', - method => 'batch_call', - api_level => 1, - cdbi => $cdbi, - ); - } + # Create the batch delete method + unless ( __PACKAGE__->is_registered( $api_prefix.'.batch.delete' ) ) { + __PACKAGE__->register_method( + api_name => $api_prefix.'.batch.delete', + method => 'batch_call', + api_level => 1, + cdbi => $cdbi, + ); + } - # Create the search-based mass delete method - unless ( __PACKAGE__->is_registered( $api_prefix.'.mass_delete' ) ) { - __PACKAGE__->register_method( - api_name => $api_prefix.'.mass_delete', - method => 'mass_delete', - api_level => 1, - cdbi => $cdbi, - ); + # Create the search-based mass delete method + unless ( __PACKAGE__->is_registered( $api_prefix.'.mass_delete' ) ) { + __PACKAGE__->register_method( + api_name => $api_prefix.'.mass_delete', + method => 'mass_delete', + api_level => 1, + cdbi => $cdbi, + ); + } } - } 1; diff --git a/Open-ILS/src/perlmods/OpenILS/Utils/Fieldmapper.pm b/Open-ILS/src/perlmods/OpenILS/Utils/Fieldmapper.pm index 971d26d815..051af15662 100644 --- a/Open-ILS/src/perlmods/OpenILS/Utils/Fieldmapper.pm +++ b/Open-ILS/src/perlmods/OpenILS/Utils/Fieldmapper.pm @@ -122,8 +122,22 @@ sub _init { fixed_fields => 1 } }, #'Fieldmapper::biblio::record_marc' => { hint => 'brx' }, # now it's inside record_entry + 'Fieldmapper::money::payment' => { hint => 'mp' }, 'Fieldmapper::money::cash_payment' => { hint => 'mcp' }, + 'Fieldmapper::money::check_payment' => { hint => 'mckp' }, + 'Fieldmapper::money::credit_payment' => { hint => 'mcrp' }, + 'Fieldmapper::money::credit_card_payment' => { hint => 'mccp' }, + 'Fieldmapper::money::forgive_payment' => { hint => 'mfp' }, + 'Fieldmapper::money::work_payment' => { hint => 'mwp' }, + 'Fieldmapper::money::billing' => { hint => 'mb' }, + 'Fieldmapper::money::billable_transaction' => { hint => 'mbt' }, + + 'Fieldmapper::money::user_summary' => { hint => 'mus', + readonly => 1 }, + + 'Fieldmapper::money::billable_transaction_summary' => { hint => 'mbts', + readonly => 1 }, 'Fieldmapper::config::identification_type' => { hint => 'cit' }, 'Fieldmapper::config::bib_source' => { hint => 'cbs' }, @@ -317,6 +331,12 @@ sub is_virtual { return $fieldmap->{$self->class_name}->{virtual}; } +sub is_readonly { + my $self = shift; + my $field = shift; + return $fieldmap->{$self->class_name}->{readonly}; +} + sub json_hint { my $self = shift; return $fieldmap->{$self->class_name}->{hint}; diff --git a/Open-ILS/src/sql/Postgres/080.schema.money.sql b/Open-ILS/src/sql/Postgres/080.schema.money.sql index ccca385a67..964ecdab46 100644 --- a/Open-ILS/src/sql/Postgres/080.schema.money.sql +++ b/Open-ILS/src/sql/Postgres/080.schema.money.sql @@ -30,26 +30,28 @@ CREATE TABLE money.payment ( ); CREATE INDEX m_p_xact_idx ON money.payment (xact); -CREATE OR REPLACE VIEW money.usr_billable_summary_xact AS - SELECT xact.id AS transaction, +CREATE OR REPLACE VIEW money.billable_xact_summary AS + SELECT xact.id AS id, xact.usr AS usr, + xact.xact_start AS xact_start, + xact.xact_finish AS xact_finish, SUM(COALESCE(credit.amount,0)) AS total_paid, MAX(credit.payment_ts) AS last_payment_ts, SUM(COALESCE(debit.amount,0)) AS total_owed, MAX(debit.billing_ts) AS last_billing_ts, 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) + LEFT JOIN money.billing debit ON (xact.id = debit.xact) LEFT JOIN money.payment credit ON (xact.id = credit.xact) WHERE xact.xact_finish IS NULL - GROUP BY 1,2; + GROUP BY 1,2,3,4; -CREATE OR REPLACE VIEW money.usr_billable_summary_total AS +CREATE OR REPLACE VIEW money.usr_summary AS SELECT usr, SUM(total_paid) AS total_paid, SUM(total_owed) AS total_owed, SUM(balance_owed) AS balance_owed - FROM money.usr_billable_summary_xact + FROM money.billable_xact_summary GROUP BY 1; CREATE TABLE money.bnm_payment ( diff --git a/Open-ILS/src/support-scripts/generate-fines.pl b/Open-ILS/src/support-scripts/generate-fines.pl index 78c6320cc2..06794d3cd6 100755 --- a/Open-ILS/src/support-scripts/generate-fines.pl +++ b/Open-ILS/src/support-scripts/generate-fines.pl @@ -26,13 +26,14 @@ try { while (!$req->failed && (my $res = $req->recv)) { my $c = $res->content; - print "ARG! overdue circ ".$c->id. + print "ARG! Overdue circulation ".$c->id. " for item ".$c->target_copy. - " : was due at ".$c->due_date."\n"; + " (user ".$c->usr.")". + " : it was due at ".$c->due_date."\n"; my $fine = $session->request( 'open-ils.storage.direct.money.billing.search.xact', - $c->id, { order_by => 'billing_ts DESC' } + $c->id, { order_by => 'billing_ts DESC', limit => '1' } )->gather(1); my $now = time; @@ -40,26 +41,26 @@ try { my $last_fine; if ($fine) { - $last_fine = $parser->parse_datetime( OpenSRF::Utils->clense_ISO8601( $fine->billing_ts ))->epoch; + $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 = $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"; + print "\t$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', + 'open-ils.storage.direct.money.billable_transaction_summary.retrieve', $c->id )->gather(1); - if ($total && $total->{balance_owed} > $c->max_fine) { + if ($total && $total->balance_owed > $c->max_fine) { $c->stop_fines('MAXFINES'); $session->request( -- 2.11.0