import { auth } from "@/auth"; import { db } from "@/lib/db"; import { redirect } from "next/navigation"; import Link from "next/link"; import { formatCurrency, formatDate } from "@/lib/utils"; import { PoStatusBadge } from "@/components/po/po-status-badge"; import type { Metadata } from "next"; export const metadata: Metadata = { title: "Closed Purchase Orders" }; export default async function MyOrdersPage() { const session = await auth(); if (!session?.user) redirect("/login"); const { role, id: userId } = session.user; if (!["TECHNICAL", "MANNING", "MANAGER", "SUPERUSER"].includes(role)) redirect("/dashboard"); const closed = await db.purchaseOrder.findMany({ where: { submitterId: userId, status: { in: ["MGR_APPROVED", "SENT_FOR_PAYMENT", "PAID_DELIVERED", "CLOSED", "REJECTED"] }, }, orderBy: { updatedAt: "desc" }, include: { vessel: { select: { name: true } }, account: { select: { name: true, code: true } }, actions: { where: { actionType: { in: ["EDITS_REQUESTED", "REJECTED", "APPROVED", "APPROVED_WITH_NOTE"] }, note: { not: null }, }, orderBy: { createdAt: "desc" }, take: 1, select: { actor: { select: { name: true } } }, }, }, }); return (
No closed purchase orders yet.
View active orders on the dashboard →| PO Number | Title | Cost Centre | Status | Amount | Updated |
|---|---|---|---|---|---|
| {po.poNumber} |
{po.title}
{po.managerNote && (
{po.actions[0]?.actor.name ? `${po.actions[0].actor.name}: ` : "Note: "}{po.managerNote} )} |
{po.vessel.name} | {formatCurrency(Number(po.totalAmount))} | {formatDate(po.updatedAt)} |