Commit | Line | Data |
---|---|---|
25410b22 OL |
1 | /******************************************************************************* |
2 | * POSTE | |
3 | *******************************************************************************/ | |
4 | ||
72b571f4 OL |
5 | |
6 | function elements_comparaison(devise_id) { | |
15061532 | 7 | if (devise_id == "") return; |
72b571f4 OL |
8 | var chargement_devise = $.getJSON("/dae/devise/code", {'devise': devise_id}); |
9 | chargement_devise.success(function(data) { | |
10 | /* data.devise | |
11 | data.taux_euro | |
12 | data.devise_code */ | |
13 | $('#elements-comparaison input').each(function() { | |
14 | var input = $(this); | |
15 | var montant = data.taux_euro * parseFloat(input.val()); | |
16 | input.parent().find(".devise_euro").html(clean_float(montant) + " EUR"); | |
17 | input.parent().find(".devise").html(data.devise_code); | |
18 | }); | |
19 | }); | |
20 | chargement_devise.error(function(data) { | |
21 | alert(data.responseText); | |
22 | }); | |
23 | } | |
24 | ||
6d047148 OL |
25 | /* filter les postes en fonction de l'implantation choisie */ |
26 | function charger_postes(implantation_id) { | |
4bce4d24 | 27 | var selected = $("#id_poste :selected").val(); |
6d047148 OL |
28 | var params = {'implantation_id' : implantation_id}; |
29 | var chargement_p = $.getJSON('/dae/liste_postes', params); | |
30 | chargement_p.success(function(data) { | |
31 | var items = []; | |
32 | ||
33 | var options = ""; | |
34 | $.each(data, function(index) { | |
4bce4d24 OL |
35 | select = ""; |
36 | if (data[index][0] == selected) | |
37 | select = " selected=selected "; | |
38 | options += '<option ' + select + ' value="' + data[index][0] + '">' + data[index][1] + '</option>'; | |
6d047148 OL |
39 | }); |
40 | ||
41 | $("#id_poste").html(options); | |
42 | }); | |
43 | } | |
01191cd0 | 44 | |
25410b22 OL |
45 | /* Construction dynamique des valeurs de point en fonction de l'implantation choisie */ |
46 | function charger_valeurs_point(implantation_id) { | |
47 | var params = {'implantation_id' : implantation_id}; | |
48 | var chargement_vp = $.getJSON('/dae/liste_valeurs_point', params); | |
2f7a8932 OL |
49 | var selected_min = null; |
50 | var selected_max = null; | |
25410b22 OL |
51 | chargement_vp.success(function(data) { |
52 | var items = []; | |
53 | ||
11f22317 | 54 | var options = '<option value="">---------</option>'; |
25410b22 | 55 | $.each(data, function() { |
7ad0549c OL |
56 | var suggestion = ""; |
57 | if (this.suggestion) { | |
11f22317 | 58 | suggestion = ' style="font-weight: bold; color: black;" ' |
b1504b48 EMS |
59 | selected_min = selected_min || this.id; |
60 | selected_max = selected_max || this.id; | |
7ad0549c | 61 | } |
11f22317 | 62 | options += '<option' + suggestion + ' value="' + this.id + '">' + this.label + '</option>'; |
25410b22 OL |
63 | }); |
64 | ||
2f7a8932 OL |
65 | $('#id_valeur_point_min').html(options).val(selected_min).trigger('change'); |
66 | $('#id_valeur_point_max').html(options).val(selected_max).trigger('change'); | |
25410b22 OL |
67 | }); |
68 | } | |
69 | ||
70 | /* Calcul des totaux dans les 2 devises, selon les champs sélectionnés. Cette fonction | |
71 | est appelée À chaque modification du formulaire de classement. */ | |
72 | function recalculer_ligne(element) { | |
28ae09c3 OL |
73 | /* on laisse la possibilité de choisir le salaire manuellement, |
74 | la réinitialisation du salaire de base s'opère dès qu'on choisi | |
75 | un nouveau classement. */ | |
76 | if (element.attr('id').match('id_classement*')) | |
77 | salaire_manuel = false; | |
78 | else | |
79 | salaire_manuel = true; | |
80 | ||
25410b22 OL |
81 | var ligne = element.parents("tr"); |
82 | var inputs = ligne.find("input, select"); | |
83 | var salaire_input; | |
5f61bccb | 84 | var salaire; |
25410b22 | 85 | var valeur_point_input; |
5f61bccb OL |
86 | var classement_id; |
87 | var indemn_expat; | |
88 | var indemn_fct; | |
89 | var charges_patronales; | |
90 | var autre; | |
91 | ||
25410b22 OL |
92 | inputs.each(function() { |
93 | var input = $(this); | |
7dcb8d40 OL |
94 | |
95 | if (input.attr('id').match('id_classement*')) { | |
96 | classement_id = input.val(); | |
25410b22 OL |
97 | } |
98 | if (input.attr('id').match('id_valeur_point*')) { | |
99 | valeur_point_input = input; | |
100 | } | |
101 | if (input.attr('id').match('id_salaire*')) { | |
102 | salaire_input = input; | |
103 | salaire = clean_float(input.val()) | |
104 | } | |
5f61bccb OL |
105 | if (input.attr('id').match('id_indemn_expat*')) { |
106 | indemn_expat = clean_float(input.val()) | |
107 | } | |
108 | if (input.attr('id').match('id_indemn_fct*')) { | |
109 | indemn_fct = clean_float(input.val()) | |
110 | } | |
111 | if (input.attr('id').match('id_charges_patronales*')) { | |
112 | charges_patronales = clean_float(input.val()) | |
25410b22 OL |
113 | } |
114 | if (input.attr('id').match('id_autre*')) { | |
115 | autre = clean_float(input.val()) | |
116 | } | |
117 | ||
118 | }); | |
119 | ||
7dcb8d40 OL |
120 | var chargement_coeff = $.getJSON("/dae/coefficient", {'classement': classement_id}); |
121 | chargement_coeff.success(function(data){ | |
122 | coeff = data.coefficient; | |
123 | ||
124 | /* on suggère un salaire de base en fonction du coefficient et de la valeur du point */ | |
125 | valeur_point_text = valeur_point_input.find(":selected").text(); | |
126 | if (valeur_point_text == "") | |
127 | valeur_point = 0; | |
128 | else | |
129 | valeur_point = clean_float(valeur_point_text.split(" ")[0]); | |
11f22317 | 130 | |
28ae09c3 OL |
131 | if (salaire_manuel == false) { |
132 | salaire = clean_float(valeur_point * coeff); | |
133 | salaire_input.val(salaire); | |
134 | } | |
d1ca1d61 | 135 | taux_euro = parseFloat(ligne.find(".taux").html()) |
5f61bccb | 136 | total = salaire + indemn_expat + indemn_fct + charges_patronales + autre; |
0f3e6f87 | 137 | remuneration = total - charges_patronales; |
7dcb8d40 | 138 | total_euro = total * taux_euro; |
0f3e6f87 | 139 | remuneration_euro = remuneration * taux_euro; |
25410b22 | 140 | |
d1ca1d61 | 141 | ligne.find(".total-devise").text(clean_float(total)); |
0f3e6f87 | 142 | ligne.find(".remuneration-devise").text(clean_float(remuneration)); |
d1ca1d61 | 143 | ligne.find(".total-euro").text(clean_float(total_euro)); |
0f3e6f87 | 144 | ligne.find(".remuneration-euro").text(clean_float(remuneration_euro)); |
7dcb8d40 | 145 | }); |
25410b22 OL |
146 | |
147 | } | |
148 | ||
149 | /* recalcule tout le classement */ | |
150 | function recalculer_tout() { | |
4ee3b82d | 151 | $("#classement tr *[name*=salaire]").each(function() { |
25410b22 OL |
152 | recalculer_ligne($(this)); |
153 | }); | |
154 | } | |
155 | ||
5f61bccb OL |
156 | function setup_taux_ligne(element) { |
157 | var input = element; | |
158 | var ligne = input.parents("tr"); | |
15061532 OL |
159 | var devise_id = input.val(); |
160 | if (devise_id == "") return; | |
161 | var chargement_devise = $.getJSON("/dae/devise/code", {'devise': devise_id}); | |
5f61bccb OL |
162 | chargement_devise.success(function(data) { |
163 | ligne.find(".taux").text(data.taux_euro) | |
164 | ligne.find(".devise_code").text(data.devise_code) | |
165 | recalculer_ligne(input); | |
166 | }); | |
167 | chargement_devise.error(function(data) { | |
168 | alert(data.responseText); | |
169 | ligne.find(".taux").text(0) | |
170 | ligne.find(".devise_code").text("???") | |
171 | }); | |
172 | } | |
173 | ||
25410b22 OL |
174 | $(document).ready(function() { |
175 | ||
4bce4d24 OL |
176 | /* Lorsqu'on choisit un poste dans la liste on recharge la page avec le |
177 | poste chargé dans la view (grâce à son id dans l'URL).*/ | |
178 | $('#id_poste').change(function() { | |
9ab4727d OL |
179 | var id_poste = $(this).val(); |
180 | if (id_poste) | |
181 | window.location = '/dae/poste/' + id_poste; | |
4bce4d24 OL |
182 | }); |
183 | ||
25410b22 OL |
184 | /* La fonctionnalité de présélection, est activé uniquement si aucune implantation n'a déjà été |
185 | sélectionnée. | |
186 | Lorsque l'implantation est changée, on ajuste les valeurs de points en fonction de cette sélection */ | |
187 | var implantation_id = $("#id_implantation").val(); | |
09a606d0 OL |
188 | if (implantation_id) { |
189 | charger_postes(implantation_id); | |
190 | charger_valeurs_point(implantation_id); | |
191 | } | |
25410b22 OL |
192 | $("#id_implantation").change(function() { |
193 | var implantation_id = this.value; | |
6d047148 | 194 | charger_postes(implantation_id); |
25410b22 OL |
195 | charger_valeurs_point(implantation_id); |
196 | }); | |
197 | ||
198 | ||
199 | $('#id_valeur_point_min, #id_valeur_point_max').change(function(e) { | |
4ee3b82d OL |
200 | // pas de traitement si aucune valeur de point n'est choisie |
201 | if (this.value == '') return; | |
202 | ||
25410b22 OL |
203 | var vp_input = $(this); |
204 | var ligne = vp_input.parents("tr").parent(); // en fait on travaille sur tout le tableau dans ce cas! | |
205 | ||
206 | var chargement_devise = $.getJSON("/dae/devise", {'valeur_point': this.value}); | |
207 | chargement_devise.success(function(data) { | |
208 | var selects = ligne.find("select"); | |
209 | selects.each(function() { | |
210 | var s = $(this); | |
211 | if (s.attr('id').match('id_devise*')) | |
212 | s.val(data.devise) | |
213 | ligne.find(".taux").text(data.taux_euro) | |
214 | ligne.find(".devise_code").text(data.devise_code) | |
215 | }); | |
216 | ||
217 | /* on synchronise les valeurs de points */ | |
218 | $('#id_valeur_point_min, #id_valeur_point_max').each(function() { | |
219 | var vp = $(this); | |
220 | if (vp.val() != vp_input.val()) { | |
221 | vp.val(vp_input.val()) | |
222 | } | |
223 | }); | |
224 | ||
989ec341 | 225 | recalculer_tout(); |
25410b22 OL |
226 | }); |
227 | chargement_devise.error(function(data) { | |
228 | alert(data.responseText); | |
229 | }); | |
11f22317 | 230 | |
25410b22 OL |
231 | }); |
232 | ||
233 | $('#id_devise_min, #id_devise_max').change(function(e) { | |
5f61bccb | 234 | setup_taux_ligne($(this)); |
25410b22 OL |
235 | }); |
236 | ||
02a2e65a | 237 | $('#id_classement_min, #id_classement_max, #classement input, #classement select').change(function(e) { |
25410b22 OL |
238 | recalculer_ligne($(this)); |
239 | }); | |
02a2e65a | 240 | |
25410b22 | 241 | /* au chargement, on calcule tout */ |
5f61bccb OL |
242 | $('#id_devise_min, #id_devise_max').each(function() { |
243 | setup_taux_ligne($(this)); | |
244 | }); | |
245 | // le setup de la devise par ligne est déjà suivi d'un recalcul de la ligne automatique | |
246 | //recalculer_tout(); | |
25410b22 | 247 | |
01191cd0 OL |
248 | /* calcul de la différence en mois */ |
249 | $("#id_date_debut, #id_date_fin").focusout(function() { | |
250 | contrat_mois(); | |
251 | }); | |
252 | contrat_mois(); | |
11f22317 | 253 | |
4bce4d24 OL |
254 | /* on charge les postes reliés à cette implantation */ |
255 | charger_postes($("#id_implantation :selected").val()); | |
01191cd0 | 256 | |
72b571f4 OL |
257 | $('#id_devise_comparaison, #elements-comparaison input').change(function(e) { |
258 | elements_comparaison($('#id_devise_comparaison').val()); | |
259 | }); | |
260 | elements_comparaison($('#id_devise_comparaison').val()); | |
261 | ||
068d1462 | 262 | /* Traitement de la recherche AJAX pour les postes de comparaison */ |
a03c8b3a | 263 | $(".comparaison-interne .results_on_deck").bind('added', function() { |
068d1462 OL |
264 | /* récupération du choix dans la liste */ |
265 | var input_id = $(this).attr('id').replace('_on_deck', ''); | |
266 | var prefix_poste_connexe = $(this).attr('id').replace('recherche_on_deck', ''); | |
267 | var input = $('#'+input_id); | |
268 | var poste_id = input.val(); | |
269 | ||
270 | /* interrogation par AJAX pour récupérer les données du poste */ | |
271 | var chargement_poste = $.getJSON("/dae/poste_resume/" + poste_id); | |
272 | chargement_poste.success(function(data) { | |
273 | $('#' + prefix_poste_connexe + 'implantation').val(data['implantation']); | |
274 | $('#' + prefix_poste_connexe + 'nom').val(data['poste']); | |
275 | $('#' + prefix_poste_connexe + 'montant').val(data['montant']); | |
276 | $('#' + prefix_poste_connexe + 'devise').val(data['devise']); | |
277 | $('#' + prefix_poste_connexe + 'montant_euros').val(data['montant_euros']); | |
278 | }); | |
279 | chargement_poste.error(function(data) { | |
280 | alert(data.responseText); | |
281 | }); | |
11f22317 | 282 | |
068d1462 OL |
283 | /* on ne veut pas afficher la personne en-dessous */ |
284 | $(this).find('div').remove(); | |
285 | input.val(''); | |
286 | ||
287 | }); | |
288 | ||
289 | ||
25410b22 | 290 | }); |