|
|
|
@@ -23,7 +23,7 @@ import { SessionWithTokens } from "@/config/authConfig"; |
|
|
|
import { createStockInLine } from "@/app/api/stockIn/actions"; |
|
|
|
import { msg } from "../Swal/CustomAlerts"; |
|
|
|
import dayjs from "dayjs"; |
|
|
|
import { fetchInventories } from "@/app/api/inventory/actions"; |
|
|
|
//import { fetchInventories } from "@/app/api/inventory/actions"; |
|
|
|
import { InventoryResult } from "@/app/api/inventory"; |
|
|
|
import { PrinterCombo } from "@/app/api/settings/printer"; |
|
|
|
import { JobTypeResponse } from "@/app/api/jo/actions"; |
|
|
|
@@ -76,16 +76,21 @@ const JoSearch: React.FC<Props> = ({ defaultInputs, bomCombo, printerCombo, jobT |
|
|
|
useEffect(() => { |
|
|
|
const fetchDetailedJos = async () => { |
|
|
|
const detailedMap = new Map<number, JobOrder>(); |
|
|
|
|
|
|
|
for (const jo of filteredJos) { |
|
|
|
try { |
|
|
|
const detailedJo = await fetchJoDetailClient(jo.id); |
|
|
|
detailedMap.set(jo.id, detailedJo); |
|
|
|
} catch (error) { |
|
|
|
console.error(`Error fetching detail for JO ${jo.id}:`, error); |
|
|
|
} |
|
|
|
try { |
|
|
|
const results = await Promise.all( |
|
|
|
filteredJos.map((jo) => |
|
|
|
fetchJoDetailClient(jo.id).then((detail) => ({ id: jo.id, detail })).catch((error) => { |
|
|
|
console.error(`Error fetching detail for JO ${jo.id}:`, error); |
|
|
|
return null; |
|
|
|
}) |
|
|
|
) |
|
|
|
); |
|
|
|
results.forEach((r) => { |
|
|
|
if (r) detailedMap.set(r.id, r.detail); |
|
|
|
}); |
|
|
|
} catch (error) { |
|
|
|
console.error("Error fetching JO details:", error); |
|
|
|
} |
|
|
|
|
|
|
|
setDetailedJos(detailedMap); |
|
|
|
}; |
|
|
|
|
|
|
|
@@ -93,7 +98,7 @@ const JoSearch: React.FC<Props> = ({ defaultInputs, bomCombo, printerCombo, jobT |
|
|
|
fetchDetailedJos(); |
|
|
|
} |
|
|
|
}, [filteredJos]); |
|
|
|
|
|
|
|
/* |
|
|
|
useEffect(() => { |
|
|
|
const fetchInventoryData = async () => { |
|
|
|
try { |
|
|
|
@@ -102,9 +107,9 @@ const JoSearch: React.FC<Props> = ({ defaultInputs, bomCombo, printerCombo, jobT |
|
|
|
name: "", |
|
|
|
type: "", |
|
|
|
pageNum: 0, |
|
|
|
pageSize: 1000 |
|
|
|
pageSize: 200, |
|
|
|
}); |
|
|
|
setInventoryData(inventoryResponse.records); |
|
|
|
setInventoryData(inventoryResponse.records ?? []); |
|
|
|
} catch (error) { |
|
|
|
console.error("Error fetching inventory data:", error); |
|
|
|
} |
|
|
|
@@ -112,6 +117,7 @@ const JoSearch: React.FC<Props> = ({ defaultInputs, bomCombo, printerCombo, jobT |
|
|
|
|
|
|
|
fetchInventoryData(); |
|
|
|
}, []); |
|
|
|
*/ |
|
|
|
|
|
|
|
const getStockAvailable = (pickLine: JoDetailPickLine) => { |
|
|
|
const inventory = inventoryData.find(inventory => |
|
|
|
|