Compare commits

...

8 Commits

Author SHA1 Message Date
allcontributors[bot]
8cb56f5a74 docs: update .all-contributorsrc [skip ci] 2024-10-24 14:51:00 +00:00
allcontributors[bot]
a67e2abde5 docs: update README.md [skip ci] 2024-10-24 14:50:59 +00:00
Ahmed Bouhuolia
bc8e440814 Merge pull request #722 from nklmantey/BIG-257-not-balanced-if-decimal
Fix: Credit and debit totals not balancing when decimal values are used
2024-10-24 16:49:52 +02:00
Ahmed Bouhuolia
4c0f9a0aef fix: using lodash utils for decimal rounding 2024-10-24 16:47:29 +02:00
Nana Kofi Larbi Mantey
bbc19df6b4 adds CREDIT_DEBIT_NOT_EQUAL error 2024-10-20 19:04:10 +00:00
Nana Kofi Larbi Mantey
c8c2786893 refactors getTotal function loginc 2024-10-20 17:45:44 +00:00
Nana Kofi Larbi Mantey
d79f26f1b5 refactors backend validator for credit-debit equals 2024-10-20 17:44:39 +00:00
Ahmed Bouhuolia
ccbb399685 Merge pull request #720 from bigcapitalhq/add-estimate-customer-note
fix Customer note does not appear in pdf document
2024-10-19 16:28:33 +02:00
4 changed files with 27 additions and 17 deletions

View File

@@ -159,6 +159,15 @@
"contributions": [ "contributions": [
"code" "code"
] ]
},
{
"login": "nklmantey",
"name": "Mantey",
"avatar_url": "https://avatars.githubusercontent.com/u/90279429?v=4",
"profile": "https://nklmantey.com/",
"contributions": [
"bug"
]
} }
], ],
"contributorsPerLine": 7, "contributorsPerLine": 7,

View File

@@ -133,6 +133,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<td align="center" valign="top" width="14.28%"><a href="https://github.com/oleynikd"><img src="https://avatars.githubusercontent.com/u/3976868?v=4?s=100" width="100px;" alt="Denis"/><br /><sub><b>Denis</b></sub></a><br /><a href="https://github.com/bigcapitalhq/bigcapital/issues?q=author%3Aoleynikd" title="Bug reports">🐛</a></td> <td align="center" valign="top" width="14.28%"><a href="https://github.com/oleynikd"><img src="https://avatars.githubusercontent.com/u/3976868?v=4?s=100" width="100px;" alt="Denis"/><br /><sub><b>Denis</b></sub></a><br /><a href="https://github.com/bigcapitalhq/bigcapital/issues?q=author%3Aoleynikd" title="Bug reports">🐛</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://myself.vercel.app/"><img src="https://avatars.githubusercontent.com/u/42431274?v=4?s=100" width="100px;" alt="Sachin Mittal"/><br /><sub><b>Sachin Mittal</b></sub></a><br /><a href="https://github.com/bigcapitalhq/bigcapital/issues?q=author%3Amittalsam98" title="Bug reports">🐛</a></td> <td align="center" valign="top" width="14.28%"><a href="https://myself.vercel.app/"><img src="https://avatars.githubusercontent.com/u/42431274?v=4?s=100" width="100px;" alt="Sachin Mittal"/><br /><sub><b>Sachin Mittal</b></sub></a><br /><a href="https://github.com/bigcapitalhq/bigcapital/issues?q=author%3Amittalsam98" title="Bug reports">🐛</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://www.camilooviedo.com/"><img src="https://avatars.githubusercontent.com/u/64604272?v=4?s=100" width="100px;" alt="Camilo Oviedo"/><br /><sub><b>Camilo Oviedo</b></sub></a><br /><a href="https://github.com/bigcapitalhq/bigcapital/commits?author=Champetaman" title="Code">💻</a></td> <td align="center" valign="top" width="14.28%"><a href="https://www.camilooviedo.com/"><img src="https://avatars.githubusercontent.com/u/64604272?v=4?s=100" width="100px;" alt="Camilo Oviedo"/><br /><sub><b>Camilo Oviedo</b></sub></a><br /><a href="https://github.com/bigcapitalhq/bigcapital/commits?author=Champetaman" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://nklmantey.com/"><img src="https://avatars.githubusercontent.com/u/90279429?v=4?s=100" width="100px;" alt="Mantey"/><br /><sub><b>Mantey</b></sub></a><br /><a href="https://github.com/bigcapitalhq/bigcapital/issues?q=author%3Anklmantey" title="Bug reports">🐛</a></td>
</tr> </tr>
</tbody> </tbody>
</table> </table>

View File

@@ -1,4 +1,4 @@
import { difference, isEmpty } from 'lodash'; import { difference, isEmpty, round, sumBy } from 'lodash';
import { Service, Inject } from 'typedi'; import { Service, Inject } from 'typedi';
import { ServiceError } from '@/exceptions'; import { ServiceError } from '@/exceptions';
import { import {
@@ -23,20 +23,18 @@ export class CommandManualJournalValidators {
* @param {IManualJournalDTO} manualJournalDTO * @param {IManualJournalDTO} manualJournalDTO
*/ */
public valdiateCreditDebitTotalEquals(manualJournalDTO: IManualJournalDTO) { public valdiateCreditDebitTotalEquals(manualJournalDTO: IManualJournalDTO) {
let totalCredit = 0; const totalCredit = round(
let totalDebit = 0; sumBy(manualJournalDTO.entries, (entry) => entry.credit || 0),
2
manualJournalDTO.entries.forEach((entry) => { );
if (entry.credit > 0) { const totalDebit = round(
totalCredit += entry.credit; sumBy(manualJournalDTO.entries, (entry) => entry.debit || 0),
} 2
if (entry.debit > 0) { );
totalDebit += entry.debit;
}
});
if (totalCredit <= 0 || totalDebit <= 0) { if (totalCredit <= 0 || totalDebit <= 0) {
throw new ServiceError(ERRORS.CREDIT_DEBIT_NOT_EQUAL_ZERO); throw new ServiceError(ERRORS.CREDIT_DEBIT_NOT_EQUAL_ZERO);
} }
if (totalCredit !== totalDebit) { if (totalCredit !== totalDebit) {
throw new ServiceError(ERRORS.CREDIT_DEBIT_NOT_EQUAL); throw new ServiceError(ERRORS.CREDIT_DEBIT_NOT_EQUAL);
} }

View File

@@ -4,7 +4,7 @@ import { Formik, Form } from 'formik';
import { Intent } from '@blueprintjs/core'; import { Intent } from '@blueprintjs/core';
import intl from 'react-intl-universal'; import intl from 'react-intl-universal';
import * as R from 'ramda'; import * as R from 'ramda';
import { isEmpty, omit } from 'lodash'; import { sumBy, round, isEmpty, omit } from 'lodash';
import classNames from 'classnames'; import classNames from 'classnames';
import { useHistory } from 'react-router-dom'; import { useHistory } from 'react-router-dom';
@@ -88,15 +88,17 @@ 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 using lodash
const getTotal = (type = 'credit') => { const getTotal = (type = 'credit') => {
return entries.reduce((total, item) => { return round(
return item[type] ? item[type] + total : total; sumBy(entries, (entry) => parseFloat(entry[type] || 0)),
}, 0); 2,
);
}; };
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'),