Fix: Purchase was still not getting the Rate Contract information.
This commit is contained in:
@ -117,7 +117,7 @@ export class PurchaseComponent implements OnInit, AfterViewInit {
|
||||
account: FormControl<string | Account | null>;
|
||||
amount: FormControl<number>;
|
||||
addRow: FormGroup<{
|
||||
product: FormControl<string | null>;
|
||||
product: FormControl<string | ProductSku | null>;
|
||||
quantity: FormControl<string>;
|
||||
price: FormControl<string>;
|
||||
tax: FormControl<string>;
|
||||
@ -128,7 +128,6 @@ export class PurchaseComponent implements OnInit, AfterViewInit {
|
||||
}>;
|
||||
|
||||
voucher: Voucher = new Voucher();
|
||||
product: ProductSku | null = null;
|
||||
accBal: AccountBalance | null = null;
|
||||
|
||||
displayedColumns = ['product', 'quantity', 'rate', 'tax', 'discount', 'amount', 'action'];
|
||||
@ -143,7 +142,7 @@ export class PurchaseComponent implements OnInit, AfterViewInit {
|
||||
account: new FormControl<string | Account | null>(null),
|
||||
amount: new FormControl({ value: 0, disabled: true }, { nonNullable: true }),
|
||||
addRow: new FormGroup({
|
||||
product: new FormControl(''),
|
||||
product: new FormControl<string | ProductSku | null>(null),
|
||||
quantity: new FormControl('', { nonNullable: true }),
|
||||
price: new FormControl('', { nonNullable: true }),
|
||||
tax: new FormControl('', { nonNullable: true }),
|
||||
@ -172,10 +171,11 @@ export class PurchaseComponent implements OnInit, AfterViewInit {
|
||||
switchMap((x) => {
|
||||
const account = this.form.value.account;
|
||||
const vendorId = account && typeof account === 'object' ? account.id : undefined;
|
||||
return x === null
|
||||
const query = typeof x !== 'string' ? '' : x;
|
||||
return query === null || query === ''
|
||||
? observableOf([])
|
||||
: this.productSer.autocompleteSku(
|
||||
x,
|
||||
query,
|
||||
true,
|
||||
moment(this.form.value.date).format('DD-MMM-YYYY'),
|
||||
vendorId,
|
||||
@ -224,22 +224,23 @@ export class PurchaseComponent implements OnInit, AfterViewInit {
|
||||
|
||||
addRow() {
|
||||
const formValue = this.form.value.addRow;
|
||||
if (formValue === undefined) {
|
||||
if (formValue === undefined || !formValue.product || typeof formValue.product === 'string') {
|
||||
return;
|
||||
}
|
||||
const product = formValue.product as ProductSku;
|
||||
const quantity = this.math.parseAmount(formValue.quantity, 2);
|
||||
if (this.product === null || quantity <= 0) {
|
||||
if (quantity <= 0) {
|
||||
return;
|
||||
}
|
||||
const price = this.product.isRateContracted
|
||||
? (this.product.costPrice as number)
|
||||
const price = product.isRateContracted
|
||||
? (product.costPrice as number)
|
||||
: 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);
|
||||
const tax = product.isRateContracted ? 0 : this.math.parseAmount(formValue.tax, 5);
|
||||
const discount = product.isRateContracted ? 0 : this.math.parseAmount(formValue.discount, 5);
|
||||
if ((price as number) <= 0 || (tax as number) < 0 || (discount as number) < 0) {
|
||||
return;
|
||||
}
|
||||
const oldFiltered = this.voucher.inventories.filter((x) => x.batch?.sku.id === (this.product as ProductSku).id);
|
||||
const oldFiltered = this.voucher.inventories.filter((x) => x.batch?.sku.id === product.id);
|
||||
if (oldFiltered.length) {
|
||||
this.snackBar.open('Product already added', 'Danger');
|
||||
return;
|
||||
@ -251,7 +252,7 @@ export class PurchaseComponent implements OnInit, AfterViewInit {
|
||||
tax,
|
||||
discount,
|
||||
amount: round(quantity * (price as number) * (1 + tax) * (1 - discount), 2),
|
||||
batch: new Batch({ sku: this.product }),
|
||||
batch: new Batch({ sku: product }),
|
||||
}),
|
||||
);
|
||||
this.resetAddRow();
|
||||
@ -260,7 +261,6 @@ export class PurchaseComponent implements OnInit, AfterViewInit {
|
||||
|
||||
resetAddRow() {
|
||||
this.form.controls.addRow.reset();
|
||||
this.product = null;
|
||||
this.form.controls.addRow.controls.price.enable();
|
||||
this.form.controls.addRow.controls.tax.enable();
|
||||
this.form.controls.addRow.controls.discount.enable();
|
||||
@ -394,7 +394,7 @@ export class PurchaseComponent implements OnInit, AfterViewInit {
|
||||
productSelected(event: MatAutocompleteSelectedEvent): void {
|
||||
const product: ProductSku = event.option.value;
|
||||
const addRowForm = this.form.controls.addRow;
|
||||
this.product = product;
|
||||
addRowForm.controls.product.setValue(product);
|
||||
addRowForm.controls.price.setValue(`${product.costPrice}`);
|
||||
if (product.isRateContracted) {
|
||||
addRowForm.controls.price.disable();
|
||||
|
||||
Reference in New Issue
Block a user