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:
@ -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 { AttendanceType } from '../attendance/attendance-type';
|
||||
import { AuthService } from '../auth/auth.service';
|
||||
@ -33,7 +33,7 @@ export class EmployeeAttendanceComponent implements OnInit, AfterViewInit {
|
||||
form: FormGroup<{
|
||||
startDate: FormControl<Date>;
|
||||
finishDate: FormControl<Date>;
|
||||
employee: FormControl<Employee | string | null>;
|
||||
employee: FormControl<string | null>;
|
||||
attendances: FormArray<
|
||||
FormGroup<{
|
||||
attendanceType: FormControl<number>;
|
||||
@ -60,13 +60,11 @@ export class EmployeeAttendanceComponent implements OnInit, AfterViewInit {
|
||||
this.form = new FormGroup({
|
||||
startDate: new FormControl(new Date(), { nonNullable: true }),
|
||||
finishDate: new FormControl(new Date(), { nonNullable: true }),
|
||||
employee: new FormControl<Employee | string | null>(null),
|
||||
employee: new FormControl<string | null>(null),
|
||||
attendances: new FormArray<FormGroup<{ attendanceType: FormControl<number> }>>([]),
|
||||
});
|
||||
// Listen to Employee Value Changes
|
||||
this.employees = this.form.controls.employee.valueChanges.pipe(
|
||||
map((x) => ((x as Employee).name !== undefined ? (x as Employee).name : (x as string))),
|
||||
map((x) => (x !== null && x.length >= 1 ? x : null)),
|
||||
debounceTime(150),
|
||||
distinctUntilChanged(),
|
||||
switchMap((x) => (x === null ? observableOf([]) : this.employeeSer.autocomplete(x))),
|
||||
@ -81,7 +79,7 @@ export class EmployeeAttendanceComponent implements OnInit, AfterViewInit {
|
||||
this.attendanceTypes = data.attendanceTypes;
|
||||
this.form.controls.startDate.setValue(moment(this.info.startDate, 'DD-MMM-YYYY').toDate());
|
||||
this.form.controls.finishDate.setValue(moment(this.info.finishDate, 'DD-MMM-YYYY').toDate());
|
||||
this.form.controls.employee.setValue(this.info.employee);
|
||||
this.form.controls.employee.setValue(this.info.employee.name);
|
||||
this.form.controls.attendances.reset();
|
||||
this.info.body.forEach((x) =>
|
||||
this.form.controls.attendances.push(
|
||||
@ -103,8 +101,8 @@ export class EmployeeAttendanceComponent implements OnInit, AfterViewInit {
|
||||
}, 0);
|
||||
}
|
||||
|
||||
displayFn(employee?: Employee): string {
|
||||
return employee ? employee.name : '';
|
||||
displayFn(employee?: Employee | string): string {
|
||||
return !employee ? '' : typeof employee === 'string' ? employee : employee.name;
|
||||
}
|
||||
|
||||
selected(event: MatAutocompleteSelectedEvent): void {
|
||||
|
||||
@ -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 { AuthService } from '../auth/auth.service';
|
||||
import { AccountBalance } from '../core/account-balance';
|
||||
@ -75,7 +75,6 @@ export class EmployeeBenefitsComponent implements OnInit, AfterViewInit {
|
||||
});
|
||||
// Setup Employee Autocomplete
|
||||
this.employees = this.form.controls.addRow.controls.employee.valueChanges.pipe(
|
||||
map((x) => (x !== null && x.length >= 1 ? x : null)),
|
||||
debounceTime(150),
|
||||
distinctUntilChanged(),
|
||||
switchMap((x) => (x === null ? observableOf([]) : this.employeeSer.autocomplete(x))),
|
||||
@ -134,8 +133,8 @@ export class EmployeeBenefitsComponent implements OnInit, AfterViewInit {
|
||||
this.benefitsObservable.next(this.voucher.employeeBenefits);
|
||||
}
|
||||
|
||||
displayFn(employee?: Employee): string {
|
||||
return employee ? employee.name : '';
|
||||
displayFn(employee?: Employee | string): string {
|
||||
return !employee ? '' : typeof employee === 'string' ? employee : employee.name;
|
||||
}
|
||||
|
||||
employeeSelected(event: MatAutocompleteSelectedEvent): void {
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -3,7 +3,7 @@ import { FormControl, FormGroup } from '@angular/forms';
|
||||
import { MatAutocompleteSelectedEvent } from '@angular/material/autocomplete';
|
||||
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
|
||||
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 { AccountBalance } from '../core/account-balance';
|
||||
@ -41,7 +41,6 @@ export class JournalDialogComponent implements OnInit {
|
||||
this.accBal = null;
|
||||
// Setup Account Autocomplete
|
||||
this.accounts = this.form.controls.account.valueChanges.pipe(
|
||||
map((x) => (x !== null && x.length >= 1 ? x : null)),
|
||||
debounceTime(150),
|
||||
distinctUntilChanged(),
|
||||
switchMap((x) => (x === null ? observableOf([]) : this.accountSer.autocomplete(x))),
|
||||
@ -57,8 +56,8 @@ export class JournalDialogComponent implements OnInit {
|
||||
this.account = this.data.journal.account;
|
||||
}
|
||||
|
||||
displayFn(account?: Account): string {
|
||||
return account ? account.name : '';
|
||||
displayFn(account?: Account | string): string {
|
||||
return !account ? '' : typeof account === 'string' ? account : account.name;
|
||||
}
|
||||
|
||||
accountSelected(event: MatAutocompleteSelectedEvent): void {
|
||||
|
||||
@ -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';
|
||||
@ -80,7 +80,6 @@ export class JournalComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
this.accBal = null;
|
||||
// Setup Account Autocomplete
|
||||
this.accounts = this.form.controls.addRow.controls.account.valueChanges.pipe(
|
||||
map((x) => (x !== null && x.length >= 1 ? x : null)),
|
||||
debounceTime(150),
|
||||
distinctUntilChanged(),
|
||||
switchMap((x) => (x === null ? observableOf([]) : this.accountSer.autocomplete(x))),
|
||||
@ -201,6 +200,7 @@ export class JournalComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
2,
|
||||
);
|
||||
this.form.controls.addRow.reset({
|
||||
debit: this.form.value.addRow?.debit ?? 1,
|
||||
account: null,
|
||||
amount: `${amount}`,
|
||||
});
|
||||
@ -324,8 +324,8 @@ export class JournalComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
});
|
||||
}
|
||||
|
||||
displayFn(account?: Account): string {
|
||||
return account ? account.name : '';
|
||||
displayFn(account?: Account | string): string {
|
||||
return !account ? '' : typeof account === 'string' ? account : account.name;
|
||||
}
|
||||
|
||||
accountSelected(event: MatAutocompleteSelectedEvent): void {
|
||||
|
||||
@ -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'),
|
||||
});
|
||||
|
||||
@ -3,7 +3,7 @@ import { FormControl, FormGroup } from '@angular/forms';
|
||||
import { MatAutocompleteSelectedEvent } from '@angular/material/autocomplete';
|
||||
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
|
||||
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 { AccountBalance } from '../core/account-balance';
|
||||
@ -39,7 +39,6 @@ export class PaymentDialogComponent implements OnInit {
|
||||
this.accBal = null;
|
||||
// Setup Account Autocomplete
|
||||
this.accounts = this.form.controls.account.valueChanges.pipe(
|
||||
map((x) => (x !== null && x.length >= 1 ? x : null)),
|
||||
debounceTime(150),
|
||||
distinctUntilChanged(),
|
||||
switchMap((x) => (x === null ? observableOf([]) : this.accountSer.autocomplete(x))),
|
||||
@ -54,8 +53,8 @@ export class PaymentDialogComponent implements OnInit {
|
||||
this.account = this.data.journal.account;
|
||||
}
|
||||
|
||||
displayFn(account?: Account): string {
|
||||
return account ? account.name : '';
|
||||
displayFn(account?: Account | string): string {
|
||||
return !account ? '' : typeof account === 'string' ? account : account.name;
|
||||
}
|
||||
|
||||
accountSelected(event: MatAutocompleteSelectedEvent): void {
|
||||
|
||||
@ -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';
|
||||
@ -84,7 +84,6 @@ export class PaymentComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
this.accBal = null;
|
||||
// Listen to Account Autocomplete Change
|
||||
this.accounts = this.form.controls.addRow.controls.account.valueChanges.pipe(
|
||||
map((x) => (x !== null && x.length >= 1 ? x : null)),
|
||||
debounceTime(150),
|
||||
distinctUntilChanged(),
|
||||
switchMap((x) => (x === null ? observableOf([]) : this.accountSer.autocomplete(x))),
|
||||
@ -334,8 +333,8 @@ export class PaymentComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
});
|
||||
}
|
||||
|
||||
displayFn(account?: Account): string {
|
||||
return account ? account.name : '';
|
||||
displayFn(account?: Account | string): string {
|
||||
return !account ? '' : typeof account === 'string' ? account : account.name;
|
||||
}
|
||||
|
||||
accountSelected(event: MatAutocompleteSelectedEvent): void {
|
||||
|
||||
@ -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 { Product } from '../core/product';
|
||||
import { ProductSku } from '../core/product-sku';
|
||||
@ -31,7 +31,7 @@ export class ProductLedgerComponent implements OnInit, AfterViewInit {
|
||||
form: FormGroup<{
|
||||
startDate: FormControl<Date>;
|
||||
finishDate: FormControl<Date>;
|
||||
product: FormControl<Product | string | null>;
|
||||
product: FormControl<string | null>;
|
||||
}>;
|
||||
|
||||
selectedRowId = '';
|
||||
@ -67,12 +67,10 @@ export class ProductLedgerComponent implements OnInit, AfterViewInit {
|
||||
this.form = new FormGroup({
|
||||
startDate: new FormControl(new Date(), { nonNullable: true }),
|
||||
finishDate: new FormControl(new Date(), { nonNullable: true }),
|
||||
product: new FormControl<Product | string | null>(null),
|
||||
product: new FormControl<string | null>(null),
|
||||
});
|
||||
|
||||
this.products = this.form.controls.product.valueChanges.pipe(
|
||||
map((x) => ((x as Product).name !== undefined ? (x as Product).name : (x as string))),
|
||||
map((x) => (x !== null && x.length >= 1 ? x : null)),
|
||||
debounceTime(150),
|
||||
distinctUntilChanged(),
|
||||
switchMap((x) =>
|
||||
@ -88,7 +86,7 @@ export class ProductLedgerComponent implements OnInit, AfterViewInit {
|
||||
this.info = data.info;
|
||||
this.calculateTotals();
|
||||
this.form.setValue({
|
||||
product: this.info.product,
|
||||
product: this.info.product.name,
|
||||
startDate: moment(this.info.startDate, 'DD-MMM-YYYY').toDate(),
|
||||
finishDate: moment(this.info.finishDate, 'DD-MMM-YYYY').toDate(),
|
||||
});
|
||||
@ -104,8 +102,8 @@ export class ProductLedgerComponent implements OnInit, AfterViewInit {
|
||||
}, 0);
|
||||
}
|
||||
|
||||
displayFn(product?: Product): string {
|
||||
return product ? product.name : '';
|
||||
displayFn(product?: Product | string): string {
|
||||
return !product ? '' : typeof product === 'string' ? product : product.name;
|
||||
}
|
||||
|
||||
calculateTotals() {
|
||||
@ -150,7 +148,7 @@ export class ProductLedgerComponent implements OnInit, AfterViewInit {
|
||||
const formModel = this.form.value;
|
||||
|
||||
return new ProductLedger({
|
||||
product: formModel.product as Product,
|
||||
product: this.info.product,
|
||||
startDate: moment(formModel.startDate).format('DD-MMM-YYYY'),
|
||||
finishDate: moment(formModel.finishDate).format('DD-MMM-YYYY'),
|
||||
});
|
||||
|
||||
@ -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 PurchaseReturnDialogComponent 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 PurchaseReturnDialogComponent 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 {
|
||||
|
||||
@ -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';
|
||||
@ -42,10 +42,10 @@ export class PurchaseReturnComponent implements OnInit, AfterViewInit, OnDestroy
|
||||
dataSource: PurchaseReturnDataSource = new PurchaseReturnDataSource(this.inventoryObservable);
|
||||
form: FormGroup<{
|
||||
date: FormControl<Date>;
|
||||
account: FormControl<Account | string | null>;
|
||||
account: FormControl<string | null>;
|
||||
amount: FormControl<number>;
|
||||
addRow: FormGroup<{
|
||||
batch: FormControl<Batch | string | null>;
|
||||
batch: FormControl<string | null>;
|
||||
quantity: FormControl<string>;
|
||||
}>;
|
||||
narration: FormControl<string>;
|
||||
@ -75,30 +75,28 @@ export class PurchaseReturnComponent 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({
|
||||
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 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 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),
|
||||
),
|
||||
);
|
||||
}
|
||||
@ -161,7 +159,7 @@ export class PurchaseReturnComponent 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: {
|
||||
batch: '',
|
||||
@ -333,8 +331,8 @@ export class PurchaseReturnComponent implements OnInit, AfterViewInit, OnDestroy
|
||||
});
|
||||
}
|
||||
|
||||
displayFn(item?: Account | Batch): string {
|
||||
return item ? item.name : '';
|
||||
displayFn(item?: Account | Batch | string): string {
|
||||
return !item ? '' : typeof item === 'string' ? item : item.name;
|
||||
}
|
||||
|
||||
accountSelected(event: MatAutocompleteSelectedEvent): void {
|
||||
|
||||
@ -4,7 +4,7 @@ import { MatAutocompleteSelectedEvent } from '@angular/material/autocomplete';
|
||||
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
|
||||
import { round } from 'mathjs';
|
||||
import { Observable, of as observableOf } from 'rxjs';
|
||||
import { debounceTime, distinctUntilChanged, map, switchMap } from 'rxjs/operators';
|
||||
import { debounceTime, distinctUntilChanged, switchMap } from 'rxjs/operators';
|
||||
|
||||
import { Batch } from '../core/batch';
|
||||
import { Inventory } from '../core/inventory';
|
||||
@ -21,7 +21,7 @@ import { MathService } from '../shared/math.service';
|
||||
export class PurchaseDialogComponent implements OnInit {
|
||||
products: Observable<ProductSku[]>;
|
||||
form: FormGroup<{
|
||||
product: FormControl<ProductSku | string | null>;
|
||||
product: FormControl<string | null>;
|
||||
quantity: FormControl<string>;
|
||||
price: FormControl<string>;
|
||||
tax: FormControl<string>;
|
||||
@ -37,7 +37,7 @@ export class PurchaseDialogComponent implements OnInit {
|
||||
private productSer: ProductService,
|
||||
) {
|
||||
this.form = new FormGroup({
|
||||
product: new FormControl<ProductSku | string | null>(null),
|
||||
product: new FormControl<string | null>(null),
|
||||
quantity: new FormControl('', { nonNullable: true }),
|
||||
price: new FormControl('', { nonNullable: true }),
|
||||
tax: new FormControl('', { nonNullable: true }),
|
||||
@ -45,8 +45,6 @@ export class PurchaseDialogComponent implements OnInit {
|
||||
});
|
||||
// Listen to Product Autocomplete Change
|
||||
this.products = this.form.controls.product.valueChanges.pipe(
|
||||
map((x) => ((x as ProductSku).name !== undefined ? (x as ProductSku).name : (x as string))),
|
||||
map((x) => (x !== null && x.length >= 1 ? x : null)),
|
||||
debounceTime(150),
|
||||
distinctUntilChanged(),
|
||||
switchMap((x) => (x === null ? observableOf([]) : this.productSer.autocompleteSku(x, true))),
|
||||
@ -55,7 +53,7 @@ export class PurchaseDialogComponent implements OnInit {
|
||||
|
||||
ngOnInit() {
|
||||
this.form.setValue({
|
||||
product: this.data.inventory.batch?.sku,
|
||||
product: this.data.inventory.batch?.sku.name,
|
||||
quantity: `${this.data.inventory.quantity}`,
|
||||
price: `${this.data.inventory.rate}`,
|
||||
tax: `${this.data.inventory.tax}`,
|
||||
@ -64,8 +62,8 @@ export class PurchaseDialogComponent implements OnInit {
|
||||
this.product = this.data.inventory.batch?.sku;
|
||||
}
|
||||
|
||||
displayFn(product?: Product): string {
|
||||
return product ? product.name : '';
|
||||
displayFn(product?: Product | string): string {
|
||||
return !product ? '' : typeof product === 'string' ? product : product.name;
|
||||
}
|
||||
|
||||
productSelected(event: MatAutocompleteSelectedEvent): void {
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -3,7 +3,7 @@ import { FormControl, FormGroup } from '@angular/forms';
|
||||
import { MatAutocompleteSelectedEvent } from '@angular/material/autocomplete';
|
||||
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
|
||||
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 { AccountBalance } from '../core/account-balance';
|
||||
@ -39,7 +39,6 @@ export class ReceiptDialogComponent implements OnInit {
|
||||
this.accBal = null;
|
||||
// Setup Account Autocomplete
|
||||
this.accounts = this.form.controls.account.valueChanges.pipe(
|
||||
map((x) => (x !== null && x.length >= 1 ? x : null)),
|
||||
debounceTime(150),
|
||||
distinctUntilChanged(),
|
||||
switchMap((x) => (x === null ? observableOf([]) : this.accountSer.autocomplete(x))),
|
||||
@ -54,8 +53,8 @@ export class ReceiptDialogComponent implements OnInit {
|
||||
this.account = this.data.journal.account;
|
||||
}
|
||||
|
||||
displayFn(account?: Account): string {
|
||||
return account ? account.name : '';
|
||||
displayFn(account?: Account | string): string {
|
||||
return !account ? '' : typeof account === 'string' ? account : account.name;
|
||||
}
|
||||
|
||||
accountSelected(event: MatAutocompleteSelectedEvent): void {
|
||||
|
||||
@ -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';
|
||||
@ -83,7 +83,6 @@ export class ReceiptComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
this.accBal = null;
|
||||
// Listen to Account Autocomplete Change
|
||||
this.accounts = this.form.controls.addRow.controls.account.valueChanges.pipe(
|
||||
map((x) => (x !== null && x.length >= 1 ? x : null)),
|
||||
debounceTime(150),
|
||||
distinctUntilChanged(),
|
||||
switchMap((x) => (x === null ? observableOf([]) : this.accountSer.autocomplete(x))),
|
||||
@ -333,8 +332,8 @@ export class ReceiptComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
});
|
||||
}
|
||||
|
||||
displayFn(account?: Account): string {
|
||||
return account ? account.name : '';
|
||||
displayFn(account?: Account | string): string {
|
||||
return !account ? '' : typeof account === 'string' ? account : account.name;
|
||||
}
|
||||
|
||||
accountSelected(event: MatAutocompleteSelectedEvent): void {
|
||||
|
||||
Reference in New Issue
Block a user