mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 14:50:32 +00:00
fix: ledger calculating closing balance.
This commit is contained in:
@@ -1,8 +1,10 @@
|
|||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
|
import { defaultTo } from 'lodash';
|
||||||
import {
|
import {
|
||||||
ILedger,
|
ILedger,
|
||||||
ILedgerEntry
|
ILedgerEntry
|
||||||
} from 'interfaces';
|
} from 'interfaces';
|
||||||
|
import EntityRepository from 'repositories/EntityRepository';
|
||||||
|
|
||||||
export default class Ledger implements ILedger {
|
export default class Ledger implements ILedger {
|
||||||
readonly entries: ILedgerEntry[];
|
readonly entries: ILedgerEntry[];
|
||||||
@@ -64,10 +66,10 @@ export default class Ledger implements ILedger {
|
|||||||
|
|
||||||
this.entries.forEach((entry) => {
|
this.entries.forEach((entry) => {
|
||||||
if (entry.accountNormal === 'credit') {
|
if (entry.accountNormal === 'credit') {
|
||||||
closingBalance += entry.credit ? entry.credit : -1 * entry.debit;
|
closingBalance += entry.credit - entry.debit;
|
||||||
|
|
||||||
} else if (entry.accountNormal === 'debit') {
|
} else if (entry.accountNormal === 'debit') {
|
||||||
closingBalance += entry.debit ? entry.debit : -1 * entry.credit;
|
closingBalance += entry.debit - entry.credit;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return closingBalance;
|
return closingBalance;
|
||||||
@@ -79,8 +81,8 @@ export default class Ledger implements ILedger {
|
|||||||
|
|
||||||
static mapEntry(entry): ILedgerEntry {
|
static mapEntry(entry): ILedgerEntry {
|
||||||
return {
|
return {
|
||||||
credit: entry.credit,
|
credit: defaultTo(entry.credit, 0),
|
||||||
debit: entry.debit,
|
debit: defaultTo(entry.debit, 0),
|
||||||
accountNormal: entry.accountNormal,
|
accountNormal: entry.accountNormal,
|
||||||
accountId: entry.accountId,
|
accountId: entry.accountId,
|
||||||
contactId: entry.contactId,
|
contactId: entry.contactId,
|
||||||
|
|||||||
Reference in New Issue
Block a user