diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2023-12-09 12:44:08 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2023-12-09 12:44:08 +0700 |
| commit | 828e0b2301bfe7ff95b776dacf5f844dd10756d0 (patch) | |
| tree | 1cb97eb299ce7ae4d7472e38dc2faa3281ea64e5 /src/app/api/stock-opname/route.tsx | |
| parent | e01af38369c04be36bc71473a46c73aca655f046 (diff) | |
Fix compute different product stock opname
Diffstat (limited to 'src/app/api/stock-opname/route.tsx')
| -rw-r--r-- | src/app/api/stock-opname/route.tsx | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/src/app/api/stock-opname/route.tsx b/src/app/api/stock-opname/route.tsx index 4c2dee4..38284bf 100644 --- a/src/app/api/stock-opname/route.tsx +++ b/src/app/api/stock-opname/route.tsx @@ -169,10 +169,6 @@ const computeIsDifferent = async ({ if (_.isNumber(totalQty['COUNT3']) && _.isNumber(COUNT3.quantity)) totalQty['COUNT3'] += COUNT3.quantity if (_.isNumber(totalQty['VERIFICATION']) && _.isNumber(VERIFICATION.quantity)) totalQty['VERIFICATION'] += VERIFICATION.quantity - 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++ } @@ -201,6 +197,26 @@ const computeIsDifferent = async ({ conditional.count2EqWithCount3 ) + for (const opname of stockOpnames) { + let { COUNT1, COUNT2, COUNT3, VERIFICATION } = opname + + const detailCondition = { + verificationCheckAll: _.isNumber(VERIFICATION.quantity), + count1EqWithCount2: COUNT1.quantity !== null && COUNT2.quantity !== null && COUNT1.quantity === COUNT2.quantity, + count1EqWithCount3: COUNT1.quantity !== null && COUNT3.quantity !== null && COUNT1.quantity === COUNT3.quantity, + count2EqWithCount3: COUNT2.quantity !== null && COUNT3.quantity !== null && COUNT2.quantity === COUNT3.quantity, + } + + isDifferent = !( + detailCondition.verificationCheckAll || + detailCondition.count1EqWithCount2 || + detailCondition.count1EqWithCount3 || + detailCondition.count2EqWithCount3 + ) + + if (isDifferent) break + } + await prisma.product.update({ where: { id: product.id }, data: { isDifferent } |
