Moved some common methods around.

This commit is contained in:
Jeremy-Z 2026-04-13 10:25:48 -04:00
parent 2754f7be9c
commit 5eb4ef0418
4 changed files with 56 additions and 93 deletions

View file

@ -86,3 +86,17 @@ export function getPropertyCaseInsensitive(obj, property) {
while (prop = props.pop()) if (prop.toLowerCase() === property.toLowerCase()) return prop;
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;
});
}

View file

@ -1,5 +1,5 @@
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];
@ -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) {
if (!lineItems) {
return false;

View file

@ -21,7 +21,7 @@ import {
ValueToLogTypes
} from '@/constants/analytics';
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 coverageType from '@/constants/coverage-type';
import { AppointmentTypeStrings } from '@/constants/schedule-constants';
@ -266,35 +266,12 @@ export default {
payload.orderNumber = "";
}
// Pricing
// 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 dont display the price)
// Unverified (no price or deductible displayed)
if (!store.isVerified) {
payload.priceSubTotal = "";
payload.priceTotal = "";
}
//deductible (in scenarios we dont display the price)
// TODO: Need to redo this for ISS 2.0
// Deductible case (no price is displayed, only deductible)
else if (
store.isVerified &&
store.currentDeductible >= 0 &&
@ -302,44 +279,23 @@ export default {
!store.isNoComp
) {
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);
payload.priceSubTotal = parseFloat(subtotal);
const total = getCartTotal(order).toFixed(2);
payload.priceTotal = parseFloat(total);
} else {
payload.priceSubTotal = "";
payload.priceTotal = "";
}
// Cash Quote or Cash Price Sub Total
payload.cashPriceSubTotal = getSubtotal(order).toString();
//unverified (in scenarios we dont display the price)
if (!store.isVerified) {
payload.priceTotal = "";
}
//deductible (in scenarios we dont 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
// TODO: Find equivalent ISS methods.
if (hasSubmittedOrder) {
payload.isRecalibrationOnOrder = store.getters.isRecalibrationOnSubmittedState;
} else {
payload.isRecalibrationOnOrder = store.hasRecalibrationPart && containsRecalParts(order.lineItems);
}
payload.isRecalibrationOnOrder = isRecalOrder(order.lineItems);
// Appointment Type
if (isDefined(order.serviceLocation.appointmentType)) {
@ -348,8 +304,6 @@ export default {
payload.appointmentType = "";
}
//Insurance
// TODO: Find equivalent ISS methods. Using store atm need to run off order object.
payload.isInsuranceVerified = store.isVerified;
payload.insuranceCompanyName = store.issConfig.clientName ?? "";
if (!store.isVerified) {

View file

@ -22,11 +22,12 @@ import {
repairWaivedForSelectedVehicle
} from '@/helpers/policy-vehicle-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 { isMobileDevice } from '@/helpers/useragent-helper';
import issPageValues from '@/router/router-constants/issPage-values';
import CoverageStatuses from '@/constants/coverage-statuses';
import { getNonFalseValuesOfPropertyInArrayOfObjects, sortArrayOfObjectsByPropertyValue } from '@/helpers/object-helper';
const storeId = 'main';
@ -276,7 +277,7 @@ export const useMainStore = defineStore({
state: () => state,
getters: {
billToAccountNumber: (storeState) => storeState.issConfig.billToAccountNumber,
hasRecalibrationPart: (storeState) => getHasRecalibrationPart(storeState),
hasRecalibrationPart: (storeState) => getHasRecalibrationPartOnOrder(storeState),
vehicle: (storeState) => storeState.order.vehicle,
damage: (storeState) => storeState.order.damage,
lineItems: (state) => state.order.lineItems,
@ -3179,39 +3180,8 @@ export const useMainStore = defineStore({
// Private Functions
function getHasRecalibrationPart(state) {
const hasRequiresRecalibration = getNonFalseValuesOfPropertyInArrayOfObjects(state.order.lineItems.glassParts, 'requiresRecalibration')?.length > 0;
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 getHasRecalibrationPartOnOrder(state) {
return getHasRecalibrationPart(state.order.lineItems);
}
function convertGlassPieceNamingForApi(glassArray) {