mescole update

This commit is contained in:
2026-03-06 08:42:18 +01:00
parent 22e5b90fe4
commit 245750f057
10 changed files with 970 additions and 89 deletions
+403
View File
@@ -0,0 +1,403 @@
<?php include('include/headscript.php'); ?>
<!doctype html>
<html lang="it">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" href="assets/images/favicon-32x32.png" type="image/png" />
<?php include('cssinclude.php'); ?>
<title>Gestione Fornitori - <?= htmlspecialchars($titlewebsite, ENT_QUOTES, 'UTF-8'); ?></title>
<!-- jQuery e Bootstrap -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<!-- DataTables -->
<link rel="stylesheet" href="https://cdn.datatables.net/1.13.6/css/dataTables.bootstrap5.min.css">
<script src="https://cdn.datatables.net/1.13.6/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.13.6/js/dataTables.bootstrap5.min.js"></script>
<style>
body {
font-size: 1.05rem;
background: #f8fafc;
}
.card {
border-radius: 16px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}
.back-dashboard {
background-color: #cfe3ff !important;
color: #1f2d3d !important;
border: 1px solid #bcd4f4 !important;
border-radius: 10px;
font-weight: 600;
font-size: 1rem;
padding: 10px 18px;
box-shadow: 0 3px 8px rgba(0, 0, 0, 0.1);
transition: all 0.2s ease-in-out;
}
.back-dashboard:hover {
background-color: #b9d3ff !important;
transform: translateY(-2px);
}
.btn-add {
background-color: #0d6efd;
color: #fff;
border-radius: 8px;
padding: 10px 20px;
font-weight: 500;
transition: all 0.2s ease-in-out;
}
.btn-add:hover {
background-color: #0b5ed7;
transform: scale(1.02);
}
.table thead {
background-color: #cfe3ff;
color: #1f2d3d;
}
.modal-content {
border-radius: 16px;
}
#tabellaSuppliers thead th {
text-align: center;
vertical-align: middle;
}
/* FIX colonne lunghe */
#tabellaSuppliers {
table-layout: fixed;
width: 100% !important;
}
#tabellaSuppliers th,
#tabellaSuppliers td {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
/* ID piccolo */
#tabellaSuppliers th:nth-child(1),
#tabellaSuppliers td:nth-child(1) {
width: 80px;
max-width: 80px;
}
/* Supplier name */
#tabellaSuppliers th:nth-child(2),
#tabellaSuppliers td:nth-child(2) {
width: 360px;
max-width: 360px;
}
/* VAT */
#tabellaSuppliers th:nth-child(3),
#tabellaSuppliers td:nth-child(3) {
width: 220px;
max-width: 220px;
}
/* Actions */
#tabellaSuppliers th:nth-child(4),
#tabellaSuppliers td:nth-child(4) {
width: 220px;
max-width: 220px;
}
</style>
</head>
<body>
<div class="wrapper toggled">
<?php include('include/navbar.php'); ?>
<?php include('include/topbar.php'); ?>
<div class="page-wrapper">
<div class="page-content">
<div class="card p-3">
<div class="card-header d-flex justify-content-between align-items-center">
<h5 class="mb-0">Gestione Fornitori</h5>
<button type="button" class="btn back-dashboard" onclick="location.href='production_dashboard.php'">
↩️ Torna alla Dashboard
</button>
</div>
<div class="card-body">
<div class="d-flex justify-content-between align-items-center mb-3">
<h6 class="fw-semibold mb-0">Elenco Completo</h6>
<button class="btn btn-add" data-bs-toggle="modal" data-bs-target="#addSupplierModal">➕ Aggiungi Fornitore</button>
</div>
<div class="table-responsive">
<table id="tabellaSuppliers" class="table table-striped align-middle text-center" style="width:100%;">
<thead>
<tr>
<th>ID</th>
<th>Fornitore</th>
<th>P.IVA / VAT</th>
<th>Azioni</th>
</tr>
</thead>
<tbody>
<?php
$db = DBHandlerSelect::getInstance();
$pdo = $db->getConnection();
$sql = "SELECT idsupplier, supplier_name, vat FROM suppliers ORDER BY idsupplier DESC";
$stmt = $pdo->query($sql);
if ($stmt->rowCount() === 0) {
echo "<tr>
<td class='text-muted'>-</td>
<td class='text-muted'>Nessun fornitore presente</td>
<td class='text-muted'>-</td>
<td class='text-muted'>-</td>
</tr>";
} else {
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
echo "<tr>
<td>{$row['idsupplier']}</td>
<td>" . htmlspecialchars($row['supplier_name']) . "</td>
<td>" . htmlspecialchars($row['vat'] ?? '') . "</td>
<td>
<button class='btn btn-sm btn-outline-secondary edit-supplier'
data-id='{$row['idsupplier']}'
data-name='" . htmlspecialchars($row['supplier_name'], ENT_QUOTES) . "'
data-vat='" . htmlspecialchars($row['vat'] ?? '', ENT_QUOTES) . "'>
✏️ Modifica
</button>
<button class='btn btn-sm btn-outline-danger delete-supplier'
data-id='{$row['idsupplier']}'
data-name='" . htmlspecialchars($row['supplier_name'], ENT_QUOTES) . "'>
🗑️ Elimina
</button>
</td>
</tr>";
}
}
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<?php include('include/footer.php'); ?>
</div>
<!-- MODALE AGGIUNTA -->
<div class="modal fade" id="addSupplierModal" tabindex="-1">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header" style="background-color:#cfe3ff;">
<h5 class="modal-title">Aggiungi Nuovo Fornitore</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<form id="addSupplierForm">
<div class="mb-3">
<label class="form-label fw-semibold">Fornitore</label>
<input type="text" class="form-control" id="supplierName" required>
</div>
<div class="mb-3">
<label class="form-label fw-semibold">P.IVA / VAT</label>
<input type="text" class="form-control" id="supplierVat" placeholder="opzionale">
</div>
<div class="text-center">
<button type="submit" class="btn btn-add">💾 Salva</button>
</div>
</form>
</div>
</div>
</div>
</div>
<!-- MODALE EDIT -->
<div class="modal fade" id="editSupplierModal" tabindex="-1">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header" style="background-color:#cfe3ff;">
<h5 class="modal-title">Modifica Fornitore</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<form id="editSupplierForm">
<input type="hidden" id="editIdSupplier">
<div class="mb-3">
<label class="form-label fw-semibold">Fornitore</label>
<input type="text" class="form-control" id="editSupplierName" required>
</div>
<div class="mb-3">
<label class="form-label fw-semibold">P.IVA / VAT</label>
<input type="text" class="form-control" id="editSupplierVat" placeholder="opzionale">
</div>
<div class="text-center">
<button type="submit" class="btn btn-add">💾 Salva Modifiche</button>
</div>
</form>
</div>
</div>
</div>
</div>
<?php include('jsinclude.php'); ?>
<script>
/* ----------------- DATATABLE ----------------- */
$(document).ready(function() {
$('#tabellaSuppliers').DataTable({
order: [
[0, 'desc']
],
pageLength: 25,
language: {
url: 'https://cdn.datatables.net/plug-ins/1.13.6/i18n/it-IT.json'
}
});
});
/* -------- AGGIUNTA -------- */
$("#addSupplierForm").on("submit", function(e) {
e.preventDefault();
let supplier_name = $("#supplierName").val().trim();
let vat = $("#supplierVat").val().trim();
fetch("save_supplier.php", {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded"
},
body: `supplier_name=${encodeURIComponent(supplier_name)}&vat=${encodeURIComponent(vat)}`
})
.then(r => r.json())
.then(data => {
if (data.success) {
Swal.fire({
icon: "success",
title: "Salvato!",
confirmButtonColor: "#3085d6"
})
.then(() => location.reload());
} else {
Swal.fire({
icon: "error",
title: "Errore",
text: data.message || "Errore salvataggio"
});
}
});
});
/* -------- APERTURA MODALE EDIT -------- */
$(document).on("click", ".edit-supplier", function() {
$("#editIdSupplier").val($(this).data("id"));
$("#editSupplierName").val($(this).data("name"));
$("#editSupplierVat").val($(this).data("vat"));
$("#editSupplierModal").modal("show");
});
/* -------- SALVATAGGIO EDIT -------- */
$("#editSupplierForm").on("submit", function(e) {
e.preventDefault();
let idsupplier = $("#editIdSupplier").val();
let supplier_name = $("#editSupplierName").val().trim();
let vat = $("#editSupplierVat").val().trim();
fetch("update_supplier.php", {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded"
},
body: `idsupplier=${encodeURIComponent(idsupplier)}&supplier_name=${encodeURIComponent(supplier_name)}&vat=${encodeURIComponent(vat)}`
})
.then(r => r.json())
.then(data => {
if (data.success) {
Swal.fire({
icon: "success",
title: "Aggiornato!",
confirmButtonColor: "#3085d6"
})
.then(() => location.reload());
} else {
Swal.fire({
icon: "error",
title: "Errore",
text: data.message || "Errore aggiornamento"
});
}
});
});
/* -------- ELIMINA -------- */
$(document).on("click", ".delete-supplier", function() {
const idsupplier = $(this).data("id");
const name = $(this).data("name");
Swal.fire({
title: "Confermi eliminazione?",
text: `Fornitore: ${name}`,
icon: "warning",
showCancelButton: true,
confirmButtonText: "Sì, elimina",
cancelButtonText: "Annulla",
confirmButtonColor: "#d33"
}).then((result) => {
if (!result.isConfirmed) return;
fetch("delete_supplier.php", {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded"
},
body: `idsupplier=${encodeURIComponent(idsupplier)}`
})
.then(r => r.json())
.then(data => {
if (data.success) {
Swal.fire({
icon: "success",
title: "Eliminato!"
})
.then(() => location.reload());
} else {
Swal.fire({
icon: "error",
title: "Errore",
text: data.message || "Impossibile eliminare"
});
}
});
});
});
</script>
</body>
</html>