From 4d6fb9dff8cb19405144609ffc5a864741b4bd57 Mon Sep 17 00:00:00 2001 From: marco370 <48531002-marco370@users.noreply.replit.com> Date: Sat, 18 Oct 2025 07:40:54 +0000 Subject: [PATCH] Improve planning overview to show sites with active contracts Update the general planning overview to filter sites by active contract dates and display a weekly summary of total guards needed, assigned, and missing. Replit-Commit-Author: Agent Replit-Commit-Session-Id: e5565357-90e1-419f-b9a8-6ee8394636df Replit-Commit-Checkpoint-Type: intermediate_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/6d543d2c-20b9-4ea6-93fe-70fe9b1d9f80/e5565357-90e1-419f-b9a8-6ee8394636df/uZXH8P1 --- replit.md | 2 ++ server/routes.ts | 12 ++++-------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/replit.md b/replit.md index c0c0e24..4060acd 100644 --- a/replit.md +++ b/replit.md @@ -47,8 +47,10 @@ The database includes core tables for `users`, `guards`, `certifications`, `site - **Location-Based Filtering**: Backend endpoints use INNER JOIN with sites table to ensure complete resource isolation between locations - guards/vehicles in one sede remain available even when assigned to shifts in other sedi - **Site Management**: Added sede selection in site creation/editing forms with visual badges showing location in site listings - **Planning Generale (October 18, 2025)**: New weekly planning overview feature showing all sites × 7 days in table format: + - **Contract filtering**: Shows only sites with active contracts in the week dates (`contractStartDate <= weekEnd AND contractEndDate >= weekStart`) - Backend endpoint `/api/general-planning?weekStart=YYYY-MM-DD&location=sede` with complex joins and location filtering - Automatic missing guards calculation: `ceil(totalShiftHours / maxHoursPerGuard) × minGuards - assignedGuards` (e.g., 24h shift, 2 guards min, 9h max = 6 total needed) + - **Weekly summary**: Shows total guards needed, guards assigned (counting slots, not unique people), and guards missing for the entire week - Table cells display: assigned guards with hours, vehicles, missing guards badge (if any), shift count, total hours - Interactive cells with click handler opening detail dialog - Dialog shows: shift count, total hours, guard list with hours and badge numbers, vehicle list, missing guards warning with explanation diff --git a/server/routes.ts b/server/routes.ts index 31793dc..8ba8d95 100644 --- a/server/routes.ts +++ b/server/routes.ts @@ -1004,22 +1004,18 @@ export async function registerRoutes(app: Express): Promise { let totalGuardsNeededForWeek = 0; let totalGuardsAssignedForWeek = 0; - // Set per tracciare guardie uniche assegnate nella settimana - const uniqueGuardsInWeek = new Set(); - for (const day of weekData) { for (const siteData of day.sites) { // Somma guardie necessarie (già calcolate per sito/giorno) + // totalGuardsNeeded per sito = guardsAssigned + missingGuards totalGuardsNeededForWeek += (siteData.guardsAssigned + siteData.missingGuards); - // Traccia guardie uniche - for (const guard of siteData.guards) { - uniqueGuardsInWeek.add(guard.guardId); - } + // Somma slot guardia assegnati (non guardie uniche) + // Questo conta ogni assegnazione, anche se la stessa guardia lavora più turni + totalGuardsAssignedForWeek += siteData.guardsAssigned; } } - totalGuardsAssignedForWeek = uniqueGuardsInWeek.size; const totalGuardsMissingForWeek = Math.max(0, totalGuardsNeededForWeek - totalGuardsAssignedForWeek); res.json({