Best JavaScript code snippet using wpt
SupplierQuoteCalculatorHelper.js
Source:SupplierQuoteCalculatorHelper.js
1({2 doInit_Helper: function (c, e, h) {3 try {4 var calcData = c.get('v.calc');5 calcData.VEN3__Repayment_Frequency__c = 'Monthly';6 calcData.VEN3__Repayment_Type__c = 'Advance';7 calcData.VEN3__Asset_Type__c = 'New';8 calcData.VEN3__Program_Partner_L__c = c.get("v.matrixUser.VEN3__Program_Partner__c");9 c.set('v.calc',calcData);10 var leadObj = c.get('v.leadObj');11 leadObj.VEN3__Vendor_Guest_User__c = c.get('v.matrixUser.Id');12 c.set('v.leadObj',leadObj);13 } catch (err) {14 console.log('Catch error===>>> ' + err);15 }16 },17 calculateRepayment_helper : function (c, e, h) {18 (h.calculateAmountFinance_Helper(c, e, h)).then(value => {19 return h.calculatePayment_Helper(c, e, h);20 }).catch(reason => {21 console.log(reason.message);22 });23 },24 calculatePayment_Helper: function (c, e, h) {25 try {26 let calcData = c.get("v.calc.VEN3__Amount_Financed__c");27 let term = c.get("v.calc.VEN3__Term_months__c");28 let RepaymentType = c.get("v.calc.VEN3__Repayment_Frequency__c");29 let balloon = c.get('v.calc.VEN3__Ballon__c');30 let rate, nperiod, fv, type, brokerageVaue = 0, amount = 0;31 let existingPriceSettings = c.get("v.settingsByPartner");32 if (existingPriceSettings !== null && existingPriceSettings !== undefined) {33 if (calcData !== null && calcData !== undefined && calcData !== ' ' && term !== null && term !== undefined && term !== ' ' && calcData <= 9999999999) {34 amount = calcData;35 nperiod = term;36 let selectedSetting = {};37 if(!$A.util.isUndefinedOrNull(existingPriceSettings)){38 existingPriceSettings.forEach(function (element) {39 if (parseInt(element.VEN3__Term_months__c) === parseInt(term)) {40 selectedSetting = element;41 }42 });43 }44 if (selectedSetting !== null && selectedSetting !== undefined) {45 if (amount < 5000) {46 c.set("v.calc.VEN3__Amount_Financed__c", undefined);47 }48 if (amount >= 5000 && amount <= 50000) {49 if (selectedSetting.VEN3__X5Kto50K_Base_Rate__c !== null && selectedSetting.VEN3__X5Kto50K_Base_Rate__c !== undefined) {50 rate = selectedSetting.VEN3__X5Kto50K_Base_Rate__c;51 }52 if (selectedSetting.VEN3__X5Kto50K_Brokerage__c !== null && selectedSetting.VEN3__X5Kto50K_Brokerage__c !== undefined) {53 brokerageVaue = selectedSetting.VEN3__X5Kto50K_Brokerage__c * amount;54 }55 }56 if (amount >= 50001 && amount <= 100000) {57 if (selectedSetting.VEN3__X50Kto100K_Base_Rate__c !== null && selectedSetting.VEN3__X50Kto100K_Base_Rate__c !== undefined) {58 rate = selectedSetting.VEN3__X50Kto100K_Base_Rate__c;59 }60 if (selectedSetting.VEN3__X50Kto100K_Brokerage__c !== null && selectedSetting.VEN3__X50Kto100K_Brokerage__c !== undefined) {61 brokerageVaue = selectedSetting.VEN3__X50Kto100K_Brokerage__c * amount;62 }63 }64 if (amount >= 100001 && amount <= 150000) {65 if (selectedSetting.VEN3__X100Kto150K_Brokerage__c !== null && selectedSetting.VEN3__X100Kto150K_Brokerage__c !== undefined) {66 brokerageVaue = selectedSetting.VEN3__X100Kto150K_Brokerage__c * amount;67 }68 if (selectedSetting.VEN3__X100Kto150K_Base_Rate__c !== null && selectedSetting.VEN3__X100Kto150K_Base_Rate__c !== undefined) {69 rate = selectedSetting.VEN3__X100Kto150K_Base_Rate__c;70 }71 }72 if (amount >= 150001 && amount <= 250000) {73 if (selectedSetting.VEN3__X150Kto250_Brokerage__c !== null && selectedSetting.VEN3__X150Kto250_Brokerage__c !== undefined) {74 brokerageVaue = selectedSetting.VEN3__X150Kto250_Brokerage__c * amount;75 }76 if (selectedSetting.VEN3__X150Kto250K_Base_Rate__c !== null && selectedSetting.VEN3__X150Kto250K_Base_Rate__c !== undefined) {77 rate = selectedSetting.VEN3__X150Kto250K_Base_Rate__c;78 }79 }80 if (amount >= 250001 && amount <= 500000) {81 if (selectedSetting.VEN3__X250Kto500K_Brokerage__c !== null && selectedSetting.VEN3__X250Kto500K_Brokerage__c !== undefined) {82 brokerageVaue = selectedSetting.VEN3__X250Kto500K_Brokerage__c * amount;83 }84 if (selectedSetting.VEN3__X250Kto500K_Base_Rate__c !== null && selectedSetting.VEN3__X250Kto500K_Base_Rate__c !== undefined) {85 rate = selectedSetting.VEN3__X250Kto500K_Base_Rate__c;86 }87 }88 if (amount >= 500001 && amount <= 999999) {89 if (selectedSetting.VEN3__X500Kto999K_Brokerage__c !== null && selectedSetting.VEN3__X500Kto999K_Brokerage__c !== undefined) {90 brokerageVaue = selectedSetting.VEN3__X500Kto999K_Brokerage__c * amount;91 }92 if (selectedSetting.VEN3__X500Kto999K_Base_Rate__c !== null && selectedSetting.VEN3__X500Kto999K_Base_Rate__c !== undefined) {93 rate = selectedSetting.VEN3__X500Kto999K_Base_Rate__c;94 }95 }96 if (amount >= 1000000 && amount <= 9999999999) {97 if (selectedSetting.VEN3__X1000KAbove_Brokerage__c !== null && selectedSetting.VEN3__X1000KAbove_Brokerage__c !== undefined) {98 brokerageVaue = selectedSetting.VEN3__X1000KAbove_Brokerage__c * amount;99 }100 if (selectedSetting.VEN3__X1000KAbove_Base_Rate__c !== null && selectedSetting.VEN3__X1000KAbove_Base_Rate__c !== undefined) {101 rate = selectedSetting.VEN3__X1000KAbove_Base_Rate__c;102 }103 }104 105 /*var repaymentType;106 if(RepaymentType == 'Monthly'){107 repaymentType = 12;108 }else if(RepaymentType == 'Weekly'){109 nperiod = (parseInt(nperiod)/12)*52;110 repaymentType = 52;111 }*/112 var Percentage = c.get('v.percentage');113 if(!$A.util.isUndefinedOrNull(Percentage)){114 rate = parseFloat(rate) + parseFloat(Percentage);115 }116 if(!$A.util.isUndefinedOrNull(rate) && !$A.util.isUndefinedOrNull(brokerageVaue)){117 118 var payment = PMT(rate / 12, parseInt(nperiod), -(parseFloat(amount) + parseFloat(brokerageVaue)), balloon, 1);119 var payment2 = PMT(rate / 52, (parseInt(nperiod)/12)*52, -(parseFloat(amount) + parseFloat(brokerageVaue)), balloon, 1);120 function PMT(rate, nperiod, pv, fv, type) { 121 if (!fv) fv = 0;122 if (!type) type = 0;123 if (rate == 0) return -(pv + fv) / nperiod;124 let pvif = Math.pow(1 + rate, nperiod);125 let pmt = rate / (pvif - 1) * -(pv * pvif + fv);126 if (type == 1) {127 pmt /= (1 + rate);128 }129 return pmt;130 }131 console.log('payment>>>>>>>'+payment);132 console.log('payment2>>>>>>'+payment2);133 c.set("v.calc.VEN3__Repayment_Expected_c__c", payment);134 c.set("v.calc.VEN3__Repayment_Expected_Weekly__c", payment2);135 } else {136 c.set("v.calc.VEN3__Repayment_Expected_c__c", undefined);137 c.set("v.calc.VEN3__Repayment_Expected_Weekly__c", undefined);138 }139 }140 } else if (calcData > 9999999999) {141 if (c.get('v.isVendor') !== false) {142 c.set("v.errorText", 'Amount Financed is greater than $9,999,999,999. Please contact Chase Finance to obtain pricing.');143 h.showErrorToast(c, e, h);144 }else {145 c.set("v.errorText", 'Amount Financed is greater than $9,999,999,999. ');146 h.showErrorToast(c, e, h);147 }148 c.set("v.calc.VEN3__Repayment_Expected_c__c", undefined);149 c.set("v.calc.VEN3__Repayment_Expected_Weekly__c", undefined);150 } else {151 c.set("v.calc.VEN3__Repayment_Expected_c__c", undefined);152 c.set("v.calc.VEN3__Repayment_Expected_Weekly__c", undefined);153 c.find('mortgageAmount').set("v.errors", null);154 }155 }else{156 c.set("v.calc.VEN3__Repayment_Expected_c__c", undefined);157 c.set("v.calc.VEN3__Repayment_Expected_Weekly__c", undefined);158 }159 160 } catch (ex) {161 console.log('Error --->>' + ex.message);162 }163 },164 calculateAmountFinance_Helper : function (c, e, h) {165 try{166 return new Promise(resolve => {167 let FinanceAmount = c.get("v.calc.VEN3__Amount_Financed__c");168 let balloonVal = c.get("v.selectedBalloons");169 let AssetType = c.get("v.calc.VEN3__Asset_Type__c");170 let Term = c.get("v.calc.VEN3__Term_months__c");171 let ProgramPartnerId = c.get("v.matrixUser.VEN3__Program_Partner__c");172 if(balloonVal != null){173 balloonVal = parseInt(balloonVal);174 }175 176 let GoodTypes = c.get("v.calc.VEN3__Goods_Type__c");177 GoodTypes = GoodTypes.trim();178 if(!$A.util.isUndefinedOrNull(FinanceAmount) && !$A.util.isUndefinedOrNull(AssetType) && !$A.util.isUndefinedOrNull(Term) && !$A.util.isUndefinedOrNull(GoodTypes) && Term !== ''){179 var action = c.get("c.getCustomSettings_Apex");180 action.setParams({181 "AssetType" : AssetType,182 "Term" : Term,183 "facilityType" : 'Chattel Mortgage',184 "ProgramPartner" : ProgramPartnerId,185 "goodTypes" : GoodTypes186 });187 action.setCallback(this, function (r) {188 if (r.getState() === 'SUCCESS') {189 let storedResponse = r.getReturnValue();190 let Percentage = 0;191 let Amount = 0;192 if (!$A.util.isUndefinedOrNull(storedResponse)) {193 if(FinanceAmount >= 5000 && FinanceAmount <= 50000){194 if(balloonVal == 0){195 Percentage = storedResponse.VEN3__X5Kto50K_Balloon_0__c;196 }197 if(balloonVal == 10){198 Percentage = storedResponse.VEN3__X5Kto50K_Balloon_10__c;199 }200 if(balloonVal == 20){201 Percentage = storedResponse.VEN3__X5Kto50K_Balloon_20__c;202 }203 if(balloonVal == 30){204 Percentage = storedResponse.VEN3__X5Kto50K_Balloon_30__c;205 }206 if(balloonVal == 40){207 Percentage = storedResponse.VEN3__X5Kto50K_Balloon_40__c;208 }209 if(balloonVal == 50){210 Percentage = storedResponse.VEN3__X5Kto50K_Balloon_50__c;211 }212 }else if(FinanceAmount >= 50001 && FinanceAmount <= 100000){213 if(balloonVal == 0){214 Percentage = storedResponse.VEN3__X50Kto100K_Balloon_0__c;215 }216 if(balloonVal == 10){217 Percentage = storedResponse.VEN3__X50Kto100K_Balloon_10__c;218 }219 if(balloonVal == 20){220 Percentage = storedResponse.VEN3__X50Kto100K_Balloon20__c;221 }222 if(balloonVal == 30){223 Percentage = storedResponse.VEN3__X50Kto100K_Balloon_30__c;224 }225 if(balloonVal == 40){226 Percentage = storedResponse.VEN3__X50Kto100K_Balloon_40__c;227 }228 if(balloonVal == 50){229 Percentage = storedResponse.VEN3__X50Kto100K_Balloon_50__c;230 }231 }else if(FinanceAmount >= 100001 && FinanceAmount <= 150000){232 if(balloonVal == 0){233 Percentage = storedResponse.VEN3__X100Kto150K_Balloon_0__c;234 }235 if(balloonVal == 10){236 Percentage = storedResponse.VEN3__X100Kto150K_Balloon_10__c;237 }238 if(balloonVal == 20){239 Percentage = storedResponse.VEN3__X100Kto150K_Balloon_20__c;240 }241 if(balloonVal == 30){242 Percentage = storedResponse.VEN3__X100Kto150K_Balloon_30__c;243 }244 if(balloonVal == 40){245 Percentage = storedResponse.VEN3__X100Kto150K_Balloon_40__c;246 }247 if(balloonVal == 50){248 Percentage = storedResponse.VEN3__X100Kto150K_Balloon_50__c;249 }250 }else if(FinanceAmount >= 150001 && FinanceAmount <= 250000){251 if(balloonVal == 0){252 Percentage = storedResponse.VEN3__X150Kto250K_Balloon_0__c;253 }254 if(balloonVal == 10){255 Percentage = storedResponse.VEN3__X150Kto250K_Balloon_10__c;256 }257 if(balloonVal == 20){258 Percentage = storedResponse.VEN3__X150Kto250_Balloon_20__c;259 }260 if(balloonVal == 30){261 Percentage = storedResponse.VEN3__X150Kto250_Balloon_30__c;262 }263 if(balloonVal == 40){264 Percentage = storedResponse.VEN3__X150Kto250_Balloon_40__c;265 }266 if(balloonVal == 50){267 Percentage = storedResponse.VEN3__X150Kto250_Balloon_50__c;268 }269 }else if(FinanceAmount >= 250001 && FinanceAmount <= 500000){270 if(balloonVal == 0){271 Percentage = storedResponse.VEN3__X250Kto500K_Balloon_0__c;272 }273 if(balloonVal == 10){274 Percentage = storedResponse.VEN3__X250Kto500K_Balloon_10__c;275 }276 if(balloonVal == 20){277 Percentage = storedResponse.VEN3__X250Kto500K_Balloon_20__c;278 }279 if(balloonVal == 30){280 Percentage = storedResponse.VEN3__X250Kto500K_Balloon_30__c;281 }282 if(balloonVal == 40){283 Percentage = storedResponse.VEN3__X250Kto500K_Balloon_40__c;284 }285 if(balloonVal == 50){286 Percentage = storedResponse.VEN3__X250Kto500K_Balloon_50__c;287 }288 }else if(FinanceAmount >= 500001 && FinanceAmount <= 999999){289 if(balloonVal == 0){290 Percentage = storedResponse.VEN3__X500Kto999K_Balloon_0__c;291 }292 if(balloonVal == 10){293 Percentage = storedResponse.VEN3__X500Kto999K_Balloon_10__c;294 }295 if(balloonVal == 20){296 Percentage = storedResponse.VEN3__X500Kto999K_Balloon_20__c;297 }298 if(balloonVal == 30){299 Percentage = storedResponse.VEN3__X500Kto999K_Balloon_30__c;300 }301 if(balloonVal == 40){302 Percentage = storedResponse.VEN3__X500Kto999K_Balloon_40__c;303 }304 if(balloonVal == 50){305 Percentage = storedResponse.VEN3__X500Kto999K_Balloon_50__c;306 }307 }else if(FinanceAmount >= 1000000 && FinanceAmount <= 9999999999){308 if(balloonVal == 0){309 Percentage = storedResponse.VEN3__X1000LKAbove_Balloon_0__c;310 }311 if(balloonVal == 10){312 Percentage = storedResponse.VEN3__X1000KAbove_Balloon_10__c;313 }314 if(balloonVal == 20){315 Percentage = storedResponse.VEN3__X1000KAbove_Balloon_20__c;316 }317 if(balloonVal == 30){318 Percentage = storedResponse.VEN3__X1000KAbove_Balloon_30__c;319 }320 if(balloonVal == 40){321 Percentage = storedResponse.VEN3__X1000KAbove_Balloon_40__c;322 }323 if(balloonVal == 50){324 Percentage = storedResponse.VEN3__X1000KAbove_Balloon_50__c;325 }326 }else{327 c.set("v.AmountFinance", FinanceAmount);328 }329 c.set("v.settingsByPartner", storedResponse);330 if(!$A.util.isUndefinedOrNull(Percentage)){331 c.set('v.percentage', Percentage);332 if(balloonVal != 0){333 Amount = (FinanceAmount*balloonVal)/100;334 }335 c.set("v.AmountFinance", FinanceAmount);336 c.set("v.calc.VEN3__Ballon__c", Amount);337 resolve(FinanceAmount);338 }339 else{340 c.set('v.percentage', 0);341 if(balloonVal != 0){342 Amount = (FinanceAmount*balloonVal)/100;343 }344 c.set("v.AmountFinance", FinanceAmount);345 c.set("v.calc.VEN3__Ballon__c", Amount);346 resolve(FinanceAmount);347 }348 }else {349 350 c.set("v.settingsByPartner", undefined);351 resolve(FinanceAmount);352 }353 } else {354 console.log('ERROR');355 console.log(r.getError());356 }357 });358 $A.enqueueAction(action);359 }else{360 c.set("v.settingsByPartner", undefined);361 }362 });363 }catch(ex){364 console.log('Error',ex.message);365 }366 },367 setGoodsType_Helper: function (c, e, h) {368 try {369 let selectedProgramPartnerId = c.get("v.matrixUser.VEN3__Program_Partner__c");370 if (!$A.util.isUndefinedOrNull(selectedProgramPartnerId)) {371 let action = c.get("c.getGoodsType_Apex");372 action.setParams({373 "selectedProgramPartnerId": selectedProgramPartnerId374 });375 action.setCallback(this, function (r) {376 if (r.getState() === 'SUCCESS') {377 let storedResponse = r.getReturnValue();378 if (!$A.util.isUndefinedOrNull(storedResponse)) {379 let tempGoodsType = storedResponse.VEN3__Goods_Type__c;380 let goodsType = tempGoodsType.split(",");381 c.set("v.calc.VEN3__Goods_Type__c",goodsType[0]);382 c.set("v.getGoodsTypeList", goodsType);383 }384 } else {385 console.log('ERROR');386 console.log(r.getError());387 }388 });389 $A.enqueueAction(action);390 } else if ($A.util.isUndefinedOrNull(selectedProgramPartnerId)) {391 let goodsType = [];392 goodsType = [393 "Coffee Machines",394 "Equipment - Office",395 "IT Equipment",396 "Motor Vehicle",397 "Point of Sale",398 "Printing Equipment",399 "Radios",400 "Security Equipment",401 "Telecommunications",402 "Agricultural",403 "Air Conditioning Systems",404 "Arcade Machines",405 "Artwork",406 "ATMâs",407 "Audio Visual",408 "Baling Equipment",409 "Caravan / Camper",410 "Catering Equipment",411 "Cleaning Supplies",412 "Digital Displays",413 "Dog Wash Units",414 "Earth Moving",415 "Energy Assets / Solar",416 "Fitness Equipment",417 "Fitouts",418 "Forklifts",419 "Fuel Management Systems",420 "Furniture & Fittings",421 "Gaming / Poker Machines",422 "Golf Simulators",423 "GPS Tracking",424 "Heaters",425 "Helicopter",426 "Industrial Equipment",427 "Intangibles",428 "Laboratory Equipment",429 "Lighting",430 "Logging",431 "Marine",432 "Materials Handling",433 "Medical Equipment",434 "Motor Cycle",435 "Office Equipment",436 "Plane",437 "Portable Building",438 "Racking",439 "Recreation Equipment",440 "Refrigeration Systems",441 "Road Marking",442 "Roasting Equipment",443 "Safes",444 "Software",445 "Tanning Beds",446 "Trailer",447 "Vending Machines",448 "Visual Sign-in Kiosk",449 "Water Filtration Systems",450 "Yellow Goods",451 "Yellow Goods",452 "Other",453 ];454 c.set("v.getGoodsTypeList", goodsType);455 c.set("v.calc.VEN3__Goods_Type__c",goodsType[0]);456 }457 c.set("v.calc.VEN3__Goods_Type__c", 'None');458 } catch (err) {459 console.log('Error',err.message);460 console.log('setGoodsType_Helper======>' + err);461 }462 },463 SaveCustomSettings_Helper: function (c, e, h, isCopy) {464 try {465 console.log('SaveCustomSettings_Helper::')466 let valid = h.checkSaveValidity(c, e, h);467 if (valid === true) {468 if (c.get("v.isMatrixGuestUser")) {469 let matrixUser = c.get("v.matrixUser");470 if (!$A.util.isUndefinedOrNull(matrixUser.VEN3__Program_Partner__c)) {471 c.set("v.calc.VEN3__Program_Partner__c", matrixUser.VEN3__Program_Partner__c);472 }473 }474 let anzCalc = {};475 let leadObj = {};476 anzCalc = c.get("v.calc");477 leadObj = c.get('v.leadObj');478 anzCalc.VEN3__Program_Partner_L__c = c.get("v.matrixUser.VEN3__Program_Partner__c");479 anzCalc.VEN3__Vendor_Guest_User__c = c.get("v.matrixUser.Id");480 anzCalc.VEN3__Loan_Facility_Type__c = 'Chattel Mortgage'; 481 leadObj.Company = leadObj.FirstName+' '+leadObj.LastName;482 leadObj.VEN3__Vendor_Guest_User__c = c.get('v.matrixUser.Id');483 if (!$A.util.isUndefinedOrNull(leadObj.FirstName) && !$A.util.isUndefinedOrNull(leadObj.LastName) && !$A.util.isUndefinedOrNull(leadObj.Email) && !$A.util.isUndefinedOrNull(anzCalc.VEN3__Amount_Financed__c) && !$A.util.isUndefinedOrNull(anzCalc.VEN3__Term_months__c)) {484 h.showSpinner_Helper(c, e, h);485 let action = c.get("c.saveANZData_Apex");486 action.setParams({487 "anzList": JSON.stringify(anzCalc),488 "leadObj": JSON.stringify(leadObj),489 "version": c.get('v.calculatorType'),490 });491 action.setCallback(this, function (response) {492 if (response.getState() === "SUCCESS") {493 494 let storedResponse = (response.getReturnValue());495 console.log('storedResponse>>>>'+storedResponse);496 if (!$A.util.isUndefinedOrNull(storedResponse)) {497 c.set('v.successText', 'Record Saved Successfully!');498 h.showSuccessToast(c, e, h);499 }500 } else {501 c.set("v.errorText", 'something misshappens with data');502 h.showErrorToast(c, e, h);503 }504 });505 $A.enqueueAction(action);506 } else {507 c.set("v.errorText", 'Please fill the required fields');508 h.showErrorToast(c, e, h);509 }510 } else {511 c.set("v.errorText", 'Please fill the required fields');512 h.showErrorToast(c, e, h);513 }514 } catch (ex) {515 console.log('Error --->>' + ex.message);516 }517 h.hideSpinner_Helper(c, e, h);518 },519 showErrorToast: function (c, e, h) {520 try {521 c.set('v.isError',true);522 window.setTimeout(523 $A.getCallback(function () {524 c.set('v.isError',false);525 }), 1000526 );527 } catch (ex) {528 console.log('Error == >>' + e);529 }530 },531 showSuccessToast: function (c, e, h) {532 try {533 c.set('v.isSuccess',true);534 //$('#SuccessToast').show();535 window.setTimeout(536 $A.getCallback(function () {537 c.set('v.isSuccess',false);538 }), 1000539 );540 } catch (ex) {541 console.log('Error == >>' + e);542 }543 },544 ClearData_Helper: function (c, e, h) {545 c.set("v.ClearDataPopup", true);546 },547 resetData_Helper: function (c, e, h) {548 h.setGoodsType_Helper(c, e, h);549 c.set('v.selectedBalloons', null);550 c.set("v.calc.VEN3__Repayment_Expected_Weekly__c", null);551 let calcData = {};552 calcData.Name = null;553 calcData.VEN3__Amount_Financed__c = null;554 calcData.VEN3__Ballon__c = null;555 calcData.VEN3__Balloon_c__c = null;556 calcData.VEN3__Customer_Rate_Expected__c = null;557 calcData.VEN3__Customer_Rate_Non_Published__c = null;558 calcData.VEN3__Desired_Brokerage_Incl_GST_c__c = null;559 calcData.VEN3__Desired_Brokerage_Incl_GST_p__c = null;560 //calcData.VEN3__Goods_Type__c = null;561 calcData.VEN3__Incl_GST_c__c = null;562 calcData.VEN3__Loan_Facility_Type__c = null;563 calcData.VEN3__Please_enter_your_desired_Base_Rate_here__c = null;564 calcData.VEN3__Published_Base_Rate__c = null;565 calcData.VEN3__Repayment_Expected_c__c = null;566 calcData.VEN3__Repayment_Non_Published__c = null;567 calcData.VEN3__Repayment_Frequency__c = null;568 calcData.VEN3__Repayment_Type__c = null;569 calcData.VEN3__State__c = null;570 calcData.VEN3__Term_months__c = undefined;571 calcData.VEN3__Total_Incl_GST_c__c = null;572 calcData.VEN3__Document_Fee_Disclosed__c = null;573 calcData.VEN3__Document_Fee_Non_Disclosed__c = null;574 calcData.VEN3__Fees_Other_Disclosed__c = null;575 calcData.VEN3__Fees_Other_Non_Disclosed__c = null;576 calcData.VEN3__PPSR_Fees_Disclosed__c = null;577 calcData.VEN3__PPSR_Fees_Non_Disclosed__c = null;578 calcData.VEN3__Additional_Payment__c = null;579 calcData.VEN3__Additional_period__c = null;580 calcData.VEN3__Asset_Type__c = 'New';581 calcData.VEN3__Repayment_Frequency__c = 'Monthly';582 calcData.VEN3__Repayment_Type__c = 'Advance';583 584 c.set("v.calc", calcData);585 c.set("v.ClearDataPopup", false);586 let leadObj = {};587 leadObj.VEN3__Date__c = null;588 leadObj.FirstName = null;589 leadObj.LastName = null;590 leadObj.Company = null;591 leadObj.Email = null;592 leadObj.Phone = null;593 leadObj.OwnerId = c.get('v.leadObj.OwnerId');594 if (!$A.util.isUndefinedOrNull(c.get('v.matrixUser.Id'))) {595 leadObj.VEN3__Vendor_Guest_User__c = c.get('v.matrixUser.Id');596 }597 c.set("v.leadObj", leadObj);598 h.hideSpinner_Helper(c, e, h);599 },600 hideSpinner_Helper: function (c, e, h) {601 c.set("v.showSpinner", false);602 },603 checkSaveValidity: function (c, e, h) {604 try {605 if (!c.get('v.isView')) {606 let allFields = c.find('checkSaveValidity');607 let allValid = false;608 if (Array.isArray(allFields)) {609 allValid = allFields.reduce(function (validSoFar, inputCmp) {610 inputCmp.showHelpMessageIfInvalid();611 return validSoFar && inputCmp.get('v.validity').valid;612 }, true);613 } else {614 allFields.showHelpMessageIfInvalid();615 allValid = allFields.get('v.validity').valid;616 }617 return allValid;618 } else {619 return true;620 }621 } catch (ex) {622 console.log('Error -->>' + e);623 }624 },625 showSpinner_Helper: function (c, e, h) {626 c.set("v.showSpinner", true);627 window.setTimeout(628 $A.getCallback(function () {629 c.set("v.showSpinner", false);630 }), 10000631 );632 },633 ViewLead_helper: function (c, e, h) {634 try {635 c.set('v.showSpinner', true);636 var recordId = c.get('v.selectedId');637 if(!$A.util.isUndefinedOrNull(recordId)){638 var action = c.get('c.getExistingRecord');639 action.setParams({640 "selectedId" : recordId641 });642 action.setCallback(this, function (r) {643 if (r.getState() === 'SUCCESS') {644 let storedResponse = r.getReturnValue();645 //console.log('storedResponse'+JSON.stringify(storedResponse));646 if(!$A.util.isUndefinedOrNull(storedResponse)){647 c.set('v.leadViewDetails',storedResponse.leadList);648 c.set('v.calViewDetails',storedResponse.calcList);649 c.set('v.showSpinner', false);650 var Balloon = storedResponse.calcList.VEN3__Ballon__c;651 if(!$A.util.isUndefinedOrNull(storedResponse)){652 Balloon = Balloon/100;653 c.set('v.calViewDetails.VEN3__Ballon__c', Balloon);654 }else{655 c.set('v.calViewDetails.VEN3__Ballon__c', '');656 } 657 658 }else{659 h.hideSpinner_Helper(c, e, h);660 console.log('Somthing Wrong with your data');661 }662 } else {663 h.hideSpinner_Helper(c, e, h);664 console.log('ERROR');665 console.log(r.getError());666 }667 });668 $A.enqueueAction(action);669 }670 }catch (e) {671 h.hideSpinner_Helper(c, e, h);672 console.log('Error',e.message);673 }674 },...
mock_xmlhttprequest.js
Source:mock_xmlhttprequest.js
1'use strict';2(function() {3 var lastInstance;4 // To avoid race conditions between defining the XHR and sending the data5 var storedResponse;6 function MockXMLHttpRequest() {7 lastInstance = this;8 }9 var throwAtNextSend = false,10 objectToThrow = null;11 function mxhr_mThrowAtNextSend(e) {12 throwAtNextSend = true;13 objectToThrow = e || new Error('throwing an exception');14 }15 function mxhr_mTeardown() {16 throwAtNextSend = false;17 objectToThrow = null;18 delete MockXMLHttpRequest.mLastOpenedUrl;19 lastInstance = null;20 storedResponse = undefined;21 }22 function mxhr_send() {23 if (throwAtNextSend) {24 throwAtNextSend = false;25 throw objectToThrow;26 }27 if (storedResponse) {28 mxhr_mOnLoad(storedResponse);29 }30 }31 function mxhr_open(method, url, opts) {32 MockXMLHttpRequest.mLastOpenedUrl = url;33 }34 function mxhr_mSendError() {35 lastInstance && lastInstance.onerror && lastInstance.onerror();36 }37 function mxhr_mOnLoad(states) {38 storedResponse = {};39 storedResponse.status = 200;40 for (var keyS in states) {41 storedResponse[keyS] = states[keyS];42 }43 if (lastInstance) {44 lastInstance.status = 200;45 for (var keySR in storedResponse) {46 lastInstance[keySR] = storedResponse[keySR];47 }48 lastInstance.onload && lastInstance.onload();49 storedResponse = undefined;50 }51 }52 function mxhr_mSendReadyState(states) {53 if (lastInstance) {54 lastInstance.readyState = XMLHttpRequest.DONE;55 lastInstance.status = 200;56 for (var key in states) {57 lastInstance[key] = states[key];58 }59 lastInstance.onreadystatechange && lastInstance.onreadystatechange();60 }61 }62 MockXMLHttpRequest.prototype = {63 open: mxhr_open,64 send: mxhr_send,65 DONE: XMLHttpRequest.prototype.DONE,66 overrideMimeType: function() {}67 };68 MockXMLHttpRequest.mThrowAtNextSend = mxhr_mThrowAtNextSend;69 MockXMLHttpRequest.mTeardown = mxhr_mTeardown;70 MockXMLHttpRequest.mSendError = mxhr_mSendError;71 MockXMLHttpRequest.mSendOnLoad = mxhr_mOnLoad;72 MockXMLHttpRequest.mSendReadyState = mxhr_mSendReadyState;73 MockXMLHttpRequest.DONE = XMLHttpRequest.DONE;74 window.MockXMLHttpRequest = MockXMLHttpRequest;...
Using AI Code Generation
1var wpt = require('webpagetest');2var webpagetest = new wpt('API_KEY');3webpagetest.getTestStatus('TEST_ID', function(err, data) {4 if (data.statusCode == 200) {5 webpagetest.getTestResults('TEST_ID', function(err, data) {6 console.log(data);7 });8 } else {9 console.log(data);10 }11});
Using AI Code Generation
1var wpt = require('webpagetest');2var api = new wpt('www.webpagetest.org');3var testId = "150210_6J_2Q";4api.getTestResults(testId, function(err, data) {5 if (err) throw err;6 console.log(data);7});8{ responseText: '{"statusCode":400,"statusText":"Bad Request","data":{"error":{"code":400,"message":"Invalid test ID"}}}',9 statusText: 'Bad Request' }
Using AI Code Generation
1var WebPageTest = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org', 'A.8baf4f4b4c4b4a3f8e3a3a9a3a9a3a9a');3wpt.getTestResults('150501_J7_1K', function(err, data) {4 if(err) {5 console.log(err);6 } else {7 console.log(data);8 }9});
Using AI Code Generation
1var wpt = require('webpagetest');2var webpagetest = new wpt('A.3B1A3B8B0A3B8B0A3B8B0A3B8B0A3B8B');3var testId = '150518_8Y_2b2a1e0a9c5d6b5c6b5a6f5a6c5b6a5';4webpagetest.getTestResults(testId, function(err, data) {5 if (err) {6 console.log(err);7 } else {8 }9});10webpagetest.getTestResults(testId, function(err, data) {11 if (
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!