fixed start stop pause
This commit is contained in:
parent
6f3b933a71
commit
4c63f16a54
35
public/userarea/delete_pause_reason.php
Normal file
35
public/userarea/delete_pause_reason.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/class/db-functions.php';
|
||||
|
||||
$db = DBHandlerSelect::getInstance();
|
||||
$pdo = $db->getConnection();
|
||||
|
||||
$id = (int)($_GET['id'] ?? 0);
|
||||
|
||||
if ($id <= 0) {
|
||||
echo json_encode(['success' => false, 'message' => 'ID non valido.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
try {
|
||||
// Verifica se è usata in production_pauses
|
||||
$check = $pdo->prepare("SELECT COUNT(*) FROM production_pauses WHERE reason_id = :id");
|
||||
$check->execute([':id' => $id]);
|
||||
$used = $check->fetchColumn();
|
||||
|
||||
if ($used > 0) {
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'message' => 'Impossibile eliminare: la causa è utilizzata in una o più pause.'
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Elimina
|
||||
$stmt = $pdo->prepare("DELETE FROM pause_reasons WHERE id = :id");
|
||||
$stmt->execute([':id' => $id]);
|
||||
|
||||
echo json_encode(['success' => true]);
|
||||
} catch (Exception $e) {
|
||||
echo json_encode(['success' => false, 'message' => $e->getMessage()]);
|
||||
}
|
||||
40
public/userarea/edit_pause_reason.php
Normal file
40
public/userarea/edit_pause_reason.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/class/db-functions.php';
|
||||
|
||||
$db = DBHandlerSelect::getInstance();
|
||||
$pdo = $db->getConnection();
|
||||
|
||||
$id = (int)($_POST['id'] ?? 0);
|
||||
$name = trim($_POST['name'] ?? '');
|
||||
$description = trim($_POST['description'] ?? '');
|
||||
$is_problem = isset($_POST['is_problem']) ? (int)$_POST['is_problem'] : 0;
|
||||
|
||||
if ($id <= 0) {
|
||||
echo json_encode(['success' => false, 'message' => 'ID non valido.']);
|
||||
exit;
|
||||
}
|
||||
if ($name === '') {
|
||||
echo json_encode(['success' => false, 'message' => 'Il nome è obbligatorio.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
try {
|
||||
$stmt = $pdo->prepare("
|
||||
UPDATE pause_reasons
|
||||
SET name = :name,
|
||||
description = :description,
|
||||
is_problem = :is_problem
|
||||
WHERE id = :id
|
||||
");
|
||||
|
||||
$stmt->execute([
|
||||
':name' => $name,
|
||||
':description' => $description !== '' ? $description : null,
|
||||
':is_problem' => $is_problem,
|
||||
':id' => $id
|
||||
]);
|
||||
|
||||
echo json_encode(['success' => true]);
|
||||
} catch (Exception $e) {
|
||||
echo json_encode(['success' => false, 'message' => $e->getMessage()]);
|
||||
}
|
||||
@ -191,6 +191,18 @@
|
||||
font-size: 2.6rem;
|
||||
}
|
||||
}
|
||||
|
||||
.btn-problem {
|
||||
background-color: #ef4444 !important;
|
||||
/* rosso brillante */
|
||||
color: #ffffff !important;
|
||||
border-radius: 12px;
|
||||
}
|
||||
|
||||
.btn-problem:hover {
|
||||
background-color: #dc2626 !important;
|
||||
/* rosso scuro hover */
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
@ -285,10 +297,11 @@
|
||||
</button>
|
||||
|
||||
|
||||
<!-- <button class="dash-btn btn-visualizza" onclick="location.href='production_all.php'">
|
||||
<div class="dash-icon">📊</div>
|
||||
<div>Riepilogo Produzione</div>
|
||||
</button> -->
|
||||
<button class="dash-btn btn-problem" onclick="location.href='production_pause_reasons.php'">
|
||||
<div class="dash-icon">🛑</div>
|
||||
<div>Cause di Pausa</div>
|
||||
</button>
|
||||
|
||||
<div></div>
|
||||
</div>
|
||||
|
||||
|
||||
1557
public/userarea/production_line_view2.php
Normal file
1557
public/userarea/production_line_view2.php
Normal file
File diff suppressed because it is too large
Load Diff
333
public/userarea/production_pause_reasons.php
Normal file
333
public/userarea/production_pause_reasons.php
Normal file
@ -0,0 +1,333 @@
|
||||
<?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 Cause di Pausa - <?= htmlspecialchars($titlewebsite, ENT_QUOTES, 'UTF-8'); ?></title>
|
||||
|
||||
<!-- jQuery, Bootstrap, DataTables, SweetAlert -->
|
||||
<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>
|
||||
|
||||
<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);
|
||||
}
|
||||
|
||||
th,
|
||||
td {
|
||||
vertical-align: middle !important;
|
||||
text-align: center !important;
|
||||
}
|
||||
|
||||
.badge-problem {
|
||||
background: #dc3545;
|
||||
color: white;
|
||||
padding: 6px 12px;
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
.badge-normal {
|
||||
background: #0d6efd;
|
||||
color: white;
|
||||
padding: 6px 12px;
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
.btn-action {
|
||||
border: none;
|
||||
background: transparent;
|
||||
cursor: pointer;
|
||||
font-size: 1.3rem;
|
||||
}
|
||||
|
||||
.btn-action.edit {
|
||||
color: #0d6efd;
|
||||
}
|
||||
|
||||
.btn-action.delete {
|
||||
color: #dc3545;
|
||||
}
|
||||
|
||||
.btn-action:hover {
|
||||
transform: scale(1.2);
|
||||
}
|
||||
|
||||
.back-dashboard {
|
||||
background-color: #cfe3ff !important;
|
||||
color: #1f2d3d !important;
|
||||
border-radius: 10px;
|
||||
font-weight: 600;
|
||||
padding: 10px 18px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="wrapper">
|
||||
<?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 text-center w-100">Gestione Cause di Pausa</h5>
|
||||
|
||||
<button type="button"
|
||||
class="btn back-dashboard position-absolute end-0 me-3"
|
||||
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 Cause</h6>
|
||||
<button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addReasonModal">
|
||||
➕ Aggiungi Causa
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="table-responsive">
|
||||
<table id="tabReasons" class="table table-striped align-middle">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Nome</th>
|
||||
<th>Descrizione</th>
|
||||
<th>Tipo</th>
|
||||
<th>Azioni</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
$db = DBHandlerSelect::getInstance();
|
||||
$pdo = $db->getConnection();
|
||||
|
||||
$stmt = $pdo->query("SELECT * FROM pause_reasons ORDER BY id ASC");
|
||||
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)):
|
||||
?>
|
||||
<tr>
|
||||
<td><?= $row['id'] ?></td>
|
||||
<td><?= htmlspecialchars($row['name']) ?></td>
|
||||
<td><?= htmlspecialchars($row['description']) ?></td>
|
||||
|
||||
<td>
|
||||
<?php if ($row['is_problem']): ?>
|
||||
<span class="badge-problem">Problema tecnico</span>
|
||||
<?php else: ?>
|
||||
<span class="badge-normal">Pausa</span>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
|
||||
<td>
|
||||
<button class="btn-action edit"
|
||||
data-id="<?= $row['id'] ?>"
|
||||
data-name="<?= htmlspecialchars($row['name'], ENT_QUOTES) ?>"
|
||||
data-desc="<?= htmlspecialchars($row['description'], ENT_QUOTES) ?>"
|
||||
data-problem="<?= $row['is_problem'] ?>">
|
||||
<i class="fas fa-edit"></i>
|
||||
</button>
|
||||
|
||||
<button class="btn-action delete" data-id="<?= $row['id'] ?>">
|
||||
<i class="fas fa-trash"></i>
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endwhile; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php include('include/footer.php'); ?>
|
||||
</div>
|
||||
|
||||
<!-- MODALE AGGIUNTA -->
|
||||
<div class="modal fade" id="addReasonModal" tabindex="-1">
|
||||
<div class="modal-dialog modal-dialog-centered">
|
||||
<div class="modal-content">
|
||||
|
||||
<div class="modal-header" style="background:#cfe3ff">
|
||||
<h5 class="modal-title">Aggiungi Causa Pausa</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
|
||||
<form id="addReasonForm">
|
||||
<div class="modal-body">
|
||||
|
||||
<label class="fw-semibold">Nome</label>
|
||||
<input type="text" name="name" class="form-control mb-3" required>
|
||||
|
||||
<label class="fw-semibold">Descrizione (opzionale)</label>
|
||||
<textarea name="description" class="form-control mb-3"></textarea>
|
||||
|
||||
<label class="fw-semibold">Tipo</label><br>
|
||||
<select name="is_problem" class="form-control">
|
||||
<option value="0">Pausa normale</option>
|
||||
<option value="1">Problema tecnico</option>
|
||||
</select>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="modal-footer">
|
||||
<button type="submit" class="btn btn-primary">💾 Salva</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- MODALE MODIFICA -->
|
||||
<div class="modal fade" id="editReasonModal" tabindex="-1">
|
||||
<div class="modal-dialog modal-dialog-centered">
|
||||
<div class="modal-content">
|
||||
|
||||
<div class="modal-header" style="background:#cfe3ff">
|
||||
<h5 class="modal-title">Modifica Causa</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
|
||||
<form id="editReasonForm">
|
||||
<div class="modal-body">
|
||||
|
||||
<input type="hidden" id="edit_id" name="id">
|
||||
|
||||
<label class="fw-semibold">Nome</label>
|
||||
<input type="text" id="edit_name" name="name" class="form-control mb-3" required>
|
||||
|
||||
<label class="fw-semibold">Descrizione</label>
|
||||
<textarea id="edit_description" name="description" class="form-control mb-3"></textarea>
|
||||
|
||||
<label class="fw-semibold">Tipo</label>
|
||||
<select id="edit_is_problem" name="is_problem" class="form-control">
|
||||
<option value="0">Pausa normale</option>
|
||||
<option value="1">Problema tecnico</option>
|
||||
</select>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="modal-footer">
|
||||
<button type="submit" class="btn btn-primary">💾 Aggiorna</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
|
||||
$('#tabReasons').DataTable({
|
||||
order: [
|
||||
[0, 'asc']
|
||||
],
|
||||
pageLength: 50,
|
||||
language: {
|
||||
url: 'https://cdn.datatables.net/plug-ins/1.13.6/i18n/it-IT.json'
|
||||
}
|
||||
});
|
||||
|
||||
// ➕ AGGIUNTA
|
||||
$("#addReasonForm").on("submit", function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
fetch("save_pause_reason.php", {
|
||||
method: "POST",
|
||||
body: new FormData(this)
|
||||
})
|
||||
.then(r => r.json())
|
||||
.then(d => {
|
||||
if (d.success) {
|
||||
Swal.fire("Salvato!", "Causa aggiunta.", "success")
|
||||
.then(() => location.reload());
|
||||
} else Swal.fire("Errore", d.message, "error");
|
||||
});
|
||||
});
|
||||
|
||||
// ✏️ APRI MODALE MODIFICA
|
||||
$(document).on("click", ".edit", function() {
|
||||
|
||||
$("#edit_id").val($(this).data("id"));
|
||||
$("#edit_name").val($(this).data("name"));
|
||||
$("#edit_description").val($(this).data("desc"));
|
||||
$("#edit_is_problem").val($(this).data("problem"));
|
||||
|
||||
$("#editReasonModal").modal("show");
|
||||
});
|
||||
|
||||
// 💾 SALVA MODIFICA
|
||||
$("#editReasonForm").on("submit", function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
fetch("edit_pause_reason.php", {
|
||||
method: "POST",
|
||||
body: new FormData(this)
|
||||
})
|
||||
.then(r => r.json())
|
||||
.then(d => {
|
||||
if (d.success) {
|
||||
Swal.fire("Aggiornato!", "Causa modificata.", "success")
|
||||
.then(() => location.reload());
|
||||
} else Swal.fire("Errore", d.message, "error");
|
||||
});
|
||||
});
|
||||
|
||||
// 🗑️ ELIMINA
|
||||
$(document).on("click", ".delete", function() {
|
||||
const id = $(this).data("id");
|
||||
|
||||
Swal.fire({
|
||||
title: "Eliminare la causa?",
|
||||
text: "Questa azione non può essere annullata.",
|
||||
icon: "warning",
|
||||
showCancelButton: true,
|
||||
confirmButtonText: "Sì, elimina",
|
||||
cancelButtonText: "Annulla"
|
||||
}).then(result => {
|
||||
if (result.isConfirmed) {
|
||||
fetch("delete_pause_reason.php?id=" + id)
|
||||
.then(r => r.json())
|
||||
.then(d => {
|
||||
if (d.success) {
|
||||
Swal.fire("Eliminato!", "Causa rimossa.", "success")
|
||||
.then(() => location.reload());
|
||||
} else Swal.fire("Errore", d.message, "error");
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@ -71,10 +71,14 @@ $statusNome = $r['status_nome'];
|
||||
<div class="record-expanded">
|
||||
<?php if ($isInProduction || $isPaused): ?>
|
||||
|
||||
<div class="timer-display" data-start="<?= $startTime ?>">
|
||||
<div class="timer-display"
|
||||
data-start="<?= $r['start_time'] ? strtotime($r['start_time']) : '' ?>"
|
||||
data-end="<?= $r['end_time'] ? strtotime($r['end_time']) : '' ?>">
|
||||
<span class="timer">00:00:00</span>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<!-- Teorici nascosti (per modale finale) -->
|
||||
<span data-field="kg_sp" style="display:none;"><?= $r['kg_sp'] ?></span>
|
||||
<span data-field="metri" style="display:none;"><?= $r['metri'] ?></span>
|
||||
|
||||
31
public/userarea/save_pause_reason.php
Normal file
31
public/userarea/save_pause_reason.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/class/db-functions.php';
|
||||
|
||||
$db = DBHandlerSelect::getInstance();
|
||||
$pdo = $db->getConnection();
|
||||
|
||||
$name = trim($_POST['name'] ?? '');
|
||||
$description = trim($_POST['description'] ?? '');
|
||||
$is_problem = isset($_POST['is_problem']) ? (int)$_POST['is_problem'] : 0;
|
||||
|
||||
if ($name === '') {
|
||||
echo json_encode(['success' => false, 'message' => 'Il nome è obbligatorio.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
try {
|
||||
$stmt = $pdo->prepare("
|
||||
INSERT INTO pause_reasons (name, description, is_problem)
|
||||
VALUES (:name, :description, :is_problem)
|
||||
");
|
||||
|
||||
$stmt->execute([
|
||||
':name' => $name,
|
||||
':description' => $description !== '' ? $description : null,
|
||||
':is_problem' => $is_problem
|
||||
]);
|
||||
|
||||
echo json_encode(['success' => true]);
|
||||
} catch (Exception $e) {
|
||||
echo json_encode(['success' => false, 'message' => $e->getMessage()]);
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user