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