110 lines
3.1 KiB
JavaScript
110 lines
3.1 KiB
JavaScript
$(document).ready(function () {
|
|
|
|
calcPrixTotalFrsF();
|
|
/**
|
|
* Partie enregistrement frais F
|
|
*/
|
|
$('.frsFrt').on('change', function (e) {
|
|
console.log($(this).val())
|
|
val = $(this).val();
|
|
val = val.replace(',', '.')
|
|
|
|
if ($.isNumeric(val)) {
|
|
/**
|
|
* Calcul le prix de la ligne
|
|
*/
|
|
id = $(this).attr('id')
|
|
formTotal = $('#totalFrs-' + id)
|
|
mttFrs = $('#mttFrs-' + id).attr('data-price')
|
|
formTotal.html((val * mttFrs).toFixed(2) + ' €');
|
|
|
|
calcPrixTotalFrsF();
|
|
}
|
|
})
|
|
|
|
|
|
/**
|
|
* Enregistrement frais HF
|
|
*/
|
|
$('.validFraisHF').on('click', function () {
|
|
let date = $('#dateHf')
|
|
let libelle = $('#libelleHf')
|
|
let montant = $('#mttHf')
|
|
let canAdd = true;
|
|
|
|
if (date.val() == "") {
|
|
canAdd = false;
|
|
date.css("border-color", "red")
|
|
} else {
|
|
date.css("border-color", "var(--bs-border-color)")
|
|
}
|
|
|
|
if (libelle.val() == "") {
|
|
canAdd = false;
|
|
libelle.css("border-color", "red")
|
|
} else {
|
|
libelle.css("border-color", "var(--bs-border-color)")
|
|
}
|
|
|
|
if (montant.val() == "") {
|
|
canAdd = false;
|
|
montant.css("border-color", "red")
|
|
} else {
|
|
montant.css("border-color", "var(--bs-border-color)")
|
|
}
|
|
|
|
if (canAdd == true) {
|
|
var line = $('tr.fraisHF:first').clone();
|
|
lastId = $('tr.fraisHF').length
|
|
/*
|
|
line.find("#dateFrsHF").html(date.val());
|
|
line.find("#LibelleFrsHF").html(libelle.val());
|
|
line.find("#MttFrsHF").html(parseFloat(montant.val()).toFixed(2) + ' €');
|
|
*/
|
|
|
|
line.find('.btn').attr('id', 'frsSup-' + lastId)
|
|
|
|
var line = $('<tr id="fraisHf-' + lastId + '" class="fraisHF"></tr>');
|
|
var tdDate = $('<td scope="row" id="dateFrsHF"></td>');
|
|
tdDate.html(date.val());
|
|
var tdLibelle = $('<td id="LibelleFrsHF"></td>');
|
|
tdLibelle.html(libelle.val());
|
|
var tdMtt = $('<td id="MttFrsHF"></td>');
|
|
tdMtt.html(parseFloat(montant.val().replace(',', '.')).toFixed(2) + ' €');
|
|
var tdJust = $('<td></td>');
|
|
var btn = $('<td><button type="button" class="btn btn-outline-primary btnSuprFraisHf" id="frsSup-' + lastId + '">Supprimer</button></td>')
|
|
|
|
$(line).append(tdDate)
|
|
$(line).append(tdLibelle)
|
|
$(line).append(tdMtt)
|
|
$(line).append(tdJust)
|
|
$(line).append(btn)
|
|
|
|
line.insertBefore('.newFraisForm')
|
|
}
|
|
})
|
|
|
|
|
|
})
|
|
|
|
/**
|
|
* Supprimer fraisHf
|
|
*/
|
|
$(document).on('click', '.btnSuprFraisHf', function () {
|
|
id = $(this).attr('id').split('-')[1]
|
|
console.log(id)
|
|
|
|
$('#fraisHf-' + id).remove()
|
|
})
|
|
|
|
/**
|
|
* Calcul prix total
|
|
*/
|
|
function calcPrixTotalFrsF() {
|
|
|
|
var prixTotal = 0;
|
|
$('td[id^="totalFrs-"]').each(function () {
|
|
prixTotal += parseFloat($(this).html().replace('€', ''))
|
|
})
|
|
$('.prixTotalFrsF').html('<strong>TOTAL :</strong> ' + prixTotal.toFixed(2) + ' €')
|
|
} |