Commit | Line | Data |
---|---|---|
25410b22 OL |
1 | /******************************************************************************* |
2 | * POSTE | |
3 | *******************************************************************************/ | |
4 | ||
01191cd0 | 5 | |
25410b22 OL |
6 | /* Construction dynamique des valeurs de point en fonction de l'implantation choisie */ |
7 | function charger_valeurs_point(implantation_id) { | |
8 | var params = {'implantation_id' : implantation_id}; | |
9 | var chargement_vp = $.getJSON('/dae/liste_valeurs_point', params); | |
10 | chargement_vp.success(function(data) { | |
11 | var items = []; | |
12 | ||
13 | var options = ""; | |
14 | $.each(data, function() { | |
15 | options += '<option value="' + this.id + '">' + this.label + '</option>'; | |
16 | }); | |
17 | ||
18 | $("#id_valeur_point_min").html(options); | |
19 | $("#id_valeur_point_max").html(options); | |
20 | alert("Les valeurs de point on été ajustées en fonction de cette implantation."); | |
21 | }); | |
22 | } | |
23 | ||
24 | /* Calcul des totaux dans les 2 devises, selon les champs sélectionnés. Cette fonction | |
25 | est appelée À chaque modification du formulaire de classement. */ | |
26 | function recalculer_ligne(element) { | |
27 | var ligne = element.parents("tr"); | |
28 | var inputs = ligne.find("input, select"); | |
29 | var salaire_input; | |
30 | var valeur_point_input; | |
31 | inputs.each(function() { | |
32 | var input = $(this); | |
33 | if (input.attr('id').match('id_coefficient*')) { | |
34 | coeff = clean_float(input.val()) | |
35 | } | |
36 | if (input.attr('id').match('id_valeur_point*')) { | |
37 | valeur_point_input = input; | |
38 | } | |
39 | if (input.attr('id').match('id_salaire*')) { | |
40 | salaire_input = input; | |
41 | salaire = clean_float(input.val()) | |
42 | } | |
43 | if (input.attr('id').match('id_indemn*')) { | |
44 | indemn = clean_float(input.val()) | |
45 | } | |
46 | if (input.attr('id').match('id_autre*')) { | |
47 | autre = clean_float(input.val()) | |
48 | } | |
49 | ||
50 | }); | |
51 | ||
52 | /* on suggère un salaire de base en fonction du coefficient et de la valeur du point */ | |
53 | valeur_point_text = valeur_point_input.find(":selected").text(); | |
54 | if (valeur_point_text == "") | |
55 | valeur_point = 0; | |
56 | else | |
57 | valeur_point = clean_float(valeur_point_text.split(" ")[0]); | |
58 | ||
59 | salaire = clean_float(valeur_point * coeff); | |
60 | salaire_input.val(salaire); | |
61 | ||
62 | taux_euro = clean_float(ligne.find(".taux").html()) | |
63 | total = 0; | |
64 | total = salaire + indemn + autre; | |
65 | total_euro = total * taux_euro; | |
66 | ||
67 | ligne.find(".total-devise").text(total.toFixed(2)); | |
68 | ligne.find(".total-euro").text(total_euro.toFixed(2)); | |
69 | ||
70 | } | |
71 | ||
72 | /* recalcule tout le classement */ | |
73 | function recalculer_tout() { | |
74 | $("#classement tr *[name*=devise]").each(function() { | |
75 | recalculer_ligne($(this)); | |
76 | }); | |
77 | } | |
78 | ||
79 | $(document).ready(function() { | |
80 | ||
81 | /* La fonctionnalité de présélection, est activé uniquement si aucune implantation n'a déjà été | |
82 | sélectionnée. | |
83 | Lorsque l'implantation est changée, on ajuste les valeurs de points en fonction de cette sélection */ | |
84 | var implantation_id = $("#id_implantation").val(); | |
85 | $("#id_implantation").change(function() { | |
86 | var implantation_id = this.value; | |
87 | charger_valeurs_point(implantation_id); | |
88 | }); | |
89 | ||
90 | ||
91 | $('#id_valeur_point_min, #id_valeur_point_max').change(function(e) { | |
92 | var vp_input = $(this); | |
93 | var ligne = vp_input.parents("tr").parent(); // en fait on travaille sur tout le tableau dans ce cas! | |
94 | ||
95 | var chargement_devise = $.getJSON("/dae/devise", {'valeur_point': this.value}); | |
96 | chargement_devise.success(function(data) { | |
97 | var selects = ligne.find("select"); | |
98 | selects.each(function() { | |
99 | var s = $(this); | |
100 | if (s.attr('id').match('id_devise*')) | |
101 | s.val(data.devise) | |
102 | ligne.find(".taux").text(data.taux_euro) | |
103 | ligne.find(".devise_code").text(data.devise_code) | |
104 | }); | |
105 | ||
106 | /* on synchronise les valeurs de points */ | |
107 | $('#id_valeur_point_min, #id_valeur_point_max').each(function() { | |
108 | var vp = $(this); | |
109 | if (vp.val() != vp_input.val()) { | |
110 | vp.val(vp_input.val()) | |
111 | } | |
112 | }); | |
113 | ||
989ec341 | 114 | recalculer_tout(); |
25410b22 OL |
115 | }); |
116 | chargement_devise.error(function(data) { | |
117 | alert(data.responseText); | |
118 | }); | |
119 | ||
120 | }); | |
121 | ||
122 | $('#id_devise_min, #id_devise_max').change(function(e) { | |
123 | var input = $(this); | |
124 | var ligne = input.parents("tr"); | |
125 | var chargement_devise = $.getJSON("/dae/devise/code", {'devise': this.value}); | |
126 | chargement_devise.success(function(data) { | |
127 | ligne.find(".taux").text(data.taux_euro) | |
128 | ligne.find(".devise_code").text(data.devise_code) | |
129 | recalculer_ligne(input); | |
130 | }); | |
131 | chargement_devise.error(function(data) { | |
132 | alert(data.responseText); | |
133 | ligne.find(".taux").text(0) | |
134 | ligne.find(".devise_code").text("???") | |
135 | }); | |
136 | ||
137 | }); | |
138 | ||
139 | $('#id_classement_min, #id_classement_max').change(function(e) { | |
140 | var classement = $(this); | |
141 | var ligne = classement.parents("tr"); | |
142 | var chargement_coeff = $.getJSON("/dae/coefficient", {'classement': classement.val()}); | |
143 | chargement_coeff.success(function(data){ | |
144 | var inputs = ligne.find("input"); | |
145 | inputs.each(function() { | |
146 | var input = $(this); | |
147 | if (input.attr('id').match('id_coefficient*')) | |
148 | input.val(data.coefficient); | |
149 | }); | |
150 | recalculer_ligne(classement); | |
151 | }); | |
152 | chargement_coeff.error(function(data){ | |
153 | }); | |
154 | }); | |
155 | ||
156 | /* refresh des totaux à chaque changement quelconque */ | |
157 | $('#classement input, #classement select').change(function() { | |
158 | recalculer_ligne($(this)); | |
159 | }); | |
160 | ||
161 | /* au chargement, on calcule tout */ | |
162 | recalculer_tout(); | |
163 | ||
01191cd0 OL |
164 | /* calcul de la différence en mois */ |
165 | $("#id_date_debut, #id_date_fin").focusout(function() { | |
166 | contrat_mois(); | |
167 | }); | |
168 | contrat_mois(); | |
169 | ||
25410b22 | 170 | }); |