Moved some common methods around.
This commit is contained in:
parent
2754f7be9c
commit
5eb4ef0418
4 changed files with 56 additions and 93 deletions
|
|
@ -86,3 +86,17 @@ export function getPropertyCaseInsensitive(obj, property) {
|
||||||
while (prop = props.pop()) if (prop.toLowerCase() === property.toLowerCase()) return prop;
|
while (prop = props.pop()) if (prop.toLowerCase() === property.toLowerCase()) return prop;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getNonFalseValuesOfPropertyInArrayOfObjects(array, propertyName) {
|
||||||
|
return (array ?? []).map((x) => x[propertyName]).filter((x) => x);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function sortArrayOfObjectsByPropertyValue(arrayOfObjects, propertyName) {
|
||||||
|
if (!arrayOfObjects) return null;
|
||||||
|
|
||||||
|
return arrayOfObjects.sort((a, b) => {
|
||||||
|
if (a[propertyName] < b[propertyName]) return -1;
|
||||||
|
if (a[propertyName] > b[propertyName]) return 1;
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import partTypeStrings from '@/constants/part-type-strings';
|
import partTypeStrings from '@/constants/part-type-strings';
|
||||||
import { deepClone } from '@/helpers/object-helper';
|
import { deepClone, getNonFalseValuesOfPropertyInArrayOfObjects } from '@/helpers/object-helper';
|
||||||
|
|
||||||
const recalPartTypes = [partTypeStrings.RECALIBRATION, partTypeStrings.ADAS_RECALIBRATION];
|
const recalPartTypes = [partTypeStrings.RECALIBRATION, partTypeStrings.ADAS_RECALIBRATION];
|
||||||
|
|
||||||
|
|
@ -73,6 +73,31 @@ export function containsRecalParts(lineItems) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isRecalOrder(lineItems) {
|
||||||
|
return (containsRecalParts(lineItems) && getHasRecalibrationPart(lineItems));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getHasRecalibrationPart(lineItems) {
|
||||||
|
const hasRequiresRecalibration = getNonFalseValuesOfPropertyInArrayOfObjects(lineItems.glassParts, 'requiresRecalibration')?.length > 0;
|
||||||
|
const hasRecalibrationType = getNonFalseValuesOfPropertyInArrayOfObjects(lineItems.glassParts, 'recalibrationType')?.length > 0;
|
||||||
|
|
||||||
|
if (hasRequiresRecalibration) {
|
||||||
|
if (hasRecalibrationType) {
|
||||||
|
// Has both 'requiresRecalibration' and 'recalibrationType' and 'recalibrationType'
|
||||||
|
return (
|
||||||
|
getNonFalseValuesOfPropertyInArrayOfObjects(
|
||||||
|
lineItems.glassParts,
|
||||||
|
'recalibrationType'
|
||||||
|
)[0].toLowerCase() !== 'unknown'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
// Has 'requiresRecalibration' but no 'recalibrationType' at all
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// Does not have 'requiresRecalibration'
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
export function anyPartWithRequiresRecalFlag(lineItems) {
|
export function anyPartWithRequiresRecalFlag(lineItems) {
|
||||||
if (!lineItems) {
|
if (!lineItems) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ import {
|
||||||
ValueToLogTypes
|
ValueToLogTypes
|
||||||
} from '@/constants/analytics';
|
} from '@/constants/analytics';
|
||||||
import { getCartTotal, getSubtotal } from '@/helpers/cart-helper';
|
import { getCartTotal, getSubtotal } from '@/helpers/cart-helper';
|
||||||
import { getRecalPartNumbers } from "@/helpers/recal-helper";
|
import { getRecalPartNumbers, isRecalOrder } from "@/helpers/recal-helper";
|
||||||
import coverageStatuses from '@/constants/coverage-statuses';
|
import coverageStatuses from '@/constants/coverage-statuses';
|
||||||
import coverageType from '@/constants/coverage-type';
|
import coverageType from '@/constants/coverage-type';
|
||||||
import { AppointmentTypeStrings } from '@/constants/schedule-constants';
|
import { AppointmentTypeStrings } from '@/constants/schedule-constants';
|
||||||
|
|
@ -266,35 +266,12 @@ export default {
|
||||||
payload.orderNumber = "";
|
payload.orderNumber = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pricing
|
// Unverified (no price or deductible displayed)
|
||||||
// Only fire for completed orders?
|
|
||||||
|
|
||||||
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));
|
|
||||||
|
|
||||||
//unverified (in scenarios we don’t display the price)
|
|
||||||
if (!store.isVerified) {
|
if (!store.isVerified) {
|
||||||
payload.priceSubTotal = "";
|
payload.priceSubTotal = "";
|
||||||
|
payload.priceTotal = "";
|
||||||
}
|
}
|
||||||
//deductible (in scenarios we don’t display the price)
|
// Deductible case (no price is displayed, only deductible)
|
||||||
// TODO: Need to redo this for ISS 2.0
|
|
||||||
else if (
|
else if (
|
||||||
store.isVerified &&
|
store.isVerified &&
|
||||||
store.currentDeductible >= 0 &&
|
store.currentDeductible >= 0 &&
|
||||||
|
|
@ -302,44 +279,23 @@ export default {
|
||||||
!store.isNoComp
|
!store.isNoComp
|
||||||
) {
|
) {
|
||||||
payload.priceSubTotal = "";
|
payload.priceSubTotal = "";
|
||||||
} else if (isPricingAvailable) {
|
payload.priceTotal = "";
|
||||||
|
// ITAC or NoComp (where cash price is shown)
|
||||||
|
} else if (store.isVerified && (store.isItac || store.isNoComp)) {
|
||||||
const subtotal = getSubtotal(order).toFixed(2);
|
const subtotal = getSubtotal(order).toFixed(2);
|
||||||
|
|
||||||
payload.priceSubTotal = parseFloat(subtotal);
|
payload.priceSubTotal = parseFloat(subtotal);
|
||||||
|
const total = getCartTotal(order).toFixed(2);
|
||||||
|
payload.priceTotal = parseFloat(total);
|
||||||
} else {
|
} else {
|
||||||
payload.priceSubTotal = "";
|
payload.priceSubTotal = "";
|
||||||
|
payload.priceTotal = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cash Quote or Cash Price Sub Total
|
// Cash Quote or Cash Price Sub Total
|
||||||
payload.cashPriceSubTotal = getSubtotal(order).toString();
|
payload.cashPriceSubTotal = getSubtotal(order).toString();
|
||||||
|
|
||||||
//unverified (in scenarios we don’t display the price)
|
|
||||||
if (!store.isVerified) {
|
|
||||||
payload.priceTotal = "";
|
|
||||||
}
|
|
||||||
//deductible (in scenarios we don’t display the price)
|
|
||||||
else if (
|
|
||||||
store.isVerified &&
|
|
||||||
store.currentDeductible >= 0 &&
|
|
||||||
!store.isItac &&
|
|
||||||
!store.isNoComp
|
|
||||||
) {
|
|
||||||
payload.priceTotal = "";
|
|
||||||
} else if (isTaxAvailable) {
|
|
||||||
const total = getCartTotal(order).toFixed(2);
|
|
||||||
|
|
||||||
payload.priceTotal = parseFloat(total);
|
|
||||||
} else {
|
|
||||||
payload.priceTotal = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Recalibration
|
// Recalibration
|
||||||
// TODO: Find equivalent ISS methods.
|
payload.isRecalibrationOnOrder = isRecalOrder(order.lineItems);
|
||||||
if (hasSubmittedOrder) {
|
|
||||||
payload.isRecalibrationOnOrder = store.getters.isRecalibrationOnSubmittedState;
|
|
||||||
} else {
|
|
||||||
payload.isRecalibrationOnOrder = store.hasRecalibrationPart && containsRecalParts(order.lineItems);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Appointment Type
|
// Appointment Type
|
||||||
if (isDefined(order.serviceLocation.appointmentType)) {
|
if (isDefined(order.serviceLocation.appointmentType)) {
|
||||||
|
|
@ -348,8 +304,6 @@ export default {
|
||||||
payload.appointmentType = "";
|
payload.appointmentType = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
//Insurance
|
|
||||||
// TODO: Find equivalent ISS methods. Using store atm need to run off order object.
|
|
||||||
payload.isInsuranceVerified = store.isVerified;
|
payload.isInsuranceVerified = store.isVerified;
|
||||||
payload.insuranceCompanyName = store.issConfig.clientName ?? "";
|
payload.insuranceCompanyName = store.issConfig.clientName ?? "";
|
||||||
if (!store.isVerified) {
|
if (!store.isVerified) {
|
||||||
|
|
|
||||||
|
|
@ -22,11 +22,12 @@ import {
|
||||||
repairWaivedForSelectedVehicle
|
repairWaivedForSelectedVehicle
|
||||||
} from '@/helpers/policy-vehicle-helper';
|
} from '@/helpers/policy-vehicle-helper';
|
||||||
import { buildURLSearchParams, getPartNumbersListForQueryString } from '@/helpers/querystring-helper';
|
import { buildURLSearchParams, getPartNumbersListForQueryString } from '@/helpers/querystring-helper';
|
||||||
import { getRecalPartNumbers, getTopLevelGlassPartsWithRecal } from '@/helpers/recal-helper';
|
import { getRecalPartNumbers, getTopLevelGlassPartsWithRecal, getHasRecalibrationPart } from '@/helpers/recal-helper';
|
||||||
import { getDateForSavedSessionTimeout } from '@/helpers/session-helper';
|
import { getDateForSavedSessionTimeout } from '@/helpers/session-helper';
|
||||||
import { isMobileDevice } from '@/helpers/useragent-helper';
|
import { isMobileDevice } from '@/helpers/useragent-helper';
|
||||||
import issPageValues from '@/router/router-constants/issPage-values';
|
import issPageValues from '@/router/router-constants/issPage-values';
|
||||||
import CoverageStatuses from '@/constants/coverage-statuses';
|
import CoverageStatuses from '@/constants/coverage-statuses';
|
||||||
|
import { getNonFalseValuesOfPropertyInArrayOfObjects, sortArrayOfObjectsByPropertyValue } from '@/helpers/object-helper';
|
||||||
|
|
||||||
const storeId = 'main';
|
const storeId = 'main';
|
||||||
|
|
||||||
|
|
@ -276,7 +277,7 @@ export const useMainStore = defineStore({
|
||||||
state: () => state,
|
state: () => state,
|
||||||
getters: {
|
getters: {
|
||||||
billToAccountNumber: (storeState) => storeState.issConfig.billToAccountNumber,
|
billToAccountNumber: (storeState) => storeState.issConfig.billToAccountNumber,
|
||||||
hasRecalibrationPart: (storeState) => getHasRecalibrationPart(storeState),
|
hasRecalibrationPart: (storeState) => getHasRecalibrationPartOnOrder(storeState),
|
||||||
vehicle: (storeState) => storeState.order.vehicle,
|
vehicle: (storeState) => storeState.order.vehicle,
|
||||||
damage: (storeState) => storeState.order.damage,
|
damage: (storeState) => storeState.order.damage,
|
||||||
lineItems: (state) => state.order.lineItems,
|
lineItems: (state) => state.order.lineItems,
|
||||||
|
|
@ -3179,39 +3180,8 @@ export const useMainStore = defineStore({
|
||||||
|
|
||||||
// Private Functions
|
// Private Functions
|
||||||
|
|
||||||
function getHasRecalibrationPart(state) {
|
function getHasRecalibrationPartOnOrder(state) {
|
||||||
const hasRequiresRecalibration = getNonFalseValuesOfPropertyInArrayOfObjects(state.order.lineItems.glassParts, 'requiresRecalibration')?.length > 0;
|
return getHasRecalibrationPart(state.order.lineItems);
|
||||||
const hasRecalibrationType = getNonFalseValuesOfPropertyInArrayOfObjects(state.order.lineItems.glassParts, 'recalibrationType')?.length > 0;
|
|
||||||
|
|
||||||
if (hasRequiresRecalibration) {
|
|
||||||
if (hasRecalibrationType) {
|
|
||||||
// Has both 'requiresRecalibration' and 'recalibrationType' and 'recalibrationType'
|
|
||||||
return (
|
|
||||||
getNonFalseValuesOfPropertyInArrayOfObjects(
|
|
||||||
state.order.lineItems.glassParts,
|
|
||||||
'recalibrationType'
|
|
||||||
)[0].toLowerCase() !== 'unknown'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
// Has 'requiresRecalibration' but no 'recalibrationType' at all
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
// Does not have 'requiresRecalibration'
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getNonFalseValuesOfPropertyInArrayOfObjects(array, propertyName) {
|
|
||||||
return (array ?? []).map((x) => x[propertyName]).filter((x) => x);
|
|
||||||
}
|
|
||||||
|
|
||||||
function sortArrayOfObjectsByPropertyValue(arrayOfObjects, propertyName) {
|
|
||||||
if (!arrayOfObjects) return null;
|
|
||||||
|
|
||||||
return arrayOfObjects.sort((a, b) => {
|
|
||||||
if (a[propertyName] < b[propertyName]) return -1;
|
|
||||||
if (a[propertyName] > b[propertyName]) return 1;
|
|
||||||
return 0;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function convertGlassPieceNamingForApi(glassArray) {
|
function convertGlassPieceNamingForApi(glassArray) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue