1 2/** 3 * Initialise une instance du simulateur dans un overlay donné. 4 * - Isole les groupes radio en renommant les name= par instance 5 * - Force un "Fixe" par défaut si aucun radio n'est coché 6 * - Initialise l'affichage du taux (#valBox) et de la barre (#filledTracktaux) 7 * - Recalcule les mensualités et le RAV 8 */ 9function initSimulator(rootOverlay) { 10 var $scope = $(rootOverlay); 11 var instance = $scope.attr("data-instance") || (Math.random().toString(36).slice(2)); 12 13 // --- Helpers (scopés) --- 14 function $id(id) { return $scope.find("#" + id); } 15 function numFrom(id) { 16 var s = ($id(id).val() || "0").toString().replace(",", "."); 17 var n = parseFloat(s); 18 return isNaN(n) ? 0 : n; 19 } 20 function setIfEmpty(id, val) { 21 var $el = $id(id); 22 if (!$el.val()) $el.val(val); 23 } 24 25 // --- Isoler les groupes radio par "name" pour éviter les interférences entre overlays --- 26 function isolateRadioGroup(name) { 27 $scope.find('input[type="radio"][name="' + name + '"]').each(function () { 28 $(this).attr("name", name + "__" + instance); 29 }); 30 } 31 ["rateType", "nombreTitulaires", "clientStatus", "ProjetStatus"].forEach(isolateRadioGroup); 32 33 // --- Définir un taux par défaut et un radio par défaut --- 34 setIfEmpty("interestRate", 3.8); 35 setIfEmpty("amount", 100000); 36 setIfEmpty("apportPersonnel", 10000); 37 setIfEmpty("RAV", 1700); 38 39 var $rateFixe = $scope.find('input[type="radio"]#fixe'); 40 var $rateVar = $scope.find('input[type="radio"]#variable'); 41 var $rateAny = $rateFixe.add($rateVar); 42 if (!$rateAny.is(":checked")) { 43 // Si aucun n'est coché (cas observé dans "simple"), on force Fixe 44 $rateFixe.prop("checked", true); 45 } 46 47 // --- Ecouteurs --- 48 // Changement de type de taux 49 $scope.on("change", 'input[type="radio"]#fixe, input[type="radio"]#variable', function () { 50 var type = $(this).val(); // "fixe" | "variable" 51 var rate = type === "fixe" ? 3.8 : 3.8; // Ajuste ici si besoin (ex: variable = 3.5) 52 $id("interestRate").val(rate).trigger("input"); 53 }); 54 55 // Curseur de taux 56 $id("interestRate").on("input", function () { 57 updateRateUI($scope); 58 updateCalculations($scope); 59 }); 60 61 // Champs déclenchant un recalcul 62 $id("amount, #duration, #apportPersonnel").on("input", function () { 63 updateCalculations($scope); 64 }); 65 66 // Déjà client â agence visible/masquée (si présent sur la page) 67 var clientRadioName = $scope.find('input#clientOui[type="radio"]').attr("name"); 68 if (clientRadioName) { 69 $scope.on("change", 'input[name="' + clientRadioName + '"]', function () { 70 var $box = $id("clientOptionsContainer"); 71 if (!$box.length) return; 72 if ($(this).val() === "oui") $box.show(); 73 else $box.hide(); 74 }); 75 } 76 77 // Recalcul initial & init UI 78 updateRateUI($scope); 79 updateCalculations($scope); 80} 81 82/** Remplit #valBox avec le taux courant et ajuste la largeur de #filledTracktaux */ 83function updateRateUI($scope) { 84 var rate = parseFloat(($scope.find("#interestRate").val() || "0").toString().replace(",", ".")) || 0; 85 var lang = $('html').attr('lang'); // récupère la langue depuis <html lang="..."> 86var label; 87 88if(lang === 'en' || lang === 'en-US') { 89 label = "Rate applied : "; 90} 91else if(lang === 'de' || lang === 'de-DE') { 92 label = "Angewendeter Zinssatz : "; 93} 94else { 95 label = "Taux d'intérêts : "; 96} 97 98 99 100 101$scope.find("#valBox").text(label + rate + "%"); 102 var pct = (rate / 10) * 98; 103 $scope.find("#filledTracktaux").css("width", pct + "%"); 104} 105 106/** Recalcule mensualité, durée affichée et progression de durée; met à jour le RAV et le message */ 107function updateCalculations($scope) { 108 function numVal(sel) { 109 var v = ($scope.find(sel).val() || "0").toString().replace(",", "."); 110 var n = parseFloat(v); 111 return isNaN(n) ? 0 : n; 112 } 113 114 var montant = numVal("#amount"); 115 var duree = (parseInt($scope.find("#duration").val(), 10) || 0) + 10; 116 var taux = numVal("#interestRate") / 100; 117 var apport = numVal("#apportPersonnel"); 118 119 var capital = Math.max(montant - apport, 0); 120 var nbMois = duree * 12; 121 var tauxMensuel = taux / 12; 122 var mensualite = capital * tauxMensuel / (1- Math.pow(1 + tauxMensuel, -nbMois)); 123 124var lang = $('html').attr('lang'); // récupère la langue depuis <html lang="..."> 125var unit; 126 127if(lang === 'en' || lang === 'en-US') { 128 unit = " years"; 129} else if (lang === 'de' || lang === 'de-DE'){ 130 unit = " Jahre"; 131 132} else { 133 unit = " ans"; 134} 135 136 137 138 $scope.find("#interestAmount").val(mensualite.toFixed(2) + " â¬"); 139$scope.find("#durationValue").text(duree + unit); 140 141 var percent = ((parseInt($scope.find("#duration").val(), 10) || 0) / 25) * 100; 142 $scope.find("#filledTrack").css("width", percent + "%"); 143 144 calculerRAV($scope); 145} 146 147function calculerRAV($scope) { 148 function numVal(sel) { 149 var v = ($scope.find(sel).val() || "0").toString().replace(",", "."); 150 var n = parseFloat(v); 151 return isNaN(n) ? 0 : n; 152 } 153 function numFromText(sel) { 154 var raw = ($scope.find(sel).val() || "0").toString(); 155 raw = raw.replace(/[^\d.,-]/g, "").replace(",", "."); 156 var n = parseFloat(raw); 157 return isNaN(n) ? 0 : n; 158 } 159 160 var revenu = numVal("#RevenuNet") + numVal("#AutreRevenu"); 161 var mensualite = numFromText("#interestAmount"); 162 var depenses = mensualite + numVal("#AutrePret"); 163 164 var rav = revenu - depenses; 165 $scope.find("#RAV").val(rav.toFixed(2)); 166 167 var ravMin = numVal("#RAVmin"); 168 var $msg = $scope.find("#nonrecevable"); 169 if ($msg.length) { 170 if (ravMin && rav < ravMin) $msg.show(); 171 else $msg.hide(); 172 } 173}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.