Rate Contract is checked during save and update of Purchase at the backend

This commit is contained in:
2021-09-13 13:01:34 +05:30
parent ceaf93d1cd
commit d34c8ea0a4
5 changed files with 155 additions and 52 deletions

View File

@ -94,7 +94,16 @@ export class PurchaseComponent implements OnInit, AfterViewInit, OnDestroy {
map((x) => (x !== null && x.length >= 1 ? x : null)),
debounceTime(150),
distinctUntilChanged(),
switchMap((x) => (x === null ? observableOf([]) : this.productSer.autocomplete(x))),
switchMap((x) =>
x === null
? observableOf([])
: this.productSer.autocomplete(
x,
false,
moment(this.form.value.date).format('DD-MMM-YYYY'),
this.form.value.account.id,
),
),
);
}
@ -182,10 +191,17 @@ export class PurchaseComponent implements OnInit, AfterViewInit, OnDestroy {
addRow() {
const formValue = (this.form.get('addRow') as FormControl).value;
const quantity = this.math.parseAmount(formValue.quantity, 2);
const price = this.math.parseAmount(formValue.price, 2);
const tax = this.math.parseAmount(formValue.tax, 5);
const discount = this.math.parseAmount(formValue.discount, 5);
if (this.product === null || quantity <= 0 || price <= 0) {
if (this.product === null || quantity <= 0) {
return;
}
const price = this.product.isRateContracted
? this.product.price
: this.math.parseAmount(formValue.price, 2);
const tax = this.product.isRateContracted ? 0 : this.math.parseAmount(formValue.tax, 5);
const discount = this.product.isRateContracted
? 0
: this.math.parseAmount(formValue.discount, 5);
if (price <= 0 || tax < 0 || discount < 0) {
return;
}
const oldFiltered = this.voucher.inventories.filter(
@ -219,6 +235,9 @@ export class PurchaseComponent implements OnInit, AfterViewInit, OnDestroy {
discount: '',
});
this.product = null;
((this.form.get('addRow') as FormControl).get('price') as FormControl).enable();
((this.form.get('addRow') as FormControl).get('tax') as FormControl).enable();
((this.form.get('addRow') as FormControl).get('discount') as FormControl).enable();
setTimeout(() => {
if (this.productElement) {
this.productElement.nativeElement.focus();
@ -344,9 +363,22 @@ export class PurchaseComponent implements OnInit, AfterViewInit, OnDestroy {
}
productSelected(event: MatAutocompleteSelectedEvent): void {
const product = event.option.value;
const product: Product = event.option.value;
this.product = product;
((this.form.get('addRow') as FormControl).get('price') as FormControl).setValue(product.price);
if (product.isRateContracted) {
((this.form.get('addRow') as FormControl).get('price') as FormControl).disable();
((this.form.get('addRow') as FormControl).get('tax') as FormControl).disable();
((this.form.get('addRow') as FormControl).get('discount') as FormControl).disable();
((this.form.get('addRow') as FormControl).get('tax') as FormControl).setValue('RC');
((this.form.get('addRow') as FormControl).get('discount') as FormControl).setValue('RC');
} else {
((this.form.get('addRow') as FormControl).get('price') as FormControl).enable();
((this.form.get('addRow') as FormControl).get('tax') as FormControl).enable();
((this.form.get('addRow') as FormControl).get('discount') as FormControl).enable();
((this.form.get('addRow') as FormControl).get('tax') as FormControl).setValue('');
((this.form.get('addRow') as FormControl).get('discount') as FormControl).setValue('');
}
}
zoomImage(file: DbFile) {