diff --git a/src/app/dashboard/plant/page.tsx b/src/app/dashboard/plant/page.tsx index 0a5b61d..3bbe919 100644 --- a/src/app/dashboard/plant/page.tsx +++ b/src/app/dashboard/plant/page.tsx @@ -1,18 +1,20 @@ import { pbAdmin } from "@/lib/pb"; -import { PlantView, type PlantRow } from "./plant-view"; +import { PlantView, type PlantRow, type PlantLogRow } from "./plant-view"; export const dynamic = "force-dynamic"; export default async function PlantPage() { const pb = await pbAdmin(); - // Plant now lives in the VEHICLES collection — we filter to rated items - // (cost_per_hour > 0) so the financial view shows the heavy machinery. - const all = await pb.collection("vehicles").getFullList({ - sort: "description", - }); + const [allVehicles, allLogs] = await Promise.all([ + pb.collection("vehicles").getFullList({ sort: "description", perPage: 5000 }), + pb + .collection("plant_hours_log") + .getFullList({ sort: "-start_date", perPage: 5000 }) + .catch(() => []), + ]); - const rows: PlantRow[] = all + const rows: PlantRow[] = allVehicles .filter((v) => (v.cost_per_hour ?? 0) > 0) .map((v) => ({ id: v.id, @@ -21,13 +23,35 @@ export default async function PlantPage() { projectCode: v.project_code, hourMeter: v.standard_work_hours, costPerHour: v.cost_per_hour, + unitType: v.unit_type ?? "fuel", })); + const logs: PlantLogRow[] = allLogs.map((l) => ({ + id: l.id, + vehicleId: l.vehicle, + vehicleQr: l.vehicle_qr, + vehicleDescription: + allVehicles.find((v) => v.id === l.vehicle)?.description ?? "", + vehicleUnitType: (allVehicles.find((v) => v.id === l.vehicle)?.unit_type ?? "fuel") as "fuel" | "plant", + projectCode: l.project_code, + startDate: l.start_date, + endDate: l.end_date, + startTime: l.start_time ?? "", + endTime: l.end_time ?? "", + hours: l.hours, + hourMeterBudget: l.hour_meter_budget, + costPerHour: l.cost_per_hour, + value: l.value, + overBudget: l.over_budget, + notes: l.notes ?? "", + })); + const projectCodes = Array.from(new Set(rows.map((r) => r.projectCode))).sort(); return ( +
+ + Download template + + + +
} /> @@ -367,6 +399,138 @@ export function PlantView({ )} + + {/* Attention Required: type-mismatched rows */} + {(() => { + const mismatches = logs.filter((l) => l.vehicleUnitType !== "plant"); + if (mismatches.length === 0) return null; + return ( + + + + + Attention required + + {mismatches.length} row(s) + + + + + + Vehicle QR + Description + Logged as + Vehicle typed as + Actions + + + + {mismatches.map((m) => ( + + {m.vehicleQr} + {m.vehicleDescription} + + plant + + + {m.vehicleUnitType} + + + + + + ))} + +
+
+
+ ); + })()} + + {/* Weekly plant hours log */} + + + Weekly plant hours log + {logs.length} entries + + + {logs.length === 0 ? ( +
+ No plant hours logged yet. Download the template, fill in your + weekly hours, and import. +
+ ) : ( + + + + Week + Vehicle + Hours + Budget + Cost/hr + Value + Status + Notes + + + + {logs.map((l) => ( + + +
+ {l.startDate} → {l.endDate} +
+ {(l.startTime || l.endTime) && ( +
+ {l.startTime} → {l.endTime} +
+ )} +
+ +
{l.vehicleDescription}
+
+ {l.vehicleQr} +
+
+ + {l.hours.toFixed(1)} + + + {l.hourMeterBudget} + + + {formatCurrency(l.costPerHour)} + + + {formatCurrency(l.value)} + + + {l.overBudget ? ( + Over budget + ) : ( + Under + )} + + + {l.notes || "—"} + +
+ ))} +
+
+ )} +
+
);