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 OL |
21 | var implantation = $('#implantation').val(); |
22 | var devise = $('#implantation').val(); | |
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 OL |
37 | function remun_line(input) { |
38 | var idParts = input.attr('id').split('-'), | |
39 | name = idParts[0], | |
40 | id = idParts[1]; | |
41 | ||
42 | var montant_mensuel = $('#montant_mois-' + id); | |
43 | var montant_annuel = $('#montant-' + id); | |
44 | ||
45 | if (input.attr('id') == montant_mensuel.attr('id')) value = (montant_mensuel.val() * 12); | |
46 | if (input.attr('id') == montant_annuel.attr('id')) value = (montant_annuel.val()); | |
47 | ||
48 | montant_mensuel.val(round2(value / 12)); | |
49 | montant_annuel.val(round2(value)); | |
50 | ||
51 | var taux = $('#taux_devise-' + id).val(); | |
52 | $('#montant_euro_mois-' + id).text(clean_float(round2(value / 12 * taux))); | |
53 | $('#montant_euro-' + id).text(clean_float(round2(value * taux))); | |
54 | } | |
55 | ||
57bd966c | 56 | function remun_totaux() { |
5b1e3a13 OL |
57 | $('#global-cost input[id^="montant"]').each(function() { |
58 | remun_line($(this)); | |
59 | }); | |
60 | ||
57bd966c OL |
61 | var total_cout = 0; |
62 | $("tr.cout td.cumulable").each(function() { | |
63 | total_cout += clean_float($(this).html()); | |
64 | }); | |
65 | $("#sous-total-cout").html(total_cout); | |
66 | ||
67 | var total_aide = 0; | |
68 | $("tr.aide td.cumulable").each(function() { | |
69 | total_aide += clean_float($(this).html()); | |
70 | }); | |
71 | $("#sous-total-aide").html(total_aide); | |
72 | ||
10cdfb37 | 73 | var total = total_cout + total_aide; |
57bd966c OL |
74 | $("#remun-total").html(total); |
75 | ||
76 | } | |
77 | ||
179f6b49 OL |
78 | |
79 | activateDossierDropDowns(); | |
80 | ||
179f6b49 OL |
81 | /* Ajout des datespickers sur les inputs loadés via AJAX. |
82 | On s'assure qu'on est pas dans le cas initial où ils sont déjà ajoutés. | |
83 | (La façon dont c'est fait requiert que les inputs soient uniquement dans la partie AJAX).*/ | |
84 | function datepicker() { | |
85 | var date_pickers = $(".datetimeshortcuts"); | |
86 | if (date_pickers.length == 0) | |
87 | DateTimeShortcuts.init(); | |
88 | } | |
89 | ||
90 | function activateEmployeDropDown() { | |
91 | $('#id_employe').change(loadEmploye); | |
92 | } | |
93 | ||
94 | function loadEmploye() { | |
95 | var employeUrl = '/dae/employe/' + $(this).val(); | |
96 | $('#form-employe').html('<tr><td>Chargement...</td></tr>') | |
97 | .load(employeUrl, activateEmployeDropDown); | |
98 | var dossierUrl = '/dae/dossier/' + $('#poste').val() + | |
99 | '/' + $(this).val(); | |
100 | $('#form-dossier').html('<tr><td>Chargement...</td></tr>') | |
101 | .load(dossierUrl, function() { | |
102 | datepicker(); | |
103 | activateDossierDropDowns(); | |
72db8238 | 104 | $("#id_contrat_date_debut, #id_contrat_date_fin").focusout(function() {contrat_mois();}); |
179f6b49 OL |
105 | }); |
106 | } | |
107 | ||
dfc31755 | 108 | $(document).ready(function() { |
179f6b49 OL |
109 | |
110 | /* Lorsqu'on choisit un poste dans la liste on recharge la page avec le | |
111 | poste chargé dans la view (grâce à son id dans l'URL).*/ | |
112 | $('#id_poste').change(function() { | |
113 | window.location = '/dae/embauche/' + $(this).val(); | |
114 | }); | |
115 | ||
116 | /* on lance le JS au chargement de la page, la toute première fois, | |
117 | puis on cable le change au select pour le rechargement. */ | |
72db8238 | 118 | //loadEmploye(); |
179f6b49 OL |
119 | activateEmployeDropDown(); |
120 | ||
72db8238 OL |
121 | /* calcul de la différence en mois */ |
122 | $("#id_contrat_date_debut, #id_contrat_date_fin").focusout(function() { | |
123 | contrat_mois(); | |
124 | }); | |
125 | contrat_mois(); | |
126 | ||
5b1e3a13 OL |
127 | /* totaux remu */ |
128 | $('#global-cost input').change(function() { | |
129 | remun_line($(this)); | |
a80286d4 | 130 | remun_totaux(); |
5b1e3a13 OL |
131 | }); |
132 | ||
057763bc OL |
133 | /* Ajouter une ligne aux couts globals */ |
134 | $('#type-remun').change(function() { | |
135 | if ($(this).val() != '') { | |
136 | $('#global-cost').html('<tr><td>Chargement...</td></tr>') | |
137 | .load('/dae/add-remun/' + | |
138 | $('#dossier').val() + '/' + | |
139 | $(this).val(), function() { | |
140 | $('#type-remun').val(''); | |
141 | }); | |
142 | } | |
143 | }); | |
57bd966c | 144 | remun_totaux(); |
057763bc OL |
145 | |
146 | ||
dfc31755 | 147 | }); |