mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 13:50:31 +00:00
33 lines
813 B
JavaScript
33 lines
813 B
JavaScript
import { repeat } from 'lodash';
|
|
import { toSafeNumber } from 'utils';
|
|
|
|
/**
|
|
* Retrieve item entry total from the given rate, quantity and discount.
|
|
* @param {number} rate
|
|
* @param {number} quantity
|
|
* @param {number} discount
|
|
* @return {number}
|
|
*/
|
|
export const calcItemEntryTotal = (discount, quantity, rate) => {
|
|
const _quantity = toSafeNumber(quantity);
|
|
const _rate = toSafeNumber(rate);
|
|
const _discount = toSafeNumber(discount);
|
|
|
|
return _quantity * _rate - (_quantity * _rate * _discount) / 100;
|
|
};
|
|
|
|
/**
|
|
* Updates the items entries total.
|
|
*/
|
|
export function updateItemsEntriesTotal(rows) {
|
|
return rows.map((row) => ({
|
|
...row,
|
|
total: calcItemEntryTotal(row.discount, row.quantity, row.rate),
|
|
}));
|
|
}
|
|
|
|
export const ITEM_TYPE = {
|
|
SELLABLE: 'SELLABLE',
|
|
PURCHASABLE: 'PURCHASABLE',
|
|
};
|