diff --git a/src/helpers/pricing-helper.js b/src/helpers/pricing-helper.js index a386ed231..7508ff0ca 100644 --- a/src/helpers/pricing-helper.js +++ b/src/helpers/pricing-helper.js @@ -1,48 +1,47 @@ import store from "@/store"; import baseMixin from "@/mixins/base-mixin.js"; -export function getDisplayAmountDue(lineItems) { - // lineItems s/b an OBJECT here (not flattened) FROM PAYMENT - return getAmountDue(lineItems).toLocaleString("en-US", { +export function getDisplayAmountDue(lineItemsObject, includeTax = true) { + return getAmountDue(lineItemsObject, includeTax).toLocaleString("en-US", { style: "currency", currency: "USD", }); } -export function getAmountDue(lineItems, includeTax = true) { - // lineItems s/b an OBJECT here (not flattened) FROM CART, PAYMENT PAGES - var amountDue = 0; - if (lineItems?.glassParts) { - amountDue += baseMixin?.methods?.getTotalPriceOfAllLineItemsAndChildParts( - lineItems.glassParts, - includeTax - ); - } - - if (lineItems?.supportingItems) { - amountDue += baseMixin?.methods?.getTotalPriceOfAllLineItemsAndChildParts( - lineItems.supportingItems, - includeTax - ); - } - +export function getAmountDue(lineItemsObject, includeTax = true) { + let amountDue = 0; const order = baseMixin?.methods?.hasSubmittedOrder() ? baseMixin?.methods?.getSubmittedOrder() : store.getters.order; + + if (lineItemsObject?.glassParts) { + amountDue += baseMixin.methods.getTotalPriceOfAllLineItemsAndChildParts( + lineItemsObject.glassParts, + includeTax + ); + } + + if (lineItemsObject?.supportingItems) { + amountDue += baseMixin?.methods?.getTotalPriceOfAllLineItemsAndChildParts( + lineItemsObject.supportingItems, + includeTax + ); + } + if (store.getters.coverageIsVerified && !order.policy.isNoComp && !order.policy.isItac) { amountDue = order.policy.currentDeductible; } - if (lineItems?.vaps) { + if (lineItemsObject?.vaps) { amountDue += baseMixin?.methods?.getTotalPriceOfAllLineItemsAndChildParts( - lineItems.vaps, + lineItemsObject.vaps, includeTax ); } - if (lineItems?.promos) { + if (lineItemsObject?.promos) { amountDue += baseMixin?.methods?.getTotalPriceOfAllLineItemsAndChildParts( - lineItems.promos, + lineItemsObject.promos, includeTax ); } @@ -50,15 +49,12 @@ export function getAmountDue(lineItems, includeTax = true) { return ((amountDue * 100) / 100).toFixed(2); } -export function getSubTotal(lineItems) { +export function getSubTotal(lineItemsObject) { // this is amountDue without sales tax - // lineItems s/b an OBJECT here (not flattened) USED IN CART - // can be an ARRAY (flattened) FROM QUOTE - return getAmountDue(lineItems, false); + return getAmountDue(lineItemsObject, false); } -export function getSalesTax(lineItems) { +export function getSalesTax(lineItemsObject) { // this is amountDue minus subTotal - // lineItems s/b an OBJECT here (not flattened) USED IN CART - return (((getAmountDue(lineItems) - getSubTotal(lineItems)) * 100) / 100).toFixed(2); + return (((getAmountDue(lineItemsObject) - getSubTotal(lineItemsObject)) * 100) / 100).toFixed(2); }