fixed scadenziario new field, dpi, dpi trash

This commit is contained in:
2026-07-16 12:05:37 +02:00
parent 1ef6cca149
commit 4e61426be7
8 changed files with 186 additions and 18 deletions
@@ -0,0 +1,44 @@
<?php
include('../../include/headscript.php');
header('Content-Type: application/json; charset=utf-8');
try {
$pdo = DBHandlerSelect::getInstance()->getConnection();
$id = (int)($_POST['id'] ?? 0);
if ($id <= 0) {
echo json_encode([
'success' => false,
'message' => 'ID DPI non valido.'
]);
exit;
}
$stmt = $pdo->prepare("
DELETE FROM employee_ppe_items
WHERE id = ?
");
$stmt->execute([$id]);
if ($stmt->rowCount() === 0) {
echo json_encode([
'success' => false,
'message' => 'Record non trovato o già eliminato.'
]);
exit;
}
echo json_encode([
'success' => true,
'message' => 'Record DPI eliminato definitivamente.'
]);
exit;
} catch (Throwable $e) {
echo json_encode([
'success' => false,
'message' => $e->getMessage()
]);
exit;
}
+73 -12
View File
@@ -1448,10 +1448,13 @@ function fmtFileSize(?int $bytes): string
data-notes="<?= htmlspecialchars($p['notes'] ?? '', ENT_QUOTES) ?>">✏️</button>
<?php if (($p['status'] ?? '') === 'assigned'): ?>
<button class="btn btn-sm btn-outline-danger delete-ppe"
<button class="btn btn-sm btn-outline-warning withdraw-ppe"
data-id="<?= $pid ?>"
data-name="<?= htmlspecialchars($p['ppe_name'], ENT_QUOTES) ?>">Rimuovi</button>
data-name="<?= htmlspecialchars($p['ppe_name'], ENT_QUOTES) ?>">Ritira</button>
<?php endif; ?>
<button class="btn btn-sm btn-outline-danger destroy-ppe"
data-id="<?= $pid ?>"
data-name="<?= htmlspecialchars($p['ppe_name'], ENT_QUOTES) ?>" title="Elimina record">🗑️</button>
</td>
<?php endif; ?>
</tr>
@@ -1518,10 +1521,13 @@ function fmtFileSize(?int $bytes): string
data-notes="<?= htmlspecialchars($p['notes'] ?? '', ENT_QUOTES) ?>">✏️ Modifica</button>
<?php if (($p['status'] ?? '') === 'assigned'): ?>
<button class="btn btn-sm btn-outline-danger delete-ppe"
<button class="btn btn-sm btn-outline-warning withdraw-ppe"
data-id="<?= $pid ?>"
data-name="<?= htmlspecialchars($p['ppe_name'], ENT_QUOTES) ?>">Rimuovi</button>
data-name="<?= htmlspecialchars($p['ppe_name'], ENT_QUOTES) ?>">Ritira</button>
<?php endif; ?>
<button class="btn btn-sm btn-outline-danger destroy-ppe"
data-id="<?= $pid ?>"
data-name="<?= htmlspecialchars($p['ppe_name'], ENT_QUOTES) ?>">🗑️ Elimina</button>
</div>
<?php endif; ?>
</div>
@@ -3002,19 +3008,19 @@ function fmtFileSize(?int $bytes): string
});
});
// ---- PPE: remove / mark as returned ----
$(document).on("click", ".delete-ppe", function() {
// ---- PPE: withdraw / mark as returned ----
$(document).on("click", ".withdraw-ppe", function() {
const id = $(this).data("id");
const name = $(this).data("name");
Swal.fire({
title: "Confermi la rimozione?",
text: name ? ("DPI: " + name) : "Il DPI verrà segnato come restituito.",
title: "Confermi il ritiro?",
text: name ? ("Il DPI \"" + name + "\" verrà ritirato dal dipendente.") : "Il DPI verrà ritirato dal dipendente.",
icon: "warning",
showCancelButton: true,
confirmButtonColor: "#d33",
confirmButtonColor: "#e8930c",
cancelButtonColor: "#6c757d",
confirmButtonText: "Sì, rimuovi",
confirmButtonText: "Sì, ritira",
cancelButtonText: "Annulla"
}).then((result) => {
if (!result.isConfirmed) return;
@@ -3034,7 +3040,7 @@ function fmtFileSize(?int $bytes): string
if (data.success) {
Swal.fire({
icon: "success",
title: "Rimosso!",
title: "Ritirato!",
confirmButtonColor: "#3085d6"
})
.then(() => location.reload());
@@ -3042,7 +3048,62 @@ function fmtFileSize(?int $bytes): string
Swal.fire({
icon: "error",
title: "Errore",
text: data.message || "Impossibile rimuovere."
text: data.message || "Impossibile ritirare."
});
}
})
.catch(err => {
Swal.fire({
icon: "error",
title: "Errore",
text: "Errore di comunicazione."
});
console.error(err);
});
});
});
// ---- PPE: destroy record (hard delete) ----
$(document).on("click", ".destroy-ppe", function() {
const id = $(this).data("id");
const name = $(this).data("name");
Swal.fire({
title: "Eliminare definitivamente il record?",
html: (name ? ("DPI: <strong>" + name + "</strong><br>") : "") + "Questa azione elimina il record e non può essere annullata. Usala solo in caso di inserimento errato.",
icon: "warning",
showCancelButton: true,
confirmButtonColor: "#d33",
cancelButtonColor: "#6c757d",
confirmButtonText: "Sì, elimina",
cancelButtonText: "Annulla"
}).then((result) => {
if (!result.isConfirmed) return;
const p = new URLSearchParams();
p.append('id', id);
fetch("ajax/employee_profile/destroy_ppe.php", {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded"
},
body: p.toString()
})
.then(r => r.json())
.then(data => {
if (data.success) {
Swal.fire({
icon: "success",
title: "Eliminato!",
confirmButtonColor: "#3085d6"
})
.then(() => location.reload());
} else {
Swal.fire({
icon: "error",
title: "Errore",
text: data.message || "Impossibile eliminare."
});
}
})
+32 -2
View File
@@ -563,6 +563,15 @@ $totalCategories = count($categories);
.ppe-name {
font-weight: 800;
color: #0f172a;
white-space: normal;
word-break: break-word;
}
.btn-desc-popup {
border-radius: 8px;
font-weight: 700;
font-size: 0.78rem;
padding: 2px 8px;
}
.ppe-description {
@@ -819,8 +828,13 @@ $totalCategories = count($categories);
</div>
<?php if (!empty($ppe['description'])): ?>
<div class="ppe-description">
<?= htmlspecialchars($ppe['description'], ENT_QUOTES, 'UTF-8'); ?>
<div class="mt-1">
<button type="button"
class="btn btn-sm btn-outline-secondary btn-desc-popup btnViewDescription"
data-ppe-name="<?= htmlspecialchars($ppe['name'], ENT_QUOTES, 'UTF-8'); ?>"
data-ppe-description="<?= htmlspecialchars($ppe['description'], ENT_QUOTES, 'UTF-8'); ?>">
📄 Descrizione
</button>
</div>
<?php else: ?>
<div class="ppe-description">
@@ -1391,7 +1405,23 @@ $totalCategories = count($categories);
});
}, 250);
});
/*
|--------------------------------------------------------------------------
| View description popup
|--------------------------------------------------------------------------
*/
$(document).on('click', '.btnViewDescription', function() {
const ppeName = $(this).data('ppe-name');
const ppeDescription = $(this).data('ppe-description');
Swal.fire({
title: htmlEscape(ppeName),
html: `<div style="text-align:left; white-space:pre-wrap; color:#334155;">${htmlEscape(ppeDescription)}</div>`,
confirmButtonText: 'Chiudi',
confirmButtonColor: '#2563eb',
width: '600px'
});
});
/*
|--------------------------------------------------------------------------
| Photo preview
@@ -20,6 +20,7 @@ try {
$notification_days = isset($_POST['notification_days']) && is_numeric($_POST['notification_days']) ? (int)$_POST['notification_days'] : 7;
$storage_location = trim($_POST['storage_location'] ?? '') ?: null;
$notes = trim($_POST['notes'] ?? '') ?: null;
$variazioni = trim($_POST['variazioni'] ?? '') ?: null;
$employee_ids = $_POST['employee_ids'] ?? [];
$department_names = $_POST['department_names'] ?? [];
@@ -56,7 +57,7 @@ try {
UPDATE scad_deadlines SET
subject_id = ?, function_id = ?, notify_function = ?, topic = ?, law_regulation = ?, recurrence_type = ?,
due_date = ?, check_date = ?, document_date = ?, notification_days = ?,
storage_location = ?, notes = ?, departments = ?
storage_location = ?, notes = ?, variazioni = ?, departments = ?
WHERE id = ?
");
$stmt->execute([
@@ -72,6 +73,7 @@ try {
$notification_days,
$storage_location,
$notes,
$variazioni,
$departmentsStr,
$id
]);
@@ -89,8 +91,8 @@ try {
$stmt = $pdo->prepare("
INSERT INTO scad_deadlines
(subject_id, function_id, notify_function, topic, law_regulation, recurrence_type, due_date, check_date,
document_date, notification_days, storage_location, notes, created_by, departments)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
document_date, notification_days, storage_location, notes, variazioni, created_by, departments)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
");
$stmt->execute([
$subject_id,
@@ -105,6 +107,7 @@ try {
$notification_days,
$storage_location,
$notes,
$variazioni,
$currentUserId,
$departmentsStr
]);
@@ -146,6 +146,10 @@
<label for="dlNotes" class="form-label fw-semibold">Note</label>
<textarea class="form-control" id="dlNotes" name="notes" rows="3" placeholder="es. Scadenza 09/06/2026, Attività in appalto a Ditta specializzata..."></textarea>
</div>
<div class="col-12">
<label for="dlVariazioni" class="form-label fw-semibold">In caso di variazioni</label>
<textarea class="form-control" id="dlVariazioni" name="variazioni" rows="3" placeholder="es. In caso di variazioni normative, aggiornare la procedura..."></textarea>
</div>
</div>
<!-- Group 5: Allegati -->
@@ -155,7 +155,7 @@
$('#dlSubject').val(d.subject_id || '').trigger('change');
document.getElementById('dlTopic').value = d.topic || '';
$('#dlFunction').val(d.function_id || '').trigger('change');
$('#notify_function').prop('checked', Number(d.notify_function) === 1);
$('#notify_function').prop('checked', Number(d.notify_function) === 1);
document.getElementById('dlLaw').value = d.law_regulation || '';
document.getElementById('dlRecurrence').value = d.recurrence_type || 'once';
fpDocDate.setDate(d.document_date || null, false, 'Y-m-d');
@@ -164,6 +164,7 @@
document.getElementById('dlNotifDays').value = d.notification_days || 7;
document.getElementById('dlStorage').value = d.storage_location || '';
document.getElementById('dlNotes').value = d.notes || '';
document.getElementById('dlVariazioni').value = d.variazioni || '';
document.getElementById('dlFiles').value = '';
document.getElementById('modalTitle').textContent = 'Modifica Scadenza';
$('#dlDepartments').val(d.department_names || []).trigger('change');
+1
View File
@@ -941,6 +941,7 @@ function getContrastTextColor($hexColor)
<?php if ((int)$row['attachment_count'] > 0): ?>
<span><i class="fa-solid fa-paperclip"></i> <?= (int)$row['attachment_count'] ?></span>
<?php endif; ?>
</div>
<?php if (!$row['_isCompleted']): ?>
<div class="card-actions">