LP1840773 SCKO Angular
authorBill Erickson <berickxx@gmail.com>
Wed, 29 Jun 2022 16:54:05 +0000 (12:54 -0400)
committerBill Erickson <berickxx@gmail.com>
Wed, 29 Jun 2022 16:54:05 +0000 (12:54 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/scko/items.component.ts
Open-ILS/src/eg2/src/app/scko/scko.service.ts
Open-ILS/src/eg2/src/app/scko/summary.component.html
Open-ILS/src/eg2/src/app/scko/summary.component.ts
Open-ILS/src/sql/Pg/upgrade/YYYY.data.scko-angular.sql

index bd759e8..9da559e 100644 (file)
@@ -49,6 +49,7 @@ export class SckoItemsComponent implements OnInit {
         });
     }
 
+    // TODO use scko versions
     isPrecat(copy: IdlObject): boolean {
         return Number(copy.id()) === -1;
     }
index 13e2202..619bb00 100644 (file)
@@ -578,6 +578,102 @@ export class SckoService {
 
         return promise;
     }
+
+    logoutPatron(receiptType: string): Promise<any> {
+
+        let promise;
+
+        switch (receiptType) {
+            case 'email':
+                promise = this.emailReceipt()
+                break;
+            case 'print':
+                promise = this.printReceipt();
+                break;
+            default:
+                promise = Promise.resolve();
+        }
+
+        return promise.then(_ => {
+            this.resetPatron();
+            this.router.navigate(['/scko']);
+        });
+    }
+
+    emailReceipt(): Promise<any> {
+
+        const circIds = this.sessionCheckouts
+            .filter(c => Boolean(c.circ)).map(c => c.circ.id());
+
+        return this.net.request(
+            'open-ils.circ',
+            'open-ils.circ.checkout.batch_notify.session.atomic',
+            this.auth.token(), this.patronSummary.id, circIds
+        ).toPromise();
+    }
+
+    printReceipt(): Promise<any> {
+
+        return new Promise((resolve, reject) => {
+
+            const sub = this.printer.printJobQueued$.subscribe(_ => {
+                sub.unsubscribe();
+                // Give the print operation just a bit more time after
+                // the data is passed to the printer just to be safe.
+                setTimeout(() => resolve, 1000);
+            });
+
+            const data = this.sessionCheckouts.map(c => {
+                return {
+                    checkout: c,
+                    barcode: c.ctx.barcode,
+                    circ: c.circ,
+                    copy: c.circ ? c.circ.target_copy() : null,
+                    title: this.getCircTitle(c.circ),
+                    author: this.getCircAuthor(c.circ)
+                };
+            });
+
+
+            this.printer.print({
+                templateName: 'scko_checkouts',
+                contextData: {
+                    checkouts: data,
+                    user: this.patronSummary.patron
+                },
+                printContext: 'default'
+            });
+        });
+    }
+
+    copyIsPrecat(copy: IdlObject): boolean {
+        return Number(copy.id()) === -1;
+    }
+
+    circDisplayValue(circ: IdlObject, field: string): string {
+        if (!circ) { return ''; }
+
+        const entry =
+            circ.target_copy().call_number().record().flat_display_entries()
+            .filter(e => e.name() === field)[0];
+
+        return entry ? entry.value() : '';
+    }
+
+    getCircTitle(circ: IdlObject): string {
+        if (!circ) { return ''; }
+        const copy = circ.target_copy();
+        if (this.copyIsPrecat(copy)) { return copy.dummy_title(); }
+        return this.circDisplayValue(circ, 'title');
+    }
+
+    getCircAuthor(circ: IdlObject): string {
+        if (!circ) { return ''; }
+        const copy = circ.target_copy();
+        if (this.copyIsPrecat(copy)) { return copy.dummy_author(); }
+        return this.circDisplayValue(circ, 'author');
+    }
+
 }
 
 
index dd9cf29..f7329a0 100644 (file)
@@ -3,12 +3,12 @@
 
   <div class="pl-2">
     <span>
-      <a (click)="null" class="mr-2">
+      <a routerLink="/scko" class="mr-2">
         <button type="button" class="scko-button">Home</button>
       </a>
     </span>
     <span>
-      <a (click)="null">
+      <a (click)="scko.logoutPatron(receiptType)">
         <button type="button" class="scko-button">Logout</button>
       </a>
     </span>
index fa46b22..3b434c6 100644 (file)
@@ -23,7 +23,6 @@ export class SckoSummaryComponent implements OnInit {
     ) {}
 
     ngOnInit() {
-
         this.scko.patronLoaded.subscribe(() => {
             if (this.canEmail()) {
                 this.showEmailOption = true;
@@ -33,7 +32,6 @@ export class SckoSummaryComponent implements OnInit {
                 this.receiptType = 'print';
             }
         });
-
     }
 
     canEmail(): boolean {
index 0fc7040..a2dc616 100644 (file)
@@ -135,6 +135,43 @@ UPDATE config.print_template SET template = $TEMPLATE$
 </div>
 $TEMPLATE$ WHERE name = 'scko_fines';
 
+INSERT INTO config.print_template 
+    (name, label, owner, active, locale, content_type, template)
+VALUES ('scko_checkouts', 'Self-Checkout Checkouts', 1, TRUE, 'en-US', 'text/html', '');
+
+UPDATE config.print_template SET template = $TEMPLATE$
+[%- 
+    USE date;
+    SET user = template_data.user;
+    SET checkouts = template_data.checkouts;
+-%]
+<div>
+  <style> li { padding: 8px; margin 5px; }</style>
+  <div>[% date.format(date.now, '%x %r') %]</div>
+  <br/>
+
+  [% user.pref_family_name || user.family_name %], 
+  [% user.pref_first_given_name || user.first_given_name %]
+
+  <ol>
+  [% FOR checkout IN checkouts %]
+    <li>
+      <div>[% checkout.title %]</div>
+      <div>Barcode: [% checkout.barcode %]</div>
+      <div>Due Date: [% 
+        IF checkout.circ;
+            date.format(helpers.format_date(
+                checkout.circ.due_date, staff_org_timezone), '%x %r') 
+        END;
+      %]
+      </div>
+    </li>
+  [% END %]
+  </ol>
+</div>
+$TEMPLATE$ WHERE name = 'scko_checkouts';
+
+
 COMMIT;