diff options
Diffstat (limited to 'src/app/api/stock-opname/route.tsx')
| -rw-r--r-- | src/app/api/stock-opname/route.tsx | 61 |
1 files changed, 45 insertions, 16 deletions
diff --git a/src/app/api/stock-opname/route.tsx b/src/app/api/stock-opname/route.tsx index 154ed14..250e70b 100644 --- a/src/app/api/stock-opname/route.tsx +++ b/src/app/api/stock-opname/route.tsx @@ -138,11 +138,11 @@ const computeIsDifferent = async ({ companyId: number, productId: number }) => { - const totalQty: { [key in keyof typeof Team]: number | null } = { - COUNT1: null, - COUNT2: null, - COUNT3: null, - VERIFICATION: null + const totalQty: { [key in keyof typeof Team]: number | 0 } = { + COUNT1: 0, + COUNT2: 0, + COUNT3: 0, + VERIFICATION: 0 } const searchParams = new URLSearchParams({ @@ -176,47 +176,76 @@ const computeIsDifferent = async ({ if (!product) return const onhandQty = product.onhandQty - const differenceQty = product.differenceQty - const allQty = onhandQty + differenceQty + const allQty = totalQty['COUNT1'] + totalQty['COUNT2'] + totalQty['COUNT3'] + totalQty['VERIFICATION'] + const differenceQty = onhandQty - allQty + // const differenceQty = product.differenceQty + // const allQty = onhandQty + differenceQty const conditional = { verificationCheckAll: verificationCounter > 0 && verificationCounter === stockOpnames.length, - anyCountEqWithOnhand: [totalQty['COUNT1'], totalQty['COUNT2'], totalQty['COUNT3']].includes(onhandQty), + // anyCountEqWithOnhand: [totalQty['COUNT1'], totalQty['COUNT2'], totalQty['COUNT3']].includes(onhandQty), + anyCountEqWithOnhand: totalQty['COUNT1'] === onhandQty || totalQty['COUNT2'] === onhandQty || totalQty['COUNT1'] === 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'], } - isDifferent = !( + // isDifferent = !( + // conditional.verificationCheckAll || + // conditional.anyCountEqWithOnhand || + // conditional.anyCountEqWithAllQty || + // conditional.count1EqWithCount2 || + // conditional.count1EqWithCount3 || + // conditional.count2EqWithCount3 + // ) + if ( conditional.verificationCheckAll || conditional.anyCountEqWithOnhand || - conditional.anyCountEqWithAllQty || conditional.count1EqWithCount2 || conditional.count1EqWithCount3 || conditional.count2EqWithCount3 - ) + ) { + isDifferent = false; + } else { + isDifferent = true; + } for (const opname of stockOpnames) { let { COUNT1, COUNT2, COUNT3, VERIFICATION } = opname const detailCondition = { verificationCheckAll: _.isNumber(VERIFICATION.quantity), + anyCountEqWithOnhand: totalQty['COUNT1'] === onhandQty || totalQty['COUNT2'] === onhandQty || totalQty['COUNT1'] === onhandQty , count1EqWithCount2: COUNT1.quantity === COUNT2.quantity, count1EqWithCount3: COUNT1.quantity === COUNT3.quantity, - count2EqWithCount3: COUNT2.quantity === COUNT3.quantity, + count2EqWithCount3: COUNT2.quantity === COUNT3.quantity && (COUNT2.quantity === 0 && COUNT3.quantity === 0), } - isDifferent = !( + if ( detailCondition.verificationCheckAll || + detailCondition.anyCountEqWithOnhand || detailCondition.count1EqWithCount2 || detailCondition.count1EqWithCount3 || detailCondition.count2EqWithCount3 - ) - - if (isDifferent) break + ) { + isDifferent = false; + } else { + isDifferent = true; + break; + } + console.log('Is Different2222:', isDifferent); + console.log('Conditions:', detailCondition); } + console.log('----------------------------------BATAS SUCI ATAS------------------------------'); + console.log('Total Quantity:', totalQty); + console.log('Onhand Quantity:', onhandQty); + console.log('Difference Quantity:', differenceQty); + console.log('Conditions:', conditional); + console.log('Is Different tambah data:', isDifferent); + console.log('----------------------------------BATAS SUCI BAWAH------------------------------'); + await prisma.product.update({ where: { id: product.id }, data: { isDifferent } |
