loaded = false;
+ accountExpired = false;
+ accountExpiresSoon = false;
+
constructor(
private net: NetService,
private auth: AuthService,
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',
{{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>
<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>
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';
export class PatronService {
constructor(
private net: NetService,
+ private org: OrgService,
private evt: EventService,
private pcrud: PcrudService,
private auth: AuthService
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;
+ });
+ }
}