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