<button class="btn btn-warning btn-sm ml-1"
(click)="disencumberCharge(charge)" *ngIf="canDisencumber(charge)" i18n>Disencumber</button>
<button class="btn btn-danger btn-sm ml-1"
- (click)="removeCharge(charge)" *ngIf="canModify" i18n>Remove</button>
+ (click)="removeCharge(charge)" *ngIf="canDelete(charge)" i18n>Remove</button>
</div>
</div>
</ng-container>
return true; // we're likely OK to disencumber
}
+ canDelete(charge: IdlObject): boolean {
+ if (!this.po()) {
+ return false;
+ }
+
+ const debit = charge.fund_debit();
+ if (debit && debit.encumbrance() === 'f') {
+ return false; // if it's expended, we can't just delete it
+ }
+ if (debit.invoice_entry()) {
+ return false; // we shouldn't actually be a po_item that is
+ // linked to an invoice_entry, but if we are,
+ // do NOT touch
+ }
+ if (debit.invoice_items() && debit.invoice_items().length) {
+ return false; // we're linked to an invoice item, so the disposition of the
+ // invoice entry should govern things
+ }
+ return true; // we're likely OK to delete
+ }
+
disencumberCharge(charge: IdlObject) {
this.disencumberChargeDialog.charge = charge;
this.disencumberChargeDialog.open().subscribe(doIt => {
);
if (!charge.isnew()) {
- this.pcrud.remove(charge).toPromise()
- .then(_ => this.poService.refreshOrderSummary());
+ return this.net.request(
+ 'open-ils.acq',
+ 'open-ils.acq.po_item.delete',
+ this.auth.token(), charge.id()
+ ).toPromise().then(res => {
+ const evt = this.evt.parse(res);
+ if (evt) { return Promise.reject(evt + ''); }
+ }).then(_ => this.poService.refreshOrderSummary(true));
}
}
}