feat: always show checklists in overview and add quarterly/halfyearly intervals

This commit is contained in:
Matthias Hochmeister
2026-03-28 17:46:31 +01:00
parent a52bb2a57c
commit 6091d6c4dd
3 changed files with 69 additions and 44 deletions

View File

@@ -18,6 +18,12 @@ function calculateNextDueDate(intervall: string | null, intervall_tage: number |
case 'monthly':
now.setMonth(now.getMonth() + 1);
return now;
case 'quarterly':
now.setMonth(now.getMonth() + 3);
return now;
case 'halfyearly':
now.setMonth(now.getMonth() + 6);
return now;
case 'yearly':
now.setFullYear(now.getFullYear() + 1);
return now;
@@ -522,38 +528,57 @@ async function getTemplatesForEquipment(ausruestungId: string) {
async function getOverviewItems() {
try {
// Vehicles with overdue or upcoming checklists (within 7 days)
// All vehicles with their assigned templates (direct, by type, or global)
// LEFT JOIN faelligkeit so unexecuted templates still appear
const vehiclesResult = await pool.query(`
SELECT f.id, f.bezeichnung AS name, f.kurzname,
json_agg(json_build_object(
'vorlage_id', cf.vorlage_id,
'vorlage_name', v.name,
SELECT f.id, COALESCE(f.bezeichnung, f.kurzname) AS name,
json_agg(DISTINCT jsonb_build_object(
'vorlage_id', cv.id,
'vorlage_name', cv.name,
'intervall', cv.intervall,
'next_due', cf.naechste_faellig_am
) ORDER BY cf.naechste_faellig_am ASC) AS checklists
FROM checklist_faelligkeit cf
JOIN fahrzeuge f ON f.id = cf.fahrzeug_id AND f.deleted_at IS NULL
JOIN checklist_vorlagen v ON v.id = cf.vorlage_id AND v.aktiv = true
WHERE cf.fahrzeug_id IS NOT NULL
AND cf.naechste_faellig_am <= CURRENT_DATE + INTERVAL '7 days'
)) AS checklists
FROM fahrzeuge f
JOIN checklist_vorlagen cv ON cv.aktiv = true
AND cv.ausruestung_id IS NULL
AND cv.ausruestung_typ_id IS NULL
AND (
cv.fahrzeug_id = f.id
OR cv.fahrzeug_typ_id IN (
SELECT fahrzeug_typ_id FROM fahrzeug_fahrzeug_typen WHERE fahrzeug_id = f.id
)
OR (cv.fahrzeug_id IS NULL AND cv.fahrzeug_typ_id IS NULL)
)
LEFT JOIN checklist_faelligkeit cf ON cf.vorlage_id = cv.id AND cf.fahrzeug_id = f.id
WHERE f.deleted_at IS NULL
GROUP BY f.id, f.bezeichnung, f.kurzname
ORDER BY MIN(cf.naechste_faellig_am) ASC
ORDER BY f.bezeichnung ASC, f.kurzname ASC
`);
// Equipment with overdue or upcoming checklists (within 7 days)
// All equipment with their assigned templates
const equipmentResult = await pool.query(`
SELECT a.id, a.name,
json_agg(json_build_object(
'vorlage_id', cf.vorlage_id,
'vorlage_name', v.name,
SELECT a.id, a.bezeichnung AS name,
json_agg(DISTINCT jsonb_build_object(
'vorlage_id', cv.id,
'vorlage_name', cv.name,
'intervall', cv.intervall,
'next_due', cf.naechste_faellig_am
) ORDER BY cf.naechste_faellig_am ASC) AS checklists
FROM checklist_faelligkeit cf
JOIN ausruestung a ON a.id = cf.ausruestung_id
JOIN checklist_vorlagen v ON v.id = cf.vorlage_id AND v.aktiv = true
WHERE cf.ausruestung_id IS NOT NULL
AND cf.naechste_faellig_am <= CURRENT_DATE + INTERVAL '7 days'
GROUP BY a.id, a.name
ORDER BY MIN(cf.naechste_faellig_am) ASC
)) AS checklists
FROM ausruestung a
JOIN checklist_vorlagen cv ON cv.aktiv = true
AND cv.fahrzeug_id IS NULL
AND cv.fahrzeug_typ_id IS NULL
AND (
cv.ausruestung_id = a.id
OR cv.ausruestung_typ_id IN (
SELECT ausruestung_typ_id FROM ausruestung_ausruestung_typen WHERE ausruestung_id = a.id
)
OR (cv.ausruestung_id IS NULL AND cv.ausruestung_typ_id IS NULL)
)
LEFT JOIN checklist_faelligkeit cf ON cf.vorlage_id = cv.id AND cf.ausruestung_id = a.id
WHERE a.deleted_at IS NULL
GROUP BY a.id, a.bezeichnung
ORDER BY a.bezeichnung ASC
`);
return {