From 558fc29962589dcfb377b54252383b62969c1579 Mon Sep 17 00:00:00 2001 From: Ahmed Bouhuolia Date: Wed, 25 Feb 2026 20:33:31 +0200 Subject: [PATCH] fix: use organization date format in banking transactions and reports - Add OrganizationSettingsModule to BankingTransactionsModule - Update GetBankAccountTransactions to pass dateFormat from settings - Add meta support to FinancialSheet base class - Refactor TransactionsByReference to use IFinancialReportMeta - Update frontend to use server-provided formatted_date --- .../BankingTransactions/BankingTransactions.module.ts | 2 ++ .../GetBankAccountTransactions.service.ts | 11 +++++++++-- .../GetBankAccountTransactions.ts | 5 ++++- .../FinancialStatements/common/FinancialSheet.ts | 5 +++++ .../TransactionsByReference.service.ts | 2 +- .../TransactionsByReferenceReport.ts | 9 +++++---- .../CashFlow/AccountTransactions/components.tsx | 5 ++--- .../src/containers/Drawers/AccountDrawer/utils.tsx | 4 +--- 8 files changed, 29 insertions(+), 14 deletions(-) diff --git a/packages/server/src/modules/BankingTransactions/BankingTransactions.module.ts b/packages/server/src/modules/BankingTransactions/BankingTransactions.module.ts index 17521edff..eaf517811 100644 --- a/packages/server/src/modules/BankingTransactions/BankingTransactions.module.ts +++ b/packages/server/src/modules/BankingTransactions/BankingTransactions.module.ts @@ -24,6 +24,7 @@ import { GetBankAccountsService } from './queries/GetBankAccounts.service'; import { DynamicListModule } from '../DynamicListing/DynamicList.module'; import { BankAccount } from './models/BankAccount'; import { LedgerModule } from '../Ledger/Ledger.module'; +import { TenancyModule } from '../Tenancy/Tenancy.module'; import { GetBankAccountTransactionsService } from './queries/GetBankAccountTransactions/GetBankAccountTransactions.service'; import { GetBankAccountTransactionsRepository } from './queries/GetBankAccountTransactions/GetBankAccountTransactionsRepo.service'; import { GetUncategorizedTransactions } from './queries/GetUncategorizedTransactions'; @@ -46,6 +47,7 @@ const models = [ LedgerModule, BranchesModule, DynamicListModule, + TenancyModule, ...models, ], controllers: [ diff --git a/packages/server/src/modules/BankingTransactions/queries/GetBankAccountTransactions/GetBankAccountTransactions.service.ts b/packages/server/src/modules/BankingTransactions/queries/GetBankAccountTransactions/GetBankAccountTransactions.service.ts index d3f943588..510001435 100644 --- a/packages/server/src/modules/BankingTransactions/queries/GetBankAccountTransactions/GetBankAccountTransactions.service.ts +++ b/packages/server/src/modules/BankingTransactions/queries/GetBankAccountTransactions/GetBankAccountTransactions.service.ts @@ -4,12 +4,14 @@ import { GetBankAccountTransactionsRepository } from './GetBankAccountTransactio import { GetBankAccountTransactions } from './GetBankAccountTransactions'; import { GetBankTransactionsQueryDto } from '../../dtos/GetBankTranasctionsQuery.dto'; import { I18nService } from 'nestjs-i18n'; +import { TenancyContext } from '@/modules/Tenancy/TenancyContext.service'; @Injectable() export class GetBankAccountTransactionsService { constructor( private readonly getBankAccountTransactionsRepository: GetBankAccountTransactionsRepository, - private readonly i18nService: I18nService + private readonly i18nService: I18nService, + private readonly tenancyContext: TenancyContext, ) {} /** @@ -28,11 +30,16 @@ export class GetBankAccountTransactionsService { await this.getBankAccountTransactionsRepository.asyncInit(); + // Retrieve the tenant metadata to get the date format. + const tenantMetadata = await this.tenancyContext.getTenantMetadata(); + const dateFormat = tenantMetadata?.dateFormat; + // Retrieve the computed report. const report = new GetBankAccountTransactions( this.getBankAccountTransactionsRepository, parsedQuery, - this.i18nService + this.i18nService, + dateFormat, ); const transactions = report.reportData(); const pagination = this.getBankAccountTransactionsRepository.pagination; diff --git a/packages/server/src/modules/BankingTransactions/queries/GetBankAccountTransactions/GetBankAccountTransactions.ts b/packages/server/src/modules/BankingTransactions/queries/GetBankAccountTransactions/GetBankAccountTransactions.ts index 5af75485b..2df7c0527 100644 --- a/packages/server/src/modules/BankingTransactions/queries/GetBankAccountTransactions/GetBankAccountTransactions.ts +++ b/packages/server/src/modules/BankingTransactions/queries/GetBankAccountTransactions/GetBankAccountTransactions.ts @@ -24,17 +24,20 @@ export class GetBankAccountTransactions extends FinancialSheet { * @param {IAccountTransaction[]} transactions - * @param {number} openingBalance - * @param {ICashflowAccountTransactionsQuery} query - + * @param {string} dateFormat - The date format from organization settings. */ constructor( repo: GetBankAccountTransactionsRepository, query: ICashflowAccountTransactionsQuery, i18n: I18nService, + dateFormat?: string, ) { super(); this.repo = repo; this.query = query; this.i18n = i18n; + this.dateFormat = dateFormat || this.dateFormat; this.runningBalance = runningBalance(this.repo.openingBalance); } @@ -98,7 +101,7 @@ export class GetBankAccountTransactions extends FinancialSheet { return { date: transaction.date, - formattedDate: moment(transaction.date).format('YYYY-MM-DD'), + formattedDate: this.getDateFormatted(transaction.date), withdrawal: transaction.credit, deposit: transaction.debit, diff --git a/packages/server/src/modules/FinancialStatements/common/FinancialSheet.ts b/packages/server/src/modules/FinancialStatements/common/FinancialSheet.ts index f3ea4d035..6dc28597c 100644 --- a/packages/server/src/modules/FinancialStatements/common/FinancialSheet.ts +++ b/packages/server/src/modules/FinancialStatements/common/FinancialSheet.ts @@ -149,6 +149,11 @@ export class FinancialSheet { }; } + protected getDateFormatted(date: moment.MomentInput, format?: string) { + const dateFormat = format || this.dateFormat || 'YYYY MMM DD'; + return moment(date).format(dateFormat); + } + getPercentageBasis = (base, amount) => { return base ? amount / base : 0; }; diff --git a/packages/server/src/modules/FinancialStatements/modules/TransactionsByReference/TransactionsByReference.service.ts b/packages/server/src/modules/FinancialStatements/modules/TransactionsByReference/TransactionsByReference.service.ts index c5d48bd5b..3136a61c4 100644 --- a/packages/server/src/modules/FinancialStatements/modules/TransactionsByReference/TransactionsByReference.service.ts +++ b/packages/server/src/modules/FinancialStatements/modules/TransactionsByReference/TransactionsByReference.service.ts @@ -38,7 +38,7 @@ export class TransactionsByReferenceService { const report = new TransactionsByReference( transactions, filter, - tenantMetadata.baseCurrency + { baseCurrency: tenantMetadata.baseCurrency, dateFormat: tenantMetadata.dateFormat } ); return { diff --git a/packages/server/src/modules/FinancialStatements/modules/TransactionsByReference/TransactionsByReferenceReport.ts b/packages/server/src/modules/FinancialStatements/modules/TransactionsByReference/TransactionsByReferenceReport.ts index d46431d23..56ed35cbd 100644 --- a/packages/server/src/modules/FinancialStatements/modules/TransactionsByReference/TransactionsByReferenceReport.ts +++ b/packages/server/src/modules/FinancialStatements/modules/TransactionsByReference/TransactionsByReferenceReport.ts @@ -4,7 +4,7 @@ import { import { FinancialSheet } from '../../common/FinancialSheet'; import { ModelObject } from 'objection'; import { AccountTransaction } from '@/modules/Accounts/models/AccountTransaction.model'; -import { INumberFormatQuery } from '../../types/Report.types'; +import { INumberFormatQuery, IFinancialReportMeta, DEFAULT_REPORT_META } from '../../types/Report.types'; import { TransactionsByReferenceQueryDto } from './TransactionsByReferenceQuery.dto'; export class TransactionsByReference extends FinancialSheet { @@ -17,18 +17,19 @@ export class TransactionsByReference extends FinancialSheet { * Constructor method. * @param {ModelObject[]} transactions * @param {TransactionsByVendorQueryDto} query - * @param {string} baseCurrency + * @param {IFinancialReportMeta} meta */ constructor( transactions: ModelObject[], query: TransactionsByReferenceQueryDto, - baseCurrency: string + meta: IFinancialReportMeta, ) { super(); this.transactions = transactions; this.query = query; - this.baseCurrency = baseCurrency; + this.baseCurrency = meta.baseCurrency; + this.dateFormat = meta.dateFormat || DEFAULT_REPORT_META.dateFormat; // this.numberFormat = this.query.numberFormat; } diff --git a/packages/webapp/src/containers/CashFlow/AccountTransactions/components.tsx b/packages/webapp/src/containers/CashFlow/AccountTransactions/components.tsx index 2fef2ed8c..07c1eb2f0 100644 --- a/packages/webapp/src/containers/CashFlow/AccountTransactions/components.tsx +++ b/packages/webapp/src/containers/CashFlow/AccountTransactions/components.tsx @@ -2,7 +2,7 @@ import React from 'react'; import intl from 'react-intl-universal'; import { Intent, Menu, MenuItem, Tag } from '@blueprintjs/core'; -import { FormatDateCell, Icon } from '@/components'; +import { Icon } from '@/components'; import { safeCallback } from '@/utils'; import { useAccountTransactionsContext } from './AccountTransactionsProvider'; import FinancialLoadingBar from '@/containers/FinancialStatements/FinancialLoadingBar'; @@ -75,8 +75,7 @@ export function useAccountTransactionsColumns() { { id: 'date', Header: intl.get('date'), - accessor: 'date', - Cell: FormatDateCell, + accessor: 'formatted_date', width: 110, className: 'date', clickable: true, diff --git a/packages/webapp/src/containers/Drawers/AccountDrawer/utils.tsx b/packages/webapp/src/containers/Drawers/AccountDrawer/utils.tsx index 1a0312a20..9ed26bc71 100644 --- a/packages/webapp/src/containers/Drawers/AccountDrawer/utils.tsx +++ b/packages/webapp/src/containers/Drawers/AccountDrawer/utils.tsx @@ -2,7 +2,6 @@ import intl from 'react-intl-universal'; import React from 'react'; -import { FormatDateCell } from '@/components'; import { useAccountDrawerTableOptionsContext } from './AccountDrawerTableOptionsProvider'; /** @@ -15,8 +14,7 @@ export const useAccountReadEntriesColumns = () => { () => [ { Header: intl.get('transaction_date'), - accessor: 'date', - Cell: FormatDateCell, + accessor: 'formatted_date', width: 110, textOverview: true, },