fix: doctype general ledger

This commit is contained in:
Ahmed Bouhuolia
2024-06-06 18:48:33 +02:00
parent 708a4dda9e
commit 94192bfc29
2 changed files with 28 additions and 23 deletions

View File

@@ -14,6 +14,7 @@ import { GeneralLedgerRepository } from './GeneralLedgerRepository';
import { FinancialSheetStructure } from '../FinancialSheetStructure'; import { FinancialSheetStructure } from '../FinancialSheetStructure';
import { flatToNestedArray } from '@/utils'; import { flatToNestedArray } from '@/utils';
import Ledger from '@/services/Accounting/Ledger'; import Ledger from '@/services/Accounting/Ledger';
import { calculateRunningBalance } from './_utils';
/** /**
* General ledger sheet. * General ledger sheet.
@@ -21,11 +22,10 @@ import Ledger from '@/services/Accounting/Ledger';
export default class GeneralLedgerSheet extends R.compose( export default class GeneralLedgerSheet extends R.compose(
FinancialSheetStructure FinancialSheetStructure
)(FinancialSheet) { )(FinancialSheet) {
tenantId: number; private query: IGeneralLedgerSheetQuery;
query: IGeneralLedgerSheetQuery; private baseCurrency: string;
baseCurrency: string; private i18n: any;
i18n: any; private repository: GeneralLedgerRepository;
repository: GeneralLedgerRepository;
/** /**
* Constructor method. * Constructor method.
@@ -51,17 +51,6 @@ export default class GeneralLedgerSheet extends R.compose(
this.i18n = i18n; this.i18n = i18n;
} }
/**
* Calculate the running balance.
* @param {number} amount - Transaction amount.
* @param {number} lastRunningBalance - Last running balance.
* @param {number} openingBalance - Opening balance.
* @return {number} Running balance.
*/
calculateRunningBalance(amount: number, lastRunningBalance: number): number {
return amount + lastRunningBalance;
}
/** /**
* Entry mapper. * Entry mapper.
* @param {ILedgerEntry} entry - * @param {ILedgerEntry} entry -
@@ -79,16 +68,19 @@ export default class GeneralLedgerSheet extends R.compose(
entry.debit, entry.debit,
entry.accountNormal entry.accountNormal
); );
return this.calculateRunningBalance(amount, lastRunningBalance); return calculateRunningBalance(amount, lastRunningBalance);
} }
/** /**
* * Maps the given ledger entry to G/L transaction.
* @param entry * @param {ILedgerEntry} entry
* @param runningBalance * @param {number} runningBalance
* @returns * @returns {IGeneralLedgerSheetAccountTransaction}
*/ */
private entryMapper(entry: ILedgerEntry, runningBalance: number) { private transactionMapper(
entry: ILedgerEntry,
runningBalance: number
): IGeneralLedgerSheetAccountTransaction {
const contact = this.repository.contactsById.get(entry.contactId); const contact = this.repository.contactsById.get(entry.contactId);
const amount = Ledger.getAmount( const amount = Ledger.getAmount(
entry.credit, entry.credit,
@@ -155,7 +147,7 @@ export default class GeneralLedgerSheet extends R.compose(
.map((entryPair: [number, ILedgerEntry]) => { .map((entryPair: [number, ILedgerEntry]) => {
const [runningBalance, entry] = entryPair; const [runningBalance, entry] = entryPair;
return this.entryMapper(entry, runningBalance); return this.transactionMapper(entry, runningBalance);
}); });
} }

View File

@@ -0,0 +1,13 @@
/**
* Calculate the running balance.
* @param {number} amount - Transaction amount.
* @param {number} lastRunningBalance - Last running balance.
* @param {number} openingBalance - Opening balance.
* @return {number} Running balance.
*/
export function calculateRunningBalance(
amount: number,
lastRunningBalance: number
): number {
return amount + lastRunningBalance;
}