From e01af38369c04be36bc71473a46c73aca655f046 Mon Sep 17 00:00:00 2001
From: Rafi Zadanly <zadanlyr@gmail.com>
Date: Sat, 9 Dec 2023 12:26:26 +0700
Subject: Fix compute different product stock opname

---
 src/modules/result/components/Table.tsx | 10 ++++++++++
 1 file changed, 10 insertions(+)

(limited to 'src/modules/result/components/Table.tsx')

diff --git a/src/modules/result/components/Table.tsx b/src/modules/result/components/Table.tsx
index 20cc2d6..082f988 100644
--- a/src/modules/result/components/Table.tsx
+++ b/src/modules/result/components/Table.tsx
@@ -76,6 +76,13 @@ const Table = () => {
     stockOpnames.refetch()
   }
 
+  const recompute = async (productId: number, companyId: string) => {
+    const response = await fetch(`/api/company/${companyId}/product/${productId}/compute-different`, { method: 'POST' })
+    const stockOpname = await response.json()
+    toast(`Berhasil menghitung ulang status barang, hasilnya ${stockOpname.data.isDifferent ? 'selisih' : 'aman'}`)
+    stockOpnames.refetch()
+  }
+
   const isLoading = stockOpnames.isLoading || stockOpnames.isRefetching
 
   const COL_LENGTH = 9
@@ -149,6 +156,9 @@ const Table = () => {
                           </Button>
                         </DropdownTrigger>
                         <DropdownMenu>
+                          <DropdownItem key="recompute" onPress={() => recompute(stockOpname.id, company)}>
+                            Re-compute
+                          </DropdownItem>
                           <DropdownItem key="toggleDifferent" onPress={() => toggleDifferent(stockOpname.id)}>
                             Tandai {stockOpname.isDifferent ? 'aman' : 'selisih'}
                           </DropdownItem>
-- 
cgit v1.2.3

