1 /*******************************************************************************
3 *******************************************************************************/
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
) {
13 $
.each(data
, function(index
) {
14 options
+= '<option value="' + data
[index][0] + '">' + data
[index][1] + '</option>';
17 $
("#id_poste").html(options
);
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
) {
29 $
.each(data
, function() {
30 options
+= '<option value="' + this.id
+ '">' + this.label
+ '</option>';
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.");
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");
45 var valeur_point_input
;
46 inputs
.each(function() {
48 if (input
.attr('id').match('id_coefficient*')) {
49 coeff
= clean_float(input
.val())
51 if (input
.attr('id').match('id_valeur_point*')) {
52 valeur_point_input
= input
;
54 if (input
.attr('id').match('id_salaire*')) {
55 salaire_input
= input
;
56 salaire
= clean_float(input
.val())
58 if (input
.attr('id').match('id_indemn*')) {
59 indemn
= clean_float(input
.val())
61 if (input
.attr('id').match('id_autre*')) {
62 autre
= clean_float(input
.val())
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
== "")
72 valeur_point
= clean_float(valeur_point_text
.split(" ")[0]);
74 salaire
= clean_float(valeur_point
* coeff
);
75 salaire_input
.val(salaire
);
77 taux_euro
= clean_float(ligne
.find(".taux").html())
79 total
= salaire
+ indemn
+ autre
;
80 total_euro
= total
* taux_euro
;
82 ligne
.find(".total-devise").text(total
.toFixed(2));
83 ligne
.find(".total-euro").text(total_euro
.toFixed(2));
87 /* recalcule tout le classement */
88 function recalculer_tout() {
89 $
("#classement tr *[name*=devise]").each(function() {
90 recalculer_ligne($
(this));
94 $
(document
).ready(function() {
96 /* La fonctionnalité de présélection, est activé uniquement si aucune implantation n'a déjà été
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
;
102 charger_postes(implantation_id
);
103 charger_valeurs_point(implantation_id
);
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!
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() {
116 if (s
.attr('id').match('id_devise*'))
118 ligne
.find(".taux").text(data
.taux_euro
)
119 ligne
.find(".devise_code").text(data
.devise_code
)
122 /* on synchronise les valeurs de points */
123 $
('#id_valeur_point_min, #id_valeur_point_max').each(function() {
125 if (vp
.val() != vp_input
.val()) {
126 vp
.val(vp_input
.val())
132 chargement_devise
.error(function(data
) {
133 alert(data
.responseText
);
138 $
('#id_devise_min, #id_devise_max').change(function(e
) {
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
);
147 chargement_devise
.error(function(data
) {
148 alert(data
.responseText
);
149 ligne
.find(".taux").text(0)
150 ligne
.find(".devise_code").text("???")
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() {
163 if (input
.attr('id').match('id_coefficient*'))
164 input
.val(data
.coefficient
);
166 recalculer_ligne(classement
);
168 chargement_coeff
.error(function(data
){
172 /* refresh des totaux à chaque changement quelconque */
173 $
('#classement input, #classement select').change(function() {
174 recalculer_ligne($
(this));
177 /* au chargement, on calcule tout */
180 /* calcul de la différence en mois */
181 $
("#id_date_debut, #id_date_fin").focusout(function() {