diff --git a/App/app/(portal)/history/history-filters.tsx b/App/app/(portal)/history/history-filters.tsx
index da6fe74..16b4132 100644
--- a/App/app/(portal)/history/history-filters.tsx
+++ b/App/app/(portal)/history/history-filters.tsx
@@ -18,33 +18,33 @@ const STATUSES = [
];
interface Props {
- costCentres: { ref: string; name: string }[];
+ vessels: { id: string; name: string }[];
}
-export function HistoryFilters({ costCentres }: Props) {
+export function HistoryFilters({ vessels }: Props) {
const router = useRouter();
const sp = useSearchParams();
const [dateFrom, setDateFrom] = useState(sp.get("dateFrom") ?? "");
const [dateTo, setDateTo] = useState(sp.get("dateTo") ?? "");
- const [costCentreRef, setCostCentreRef] = useState(sp.get("costCentreRef") ?? "");
+ const [vesselId, setVesselId] = useState(sp.get("vesselId") ?? "");
const [status, setStatus] = useState(sp.get("status") ?? "");
function apply() {
const params = new URLSearchParams();
if (dateFrom) params.set("dateFrom", dateFrom);
if (dateTo) params.set("dateTo", dateTo);
- if (costCentreRef) params.set("costCentreRef", costCentreRef);
+ if (vesselId) params.set("vesselId", vesselId);
if (status) params.set("status", status);
router.push(`/history?${params.toString()}`);
}
function clear() {
- setDateFrom(""); setDateTo(""); setCostCentreRef(""); setStatus("");
+ setDateFrom(""); setDateTo(""); setVesselId(""); setStatus("");
router.push("/history");
}
- const hasFilters = dateFrom || dateTo || costCentreRef || status;
+ const hasFilters = dateFrom || dateTo || vesselId || status;
return (
@@ -61,12 +61,10 @@ export function HistoryFilters({ costCentres }: Props) {
@@ -116,7 +107,7 @@ export default async function HistoryPage({ searchParams }: Props) {
{po.title} |
-
{po.vessel?.name ?? po.site?.name ?? "—"} |
+
{po.vessel.name} |
{po.submitter.name} |
diff --git a/App/app/(portal)/my-orders/page.tsx b/App/app/(portal)/my-orders/page.tsx
index 4cf5aa2..2bd44a8 100644
--- a/App/app/(portal)/my-orders/page.tsx
+++ b/App/app/(portal)/my-orders/page.tsx
@@ -23,7 +23,6 @@ export default async function MyOrdersPage() {
orderBy: { updatedAt: "desc" },
include: {
vessel: { select: { name: true } },
- site: { select: { name: true } },
account: { select: { name: true, code: true } },
actions: {
where: {
@@ -68,8 +67,7 @@ type PoRow = {
title: string;
status: import("@prisma/client").POStatus;
totalAmount: import("@prisma/client").Prisma.Decimal;
- vessel: { name: string } | null;
- site: { name: string } | null;
+ vessel: { name: string };
account: { name: string; code: string };
updatedAt: Date;
managerNote: string | null;
@@ -111,7 +109,7 @@ function PoTable({ title, rows, className = "" }: { title: string; rows: PoRow[]
)}
|
-
{po.vessel?.name ?? po.site?.name ?? "—"} |
+
{po.vessel.name} |
|
{formatCurrency(Number(po.totalAmount))} |
{formatDate(po.updatedAt)} |
diff --git a/App/app/(portal)/payments/history/page.tsx b/App/app/(portal)/payments/history/page.tsx
index ad0e179..28e564b 100644
--- a/App/app/(portal)/payments/history/page.tsx
+++ b/App/app/(portal)/payments/history/page.tsx
@@ -117,7 +117,7 @@ export default async function PaymentHistoryPage({ searchParams }: Props) {
{po.title}
|
-
{po.vessel?.name ?? po.site?.name ?? "—"} |
+
{po.vessel.name} |
{po.vendor?.name ?? "—"} |
{po.submitter.name} |
diff --git a/App/app/(portal)/payments/page.tsx b/App/app/(portal)/payments/page.tsx
index 55d9dc9..92230e0 100644
--- a/App/app/(portal)/payments/page.tsx
+++ b/App/app/(portal)/payments/page.tsx
@@ -45,7 +45,7 @@ export default async function PaymentsPage() {
{po.title}
- {po.vessel?.name ?? po.site?.name ?? "—"}
+ {po.vessel.name}
·
{po.submitter.name}
{po.vendor && (
diff --git a/App/app/(portal)/po/[id]/edit/actions.ts b/App/app/(portal)/po/[id]/edit/actions.ts
index 7b2821b..5c2198a 100644
--- a/App/app/(portal)/po/[id]/edit/actions.ts
+++ b/App/app/(portal)/po/[id]/edit/actions.ts
@@ -45,7 +45,7 @@ export async function updatePo(
const parsed = createPoSchema.safeParse({
title: formData.get("title"),
- costCentreRef: formData.get("costCentreRef"),
+ vesselId: formData.get("vesselId"),
accountId: formData.get("accountId"),
projectCode: formData.get("projectCode") || undefined,
dateRequired: formData.get("dateRequired") || undefined,
@@ -69,8 +69,6 @@ export async function updatePo(
}
const data = parsed.data;
- const newVesselId = data.costCentreRef.startsWith("v:") ? data.costCentreRef.slice(2) : null;
- const newCostCentreSiteId = data.costCentreRef.startsWith("s:") ? data.costCentreRef.slice(2) : null;
const total = data.lineItems.reduce(
(sum, item) => sum + item.quantity * item.unitPrice * (1 + item.gstRate),
0
@@ -102,7 +100,6 @@ export async function updatePo(
include: {
lineItems: { orderBy: { sortOrder: "asc" } },
vessel: true,
- site: { select: { name: true } },
account: true,
vendor: true,
},
@@ -120,8 +117,8 @@ export async function updatePo(
})),
fields: {
title: currentPo.title,
- vessel: currentPo.vessel?.name ?? currentPo.site?.name ?? null,
- vesselId: currentPo.vesselId ?? currentPo.siteId ?? "",
+ vessel: currentPo.vessel?.name ?? null,
+ vesselId: currentPo.vesselId,
account: `${currentPo.account.name} (${currentPo.account.code})`,
accountId: currentPo.accountId,
vendor: currentPo.vendor?.name ?? null,
@@ -138,8 +135,7 @@ export async function updatePo(
where: { id: poId },
data: {
title: data.title,
- vesselId: newVesselId,
- siteId: newCostCentreSiteId,
+ vesselId: data.vesselId,
accountId: data.accountId,
vendorId: data.vendorId ?? null,
projectCode: data.projectCode ?? null,
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 e4ea9ac..580ec5c 100644
--- a/App/app/(portal)/po/[id]/edit/edit-po-form.tsx
+++ b/App/app/(portal)/po/[id]/edit/edit-po-form.tsx
@@ -4,7 +4,7 @@ import { useState } from "react";
import { useRouter } from "next/navigation";
import { updatePo } from "./actions";
import type { Vendor, PurchaseOrder } from "@prisma/client";
-import type { CostCentreGroup, AccountGroup } from "@/app/(portal)/po/new/new-po-form";
+import type { VesselOption, AccountGroup } from "@/app/(portal)/po/new/new-po-form";
import { LineItemsEditor } from "@/components/po/po-line-items-editor";
import { SearchableSelect } from "@/components/ui/searchable-select";
import type { LineItemInput } from "@/lib/validations/po";
@@ -36,14 +36,13 @@ type PoWithItems = Omit & {
interface Props {
po: PoWithItems;
- costCentres: CostCentreGroup[];
- initialCostCentreRef: string;
+ vessels: VesselOption[];
accounts: AccountGroup[];
vendors: Vendor[];
managerNoteAuthor?: string | null;
}
-export function EditPoForm({ po, costCentres, initialCostCentreRef, accounts, vendors, managerNoteAuthor }: Props) {
+export function EditPoForm({ po, vessels, accounts, vendors, managerNoteAuthor }: Props) {
const router = useRouter();
const [lineItems, setLineItems] = useState(
po.lineItems.map((li) => ({
@@ -131,17 +130,10 @@ export function EditPoForm({ po, costCentres, initialCostCentreRef, accounts, ve
-
diff --git a/App/app/(portal)/po/[id]/edit/page.tsx b/App/app/(portal)/po/[id]/edit/page.tsx
index 19a83b4..17c0bba 100644
--- a/App/app/(portal)/po/[id]/edit/page.tsx
+++ b/App/app/(portal)/po/[id]/edit/page.tsx
@@ -2,7 +2,7 @@ import { auth } from "@/auth";
import { db } from "@/lib/db";
import { notFound, redirect } from "next/navigation";
import { EditPoForm } from "./edit-po-form";
-import { buildCostCentreGroups, buildAccountGroups } from "@/lib/cost-centre-groups";
+import { buildAccountGroups } from "@/lib/cost-centre-groups";
import type { Metadata } from "next";
interface Props {
@@ -23,15 +23,13 @@ export default async function EditPoPage({ params }: Props) {
});
if (!po) notFound();
-
if (!["DRAFT", "EDITS_REQUESTED"].includes(po.status)) redirect(`/po/${id}`);
const canEdit = po.submitterId === session.user.id || session.user.role === "SUPERUSER";
if (!canEdit) redirect(`/po/${id}`);
- const [vessels, sites, leafAccounts, vendors, noteAction] = await Promise.all([
- db.vessel.findMany({ where: { isActive: true }, orderBy: { name: "asc" }, select: { id: true, name: true, code: true, siteId: true } }),
- db.site.findMany({ where: { isActive: true }, orderBy: { name: "asc" }, select: { id: true, name: true } }),
+ const [vessels, leafAccounts, vendors, noteAction] = await Promise.all([
+ db.vessel.findMany({ where: { isActive: true }, orderBy: { name: "asc" }, select: { id: true, name: true, code: true } }),
db.account.findMany({
where: { isActive: true, children: { none: {} } },
orderBy: { code: "asc" },
@@ -47,9 +45,7 @@ export default async function EditPoPage({ params }: Props) {
: Promise.resolve(null),
]);
- const costCentres = buildCostCentreGroups(vessels, sites);
- const accountGroups = buildAccountGroups(leafAccounts);
- const initialCostCentreRef = po.vesselId ? `v:${po.vesselId}` : po.siteId ? `s:${po.siteId}` : "";
+ const accounts = buildAccountGroups(leafAccounts);
const serializedPo = {
...po,
@@ -71,9 +67,8 @@ export default async function EditPoPage({ params }: Props) {
diff --git a/App/app/(portal)/po/[id]/page.tsx b/App/app/(portal)/po/[id]/page.tsx
index 9e96e7f..4884165 100644
--- a/App/app/(portal)/po/[id]/page.tsx
+++ b/App/app/(portal)/po/[id]/page.tsx
@@ -26,7 +26,6 @@ export default async function PoDetailPage({ params }: Props) {
include: {
submitter: true,
vessel: true,
- site: { select: { id: true, name: true } },
account: true,
vendor: true,
lineItems: { orderBy: { sortOrder: "asc" } },
diff --git a/App/app/(portal)/po/[id]/receipt/actions.ts b/App/app/(portal)/po/[id]/receipt/actions.ts
index ce0fa77..7b413de 100644
--- a/App/app/(portal)/po/[id]/receipt/actions.ts
+++ b/App/app/(portal)/po/[id]/receipt/actions.ts
@@ -28,7 +28,7 @@ export async function confirmReceipt({
include: {
submitter: true,
lineItems: true,
- vessel: { include: { site: true } },
+ vessel: true,
},
});
if (!po) return { error: "PO not found" };
@@ -134,7 +134,6 @@ export async function confirmReceipt({
// Auto-update inventory for delivered quantities
const siteId =
(po as typeof po & { siteId?: string | null }).siteId ??
- po.vessel?.site?.id ??
null;
if (siteId) {
diff --git a/App/app/(portal)/po/import/actions.ts b/App/app/(portal)/po/import/actions.ts
index bb65a48..17200e1 100644
--- a/App/app/(portal)/po/import/actions.ts
+++ b/App/app/(portal)/po/import/actions.ts
@@ -9,7 +9,7 @@ import type { ParsedImportLine } from "@/app/api/po/import/route";
export type ImportPoInput = {
title: string;
- costCentreRef: string;
+ vesselId: string;
accountId: string;
vendorId?: string;
piQuotationNo?: string;
@@ -32,9 +32,6 @@ export async function importPo(
return { error: "You do not have permission to import purchase orders." };
}
- const importVesselId = input.costCentreRef.startsWith("v:") ? input.costCentreRef.slice(2) : null;
- const importSiteId = input.costCentreRef.startsWith("s:") ? input.costCentreRef.slice(2) : null;
-
const total = input.lineItems.reduce(
(sum, item) => sum + item.quantity * item.unitPrice * (1 + (item.gstRate ?? 0.18)),
0
@@ -47,8 +44,7 @@ export async function importPo(
status: "DRAFT",
totalAmount: total,
currency: "INR",
- vesselId: importVesselId,
- siteId: importSiteId,
+ vesselId: input.vesselId,
accountId: input.accountId,
vendorId: input.vendorId ?? null,
piQuotationNo: input.piQuotationNo ?? null,
diff --git a/App/app/(portal)/po/import/import-form.tsx b/App/app/(portal)/po/import/import-form.tsx
index 64e151f..68ad3a3 100644
--- a/App/app/(portal)/po/import/import-form.tsx
+++ b/App/app/(portal)/po/import/import-form.tsx
@@ -3,7 +3,7 @@
import { useState, useRef } from "react";
import { useRouter } from "next/navigation";
import type { Vendor } from "@prisma/client";
-import type { CostCentreGroup, AccountGroup } from "@/app/(portal)/po/new/new-po-form";
+import type { VesselOption, AccountGroup } from "@/app/(portal)/po/new/new-po-form";
import { SearchableSelect } from "@/components/ui/searchable-select";
import { importPo } from "./actions";
import type { ParsedImport } from "@/app/api/po/import/route";
@@ -13,7 +13,7 @@ const INPUT_CLS =
"w-full rounded-lg border border-neutral-300 px-3 py-2.5 text-sm focus:border-primary-500 focus:outline-none focus:ring-2 focus:ring-primary-500/20";
interface Props {
- costCentres: CostCentreGroup[];
+ vessels: VesselOption[];
accounts: AccountGroup[];
vendors: Vendor[];
}
@@ -21,12 +21,12 @@ interface Props {
type PreviewState = {
parsed: ParsedImport;
title: string;
- costCentreRef: string;
+ vesselId: string;
accountId: string;
vendorId: string;
};
-export function ImportForm({ costCentres, accounts, vendors }: Props) {
+export function ImportForm({ vessels, accounts, vendors }: Props) {
const router = useRouter();
const fileRef = useRef(null);
const [parsing, setParsing] = useState(false);
@@ -66,7 +66,7 @@ export function ImportForm({ costCentres, accounts, vendors }: Props) {
title: parsed.vendorName
? `${parsed.vendorName} — Import`
: "Imported Purchase Order",
- costCentreRef: costCentres[0]?.siteRef ?? costCentres[0]?.vessels[0]?.ref ?? "",
+ vesselId: vessels[0]?.id ?? "",
accountId: accounts[0]?.items[0]?.id ?? "",
vendorId: matchedVendor?.id ?? "",
});
@@ -85,7 +85,7 @@ export function ImportForm({ costCentres, accounts, vendors }: Props) {
const result = await importPo({
title: preview.title,
- costCentreRef: preview.costCentreRef,
+ vesselId: preview.vesselId,
accountId: preview.accountId,
vendorId: preview.vendorId || undefined,
piQuotationNo: preview.parsed.piQuotationNo || undefined,
@@ -184,21 +184,14 @@ export function ImportForm({ costCentres, accounts, vendors }: Props) {
Cost Centre *
setPreview({ ...preview, costCentreRef: e.target.value })}
+ value={preview.vesselId}
+ onChange={(e) => setPreview({ ...preview, vesselId: e.target.value })}
required
className={INPUT_CLS}
>
- {costCentres.map((group) => (
-
+ {vessels.map((v) => (
+
))}
@@ -295,7 +288,7 @@ export function ImportForm({ costCentres, accounts, vendors }: Props) {
|