LP#1942220: (follow-up) fix handling of fund balance warning
authorGalen Charlton <gmc@equinoxOLI.org>
Tue, 11 Jan 2022 21:44:55 +0000 (16:44 -0500)
committerGalen Charlton <gmc@equinoxOLI.org>
Tue, 11 Jan 2022 21:44:55 +0000 (16:44 -0500)
This is now just a warning that requires an extra confirmation
step to activate a PO, not a blocker to activation.

Signed-off-by: Galen Charlton <gmc@equinoxOLI.org>
Open-ILS/src/eg2/src/app/staff/acq/po/summary.component.html
Open-ILS/src/eg2/src/app/staff/acq/po/summary.component.ts

index 4d4b350..f7407c1 100644 (file)
@@ -7,6 +7,12 @@
   dialogTitle="Finalize Blanket Order?"
   dialogBody="This will disencumber all blanket charges and mark the PO as received.">
 </eg-confirm-dialog>
+<eg-confirm-dialog #confirmActivate
+  i18n-dialogTitle i18n-dialogBody
+  dialogTitle="Confirm Order Activation?"
+  dialogBody="Please confirm that you want to activate the order; there are warnings.">
+</eg-confirm-dialog>
+
 
 <div *ngIf="po()" class="p-1 border border-secondary rounded">
 
               </span>
             </ng-container>
 
+            <!-- activation warnings -->
+            <ng-container *ngIf='activationWarnings.length'>
+              <span i18n> (Warning: </span>
+              <ng-container *ngFor="let evt of activationWarnings">
+                <ng-container 
+                 *ngIf="evt.textcode == 'ACQ_FUND_EXCEEDS_WARN_PERCENT'">
+                  <span class="bg-warning" i18n>
+                    Fund exceeds warning percent: 
+                    {{evt.payload.fund.code()}} ({{evt.payload.fund.year()}}).
+                  </span>
+                </ng-container>
+              </ng-container>
+              <span i18n>)</span>
+            </ng-container>
+
             <!-- activation blocks -->
             <div class="text-danger" *ngFor="let evt of activationBlocks">
               <ng-container 
-                *ngIf="evt.textcode == 'ACQ_FUND_EXCEEDS_STOP_PERCENT'; else fundWarn">
+                *ngIf="evt.textcode == 'ACQ_FUND_EXCEEDS_STOP_PERCENT'; else noPrice">
                 <span i18n>
                   Fund exceeds stop percent: 
                   {{evt.payload.fund.code()}} ({{evt.payload.fund.year()}}).
                 </span>
               </ng-container>
-              <ng-template #fundWarn>
-                <ng-container 
-                  *ngIf="evt.textcode == 'ACQ_FUND_EXCEEDS_WARN_PERCENT'; else noPrice">
-                  <span i18n>
-                    Fund exceeds warning percent: 
-                    {{evt.payload.fund.code()}} ({{evt.payload.fund.year()}}).
-                  </span>
-                </ng-container>
-              </ng-template>
               <ng-template #noPrice>
                 <ng-container 
                   *ngIf="evt.textcode == 'ACQ_LINEITEM_NO_PRICE'; else noCopies">
index 66d19d0..ec02900 100644 (file)
@@ -17,6 +17,10 @@ import {LineitemService} from '../lineitem/lineitem.service';
 import {CancelDialogComponent} from '../lineitem/cancel-dialog.component';
 import {LinkInvoiceDialogComponent} from '../lineitem/link-invoice-dialog.component';
 
+const PO_ACTIVATION_WARNINGS = [
+    'ACQ_FUND_EXCEEDS_WARN_PERCENT'
+];
+
 @Component({
   templateUrl: 'summary.component.html',
   selector: 'eg-acq-po-summary'
@@ -43,6 +47,7 @@ export class PoSummaryComponent implements OnInit, OnDestroy {
     showLegacyLinks = false;
 
     activationBlocks: EgEvent[] = [];
+    activationWarnings: EgEvent[] = [];
     activationEvent: EgEvent;
     nameEditEnterToggled = false;
     stateChangeSub: Subscription;
@@ -51,6 +56,7 @@ export class PoSummaryComponent implements OnInit, OnDestroy {
     @ViewChild('linkInvoiceDialog') linkInvoiceDialog: LinkInvoiceDialogComponent;
     @ViewChild('progressDialog') progressDialog: ProgressDialogComponent;
     @ViewChild('confirmFinalize') confirmFinalize: ConfirmDialogComponent;
+    @ViewChild('confirmActivate') confirmActivate: ConfirmDialogComponent;
 
     constructor(
         private router: Router,
@@ -183,6 +189,7 @@ export class PoSummaryComponent implements OnInit, OnDestroy {
     setCanActivate() {
         this.canActivate = null;
         this.activationBlocks = [];
+        this.activationWarnings = [];
 
         if (!(this.po().state().match(/new|pending/))) {
             this.canActivate = false;
@@ -200,7 +207,13 @@ export class PoSummaryComponent implements OnInit, OnDestroy {
         ).pipe(tap(resp => {
 
             const evt = this.evt.parse(resp);
-            if (evt) { this.activationBlocks.push(evt); }
+            if (evt) {
+                if (PO_ACTIVATION_WARNINGS.includes(evt.textcode)) {
+                    this.activationWarnings.push(evt);
+                } else {
+                    this.activationBlocks.push(evt);
+                }
+            }
 
         })).toPromise().then(_ => {
 
@@ -214,6 +227,18 @@ export class PoSummaryComponent implements OnInit, OnDestroy {
     }
 
     activatePo(noAssets?: boolean) {
+        if (this.activationWarnings.length) {
+            this.confirmActivate.open().subscribe(confirmed => {
+                if (!confirmed) { return; }
+
+                this._activatePo(noAssets);
+            });
+        } else {
+            this._activatePo(noAssets);
+        }
+    }
+
+    _activatePo(noAssets?: boolean) {
         this.activationEvent = null;
         this.progressDialog.open();
         this.progressDialog.update({max: this.po().lineitem_count() * 3});