summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/app/api/company/[companyId]/product/[productId]/compute-different/route.tsx14
-rw-r--r--src/app/api/stock-opname/route.tsx44
2 files changed, 39 insertions, 19 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 a99bb3f..61e6db3 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
@@ -55,6 +55,9 @@ export async function POST(request: NextRequest, { params }: PostParams) {
const zeroCount2: boolean = totalQty["COUNT2"] === 0;
const zeroCount3: boolean = totalQty["COUNT3"] === 0;
+ if (verificationCounter > 0){
+ isDifferent = false
+ } else {
const conditional = {
verificationCheckAll: verificationCounter > 0 && verificationCounter === stockOpnames.length,
// anyCountEqWithOnhand: [totalQty['COUNT1'], totalQty['COUNT2'], totalQty['COUNT3']].includes(onhandQty),
@@ -70,16 +73,21 @@ export async function POST(request: NextRequest, { params }: PostParams) {
} else {
isDifferent = true;
}
+ }
for (const opname of stockOpnames) {
let { COUNT1, COUNT2, COUNT3, VERIFICATION } = opname;
+ const count1 = _.isNumber(COUNT1.quantity) ? COUNT1.quantity : 0;
+ const count2 = _.isNumber(COUNT2.quantity) ? COUNT2.quantity : 0;
+ const count3 = _.isNumber(COUNT3.quantity) ? COUNT3.quantity : 0;
+
const detailCondition = {
verificationCheckAll: _.isNumber(VERIFICATION.quantity),
anyCountEqWithOnhand: (totalQty["COUNT1"] === onhandQty && zeroCount2 && zeroCount3) || (totalQty["COUNT2"] === onhandQty && zeroCount3 && onhandQty!== 0) || (totalQty["COUNT3"] === onhandQty && onhandQty!== 0),
- count1EqWithCount2: totalQty["COUNT3"] === 0 && COUNT1.quantity === COUNT2.quantity && totalQty["COUNT1"] !== onhandQty,
- count1EqWithCount3: COUNT1.quantity === COUNT3.quantity,
- count2EqWithCount3: totalQty["COUNT2"] !== 0 && totalQty["COUNT3"] !== 0 && totalQty["COUNT2"] === totalQty["COUNT3"],
+ count1EqWithCount2: totalQty["COUNT3"] === 0 && count1 === count2,
+ count1EqWithCount3: count1 == count3,
+ count2EqWithCount3: totalQty["COUNT2"] !== 0 && totalQty["COUNT3"] !== 0 && count2 === count3,
// count3EqWithCount1_2: (COUNT3.quantity !== COUNT1.quantity) && (COUNT3.quantity !== COUNT2.quantity) && (COUNT1.quantity === COUNT2.quantity) && (COUNT3.quantity !== onhandQty)
};
diff --git a/src/app/api/stock-opname/route.tsx b/src/app/api/stock-opname/route.tsx
index 384c834..e1adb0f 100644
--- a/src/app/api/stock-opname/route.tsx
+++ b/src/app/api/stock-opname/route.tsx
@@ -174,37 +174,49 @@ const computeIsDifferent = async ({ companyId, productId }: { companyId: number;
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 && onhandQty!== 0) || (totalQty["COUNT3"] === onhandQty && onhandQty!== 0),
- 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"] !== 0 && totalQty["COUNT3"] !== 0 && totalQty["COUNT2"] === totalQty["COUNT3"],
- };
-
- if (conditional.verificationCheckAll || conditional.anyCountEqWithOnhand || conditional.count1EqWithCount2 || conditional.count1EqWithCount3 || conditional.count2EqWithCount3) {
+ // Jika ada verifikasi qty, langsung AMAN
+ if (verificationCounter > 0) {
isDifferent = false;
} else {
- isDifferent = true;
+ // Jika tidak ada qty verifikasi, cek kondisi tim 1/2/3
+ const conditional = {
+ // anyCountEqWithOnhand: [totalQty['COUNT1'], totalQty['COUNT2'], totalQty['COUNT3']].includes(onhandQty),
+ anyCountEqWithOnhand: (totalQty["COUNT1"] === onhandQty && zeroCount2 && zeroCount3) || (totalQty["COUNT2"] === onhandQty && zeroCount3 && onhandQty!== 0) || (totalQty["COUNT3"] === onhandQty && onhandQty!== 0),
+ 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"] !== 0 && totalQty["COUNT3"] !== 0 && totalQty["COUNT2"] === totalQty["COUNT3"],
+ };
+
+ if (conditional.anyCountEqWithOnhand || conditional.count1EqWithCount2 || conditional.count1EqWithCount3 || conditional.count2EqWithCount3) {
+ isDifferent = false;
+ }
+ else {
+ isDifferent = true;
+ }
}
for (const opname of stockOpnames) {
let { COUNT1, COUNT2, COUNT3, VERIFICATION } = opname;
+ // Normalize: treat missing (null/undefined) same as 0
+ const count1 = _.isNumber(COUNT1.quantity) ? COUNT1.quantity : 0;
+ const count2 = _.isNumber(COUNT2.quantity) ? COUNT2.quantity : 0;
+ const count3 = _.isNumber(COUNT3.quantity) ? COUNT3.quantity : 0;
+
const detailCondition = {
verificationCheckAll: _.isNumber(VERIFICATION.quantity),
anyCountEqWithOnhand: (totalQty["COUNT1"] === onhandQty && zeroCount2 && zeroCount3) || (totalQty["COUNT2"] === onhandQty && zeroCount3 && onhandQty!== 0) || (totalQty["COUNT3"] === onhandQty && onhandQty!== 0),
- count1EqWithCount2: totalQty["COUNT3"] === 0 && COUNT1.quantity === COUNT2.quantity,
- count1EqWithCount3: COUNT1.quantity === COUNT3.quantity,
- count2EqWithCount3: totalQty["COUNT2"] !== 0 && totalQty["COUNT3"] !== 0 && totalQty["COUNT2"] === totalQty["COUNT3"],
+ count1EqWithCount2: totalQty["COUNT3"] === 0 && count1 === count2,
+ count1EqWithCount3: count1 === count3,
+ count2EqWithCount3: totalQty["COUNT2"] !== 0 && totalQty["COUNT3"] !== 0 && count2 === count3,
// 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) {
isDifferent = false;
- } else {
+ }
+ else {
isDifferent = true;
break;
}