LP1904036 Payment receipts
authorBill Erickson <berickxx@gmail.com>
Thu, 11 Mar 2021 16:55:27 +0000 (11:55 -0500)
committerGalen Charlton <gmc@equinoxOLI.org>
Fri, 28 Oct 2022 00:13:26 +0000 (20:13 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Jane Sandberg <js7389@princeton.edu>
Signed-off-by: Galen Charlton <gmc@equinoxOLI.org>
Open-ILS/src/eg2/src/app/staff/admin/server/print-template.component.ts
Open-ILS/src/eg2/src/app/staff/circ/patron/bills.component.ts
Open-ILS/src/eg2/src/app/staff/share/patron/search.component.ts
Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm
Open-ILS/src/sql/Pg/upgrade/XXXX.data.angular-patron.sql

index 3cd8d56..e6542ab 100644 (file)
@@ -112,7 +112,7 @@ export class PrintTemplateComponent implements OnInit {
 
         this.sampleData.holds_for_bib = wide_holds;
 
-        // Flesh the summary
+        // Bills
         samples.mbt[0].summary = samples.mbts[0];
         samples.mbt[1].summary = samples.mbts[1];
         samples.mbt[2].summary = samples.mbts[2];
@@ -122,6 +122,28 @@ export class PrintTemplateComponent implements OnInit {
             samples.mbt[1],
             samples.mbt[2]
         ];
+
+        // Payments
+        this.sampleData.bills_payment = {
+            previous_balance: 10,
+            payment_type: 'cash_payment',
+            payment_total: 5,
+            payment_applied: 3,
+            amount_voided: 0,
+            change_given: 2,
+            payment_note: 'Test Note',
+            payments: [{
+                amount: 1,
+                xact: samples.mbt[0],
+                title: 'A Title',
+                copy_barcode: '3423482302393'
+            }, {
+                amount: 4,
+                xact: samples.mbt[1],
+                title: 'Another Title',
+                copy_barcode: '3423482302394'
+            }]
+        };
     }
 
     onTabChange(evt: NgbTabChangeEvent) {
index a894aa7..2bf5f2d 100644 (file)
@@ -319,17 +319,7 @@ export class BillsComponent implements OnInit, AfterViewInit {
         .finally(() => this.applyingPayment = false);
     }
 
-    handlePayReceipt(payments: Array<Array<number>>, paymentIds: number[]): Promise<any> {
-
-        if (this.disableAutoPrint || !this.receiptOnPayment) {
-            return Promise.resolve();
-        }
-
-        // TODO
-        // return this.printer.pr
-    }
-
-    compilePayments(): Array<Array<number>> {
+    compilePayments(): Array<Array<number>> { // [ [xactId, payAmount], ... ]
         const payments = [];
         this.entries.forEach(row => {
             if (row.paymentPending) {
@@ -431,5 +421,43 @@ export class BillsComponent implements OnInit, AfterViewInit {
             printContext: 'default'
         });
     }
+
+    handlePayReceipt(payments: Array<Array<number>>, paymentIds: number[]): Promise<any> {
+
+        if (this.disableAutoPrint || !this.receiptOnPayment) {
+            return Promise.resolve();
+        }
+
+        const context = {
+            payments: [],
+            previous_balance: this.context.patronStats.fines.balance_owed,
+            payment_type: this.paymentType,
+            payment_total: this.paymentAmount,
+            payment_applied: this.pendingPayment(),
+            amount_voided: this.sessionVoided,
+            change_given: this.pendingChange(),
+            payment_note: this.paymentNote
+        };
+
+        payments.forEach(payment => {
+            const entry =
+                this.entries.filter(entry => entry.xact.id() === payment[0])[0];
+
+            context.payments.push({
+                amount: payment[1],
+                xact: entry.xact,
+                title: entry.title,
+                copy_barcode: entry.copy ? entry.copy.barcode() : ''
+            });
+        });
+
+        this.printer.print({
+            templateName: 'bills_payment',
+            contextData: context,
+            printContext: 'receipt'
+        });
+    }
+
+
 }
 
index 2434156..d8a172c 100644 (file)
@@ -50,6 +50,7 @@ export class PatronSearchComponent implements OnInit, AfterViewInit {
 
     @ViewChild('searchGrid', {static: false}) searchGrid: GridComponent;
 
+    startWithFired = false;
     @Input() startWithSearch: PatronSearch;
 
     // Fires on dbl-click or Enter while one or more search result
@@ -171,11 +172,13 @@ export class PatronSearchComponent implements OnInit, AfterViewInit {
 
     searchByForm(pager: Pager, sort: any[]): Observable<IdlObject> {
 
-        if (this.startWithSearch) {
+        if (this.startWithSearch && !this.startWithFired) {
             this.absorbPatronSearch(this.startWithSearch);
-            this.startWithSearch = null;
         }
 
+        // Never fire a "start with" search after any search has fired
+        this.startWithFired = true;
+
         const search = this.compileSearch();
         if (!search) { return of(); }
 
index 3bf2c14..be10105 100644 (file)
@@ -5396,25 +5396,25 @@ sub user_billing_xacts {
             $xact_id, {
                 flesh => 5,
                 flesh_fields => {
-                                   mbt => [qw/summary circulation grocery/],
-                                   circ => [qw/
+                    mbt => [qw/summary circulation grocery/],
+                    circ => [qw/
                         target_copy 
                         workstation 
                         checkin_workstation 
                     /],
-                                   acp =>  [qw/
-                                           call_number
-                                           holds_count
-                                           status
-                                           circ_lib
-                                           location
-                                           floating
-                                           age_protect
-                                           parts
-                                   /],
-                                   acpm => [qw/part/],
-                                   acn =>  [qw/record owning_lib prefix suffix/],
-                                   bre =>  [qw/wide_display_entry/]
+                    acp =>  [qw/
+                        call_number
+                        holds_count
+                        status
+                        circ_lib
+                        location
+                        floating
+                        age_protect
+                        parts
+                    /],
+                    acpm => [qw/part/],
+                    acn =>  [qw/record owning_lib prefix suffix/],
+                    bre =>  [qw/wide_display_entry/]
                 },
                 # Avoid adding the MARXML
                 # Fleshed fields are implicitly included.
index 5517680..55fbd79 100644 (file)
@@ -60,7 +60,6 @@ UPDATE config.print_template SET active = TRUE WHERE name = 'patron_address';
 INSERT INTO config.print_template 
     (name, label, owner, active, locale, content_type, template)
 VALUES ('bills_current', 'Bills, Current', 1, TRUE, 'en-US', 'text/html', '');
-*/
 
 UPDATE config.print_template SET template = $TEMPLATE$
 [% 
@@ -124,6 +123,102 @@ UPDATE config.print_template SET template = $TEMPLATE$
 </div>
 $TEMPLATE$ WHERE name = 'bills_current';
 
+
+INSERT INTO config.print_template 
+    (name, label, owner, active, locale, content_type, template)
+VALUES ('bills_payment', 'Bills, Payment', 1, TRUE, 'en-US', 'text/html', '');
+*/
+
+UPDATE config.print_template SET template = $TEMPLATE$
+[% 
+  USE date;
+  USE money = format('$%.2f');
+  SET payments = template_data.payments;
+  SET previous_balance = template_data.previous_balance;
+  SET payment_type = template_data.payment_type;
+  SET payment_total = template_data.payment_total;
+  SET payment_applied = template_data.payment_applied;
+  SET amount_voided = template_data.amount_voided;
+  SET change_given = template_data.change_given;
+  SET payment_note = template_data.payment_note;
+  SET copy_barcode = template_data.copy_barcode;
+  SET title = template_data.title;
+%]
+<div>
+  <style>td { padding: 1px 3px 1px 3px; }</style>
+  <div>Welcome to [% staff_org.name %]</div>
+  <div>A receipt of your transaction:</div>
+  <hr/>
+
+  <table style="width:100%"> 
+    <tr> 
+      <td>Original Balance:</td> 
+      <td align="right">[% money(previous_balance) %]</td> 
+    </tr> 
+    <tr> 
+      <td>Payment Method:</td> 
+      <td align="right">
+        [% SWITCH payment_type %]
+          [% CASE "cash_payment" %]Cash
+          [% CASE "check_payment" %]Check
+          [% CASE "credit_card_payment" %]Credit Card
+          [% CASE "debit_card_payment" %]Debit Card
+          [% CASE "credit_payment" %]Patron Credit
+          [% CASE "work_payment" %]Work
+          [% CASE "forgive_payment" %]Forgive
+          [% CASE "goods_payment" %]Goods
+        [% END %]
+      </td>
+    </tr> 
+    <tr> 
+      <td>Payment Received:</td> 
+      <td align="right">[% money(payment_total) %]</td> 
+    </tr> 
+    <tr> 
+      <td>Payment Applied:</td> 
+      <td align="right">[% money(payment_applied) %]</td> 
+    </tr> 
+    <tr> 
+      <td>Billings Voided:</td> 
+      <td align="right">[% money(amount_voided) %]</td> 
+    </tr> 
+    <tr> 
+      <td>Change Given:</td> 
+      <td align="right">[% money(change_given) %]</td> 
+    </tr> 
+    <tr> 
+      <td>New Balance:</td> 
+      <td align="right">[% money(new_balance) %]</td> 
+    </tr> 
+  </table> 
+  <p>Note: [% payment_note %]</p>
+  <p>
+    Specific Bills
+    <blockquote>
+      [% FOR payment IN payments %]
+        <table style="width:100%">
+          <tr>
+            <td>Bill # [% payment.xact.id %]</td>
+            <td>[% payment.xact.summary.last_billing_type %]</td>
+            <td>Received: [% money(payment.amount) %]</td>
+          </tr>
+          [% IF payment.copy_barcode %]
+          <tr>
+            <td colspan="5">[% payment.copy_barcode %] [% payment.title %]</td>
+          </tr>
+          [% END %]
+        </table>
+        <br/>
+      [% END %]
+    </blockquote>
+  </p> 
+  <hr/>
+  <br/><br/> 
+  <div>[% staff_org.name %] [% date.format(date.now, '%x %r') %]</div>
+  <div>You were helped by [% staff.first_given_name %]</div>
+</div>
+$TEMPLATE$ WHERE name = 'bills_payment';
+
 COMMIT;