manteinance color

This commit is contained in:
2026-08-25 09:04:07 +02:00
parent fc34f837d4
commit 8425a7d90c
2 changed files with 855 additions and 332 deletions
+249 -237
View File
@@ -108,235 +108,236 @@ $MNT_TITLE = 'Manutenzioni';
<body>
<?php include __DIR__ . '/include/wrapper_open.php'; ?>
<?php include(__DIR__ . '/../include/navbar.php'); ?>
<?php include(__DIR__ . '/../include/topbar.php'); ?>
<?php include(__DIR__ . '/../include/navbar.php'); ?>
<?php include(__DIR__ . '/../include/topbar.php'); ?>
<div class="page-wrapper">
<div class="page-content">
<div class="page-wrapper">
<div class="page-content">
<div class="card mnt-card">
<div class="card-header d-flex align-items-center justify-content-between flex-wrap gap-2">
<h5><i class="fa-solid fa-screwdriver-wrench me-2"></i>Manutenzioni</h5>
<div class="header-actions d-flex gap-2 flex-wrap">
<a href="manutenzioni/calendar.php" class="btn btn-mnt-outline d-inline-flex align-items-center gap-2">
<i class="fa-solid fa-calendar-days"></i><span>Calendario</span>
</a>
<a href="manutenzioni/index.php" class="btn btn-mnt-outline d-inline-flex align-items-center gap-2">
<i class="fa-solid fa-boxes-stacked"></i><span>Registro</span>
</a>
</div>
</div>
<div class="card-body">
<div class="row g-2 mb-3">
<?php
$tiles = [
['key' => 'overdue', 'label' => 'Scadute', 'class' => 'mnt-badge-overdue'],
['key' => 'due_soon', 'label' => 'In scadenza', 'class' => 'mnt-badge-soon'],
['key' => 'ok', 'label' => 'In regola', 'class' => 'mnt-badge-ok'],
['key' => 'none', 'label' => 'Senza scadenza', 'class' => 'mnt-badge-none'],
];
?>
<?php foreach ($tiles as $tile): ?>
<div class="col-6 col-md-3">
<?php
// Percorso completo, non "?...": con <base href="/userarea/">
// un href di sola query porterebbe alla dashboard del template.
// page is dropped: changing the filter changes the result
// set, and staying on page 3 of the previous one is nonsense.
$tileQuery = $_GET;
unset($tileQuery['page']);
$tileUrl = 'manutenzioni/maintenances.php?' . http_build_query(
array_merge($tileQuery, ['state' => $filterState === $tile['key'] ? '' : $tile['key']])
);
?>
<a class="d-block text-decoration-none" href="<?= mnt_h($tileUrl) ?>">
<div class="mnt-item-card mb-0 <?= $filterState === $tile['key'] ? 'border-2' : '' ?>"
style="--row-color: <?= $tile['key'] === 'overdue' ? '#dc3545' : ($tile['key'] === 'due_soon' ? '#f0a202' : ($tile['key'] === 'ok' ? '#198754' : '#adb5bd')) ?>">
<div class="ic-title" style="font-size:1.4rem"><?= (int)$counters[$tile['key']] ?></div>
<div class="ic-meta"><?= $tile['label'] ?></div>
</div>
</a>
</div>
<?php endforeach; ?>
</div>
<form class="mnt-filter-bar" method="get" id="filterForm">
<input type="hidden" name="state" value="<?= mnt_h($filterState) ?>">
<select class="form-select" name="type">
<option value="">Programmate e straordinarie</option>
<?php foreach ($typeLabels as $value => $label): ?>
<option value="<?= mnt_h($value) ?>" <?= $filterType === $value ? 'selected' : '' ?>>
Solo <?= mnt_h(mb_strtolower($label)) ?>
</option>
<?php endforeach; ?>
</select>
<select class="form-select" name="category">
<option value="">Tutte le categorie</option>
<?php foreach ($formData['categories'] as $category): ?>
<option value="<?= (int)$category['id'] ?>" <?= $filterCategory === (int)$category['id'] ? 'selected' : '' ?>>
<?= mnt_h($category['name']) ?>
</option>
<?php endforeach; ?>
</select>
<div class="form-check d-flex align-items-center gap-2 ms-1">
<input class="form-check-input mt-0" type="checkbox" name="critical" value="1" id="fCritical" <?= $filterCritical ? 'checked' : '' ?>>
<label class="form-check-label" for="fCritical">Solo critiche</label>
</div>
<div class="form-check d-flex align-items-center gap-2 ms-1">
<input class="form-check-input mt-0" type="checkbox" name="mine" value="1" id="fMine" <?= $filterMine ? 'checked' : '' ?>>
<label class="form-check-label" for="fMine">Assegnate a me</label>
</div>
<?php if ($perPage !== 25): ?>
<input type="hidden" name="per_page" value="<?= (int)$perPage ?>">
<?php endif; ?>
<!-- No «Filtra» button: selects and checkboxes all submit on change,
so it never had anything left to do. Kept hidden only as the
no-JavaScript fallback. -->
<button type="submit" class="visually-hidden">Filtra</button>
<a href="manutenzioni/maintenances.php" class="btn btn-mnt-outline btn-reset-filters d-inline-flex align-items-center gap-2">
<i class="fa-solid fa-xmark"></i><span>Azzera filtri</span>
</a>
</form>
<?php if (!$maintenances): ?>
<div class="empty-state">
<i class="fa-solid fa-screwdriver-wrench"></i>
<p>Nessuna manutenzione con questi filtri.</p>
</div>
<?php else: ?>
<div id="maintenanceList">
<!-- CARD -->
<div class="d-xl-none">
<?php foreach ($maintenances as $maintenance): ?>
<?php $badge = mnt_due_badge($maintenance['state'], $maintenance['frequency_unit']); ?>
<div class="mnt-item-card" data-id="<?= (int)$maintenance['id'] ?>"
style="--row-color: <?= $maintenance['is_critical'] ? '#dc3545' : mnt_h($maintenance['category_color'] ?? '#e9ecef') ?>">
<div class="ic-title"><?= mnt_h($maintenance['equipment_name']) ?></div>
<div class="ic-meta">
<?php if ($maintenance['code']): ?><strong><?= mnt_h($maintenance['code']) ?></strong> · <?php endif; ?>
<?= mnt_h($maintenance['title']) ?>
</div>
<div class="ic-meta">
Prossimo: <strong><?= mnt_format_date($maintenance['next_due_date']) ?></strong>
<span class="mnt-badge <?= $badge['class'] ?> ms-1"><?= $badge['label'] ?></span>
</div>
<div class="ic-actions">
<a class="btn-action btn-action-view" href="manutenzioni/equipment.php?id=<?= (int)$maintenance['equipment_id'] ?>">
<i class="fa-solid fa-eye"></i>
</a>
<?php if ($canManage): ?>
<button class="btn-action btn-action-done btn-register" title="Registra intervento">
<i class="fa-solid fa-check"></i>
</button>
<?php endif; ?>
</div>
</div>
<?php endforeach; ?>
</div>
<!-- DESKTOP -->
<!-- Table only from 1200px up: measured, the 6 columns need
~1280px to fit, so on a tablet it only scrolls sideways. -->
<div class="d-none d-xl-block table-responsive">
<table class="table table-hover align-middle mb-0">
<thead>
<tr>
<th class="mnt-equipment-cell">Attrezzatura</th>
<th>Manutenzione</th>
<th class="mnt-freq-cell">Frequenza</th>
<th class="mnt-person-cell">Incaricato</th>
<th class="text-center">Prossima</th>
<th class="text-center" style="width:130px">Azioni</th>
</tr>
</thead>
<tbody>
<?php foreach ($maintenances as $maintenance): ?>
<?php $badge = mnt_due_badge($maintenance['state'], $maintenance['frequency_unit']); ?>
<tr data-id="<?= (int)$maintenance['id'] ?>">
<td class="mnt-equipment-cell">
<span class="d-flex align-items-start gap-2">
<span class="mnt-cat-dot mt-1" style="background: <?= mnt_h($maintenance['category_color'] ?? '#adb5bd') ?>"></span>
<span class="fw-semibold mnt-title-clamp" style="color:var(--mnt-heading)"
title="<?= mnt_h($maintenance['equipment_name']) ?>"><?= mnt_h($maintenance['equipment_name']) ?></span>
</span>
<div class="small text-muted"><?= mnt_h($maintenance['category_name'] ?? '') ?></div>
</td>
<td class="mnt-title-cell">
<?php if ($maintenance['code']): ?>
<span class="mnt-badge mnt-badge-soft me-1"><?= mnt_h($maintenance['code']) ?></span>
<?php endif; ?>
<?php if ($maintenance['is_critical']): ?>
<span class="mnt-badge mnt-badge-critical ms-1">Critica</span>
<?php endif; ?>
<div class="mnt-title-clamp" title="<?= mnt_h($maintenance['title']) ?>">
<?= mnt_h($maintenance['title']) ?>
</div>
<div class="small text-muted">
<?= mnt_h($typeLabels[$maintenance['intervention_type']] ?? '') ?>
· <?= mnt_h($executionLabels[$maintenance['execution_type']] ?? '') ?>
<?php if ($maintenance['supplier_name']): ?>
<?= mnt_h($maintenance['supplier_name']) ?>
<?php endif; ?>
</div>
</td>
<td class="small mnt-freq-cell"><div class="mnt-title-clamp"><?= mnt_h(mnt_format_frequency(
$maintenance['frequency_value'] !== null ? (int)$maintenance['frequency_value'] : null,
$maintenance['frequency_unit'],
$maintenance['frequency_note']
)) ?></div></td>
<td class="small mnt-person-cell">
<?= mnt_h($maintenance['assignee_name'] ?: '—') ?>
<?php if ($maintenance['supervisor_name']): ?>
<div class="text-muted"><?= mnt_h($maintenance['supervisor_name']) ?></div>
<?php endif; ?>
</td>
<td class="text-center">
<div><?= mnt_format_date($maintenance['next_due_date']) ?></div>
<span class="mnt-badge <?= $badge['class'] ?>"><?= $badge['label'] ?></span>
</td>
<td class="text-center">
<div class="d-inline-flex gap-1">
<a class="btn-action btn-action-view" title="Apri scheda"
href="manutenzioni/equipment.php?id=<?= (int)$maintenance['equipment_id'] ?>">
<i class="fa-solid fa-eye"></i>
</a>
<?php if ($canManage): ?>
<button class="btn-action btn-action-done btn-register" title="Registra intervento">
<i class="fa-solid fa-check"></i>
</button>
<?php endif; ?>
</div>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
<?php
$mntPagerUrl = 'manutenzioni/maintenances.php';
$mntPagerPage = $page;
$mntPagerPages = $totalPages;
$mntPagerTotal = $totalMaintenances;
$mntPagerPer = $perPage;
include __DIR__ . '/include/pagination.php';
?>
<?php endif; ?>
<div class="card mnt-card">
<div class="card-header d-flex align-items-center justify-content-between flex-wrap gap-2">
<h5><i class="fa-solid fa-screwdriver-wrench me-2"></i>Manutenzioni</h5>
<div class="header-actions d-flex gap-2 flex-wrap">
<a href="manutenzioni/calendar.php" class="btn btn-mnt-outline d-inline-flex align-items-center gap-2">
<i class="fa-solid fa-calendar-days"></i><span>Calendario</span>
</a>
<a href="manutenzioni/index.php" class="btn btn-mnt-outline d-inline-flex align-items-center gap-2">
<i class="fa-solid fa-boxes-stacked"></i><span>Registro</span>
</a>
</div>
</div>
<div class="card-body">
<div class="row g-2 mb-3">
<?php
$tiles = [
['key' => 'overdue', 'label' => 'Scadute', 'class' => 'mnt-badge-overdue'],
['key' => 'due_soon', 'label' => 'In scadenza', 'class' => 'mnt-badge-soon'],
['key' => 'ok', 'label' => 'In regola', 'class' => 'mnt-badge-ok'],
['key' => 'none', 'label' => 'Senza scadenza', 'class' => 'mnt-badge-none'],
];
?>
<?php foreach ($tiles as $tile): ?>
<div class="col-6 col-md-3">
<?php
// Percorso completo, non "?...": con <base href="/userarea/">
// un href di sola query porterebbe alla dashboard del template.
// page is dropped: changing the filter changes the result
// set, and staying on page 3 of the previous one is nonsense.
$tileQuery = $_GET;
unset($tileQuery['page']);
$tileUrl = 'manutenzioni/maintenances.php?' . http_build_query(
array_merge($tileQuery, ['state' => $filterState === $tile['key'] ? '' : $tile['key']])
);
?>
<a class="d-block text-decoration-none" href="<?= mnt_h($tileUrl) ?>">
<div class="mnt-item-card mnt-tile mnt-tile-<?= $tile['key'] ?> mb-0 <?= $filterState === $tile['key'] ? 'mnt-tile-active' : '' ?>">
<div class="ic-title" style="font-size:1.4rem"><?= (int)$counters[$tile['key']] ?></div>
<div class="ic-meta"><?= $tile['label'] ?></div>
</div>
</a>
</div>
<?php endforeach; ?>
</div>
<form class="mnt-filter-bar" method="get" id="filterForm">
<input type="hidden" name="state" value="<?= mnt_h($filterState) ?>">
<select class="form-select" name="type">
<option value="">Programmate e straordinarie</option>
<?php foreach ($typeLabels as $value => $label): ?>
<option value="<?= mnt_h($value) ?>" <?= $filterType === $value ? 'selected' : '' ?>>
Solo <?= mnt_h(mb_strtolower($label)) ?>
</option>
<?php endforeach; ?>
</select>
<select class="form-select" name="category">
<option value="">Tutte le categorie</option>
<?php foreach ($formData['categories'] as $category): ?>
<option value="<?= (int)$category['id'] ?>" <?= $filterCategory === (int)$category['id'] ? 'selected' : '' ?>>
<?= mnt_h($category['name']) ?>
</option>
<?php endforeach; ?>
</select>
<div class="form-check d-flex align-items-center gap-2 ms-1">
<input class="form-check-input mt-0" type="checkbox" name="critical" value="1" id="fCritical" <?= $filterCritical ? 'checked' : '' ?>>
<label class="form-check-label" for="fCritical">Solo critiche</label>
</div>
<div class="form-check d-flex align-items-center gap-2 ms-1">
<input class="form-check-input mt-0" type="checkbox" name="mine" value="1" id="fMine" <?= $filterMine ? 'checked' : '' ?>>
<label class="form-check-label" for="fMine">Assegnate a me</label>
</div>
<?php if ($perPage !== 25): ?>
<input type="hidden" name="per_page" value="<?= (int)$perPage ?>">
<?php endif; ?>
<!-- No «Filtra» button: selects and checkboxes all submit on change,
so it never had anything left to do. Kept hidden only as the
no-JavaScript fallback. -->
<button type="submit" class="visually-hidden">Filtra</button>
<a href="manutenzioni/maintenances.php" class="btn btn-mnt-outline btn-reset-filters d-inline-flex align-items-center gap-2">
<i class="fa-solid fa-xmark"></i><span>Azzera filtri</span>
</a>
</form>
<?php if (!$maintenances): ?>
<div class="empty-state">
<i class="fa-solid fa-screwdriver-wrench"></i>
<p>Nessuna manutenzione con questi filtri.</p>
</div>
<?php else: ?>
<div id="maintenanceList">
<!-- CARD -->
<div class="d-xl-none">
<?php foreach ($maintenances as $maintenance): ?>
<?php $badge = mnt_due_badge($maintenance['state'], $maintenance['frequency_unit']); ?>
<div class="mnt-item-card" data-id="<?= (int)$maintenance['id'] ?>"
style="--row-color: <?= $maintenance['is_critical'] ? '#dc3545' : mnt_h($maintenance['category_color'] ?? '#e9ecef') ?>">
<div class="ic-title"><?= mnt_h($maintenance['equipment_name']) ?></div>
<div class="ic-meta">
<?php if ($maintenance['code']): ?><strong><?= mnt_h($maintenance['code']) ?></strong> · <?php endif; ?>
<?= mnt_h($maintenance['title']) ?>
</div>
<div class="ic-meta">
Prossimo: <strong><?= mnt_format_date($maintenance['next_due_date']) ?></strong>
<span class="mnt-badge <?= $badge['class'] ?> ms-1"><?= $badge['label'] ?></span>
</div>
<div class="ic-actions">
<a class="btn-action btn-action-view" href="manutenzioni/equipment.php?id=<?= (int)$maintenance['equipment_id'] ?>">
<i class="fa-solid fa-eye"></i>
</a>
<?php if ($canManage): ?>
<button class="btn-action btn-action-done btn-register" title="Registra intervento">
<i class="fa-solid fa-check"></i>
</button>
<?php endif; ?>
</div>
</div>
<?php endforeach; ?>
</div>
<!-- DESKTOP -->
<!-- Table only from 1200px up: measured, the 6 columns need
~1280px to fit, so on a tablet it only scrolls sideways. -->
<div class="d-none d-xl-block table-responsive">
<table class="table table-hover align-middle mb-0">
<thead>
<tr>
<th class="mnt-equipment-cell">Attrezzatura</th>
<th>Manutenzione</th>
<th class="mnt-freq-cell">Frequenza</th>
<th class="mnt-person-cell">Incaricato</th>
<th class="text-center">Prossima</th>
<th class="text-center" style="width:130px">Azioni</th>
</tr>
</thead>
<tbody>
<?php foreach ($maintenances as $maintenance): ?>
<?php $badge = mnt_due_badge($maintenance['state'], $maintenance['frequency_unit']); ?>
<tr data-id="<?= (int)$maintenance['id'] ?>">
<td class="mnt-equipment-cell">
<span class="d-flex align-items-start gap-2">
<span class="mnt-cat-dot mt-1" style="background: <?= mnt_h($maintenance['category_color'] ?? '#adb5bd') ?>"></span>
<span class="fw-semibold mnt-title-clamp" style="color:var(--mnt-heading)"
title="<?= mnt_h($maintenance['equipment_name']) ?>"><?= mnt_h($maintenance['equipment_name']) ?></span>
</span>
<div class="small text-muted"><?= mnt_h($maintenance['category_name'] ?? '') ?></div>
</td>
<td class="mnt-title-cell">
<?php if ($maintenance['code']): ?>
<span class="mnt-badge mnt-badge-soft me-1"><?= mnt_h($maintenance['code']) ?></span>
<?php endif; ?>
<?php if ($maintenance['is_critical']): ?>
<span class="mnt-badge mnt-badge-critical ms-1">Critica</span>
<?php endif; ?>
<div class="mnt-title-clamp" title="<?= mnt_h($maintenance['title']) ?>">
<?= mnt_h($maintenance['title']) ?>
</div>
<div class="small text-muted">
<?= mnt_h($typeLabels[$maintenance['intervention_type']] ?? '') ?>
· <?= mnt_h($executionLabels[$maintenance['execution_type']] ?? '') ?>
<?php if ($maintenance['supplier_name']): ?>
<?= mnt_h($maintenance['supplier_name']) ?>
<?php endif; ?>
</div>
</td>
<td class="small mnt-freq-cell">
<div class="mnt-title-clamp"><?= mnt_h(mnt_format_frequency(
$maintenance['frequency_value'] !== null ? (int)$maintenance['frequency_value'] : null,
$maintenance['frequency_unit'],
$maintenance['frequency_note']
)) ?></div>
</td>
<td class="small mnt-person-cell">
<?= mnt_h($maintenance['assignee_name'] ?: '—') ?>
<?php if ($maintenance['supervisor_name']): ?>
<div class="text-muted"><?= mnt_h($maintenance['supervisor_name']) ?></div>
<?php endif; ?>
</td>
<td class="text-center">
<div><?= mnt_format_date($maintenance['next_due_date']) ?></div>
<span class="mnt-badge <?= $badge['class'] ?>"><?= $badge['label'] ?></span>
</td>
<td class="text-center">
<div class="d-inline-flex gap-1">
<a class="btn-action btn-action-view" title="Apri scheda"
href="manutenzioni/equipment.php?id=<?= (int)$maintenance['equipment_id'] ?>">
<i class="fa-solid fa-eye"></i>
</a>
<?php if ($canManage): ?>
<button class="btn-action btn-action-done btn-register" title="Registra intervento">
<i class="fa-solid fa-check"></i>
</button>
<?php endif; ?>
</div>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
<?php
$mntPagerUrl = 'manutenzioni/maintenances.php';
$mntPagerPage = $page;
$mntPagerPages = $totalPages;
$mntPagerTotal = $totalMaintenances;
$mntPagerPer = $perPage;
include __DIR__ . '/include/pagination.php';
?>
<?php endif; ?>
</div>
</div>
</div>
<?php include(__DIR__ . '/../include/footer.php'); ?>
</div>
<?php include(__DIR__ . '/../include/footer.php'); ?>
</div>
<?php if ($canManage): ?>
@@ -345,26 +346,37 @@ $MNT_TITLE = 'Manutenzioni';
<?php include(__DIR__ . '/../jsinclude.php'); ?>
<script>
$(function () {
$('#filterForm select, #filterForm input[type=checkbox]').on('change', function () { $('#filterForm').submit(); });
$(function() {
$('#filterForm select, #filterForm input[type=checkbox]').on('change', function() {
$('#filterForm').submit();
});
<?php if ($canManage): ?>
$('#maintenanceList').on('click', '.btn-register', function () {
const id = $(this).closest('[data-id]').data('id');
$.getJSON('manutenzioni/ajax/get_maintenance.php', { id: id })
.done(res => {
if (!res.success) { Swal.fire({ icon: 'error', title: 'Errore', text: res.message }); return; }
mntOpenInterventionModal(null, {
id: res.maintenance.id,
title: res.maintenance.title,
equipment_name: res.maintenance.equipment_name,
supplier_id: res.maintenance.supplier_id
$('#maintenanceList').on('click', '.btn-register', function() {
const id = $(this).closest('[data-id]').data('id');
$.getJSON('manutenzioni/ajax/get_maintenance.php', {
id: id
})
.done(res => {
if (!res.success) {
Swal.fire({
icon: 'error',
title: 'Errore',
text: res.message
});
return;
}
mntOpenInterventionModal(null, {
id: res.maintenance.id,
title: res.maintenance.title,
equipment_name: res.maintenance.equipment_name,
supplier_id: res.maintenance.supplier_id
});
});
});
});
});
<?php endif; ?>
});
</script>
</body>
</html>
</html>