Fix: Autocomplete could fuck up and was definitely doing it in product.
When checking for .name, it would error out if the input was null Fix: Journal addRow reset would reset Debit/Credit
This commit is contained in:
+9
-13
@@ -5,7 +5,7 @@ import { MatDialog } from '@angular/material/dialog';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import * as moment from 'moment';
|
||||
import { BehaviorSubject, Observable, of as observableOf } from 'rxjs';
|
||||
import { debounceTime, distinctUntilChanged, map, switchMap } from 'rxjs/operators';
|
||||
import { debounceTime, distinctUntilChanged, switchMap } from 'rxjs/operators';
|
||||
|
||||
import { Account } from '../../core/account';
|
||||
import { AccountService } from '../../core/account.service';
|
||||
@@ -33,7 +33,7 @@ export class RateContractDetailComponent implements OnInit, AfterViewInit {
|
||||
dataSource: RateContractDetailDatasource = new RateContractDetailDatasource(this.itemsObservable);
|
||||
form: FormGroup<{
|
||||
date: FormControl<Date>;
|
||||
account: FormControl<Account | string | null>;
|
||||
account: FormControl<string | null>;
|
||||
validFrom: FormControl<Date>;
|
||||
validTill: FormControl<Date>;
|
||||
addRow: FormGroup<{
|
||||
@@ -45,6 +45,7 @@ export class RateContractDetailComponent implements OnInit, AfterViewInit {
|
||||
|
||||
item: RateContract = new RateContract();
|
||||
|
||||
account: Account | null = null;
|
||||
product: Product | null = null;
|
||||
|
||||
displayedColumns = ['product', 'price', 'action'];
|
||||
@@ -64,7 +65,7 @@ export class RateContractDetailComponent implements OnInit, AfterViewInit {
|
||||
) {
|
||||
this.form = new FormGroup({
|
||||
date: new FormControl(new Date(), { nonNullable: true }),
|
||||
account: new FormControl<Account | string | null>(null),
|
||||
account: new FormControl<string | null>(null),
|
||||
validFrom: new FormControl(new Date(), { nonNullable: true }),
|
||||
validTill: new FormControl(new Date(), { nonNullable: true }),
|
||||
addRow: new FormGroup({
|
||||
@@ -74,15 +75,12 @@ export class RateContractDetailComponent implements OnInit, AfterViewInit {
|
||||
narration: new FormControl('', { nonNullable: true }),
|
||||
});
|
||||
this.accounts = this.form.controls.account.valueChanges.pipe(
|
||||
map((x) => ((x as Account).name !== undefined ? (x as Account).name : (x as string))),
|
||||
map((x) => (x !== null && x.length >= 1 ? x : null)),
|
||||
debounceTime(150),
|
||||
distinctUntilChanged(),
|
||||
switchMap((x) => (x === null ? observableOf([]) : this.accountSer.autocomplete(x))),
|
||||
);
|
||||
// Listen to Product Autocomplete Change
|
||||
this.products = this.form.controls.addRow.controls.product.valueChanges.pipe(
|
||||
map((x) => (x !== null && x.length >= 1 ? x : null)),
|
||||
debounceTime(150),
|
||||
distinctUntilChanged(),
|
||||
switchMap((x) => (x === null ? observableOf([]) : this.productSer.autocompleteSku(x, true))),
|
||||
@@ -102,7 +100,7 @@ export class RateContractDetailComponent implements OnInit, AfterViewInit {
|
||||
date: moment(this.item.date, 'DD-MMM-YYYY').toDate(),
|
||||
validFrom: moment(this.item.validFrom, 'DD-MMM-YYYY').toDate(),
|
||||
validTill: moment(this.item.validTill, 'DD-MMM-YYYY').toDate(),
|
||||
account: this.item.vendor,
|
||||
account: this.item.vendor.name,
|
||||
addRow: {
|
||||
product: '',
|
||||
price: '',
|
||||
@@ -155,8 +153,8 @@ export class RateContractDetailComponent implements OnInit, AfterViewInit {
|
||||
}, 0);
|
||||
}
|
||||
|
||||
displayFn(item?: Account | Product): string {
|
||||
return item ? item.name : '';
|
||||
displayFn(item?: Account | Product | string): string {
|
||||
return !item ? '' : typeof item === 'string' ? item : item.name;
|
||||
}
|
||||
|
||||
updateView() {
|
||||
@@ -164,7 +162,7 @@ export class RateContractDetailComponent implements OnInit, AfterViewInit {
|
||||
}
|
||||
|
||||
accountSelected(event: MatAutocompleteSelectedEvent): void {
|
||||
this.form.controls.account.setValue(event.option.value);
|
||||
this.account = event.option.value;
|
||||
}
|
||||
|
||||
productSelected(event: MatAutocompleteSelectedEvent): void {
|
||||
@@ -218,9 +216,7 @@ export class RateContractDetailComponent implements OnInit, AfterViewInit {
|
||||
this.item.date = moment(formModel.date).format('DD-MMM-YYYY');
|
||||
this.item.validFrom = moment(formModel.validFrom).format('DD-MMM-YYYY');
|
||||
this.item.validTill = moment(formModel.validTill).format('DD-MMM-YYYY');
|
||||
if (formModel.account && typeof formModel.account !== 'string') {
|
||||
this.item.vendor = formModel.account;
|
||||
}
|
||||
this.item.vendor = this.account ?? new Account();
|
||||
this.item.narration = formModel.narration ?? '';
|
||||
return this.item;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user