fix: items entries total calculation.

This commit is contained in:
a.bouhuolia
2021-08-03 16:04:31 +02:00
parent 0783fb26f2
commit b2c892b649
15 changed files with 222 additions and 175 deletions

View File

@@ -75,7 +75,7 @@ export function QuantityTotalFooterCell({ rows }) {
* Total footer cell.
*/
export function TotalFooterCell({ payload: { currencyCode }, rows }) {
const total = safeSumBy(rows, 'original.total');
const total = safeSumBy(rows, 'original.amount');
return <span>{formattedAmount(total, currencyCode)}</span>;
}
@@ -168,7 +168,7 @@ export function useEditableItemsEntriesColumns({ landedCost }) {
{
Header: intl.get('total'),
Footer: TotalFooterCell,
accessor: 'total',
accessor: 'amount',
Cell: TotalCell,
disableSortBy: true,
width: 100,

View File

@@ -1,3 +1,4 @@
import { sumBy } from 'lodash';
import { toSafeNumber } from 'utils';
/**
@@ -21,7 +22,7 @@ export const calcItemEntryTotal = (discount, quantity, rate) => {
export function updateItemsEntriesTotal(rows) {
return rows.map((row) => ({
...row,
total: calcItemEntryTotal(row.discount, row.quantity, row.rate),
amount: calcItemEntryTotal(row.discount, row.quantity, row.rate),
}));
}
@@ -29,3 +30,10 @@ export const ITEM_TYPE = {
SELLABLE: 'SELLABLE',
PURCHASABLE: 'PURCHASABLE',
};
/**
* Retrieve total of the given items entries.
*/
export function getEntriesTotal(entries) {
return sumBy(entries, 'amount');
}