From: Kathy Lussier Date: Fri, 19 Feb 2016 17:41:43 +0000 (-0500) Subject: LP#1474051 Stamping upgrade script for drop-cc-data X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=4ae3fa1a24e1e1bbfbd8b1ba77c8cc8e5d5b99a0;p=evergreen%2Fequinox.git LP#1474051 Stamping upgrade script for drop-cc-data Signed-off-by: Kathy Lussier --- diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql index ab33a79ae9..1559923e11 100644 --- a/Open-ILS/src/sql/Pg/002.schema.config.sql +++ b/Open-ILS/src/sql/Pg/002.schema.config.sql @@ -91,7 +91,7 @@ CREATE TRIGGER no_overlapping_deps BEFORE INSERT OR UPDATE ON config.db_patch_dependencies FOR EACH ROW EXECUTE PROCEDURE evergreen.array_overlap_check ('deprecates'); -INSERT INTO config.upgrade_log (version, applied_to) VALUES ('0955', :eg_version); --mpeters/christineb/kmlussier +INSERT INTO config.upgrade_log (version, applied_to) VALUES ('0957', :eg_version); --berick/kmlussier CREATE TABLE config.bib_source ( id SERIAL PRIMARY KEY, diff --git a/Open-ILS/src/sql/Pg/upgrade/0956.schema.drop_cc_cols.sql b/Open-ILS/src/sql/Pg/upgrade/0956.schema.drop_cc_cols.sql new file mode 100644 index 0000000000..fc8fb1b333 --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/0956.schema.drop_cc_cols.sql @@ -0,0 +1,13 @@ +BEGIN; + +SELECT evergreen.upgrade_deps_block_check('0956', :eg_version); + +ALTER TABLE money.credit_card_payment + DROP COLUMN cc_type, + DROP COLUMN expire_month, + DROP COLUMN expire_year, + DROP COLUMN cc_first_name, + DROP COLUMN cc_last_name; + +COMMIT; + diff --git a/Open-ILS/src/sql/Pg/upgrade/0957.data.drop_cc_cols.sql b/Open-ILS/src/sql/Pg/upgrade/0957.data.drop_cc_cols.sql new file mode 100644 index 0000000000..36124179c8 --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/0957.data.drop_cc_cols.sql @@ -0,0 +1,270 @@ + +BEGIN; + +SELECT evergreen.upgrade_deps_block_check('0957', :eg_version); + +-- Remove references to dropped CC payment columns in the print/email +-- payment receipt templates, but only if the in-db template matches +-- the stock template. +-- The actual diff here is only about 8 lines. + +UPDATE action_trigger.event_definition SET template = +$$ +[%- USE date -%] +[%- SET user = target.0.xact.usr -%] +To: [%- params.recipient_email || user.email %] +From: [%- params.sender_email || default_sender %] +Subject: Payment Receipt + +[% date.format -%] +[%- SET xact_mp_hash = {} -%] +[%- FOR mp IN target %][%# Template is hooked around payments, but let us make the receipt focused on transactions -%] + [%- SET xact_id = mp.xact.id -%] + [%- IF ! xact_mp_hash.defined( xact_id ) -%][%- xact_mp_hash.$xact_id = { 'xact' => mp.xact, 'payments' => [] } -%][%- END -%] + [%- xact_mp_hash.$xact_id.payments.push(mp) -%] +[%- END -%] +[%- FOR xact_id IN xact_mp_hash.keys.sort -%] + [%- SET xact = xact_mp_hash.$xact_id.xact %] +Transaction ID: [% xact_id %] + [% IF xact.circulation %][% helpers.get_copy_bib_basics(xact.circulation.target_copy).title %] + [% ELSE %]Miscellaneous + [% END %] + Line item billings: + [%- SET mb_type_hash = {} -%] + [%- FOR mb IN xact.billings %][%# Group billings by their btype -%] + [%- IF mb.voided == 'f' -%] + [%- SET mb_type = mb.btype.id -%] + [%- IF ! mb_type_hash.defined( mb_type ) -%][%- mb_type_hash.$mb_type = { 'sum' => 0.00, 'billings' => [] } -%][%- END -%] + [%- IF ! mb_type_hash.$mb_type.defined( 'first_ts' ) -%][%- mb_type_hash.$mb_type.first_ts = mb.billing_ts -%][%- END -%] + [%- mb_type_hash.$mb_type.last_ts = mb.billing_ts -%] + [%- mb_type_hash.$mb_type.sum = mb_type_hash.$mb_type.sum + mb.amount -%] + [%- mb_type_hash.$mb_type.billings.push( mb ) -%] + [%- END -%] + [%- END -%] + [%- FOR mb_type IN mb_type_hash.keys.sort -%] + [%- IF mb_type == 1 %][%-# Consolidated view of overdue billings -%] + $[% mb_type_hash.$mb_type.sum %] for [% mb_type_hash.$mb_type.billings.0.btype.name %] + on [% mb_type_hash.$mb_type.first_ts %] through [% mb_type_hash.$mb_type.last_ts %] + [%- ELSE -%][%# all other billings show individually %] + [% FOR mb IN mb_type_hash.$mb_type.billings %] + $[% mb.amount %] for [% mb.btype.name %] on [% mb.billing_ts %] [% mb.note %] + [% END %] + [% END %] + [% END %] + Line item payments: + [% FOR mp IN xact_mp_hash.$xact_id.payments %] + 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 + [%- IF mp.credit_card_payment.cc_number %] ([% mp.credit_card_payment.cc_number %])[% END %] + [% CASE "credit_payment" %]credit + [% CASE "forgive_payment" %]forgiveness + [% CASE "goods_payment" %]goods + [% CASE "work_payment" %]work + [%- END %] on [% mp.payment_ts %] [% mp.note %] + [% END %] +[% END %] +$$ + +WHERE id = 29 AND template = + +$$ +[%- USE date -%] +[%- SET user = target.0.xact.usr -%] +To: [%- params.recipient_email || user.email %] +From: [%- params.sender_email || default_sender %] +Subject: Payment Receipt + +[% date.format -%] +[%- SET xact_mp_hash = {} -%] +[%- FOR mp IN target %][%# Template is hooked around payments, but let us make the receipt focused on transactions -%] + [%- SET xact_id = mp.xact.id -%] + [%- IF ! xact_mp_hash.defined( xact_id ) -%][%- xact_mp_hash.$xact_id = { 'xact' => mp.xact, 'payments' => [] } -%][%- END -%] + [%- xact_mp_hash.$xact_id.payments.push(mp) -%] +[%- END -%] +[%- FOR xact_id IN xact_mp_hash.keys.sort -%] + [%- SET xact = xact_mp_hash.$xact_id.xact %] +Transaction ID: [% xact_id %] + [% IF xact.circulation %][% helpers.get_copy_bib_basics(xact.circulation.target_copy).title %] + [% ELSE %]Miscellaneous + [% END %] + Line item billings: + [%- SET mb_type_hash = {} -%] + [%- FOR mb IN xact.billings %][%# Group billings by their btype -%] + [%- IF mb.voided == 'f' -%] + [%- SET mb_type = mb.btype.id -%] + [%- IF ! mb_type_hash.defined( mb_type ) -%][%- mb_type_hash.$mb_type = { 'sum' => 0.00, 'billings' => [] } -%][%- END -%] + [%- IF ! mb_type_hash.$mb_type.defined( 'first_ts' ) -%][%- mb_type_hash.$mb_type.first_ts = mb.billing_ts -%][%- END -%] + [%- mb_type_hash.$mb_type.last_ts = mb.billing_ts -%] + [%- mb_type_hash.$mb_type.sum = mb_type_hash.$mb_type.sum + mb.amount -%] + [%- mb_type_hash.$mb_type.billings.push( mb ) -%] + [%- END -%] + [%- END -%] + [%- FOR mb_type IN mb_type_hash.keys.sort -%] + [%- IF mb_type == 1 %][%-# Consolidated view of overdue billings -%] + $[% mb_type_hash.$mb_type.sum %] for [% mb_type_hash.$mb_type.billings.0.btype.name %] + on [% mb_type_hash.$mb_type.first_ts %] through [% mb_type_hash.$mb_type.last_ts %] + [%- ELSE -%][%# all other billings show individually %] + [% FOR mb IN mb_type_hash.$mb_type.billings %] + $[% mb.amount %] for [% mb.btype.name %] on [% mb.billing_ts %] [% mb.note %] + [% END %] + [% END %] + [% END %] + Line item payments: + [% FOR mp IN xact_mp_hash.$xact_id.payments %] + 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 ( + [%- SET cc_chunks = mp.credit_card_payment.cc_number.replace(' ','').chunk(4); -%] + [%- cc_chunks.slice(0, -1+cc_chunks.max).join.replace('\S','X') -%] + [% cc_chunks.last -%] + exp [% mp.credit_card_payment.expire_month %]/[% mp.credit_card_payment.expire_year -%] + ) + [% CASE "credit_payment" %]credit + [% CASE "forgive_payment" %]forgiveness + [% CASE "goods_payment" %]goods + [% CASE "work_payment" %]work + [%- END %] on [% mp.payment_ts %] [% mp.note %] + [% END %] +[% END %] +$$; + + +UPDATE action_trigger.event_definition SET template = +$$ +[%- USE date -%][%- SET user = target.0.xact.usr -%] +
+
[% date.format %]

+
    + [% SET xact_mp_hash = {} %] + [% FOR mp IN target %][%# Template is hooked around payments, but let us make the receipt focused on transactions %] + [% SET xact_id = mp.xact.id %] + [% IF ! xact_mp_hash.defined( xact_id ) %][% xact_mp_hash.$xact_id = { 'xact' => mp.xact, 'payments' => [] } %][% END %] + [% xact_mp_hash.$xact_id.payments.push(mp) %] + [% END %] + [% FOR xact_id IN xact_mp_hash.keys.sort %] + [% SET xact = xact_mp_hash.$xact_id.xact %] +
  1. Transaction ID: [% xact_id %] + [% IF xact.circulation %][% helpers.get_copy_bib_basics(xact.circulation.target_copy).title %] + [% ELSE %]Miscellaneous + [% END %] + Line item billings:
      + [% SET mb_type_hash = {} %] + [% FOR mb IN xact.billings %][%# Group billings by their btype %] + [% IF mb.voided == 'f' %] + [% SET mb_type = mb.btype.id %] + [% IF ! mb_type_hash.defined( mb_type ) %][% mb_type_hash.$mb_type = { 'sum' => 0.00, 'billings' => [] } %][% END %] + [% IF ! mb_type_hash.$mb_type.defined( 'first_ts' ) %][% mb_type_hash.$mb_type.first_ts = mb.billing_ts %][% END %] + [% mb_type_hash.$mb_type.last_ts = mb.billing_ts %] + [% mb_type_hash.$mb_type.sum = mb_type_hash.$mb_type.sum + mb.amount %] + [% mb_type_hash.$mb_type.billings.push( mb ) %] + [% END %] + [% END %] + [% FOR mb_type IN mb_type_hash.keys.sort %] +
    1. [% IF mb_type == 1 %][%# Consolidated view of overdue billings %] + $[% mb_type_hash.$mb_type.sum %] for [% mb_type_hash.$mb_type.billings.0.btype.name %] + on [% mb_type_hash.$mb_type.first_ts %] through [% mb_type_hash.$mb_type.last_ts %] + [% ELSE %][%# all other billings show individually %] + [% FOR mb IN mb_type_hash.$mb_type.billings %] + $[% mb.amount %] for [% mb.btype.name %] on [% mb.billing_ts %] [% mb.note %] + [% END %] + [% END %]
    2. + [% END %] +
    + Line item payments:
      + [% FOR mp IN xact_mp_hash.$xact_id.payments %] +
    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 + [%- IF mp.credit_card_payment.cc_number %] ([% mp.credit_card_payment.cc_number %])[% END %] + [% CASE "credit_payment" %]credit + [% CASE "forgive_payment" %]forgiveness + [% CASE "goods_payment" %]goods + [% CASE "work_payment" %]work + [%- END %] on [% mp.payment_ts %] [% mp.note %] +
    2. + [% END %] +
    +
  2. + [% END %] +
+
+$$ + +WHERE id = 30 AND template = + +$$ +[%- USE date -%][%- SET user = target.0.xact.usr -%] +
+
[% date.format %]

+
    + [% SET xact_mp_hash = {} %] + [% FOR mp IN target %][%# Template is hooked around payments, but let us make the receipt focused on transactions %] + [% SET xact_id = mp.xact.id %] + [% IF ! xact_mp_hash.defined( xact_id ) %][% xact_mp_hash.$xact_id = { 'xact' => mp.xact, 'payments' => [] } %][% END %] + [% xact_mp_hash.$xact_id.payments.push(mp) %] + [% END %] + [% FOR xact_id IN xact_mp_hash.keys.sort %] + [% SET xact = xact_mp_hash.$xact_id.xact %] +
  1. Transaction ID: [% xact_id %] + [% IF xact.circulation %][% helpers.get_copy_bib_basics(xact.circulation.target_copy).title %] + [% ELSE %]Miscellaneous + [% END %] + Line item billings:
      + [% SET mb_type_hash = {} %] + [% FOR mb IN xact.billings %][%# Group billings by their btype %] + [% IF mb.voided == 'f' %] + [% SET mb_type = mb.btype.id %] + [% IF ! mb_type_hash.defined( mb_type ) %][% mb_type_hash.$mb_type = { 'sum' => 0.00, 'billings' => [] } %][% END %] + [% IF ! mb_type_hash.$mb_type.defined( 'first_ts' ) %][% mb_type_hash.$mb_type.first_ts = mb.billing_ts %][% END %] + [% mb_type_hash.$mb_type.last_ts = mb.billing_ts %] + [% mb_type_hash.$mb_type.sum = mb_type_hash.$mb_type.sum + mb.amount %] + [% mb_type_hash.$mb_type.billings.push( mb ) %] + [% END %] + [% END %] + [% FOR mb_type IN mb_type_hash.keys.sort %] +
    1. [% IF mb_type == 1 %][%# Consolidated view of overdue billings %] + $[% mb_type_hash.$mb_type.sum %] for [% mb_type_hash.$mb_type.billings.0.btype.name %] + on [% mb_type_hash.$mb_type.first_ts %] through [% mb_type_hash.$mb_type.last_ts %] + [% ELSE %][%# all other billings show individually %] + [% FOR mb IN mb_type_hash.$mb_type.billings %] + $[% mb.amount %] for [% mb.btype.name %] on [% mb.billing_ts %] [% mb.note %] + [% END %] + [% END %]
    2. + [% END %] +
    + Line item payments:
      + [% FOR mp IN xact_mp_hash.$xact_id.payments %] +
    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 ( + [%- SET cc_chunks = mp.credit_card_payment.cc_number.replace(' ','').chunk(4); -%] + [%- cc_chunks.slice(0, -1+cc_chunks.max).join.replace('\S','X') -%] + [% cc_chunks.last -%] + exp [% mp.credit_card_payment.expire_month %]/[% mp.credit_card_payment.expire_year -%] + ) + [% CASE "credit_payment" %]credit + [% CASE "forgive_payment" %]forgiveness + [% CASE "goods_payment" %]goods + [% CASE "work_payment" %]work + [%- END %] on [% mp.payment_ts %] [% mp.note %] +
    2. + [% END %] +
    +
  2. + [% END %] +
+
+$$; + + +--ROLLBACK; +COMMIT; diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.drop_cc_cols.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.drop_cc_cols.sql deleted file mode 100644 index c24ab04c6f..0000000000 --- a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.drop_cc_cols.sql +++ /dev/null @@ -1,13 +0,0 @@ -BEGIN; - --- SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version); - -ALTER TABLE money.credit_card_payment - DROP COLUMN cc_type, - DROP COLUMN expire_month, - DROP COLUMN expire_year, - DROP COLUMN cc_first_name, - DROP COLUMN cc_last_name; - -COMMIT; - diff --git a/Open-ILS/src/sql/Pg/upgrade/YYYY.data.drop_cc_cols.sql b/Open-ILS/src/sql/Pg/upgrade/YYYY.data.drop_cc_cols.sql deleted file mode 100644 index 763dcbd56d..0000000000 --- a/Open-ILS/src/sql/Pg/upgrade/YYYY.data.drop_cc_cols.sql +++ /dev/null @@ -1,270 +0,0 @@ - -BEGIN; - --- SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version); - --- Remove references to dropped CC payment columns in the print/email --- payment receipt templates, but only if the in-db template matches --- the stock template. --- The actual diff here is only about 8 lines. - -UPDATE action_trigger.event_definition SET template = -$$ -[%- USE date -%] -[%- SET user = target.0.xact.usr -%] -To: [%- params.recipient_email || user.email %] -From: [%- params.sender_email || default_sender %] -Subject: Payment Receipt - -[% date.format -%] -[%- SET xact_mp_hash = {} -%] -[%- FOR mp IN target %][%# Template is hooked around payments, but let us make the receipt focused on transactions -%] - [%- SET xact_id = mp.xact.id -%] - [%- IF ! xact_mp_hash.defined( xact_id ) -%][%- xact_mp_hash.$xact_id = { 'xact' => mp.xact, 'payments' => [] } -%][%- END -%] - [%- xact_mp_hash.$xact_id.payments.push(mp) -%] -[%- END -%] -[%- FOR xact_id IN xact_mp_hash.keys.sort -%] - [%- SET xact = xact_mp_hash.$xact_id.xact %] -Transaction ID: [% xact_id %] - [% IF xact.circulation %][% helpers.get_copy_bib_basics(xact.circulation.target_copy).title %] - [% ELSE %]Miscellaneous - [% END %] - Line item billings: - [%- SET mb_type_hash = {} -%] - [%- FOR mb IN xact.billings %][%# Group billings by their btype -%] - [%- IF mb.voided == 'f' -%] - [%- SET mb_type = mb.btype.id -%] - [%- IF ! mb_type_hash.defined( mb_type ) -%][%- mb_type_hash.$mb_type = { 'sum' => 0.00, 'billings' => [] } -%][%- END -%] - [%- IF ! mb_type_hash.$mb_type.defined( 'first_ts' ) -%][%- mb_type_hash.$mb_type.first_ts = mb.billing_ts -%][%- END -%] - [%- mb_type_hash.$mb_type.last_ts = mb.billing_ts -%] - [%- mb_type_hash.$mb_type.sum = mb_type_hash.$mb_type.sum + mb.amount -%] - [%- mb_type_hash.$mb_type.billings.push( mb ) -%] - [%- END -%] - [%- END -%] - [%- FOR mb_type IN mb_type_hash.keys.sort -%] - [%- IF mb_type == 1 %][%-# Consolidated view of overdue billings -%] - $[% mb_type_hash.$mb_type.sum %] for [% mb_type_hash.$mb_type.billings.0.btype.name %] - on [% mb_type_hash.$mb_type.first_ts %] through [% mb_type_hash.$mb_type.last_ts %] - [%- ELSE -%][%# all other billings show individually %] - [% FOR mb IN mb_type_hash.$mb_type.billings %] - $[% mb.amount %] for [% mb.btype.name %] on [% mb.billing_ts %] [% mb.note %] - [% END %] - [% END %] - [% END %] - Line item payments: - [% FOR mp IN xact_mp_hash.$xact_id.payments %] - 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 - [%- IF mp.credit_card_payment.cc_number %] ([% mp.credit_card_payment.cc_number %])[% END %] - [% CASE "credit_payment" %]credit - [% CASE "forgive_payment" %]forgiveness - [% CASE "goods_payment" %]goods - [% CASE "work_payment" %]work - [%- END %] on [% mp.payment_ts %] [% mp.note %] - [% END %] -[% END %] -$$ - -WHERE id = 29 AND template = - -$$ -[%- USE date -%] -[%- SET user = target.0.xact.usr -%] -To: [%- params.recipient_email || user.email %] -From: [%- params.sender_email || default_sender %] -Subject: Payment Receipt - -[% date.format -%] -[%- SET xact_mp_hash = {} -%] -[%- FOR mp IN target %][%# Template is hooked around payments, but let us make the receipt focused on transactions -%] - [%- SET xact_id = mp.xact.id -%] - [%- IF ! xact_mp_hash.defined( xact_id ) -%][%- xact_mp_hash.$xact_id = { 'xact' => mp.xact, 'payments' => [] } -%][%- END -%] - [%- xact_mp_hash.$xact_id.payments.push(mp) -%] -[%- END -%] -[%- FOR xact_id IN xact_mp_hash.keys.sort -%] - [%- SET xact = xact_mp_hash.$xact_id.xact %] -Transaction ID: [% xact_id %] - [% IF xact.circulation %][% helpers.get_copy_bib_basics(xact.circulation.target_copy).title %] - [% ELSE %]Miscellaneous - [% END %] - Line item billings: - [%- SET mb_type_hash = {} -%] - [%- FOR mb IN xact.billings %][%# Group billings by their btype -%] - [%- IF mb.voided == 'f' -%] - [%- SET mb_type = mb.btype.id -%] - [%- IF ! mb_type_hash.defined( mb_type ) -%][%- mb_type_hash.$mb_type = { 'sum' => 0.00, 'billings' => [] } -%][%- END -%] - [%- IF ! mb_type_hash.$mb_type.defined( 'first_ts' ) -%][%- mb_type_hash.$mb_type.first_ts = mb.billing_ts -%][%- END -%] - [%- mb_type_hash.$mb_type.last_ts = mb.billing_ts -%] - [%- mb_type_hash.$mb_type.sum = mb_type_hash.$mb_type.sum + mb.amount -%] - [%- mb_type_hash.$mb_type.billings.push( mb ) -%] - [%- END -%] - [%- END -%] - [%- FOR mb_type IN mb_type_hash.keys.sort -%] - [%- IF mb_type == 1 %][%-# Consolidated view of overdue billings -%] - $[% mb_type_hash.$mb_type.sum %] for [% mb_type_hash.$mb_type.billings.0.btype.name %] - on [% mb_type_hash.$mb_type.first_ts %] through [% mb_type_hash.$mb_type.last_ts %] - [%- ELSE -%][%# all other billings show individually %] - [% FOR mb IN mb_type_hash.$mb_type.billings %] - $[% mb.amount %] for [% mb.btype.name %] on [% mb.billing_ts %] [% mb.note %] - [% END %] - [% END %] - [% END %] - Line item payments: - [% FOR mp IN xact_mp_hash.$xact_id.payments %] - 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 ( - [%- SET cc_chunks = mp.credit_card_payment.cc_number.replace(' ','').chunk(4); -%] - [%- cc_chunks.slice(0, -1+cc_chunks.max).join.replace('\S','X') -%] - [% cc_chunks.last -%] - exp [% mp.credit_card_payment.expire_month %]/[% mp.credit_card_payment.expire_year -%] - ) - [% CASE "credit_payment" %]credit - [% CASE "forgive_payment" %]forgiveness - [% CASE "goods_payment" %]goods - [% CASE "work_payment" %]work - [%- END %] on [% mp.payment_ts %] [% mp.note %] - [% END %] -[% END %] -$$; - - -UPDATE action_trigger.event_definition SET template = -$$ -[%- USE date -%][%- SET user = target.0.xact.usr -%] -
-
[% date.format %]

-
    - [% SET xact_mp_hash = {} %] - [% FOR mp IN target %][%# Template is hooked around payments, but let us make the receipt focused on transactions %] - [% SET xact_id = mp.xact.id %] - [% IF ! xact_mp_hash.defined( xact_id ) %][% xact_mp_hash.$xact_id = { 'xact' => mp.xact, 'payments' => [] } %][% END %] - [% xact_mp_hash.$xact_id.payments.push(mp) %] - [% END %] - [% FOR xact_id IN xact_mp_hash.keys.sort %] - [% SET xact = xact_mp_hash.$xact_id.xact %] -
  1. Transaction ID: [% xact_id %] - [% IF xact.circulation %][% helpers.get_copy_bib_basics(xact.circulation.target_copy).title %] - [% ELSE %]Miscellaneous - [% END %] - Line item billings:
      - [% SET mb_type_hash = {} %] - [% FOR mb IN xact.billings %][%# Group billings by their btype %] - [% IF mb.voided == 'f' %] - [% SET mb_type = mb.btype.id %] - [% IF ! mb_type_hash.defined( mb_type ) %][% mb_type_hash.$mb_type = { 'sum' => 0.00, 'billings' => [] } %][% END %] - [% IF ! mb_type_hash.$mb_type.defined( 'first_ts' ) %][% mb_type_hash.$mb_type.first_ts = mb.billing_ts %][% END %] - [% mb_type_hash.$mb_type.last_ts = mb.billing_ts %] - [% mb_type_hash.$mb_type.sum = mb_type_hash.$mb_type.sum + mb.amount %] - [% mb_type_hash.$mb_type.billings.push( mb ) %] - [% END %] - [% END %] - [% FOR mb_type IN mb_type_hash.keys.sort %] -
    1. [% IF mb_type == 1 %][%# Consolidated view of overdue billings %] - $[% mb_type_hash.$mb_type.sum %] for [% mb_type_hash.$mb_type.billings.0.btype.name %] - on [% mb_type_hash.$mb_type.first_ts %] through [% mb_type_hash.$mb_type.last_ts %] - [% ELSE %][%# all other billings show individually %] - [% FOR mb IN mb_type_hash.$mb_type.billings %] - $[% mb.amount %] for [% mb.btype.name %] on [% mb.billing_ts %] [% mb.note %] - [% END %] - [% END %]
    2. - [% END %] -
    - Line item payments:
      - [% FOR mp IN xact_mp_hash.$xact_id.payments %] -
    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 - [%- IF mp.credit_card_payment.cc_number %] ([% mp.credit_card_payment.cc_number %])[% END %] - [% CASE "credit_payment" %]credit - [% CASE "forgive_payment" %]forgiveness - [% CASE "goods_payment" %]goods - [% CASE "work_payment" %]work - [%- END %] on [% mp.payment_ts %] [% mp.note %] -
    2. - [% END %] -
    -
  2. - [% END %] -
-
-$$ - -WHERE id = 30 AND template = - -$$ -[%- USE date -%][%- SET user = target.0.xact.usr -%] -
-
[% date.format %]

-
    - [% SET xact_mp_hash = {} %] - [% FOR mp IN target %][%# Template is hooked around payments, but let us make the receipt focused on transactions %] - [% SET xact_id = mp.xact.id %] - [% IF ! xact_mp_hash.defined( xact_id ) %][% xact_mp_hash.$xact_id = { 'xact' => mp.xact, 'payments' => [] } %][% END %] - [% xact_mp_hash.$xact_id.payments.push(mp) %] - [% END %] - [% FOR xact_id IN xact_mp_hash.keys.sort %] - [% SET xact = xact_mp_hash.$xact_id.xact %] -
  1. Transaction ID: [% xact_id %] - [% IF xact.circulation %][% helpers.get_copy_bib_basics(xact.circulation.target_copy).title %] - [% ELSE %]Miscellaneous - [% END %] - Line item billings:
      - [% SET mb_type_hash = {} %] - [% FOR mb IN xact.billings %][%# Group billings by their btype %] - [% IF mb.voided == 'f' %] - [% SET mb_type = mb.btype.id %] - [% IF ! mb_type_hash.defined( mb_type ) %][% mb_type_hash.$mb_type = { 'sum' => 0.00, 'billings' => [] } %][% END %] - [% IF ! mb_type_hash.$mb_type.defined( 'first_ts' ) %][% mb_type_hash.$mb_type.first_ts = mb.billing_ts %][% END %] - [% mb_type_hash.$mb_type.last_ts = mb.billing_ts %] - [% mb_type_hash.$mb_type.sum = mb_type_hash.$mb_type.sum + mb.amount %] - [% mb_type_hash.$mb_type.billings.push( mb ) %] - [% END %] - [% END %] - [% FOR mb_type IN mb_type_hash.keys.sort %] -
    1. [% IF mb_type == 1 %][%# Consolidated view of overdue billings %] - $[% mb_type_hash.$mb_type.sum %] for [% mb_type_hash.$mb_type.billings.0.btype.name %] - on [% mb_type_hash.$mb_type.first_ts %] through [% mb_type_hash.$mb_type.last_ts %] - [% ELSE %][%# all other billings show individually %] - [% FOR mb IN mb_type_hash.$mb_type.billings %] - $[% mb.amount %] for [% mb.btype.name %] on [% mb.billing_ts %] [% mb.note %] - [% END %] - [% END %]
    2. - [% END %] -
    - Line item payments:
      - [% FOR mp IN xact_mp_hash.$xact_id.payments %] -
    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 ( - [%- SET cc_chunks = mp.credit_card_payment.cc_number.replace(' ','').chunk(4); -%] - [%- cc_chunks.slice(0, -1+cc_chunks.max).join.replace('\S','X') -%] - [% cc_chunks.last -%] - exp [% mp.credit_card_payment.expire_month %]/[% mp.credit_card_payment.expire_year -%] - ) - [% CASE "credit_payment" %]credit - [% CASE "forgive_payment" %]forgiveness - [% CASE "goods_payment" %]goods - [% CASE "work_payment" %]work - [%- END %] on [% mp.payment_ts %] [% mp.note %] -
    2. - [% END %] -
    -
  2. - [% END %] -
-
-$$; - - ---ROLLBACK; -COMMIT;