Fix: Select customer could not edit or create a customer.

This commit is contained in:
2026-09-04 09:59:29 +00:00
parent 11b93cb11c
commit 221fadfdfc
9 changed files with 21 additions and 20 deletions
@@ -30,7 +30,7 @@
</mat-card> </mat-card>
</div> </div>
</mat-dialog-content> </mat-dialog-content>
<mat-dialog-actions align="end"> <mat-dialog-actions>
<button mat-button [mat-dialog-close]="false">Cancel</button> <button mat-button [mat-dialog-close]="false">Cancel</button>
<button mat-button [mat-dialog-close]="selectedVal">Done</button> <button mat-button [mat-dialog-close]="selectedVal">Done</button>
</mat-dialog-actions> </mat-dialog-actions>
@@ -27,22 +27,22 @@
<div class="row-container"> <div class="row-container">
<mat-form-field class="flex-auto"> <mat-form-field class="flex-auto">
<mat-label>Name</mat-label> <mat-label>Name</mat-label>
<input matInput [value]="formModel().name" readonly /> <input matInput [formField]="form.name" />
</mat-form-field> </mat-form-field>
</div> </div>
<div class="row-container"> <div class="row-container">
<mat-form-field class="flex-auto"> <mat-form-field class="flex-auto">
<mat-label>Address</mat-label> <mat-label>Address</mat-label>
<textarea matInput [value]="formModel().address" readonly> </textarea> <textarea matInput [formField]="form.address"> </textarea>
</mat-form-field> </mat-form-field>
</div> </div>
<div class="row-container"> <div class="row-container">
<mat-checkbox [checked]="formModel().printInBill" [disabled]="true">Print in Bill?</mat-checkbox> <mat-checkbox [formField]="form.printInBill">Print in Bill?</mat-checkbox>
</div> </div>
<p></p> <p></p>
<div class="discounts"> <div class="discounts">
<ul> <ul>
@for (r of formModel().discounts; track r.id) { @for (r of form().value().discounts; track r.id) {
@if (r.discount > 0) { @if (r.discount > 0) {
<li>{{ r.name }} - {{ r.discount | percent: '1.2-2' }}</li> <li>{{ r.name }} - {{ r.discount | percent: '1.2-2' }}</li>
} }
@@ -51,7 +51,7 @@
</div> </div>
</form> </form>
</mat-dialog-content> </mat-dialog-content>
<mat-dialog-actions align="end"> <mat-dialog-actions>
<button mat-button [mat-dialog-close]="false">Cancel</button> <button mat-button [mat-dialog-close]="false">Cancel</button>
<button type="button" mat-raised-button color="primary" (click)="save()">Select</button> <button type="button" mat-raised-button color="primary" (click)="save()">Select</button>
</mat-dialog-actions> </mat-dialog-actions>
@@ -79,6 +79,7 @@ export class ChooseCustomerComponent {
save() { save() {
const customer = this.getItem(); const customer = this.getItem();
console.log(customer);
const promise = this.ser.saveOrUpdate(customer); const promise = this.ser.saveOrUpdate(customer);
promise.subscribe((x) => this.dialogRef.close(x)); promise.subscribe((x) => this.dialogRef.close(x));
} }
@@ -96,15 +97,15 @@ export class ChooseCustomerComponent {
} }
getItem(): Customer { getItem(): Customer {
const formModel = this.formModel(); const formValue = this.form().value();
return new Customer({ return new Customer({
id: formModel.id, id: formValue.id,
name: formModel.name ?? '', name: formValue.name ?? '',
phone: formModel.phone ?? '', phone: formValue.phone ?? '',
address: formModel.address ?? '', address: formValue.address ?? '',
printInBill: formModel.printInBill ?? false, printInBill: formValue.printInBill ?? false,
discounts: formModel.discounts.map((item) => ({ ...item })), discounts: formValue.discounts.map((item) => ({ ...item })),
}); });
} }
} }
@@ -16,7 +16,7 @@
<input matInput type="number" [formField]="form.discounts[i].discount" autocomplete="off" /> <input matInput type="number" [formField]="form.discounts[i].discount" autocomplete="off" />
<span matTextSuffix>%</span> <span matTextSuffix>%</span>
<mat-hint>Cust: {{ row.customer | percent: '1.2-2' }}</mat-hint> <mat-hint>Cust: {{ row.customer | percent: '1.2-2' }}</mat-hint>
<mat-hint align="end">Max: {{ row.limit | percent: '1.2-2' }}</mat-hint> <mat-hint>Max: {{ row.limit | percent: '1.2-2' }}</mat-hint>
</mat-form-field> </mat-form-field>
</mat-cell> </mat-cell>
</ng-container> </ng-container>
@@ -26,7 +26,7 @@
</mat-table> </mat-table>
</form> </form>
</mat-dialog-content> </mat-dialog-content>
<mat-dialog-actions align="end"> <mat-dialog-actions>
<button mat-button [mat-dialog-close]="false">Cancel</button> <button mat-button [mat-dialog-close]="false">Cancel</button>
<button type="button" mat-button (click)="accept()" color="primary">Ok</button> <button type="button" mat-button (click)="accept()" color="primary">Ok</button>
</mat-dialog-actions> </mat-dialog-actions>
@@ -30,6 +30,6 @@
} }
</mat-tab-group> </mat-tab-group>
</mat-dialog-content> </mat-dialog-content>
<mat-dialog-actions align="end"> <mat-dialog-actions>
<button mat-button [mat-dialog-close]="selected()">Done</button> <button mat-button [mat-dialog-close]="selected()">Done</button>
</mat-dialog-actions> </mat-dialog-actions>
@@ -26,7 +26,7 @@
</mat-table> </mat-table>
</form> </form>
</mat-dialog-content> </mat-dialog-content>
<mat-dialog-actions align="end"> <mat-dialog-actions>
<button mat-button [mat-dialog-close]="false">Cancel</button> <button mat-button [mat-dialog-close]="false">Cancel</button>
<button type="button" mat-button (click)="accept()" color="primary" [disabled]="!selected">Ok</button> <button type="button" mat-button (click)="accept()" color="primary" [disabled]="!selected">Ok</button>
</mat-dialog-actions> </mat-dialog-actions>
@@ -48,7 +48,7 @@
</mat-form-field> </mat-form-field>
</form> </form>
</mat-dialog-content> </mat-dialog-content>
<mat-dialog-actions align="end"> <mat-dialog-actions>
<button mat-button [mat-dialog-close]>Cancel</button> <button mat-button [mat-dialog-close]>Cancel</button>
<button type="button" mat-button (click)="accept()" color="primary" [disabled]="!!balance()">Ok</button> <button type="button" mat-button (click)="accept()" color="primary" [disabled]="!!balance()">Ok</button>
</mat-dialog-actions> </mat-dialog-actions>
@@ -10,7 +10,7 @@
</div> </div>
</form> </form>
</mat-dialog-content> </mat-dialog-content>
<mat-dialog-actions align="end"> <mat-dialog-actions>
<button mat-button [mat-dialog-close]="false">Cancel</button> <button mat-button [mat-dialog-close]="false">Cancel</button>
<button type="button" mat-button (click)="accept()" color="primary">Ok</button> <button type="button" mat-button (click)="accept()" color="primary">Ok</button>
</mat-dialog-actions> </mat-dialog-actions>
@@ -23,7 +23,7 @@
} }
</div> </div>
</mat-dialog-content> </mat-dialog-content>
<mat-dialog-actions align="end"> <mat-dialog-actions>
<button mat-button [mat-dialog-close]="false">Cancel</button> <button mat-button [mat-dialog-close]="false">Cancel</button>
<button type="button" mat-button (click)="accept()" color="primary">Ok</button> <button type="button" mat-button (click)="accept()" color="primary">Ok</button>
</mat-dialog-actions> </mat-dialog-actions>