summaryrefslogtreecommitdiff
path: root/src/app/api/stock-opname/route.tsx
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2023-12-01 10:16:12 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2023-12-01 10:16:12 +0700
commitae3207e9778c3f2fb01d64714ff15fc073ec093d (patch)
tree7b4c8cd8c00fec4d9eeafec8e01e938917cbee2e /src/app/api/stock-opname/route.tsx
parent812e4ac0afc56ee3121a5673af35bf8be2f4432c (diff)
Update compute different, result, and product list feature
Diffstat (limited to 'src/app/api/stock-opname/route.tsx')
-rw-r--r--src/app/api/stock-opname/route.tsx19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/app/api/stock-opname/route.tsx b/src/app/api/stock-opname/route.tsx
index 3b3ad5a..e98c3b2 100644
--- a/src/app/api/stock-opname/route.tsx
+++ b/src/app/api/stock-opname/route.tsx
@@ -113,9 +113,7 @@ export async function POST(request: NextRequest) {
team
}
- const stockOpname = await prisma.stockOpname.findFirst({
- where: query
- })
+ const stockOpname = await prisma.stockOpname.findFirst({ where: query })
const data = {
...query,
@@ -165,6 +163,7 @@ const computeIsDifferent = async ({
const stockOpnames: StockOpnameLocationRes[] = await stockOpnamesFetch.json()
let isDifferent: boolean = false
+ let verificationCounter: number = 0
for (const opname of stockOpnames) {
let { COUNT1, COUNT2, COUNT3, VERIFICATION } = opname
@@ -182,25 +181,31 @@ const computeIsDifferent = async ({
if (_.isNumber(COUNT1.quantity) && _.isNumber(COUNT2.quantity) && COUNT1.quantity !== COUNT2.quantity) isDifferent = true
if (_.isNumber(COUNT1.quantity) && _.isNumber(COUNT3.quantity) && COUNT1.quantity !== COUNT3.quantity) isDifferent = true
if (_.isNumber(COUNT2.quantity) && _.isNumber(COUNT3.quantity) && COUNT2.quantity !== COUNT3.quantity) isDifferent = true
+
+ if (_.isNumber(VERIFICATION.quantity)) verificationCounter++
}
const product = await prisma.product.findFirst({ where: { id: productId } })
if (!product) return
- const onhandQty = product?.onhandQty || 0
+ const onhandQty = product.onhandQty
+ const differenceQty = product.differenceQty
+ const allQty = onhandQty + differenceQty
if (!isDifferent) {
const conditional = {
- wasVerified: typeof totalQty['VERIFICATION'] === 'number',
+ verificationCheckAll: verificationCounter > 0 && verificationCounter === stockOpnames.length,
anyCountEqWithOnhand: [totalQty['COUNT1'], totalQty['COUNT2'], totalQty['COUNT3']].includes(onhandQty),
+ anyCountEqWithAllQty: [totalQty['COUNT1'], totalQty['COUNT2'], totalQty['COUNT3']].includes(allQty),
count1EqWithCount2: totalQty['COUNT1'] !== null && totalQty['COUNT2'] !== null && totalQty['COUNT1'] === totalQty['COUNT2'],
count1EqWithCount3: totalQty['COUNT1'] !== null && totalQty['COUNT3'] !== null && totalQty['COUNT1'] === totalQty['COUNT3'],
- count2EqWithCount3: totalQty['COUNT2'] !== null && totalQty['COUNT3'] !== null && totalQty['COUNT2'] === totalQty['COUNT3']
+ count2EqWithCount3: totalQty['COUNT2'] !== null && totalQty['COUNT3'] !== null && totalQty['COUNT2'] === totalQty['COUNT3'],
}
isDifferent = !(
- conditional.wasVerified ||
+ conditional.verificationCheckAll ||
conditional.anyCountEqWithOnhand ||
+ conditional.anyCountEqWithAllQty ||
conditional.count1EqWithCount2 ||
conditional.count1EqWithCount3 ||
conditional.count2EqWithCount3