From 1ddcb86c6148e0b2a0abc1eedec8f0d5c1ccb9a0 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Tue, 18 Aug 2020 10:48:12 -0400 Subject: [PATCH] LP1904036 patron expire check Signed-off-by: Bill Erickson Signed-off-by: Jane Sandberg Signed-off-by: Galen Charlton --- .../src/app/staff/circ/patron/patron.service.ts | 20 ++++++++++++++++- .../app/staff/circ/patron/summary.component.html | 14 ++++++++++-- .../src/app/staff/share/patron/patron.service.ts | 26 ++++++++++++++++++++++ 3 files changed, 57 insertions(+), 3 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/staff/circ/patron/patron.service.ts b/Open-ILS/src/eg2/src/app/staff/circ/patron/patron.service.ts index ef7c004acb..0f1a8bbe56 100644 --- a/Open-ILS/src/eg2/src/app/staff/circ/patron/patron.service.ts +++ b/Open-ILS/src/eg2/src/app/staff/circ/patron/patron.service.ts @@ -49,6 +49,9 @@ export class PatronManagerService { loaded = false; + accountExpired = false; + accountExpiresSoon = false; + constructor( private net: NetService, private auth: AuthService, @@ -65,10 +68,25 @@ export class PatronManagerService { this.auth.token(), id, PATRON_FLESH_FIELDS).toPromise() .then(patron => this.patron = patron) .then(_ => this.getPatronStats(id)) + .then(_ => this.setExpires()) .then(_ => this.loaded = true); } - getPatronStats(id: number): Promise { + setExpires(): Promise { + this.accountExpired = false; + this.accountExpiresSoon = false; + + return this.patronService.testExpire(this.patron) + .then(value => { + if (value === 'expired') { + this.accountExpired = true; + } else if (value === 'soon') { + this.accountExpiresSoon = true; + } + }); + } + + getPatronStats(id: number): Promise { return this.net.request( 'open-ils.actor', diff --git a/Open-ILS/src/eg2/src/app/staff/circ/patron/summary.component.html b/Open-ILS/src/eg2/src/app/staff/circ/patron/summary.component.html index d1d0eb7978..a7e7cf84a7 100644 --- a/Open-ILS/src/eg2/src/app/staff/circ/patron/summary.component.html +++ b/Open-ILS/src/eg2/src/app/staff/circ/patron/summary.component.html @@ -7,6 +7,12 @@ {{patronService.namePart(context.patron, 'second_given_name')}} +
+
+ Patron account will expire soon. Please renew. +
+
+
Profile
{{context.patron.profile().name()}}
@@ -43,7 +49,7 @@
Create Date
{{context.patron.create_date() | date:'shortDate'}}
-
+
Expire Date
{{context.patron.expire_date() | date:'shortDate'}}
@@ -52,10 +58,14 @@ -
+
Fines Owed
{{context.patronStats.fines.total_owed | currency}}
+ + +
Items Out
{{context.patronStats.checkouts.total_out}}
diff --git a/Open-ILS/src/eg2/src/app/staff/share/patron/patron.service.ts b/Open-ILS/src/eg2/src/app/staff/share/patron/patron.service.ts index d459b45a10..5939cca086 100644 --- a/Open-ILS/src/eg2/src/app/staff/share/patron/patron.service.ts +++ b/Open-ILS/src/eg2/src/app/staff/share/patron/patron.service.ts @@ -1,6 +1,7 @@ import {Injectable} from '@angular/core'; import {IdlObject} from '@eg/core/idl.service'; import {NetService} from '@eg/core/net.service'; +import {OrgService} from '@eg/core/org.service'; import {EventService} from '@eg/core/event.service'; import {PcrudService} from '@eg/core/pcrud.service'; import {AuthService} from '@eg/core/auth.service'; @@ -11,6 +12,7 @@ import {Observable} from 'rxjs'; export class PatronService { constructor( private net: NetService, + private org: OrgService, private evt: EventService, private pcrud: PcrudService, private auth: AuthService @@ -56,5 +58,29 @@ export class PatronService { if (!patron) { return ''; } return patron['pref_' + part]() || patron[part](); } + + + // Returns promise of 'expired', 'soon', or null depending on the + // expire date disposition of the provided patron. + testExpire(patron: IdlObject): Promise<'expired' | 'soon'> { + + const expire = new Date(Date.parse(patron.expire_date())); + if (expire < new Date()) { + return Promise.resolve('expired'); + } + + return this.org.settings(['circ.patron_expires_soon_warning']) + .then(setting => { + const days = setting['circ.patron_expires_soon_warning']; + + if (Number(days)) { + const preExpire = new Date(); + preExpire.setDate(preExpire.getDate() + Number(days)); + if (expire < preExpire) { return 'soon'; } + } + + return null; + }); + } } -- 2.11.0