Fix: Purchase was not showing contract rates.
This commit is contained in:
@ -114,7 +114,7 @@ export class PurchaseComponent implements OnInit, AfterViewInit {
|
|||||||
dataSource: PurchaseDataSource = new PurchaseDataSource(this.inventoryObservable);
|
dataSource: PurchaseDataSource = new PurchaseDataSource(this.inventoryObservable);
|
||||||
form: FormGroup<{
|
form: FormGroup<{
|
||||||
date: FormControl<moment.Moment>;
|
date: FormControl<moment.Moment>;
|
||||||
account: FormControl<string | null>;
|
account: FormControl<string | Account | null>;
|
||||||
amount: FormControl<number>;
|
amount: FormControl<number>;
|
||||||
addRow: FormGroup<{
|
addRow: FormGroup<{
|
||||||
product: FormControl<string | null>;
|
product: FormControl<string | null>;
|
||||||
@ -140,7 +140,7 @@ export class PurchaseComponent implements OnInit, AfterViewInit {
|
|||||||
constructor() {
|
constructor() {
|
||||||
this.form = new FormGroup({
|
this.form = new FormGroup({
|
||||||
date: new FormControl(moment(new Date()), { nonNullable: true }),
|
date: new FormControl(moment(new Date()), { nonNullable: true }),
|
||||||
account: new FormControl<string | null>(null),
|
account: new FormControl<string | Account | null>(null),
|
||||||
amount: new FormControl({ value: 0, disabled: true }, { nonNullable: true }),
|
amount: new FormControl({ value: 0, disabled: true }, { nonNullable: true }),
|
||||||
addRow: new FormGroup({
|
addRow: new FormGroup({
|
||||||
product: new FormControl(''),
|
product: new FormControl(''),
|
||||||
@ -157,7 +157,7 @@ export class PurchaseComponent implements OnInit, AfterViewInit {
|
|||||||
this.accounts = this.form.controls.account.valueChanges.pipe(
|
this.accounts = this.form.controls.account.valueChanges.pipe(
|
||||||
debounceTime(150),
|
debounceTime(150),
|
||||||
distinctUntilChanged(),
|
distinctUntilChanged(),
|
||||||
switchMap((x) => (x === null ? observableOf([]) : this.accountSer.autocomplete(x))),
|
switchMap((x) => (x === null ? observableOf([]) : this.accountSer.autocomplete(typeof x === 'string' ? x : x.name))),
|
||||||
);
|
);
|
||||||
this.tags = this.form.controls.tags.valueChanges.pipe(
|
this.tags = this.form.controls.tags.valueChanges.pipe(
|
||||||
debounceTime(150),
|
debounceTime(150),
|
||||||
@ -169,17 +169,18 @@ export class PurchaseComponent implements OnInit, AfterViewInit {
|
|||||||
this.products = this.form.controls.addRow.controls.product.valueChanges.pipe(
|
this.products = this.form.controls.addRow.controls.product.valueChanges.pipe(
|
||||||
debounceTime(150),
|
debounceTime(150),
|
||||||
distinctUntilChanged(),
|
distinctUntilChanged(),
|
||||||
switchMap((x) =>
|
switchMap((x) => {
|
||||||
x === null
|
const account = this.form.value.account;
|
||||||
|
const vendorId = account && typeof account === 'object' ? account.id : undefined;
|
||||||
|
return x === null
|
||||||
? observableOf([])
|
? observableOf([])
|
||||||
: this.productSer.autocompleteSku(
|
: this.productSer.autocompleteSku(
|
||||||
x,
|
x,
|
||||||
true,
|
true,
|
||||||
moment(this.form.value.date).format('DD-MMM-YYYY'),
|
moment(this.form.value.date).format('DD-MMM-YYYY'),
|
||||||
// this.form.value.account?.id,
|
vendorId,
|
||||||
'',
|
);
|
||||||
),
|
}),
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -199,7 +200,7 @@ export class PurchaseComponent implements OnInit, AfterViewInit {
|
|||||||
this.voucher = voucher;
|
this.voucher = voucher;
|
||||||
this.form.setValue({
|
this.form.setValue({
|
||||||
date: moment(this.voucher.date, 'DD-MMM-YYYY'),
|
date: moment(this.voucher.date, 'DD-MMM-YYYY'),
|
||||||
account: this.voucher.vendor?.name ?? null,
|
account: this.voucher.vendor ?? null,
|
||||||
amount: Math.abs(this.voucher.inventories.map((x) => x.amount).reduce((p, c) => p + c, 0)),
|
amount: Math.abs(this.voucher.inventories.map((x) => x.amount).reduce((p, c) => p + c, 0)),
|
||||||
addRow: {
|
addRow: {
|
||||||
product: '',
|
product: '',
|
||||||
@ -303,6 +304,10 @@ export class PurchaseComponent implements OnInit, AfterViewInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
canSave() {
|
canSave() {
|
||||||
|
const account = this.form.value.account;
|
||||||
|
if (!account || typeof account === 'string') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (!this.voucher.id) {
|
if (!this.voucher.id) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -344,7 +349,9 @@ export class PurchaseComponent implements OnInit, AfterViewInit {
|
|||||||
getVoucher(): Voucher {
|
getVoucher(): Voucher {
|
||||||
const formModel = this.form.value;
|
const formModel = this.form.value;
|
||||||
this.voucher.date = moment(formModel.date).format('DD-MMM-YYYY');
|
this.voucher.date = moment(formModel.date).format('DD-MMM-YYYY');
|
||||||
if (formModel.account !== null && typeof formModel.account !== 'string') {
|
if (!formModel.account || typeof formModel.account === 'string') {
|
||||||
|
this.voucher.vendor = undefined;
|
||||||
|
} else {
|
||||||
this.voucher.vendor = formModel.account;
|
this.voucher.vendor = formModel.account;
|
||||||
}
|
}
|
||||||
this.voucher.narration = formModel.narration ?? '';
|
this.voucher.narration = formModel.narration ?? '';
|
||||||
|
|||||||
Reference in New Issue
Block a user