fixed update fornitore

This commit is contained in:
2026-04-01 14:57:20 +02:00
parent 1b23885659
commit d39e997beb
2 changed files with 197 additions and 29 deletions
+53 -29
View File
@@ -650,17 +650,23 @@
$("#afCancelEdit").hide();
}
function afLoadSuppliers() {
function afLoadSuppliers(selectedId = "") {
return fetch("get_suppliers.php")
.then(r => r.json())
.then(data => {
const sel = $("#afIdSupplier");
if (sel.hasClass("select2-hidden-accessible")) {
sel.select2("destroy");
}
sel.empty();
sel.append(`<option value="">Seleziona...</option>`);
if (data.success && Array.isArray(data.rows)) {
data.rows.forEach(s => {
sel.append(`<option value="${s.idsupplier}">${s.supplier_name}</option>`);
const value = String(s.idsupplier);
sel.append(`<option value="${value}">${s.supplier_name}</option>`);
});
}
@@ -669,6 +675,12 @@
width: "100%",
dropdownParent: $("#associaFornitoriModal")
});
if (selectedId !== "") {
sel.val(String(selectedId)).trigger("change");
} else {
sel.val("").trigger("change");
}
});
}
@@ -694,25 +706,26 @@
data.rows.forEach(row => {
const exp = row.expiry_date ? row.expiry_date : "";
const supplierId = String(row.idsupplier ?? "");
tbody.append(`
<tr>
<td>${row.id}</td>
<td>${row.supplier_name}</td>
<td>${row.supplier_mix_name}</td>
<td>${row.lot_code ?? ""}</td>
<td>${exp}</td>
<td>${row.qty}</td>
<td>
<button class="btn btn-sm btn-outline-secondary af-edit"
data-id="${row.id}"
data-idsupplier="${row.idsupplier}"
data-mix="${String(row.supplier_mix_name).replace(/"/g, '&quot;')}"
data-lot="${String(row.lot_code ?? '').replace(/"/g, '&quot;')}"
data-exp="${exp}"
data-qty="${row.qty}">
✏️
</button>
<button class="btn btn-sm btn-outline-danger af-del" data-id="${row.id}">🗑️</button>
<tr>
<td>${row.id}</td>
<td>${row.supplier_name}</td>
<td>${row.supplier_mix_name}</td>
<td>${row.lot_code ?? ""}</td>
<td>${exp}</td>
<td>${row.qty}</td>
<td>
<button type="button" class="btn btn-sm btn-outline-secondary af-edit"
data-id="${row.id}"
data-idsupplier="${supplierId}"
data-mix="${String(row.supplier_mix_name).replace(/"/g, '&quot;')}"
data-lot="${String(row.lot_code ?? '').replace(/"/g, '&quot;')}"
data-exp="${exp}"
data-qty="${row.qty}">
✏️
</button>
<button type="button" class="btn btn-sm btn-outline-danger af-del" data-id="${row.id}">🗑️</button>
</td>
</tr>
`);
@@ -728,19 +741,30 @@
$("#afIdMescola").val(idMescola);
$("#afNomeUscita").text(nomeUscita);
$("#associaFornitoriModal").modal("show");
afResetForm();
afLoadSuppliers().then(() => afLoadRows(idMescola));
afLoadSuppliers("")
.then(() => {
$("#associaFornitoriModal").modal("show");
afLoadRows(idMescola);
});
});
// Edit row in modal
$(document).on("click", ".af-edit", function() {
$("#afEditId").val($(this).data("id"));
$("#afIdSupplier").val(String($(this).data("idsupplier"))).trigger("change");
$("#afSupplierMixName").val($(this).data("mix"));
$("#afLotCode").val($(this).data("lot"));
$("#afExpiryDate").val($(this).data("exp"));
$("#afQty").val($(this).data("qty"));
const editId = $(this).attr("data-id");
const supplierId = $(this).attr("data-idsupplier");
const mix = $(this).attr("data-mix");
const lot = $(this).attr("data-lot");
const exp = $(this).attr("data-exp");
const qty = $(this).attr("data-qty");
$("#afEditId").val(editId);
$("#afIdSupplier").val(String(supplierId)).trigger("change");
$("#afSupplierMixName").val(mix);
$("#afLotCode").val(lot);
$("#afExpiryDate").val(exp);
$("#afQty").val(qty);
$("#afSaveBtn").text("💾 Salva Modifica");
$("#afCancelEdit").show();
@@ -757,7 +781,7 @@
const idmescola = $("#afIdMescola").val();
const editId = $("#afEditId").val();
const idsupplier = $("#afIdSupplier").val();
const idsupplier = String($("#afIdSupplier").val() || "").trim();
const supplier_mix_name = $("#afSupplierMixName").val().trim();
const lot_code = $("#afLotCode").val().trim();
const expiry_date = $("#afExpiryDate").val();