From 245750f0575cd1d25969edcba9ade6b79fea437b Mon Sep 17 00:00:00 2001 From: solocla Date: Fri, 6 Mar 2026 08:42:18 +0100 Subject: [PATCH] mescole update --- .../userarea/delete_mescola_supplier_lot.php | 17 + public/userarea/get_mescola_supplier_lots.php | 30 ++ public/userarea/get_suppliers.php | 11 + public/userarea/manage-worksheet.php | 122 ++++-- public/userarea/mescole.php | 398 ++++++++++++++--- public/userarea/production_dashboard.php | 4 + public/userarea/save_mescola_supplier_lot.php | 35 ++ public/userarea/save_supplier.php | 19 + public/userarea/suppliers.php | 403 ++++++++++++++++++ public/userarea/update_supplier.php | 20 + 10 files changed, 970 insertions(+), 89 deletions(-) create mode 100644 public/userarea/delete_mescola_supplier_lot.php create mode 100644 public/userarea/get_mescola_supplier_lots.php create mode 100644 public/userarea/get_suppliers.php create mode 100644 public/userarea/save_mescola_supplier_lot.php create mode 100644 public/userarea/save_supplier.php create mode 100644 public/userarea/suppliers.php create mode 100644 public/userarea/update_supplier.php diff --git a/public/userarea/delete_mescola_supplier_lot.php b/public/userarea/delete_mescola_supplier_lot.php new file mode 100644 index 0000000..b5a7d76 --- /dev/null +++ b/public/userarea/delete_mescola_supplier_lot.php @@ -0,0 +1,17 @@ + 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]); diff --git a/public/userarea/get_mescola_supplier_lots.php b/public/userarea/get_mescola_supplier_lots.php new file mode 100644 index 0000000..1db7df8 --- /dev/null +++ b/public/userarea/get_mescola_supplier_lots.php @@ -0,0 +1,30 @@ + 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]); diff --git a/public/userarea/get_suppliers.php b/public/userarea/get_suppliers.php new file mode 100644 index 0000000..0db9e71 --- /dev/null +++ b/public/userarea/get_suppliers.php @@ -0,0 +1,11 @@ +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]); diff --git a/public/userarea/manage-worksheet.php b/public/userarea/manage-worksheet.php index 64ad7f6..95b0746 100644 --- a/public/userarea/manage-worksheet.php +++ b/public/userarea/manage-worksheet.php @@ -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 = ''; + if (!$rows) return $html; + + foreach ($rows as $r) { + $val = h($r['value']); + $lab = h($r['label']); + $sel = ((string)$r['value'] === $selectedValue) ? ' selected' : ''; + $html .= ""; + } + return $html; +} + $isEdit = ($worksheet_id > 0); ?> @@ -489,11 +530,10 @@ $isEdit = ($worksheet_id > 0);
- + +
@@ -509,29 +549,39 @@ $isEdit = ($worksheet_id > 0);
- + +
- + +
- + +
- + +
- + +
@@ -545,8 +595,10 @@ $isEdit = ($worksheet_id > 0);
- + +
@@ -702,11 +754,9 @@ $isEdit = ($worksheet_id > 0);
+
@@ -716,7 +766,10 @@ $isEdit = ($worksheet_id > 0);
- + +
@@ -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(); }); diff --git a/public/userarea/mescole.php b/public/userarea/mescole.php index 7f2d0c5..e53859d 100644 --- a/public/userarea/mescole.php +++ b/public/userarea/mescole.php @@ -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; + } @@ -153,8 +157,8 @@ ID - Nome Mescola Nome Uscita + Q.tà Totale Linee Associate Azioni @@ -163,37 +167,61 @@ 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 "Nessuna mescola presente"; + // DataTables-friendly: 5 TD reali + echo " + - + Nessuna mescola presente + - + - + - + "; } else { while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $linee = $row['linee'] ? htmlspecialchars($row['linee']) : 'Nessuna'; + $qtyTot = number_format((float)$row['qty_totale'], 3, ',', '.'); echo " {$row['id']} - " . htmlspecialchars($row['nome']) . " " . htmlspecialchars($row['nomeuscita']) . " + {$qtyTot} {$linee} - + + @@ -226,8 +254,8 @@ +
+
+ + +
+ + + + + + + + + + + + + + \ No newline at end of file diff --git a/public/userarea/update_supplier.php b/public/userarea/update_supplier.php new file mode 100644 index 0000000..2ad8ec4 --- /dev/null +++ b/public/userarea/update_supplier.php @@ -0,0 +1,20 @@ + 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]);