import warnings
from django.core.urlresolvers import reverse
-from django.http import Http404, HttpResponse
+from django.http import Http404, HttpResponse, HttpResponseGone
from django.shortcuts import redirect, render_to_response, get_object_or_404
from django.template import RequestContext
devise = rh.Devise.objects.get(pk=devise)
annee = date.today().year
taux = rh.TauxChange.objects.filter(annee=annee, devise=devise)
+ if len(taux) == 0:
+ return HttpResponseGone("Le taux n'est pas disponible")
data['devise_code'] = devise.code
data['taux_euro'] = taux[0].taux
return HttpResponse(dumps(data))
/* string to float */
function clean_float(value){
- if (value == undefined)
+ if (isNaN(value) || value == undefined)
output = 0;
else
output = parseFloat(value);
function recalculer(element) {
var ligne = element.parents("tr");
- var inputs = ligne.find("input");
+ var inputs = ligne.find("input, select");
+ var salaire_input;
+ var valeur_point_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*'))
+ if (input.attr('id').match('id_coefficient*')) {
coeff = clean_float(input.val())
- if (input.attr('id').match('id_salaire*'))
+ }
+ if (input.attr('id').match('id_valeur_point*')) {
+ valeur_point_input = input;
+ }
+ if (input.attr('id').match('id_salaire*')) {
+ salaire_input = input;
salaire = clean_float(input.val())
- if (input.attr('id').match('id_indemn*'))
+ }
+ if (input.attr('id').match('id_indemn*')) {
indemn = clean_float(input.val())
- if (input.attr('id').match('id_autre*'))
+ }
+ if (input.attr('id').match('id_autre*')) {
autre = clean_float(input.val())
+ }
});
+ /* on suggère un salaire de base en fonction du coefficient et de la valeur du point */
+ valeur_point_text = valeur_point_input.find(":selected").text();
+ valeur_point = clean_float(valeur_point_text.split(" ")[0]);
+ if (valeur_point > 0 && coeff > 0) {
+ salaire = clean_float(valeur_point * coeff);
+ salaire_input.val(salaire);
+ }
+
taux_euro = clean_float(ligne.find(".taux").html())
total = 0;
total = salaire + indemn + autre;
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 chargement_devise = $.getJSON("/dae/devise", {'valeur_point': this.value});
+ chargement_devise.success(function(data) {
var selects = ligne.find("select");
selects.each(function() {
var s = $(this);
ligne.find(".taux").text(data.taux_euro)
ligne.find(".devise_code").text(data.devise_code)
});
+ recalculer(vp_input);
});
+ chargement_devise.error(function(data) {
+ });
+
});
$('#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){
+ var chargement_devise = $.getJSON("/dae/devise/code", {'devise': this.value});
+ chargement_devise.success(function(data) {
ligne.find(".taux").text(data.taux_euro)
ligne.find(".devise_code").text(data.devise_code)
+ recalculer(input);
+ });
+ chargement_devise.error(function(data) {
+ alert(data.responseText);
+ ligne.find(".taux").text(0)
+ ligne.find(".devise_code").text("???")
});
});
$('#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 chargement_coeff = $.getJSON("/dae/coefficient", {'classement': classement.val()});
+ chargement_coeff.success(function(data){
var inputs = ligne.find("input");
inputs.each(function() {
var input = $(this);
if (input.attr('id').match('id_coefficient*'))
input.val(data.coefficient);
- });
+ });
+ recalculer(classement);
+ });
+ chargement_coeff.error(function(data){
});
-
});
- $('#classement input').change(function() {
+ $('#classement input, #classement select').change(function() {
recalculer($(this));
});