Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- GetMrcFilterList(vehicle: IVehicle, searchRank: number, customizeParams: ICustomizeParams) {
- let availablePlans = this.PlansMrc();
- let filteredPlans = [];
- searchRank = searchRank >= 0 ? searchRank : 7;
- let MONTHS_IN_YEAR = 12;
- let quoteMileageLow = 1001;
- let quoteMileageHigh = 1700;
- let averageMilesDriven = customizeParams.miles;
- let yearsOfCoverage = customizeParams.months;
- let monthsTo100000 = (100000 - vehicle.mileage) / averageMilesDriven * MONTHS_IN_YEAR;
- let currentYearVehicleYearDifference = new Date().getFullYear() - parseInt(vehicle.year.name);
- let minimumTargetMiles = currentYearVehicleYearDifference < vehicle.specification.BaseWarrantyMonths() / MONTHS_IN_YEAR ? vehicle.specification.BaseWarrantyMiles() : 0;
- //START distinct on plans
- filteredPlans = this.groupAndGetLowestPricedMrcPlans(availablePlans);
- //END distint on plans
- filteredPlans = Enumerable(filteredPlans)
- .where(/** @param {MrcCoveragePlan} plan */(plan) => {
- return plan.endingMiles > (minimumTargetMiles + averageMilesDriven);
- })
- .toList();
- //Start first conditional check
- let tempList = Enumerable(filteredPlans)
- .where((plan) => {
- let actualPlanMilesPerYear = ((plan.termMiles - vehicle.mileage) / plan.termMonths) * MONTHS_IN_YEAR; // 12 stands for 12 months in a year.
- return plan.rankId == searchRank &&
- plan.mileageCalculated == 1 &&
- (
- actualPlanMilesPerYear >= averageMilesDriven - quoteMileageLow &&
- actualPlanMilesPerYear <= averageMilesDriven + quoteMileageHigh
- );
- })
- .toList();
- //END first conditional check
- //Start second conditional check
- if (tempList.length == 0 && vehicle.mileage <= 60000) {
- tempList = Enumerable(filteredPlans)
- .where((plan) => {
- let actualPlanMilesPerYear = ((plan.termMiles - vehicle.mileage) / plan.termMonths) * MONTHS_IN_YEAR;
- return plan.rankId == searchRank &&
- plan.mileageCalculated == 1 &&
- (
- actualPlanMilesPerYear >= averageMilesDriven - (quoteMileageLow + 2500) &&
- actualPlanMilesPerYear <= averageMilesDriven + (quoteMileageHigh + 5000)
- );
- })
- .toList();
- }
- //End second conditional check
- if (tempList.length == 0) {
- tempList = Enumerable(filteredPlans)
- .where((plan) => {
- return plan.mileageCalculated == 2 && plan.rankId == searchRank && plan.termMonths > 12 && plan.termMonths < 60;
- })
- .toList();
- }
- if (tempList.length == 0 && searchRank > 0) {
- tempList = this.GetMrcFilterList(vehicle, searchRank - 1, customizeParams);
- }
- if (tempList.length == 0 && searchRank == 0) {
- tempList = filteredPlans;
- }
- // end last chance
- this.sortMrcPlans(tempList);
- return tempList;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement