<h4 i18n>Direct Charges, Taxes, Fees, etc.
- <button class="btn btn-info btn-sm" (click)="newCharge()">New Charge</button>
+ <button class="btn btn-info btn-sm" (click)="newCharge()" *ngIf="canModify">New Charge</button>
</h4>
<ng-container *ngIf="showBody">
[asyncSupportsEmptyTermClick]="true"
(onChange)="charge.inv_item_type($event ? $event.id : null)"
i18n-placeholder placeholder="Charge Type..."
- [required]="true" [readOnly]="!charge.isnew()"></eg-combobox>
+ [required]="true" [readOnly]="!charge.isnew() && !charge.ischanged()"></eg-combobox>
</div>
<div class="flex-2 p-2">
<!-- the IDL does not require a fund, but the Perl code assumes
<eg-combobox idlClass="acqf" [selectedId]="charge.fund()"
(onChange)="charge.fund($event ? $event.id : null)"
i18n-placeholder placeholder="Fund..."
- [required]="true" [readOnly]="!charge.isnew()"
+ [required]="true" [readOnly]="!charge.isnew() && !charge.ischanged()"
[idlQuerySort]="{acqf: 'year DESC, code'}"
[idlQueryAnd]="{active: 't'}">
</eg-combobox>
</div>
<div class="flex-2 p-2">
- <span *ngIf="!charge.isnew()">{{charge.title()}}</span>
- <input *ngIf="charge.isnew()" type="text" class="form-control"
+ <span *ngIf="!charge.isnew() && !charge.ischanged()">{{charge.title()}}</span>
+ <input *ngIf="charge.isnew() || charge.ischanged()" type="text" class="form-control"
i18n-placeholder placeholder="Title..."
[ngModel]="charge.title()" (ngModelChange)="charge.title($event)"/>
</div>
<div class="flex-2 p-2">
- <span *ngIf="!charge.isnew()">{{charge.author()}}</span>
- <input *ngIf="charge.isnew()" type="text" class="form-control"
+ <span *ngIf="!charge.isnew() && !charge.ischanged()">{{charge.author()}}</span>
+ <input *ngIf="charge.isnew() || charge.ischanged()" type="text" class="form-control"
i18n-placeholder placeholder="Author..."
[ngModel]="charge.author()" (ngModelChange)="charge.author($event)"/>
</div>
<div class="flex-2 p-2">
- <span *ngIf="!charge.isnew()">{{charge.note()}}</span>
- <input *ngIf="charge.isnew()" type="text" class="form-control"
+ <span *ngIf="!charge.isnew() && !charge.ischanged()">{{charge.note()}}</span>
+ <input *ngIf="charge.isnew() || charge.ischanged()" type="text" class="form-control"
i18n-placeholder placeholder="Note..."
[ngModel]="charge.note()" (ngModelChange)="charge.note($event)"/>
</div>
<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"
+ <span *ngIf="!charge.isnew() && !charge.ischanged()">{{charge.estimated_cost() | currency}}</span>
+ <input *ngIf="charge.isnew() || charge.ischanged()" type="number" min="0" class="form-control"
i18n-placeholder placeholder="Esimated Cost..." [required]="true"
[ngModel]="charge.estimated_cost()" (ngModelChange)="charge.estimated_cost($event)"/>
</div>
- <div class="flex-1 p-1">
- <button *ngIf="charge.isnew()" class="btn btn-success btn-sm"
+ <div class="flex-2 p-1">
+ <button *ngIf="canModify" [disabled]="!(charge.isnew() || charge.ischanged())" class="btn btn-success btn-sm"
(click)="saveCharge(charge)" i18n>Save</button>
- </div>
- <div class="flex-1 p-1">
- <button class="btn btn-danger btn-sm"
- (click)="removeCharge(charge)" i18n>Remove</button>
+ <button *ngIf="canModify" [disabled]="charge.isnew()" class="btn btn-outline-dark btn-sm ml-1"
+ (click)="charge.ischanged(true)" i18n>Edit</button>
+ <button class="btn btn-danger btn-sm ml-1"
+ (click)="removeCharge(charge)" *ngIf="canModify" i18n>Remove</button>
</div>
</div>
</ng-container>
export class PoChargesComponent implements OnInit, OnDestroy {
showBody = false;
+ canModify = false;
autoId = -1;
poSubscription: Subscription;
if (this.po()) {
// Sometimes our PO is already available at render time.
this.showBody = this.po().po_items().length > 0;
+ this.canModify = this.po().order_date() ? false : true;
}
// Other times we have to wait for it.
this.poSubscription = this.poService.poRetrieved.subscribe(() => {
this.showBody = this.po().po_items().length > 0;
+ this.canModify = this.po().order_date() ? false : true;
});
}
if (!charge.inv_item_type() || !charge.fund()) { return; }
if (typeof charge.estimated_cost() !== 'number') { return; }
- charge.id(undefined);
- this.pcrud.create(charge).toPromise()
- .then(item => {
- charge.id(item.id());
- charge.isnew(false);
- })
- .then(_ => this.poService.refreshOrderSummary());
+ if (charge.isnew()) {
+ charge.id(undefined);
+ this.pcrud.create(charge).toPromise()
+ .then(item => {
+ charge.id(item.id());
+ charge.isnew(false);
+ })
+ .then(_ => this.poService.refreshOrderSummary());
+ } else if (charge.ischanged()) {
+ this.pcrud.update(charge).toPromise()
+ .then(item => {
+ charge.ischanged(false);
+ })
+ .then(_ => this.poService.refreshOrderSummary());
+ }
}
removeCharge(charge: IdlObject) {