Calculate total + subtotal as early as available
This commit is contained in:
parent
fbdea3582f
commit
5800d00839
1 changed files with 27 additions and 10 deletions
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue