CASH-152: refactor/improve pricing-helper
This commit is contained in:
parent
e4fee3c8ab
commit
a98a45c769
1 changed files with 27 additions and 31 deletions
|
|
@ -1,48 +1,47 @@
|
||||||
import store from "@/store";
|
import store from "@/store";
|
||||||
import baseMixin from "@/mixins/base-mixin.js";
|
import baseMixin from "@/mixins/base-mixin.js";
|
||||||
|
|
||||||
export function getDisplayAmountDue(lineItems) {
|
export function getDisplayAmountDue(lineItemsObject, includeTax = true) {
|
||||||
// lineItems s/b an OBJECT here (not flattened) FROM PAYMENT
|
return getAmountDue(lineItemsObject, includeTax).toLocaleString("en-US", {
|
||||||
return getAmountDue(lineItems).toLocaleString("en-US", {
|
|
||||||
style: "currency",
|
style: "currency",
|
||||||
currency: "USD",
|
currency: "USD",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getAmountDue(lineItems, includeTax = true) {
|
export function getAmountDue(lineItemsObject, includeTax = true) {
|
||||||
// lineItems s/b an OBJECT here (not flattened) FROM CART, PAYMENT PAGES
|
let amountDue = 0;
|
||||||
var amountDue = 0;
|
|
||||||
if (lineItems?.glassParts) {
|
|
||||||
amountDue += baseMixin?.methods?.getTotalPriceOfAllLineItemsAndChildParts(
|
|
||||||
lineItems.glassParts,
|
|
||||||
includeTax
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lineItems?.supportingItems) {
|
|
||||||
amountDue += baseMixin?.methods?.getTotalPriceOfAllLineItemsAndChildParts(
|
|
||||||
lineItems.supportingItems,
|
|
||||||
includeTax
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const order = baseMixin?.methods?.hasSubmittedOrder()
|
const order = baseMixin?.methods?.hasSubmittedOrder()
|
||||||
? baseMixin?.methods?.getSubmittedOrder()
|
? baseMixin?.methods?.getSubmittedOrder()
|
||||||
: store.getters.order;
|
: 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) {
|
if (store.getters.coverageIsVerified && !order.policy.isNoComp && !order.policy.isItac) {
|
||||||
amountDue = order.policy.currentDeductible;
|
amountDue = order.policy.currentDeductible;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lineItems?.vaps) {
|
if (lineItemsObject?.vaps) {
|
||||||
amountDue += baseMixin?.methods?.getTotalPriceOfAllLineItemsAndChildParts(
|
amountDue += baseMixin?.methods?.getTotalPriceOfAllLineItemsAndChildParts(
|
||||||
lineItems.vaps,
|
lineItemsObject.vaps,
|
||||||
includeTax
|
includeTax
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lineItems?.promos) {
|
if (lineItemsObject?.promos) {
|
||||||
amountDue += baseMixin?.methods?.getTotalPriceOfAllLineItemsAndChildParts(
|
amountDue += baseMixin?.methods?.getTotalPriceOfAllLineItemsAndChildParts(
|
||||||
lineItems.promos,
|
lineItemsObject.promos,
|
||||||
includeTax
|
includeTax
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -50,15 +49,12 @@ export function getAmountDue(lineItems, includeTax = true) {
|
||||||
return ((amountDue * 100) / 100).toFixed(2);
|
return ((amountDue * 100) / 100).toFixed(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getSubTotal(lineItems) {
|
export function getSubTotal(lineItemsObject) {
|
||||||
// this is amountDue without sales tax
|
// this is amountDue without sales tax
|
||||||
// lineItems s/b an OBJECT here (not flattened) USED IN CART
|
return getAmountDue(lineItemsObject, false);
|
||||||
// can be an ARRAY (flattened) FROM QUOTE
|
|
||||||
return getAmountDue(lineItems, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getSalesTax(lineItems) {
|
export function getSalesTax(lineItemsObject) {
|
||||||
// this is amountDue minus subTotal
|
// this is amountDue minus subTotal
|
||||||
// lineItems s/b an OBJECT here (not flattened) USED IN CART
|
return (((getAmountDue(lineItemsObject) - getSubTotal(lineItemsObject)) * 100) / 100).toFixed(2);
|
||||||
return (((getAmountDue(lineItems) - getSubTotal(lineItems)) * 100) / 100).toFixed(2);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue