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