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({