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]); | |
378ffe6c OL |
69 | console.log(prefix); |
70 | console.log(devise); | |
71 | console.log(DEVISES); | |
72 | console.log(taux); | |
0a085c42 | 73 | if (isNaN(taux)) taux = 0; |
3bb57906 OL |
74 | montant_mensuel_euros.text(roundNumber((value / 12 * taux), 2)) |
75 | montant_annuel_euros.text(roundNumber((value * taux), 0)) | |
5b1e3a13 | 76 | |
5b1e3a13 OL |
77 | } |
78 | ||
57bd966c | 79 | function remun_totaux() { |
0a085c42 | 80 | $('#global-cost input[type="text"]').each(function() { |
5b1e3a13 OL |
81 | remun_line($(this)); |
82 | }); | |
83 | ||
57bd966c OL |
84 | var total_cout = 0; |
85 | $("tr.cout td.cumulable").each(function() { | |
86 | total_cout += clean_float($(this).html()); | |
87 | }); | |
88 | $("#sous-total-cout").html(total_cout); | |
89 | ||
90 | var total_aide = 0; | |
91 | $("tr.aide td.cumulable").each(function() { | |
92 | total_aide += clean_float($(this).html()); | |
93 | }); | |
94 | $("#sous-total-aide").html(total_aide); | |
95 | ||
10cdfb37 | 96 | var total = total_cout + total_aide; |
57bd966c OL |
97 | $("#remun-total").html(total); |
98 | ||
99 | } | |
100 | ||
179f6b49 OL |
101 | |
102 | activateDossierDropDowns(); | |
103 | ||
179f6b49 OL |
104 | /* Ajout des datespickers sur les inputs loadés via AJAX. |
105 | On s'assure qu'on est pas dans le cas initial où ils sont déjà ajoutés. | |
106 | (La façon dont c'est fait requiert que les inputs soient uniquement dans la partie AJAX).*/ | |
107 | function datepicker() { | |
108 | var date_pickers = $(".datetimeshortcuts"); | |
109 | if (date_pickers.length == 0) | |
110 | DateTimeShortcuts.init(); | |
111 | } | |
112 | ||
113 | function activateEmployeDropDown() { | |
114 | $('#id_employe').change(loadEmploye); | |
115 | } | |
116 | ||
117 | function loadEmploye() { | |
118 | var employeUrl = '/dae/employe/' + $(this).val(); | |
119 | $('#form-employe').html('<tr><td>Chargement...</td></tr>') | |
120 | .load(employeUrl, activateEmployeDropDown); | |
121 | var dossierUrl = '/dae/dossier/' + $('#poste').val() + | |
122 | '/' + $(this).val(); | |
123 | $('#form-dossier').html('<tr><td>Chargement...</td></tr>') | |
124 | .load(dossierUrl, function() { | |
125 | datepicker(); | |
126 | activateDossierDropDowns(); | |
72db8238 | 127 | $("#id_contrat_date_debut, #id_contrat_date_fin").focusout(function() {contrat_mois();}); |
179f6b49 OL |
128 | }); |
129 | } | |
130 | ||
dfc31755 | 131 | $(document).ready(function() { |
179f6b49 OL |
132 | |
133 | /* Lorsqu'on choisit un poste dans la liste on recharge la page avec le | |
134 | poste chargé dans la view (grâce à son id dans l'URL).*/ | |
135 | $('#id_poste').change(function() { | |
136 | window.location = '/dae/embauche/' + $(this).val(); | |
137 | }); | |
138 | ||
139 | /* on lance le JS au chargement de la page, la toute première fois, | |
140 | puis on cable le change au select pour le rechargement. */ | |
72db8238 | 141 | //loadEmploye(); |
179f6b49 OL |
142 | activateEmployeDropDown(); |
143 | ||
72db8238 OL |
144 | /* calcul de la différence en mois */ |
145 | $("#id_contrat_date_debut, #id_contrat_date_fin").focusout(function() { | |
146 | contrat_mois(); | |
147 | }); | |
148 | contrat_mois(); | |
149 | ||
5b1e3a13 | 150 | /* totaux remu */ |
0a085c42 | 151 | $('#global-cost input, #global-cost select').change(function() { |
5b1e3a13 | 152 | remun_line($(this)); |
a80286d4 | 153 | remun_totaux(); |
5b1e3a13 OL |
154 | }); |
155 | ||
057763bc | 156 | /* Ajouter une ligne aux couts globals */ |
0a085c42 | 157 | /*$('#type-remun').change(function() { |
58ad4beb | 158 | var dossier_id = $('#dossier').attr('dossier'); |
057763bc OL |
159 | if ($(this).val() != '') { |
160 | $('#global-cost').html('<tr><td>Chargement...</td></tr>') | |
161 | .load('/dae/add-remun/' + | |
58ad4beb | 162 | dossier_id + '/' + |
057763bc OL |
163 | $(this).val(), function() { |
164 | $('#type-remun').val(''); | |
165 | }); | |
166 | } | |
167 | }); | |
0a085c42 | 168 | */ |
57bd966c | 169 | remun_totaux(); |
057763bc | 170 | |
03b395db OL |
171 | /* Traitement de la recherche AJAX pour les dossiers de comparaison */ |
172 | $(".results_on_deck").bind('added', function() { | |
173 | ||
174 | /* récupération du choix dans la liste */ | |
175 | var input_id = $(this).attr('id').replace('_on_deck', ''); | |
176 | var prefix_dossier_connexe = $(this).attr('id').replace('recherche_on_deck', ''); | |
177 | var input = $('#'+input_id); | |
178 | var dossier_id = input.val(); | |
179 | ||
180 | /* interrogation par AJAX pour récupérer les données du dossier */ | |
181 | var chargement_dossier = $.getJSON("/dae/dossier_resume/" + dossier_id); | |
182 | chargement_dossier.success(function(data) { | |
183 | $('#' + prefix_dossier_connexe + 'implantation').val(data['implantation']); | |
0ebb99b3 OL |
184 | $('#' + prefix_dossier_connexe + 'classement').val(data['classement']); |
185 | $('#' + prefix_dossier_connexe + 'statut').val(data['statut']); | |
03b395db OL |
186 | $('#' + prefix_dossier_connexe + 'poste').val(data['poste']); |
187 | $('#' + prefix_dossier_connexe + 'personne').val(data['personne']); | |
188 | $('#' + prefix_dossier_connexe + 'montant').val(data['montant']); | |
189 | $('#' + prefix_dossier_connexe + 'devise').val(data['devise']); | |
190 | $('#' + prefix_dossier_connexe + 'montant_euros').val(data['montant_euros']); | |
191 | }); | |
192 | chargement_dossier.error(function(data) { | |
193 | alert(data.responseText); | |
194 | }); | |
195 | ||
196 | /* on ne veut pas afficher la personne en-dessous */ | |
197 | $(this).find('div').remove(); | |
198 | input.val(''); | |
199 | ||
200 | }); | |
057763bc | 201 | |
dfc31755 | 202 | }); |