From: phasefx Date: Thu, 3 Jun 2010 10:31:18 +0000 (+0000) Subject: templates and methods for generating payment receipts X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=4017a42125796f31180394d1507850b4a4f6e9eb;p=evergreen%2Fbjwebb.git templates and methods for generating payment receipts git-svn-id: svn://svn.open-ils.org/ILS/trunk@16578 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Circ/Money.pm b/Open-ILS/src/perlmods/OpenILS/Application/Circ/Money.pm index 2dccec39b..7e10d6f4f 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Circ/Money.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Circ/Money.pm @@ -421,6 +421,83 @@ sub retrieve_payments2 { return \@payments; } +__PACKAGE__->register_method( + method => "format_payment_receipt", + api_name => "open-ils.circ.money.payment_receipt.print", + signature => { + desc => 'Returns a printable receipt for the specified payments', + params => [ + { desc => 'Authentication token', type => 'string'}, + { desc => 'Payment ID or array of payment IDs', type => 'number' }, + ], + return => { + desc => q/An action_trigger.event object or error event./, + type => 'object', + } + } +); +__PACKAGE__->register_method( + method => "format_payment_receipt", + api_name => "open-ils.circ.money.payment_receipt.email", + signature => { + desc => 'Emails a receipt for the specified payments to the user associated with the first payment', + params => [ + { desc => 'Authentication token', type => 'string'}, + { desc => 'Payment ID or array of payment IDs', type => 'number' }, + ], + return => { + desc => q/Undefined on success, otherwise an error event./, + type => 'object', + } + } +); + +sub format_payment_receipt { + my($self, $conn, $auth, $mp_id) = @_; + + my $mp_ids; + if (ref $mp_id ne 'ARRAY') { + $mp_ids = [ $mp_id ]; + } else { + $mp_ids = $mp_id; + } + + my $for_print = ($self->api_name =~ /print/); + my $for_email = ($self->api_name =~ /email/); + my $e = new_editor(authtoken => $auth); + return $e->event unless $e->checkauth; + + my $payments = []; + for my $id (@$mp_ids) { + + my $payment = $e->retrieve_money_payment([ + $id, + { flesh => 2, + flesh_fields => { + mp => ['xact'], + mbt => ['usr'] + } + } + ]) or return OpenILS::Event->new('MP_NOT_FOUND'); + + return $e->event unless $e->allowed('VIEW_TRANSACTION', $payment->xact->usr->home_ou); + + push @$payments, $payment; + } + + if ($for_print) { + + return $U->fire_object_event(undef, 'money.format.payment_receipt.print', $payments, $$payments[0]->xact->usr->home_ou); + + } elsif ($for_email) { + + for my $p (@$payments) { + $U->create_events_for_hook('money.format.payment_receipt.email', $p, $p->xact->usr->home_ou, 1); + } + } + + return undef; +} __PACKAGE__->register_method( method => "create_grocery_bill", diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql index 6ff9ad75d..2b3bbe6c8 100644 --- a/Open-ILS/src/sql/Pg/002.schema.config.sql +++ b/Open-ILS/src/sql/Pg/002.schema.config.sql @@ -65,7 +65,7 @@ CREATE TABLE config.upgrade_log ( install_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW() ); -INSERT INTO config.upgrade_log (version) VALUES ('0288'); -- Scott McKellar +INSERT INTO config.upgrade_log (version) VALUES ('0289'); -- phasefx CREATE TABLE config.bib_source ( id SERIAL PRIMARY KEY, diff --git a/Open-ILS/src/sql/Pg/950.data.seed-values.sql b/Open-ILS/src/sql/Pg/950.data.seed-values.sql index f285a9dde..d0a1b118e 100644 --- a/Open-ILS/src/sql/Pg/950.data.seed-values.sql +++ b/Open-ILS/src/sql/Pg/950.data.seed-values.sql @@ -5097,6 +5097,139 @@ INSERT INTO action_trigger.environment ( ,( 28, 'usr' ) ; +-- 0289.data.payment_receipt_format.sql + +INSERT INTO action_trigger.hook (key,core_type,description,passive) VALUES ( + 'money.format.payment_receipt.email', + 'mp', + oils_i18n_gettext( + 'money.format.payment_receipt.email', + 'An email has been requested for a payment receipt.', + 'ath', + 'description' + ), + FALSE + ) + ,( + 'money.format.payment_receipt.print', + 'mp', + oils_i18n_gettext( + 'money.format.payment_receipt.print', + 'A payment receipt needs to be formatted for printing.', + 'ath', + 'description' + ), + FALSE + ) +; + +INSERT INTO action_trigger.event_definition ( + id, + active, + owner, + name, + hook, + validator, + reactor, + group_field, + granularity, + template + ) VALUES ( + 29, + TRUE, + 1, + 'money.payment_receipt.email', + 'money.format.payment_receipt.email', + 'NOOP_True', + 'SendEmail', + 'xact.usr', + NULL, +$$ +[%- USE date -%] +[%- SET user = target.0.xact.usr -%] +To: [%- params.recipient_email || user.email %] +From: [%- params.sender_email || default_sender %] +Subject: Payment Receipt + + [% FOR mp IN target %] + Payment ID: [% mp.id %] + Paid [% mp.amount %] via [% SWITCH mp.payment_type %] + [% CASE "cash_payment" %]cash + [% CASE "check_payment" %]check + [% CASE "credit_card_payment" %]credit card + [% CASE "credit_payment" %]credit + [% CASE "forgive_payment" %]forgiveness + [% CASE "goods_payment" %]goods + [% CASE "work_payment" %]work + [% END %] on [% mp.payment_ts %] for + [% IF mp.xact.circulation %] + [% helpers.get_copy_bib_basics(mp.xact.circulation.target_copy).title %] + [% ELSE %] + grocery + [% END %] + [% END %] +$$ + ) + ,( + 30, + TRUE, + 1, + 'money.payment_receipt.print', + 'money.format.payment_receipt.print', + 'NOOP_True', + 'ProcessTemplate', + 'xact.usr', + 'print-on-demand', +$$ +[%- USE date -%] +[%- SET user = target.0.xact.usr -%] +
+ +
[% date.format %]
+
+ +
    + [% FOR mp IN target %] +
  1. + Payment ID: [% mp.id %] + Paid [% mp.amount %] via [% SWITCH mp.payment_type %] + [% CASE "cash_payment" %]cash + [% CASE "check_payment" %]check + [% CASE "credit_card_payment" %]credit card + [% CASE "credit_payment" %]credit + [% CASE "forgive_payment" %]forgiveness + [% CASE "goods_payment" %]goods + [% CASE "work_payment" %]work + [% END %] on [% mp.payment_ts %] for + [% IF mp.xact.circulation %] + [% helpers.get_copy_bib_basics(mp.xact.circulation.target_copy).title %] + [% ELSE %] + grocery + [% END %] +
  2. + [% END %] +
+
+$$ + ) +; + +INSERT INTO action_trigger.environment ( + event_def, + path + ) VALUES -- for fleshing mp objects + ( 29, 'xact') + ,( 29, 'xact.usr') + ,( 29, 'xact.grocery' ) + ,( 29, 'xact.circulation' ) + ,( 29, 'xact.summary' ) + ,( 30, 'xact') + ,( 30, 'xact.usr') + ,( 30, 'xact.grocery' ) + ,( 30, 'xact.circulation' ) + ,( 30, 'xact.summary' ) +; + -- Org unit settings for fund spending limits diff --git a/Open-ILS/src/sql/Pg/upgrade/0289.data.payment_receipt_format.sql b/Open-ILS/src/sql/Pg/upgrade/0289.data.payment_receipt_format.sql new file mode 100644 index 000000000..7e72bcba9 --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/0289.data.payment_receipt_format.sql @@ -0,0 +1,139 @@ +BEGIN; + +INSERT INTO config.upgrade_log (version) VALUES ('0289'); -- phasefx + +INSERT INTO action_trigger.hook (key,core_type,description,passive) VALUES ( + 'money.format.payment_receipt.email', + 'mp', + oils_i18n_gettext( + 'money.format.payment_receipt.email', + 'An email has been requested for a payment receipt.', + 'ath', + 'description' + ), + FALSE + ) + ,( + 'money.format.payment_receipt.print', + 'mp', + oils_i18n_gettext( + 'money.format.payment_receipt.print', + 'A payment receipt needs to be formatted for printing.', + 'ath', + 'description' + ), + FALSE + ) +; + +INSERT INTO action_trigger.event_definition ( + id, + active, + owner, + name, + hook, + validator, + reactor, + group_field, + granularity, + template + ) VALUES ( + 29, + TRUE, + 1, + 'money.payment_receipt.email', + 'money.format.payment_receipt.email', + 'NOOP_True', + 'SendEmail', + 'xact.usr', + NULL, +$$ +[%- USE date -%] +[%- SET user = target.0.xact.usr -%] +To: [%- params.recipient_email || user.email %] +From: [%- params.sender_email || default_sender %] +Subject: Payment Receipt + + [% FOR mp IN target %] + Payment ID: [% mp.id %] + Paid [% mp.amount %] via [% SWITCH mp.payment_type %] + [% CASE "cash_payment" %]cash + [% CASE "check_payment" %]check + [% CASE "credit_card_payment" %]credit card + [% CASE "credit_payment" %]credit + [% CASE "forgive_payment" %]forgiveness + [% CASE "goods_payment" %]goods + [% CASE "work_payment" %]work + [% END %] on [% mp.payment_ts %] for + [% IF mp.xact.circulation %] + [% helpers.get_copy_bib_basics(mp.xact.circulation.target_copy).title %] + [% ELSE %] + grocery + [% END %] + [% END %] +$$ + ) + ,( + 30, + TRUE, + 1, + 'money.payment_receipt.print', + 'money.format.payment_receipt.print', + 'NOOP_True', + 'ProcessTemplate', + 'xact.usr', + 'print-on-demand', +$$ +[%- USE date -%] +[%- SET user = target.0.xact.usr -%] +
+ +
[% date.format %]
+
+ +
    + [% FOR mp IN target %] +
  1. + Payment ID: [% mp.id %] + Paid [% mp.amount %] via [% SWITCH mp.payment_type %] + [% CASE "cash_payment" %]cash + [% CASE "check_payment" %]check + [% CASE "credit_card_payment" %]credit card + [% CASE "credit_payment" %]credit + [% CASE "forgive_payment" %]forgiveness + [% CASE "goods_payment" %]goods + [% CASE "work_payment" %]work + [% END %] on [% mp.payment_ts %] for + [% IF mp.xact.circulation %] + [% helpers.get_copy_bib_basics(mp.xact.circulation.target_copy).title %] + [% ELSE %] + grocery + [% END %] +
  2. + [% END %] +
+
+$$ + ) +; + +INSERT INTO action_trigger.environment ( + event_def, + path + ) VALUES -- for fleshing mp objects + ( 29, 'xact') + ,( 29, 'xact.usr') + ,( 29, 'xact.grocery' ) + ,( 29, 'xact.circulation' ) + ,( 29, 'xact.summary' ) + ,( 30, 'xact') + ,( 30, 'xact.usr') + ,( 30, 'xact.grocery' ) + ,( 30, 'xact.circulation' ) + ,( 30, 'xact.summary' ) +; + +-- DELETE FROM action_trigger.environment WHERE event_def IN (29,30); DELETE FROM action_trigger.event where event_def IN (29,30); DELETE FROM action_trigger.event_definition WHERE id IN (29,30); DELETE FROM action_trigger.hook WHERE key IN ('money.format.payment_receipt.email','money.format.payment_receipt.print'); DELETE FROM config.upgrade_log WHERE version = '0289'; -- from testing, this sql will remove these events, etc. + +COMMIT; +