Skip to content

Commit

Permalink
Merge pull request #2739 from CAFECA-IO/feature/fixCashFlowBug
Browse files Browse the repository at this point in the history
Cash flow begin amount fix
  • Loading branch information
Luphia authored Oct 9, 2024
2 parents 19cde06 + 88fda1c commit 36aca3a
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "iSunFA",
"version": "0.8.2+37",
"version": "0.8.2+38",
"private": false,
"scripts": {
"dev": "next dev",
Expand Down
15 changes: 15 additions & 0 deletions src/interfaces/voucher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
6 changes: 5 additions & 1 deletion src/lib/utils/repo/voucher.beta.repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,11 @@ export async function findManyVoucherWithCashInPrisma(
};

const include = {
journal: true,
journal: {
include: {
invoice: true,
},
},
lineItems: {
include: {
account: true,
Expand Down
6 changes: 5 additions & 1 deletion src/lib/utils/repo/voucher.repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,11 @@ export async function findManyVoucherWithCashInPrisma(
},
},
include: {
journal: true,
journal: {
include: {
invoice: true,
},
},
lineItems: {
include: {
account: true,
Expand Down
21 changes: 15 additions & 6 deletions src/lib/utils/report/cash_flow_statement_generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -28,7 +31,7 @@ export default class CashFlowStatementGenerator extends FinancialReportGenerator

private voucherRelatedToCash: IVoucherFromPrismaIncludeJournalLineItems[];

private voucherLastPeriod: IVoucherFromPrismaIncludeJournalLineItems[];
private voucherLastPeriod: IVoucherForCashFlow[];

private YEAR_RANGE = 5;

Expand All @@ -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);
Expand All @@ -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;
});
}
Expand Down

0 comments on commit 36aca3a

Please sign in to comment.