mescole update
This commit is contained in:
parent
22e5b90fe4
commit
245750f057
17
public/userarea/delete_mescola_supplier_lot.php
Normal file
17
public/userarea/delete_mescola_supplier_lot.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
include('include/headscript.php');
|
||||
header('Content-Type: application/json');
|
||||
|
||||
$id = isset($_POST['id']) ? (int)$_POST['id'] : 0;
|
||||
if ($id <= 0) {
|
||||
echo json_encode(['success' => false, 'message' => 'Invalid id']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$db = DBHandlerSelect::getInstance();
|
||||
$pdo = $db->getConnection();
|
||||
|
||||
$stmt = $pdo->prepare("DELETE FROM mescole_supplier_lots WHERE id = ?");
|
||||
$ok = $stmt->execute([$id]);
|
||||
|
||||
echo json_encode(['success' => (bool)$ok]);
|
||||
30
public/userarea/get_mescola_supplier_lots.php
Normal file
30
public/userarea/get_mescola_supplier_lots.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
include('include/headscript.php');
|
||||
header('Content-Type: application/json');
|
||||
|
||||
$id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
|
||||
if ($id <= 0) {
|
||||
echo json_encode(['success' => false, 'message' => 'Invalid id']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$db = DBHandlerSelect::getInstance();
|
||||
$pdo = $db->getConnection();
|
||||
|
||||
$sql = "SELECT
|
||||
msl.id,
|
||||
s.supplier_name,
|
||||
msl.supplier_mix_name,
|
||||
msl.lot_code,
|
||||
msl.expiry_date,
|
||||
msl.qty
|
||||
FROM mescole_supplier_lots msl
|
||||
INNER JOIN suppliers s ON s.idsupplier = msl.idsupplier
|
||||
WHERE msl.idmescola = ?
|
||||
ORDER BY msl.id DESC";
|
||||
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute([$id]);
|
||||
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
echo json_encode(['success' => true, 'rows' => $rows]);
|
||||
11
public/userarea/get_suppliers.php
Normal file
11
public/userarea/get_suppliers.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
include('include/headscript.php');
|
||||
header('Content-Type: application/json');
|
||||
|
||||
$db = DBHandlerSelect::getInstance();
|
||||
$pdo = $db->getConnection();
|
||||
|
||||
$stmt = $pdo->query("SELECT idsupplier, supplier_name FROM suppliers ORDER BY supplier_name ASC");
|
||||
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
echo json_encode(['success' => true, 'rows' => $rows]);
|
||||
@ -313,6 +313,27 @@ $matrici = $pdo->query("
|
||||
ORDER BY nome ASC
|
||||
")->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
// Load worksheet lookup options
|
||||
$lookup = [];
|
||||
$lookupDefault = [];
|
||||
|
||||
$stmt = $pdo->prepare("
|
||||
SELECT category, value, label, is_default
|
||||
FROM ws_lookup_options
|
||||
WHERE is_active = 1
|
||||
ORDER BY category ASC, sort_order ASC, label ASC
|
||||
");
|
||||
$stmt->execute();
|
||||
|
||||
foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $r) {
|
||||
$lookup[$r['category']][] = $r;
|
||||
|
||||
if ((int)$r['is_default'] === 1 && !isset($lookupDefault[$r['category']])) {
|
||||
$lookupDefault[$r['category']] = $r['value'];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Load mescole dropdown for modal
|
||||
$mescole = $pdo->query("
|
||||
SELECT id, nome, nomeuscita
|
||||
@ -357,6 +378,26 @@ function h($v)
|
||||
{
|
||||
return htmlspecialchars((string)$v, ENT_QUOTES);
|
||||
}
|
||||
|
||||
function ws_options($rows, $selectedValue, $defaultValue = '')
|
||||
{
|
||||
$selectedValue = (string)$selectedValue;
|
||||
if ($selectedValue === '' && $defaultValue !== '') {
|
||||
$selectedValue = (string)$defaultValue;
|
||||
}
|
||||
|
||||
$html = '<option value="">--</option>';
|
||||
if (!$rows) return $html;
|
||||
|
||||
foreach ($rows as $r) {
|
||||
$val = h($r['value']);
|
||||
$lab = h($r['label']);
|
||||
$sel = ((string)$r['value'] === $selectedValue) ? ' selected' : '';
|
||||
$html .= "<option value=\"{$val}\"{$sel}>{$lab}</option>";
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
|
||||
$isEdit = ($worksheet_id > 0);
|
||||
?>
|
||||
|
||||
@ -489,11 +530,10 @@ $isEdit = ($worksheet_id > 0);
|
||||
|
||||
<div class="col-md-3">
|
||||
<label class="form-label fw-semibold">Marchiatura</label>
|
||||
<select class="form-select" name="marking">
|
||||
<option value="">--</option>
|
||||
<option value="S" <?= $worksheet && $worksheet['marking'] === 'S' ? 'selected' : '' ?>>Sì</option>
|
||||
<option value="N" <?= $worksheet && $worksheet['marking'] === 'N' ? 'selected' : '' ?>>No</option>
|
||||
<select class="form-select" name="marking" id="marking">
|
||||
<?= ws_options($lookup['marking'] ?? [], $worksheet['marking'] ?? '', $lookupDefault['marking'] ?? '') ?>
|
||||
</select>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="col-md-3">
|
||||
@ -509,29 +549,39 @@ $isEdit = ($worksheet_id > 0);
|
||||
|
||||
<div class="col-md-3">
|
||||
<label class="form-label fw-semibold">Controlli - Taglio</label>
|
||||
<input type="text" class="form-control" name="control_frequency_cut"
|
||||
value="<?= $worksheet ? h($worksheet['control_frequency_cut']) : '' ?>">
|
||||
<select class="form-select" name="control_frequency_cut" id="control_frequency_cut">
|
||||
<?= ws_options($lookup['control_frequency_cut'] ?? [], $worksheet['control_frequency_cut'] ?? '', $lookupDefault['control_frequency_cut'] ?? '') ?>
|
||||
</select>
|
||||
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<label class="form-label fw-semibold">Controlli - Disegno</label>
|
||||
<input type="text" class="form-control" name="control_frequency_drawing"
|
||||
value="<?= $worksheet ? h($worksheet['control_frequency_drawing']) : '' ?>">
|
||||
<select class="form-select" name="control_frequency_drawing" id="control_frequency_drawing">
|
||||
<?= ws_options($lookup['control_frequency_drawing'] ?? [], $worksheet['control_frequency_drawing'] ?? '', $lookupDefault['control_frequency_drawing'] ?? '') ?>
|
||||
</select>
|
||||
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<label class="form-label fw-semibold">Controlli - Dima</label>
|
||||
<input type="text" class="form-control" name="control_frequency_jig"
|
||||
value="<?= $worksheet ? h($worksheet['control_frequency_jig']) : '' ?>">
|
||||
<select class="form-select" name="control_frequency_jig" id="control_frequency_jig">
|
||||
<?= ws_options($lookup['control_frequency_jig'] ?? [], $worksheet['control_frequency_jig'] ?? '', $lookupDefault['control_frequency_jig'] ?? '') ?>
|
||||
</select>
|
||||
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<label class="form-label fw-semibold">Modalità dima</label>
|
||||
<input type="text" class="form-control" name="control_mode_jig"
|
||||
value="<?= $worksheet ? h($worksheet['control_mode_jig']) : '' ?>">
|
||||
<select class="form-select" name="control_mode_jig" id="control_mode_jig">
|
||||
<?= ws_options($lookup['control_mode_jig'] ?? [], $worksheet['control_mode_jig'] ?? '', $lookupDefault['control_mode_jig'] ?? '') ?>
|
||||
</select>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="col-md-3">
|
||||
<label class="form-label fw-semibold">Scatola (tipo)</label>
|
||||
<input type="text" class="form-control" name="box_type"
|
||||
value="<?= $worksheet ? h($worksheet['box_type']) : '' ?>">
|
||||
<select class="form-select" name="box_type" id="box_type">
|
||||
<?= ws_options($lookup['box_type'] ?? [], $worksheet['box_type'] ?? '', $lookupDefault['box_type'] ?? '') ?>
|
||||
</select>
|
||||
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<label class="form-label fw-semibold">N° conf./pezzi per scatola</label>
|
||||
@ -545,8 +595,10 @@ $isEdit = ($worksheet_id > 0);
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<label class="form-label fw-semibold">Bancale (tipo)</label>
|
||||
<input type="text" class="form-control" name="pallet_type"
|
||||
value="<?= $worksheet ? h($worksheet['pallet_type']) : '' ?>">
|
||||
<select class="form-select" name="pallet_type" id="pallet_type">
|
||||
<?= ws_options($lookup['pallet_type'] ?? [], $worksheet['pallet_type'] ?? '', $lookupDefault['pallet_type'] ?? '') ?>
|
||||
</select>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="col-md-3">
|
||||
@ -702,11 +754,9 @@ $isEdit = ($worksheet_id > 0);
|
||||
<div class="col-md-4">
|
||||
<label class="form-label fw-semibold">Lubrificazione</label>
|
||||
<select class="form-select" name="lubrication_type" id="lubrication_type">
|
||||
<option value="">--</option>
|
||||
<option value="S">S (Siliconatura)</option>
|
||||
<option value="G">G (Glicerina)</option>
|
||||
<option value="N">N (No)</option>
|
||||
<?= ws_options($lookup['lubrication_type'] ?? [], '', $lookupDefault['lubrication_type'] ?? '') ?>
|
||||
</select>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="col-md-8">
|
||||
@ -716,7 +766,10 @@ $isEdit = ($worksheet_id > 0);
|
||||
|
||||
<div class="col-md-4">
|
||||
<label class="form-label fw-semibold">Codice confezione</label>
|
||||
<input type="text" class="form-control" name="requested_package_code" id="requested_package_code" placeholder="es. B390">
|
||||
<select class="form-select" name="requested_package_code" id="requested_package_code">
|
||||
<?= ws_options($lookup['requested_package_code'] ?? [], '', $lookupDefault['requested_package_code'] ?? '') ?>
|
||||
</select>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="col-md-4">
|
||||
@ -889,41 +942,32 @@ $isEdit = ($worksheet_id > 0);
|
||||
let row = $(this).attr('data-row');
|
||||
row = JSON.parse(row);
|
||||
|
||||
// Titolo modale
|
||||
$('#mixModalTitle').text('Modifica Mescola');
|
||||
|
||||
// NON resettare in "add"
|
||||
$('#mixForm')[0].reset();
|
||||
|
||||
// Set id riga e worksheet
|
||||
$('#mixRowId').val(row.id);
|
||||
$('#mixWorksheetId').val(row.worksheet_id);
|
||||
|
||||
$('#idmescola').val(row.idmescola).prop('disabled', false);
|
||||
// Compute next available position (max + 1) from current table rows
|
||||
let maxPos = 0;
|
||||
$('#tabellaMixRows tbody tr').each(function() {
|
||||
const v = parseInt($(this).find('td').eq(0).text().trim(), 10);
|
||||
if (!isNaN(v) && v > maxPos) maxPos = v;
|
||||
});
|
||||
const nextPos = maxPos + 1;
|
||||
|
||||
// Reset for add by default
|
||||
$('#mixModalTitle').text('Aggiungi Mescola');
|
||||
$('#mixForm')[0].reset();
|
||||
$('#mixRowId').val('0');
|
||||
$('#mixWorksheetId').val(wsId);
|
||||
$('#mix_position').val(nextPos);
|
||||
// Mescola (se usi select2 devi triggerare change)
|
||||
$('#idmescola').prop('disabled', false);
|
||||
$('#idmescola').val(row.idmescola).trigger('change');
|
||||
|
||||
|
||||
// Campi
|
||||
$('#mix_weight_g_m').val(row.mix_weight_g_m ?? '');
|
||||
$('#required_density').val(row.required_density ?? '');
|
||||
$('#required_hardness_shore_a').val(row.required_hardness_shore_a ?? '');
|
||||
|
||||
$('#lubrication_type').val(row.lubrication_type ?? '');
|
||||
$('#lubrication_notes').val(row.lubrication_notes ?? '');
|
||||
|
||||
$('#requested_package_code').val(row.requested_package_code ?? '');
|
||||
$('#meters_per_package').val(row.meters_per_package ?? '');
|
||||
$('#meters_per_package_tolerance').val(row.meters_per_package_tolerance ?? '');
|
||||
$('#meters_per_package_notes').val(row.meters_per_package_notes ?? '');
|
||||
|
||||
// Apri modale
|
||||
const modal = new bootstrap.Modal(document.getElementById('mixModal'));
|
||||
modal.show();
|
||||
});
|
||||
|
||||
@ -83,7 +83,6 @@
|
||||
/* --- FIX colonne lunghe: tronca con ellissi --- */
|
||||
#tabellaMescole {
|
||||
table-layout: fixed;
|
||||
/* fondamentale: rende fisse le larghezze */
|
||||
width: 100% !important;
|
||||
}
|
||||
|
||||
@ -92,37 +91,42 @@
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
/* una riga sola */
|
||||
}
|
||||
|
||||
/* Larghezze consigliate (aggiusta se vuoi) */
|
||||
#tabellaMescole th:nth-child(2),
|
||||
#tabellaMescole td:nth-child(2) {
|
||||
/* Nome Mescola */
|
||||
width: 260px;
|
||||
max-width: 260px;
|
||||
}
|
||||
|
||||
#tabellaMescole th:nth-child(3),
|
||||
#tabellaMescole td:nth-child(3) {
|
||||
/* Nome Uscita */
|
||||
width: 260px;
|
||||
max-width: 260px;
|
||||
}
|
||||
|
||||
/* facoltativo: azioni sempre leggibili */
|
||||
#tabellaMescole th:nth-child(5),
|
||||
#tabellaMescole td:nth-child(5) {
|
||||
width: 230px;
|
||||
max-width: 230px;
|
||||
}
|
||||
|
||||
/* ID sempre piccolo */
|
||||
/* ID */
|
||||
#tabellaMescole th:nth-child(1),
|
||||
#tabellaMescole td:nth-child(1) {
|
||||
width: 70px;
|
||||
max-width: 70px;
|
||||
}
|
||||
|
||||
/* Nome Uscita */
|
||||
#tabellaMescole th:nth-child(2),
|
||||
#tabellaMescole td:nth-child(2) {
|
||||
width: 360px;
|
||||
max-width: 360px;
|
||||
}
|
||||
|
||||
/* Q.tà totale */
|
||||
#tabellaMescole th:nth-child(3),
|
||||
#tabellaMescole td:nth-child(3) {
|
||||
width: 140px;
|
||||
max-width: 140px;
|
||||
}
|
||||
|
||||
/* Linee */
|
||||
#tabellaMescole th:nth-child(4),
|
||||
#tabellaMescole td:nth-child(4) {
|
||||
width: 260px;
|
||||
max-width: 260px;
|
||||
}
|
||||
|
||||
/* Azioni */
|
||||
#tabellaMescole th:nth-child(5),
|
||||
#tabellaMescole td:nth-child(5) {
|
||||
width: 330px;
|
||||
max-width: 330px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
@ -153,8 +157,8 @@
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Nome Mescola</th>
|
||||
<th>Nome Uscita</th>
|
||||
<th>Q.tà Totale</th>
|
||||
<th>Linee Associate</th>
|
||||
<th>Azioni</th>
|
||||
</tr>
|
||||
@ -163,37 +167,61 @@
|
||||
<?php
|
||||
$db = DBHandlerSelect::getInstance();
|
||||
$pdo = $db->getConnection();
|
||||
|
||||
// QTY IN SUBQUERY per evitare raddoppi dovuti alle linee
|
||||
$sql = "
|
||||
SELECT m.id, m.nome, m.nomeuscita,
|
||||
GROUP_CONCAT(pl.name SEPARATOR ', ') AS linee
|
||||
FROM mescole m
|
||||
LEFT JOIN mescole_lines ml ON m.id = ml.idmescola
|
||||
LEFT JOIN production_lines pl ON ml.idlinea = pl.id
|
||||
GROUP BY m.id
|
||||
ORDER BY m.id DESC";
|
||||
SELECT
|
||||
m.id,
|
||||
m.nomeuscita,
|
||||
IFNULL(q.qty_totale, 0) AS qty_totale,
|
||||
GROUP_CONCAT(DISTINCT pl.name SEPARATOR ', ') AS linee
|
||||
FROM mescole m
|
||||
LEFT JOIN (
|
||||
SELECT idmescola, SUM(qty) AS qty_totale
|
||||
FROM mescole_supplier_lots
|
||||
GROUP BY idmescola
|
||||
) q ON q.idmescola = m.id
|
||||
LEFT JOIN mescole_lines ml ON m.id = ml.idmescola
|
||||
LEFT JOIN production_lines pl ON ml.idlinea = pl.id
|
||||
GROUP BY m.id
|
||||
ORDER BY m.id DESC
|
||||
";
|
||||
|
||||
$stmt = $pdo->query($sql);
|
||||
|
||||
if ($stmt->rowCount() === 0) {
|
||||
echo "<tr><td colspan='5' class='text-muted'>Nessuna mescola presente</td></tr>";
|
||||
// DataTables-friendly: 5 TD reali
|
||||
echo "<tr>
|
||||
<td class='text-muted'>-</td>
|
||||
<td class='text-muted'>Nessuna mescola presente</td>
|
||||
<td class='text-muted'>-</td>
|
||||
<td class='text-muted'>-</td>
|
||||
<td class='text-muted'>-</td>
|
||||
</tr>";
|
||||
} else {
|
||||
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
$linee = $row['linee'] ? htmlspecialchars($row['linee']) : '<span class="text-muted">Nessuna</span>';
|
||||
$qtyTot = number_format((float)$row['qty_totale'], 3, ',', '.');
|
||||
|
||||
echo "<tr>
|
||||
<td>{$row['id']}</td>
|
||||
<td>" . htmlspecialchars($row['nome']) . "</td>
|
||||
<td>" . htmlspecialchars($row['nomeuscita']) . "</td>
|
||||
<td><span class='fw-semibold'>{$qtyTot}</span></td>
|
||||
<td>{$linee}</td>
|
||||
<td>
|
||||
<button class='btn btn-sm btn-outline-primary associa-linee'
|
||||
<button class='btn btn-sm btn-outline-dark associa-fornitori'
|
||||
data-id='{$row['id']}'
|
||||
data-nome='" . htmlspecialchars($row['nome'], ENT_QUOTES) . "'>
|
||||
⚙️ Associa Linee
|
||||
data-nomeuscita='" . htmlspecialchars($row['nomeuscita'], ENT_QUOTES) . "'>
|
||||
🧾 Fornitori/Lotti
|
||||
</button>
|
||||
|
||||
<button class='btn btn-sm btn-outline-primary associa-linee'
|
||||
data-id='{$row['id']}'>
|
||||
⚙️ Linee
|
||||
</button>
|
||||
|
||||
<button class='btn btn-sm btn-outline-secondary edit-mescola'
|
||||
data-id='{$row['id']}'
|
||||
data-nome='" . htmlspecialchars($row['nome'], ENT_QUOTES) . "'
|
||||
data-nomeuscita='" . htmlspecialchars($row['nomeuscita'], ENT_QUOTES) . "'>
|
||||
✏️ Modifica
|
||||
</button>
|
||||
@ -226,8 +254,8 @@
|
||||
<div class="modal-body">
|
||||
<form id="addMescolaForm">
|
||||
<div class="mb-3">
|
||||
<label class="form-label fw-semibold">Nome Mescola</label>
|
||||
<input type="text" class="form-control" id="nomeMescola" required>
|
||||
<label class="form-label fw-semibold">Nome Mescola (interno)</label>
|
||||
<input type="text" class="form-control" id="nomeMescola" placeholder="opzionale / interno">
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
@ -259,8 +287,8 @@
|
||||
<input type="hidden" id="editIdMescola">
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label fw-semibold">Nome Mescola</label>
|
||||
<input type="text" class="form-control" id="editNomeMescola" required>
|
||||
<label class="form-label fw-semibold">Nome Mescola (interno)</label>
|
||||
<input type="text" class="form-control" id="editNomeMescola" placeholder="opzionale / interno">
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
@ -305,6 +333,68 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- MODALE ASSOCIA FORNITORI / LOTTI -->
|
||||
<div class="modal fade" id="associaFornitoriModal" tabindex="-1">
|
||||
<div class="modal-dialog modal-xl modal-dialog-centered">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header" style="background-color:#cfe3ff;">
|
||||
<h5 class="modal-title">Fornitori / Lotti - <span id="afNomeUscita"></span></h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
|
||||
<div class="modal-body">
|
||||
<input type="hidden" id="afIdMescola">
|
||||
<input type="hidden" id="afEditId">
|
||||
|
||||
<div class="row g-2 align-items-end mb-3">
|
||||
<div class="col-md-3">
|
||||
<label class="form-label fw-semibold">Fornitore</label>
|
||||
<select class="form-select" id="afIdSupplier" style="width:100%;"></select>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<label class="form-label fw-semibold">Nome mescola fornitore</label>
|
||||
<input type="text" class="form-control" id="afSupplierMixName" placeholder="Nome specifico fornitore">
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<label class="form-label fw-semibold">Lotto</label>
|
||||
<input type="text" class="form-control" id="afLotCode" placeholder="LOT-...">
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<label class="form-label fw-semibold">Scadenza</label>
|
||||
<input type="date" class="form-control" id="afExpiryDate">
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<label class="form-label fw-semibold">Q.tà</label>
|
||||
<input type="number" step="0.001" class="form-control" id="afQty" value="0">
|
||||
</div>
|
||||
<div class="col-md-12 text-end">
|
||||
<button class="btn btn-add" id="afSaveBtn">➕ Aggiungi Riga</button>
|
||||
<button class="btn btn-outline-secondary ms-2" id="afCancelEdit" type="button" style="display:none;">Annulla modifica</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped align-middle text-center" id="afTable">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Fornitore</th>
|
||||
<th>Nome mescola fornitore</th>
|
||||
<th>Lotto</th>
|
||||
<th>Scadenza</th>
|
||||
<th>Q.tà</th>
|
||||
<th>Azioni</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody></tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php include('jsinclude.php'); ?>
|
||||
|
||||
<script>
|
||||
@ -348,7 +438,7 @@
|
||||
Swal.fire({
|
||||
icon: "error",
|
||||
title: "Errore",
|
||||
text: data.message
|
||||
text: data.message || "Errore salvataggio"
|
||||
});
|
||||
}
|
||||
});
|
||||
@ -357,8 +447,9 @@
|
||||
/* -------- APERTURA MODALE EDIT -------- */
|
||||
$(document).on("click", ".edit-mescola", function() {
|
||||
$("#editIdMescola").val($(this).data("id"));
|
||||
$("#editNomeMescola").val($(this).data("nome"));
|
||||
$("#editNomeUscita").val($(this).data("nomeuscita"));
|
||||
// nome interno non lo abbiamo in tabella: lo lasciamo vuoto o lo recuperi se vuoi via endpoint
|
||||
$("#editNomeMescola").val("");
|
||||
$("#editMescolaModal").modal("show");
|
||||
});
|
||||
|
||||
@ -375,7 +466,7 @@
|
||||
headers: {
|
||||
"Content-Type": "application/x-www-form-urlencoded"
|
||||
},
|
||||
body: `id=${id}&nome=${encodeURIComponent(nome)}&nomeuscita=${encodeURIComponent(nomeuscita)}`
|
||||
body: `id=${encodeURIComponent(id)}&nome=${encodeURIComponent(nome)}&nomeuscita=${encodeURIComponent(nomeuscita)}`
|
||||
})
|
||||
.then(r => r.json())
|
||||
.then(data => {
|
||||
@ -390,7 +481,7 @@
|
||||
Swal.fire({
|
||||
icon: "error",
|
||||
title: "Errore",
|
||||
text: data.message
|
||||
text: data.message || "Errore aggiornamento"
|
||||
});
|
||||
}
|
||||
});
|
||||
@ -398,11 +489,10 @@
|
||||
|
||||
/* -------- MODALE ASSOCIA LINEE -------- */
|
||||
$(document).on("click", ".associa-linee", function() {
|
||||
|
||||
const idMescola = $(this).data("id");
|
||||
$("#idMescolaLinee").val(idMescola);
|
||||
|
||||
fetch("get_linee_mescola.php?id=" + idMescola)
|
||||
fetch("get_linee_mescola.php?id=" + encodeURIComponent(idMescola))
|
||||
.then(r => r.json())
|
||||
.then(data => {
|
||||
const select = $("#lineeSelect");
|
||||
@ -451,11 +541,219 @@
|
||||
Swal.fire({
|
||||
icon: "error",
|
||||
title: "Errore",
|
||||
text: data.message
|
||||
text: data.message || "Errore salvataggio"
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// ============================
|
||||
// FORNITORI / LOTTI
|
||||
// ============================
|
||||
|
||||
function afResetForm() {
|
||||
$("#afEditId").val("");
|
||||
$("#afIdSupplier").val("").trigger("change");
|
||||
$("#afSupplierMixName").val("");
|
||||
$("#afLotCode").val("");
|
||||
$("#afExpiryDate").val("");
|
||||
$("#afQty").val("0");
|
||||
$("#afSaveBtn").text("➕ Aggiungi Riga");
|
||||
$("#afCancelEdit").hide();
|
||||
}
|
||||
|
||||
function afLoadSuppliers() {
|
||||
return fetch("get_suppliers.php")
|
||||
.then(r => r.json())
|
||||
.then(data => {
|
||||
const sel = $("#afIdSupplier");
|
||||
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>`);
|
||||
});
|
||||
}
|
||||
|
||||
sel.select2({
|
||||
theme: "bootstrap-5",
|
||||
width: "100%",
|
||||
dropdownParent: $("#associaFornitoriModal")
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function afLoadRows(idMescola) {
|
||||
fetch("get_mescola_supplier_lots.php?id=" + encodeURIComponent(idMescola))
|
||||
.then(r => r.json())
|
||||
.then(data => {
|
||||
const tbody = $("#afTable tbody");
|
||||
tbody.empty();
|
||||
|
||||
if (!data.success || !Array.isArray(data.rows) || data.rows.length === 0) {
|
||||
tbody.append(`<tr>
|
||||
<td class="text-muted">-</td>
|
||||
<td class="text-muted">Nessuna associazione presente</td>
|
||||
<td class="text-muted">-</td>
|
||||
<td class="text-muted">-</td>
|
||||
<td class="text-muted">-</td>
|
||||
<td class="text-muted">-</td>
|
||||
<td class="text-muted">-</td>
|
||||
</tr>`);
|
||||
return;
|
||||
}
|
||||
|
||||
data.rows.forEach(row => {
|
||||
const exp = row.expiry_date ? row.expiry_date : "";
|
||||
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, '"')}"
|
||||
data-lot="${String(row.lot_code ?? '').replace(/"/g, '"')}"
|
||||
data-exp="${exp}"
|
||||
data-qty="${row.qty}">
|
||||
✏️
|
||||
</button>
|
||||
<button class="btn btn-sm btn-outline-danger af-del" data-id="${row.id}">🗑️</button>
|
||||
</td>
|
||||
</tr>
|
||||
`);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Open modal
|
||||
$(document).on("click", ".associa-fornitori", function() {
|
||||
const idMescola = $(this).data("id");
|
||||
const nomeUscita = $(this).data("nomeuscita");
|
||||
|
||||
$("#afIdMescola").val(idMescola);
|
||||
$("#afNomeUscita").text(nomeUscita);
|
||||
|
||||
$("#associaFornitoriModal").modal("show");
|
||||
afResetForm();
|
||||
afLoadSuppliers().then(() => 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"));
|
||||
|
||||
$("#afSaveBtn").text("💾 Salva Modifica");
|
||||
$("#afCancelEdit").show();
|
||||
});
|
||||
|
||||
$("#afCancelEdit").on("click", function() {
|
||||
afResetForm();
|
||||
});
|
||||
|
||||
// Save (insert/update)
|
||||
$("#afSaveBtn").on("click", function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
const idmescola = $("#afIdMescola").val();
|
||||
const editId = $("#afEditId").val();
|
||||
|
||||
const idsupplier = $("#afIdSupplier").val();
|
||||
const supplier_mix_name = $("#afSupplierMixName").val().trim();
|
||||
const lot_code = $("#afLotCode").val().trim();
|
||||
const expiry_date = $("#afExpiryDate").val();
|
||||
const qty = $("#afQty").val();
|
||||
|
||||
if (!idsupplier || !supplier_mix_name) {
|
||||
Swal.fire({
|
||||
icon: "warning",
|
||||
title: "Attenzione",
|
||||
text: "Fornitore e Nome mescola fornitore sono obbligatori"
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const actionUrl = editId ? "update_mescola_supplier_lot.php" : "save_mescola_supplier_lot.php";
|
||||
|
||||
const body =
|
||||
(editId ? `id=${encodeURIComponent(editId)}&` : ``) +
|
||||
`idmescola=${encodeURIComponent(idmescola)}` +
|
||||
`&idsupplier=${encodeURIComponent(idsupplier)}` +
|
||||
`&supplier_mix_name=${encodeURIComponent(supplier_mix_name)}` +
|
||||
`&lot_code=${encodeURIComponent(lot_code)}` +
|
||||
`&expiry_date=${encodeURIComponent(expiry_date)}` +
|
||||
`&qty=${encodeURIComponent(qty)}`;
|
||||
|
||||
fetch(actionUrl, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/x-www-form-urlencoded"
|
||||
},
|
||||
body
|
||||
})
|
||||
.then(r => r.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
afResetForm();
|
||||
afLoadRows(idmescola);
|
||||
// se vuoi aggiornare anche la Q.tà Totale live senza reload: lo facciamo dopo
|
||||
} else {
|
||||
Swal.fire({
|
||||
icon: "error",
|
||||
title: "Errore",
|
||||
text: data.message || "Operazione non riuscita"
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Delete
|
||||
$(document).on("click", ".af-del", function() {
|
||||
const id = $(this).data("id");
|
||||
const idmescola = $("#afIdMescola").val();
|
||||
|
||||
Swal.fire({
|
||||
title: "Eliminare la riga?",
|
||||
icon: "warning",
|
||||
showCancelButton: true,
|
||||
confirmButtonText: "Sì, elimina",
|
||||
cancelButtonText: "Annulla",
|
||||
confirmButtonColor: "#d33"
|
||||
}).then((res) => {
|
||||
if (!res.isConfirmed) return;
|
||||
|
||||
fetch("delete_mescola_supplier_lot.php", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/x-www-form-urlencoded"
|
||||
},
|
||||
body: `id=${encodeURIComponent(id)}`
|
||||
})
|
||||
.then(r => r.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
afLoadRows(idmescola);
|
||||
} else {
|
||||
Swal.fire({
|
||||
icon: "error",
|
||||
title: "Errore",
|
||||
text: data.message || "Cancellazione non riuscita"
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
</body>
|
||||
|
||||
@ -357,6 +357,10 @@
|
||||
|
||||
<!-- 🔹 Quinta RIGA: EMPLOYEES -->
|
||||
<div class="dashboard-grid-bottom" style="margin-top: 20px;">
|
||||
<button class="dash-btn dash-btn-small btn-skills" onclick="location.href='suppliers.php'">
|
||||
<div class="dash-icon">🛠️</div>
|
||||
<div>Suppliers</div>
|
||||
</button>
|
||||
<button class="dash-btn dash-btn-small btn-skills" onclick="location.href='lookup_values.php'">
|
||||
<div class="dash-icon">🛠️</div>
|
||||
<div>Setup</div>
|
||||
|
||||
35
public/userarea/save_mescola_supplier_lot.php
Normal file
35
public/userarea/save_mescola_supplier_lot.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
include('include/headscript.php');
|
||||
header('Content-Type: application/json');
|
||||
|
||||
$idmescola = isset($_POST['idmescola']) ? (int)$_POST['idmescola'] : 0;
|
||||
$idsupplier = isset($_POST['idsupplier']) ? (int)$_POST['idsupplier'] : 0;
|
||||
$supplier_mix_name = trim($_POST['supplier_mix_name'] ?? '');
|
||||
$lot_code = trim($_POST['lot_code'] ?? '');
|
||||
$expiry_date = trim($_POST['expiry_date'] ?? '');
|
||||
$qty = isset($_POST['qty']) ? (float)$_POST['qty'] : 0;
|
||||
|
||||
if ($idmescola <= 0 || $idsupplier <= 0 || $supplier_mix_name === '') {
|
||||
echo json_encode(['success' => false, 'message' => 'Missing required fields']);
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($expiry_date === '') $expiry_date = null;
|
||||
|
||||
$db = DBHandlerSelect::getInstance();
|
||||
$pdo = $db->getConnection();
|
||||
|
||||
$stmt = $pdo->prepare("INSERT INTO mescole_supplier_lots
|
||||
(idmescola, idsupplier, supplier_mix_name, lot_code, expiry_date, qty)
|
||||
VALUES (?, ?, ?, ?, ?, ?)");
|
||||
|
||||
$ok = $stmt->execute([
|
||||
$idmescola,
|
||||
$idsupplier,
|
||||
$supplier_mix_name,
|
||||
$lot_code !== '' ? $lot_code : null,
|
||||
$expiry_date,
|
||||
$qty
|
||||
]);
|
||||
|
||||
echo json_encode(['success' => (bool)$ok]);
|
||||
19
public/userarea/save_supplier.php
Normal file
19
public/userarea/save_supplier.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
include('include/headscript.php');
|
||||
header('Content-Type: application/json');
|
||||
|
||||
$supplier_name = trim($_POST['supplier_name'] ?? '');
|
||||
$vat = trim($_POST['vat'] ?? '');
|
||||
|
||||
if ($supplier_name === '') {
|
||||
echo json_encode(['success' => false, 'message' => 'Supplier name required']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$db = DBHandlerSelect::getInstance();
|
||||
$pdo = $db->getConnection();
|
||||
|
||||
$stmt = $pdo->prepare("INSERT INTO suppliers (supplier_name, vat) VALUES (?, ?)");
|
||||
$ok = $stmt->execute([$supplier_name, $vat !== '' ? $vat : null]);
|
||||
|
||||
echo json_encode(['success' => (bool)$ok]);
|
||||
403
public/userarea/suppliers.php
Normal file
403
public/userarea/suppliers.php
Normal 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>
|
||||
20
public/userarea/update_supplier.php
Normal file
20
public/userarea/update_supplier.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
include('include/headscript.php');
|
||||
header('Content-Type: application/json');
|
||||
|
||||
$idsupplier = isset($_POST['idsupplier']) ? (int)$_POST['idsupplier'] : 0;
|
||||
$supplier_name = trim($_POST['supplier_name'] ?? '');
|
||||
$vat = trim($_POST['vat'] ?? '');
|
||||
|
||||
if ($idsupplier <= 0 || $supplier_name === '') {
|
||||
echo json_encode(['success' => false, 'message' => 'Invalid input']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$db = DBHandlerSelect::getInstance();
|
||||
$pdo = $db->getConnection();
|
||||
|
||||
$stmt = $pdo->prepare("UPDATE suppliers SET supplier_name = ?, vat = ? WHERE idsupplier = ?");
|
||||
$ok = $stmt->execute([$supplier_name, $vat !== '' ? $vat : null, $idsupplier]);
|
||||
|
||||
echo json_encode(['success' => (bool)$ok]);
|
||||
Loading…
x
Reference in New Issue
Block a user