diff --git a/public/userarea/delete_status.php b/public/userarea/delete_status.php new file mode 100644 index 0000000..a1aaf13 --- /dev/null +++ b/public/userarea/delete_status.php @@ -0,0 +1,37 @@ +getConnection(); + + $id = intval($_GET['id'] ?? 0); + + if ($id <= 0) { + echo json_encode(['success' => false, 'message' => 'ID non valido']); + exit; + } + + // Verifica se status è usato in produzione + $check = $pdo->prepare("SELECT COUNT(*) FROM productiondata WHERE id_status = :id"); + $check->execute([':id' => $id]); + $count = $check->fetchColumn(); + + if ($count > 0) { + echo json_encode([ + 'success' => false, + 'message' => "Impossibile eliminare: lo status è utilizzato in $count record di produzione." + ]); + exit; + } + + // Eliminazione + $stmt = $pdo->prepare("DELETE FROM production_status WHERE id = :id"); + $stmt->execute([':id' => $id]); + + echo json_encode(['success' => true]); +} catch (Exception $e) { + echo json_encode(['success' => false, 'message' => $e->getMessage()]); +} diff --git a/public/userarea/edit_status.php b/public/userarea/edit_status.php new file mode 100644 index 0000000..333256b --- /dev/null +++ b/public/userarea/edit_status.php @@ -0,0 +1,48 @@ +getConnection(); + + // Validazione + $id = intval($_POST['id'] ?? 0); + $nome = trim($_POST['nome'] ?? ''); + $ordinamento = intval($_POST['ordinamento'] ?? 0); + $badge = $_POST['badge_color'] ?? '#6c757d'; + $line = $_POST['line_color'] ?? '#e9ecef'; + + if ($id <= 0) { + echo json_encode(['success' => false, 'message' => 'ID non valido']); + exit; + } + + if ($nome === '') { + echo json_encode(['success' => false, 'message' => 'Il nome è obbligatorio']); + exit; + } + + // Update + $stmt = $pdo->prepare(" + UPDATE production_status + SET nome = :nome, + ordinamento = :ordinamento, + badge_color = :badge, + line_color = :line + WHERE id = :id + "); + + $stmt->execute([ + ':nome' => $nome, + ':ordinamento' => $ordinamento, + ':badge' => $badge, + ':line' => $line, + ':id' => $id + ]); + + echo json_encode(['success' => true]); +} catch (Exception $e) { + echo json_encode(['success' => false, 'message' => $e->getMessage()]); +} diff --git a/public/userarea/production_dashboard.php b/public/userarea/production_dashboard.php index abc12f5..9e7da12 100644 --- a/public/userarea/production_dashboard.php +++ b/public/userarea/production_dashboard.php @@ -276,20 +276,21 @@ -
- - --> +
+
diff --git a/public/userarea/production_line_view.php b/public/userarea/production_line_view.php index 802de43..12ad2d7 100644 --- a/public/userarea/production_line_view.php +++ b/public/userarea/production_line_view.php @@ -20,9 +20,7 @@ $statusProgrammatoId = $statusProgrammato['id']; $statusProduzioneId = $statusProduzione['id']; $statusPausaId = $statusPausa['id']; -// --- DATA E LINEA SELEZIONATE --- -$selected_date = $_GET['date'] ?? date('Y-m-d'); -$selected_line = $_GET['line'] ?? ''; + // --- AVVIO / RIPRESA PRODUZIONE --- if ($_SERVER['REQUEST_METHOD'] === 'POST' && !empty($_POST['start_production'])) { @@ -174,64 +172,13 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && !empty($_POST['save_final_data'])) exit; } -// --- AJAX: carica record giorno successivo --- -if (!empty($_GET['ajax_next'])) { - - $date = $_GET['date'] ?? date('Y-m-d'); - $lineRaw = $_GET['line'] ?? ''; - $lineArray = $lineRaw !== '' ? explode(',', $lineRaw) : []; - - $sql = "SELECT - p.*, - m.nome AS matrice, - ms.nome AS mescola, - l.name AS linea, - c.nome AS cliente, - s.nome AS status_nome, - s.badge_color, - s.line_color, - p.tempo_totale_produzione - FROM productiondata p - LEFT JOIN matrice m ON p.idmatrice = m.id - LEFT JOIN mescole ms ON p.idmescola = ms.id - LEFT JOIN production_lines l ON p.id_linea = l.id - LEFT JOIN clients c ON p.id_cliente = c.id - LEFT JOIN production_status s ON p.id_status = s.id - WHERE p.data_produzione = :date - AND p.id_status IN (:programmato, :produzione, :pausa)" - . (!empty($lineArray) ? " AND p.id_linea IN (" . implode(',', array_map('intval', $lineArray)) . ")" : "") - . " ORDER BY l.line_number, p.Data"; - - $params = [ - ':date' => $date, - ':programmato' => $statusProgrammatoId, - ':produzione' => $statusProduzioneId, - ':pausa' => $statusPausaId - ]; - - $stmt = $pdo->prepare($sql); - $stmt->execute($params); - - $recordsNext = $stmt->fetchAll(); - - if (empty($recordsNext)) { - exit; // ritorna vuoto - } - - foreach ($recordsNext as $r) { - include __DIR__ . "/render_production_card.php"; - } - - exit; -} - // --- AJAX PRINCIPALE: carica i record della data selezionata --- if (!empty($_GET['ajax'])) { - $date = $_GET['date'] ?? date('Y-m-d'); $lineRaw = $_GET['line'] ?? ''; $lineArray = $lineRaw !== '' ? explode(',', $lineRaw) : []; + // --- RECORD IN PRODUZIONE (2,7,8) $sql = "SELECT p.*, m.nome AS matrice, @@ -248,34 +195,55 @@ if (!empty($_GET['ajax'])) { LEFT JOIN production_lines l ON p.id_linea = l.id LEFT JOIN clients c ON p.id_cliente = c.id LEFT JOIN production_status s ON p.id_status = s.id - WHERE p.data_produzione = :date - AND p.id_status IN (:programmato, :produzione, :pausa)" - . (!empty($lineArray) ? " AND p.id_linea IN (" . implode(',', array_map('intval', $lineArray)) . ")" : "") - . " ORDER BY l.line_number, p.Data"; - - $params = [ - ':date' => $date, - ':programmato' => $statusProgrammatoId, - ':produzione' => $statusProduzioneId, - ':pausa' => $statusPausaId - ]; + WHERE p.id_status IN (2, 7, 8) + " . (!empty($lineArray) ? " AND p.id_linea IN (" . implode(',', array_map('intval', $lineArray)) . ")" : "") . " + ORDER BY l.line_number, p.Data"; $stmt = $pdo->prepare($sql); - $stmt->execute($params); + $stmt->execute(); $records = $stmt->fetchAll(); - if (empty($records)) { - exit; - } - foreach ($records as $r) { include __DIR__ . "/render_production_card.php"; } + // --- RECORD IN STATO 6 ORDINATI PER PRIORITY + $sql2 = "SELECT + p.*, + m.nome AS matrice, + ms.nome AS mescola, + l.name AS linea, + c.nome AS cliente, + s.nome AS status_nome, + s.badge_color, + s.line_color, + p.tempo_totale_produzione + FROM productiondata p + LEFT JOIN matrice m ON p.idmatrice = m.id + LEFT JOIN mescole ms ON p.idmescola = ms.id + LEFT JOIN production_lines l ON p.id_linea = l.id + LEFT JOIN clients c ON p.id_cliente = c.id + LEFT JOIN production_status s ON p.id_status = s.id + WHERE p.id_status = 6 + " . (!empty($lineArray) ? " AND p.id_linea IN (" . implode(',', array_map('intval', $lineArray)) . ")" : "") . " + ORDER BY p.priority ASC"; + + $stmt2 = $pdo->prepare($sql2); + $stmt2->execute(); + $recordsPriority = $stmt2->fetchAll(); + + if (!empty($recordsPriority)) { + echo '
Programmato (in ordine di priorità)
'; + foreach ($recordsPriority as $r) { + include __DIR__ . "/render_production_card.php"; + } + } + exit; } + ?> @@ -287,7 +255,7 @@ if (!empty($_GET['ajax'])) { Linea Produzione - Tablet - + + + + +
+ + + +
+
+ +
+ +
+
Gestione Status Produzione
+ +
+ +
+ +
+
Elenco Status
+ +
+ +
+ + + + + + + + + + + + + getConnection(); + + $stmt = $pdo->query("SELECT * FROM production_status ORDER BY ordinamento ASC"); + + while ($row = $stmt->fetch(PDO::FETCH_ASSOC)): + ?> + + + + + + + + + + + + + +
IDNomeOrdinamentoColore BadgeColore LineaAzioni
+
+ +
+
+ +
+ + + +
+
+ +
+
+ +
+
+ + +
+ + + + + + + + + + + + \ No newline at end of file diff --git a/public/userarea/save_status.php b/public/userarea/save_status.php new file mode 100644 index 0000000..641a70b --- /dev/null +++ b/public/userarea/save_status.php @@ -0,0 +1,37 @@ +getConnection(); + + // Validazione campi + $nome = trim($_POST['nome'] ?? ''); + $ordinamento = intval($_POST['ordinamento'] ?? 0); + $badge = $_POST['badge_color'] ?? '#6c757d'; + $line = $_POST['line_color'] ?? '#e9ecef'; + + if ($nome === '') { + echo json_encode(['success' => false, 'message' => 'Il nome è obbligatorio']); + exit; + } + + // Inserimento + $stmt = $pdo->prepare(" + INSERT INTO production_status (nome, ordinamento, badge_color, line_color) + VALUES (:nome, :ordinamento, :badge, :line) + "); + + $stmt->execute([ + ':nome' => $nome, + ':ordinamento' => $ordinamento, + ':badge' => $badge, + ':line' => $line, + ]); + + echo json_encode(['success' => true]); +} catch (Exception $e) { + echo json_encode(['success' => false, 'message' => $e->getMessage()]); +}