fix(po): tighten filters and export data

This commit is contained in:
Hardik 2026-05-22 17:15:03 +05:30
parent 2c39f0225f
commit 32ea27331c
7 changed files with 31 additions and 21 deletions

View file

@ -27,7 +27,7 @@ export default async function ApprovalsPage({ searchParams }: Props) {
const { q, vesselId, dateFrom } = await searchParams; const { q, vesselId, dateFrom } = await searchParams;
const where: Parameters<typeof db.purchaseOrder.findMany>[0]["where"] = { const where: NonNullable<Parameters<typeof db.purchaseOrder.findMany>[0]>["where"] = {
status: "MGR_REVIEW", status: "MGR_REVIEW",
}; };

View file

@ -29,12 +29,16 @@ export default async function HistoryPage({ searchParams }: Props) {
const { dateFrom, dateTo, vesselId, status } = await searchParams; const { dateFrom, dateTo, vesselId, status } = await searchParams;
const where: Parameters<typeof db.purchaseOrder.findMany>[0]["where"] = {}; const where: NonNullable<Parameters<typeof db.purchaseOrder.findMany>[0]>["where"] = {};
if (dateFrom) where.createdAt = { ...where.createdAt, gte: new Date(dateFrom) }; if (dateFrom || dateTo) {
if (dateTo) { const createdAt: { gte?: Date; lt?: Date } = {};
const end = new Date(dateTo); if (dateFrom) createdAt.gte = new Date(dateFrom);
end.setDate(end.getDate() + 1); if (dateTo) {
where.createdAt = { ...where.createdAt, lt: end }; const end = new Date(dateTo);
end.setDate(end.getDate() + 1);
createdAt.lt = end;
}
where.createdAt = createdAt;
} }
if (vesselId) where.vesselId = vesselId; if (vesselId) where.vesselId = vesselId;
if (status) where.status = status as POStatus; if (status) where.status = status as POStatus;

View file

@ -27,7 +27,7 @@ export default async function PaymentHistoryPage({ searchParams }: Props) {
const { dateFrom, dateTo, vesselId } = await searchParams; const { dateFrom, dateTo, vesselId } = await searchParams;
const where: Parameters<typeof db.purchaseOrder.findMany>[0]["where"] = { const where: NonNullable<Parameters<typeof db.purchaseOrder.findMany>[0]>["where"] = {
status: { in: ["PAID_DELIVERED", "CLOSED"] }, status: { in: ["PAID_DELIVERED", "CLOSED"] },
}; };

View file

@ -62,7 +62,7 @@ export function EditPoForm({ po, vessels, accounts, vendors }: Props) {
const canSubmit = po.status === "DRAFT"; const canSubmit = po.status === "DRAFT";
const canResubmit = po.status === "EDITS_REQUESTED"; const canResubmit = po.status === "EDITS_REQUESTED";
async function handleSubmit(intent: "save" | "resubmit") { async function handleSubmit(intent: "save" | "submit" | "resubmit") {
setSubmitting(intent); setSubmitting(intent);
setError(""); setError("");
const form = document.getElementById("edit-po-form") as HTMLFormElement; const form = document.getElementById("edit-po-form") as HTMLFormElement;

View file

@ -35,7 +35,8 @@ export async function GET(request: NextRequest, { params }: Props) {
const po = await db.purchaseOrder.findUnique({ const po = await db.purchaseOrder.findUnique({
where: { id }, where: { id },
include: { 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" } }, lineItems: { orderBy: { sortOrder: "asc" } },
actions: { include: { actor: true }, orderBy: { createdAt: "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?.address,
po.vendor?.gstin ? `GSTIN: ${po.vendor.gstin}` : null, po.vendor?.gstin ? `GSTIN: ${po.vendor.gstin}` : null,
].filter(Boolean).join(" "); ].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(" "); .filter(Boolean).join(" ");
// ── GST summary row label ───────────────────────────────────────────────── // ── GST summary row label ─────────────────────────────────────────────────
@ -390,8 +392,10 @@ export async function GET(request: NextRequest, { params }: Props) {
const imgId = wb.addImage({ base64: signatureBase64, extension: imgType }); const imgId = wb.addImage({ base64: signatureBase64, extension: imgType });
// Span the image across columns A-D in the sig row // Span the image across columns A-D in the sig row
ws.addImage(imgId, { ws.addImage(imgId, {
tl: { col: 0, row: SIG_ROW - 1 }, // eslint-disable-next-line @typescript-eslint/no-explicit-any
br: { col: 4, row: SIG_ROW }, 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", editAs: "oneCell",
}); });
sc(SIG_ROW, 1, "", { border: { top: thin(), left: thin(), right: thin() } }); sc(SIG_ROW, 1, "", { border: { top: thin(), left: thin(), right: thin() } });

View file

@ -27,12 +27,16 @@ export async function GET(request: NextRequest) {
const vesselId = sp.get("vesselId"); const vesselId = sp.get("vesselId");
const status = sp.get("status"); const status = sp.get("status");
const where: Parameters<typeof db.purchaseOrder.findMany>[0]["where"] = {}; const where: NonNullable<Parameters<typeof db.purchaseOrder.findMany>[0]>["where"] = {};
if (dateFrom) where.createdAt = { ...where.createdAt, gte: new Date(dateFrom) }; if (dateFrom || dateTo) {
if (dateTo) { const createdAt: { gte?: Date; lt?: Date } = {};
const end = new Date(dateTo); if (dateFrom) createdAt.gte = new Date(dateFrom);
end.setDate(end.getDate() + 1); if (dateTo) {
where.createdAt = { ...where.createdAt, lt: end }; const end = new Date(dateTo);
end.setDate(end.getDate() + 1);
createdAt.lt = end;
}
where.createdAt = createdAt;
} }
if (vesselId) where.vesselId = vesselId; if (vesselId) where.vesselId = vesselId;
if (status) where.status = status as POStatus; if (status) where.status = status as POStatus;

View file

@ -20,7 +20,6 @@ import {
Upload, Upload,
MapPin, MapPin,
ShoppingCart, ShoppingCart,
BarChart3,
UserCircle, UserCircle,
ShieldCheck, ShieldCheck,
} from "lucide-react"; } from "lucide-react";
@ -59,7 +58,6 @@ const ADMIN_ITEMS: NavItem[] = [
{ href: "/admin/users", label: "Users", icon: Users }, { href: "/admin/users", label: "Users", icon: Users },
{ href: "/admin/superuser-requests", label: "SuperUser Requests", icon: ShieldCheck }, { href: "/admin/superuser-requests", label: "SuperUser Requests", icon: ShieldCheck },
{ href: "/admin/accounts", label: "Accounts", icon: Building2 }, { href: "/admin/accounts", label: "Accounts", icon: Building2 },
{ href: "/reports", label: "Reports", icon: BarChart3 },
]; ];
export function Sidebar({ userRole }: { userRole: Role }) { export function Sidebar({ userRole }: { userRole: Role }) {