257 lines
7.3 KiB
JavaScript
257 lines
7.3 KiB
JavaScript
$(document).ready(function () {
|
|
|
|
calcPrixTotalFrsF();
|
|
calcPrixTotalFrsHorsF();
|
|
updatePrixTotal();
|
|
/**
|
|
* 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();
|
|
updatePrixTotal();
|
|
}
|
|
})
|
|
|
|
|
|
/**
|
|
* 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('.btn').attr('id', 'frsSup-' + lastId)
|
|
|
|
var line = $('<tr id="fraisHf-' + lastId + '" data-id="" class="fraisHF"></tr>');
|
|
var tdDate = $('<th scope="row" id="dateFrsHF"></th>');
|
|
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')
|
|
|
|
date.val('')
|
|
libelle.val('')
|
|
montant.val('')
|
|
}
|
|
|
|
calcPrixTotalFrsHorsF();
|
|
updatePrixTotal();
|
|
})
|
|
})
|
|
|
|
/**
|
|
* Refus d'un frais HF pour un comptable
|
|
*/
|
|
$(document).on('click', '.btnRefuseFraisHf', function () {
|
|
idFrais = $(this).parent().parent().attr('data-id')
|
|
fiche = $('#idFiche').attr('data-id')
|
|
etatLigne = $(this).attr('data-status')
|
|
console.log(etatLigne)
|
|
//set on refus
|
|
$.ajax({
|
|
// url: "../controleurs/c_actionFiche.php?action=refusFraisHF&fiche=" + fiche + "&idFrais=" + idFrais + "&state=" + etatLigne,
|
|
url: "controleurs/c_actionFiche.php?action=refusFraisHF&fiche=" + fiche + "&idFrais=" + idFrais + "&state=" + etatLigne,
|
|
method: "POST",
|
|
}).done(function () {
|
|
location.reload();
|
|
})
|
|
})
|
|
/**
|
|
* Supprimer fraisHf
|
|
*/
|
|
$(document).on('click', '.btnSuprFraisHf', function () {
|
|
id = $(this).attr('id').split('-')[1]
|
|
fiche = $('#idFiche').attr('data-id')
|
|
idFrais = $(this).parent().parent().attr('data-id')
|
|
//SUPPRIME DE LA BD
|
|
$.ajax({
|
|
url: "controleurs/c_actionFiche.php?action=suprFraisHF&fiche=" + fiche + "&idFrais=" + idFrais,
|
|
// url: "../controleurs/c_actionFiche.php?action=suprFraisHF&fiche=" + fiche + "&idFrais=" + idFrais,
|
|
method: "POST",
|
|
})
|
|
|
|
$('#fraisHf-' + id).remove()
|
|
calcPrixTotalFrsHorsF();
|
|
updatePrixTotal();
|
|
})
|
|
|
|
/**
|
|
* PARTIE ENVOIE DE LA FICHE
|
|
*/
|
|
$(document).on('click', '#sendFileBtn', function () {
|
|
|
|
//FRAIS FORFAITAIRES
|
|
var listeFraisF = []
|
|
$('tr.fraisForfaitaire').each(function () {
|
|
quantite = parseInt($(this).find('.frsFrt').val())
|
|
montant = parseFloat($(this).find('.mttFrsTotal').html())
|
|
id = $(this).attr('data-id')
|
|
|
|
tabData = {
|
|
'quantité': quantite,
|
|
'montant': montant,
|
|
'id': id
|
|
}
|
|
listeFraisF.push(tabData);
|
|
})
|
|
|
|
//FRAIS HF
|
|
var listeFraisHf = []
|
|
$('tr.fraisHF').each(function () {
|
|
date = $(this).find('#dateFrsHF').html()
|
|
libelle = $(this).find('#LibelleFrsHF').html()
|
|
montant = parseFloat($(this).find('#MttFrsHF').html())
|
|
id = $(this).attr('data-id')
|
|
|
|
tabData = {
|
|
'date': date,
|
|
'libelle': libelle,
|
|
'montant': montant,
|
|
'id': id
|
|
}
|
|
listeFraisHf.push(tabData);
|
|
})
|
|
data = {
|
|
fraisF: listeFraisF,
|
|
fraisHF: listeFraisHf
|
|
}
|
|
fiche = $('#idFiche').attr('data-id')
|
|
|
|
$.ajax({
|
|
url: "controleurs/c_actionFiche.php?action=update&fiche=" + fiche,
|
|
// url: "../controleurs/c_actionFiche.php?action=update&fiche=" + fiche,
|
|
method: "POST",
|
|
data: data,
|
|
}).done(function () {
|
|
location.reload();
|
|
})
|
|
})
|
|
|
|
/**
|
|
* Partie Validation fiche par le comptable
|
|
*/
|
|
$(document).on('click', '#validSheetBtn', function () {
|
|
//FRAIS FORFAITAIRES
|
|
var listeFraisF = []
|
|
$('tr.fraisForfaitaire').each(function () {
|
|
quantite = parseInt($(this).find('.frsFrt').val())
|
|
montant = parseFloat($(this).find('.mttFrsTotal').html())
|
|
id = $(this).attr('data-id')
|
|
|
|
tabData = {
|
|
'quantité': quantite,
|
|
'montant': montant,
|
|
'id': id
|
|
}
|
|
listeFraisF.push(tabData);
|
|
})
|
|
|
|
nbFraisHf = $('tr.fraisHF').length
|
|
|
|
data = {
|
|
fraisF: listeFraisF,
|
|
nbJustif: nbFraisHf
|
|
}
|
|
fiche = $('#idFiche').attr('data-id')
|
|
|
|
$.ajax({
|
|
url: "controleurs/c_actionFiche.php?action=valid&fiche=" + fiche,
|
|
// url: "../controleurs/c_actionFiche.php?action=update&fiche=" + fiche,
|
|
method: "POST",
|
|
data: data,
|
|
}).done(function () {
|
|
location.reload();
|
|
})
|
|
|
|
});
|
|
|
|
/**
|
|
* Calcul prix total frais forfaitaires
|
|
*/
|
|
function calcPrixTotalFrsF() {
|
|
|
|
var prixTotal = 0;
|
|
$('td.mttFrsTotal').each(function () {
|
|
prixTotal += parseFloat($(this).html().replace('€', ''))
|
|
})
|
|
$('.prixTotalFrsF').html('<strong>TOTAL :</strong> ' + prixTotal.toFixed(2) + ' €')
|
|
$('.prixTotalFrsF').attr('data-prix', prixTotal.toFixed(2))
|
|
}
|
|
/**
|
|
* Calcul prix total frais hors forfait
|
|
*/
|
|
function calcPrixTotalFrsHorsF() {
|
|
|
|
console.log($('td#MttFrsHF').length)
|
|
|
|
// if ($('td#MttFrsHF').length == 0) {
|
|
// vf
|
|
// }
|
|
|
|
var prixTotal = 0;
|
|
$('td#MttFrsHF').each(function () {
|
|
prixTotal += parseFloat($(this).html().replace('€', ''))
|
|
})
|
|
$('#total-frais-HF').html('<strong>TOTAL :</strong> ' + prixTotal.toFixed(2) + ' €')
|
|
$('#total-frais-HF').attr('data-prix', prixTotal.toFixed(2))
|
|
}
|
|
/**
|
|
* Calcul prix total de la fiche
|
|
*/
|
|
function updatePrixTotal() {
|
|
var total = parseFloat($('#total-frais-HF').attr('data-prix'))
|
|
total += parseFloat($('.prixTotalFrsF').attr('data-prix'))
|
|
|
|
$('#total-fiche').html('<strong>TOTAL :</strong> ' + total.toFixed(2) + ' €')
|
|
} |