|
|
@@ -181,7 +181,8 @@ const PoDetail: React.FC<Props> = ({ po, qc, warehouse }) => { |
|
|
|
const pathname = usePathname() |
|
|
|
const searchParams = useSearchParams(); |
|
|
|
|
|
|
|
const [row, setRow] = useState<PurchaseOrderLine>({}); |
|
|
|
const [row, setRow] = useState(rows[0]); |
|
|
|
|
|
|
|
const [stockInLine, setStockInLine] = useState<StockInLine[]>([]); |
|
|
|
const [processedQty, setProcessedQty] = useState(0); |
|
|
|
|
|
|
@@ -190,7 +191,7 @@ const PoDetail: React.FC<Props> = ({ po, qc, warehouse }) => { |
|
|
|
const [selectedPoId, setSelectedPoId] = useState(po.id); |
|
|
|
const currentPoId = searchParams.get('id'); |
|
|
|
const selectedIdsParam = searchParams.get('selectedIds'); |
|
|
|
|
|
|
|
const [selectedRowId, setSelectedRowId] = useState<number | null>(null); |
|
|
|
|
|
|
|
const fetchPoList = useCallback(async () => { |
|
|
|
try { |
|
|
@@ -212,15 +213,6 @@ const PoDetail: React.FC<Props> = ({ po, qc, warehouse }) => { |
|
|
|
} |
|
|
|
}, [selectedIdsParam]); |
|
|
|
|
|
|
|
const handlePoSelect = useCallback( |
|
|
|
(selectedPo: PoResult) => { |
|
|
|
setSelectedPoId(selectedPo.id); |
|
|
|
|
|
|
|
const newSelectedIds = selectedIdsParam || selectedPo.id.toString(); |
|
|
|
router.push(`/po/edit?id=${selectedPo.id}&start=true&selectedIds=${newSelectedIds}`, { scroll: false }); |
|
|
|
}, |
|
|
|
[router, selectedIdsParam] |
|
|
|
); |
|
|
|
|
|
|
|
const fetchPoDetail = useCallback(async (poId: string) => { |
|
|
|
try { |
|
|
@@ -238,7 +230,16 @@ const PoDetail: React.FC<Props> = ({ po, qc, warehouse }) => { |
|
|
|
console.error("Failed to fetch PO detail:", error); |
|
|
|
} |
|
|
|
}, []); |
|
|
|
|
|
|
|
|
|
|
|
const handlePoSelect = useCallback( |
|
|
|
async (selectedPo: PoResult) => { |
|
|
|
setSelectedPoId(selectedPo.id); |
|
|
|
await fetchPoDetail(selectedPo.id.toString()); |
|
|
|
const newSelectedIds = selectedIdsParam || selectedPo.id.toString(); |
|
|
|
router.push(`/po/edit?id=${selectedPo.id}&start=true&selectedIds=${newSelectedIds}`, { scroll: false }); |
|
|
|
}, |
|
|
|
[router, selectedIdsParam, fetchPoDetail] |
|
|
|
); |
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
if (currentPoId && currentPoId !== selectedPoId.toString()) { |
|
|
@@ -326,6 +327,12 @@ const PoDetail: React.FC<Props> = ({ po, qc, warehouse }) => { |
|
|
|
} |
|
|
|
}, [processedQty, row.qty]); |
|
|
|
|
|
|
|
const handleRowSelect = () => { |
|
|
|
setSelectedRowId(row.id); |
|
|
|
setRow(row); |
|
|
|
setStockInLine(row.stockInLine); |
|
|
|
setProcessedQty(row.processed); |
|
|
|
}; |
|
|
|
const changeStockInLines = useCallback( |
|
|
|
(id: number) => { |
|
|
|
console.log(id) |
|
|
@@ -402,6 +409,13 @@ const PoDetail: React.FC<Props> = ({ po, qc, warehouse }) => { |
|
|
|
{open ? <KeyboardArrowUpIcon /> : <KeyboardArrowDownIcon />} |
|
|
|
</IconButton> |
|
|
|
</TableCell> */} |
|
|
|
<TableCell align="center" sx={{ width: '60px' }}> |
|
|
|
<Checkbox |
|
|
|
checked={selectedRowId === row.id} |
|
|
|
onChange={handleRowSelect} |
|
|
|
onClick={(e) => e.stopPropagation()} |
|
|
|
/> |
|
|
|
</TableCell> |
|
|
|
<TableCell align="left">{row.itemNo}</TableCell> |
|
|
|
<TableCell align="left">{row.itemName}</TableCell> |
|
|
|
<TableCell align="right">{integerFormatter.format(row.qty)}</TableCell> |
|
|
@@ -645,6 +659,7 @@ const PoDetail: React.FC<Props> = ({ po, qc, warehouse }) => { |
|
|
|
<Table aria-label="collapsible table" stickyHeader> |
|
|
|
<TableHead> |
|
|
|
<TableRow> |
|
|
|
<TableCell align="center" sx={{ width: '60px' }}>Select</TableCell> |
|
|
|
<TableCell sx={{ width: '125px' }}>{t("itemNo")}</TableCell> |
|
|
|
<TableCell align="left" sx={{ width: '125px' }}>{t("itemName")}</TableCell> |
|
|
|
<TableCell align="right">{t("qty")}</TableCell> |
|
|
@@ -671,30 +686,34 @@ const PoDetail: React.FC<Props> = ({ po, qc, warehouse }) => { |
|
|
|
{/* area5: selected item info */} |
|
|
|
<Grid container xs={12} justifyContent="start"> |
|
|
|
<Grid item xs={12}> |
|
|
|
<Typography variant="h6">{row.itemNo && row.itemName ? `已選擇: ${row.itemNo}-${row.itemName}` : `未選擇貨品`}</Typography> |
|
|
|
<Typography variant="h6"> |
|
|
|
已選擇: {selectedRowId ? row.itemNo : '無'} - {selectedRowId ? row.itemName : '無'} |
|
|
|
</Typography> |
|
|
|
</Grid> |
|
|
|
<Grid item xs={12}> |
|
|
|
<TableContainer component={Paper} sx={{ width: 'fit-content', overflow: 'auto' }}> |
|
|
|
<Table> |
|
|
|
<TableBody> |
|
|
|
<TableRow> |
|
|
|
<TableCell align="right"> |
|
|
|
<Box> |
|
|
|
<PoInputGrid |
|
|
|
qc={qc} |
|
|
|
setRows={setRows} |
|
|
|
stockInLine={stockInLine} |
|
|
|
setStockInLine={setStockInLine} |
|
|
|
setProcessedQty={setProcessedQty} |
|
|
|
itemDetail={row} |
|
|
|
warehouse={warehouse} |
|
|
|
/> |
|
|
|
</Box> |
|
|
|
</TableCell> |
|
|
|
</TableRow> |
|
|
|
</TableBody> |
|
|
|
</Table> |
|
|
|
</TableContainer> |
|
|
|
{selectedRowId && ( |
|
|
|
<TableContainer component={Paper} sx={{ width: 'fit-content', overflow: 'auto' }}> |
|
|
|
<Table> |
|
|
|
<TableBody> |
|
|
|
<TableRow> |
|
|
|
<TableCell align="right"> |
|
|
|
<Box> |
|
|
|
<PoInputGrid |
|
|
|
qc={qc} |
|
|
|
setRows={setRows} |
|
|
|
stockInLine={stockInLine} |
|
|
|
setStockInLine={setStockInLine} |
|
|
|
setProcessedQty={setProcessedQty} |
|
|
|
itemDetail={row} |
|
|
|
warehouse={warehouse} |
|
|
|
/> |
|
|
|
</Box> |
|
|
|
</TableCell> |
|
|
|
</TableRow> |
|
|
|
</TableBody> |
|
|
|
</Table> |
|
|
|
</TableContainer> |
|
|
|
)} |
|
|
|
</Grid> |
|
|
|
</Grid> |
|
|
|
{/* tab 2 */} |
|
|
|