Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
updateRebates(vendorId: number) {
this.dealerService.VendorRetrieveDealsRebates(vendorId).subscribe(rebates => {
let currentCoverageGroup = "";
this.groupedDealsRebates = [];
for (let rebateA of rebates) {
if (rebateA.coverageGroup === currentCoverageGroup) {
continue;
}
let coverageGroup = {
coverages: [],
coverageGroup: rebateA.coverageGroup
};
currentCoverageGroup = rebateA.coverageGroup;
let coverageIndex = 0;
for (let rebateB of rebates) {
let currentCoverage = "";
if (!(rebateB.coverageGroup === currentCoverageGroup &&
rebateB.coverage !== currentCoverage)) {
continue;
}
let coverage = {
coverage: rebateB.coverage,
deals: [], // deals contain one or more deal combinations as well as a total
deductibles: [],
isOpen: (coverageIndex === 0),
partGroups: []
};
currentCoverage = rebateB.coverage;
coverageIndex++;
let currentAgeBand = "";
let currentDistanceBand = "";
for (let rebateC of rebates) {
if (rebateC.coverageGroup === currentCoverageGroup &&
rebateC.coverage === currentCoverage &&
rebateC.coverageAgeBand !== currentAgeBand &&
rebateC.coverageDistanceBand !== currentDistanceBand) {
currentAgeBand = undefined;
currentDistanceBand = undefined;
continue;
}
let deal = {
records: [],
total: 0
};
// does deal already exist
let exists = false;
for (let deal of coverage.deals) {
for (let record of deal.records) {
if (record.coverageGroup === currentCoverageGroup &&
record.coverage === currentCoverage &&
record.coverageAgeBand !== currentAgeBand &&
record.coverageDistanceBand !== currentDistanceBand) {
exists = true;
}
}
}
if (exists) {
continue;
}
currentAgeBand = rebateC.coverageAgeBand;
currentDistanceBand = rebateC.coverageDistanceBand;
for (let rebateD of rebates) {
if (!(rebateD.coverageGroup === currentCoverageGroup &&
rebateD.coverage === currentCoverage &&
rebateD.coverageAgeBand === currentAgeBand &&
rebateD.coverageDistanceBand === currentDistanceBand &&
rebateD.deductible === null &&
rebateD.partGroup === null)) {
continue;
}
console.log(currentCoverageGroup + "::" + currentCoverage + "::" + currentAgeBand + "::" + currentDistanceBand);
deal.records.push(rebateD);
deal.total += rebateD.basePrice || 0;
deal.total += rebateD.adjustment || 0;
deal.total += rebateD.surcharge || 0;
}
coverage.deals.push(deal);
}
for (let rebateE of rebates) {
if (rebateE.coverageGroup === currentCoverageGroup && rebateE.coverage === currentCoverage && rebateE.deductible !== null) {
coverage.deductibles.push(rebateE);
}
if (rebateE.coverageGroup === currentCoverageGroup && rebateE.coverage === currentCoverage && rebateE.partGroup !== null) {
coverage.partGroups.push(rebateE);
}
}
coverageGroup.coverages.push(coverage);
}
this.groupedDealsRebates.push(coverageGroup);
}
console.log(JSON.stringify(this.groupedDealsRebates));
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.