| @@ -68,7 +68,7 @@ export async function fetchStaffDeliveryPerformanceHandlers(): Promise<StaffOpti | |||||
| if (!res.ok) throw new Error("Failed to fetch staff list"); | if (!res.ok) throw new Error("Failed to fetch staff list"); | ||||
| const data = await res.json(); | const data = await res.json(); | ||||
| if (!Array.isArray(data)) return []; | if (!Array.isArray(data)) return []; | ||||
| return data.map((r: Record<string, unknown>) => ({ | |||||
| return (data as Record<string, unknown>[]).map((r: Record<string, unknown>) => ({ | |||||
| staffNo: String(r.staffNo ?? ""), | staffNo: String(r.staffNo ?? ""), | ||||
| name: String(r.name ?? ""), | name: String(r.name ?? ""), | ||||
| })); | })); | ||||
| @@ -112,7 +112,7 @@ export async function fetchJobOrderByStatus( | |||||
| ); | ); | ||||
| if (!res.ok) throw new Error("Failed to fetch job order by status"); | if (!res.ok) throw new Error("Failed to fetch job order by status"); | ||||
| const data = await res.json(); | const data = await res.json(); | ||||
| return (Array.isArray(data) ? data : []).map((r: Record<string, unknown>) => ({ | |||||
| return ((Array.isArray(data) ? data : []) as Record<string, unknown>[]).map((r: Record<string, unknown>) => ({ | |||||
| status: String(r.status ?? ""), | status: String(r.status ?? ""), | ||||
| count: Number(r.count ?? 0), | count: Number(r.count ?? 0), | ||||
| })); | })); | ||||
| @@ -139,7 +139,7 @@ export async function fetchJobOrderCreatedCompletedByDate( | |||||
| ); | ); | ||||
| if (!res.ok) throw new Error("Failed to fetch job order created/completed"); | if (!res.ok) throw new Error("Failed to fetch job order created/completed"); | ||||
| const data = await res.json(); | const data = await res.json(); | ||||
| return (Array.isArray(data) ? data : []).map((r: Record<string, unknown>) => ({ | |||||
| return ((Array.isArray(data) ? data : []) as Record<string, unknown>[]).map((r: Record<string, unknown>) => ({ | |||||
| date: String(r.date ?? ""), | date: String(r.date ?? ""), | ||||
| createdCount: Number(r.createdCount ?? 0), | createdCount: Number(r.createdCount ?? 0), | ||||
| completedCount: Number(r.completedCount ?? 0), | completedCount: Number(r.completedCount ?? 0), | ||||
| @@ -160,7 +160,7 @@ export async function fetchJobMaterialPendingPickedByDate( | |||||
| const res = await clientAuthFetch(`${BASE}/job-material-pending-picked-by-date?${q}`); | const res = await clientAuthFetch(`${BASE}/job-material-pending-picked-by-date?${q}`); | ||||
| if (!res.ok) throw new Error("Failed to fetch job material pending/picked"); | if (!res.ok) throw new Error("Failed to fetch job material pending/picked"); | ||||
| const data = await res.json(); | const data = await res.json(); | ||||
| return (Array.isArray(data) ? data : []).map((r: Record<string, unknown>) => ({ | |||||
| return ((Array.isArray(data) ? data : []) as Record<string, unknown>[]).map((r: Record<string, unknown>) => ({ | |||||
| date: String(r.date ?? ""), | date: String(r.date ?? ""), | ||||
| pendingCount: Number(r.pendingCount ?? 0), | pendingCount: Number(r.pendingCount ?? 0), | ||||
| pickedCount: Number(r.pickedCount ?? 0), | pickedCount: Number(r.pickedCount ?? 0), | ||||
| @@ -181,7 +181,7 @@ export async function fetchJobProcessPendingCompletedByDate( | |||||
| const res = await clientAuthFetch(`${BASE}/job-process-pending-completed-by-date?${q}`); | const res = await clientAuthFetch(`${BASE}/job-process-pending-completed-by-date?${q}`); | ||||
| if (!res.ok) throw new Error("Failed to fetch job process pending/completed"); | if (!res.ok) throw new Error("Failed to fetch job process pending/completed"); | ||||
| const data = await res.json(); | const data = await res.json(); | ||||
| return (Array.isArray(data) ? data : []).map((r: Record<string, unknown>) => ({ | |||||
| return ((Array.isArray(data) ? data : []) as Record<string, unknown>[]).map((r: Record<string, unknown>) => ({ | |||||
| date: String(r.date ?? ""), | date: String(r.date ?? ""), | ||||
| pendingCount: Number(r.pendingCount ?? 0), | pendingCount: Number(r.pendingCount ?? 0), | ||||
| completedCount: Number(r.completedCount ?? 0), | completedCount: Number(r.completedCount ?? 0), | ||||
| @@ -202,7 +202,7 @@ export async function fetchJobEquipmentWorkingWorkedByDate( | |||||
| const res = await clientAuthFetch(`${BASE}/job-equipment-working-worked-by-date?${q}`); | const res = await clientAuthFetch(`${BASE}/job-equipment-working-worked-by-date?${q}`); | ||||
| if (!res.ok) throw new Error("Failed to fetch job equipment working/worked"); | if (!res.ok) throw new Error("Failed to fetch job equipment working/worked"); | ||||
| const data = await res.json(); | const data = await res.json(); | ||||
| return (Array.isArray(data) ? data : []).map((r: Record<string, unknown>) => ({ | |||||
| return ((Array.isArray(data) ? data : []) as Record<string, unknown>[]).map((r: Record<string, unknown>) => ({ | |||||
| date: String(r.date ?? ""), | date: String(r.date ?? ""), | ||||
| workingCount: Number(r.workingCount ?? 0), | workingCount: Number(r.workingCount ?? 0), | ||||
| workedCount: Number(r.workedCount ?? 0), | workedCount: Number(r.workedCount ?? 0), | ||||
| @@ -219,7 +219,7 @@ export async function fetchProductionScheduleByDate( | |||||
| ); | ); | ||||
| if (!res.ok) throw new Error("Failed to fetch production schedule by date"); | if (!res.ok) throw new Error("Failed to fetch production schedule by date"); | ||||
| const data = await res.json(); | const data = await res.json(); | ||||
| return (Array.isArray(data) ? data : []).map((r: Record<string, unknown>) => ({ | |||||
| return ((Array.isArray(data) ? data : []) as Record<string, unknown>[]).map((r: Record<string, unknown>) => ({ | |||||
| date: String(r.date ?? ""), | date: String(r.date ?? ""), | ||||
| scheduledItemCount: Number(r.scheduledItemCount ?? r.scheduleCount ?? 0), | scheduledItemCount: Number(r.scheduledItemCount ?? r.scheduleCount ?? 0), | ||||
| totalEstProdCount: Number(r.totalEstProdCount ?? 0), | totalEstProdCount: Number(r.totalEstProdCount ?? 0), | ||||
| @@ -234,7 +234,7 @@ export async function fetchPlannedDailyOutputByItem( | |||||
| ); | ); | ||||
| if (!res.ok) throw new Error("Failed to fetch planned daily output"); | if (!res.ok) throw new Error("Failed to fetch planned daily output"); | ||||
| const data = await res.json(); | const data = await res.json(); | ||||
| return (Array.isArray(data) ? data : []).map((r: Record<string, unknown>) => ({ | |||||
| return ((Array.isArray(data) ? data : []) as Record<string, unknown>[]).map((r: Record<string, unknown>) => ({ | |||||
| itemCode: String(r.itemCode ?? ""), | itemCode: String(r.itemCode ?? ""), | ||||
| itemName: String(r.itemName ?? ""), | itemName: String(r.itemName ?? ""), | ||||
| dailyQty: Number(r.dailyQty ?? 0), | dailyQty: Number(r.dailyQty ?? 0), | ||||
| @@ -259,7 +259,7 @@ export async function fetchPlannedOutputByDateAndItem( | |||||
| ); | ); | ||||
| if (!res.ok) throw new Error("Failed to fetch planned output by date and item"); | if (!res.ok) throw new Error("Failed to fetch planned output by date and item"); | ||||
| const data = await res.json(); | const data = await res.json(); | ||||
| return (Array.isArray(data) ? data : []).map((r: Record<string, unknown>) => ({ | |||||
| return ((Array.isArray(data) ? data : []) as Record<string, unknown>[]).map((r: Record<string, unknown>) => ({ | |||||
| date: String(r.date ?? ""), | date: String(r.date ?? ""), | ||||
| itemCode: String(r.itemCode ?? ""), | itemCode: String(r.itemCode ?? ""), | ||||
| itemName: String(r.itemName ?? ""), | itemName: String(r.itemName ?? ""), | ||||
| @@ -282,7 +282,7 @@ export async function fetchStaffDeliveryPerformance( | |||||
| ); | ); | ||||
| if (!res.ok) throw new Error("Failed to fetch staff delivery performance"); | if (!res.ok) throw new Error("Failed to fetch staff delivery performance"); | ||||
| const data = await res.json(); | const data = await res.json(); | ||||
| return (Array.isArray(data) ? data : []).map((r: Record<string, unknown>) => { | |||||
| return ((Array.isArray(data) ? data : []) as Record<string, unknown>[]).map((r: Record<string, unknown>) => { | |||||
| // Accept camelCase or lowercase keys (JDBC/DB may return different casing) | // Accept camelCase or lowercase keys (JDBC/DB may return different casing) | ||||
| const row = r as Record<string, unknown>; | const row = r as Record<string, unknown>; | ||||
| return { | return { | ||||
| @@ -327,7 +327,7 @@ export async function fetchPurchaseOrderByStatus( | |||||
| ); | ); | ||||
| if (!res.ok) throw new Error("Failed to fetch purchase order by status"); | if (!res.ok) throw new Error("Failed to fetch purchase order by status"); | ||||
| const data = await res.json(); | const data = await res.json(); | ||||
| return (Array.isArray(data) ? data : []).map((r: Record<string, unknown>) => ({ | |||||
| return ((Array.isArray(data) ? data : []) as Record<string, unknown>[]).map((r: Record<string, unknown>) => ({ | |||||
| status: String(r.status ?? ""), | status: String(r.status ?? ""), | ||||
| count: Number(r.count ?? 0), | count: Number(r.count ?? 0), | ||||
| })); | })); | ||||
| @@ -359,7 +359,7 @@ export async function fetchTopDeliveryItemsItemOptions( | |||||
| ); | ); | ||||
| if (!res.ok) throw new Error("Failed to fetch item options"); | if (!res.ok) throw new Error("Failed to fetch item options"); | ||||
| const data = await res.json(); | const data = await res.json(); | ||||
| return (Array.isArray(data) ? data : []).map((r: Record<string, unknown>) => ({ | |||||
| return ((Array.isArray(data) ? data : []) as Record<string, unknown>[]).map((r: Record<string, unknown>) => ({ | |||||
| itemCode: String(r.itemCode ?? ""), | itemCode: String(r.itemCode ?? ""), | ||||
| itemName: String(r.itemName ?? ""), | itemName: String(r.itemName ?? ""), | ||||
| })); | })); | ||||
| @@ -380,7 +380,7 @@ export async function fetchTopDeliveryItems( | |||||
| const res = await clientAuthFetch(`${BASE}/top-delivery-items?${q}`); | const res = await clientAuthFetch(`${BASE}/top-delivery-items?${q}`); | ||||
| if (!res.ok) throw new Error("Failed to fetch top delivery items"); | if (!res.ok) throw new Error("Failed to fetch top delivery items"); | ||||
| const data = await res.json(); | const data = await res.json(); | ||||
| return (Array.isArray(data) ? data : []).map((r: Record<string, unknown>) => ({ | |||||
| return ((Array.isArray(data) ? data : []) as Record<string, unknown>[]).map((r: Record<string, unknown>) => ({ | |||||
| itemCode: String(r.itemCode ?? ""), | itemCode: String(r.itemCode ?? ""), | ||||
| itemName: String(r.itemName ?? ""), | itemName: String(r.itemName ?? ""), | ||||
| totalQty: Number(r.totalQty ?? 0), | totalQty: Number(r.totalQty ?? 0), | ||||
| @@ -418,7 +418,7 @@ export async function fetchConsumptionTrendByMonth( | |||||
| const res = await clientAuthFetch(`${BASE}/consumption-trend-by-month?${q}`); | const res = await clientAuthFetch(`${BASE}/consumption-trend-by-month?${q}`); | ||||
| if (!res.ok) throw new Error("Failed to fetch consumption trend"); | if (!res.ok) throw new Error("Failed to fetch consumption trend"); | ||||
| const data = await res.json(); | const data = await res.json(); | ||||
| return (Array.isArray(data) ? data : []).map((r: Record<string, unknown>) => ({ | |||||
| return ((Array.isArray(data) ? data : []) as Record<string, unknown>[]).map((r: Record<string, unknown>) => ({ | |||||
| month: String(r.month ?? ""), | month: String(r.month ?? ""), | ||||
| outQty: Number(r.outQty ?? 0), | outQty: Number(r.outQty ?? 0), | ||||
| })); | })); | ||||
| @@ -431,11 +431,12 @@ function normalizeChartRows<T>( | |||||
| numberKeys: string[] | numberKeys: string[] | ||||
| ): T[] { | ): T[] { | ||||
| if (!Array.isArray(rows)) return []; | if (!Array.isArray(rows)) return []; | ||||
| return rows.map((r: Record<string, unknown>) => { | |||||
| return rows.map((r: unknown) => { | |||||
| const row = r as Record<string, unknown>; | |||||
| const out: Record<string, unknown> = {}; | const out: Record<string, unknown> = {}; | ||||
| out[dateKey] = r[dateKey] != null ? String(r[dateKey]) : ""; | |||||
| out[dateKey] = row[dateKey] != null ? String(row[dateKey]) : ""; | |||||
| numberKeys.forEach((k) => { | numberKeys.forEach((k) => { | ||||
| out[k] = Number(r[k]) || 0; | |||||
| out[k] = Number(row[k]) || 0; | |||||
| }); | }); | ||||
| return out as T; | return out as T; | ||||
| }); | }); | ||||