#7936 improve InvoiceIn #1004
|
@ -1,11 +1,10 @@
|
|||
import { toCurrency } from 'src/filters';
|
||||
|
||||
export function getTotal(rows, key, opts = {}) {
|
||||
const { currency, cb, decimalPlaces, int } = opts;
|
||||
const { currency, cb, decimalPlaces } = opts;
|
||||
jorgep marked this conversation as resolved
Outdated
|
||||
const total = rows.reduce((acc, row) => acc + +(cb ? cb(row) : row[key] || 0), 0);
|
||||
const decimals = int ? 0 : decimalPlaces ?? 2;
|
||||
|
||||
return currency
|
||||
? toCurrency(total, currency == 'default' ? undefined : currency)
|
||||
: parseFloat(total).toFixed(decimals);
|
||||
: parseFloat(total).toFixed(decimalPlaces ?? 2);
|
||||
}
|
||||
|
|
|
@ -146,7 +146,7 @@ const columns = computed(() => [
|
|||
{{ getTotal(rows, 'net') }}
|
||||
</QTd>
|
||||
<QTd>
|
||||
{{ getTotal(rows, 'stems', { int: true }) }}
|
||||
{{ getTotal(rows, 'stems', { decimalPlaces: 0 }) }}
|
||||
</QTd>
|
||||
<QTd />
|
||||
</QTr>
|
||||
|
|
|
@ -33,7 +33,7 @@ describe('getTotal()', () => {
|
|||
});
|
||||
|
||||
it('should calculate the total with integer formatting', () => {
|
||||
const total = getTotal(rows, 'amount', { int: true });
|
||||
const total = getTotal(rows, 'amount', { decimalPlaces: 0 });
|
||||
expect(total).toBe('62');
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue
int?