<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>
showNotes = false;
zeroCopyActivate = false;
canActivate: boolean = null;
+ canFinalize = false;
activationBlocks: EgEvent[] = [];
activationEvent: EgEvent;
@ViewChild('cancelDialog') cancelDialog: CancelDialogComponent;
@ViewChild('progressDialog') progressDialog: ProgressDialogComponent;
+ @ViewChild('confirmFinalize') confirmFinalize: ConfirmDialogComponent;
constructor(
private router: Router,
{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',
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
}
});
}
+
+ 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;
+ }
+ });
+ });
+ }
}