BOD-63 Added CSS styling to prevent overflow. Added totals calculation to invoice screen. Updated packages.

This commit is contained in:
Patrick Fic
2020-05-05 16:57:17 -07:00
parent 522dc07058
commit 2317d7d385
20 changed files with 835 additions and 208 deletions

View File

@@ -0,0 +1,49 @@
import Dinero from "dinero.js";
export const CalculateInvoiceTotal = (invoice) => {
const {
total,
invoicelines,
federal_tax_rate,
local_tax_rate,
state_tax_rate,
} = invoice;
let subtotal = Dinero({ amount: 0 });
let federalTax = Dinero({ amount: 0 });
let stateTax = Dinero({ amount: 0 });
let localTax = Dinero({ amount: 0 });
if (!!!invoicelines) return null;
invoicelines.map((i) => {
if (!!i) {
const itemTotal = Dinero({ amount: i.actual_cost * 100 || 0 }).multiply(
i.quantity || 1
);
subtotal = subtotal.add(itemTotal);
if (i.applicable_taxes.federal) {
console.log("Adding fed tax.");
federalTax = federalTax.add(
itemTotal.percentage(federal_tax_rate || 0)
);
}
if (i.applicable_taxes.state)
stateTax = stateTax.add(itemTotal.percentage(state_tax_rate || 0));
if (i.applicable_taxes.local)
localTax = localTax.add(itemTotal.percentage(local_tax_rate || 0));
}
});
const invoiceTotal = Dinero({ amount: total * 100 || 0 });
const enteredTotal = subtotal.add(federalTax).add(stateTax).add(localTax);
const discrepancy = enteredTotal.subtract(invoiceTotal);
return {
subtotal,
federalTax,
stateTax,
localTax,
enteredTotal,
invoiceTotal,
discrepancy,
};
};