summaryrefslogtreecommitdiff
path: root/src/modules/stock-opname/index.tsx
diff options
context:
space:
mode:
authorMqdd <ahmadmiqdad27@gmail.com>2026-02-15 11:18:35 +0700
committerMqdd <ahmadmiqdad27@gmail.com>2026-02-15 11:18:35 +0700
commit2af2659018d08cd8685a6e727994ab76f0735189 (patch)
tree5d1327d8269c9e2f625ec809ac31beb4fb4b08e4 /src/modules/stock-opname/index.tsx
parentd131b3cc79148b9f72a9bfe2fab3a0c6b3dd092d (diff)
<Miqdad> Locatorlocator
Diffstat (limited to 'src/modules/stock-opname/index.tsx')
-rw-r--r--src/modules/stock-opname/index.tsx29
1 files changed, 27 insertions, 2 deletions
diff --git a/src/modules/stock-opname/index.tsx b/src/modules/stock-opname/index.tsx
index 2937a98..4456b11 100644
--- a/src/modules/stock-opname/index.tsx
+++ b/src/modules/stock-opname/index.tsx
@@ -37,6 +37,31 @@ const StockOpname = () => {
}, [form.product, form.location, setOldOpname])
+ // Auto-populate location when a product with assigned location is selected
+ useEffect(() => {
+ const loadProductAndSetLocation = async () => {
+ if (form.product?.value) {
+ try {
+ const response = await fetch(`/api/product?search=`)
+ const data: { products: Product[] } = await response.json()
+ const selectedProduct = data?.products.find(p => p.id === form.product?.value)
+
+ if (selectedProduct && (selectedProduct as any).location && !form.location?.value) {
+ const location = (selectedProduct as any).location
+ updateForm('location', {
+ value: location.id,
+ label: location.name
+ })
+ }
+ } catch (error) {
+ console.error('Error loading product location:', error)
+ }
+ }
+ }
+
+ loadProductAndSetLocation()
+ }, [form.product?.value, form.location?.value, updateForm])
+
const handleSelectChange = (val: SingleValue<SelectOption>, action: ActionMeta<SelectOption>) => {
updateForm(action.name as keyof typeof form, val)
}
@@ -253,9 +278,9 @@ const loadProduct = async (inputValue: string) => {
const response = await fetch(`/api/product?search=${inputValue}`)
const data: { products: Product[] } = await response.json() || []
- return data?.products.map((product) => ({
+ return data?.products.map((product: any) => ({
value: product.id,
- label: `${product.itemCode ? `[${product.itemCode}]` : ''} ${product.name} ${product.barcode ? ` [${product.barcode}]` : ''}`
+ label: `${product.itemCode ? `[${product.itemCode}]` : ''} ${product.name} ${product.barcode ? ` [${product.barcode}]` : ''} ${product.location ? `(Lokasi: ${product.location.name})` : ''}`
}
))
}