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 /* stocker le texte par défaut à afficher */
80 var note_duree_indeterminee
= "";
82 function contrat_mois() {
83 if (note_duree_indeterminee
== "")
84 note_duree_indeterminee
= $
("#note-duree").html();
85 var debut
= $
("#id_date_debut").val();
86 var fin
= $
("#id_date_fin").val();
87 if (debut
== "" || fin
== "")
88 note
= note_duree_indeterminee
;
90 var d1
= new Date(debut
);
91 var d2
= new Date(fin
);
92 var duree
= Math
.round((d2
-d1
) / (1000*60*60*24) / (365/12));
93 note
= duree
+ " mois";
95 $
("#note-duree").html(note
);
98 $
(document
).ready(function() {
100 /* La fonctionnalité de présélection, est activé uniquement si aucune implantation n'a déjà été
102 Lorsque l'implantation est changée, on ajuste les valeurs de points en fonction de cette sélection */
103 var implantation_id
= $
("#id_implantation").val();
104 $
("#id_implantation").change(function() {
105 var implantation_id
= this.value
;
106 charger_valeurs_point(implantation_id
);
110 $
('#id_valeur_point_min, #id_valeur_point_max').change(function(e
) {
111 var vp_input
= $
(this);
112 var ligne
= vp_input
.parents("tr").parent(); // en fait on travaille sur tout le tableau dans ce cas!
114 var chargement_devise
= $
.getJSON("/dae/devise", {'valeur_point': this.value
});
115 chargement_devise
.success(function(data
) {
116 var selects
= ligne
.find("select");
117 selects
.each(function() {
119 if (s
.attr('id').match('id_devise*'))
121 ligne
.find(".taux").text(data
.taux_euro
)
122 ligne
.find(".devise_code").text(data
.devise_code
)
125 /* on synchronise les valeurs de points */
126 $
('#id_valeur_point_min, #id_valeur_point_max').each(function() {
128 if (vp
.val() != vp_input
.val()) {
129 vp
.val(vp_input
.val())
135 chargement_devise
.error(function(data
) {
136 alert(data
.responseText
);
141 $
('#id_devise_min, #id_devise_max').change(function(e
) {
143 var ligne
= input
.parents("tr");
144 var chargement_devise
= $
.getJSON("/dae/devise/code", {'devise': this.value
});
145 chargement_devise
.success(function(data
) {
146 ligne
.find(".taux").text(data
.taux_euro
)
147 ligne
.find(".devise_code").text(data
.devise_code
)
148 recalculer_ligne(input
);
150 chargement_devise
.error(function(data
) {
151 alert(data
.responseText
);
152 ligne
.find(".taux").text(0)
153 ligne
.find(".devise_code").text("???")
158 $
('#id_classement_min, #id_classement_max').change(function(e
) {
159 var classement
= $
(this);
160 var ligne
= classement
.parents("tr");
161 var chargement_coeff
= $
.getJSON("/dae/coefficient", {'classement': classement
.val()});
162 chargement_coeff
.success(function(data
){
163 var inputs
= ligne
.find("input");
164 inputs
.each(function() {
166 if (input
.attr('id').match('id_coefficient*'))
167 input
.val(data
.coefficient
);
169 recalculer_ligne(classement
);
171 chargement_coeff
.error(function(data
){
175 /* refresh des totaux à chaque changement quelconque */
176 $
('#classement input, #classement select').change(function() {
177 recalculer_ligne($
(this));
180 /* au chargement, on calcule tout */
183 /* calcul de la différence en mois */
184 $
("#id_date_debut, #id_date_fin").focusout(function() {