updating money handling; adding readonly fieldmapper classes (views); allow fields...
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 15 Jul 2005 00:38:26 +0000 (00:38 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 15 Jul 2005 00:38:26 +0000 (00:38 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@1192 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI.pm
Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI/money.pm
Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/dbi.pm
Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher.pm
Open-ILS/src/perlmods/OpenILS/Utils/Fieldmapper.pm
Open-ILS/src/sql/Postgres/080.schema.money.sql
Open-ILS/src/support-scripts/generate-fines.pl

index 9176210..de9b419 100644 (file)
@@ -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;
index f800625..d0d961a 100644 (file)
@@ -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');
index 4d51834..c8af7de 100644 (file)
@@ -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' );
index 8ce47d4..1e7fe4d 100644 (file)
@@ -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;
index 971d26d..051af15 100644 (file)
@@ -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};
index ccca385..964ecda 100644 (file)
@@ -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 (
index 78c6320..06794d3 100755 (executable)
@@ -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(