import { auth } from "@/auth"; import { db } from "@/lib/db"; import { redirect } from "next/navigation"; import { ImportForm } from "./import-form"; import type { CostCentreOption } from "@/app/(portal)/po/new/new-po-form"; import type { Metadata } from "next"; export const metadata: Metadata = { title: "Import Purchase Order" }; export default async function ImportPoPage() { const session = await auth(); if (!session?.user) redirect("/login"); const { role } = session.user; if (!["MANAGER", "SUPERUSER", "ADMIN"].includes(role)) redirect("/dashboard"); const [vessels, sites, accounts, vendors] = await Promise.all([ db.vessel.findMany({ where: { isActive: true }, orderBy: { name: "asc" }, select: { id: true, name: true, code: true } }), db.site.findMany({ where: { isActive: true }, orderBy: { name: "asc" }, select: { id: true, name: true, code: true } }), db.account.findMany({ where: { isActive: true }, orderBy: { name: "asc" } }), db.vendor.findMany({ orderBy: { name: "asc" } }), ]); const costCentres: CostCentreOption[] = [ ...vessels.map((v) => ({ ref: `v:${v.id}`, label: `${v.code} — ${v.name}`, group: "Vessels" as const })), ...sites.map((s) => ({ ref: `s:${s.id}`, label: `${s.code} — ${s.name}`, group: "Sites" as const })), ]; return (
Upload a Pelagia-format Excel PO file. Line items and vendor details are extracted automatically. You then select the cost centre, accounting code, and confirm before saving as a draft.