summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2024-07-04 11:53:01 +0700
committerit-fixcomart <it@fixcomart.co.id>2024-07-04 11:53:01 +0700
commit9a80c0a767c6a35a489b9d45654ae60f7ddc6794 (patch)
tree719161efc93b3abb408fa77d1d78e8193dc86df2
parenta711c3d7f3a41bb5ac20485723a0f629fbfde1b7 (diff)
<iman> update stock opname logic
-rw-r--r--src/app/api/company/[companyId]/product/[productId]/compute-different/route.tsx34
-rw-r--r--src/app/api/stock-opname/route.tsx11
-rw-r--r--src/modules/result/components/MoreMenu.tsx17
-rw-r--r--src/modules/result/components/Table.tsx6
-rw-r--r--src/modules/result/index.tsx10
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<Credential | null>(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' && (
<>
<Dropdown>
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 = () => {
<div className="w-full flex-1 overflow-auto pb-4">
<table className="w-full">
- <thead className={styles.thead}>
+ <thead className={styles.thead}>
+ <tr>
<th className={styles.th}>STATUS</th>
<th className={clsxm(styles.th, '!text-left')}>NAMA PRODUK</th>
<th className={styles.th}>TIM HITUNG 1</th>
@@ -109,7 +110,8 @@ const Table = () => {
<th className={styles.th}>ON-HAND QTY</th>
<th className={styles.th}>GUDANG SELISIH</th>
<th className={styles.th}></th>
- </thead>
+ </tr>
+ </thead>
<tbody className={styles.tbody}>
{!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 (
<>
- <div className={styles.wrapper}>
- <div className={styles.title}>Stock Opname Result</div>
- <MoreMenu />
+ <div className="flex justify-between items-center">
+ <div className="font-semibold text-xl">Stock Opname Result</div>
+ <Suspense fallback={<div>Loading...</div>}>
+ <MoreMenu />
+ </Suspense>
</div>
<Spacer y={4} />
<Filter />