From e02cdfbe9ce50c05ffa266f3e8bf9a29864fd7fe Mon Sep 17 00:00:00 2001 From: Amritanshu <git@tanshu.com> Date: Mon, 18 Jul 2022 23:40:33 +0530 Subject: [PATCH] Fix: Ledger and product ledger on init would fail because account/product ledger was null. Fixed --- .../employee-attendance.component.ts | 2 +- .../employee-benefits.component.ts | 2 +- .../src/app/issue/issue-dialog.component.ts | 2 +- overlord/src/app/issue/issue.component.ts | 2 +- .../app/journal/journal-dialog.component.ts | 2 +- overlord/src/app/journal/journal.component.ts | 2 +- overlord/src/app/ledger/ledger.component.ts | 18 ++++++++++-------- overlord/src/app/ledger/ledger.ts | 3 +-- .../product-ledger/product-ledger.component.ts | 16 +++++++++------- .../src/app/product-ledger/product-ledger.ts | 3 +-- 10 files changed, 27 insertions(+), 25 deletions(-) diff --git a/overlord/src/app/employee-attendance/employee-attendance.component.ts b/overlord/src/app/employee-attendance/employee-attendance.component.ts index f1f6b2b3..b5672141 100644 --- a/overlord/src/app/employee-attendance/employee-attendance.component.ts +++ b/overlord/src/app/employee-attendance/employee-attendance.component.ts @@ -106,7 +106,7 @@ export class EmployeeAttendanceComponent implements OnInit, AfterViewInit { } selected(event: MatAutocompleteSelectedEvent): void { - this.info.employee = event.option.value; + this.info.employee = event.option.value as Employee; } getClass(index: number) { diff --git a/overlord/src/app/employee-benefits/employee-benefits.component.ts b/overlord/src/app/employee-benefits/employee-benefits.component.ts index 6d53dbfc..1d9dd682 100644 --- a/overlord/src/app/employee-benefits/employee-benefits.component.ts +++ b/overlord/src/app/employee-benefits/employee-benefits.component.ts @@ -138,7 +138,7 @@ export class EmployeeBenefitsComponent implements OnInit, AfterViewInit { } employeeSelected(event: MatAutocompleteSelectedEvent): void { - this.employee = event.option.value; + this.employee = event.option.value as Employee; } addRow() { diff --git a/overlord/src/app/issue/issue-dialog.component.ts b/overlord/src/app/issue/issue-dialog.component.ts index d4d0282b..2776453c 100644 --- a/overlord/src/app/issue/issue-dialog.component.ts +++ b/overlord/src/app/issue/issue-dialog.component.ts @@ -57,7 +57,7 @@ export class IssueDialogComponent implements OnInit { } batchSelected(event: MatAutocompleteSelectedEvent): void { - this.batch = event.option.value; + this.batch = event.option.value as Batch; } accept(): void { diff --git a/overlord/src/app/issue/issue.component.ts b/overlord/src/app/issue/issue.component.ts index 28a11686..600ce849 100644 --- a/overlord/src/app/issue/issue.component.ts +++ b/overlord/src/app/issue/issue.component.ts @@ -331,7 +331,7 @@ export class IssueComponent implements OnInit, AfterViewInit, OnDestroy { } batchSelected(event: MatAutocompleteSelectedEvent): void { - this.batch = event.option.value; + this.batch = event.option.value as Batch; } goToVoucher(id: string) { diff --git a/overlord/src/app/journal/journal-dialog.component.ts b/overlord/src/app/journal/journal-dialog.component.ts index 293acd34..03cfb999 100644 --- a/overlord/src/app/journal/journal-dialog.component.ts +++ b/overlord/src/app/journal/journal-dialog.component.ts @@ -61,7 +61,7 @@ export class JournalDialogComponent implements OnInit { } accountSelected(event: MatAutocompleteSelectedEvent): void { - const account = event.option.value; + const account = event.option.value as Account; this.account = account; this.accountSer.balance(account.id as string, this.data.date).subscribe((v) => { this.accBal = v; diff --git a/overlord/src/app/journal/journal.component.ts b/overlord/src/app/journal/journal.component.ts index 1ff253f8..63018b3a 100644 --- a/overlord/src/app/journal/journal.component.ts +++ b/overlord/src/app/journal/journal.component.ts @@ -329,7 +329,7 @@ export class JournalComponent implements OnInit, AfterViewInit, OnDestroy { } accountSelected(event: MatAutocompleteSelectedEvent): void { - const account = event.option.value; + const account = event.option.value as Account; this.account = account; const date = moment(this.form.value.date).format('DD-MMM-YYYY'); this.accountSer.balance(account.id as string, date).subscribe((v) => { diff --git a/overlord/src/app/ledger/ledger.component.ts b/overlord/src/app/ledger/ledger.component.ts index 1103e720..cae3d2bc 100644 --- a/overlord/src/app/ledger/ledger.component.ts +++ b/overlord/src/app/ledger/ledger.component.ts @@ -69,7 +69,7 @@ export class LedgerComponent implements OnInit, AfterViewInit { this.info = data.info; this.calculateTotals(); this.form.setValue({ - account: this.info.account.name, + account: this.info.account?.name ?? '', startDate: moment(this.info.startDate, 'DD-MMM-YYYY').toDate(), finishDate: moment(this.info.finishDate, 'DD-MMM-YYYY').toDate(), }); @@ -108,7 +108,7 @@ export class LedgerComponent implements OnInit, AfterViewInit { } selected(event: MatAutocompleteSelectedEvent): void { - this.info.account = event.option.value; + this.info.account = event.option.value as Account; } selectRow(id: string): void { @@ -117,12 +117,14 @@ export class LedgerComponent implements OnInit, AfterViewInit { show() { const info = this.getInfo(); - this.router.navigate(['ledger', info.account.id], { - queryParams: { - startDate: info.startDate, - finishDate: info.finishDate, - }, - }); + if (info.account) { + this.router.navigate(['ledger', info.account.id], { + queryParams: { + startDate: info.startDate, + finishDate: info.finishDate, + }, + }); + } } getInfo(): Ledger { diff --git a/overlord/src/app/ledger/ledger.ts b/overlord/src/app/ledger/ledger.ts index c4485512..5ba00396 100644 --- a/overlord/src/app/ledger/ledger.ts +++ b/overlord/src/app/ledger/ledger.ts @@ -5,13 +5,12 @@ import { LedgerItem } from './ledger-item'; export class Ledger { startDate: string; finishDate: string; - account: Account; + account?: Account; body: LedgerItem[]; public constructor(init?: Partial<Ledger>) { this.startDate = ''; this.finishDate = ''; - this.account = new Account(); this.body = []; Object.assign(this, init); } diff --git a/overlord/src/app/product-ledger/product-ledger.component.ts b/overlord/src/app/product-ledger/product-ledger.component.ts index af540029..1b743f94 100644 --- a/overlord/src/app/product-ledger/product-ledger.component.ts +++ b/overlord/src/app/product-ledger/product-ledger.component.ts @@ -86,7 +86,7 @@ export class ProductLedgerComponent implements OnInit, AfterViewInit { this.info = data.info; this.calculateTotals(); this.form.setValue({ - product: this.info.product.name, + product: this.info.product?.name ?? '', startDate: moment(this.info.startDate, 'DD-MMM-YYYY').toDate(), finishDate: moment(this.info.finishDate, 'DD-MMM-YYYY').toDate(), }); @@ -136,12 +136,14 @@ export class ProductLedgerComponent implements OnInit, AfterViewInit { show() { const info = this.getInfo(); - this.router.navigate(['product-ledger', info.product.id], { - queryParams: { - startDate: info.startDate, - finishDate: info.finishDate, - }, - }); + if (info.product) { + this.router.navigate(['product-ledger', info.product.id], { + queryParams: { + startDate: info.startDate, + finishDate: info.finishDate, + }, + }); + } } getInfo(): ProductLedger { diff --git a/overlord/src/app/product-ledger/product-ledger.ts b/overlord/src/app/product-ledger/product-ledger.ts index a2f68a61..6e6f31f2 100644 --- a/overlord/src/app/product-ledger/product-ledger.ts +++ b/overlord/src/app/product-ledger/product-ledger.ts @@ -5,13 +5,12 @@ import { ProductLedgerItem } from './product-ledger-item'; export class ProductLedger { startDate: string; finishDate: string; - product: Product; + product?: Product; body: ProductLedgerItem[]; public constructor(init?: Partial<ProductLedger>) { this.startDate = ''; this.finishDate = ''; - this.product = new Product(); this.body = []; Object.assign(this, init); }