Commit | Line | Data |
---|---|---|
25410b22 OL |
1 | /******************************************************************************* |
2 | * POSTE | |
3 | *******************************************************************************/ | |
4 | ||
72b571f4 OL |
5 | |
6 | function elements_comparaison(devise_id) { | |
7 | var chargement_devise = $.getJSON("/dae/devise/code", {'devise': devise_id}); | |
8 | chargement_devise.success(function(data) { | |
9 | /* data.devise | |
10 | data.taux_euro | |
11 | data.devise_code */ | |
12 | $('#elements-comparaison input').each(function() { | |
13 | var input = $(this); | |
14 | var montant = data.taux_euro * parseFloat(input.val()); | |
15 | input.parent().find(".devise_euro").html(clean_float(montant) + " EUR"); | |
16 | input.parent().find(".devise").html(data.devise_code); | |
17 | }); | |
18 | }); | |
19 | chargement_devise.error(function(data) { | |
20 | alert(data.responseText); | |
21 | }); | |
22 | } | |
23 | ||
6d047148 OL |
24 | /* filter les postes en fonction de l'implantation choisie */ |
25 | function charger_postes(implantation_id) { | |
4bce4d24 | 26 | var selected = $("#id_poste :selected").val(); |
6d047148 OL |
27 | var params = {'implantation_id' : implantation_id}; |
28 | var chargement_p = $.getJSON('/dae/liste_postes', params); | |
29 | chargement_p.success(function(data) { | |
30 | var items = []; | |
31 | ||
32 | var options = ""; | |
33 | $.each(data, function(index) { | |
4bce4d24 OL |
34 | select = ""; |
35 | if (data[index][0] == selected) | |
36 | select = " selected=selected "; | |
37 | options += '<option ' + select + ' value="' + data[index][0] + '">' + data[index][1] + '</option>'; | |
6d047148 OL |
38 | }); |
39 | ||
40 | $("#id_poste").html(options); | |
41 | }); | |
42 | } | |
01191cd0 | 43 | |
25410b22 OL |
44 | /* Construction dynamique des valeurs de point en fonction de l'implantation choisie */ |
45 | function charger_valeurs_point(implantation_id) { | |
46 | var params = {'implantation_id' : implantation_id}; | |
47 | var chargement_vp = $.getJSON('/dae/liste_valeurs_point', params); | |
48 | chargement_vp.success(function(data) { | |
49 | var items = []; | |
50 | ||
51 | var options = ""; | |
52 | $.each(data, function() { | |
53 | options += '<option value="' + this.id + '">' + this.label + '</option>'; | |
54 | }); | |
55 | ||
56 | $("#id_valeur_point_min").html(options); | |
57 | $("#id_valeur_point_max").html(options); | |
4bce4d24 | 58 | alert("Les valeurs de point et les postes ont été ajustés en fonction de cette implantation."); |
25410b22 OL |
59 | }); |
60 | } | |
61 | ||
62 | /* Calcul des totaux dans les 2 devises, selon les champs sélectionnés. Cette fonction | |
63 | est appelée À chaque modification du formulaire de classement. */ | |
64 | function recalculer_ligne(element) { | |
28ae09c3 OL |
65 | |
66 | /* on laisse la possibilité de choisir le salaire manuellement, | |
67 | la réinitialisation du salaire de base s'opère dès qu'on choisi | |
68 | un nouveau classement. */ | |
69 | if (element.attr('id').match('id_classement*')) | |
70 | salaire_manuel = false; | |
71 | else | |
72 | salaire_manuel = true; | |
73 | ||
25410b22 OL |
74 | var ligne = element.parents("tr"); |
75 | var inputs = ligne.find("input, select"); | |
76 | var salaire_input; | |
77 | var valeur_point_input; | |
78 | inputs.each(function() { | |
79 | var input = $(this); | |
7dcb8d40 OL |
80 | |
81 | if (input.attr('id').match('id_classement*')) { | |
82 | classement_id = input.val(); | |
25410b22 OL |
83 | } |
84 | if (input.attr('id').match('id_valeur_point*')) { | |
85 | valeur_point_input = input; | |
86 | } | |
87 | if (input.attr('id').match('id_salaire*')) { | |
88 | salaire_input = input; | |
89 | salaire = clean_float(input.val()) | |
90 | } | |
91 | if (input.attr('id').match('id_indemn*')) { | |
92 | indemn = clean_float(input.val()) | |
93 | } | |
94 | if (input.attr('id').match('id_autre*')) { | |
95 | autre = clean_float(input.val()) | |
96 | } | |
97 | ||
98 | }); | |
99 | ||
7dcb8d40 OL |
100 | var chargement_coeff = $.getJSON("/dae/coefficient", {'classement': classement_id}); |
101 | chargement_coeff.success(function(data){ | |
102 | coeff = data.coefficient; | |
103 | ||
104 | /* on suggère un salaire de base en fonction du coefficient et de la valeur du point */ | |
105 | valeur_point_text = valeur_point_input.find(":selected").text(); | |
106 | if (valeur_point_text == "") | |
107 | valeur_point = 0; | |
108 | else | |
109 | valeur_point = clean_float(valeur_point_text.split(" ")[0]); | |
28ae09c3 OL |
110 | |
111 | if (salaire_manuel == false) { | |
112 | salaire = clean_float(valeur_point * coeff); | |
113 | salaire_input.val(salaire); | |
114 | } | |
25410b22 | 115 | |
d1ca1d61 | 116 | taux_euro = parseFloat(ligne.find(".taux").html()) |
7dcb8d40 OL |
117 | total = 0; |
118 | total = salaire + indemn + autre; | |
119 | total_euro = total * taux_euro; | |
25410b22 | 120 | |
d1ca1d61 OL |
121 | ligne.find(".total-devise").text(clean_float(total)); |
122 | ligne.find(".total-euro").text(clean_float(total_euro)); | |
7dcb8d40 | 123 | }); |
25410b22 OL |
124 | |
125 | } | |
126 | ||
127 | /* recalcule tout le classement */ | |
128 | function recalculer_tout() { | |
02a2e65a | 129 | $("#classement tr *[name*=classement]").each(function() { |
25410b22 OL |
130 | recalculer_ligne($(this)); |
131 | }); | |
132 | } | |
133 | ||
134 | $(document).ready(function() { | |
135 | ||
4bce4d24 OL |
136 | /* Lorsqu'on choisit un poste dans la liste on recharge la page avec le |
137 | poste chargé dans la view (grâce à son id dans l'URL).*/ | |
138 | $('#id_poste').change(function() { | |
139 | window.location = '/dae/poste/' + $(this).val(); | |
140 | }); | |
141 | ||
25410b22 OL |
142 | /* La fonctionnalité de présélection, est activé uniquement si aucune implantation n'a déjà été |
143 | sélectionnée. | |
144 | Lorsque l'implantation est changée, on ajuste les valeurs de points en fonction de cette sélection */ | |
145 | var implantation_id = $("#id_implantation").val(); | |
146 | $("#id_implantation").change(function() { | |
147 | var implantation_id = this.value; | |
6d047148 | 148 | charger_postes(implantation_id); |
25410b22 OL |
149 | charger_valeurs_point(implantation_id); |
150 | }); | |
151 | ||
152 | ||
153 | $('#id_valeur_point_min, #id_valeur_point_max').change(function(e) { | |
154 | var vp_input = $(this); | |
155 | var ligne = vp_input.parents("tr").parent(); // en fait on travaille sur tout le tableau dans ce cas! | |
156 | ||
157 | var chargement_devise = $.getJSON("/dae/devise", {'valeur_point': this.value}); | |
158 | chargement_devise.success(function(data) { | |
159 | var selects = ligne.find("select"); | |
160 | selects.each(function() { | |
161 | var s = $(this); | |
162 | if (s.attr('id').match('id_devise*')) | |
163 | s.val(data.devise) | |
164 | ligne.find(".taux").text(data.taux_euro) | |
165 | ligne.find(".devise_code").text(data.devise_code) | |
166 | }); | |
167 | ||
168 | /* on synchronise les valeurs de points */ | |
169 | $('#id_valeur_point_min, #id_valeur_point_max').each(function() { | |
170 | var vp = $(this); | |
171 | if (vp.val() != vp_input.val()) { | |
172 | vp.val(vp_input.val()) | |
173 | } | |
174 | }); | |
175 | ||
989ec341 | 176 | recalculer_tout(); |
25410b22 OL |
177 | }); |
178 | chargement_devise.error(function(data) { | |
179 | alert(data.responseText); | |
180 | }); | |
181 | ||
182 | }); | |
183 | ||
184 | $('#id_devise_min, #id_devise_max').change(function(e) { | |
185 | var input = $(this); | |
186 | var ligne = input.parents("tr"); | |
187 | var chargement_devise = $.getJSON("/dae/devise/code", {'devise': this.value}); | |
188 | chargement_devise.success(function(data) { | |
189 | ligne.find(".taux").text(data.taux_euro) | |
190 | ligne.find(".devise_code").text(data.devise_code) | |
191 | recalculer_ligne(input); | |
192 | }); | |
193 | chargement_devise.error(function(data) { | |
194 | alert(data.responseText); | |
195 | ligne.find(".taux").text(0) | |
196 | ligne.find(".devise_code").text("???") | |
197 | }); | |
198 | ||
199 | }); | |
200 | ||
02a2e65a | 201 | $('#id_classement_min, #id_classement_max, #classement input, #classement select').change(function(e) { |
25410b22 OL |
202 | recalculer_ligne($(this)); |
203 | }); | |
02a2e65a | 204 | |
25410b22 OL |
205 | /* au chargement, on calcule tout */ |
206 | recalculer_tout(); | |
207 | ||
01191cd0 OL |
208 | /* calcul de la différence en mois */ |
209 | $("#id_date_debut, #id_date_fin").focusout(function() { | |
210 | contrat_mois(); | |
211 | }); | |
212 | contrat_mois(); | |
4bce4d24 OL |
213 | |
214 | /* on charge les postes reliés à cette implantation */ | |
215 | charger_postes($("#id_implantation :selected").val()); | |
01191cd0 | 216 | |
72b571f4 OL |
217 | $('#id_devise_comparaison, #elements-comparaison input').change(function(e) { |
218 | elements_comparaison($('#id_devise_comparaison').val()); | |
219 | }); | |
220 | elements_comparaison($('#id_devise_comparaison').val()); | |
221 | ||
25410b22 | 222 | }); |