summaryrefslogtreecommitdiff
path: root/src/app/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/app/api')
-rw-r--r--src/app/api/company/[companyId]/product/[productId]/compute-different/route.tsx24
-rw-r--r--src/app/api/stock-opname/route.tsx24
2 files changed, 40 insertions, 8 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 2141c27..33cd55d 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
@@ -40,10 +40,6 @@ export async function POST(request: NextRequest, { params }: PostParams) {
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) && _.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++
}
@@ -72,6 +68,26 @@ export async function POST(request: NextRequest, { params }: PostParams) {
conditional.count2EqWithCount3
)
+ for (const opname of stockOpnames) {
+ let { COUNT1, COUNT2, COUNT3, VERIFICATION } = opname
+
+ const detailCondition = {
+ verificationCheckAll: _.isNumber(VERIFICATION.quantity),
+ count1EqWithCount2: COUNT1.quantity !== null && COUNT2.quantity !== null && COUNT1.quantity === COUNT2.quantity,
+ count1EqWithCount3: COUNT1.quantity !== null && COUNT3.quantity !== null && COUNT1.quantity === COUNT3.quantity,
+ count2EqWithCount3: COUNT2.quantity !== null && COUNT3.quantity !== null && COUNT2.quantity === COUNT3.quantity,
+ }
+
+ isDifferent = !(
+ detailCondition.verificationCheckAll ||
+ detailCondition.count1EqWithCount2 ||
+ detailCondition.count1EqWithCount3 ||
+ detailCondition.count2EqWithCount3
+ )
+
+ if (isDifferent) break
+ }
+
const payload = {
where: { id: product.id },
data: { isDifferent }
diff --git a/src/app/api/stock-opname/route.tsx b/src/app/api/stock-opname/route.tsx
index 4c2dee4..38284bf 100644
--- a/src/app/api/stock-opname/route.tsx
+++ b/src/app/api/stock-opname/route.tsx
@@ -169,10 +169,6 @@ const computeIsDifferent = async ({
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) && _.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++
}
@@ -201,6 +197,26 @@ const computeIsDifferent = async ({
conditional.count2EqWithCount3
)
+ for (const opname of stockOpnames) {
+ let { COUNT1, COUNT2, COUNT3, VERIFICATION } = opname
+
+ const detailCondition = {
+ verificationCheckAll: _.isNumber(VERIFICATION.quantity),
+ count1EqWithCount2: COUNT1.quantity !== null && COUNT2.quantity !== null && COUNT1.quantity === COUNT2.quantity,
+ count1EqWithCount3: COUNT1.quantity !== null && COUNT3.quantity !== null && COUNT1.quantity === COUNT3.quantity,
+ count2EqWithCount3: COUNT2.quantity !== null && COUNT3.quantity !== null && COUNT2.quantity === COUNT3.quantity,
+ }
+
+ isDifferent = !(
+ detailCondition.verificationCheckAll ||
+ detailCondition.count1EqWithCount2 ||
+ detailCondition.count1EqWithCount3 ||
+ detailCondition.count2EqWithCount3
+ )
+
+ if (isDifferent) break
+ }
+
await prisma.product.update({
where: { id: product.id },
data: { isDifferent }