LP1929741 Blanket order finalizing; improved charges handling
authorBill Erickson <berickxx@gmail.com>
Tue, 22 Jun 2021 18:06:00 +0000 (14:06 -0400)
committerJane Sandberg <js7389@princeton.edu>
Sun, 2 Oct 2022 15:02:49 +0000 (08:02 -0700)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Galen Charlton <gmc@equinoxOLI.org>
Signed-off-by: Jane Sandberg <js7389@princeton.edu>
Open-ILS/src/eg2/src/app/staff/acq/po/charges.component.html
Open-ILS/src/eg2/src/app/staff/acq/po/charges.component.ts
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 a51e067..7ee0484 100644 (file)
@@ -51,7 +51,7 @@
     <div class="flex-2 p-2">
       <span *ngIf="!charge.isnew()">{{charge.estimated_cost() | currency}}</span>
       <input *ngIf="charge.isnew()" type="number" min="0" class="form-control" 
-        i18n-placeholder placeholder="Esimated Cost..."
+        i18n-placeholder placeholder="Esimated Cost..." [required]="true"
         [ngModel]="charge.estimated_cost()" (ngModelChange)="charge.estimated_cost($event)"/>
     </div>
     <div class="flex-1 p-1">
index 3087aed..288c4b1 100644 (file)
@@ -50,7 +50,8 @@ export class PoChargesComponent implements OnInit {
     }
 
     saveCharge(charge: IdlObject) {
-        if (!charge.inv_item_type()) { return; }
+        if (!charge.inv_item_type() || !charge.fund()) { return; }
+        if (typeof charge.estimated_cost() !== 'number') { return; }
 
         charge.id(undefined);
         this.pcrud.create(charge).toPromise()
index e89d43e..262b020 100644 (file)
@@ -1,6 +1,11 @@
 
 <eg-acq-cancel-dialog #cancelDialog></eg-acq-cancel-dialog>
 <eg-progress-dialog #progressDialog></eg-progress-dialog>
+<eg-confirm-dialog #confirmFinalize
+  i18n-dialogTitle i18n-dialogBody
+  dialogTitle="Finalize Blanket Order?"
+  dialogBody="This will disencumber all blanket charges and mark the PO as received.">
+</eg-confirm-dialog>
 
 <div *ngIf="po()" class="p-1 border border-secondary rounded">
 
           <span i18n>Activate Order</span>
         </a>
       </ng-container>
+      <ng-container *ngIf="canFinalize">
+        <span class="pl-2 pr-2" i18n> | </span>
+        <a (click)="finalizePo()" href="javascript:;" class="label-with-material-icon">
+          <span class="material-icons small mr-1">check_circle</span>
+          <span i18n>Finalize Blanket Order</span>
+        </a>
+      </ng-container>
     </div>
   </div>
 
index 2cef47f..8d28763 100644 (file)
@@ -39,6 +39,7 @@ export class PoSummaryComponent implements OnInit {
     showNotes = false;
     zeroCopyActivate = false;
     canActivate: boolean = null;
+    canFinalize = false;
 
     activationBlocks: EgEvent[] = [];
     activationEvent: EgEvent;
@@ -46,6 +47,7 @@ export class PoSummaryComponent implements OnInit {
 
     @ViewChild('cancelDialog') cancelDialog: CancelDialogComponent;
     @ViewChild('progressDialog') progressDialog: ProgressDialogComponent;
+    @ViewChild('confirmFinalize') confirmFinalize: ConfirmDialogComponent;
 
     constructor(
         private router: Router,
@@ -85,7 +87,8 @@ export class PoSummaryComponent implements OnInit {
                 {purchase_order: this.poId}, {}, {idlist: true, atomic: true}
             ).toPromise().then(ids => this.ediMessageCount = ids.length);
 
-        }).then(_ => {
+        })
+        .then(_ => {
 
             // Invoice count
             return this.net.request('open-ils.acq',
@@ -94,7 +97,9 @@ export class PoSummaryComponent implements OnInit {
                 null, null, {id_list: true}
             ).toPromise().then(ids => this.invoiceCount = ids.length);
 
-        }).then(_ => this.setCanActivate());
+        })
+        .then(_ => this.setCanActivate())
+        .then(_ => this.setCanFinalize());
     }
 
     // Can run via Enter or blur.  If it just ran via Enter, avoid
@@ -226,6 +231,42 @@ export class PoSummaryComponent implements OnInit {
             }
         });
     }
+
+    setCanFinalize() {
+
+        if (this.po().state() === 'received') { return; }
+
+        var invTypes = [];
+
+        // get the unique set of invoice item type IDs
+        this.po().po_items().forEach(item => {
+            if (!invTypes.includes(item.inv_item_type())) {
+                invTypes.push(item.inv_item_type());
+            }
+        });
+
+        if (invTypes.length == 0) { return; }
+
+        this.pcrud.search('aiit',
+            {code: invTypes, blanket: 't'}, {limit: 1})
+        .subscribe(_ => this.canFinalize = true);
+    }
+
+    finalizePo() {
+
+        this.confirmFinalize.open().subscribe(confirmed => {
+            if (!confirmed) { return; }
+
+            this.net.request('open-ils.acq',
+                'open-ils.acq.purchase_order.blanket.finalize',
+                this.auth.token(), this.poId
+            ).subscribe(resp => {
+                if (Number(resp) === 1) {
+                    location.href = location.href;
+                }
+            });
+        });
+    }
 }