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:
@ -7,7 +7,7 @@ import { Hotkey, HotkeysService } from 'angular2-hotkeys';
|
||||
import { round } from 'mathjs';
|
||||
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 { AuthService } from '../auth/auth.service';
|
||||
import { Account } from '../core/account';
|
||||
@ -44,7 +44,7 @@ export class PurchaseComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
dataSource: PurchaseDataSource = new PurchaseDataSource(this.inventoryObservable);
|
||||
form: FormGroup<{
|
||||
date: FormControl<Date>;
|
||||
account: FormControl<Account | string | null>;
|
||||
account: FormControl<string | null>;
|
||||
amount: FormControl<number>;
|
||||
addRow: FormGroup<{
|
||||
product: FormControl<string | null>;
|
||||
@ -80,7 +80,7 @@ export class PurchaseComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
) {
|
||||
this.form = new FormGroup({
|
||||
date: new FormControl(new Date(), { nonNullable: true }),
|
||||
account: new FormControl<Account | string | null>(null),
|
||||
account: new FormControl<string | null>(null),
|
||||
amount: new FormControl({ value: 0, disabled: true }, { nonNullable: true }),
|
||||
addRow: new FormGroup({
|
||||
product: new FormControl(''),
|
||||
@ -94,15 +94,12 @@ export class PurchaseComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
this.accBal = null;
|
||||
// Listen to Account Autocomplete Change
|
||||
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) =>
|
||||
@ -177,7 +174,7 @@ export class PurchaseComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
this.voucher = voucher;
|
||||
this.form.setValue({
|
||||
date: moment(this.voucher.date, 'DD-MMM-YYYY').toDate(),
|
||||
account: this.voucher.vendor || null,
|
||||
account: this.voucher.vendor?.name ?? null,
|
||||
amount: Math.abs(this.voucher.inventories.map((x) => x.amount).reduce((p, c) => p + c, 0)),
|
||||
addRow: {
|
||||
product: '',
|
||||
@ -364,8 +361,8 @@ export class PurchaseComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
});
|
||||
}
|
||||
|
||||
displayFn(item?: Account | Product): string {
|
||||
return item ? item.name : '';
|
||||
displayFn(item?: Account | Product | string): string {
|
||||
return !item ? '' : typeof item === 'string' ? item : item.name;
|
||||
}
|
||||
|
||||
accountSelected(event: MatAutocompleteSelectedEvent): void {
|
||||
|
||||
Reference in New Issue
Block a user