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,28 +231,45 @@ export default {
|
|||
|
||||
// Pricing
|
||||
// Only fire for completed orders?
|
||||
if (hasSubmittedOrder) {
|
||||
const lineItems = order.lineItems ?? {};
|
||||
const combinedLineItems = [
|
||||
...(lineItems.glassParts ?? []),
|
||||
...(lineItems.supportingItems ?? []),
|
||||
...(lineItems.vaps ?? []),
|
||||
...(lineItems.promos ?? []),
|
||||
];
|
||||
|
||||
const lineItems = order.lineItems ?? {};
|
||||
const combinedLineItems = [
|
||||
...(lineItems.glassParts ?? []),
|
||||
...(lineItems.supportingItems ?? []),
|
||||
...(lineItems.vaps ?? []),
|
||||
...(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
|
||||
.getTotalPriceOfAllLineItemsAndChildParts(combinedLineItems, false)
|
||||
.toFixed(2);
|
||||
|
||||
payload.priceSubTotal = parseFloat(subtotal);
|
||||
} else {
|
||||
payload.priceSubTotal = "";
|
||||
}
|
||||
|
||||
if (isTaxAvailable) {
|
||||
const total = baseMixin.methods
|
||||
.getTotalPriceOfAllLineItemsAndChildParts(combinedLineItems, true)
|
||||
.toFixed(2);
|
||||
|
||||
payload.priceTotal = parseFloat(total);
|
||||
payload.priceSubTotal = parseFloat(subtotal);
|
||||
} else {
|
||||
payload.priceTotal = "";
|
||||
payload.priceSubTotal = "";
|
||||
}
|
||||
|
||||
// Recalibration
|
||||
|
|
|
|||
Loading…
Reference in a new issue