diff --git a/public/userarea/ajax/worksheet-linked-data.php b/public/userarea/ajax/worksheet-linked-data.php
new file mode 100644
index 0000000..793a534
--- /dev/null
+++ b/public/userarea/ajax/worksheet-linked-data.php
@@ -0,0 +1,254 @@
+ false,
+ 'message' => 'Classe Auth non disponibile'
+ ]);
+ exit;
+}
+
+if (!Auth::check()) {
+ echo json_encode([
+ 'success' => false,
+ 'message' => 'Sessione non valida o utente non autenticato'
+ ]);
+ exit;
+}
+
+$db = DBHandlerSelect::getInstance();
+$pdo = $db->getConnection();
+$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+
+function formatDateIT($d)
+{
+ if (!$d || $d === '0000-00-00') return '';
+ return date("d/m/Y", strtotime($d));
+}
+
+function formatDateTimeIT($d)
+{
+ if (!$d || $d === '0000-00-00 00:00:00') return '';
+ return date("d/m/Y H:i", strtotime($d));
+}
+
+function worksheetNumberLabel($n)
+{
+ $n = (int)$n;
+ return $n > 0 ? 'FL' . $n : '—';
+}
+
+function revisionLabel($rev)
+{
+ $rev = trim((string)$rev);
+ return $rev !== '' ? $rev : '0';
+}
+
+
+
+$action = $_POST['action'] ?? '';
+
+try {
+ if ($action === 'get_matrice_worksheets') {
+ $idmatrice = isset($_POST['idmatrice']) ? (int)$_POST['idmatrice'] : 0;
+ if ($idmatrice <= 0) {
+ echo json_encode([
+ 'success' => false,
+ 'message' => 'ID matrice non valido'
+ ]);
+ exit;
+ }
+
+ $stmt = $pdo->prepare("
+ SELECT
+ ws.id,
+ ws.idmatrice,
+ ws.worksheet_number,
+ ws.revision_code,
+ ws.worksheet_status,
+ ws.worksheet_date,
+ ws.customer_name,
+ ws.profile_type_code,
+ ws.marking,
+ ws.approved_by,
+ ws.created_at,
+ ws.updated_at,
+ (
+ SELECT COUNT(*)
+ FROM work_sheet_mescole wsm
+ WHERE wsm.worksheet_id = ws.id
+ ) AS mix_count
+ FROM work_sheets ws
+ WHERE ws.idmatrice = ?
+ ORDER BY
+ ws.worksheet_number DESC,
+ CASE
+ WHEN ws.revision_code IS NULL OR ws.revision_code = '' THEN 0
+ WHEN ws.revision_code REGEXP '^R[0-9]+$' THEN CAST(SUBSTRING(ws.revision_code, 2) AS UNSIGNED)
+ ELSE 0
+ END DESC,
+ ws.id DESC
+ ");
+ $stmt->execute([$idmatrice]);
+ $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
+
+ $data = [];
+ foreach ($rows as $r) {
+ $data[] = [
+ 'id' => (int)$r['id'],
+ 'idmatrice' => (int)$r['idmatrice'],
+ 'worksheet_number' => (int)($r['worksheet_number'] ?? 0),
+ 'worksheet_number_label' => worksheetNumberLabel($r['worksheet_number'] ?? 0),
+ 'revision_code' => $r['revision_code'] ?? '',
+ 'revision_label' => revisionLabel($r['revision_code'] ?? ''),
+ 'worksheet_status' => $r['worksheet_status'] ?? 'active',
+ 'worksheet_status_label' => (($r['worksheet_status'] ?? 'active') === 'inactive') ? 'Inattivo' : 'Attivo',
+ 'worksheet_date' => $r['worksheet_date'],
+ 'worksheet_date_it' => formatDateIT($r['worksheet_date']),
+ 'customer_name' => $r['customer_name'] ?? '',
+ 'profile_type_code' => $r['profile_type_code'] ?? '',
+ 'marking' => $r['marking'] ?? '',
+ 'approved_by' => $r['approved_by'] ?? '',
+ 'created_at' => $r['created_at'] ?? '',
+ 'created_at_it' => formatDateTimeIT($r['created_at'] ?? ''),
+ 'updated_at' => $r['updated_at'] ?? '',
+ 'updated_at_it' => formatDateTimeIT($r['updated_at'] ?? ''),
+ 'mix_count' => (int)($r['mix_count'] ?? 0)
+ ];
+ }
+
+ echo json_encode([
+ 'success' => true,
+ 'worksheets' => $data
+ ]);
+ exit;
+ }
+
+ if ($action === 'get_worksheet_detail') {
+ $worksheetId = isset($_POST['worksheet_id']) ? (int)$_POST['worksheet_id'] : 0;
+ if ($worksheetId <= 0) {
+ echo json_encode([
+ 'success' => false,
+ 'message' => 'ID foglio non valido'
+ ]);
+ exit;
+ }
+
+ $stmt = $pdo->prepare("
+ SELECT
+ ws.*,
+ m.nome AS matrice_nome,
+ m.cliente AS matrice_cliente
+ FROM work_sheets ws
+ LEFT JOIN matrice m ON m.id = ws.idmatrice
+ WHERE ws.id = ?
+ LIMIT 1
+ ");
+ $stmt->execute([$worksheetId]);
+ $ws = $stmt->fetch(PDO::FETCH_ASSOC);
+
+ if (!$ws) {
+ echo json_encode([
+ 'success' => false,
+ 'message' => 'Foglio di lavoro non trovato'
+ ]);
+ exit;
+ }
+
+ $stmtMix = $pdo->prepare("
+ SELECT
+ wsm.*,
+ me.nome AS mescola_nome,
+ me.nomeuscita AS mescola_uscita
+ FROM work_sheet_mescole wsm
+ LEFT JOIN mescole me ON me.id = wsm.idmescola
+ WHERE wsm.worksheet_id = ?
+ ORDER BY wsm.mix_position ASC, wsm.id ASC
+ ");
+ $stmtMix->execute([$worksheetId]);
+ $mixRows = $stmtMix->fetchAll(PDO::FETCH_ASSOC);
+
+ echo json_encode([
+ 'success' => true,
+ 'worksheet' => [
+ 'id' => (int)$ws['id'],
+ 'worksheet_number' => (int)($ws['worksheet_number'] ?? 0),
+ 'worksheet_number_label' => worksheetNumberLabel($ws['worksheet_number'] ?? 0),
+ 'revision_code' => $ws['revision_code'] ?? '',
+ 'revision_label' => revisionLabel($ws['revision_code'] ?? ''),
+ 'worksheet_status' => $ws['worksheet_status'] ?? 'active',
+ 'worksheet_status_label' => (($ws['worksheet_status'] ?? 'active') === 'inactive') ? 'Inattivo' : 'Attivo',
+ 'idmatrice' => (int)$ws['idmatrice'],
+ 'matrice_nome' => $ws['matrice_nome'] ?? '',
+ 'matrice_cliente' => $ws['matrice_cliente'] ?? '',
+ 'worksheet_date' => $ws['worksheet_date'] ?? '',
+ 'worksheet_date_it' => formatDateIT($ws['worksheet_date'] ?? ''),
+ 'customer_name' => $ws['customer_name'] ?? '',
+ 'profile_type_code' => $ws['profile_type_code'] ?? '',
+ 'marking' => $ws['marking'] ?? '',
+ 'prod_control_measure_settings' => $ws['prod_control_measure_settings'] ?? '',
+ 'control_frequency_cut' => $ws['control_frequency_cut'] ?? '',
+ 'control_frequency_drawing' => $ws['control_frequency_drawing'] ?? '',
+ 'control_frequency_jig' => $ws['control_frequency_jig'] ?? '',
+ 'control_mode_jig' => $ws['control_mode_jig'] ?? '',
+ 'requested_package_code' => $ws['requested_package_code'] ?? '',
+ 'meters_per_package' => $ws['meters_per_package'] ?? '',
+ 'meters_per_package_tolerance' => $ws['meters_per_package_tolerance'] ?? '',
+ 'meters_per_package_notes' => $ws['meters_per_package_notes'] ?? '',
+ 'box_type' => $ws['box_type'] ?? '',
+ 'packages_or_pieces_per_box' => $ws['packages_or_pieces_per_box'] ?? '',
+ 'meters_per_box' => $ws['meters_per_box'] ?? '',
+ 'pallet_type' => $ws['pallet_type'] ?? '',
+ 'boxes_or_packages_per_pallet' => $ws['boxes_or_packages_per_pallet'] ?? '',
+ 'speed_expected_kg_h' => $ws['speed_expected_kg_h'] ?? '',
+ 'speed_actual_kg_h' => $ws['speed_actual_kg_h'] ?? '',
+ 'speed_expected_m_h' => $ws['speed_expected_m_h'] ?? '',
+ 'speed_actual_m_h' => $ws['speed_actual_m_h'] ?? '',
+ 'approved_by' => $ws['approved_by'] ?? '',
+ 'notes' => $ws['notes'] ?? '',
+ 'created_at' => $ws['created_at'] ?? '',
+ 'created_at_it' => formatDateTimeIT($ws['created_at'] ?? ''),
+ 'updated_at' => $ws['updated_at'] ?? '',
+ 'updated_at_it' => formatDateTimeIT($ws['updated_at'] ?? '')
+ ],
+ 'mix_rows' => array_map(function ($r) {
+ return [
+ 'id' => (int)$r['id'],
+ 'mix_position' => (int)$r['mix_position'],
+ 'mescola_nome' => $r['mescola_nome'] ?? '',
+ 'mescola_uscita' => $r['mescola_uscita'] ?? '',
+ 'mix_weight_g_m' => $r['mix_weight_g_m'] ?? '',
+ 'required_density' => $r['required_density'] ?? '',
+ 'required_hardness_shore_a' => $r['required_hardness_shore_a'] ?? '',
+ 'lubrication_type' => $r['lubrication_type'] ?? '',
+ 'lubrication_notes' => $r['lubrication_notes'] ?? ''
+ ];
+ }, $mixRows)
+ ]);
+ exit;
+ }
+
+ echo json_encode([
+ 'success' => false,
+ 'message' => 'Azione AJAX sconosciuta'
+ ]);
+ exit;
+} catch (Exception $e) {
+ echo json_encode([
+ 'success' => false,
+ 'message' => $e->getMessage()
+ ]);
+ exit;
+}
diff --git a/public/userarea/assets/js/worksheets-linked-modals.js b/public/userarea/assets/js/worksheets-linked-modals.js
new file mode 100644
index 0000000..7da90d4
--- /dev/null
+++ b/public/userarea/assets/js/worksheets-linked-modals.js
@@ -0,0 +1,362 @@
+(function () {
+ function escapeHtml(str) {
+ return String(str || "")
+ .replace(/&/g, "&")
+ .replace(//g, ">")
+ .replace(/"/g, """)
+ .replace(/'/g, "'");
+ }
+
+ function valueOrDash(v) {
+ return v === null || v === undefined || String(v).trim() === ""
+ ? "—"
+ : escapeHtml(v);
+ }
+
+ function renderReadonlyField(label, value) {
+ return `
+
${escapeHtml(label)}
+ ${valueOrDash(value)}
+ `;
+ }
+
+ window.loadMatriceWorksheets = function (idmatrice, matriceNome, endpoint) {
+ endpoint = endpoint || "ajax/worksheet-linked-data.php";
+
+ $("#wl_idmatrice").val(idmatrice);
+ $("#wl_matrice_name").html(
+ `${escapeHtml(matriceNome || "")}`,
+ );
+ $("#worksheetsListContainer").html(
+ 'Caricamento fogli di lavoro...
',
+ );
+
+ fetch(endpoint, {
+ method: "POST",
+ headers: { "Content-Type": "application/x-www-form-urlencoded" },
+ body:
+ "action=get_matrice_worksheets&idmatrice=" +
+ encodeURIComponent(idmatrice),
+ })
+ .then(async (r) => {
+ const text = await r.text();
+ try {
+ return JSON.parse(text);
+ } catch (e) {
+ console.error("Risposta non JSON worksheets:", text);
+ throw new Error("Risposta non JSON, vedi console");
+ }
+ })
+ .then((data) => {
+ if (!data.success) {
+ $("#worksheetsListContainer").html(
+ 'Errore nel caricamento dei fogli
',
+ );
+ return;
+ }
+
+ const rows = data.worksheets || [];
+
+ if (!rows.length) {
+ $("#worksheetsListContainer").html(
+ 'Nessun foglio di lavoro collegato a questo profilo
',
+ );
+ return;
+ }
+
+ let html = `
+
+
+
+
+ | Foglio |
+ Rev. |
+ Stato |
+ Data foglio |
+ Cliente |
+ Codice profilo |
+ Mescole |
+ Azioni |
+
+
+
+ `;
+
+ rows.forEach((r) => {
+ const statusBadge =
+ r.worksheet_status === "inactive"
+ ? `Inattivo`
+ : `Attivo`;
+
+ html += `
+
+ | ${escapeHtml(r.worksheet_number_label || "—")} |
+ ${escapeHtml(r.revision_label || "0")} |
+ ${statusBadge} |
+ ${escapeHtml(r.worksheet_date_it || "—")} |
+ ${escapeHtml(r.customer_name || "—")} |
+ ${escapeHtml(r.profile_type_code || "—")} |
+ ${escapeHtml(String(r.mix_count || 0))} |
+
+
+
+ Apri pagina
+
+ |
+
+ `;
+ });
+
+ html += `
+
+
+
+ `;
+
+ $("#worksheetsListContainer").html(html);
+ })
+ .catch(() => {
+ $("#worksheetsListContainer").html(
+ 'Errore nel caricamento dei fogli
',
+ );
+ });
+ };
+
+ window.loadWorksheetDetail = function (worksheetId, endpoint) {
+ endpoint = endpoint || "ajax/worksheet-linked-data.php";
+
+ $("#worksheetDetailContainer").html(
+ 'Caricamento dettaglio foglio...
',
+ );
+
+ fetch(endpoint, {
+ method: "POST",
+ headers: { "Content-Type": "application/x-www-form-urlencoded" },
+ body:
+ "action=get_worksheet_detail&worksheet_id=" +
+ encodeURIComponent(worksheetId),
+ })
+ .then(async (r) => {
+ const text = await r.text();
+ try {
+ return JSON.parse(text);
+ } catch (e) {
+ console.error("Risposta non JSON worksheet detail:", text);
+ throw new Error("Risposta non JSON, vedi console");
+ }
+ })
+ .then((data) => {
+ if (!data.success) {
+ console.error("Errore worksheets:", data);
+
+ $("#worksheetsListContainer").html(
+ 'Errore nel caricamento dei fogli: ' +
+ escapeHtml(
+ data.message || "nessun dettaglio restituito",
+ ) +
+ "
",
+ );
+ return;
+ }
+
+ const ws = data.worksheet || {};
+ const mixRows = data.mix_rows || [];
+
+ let mixHtml = `Nessuna mescola associata
`;
+
+ if (mixRows.length) {
+ mixHtml = `
+
+
+
+
+ | Pos |
+ Mescola |
+ Peso g/m |
+ Densità |
+ Durezza |
+ Lubr. |
+ Note lubr. |
+
+
+
+ `;
+
+ mixRows.forEach((r) => {
+ const nomeMescola = r.mescola_uscita
+ ? `${escapeHtml(r.mescola_nome || "—")} ${escapeHtml(r.mescola_uscita)}
`
+ : escapeHtml(r.mescola_nome || "—");
+
+ mixHtml += `
+
+ | ${escapeHtml(String(r.mix_position || ""))} |
+ ${nomeMescola} |
+ ${valueOrDash(r.mix_weight_g_m)} |
+ ${valueOrDash(r.required_density)} |
+ ${valueOrDash(r.required_hardness_shore_a)} |
+ ${valueOrDash(r.lubrication_type)} |
+ ${valueOrDash(r.lubrication_notes)} |
+
+ `;
+ });
+
+ mixHtml += `
+
+
+
+ `;
+ }
+
+ const html = `
+
+
+
+
${escapeHtml(ws.worksheet_number_label || "—")} / Rev. ${escapeHtml(ws.revision_label || "0")}
+
+ Stato: ${escapeHtml(ws.worksheet_status_label || "Attivo")}
+ ${ws.matrice_nome ? " • Profilo: " + escapeHtml(ws.matrice_nome) : ""}
+ ${ws.matrice_cliente ? " • Cliente matrice: " + escapeHtml(ws.matrice_cliente) : ""}
+
+
+
+
+
+
+
+
+
+
+
+
+ ${renderReadonlyField("Foglio", ws.worksheet_number_label)}
+ ${renderReadonlyField("Revisione", ws.revision_label)}
+ ${renderReadonlyField("Stato", ws.worksheet_status_label)}
+ ${renderReadonlyField("Data foglio", ws.worksheet_date_it)}
+ ${renderReadonlyField("Cliente override", ws.customer_name)}
+ ${renderReadonlyField("Codice profilo", ws.profile_type_code)}
+ ${renderReadonlyField("Marchiatura", ws.marking)}
+ ${renderReadonlyField("Approvato da", ws.approved_by)}
+ ${renderReadonlyField("Creato il", ws.created_at_it)}
+ ${renderReadonlyField("Ultimo aggiornamento", ws.updated_at_it)}
+
+
+
+
+
+
+
+
+
+
+ ${renderReadonlyField("Taglio", ws.control_frequency_cut)}
+ ${renderReadonlyField("Disegno", ws.control_frequency_drawing)}
+ ${renderReadonlyField("Dima", ws.control_frequency_jig)}
+ ${renderReadonlyField("Modalità dima", ws.control_mode_jig)}
+
+
+
Impostazione misure controllo produzione
+
${valueOrDash(ws.prod_control_measure_settings)}
+
+
+
+
+
+
+
+
+
+ ${renderReadonlyField("Codice confezione", ws.requested_package_code)}
+ ${renderReadonlyField("Metri per confezione", ws.meters_per_package)}
+ ${renderReadonlyField("Tolleranza metri/conf.", ws.meters_per_package_tolerance)}
+ ${renderReadonlyField("Scatola tipo", ws.box_type)}
+ ${renderReadonlyField("Conf./pezzi per scatola", ws.packages_or_pieces_per_box)}
+ ${renderReadonlyField("Metri per scatola", ws.meters_per_box)}
+ ${renderReadonlyField("Bancale tipo", ws.pallet_type)}
+ ${renderReadonlyField("Scatole/conf. per bancale", ws.boxes_or_packages_per_pallet)}
+
+
+
Note metri / confezione
+
${valueOrDash(ws.meters_per_package_notes)}
+
+
+
+
+
+
+
+
+
+ ${renderReadonlyField("Vel. prevista kg/h", ws.speed_expected_kg_h)}
+ ${renderReadonlyField("Vel. effettiva kg/h", ws.speed_actual_kg_h)}
+ ${renderReadonlyField("Vel. prevista m/h", ws.speed_expected_m_h)}
+ ${renderReadonlyField("Vel. effettiva m/h", ws.speed_actual_m_h)}
+
+
+
Note
+
${valueOrDash(ws.notes)}
+
+
+
+
+
+
+ `;
+
+ $("#worksheetDetailContainer").html(html);
+ })
+ .catch((err) => {
+ console.error("Catch loadMatriceWorksheets:", err);
+
+ $("#worksheetsListContainer").html(
+ 'Errore nel caricamento dei fogli: ' +
+ escapeHtml(err.message || "errore JavaScript/fetch") +
+ "
",
+ );
+ });
+ };
+
+ $(document).on("click", ".worksheets, .show-worksheets", function () {
+ const idmatrice = $(this).data("id");
+ const nome = $(this).data("nome") || "";
+ const endpoint =
+ $(this).data("endpoint") || "ajax/worksheet-linked-data.php";
+
+ loadMatriceWorksheets(idmatrice, nome, endpoint);
+ new bootstrap.Modal(
+ document.getElementById("worksheetsListModal"),
+ ).show();
+ });
+
+ $(document).on("click", ".open-worksheet-detail", function () {
+ const worksheetId = $(this).data("id");
+ const endpoint =
+ $(this).data("endpoint") || "ajax/worksheet-linked-data.php";
+
+ loadWorksheetDetail(worksheetId, endpoint);
+ new bootstrap.Modal(
+ document.getElementById("worksheetDetailModal"),
+ ).show();
+ });
+})();
diff --git a/public/userarea/include/worksheets-linked-modals.php b/public/userarea/include/worksheets-linked-modals.php
new file mode 100644
index 0000000..cad9c5d
--- /dev/null
+++ b/public/userarea/include/worksheets-linked-modals.php
@@ -0,0 +1,46 @@
+
+
+
+
+
+
+
+
+
+
+
+
Caricamento fogli di lavoro...
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/public/userarea/manage-worksheet.php b/public/userarea/manage-worksheet.php
index 75a300c..0e68c0d 100644
--- a/public/userarea/manage-worksheet.php
+++ b/public/userarea/manage-worksheet.php
@@ -64,6 +64,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['ajax']) && $_POST['aj
$approved_by = trim($_POST['approved_by'] ?? '');
$notes = trim($_POST['notes'] ?? '');
+ $worksheet_number = null;
if ($id > 0) {
$stmt = $pdo->prepare("
@@ -128,34 +129,65 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['ajax']) && $_POST['aj
exit;
}
+ $pdo->beginTransaction();
+
+ $stmtNum = $pdo->query("
+ SELECT IFNULL(MAX(worksheet_number), 0) + 1 AS next_number
+ FROM work_sheets
+");
+ $worksheet_number = (int)$stmtNum->fetchColumn();
+ if ($worksheet_number <= 0) {
+ $worksheet_number = 1;
+ }
+
$stmt = $pdo->prepare("
- INSERT INTO work_sheets
- (
- idmatrice, worksheet_date, customer_name, profile_type_code, marking,
- prod_control_measure_settings, control_frequency_cut, control_frequency_drawing,
- control_frequency_jig, control_mode_jig,
- requested_package_code, meters_per_package, meters_per_package_tolerance, meters_per_package_notes,
- box_type, packages_or_pieces_per_box, meters_per_box,
- pallet_type, boxes_or_packages_per_pallet,
- speed_expected_kg_h, speed_actual_kg_h, speed_expected_m_h, speed_actual_m_h,
- approved_by, notes
- )
- VALUES
- (
- ?, ?, ?, ?, ?,
- ?, ?, ?, ?, ?,
- ?, ?, ?, ?,
- ?, ?, ?,
- ?, ?,
- ?, ?, ?, ?,
- ?, ?
- )
- ");
+ INSERT INTO work_sheets
+ (
+ worksheet_number,
+ idmatrice,
+ worksheet_date,
+ customer_name,
+ profile_type_code,
+ revision_code,
+ worksheet_status,
+ marking,
+ prod_control_measure_settings,
+ control_frequency_cut,
+ control_frequency_drawing,
+ control_frequency_jig,
+ control_mode_jig,
+ requested_package_code,
+ meters_per_package,
+ meters_per_package_tolerance,
+ meters_per_package_notes,
+ box_type,
+ packages_or_pieces_per_box,
+ meters_per_box,
+ pallet_type,
+ boxes_or_packages_per_pallet,
+ speed_expected_kg_h,
+ speed_actual_kg_h,
+ speed_expected_m_h,
+ speed_actual_m_h,
+ approved_by,
+ notes
+ )
+ VALUES
+ (
+ ?, ?, ?, ?, ?, ?, ?,
+ ?, ?, ?, ?, ?, ?,
+ ?, ?, ?, ?, ?, ?, ?, ?, ?,
+ ?, ?, ?, ?, ?, ?
+ )
+");
$stmt->execute([
+ $worksheet_number,
$idmatrice,
$worksheet_date,
$customer_name !== '' ? $customer_name : null,
$profile_code !== '' ? $profile_code : null,
+ null, // revision_code = vuoto => revisione 0
+ 'active', // worksheet_status
$marking,
$prod_control !== '' ? $prod_control : null,
$freq_cut !== '' ? $freq_cut : null,
@@ -180,7 +212,14 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['ajax']) && $_POST['aj
]);
$newId = (int)$pdo->lastInsertId();
- echo json_encode(['success' => true, 'id' => $newId]);
+ $pdo->commit();
+
+ echo json_encode([
+ 'success' => true,
+ 'id' => $newId,
+ 'worksheet_number' => $worksheet_number,
+ 'worksheet_number_label' => worksheet_number_label($worksheet_number)
+ ]);
exit;
}
@@ -399,6 +438,12 @@ function h($v)
return htmlspecialchars((string)$v, ENT_QUOTES);
}
+function worksheet_number_label($n)
+{
+ $n = (int)$n;
+ return $n > 0 ? 'FL' . $n : 'Non assegnato';
+}
+
function ws_options($rows, $selectedValue, $defaultValue = '')
{
$selectedValue = (string)$selectedValue;
@@ -855,8 +900,20 @@ $isEdit = ($worksheet_id > 0);
= $isEdit ? 'In modifica' : 'Nuovo foglio' ?>
-
ID foglio
-
= $worksheet_id > 0 ? (int)$worksheet_id : 'Non salvato' ?>
+
Foglio / Revisione
+
+
+
Mescole inserite
@@ -1298,11 +1355,14 @@ $isEdit = ($worksheet_id > 0);
if (id > 0) {
btnAddMix.prop('disabled', false);
$('#mixWorksheetId').val(id);
- summaryWsId.text(id);
+
+ if (!summaryWsId.text().trim()) {
+ summaryWsId.text('Assegnato');
+ }
} else {
btnAddMix.prop('disabled', true);
$('#mixWorksheetId').val('0');
- summaryWsId.text('Non salvato');
+ summaryWsId.text('Non assegnato');
}
}
enableMixButtonIfSaved();
@@ -1350,6 +1410,11 @@ $isEdit = ($worksheet_id > 0);
}
wsIdInput.val(data.id);
+
+ if (data.worksheet_number_label) {
+ summaryWsId.text(data.worksheet_number_label);
+ }
+
enableMixButtonIfSaved();
if (!window.location.search.includes('id=')) {
@@ -1360,7 +1425,7 @@ $isEdit = ($worksheet_id > 0);
Swal.fire({
icon: 'success',
title: 'Testata salvata',
- text: 'Vuoi aggiungere subito le mescole?',
+ text: (data.worksheet_number_label ? ('Foglio ' + data.worksheet_number_label + ' creato correttamente. Vuoi aggiungere subito le mescole?') : 'Vuoi aggiungere subito le mescole?'),
showCancelButton: true,
confirmButtonText: 'Sì, aggiungi mescole',
cancelButtonText: 'No'
diff --git a/public/userarea/matrici.php b/public/userarea/matrici.php
index 37d3275..0314c14 100644
--- a/public/userarea/matrici.php
+++ b/public/userarea/matrici.php
@@ -34,192 +34,18 @@ function formatNullable($v, $fallback = '—')
return $v !== '' ? $v : $fallback;
}
-/**
- * AJAX HANDLERS
- */
-if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['ajax']) && $_POST['ajax'] == '1') {
- while (ob_get_level()) {
- ob_end_clean();
- }
-
- header('Content-Type: application/json; charset=utf-8');
-
- $action = $_POST['action'] ?? '';
-
- try {
- if ($action === 'get_matrice_worksheets') {
- $idmatrice = isset($_POST['idmatrice']) ? (int)$_POST['idmatrice'] : 0;
- if ($idmatrice <= 0) {
- echo json_encode([
- 'success' => false,
- 'message' => 'ID matrice non valido'
- ]);
- exit;
- }
-
- $stmt = $pdo->prepare("
- SELECT
- ws.id,
- ws.idmatrice,
- ws.worksheet_date,
- ws.customer_name,
- ws.profile_type_code,
- ws.marking,
- ws.approved_by,
- ws.created_at,
- ws.updated_at,
- (
- SELECT COUNT(*)
- FROM work_sheet_mescole wsm
- WHERE wsm.worksheet_id = ws.id
- ) AS mix_count
- FROM work_sheets ws
- WHERE ws.idmatrice = ?
- ORDER BY
- CASE WHEN ws.worksheet_date IS NULL THEN 1 ELSE 0 END,
- ws.worksheet_date DESC,
- ws.id DESC
- ");
- $stmt->execute([$idmatrice]);
- $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
-
- $data = [];
- foreach ($rows as $r) {
- $data[] = [
- 'id' => (int)$r['id'],
- 'idmatrice' => (int)$r['idmatrice'],
- 'worksheet_date' => $r['worksheet_date'],
- 'worksheet_date_it' => formatDateIT($r['worksheet_date']),
- 'customer_name' => $r['customer_name'] ?? '',
- 'profile_type_code' => $r['profile_type_code'] ?? '',
- 'marking' => $r['marking'] ?? '',
- 'approved_by' => $r['approved_by'] ?? '',
- 'created_at' => $r['created_at'] ?? '',
- 'created_at_it' => formatDateTimeIT($r['created_at'] ?? ''),
- 'updated_at' => $r['updated_at'] ?? '',
- 'updated_at_it' => formatDateTimeIT($r['updated_at'] ?? ''),
- 'mix_count' => (int)($r['mix_count'] ?? 0)
- ];
- }
-
- echo json_encode([
- 'success' => true,
- 'worksheets' => $data
- ]);
- exit;
- }
-
- if ($action === 'get_worksheet_detail') {
- $worksheetId = isset($_POST['worksheet_id']) ? (int)$_POST['worksheet_id'] : 0;
- if ($worksheetId <= 0) {
- echo json_encode([
- 'success' => false,
- 'message' => 'ID foglio non valido'
- ]);
- exit;
- }
-
- $stmt = $pdo->prepare("
- SELECT
- ws.*,
- m.nome AS matrice_nome,
- m.cliente AS matrice_cliente
- FROM work_sheets ws
- LEFT JOIN matrice m ON m.id = ws.idmatrice
- WHERE ws.id = ?
- LIMIT 1
- ");
- $stmt->execute([$worksheetId]);
- $ws = $stmt->fetch(PDO::FETCH_ASSOC);
-
- if (!$ws) {
- echo json_encode([
- 'success' => false,
- 'message' => 'Foglio di lavoro non trovato'
- ]);
- exit;
- }
-
- $stmtMix = $pdo->prepare("
- SELECT
- wsm.*,
- me.nome AS mescola_nome,
- me.nomeuscita AS mescola_uscita
- FROM work_sheet_mescole wsm
- LEFT JOIN mescole me ON me.id = wsm.idmescola
- WHERE wsm.worksheet_id = ?
- ORDER BY wsm.mix_position ASC, wsm.id ASC
- ");
- $stmtMix->execute([$worksheetId]);
- $mixRows = $stmtMix->fetchAll(PDO::FETCH_ASSOC);
-
- echo json_encode([
- 'success' => true,
- 'worksheet' => [
- 'id' => (int)$ws['id'],
- 'idmatrice' => (int)$ws['idmatrice'],
- 'matrice_nome' => $ws['matrice_nome'] ?? '',
- 'matrice_cliente' => $ws['matrice_cliente'] ?? '',
- 'worksheet_date' => $ws['worksheet_date'] ?? '',
- 'worksheet_date_it' => formatDateIT($ws['worksheet_date'] ?? ''),
- 'customer_name' => $ws['customer_name'] ?? '',
- 'profile_type_code' => $ws['profile_type_code'] ?? '',
- 'marking' => $ws['marking'] ?? '',
- 'prod_control_measure_settings' => $ws['prod_control_measure_settings'] ?? '',
- 'control_frequency_cut' => $ws['control_frequency_cut'] ?? '',
- 'control_frequency_drawing' => $ws['control_frequency_drawing'] ?? '',
- 'control_frequency_jig' => $ws['control_frequency_jig'] ?? '',
- 'control_mode_jig' => $ws['control_mode_jig'] ?? '',
- 'requested_package_code' => $ws['requested_package_code'] ?? '',
- 'meters_per_package' => $ws['meters_per_package'] ?? '',
- 'meters_per_package_tolerance' => $ws['meters_per_package_tolerance'] ?? '',
- 'meters_per_package_notes' => $ws['meters_per_package_notes'] ?? '',
- 'box_type' => $ws['box_type'] ?? '',
- 'packages_or_pieces_per_box' => $ws['packages_or_pieces_per_box'] ?? '',
- 'meters_per_box' => $ws['meters_per_box'] ?? '',
- 'pallet_type' => $ws['pallet_type'] ?? '',
- 'boxes_or_packages_per_pallet' => $ws['boxes_or_packages_per_pallet'] ?? '',
- 'speed_expected_kg_h' => $ws['speed_expected_kg_h'] ?? '',
- 'speed_actual_kg_h' => $ws['speed_actual_kg_h'] ?? '',
- 'speed_expected_m_h' => $ws['speed_expected_m_h'] ?? '',
- 'speed_actual_m_h' => $ws['speed_actual_m_h'] ?? '',
- 'approved_by' => $ws['approved_by'] ?? '',
- 'notes' => $ws['notes'] ?? '',
- 'created_at' => $ws['created_at'] ?? '',
- 'created_at_it' => formatDateTimeIT($ws['created_at'] ?? ''),
- 'updated_at' => $ws['updated_at'] ?? '',
- 'updated_at_it' => formatDateTimeIT($ws['updated_at'] ?? '')
- ],
- 'mix_rows' => array_map(function ($r) {
- return [
- 'id' => (int)$r['id'],
- 'mix_position' => (int)$r['mix_position'],
- 'mescola_nome' => $r['mescola_nome'] ?? '',
- 'mescola_uscita' => $r['mescola_uscita'] ?? '',
- 'mix_weight_g_m' => $r['mix_weight_g_m'] ?? '',
- 'required_density' => $r['required_density'] ?? '',
- 'required_hardness_shore_a' => $r['required_hardness_shore_a'] ?? '',
- 'lubrication_type' => $r['lubrication_type'] ?? '',
- 'lubrication_notes' => $r['lubrication_notes'] ?? ''
- ];
- }, $mixRows)
- ]);
- exit;
- }
-
- echo json_encode([
- 'success' => false,
- 'message' => 'Azione AJAX sconosciuta'
- ]);
- exit;
- } catch (Exception $e) {
- echo json_encode([
- 'success' => false,
- 'message' => $e->getMessage()
- ]);
- exit;
- }
+function worksheetNumberLabel($n)
+{
+ $n = (int)$n;
+ return $n > 0 ? 'FL' . $n : '—';
}
+
+function revisionLabel($rev)
+{
+ $rev = trim((string)$rev);
+ return $rev !== '' ? $rev : '0';
+}
+
?>
@@ -524,8 +350,60 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['ajax']) && $_POST['aj
}
.modal-worksheet-list {
- max-width: 980px;
- width: 94vw;
+ max-width: 1320px;
+ width: 97vw;
+ }
+
+ .worksheet-badge-fl {
+ display: inline-flex;
+ align-items: center;
+ justify-content: center;
+ min-width: 68px;
+ padding: 6px 12px;
+ border-radius: 999px;
+ background: #e8f7ee;
+ color: #198754;
+ font-weight: 800;
+ font-size: .85rem;
+ }
+
+ .worksheet-badge-rev {
+ display: inline-flex;
+ align-items: center;
+ justify-content: center;
+ min-width: 54px;
+ padding: 6px 10px;
+ border-radius: 999px;
+ background: #e7f1ff;
+ color: #0d6efd;
+ font-weight: 700;
+ font-size: .84rem;
+ }
+
+ .worksheet-badge-status-active {
+ display: inline-flex;
+ align-items: center;
+ justify-content: center;
+ min-width: 88px;
+ padding: 6px 10px;
+ border-radius: 999px;
+ background: #d1e7dd;
+ color: #0f5132;
+ font-weight: 700;
+ font-size: .84rem;
+ }
+
+ .worksheet-badge-status-inactive {
+ display: inline-flex;
+ align-items: center;
+ justify-content: center;
+ min-width: 88px;
+ padding: 6px 10px;
+ border-radius: 999px;
+ background: #f8d7da;
+ color: #842029;
+ font-weight: 700;
+ font-size: .84rem;
}
.modal-worksheet-view {
@@ -1104,53 +982,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['ajax']) && $_POST['aj
-
-
-
-
-
-
-
-
-
-
-
-
Caricamento fogli di lavoro...
-
-
-
-
-
-
-
-
-
@@ -1164,9 +995,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['ajax']) && $_POST['aj
-
+
-
+
-