JBAS-953 Drop CC cols local SQL
authorBill Erickson <berickxx@gmail.com>
Tue, 3 May 2016 15:59:43 +0000 (11:59 -0400)
committerBill Erickson <berickxx@gmail.com>
Thu, 21 Mar 2019 19:46:23 +0000 (15:46 -0400)
Column mods and print/email template updates.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
KCLS/sql/schema/deploy/drop-cc-cols.sql [new file with mode: 0644]
KCLS/sql/schema/revert/drop-cc-cols.sql [new file with mode: 0644]
KCLS/sql/schema/sqitch.plan
KCLS/sql/schema/verify/drop-cc-cols.sql [new file with mode: 0644]

diff --git a/KCLS/sql/schema/deploy/drop-cc-cols.sql b/KCLS/sql/schema/deploy/drop-cc-cols.sql
new file mode 100644 (file)
index 0000000..f73af50
--- /dev/null
@@ -0,0 +1,228 @@
+-- Deploy kcls-evergreen:drop-cc-cols to pg
+-- requires: sip-activity-types
+
+BEGIN;
+
+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;
+
+UPDATE action_trigger.event_definition SET template =
+$$
+[%- USE date -%]
+[%- SET user = target.xact.usr -%][% USE money=format('%.2f') -%]
+To: [%- params.recipient_email || user.email %]
+From: [%- params.sender_email || default_sender %]
+Subject: KCLS Payment Receipt
+
+[% MACRO mkdate(ts) GET date.format(helpers.format_date(ts), '%m/%d/%Y') %][% date.format(date.now, '%m/%d/%Y') %]
+Please print ALL PAGES of this receipt for your records.
+If you are paying for a lost item, and you return the item within 12 months of this date,
+this receipt will be REQUIRED to request a refund.
+
+Billing Info
+[% 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 %][% 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 %]    [% END %][% END %][% FOR mb_type IN mb_type_hash.keys.sort %][% IF mb_type == 1 %][%# Consolidated view of overdue billings %][% ELSE %][%# all other billings show individually %][% FOR mb IN mb_type_hash.$mb_type.billings %][% END %][% END %][% END %]
+
+[%- 
+FOR mp IN xact_mp_hash.$xact_id.payments;
+    SWITCH mp.payment_type;
+        CASE "cash_payment";
+        CASE "check_payment";
+        CASE "credit_payment";
+        CASE "forgive_payment";
+        CASE "goods_payment";
+        CASE "work_payment";
+        CASE "credit_card_payment";
+            # Default to XXXX when card number has been cleared.
+            cc_number = 'XXXX';
+            IF mp.credit_card_payment.cc_number;
+                cc_number = mp.credit_card_payment.cc_number; 
+            END %]
+Card Ending: [% cc_number %]
+Transaction #: [% mp.credit_card_payment.cc_order_number -%]
+    [% END; # SWITCH
+END; # FOR 
+-%]
+[% END -%]
+
+Paid Charges
+
+[% 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 %]
+[% IF xact.circulation %]Title: [% helpers.get_copy_bib_basics(xact.circulation.target_copy.id).title %]  -- Item Barcode: [% xact.circulation.target_copy.barcode %][% ELSE %]Type: Miscellaneous[% END %]
+Charges: [% 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 %]$[% money(mb_type_hash.$mb_type.sum) %] for [% mb_type_hash.$mb_type.billings.0.btype.name %] on [% mkdate(mb_type_hash.$mb_type.first_ts) %] through [% mkdate(mb_type_hash.$mb_type.last_ts) %][% ELSE %][%# all other billings show individually %][% FOR mb IN mb_type_hash.$mb_type.billings %]$[% money(mb.amount) %] for "[% mb.btype.name %]" on [% mkdate(mb.billing_ts) %][% IF mb.note %]([% mb.note %])[% END %][% END %][% END %][% END %]
+Payments:[% FOR mp IN xact_mp_hash.$xact_id.payments %]$[% money(mp.amount) %] paid by [% 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 [% mkdate(mp.payment_ts) %]
+[% END %][% END %]
+
+If the items listed on this receipt are returned within 12 months of the receipt date, you may request a refund within 12 months of the receipt date for the cost of the item minus any outstanding charges on your account. The usual overdue fee will still be in effect for the returned item. You may choose to pay this overdue fee at the time you request a refund or have the overdue fee deducted from the amount of the refund. Patrons requesting a refund must present this receipt at any KCLS location.
+
+Refunds are not available for parts and pieces, overdue fines, or items that do not display a specific title in My Account. For a list of refundable and nonrefundable items, visit http://www.kcls.org/usingthelibrary/borrowing/
+
+**END OF RECEIPT**
+$$
+WHERE id = 29;
+
+
+
+UPDATE action_trigger.event_definition SET template =
+$$
+[%- USE date -%][%- SET user = target.0.xact.usr -%]
+[% USE money=format('%.2f') -%]
+[% MACRO mkdate(ts) GET date.format(helpers.format_date(ts), '%m/%d/%Y') %]
+<style>
+
+
+    #cc-table { margin:25px; font-size:12px; }
+
+</style>
+
+<div style="li { padding: 8px; margin 5px;}">
+    <div style="font-size:12px">[% date.format(date.now, '%m/%d/%Y') %]</div><br/>
+   <div style="font-size:12px">
+<font color="#FF0000" >Please print ALL PAGES of this receipt for your records.<br/> If you are paying for a lost item, and you return the item within 12 months of this date,
+this receipt will be REQUIRED to request a refund.<br/></font>
+
+    </div>
+<div style="font-size:12px">
+      <br/>
+<b>Billing Info</b>
+[% 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 %]
+   
+                [% 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 %]
+                       
+                    [% END %]
+                [% END %]
+                [% FOR mb_type IN mb_type_hash.keys.sort %]
+                    [% IF mb_type == 1 %][%# Consolidated view of overdue billings %]
+                     
+                    [% ELSE %][%# all other billings show individually %]
+                        [% FOR mb IN mb_type_hash.$mb_type.billings %]
+                          
+                        [% END %]
+                    [% END %]
+                [% END %]
+
+    
+                [% FOR mp IN xact_mp_hash.$xact_id.payments %]
+                    [% SWITCH mp.payment_type -%]
+                        [% CASE "cash_payment" %]
+                        [% CASE "check_payment" %]
+                        [% CASE "credit_payment" %]
+                        [% CASE "forgive_payment" %]
+                        [% CASE "goods_payment" %]
+                        [% CASE "work_payment" %]
+                        [% CASE "credit_card_payment";
+                            # cc_number may have been cleared
+                            IF mp.credit_card_payment.cc_number;
+                                SET cc_number = mp.credit_card_payment.cc_number;
+                            END;
+                            # all CC payments have an order number
+                            SET cc_order_number = mp.credit_card_payment.cc_order_number;
+                        END %]
+                [% END %]
+    [% END %]
+
+<table id='cc-table'>
+[% IF cc_order_number %]
+    [% SET cc_number = 'XXXX' UNLESS cc_number %]
+    <tr><td>Card Ending:</td><td>[% cc_number %]</td></tr>
+    <tr><td>Transaction #:</td><td>[% cc_order_number %]</td></tr>
+[% END %]
+</table>
+</div>
+<div style="font-size:12px"><b>Paid Charges</b></div>
+<div style="font-size:12px">
+    <ol>
+    [% 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 %]
+        <li>
+            <b>
+             [% IF xact.circulation %][% helpers.get_copy_bib_basics(xact.circulation.target_copy.id).title %] <br/>Item Barcode: [% xact.circulation.target_copy.barcode %]
+            [% ELSE %]Miscellaneous
+            [% END %]</b>
+                     <br/>
+
+<b>Charges:</b>
+          
+                [% 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 %]
+                       <b> $[% money(mb_type_hash.$mb_type.sum) %] </b>for [% mb_type_hash.$mb_type.billings.0.btype.name %]
+                            on [% mkdate(mb_type_hash.$mb_type.first_ts) %] through [% mkdate(mb_type_hash.$mb_type.last_ts) %]
+                    [% ELSE %][%# all other billings show individually %]
+                        [% FOR mb IN mb_type_hash.$mb_type.billings %]
+                            <b>$[% money(mb.amount) %]</b> for "[% mb.btype.name %]" on [% mkdate(mb.billing_ts) %]
+     [% IF mb.note %]([% mb.note %])[% END %]
+
+                        [% END %]
+                    [% END %]
+                [% END %]
+<br/>   
+<b>Payments:</b>
+        
+                [% FOR mp IN xact_mp_hash.$xact_id.payments %]
+                   <b>$[% money(mp.amount) %]</b> paid by [% 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 [% mkdate(mp.payment_ts) %] <br/>
+                       
+                
+                [% END %]
+         
+       <br/>
+    [% END %]
+    </ol>
+</div>
+<div style="font-size:12px">
+If the items listed on this receipt are returned within 12 months of the receipt date, you may request a refund within 12 months of the receipt date for the cost of the item minus any outstanding charges on your account. The usual overdue fee will still be in effect for the returned item. You may choose to pay this overdue fee at the time you request a refund or have the overdue fee deducted from the amount of the refund. Patrons requesting a refund must present this receipt at any KCLS location.</br>
+Refunds are not available for parts and pieces, overdue fines, or items that do not display a specific title in My Account. For a list of refundable and nonrefundable items, visit <a href='http://www.kcls.org/usingthelibrary/borrowing/'>http://www.kcls.org/usingthelibrary/borrowing/</a><br/>
+**END OF RECEIPT**
+    </div>
+</div>
+</p>
+$$
+WHERE id = 30;
+
+
+
+COMMIT;
diff --git a/KCLS/sql/schema/revert/drop-cc-cols.sql b/KCLS/sql/schema/revert/drop-cc-cols.sql
new file mode 100644 (file)
index 0000000..b334414
--- /dev/null
@@ -0,0 +1,222 @@
+-- Revert kcls-evergreen:drop-cc-cols from pg
+
+BEGIN;
+
+ALTER TABLE money.credit_card_payment 
+    ADD COLUMN cc_type TEXT,
+    ADD COLUMN expire_month INT,
+    ADD COLUMN expire_year INT,
+    ADD COLUMN cc_first_name TEXT,
+    ADD COLUMN cc_last_name TEXT;
+
+UPDATE action_trigger.event_definition SET template =
+$$
+[%- USE date -%]
+[%- SET user = target.xact.usr -%][% USE money=format('%.2f') -%]
+To: [%- params.recipient_email || user.email %]
+From: [%- params.sender_email || default_sender %]
+Subject: KCLS Payment Receipt
+
+[% MACRO mkdate(ts) GET date.format(helpers.format_date(ts), '%m/%d/%Y') %][% date.format(date.now, '%m/%d/%Y') %]
+Please print ALL PAGES of this receipt for your records.
+If you are paying for a lost item, and you return the item within 12 months of this date,
+this receipt will be REQUIRED to request a refund.
+
+Billing Info
+[% 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 %][% 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 %]    [% END %][% END %][% FOR mb_type IN mb_type_hash.keys.sort %][% IF mb_type == 1 %][%# Consolidated view of overdue billings %][% ELSE %][%# all other billings show individually %][% FOR mb IN mb_type_hash.$mb_type.billings %][% END %][% END %][% END %][% FOR mp IN xact_mp_hash.$xact_id.payments %][% SWITCH mp.payment_type -%][% CASE "cash_payment" %][% CASE "check_payment" %][% CASE "credit_card_payment" %][% CASE "credit_payment" %][% CASE "forgive_payment" %][% CASE "goods_payment" %][% CASE "work_payment" %][%- END %][% IF mp.payment_type == 'credit_card_payment' %][%  SET cc_print1 = mp.credit_card_payment.cc_number.replace(' ','').chunk(-4).last %][% SET cc_print2 =  mp.credit_card_payment.cc_first_name %] [% SET cc_print3 = mp.credit_card_payment.cc_last_name %][% SET cc_print4 = mp.credit_card_payment.expire_month %][% SET cc_print5 = mp.credit_card_payment.expire_year -%][% IF mp.credit_card_payment.cc_order_number %][% SET cc_print6 = mp.credit_card_payment.cc_order_number %][% END %][% END %][% END %][% END %]
+Card Ending:[% cc_print1 %]
+Name:[% cc_print2 %] [% cc_print3 %]
+Exp:[% cc_print4 %]/[% cc_print5 %]
+Transaction #:[% cc_print6 %]
+
+Paid Charges
+
+[% 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 %]
+[% IF xact.circulation %]Title: [% helpers.get_copy_bib_basics(xact.circulation.target_copy.id).title %]  -- Item Barcode: [% xact.circulation.target_copy.barcode %][% ELSE %]Type: Miscellaneous[% END %]
+Charges: [% 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 %]$[% money(mb_type_hash.$mb_type.sum) %] for [% mb_type_hash.$mb_type.billings.0.btype.name %] on [% mkdate(mb_type_hash.$mb_type.first_ts) %] through [% mkdate(mb_type_hash.$mb_type.last_ts) %][% ELSE %][%# all other billings show individually %][% FOR mb IN mb_type_hash.$mb_type.billings %]$[% money(mb.amount) %] for "[% mb.btype.name %]" on [% mkdate(mb.billing_ts) %][% IF mb.note %]([% mb.note %])[% END %][% END %][% END %][% END %]
+Payments:[% FOR mp IN xact_mp_hash.$xact_id.payments %]$[% money(mp.amount) %] paid by [% 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 [% mkdate(mp.payment_ts) %]
+[% END %][% END %]
+
+If the items listed on this receipt are returned within 12 months of the receipt date, you may request a refund within 12 months of the receipt date for the cost of the item minus any outstanding charges on your account. The usual overdue fee will still be in effect for the returned item. You may choose to pay this overdue fee at the time you request a refund or have the overdue fee deducted from the amount of the refund. Patrons requesting a refund must present this receipt at any KCLS location.
+
+Refunds are not available for parts and pieces, overdue fines, or items that do not display a specific title in My Account. For a list of refundable and nonrefundable items, visit http://www.kcls.org/usingthelibrary/borrowing/
+
+**END OF RECEIPT**
+$$
+WHERE id = 29;
+
+
+
+UPDATE action_trigger.event_definition SET template =
+$$
+[%- USE date -%][%- SET user = target.0.xact.usr -%]
+[% USE money=format('%.2f') -%]
+[% MACRO mkdate(ts) GET date.format(helpers.format_date(ts), '%m/%d/%Y') %]
+<style>
+
+
+    #cc-table { margin:25px; font-size:12px; }
+
+</style>
+
+
+<div style="li { padding: 8px; margin 5px;}">
+    <div style="font-size:12px">[% date.format(date.now, '%m/%d/%Y') %]</div><br/>
+   <div style="font-size:12px">
+<font color="#FF0000" >Please print ALL PAGES of this receipt for your records.<br/> If you are paying for a lost item, and you return the item within 12 months of this date,
+this receipt will be REQUIRED to request a refund.<br/></font>
+
+
+    </div>
+<div style="font-size:12px">
+      <br/>
+<b>Billing Info</b>
+[% 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 %]
+   
+
+         
+
+      
+                [% 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 %]
+                       
+                    [% END %]
+                [% END %]
+                [% FOR mb_type IN mb_type_hash.keys.sort %]
+                    [% IF mb_type == 1 %][%# Consolidated view of overdue billings %]
+                     
+                    [% ELSE %][%# all other billings show individually %]
+                        [% FOR mb IN mb_type_hash.$mb_type.billings %]
+                          
+                        [% END %]
+                    [% END %]
+                [% END %]
+
+    
+                [% FOR mp IN xact_mp_hash.$xact_id.payments %]
+                 [% SWITCH mp.payment_type -%]
+                            [% CASE "cash_payment" %]
+                            [% CASE "check_payment" %]
+                            [% CASE "credit_card_payment" %]
+                            [% CASE "credit_payment" %]
+                            [% CASE "forgive_payment" %]
+                            [% CASE "goods_payment" %]
+                            [% CASE "work_payment" %]
+                        [%- END %]
+                        [% IF mp.payment_type == 'credit_card_payment' %]
+                        
+                          [%  SET cc_print1 = mp.credit_card_payment.cc_number.replace(' ','').chunk(-4).last %]
+                [% SET cc_print2 =  mp.credit_card_payment.cc_first_name %] [% SET cc_print3 = mp.credit_card_payment.cc_last_name %]
+                            [% SET cc_print4 = mp.credit_card_payment.expire_month %][% SET cc_print5 = mp.credit_card_payment.expire_year -%]
+                            [% IF mp.credit_card_payment.cc_order_number %]
+                                [% SET cc_print6 = mp.credit_card_payment.cc_order_number %]
+                            [% END %]
+                          
+                        [% END %]
+                 
+                [% END %]
+  
+    [% END %]
+
+<table id='cc-table'>
+<tr><td>Card Ending:</td><td>[% cc_print1 %]</td></tr>
+<tr><td>Name:</td><td>[% cc_print2 %]&nbsp;[% cc_print3 %]</td></tr>
+<tr><td>Exp:</td><td>[% cc_print4 %]/[% cc_print5 %]</td></tr>
+<tr><td>Transaction #:</td><td>[% cc_print6 %]</td></tr>
+</table>
+</div>
+<div style="font-size:12px"><b>Paid Charges</b></div>
+<div style="font-size:12px">
+    <ol>
+    [% 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 %]
+        <li>
+            <b>
+             [% IF xact.circulation %][% helpers.get_copy_bib_basics(xact.circulation.target_copy.id).title %] <br/>Item Barcode: [% xact.circulation.target_copy.barcode %]
+            [% ELSE %]Miscellaneous
+            [% END %]</b>
+                     <br/>
+
+<b>Charges:</b>
+          
+                [% 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 %]
+                       <b> $[% money(mb_type_hash.$mb_type.sum) %] </b>for [% mb_type_hash.$mb_type.billings.0.btype.name %]
+                            on [% mkdate(mb_type_hash.$mb_type.first_ts) %] through [% mkdate(mb_type_hash.$mb_type.last_ts) %]
+                    [% ELSE %][%# all other billings show individually %]
+                        [% FOR mb IN mb_type_hash.$mb_type.billings %]
+                            <b>$[% money(mb.amount) %]</b> for "[% mb.btype.name %]" on [% mkdate(mb.billing_ts) %]
+     [% IF mb.note %]([% mb.note %])[% END %]
+
+                        [% END %]
+                    [% END %]
+                [% END %]
+<br/>   
+<b>Payments:</b>
+        
+                [% FOR mp IN xact_mp_hash.$xact_id.payments %]
+                   <b>$[% money(mp.amount) %]</b> paid by [% 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 [% mkdate(mp.payment_ts) %] <br/>
+                       
+                
+                [% END %]
+         
+       <br/>
+    [% END %]
+    </ol>
+</div>
+<div style="font-size:12px">
+If the items listed on this receipt are returned within 12 months of the receipt date, you may request a refund within 12 months of the receipt date for the cost of the item minus any outstanding charges on your account. The usual overdue fee will still be in effect for the returned item. You may choose to pay this overdue fee at the time you request a refund or have the overdue fee deducted from the amount of the refund. Patrons requesting a refund must present this receipt at any KCLS location.</br>
+Refunds are not available for parts and pieces, overdue fines, or items that do not display a specific title in My Account. For a list of refundable and nonrefundable items, visit <a href='http://www.kcls.org/usingthelibrary/borrowing/'>http://www.kcls.org/usingthelibrary/borrowing/</a><br/>
+**END OF RECEIPT**
+    </div>
+</div>
+</p>
+$$
+WHERE id = 30;
+
+
+
+
+
+COMMIT;
index 765dcfe..0013d98 100644 (file)
@@ -23,3 +23,4 @@ patron-self-reg-mods [blanket-po-print-template] 2016-01-13T20:14:00Z Bill Erick
 sip-activity-types [2.7-auth-reingest] 2016-03-15T21:30:39Z Bill Erickson <berickxx@gmail.com> # User activity types for hoopla/lynda SIP auth
 ingram-edi-mods [sip-activity-types] 2016-05-24T16:31:46Z Bill Erickson <berickxx@gmail.com> # Ingram EDI config updates
 org-unit-addrs-copy [sip-activity-types] 2016-05-03T14:17:59Z Bill Erickson <berickxx@gmail.com> # Give each org unit its own mailing address
+drop-cc-cols [sip-activity-types] 2016-05-03T15:26:50Z Bill Erickson <berickxx@gmail.com> # Drop unneeded CC payment columns
diff --git a/KCLS/sql/schema/verify/drop-cc-cols.sql b/KCLS/sql/schema/verify/drop-cc-cols.sql
new file mode 100644 (file)
index 0000000..f283284
--- /dev/null
@@ -0,0 +1,7 @@
+-- Verify kcls-evergreen:drop-cc-cols on pg
+
+BEGIN;
+
+-- XXX Add verifications here.
+
+ROLLBACK;