mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 22:30:31 +00:00
fix: doctype general ledger
This commit is contained in:
@@ -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);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user