From 32ea27331cdafe865b42f88d63da10d1f99cb4c0 Mon Sep 17 00:00:00 2001 From: Hardik Date: Fri, 22 May 2026 17:15:03 +0530 Subject: [PATCH] fix(po): tighten filters and export data --- App/app/(portal)/approvals/page.tsx | 2 +- App/app/(portal)/history/page.tsx | 16 ++++++++++------ App/app/(portal)/payments/history/page.tsx | 2 +- App/app/(portal)/po/[id]/edit/edit-po-form.tsx | 2 +- App/app/api/po/[id]/export/route.ts | 12 ++++++++---- App/app/api/reports/export/route.ts | 16 ++++++++++------ App/components/layout/sidebar.tsx | 2 -- 7 files changed, 31 insertions(+), 21 deletions(-) diff --git a/App/app/(portal)/approvals/page.tsx b/App/app/(portal)/approvals/page.tsx index a916619..546c1f9 100644 --- a/App/app/(portal)/approvals/page.tsx +++ b/App/app/(portal)/approvals/page.tsx @@ -27,7 +27,7 @@ export default async function ApprovalsPage({ searchParams }: Props) { const { q, vesselId, dateFrom } = await searchParams; - const where: Parameters[0]["where"] = { + const where: NonNullable[0]>["where"] = { status: "MGR_REVIEW", }; diff --git a/App/app/(portal)/history/page.tsx b/App/app/(portal)/history/page.tsx index e30f9c8..cc1a639 100644 --- a/App/app/(portal)/history/page.tsx +++ b/App/app/(portal)/history/page.tsx @@ -29,12 +29,16 @@ export default async function HistoryPage({ searchParams }: Props) { const { dateFrom, dateTo, vesselId, status } = await searchParams; - const where: Parameters[0]["where"] = {}; - if (dateFrom) where.createdAt = { ...where.createdAt, gte: new Date(dateFrom) }; - if (dateTo) { - const end = new Date(dateTo); - end.setDate(end.getDate() + 1); - where.createdAt = { ...where.createdAt, lt: end }; + const where: NonNullable[0]>["where"] = {}; + if (dateFrom || dateTo) { + const createdAt: { gte?: Date; lt?: Date } = {}; + if (dateFrom) createdAt.gte = new Date(dateFrom); + if (dateTo) { + const end = new Date(dateTo); + end.setDate(end.getDate() + 1); + createdAt.lt = end; + } + where.createdAt = createdAt; } if (vesselId) where.vesselId = vesselId; if (status) where.status = status as POStatus; diff --git a/App/app/(portal)/payments/history/page.tsx b/App/app/(portal)/payments/history/page.tsx index a5b7e91..4a54a7c 100644 --- a/App/app/(portal)/payments/history/page.tsx +++ b/App/app/(portal)/payments/history/page.tsx @@ -27,7 +27,7 @@ export default async function PaymentHistoryPage({ searchParams }: Props) { const { dateFrom, dateTo, vesselId } = await searchParams; - const where: Parameters[0]["where"] = { + const where: NonNullable[0]>["where"] = { status: { in: ["PAID_DELIVERED", "CLOSED"] }, }; diff --git a/App/app/(portal)/po/[id]/edit/edit-po-form.tsx b/App/app/(portal)/po/[id]/edit/edit-po-form.tsx index 21de1be..e147848 100644 --- a/App/app/(portal)/po/[id]/edit/edit-po-form.tsx +++ b/App/app/(portal)/po/[id]/edit/edit-po-form.tsx @@ -62,7 +62,7 @@ export function EditPoForm({ po, vessels, accounts, vendors }: Props) { const canSubmit = po.status === "DRAFT"; const canResubmit = po.status === "EDITS_REQUESTED"; - async function handleSubmit(intent: "save" | "resubmit") { + async function handleSubmit(intent: "save" | "submit" | "resubmit") { setSubmitting(intent); setError(""); const form = document.getElementById("edit-po-form") as HTMLFormElement; diff --git a/App/app/api/po/[id]/export/route.ts b/App/app/api/po/[id]/export/route.ts index d58b7fd..251bba7 100644 --- a/App/app/api/po/[id]/export/route.ts +++ b/App/app/api/po/[id]/export/route.ts @@ -35,7 +35,8 @@ export async function GET(request: NextRequest, { params }: Props) { const po = await db.purchaseOrder.findUnique({ where: { id }, include: { - submitter: true, vessel: true, account: true, vendor: true, + submitter: true, vessel: true, account: true, + vendor: { include: { contacts: { where: { isPrimary: true }, take: 1 } } }, lineItems: { orderBy: { sortOrder: "asc" } }, actions: { include: { actor: true }, orderBy: { createdAt: "asc" } }, }, @@ -126,7 +127,8 @@ export async function GET(request: NextRequest, { params }: Props) { po.vendor?.address, po.vendor?.gstin ? `GSTIN: ${po.vendor.gstin}` : null, ].filter(Boolean).join(" "); - const vendorContact = [po.vendor?.contactName, po.vendor?.contactMobile, po.vendor?.contactEmail] + const primaryContact = po.vendor?.contacts?.[0]; + const vendorContact = [primaryContact?.name, primaryContact?.mobile, primaryContact?.email] .filter(Boolean).join(" "); // ── GST summary row label ───────────────────────────────────────────────── @@ -390,8 +392,10 @@ export async function GET(request: NextRequest, { params }: Props) { const imgId = wb.addImage({ base64: signatureBase64, extension: imgType }); // Span the image across columns A-D in the sig row ws.addImage(imgId, { - tl: { col: 0, row: SIG_ROW - 1 }, - br: { col: 4, row: SIG_ROW }, + // eslint-disable-next-line @typescript-eslint/no-explicit-any + tl: { col: 0, row: SIG_ROW - 1 } as any, + // eslint-disable-next-line @typescript-eslint/no-explicit-any + br: { col: 4, row: SIG_ROW } as any, editAs: "oneCell", }); sc(SIG_ROW, 1, "", { border: { top: thin(), left: thin(), right: thin() } }); diff --git a/App/app/api/reports/export/route.ts b/App/app/api/reports/export/route.ts index 8b61b86..a5aa672 100644 --- a/App/app/api/reports/export/route.ts +++ b/App/app/api/reports/export/route.ts @@ -27,12 +27,16 @@ export async function GET(request: NextRequest) { const vesselId = sp.get("vesselId"); const status = sp.get("status"); - const where: Parameters[0]["where"] = {}; - if (dateFrom) where.createdAt = { ...where.createdAt, gte: new Date(dateFrom) }; - if (dateTo) { - const end = new Date(dateTo); - end.setDate(end.getDate() + 1); - where.createdAt = { ...where.createdAt, lt: end }; + const where: NonNullable[0]>["where"] = {}; + if (dateFrom || dateTo) { + const createdAt: { gte?: Date; lt?: Date } = {}; + if (dateFrom) createdAt.gte = new Date(dateFrom); + if (dateTo) { + const end = new Date(dateTo); + end.setDate(end.getDate() + 1); + createdAt.lt = end; + } + where.createdAt = createdAt; } if (vesselId) where.vesselId = vesselId; if (status) where.status = status as POStatus; diff --git a/App/components/layout/sidebar.tsx b/App/components/layout/sidebar.tsx index 6d58f2e..3e82f2c 100644 --- a/App/components/layout/sidebar.tsx +++ b/App/components/layout/sidebar.tsx @@ -20,7 +20,6 @@ import { Upload, MapPin, ShoppingCart, - BarChart3, UserCircle, ShieldCheck, } from "lucide-react"; @@ -59,7 +58,6 @@ const ADMIN_ITEMS: NavItem[] = [ { href: "/admin/users", label: "Users", icon: Users }, { href: "/admin/superuser-requests", label: "SuperUser Requests", icon: ShieldCheck }, { href: "/admin/accounts", label: "Accounts", icon: Building2 }, - { href: "/reports", label: "Reports", icon: BarChart3 }, ]; export function Sidebar({ userRole }: { userRole: Role }) {