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
|
||||
v-if="isQuoteDisplayed"
|
||||
class="d-flex justify-content-center cost mb-0">
|
||||
{{ formattedServicePrice }}
|
||||
{{ servicePriceForDisplay }}
|
||||
</div>
|
||||
<div
|
||||
v-if="verifiedITAC"
|
||||
|
|
@ -130,6 +130,7 @@ import routerParams from '@/router/router-constants/router-params';
|
|||
import issPageValues from '@/router/router-constants/issPage-values';
|
||||
import bailoutMessage from '@/constants/bailoutMessage';
|
||||
import widgetFields from '@/constants/cms-widget-fields.js';
|
||||
import getPriceOfLineItems from '@/helpers/price-calculator.js';
|
||||
|
||||
const SAFELITE_PROVIDER = 'Safelite';
|
||||
|
||||
|
|
@ -211,13 +212,15 @@ export default {
|
|||
data() {
|
||||
const { isRepair } = useMainStore().damage;
|
||||
const { policyLookupSuccessful, noCoverage } = useMainStore().policy;
|
||||
const { currentDeductible } = useMainStore().order.currentDeductible;
|
||||
return {
|
||||
currencyFormatter: new Intl.NumberFormat('en-US', {
|
||||
style: 'currency',
|
||||
currency: 'USD'
|
||||
}),
|
||||
isRepair,
|
||||
policyLookupSuccessful,
|
||||
deductibleValue: currentDeductible,
|
||||
isNoComp: noCoverage ?? false,
|
||||
availableLineItems: [],
|
||||
baseServiceLineItems: [],
|
||||
selectedProvider: '',
|
||||
deductibleText: 'Your deductible is',
|
||||
// TODO update when design team gives appropriate text
|
||||
|
|
@ -286,8 +289,11 @@ export default {
|
|||
const damageString = getDamageString();
|
||||
return damageString === 'match' ? '' : damageString;
|
||||
},
|
||||
deductibleValue() {
|
||||
return useMainStore().order.currentDeductible;
|
||||
},
|
||||
formattedDeductible() {
|
||||
return this.getDeductibleString(this.deductibleValue);
|
||||
return this.getFormattedAmount(this.deductibleValue);
|
||||
},
|
||||
registerClaimSuccessful() {
|
||||
return useMainStore().payment.insuranceCoverage.isVerified;
|
||||
|
|
@ -300,7 +306,6 @@ export default {
|
|||
&& !this.isNoComp
|
||||
&& this.deductibleValue > this.totalServicePrice;
|
||||
},
|
||||
// TODO maybe tweak
|
||||
coveredAndServicePriceAboveOrEqualDeductible() {
|
||||
return !this.verifiedNoComp && this.totalServicePrice >= this.deductibleValue;
|
||||
},
|
||||
|
|
@ -316,21 +321,17 @@ export default {
|
|||
const parts = useMainStore().order.lineItems.glassParts;
|
||||
return parts !== null && !!parts.find((part) => part.requiresRecalibration);
|
||||
},
|
||||
// TODO replace with better method
|
||||
totalServicePrice() {
|
||||
let total = 0;
|
||||
this.availableLineItems.forEach((lineItem) => {
|
||||
total += this.getTotalLineItemPrice(lineItem);
|
||||
});
|
||||
return total;
|
||||
return getPriceOfLineItems(this.baseServiceLineItems);
|
||||
},
|
||||
formattedServicePrice() {
|
||||
return this.getServicePriceString(this.totalServicePrice);
|
||||
servicePriceForDisplay() {
|
||||
return this.getFormattedAmount(this.totalServicePrice);
|
||||
},
|
||||
costSavings() {
|
||||
const savings = this.getITACCostSavings(this.deductibleValue, this.totalServicePrice);
|
||||
const formattedSavings = parseFloat(savings).toFixed(2);
|
||||
return `$${formattedSavings}`;
|
||||
itacCostSavings() {
|
||||
return this.deductibleValue - this.totalServicePrice;
|
||||
},
|
||||
itacCostSavingsForDisplay() {
|
||||
return this.getFormattedAmount(this.itacCostSavings);
|
||||
},
|
||||
serviceProviderQuestionText() {
|
||||
return this.getCmsContent(
|
||||
|
|
@ -367,10 +368,13 @@ export default {
|
|||
arePagePrerequisitesValid() {
|
||||
return !!useMainStore().vehicle.carId;
|
||||
},
|
||||
getFormattedAmount(amount) {
|
||||
return this.currencyFormatter.format(amount);
|
||||
},
|
||||
async initializeComponent() {
|
||||
useMainStore().updatePolicyITACFlag(this.verifiedITAC);
|
||||
if (this.policyLookupSuccessful
|
||||
&& useMainStore().order.vehicle.policyVehicleId >= 0
|
||||
&& useMainStore().vehicle.policyVehicleId >= 0
|
||||
&& useMainStore().isClaimRegistrationRequired
|
||||
&& !useMainStore().isClaimAlreadyRegistered
|
||||
&& (this.coveredAndServicePriceAboveOrEqualDeductible || this.verifiedITAC)) {
|
||||
|
|
@ -380,11 +384,7 @@ export default {
|
|||
},
|
||||
async navigateForward() {
|
||||
if (this.unverified || this.verifiedDeductible) {
|
||||
<<<<<<< HEAD
|
||||
useMainStore().saveSupportingItems(this.supportingItems);
|
||||
=======
|
||||
useMainStore().updateSupportingItems(this.supportingItems);
|
||||
>>>>>>> 24103335eec282fad8ded09087cf8502b0150ad6
|
||||
this.$router.navigate(
|
||||
navigationScenarios.CLICKED_FORWARD,
|
||||
this.$route,
|
||||
|
|
@ -392,37 +392,28 @@ export default {
|
|||
{ [routerParams.SAVE_SESSION_SYNCHRONOUS]: true }
|
||||
);
|
||||
} else if (this.verifiedITAC || this.verifiedNoComp) {
|
||||
<<<<<<< HEAD
|
||||
useMainStore().updateIsSafeliteProvider(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);
|
||||
>>>>>>> 24103335eec282fad8ded09087cf8502b0150ad6
|
||||
this.$router.navigate(
|
||||
navigationScenarios.CLICKED_FORWARD_WITH_SAFELITE,
|
||||
this.$route,
|
||||
{},
|
||||
{ [routerParams.SAVE_SESSION_SYNCHRONOUS]: true }
|
||||
this.$route
|
||||
);
|
||||
} else {
|
||||
useMainStore().setBailout(this.$router.currentRoute, bailoutMessage.RequestCallback());
|
||||
this.$router.navigate(
|
||||
navigationScenarios.CLICKED_FORWARD_WITH_NON_SAFELITE_SHOP,
|
||||
this.$route,
|
||||
{},
|
||||
{ [routerParams.SAVE_SESSION_SYNCHRONOUS]: true }
|
||||
this.$route
|
||||
);
|
||||
}
|
||||
} else {
|
||||
useMainStore().setBailout(this.$router.currentRoute, bailoutMessage.coverageStatementInvalidState());
|
||||
useMainStore().setBailout(
|
||||
this.$router.currentRoute,
|
||||
bailoutMessage.coverageStatementInvalidState()
|
||||
);
|
||||
this.$router.navigate(
|
||||
navigationScenarios.CLICKED_FORWARD_WITH_INVALID_STATE,
|
||||
this.$route,
|
||||
{},
|
||||
{ [routerParams.SAVE_SESSION_SYNCHRONOUS]: true }
|
||||
this.$route
|
||||
);
|
||||
}
|
||||
},
|
||||
|
|
@ -454,28 +445,11 @@ export default {
|
|||
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) {
|
||||
this.supportingItems = newSupportingItems;
|
||||
},
|
||||
setAvailableLineItems(newAvailableLineItems) {
|
||||
this.availableLineItems = newAvailableLineItems;
|
||||
setBaseServiceLineItems(lineItems) {
|
||||
this.baseServiceLineItems = lineItems;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
@ -485,7 +459,7 @@ export default {
|
|||
.cost {
|
||||
color: $green;
|
||||
font-size: 2rem;
|
||||
font-weight: 300;
|
||||
font-weight: $font-weight-light;
|
||||
line-height: 2.75rem;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue