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:
@ -6,7 +6,7 @@ import { MatSort } from '@angular/material/sort';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import * as moment from 'moment';
|
||||
import { 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';
|
||||
@ -30,7 +30,7 @@ export class LedgerComponent implements OnInit, AfterViewInit {
|
||||
form: FormGroup<{
|
||||
startDate: FormControl<Date>;
|
||||
finishDate: FormControl<Date>;
|
||||
account: FormControl<Account | string | null>;
|
||||
account: FormControl<string | null>;
|
||||
}>;
|
||||
|
||||
selectedRowId = '';
|
||||
@ -52,12 +52,10 @@ export class LedgerComponent implements OnInit, AfterViewInit {
|
||||
this.form = new FormGroup({
|
||||
startDate: new FormControl(new Date(), { nonNullable: true }),
|
||||
finishDate: new FormControl(new Date(), { nonNullable: true }),
|
||||
account: new FormControl<Account | string | null>(null),
|
||||
account: new FormControl<string | null>(null),
|
||||
});
|
||||
|
||||
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))),
|
||||
@ -71,7 +69,7 @@ export class LedgerComponent implements OnInit, AfterViewInit {
|
||||
this.info = data.info;
|
||||
this.calculateTotals();
|
||||
this.form.setValue({
|
||||
account: this.info.account,
|
||||
account: this.info.account.name,
|
||||
startDate: moment(this.info.startDate, 'DD-MMM-YYYY').toDate(),
|
||||
finishDate: moment(this.info.finishDate, 'DD-MMM-YYYY').toDate(),
|
||||
});
|
||||
@ -87,8 +85,8 @@ export class LedgerComponent implements OnInit, AfterViewInit {
|
||||
}, 0);
|
||||
}
|
||||
|
||||
displayFn(account?: Account): string {
|
||||
return account ? account.name : '';
|
||||
displayFn(account?: Account | string): string {
|
||||
return !account ? '' : typeof account === 'string' ? account : account.name;
|
||||
}
|
||||
|
||||
calculateTotals() {
|
||||
@ -131,7 +129,7 @@ export class LedgerComponent implements OnInit, AfterViewInit {
|
||||
const formModel = this.form.value;
|
||||
|
||||
return new Ledger({
|
||||
account: formModel.account as Account,
|
||||
account: this.info.account,
|
||||
startDate: moment(formModel.startDate).format('DD-MMM-YYYY'),
|
||||
finishDate: moment(formModel.finishDate).format('DD-MMM-YYYY'),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user