Quotient Familial - Services
Ancien Code
<script>
"use strict";
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
(function ($) {
var revenuFiscalReferenceR1Input = $('[data-original_id="revenu_fiscal_reference_r1"]');
var revenuFiscalReferenceR2Input = $('[data-original_id="revenu_fiscal_reference_r2"]');
var allocationCAFMensuelInput = $('[data-original_id="allocation_caf"]');
var nbFoyerInput = $('[data-original_id="nb_foyer"]');
var tarifLinearises = {
'price-restauration': {
'<=330': 0.77,
'>330|<=1500': {
a: 0.00331624,
b: -0.324358974
},
'>1500|<=3000': {
a: 0.000686667,
b: 3.62
},
'>3000|<=5000': {
a: 0.000260,
b: 4.90
},
'>5000': 6.20
},
'price-classe-decouverte': {
'<=330': 7.55,
'>330|<=1500': {
a: 0.009589744,
b: 4.385384480
},
'>1500|<=3000': {
a: 0.005360036,
b: 10.729892400
},
'>3000|<=5000': {
a: 0.001345007,
b: 22.774965550
},
'>5000': 29.5
},
'price-etudes-dirigees': {
'<=330': 0.72,
'>330|<=1500': {
a: 0.0007094,
b: 0.485897
},
'>1500|<=3000': {
a: 0.001026667,
b: 0.01
},
'>3000|<=5000': {
a: 0.001035,
b: -0.015
},
'>5000': 5.16
},
'price-accueil-matin': {
'<=330': 0.23,
'>330|<=1500': {
a: 0.000153846,
b: 0.179230820
},
'>1500|<=3000': {
a: 0.000126668,
b: 0.219996733
},
'>3000|<=5000': {
a: 0.000100001,
b: 0.299996000
},
'>5000': 0.8
},
'price-accueil-soir': {
'<=330': 0.36,
'>330|<=1500': {
a: 0.000683761,
b: 0.134358870
},
'>1500|<=3000': {
a: 0.000313335,
b: 0.689994367
},
'>3000|<=5000': {
a: 0,
b: 2.1
},
'>5000': 2.105
},
'price-club-ados': {
'<=330': 0.41,
'>330|<=1500': {
a: 0.000735043,
b: 0.167435810
},
'>1500|<=3000': {
a: 0.000353336,
b: 0.739992467
},
'>3000|<=5000': {
a: 0.000840004,
b: -0.750020500
},
'>5000': 3.5
},
'price-cdl-vacances-mercredi': {
'<=330': 0.91,
'>330|<=1500': {
a: 0.00125641,
b: 0.495384700
},
'>1500|<=3000': {
a: 0.000693338,
b: 1.339986067
},
'>3000|<=5000': {
a: 0.000540003,
b: 1.799985600
},
'>5000': 4.5
},
'price-cdl-ete': {
'<=1050': {
a: 1.06667,
b: -107,
min: 245
},
'>1050': {
a: 0.19333,
b: 810,
max: 1100
}
},
'price-cdl-hiver': {
'<=1050': {
a: 0.54306,
b: -0.79,
min: 180
},
'>1050': {
a: 0.06444,
b: 503.33,
max: 600
}
}
};
function calcul() {
var quotientFamilial = ((parseInt(revenuFiscalReferenceR1Input.val()) + parseInt(revenuFiscalReferenceR2Input.val() ? revenuFiscalReferenceR2Input.val() : 0)) / 12 + parseFloat(allocationCAFMensuelInput.val())) / parseInt(nbFoyerInput.val());
var keys = Object.keys(tarifLinearises);
keys.forEach(function (item) {
var tarifLinearise = tarifLinearises[item];
Object.keys(tarifLinearise).forEach(function (localEval) {
var localSplit = localEval.split('|');
var localValue = undefined;
if (localSplit.length === 2) {
if (eval("".concat(quotientFamilial).concat(localSplit[0])) && eval("".concat(quotientFamilial).concat(localSplit[1]))) {
localValue = tarifLinearise["".concat(localEval)];
}
} else {
if (eval("".concat(quotientFamilial).concat(localSplit[0]))) {
localValue = tarifLinearise["".concat(localEval)];
}
}
if (_typeof(localValue) === "object") {
var tmpValue = localValue.a * quotientFamilial + localValue.b;
if (localValue.min != undefined) tmpValue = Math.max(tmpValue, localValue.min);
if (localValue.max != undefined) tmpValue = Math.min(tmpValue, localValue.max);
localValue = tmpValue;
}
if (typeof localValue === "number") {
$(".".concat(item)).text("".concat(localValue.toFixed(2), " "));
}
});
});
}
$("#quotien_familial_form form p input").on('change', function (e) {
calcul();
});
$("#quotien_familial_form form").on('submit', function (e) {
e.preventDefault();
calcul();
});
$('quotien_familial_form button[type="submit"]').on('click', function (e) {
e.preventDefault();
calcul();
});
})(jQuery);
</script>Nouveau code
<script>
"use strict";
function _typeof(obj) {
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
_typeof = function _typeof(obj) {
return typeof obj;
};
} else {
_typeof = function _typeof(obj) {
return obj && typeof Symbol === "function" && obj.constructor ===
Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
};
}
return _typeof(obj);
}
// Votre script pour effectuer les calculs ici
(function ($) {
var revenuFiscalReferenceR1Input = $('[data-
original_id="revenu_fiscal_reference_r1"]');
var revenuFiscalReferenceR2Input = $('[data-
original_id="revenu_fiscal_reference_r2"]');
var allocationCAFMensuelInput = $('[data-original_id="allocation_caf"]');
var nbFoyerInput = $('[data-original_id="nb_foyer"]');
var tarifLinearises = {
'price-restauration': {
'<=330': 0.77,
'>330|<=1500': {
a: 0.00331624,
b: -0.324358974
},
'>1500|<=3000': {
a: 0.000686667,
b: 3.62
},
'>3000|<=5000': {
a: 0.000260,
b: 4.90
},
'>5000': 6.20
},
'price-classe-decouverte': {
'<=330': 7.55,
'>330|<=1500': {
a: 0.009589744,
b: 4.385384480
},
'>1500|<=3000': {
a: 0.005360036,
b: 10.729892400
},
'>3000|<=5000': {
a: 0.001345007,
b: 22.774965550
},
'>5000': 29.5
},
'price-etudes-dirigees': {
'<=330': 0.72,
'>330|<=1500': {
a: 0.0007094,
b: 0.485897
},
'>1500|<=3000': {
a: 0.001026667,
b: 0.01
},
'>3000|<=5000': {
a: 0.001035,
b: -0.015
},
'>5000': 5.16
},
'price-accueil-matin': {
'<=330': 0.23,
'>330|<=1500': {
a: 0.000153846,
b: 0.179230820
},
'>1500|<=3000': {
a: 0.000126668,
b: 0.219996733
},
'>3000|<=5000': {
a: 0.000100001,
b: 0.299996000
},
'>5000': 0.8
},
'price-accueil-soir': {
'<=330': 0.36,
'>330|<=1500': {
a: 0.000683761,
b: 0.134358870
},
'>1500|<=3000': {
a: 0.000313335,
b: 0.689994367
},
'>3000|<=5000': {
a: 0,
b: 2.1
},
'>5000': 2.105
},
'price-club-ados': {
'<=330': 0.41,
'>330|<=1500': {
a: 0.000735043,
b: 0.167435810
},
'>1500|<=3000': {
a: 0.000353336,
b: 0.739992467
},
'>3000|<=5000': {
a: 0.000840004,
b: -0.750020500
},
'>5000': 3.5
},
'price-cdl-vacances-mercredi': {
'<=330': 0.91,
'>330|<=1500': {
a: 0.00125641,
b: 0.495384700
},
'>1500|<=3000': {
a: 0.000693338,
b: 1.339986067
},
'>3000|<=5000': {
a: 0.000540003,
b: 1.799985600
},
'>5000': 4.5
},
'price-cdl-ete': {
'<=1050': {
a: 1.06667,
b: -107,
min: 245
},
'>1050': {
a: 0.19333,
b: 810,
max: 1100
}
},
'price-cdl-hiver': {
'<=1050': {
a: 0.54306,
b: -0.79,
min: 180
},
'>1050': {
a: 0.06444,
b: 503.33,
max: 600
}
}
};
// Fonction pour mettre à jour le tableau avec les résultats des calculs
function updateTableWithResults() {
var quotientFamilial = ((parseInt(revenuFiscalReferenceR1Input.val()) +
parseInt(revenuFiscalReferenceR2Input.val() ?
revenuFiscalReferenceR2Input.val() : 0)) / 12 +
parseFloat(allocationCAFMensuelInput.val())) / parseInt(nbFoyerInput.val());
var resultTable = $('#result_table');
var keys = Object.keys(tarifLinearises);
keys.forEach(function (item) {
var tarifLinearise = tarifLinearises[item];
Object.keys(tarifLinearise).forEach(function (localEval) {
var localSplit = localEval.split('|');
var localValue = undefined;
if (localSplit.length === 2) {
if (eval("".concat(quotientFamilial).concat(localSplit[0])) &&
eval("".concat(quotientFamilial).concat(localSplit[1]))) {
localValue = tarifLinearise["".concat(localEval)];
}
} else {
if (eval("".concat(quotientFamilial).concat(localSplit[0]))) {
localValue = tarifLinearise["".concat(localEval)];
}
}
if (_typeof(localValue) === "object") {
var tmpValue = localValue.a * quotientFamilial + localValue.b;
if (localValue.min != undefined) tmpValue = Math.max(tmpValue,
localValue.min);
if (localValue.max != undefined) tmpValue = Math.min(tmpValue,
localValue.max);
localValue = tmpValue;
}
if (typeof localValue === "number") {
resultTable.find(".".concat(item)).text("".concat(localValue.toFixed(2)));
}
});
});
}
// Gérer les événements de formulaire pour déclencher les calculs et mettre
à jour le tableau
$("#quotien_familial_form form div input").on('change', function (e) {
e.preventDefault();
updateTableWithResults();
});
$("#quotien_familial_form form").on('submit', function (e) {
e.preventDefault();
updateTableWithResults();
});
$('#quotien_familial_form button[type="submit"]').on('click', function (e) {
e.preventDefault();
updateTableWithResults();
});
// Appel initial pour mettre à jour le tableau avec les résultats initiaux
(valeurs par défaut)
updateTableWithResults();
})(jQuery);Mis à jour