feat(plant): sort equipment by rate then hours this month
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
824271cdd0
commit
e9edc1988e
2 changed files with 15 additions and 3 deletions
|
|
@ -78,10 +78,13 @@ export default async function PlantPage({
|
||||||
...allFuelLogs.filter(l=>activeIds.has(l.site)).flatMap(l=>l.expand?.vehicle ? [l.expand.vehicle] : []),
|
...allFuelLogs.filter(l=>activeIds.has(l.site)).flatMap(l=>l.expand?.vehicle ? [l.expand.vehicle] : []),
|
||||||
...periods.filter(p=>activeIds.has(p.site ?? "")).flatMap(p=>p.expand?.vehicle ? [p.expand.vehicle] : []),
|
...periods.filter(p=>activeIds.has(p.site ?? "")).flatMap(p=>p.expand?.vehicle ? [p.expand.vehicle] : []),
|
||||||
].filter(isPlant).map(v=>[v.id,v])).values()].sort((a,b)=>a.description.localeCompare(b.description));
|
].filter(isPlant).map(v=>[v.id,v])).values()].sort((a,b)=>a.description.localeCompare(b.description));
|
||||||
|
const monthStart = `${today.slice(0, 8)}01`;
|
||||||
const aggByVehicle = new Map(allVehicles.map(v=> {
|
const aggByVehicle = new Map(allVehicles.map(v=> {
|
||||||
const points = plantUsage(allFuelLogs.filter(l=>l.vehicle===v.id), periods.filter(p=>p.vehicle===v.id), v.cost_per_hour ?? 0, today)
|
const visible = plantUsage(allFuelLogs.filter(l=>l.vehicle===v.id), periods.filter(p=>p.vehicle===v.id), v.cost_per_hour ?? 0, today)
|
||||||
.filter(p=>activeIds.has(p.site) && p.date.slice(0,10) <= today && p.date.slice(0,10) >= rangeStart);
|
.filter(p=>activeIds.has(p.site) && p.date.slice(0,10) <= today);
|
||||||
return [v.id, {totalHours:points.reduce((s,p)=>s+p.hours,0),totalValue:points.reduce((s,p)=>s+p.value,0),logCount:points.length,reviewCount:points.filter(p=>p.rejected).length,projectCodes:[...new Set(points.map(p=>siteById[p.site]).filter(Boolean))].join(" · ")}];
|
const points = visible.filter(p=>p.date.slice(0,10) >= rangeStart);
|
||||||
|
const monthHours = visible.filter(p=>p.date.slice(0,10) >= monthStart).reduce((s,p)=>s+p.hours,0);
|
||||||
|
return [v.id, {monthHours,totalHours:points.reduce((s,p)=>s+p.hours,0),totalValue:points.reduce((s,p)=>s+p.value,0),logCount:points.length,reviewCount:points.filter(p=>p.rejected).length,projectCodes:[...new Set(points.map(p=>siteById[p.site]).filter(Boolean))].join(" · ")}];
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// All plant vehicles show up — even those without a cost_per_hour
|
// All plant vehicles show up — even those without a cost_per_hour
|
||||||
|
|
@ -99,6 +102,7 @@ export default async function PlantPage({
|
||||||
historical: !activeIds.has(v.site),
|
historical: !activeIds.has(v.site),
|
||||||
canManage: scope.allowed.some(s=>s.id===v.site),
|
canManage: scope.allowed.some(s=>s.id===v.site),
|
||||||
totalHours: agg?.totalHours ?? 0,
|
totalHours: agg?.totalHours ?? 0,
|
||||||
|
monthHours: agg?.monthHours ?? 0,
|
||||||
totalValue: agg?.totalValue ?? 0,
|
totalValue: agg?.totalValue ?? 0,
|
||||||
logCount: agg?.logCount ?? 0,
|
logCount: agg?.logCount ?? 0,
|
||||||
overBudgetCount: 0, // no per-period budget field on fuel_logs
|
overBudgetCount: 0, // no per-period budget field on fuel_logs
|
||||||
|
|
@ -106,6 +110,12 @@ export default async function PlantPage({
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Default order: rated equipment first, then most hours this month, then name.
|
||||||
|
rows.sort((a, b) =>
|
||||||
|
Number((b.costPerHour ?? 0) > 0) - Number((a.costPerHour ?? 0) > 0) ||
|
||||||
|
(b.monthHours ?? 0) - (a.monthHours ?? 0) ||
|
||||||
|
a.description.localeCompare(b.description));
|
||||||
|
|
||||||
const sites: PlantSiteOption[] = allSites.map((s) => ({
|
const sites: PlantSiteOption[] = allSites.map((s) => ({
|
||||||
id: s.id,
|
id: s.id,
|
||||||
project_code: s.project_code,
|
project_code: s.project_code,
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,8 @@ export interface PlantRow {
|
||||||
fuelLimits: string;
|
fuelLimits: string;
|
||||||
/** Per-vehicle totals computed from fuel_logs (odo diffs for plant). */
|
/** Per-vehicle totals computed from fuel_logs (odo diffs for plant). */
|
||||||
totalHours: number;
|
totalHours: number;
|
||||||
|
/** Hours in the current calendar month; drives the default sort. */
|
||||||
|
monthHours?: number;
|
||||||
costPerHour?: number;
|
costPerHour?: number;
|
||||||
reviewCount?: number;
|
reviewCount?: number;
|
||||||
historical?: boolean;
|
historical?: boolean;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue