From a711c3d7f3a41bb5ac20485723a0f629fbfde1b7 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Wed, 3 Jul 2024 17:48:31 +0700 Subject: update code logic --- .../[productId]/compute-different/route.tsx | 93 +++++++++++++++------- 1 file changed, 64 insertions(+), 29 deletions(-) (limited to 'src/app/api/company') diff --git a/src/app/api/company/[companyId]/product/[productId]/compute-different/route.tsx b/src/app/api/company/[companyId]/product/[productId]/compute-different/route.tsx index ff9cd74..f2e8c3d 100644 --- a/src/app/api/company/[companyId]/product/[productId]/compute-different/route.tsx +++ b/src/app/api/company/[companyId]/product/[productId]/compute-different/route.tsx @@ -9,11 +9,11 @@ type PostParams = { params: { companyId: string, productId: string } } const SELF_HOST = process.env.SELF_HOST as string export async function POST(request: NextRequest, { params }: PostParams) { - 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({ @@ -22,7 +22,9 @@ export async function POST(request: NextRequest, { params }: PostParams) { }) const stockOpnamesFetch = await fetch(`${SELF_HOST}/api/stock-opname/location?${searchParams}`) + console.log("stockOpnamesFetch",stockOpnamesFetch) const stockOpnames: StockOpnameLocationRes[] = await stockOpnamesFetch.json() + console.log("stockOpnames",stockOpnames) let isDifferent: boolean = false let verificationCounter: number = 0 @@ -35,10 +37,11 @@ export async function POST(request: NextRequest, { params }: PostParams) { if (totalQty['COUNT3'] === null && _.isNumber(COUNT3.quantity)) totalQty['COUNT3'] = 0 if (totalQty['VERIFICATION'] === null && _.isNumber(VERIFICATION.quantity)) totalQty['VERIFICATION'] = 0 - if (_.isNumber(totalQty['COUNT1']) && _.isNumber(COUNT1.quantity)) totalQty['COUNT1'] += COUNT1.quantity - if (_.isNumber(totalQty['COUNT2']) && _.isNumber(COUNT2.quantity)) totalQty['COUNT2'] += COUNT2.quantity - 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)) totalQty['COUNT1'] = (totalQty['COUNT1'] || 0) + COUNT1.quantity; + if (_.isNumber(COUNT2.quantity)) totalQty['COUNT2'] = (totalQty['COUNT2'] || 0) + COUNT2.quantity; + if (_.isNumber(COUNT3.quantity)) totalQty['COUNT3'] = (totalQty['COUNT3'] || 0) + COUNT3.quantity; + if (_.isNumber(VERIFICATION.quantity)) totalQty['VERIFICATION'] = (totalQty['VERIFICATION'] || 0) + VERIFICATION.quantity; + if (_.isNumber(VERIFICATION.quantity)) verificationCounter++ } @@ -47,46 +50,76 @@ export async function POST(request: NextRequest, { params }: PostParams) { if (!product) return const onhandQty = product.onhandQty - const differenceQty = product.differenceQty - const allQty = onhandQty + differenceQty + // const differenceQty = product.differenceQty + const allQty = totalQty['COUNT1'] + totalQty['COUNT2'] + totalQty['COUNT3'] + totalQty['VERIFICATION'] + const differenceQty = onhandQty - allQty + // 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 = !( + count1EqWithCount2: totalQty['COUNT1'] !== 0 && totalQty['COUNT2'] !== 0 && totalQty['COUNT1'] === totalQty['COUNT2'], + count1EqWithCount3: totalQty['COUNT1'] !== 0 && totalQty['COUNT3'] !== 0 && totalQty['COUNT1'] === totalQty['COUNT3'], + count2EqWithCount3: totalQty['COUNT2'] !== 0 && totalQty['COUNT3'] !== 0 && totalQty['COUNT2'] === totalQty['COUNT3'], + }; + + // 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 - + 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, - } - - isDifferent = !( + count2EqWithCount3: COUNT2.quantity === COUNT3.quantity && (COUNT2.quantity === 0 && COUNT3.quantity === 0), + }; + + if ( detailCondition.verificationCheckAll || + detailCondition.anyCountEqWithOnhand || detailCondition.count1EqWithCount2 || detailCondition.count1EqWithCount3 || detailCondition.count2EqWithCount3 - ) - - if (isDifferent) break + ) { + isDifferent = false; + } else { + isDifferent = true; + break; + } + // console.log('opname:', opname); + // 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:', isDifferent); + // console.log('----------------------------------BATAS SUCI BAWAH------------------------------'); + const payload = { where: { id: product.id }, @@ -96,4 +129,6 @@ export async function POST(request: NextRequest, { params }: PostParams) { await prisma.product.update(payload) return NextResponse.json(payload) + + } \ No newline at end of file -- cgit v1.2.3 From 9a80c0a767c6a35a489b9d45654ae60f7ddc6794 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Thu, 4 Jul 2024 11:53:01 +0700 Subject: update stock opname logic --- .../[productId]/compute-different/route.tsx | 34 ++++++++++++---------- 1 file changed, 19 insertions(+), 15 deletions(-) (limited to 'src/app/api/company') diff --git a/src/app/api/company/[companyId]/product/[productId]/compute-different/route.tsx b/src/app/api/company/[companyId]/product/[productId]/compute-different/route.tsx index f2e8c3d..cf76ac3 100644 --- a/src/app/api/company/[companyId]/product/[productId]/compute-different/route.tsx +++ b/src/app/api/company/[companyId]/product/[productId]/compute-different/route.tsx @@ -54,13 +54,16 @@ export async function POST(request: NextRequest, { params }: PostParams) { const allQty = totalQty['COUNT1'] + totalQty['COUNT2'] + totalQty['COUNT3'] + totalQty['VERIFICATION'] const differenceQty = onhandQty - allQty // const allQty = onhandQty + differenceQty + const zeroCount1: boolean = totalQty['COUNT1'] === 0; + const zeroCount2: boolean = totalQty['COUNT2'] === 0; + const zeroCount3: boolean = totalQty['COUNT3'] === 0; const conditional = { verificationCheckAll: verificationCounter > 0 && verificationCounter === stockOpnames.length, // anyCountEqWithOnhand: [totalQty['COUNT1'], totalQty['COUNT2'], totalQty['COUNT3']].includes(onhandQty), - anyCountEqWithOnhand: totalQty['COUNT1'] === onhandQty || totalQty['COUNT2'] === onhandQty || totalQty['COUNT1'] === onhandQty , + anyCountEqWithOnhand: (totalQty['COUNT1'] === onhandQty && zeroCount2 && zeroCount3) || (totalQty['COUNT2'] === onhandQty && zeroCount3) || totalQty['COUNT3'] === onhandQty , anyCountEqWithAllQty: [totalQty['COUNT1'], totalQty['COUNT2'], totalQty['COUNT3']].includes(allQty), - count1EqWithCount2: totalQty['COUNT1'] !== 0 && totalQty['COUNT2'] !== 0 && totalQty['COUNT1'] === totalQty['COUNT2'], + count1EqWithCount2: totalQty['COUNT1'] !== 0 && totalQty['COUNT2'] !== 0 && totalQty['COUNT1'] === totalQty['COUNT2'] && totalQty['COUNT3'] === null && totalQty['COUNT1'] !== onhandQty, count1EqWithCount3: totalQty['COUNT1'] !== 0 && totalQty['COUNT3'] !== 0 && totalQty['COUNT1'] === totalQty['COUNT3'], count2EqWithCount3: totalQty['COUNT2'] !== 0 && totalQty['COUNT3'] !== 0 && totalQty['COUNT2'] === totalQty['COUNT3'], }; @@ -90,10 +93,11 @@ export async function POST(request: NextRequest, { params }: PostParams) { const detailCondition = { verificationCheckAll: _.isNumber(VERIFICATION.quantity), - anyCountEqWithOnhand: totalQty['COUNT1'] === onhandQty || totalQty['COUNT2'] === onhandQty || totalQty['COUNT1'] === onhandQty , - count1EqWithCount2: COUNT1.quantity === COUNT2.quantity, + anyCountEqWithOnhand: (totalQty['COUNT1'] === onhandQty && zeroCount2 && zeroCount3) || (totalQty['COUNT2'] === onhandQty && zeroCount3) || totalQty['COUNT3'] === onhandQty , + count1EqWithCount2: totalQty['COUNT3'] === 0 && COUNT1.quantity === COUNT2.quantity && totalQty['COUNT1'] !== onhandQty, count1EqWithCount3: COUNT1.quantity === COUNT3.quantity, count2EqWithCount3: COUNT2.quantity === COUNT3.quantity && (COUNT2.quantity === 0 && COUNT3.quantity === 0), + // count3EqWithCount1_2: (COUNT3.quantity !== COUNT1.quantity) && (COUNT3.quantity !== COUNT2.quantity) && (COUNT1.quantity === COUNT2.quantity) && (COUNT3.quantity !== onhandQty) }; if ( @@ -101,24 +105,24 @@ export async function POST(request: NextRequest, { params }: PostParams) { detailCondition.anyCountEqWithOnhand || detailCondition.count1EqWithCount2 || detailCondition.count1EqWithCount3 || - detailCondition.count2EqWithCount3 + detailCondition.count2EqWithCount3 ) { isDifferent = false; } else { isDifferent = true; break; } - // console.log('opname:', opname); - // console.log('Is Different2222:', isDifferent); - // console.log('Conditions:', detailCondition); + console.log('----------------------------------BATAS SUCI ATAS RECOMPUTE------------------------------'); + console.log('opname:', opname); + 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:', isDifferent); - // console.log('----------------------------------BATAS SUCI BAWAH------------------------------'); + console.log('Total Quantity:', totalQty); + console.log('Onhand Quantity:', onhandQty); + console.log('Difference Quantity:', differenceQty); + console.log('Conditions:', conditional); + console.log('Is Different:', isDifferent); + console.log('----------------------------------BATAS SUCI BAWAH RECOMPUTE------------------------------'); const payload = { -- cgit v1.2.3 From d0c00e30f3f850f8452397db05f41e0c0ecef3f9 Mon Sep 17 00:00:00 2001 From: Imanuel Marinao Date: Thu, 4 Jul 2024 13:40:28 +0700 Subject: update stock opname --- .../[productId]/compute-different/route.tsx | 142 ++++++++------------- 1 file changed, 55 insertions(+), 87 deletions(-) (limited to 'src/app/api/company') diff --git a/src/app/api/company/[companyId]/product/[productId]/compute-different/route.tsx b/src/app/api/company/[companyId]/product/[productId]/compute-different/route.tsx index cf76ac3..c533392 100644 --- a/src/app/api/company/[companyId]/product/[productId]/compute-different/route.tsx +++ b/src/app/api/company/[companyId]/product/[productId]/compute-different/route.tsx @@ -1,12 +1,12 @@ -import { StockOpnameLocationRes } from "@/common/types/stockOpname" -import { NextRequest, NextResponse } from "next/server" -import { prisma } from "prisma/client" -import { Team } from "prisma/generated/client" -import _ from "lodash" +import { StockOpnameLocationRes } from "@/common/types/stockOpname"; +import { NextRequest, NextResponse } from "next/server"; +import { prisma } from "prisma/client"; +import { Team } from "prisma/generated/client"; +import _ from "lodash"; -type PostParams = { params: { companyId: string, productId: string } } +type PostParams = { params: { companyId: string; productId: string } }; -const SELF_HOST = process.env.SELF_HOST as string +const SELF_HOST = process.env.SELF_HOST as string; export async function POST(request: NextRequest, { params }: PostParams) { const totalQty: { [key in keyof typeof Team]: number | 0 } = { @@ -14,75 +14,61 @@ export async function POST(request: NextRequest, { params }: PostParams) { COUNT2: 0, COUNT3: 0, VERIFICATION: 0, - } + }; const searchParams = new URLSearchParams({ companyId: params.companyId.toString(), - productId: params.productId.toString() - }) + productId: params.productId.toString(), + }); - const stockOpnamesFetch = await fetch(`${SELF_HOST}/api/stock-opname/location?${searchParams}`) - console.log("stockOpnamesFetch",stockOpnamesFetch) - const stockOpnames: StockOpnameLocationRes[] = await stockOpnamesFetch.json() - console.log("stockOpnames",stockOpnames) + const stockOpnamesFetch = await fetch(`${SELF_HOST}/api/stock-opname/location?${searchParams}`); + console.log("stockOpnamesFetch", stockOpnamesFetch); + const stockOpnames: StockOpnameLocationRes[] = await stockOpnamesFetch.json(); + console.log("stockOpnames", stockOpnames); - let isDifferent: boolean = false - let verificationCounter: number = 0 + let isDifferent: boolean = false; + let verificationCounter: number = 0; for (const opname of stockOpnames) { - let { COUNT1, COUNT2, COUNT3, VERIFICATION } = opname - - if (totalQty['COUNT1'] === null && _.isNumber(COUNT1.quantity)) totalQty['COUNT1'] = 0 - if (totalQty['COUNT2'] === null && _.isNumber(COUNT2.quantity)) totalQty['COUNT2'] = 0 - if (totalQty['COUNT3'] === null && _.isNumber(COUNT3.quantity)) totalQty['COUNT3'] = 0 - if (totalQty['VERIFICATION'] === null && _.isNumber(VERIFICATION.quantity)) totalQty['VERIFICATION'] = 0 + let { COUNT1, COUNT2, COUNT3, VERIFICATION } = opname; - if (_.isNumber(COUNT1.quantity)) totalQty['COUNT1'] = (totalQty['COUNT1'] || 0) + COUNT1.quantity; - if (_.isNumber(COUNT2.quantity)) totalQty['COUNT2'] = (totalQty['COUNT2'] || 0) + COUNT2.quantity; - if (_.isNumber(COUNT3.quantity)) totalQty['COUNT3'] = (totalQty['COUNT3'] || 0) + COUNT3.quantity; - if (_.isNumber(VERIFICATION.quantity)) totalQty['VERIFICATION'] = (totalQty['VERIFICATION'] || 0) + VERIFICATION.quantity; + if (totalQty["COUNT1"] === null && _.isNumber(COUNT1.quantity)) totalQty["COUNT1"] = 0; + if (totalQty["COUNT2"] === null && _.isNumber(COUNT2.quantity)) totalQty["COUNT2"] = 0; + if (totalQty["COUNT3"] === null && _.isNumber(COUNT3.quantity)) totalQty["COUNT3"] = 0; + if (totalQty["VERIFICATION"] === null && _.isNumber(VERIFICATION.quantity)) totalQty["VERIFICATION"] = 0; + if (_.isNumber(COUNT1.quantity)) totalQty["COUNT1"] = (totalQty["COUNT1"] || 0) + COUNT1.quantity; + if (_.isNumber(COUNT2.quantity)) totalQty["COUNT2"] = (totalQty["COUNT2"] || 0) + COUNT2.quantity; + if (_.isNumber(COUNT3.quantity)) totalQty["COUNT3"] = (totalQty["COUNT3"] || 0) + COUNT3.quantity; + if (_.isNumber(VERIFICATION.quantity)) totalQty["VERIFICATION"] = (totalQty["VERIFICATION"] || 0) + VERIFICATION.quantity; - if (_.isNumber(VERIFICATION.quantity)) verificationCounter++ + if (_.isNumber(VERIFICATION.quantity)) verificationCounter++; } - const product = await prisma.product.findFirst({ where: { id: parseInt(params.productId) } }) - if (!product) return + const product = await prisma.product.findFirst({ where: { id: parseInt(params.productId) } }); + if (!product) return; - const onhandQty = product.onhandQty - // const differenceQty = product.differenceQty - const allQty = totalQty['COUNT1'] + totalQty['COUNT2'] + totalQty['COUNT3'] + totalQty['VERIFICATION'] - const differenceQty = onhandQty - allQty + const onhandQty = product.onhandQty; + // const differenceQty = product.differenceQty + const allQty = totalQty["COUNT1"] + totalQty["COUNT2"] + totalQty["COUNT3"] + totalQty["VERIFICATION"]; + const differenceQty = onhandQty - allQty; // const allQty = onhandQty + differenceQty - const zeroCount1: boolean = totalQty['COUNT1'] === 0; - const zeroCount2: boolean = totalQty['COUNT2'] === 0; - const zeroCount3: boolean = totalQty['COUNT3'] === 0; + const zeroCount1: boolean = totalQty["COUNT1"] === 0; + const zeroCount2: boolean = totalQty["COUNT2"] === 0; + const zeroCount3: boolean = totalQty["COUNT3"] === 0; const conditional = { verificationCheckAll: verificationCounter > 0 && verificationCounter === stockOpnames.length, // anyCountEqWithOnhand: [totalQty['COUNT1'], totalQty['COUNT2'], totalQty['COUNT3']].includes(onhandQty), - anyCountEqWithOnhand: (totalQty['COUNT1'] === onhandQty && zeroCount2 && zeroCount3) || (totalQty['COUNT2'] === onhandQty && zeroCount3) || totalQty['COUNT3'] === onhandQty , - anyCountEqWithAllQty: [totalQty['COUNT1'], totalQty['COUNT2'], totalQty['COUNT3']].includes(allQty), - count1EqWithCount2: totalQty['COUNT1'] !== 0 && totalQty['COUNT2'] !== 0 && totalQty['COUNT1'] === totalQty['COUNT2'] && totalQty['COUNT3'] === null && totalQty['COUNT1'] !== onhandQty, - count1EqWithCount3: totalQty['COUNT1'] !== 0 && totalQty['COUNT3'] !== 0 && totalQty['COUNT1'] === totalQty['COUNT3'], - count2EqWithCount3: totalQty['COUNT2'] !== 0 && totalQty['COUNT3'] !== 0 && totalQty['COUNT2'] === totalQty['COUNT3'], + // anyCountEqWithOnhand: (totalQty["COUNT1"] === onhandQty && zeroCount2 && zeroCount3) || (totalQty["COUNT2"] === onhandQty && zeroCount3) || totalQty["COUNT3"] === onhandQty, + anyCountEqWithOnhand: totalQty["COUNT1"] === onhandQty || totalQty["COUNT2"] === onhandQty || totalQty["COUNT1"] === onhandQty, + anyCountEqWithAllQty: [totalQty["COUNT1"], totalQty["COUNT2"], totalQty["COUNT3"]].includes(allQty), + count1EqWithCount2: totalQty["COUNT1"] !== 0 && totalQty["COUNT2"] !== 0 && totalQty["COUNT1"] === totalQty["COUNT2"] && totalQty["COUNT3"] === null && totalQty["COUNT1"] !== onhandQty, + count1EqWithCount3: totalQty["COUNT1"] !== 0 && totalQty["COUNT3"] !== 0 && totalQty["COUNT1"] === totalQty["COUNT3"], + count2EqWithCount3: totalQty["COUNT2"] !== 0 && totalQty["COUNT3"] !== 0 && totalQty["COUNT2"] === totalQty["COUNT3"], }; - - // isDifferent = !( - // conditional.verificationCheckAll || - // conditional.anyCountEqWithOnhand || - // conditional.anyCountEqWithAllQty || - // conditional.count1EqWithCount2 || - // conditional.count1EqWithCount3 || - // conditional.count2EqWithCount3 - // ); - if ( - conditional.verificationCheckAll || - conditional.anyCountEqWithOnhand || - conditional.count1EqWithCount2 || - conditional.count1EqWithCount3 || - conditional.count2EqWithCount3 - ) { + + if (conditional.verificationCheckAll || conditional.anyCountEqWithOnhand || conditional.count1EqWithCount2 || conditional.count1EqWithCount3 || conditional.count2EqWithCount3) { isDifferent = false; } else { isDifferent = true; @@ -90,49 +76,31 @@ export async function POST(request: NextRequest, { params }: PostParams) { for (const opname of stockOpnames) { let { COUNT1, COUNT2, COUNT3, VERIFICATION } = opname; - + const detailCondition = { verificationCheckAll: _.isNumber(VERIFICATION.quantity), - anyCountEqWithOnhand: (totalQty['COUNT1'] === onhandQty && zeroCount2 && zeroCount3) || (totalQty['COUNT2'] === onhandQty && zeroCount3) || totalQty['COUNT3'] === onhandQty , - count1EqWithCount2: totalQty['COUNT3'] === 0 && COUNT1.quantity === COUNT2.quantity && totalQty['COUNT1'] !== onhandQty, + // anyCountEqWithOnhand: (totalQty["COUNT1"] === onhandQty && zeroCount2 && zeroCount3) || (totalQty["COUNT2"] === onhandQty && zeroCount3) || totalQty["COUNT3"] === onhandQty, + anyCountEqWithOnhand: totalQty["COUNT1"] === onhandQty || totalQty["COUNT2"] === onhandQty || totalQty["COUNT1"] === onhandQty, + count1EqWithCount2: totalQty["COUNT3"] === 0 && COUNT1.quantity === COUNT2.quantity && totalQty["COUNT1"] !== onhandQty, count1EqWithCount3: COUNT1.quantity === COUNT3.quantity, - count2EqWithCount3: COUNT2.quantity === COUNT3.quantity && (COUNT2.quantity === 0 && COUNT3.quantity === 0), + count2EqWithCount3: COUNT2.quantity === COUNT3.quantity && COUNT2.quantity !== 0 && COUNT3.quantity !== 0, // count3EqWithCount1_2: (COUNT3.quantity !== COUNT1.quantity) && (COUNT3.quantity !== COUNT2.quantity) && (COUNT1.quantity === COUNT2.quantity) && (COUNT3.quantity !== onhandQty) }; - - if ( - detailCondition.verificationCheckAll || - detailCondition.anyCountEqWithOnhand || - detailCondition.count1EqWithCount2 || - detailCondition.count1EqWithCount3 || - detailCondition.count2EqWithCount3 - ) { + + if (detailCondition.verificationCheckAll || detailCondition.anyCountEqWithOnhand || detailCondition.count1EqWithCount2 || detailCondition.count1EqWithCount3 || detailCondition.count2EqWithCount3) { isDifferent = false; } else { isDifferent = true; break; } - console.log('----------------------------------BATAS SUCI ATAS RECOMPUTE------------------------------'); - console.log('opname:', opname); - console.log('Is Different2222:', isDifferent); - console.log('Conditions:', detailCondition); } - console.log('Total Quantity:', totalQty); - console.log('Onhand Quantity:', onhandQty); - console.log('Difference Quantity:', differenceQty); - console.log('Conditions:', conditional); - console.log('Is Different:', isDifferent); - console.log('----------------------------------BATAS SUCI BAWAH RECOMPUTE------------------------------'); - const payload = { where: { id: product.id }, - data: { isDifferent } - } - - await prisma.product.update(payload) + data: { isDifferent }, + }; - return NextResponse.json(payload) + await prisma.product.update(payload); - -} \ No newline at end of file + return NextResponse.json(payload); +} -- cgit v1.2.3 From a50bc458c9f9dfff8fa9902afa51769e8a282c0c Mon Sep 17 00:00:00 2001 From: Imanuel Marinao Date: Thu, 4 Jul 2024 14:33:23 +0700 Subject: update stock opname --- .../[productId]/compute-different/route.tsx | 26 +++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'src/app/api/company') diff --git a/src/app/api/company/[companyId]/product/[productId]/compute-different/route.tsx b/src/app/api/company/[companyId]/product/[productId]/compute-different/route.tsx index c533392..7bf44cf 100644 --- a/src/app/api/company/[companyId]/product/[productId]/compute-different/route.tsx +++ b/src/app/api/company/[companyId]/product/[productId]/compute-different/route.tsx @@ -60,14 +60,21 @@ export async function POST(request: NextRequest, { params }: PostParams) { const conditional = { verificationCheckAll: verificationCounter > 0 && verificationCounter === stockOpnames.length, // anyCountEqWithOnhand: [totalQty['COUNT1'], totalQty['COUNT2'], totalQty['COUNT3']].includes(onhandQty), - // anyCountEqWithOnhand: (totalQty["COUNT1"] === onhandQty && zeroCount2 && zeroCount3) || (totalQty["COUNT2"] === onhandQty && zeroCount3) || totalQty["COUNT3"] === onhandQty, - anyCountEqWithOnhand: totalQty["COUNT1"] === onhandQty || totalQty["COUNT2"] === onhandQty || totalQty["COUNT1"] === onhandQty, + anyCountEqWithOnhand: (totalQty["COUNT1"] === onhandQty && zeroCount2 && zeroCount3) || (totalQty["COUNT2"] === onhandQty && zeroCount3) || totalQty["COUNT3"] === onhandQty, anyCountEqWithAllQty: [totalQty["COUNT1"], totalQty["COUNT2"], totalQty["COUNT3"]].includes(allQty), count1EqWithCount2: totalQty["COUNT1"] !== 0 && totalQty["COUNT2"] !== 0 && totalQty["COUNT1"] === totalQty["COUNT2"] && totalQty["COUNT3"] === null && totalQty["COUNT1"] !== onhandQty, count1EqWithCount3: totalQty["COUNT1"] !== 0 && totalQty["COUNT3"] !== 0 && totalQty["COUNT1"] === totalQty["COUNT3"], count2EqWithCount3: totalQty["COUNT2"] !== 0 && totalQty["COUNT3"] !== 0 && totalQty["COUNT2"] === totalQty["COUNT3"], }; + // isDifferent = !( + // conditional.verificationCheckAll || + // conditional.anyCountEqWithOnhand || + // conditional.anyCountEqWithAllQty || + // conditional.count1EqWithCount2 || + // conditional.count1EqWithCount3 || + // conditional.count2EqWithCount3 + // ); if (conditional.verificationCheckAll || conditional.anyCountEqWithOnhand || conditional.count1EqWithCount2 || conditional.count1EqWithCount3 || conditional.count2EqWithCount3) { isDifferent = false; } else { @@ -79,11 +86,10 @@ export async function POST(request: NextRequest, { params }: PostParams) { const detailCondition = { verificationCheckAll: _.isNumber(VERIFICATION.quantity), - // anyCountEqWithOnhand: (totalQty["COUNT1"] === onhandQty && zeroCount2 && zeroCount3) || (totalQty["COUNT2"] === onhandQty && zeroCount3) || totalQty["COUNT3"] === onhandQty, - anyCountEqWithOnhand: totalQty["COUNT1"] === onhandQty || totalQty["COUNT2"] === onhandQty || totalQty["COUNT1"] === onhandQty, + anyCountEqWithOnhand: (totalQty["COUNT1"] === onhandQty && zeroCount2 && zeroCount3) || (totalQty["COUNT2"] === onhandQty && zeroCount3) || totalQty["COUNT3"] === onhandQty, count1EqWithCount2: totalQty["COUNT3"] === 0 && COUNT1.quantity === COUNT2.quantity && totalQty["COUNT1"] !== onhandQty, count1EqWithCount3: COUNT1.quantity === COUNT3.quantity, - count2EqWithCount3: COUNT2.quantity === COUNT3.quantity && COUNT2.quantity !== 0 && COUNT3.quantity !== 0, + count2EqWithCount3: totalQty["COUNT2"] !== null && totalQty["COUNT3"] !== null && totalQty["COUNT2"] === totalQty["COUNT3"], // count3EqWithCount1_2: (COUNT3.quantity !== COUNT1.quantity) && (COUNT3.quantity !== COUNT2.quantity) && (COUNT1.quantity === COUNT2.quantity) && (COUNT3.quantity !== onhandQty) }; @@ -93,7 +99,17 @@ export async function POST(request: NextRequest, { params }: PostParams) { isDifferent = true; break; } + console.log("----------------------------------BATAS SUCI ATAS RECOMPUTE------------------------------"); + console.log("opname:", opname); + console.log("Is Different2222:", isDifferent); + console.log("Conditions:", detailCondition); } + console.log("Total Quantity:", totalQty); + console.log("Onhand Quantity:", onhandQty); + console.log("Difference Quantity:", differenceQty); + console.log("Conditions:", conditional); + console.log("Is Different:", isDifferent); + console.log("----------------------------------BATAS SUCI BAWAH RECOMPUTE------------------------------"); const payload = { where: { id: product.id }, -- cgit v1.2.3 From bb1cd2048fd3f4d93479509a561b35e3b0fa1f2d Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Thu, 4 Jul 2024 15:49:34 +0700 Subject: delete console log --- .../[productId]/compute-different/route.tsx | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) (limited to 'src/app/api/company') diff --git a/src/app/api/company/[companyId]/product/[productId]/compute-different/route.tsx b/src/app/api/company/[companyId]/product/[productId]/compute-different/route.tsx index 7bf44cf..acfb413 100644 --- a/src/app/api/company/[companyId]/product/[productId]/compute-different/route.tsx +++ b/src/app/api/company/[companyId]/product/[productId]/compute-different/route.tsx @@ -22,9 +22,7 @@ export async function POST(request: NextRequest, { params }: PostParams) { }); const stockOpnamesFetch = await fetch(`${SELF_HOST}/api/stock-opname/location?${searchParams}`); - console.log("stockOpnamesFetch", stockOpnamesFetch); const stockOpnames: StockOpnameLocationRes[] = await stockOpnamesFetch.json(); - console.log("stockOpnames", stockOpnames); let isDifferent: boolean = false; let verificationCounter: number = 0; @@ -67,14 +65,6 @@ export async function POST(request: NextRequest, { params }: PostParams) { count2EqWithCount3: totalQty["COUNT2"] !== 0 && totalQty["COUNT3"] !== 0 && totalQty["COUNT2"] === totalQty["COUNT3"], }; - // isDifferent = !( - // conditional.verificationCheckAll || - // conditional.anyCountEqWithOnhand || - // conditional.anyCountEqWithAllQty || - // conditional.count1EqWithCount2 || - // conditional.count1EqWithCount3 || - // conditional.count2EqWithCount3 - // ); if (conditional.verificationCheckAll || conditional.anyCountEqWithOnhand || conditional.count1EqWithCount2 || conditional.count1EqWithCount3 || conditional.count2EqWithCount3) { isDifferent = false; } else { @@ -99,17 +89,9 @@ export async function POST(request: NextRequest, { params }: PostParams) { isDifferent = true; break; } - console.log("----------------------------------BATAS SUCI ATAS RECOMPUTE------------------------------"); - console.log("opname:", opname); - console.log("Is Different2222:", isDifferent); - console.log("Conditions:", detailCondition); + } - console.log("Total Quantity:", totalQty); - console.log("Onhand Quantity:", onhandQty); - console.log("Difference Quantity:", differenceQty); - console.log("Conditions:", conditional); - console.log("Is Different:", isDifferent); - console.log("----------------------------------BATAS SUCI BAWAH RECOMPUTE------------------------------"); + const payload = { where: { id: product.id }, -- cgit v1.2.3