Feature: Discount will only update the sale types which have been updated in the form.
This commit is contained in:
parent
565cffaef1
commit
7b327b4fda
@ -1,5 +1,5 @@
|
||||
import { Component, Inject } from '@angular/core';
|
||||
import { FormArray, FormBuilder, FormGroup, Validators } from '@angular/forms';
|
||||
import {FormArray, FormBuilder, FormControl, FormGroup, Validators} from '@angular/forms';
|
||||
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
|
||||
import { round } from 'mathjs';
|
||||
import { Observable } from 'rxjs';
|
||||
@ -46,12 +46,19 @@ export class DiscountComponent {
|
||||
|
||||
accept(): void {
|
||||
const array = this.form.get('discounts') as FormArray;
|
||||
this.list.forEach((item, index) => {
|
||||
item.discount = Math.max(
|
||||
Math.min(round(array.controls[index].value.discount / 100, 5), item.discountLimit),
|
||||
0,
|
||||
);
|
||||
});
|
||||
for (let i = this.list.length - 1; i >=0 ; i--) {
|
||||
const item = this.list[i];
|
||||
const control = (array.controls[i] as FormGroup).controls.discount as FormControl;
|
||||
if (control.pristine || control.value === null) {
|
||||
this.list.splice(i, 1);
|
||||
}
|
||||
else {
|
||||
item.discount = Math.max(
|
||||
Math.min(round(array.controls[i].value.discount / 100, 5), item.discountLimit),
|
||||
0,
|
||||
);
|
||||
}
|
||||
}
|
||||
this.dialogRef.close(this.list);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user