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