summaryrefslogtreecommitdiff
path: root/src/app/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/app/api')
-rw-r--r--src/app/api/product/[id]/toggle-different/route.tsx16
-rw-r--r--src/app/api/product/route.tsx11
-rw-r--r--src/app/api/stock-opname/route.tsx19
3 files changed, 37 insertions, 9 deletions
diff --git a/src/app/api/product/[id]/toggle-different/route.tsx b/src/app/api/product/[id]/toggle-different/route.tsx
new file mode 100644
index 0000000..987dbf3
--- /dev/null
+++ b/src/app/api/product/[id]/toggle-different/route.tsx
@@ -0,0 +1,16 @@
+import { NextRequest, NextResponse } from "next/server";
+import { prisma } from "prisma/client";
+
+type Params = { params: { id: string } }
+export async function POST(request: NextRequest, { params }: Params) {
+ const intId = parseInt(params.id)
+ const product = await prisma.product.findUnique({ where: { id: intId } })
+ const updatedProduct = await prisma.product.update({
+ where: { id: intId },
+ data: {
+ isDifferent: !product?.isDifferent
+ }
+ })
+
+ return NextResponse.json(updatedProduct)
+} \ No newline at end of file
diff --git a/src/app/api/product/route.tsx b/src/app/api/product/route.tsx
index 63813aa..de8a482 100644
--- a/src/app/api/product/route.tsx
+++ b/src/app/api/product/route.tsx
@@ -8,11 +8,15 @@ export async function GET(request: NextRequest) {
const searchParams = request.nextUrl.searchParams;
const search = searchParams.get('search');
+
const page = searchParams.get('page');
const intPage: number = page ? parseInt(page) : 1;
+
const paramCompanyId = searchParams.get('companyId')
const companyId = paramCompanyId ? parseInt(paramCompanyId) : null
+ const show = searchParams.get('show')
+
const credential = getServerCredential()
if (!credential) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
@@ -24,8 +28,10 @@ export async function GET(request: NextRequest) {
{ barcode: { mode: 'insensitive', contains: search ?? '' } },
{ itemCode: { mode: 'insensitive', contains: search ?? '' } },
],
- companyId: companyId ?? credential.companyId
- }
+ companyId: companyId ?? credential.companyId,
+ stockOpnames: { none: show === 'not-count' ? {} : undefined },
+ onhandQty: { gt: show === 'not-count' ? 0 : undefined },
+ },
}
const products = await prisma.product.findMany({
@@ -40,6 +46,7 @@ export async function GET(request: NextRequest) {
const pagination = {
page: intPage,
totalPage: Math.ceil(count / PAGE_SIZE),
+ count
}
return NextResponse.json({ products, ...pagination })
diff --git a/src/app/api/stock-opname/route.tsx b/src/app/api/stock-opname/route.tsx
index 3b3ad5a..e98c3b2 100644
--- a/src/app/api/stock-opname/route.tsx
+++ b/src/app/api/stock-opname/route.tsx
@@ -113,9 +113,7 @@ export async function POST(request: NextRequest) {
team
}
- const stockOpname = await prisma.stockOpname.findFirst({
- where: query
- })
+ const stockOpname = await prisma.stockOpname.findFirst({ where: query })
const data = {
...query,
@@ -165,6 +163,7 @@ const computeIsDifferent = async ({
const stockOpnames: StockOpnameLocationRes[] = await stockOpnamesFetch.json()
let isDifferent: boolean = false
+ let verificationCounter: number = 0
for (const opname of stockOpnames) {
let { COUNT1, COUNT2, COUNT3, VERIFICATION } = opname
@@ -182,25 +181,31 @@ const computeIsDifferent = async ({
if (_.isNumber(COUNT1.quantity) && _.isNumber(COUNT2.quantity) && COUNT1.quantity !== COUNT2.quantity) isDifferent = true
if (_.isNumber(COUNT1.quantity) && _.isNumber(COUNT3.quantity) && COUNT1.quantity !== COUNT3.quantity) isDifferent = true
if (_.isNumber(COUNT2.quantity) && _.isNumber(COUNT3.quantity) && COUNT2.quantity !== COUNT3.quantity) isDifferent = true
+
+ if (_.isNumber(VERIFICATION.quantity)) verificationCounter++
}
const product = await prisma.product.findFirst({ where: { id: productId } })
if (!product) return
- const onhandQty = product?.onhandQty || 0
+ const onhandQty = product.onhandQty
+ const differenceQty = product.differenceQty
+ const allQty = onhandQty + differenceQty
if (!isDifferent) {
const conditional = {
- wasVerified: typeof totalQty['VERIFICATION'] === 'number',
+ verificationCheckAll: verificationCounter > 0 && verificationCounter === stockOpnames.length,
anyCountEqWithOnhand: [totalQty['COUNT1'], totalQty['COUNT2'], totalQty['COUNT3']].includes(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']
+ count2EqWithCount3: totalQty['COUNT2'] !== null && totalQty['COUNT3'] !== null && totalQty['COUNT2'] === totalQty['COUNT3'],
}
isDifferent = !(
- conditional.wasVerified ||
+ conditional.verificationCheckAll ||
conditional.anyCountEqWithOnhand ||
+ conditional.anyCountEqWithAllQty ||
conditional.count1EqWithCount2 ||
conditional.count1EqWithCount3 ||
conditional.count2EqWithCount3