{{ form.media }}
+ <script src="{{ MEDIA_URL }}js/dae.js" /></script>
+
<link href="{{ MEDIA_URL }}/css/redmond/jquery-ui-1.8.11.custom.css"
rel="stylesheet" />
<fieldset>
<h2>Classement du poste</h2>
- <table>
+ <table id="classement">
<tbody>
<tr>
<th></th>
{{ form.coefficient_min.errors }}
</td>
<td>
- {{ form.valeur_point_min }}
+ {{ form.valeur_point_min }}<span class="valeur-point"></span>
{{ form.valeur_point_min.errors }}
</td>
<td>
{{ form.salaire_min }}
{{ form.salaire_min.errors }}
</td>
- <td><span class="devise_min_code">EUR</span></td>
+ <td><span class="devise_code">EUR</span></td>
<td>{{ form.indemn_min }}</td>
- <td><span class="devise_min_code">EUR</span></td>
+ <td><span class="devise_code">EUR</span></td>
<td>{{ form.autre_min }}</td>
- <td><span class="devise_min_code">EUR</span></td>
- <td id="total_min" class="cell-nombre">0.00</td>
- <td><span class="devise_min_code">EUR</span></td>
- <td id="taux_min_euro_display">1</td>
- <td id="total_min_euro" class="cell-nombre">0.00</td>
+ <td><span class="devise_code">EUR</span></td>
+ <td id="total_min" class="total-devise cell-nombre">0.00</td>
+ <td><span class="devise_code">EUR</span></td>
+ <td class="taux">1</td>
+ <td id="total_min_euro" class="total-euro cell-nombre">0.00</td>
<td>€</td>
</tr>
<tr>
{{ form.coefficient_max.errors }}
</td>
<td>
- {{ form.valeur_point_max }}
+ {{ form.valeur_point_max }}<span class="valeur-point"></span>
{{ form.valeur_point_max.errors }}
</td>
<td>
{{ form.salaire_max }}
{{ form.salaire_max.errors }}
</td>
- <td><span class="devise_max_code">EUR</span></td>
+ <td><span class="devise_code">EUR</span></td>
<td>{{ form.indemn_max }}</td>
- <td><span class="devise_max_code">EUR</span></td>
+ <td><span class="devise_code">EUR</span></td>
<td>{{ form.autre_max }}</td>
- <td><span class="devise_max_code">EUR</span></td>
- <td id="total_max" class="cell-nombre">0.00</td>
- <td><span class="devise_max_code">EUR</span></td>
- <td id="taux_max_euro_display">1</td>
- <td id="total_max_euro" class="cell-nombre">0.00</td>
+ <td><span class="devise_code">EUR</span></td>
+ <td id="total_max" class="total-devise cell-nombre">0.00</td>
+ <td><span class="devise_code">EUR</span></td>
+ <td class="taux">1</td>
+ <td id="total_max_euro" class="total-euro cell-nombre">0.00</td>
<td>€</td>
</tr>
</tbody>
});
/* CLASSEMENT MIN */
+ {% comment %}
$(document).ready(function() {
valeur_min = '<input type="hidden" id="valeur_min" name="valeur_min" value="0" disabled="disabled">'
devise_min_code = '<input type="hidden" id="devise_min_code" name="devise_min_code" value="EUR" disabled="disabled">'
output = Math.round(output*100)/100;
return output;
}
+ {% endcomment %}
</script>
{% endblock %}
url(r'^salaire$', 'salaire', name='salaire'),
url(r'^salaire/(.*)/(.*)/(.*)$', 'salaire', name='salaire'),
url(r'^coefficient$', 'coefficient', name='dae_coefficient'),
- url(r'^valeur$', 'valeur', name='dae_valeur'),
+ url(r'^liste_valeurs_point$', 'liste_valeurs_point', name='liste_valeurs_point'),
url(r'^devise$', 'devise', name='dae_devise'),
url(r'^devise/code$', 'devise_code', name='dae_devise_code'),
url(r'^add-remun$', 'add_remun', name='add_remun'),
# -*- encoding: utf-8 -*-
+
+import datetime
from collections import defaultdict
from datetime import date
from simplejson import dumps
input : classement
output : coefficient
"""
+ method = request.method
+ params = getattr(request, method, [])
data = dict()
- if request.POST and 'classement' in request.POST:
- classement = request.POST.get('classement')
+ if 'classement' in params:
+ classement = params.get('classement')
classement = rh.Classement.objects.get(pk=classement)
data['coefficient'] = classement.coefficient
return HttpResponse(dumps(data))
-def valeur(request):
+
+def liste_valeurs_point(request):
""" Appel AJAX :
- input : valeur_point
- output : valeur
+ input : implantation_id
+ output : JSON liste de valeur point
"""
- data = dict()
- if request.POST and 'valeur_point' in request.POST:
- valeur_point = request.POST.get('valeur_point')
- valeur_point = rh.ValeurPoint.objects.get(pk=valeur_point)
- data['valeur'] = valeur_point.valeur
+ method = request.method
+ params = getattr(request, method, [])
+ data = []
+ annee_courante = datetime.datetime.now().year
+ if 'implantation_id' in params and params.get('implantation_id') is not u"":
+ implantation_id = params.get('implantation_id')
+ objects = rh.ValeurPoint.objects.filter(implantation=implantation_id, annee__in=(annee_courante-1, annee_courante)).order_by("-annee")
+ else:
+ objects = rh.ValeurPoint.objects.filter(annee__in=(annee_courante-1, annee_courante)).order_by("-annee")
+ for o in objects:
+ data.append({'id' : o.id, 'label' : o.__unicode__(), })
return HttpResponse(dumps(data))
-
+
def devise(request):
""" Appel AJAX :
input : valeur_point
output : devise, devise_code, taux_euro
"""
+ method = request.method
+ params = getattr(request, method, [])
data = dict()
- if request.POST and 'valeur_point' in request.POST:
- valeur_point = request.POST.get('valeur_point')
+ if 'valeur_point' in params and params.get('valeur_point') is not u"":
+ valeur_point = params.get('valeur_point')
valeur_point = rh.ValeurPoint.objects.get(pk=valeur_point)
annee = valeur_point.annee
implantation = valeur_point.implantation
taux = rh.TauxChange.objects.get(annee=annee,
implantation=implantation)
data['devise'] = taux.devise.id
+ data['valeur'] = valeur_point.valeur
data['devise_code'] = taux.devise.code
data['taux_euro'] = taux.taux
return HttpResponse(dumps(data))
input : devise
output : devise_code, taux_euro
"""
+ method = request.method
+ params = getattr(request, method, [])
data = dict()
- if request.POST and 'devise' in request.POST:
- devise = request.POST.get('devise')
+ if 'devise' in params:
+ devise = params.get('devise')
devise = rh.Devise.objects.get(pk=devise)
annee = date.today().year
taux = rh.TauxChange.objects.filter(annee=annee, devise=devise)
--- /dev/null
+/* string to float */
+function clean_float(value){
+ if (value == undefined)
+ output = 0;
+ else
+ output = parseFloat(value);
+ output = Math.round(output*100)/100;
+ return output;
+}
+
+function charger_valeurs_point(implantation_id) {
+ var params = {'implantation_id' : implantation_id};
+ $.getJSON('/dae/liste_valeurs_point', params, function(data) {
+ var items = [];
+
+ var options = "";
+ $.each(data, function() {
+ options += '<option value="' + this.id + '">' + this.label + '</option>';
+ });
+
+ $("#id_valeur_point_min").html(options);
+ $("#id_valeur_point_max").html(options);
+ });
+}
+
+function recalculer(element) {
+ var ligne = element.parents("tr");
+ var inputs = ligne.find("input");
+ inputs.each(function() {
+ var input = $(this);
+ /*
+ console.log(input.attr('id'))
+ id_coefficient_min
+ valeur_min
+ devise_min_code
+ id_salaire_min
+ id_indemn_min
+ id_autre_min
+ taux_min_euro
+ */
+ if (input.attr('id').match('id_coefficient*'))
+ coeff = clean_float(input.val())
+ if (input.attr('id').match('id_salaire*'))
+ salaire = clean_float(input.val())
+ if (input.attr('id').match('id_indemn*'))
+ indemn = clean_float(input.val())
+ if (input.attr('id').match('id_autre*'))
+ autre = clean_float(input.val())
+
+ });
+
+ taux_euro = clean_float(ligne.find(".taux").html())
+ total = 0;
+ total = salaire + indemn + autre;
+ total_euro = total * taux_euro;
+
+ ligne.find(".total-devise").text(total.toFixed(2));
+ ligne.find(".total-euro").text(total_euro.toFixed(2));
+
+}
+
+$(document).ready(function() {
+
+ /* La fonctionnalité de présélection, est activé uniquement si aucune implantation n'a déjà été
+ sélectionnée.
+ Lorsque l'implantation est changée, on ajuste les valeurs de points en fonction de cette
+ sélection, UNIQUEMENT si aucune valeur n'est encore définie. */
+ var implantation_id = $("#id_implantation").val();
+ if (implantation_id == "") {
+
+ $("#id_implantation").change(function() {
+ var implantation_id = this.value;
+ charger_valeurs_point(implantation_id);
+ });
+ }
+
+
+ $('#id_valeur_point_min, #id_valeur_point_max').change(function(e) {
+ var vp_input = $(this);
+ var ligne = vp_input.parents("tr");
+
+ $.getJSON("/dae/devise", {'valeur_point': this.value}, function(data){
+ ligne.find(".valeur-point").text(data.valeur)
+ var selects = ligne.find("select");
+ selects.each(function() {
+ var s = $(this);
+ if (s.attr('id').match('id_devise*'))
+ s.val(data.devise)
+ ligne.find(".taux").text(data.taux_euro)
+ ligne.find(".devise_code").text(data.devise_code)
+ });
+ });
+ });
+
+ $('#id_devise_min, #id_devise_max').change(function(e) {
+ var input = $(this);
+ var ligne = input.parents("tr");
+ $.getJSON("/dae/devise/code", {'devise': this.value}, function(data){
+ ligne.find(".taux").text(data.taux_euro)
+ ligne.find(".devise_code").text(data.devise_code)
+ });
+
+ });
+
+ $('#id_classement_min, #id_classement_max').change(function(e) {
+ var classement = $(this);
+ var ligne = classement.parents("tr");
+ $.getJSON("/dae/coefficient", {'classement': classement.val()}, function(data){
+ var inputs = ligne.find("input");
+ inputs.each(function() {
+ var input = $(this);
+ if (input.attr('id').match('id_coefficient*'))
+ input.val(data.coefficient);
+ });
+ });
+
+ });
+
+
+ $('#classement input').change(function() {
+ recalculer($(this));
+ });
+
+});