1 /*******************************************************************************
3 *******************************************************************************/
6 /* Construction dynamique des valeurs de point en fonction de l'implantation choisie */
7 function charger_valeurs_point(implantation_id
) {
8 var params
= {'implantation_id' : implantation_id
};
9 var chargement_vp
= $
.getJSON('/dae/liste_valeurs_point', params
);
10 chargement_vp
.success(function(data
) {
14 $
.each(data
, function() {
15 options
+= '<option value="' + this.id
+ '">' + this.label
+ '</option>';
18 $
("#id_valeur_point_min").html(options
);
19 $
("#id_valeur_point_max").html(options
);
20 alert("Les valeurs de point on été ajustées en fonction de cette implantation.");
24 /* Calcul des totaux dans les 2 devises, selon les champs sélectionnés. Cette fonction
25 est appelée À chaque modification du formulaire de classement. */
26 function recalculer_ligne(element
) {
27 var ligne
= element
.parents("tr");
28 var inputs
= ligne
.find("input, select");
30 var valeur_point_input
;
31 inputs
.each(function() {
33 if (input
.attr('id').match('id_coefficient*')) {
34 coeff
= clean_float(input
.val())
36 if (input
.attr('id').match('id_valeur_point*')) {
37 valeur_point_input
= input
;
39 if (input
.attr('id').match('id_salaire*')) {
40 salaire_input
= input
;
41 salaire
= clean_float(input
.val())
43 if (input
.attr('id').match('id_indemn*')) {
44 indemn
= clean_float(input
.val())
46 if (input
.attr('id').match('id_autre*')) {
47 autre
= clean_float(input
.val())
52 /* on suggère un salaire de base en fonction du coefficient et de la valeur du point */
53 valeur_point_text
= valeur_point_input
.find(":selected").text();
54 if (valeur_point_text
== "")
57 valeur_point
= clean_float(valeur_point_text
.split(" ")[0]);
59 salaire
= clean_float(valeur_point
* coeff
);
60 salaire_input
.val(salaire
);
62 taux_euro
= clean_float(ligne
.find(".taux").html())
64 total
= salaire
+ indemn
+ autre
;
65 total_euro
= total
* taux_euro
;
67 ligne
.find(".total-devise").text(total
.toFixed(2));
68 ligne
.find(".total-euro").text(total_euro
.toFixed(2));
72 /* recalcule tout le classement */
73 function recalculer_tout() {
74 $
("#classement tr *[name*=devise]").each(function() {
75 recalculer_ligne($
(this));
79 $
(document
).ready(function() {
81 /* La fonctionnalité de présélection, est activé uniquement si aucune implantation n'a déjà été
83 Lorsque l'implantation est changée, on ajuste les valeurs de points en fonction de cette sélection */
84 var implantation_id
= $
("#id_implantation").val();
85 $
("#id_implantation").change(function() {
86 var implantation_id
= this.value
;
87 charger_valeurs_point(implantation_id
);
91 $
('#id_valeur_point_min, #id_valeur_point_max').change(function(e
) {
92 var vp_input
= $
(this);
93 var ligne
= vp_input
.parents("tr").parent(); // en fait on travaille sur tout le tableau dans ce cas!
95 var chargement_devise
= $
.getJSON("/dae/devise", {'valeur_point': this.value
});
96 chargement_devise
.success(function(data
) {
97 var selects
= ligne
.find("select");
98 selects
.each(function() {
100 if (s
.attr('id').match('id_devise*'))
102 ligne
.find(".taux").text(data
.taux_euro
)
103 ligne
.find(".devise_code").text(data
.devise_code
)
106 /* on synchronise les valeurs de points */
107 $
('#id_valeur_point_min, #id_valeur_point_max').each(function() {
109 if (vp
.val() != vp_input
.val()) {
110 vp
.val(vp_input
.val())
116 chargement_devise
.error(function(data
) {
117 alert(data
.responseText
);
122 $
('#id_devise_min, #id_devise_max').change(function(e
) {
124 var ligne
= input
.parents("tr");
125 var chargement_devise
= $
.getJSON("/dae/devise/code", {'devise': this.value
});
126 chargement_devise
.success(function(data
) {
127 ligne
.find(".taux").text(data
.taux_euro
)
128 ligne
.find(".devise_code").text(data
.devise_code
)
129 recalculer_ligne(input
);
131 chargement_devise
.error(function(data
) {
132 alert(data
.responseText
);
133 ligne
.find(".taux").text(0)
134 ligne
.find(".devise_code").text("???")
139 $
('#id_classement_min, #id_classement_max').change(function(e
) {
140 var classement
= $
(this);
141 var ligne
= classement
.parents("tr");
142 var chargement_coeff
= $
.getJSON("/dae/coefficient", {'classement': classement
.val()});
143 chargement_coeff
.success(function(data
){
144 var inputs
= ligne
.find("input");
145 inputs
.each(function() {
147 if (input
.attr('id').match('id_coefficient*'))
148 input
.val(data
.coefficient
);
150 recalculer_ligne(classement
);
152 chargement_coeff
.error(function(data
){
156 /* refresh des totaux à chaque changement quelconque */
157 $
('#classement input, #classement select').change(function() {
158 recalculer_ligne($
(this));
161 /* au chargement, on calcule tout */
164 /* calcul de la différence en mois */
165 $
("#id_date_debut, #id_date_fin").focusout(function() {