bug fixing

This commit is contained in:
2026-09-09 14:38:53 +05:30
parent b3b6a25ce8
commit 629f3d1f44
27 changed files with 8403 additions and 50 deletions
@@ -1,6 +1,6 @@
"use client"
import { useEffect, useMemo, useState } from "react"
import { useEffect, useState } from "react"
import { useRouter } from "next/navigation"
import Link from "next/link"
import { ArrowLeft, ExternalLink, Plus, RefreshCw, ShieldCheck, Trash2 } from "lucide-react"
@@ -265,17 +265,10 @@ export default function NewGrnPage() {
// branch to pin to and the Admin must pick one explicitly for this GRN.
const lockedBranchId = isAdmin ? activeBranchId : myBranchId
const showBranchPicker = branchingEnabled && isAdmin && !lockedBranchId
// The branch this GRN is being raised for — no longer used to filter warehouses
// (warehouses are shared infrastructure across branches), only to scope the document itself.
const effectiveBranchId = branchingEnabled ? (isAdmin ? (activeBranchId ?? branchFilterId) : myBranchId) : null
const visibleWarehouses = useMemo(
() => (effectiveBranchId === null ? (warehouses ?? []) : (warehouses ?? []).filter((w) => w.branchId === effectiveBranchId)),
[warehouses, effectiveBranchId]
)
// Switching branch can strip the currently-picked warehouse out of the visible set —
// clear it rather than silently submitting a warehouse from the previous branch.
useEffect(() => {
setWarehouseId((prev) => (prev !== null && !visibleWarehouses.some((w) => w.warehouseId === prev) ? null : prev))
}, [visibleWarehouses])
const visibleWarehouses = warehouses ?? []
function switchMode(next: Mode) {
setMode(next)
@@ -459,6 +452,10 @@ export default function NewGrnPage() {
setHeaderError("Select a purchase order.")
return
}
if (branchingEnabled && !effectiveBranchId) {
setHeaderError("Select a branch for this GRN.")
return
}
if (lines.length === 0) {
setSubmitError("Add at least one line.")
return
@@ -513,6 +510,7 @@ export default function NewGrnPage() {
poId: mode === "po" ? poId : null,
vendorId: mode === "direct" ? vendorId : null,
warehouseId: warehouseId as number,
branchId: effectiveBranchId ?? 0,
lines: payloadLines,
})
toast.success("GRN created", `${grn.docNo} is ready to confirm.`)
+4
View File
@@ -61,6 +61,8 @@ export interface CreateGrnRequest {
/** Required when poId is null (direct/emergency receipt, FR-GRN-02). */
vendorId?: number | null
warehouseId: number
/** Owning branch — warehouses are shared across branches, so this is what actually scopes the GRN. */
branchId: number
lines: CreateGrnLineInput[]
}
@@ -96,6 +98,7 @@ export interface Grn {
poId: number | null
vendorId: number
warehouseId: number
branchId: number
status: GrnStatus
createdBy: number
createdAt: string
@@ -116,6 +119,7 @@ export interface GrnSummary {
poId: number | null
vendorId: number
warehouseId: number
branchId: number
status: GrnStatus
createdBy: number
createdAt: string