Files
inven/app/purchase-orders/page.tsx

85 lines
4.0 KiB
TypeScript
Raw Normal View History

2026-03-23 16:56:23 -05:00
import { receivePurchaseOrder } from "@/lib/actions";
import { PurchaseOrderCreateForm } from "@/components/purchase-order-create-form";
2026-03-23 16:16:45 -05:00
import { formatCurrency, formatDate } from "@/lib/format";
2026-03-23 16:56:23 -05:00
import { getLowStockParts, getOrderItemOptions, getPurchaseOrders, getVendors } from "@/lib/repository";
2026-03-23 16:16:45 -05:00
export default function PurchaseOrdersPage() {
const vendors = getVendors();
2026-03-23 16:56:23 -05:00
const items = getOrderItemOptions();
2026-03-23 16:16:45 -05:00
const orders = getPurchaseOrders();
const lowStockParts = getLowStockParts();
return (
<div className="grid">
<section className="two-up">
<article className="panel">
<h2 className="section-title">Create Purchase Order</h2>
2026-03-23 16:56:23 -05:00
<p className="section-copy">Build the PO from real inventory items so receipts, costing, and restocking stay relational.</p>
<PurchaseOrderCreateForm vendors={vendors} items={items} />
2026-03-23 16:16:45 -05:00
</article>
<article className="panel">
<h2 className="section-title">Receiving Flow</h2>
<p className="section-copy">Leave line quantities blank to receive the remaining balance, or enter `SKU,quantity` rows for a partial receipt.</p>
<div className="table-wrap">
<table className="table">
<thead><tr><th>Order</th><th>Vendor</th><th>Status</th><th>Total</th><th>Qty Progress</th><th>Created</th><th>Action</th></tr></thead>
<tbody>
{orders.length === 0 ? (
<tr><td colSpan={7} className="muted">No purchase orders yet.</td></tr>
) : (
orders.map((order) => (
<tr key={order.id}>
<td>{order.orderNumber}</td>
<td>{order.vendorName}</td>
<td><span className={`pill ${order.status === "received" ? "" : "warning"}`}>{order.status}</span></td>
<td>{formatCurrency(order.totalAmount)}</td>
<td>{order.fulfilledQuantity} / {order.orderedQuantity}</td>
<td>{formatDate(order.createdAt)}</td>
<td>
{order.status === "received" ? (
<span className="muted">Received</span>
) : (
<form action={receivePurchaseOrder} className="form-grid">
<input type="hidden" name="orderId" value={order.id} />
<textarea className="textarea" name="lines" placeholder={"PART-001,4\nPART-002,10"} />
<button className="button secondary" type="submit">Receive</button>
</form>
)}
</td>
</tr>
))
)}
</tbody>
</table>
</div>
</article>
</section>
<section className="panel">
<h2 className="section-title">Restock Recommendations</h2>
<p className="section-copy">Use this list to plan the next purchase order from items already below target.</p>
<div className="table-wrap">
<table className="table">
<thead><tr><th>SKU</th><th>Name</th><th>On Hand</th><th>Reorder Point</th><th>Suggested Qty</th><th>Last Vendor</th></tr></thead>
<tbody>
{lowStockParts.length === 0 ? (
<tr><td colSpan={6} className="muted">No parts currently need restocking.</td></tr>
) : (
lowStockParts.map((part) => (
<tr key={part.id}>
<td>{part.sku}</td>
<td>{part.name}</td>
<td>{part.quantityOnHand} {part.unitOfMeasure}</td>
<td>{part.reorderPoint}</td>
<td>{part.suggestedReorderQuantity}</td>
<td>{part.preferredVendorName || "-"}</td>
</tr>
))
)}
</tbody>
</table>
</div>
</section>
</div>
);
}