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');
+ }
+
}
</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;