LP1904036 patron expire check
authorBill Erickson <berickxx@gmail.com>
Tue, 18 Aug 2020 14:48:12 +0000 (10:48 -0400)
committerGalen Charlton <gmc@equinoxOLI.org>
Fri, 28 Oct 2022 00:13:22 +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/circ/patron/patron.service.ts
Open-ILS/src/eg2/src/app/staff/circ/patron/summary.component.html
Open-ILS/src/eg2/src/app/staff/share/patron/patron.service.ts

index ef7c004..0f1a8bb 100644 (file)
@@ -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<any> {
+    setExpires(): Promise<any> {
+        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<any> {
 
         return this.net.request(
             'open-ils.actor',
index d1d0eb7..a7e7cf8 100644 (file)
@@ -7,6 +7,12 @@
     {{patronService.namePart(context.patron, 'second_given_name')}}
   </h3>
 
+  <div class="row mb-1 alert alert-danger p-0" *ngIf="context.accountExpiresSoon">
+    <div class="col-lg-12" i18n>
+      Patron account will expire soon.  Please renew.
+    </div>
+  </div>
+
   <div class="row mb-1">
     <div class="col-lg-5" i18n>Profile</div>
     <div class="col-lg-7">{{context.patron.profile().name()}}</div>
@@ -43,7 +49,7 @@
     <div class="col-lg-5" i18n>Create Date</div>
     <div class="col-lg-7">{{context.patron.create_date() | date:'shortDate'}}</div>
   </div>
-  <div class="row">
+  <div class="row" [ngClass]="{'alert alert-danger p-0': context.accountExpired}">
     <div class="col-lg-5" i18n>Expire Date</div>
     <div class="col-lg-7">{{context.patron.expire_date() | date:'shortDate'}}</div>
   </div>
 
   <ng-container *ngIf="context.patronStats">
 
-    <div class="row mb-1">
+    <div class="row mb-1"
+      [ngClass]="{'alert alert-danger p-0': context.patronStats.fines.total_owed > 0}">
       <div class="col-lg-5" i18n>Fines Owed</div>
       <div class="col-lg-7">{{context.patronStats.fines.total_owed | currency}}</div>
     </div>
+
+    <!-- TODO GROUP FINES -->
+
     <div class="row mb-1">
       <div class="col-lg-5" i18n>Items Out</div>
       <div class="col-lg-7">{{context.patronStats.checkouts.total_out}}</div>
index d459b45..5939cca 100644 (file)
@@ -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;
+        });
+    }
 }