UNPKG

gros-bras-shared

Version:

This holds all shared files such as interfaces or helpers used by Gros Bras, both frontoffices and baackoffices, and backend etc...

47 lines (46 loc) 1.82 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.invoiceAmounts = void 0; var _1 = require("."); ; ; var invoiceAmounts = function (rows, additionalFees) { var totalAmount = rows.reduce(function (prev, el) { return prev + el.quantity * el.unit_price; }, 0); var reductionAmount = additionalFees.reduction && additionalFees.reduction.percentage_value >= 0 ? totalAmount * additionalFees.reduction.percentage_value / 100 : 0; var otherReductionsAmounts = additionalFees.other_reductions.map(function (reduction) { return totalAmount * reduction.percentage_value / 100; }); var otherReductions = otherReductionsAmounts.length === 0 ? 0 : otherReductionsAmounts.reduce(function (prev, curr) { return prev + curr; }); var thtAmount = totalAmount - reductionAmount - otherReductions; var tvaAmount = thtAmount * additionalFees.tva / 100; var ttcAmount = thtAmount + tvaAmount; return { total: { value: totalAmount, formated: (0, _1.formatPrices)(totalAmount), }, tva: { value: tvaAmount, formated: (0, _1.formatPrices)(tvaAmount), }, reduction: { value: reductionAmount, formated: (0, _1.formatPrices)(reductionAmount), }, other_reductions: otherReductionsAmounts.map(function (red) { return ({ value: red, formated: (0, _1.formatPrices)(red), }); }), tht: { value: thtAmount, formated: (0, _1.formatPrices)(thtAmount), }, ttc: { value: ttcAmount, formated: (0, _1.formatPrices)(ttcAmount), }, }; }; exports.invoiceAmounts = invoiceAmounts;