getConnection(); /** * Helpers */ function h($v) { return htmlspecialchars((string)$v, ENT_QUOTES, 'UTF-8'); } 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 formatNullable($v, $fallback = '—') { $v = trim((string)$v); 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; } } ?> Gestione Matrici - <?= htmlspecialchars($titlewebsite, ENT_QUOTES, 'UTF-8'); ?>
Gestione elenco Profili
Elenco Completo
query(" SELECT m.*, COALESCE(lg.linee_associate, '—') AS linee_associate, COALESCE(mg.mescole_associate, '') AS mescole_associate, COALESCE(mg.mescole_count, 0) AS mescole_count, COALESCE(wsg.worksheets_count, 0) AS worksheets_count FROM matrice m LEFT JOIN ( SELECT ml.idmatrice, GROUP_CONCAT(pl.name ORDER BY pl.name SEPARATOR ', ') AS linee_associate FROM matrici_lines ml JOIN production_lines pl ON pl.id = ml.idlinea GROUP BY ml.idmatrice ) lg ON lg.idmatrice = m.id LEFT JOIN ( SELECT mm.idmatrice, GROUP_CONCAT(ms.nome ORDER BY ms.nome SEPARATOR ', ') AS mescole_associate, COUNT(*) AS mescole_count FROM matrici_mescole mm JOIN mescole ms ON ms.id = mm.idmescola GROUP BY mm.idmatrice ) mg ON mg.idmatrice = m.id LEFT JOIN ( SELECT ws.idmatrice, COUNT(*) AS worksheets_count FROM work_sheets ws GROUP BY ws.idmatrice ) wsg ON wsg.idmatrice = m.id ORDER BY CASE WHEN TRIM(COALESCE(m.nome, '')) = '' THEN 1 ELSE 0 END, m.nome ASC "); if ($stmt->rowCount() === 0) { echo ""; } else { while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $dataIT = formatDateIT($row['data_produzione']); $foto = $row['photo'] ?? ''; $pathFoto = "photos/matrici/" . $foto; $placeholder = "assets/images/no-photo.png"; if ($foto && file_exists($pathFoto)) { $thumb = $pathFoto; $hasPhoto = true; } else { $thumb = $placeholder; $hasPhoto = false; } echo ""; $imgSrc = $hasPhoto ? $thumb : ''; echo ""; echo ""; echo ""; $lineeTxt = $row['linee_associate'] ?? '—'; $mescoleTxt = $row['mescole_associate'] ?? ''; $mescoleCount = (int)($row['mescole_count'] ?? 0); $worksheetsCount = (int)($row['worksheets_count'] ?? 0); $btnMescole = ''; if ($mescoleCount > 0) { $btnMescole = " "; } echo ""; echo ""; echo ""; echo ""; } } ?>
Foto Nome Cliente Linee Fogli Azioni
Nessuna matrice presente
NP " . htmlspecialchars($row['nome']) . "" . htmlspecialchars($row['cliente']) . "" . htmlspecialchars($lineeTxt) . $btnMescole . "
{$worksheetsCount}"; if ($worksheetsCount > 0) { echo ""; } else { echo ""; } echo "