Calculate total + subtotal as early as available

This commit is contained in:
Chloe Herd 2024-02-14 14:48:50 -05:00
parent fbdea3582f
commit 5800d00839

View file

@ -231,7 +231,7 @@ export default {
// Pricing // Pricing
// Only fire for completed orders? // Only fire for completed orders?
if (hasSubmittedOrder) {
const lineItems = order.lineItems ?? {}; const lineItems = order.lineItems ?? {};
const combinedLineItems = [ const combinedLineItems = [
...(lineItems.glassParts ?? []), ...(lineItems.glassParts ?? []),
@ -240,19 +240,36 @@ export default {
...(lineItems.promos ?? []), ...(lineItems.promos ?? []),
]; ];
const isPricingAvailable =
combinedLineItems.length > 0 &&
combinedLineItems.every(
(lineItem) =>
isDefined(lineItem.kitPrice) &&
isDefined(lineItem.laborAmount) &&
isDefined(lineItem.sellingPrice)
);
const isTaxAvailable =
isPricingAvailable &&
combinedLineItems.every((lineItem) => isDefined(lineItem.salesTax));
if (isPricingAvailable) {
const subtotal = baseMixin.methods const subtotal = baseMixin.methods
.getTotalPriceOfAllLineItemsAndChildParts(combinedLineItems, false) .getTotalPriceOfAllLineItemsAndChildParts(combinedLineItems, false)
.toFixed(2); .toFixed(2);
payload.priceSubTotal = parseFloat(subtotal);
} else {
payload.priceSubTotal = "";
}
if (isTaxAvailable) {
const total = baseMixin.methods const total = baseMixin.methods
.getTotalPriceOfAllLineItemsAndChildParts(combinedLineItems, true) .getTotalPriceOfAllLineItemsAndChildParts(combinedLineItems, true)
.toFixed(2); .toFixed(2);
payload.priceTotal = parseFloat(total); payload.priceTotal = parseFloat(total);
payload.priceSubTotal = parseFloat(subtotal);
} else { } else {
payload.priceTotal = ""; payload.priceTotal = "";
payload.priceSubTotal = "";
} }
// Recalibration // Recalibration