LP#1942220: changes to direct charge form
authorGalen Charlton <gmc@equinoxOLI.org>
Wed, 8 Dec 2021 23:01:36 +0000 (18:01 -0500)
committerGalen Charlton <gmc@equinoxOLI.org>
Wed, 8 Dec 2021 23:01:36 +0000 (18:01 -0500)
- can now edit charges on a pending order
- direct charges are now read-only on an activated order

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

index 4ea1891..4e64164 100644 (file)
@@ -1,6 +1,6 @@
 
 <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">
@@ -20,7 +20,7 @@
         [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>
index 5f443c1..34a4be3 100644 (file)
@@ -13,6 +13,7 @@ import {PoService} from './po.service';
 export class PoChargesComponent implements OnInit, OnDestroy {
 
     showBody = false;
+    canModify = false;
     autoId = -1;
     poSubscription: Subscription;
 
@@ -26,11 +27,13 @@ export class PoChargesComponent implements OnInit, OnDestroy {
         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;
         });
     }
 
@@ -57,13 +60,21 @@ export class PoChargesComponent implements OnInit, OnDestroy {
         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) {