Commit | Line | Data |
---|---|---|
dfc31755 OL |
1 | /******************************************************************************* |
2 | * EMBAUCHE | |
3 | *******************************************************************************/ | |
66796c1f OL |
4 | function proposition_comparaison(devise_id) { |
5 | var chargement_devise = $.getJSON("/dae/devise/code", {'devise': devise_id}); | |
6 | chargement_devise.success(function(data) { | |
7 | var salaire = $("#id_salaire").val(); | |
8 | var montant = parseFloat(data.taux_euro) * parseFloat(salaire); | |
9 | $("#salaire-propose-euros").html(clean_float(montant)); | |
10 | }); | |
11 | chargement_devise.error(function(data) { | |
12 | alert(data.responseText); | |
13 | }); | |
14 | } | |
dfc31755 | 15 | |
179f6b49 OL |
16 | function activateDossierDropDowns() { |
17 | $('#id_classement, #id_devise').change(loadSalaire); | |
18 | } | |
19 | ||
20 | function loadSalaire() { | |
059d7fc3 | 21 | var implantation = $('#implantation').val(); |
a30962a4 | 22 | var devise = $('#id_devise').val(); |
059d7fc3 OL |
23 | var classement = $('#id_classement').val(); |
24 | if (implantation && devise && classement) { | |
25 | $.getJSON('/dae/salaire/' + implantation + '/' + devise + '/' + classement, | |
26 | function(data) { | |
27 | $('#id_salaire').val(clean_float(data.salaire_devise)); | |
28 | $('#id_salaire').trigger('change'); | |
29 | }); | |
30 | } | |
179f6b49 OL |
31 | } |
32 | ||
33 | function round2(n) { | |
34 | return Math.round(n * 100) / 100; | |
35 | } | |
36 | ||
5b1e3a13 | 37 | function remun_line(input) { |
0a085c42 OL |
38 | var idParts = input.attr('id').split('-'); |
39 | var prefix = idParts[0] + "-" + idParts[1]; | |
40 | var field = idParts[2]; | |
41 | ||
42 | var montant_mensuel = $('#' + prefix + '-montant_mensuel'); | |
43 | var montant_annuel = $('#' + prefix + '-montant'); | |
44 | var montant_mensuel_euros = $('#' + prefix + '-montant_mensuel_euros'); | |
45 | var montant_annuel_euros = $('#' + prefix + '-montant_annuel_euros'); | |
46 | ||
47 | /* auto calcul a besoin d'un type (autrement ca devient un champs requis)*/ | |
48 | if ($('#' + prefix + '-type').val() == '') { | |
49 | montant_mensuel.val(''); | |
50 | montant_annuel.val(''); | |
51 | montant_mensuel_euros.val(''); | |
52 | montant_annuel_euros.val(''); | |
53 | return; | |
54 | } | |
55 | ||
56 | if (input.attr('id') == montant_mensuel.attr('id') && montant_mensuel.val() != 0) { | |
57 | value = (montant_mensuel.val() * 12); | |
58 | } | |
59 | else { | |
60 | value = (montant_annuel.val()); | |
61 | } | |
3bb57906 | 62 | value = roundNumber(value, 2) |
0a085c42 | 63 | |
3bb57906 OL |
64 | montant_mensuel.val(roundNumber((value / 12), 2)); |
65 | montant_annuel.val(roundNumber(value, 0)); | |
0a085c42 OL |
66 | |
67 | var devise = $('#' + prefix + '-devise').val(); | |
68 | var taux = parseFloat(DEVISES[devise]); | |
69 | if (isNaN(taux)) taux = 0; | |
3bb57906 OL |
70 | montant_mensuel_euros.text(roundNumber((value / 12 * taux), 2)) |
71 | montant_annuel_euros.text(roundNumber((value * taux), 0)) | |
5b1e3a13 | 72 | |
5b1e3a13 OL |
73 | } |
74 | ||
57bd966c | 75 | function remun_totaux() { |
0a085c42 | 76 | $('#global-cost input[type="text"]').each(function() { |
5b1e3a13 OL |
77 | remun_line($(this)); |
78 | }); | |
79 | ||
57bd966c OL |
80 | var total_cout = 0; |
81 | $("tr.cout td.cumulable").each(function() { | |
82 | total_cout += clean_float($(this).html()); | |
83 | }); | |
84 | $("#sous-total-cout").html(total_cout); | |
85 | ||
86 | var total_aide = 0; | |
87 | $("tr.aide td.cumulable").each(function() { | |
88 | total_aide += clean_float($(this).html()); | |
89 | }); | |
90 | $("#sous-total-aide").html(total_aide); | |
91 | ||
10cdfb37 | 92 | var total = total_cout + total_aide; |
57bd966c OL |
93 | $("#remun-total").html(total); |
94 | ||
95 | } | |
96 | ||
179f6b49 OL |
97 | |
98 | activateDossierDropDowns(); | |
99 | ||
179f6b49 OL |
100 | /* Ajout des datespickers sur les inputs loadés via AJAX. |
101 | On s'assure qu'on est pas dans le cas initial où ils sont déjà ajoutés. | |
102 | (La façon dont c'est fait requiert que les inputs soient uniquement dans la partie AJAX).*/ | |
103 | function datepicker() { | |
104 | var date_pickers = $(".datetimeshortcuts"); | |
105 | if (date_pickers.length == 0) | |
106 | DateTimeShortcuts.init(); | |
107 | } | |
108 | ||
109 | function activateEmployeDropDown() { | |
110 | $('#id_employe').change(loadEmploye); | |
111 | } | |
112 | ||
113 | function loadEmploye() { | |
114 | var employeUrl = '/dae/employe/' + $(this).val(); | |
115 | $('#form-employe').html('<tr><td>Chargement...</td></tr>') | |
116 | .load(employeUrl, activateEmployeDropDown); | |
117 | var dossierUrl = '/dae/dossier/' + $('#poste').val() + | |
118 | '/' + $(this).val(); | |
119 | $('#form-dossier').html('<tr><td>Chargement...</td></tr>') | |
120 | .load(dossierUrl, function() { | |
121 | datepicker(); | |
122 | activateDossierDropDowns(); | |
72db8238 | 123 | $("#id_contrat_date_debut, #id_contrat_date_fin").focusout(function() {contrat_mois();}); |
179f6b49 OL |
124 | }); |
125 | } | |
126 | ||
dfc31755 | 127 | $(document).ready(function() { |
179f6b49 OL |
128 | |
129 | /* Lorsqu'on choisit un poste dans la liste on recharge la page avec le | |
130 | poste chargé dans la view (grâce à son id dans l'URL).*/ | |
131 | $('#id_poste').change(function() { | |
132 | window.location = '/dae/embauche/' + $(this).val(); | |
133 | }); | |
134 | ||
135 | /* on lance le JS au chargement de la page, la toute première fois, | |
136 | puis on cable le change au select pour le rechargement. */ | |
72db8238 | 137 | //loadEmploye(); |
179f6b49 OL |
138 | activateEmployeDropDown(); |
139 | ||
72db8238 OL |
140 | /* calcul de la différence en mois */ |
141 | $("#id_contrat_date_debut, #id_contrat_date_fin").focusout(function() { | |
142 | contrat_mois(); | |
143 | }); | |
144 | contrat_mois(); | |
145 | ||
5b1e3a13 | 146 | /* totaux remu */ |
0a085c42 | 147 | $('#global-cost input, #global-cost select').change(function() { |
5b1e3a13 | 148 | remun_line($(this)); |
a80286d4 | 149 | remun_totaux(); |
5b1e3a13 OL |
150 | }); |
151 | ||
057763bc | 152 | /* Ajouter une ligne aux couts globals */ |
0a085c42 | 153 | /*$('#type-remun').change(function() { |
58ad4beb | 154 | var dossier_id = $('#dossier').attr('dossier'); |
057763bc OL |
155 | if ($(this).val() != '') { |
156 | $('#global-cost').html('<tr><td>Chargement...</td></tr>') | |
157 | .load('/dae/add-remun/' + | |
58ad4beb | 158 | dossier_id + '/' + |
057763bc OL |
159 | $(this).val(), function() { |
160 | $('#type-remun').val(''); | |
161 | }); | |
162 | } | |
163 | }); | |
0a085c42 | 164 | */ |
57bd966c | 165 | remun_totaux(); |
057763bc | 166 | |
03b395db OL |
167 | /* Traitement de la recherche AJAX pour les dossiers de comparaison */ |
168 | $(".results_on_deck").bind('added', function() { | |
169 | ||
170 | /* récupération du choix dans la liste */ | |
171 | var input_id = $(this).attr('id').replace('_on_deck', ''); | |
172 | var prefix_dossier_connexe = $(this).attr('id').replace('recherche_on_deck', ''); | |
173 | var input = $('#'+input_id); | |
174 | var dossier_id = input.val(); | |
175 | ||
176 | /* interrogation par AJAX pour récupérer les données du dossier */ | |
177 | var chargement_dossier = $.getJSON("/dae/dossier_resume/" + dossier_id); | |
178 | chargement_dossier.success(function(data) { | |
179 | $('#' + prefix_dossier_connexe + 'implantation').val(data['implantation']); | |
0ebb99b3 OL |
180 | $('#' + prefix_dossier_connexe + 'classement').val(data['classement']); |
181 | $('#' + prefix_dossier_connexe + 'statut').val(data['statut']); | |
03b395db OL |
182 | $('#' + prefix_dossier_connexe + 'poste').val(data['poste']); |
183 | $('#' + prefix_dossier_connexe + 'personne').val(data['personne']); | |
184 | $('#' + prefix_dossier_connexe + 'montant').val(data['montant']); | |
185 | $('#' + prefix_dossier_connexe + 'devise').val(data['devise']); | |
186 | $('#' + prefix_dossier_connexe + 'montant_euros').val(data['montant_euros']); | |
187 | }); | |
188 | chargement_dossier.error(function(data) { | |
189 | alert(data.responseText); | |
190 | }); | |
191 | ||
192 | /* on ne veut pas afficher la personne en-dessous */ | |
193 | $(this).find('div').remove(); | |
194 | input.val(''); | |
195 | ||
196 | }); | |
057763bc | 197 | |
dfc31755 | 198 | }); |