Moving line item pricing to price calculator
This commit is contained in:
parent
87837f013c
commit
4e4f99f7c9
3 changed files with 99 additions and 59 deletions
10
src/helpers/price-calculator.js
Normal file
10
src/helpers/price-calculator.js
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
function getPriceOfLineItem(lineItem) {
|
||||||
|
return lineItem.kitPrice + lineItem.laborAmount + lineItem.sellingPrice;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function getPriceOfLineItems(lineItems) {
|
||||||
|
return lineItems.reduce(
|
||||||
|
(accumulator, lineItem) => accumulator + getPriceOfLineItem(lineItem),
|
||||||
|
0
|
||||||
|
);
|
||||||
|
}
|
||||||
56
src/helpers/price-calculator.spec.js
Normal file
56
src/helpers/price-calculator.spec.js
Normal file
|
|
@ -0,0 +1,56 @@
|
||||||
|
import getPriceOfLineItems from "@/helpers/price-calculator.js";
|
||||||
|
|
||||||
|
describe('getPriceOfLineItems', () => {
|
||||||
|
test('Returns zero when no line items', () => {
|
||||||
|
// Arrange
|
||||||
|
const lineItems = [];
|
||||||
|
|
||||||
|
// Act
|
||||||
|
const result = getPriceOfLineItems(lineItems);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(result).toBe(0);
|
||||||
|
});
|
||||||
|
test('Returns expected when one line item', () => {
|
||||||
|
// Arrange
|
||||||
|
const lineItems = [
|
||||||
|
{
|
||||||
|
kitPrice: 1,
|
||||||
|
laborAmount: 2,
|
||||||
|
sellingPrice: 3
|
||||||
|
}
|
||||||
|
];
|
||||||
|
const expected = 6;
|
||||||
|
|
||||||
|
// Act
|
||||||
|
const result = getPriceOfLineItems(lineItems);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(result).toBe(expected);
|
||||||
|
});
|
||||||
|
test('Returns expected when multiple line items', () => {
|
||||||
|
// Arrange
|
||||||
|
const lineItems = [
|
||||||
|
{
|
||||||
|
kitPrice: 1,
|
||||||
|
laborAmount: 2,
|
||||||
|
sellingPrice: 3
|
||||||
|
},
|
||||||
|
{
|
||||||
|
kitPrice: 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
kitPrice: 10,
|
||||||
|
laborAmount: 100,
|
||||||
|
sellingPrice: 1000
|
||||||
|
}
|
||||||
|
];
|
||||||
|
const expected = 1117;
|
||||||
|
|
||||||
|
// Act
|
||||||
|
const result = getPriceOfLineItems(lineItems);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(result).toBe(expected);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
@ -40,7 +40,7 @@
|
||||||
<div
|
<div
|
||||||
v-if="isQuoteDisplayed"
|
v-if="isQuoteDisplayed"
|
||||||
class="d-flex justify-content-center cost mb-0">
|
class="d-flex justify-content-center cost mb-0">
|
||||||
{{ formattedServicePrice }}
|
{{ servicePriceForDisplay }}
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
v-if="verifiedITAC"
|
v-if="verifiedITAC"
|
||||||
|
|
@ -130,6 +130,7 @@ import routerParams from '@/router/router-constants/router-params';
|
||||||
import issPageValues from '@/router/router-constants/issPage-values';
|
import issPageValues from '@/router/router-constants/issPage-values';
|
||||||
import bailoutMessage from '@/constants/bailoutMessage';
|
import bailoutMessage from '@/constants/bailoutMessage';
|
||||||
import widgetFields from '@/constants/cms-widget-fields.js';
|
import widgetFields from '@/constants/cms-widget-fields.js';
|
||||||
|
import getPriceOfLineItems from '@/helpers/price-calculator.js';
|
||||||
|
|
||||||
const SAFELITE_PROVIDER = 'Safelite';
|
const SAFELITE_PROVIDER = 'Safelite';
|
||||||
|
|
||||||
|
|
@ -211,13 +212,15 @@ export default {
|
||||||
data() {
|
data() {
|
||||||
const { isRepair } = useMainStore().damage;
|
const { isRepair } = useMainStore().damage;
|
||||||
const { policyLookupSuccessful, noCoverage } = useMainStore().policy;
|
const { policyLookupSuccessful, noCoverage } = useMainStore().policy;
|
||||||
const { currentDeductible } = useMainStore().order.currentDeductible;
|
|
||||||
return {
|
return {
|
||||||
|
currencyFormatter: new Intl.NumberFormat('en-US', {
|
||||||
|
style: 'currency',
|
||||||
|
currency: 'USD'
|
||||||
|
}),
|
||||||
isRepair,
|
isRepair,
|
||||||
policyLookupSuccessful,
|
policyLookupSuccessful,
|
||||||
deductibleValue: currentDeductible,
|
|
||||||
isNoComp: noCoverage ?? false,
|
isNoComp: noCoverage ?? false,
|
||||||
availableLineItems: [],
|
baseServiceLineItems: [],
|
||||||
selectedProvider: '',
|
selectedProvider: '',
|
||||||
deductibleText: 'Your deductible is',
|
deductibleText: 'Your deductible is',
|
||||||
// TODO update when design team gives appropriate text
|
// TODO update when design team gives appropriate text
|
||||||
|
|
@ -286,8 +289,11 @@ export default {
|
||||||
const damageString = getDamageString();
|
const damageString = getDamageString();
|
||||||
return damageString === 'match' ? '' : damageString;
|
return damageString === 'match' ? '' : damageString;
|
||||||
},
|
},
|
||||||
|
deductibleValue() {
|
||||||
|
return useMainStore().order.currentDeductible;
|
||||||
|
},
|
||||||
formattedDeductible() {
|
formattedDeductible() {
|
||||||
return this.getDeductibleString(this.deductibleValue);
|
return this.getFormattedAmount(this.deductibleValue);
|
||||||
},
|
},
|
||||||
registerClaimSuccessful() {
|
registerClaimSuccessful() {
|
||||||
return useMainStore().payment.insuranceCoverage.isVerified;
|
return useMainStore().payment.insuranceCoverage.isVerified;
|
||||||
|
|
@ -300,7 +306,6 @@ export default {
|
||||||
&& !this.isNoComp
|
&& !this.isNoComp
|
||||||
&& this.deductibleValue > this.totalServicePrice;
|
&& this.deductibleValue > this.totalServicePrice;
|
||||||
},
|
},
|
||||||
// TODO maybe tweak
|
|
||||||
coveredAndServicePriceAboveOrEqualDeductible() {
|
coveredAndServicePriceAboveOrEqualDeductible() {
|
||||||
return !this.verifiedNoComp && this.totalServicePrice >= this.deductibleValue;
|
return !this.verifiedNoComp && this.totalServicePrice >= this.deductibleValue;
|
||||||
},
|
},
|
||||||
|
|
@ -316,21 +321,17 @@ export default {
|
||||||
const parts = useMainStore().order.lineItems.glassParts;
|
const parts = useMainStore().order.lineItems.glassParts;
|
||||||
return parts !== null && !!parts.find((part) => part.requiresRecalibration);
|
return parts !== null && !!parts.find((part) => part.requiresRecalibration);
|
||||||
},
|
},
|
||||||
// TODO replace with better method
|
|
||||||
totalServicePrice() {
|
totalServicePrice() {
|
||||||
let total = 0;
|
return getPriceOfLineItems(this.baseServiceLineItems);
|
||||||
this.availableLineItems.forEach((lineItem) => {
|
|
||||||
total += this.getTotalLineItemPrice(lineItem);
|
|
||||||
});
|
|
||||||
return total;
|
|
||||||
},
|
},
|
||||||
formattedServicePrice() {
|
servicePriceForDisplay() {
|
||||||
return this.getServicePriceString(this.totalServicePrice);
|
return this.getFormattedAmount(this.totalServicePrice);
|
||||||
},
|
},
|
||||||
costSavings() {
|
itacCostSavings() {
|
||||||
const savings = this.getITACCostSavings(this.deductibleValue, this.totalServicePrice);
|
return this.deductibleValue - this.totalServicePrice;
|
||||||
const formattedSavings = parseFloat(savings).toFixed(2);
|
},
|
||||||
return `$${formattedSavings}`;
|
itacCostSavingsForDisplay() {
|
||||||
|
return this.getFormattedAmount(this.itacCostSavings);
|
||||||
},
|
},
|
||||||
serviceProviderQuestionText() {
|
serviceProviderQuestionText() {
|
||||||
return this.getCmsContent(
|
return this.getCmsContent(
|
||||||
|
|
@ -367,10 +368,13 @@ export default {
|
||||||
arePagePrerequisitesValid() {
|
arePagePrerequisitesValid() {
|
||||||
return !!useMainStore().vehicle.carId;
|
return !!useMainStore().vehicle.carId;
|
||||||
},
|
},
|
||||||
|
getFormattedAmount(amount) {
|
||||||
|
return this.currencyFormatter.format(amount);
|
||||||
|
},
|
||||||
async initializeComponent() {
|
async initializeComponent() {
|
||||||
useMainStore().updatePolicyITACFlag(this.verifiedITAC);
|
useMainStore().updatePolicyITACFlag(this.verifiedITAC);
|
||||||
if (this.policyLookupSuccessful
|
if (this.policyLookupSuccessful
|
||||||
&& useMainStore().order.vehicle.policyVehicleId >= 0
|
&& useMainStore().vehicle.policyVehicleId >= 0
|
||||||
&& useMainStore().isClaimRegistrationRequired
|
&& useMainStore().isClaimRegistrationRequired
|
||||||
&& !useMainStore().isClaimAlreadyRegistered
|
&& !useMainStore().isClaimAlreadyRegistered
|
||||||
&& (this.coveredAndServicePriceAboveOrEqualDeductible || this.verifiedITAC)) {
|
&& (this.coveredAndServicePriceAboveOrEqualDeductible || this.verifiedITAC)) {
|
||||||
|
|
@ -380,11 +384,7 @@ export default {
|
||||||
},
|
},
|
||||||
async navigateForward() {
|
async navigateForward() {
|
||||||
if (this.unverified || this.verifiedDeductible) {
|
if (this.unverified || this.verifiedDeductible) {
|
||||||
<<<<<<< HEAD
|
|
||||||
useMainStore().saveSupportingItems(this.supportingItems);
|
|
||||||
=======
|
|
||||||
useMainStore().updateSupportingItems(this.supportingItems);
|
useMainStore().updateSupportingItems(this.supportingItems);
|
||||||
>>>>>>> 24103335eec282fad8ded09087cf8502b0150ad6
|
|
||||||
this.$router.navigate(
|
this.$router.navigate(
|
||||||
navigationScenarios.CLICKED_FORWARD,
|
navigationScenarios.CLICKED_FORWARD,
|
||||||
this.$route,
|
this.$route,
|
||||||
|
|
@ -392,37 +392,28 @@ export default {
|
||||||
{ [routerParams.SAVE_SESSION_SYNCHRONOUS]: true }
|
{ [routerParams.SAVE_SESSION_SYNCHRONOUS]: true }
|
||||||
);
|
);
|
||||||
} else if (this.verifiedITAC || this.verifiedNoComp) {
|
} else if (this.verifiedITAC || this.verifiedNoComp) {
|
||||||
<<<<<<< HEAD
|
|
||||||
useMainStore().updateIsSafeliteProvider(this.selectedProvider === SAFELITE_PROVIDER);
|
useMainStore().updateIsSafeliteProvider(this.selectedProvider === SAFELITE_PROVIDER);
|
||||||
if (this.selectedProvider === SAFELITE_PROVIDER) {
|
if (this.selectedProvider === SAFELITE_PROVIDER) {
|
||||||
useMainStore().saveSupportingItems(this.supportingItems);
|
|
||||||
=======
|
|
||||||
useMainStore().updateIsSafeliteProvider(this.selectedProvider === 'Safelite');
|
|
||||||
if (this.selectedProvider === 'Safelite') {
|
|
||||||
useMainStore().updateSupportingItems(this.supportingItems);
|
useMainStore().updateSupportingItems(this.supportingItems);
|
||||||
>>>>>>> 24103335eec282fad8ded09087cf8502b0150ad6
|
|
||||||
this.$router.navigate(
|
this.$router.navigate(
|
||||||
navigationScenarios.CLICKED_FORWARD_WITH_SAFELITE,
|
navigationScenarios.CLICKED_FORWARD_WITH_SAFELITE,
|
||||||
this.$route,
|
this.$route
|
||||||
{},
|
|
||||||
{ [routerParams.SAVE_SESSION_SYNCHRONOUS]: true }
|
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
useMainStore().setBailout(this.$router.currentRoute, bailoutMessage.RequestCallback());
|
useMainStore().setBailout(this.$router.currentRoute, bailoutMessage.RequestCallback());
|
||||||
this.$router.navigate(
|
this.$router.navigate(
|
||||||
navigationScenarios.CLICKED_FORWARD_WITH_NON_SAFELITE_SHOP,
|
navigationScenarios.CLICKED_FORWARD_WITH_NON_SAFELITE_SHOP,
|
||||||
this.$route,
|
this.$route
|
||||||
{},
|
|
||||||
{ [routerParams.SAVE_SESSION_SYNCHRONOUS]: true }
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
useMainStore().setBailout(this.$router.currentRoute, bailoutMessage.coverageStatementInvalidState());
|
useMainStore().setBailout(
|
||||||
|
this.$router.currentRoute,
|
||||||
|
bailoutMessage.coverageStatementInvalidState()
|
||||||
|
);
|
||||||
this.$router.navigate(
|
this.$router.navigate(
|
||||||
navigationScenarios.CLICKED_FORWARD_WITH_INVALID_STATE,
|
navigationScenarios.CLICKED_FORWARD_WITH_INVALID_STATE,
|
||||||
this.$route,
|
this.$route
|
||||||
{},
|
|
||||||
{ [routerParams.SAVE_SESSION_SYNCHRONOUS]: true }
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -454,28 +445,11 @@ export default {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// TODO move to common location
|
|
||||||
getTotalLineItemPrice(lineItem) {
|
|
||||||
return lineItem.kitPrice + lineItem.laborAmount + lineItem.sellingPrice;
|
|
||||||
},
|
|
||||||
// TODO use price formatter
|
|
||||||
getDeductibleString(deductible) {
|
|
||||||
const formattedDeductibleFloat = parseFloat(deductible).toFixed(2);
|
|
||||||
return `$${formattedDeductibleFloat}`;
|
|
||||||
},
|
|
||||||
// TODO use price formatter
|
|
||||||
getServicePriceString(price) {
|
|
||||||
const formattedPriceFloat = parseFloat(price).toFixed(2);
|
|
||||||
return `$${formattedPriceFloat}`;
|
|
||||||
},
|
|
||||||
getITACCostSavings(vehicleDeductible, totalServicePrice) {
|
|
||||||
return vehicleDeductible - totalServicePrice;
|
|
||||||
},
|
|
||||||
setSupportingItems(newSupportingItems) {
|
setSupportingItems(newSupportingItems) {
|
||||||
this.supportingItems = newSupportingItems;
|
this.supportingItems = newSupportingItems;
|
||||||
},
|
},
|
||||||
setAvailableLineItems(newAvailableLineItems) {
|
setBaseServiceLineItems(lineItems) {
|
||||||
this.availableLineItems = newAvailableLineItems;
|
this.baseServiceLineItems = lineItems;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -485,7 +459,7 @@ export default {
|
||||||
.cost {
|
.cost {
|
||||||
color: $green;
|
color: $green;
|
||||||
font-size: 2rem;
|
font-size: 2rem;
|
||||||
font-weight: 300;
|
font-weight: $font-weight-light;
|
||||||
line-height: 2.75rem;
|
line-height: 2.75rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue