From 88fda1cbde4abada611ec6a37dfa123ecdbfee67 Mon Sep 17 00:00:00 2001 From: Tiny_Murky Date: Wed, 9 Oct 2024 11:58:15 +0800 Subject: [PATCH] Cash flow begin fix --- package.json | 2 +- src/interfaces/voucher.ts | 15 +++++++++++++ src/lib/utils/repo/voucher.beta.repo.ts | 6 +++++- src/lib/utils/repo/voucher.repo.ts | 6 +++++- .../report/cash_flow_statement_generator.ts | 21 +++++++++++++------ 5 files changed, 41 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 47ed8048f..038ad00ab 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "iSunFA", - "version": "0.8.2+37", + "version": "0.8.2+38", "private": false, "scripts": { "dev": "next dev", diff --git a/src/interfaces/voucher.ts b/src/interfaces/voucher.ts index cc619f839..96a05facf 100644 --- a/src/interfaces/voucher.ts +++ b/src/interfaces/voucher.ts @@ -58,6 +58,21 @@ export type IVoucherFromPrismaIncludeJournalLineItems = Prisma.VoucherGetPayload }; }>; +export type IVoucherForCashFlow = Prisma.VoucherGetPayload<{ + include: { + journal: { + include: { + invoice: true; + }; + }; + lineItems: { + include: { + account: true; + }; + }; + }; +}>; + export type IVoucherFromPrismaIncludeLineItems = Prisma.VoucherGetPayload<{ include: { lineItems: { diff --git a/src/lib/utils/repo/voucher.beta.repo.ts b/src/lib/utils/repo/voucher.beta.repo.ts index 0cdf7fe44..dffe6e065 100644 --- a/src/lib/utils/repo/voucher.beta.repo.ts +++ b/src/lib/utils/repo/voucher.beta.repo.ts @@ -191,7 +191,11 @@ export async function findManyVoucherWithCashInPrisma( }; const include = { - journal: true, + journal: { + include: { + invoice: true, + }, + }, lineItems: { include: { account: true, diff --git a/src/lib/utils/repo/voucher.repo.ts b/src/lib/utils/repo/voucher.repo.ts index a41f47259..2e291938c 100644 --- a/src/lib/utils/repo/voucher.repo.ts +++ b/src/lib/utils/repo/voucher.repo.ts @@ -303,7 +303,11 @@ export async function findManyVoucherWithCashInPrisma( }, }, include: { - journal: true, + journal: { + include: { + invoice: true, + }, + }, lineItems: { include: { account: true, diff --git a/src/lib/utils/report/cash_flow_statement_generator.ts b/src/lib/utils/report/cash_flow_statement_generator.ts index 60b2dfe64..afec4c42b 100644 --- a/src/lib/utils/report/cash_flow_statement_generator.ts +++ b/src/lib/utils/report/cash_flow_statement_generator.ts @@ -9,7 +9,10 @@ import { } from '@/interfaces/accounting_account'; import { IDirectCashFlowMapping, IOperatingCashFlowMapping } from '@/interfaces/cash_flow'; import { OPERATING_CASH_FLOW_INDIRECT_MAPPING } from '@/constants/cash_flow/operating_cash_flow'; -import { IVoucherFromPrismaIncludeJournalLineItems } from '@/interfaces/voucher'; +import { + IVoucherForCashFlow, + IVoucherFromPrismaIncludeJournalLineItems, +} from '@/interfaces/voucher'; import { findManyVoucherWithCashInPrisma } from '@/lib/utils/repo/voucher.repo'; import { INVESTING_CASH_FLOW_DIRECT_MAPPING } from '@/constants/cash_flow/investing_cash_flow'; import { FINANCING_CASH_FLOW_DIRECT_MAPPING } from '@/constants/cash_flow/financing_cash_flow'; @@ -28,7 +31,7 @@ export default class CashFlowStatementGenerator extends FinancialReportGenerator private voucherRelatedToCash: IVoucherFromPrismaIncludeJournalLineItems[]; - private voucherLastPeriod: IVoucherFromPrismaIncludeJournalLineItems[]; + private voucherLastPeriod: IVoucherForCashFlow[]; private YEAR_RANGE = 5; @@ -38,7 +41,7 @@ export default class CashFlowStatementGenerator extends FinancialReportGenerator companyId: number, startDateInSecond: number, endDateInSecond: number, - voucherRelatedToCash: IVoucherFromPrismaIncludeJournalLineItems[] + voucherRelatedToCash: IVoucherForCashFlow[] ) { const reportSheetType = ReportSheetType.CASH_FLOW_STATEMENT; super(companyId, startDateInSecond, endDateInSecond, reportSheetType); @@ -54,13 +57,19 @@ export default class CashFlowStatementGenerator extends FinancialReportGenerator endDateInSecond ); this.voucherRelatedToCash = voucherRelatedToCash.filter((voucher) => { - const laterThanStartDate = voucher.journal.createdAt >= startDateInSecond; - const earlierThanEndDate = voucher.journal.createdAt <= endDateInSecond; + const laterThanStartDate = voucher.journal?.invoice?.date + ? voucher.journal.invoice.date >= startDateInSecond + : false; + const earlierThanEndDate = voucher.journal?.invoice?.date + ? voucher.journal?.invoice?.date <= endDateInSecond + : false; return laterThanStartDate && earlierThanEndDate; }); this.voucherLastPeriod = voucherRelatedToCash.filter((voucher) => { - const earlierThanStartDate = voucher.journal.createdAt < startDateInSecond; + const earlierThanStartDate = voucher.journal?.invoice?.date + ? voucher.journal?.invoice?.date < startDateInSecond + : false; return earlierThanStartDate; }); }