__PACKAGE__->columns(Essential => qw/total_paid total_owed balance_owed/);
#-------------------------------------------------------------------------------
+package money::user_circulation_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/);
+ balance_owed xact_type/);
#-------------------------------------------------------------------------------
package money::billing;
money::user_summary->table( 'money.usr_summary' );
#---------------------------------------------------------------------
+ package money::user_circulation_summary;
+
+ money::user_summary->table( 'money.usr_circulation_summary' );
+
+ #---------------------------------------------------------------------
package action::circulation;
action::circulation->table( 'action.circulation' );
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
+ SUM(COALESCE(debit.amount,0) - COALESCE(credit.amount,0)) AS balance_owed,
+ p.relname AS xact_type
FROM money.billable_xact xact
+ JOIN pg_class p ON (xact.tableoid = p.oid)
LEFT JOIN money.billing debit ON (xact.id = debit.xact AND debit.voided IS FALSE)
LEFT JOIN money.payment credit ON (xact.id = credit.xact AND credit.voided IS FALSE)
WHERE xact.xact_finish IS NULL
- GROUP BY 1,2,3,4;
+ GROUP BY 1,2,3,4,10;
CREATE OR REPLACE VIEW money.usr_summary AS
SELECT usr,
FROM money.billable_xact_summary
GROUP BY 1;
+CREATE OR REPLACE VIEW money.usr_circulation_summary AS
+ SELECT usr,
+ SUM(total_paid) AS total_paid,
+ SUM(total_owed) AS total_owed,
+ SUM(balance_owed) AS balance_owed
+ FROM money.billable_xact_summary
+ WHERE xact_type = 'circulation'
+ GROUP BY 1;
+
CREATE TABLE money.bnm_payment (
amount_collected NUMERIC(6,2) NOT NULL,
accepting_usr INT NOT NULL