1 /*******************************************************************************
3 *******************************************************************************/
6 function elements_comparaison(devise_id
) {
7 if (devise_id
== "") return;
8 var chargement_devise
= $
.getJSON("/dae/devise/code", {'devise': devise_id
});
9 chargement_devise
.success(function(data
) {
13 $
('#elements-comparaison input').each(function() {
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
);
20 chargement_devise
.error(function(data
) {
21 alert(data
.responseText
);
25 /* filter les postes en fonction de l'implantation choisie */
26 function charger_postes(implantation_id
) {
27 var selected
= $
("#id_poste :selected").val();
28 var params
= {'implantation_id' : implantation_id
};
29 var chargement_p
= $
.getJSON('/dae/liste_postes', params
);
30 chargement_p
.success(function(data
) {
34 $
.each(data
, function(index
) {
36 if (data
[index][0] == selected
)
37 select
= " selected=selected ";
38 options
+= '<option ' + select
+ ' value="' + data
[index][0] + '">' + data
[index][1] + '</option>';
41 $
("#id_poste").html(options
);
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
);
49 var selected_min
= null;
50 var selected_max
= null;
51 chargement_vp
.success(function(data
) {
54 var options
= '<option value="">---------</option>';
55 $
.each(data
, function() {
57 if (this.suggestion
) {
58 suggestion
= ' style="font-weight: bold; color: black;" '
59 selected_min
= selected_min ||
this.id
;
60 selected_max
= selected_max ||
this.id
;
62 options
+= '<option' + suggestion
+ ' value="' + this.id
+ '">' + this.label
+ '</option>';
65 $
('#id_valeur_point_min').html(options
).val(selected_min
).trigger('change');
66 $
('#id_valeur_point_max').html(options
).val(selected_max
).trigger('change');
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
) {
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;
79 salaire_manuel
= true;
81 var ligne
= element
.parents("tr");
82 var inputs
= ligne
.find("input, select");
85 var valeur_point_input
;
89 var charges_patronales
;
92 inputs
.each(function() {
95 if (input
.attr('id').match('id_classement*')) {
96 classement_id
= input
.val();
98 if (input
.attr('id').match('id_valeur_point*')) {
99 valeur_point_input
= input
;
101 if (input
.attr('id').match('id_salaire*')) {
102 salaire_input
= input
;
103 salaire
= clean_float(input
.val())
105 if (input
.attr('id').match('id_indemn_expat*')) {
106 indemn_expat
= clean_float(input
.val())
108 if (input
.attr('id').match('id_indemn_fct*')) {
109 indemn_fct
= clean_float(input
.val())
111 if (input
.attr('id').match('id_charges_patronales*')) {
112 charges_patronales
= clean_float(input
.val())
114 if (input
.attr('id').match('id_autre*')) {
115 autre
= clean_float(input
.val())
120 var chargement_coeff
= $
.getJSON("/dae/coefficient", {'classement': classement_id
});
121 chargement_coeff
.success(function(data
){
122 coeff
= data
.coefficient
;
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
== "")
129 valeur_point
= clean_float(valeur_point_text
.split(" ")[2]);
130 if (salaire_manuel
== false) {
131 salaire
= clean_float(valeur_point
* coeff
);
132 salaire_input
.val(salaire
);
134 taux_euro
= parseFloat(ligne
.find(".taux").html())
135 total
= salaire
+ indemn_expat
+ indemn_fct
+ charges_patronales
+ autre
;
136 remuneration
= total
- charges_patronales
;
137 total_euro
= total
* taux_euro
;
138 remuneration_euro
= remuneration
* taux_euro
;
140 ligne
.find(".total-devise").text(clean_float(total
));
141 ligne
.find(".remuneration-devise").text(clean_float(remuneration
));
142 ligne
.find(".total-euro").text(clean_float(total_euro
));
143 ligne
.find(".remuneration-euro").text(clean_float(remuneration_euro
));
148 /* recalcule tout le classement */
149 function recalculer_tout() {
150 $
("#classement tr *[name*=salaire]").each(function() {
151 recalculer_ligne($
(this));
155 function setup_taux_ligne(element
) {
157 var ligne
= input
.parents("tr");
158 var devise_id
= input
.val();
159 if (devise_id
== "") return;
160 var chargement_devise
= $
.getJSON("/dae/devise/code", {'devise': devise_id
});
161 chargement_devise
.success(function(data
) {
162 ligne
.find(".taux").text(data
.taux_euro
)
163 ligne
.find(".devise_code").text(data
.devise_code
)
164 recalculer_ligne(input
);
166 chargement_devise
.error(function(data
) {
167 alert(data
.responseText
);
168 ligne
.find(".taux").text(0)
169 ligne
.find(".devise_code").text("???")
173 function poste_redirection() {
174 var id_poste
= $
("#id_poste").val();
176 window
.location
= '/dae/poste/' + id_poste
+
177 '?type_intervention=' + $
("input[name='type_intervention']:checked").val();
180 $
(document
).ready(function() {
182 /* Lorsqu'on choisit un poste dans la liste on recharge la page avec le
183 poste chargé dans la view (grâce à son id dans l'URL).*/
184 $
('#id_poste').change(function() {
188 /* La fonctionnalité de présélection, est activé uniquement si aucune implantation n'a déjà été
190 Lorsque l'implantation est changée, on ajuste les valeurs de points en fonction de cette sélection */
191 var implantation_id
= $
("#id_implantation").val();
192 var null_vp_min
= $
("#valeur_point_min").val() == '';
193 var null_vp_max
= $
("#valeur_point_max").val() == '';
195 if (implantation_id
&& null_vp_min
&& null_vp_max
) {
196 charger_postes(implantation_id
);
197 charger_valeurs_point(implantation_id
);
199 $
("#id_implantation").change(function() {
200 var implantation_id
= this.value
;
201 charger_postes(implantation_id
);
202 charger_valeurs_point(implantation_id
);
205 $
('#poste_id_shortcut').change(function() {
206 var poste_id_rh
= $
('#poste_id_shortcut').val();
207 var key
= 'rh-'+poste_id_rh
;
208 $
('#id_poste').val(key
);
209 if ($
('#id_poste').val() == key
) {
216 $
('#id_valeur_point_min, #id_valeur_point_max').change(function(e
) {
217 // pas de traitement si aucune valeur de point n'est choisie
218 if (this.value
== '') return;
220 var vp_input
= $
(this);
221 var ligne
= vp_input
.parents("tr").parent(); // en fait on travaille sur tout le tableau dans ce cas!
223 var chargement_devise
= $
.getJSON("/dae/devise", {'valeur_point': this.value
});
224 chargement_devise
.success(function(data
) {
225 var selects
= ligne
.find("select");
226 selects
.each(function() {
228 if (s
.attr('id').match('id_devise*'))
230 ligne
.find(".taux").text(data
.taux_euro
)
231 ligne
.find(".devise_code").text(data
.devise_code
)
234 /* on synchronise les valeurs de points */
235 $
('#id_valeur_point_min, #id_valeur_point_max').each(function() {
237 if (vp
.val() != vp_input
.val()) {
238 vp
.val(vp_input
.val())
244 chargement_devise
.error(function(data
) {
245 alert(data
.responseText
);
250 $
('#id_devise_min, #id_devise_max').change(function(e
) {
251 setup_taux_ligne($
(this));
254 $
('#id_classement_min, #id_classement_max, #classement input, #classement select').change(function(e
) {
255 recalculer_ligne($
(this));
258 /* au chargement, on calcule tout */
259 $
('#id_devise_min, #id_devise_max').each(function() {
260 setup_taux_ligne($
(this));
262 // le setup de la devise par ligne est déjà suivi d'un recalcul de la ligne automatique
265 /* calcul de la différence en mois */
266 $
("#id_date_debut, #id_date_fin").focusout(function() {
271 /* on charge les postes reliés à cette implantation */
272 charger_postes($
("#id_implantation :selected").val());
274 $
('#id_devise_comparaison, #elements-comparaison input').change(function(e
) {
275 elements_comparaison($
('#id_devise_comparaison').val());
277 elements_comparaison($
('#id_devise_comparaison').val());
279 /* Traitement de la recherche AJAX pour les postes de comparaison */
280 $
(".comparaison-interne .results_on_deck").bind('added', function() {
281 /* récupération du choix dans la liste */
282 var input_id
= $
(this).attr('id').replace('_on_deck', '');
283 var prefix_poste_connexe
= $
(this).attr('id').replace('recherche_on_deck', '');
284 var input
= $
('#'+input_id
);
285 var poste_id
= input
.val();
287 /* interrogation par AJAX pour récupérer les données du poste */
288 var chargement_poste
= $
.getJSON("/dae/poste_resume/" + poste_id
);
289 chargement_poste
.success(function(data
) {
290 $
('#' + prefix_poste_connexe
+ 'implantation').val(data
['implantation']);
291 $
('#' + prefix_poste_connexe
+ 'nom').val(data
['poste']);
292 $
('#' + prefix_poste_connexe
+ 'montant').val(data
['montant']);
293 $
('#' + prefix_poste_connexe
+ 'devise').val(data
['devise']);
294 $
('#' + prefix_poste_connexe
+ 'montant_euros').val(data
['montant_euros']);
295 $
('#' + prefix_poste_connexe
+ 'statut').val(data
['statut']);
296 $
('#' + prefix_poste_connexe
+ 'classement').val(data
['classement']);
298 chargement_poste
.error(function(data
) {
299 alert(data
.responseText
);
302 /* on ne veut pas afficher la personne en-dessous */
303 $
(this).find('div').remove();