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 --- package.json | 1 + .../[productId]/compute-different/route.tsx | 93 +++++++++++++++------- src/app/api/stock-opname/route.tsx | 61 ++++++++++---- src/modules/result/components/Table.tsx | 2 + 4 files changed, 112 insertions(+), 45 deletions(-) diff --git a/package.json b/package.json index 3ed98f1..1b5ef6a 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "bcrypt": "^5.1.1", "clsx": "^2.0.0", "cookies-next": "^4.0.0", + "dotenv": "^16.4.5", "framer-motion": "^10.16.4", "jsonwebtoken": "^9.0.2", "lodash": "^4.17.21", 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 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 } diff --git a/src/modules/result/components/Table.tsx b/src/modules/result/components/Table.tsx index 082f988..94ed5bf 100644 --- a/src/modules/result/components/Table.tsx +++ b/src/modules/result/components/Table.tsx @@ -78,7 +78,9 @@ const Table = () => { const recompute = async (productId: number, companyId: string) => { const response = await fetch(`/api/company/${companyId}/product/${productId}/compute-different`, { method: 'POST' }) + console.log("response",response) const stockOpname = await response.json() + console.log("stockOpname",stockOpname) toast(`Berhasil menghitung ulang status barang, hasilnya ${stockOpname.data.isDifferent ? 'selisih' : 'aman'}`) stockOpnames.refetch() } -- 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 ++++++++++++---------- src/app/api/stock-opname/route.tsx | 11 +++---- src/modules/result/components/MoreMenu.tsx | 17 +++++++++-- src/modules/result/components/Table.tsx | 6 ++-- src/modules/result/index.tsx | 10 ++++--- 5 files changed, 50 insertions(+), 28 deletions(-) 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 = { diff --git a/src/app/api/stock-opname/route.tsx b/src/app/api/stock-opname/route.tsx index 250e70b..9f44158 100644 --- a/src/app/api/stock-opname/route.tsx +++ b/src/app/api/stock-opname/route.tsx @@ -186,7 +186,7 @@ const computeIsDifferent = async ({ // 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'], + count1EqWithCount2: totalQty['COUNT1'] !== null && totalQty['COUNT2'] !== null && totalQty['COUNT1'] === totalQty['COUNT2'] && totalQty['COUNT3'] === null, count1EqWithCount3: totalQty['COUNT1'] !== null && totalQty['COUNT3'] !== null && totalQty['COUNT1'] === totalQty['COUNT3'], count2EqWithCount3: totalQty['COUNT2'] !== null && totalQty['COUNT3'] !== null && totalQty['COUNT2'] === totalQty['COUNT3'], } @@ -216,10 +216,11 @@ const computeIsDifferent = async ({ 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 || totalQty['COUNT2'] === onhandQty || totalQty['COUNT3'] === onhandQty , + count1EqWithCount2: totalQty['COUNT3'] === 0 && COUNT1.quantity === COUNT2.quantity, 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 ( @@ -234,17 +235,17 @@ const computeIsDifferent = async ({ isDifferent = true; break; } + console.log('----------------------------------BATAS SUCI ATAS NEW STOCK ------------------------------'); 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------------------------------'); + console.log('----------------------------------BATAS SUCI BAWAH NEW STOCK------------------------------'); await prisma.product.update({ where: { id: product.id }, diff --git a/src/modules/result/components/MoreMenu.tsx b/src/modules/result/components/MoreMenu.tsx index 03c9786..cd4e8be 100644 --- a/src/modules/result/components/MoreMenu.tsx +++ b/src/modules/result/components/MoreMenu.tsx @@ -1,16 +1,29 @@ "use client"; import { Button, Dropdown, DropdownItem, DropdownMenu, DropdownTrigger, useDisclosure } from '@nextui-org/react' import { MoreVerticalIcon } from 'lucide-react' -import React from 'react' +import React, { useState, useEffect } from 'react' import ImportModal from './ImportModal'; import ProductModal from './ProductModal'; import getClientCredential from '@/common/libs/getClientCredential'; +type Credential = { + team: string; +}; + const MoreMenu = () => { - const credential = getClientCredential() + const [credential, setCredential] = useState(null); const importModal = useDisclosure(); const productModal = useDisclosure(); + useEffect(() => { + const cred = getClientCredential(); + setCredential(cred); + }, []); + + if (!credential || credential.team !== 'VERIFICATION') { + return null; + } + return credential && credential.team == 'VERIFICATION' && ( <> diff --git a/src/modules/result/components/Table.tsx b/src/modules/result/components/Table.tsx index 94ed5bf..fc40932 100644 --- a/src/modules/result/components/Table.tsx +++ b/src/modules/result/components/Table.tsx @@ -99,7 +99,8 @@ const Table = () => {
- + + @@ -109,7 +110,8 @@ const Table = () => { - + + {!isLoading && stockOpnames.data?.result.map((stockOpname: StockOpnameRes['result']) => ( <> diff --git a/src/modules/result/index.tsx b/src/modules/result/index.tsx index cbb2173..095b4db 100644 --- a/src/modules/result/index.tsx +++ b/src/modules/result/index.tsx @@ -1,15 +1,17 @@ import { Spacer } from "@nextui-org/react" import Filter from "./components/Filter" -import styles from "./result.module.css" import Table from "./components/Table" import MoreMenu from "./components/MoreMenu" +import { Suspense } from "react" const Result = () => { return ( <> -
-
Stock Opname Result
- +
+
Stock Opname Result
+ Loading...
}> + +
-- 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 ++++------- src/app/api/stock-opname/route.tsx | 231 +++++++---------- src/modules/result/components/Table.tsx | 278 ++++++++++----------- 3 files changed, 288 insertions(+), 363 deletions(-) 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); +} diff --git a/src/app/api/stock-opname/route.tsx b/src/app/api/stock-opname/route.tsx index 9f44158..1ec79d1 100644 --- a/src/app/api/stock-opname/route.tsx +++ b/src/app/api/stock-opname/route.tsx @@ -2,253 +2,212 @@ import { StockOpnameLocationRes, StockOpnameRequest } from "@/common/types/stock import { Prisma, Team } from "prisma/generated/client"; import { NextRequest, NextResponse } from "next/server"; import { prisma } from "prisma/client"; -import _ from "lodash" +import _ from "lodash"; import getServerCredential from "@/common/libs/getServerCredential"; type Quantity = { - [key in keyof typeof Team]: number | null -} + [key in keyof typeof Team]: number | null; +}; export async function GET(request: NextRequest) { const PAGE_SIZE = 30; - const params = request.nextUrl.searchParams - const companyId = params.get('companyId') - const search = params.get('search') - const page = params.get('page') ?? null - const show = params.get('show') - const intPage = page ? parseInt(page) : 1 + const params = request.nextUrl.searchParams; + const companyId = params.get("companyId"); + const search = params.get("search"); + const page = params.get("page") ?? null; + const show = params.get("show"); + const intPage = page ? parseInt(page) : 1; if (!companyId) { - return NextResponse.json({ error: 'Bad Request. Missing companyId' }, { status: 400 }) + return NextResponse.json({ error: "Bad Request. Missing companyId" }, { status: 400 }); } const where: Prisma.ProductWhereInput = { AND: { stockOpnames: { some: {} }, companyId: parseInt(companyId), - isDifferent: show ? (show == 'diff' ? true : false) : undefined, + isDifferent: show ? (show == "diff" ? true : false) : undefined, OR: [ - { name: { mode: 'insensitive', contains: search ?? '' } }, - { itemCode: { mode: 'insensitive', contains: search ?? '' } }, - { barcode: { mode: 'insensitive', contains: search ?? '' } }, - { stockOpnames: { some: { location: { name: { mode: 'insensitive', contains: search ?? '' } } } } }, - ] - } - } + { name: { mode: "insensitive", contains: search ?? "" } }, + { itemCode: { mode: "insensitive", contains: search ?? "" } }, + { barcode: { mode: "insensitive", contains: search ?? "" } }, + { stockOpnames: { some: { location: { name: { mode: "insensitive", contains: search ?? "" } } } } }, + ], + }, + }; const products = await prisma.product.findMany({ skip: (intPage - 1) * PAGE_SIZE, take: PAGE_SIZE, - where - }) + where, + }); - const productCount = await prisma.product.count({ where }) + const productCount = await prisma.product.count({ where }); const pagination = { page: intPage, totalPage: Math.ceil(productCount / PAGE_SIZE), - } + }; - type ProductWithSum = typeof products[0] & { quantity: Quantity } + type ProductWithSum = (typeof products)[0] & { quantity: Quantity }; - const productsWithSum: ProductWithSum[] = [] + const productsWithSum: ProductWithSum[] = []; for (const product of products) { const quantity = await calculateOpnameQuantity({ productId: product.id, - companyId: parseInt(companyId) - }) - productsWithSum.push({ ...product, quantity }) + companyId: parseInt(companyId), + }); + productsWithSum.push({ ...product, quantity }); } return NextResponse.json({ result: productsWithSum, - ...pagination - }) + ...pagination, + }); } -const calculateOpnameQuantity = async ( - where: { - productId: number, - companyId: number - } -): Promise => { - const quantity: Quantity = { COUNT1: null, COUNT2: null, COUNT3: null, VERIFICATION: null } +const calculateOpnameQuantity = async (where: { productId: number; companyId: number }): Promise => { + const quantity: Quantity = { COUNT1: null, COUNT2: null, COUNT3: null, VERIFICATION: null }; for (const team of Object.values(Team)) { const opnameQty = await prisma.stockOpname.groupBy({ - by: ['productId', 'team'], + by: ["productId", "team"], _sum: { quantity: true }, - where: { team, ...where } - }) - if (opnameQty.length === 0) continue - quantity[team] = opnameQty[0]._sum.quantity + where: { team, ...where }, + }); + if (opnameQty.length === 0) continue; + quantity[team] = opnameQty[0]._sum.quantity; } - return quantity -} + return quantity; +}; export async function POST(request: NextRequest) { - const credential = getServerCredential() + const credential = getServerCredential(); - if (!credential) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }) + if (!credential) return NextResponse.json({ error: "Unauthorized" }, { status: 401 }); - const body: StockOpnameRequest = await request.json() + const body: StockOpnameRequest = await request.json(); - const { companyId, team } = credential + const { companyId, team } = credential; const query = { locationId: body.location, productId: body.product, companyId, - team - } + team, + }; - const stockOpname = await prisma.stockOpname.findFirst({ where: query }) + const stockOpname = await prisma.stockOpname.findFirst({ where: query }); const data = { ...query, userId: credential.id, quantity: body.quantity, - isDifferent: false - } + isDifferent: false, + }; - let newStockOpname = null + let newStockOpname = null; if (!stockOpname) { - newStockOpname = await prisma.stockOpname.create({ data }) + newStockOpname = await prisma.stockOpname.create({ data }); } else { newStockOpname = await prisma.stockOpname.update({ where: { id: stockOpname.id }, - data - }) + data, + }); } - await computeIsDifferent({ productId: body.product, companyId: companyId }) + await computeIsDifferent({ productId: body.product, companyId: companyId }); - return NextResponse.json(newStockOpname) + return NextResponse.json(newStockOpname); } -const SELF_HOST = process.env.SELF_HOST as string +const SELF_HOST = process.env.SELF_HOST as string; -const computeIsDifferent = async ({ - companyId, - productId -}: { - companyId: number, - productId: number -}) => { +const computeIsDifferent = async ({ companyId, productId }: { companyId: number; productId: number }) => { const totalQty: { [key in keyof typeof Team]: number | 0 } = { COUNT1: 0, COUNT2: 0, COUNT3: 0, - VERIFICATION: 0 - } + VERIFICATION: 0, + }; const searchParams = new URLSearchParams({ companyId: companyId.toString(), - productId: productId.toString() - }) + productId: productId.toString(), + }); - const stockOpnamesFetch = await fetch(`${SELF_HOST}/api/stock-opname/location?${searchParams}`) - const stockOpnames: StockOpnameLocationRes[] = await stockOpnamesFetch.json() + const stockOpnamesFetch = await fetch(`${SELF_HOST}/api/stock-opname/location?${searchParams}`); + const stockOpnames: StockOpnameLocationRes[] = await stockOpnamesFetch.json(); - 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 + 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 + 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(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(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(VERIFICATION.quantity)) verificationCounter++ + if (_.isNumber(VERIFICATION.quantity)) verificationCounter++; } - const product = await prisma.product.findFirst({ where: { id: productId } }) - if (!product) return + const product = await prisma.product.findFirst({ where: { id: productId } }); + if (!product) return; - const onhandQty = product.onhandQty - const allQty = totalQty['COUNT1'] + totalQty['COUNT2'] + totalQty['COUNT3'] + totalQty['VERIFICATION'] - const differenceQty = onhandQty - allQty + const onhandQty = product.onhandQty; + 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'] === 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'] && totalQty['COUNT3'] === null, - count1EqWithCount3: totalQty['COUNT1'] !== null && totalQty['COUNT3'] !== null && totalQty['COUNT1'] === totalQty['COUNT3'], - count2EqWithCount3: totalQty['COUNT2'] !== null && totalQty['COUNT3'] !== null && 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 - ) { + 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"] && totalQty["COUNT3"] === null, + count1EqWithCount3: totalQty["COUNT1"] !== null && totalQty["COUNT3"] !== null && totalQty["COUNT1"] === totalQty["COUNT3"], + count2EqWithCount3: totalQty["COUNT2"] !== null && totalQty["COUNT3"] !== null && totalQty["COUNT2"] === totalQty["COUNT3"], + }; + + if (conditional.verificationCheckAll || conditional.anyCountEqWithOnhand || 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['COUNT3'] === onhandQty , - count1EqWithCount2: totalQty['COUNT3'] === 0 && COUNT1.quantity === COUNT2.quantity, + anyCountEqWithOnhand: totalQty["COUNT1"] === onhandQty || totalQty["COUNT2"] === onhandQty || totalQty["COUNT3"] === onhandQty, + count1EqWithCount2: totalQty["COUNT3"] === 0 && COUNT1.quantity === COUNT2.quantity, 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 NEW STOCK ------------------------------'); - 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 tambah data:', isDifferent); - console.log('----------------------------------BATAS SUCI BAWAH NEW STOCK------------------------------'); - await prisma.product.update({ where: { id: product.id }, - data: { isDifferent } - }) -} \ No newline at end of file + data: { isDifferent }, + }); +}; diff --git a/src/modules/result/components/Table.tsx b/src/modules/result/components/Table.tsx index fc40932..19a1e8b 100644 --- a/src/modules/result/components/Table.tsx +++ b/src/modules/result/components/Table.tsx @@ -1,9 +1,9 @@ "use client"; import { useResultStore } from "@/common/stores/useResultStore"; import { StockOpnameRes } from "@/common/types/stockOpname"; -import { Button, Dropdown, DropdownItem, DropdownMenu, DropdownTrigger, Pagination, Skeleton, Spacer, Spinner } from "@nextui-org/react" +import { Button, Dropdown, DropdownItem, DropdownMenu, DropdownTrigger, Pagination, Skeleton, Spacer, Spinner } from "@nextui-org/react"; import { keepPreviousData, useQuery } from "@tanstack/react-query"; -import styles from "./table.module.css" +import styles from "./table.module.css"; import clsxm from "@/common/libs/clsxm"; import DetailRow from "./DetailRow"; import { useDebounce } from "usehooks-ts"; @@ -16,169 +16,173 @@ import toast from "@/common/libs/toast"; import { Product } from "prisma/generated/client"; const Table = () => { - const credential = getClientCredential() + const credential = getClientCredential(); - const { filter: { company, search, show, page }, updateFilter } = useResultStore() - const debouncedSearch = useDebounce(search, 500) + const { + filter: { company, search, show, page }, + updateFilter, + } = useResultStore(); + const debouncedSearch = useDebounce(search, 500); useEffect(() => { - updateFilter('page', 1) - }, [company, debouncedSearch, show, updateFilter]) + updateFilter("page", 1); + }, [company, debouncedSearch, show, updateFilter]); const stockOpnames = useQuery({ - queryKey: ['stockOpnames', company, debouncedSearch, page, show], + queryKey: ["stockOpnames", company, debouncedSearch, page, show], queryFn: async () => { - const searchParams = new URLSearchParams() - if (!company) return null - searchParams.set('companyId', company) + const searchParams = new URLSearchParams(); + if (!company) return null; + searchParams.set("companyId", company); - const showValue = SHOWING_SELECTIONS.find((item) => item.key === show)?.value || '' - searchParams.set('show', showValue); + const showValue = SHOWING_SELECTIONS.find((item) => item.key === show)?.value || ""; + searchParams.set("show", showValue); - if (debouncedSearch) searchParams.set('search', debouncedSearch) + if (debouncedSearch) searchParams.set("search", debouncedSearch); - searchParams.set('page', page.toString()); + searchParams.set("page", page.toString()); - return await fetch(`/api/stock-opname?${searchParams}`) - .then(res => { - window.scrollTo({ top: 0, 'behavior': 'smooth' }) - return res.json() - }) + return await fetch(`/api/stock-opname?${searchParams}`).then((res) => { + window.scrollTo({ top: 0, behavior: "smooth" }); + return res.json(); + }); }, - placeholderData: keepPreviousData - }) + placeholderData: keepPreviousData, + }); - const { filter } = useResultStore() + const { filter } = useResultStore(); - const [exportLoad, setExportLoad] = useState(false) + const [exportLoad, setExportLoad] = useState(false); const exportResult = async () => { - setExportLoad(true) - const response = await fetch(`/api/stock-opname/export?companyId=${filter.company}`) - const buffer = await response.arrayBuffer() - console.log({ type: response.headers.get('type') }); - - const blob = new Blob([buffer], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' }) - const url = window.URL.createObjectURL(blob) - const a = document.createElement('a') - a.href = url - a.download = `export_${moment().format('MM_DD_HH_ss')}.xlsx` - document.body.appendChild(a) - a.click() - document.body.removeChild(a) - setExportLoad(false) - } + setExportLoad(true); + const response = await fetch(`/api/stock-opname/export?companyId=${filter.company}`); + const buffer = await response.arrayBuffer(); + console.log({ type: response.headers.get("type") }); + + const blob = new Blob([buffer], { type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" }); + const url = window.URL.createObjectURL(blob); + const a = document.createElement("a"); + a.href = url; + a.download = `export_${moment().format("MM_DD_HH_ss")}.xlsx`; + document.body.appendChild(a); + a.click(); + document.body.removeChild(a); + setExportLoad(false); + }; const toggleDifferent = async (id: number) => { - const response = await fetch(`/api/product/${id}/toggle-different`, { method: 'POST' }) - const product: Product = await response.json() - toast(`Berhasil mengubah status barang ${product.itemCode} ${product.name} menjadi ${product.isDifferent ? 'selisih' : 'aman'}`, { duration: 10000 }) - stockOpnames.refetch() - } + const response = await fetch(`/api/product/${id}/toggle-different`, { method: "POST" }); + const product: Product = await response.json(); + toast(`Berhasil mengubah status barang ${product.itemCode} ${product.name} menjadi ${product.isDifferent ? "selisih" : "aman"}`, { duration: 10000 }); + stockOpnames.refetch(); + }; const recompute = async (productId: number, companyId: string) => { - const response = await fetch(`/api/company/${companyId}/product/${productId}/compute-different`, { method: 'POST' }) - console.log("response",response) - const stockOpname = await response.json() - console.log("stockOpname",stockOpname) - toast(`Berhasil menghitung ulang status barang, hasilnya ${stockOpname.data.isDifferent ? 'selisih' : 'aman'}`) - stockOpnames.refetch() - } + const response = await fetch(`/api/company/${companyId}/product/${productId}/compute-different`, { method: "POST" }); + console.log("response", response); + const stockOpname = await response.json(); + console.log("stockOpname", stockOpname); + toast(`Berhasil menghitung ulang status barang, hasilnya ${stockOpname.data.isDifferent ? "selisih" : "aman"}`); + stockOpnames.refetch(); + }; - const isLoading = stockOpnames.isLoading || stockOpnames.isRefetching + const isLoading = stockOpnames.isLoading || stockOpnames.isRefetching; - const COL_LENGTH = 9 + const COL_LENGTH = 9; return ( <>
STATUS NAMA PRODUK TIM HITUNG 1ON-HAND QTY GUDANG SELISIH
- - - - - - - - - - - - - + + + + + + + + + + + + + - {!isLoading && stockOpnames.data?.result.map((stockOpname: StockOpnameRes['result']) => ( - <> - - - - - - - - - - - - - - - ))} + {!isLoading && + stockOpnames.data?.result.map((stockOpname: StockOpnameRes["result"]) => ( + <> + + + + + + + + + + + + + + + ))} {!isLoading && stockOpnames.data?.result.length === 0 && ( - + )} @@ -195,19 +199,13 @@ const Table = () => { )}
STATUSNAMA PRODUKTIM HITUNG 1TIM HITUNG 2TIM HITUNG 3TIM VERIFIKASION-HAND QTYGUDANG SELISIH
STATUSNAMA PRODUKTIM HITUNG 1TIM HITUNG 2TIM HITUNG 3TIM VERIFIKASION-HAND QTYGUDANG SELISIH
-
- {stockOpname.isDifferent ? 'Selisih' : 'Aman'} -
-
- {stockOpname.itemCode ? `[${stockOpname.itemCode}] ` : ''} - {stockOpname.name} - {stockOpname.barcode ? ` [${stockOpname.barcode}]` : ''} - - {credential?.team == 'VERIFICATION' && typeof stockOpname.quantity.COUNT1 === 'number' ? stockOpname.quantity.COUNT1 : '-'} - - {credential?.team == 'VERIFICATION' && typeof stockOpname.quantity.COUNT2 === 'number' ? stockOpname.quantity.COUNT2 : '-'} - - {credential?.team == 'VERIFICATION' && typeof stockOpname.quantity.COUNT3 === 'number' ? stockOpname.quantity.COUNT3 : '-'} - - {credential?.team == 'VERIFICATION' && typeof stockOpname.quantity.VERIFICATION === 'number' ? stockOpname.quantity.VERIFICATION : '-'} - - {credential?.team == 'VERIFICATION' ? stockOpname.onhandQty : '-'} - - {credential?.team == 'VERIFICATION' ? stockOpname.differenceQty : '-'} - - {credential?.team == 'VERIFICATION' && ( - - - - - - recompute(stockOpname.id, company)}> - Re-compute - - toggleDifferent(stockOpname.id)}> - Tandai {stockOpname.isDifferent ? 'aman' : 'selisih'} - - - - )} -
+
+ {stockOpname.isDifferent ? "Selisih" : "Aman"} +
+
+ {stockOpname.itemCode ? `[${stockOpname.itemCode}] ` : ""} + {stockOpname.name} + {stockOpname.barcode ? ` [${stockOpname.barcode}]` : ""} + {credential?.team == "VERIFICATION" && typeof stockOpname.quantity.COUNT1 === "number" ? stockOpname.quantity.COUNT1 : "-"}{credential?.team == "VERIFICATION" && typeof stockOpname.quantity.COUNT2 === "number" ? stockOpname.quantity.COUNT2 : "-"}{credential?.team == "VERIFICATION" && typeof stockOpname.quantity.COUNT3 === "number" ? stockOpname.quantity.COUNT3 : "-"}{credential?.team == "VERIFICATION" && typeof stockOpname.quantity.VERIFICATION === "number" ? stockOpname.quantity.VERIFICATION : "-"}{credential?.team == "VERIFICATION" ? stockOpname.onhandQty : "-"}{credential?.team == "VERIFICATION" ? stockOpname.differenceQty : "-"} + {credential?.team == "VERIFICATION" && ( + + + + + + recompute(stockOpname.id, company)}> + Re-compute + + toggleDifferent(stockOpname.id)}> + Tandai {stockOpname.isDifferent ? "aman" : "selisih"} + + + + )} +
Belum ada data untuk ditampilkan + Belum ada data untuk ditampilkan +
-
- updateFilter('page', page)} - className="min-h-[36px] m-0 p-0" - /> + updateFilter("page", page)} className="min-h-[36px] m-0 p-0" /> - ) -} + ); +}; -export default Table \ No newline at end of file +export default Table; -- 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 +++++++++++++++++----- src/app/api/stock-opname/route.tsx | 20 ++++++++++++++++- 2 files changed, 40 insertions(+), 6 deletions(-) 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 }, diff --git a/src/app/api/stock-opname/route.tsx b/src/app/api/stock-opname/route.tsx index 1ec79d1..e0a5ee7 100644 --- a/src/app/api/stock-opname/route.tsx +++ b/src/app/api/stock-opname/route.tsx @@ -180,6 +180,14 @@ const computeIsDifferent = async ({ companyId, productId }: { companyId: number; count2EqWithCount3: totalQty["COUNT2"] !== null && totalQty["COUNT3"] !== null && 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 { @@ -194,7 +202,7 @@ const computeIsDifferent = async ({ companyId, productId }: { companyId: number; anyCountEqWithOnhand: totalQty["COUNT1"] === onhandQty || totalQty["COUNT2"] === onhandQty || totalQty["COUNT3"] === onhandQty, count1EqWithCount2: totalQty["COUNT3"] === 0 && COUNT1.quantity === COUNT2.quantity, 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) }; @@ -204,8 +212,18 @@ const computeIsDifferent = async ({ companyId, productId }: { companyId: number; isDifferent = true; break; } + console.log("----------------------------------BATAS SUCI ATAS NEW STOCK ------------------------------"); + 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 tambah data:", isDifferent); + console.log("----------------------------------BATAS SUCI BAWAH NEW STOCK------------------------------"); + await prisma.product.update({ where: { id: product.id }, data: { isDifferent }, -- cgit v1.2.3 From 67d283bb61d7167e7c6460293f3c5669eacf3b63 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Thu, 4 Jul 2024 15:45:23 +0700 Subject: delete console log --- src/app/api/stock-opname/route.tsx | 19 +------------------ src/modules/result/components/Table.tsx | 3 --- 2 files changed, 1 insertion(+), 21 deletions(-) diff --git a/src/app/api/stock-opname/route.tsx b/src/app/api/stock-opname/route.tsx index e0a5ee7..69caca0 100644 --- a/src/app/api/stock-opname/route.tsx +++ b/src/app/api/stock-opname/route.tsx @@ -180,14 +180,6 @@ const computeIsDifferent = async ({ companyId, productId }: { companyId: number; count2EqWithCount3: totalQty["COUNT2"] !== null && totalQty["COUNT3"] !== null && 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 { @@ -212,17 +204,8 @@ const computeIsDifferent = async ({ companyId, productId }: { companyId: number; isDifferent = true; break; } - console.log("----------------------------------BATAS SUCI ATAS NEW STOCK ------------------------------"); - 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 tambah data:", isDifferent); - console.log("----------------------------------BATAS SUCI BAWAH NEW STOCK------------------------------"); + } await prisma.product.update({ where: { id: product.id }, diff --git a/src/modules/result/components/Table.tsx b/src/modules/result/components/Table.tsx index 19a1e8b..555c8af 100644 --- a/src/modules/result/components/Table.tsx +++ b/src/modules/result/components/Table.tsx @@ -58,7 +58,6 @@ const Table = () => { setExportLoad(true); const response = await fetch(`/api/stock-opname/export?companyId=${filter.company}`); const buffer = await response.arrayBuffer(); - console.log({ type: response.headers.get("type") }); const blob = new Blob([buffer], { type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" }); const url = window.URL.createObjectURL(blob); @@ -80,9 +79,7 @@ const Table = () => { const recompute = async (productId: number, companyId: string) => { const response = await fetch(`/api/company/${companyId}/product/${productId}/compute-different`, { method: "POST" }); - console.log("response", response); const stockOpname = await response.json(); - console.log("stockOpname", stockOpname); toast(`Berhasil menghitung ulang status barang, hasilnya ${stockOpname.data.isDifferent ? "selisih" : "aman"}`); stockOpnames.refetch(); }; -- 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(-) 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