From 9317e5ddacf27a53f5dc356bb7a00ac067a867ec Mon Sep 17 00:00:00 2001 From: Stephanie Leary Date: Tue, 16 May 2023 19:06:27 +0000 Subject: [PATCH] LP1984007 Fund warning logic to check balances Adds logic to check fund balances in order to set CSS warning/stop classes in funds dropdowns. Signed-off-by: Stephanie Leary --- .../src/app/staff/acq/po/charges.component.html | 6 +++++ .../eg2/src/app/staff/acq/po/charges.component.ts | 28 ++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/Open-ILS/src/eg2/src/app/staff/acq/po/charges.component.html b/Open-ILS/src/eg2/src/app/staff/acq/po/charges.component.html index 3b8fcdcbc2..298917bbb9 100644 --- a/Open-ILS/src/eg2/src/app/staff/acq/po/charges.component.html +++ b/Open-ILS/src/eg2/src/app/staff/acq/po/charges.component.html @@ -31,6 +31,7 @@ (onChange)="charge.fund($event ? $event.id : null)" i18n-placeholder placeholder="Fund..." [asyncSupportsEmptyTermClick]="true" + [displayTemplate]="fundTmpl" [required]="true" [readOnly]="!charge.isnew() && !charge.ischanged()" [idlQuerySort]="{acqf: 'year DESC, code'}" [idlQueryAnd]="{org: owners, active: 't'}"> @@ -87,3 +88,8 @@ + + + {{r.label}} + \ No newline at end of file diff --git a/Open-ILS/src/eg2/src/app/staff/acq/po/charges.component.ts b/Open-ILS/src/eg2/src/app/staff/acq/po/charges.component.ts index 6e968c750b..5da7fc8770 100644 --- a/Open-ILS/src/eg2/src/app/staff/acq/po/charges.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/acq/po/charges.component.ts @@ -23,6 +23,8 @@ export class PoChargesComponent implements OnInit, OnDestroy { poSubscription: Subscription; owners: number[]; classNames: string[]; + _fundBalanceCache: string[] = []; + _inflight: Promise[] = []; @ViewChild('disencumberChargeDialog') disencumberChargeDialog: DisencumberChargeDialogComponent; @@ -176,5 +178,31 @@ export class PoChargesComponent implements OnInit, OnDestroy { }).then(_ => this.poService.refreshOrderSummary(true)); } } + + // duplicated from acq/lineitem/copy-attrs.component + checkFundBalance(fundId: number): string { + if (this._fundBalanceCache[fundId]) { + return this._fundBalanceCache[fundId]; + } + if (this._inflight[fundId]) { + return 'ok'; + } + this._inflight[fundId] = this.net.request( + 'open-ils.acq', + 'open-ils.acq.fund.check_balance_percentages', + this.auth.token(), fundId + ).toPromise().then(r => { + if (r[0]) { + this._fundBalanceCache[fundId] = 'stop'; + } else if (r[1]) { + this._fundBalanceCache[fundId] = 'warning'; + } else { + this._fundBalanceCache[fundId] = 'ok'; + } + + delete this._inflight[fundId]; + return this._fundBalanceCache[fundId]; + }); + } } -- 2.11.0