const Charge = function() { this.label = ""; this.rate = 0.0; this.getValue = function(salaireBrut) { return (this.rate / 100) * salaireBrut; } }; const ConstantsParser = function () { const that = this; this.constants = JSON.parse('[{"scope":"GENERAL","name":"SMIC","value":1539.45},{"scope":"GENERAL","name":"dureeLegale","value":35},{"scope":"GENERAL","name":"ratioheuresMensuelles","value":4.33},{"scope":"GENERAL","name":"tauxHeuresSupp","value":1.25},{"scope":"GENERAL","name":"tauxHoraireMin","value":10.1581},{"scope":"GENERAL","name":"coeffFillonMax","value":0.3214},{"scope":"CHARGES PATRONALES","name":"Maladie_p","value":7},{"scope":"CHARGES PATRONALES","name":"Viellesse_p","value":8.55},{"scope":"CHARGES PATRONALES","name":"Viellesse2_p","value":1.9},{"scope":"CHARGES PATRONALES","name":"SolAut_p","value":0.3},{"scope":"CHARGES PATRONALES","name":"Chomage_p","value":4.05},{"scope":"CHARGES PATRONALES","name":"AGFF_p","value":1.2},{"scope":"CHARGES PATRONALES","name":"Retraite_p","value":4.72},{"scope":"CHARGES PATRONALES","name":"Medecine_p","value":0.42},{"scope":"CHARGES PATRONALES","name":"Logement_p","value":0.1},{"scope":"CHARGES PATRONALES","name":"AGS_p","value":0.15},{"scope":"CHARGES PATRONALES","name":"Formation_p","value":0.55},{"scope":"CHARGES PATRONALES","name":"Accident_p","value":3},{"scope":"CHARGES PATRONALES","name":"Alloc_p","value":5.25},{"scope":"CHARGES PATRONALES","name":"CADS","value":0.016},{"scope":"CHARGES PATRONALES","name":"CEG","value":1.29},{"scope":"CHARGES SALARIALES","name":"Maladie_s","value":0},{"scope":"CHARGES SALARIALES","name":"Viellesse_s","value":6.9},{"scope":"CHARGES SALARIALES","name":"Viellesse2_s","value":0.1},{"scope":"CHARGES SALARIALES","name":"Chomage_s","value":0},{"scope":"CHARGES SALARIALES","name":"AGFF_s","value":0},{"scope":"CHARGES SALARIALES","name":"Retraite_s","value":3.15},{"scope":"CHARGES SALARIALES","name":"CSG_s","value":5.01228},{"scope":"CHARGES SALARIALES","name":"CRDS-CSG_s","value":2.84925}]'); this.getVarByName = function (name) { let constant = null; for (let i in that.constants) { const _constant = that.constants[i]; if (_constant.name === name) { constant = _constant; } } return constant; }; this.getVarsByScope = function (scope) { let constants = []; for (let i in that.constants) { const _constant = that.constants[i]; if (_constant.scope === scope) { constants.push(_constant); } } return constants; } this.chargesP = function() { return this.dataToCharges(this.getVarsByScope("CHARGES PATRONALES")); }; this.chargesS = function() { return this.dataToCharges(this.getVarsByScope("CHARGES SALARIALES")); }; this.dataToCharges = function (data) { const charges = []; for (let i in data) { const charge = new Charge(); charge.label = data[i].name; charge.rate = data[i].value; charges.push(charge) } return charges; } }; const constantParser = new ConstantsParser(); const SMIC = constantParser.getVarByName("SMIC").value; const dureeLegale = constantParser.getVarByName("dureeLegale").value; const ratioHeuresMensuelles = constantParser.getVarByName("ratioheuresMensuelles").value; const tauxHoraireMin = constantParser.getVarByName("tauxHoraireMin").value; const tauxHeuresSupp = constantParser.getVarByName("tauxHeuresSupp").value; const coeffFillonMax = constantParser.getVarByName("coeffFillonMax").value; const chargesP = constantParser.chargesP(); const chargesS = constantParser.chargesS(); const Calculator = function() { this.salaireBrut = 0; this.heuresS = 0; this.nbMois = 0; this.salaireNet = function() { return this.salaireBrut - this.valueChargesS(); }; this.coutMensuel = function() { return this.salaireBrut + this.valueChargesP(); }; this.coutAnnuel = function() { return this.coutMensuel() * this.nbMois; }; this.valueChargesPTot = function() { let value = 0; for(let i in chargesP) { value += chargesP[i].getValue(this.salaireBrut); } return value; }; this.valueChargesS = function() { let value = 0; for(let i in chargesS) { value += chargesS[i].getValue(this.salaireBrut); } return value; }; this.valueChargesP = function() { return this.valueChargesPTot() - this.reductionFillon(); }; this.reductionFillon = function() { return this.coeffFillon() * this.salaireBrut; }; this.coeffFillon = function() { const coeff = (coeffFillonMax / 0.6) * (1.6 * ((SMIC * this.nbMois) / (this.salaireBrut * this.nbMois)) - 1); if (coeff > coeffFillonMax) { return coeffFillonMax; } if (coeff < 0) { return 0; } return coeff; }; this.salaireBaseMin = function() { return this.heuresBase() * ratioHeuresMensuelles * tauxHoraireMin; }; this.salaireSupMin = function() { return this.heuresSup() * ratioHeuresMensuelles * tauxHoraireMin * tauxHeuresSupp; }; this.salaireBrutMin = function() { return this.salaireBaseMin() + this.salaireSupMin(); }; this.heuresSup = function() { return this.heuresS - this.heuresBase() ; }; this.heuresBase = function() { if (this.heuresS <= dureeLegale) { return this.heuresS; } return dureeLegale; }; this.checkSalaireBrut = function() { if (this.salaireBrutMin() > this.salaireBrut) { this.salaireBrut = this.salaireBrutMin(); } return this.salaireBrut; }; }; const calculator = new Calculator(); const HTMLBridge = function () { const that = this; this.$salaireM = $('#salaireM'); this.$heuresS = $('#HeuresS'); this.$nbMois = $('#nbMois'); this.$salaireNet = $('#SalaireNet'); this.$coutAnnuel = $('#CoutAnnuel'); this.updateInProgress = false; this.init = function () { this.$salaireM.val(SMIC); this.$heuresS.val(dureeLegale); this.$nbMois.val(12); this.$salaireM.change(function() {that.update()}); this.$heuresS.change(function() {that.update()}); this.$nbMois.change(function() {that.update()}); this.$salaireNet.attr('readonly', true); this.$coutAnnuel.attr('readonly', true); this.update(); }; this.update = function() { if (this.updateInProgress) { return; } this.updateInProgress = true; calculator.salaireBrut = Number(this.$salaireM.val()); calculator.heuresS = Number(this.$heuresS.val()); calculator.nbMois = Number(this.$nbMois.val()); calculator.checkSalaireBrut(); this.$salaireM.val(this.round(calculator.salaireBrut).toString()); this.$salaireNet.val(Math.round(calculator.salaireNet()).toString()); this.$coutAnnuel.val(Math.round(calculator.coutAnnuel()).toString()); this.updateInProgress = false; }; this.round = function(number) { return (Math.round(number * 100) / 100); }; }; let htmlBridge = null; $(document).ready(function() { htmlBridge = new HTMLBridge(); htmlBridge.init(); });