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:
@ -2,8 +2,8 @@ import { Component, Inject, OnInit } from '@angular/core';
|
||||
import { FormControl, FormGroup } from '@angular/forms';
|
||||
import { MatAutocompleteSelectedEvent } from '@angular/material/autocomplete';
|
||||
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
|
||||
import { Observable } from 'rxjs';
|
||||
import { debounceTime, distinctUntilChanged, map, switchMap } from 'rxjs/operators';
|
||||
import { Observable, of as observableOf } from 'rxjs';
|
||||
import { debounceTime, distinctUntilChanged, switchMap } from 'rxjs/operators';
|
||||
|
||||
import { Batch } from '../core/batch';
|
||||
import { BatchService } from '../core/batch.service';
|
||||
@ -18,7 +18,7 @@ import { MathService } from '../shared/math.service';
|
||||
export class IssueDialogComponent implements OnInit {
|
||||
batches: Observable<Batch[]>;
|
||||
form: FormGroup<{
|
||||
batch: FormControl<Batch | string | null>;
|
||||
batch: FormControl<string | null>;
|
||||
quantity: FormControl<string>;
|
||||
}>;
|
||||
|
||||
@ -31,29 +31,29 @@ export class IssueDialogComponent implements OnInit {
|
||||
private batchSer: BatchService,
|
||||
) {
|
||||
this.form = new FormGroup({
|
||||
batch: new FormControl<Batch | string | null>(null),
|
||||
batch: new FormControl<string | null>(null),
|
||||
quantity: new FormControl<string>('', { nonNullable: true }),
|
||||
});
|
||||
// Listen to Batch Autocomplete Change
|
||||
this.batches = this.form.controls.batch.valueChanges.pipe(
|
||||
map((x) => ((x as Batch).name !== undefined ? (x as Batch).name : (x as string))),
|
||||
map((x) => (x !== null && x.length >= 1 ? x : '')),
|
||||
debounceTime(150),
|
||||
distinctUntilChanged(),
|
||||
switchMap((x) => this.batchSer.autocomplete(this.data.date, x)),
|
||||
switchMap((x) =>
|
||||
x === null ? observableOf([]) : this.batchSer.autocomplete(this.data.date, x),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.form.setValue({
|
||||
batch: this.data.inventory.batch,
|
||||
batch: this.data.inventory.batch.name,
|
||||
quantity: `${this.data.inventory.quantity}`,
|
||||
});
|
||||
this.batch = this.data.inventory.batch as Batch;
|
||||
this.batch = this.data.inventory.batch;
|
||||
}
|
||||
|
||||
displayFn(batch?: Batch): string {
|
||||
return batch ? batch.name : '';
|
||||
displayFn(batch?: Batch | string): string {
|
||||
return !batch ? '' : typeof batch === 'string' ? batch : batch.name;
|
||||
}
|
||||
|
||||
batchSelected(event: MatAutocompleteSelectedEvent): void {
|
||||
|
||||
@ -6,7 +6,7 @@ import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { Hotkey, HotkeysService } from 'angular2-hotkeys';
|
||||
import { round } from 'mathjs';
|
||||
import * as moment from 'moment';
|
||||
import { BehaviorSubject, Observable } from 'rxjs';
|
||||
import { BehaviorSubject, Observable, of as observableOf } from 'rxjs';
|
||||
import { debounceTime, distinctUntilChanged, map, switchMap } from 'rxjs/operators';
|
||||
|
||||
import { AuthService } from '../auth/auth.service';
|
||||
@ -45,7 +45,7 @@ export class IssueComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
destination: FormControl<string | null>;
|
||||
amount: FormControl<number>;
|
||||
addRow: FormGroup<{
|
||||
batch: FormControl<Batch | string | null>;
|
||||
batch: FormControl<string | null>;
|
||||
quantity: FormControl<string>;
|
||||
}>;
|
||||
narration: FormControl<string>;
|
||||
@ -78,19 +78,19 @@ export class IssueComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
destination: new FormControl<string | null>(null),
|
||||
amount: new FormControl({ value: 0, disabled: true }, { nonNullable: true }),
|
||||
addRow: new FormGroup({
|
||||
batch: new FormControl<Batch | string | null>(null),
|
||||
batch: new FormControl<string | null>(null),
|
||||
quantity: new FormControl<string>('', { nonNullable: true }),
|
||||
}),
|
||||
narration: new FormControl('', { nonNullable: true }),
|
||||
});
|
||||
// Listen to Batch Autocomplete Change
|
||||
this.batches = this.form.controls.addRow.controls.batch.valueChanges.pipe(
|
||||
map((x) => ((x as Batch).name !== undefined ? (x as Batch).name : (x as string))),
|
||||
map((x) => (x !== null && x.length >= 1 ? x : '')),
|
||||
debounceTime(150),
|
||||
distinctUntilChanged(),
|
||||
switchMap((x) =>
|
||||
this.batchSer.autocomplete(moment(this.form.value.date).format('DD-MMM-YYYY'), x),
|
||||
x === null
|
||||
? observableOf([])
|
||||
: this.batchSer.autocomplete(moment(this.form.value.date).format('DD-MMM-YYYY'), x),
|
||||
),
|
||||
);
|
||||
// Listen to Date Change
|
||||
@ -326,8 +326,8 @@ export class IssueComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
this.issueGridSer.issueGrid(date).subscribe((x) => this.gridObservable.next(x));
|
||||
}
|
||||
|
||||
displayFn(batch?: Batch): string {
|
||||
return batch ? batch.name : '';
|
||||
displayFn(batch?: Batch | string): string {
|
||||
return !batch ? '' : typeof batch == 'string' ? batch : batch.name;
|
||||
}
|
||||
|
||||
batchSelected(event: MatAutocompleteSelectedEvent): void {
|
||||
|
||||
Reference in New Issue
Block a user