204 lines
6.6 KiB
JavaScript
204 lines
6.6 KiB
JavaScript
const $ = (id) => document.getElementById(id);
|
|
|
|
const table_demandes = new Tabulator("#demande_produit", {
|
|
layout:"fitColumns",
|
|
ajaxURL:`${$('demande_produit').dataset.url}`,
|
|
pagination: true,
|
|
paginationSize: 8,
|
|
columns:[
|
|
{title:"Libellé", field:"produit"},
|
|
{title:"Quantité", field:"quantite"},
|
|
{title:"A rendre", field:"a_rendre", formatter: "tickCross"},
|
|
],
|
|
});
|
|
|
|
table_demandes.on("rowClick", function(e, row){
|
|
let data = row.getData();
|
|
console.log("Data", data);
|
|
const modal = new bootstrap.Modal($('listeDemandesModal'));
|
|
$('produit').value = data.produit;
|
|
$("demandeur").value = data.demandeur;
|
|
$('quantite').value = data.quantite;
|
|
$('motifs').textContent = data.motifs;
|
|
$('date_demande').value = data.date_de_mise_a_dispo_souhaite;
|
|
$('a_rendre').checked = data.a_rendre ? true : false;
|
|
$('valider_par_chef').checked = data.valider_par_chef ? true : false;
|
|
$("radioRefuser").dataset.id = data.id_demande;
|
|
$("radioValider").dataset.id = data.id_demande;
|
|
|
|
$("radioRefuser").addEventListener("click", (e) =>{
|
|
$("box-motif-refus").classList.remove("d-none");
|
|
$("box-motif-refus").classList.add("d-block");
|
|
})
|
|
|
|
$("radioValider").addEventListener("click", (e) =>{
|
|
$("box-motif-refus").classList.remove("d-block");
|
|
$("box-motif-refus").classList.add("d-none");
|
|
})
|
|
|
|
if(data.is_logisticien){
|
|
modal.show();
|
|
}
|
|
});
|
|
|
|
const table_commande = new Tabulator("#commande_attentes", {
|
|
layout:"fitColumns",
|
|
ajaxURL:`${$('commande_attentes').dataset.url}`,
|
|
pagination: true,
|
|
paginationSize: 8,
|
|
columns:[
|
|
{title:"Libellé", field:"produit"},
|
|
{title:"Fournisseur", field:"fournisseur"},
|
|
{title:"Date de livraison", field:"date_livraison"},
|
|
],
|
|
});
|
|
|
|
const tableau_produit_rupture = new Tabulator("#tableau-produit-rupture", {
|
|
layout: "fitcolumns",
|
|
ajaxURL: `${$("tableau-produit-rupture").dataset.url}`,
|
|
ajaxParams: {
|
|
type: "rupture"
|
|
},
|
|
pagination: true,
|
|
paginationSize: 8,
|
|
columns: [
|
|
{title: "Libellé", field:"libelle"},
|
|
// {title: "Catégorie", field:"categorie"},
|
|
{title: "Conditionnement", field:"conditionnement"},
|
|
{title: "Quantité en stock", field:"stockActuel"},
|
|
]
|
|
})
|
|
|
|
$("produit_rupture").addEventListener("click", function () {
|
|
produitRuptureModal = new bootstrap.Modal($("produitRuptureModal"));
|
|
tableau_produit_rupture.setData(`${$("tableau-produit-rupture").dataset.url}`, {type: "rupture"})
|
|
$("produitRuptureModalLabel").innerHTML = "Produit en rupture"
|
|
produitRuptureModal.show();
|
|
})
|
|
|
|
$("produit_pre_rupture").addEventListener("click", function() {
|
|
produitRuptureModal = new bootstrap.Modal($("produitRuptureModal"));
|
|
tableau_produit_rupture.setData(`${$("tableau-produit-rupture").dataset.url}`, {type: "pre_rupture"})
|
|
$("produitRuptureModalLabel").innerHTML = "Produit en pré-rupture"
|
|
produitRuptureModal.show()
|
|
})
|
|
|
|
|
|
$("produit_normal").addEventListener("click", function() {
|
|
produitRuptureModal = new bootstrap.Modal($("produitRuptureModal"));
|
|
tableau_produit_rupture.setData(`${$("tableau-produit-rupture").dataset.url}`, {type: "normal"})
|
|
$("produitRuptureModalLabel").innerHTML = "Produit en quantité suffisante"
|
|
produitRuptureModal.show()
|
|
})
|
|
|
|
function updateStatut(demandeId, action, motifRefus='') {
|
|
const url = $("radioRefuser").dataset.url;
|
|
const csrf = document.querySelector('[name=csrfmiddlewaretoken]').value;
|
|
fetch(url, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
'X-Requested-With': 'XMLHttpRequest',
|
|
'X-CSRFToken': csrf
|
|
},
|
|
body: `id=${demandeId}&action=${action}&emetteur=logisticien&motif_refus=${motifRefus}`
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.success) {
|
|
alert(`Demande ${action} avec succès !`);
|
|
location.reload(); // recharge la page pour voir le nouveau statut
|
|
} else {
|
|
alert(data.message);
|
|
}
|
|
})
|
|
.catch(error => console.error('Erreur :', error));
|
|
}
|
|
|
|
$('enregistrerModifs').addEventListener('click', function () {
|
|
if($("radioRefuser").checked){
|
|
updateStatut(
|
|
$("radioRefuser").dataset.id,
|
|
'0',
|
|
$("motifs_refus").value
|
|
); // '0' pour refuser
|
|
}else{
|
|
updateStatut(
|
|
$("radioValider").dataset.id,
|
|
'1',
|
|
); // '1' pour confirmer
|
|
}
|
|
});
|
|
|
|
table_commande.on("rowClick", function(e, row){
|
|
let data = row.getData();
|
|
const modal = new bootstrap.Modal($('listeCommandesModal'));
|
|
$('produitCommande').value = data.produit;
|
|
$('fournisseur').value = data.fournisseur;
|
|
$('quantiteCommande').value = data.quantite;
|
|
$('date_commande').value = data.date_commande;
|
|
$('date_livraison').value = data.date_livraison;
|
|
|
|
$("enregistrerModifsCommande").dataset.id = data.id_commande;
|
|
|
|
if(data.is_logisticien){
|
|
modal.show();
|
|
}
|
|
});
|
|
|
|
$('enregistrerModifsCommande').addEventListener('click', function () {
|
|
const csrf = document.querySelector('[name=csrfmiddlewaretoken]').value;
|
|
if($("produit_livre").checked){
|
|
fetch(`${$("enregistrerModifsCommande").dataset.url}`, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
'X-CSRFToken': csrf
|
|
},
|
|
body: `id_commande=${$("enregistrerModifsCommande").dataset.id}`
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.status === "success") {
|
|
alert(data.message);
|
|
location.reload(); // recharge la page pour voir le nouveau statut
|
|
} else {
|
|
alert(data.message);
|
|
}
|
|
})
|
|
.catch(error => console.error('Erreur :', error));
|
|
}
|
|
});
|
|
|
|
const tableau_equipement_rendre = new Tabulator("#tableau-equipement-rendre", {
|
|
layout:"fitColumns",
|
|
ajaxURL: `${$("tableau-equipement-rendre").dataset.url}`,
|
|
pagination: true,
|
|
paginationSize: 8,
|
|
columns:[
|
|
{title:"Libellé", field:"produit"},
|
|
{title:"Quantite", field:"quantite"},
|
|
{title:"Detenteur", field:"detenteur"},
|
|
// {title:"Departement", field:"detenteur"},
|
|
{title:"Rendu", field:"action", formatter:"tickCross", editor: true},
|
|
],
|
|
})
|
|
|
|
$("equipementARendreEnregistrer").addEventListener("click", function () {
|
|
const information_equipement = tableau_equipement_rendre.getData();
|
|
const csrf = document.querySelector('[name=csrfmiddlewaretoken]').value;
|
|
fetch(`${$("equipementARendreEnregistrer").dataset.url}`, {
|
|
method: "POST",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
"X-CSRFToken": csrf
|
|
},
|
|
body: JSON.stringify(information_equipement)
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
tableau_equipement_rendre.setData("/equipement-a-rendre");
|
|
// tableau_equipement_rendre.clearEditedData();
|
|
})
|
|
.catch(error => console.error(error))
|
|
}) |