Commit | Line | Data |
---|---|---|
25410b22 OL |
1 | /******************************************************************************* |
2 | * POSTE | |
3 | *******************************************************************************/ | |
4 | ||
01191cd0 | 5 | |
25410b22 OL |
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) { | |
11 | var items = []; | |
12 | ||
13 | var options = ""; | |
14 | $.each(data, function() { | |
15 | options += '<option value="' + this.id + '">' + this.label + '</option>'; | |
16 | }); | |
17 | ||
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."); | |
21 | }); | |
22 | } | |
23 | ||
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"); | |
29 | var salaire_input; | |
30 | var valeur_point_input; | |
31 | inputs.each(function() { | |
32 | var input = $(this); | |
33 | if (input.attr('id').match('id_coefficient*')) { | |
34 | coeff = clean_float(input.val()) | |
35 | } | |
36 | if (input.attr('id').match('id_valeur_point*')) { | |
37 | valeur_point_input = input; | |
38 | } | |
39 | if (input.attr('id').match('id_salaire*')) { | |
40 | salaire_input = input; | |
41 | salaire = clean_float(input.val()) | |
42 | } | |
43 | if (input.attr('id').match('id_indemn*')) { | |
44 | indemn = clean_float(input.val()) | |
45 | } | |
46 | if (input.attr('id').match('id_autre*')) { | |
47 | autre = clean_float(input.val()) | |
48 | } | |
49 | ||
50 | }); | |
51 | ||
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 == "") | |
55 | valeur_point = 0; | |
56 | else | |
57 | valeur_point = clean_float(valeur_point_text.split(" ")[0]); | |
58 | ||
59 | salaire = clean_float(valeur_point * coeff); | |
60 | salaire_input.val(salaire); | |
61 | ||
62 | taux_euro = clean_float(ligne.find(".taux").html()) | |
63 | total = 0; | |
64 | total = salaire + indemn + autre; | |
65 | total_euro = total * taux_euro; | |
66 | ||
67 | ligne.find(".total-devise").text(total.toFixed(2)); | |
68 | ligne.find(".total-euro").text(total_euro.toFixed(2)); | |
69 | ||
70 | } | |
71 | ||
72 | /* recalcule tout le classement */ | |
73 | function recalculer_tout() { | |
74 | $("#classement tr *[name*=devise]").each(function() { | |
75 | recalculer_ligne($(this)); | |
76 | }); | |
77 | } | |
78 | ||
01191cd0 OL |
79 | /* stocker le texte par défaut à afficher */ |
80 | var note_duree_indeterminee = ""; | |
81 | ||
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; | |
89 | else { | |
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"; | |
94 | } | |
95 | $("#note-duree").html(note); | |
96 | } | |
97 | ||
25410b22 OL |
98 | $(document).ready(function() { |
99 | ||
100 | /* La fonctionnalité de présélection, est activé uniquement si aucune implantation n'a déjà été | |
101 | sélectionnée. | |
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); | |
107 | }); | |
108 | ||
109 | ||
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! | |
113 | ||
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() { | |
118 | var s = $(this); | |
119 | if (s.attr('id').match('id_devise*')) | |
120 | s.val(data.devise) | |
121 | ligne.find(".taux").text(data.taux_euro) | |
122 | ligne.find(".devise_code").text(data.devise_code) | |
123 | }); | |
124 | ||
125 | /* on synchronise les valeurs de points */ | |
126 | $('#id_valeur_point_min, #id_valeur_point_max').each(function() { | |
127 | var vp = $(this); | |
128 | if (vp.val() != vp_input.val()) { | |
129 | vp.val(vp_input.val()) | |
130 | } | |
131 | }); | |
132 | ||
989ec341 | 133 | recalculer_tout(); |
25410b22 OL |
134 | }); |
135 | chargement_devise.error(function(data) { | |
136 | alert(data.responseText); | |
137 | }); | |
138 | ||
139 | }); | |
140 | ||
141 | $('#id_devise_min, #id_devise_max').change(function(e) { | |
142 | var input = $(this); | |
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); | |
149 | }); | |
150 | chargement_devise.error(function(data) { | |
151 | alert(data.responseText); | |
152 | ligne.find(".taux").text(0) | |
153 | ligne.find(".devise_code").text("???") | |
154 | }); | |
155 | ||
156 | }); | |
157 | ||
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() { | |
165 | var input = $(this); | |
166 | if (input.attr('id').match('id_coefficient*')) | |
167 | input.val(data.coefficient); | |
168 | }); | |
169 | recalculer_ligne(classement); | |
170 | }); | |
171 | chargement_coeff.error(function(data){ | |
172 | }); | |
173 | }); | |
174 | ||
175 | /* refresh des totaux à chaque changement quelconque */ | |
176 | $('#classement input, #classement select').change(function() { | |
177 | recalculer_ligne($(this)); | |
178 | }); | |
179 | ||
180 | /* au chargement, on calcule tout */ | |
181 | recalculer_tout(); | |
182 | ||
01191cd0 OL |
183 | /* calcul de la différence en mois */ |
184 | $("#id_date_debut, #id_date_fin").focusout(function() { | |
185 | contrat_mois(); | |
186 | }); | |
187 | contrat_mois(); | |
188 | ||
25410b22 | 189 | }); |