diff --git a/src/components/FinishedGoodSearch/FGPickOrderCard.tsx b/src/components/FinishedGoodSearch/FGPickOrderCard.tsx index e406fca..f1bfd05 100644 --- a/src/components/FinishedGoodSearch/FGPickOrderCard.tsx +++ b/src/components/FinishedGoodSearch/FGPickOrderCard.tsx @@ -20,7 +20,7 @@ const FGPickOrderCard: React.FC = ({ fgOrder, onQrCodeClick }) => { = ({ fgOrder, onQrCodeClick }) => { = ({ fgOrder, onQrCodeClick }) => { = ({ pickOrders }) => { console.error("Missing user id in session"); return; } - const res = await autoAssignAndReleasePickOrderByStore(currentUserId, storeId); - console.log("Assign by store result:", res); - // Optionally show toast/refresh list here - }; - // ✅ Manual assignment handler - uses the action function - const handleManualAssign = useCallback(async () => { - if (!currentUserId || isAssigning) return; setIsAssigning(true); try { - console.log("đŸŽ¯ Manual assignment triggered for user:", currentUserId); - - // ✅ Use the action function instead of direct fetch - const result = await autoAssignAndReleasePickOrder(currentUserId); - console.log("✅ Manual assignment result:", result); + const res = await autoAssignAndReleasePickOrderByStore(currentUserId, storeId); + console.log("Assign by store result:", res); - if (result.code === "SUCCESS") { - console.log("✅ Successfully assigned pick order manually"); - // Trigger refresh of the PickExecution component + // ✅ Handle different response codes + if (res.code === "SUCCESS") { + console.log("✅ Successfully assigned pick order to store", storeId); + // ✅ Trigger refresh to show newly assigned data window.dispatchEvent(new CustomEvent('pickOrderAssigned')); - } else if (result.code === "EXISTS") { - console.log("â„šī¸ User already has active pick orders"); - // Still trigger refresh to show existing orders + } else if (res.code === "USER_BUSY") { + console.warn("âš ī¸ User already has pick orders in progress:", res.message); + // ✅ Show warning but still refresh to show existing orders + alert(`Warning: ${res.message}`); window.dispatchEvent(new CustomEvent('pickOrderAssigned')); + } else if (res.code === "NO_ORDERS") { + console.log("â„šī¸ No available pick orders for store", storeId); + alert(`Info: ${res.message}`); } else { - console.log("â„šī¸ No available pick orders or other status:", result.message); + console.log("â„šī¸ Assignment result:", res.message); + alert(`Info: ${res.message}`); } } catch (error) { - console.error("❌ Error in manual assignment:", error); + console.error("❌ Error assigning by store:", error); + alert("Error occurred during assignment"); } finally { setIsAssigning(false); } - }, [currentUserId, isAssigning]); + }; + // ✅ Manual assignment handler - uses the action function + const handleTabChange = useCallback>( (_e, newValue) => { @@ -316,7 +315,7 @@ const PickOrderSearch: React.FC = ({ pickOrders }) => { borderBottom: '1px solid #e0e0e0' }}> - + diff --git a/src/components/FinishedGoodSearch/GoodPickExecutiondetail.tsx b/src/components/FinishedGoodSearch/GoodPickExecutiondetail.tsx index 36b24c5..aa7142e 100644 --- a/src/components/FinishedGoodSearch/GoodPickExecutiondetail.tsx +++ b/src/components/FinishedGoodSearch/GoodPickExecutiondetail.tsx @@ -15,6 +15,7 @@ import { TableHead, TableRow, Paper, + Checkbox, TablePagination, Modal, } from "@mui/material"; @@ -490,25 +491,21 @@ const PickExecution: React.FC = ({ filterArgs }) => { console.log(`✅ Stock out line already exists for line ${matchingLot.pickOrderLineId}`); existsCount++; } else { - const stockOutLineData: CreateStockOutLine = { - consoCode: matchingLot.pickOrderConsoCode, - pickOrderLineId: matchingLot.pickOrderLineId, - inventoryLotLineId: matchingLot.lotId, - qty: 0.0 - }; + const stockOutLineUpdate = await updateStockOutLineStatus({ + id: selectedLotForQr.stockOutLineId, + status: 'checked', + qty: selectedLotForQr.stockOutLineQty || 0 + }); + console.log(`Create stock out line result for line ${matchingLot.pickOrderLineId}:`,stockOutLineUpdate); - console.log(`Creating stock out line for pick order line ${matchingLot.pickOrderLineId}:`, stockOutLineData); - const result = await createStockOutLine(stockOutLineData); - console.log(`Create stock out line result for line ${matchingLot.pickOrderLineId}:`, result); - - if (result && result.code === "EXISTS") { + if (stockOutLineUpdate && stockOutLineUpdate.code === "EXISTS") { console.log(`✅ Stock out line already exists for line ${matchingLot.pickOrderLineId}`); existsCount++; - } else if (result && result.code === "SUCCESS") { + } else if (stockOutLineUpdate && stockOutLineUpdate.code === "SUCCESS") { console.log(`✅ Stock out line created successfully for line ${matchingLot.pickOrderLineId}`); successCount++; } else { - console.error(`❌ Failed to create stock out line for line ${matchingLot.pickOrderLineId}:`, result); + console.error(`❌ Failed to create stock out line for line ${matchingLot.pickOrderLineId}:`, stockOutLineUpdate); errorCount++; } } @@ -567,16 +564,15 @@ const PickExecution: React.FC = ({ filterArgs }) => { const lotId = selectedLotForQr.lotId; // Create stock out line - const stockOutLineData: CreateStockOutLine = { - consoCode: selectedLotForQr.pickOrderConsoCode, // ✅ Use pickOrderConsoCode instead of pickOrderCode - pickOrderLineId: selectedLotForQr.pickOrderLineId, - inventoryLotLineId: selectedLotForQr.lotId, - qty: 0.0 - }; + try { - await createStockOutLine(stockOutLineData); - console.log("Stock out line created successfully!"); + const stockOutLineUpdate = await updateStockOutLineStatus({ + id: selectedLotForQr.stockOutLineId, + status: 'checked', + qty: selectedLotForQr.stockOutLineQty || 0 + }); + console.log("Stock out line updated successfully!"); // Close modal setQrModalOpen(false); @@ -907,30 +903,12 @@ const PickExecution: React.FC = ({ filterArgs }) => { }, []); // Pagination data with sorting by routerIndex - const paginatedData = useMemo(() => { - // ✅ Sort by routerIndex first, then by other criteria - const sortedData = [...combinedLotData].sort((a, b) => { - const aIndex = a.routerIndex || 0; - const bIndex = b.routerIndex || 0; - - // Primary sort: by routerIndex - if (aIndex !== bIndex) { - return aIndex - bIndex; - } - - // Secondary sort: by pickOrderCode if routerIndex is the same - if (a.pickOrderCode !== b.pickOrderCode) { - return a.pickOrderCode.localeCompare(b.pickOrderCode); - } - - // Tertiary sort: by lotNo if everything else is the same - return (a.lotNo || '').localeCompare(b.lotNo || ''); - }); - - const startIndex = paginationController.pageNum * paginationController.pageSize; - const endIndex = startIndex + paginationController.pageSize; - return sortedData.slice(startIndex, endIndex); - }, [combinedLotData, paginationController]); + // Remove the sorting logic and just do pagination +const paginatedData = useMemo(() => { + const startIndex = paginationController.pageNum * paginationController.pageSize; + const endIndex = startIndex + paginationController.pageSize; + return combinedLotData.slice(startIndex, endIndex); // ✅ No sorting needed +}, [combinedLotData, paginationController]); return ( @@ -980,7 +958,7 @@ const PickExecution: React.FC = ({ filterArgs }) => { {t("Shop Name")}: {fgPickOrders[0].shopName || '-'} - {t("Delivery Date")}: {(fgPickOrders[0].deliveryDate || '-').split('T')[0]} + {t("Pick Order Code")}:{fgPickOrders[0].pickOrderCode || '-'} {t("Departure Time")}: {fgPickOrders[0].DepartureTime || '-'} @@ -1015,6 +993,7 @@ const PickExecution: React.FC = ({ filterArgs }) => { {/* {t("Original Available Qty")} */} {t("Lot Actual Pick Qty")} {/* {t("Remaining Available Qty")} */} + {t("Finish Scan?")} {t("Action")} @@ -1041,7 +1020,7 @@ const PickExecution: React.FC = ({ filterArgs }) => { > - {lot.routerIndex || index + 1} + {index + 1} @@ -1070,7 +1049,7 @@ const PickExecution: React.FC = ({ filterArgs }) => { const inQty = lot.inQty || 0; const outQty = lot.outQty || 0; const result = inQty - outQty; - return result.toLocaleString(); + return result.toLocaleString()+'('+lot.stockUnit+')'; })()} @@ -1102,7 +1081,7 @@ const PickExecution: React.FC = ({ filterArgs }) => { {t("Scan")} ) : ( - // ✅ When stockOutLineId exists, show TextField + Issue button + = ({ filterArgs }) => { return result.toLocaleString(); })()} */} + + +