package OpenILS::Application::Storage::Publisher::action;
use base qw/OpenILS::Application::Storage/;
-#use OpenILS::Application::Storage::CDBI::action;
-#use OpenSRF::Utils::Logger qw/:level/;
-#use OpenILS::Utils::Fieldmapper;
-#
-#my $log = 'OpenSRF::Utils::Logger';
+use OpenSRF::Utils::Logger qw/:level/;
+my $log = 'OpenSRF::Utils::Logger';
+
+sub grab_overdue {
+ my $self = shift;
+ my $client = shift;
+ my $grace = shift || '';
+
+ my $c_t = action::circulation->table;
+
+ $grace = ' - (1 * (fine_interval))' if ($grace);
+
+ my $sql = <<" SQL";
+ SELECT *
+ FROM $c_t
+ WHERE stop_fines IS NULL
+ AND due_date < ( CURRENT_TIMESTAMP $grace)
+ SQL
+
+ my $sth = action::circulation->db_Main->prepare_cached($sql);
+ $sth->execute;
+
+ $client->respond( $_->to_fieldmapper ) for ( map { action::circulation->construct($_) } $sth->fetchall_hash );
+
+ return undef;
+
+}
+__PACKAGE__->register_method(
+ api_name => 'open-ils.storage.action.circulation.overdue',
+ api_level => 1,
+ stream => 1,
+ method => 'grab_overdue',
+);
sub next_resp_group_id {
my $self = shift;
);
CREATE INDEX m_p_xact_idx ON money.payment (xact);
-CREATE VIEW money.usr_billable_summary_total AS
- SELECT xact.usr AS usr,
- SUM(COALESCE(credit.amount,0)) AS payed, SUM(COALESCE(debit.amount,0)) AS owed
- FROM money.billable_xact xact
- JOIN money.billing debit ON (xact.id = debit.xact)
- JOIN money.payment credit ON (xact.id = credit.xact)
- WHERE xact.xact_finish IS NULL
- GROUP BY 1;
-
-CREATE VIEW money.usr_billable_summary_xact AS
+CREATE OR REPLACE VIEW money.usr_billable_summary_xact AS
SELECT xact.id AS transaction,
xact.usr AS usr,
- SUM(COALESCE(credit.amount,0)) AS payed, SUM(COALESCE(debit.amount,0)) AS owed
+ 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)
JOIN money.payment credit ON (xact.id = credit.xact)
WHERE xact.xact_finish IS NULL
GROUP BY 1,2;
-
+CREATE OR REPLACE VIEW money.usr_billable_summary_total 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
+ GROUP BY 1;
CREATE TABLE money.bnm_payment (
amount_collected NUMERIC(6,2) NOT NULL,
--- /dev/null
+#!/usr/bin/perl -w
+use strict;
+use OpenSRF::EX qw/:try/;
+use OpenSRF::System;
+use OpenSRF::Application;
+use OpenSRF::Utils::SettingsClient;
+use OpenILS::Utils::Fieldmapper;
+use OpenSRF::Utils;
+use Time::Local ('timegm_nocheck');
+
+die "USAGE:\n\t$0 config_file [grace?]\n" unless @ARGV;
+
+
+# hard coded for now, option later
+
+OpenSRF::System->bootstrap_client( config_file => $ARGV[0] );
+my $session = OpenSRF::AppSession->create('open-ils.storage');
+
+my $grace = $ARGV[1];
+
+try {
+ my $req = $session->request( 'open-ils.storage.action.circulation.overdue',$grace );
+ while (!$req->failed && (my $res = $req->recv)) {
+ my $c = $res->content;
+
+ print "ARG! overdue circ ".$c->id.
+ " for item ".$c->target_copy.
+ " : was due at ".$c->due_date."\n";
+
+ my $fine = $session->request(
+ 'open-ils.storage.direct.money.billing.xact',
+ $c->id, { order_by => 'billing_ts DESC' }
+ )->gather(1);
+
+ my $last_fine;
+ if ($fine) {
+ $last_fine = $fine->billing_ts;
+ } else {
+ # Use Date::Manip here
+ }
+ }
+
+} catch Error with {
+ my $e = shift;
+ die "Error processing overdue circulations:\n\n$e\n";
+};
+
+