prepare("SELECT id FROM employees WHERE auth_user_id = ? LIMIT 1"); $stmt->execute([(int)$iduserlogin]); $myEmployeeId = (int)$stmt->fetchColumn(); if ($myEmployeeId) { $where[] = "(m.assignee_employee_id = ? OR m.supervisor_employee_id = ?)"; $params[] = $myEmployeeId; $params[] = $myEmployeeId; } else { $filterMine = false; } } $stmt = $pdo->prepare(" SELECT m.*, e.id AS equipment_id, e.name AS equipment_name, c.name AS category_name, c.color AS category_color, CONCAT(a.first_name, ' ', a.last_name) AS assignee_name, CONCAT(s.first_name, ' ', s.last_name) AS supervisor_name, sup.supplier_name FROM maint_maintenances m INNER JOIN inv_equipment e ON e.id = m.equipment_id LEFT JOIN inv_categories c ON c.id = e.category_id LEFT JOIN employees a ON a.id = m.assignee_employee_id LEFT JOIN employees s ON s.id = m.supervisor_employee_id LEFT JOIN suppliers sup ON sup.idsupplier = m.supplier_id WHERE " . implode(' AND ', $where) . " ORDER BY (m.next_due_date IS NULL) ASC, m.next_due_date ASC, e.name ASC "); $stmt->execute($params); $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); // The schedule state depends on each maintenance's own lead time, so it is // computed in PHP rather than in SQL. $maintenances = []; $counters = ['overdue' => 0, 'due_soon' => 0, 'ok' => 0, 'none' => 0]; foreach ($rows as $row) { $state = mnt_due_state($row['next_due_date'], (int)$row['alert_days']); $counters[$state]++; if ($filterState !== '' && $filterState !== $state) { continue; } $row['state'] = $state; $maintenances[] = $row; } // Paging happens here and not in SQL: the state of each task and the four // counter tiles are computed in PHP over the whole result set, so a LIMIT in // the query would leave the tiles counting one page instead of everything. [$page, $perPage] = mnt_page_params(); $totalMaintenances = count($maintenances); $totalPages = max(1, (int)ceil($totalMaintenances / $perPage)); $page = min($page, $totalPages); $maintenances = array_slice($maintenances, ($page - 1) * $perPage, $perPage); $formData = mnt_form_data($pdo); $typeLabels = mnt_intervention_types(); $executionLabels = mnt_execution_types(); $MNT_TITLE = 'Manutenzioni'; ?>
'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'], ]; ?>
// 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']]) ); ?>
>
>
Azzera filtri

Nessuna manutenzione con questi filtri.

·
Prossimo:
Attrezzatura Manutenzione Frequenza Incaricato Prossima Azioni
Critica
·