mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-26 09:39:49 +00:00
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
This commit is contained in:
@@ -24,6 +24,7 @@ import { GetBankAccountsService } from './queries/GetBankAccounts.service';
|
|||||||
import { DynamicListModule } from '../DynamicListing/DynamicList.module';
|
import { DynamicListModule } from '../DynamicListing/DynamicList.module';
|
||||||
import { BankAccount } from './models/BankAccount';
|
import { BankAccount } from './models/BankAccount';
|
||||||
import { LedgerModule } from '../Ledger/Ledger.module';
|
import { LedgerModule } from '../Ledger/Ledger.module';
|
||||||
|
import { TenancyModule } from '../Tenancy/Tenancy.module';
|
||||||
import { GetBankAccountTransactionsService } from './queries/GetBankAccountTransactions/GetBankAccountTransactions.service';
|
import { GetBankAccountTransactionsService } from './queries/GetBankAccountTransactions/GetBankAccountTransactions.service';
|
||||||
import { GetBankAccountTransactionsRepository } from './queries/GetBankAccountTransactions/GetBankAccountTransactionsRepo.service';
|
import { GetBankAccountTransactionsRepository } from './queries/GetBankAccountTransactions/GetBankAccountTransactionsRepo.service';
|
||||||
import { GetUncategorizedTransactions } from './queries/GetUncategorizedTransactions';
|
import { GetUncategorizedTransactions } from './queries/GetUncategorizedTransactions';
|
||||||
@@ -46,6 +47,7 @@ const models = [
|
|||||||
LedgerModule,
|
LedgerModule,
|
||||||
BranchesModule,
|
BranchesModule,
|
||||||
DynamicListModule,
|
DynamicListModule,
|
||||||
|
TenancyModule,
|
||||||
...models,
|
...models,
|
||||||
],
|
],
|
||||||
controllers: [
|
controllers: [
|
||||||
|
|||||||
@@ -4,12 +4,14 @@ import { GetBankAccountTransactionsRepository } from './GetBankAccountTransactio
|
|||||||
import { GetBankAccountTransactions } from './GetBankAccountTransactions';
|
import { GetBankAccountTransactions } from './GetBankAccountTransactions';
|
||||||
import { GetBankTransactionsQueryDto } from '../../dtos/GetBankTranasctionsQuery.dto';
|
import { GetBankTransactionsQueryDto } from '../../dtos/GetBankTranasctionsQuery.dto';
|
||||||
import { I18nService } from 'nestjs-i18n';
|
import { I18nService } from 'nestjs-i18n';
|
||||||
|
import { TenancyContext } from '@/modules/Tenancy/TenancyContext.service';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class GetBankAccountTransactionsService {
|
export class GetBankAccountTransactionsService {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly getBankAccountTransactionsRepository: GetBankAccountTransactionsRepository,
|
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();
|
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.
|
// Retrieve the computed report.
|
||||||
const report = new GetBankAccountTransactions(
|
const report = new GetBankAccountTransactions(
|
||||||
this.getBankAccountTransactionsRepository,
|
this.getBankAccountTransactionsRepository,
|
||||||
parsedQuery,
|
parsedQuery,
|
||||||
this.i18nService
|
this.i18nService,
|
||||||
|
dateFormat,
|
||||||
);
|
);
|
||||||
const transactions = report.reportData();
|
const transactions = report.reportData();
|
||||||
const pagination = this.getBankAccountTransactionsRepository.pagination;
|
const pagination = this.getBankAccountTransactionsRepository.pagination;
|
||||||
|
|||||||
@@ -24,17 +24,20 @@ export class GetBankAccountTransactions extends FinancialSheet {
|
|||||||
* @param {IAccountTransaction[]} transactions -
|
* @param {IAccountTransaction[]} transactions -
|
||||||
* @param {number} openingBalance -
|
* @param {number} openingBalance -
|
||||||
* @param {ICashflowAccountTransactionsQuery} query -
|
* @param {ICashflowAccountTransactionsQuery} query -
|
||||||
|
* @param {string} dateFormat - The date format from organization settings.
|
||||||
*/
|
*/
|
||||||
constructor(
|
constructor(
|
||||||
repo: GetBankAccountTransactionsRepository,
|
repo: GetBankAccountTransactionsRepository,
|
||||||
query: ICashflowAccountTransactionsQuery,
|
query: ICashflowAccountTransactionsQuery,
|
||||||
i18n: I18nService,
|
i18n: I18nService,
|
||||||
|
dateFormat?: string,
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.repo = repo;
|
this.repo = repo;
|
||||||
this.query = query;
|
this.query = query;
|
||||||
this.i18n = i18n;
|
this.i18n = i18n;
|
||||||
|
this.dateFormat = dateFormat || this.dateFormat;
|
||||||
|
|
||||||
this.runningBalance = runningBalance(this.repo.openingBalance);
|
this.runningBalance = runningBalance(this.repo.openingBalance);
|
||||||
}
|
}
|
||||||
@@ -98,7 +101,7 @@ export class GetBankAccountTransactions extends FinancialSheet {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
date: transaction.date,
|
date: transaction.date,
|
||||||
formattedDate: moment(transaction.date).format('YYYY-MM-DD'),
|
formattedDate: this.getDateFormatted(transaction.date),
|
||||||
|
|
||||||
withdrawal: transaction.credit,
|
withdrawal: transaction.credit,
|
||||||
deposit: transaction.debit,
|
deposit: transaction.debit,
|
||||||
|
|||||||
@@ -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) => {
|
getPercentageBasis = (base, amount) => {
|
||||||
return base ? amount / base : 0;
|
return base ? amount / base : 0;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ export class TransactionsByReferenceService {
|
|||||||
const report = new TransactionsByReference(
|
const report = new TransactionsByReference(
|
||||||
transactions,
|
transactions,
|
||||||
filter,
|
filter,
|
||||||
tenantMetadata.baseCurrency
|
{ baseCurrency: tenantMetadata.baseCurrency, dateFormat: tenantMetadata.dateFormat }
|
||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import {
|
|||||||
import { FinancialSheet } from '../../common/FinancialSheet';
|
import { FinancialSheet } from '../../common/FinancialSheet';
|
||||||
import { ModelObject } from 'objection';
|
import { ModelObject } from 'objection';
|
||||||
import { AccountTransaction } from '@/modules/Accounts/models/AccountTransaction.model';
|
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';
|
import { TransactionsByReferenceQueryDto } from './TransactionsByReferenceQuery.dto';
|
||||||
|
|
||||||
export class TransactionsByReference extends FinancialSheet {
|
export class TransactionsByReference extends FinancialSheet {
|
||||||
@@ -17,18 +17,19 @@ export class TransactionsByReference extends FinancialSheet {
|
|||||||
* Constructor method.
|
* Constructor method.
|
||||||
* @param {ModelObject<AccountTransaction>[]} transactions
|
* @param {ModelObject<AccountTransaction>[]} transactions
|
||||||
* @param {TransactionsByVendorQueryDto} query
|
* @param {TransactionsByVendorQueryDto} query
|
||||||
* @param {string} baseCurrency
|
* @param {IFinancialReportMeta} meta
|
||||||
*/
|
*/
|
||||||
constructor(
|
constructor(
|
||||||
transactions: ModelObject<AccountTransaction>[],
|
transactions: ModelObject<AccountTransaction>[],
|
||||||
query: TransactionsByReferenceQueryDto,
|
query: TransactionsByReferenceQueryDto,
|
||||||
baseCurrency: string
|
meta: IFinancialReportMeta,
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.transactions = transactions;
|
this.transactions = transactions;
|
||||||
this.query = query;
|
this.query = query;
|
||||||
this.baseCurrency = baseCurrency;
|
this.baseCurrency = meta.baseCurrency;
|
||||||
|
this.dateFormat = meta.dateFormat || DEFAULT_REPORT_META.dateFormat;
|
||||||
// this.numberFormat = this.query.numberFormat;
|
// this.numberFormat = this.query.numberFormat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import intl from 'react-intl-universal';
|
import intl from 'react-intl-universal';
|
||||||
import { Intent, Menu, MenuItem, Tag } from '@blueprintjs/core';
|
import { Intent, Menu, MenuItem, Tag } from '@blueprintjs/core';
|
||||||
import { FormatDateCell, Icon } from '@/components';
|
import { Icon } from '@/components';
|
||||||
import { safeCallback } from '@/utils';
|
import { safeCallback } from '@/utils';
|
||||||
import { useAccountTransactionsContext } from './AccountTransactionsProvider';
|
import { useAccountTransactionsContext } from './AccountTransactionsProvider';
|
||||||
import FinancialLoadingBar from '@/containers/FinancialStatements/FinancialLoadingBar';
|
import FinancialLoadingBar from '@/containers/FinancialStatements/FinancialLoadingBar';
|
||||||
@@ -75,8 +75,7 @@ export function useAccountTransactionsColumns() {
|
|||||||
{
|
{
|
||||||
id: 'date',
|
id: 'date',
|
||||||
Header: intl.get('date'),
|
Header: intl.get('date'),
|
||||||
accessor: 'date',
|
accessor: 'formatted_date',
|
||||||
Cell: FormatDateCell,
|
|
||||||
width: 110,
|
width: 110,
|
||||||
className: 'date',
|
className: 'date',
|
||||||
clickable: true,
|
clickable: true,
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
import intl from 'react-intl-universal';
|
import intl from 'react-intl-universal';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import { FormatDateCell } from '@/components';
|
|
||||||
import { useAccountDrawerTableOptionsContext } from './AccountDrawerTableOptionsProvider';
|
import { useAccountDrawerTableOptionsContext } from './AccountDrawerTableOptionsProvider';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -15,8 +14,7 @@ export const useAccountReadEntriesColumns = () => {
|
|||||||
() => [
|
() => [
|
||||||
{
|
{
|
||||||
Header: intl.get('transaction_date'),
|
Header: intl.get('transaction_date'),
|
||||||
accessor: 'date',
|
accessor: 'formatted_date',
|
||||||
Cell: FormatDateCell,
|
|
||||||
width: 110,
|
width: 110,
|
||||||
textOverview: true,
|
textOverview: true,
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user