mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-21 07:10:33 +00:00
refactors getTotal function loginc
This commit is contained in:
@@ -67,17 +67,17 @@ function MakeJournalEntriesForm({
|
|||||||
() => ({
|
() => ({
|
||||||
...(!isEmpty(manualJournal)
|
...(!isEmpty(manualJournal)
|
||||||
? {
|
? {
|
||||||
...transformToEditForm(manualJournal),
|
...transformToEditForm(manualJournal),
|
||||||
}
|
}
|
||||||
: {
|
: {
|
||||||
...defaultManualJournal,
|
...defaultManualJournal,
|
||||||
// If the auto-increment mode is enabled, take the next journal
|
// If the auto-increment mode is enabled, take the next journal
|
||||||
// number from the settings.
|
// number from the settings.
|
||||||
...(journalAutoIncrement && {
|
...(journalAutoIncrement && {
|
||||||
journal_number: journalNumber,
|
journal_number: journalNumber,
|
||||||
}),
|
|
||||||
currency_code: base_currency,
|
|
||||||
}),
|
}),
|
||||||
|
currency_code: base_currency,
|
||||||
|
}),
|
||||||
}),
|
}),
|
||||||
[manualJournal, base_currency, journalNumber, journalAutoIncrement],
|
[manualJournal, base_currency, journalNumber, journalAutoIncrement],
|
||||||
);
|
);
|
||||||
@@ -88,15 +88,19 @@ function MakeJournalEntriesForm({
|
|||||||
const entries = values.entries.filter(
|
const entries = values.entries.filter(
|
||||||
(entry) => entry.debit || entry.credit,
|
(entry) => entry.debit || entry.credit,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Updated getTotal function
|
||||||
const getTotal = (type = 'credit') => {
|
const getTotal = (type = 'credit') => {
|
||||||
return entries.reduce((total, item) => {
|
return entries.reduce((total, item) => {
|
||||||
return item[type] ? item[type] + total : total;
|
const value = item[type] ? parseFloat(item[type]) : 0;
|
||||||
|
return Math.round((total + value) * 100) / 100;
|
||||||
}, 0);
|
}, 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
const totalCredit = getTotal('credit');
|
const totalCredit = getTotal('credit');
|
||||||
const totalDebit = getTotal('debit');
|
const totalDebit = getTotal('debit');
|
||||||
|
|
||||||
// Validate the total credit should be eqials total debit.
|
// Validate the total credit should be equals total debit.
|
||||||
if (totalCredit !== totalDebit) {
|
if (totalCredit !== totalDebit) {
|
||||||
AppToaster.show({
|
AppToaster.show({
|
||||||
message: intl.get('should_total_of_credit_and_debit_be_equal'),
|
message: intl.get('should_total_of_credit_and_debit_be_equal'),
|
||||||
|
|||||||
Reference in New Issue
Block a user