$(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 = $(''); var tdDate = $(''); tdDate.html(date.val()); var tdLibelle = $(''); tdLibelle.html(libelle.val()); var tdMtt = $(''); tdMtt.html(parseFloat(montant.val().replace(',', '.')).toFixed(2) + ' €'); var tdJust = $(''); var btn = $('') $(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('TOTAL : ' + prixTotal.toFixed(2) + ' €') }