added alert flag and variation flag

This commit is contained in:
2026-07-19 15:06:18 +02:00
parent 4e61426be7
commit 58af735082
10 changed files with 180 additions and 27 deletions
@@ -0,0 +1,21 @@
<?php
declare(strict_types=1);
use Phinx\Migration\AbstractMigration;
final class ChangeVariazioniToFlag extends AbstractMigration
{
public function up(): void
{
$this->execute("ALTER TABLE `scad_deadlines`
CHANGE `variazioni` `variazioni` TINYINT(1) NOT NULL DEFAULT 0
COMMENT 'Flag: in caso di variazioni'");
}
public function down(): void
{
$this->execute("ALTER TABLE `scad_deadlines`
CHANGE `variazioni` `variazioni` TEXT NULL DEFAULT NULL");
}
}
@@ -0,0 +1,31 @@
<?php
declare(strict_types=1);
use Phinx\Migration\AbstractMigration;
final class SetAttivaAlertDefaultOn extends AbstractMigration
{
/**
* Change Method.
*
* Write your reversible migrations using this method.
*
* More information on writing migrations is available here:
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
*
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
public function up(): void
{
$this->execute("ALTER TABLE `scad_deadlines`
CHANGE `attiva_alert` `attiva_alert` TINYINT(1) NOT NULL DEFAULT 1");
}
public function down(): void
{
$this->execute("ALTER TABLE `scad_deadlines`
CHANGE `attiva_alert` `attiva_alert` TINYINT(1) NOT NULL DEFAULT 0");
}
}
@@ -0,0 +1,22 @@
<?php
declare(strict_types=1);
use Phinx\Migration\AbstractMigration;
final class EnableAttivaAlertOnExisting extends AbstractMigration
{
public function up(): void
{
$this->execute("UPDATE `scad_deadlines`
SET `attiva_alert` = 1
WHERE `status` = 'active'");
}
public function down(): void
{
$this->execute("UPDATE `scad_deadlines`
SET `attiva_alert` = 0
WHERE `status` = 'active'");
}
}
@@ -50,17 +50,38 @@ try {
$documentDate = $deadline['document_date'] ? new DateTime($deadline['document_date']) : null; $documentDate = $deadline['document_date'] ? new DateTime($deadline['document_date']) : null;
switch ($deadline['recurrence_type']) { switch ($deadline['recurrence_type']) {
case 'monthly': $interval = new DateInterval('P1M'); break; case 'monthly':
case 'quarterly': $interval = new DateInterval('P3M'); break; $interval = new DateInterval('P1M');
case 'semiannual': $interval = new DateInterval('P6M'); break; break;
case 'annual': $interval = new DateInterval('P1Y'); break; case 'quarterly':
case 'biennial': $interval = new DateInterval('P2Y'); break; $interval = new DateInterval('P3M');
case 'triennial': $interval = new DateInterval('P3Y'); break; break;
case 'quadriennial': $interval = new DateInterval('P4Y'); break; case 'semiannual':
case 'quinquennial': $interval = new DateInterval('P5Y'); break; $interval = new DateInterval('P6M');
case 'decennial': $interval = new DateInterval('P10Y'); break; break;
case 'quindecennial': $interval = new DateInterval('P15Y'); break; case 'annual':
default: $interval = null; $interval = new DateInterval('P1Y');
break;
case 'biennial':
$interval = new DateInterval('P2Y');
break;
case 'triennial':
$interval = new DateInterval('P3Y');
break;
case 'quadriennial':
$interval = new DateInterval('P4Y');
break;
case 'quinquennial':
$interval = new DateInterval('P5Y');
break;
case 'decennial':
$interval = new DateInterval('P10Y');
break;
case 'quindecennial':
$interval = new DateInterval('P15Y');
break;
default:
$interval = null;
} }
if ($interval) { if ($interval) {
@@ -70,17 +91,27 @@ try {
$ins = $pdo->prepare(" $ins = $pdo->prepare("
INSERT INTO scad_deadlines INSERT INTO scad_deadlines
(subject_id, function_id, topic, law_regulation, recurrence_type, due_date, check_date, (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) document_date, notification_days, storage_location, notes, variazioni, attiva_alert, created_by, departments)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
"); ");
$ins->execute([ $ins->execute([
$deadline['subject_id'], $deadline['function_id'], $deadline['topic'], $deadline['law_regulation'], $deadline['subject_id'],
$deadline['recurrence_type'], $dueDate->format('Y-m-d'), $deadline['function_id'],
$deadline['notify_function'],
$deadline['topic'],
$deadline['law_regulation'],
$deadline['recurrence_type'],
$dueDate->format('Y-m-d'),
$checkDate ? $checkDate->format('Y-m-d') : null, $checkDate ? $checkDate->format('Y-m-d') : null,
$documentDate ? $documentDate->format('Y-m-d') : null, $documentDate ? $documentDate->format('Y-m-d') : null,
$deadline['notification_days'], $deadline['storage_location'], $deadline['notification_days'],
$deadline['notes'], $deadline['created_by'], $deadline['departments'] $deadline['storage_location'],
$deadline['notes'],
$deadline['variazioni'],
$deadline['attiva_alert'],
$deadline['created_by'],
$deadline['departments']
]); ]);
$newId = $pdo->lastInsertId(); $newId = $pdo->lastInsertId();
@@ -137,7 +168,6 @@ try {
} }
echo json_encode(['success' => true, 'message' => $msg, 'new_id' => $newId]); echo json_encode(['success' => true, 'message' => $msg, 'new_id' => $newId]);
} catch (Exception $e) { } catch (Exception $e) {
if (isset($pdo) && $pdo->inTransaction()) { if (isset($pdo) && $pdo->inTransaction()) {
$pdo->rollBack(); $pdo->rollBack();
@@ -20,7 +20,8 @@ try {
$notification_days = isset($_POST['notification_days']) && is_numeric($_POST['notification_days']) ? (int)$_POST['notification_days'] : 7; $notification_days = isset($_POST['notification_days']) && is_numeric($_POST['notification_days']) ? (int)$_POST['notification_days'] : 7;
$storage_location = trim($_POST['storage_location'] ?? '') ?: null; $storage_location = trim($_POST['storage_location'] ?? '') ?: null;
$notes = trim($_POST['notes'] ?? '') ?: null; $notes = trim($_POST['notes'] ?? '') ?: null;
$variazioni = trim($_POST['variazioni'] ?? '') ?: null; $variazioni = !empty($_POST['variazioni']) ? 1 : 0;
$attiva_alert = !empty($_POST['attiva_alert']) ? 1 : 0;
$employee_ids = $_POST['employee_ids'] ?? []; $employee_ids = $_POST['employee_ids'] ?? [];
$department_names = $_POST['department_names'] ?? []; $department_names = $_POST['department_names'] ?? [];
@@ -57,7 +58,7 @@ try {
UPDATE scad_deadlines SET UPDATE scad_deadlines SET
subject_id = ?, function_id = ?, notify_function = ?, topic = ?, law_regulation = ?, recurrence_type = ?, subject_id = ?, function_id = ?, notify_function = ?, topic = ?, law_regulation = ?, recurrence_type = ?,
due_date = ?, check_date = ?, document_date = ?, notification_days = ?, due_date = ?, check_date = ?, document_date = ?, notification_days = ?,
storage_location = ?, notes = ?, variazioni = ?, departments = ? storage_location = ?, notes = ?, variazioni = ?, attiva_alert = ?, departments = ?
WHERE id = ? WHERE id = ?
"); ");
$stmt->execute([ $stmt->execute([
@@ -74,6 +75,7 @@ try {
$storage_location, $storage_location,
$notes, $notes,
$variazioni, $variazioni,
$attiva_alert,
$departmentsStr, $departmentsStr,
$id $id
]); ]);
@@ -91,8 +93,8 @@ try {
$stmt = $pdo->prepare(" $stmt = $pdo->prepare("
INSERT INTO scad_deadlines INSERT INTO scad_deadlines
(subject_id, function_id, notify_function, topic, law_regulation, recurrence_type, due_date, check_date, (subject_id, function_id, notify_function, topic, law_regulation, recurrence_type, due_date, check_date,
document_date, notification_days, storage_location, notes, variazioni, created_by, departments) document_date, notification_days, storage_location, notes, variazioni, attiva_alert, created_by, departments)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
"); ");
$stmt->execute([ $stmt->execute([
$subject_id, $subject_id,
@@ -108,6 +110,7 @@ try {
$storage_location, $storage_location,
$notes, $notes,
$variazioni, $variazioni,
$attiva_alert,
$currentUserId, $currentUserId,
$departmentsStr $departmentsStr
]); ]);
@@ -57,12 +57,13 @@ $stmt = $pdo->query("
LEFT JOIN scad_subjects s ON s.id = d.subject_id LEFT JOIN scad_subjects s ON s.id = d.subject_id
LEFT JOIN scad_functions f ON f.id = d.function_id LEFT JOIN scad_functions f ON f.id = d.function_id
WHERE d.status = 'active' WHERE d.status = 'active'
AND d.attiva_alert = 1
AND d.due_date <= DATE_ADD(CURDATE(), INTERVAL d.notification_days DAY) AND d.due_date <= DATE_ADD(CURDATE(), INTERVAL d.notification_days DAY)
"); ");
$deadlines = $stmt->fetchAll(PDO::FETCH_ASSOC); $deadlines = $stmt->fetchAll(PDO::FETCH_ASSOC);
if (empty($deadlines)) { if (empty($deadlines)) {
echo date('Y-m-d H:i:s') . " — Nessuna scadenza da notificare.\n"; echo date('Y-m-d H:i:s') . " — Nessuna scadenza da notificare (alert attivo).\n";
exit(0); exit(0);
} }
+18
View File
@@ -646,6 +646,24 @@ if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
<div class="detail-label">Note</div> <div class="detail-label">Note</div>
<div class="detail-value"><?= nl2br(htmlspecialchars($deadline['notes'], ENT_QUOTES, 'UTF-8')) ?></div> <div class="detail-value"><?= nl2br(htmlspecialchars($deadline['notes'], ENT_QUOTES, 'UTF-8')) ?></div>
<?php endif; ?> <?php endif; ?>
<div class="detail-label">Alert</div>
<div class="detail-value">
<?php if (!empty($deadline['attiva_alert'])): ?>
<i class="fa-solid fa-bell text-warning me-1"></i> Attivo
<?php else: ?>
<span class="text-muted">Non attivo</span>
<?php endif; ?>
</div>
<div class="detail-label">In caso di variazioni</div>
<div class="detail-value">
<?php if (!empty($deadline['variazioni'])): ?>
<i class="fa-solid fa-arrows-rotate text-info me-1"></i>
<?php else: ?>
<span class="text-muted">No</span>
<?php endif; ?>
</div>
</div> </div>
</div> </div>
@@ -147,8 +147,20 @@
<textarea class="form-control" id="dlNotes" name="notes" rows="3" placeholder="es. Scadenza 09/06/2026, Attività in appalto a Ditta specializzata..."></textarea> <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>
<div class="col-12"> <div class="col-12">
<label for="dlVariazioni" class="form-label fw-semibold">In caso di variazioni</label> <div class="form-check form-switch">
<textarea class="form-control" id="dlVariazioni" name="variazioni" rows="3" placeholder="es. In caso di variazioni normative, aggiornare la procedura..."></textarea> <input class="form-check-input" type="checkbox" role="switch" id="dlVariazioni" name="variazioni" value="1">
<label class="form-check-label fw-semibold" for="dlVariazioni">
In caso di variazioni
</label>
</div>
</div>
<div class="col-12">
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" role="switch" id="dlAttivaAlert" name="attiva_alert" value="1">
<label class="form-check-label fw-semibold" for="dlAttivaAlert">
<i class="fa-solid fa-bell me-1 text-warning"></i> Attiva alert
</label>
</div>
</div> </div>
</div> </div>
@@ -135,6 +135,8 @@
$('#dlEmployees').val(null).trigger('change'); $('#dlEmployees').val(null).trigger('change');
$('#dlFunction').val('').trigger('change'); $('#dlFunction').val('').trigger('change');
$('#notify_function').prop('checked', false); $('#notify_function').prop('checked', false);
$('#dlVariazioni').prop('checked', false);
$('#dlAttivaAlert').prop('checked', false);
renderAttachments([]); renderAttachments([]);
modal.show(); modal.show();
}; };
@@ -164,7 +166,8 @@
document.getElementById('dlNotifDays').value = d.notification_days || 7; document.getElementById('dlNotifDays').value = d.notification_days || 7;
document.getElementById('dlStorage').value = d.storage_location || ''; document.getElementById('dlStorage').value = d.storage_location || '';
document.getElementById('dlNotes').value = d.notes || ''; document.getElementById('dlNotes').value = d.notes || '';
document.getElementById('dlVariazioni').value = d.variazioni || ''; $('#dlVariazioni').prop('checked', Number(d.variazioni) === 1);
$('#dlAttivaAlert').prop('checked', Number(d.attiva_alert) === 1);
document.getElementById('dlFiles').value = ''; document.getElementById('dlFiles').value = '';
document.getElementById('modalTitle').textContent = 'Modifica Scadenza'; document.getElementById('modalTitle').textContent = 'Modifica Scadenza';
$('#dlDepartments').val(d.department_names || []).trigger('change'); $('#dlDepartments').val(d.department_names || []).trigger('change');
+12
View File
@@ -941,6 +941,12 @@ function getContrastTextColor($hexColor)
<?php if ((int)$row['attachment_count'] > 0): ?> <?php if ((int)$row['attachment_count'] > 0): ?>
<span><i class="fa-solid fa-paperclip"></i> <?= (int)$row['attachment_count'] ?></span> <span><i class="fa-solid fa-paperclip"></i> <?= (int)$row['attachment_count'] ?></span>
<?php endif; ?> <?php endif; ?>
<?php if (!empty($row['attiva_alert'])): ?>
<span><i class="fa-solid fa-bell text-warning"></i> Alert</span>
<?php endif; ?>
<?php if (!empty($row['variazioni'])): ?>
<span><i class="fa-solid fa-arrows-rotate text-info"></i> Variazioni</span>
<?php endif; ?>
</div> </div>
<?php if (!$row['_isCompleted']): ?> <?php if (!$row['_isCompleted']): ?>
@@ -1010,6 +1016,12 @@ function getContrastTextColor($hexColor)
<td> <td>
<a href="scadenzario/detail.php?id=<?= (int)$row['id'] ?>" class="fw-semibold text-decoration-none" style="color:var(--scad-heading)"><?= htmlspecialchars($row['topic'], ENT_QUOTES, 'UTF-8') ?></a> <a href="scadenzario/detail.php?id=<?= (int)$row['id'] ?>" class="fw-semibold text-decoration-none" style="color:var(--scad-heading)"><?= htmlspecialchars($row['topic'], ENT_QUOTES, 'UTF-8') ?></a>
<?php if (!empty($row['attiva_alert'])): ?>
<i class="fa-solid fa-bell text-warning ms-1" title="Alert attivo"></i>
<?php endif; ?>
<?php if (!empty($row['variazioni'])): ?>
<i class="fa-solid fa-arrows-rotate text-info ms-1" title="In caso di variazioni"></i>
<?php endif; ?>
<?php if ((int)$row['attachment_count'] > 0): ?> <?php if ((int)$row['attachment_count'] > 0): ?>
<span class="text-muted ms-1" title="<?= (int)$row['attachment_count'] ?> allegati"><i class="fa-solid fa-paperclip"></i> <?= (int)$row['attachment_count'] ?></span> <span class="text-muted ms-1" title="<?= (int)$row['attachment_count'] ?> allegati"><i class="fa-solid fa-paperclip"></i> <?= (int)$row['attachment_count'] ?></span>
<?php endif; ?> <?php endif; ?>