chore: upload parte 1 - logica
DevSecOps Enterprise Pipeline / security-gate-and-deploy (push) Failing after 41s
DevSecOps Enterprise Pipeline / security-gate-and-deploy (push) Failing after 41s
This commit is contained in:
@@ -0,0 +1,679 @@
|
||||
"use client";
|
||||
|
||||
import { useState, useEffect } from "react";
|
||||
import { useParams, useRouter } from "next/navigation";
|
||||
import useSWR from "swr";
|
||||
import {
|
||||
Card,
|
||||
CardContent,
|
||||
CardHeader,
|
||||
CardTitle,
|
||||
} from "@/components/ui/card";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "@/components/ui/select";
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableHead,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from "@/components/ui/table";
|
||||
import { Progress } from "@/components/ui/progress";
|
||||
import { ArrowLeft, Plus, Trash2, Package, Save, Euro, Layers, Truck, FileDown } from "lucide-react";
|
||||
import { toast } from "sonner";
|
||||
import { formatCurrency } from "@/lib/format";
|
||||
import type { Product, PurchaseOrder, PurchaseOrderItem } from "@/lib/types";
|
||||
|
||||
const fetcher = (url: string) => fetch(url).then((r) => r.json());
|
||||
|
||||
interface OrderLineItem {
|
||||
product_id: string;
|
||||
quantity: string;
|
||||
unit_price: string;
|
||||
notes: string;
|
||||
}
|
||||
|
||||
const statusConfig: Record<string, { label: string; variant: "default" | "secondary" | "destructive" | "outline" }> = {
|
||||
draft: { label: "Draft", variant: "secondary" },
|
||||
confirmed: { label: "Confirmed", variant: "default" },
|
||||
in_production: { label: "In Production", variant: "outline" },
|
||||
shipped: { label: "Shipped", variant: "default" },
|
||||
completed: { label: "Completed", variant: "default" },
|
||||
cancelled: { label: "Cancelled", variant: "destructive" },
|
||||
};
|
||||
|
||||
export default function OrderDetailPage() {
|
||||
const params = useParams();
|
||||
const router = useRouter();
|
||||
const customerId = params.id as string;
|
||||
const orderId = params.orderId as string;
|
||||
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [editing, setEditing] = useState(false);
|
||||
|
||||
const [form, setForm] = useState({
|
||||
po_number: "",
|
||||
customer_ref: "",
|
||||
status: "draft",
|
||||
order_date: "",
|
||||
due_date: "",
|
||||
notes: "",
|
||||
});
|
||||
|
||||
const [items, setItems] = useState<OrderLineItem[]>([]);
|
||||
|
||||
const { data: orderData, mutate } = useSWR<
|
||||
PurchaseOrder & { items: PurchaseOrderItem[] }
|
||||
>(`/api/orders/${orderId}`, fetcher);
|
||||
|
||||
const { data: products = [] } = useSWR<Product[]>("/api/products", fetcher);
|
||||
|
||||
useEffect(() => {
|
||||
if (orderData) {
|
||||
setForm({
|
||||
po_number: orderData.po_number || "",
|
||||
customer_ref: orderData.customer_ref || "",
|
||||
status: orderData.status || "draft",
|
||||
order_date: orderData.order_date
|
||||
? new Date(orderData.order_date).toISOString().slice(0, 10)
|
||||
: "",
|
||||
due_date: orderData.due_date
|
||||
? new Date(orderData.due_date).toISOString().slice(0, 10)
|
||||
: "",
|
||||
notes: orderData.notes || "",
|
||||
});
|
||||
setItems(
|
||||
(orderData.items || []).map((item) => ({
|
||||
product_id: String(item.product_id),
|
||||
quantity: String(item.quantity),
|
||||
unit_price: String(item.unit_price),
|
||||
notes: item.notes || "",
|
||||
}))
|
||||
);
|
||||
}
|
||||
}, [orderData]);
|
||||
|
||||
function addLine() {
|
||||
setItems([
|
||||
...items,
|
||||
{ product_id: "", quantity: "1", unit_price: "", notes: "" },
|
||||
]);
|
||||
}
|
||||
|
||||
function removeLine(index: number) {
|
||||
if (items.length <= 1) return;
|
||||
setItems(items.filter((_, i) => i !== index));
|
||||
}
|
||||
|
||||
function updateLine(index: number, field: keyof OrderLineItem, value: string) {
|
||||
const updated = [...items];
|
||||
updated[index] = { ...updated[index], [field]: value };
|
||||
setItems(updated);
|
||||
}
|
||||
|
||||
function getLineTotal(item: OrderLineItem) {
|
||||
return (Number(item.quantity) || 0) * (Number(item.unit_price) || 0);
|
||||
}
|
||||
|
||||
const orderTotal = items.reduce((sum, item) => sum + getLineTotal(item), 0);
|
||||
|
||||
async function handleDownloadPO() {
|
||||
if (!orderData) return;
|
||||
const { generatePoPdf } = await import("@/lib/generate-po-pdf");
|
||||
const doc = generatePoPdf({
|
||||
po_number: orderData.po_number,
|
||||
order_date: orderData.order_date,
|
||||
due_date: orderData.due_date,
|
||||
customer_ref: orderData.customer_ref,
|
||||
status: orderData.status,
|
||||
customer_name: orderData.customer_name || "",
|
||||
customer_code: orderData.customer_code || "",
|
||||
customer_email: (orderData as Record<string, unknown>).customer_email as string | null,
|
||||
customer_phone: (orderData as Record<string, unknown>).customer_phone as string | null,
|
||||
customer_address: (orderData as Record<string, unknown>).customer_address as string | null,
|
||||
customer_contact: (orderData as Record<string, unknown>).customer_contact as string | null,
|
||||
notes: orderData.notes,
|
||||
items: (orderData.items || []).map((item) => ({
|
||||
product_name: item.product_name || "",
|
||||
product_sku: item.product_sku || "",
|
||||
quantity: Number(item.quantity),
|
||||
unit_price: Number(item.unit_price),
|
||||
line_total: Number(item.line_total || 0),
|
||||
notes: item.notes,
|
||||
})),
|
||||
});
|
||||
doc.save(`${orderData.po_number}.pdf`);
|
||||
}
|
||||
|
||||
async function handleSave() {
|
||||
setLoading(true);
|
||||
try {
|
||||
const validItems = items.filter((item) => item.product_id);
|
||||
const res = await fetch(`/api/orders/${orderId}`, {
|
||||
method: "PUT",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
customer_id: Number(customerId),
|
||||
...form,
|
||||
due_date: form.due_date || null,
|
||||
items: validItems.map((item) => ({
|
||||
product_id: Number(item.product_id),
|
||||
quantity: Number(item.quantity) || 1,
|
||||
unit_price: Number(item.unit_price) || 0,
|
||||
notes: item.notes || null,
|
||||
})),
|
||||
}),
|
||||
});
|
||||
|
||||
if (!res.ok) throw new Error("Failed to update");
|
||||
toast.success("Purchase order updated");
|
||||
mutate();
|
||||
setEditing(false);
|
||||
} catch {
|
||||
toast.error("Failed to update order");
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
if (!orderData) {
|
||||
return (
|
||||
<div className="flex items-center justify-center p-12">
|
||||
<p className="text-muted-foreground">Loading order...</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const sc = statusConfig[orderData.status] || statusConfig.draft;
|
||||
|
||||
// VIEW MODE
|
||||
if (!editing) {
|
||||
return (
|
||||
<div className="flex flex-col gap-6 p-6">
|
||||
<div className="flex items-start justify-between">
|
||||
<div className="flex items-center gap-4">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
onClick={() => router.push(`/customers/${customerId}`)}
|
||||
>
|
||||
<ArrowLeft className="h-4 w-4" />
|
||||
</Button>
|
||||
<div>
|
||||
<div className="flex items-center gap-3">
|
||||
<h1 className="text-2xl font-bold tracking-tight font-mono text-foreground">
|
||||
{orderData.po_number}
|
||||
</h1>
|
||||
<Badge variant={sc.variant}>{sc.label}</Badge>
|
||||
</div>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Order for {orderData.customer_name} ({orderData.customer_code})
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Button variant="outline" size="sm" onClick={handleDownloadPO}>
|
||||
<FileDown className="mr-2 h-3.5 w-3.5" />
|
||||
Download PO
|
||||
</Button>
|
||||
<Button variant="outline" size="sm" onClick={() => setEditing(true)}>
|
||||
Edit Order
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Summary Cards */}
|
||||
{(() => {
|
||||
const itemsList = orderData.items || [];
|
||||
const totalOrdered = itemsList.reduce((s, i) => s + Number(i.quantity), 0);
|
||||
const totalShipped = itemsList.reduce((s, i) => s + Number(i.shipped_quantity || 0), 0);
|
||||
const totalRemaining = totalOrdered - totalShipped;
|
||||
const fulfillmentPct = totalOrdered > 0 ? Math.round((totalShipped / totalOrdered) * 100) : 0;
|
||||
const isOverdue = orderData.due_date && new Date(orderData.due_date) < new Date() && fulfillmentPct < 100;
|
||||
|
||||
return (
|
||||
<div className="grid grid-cols-1 gap-4 md:grid-cols-5">
|
||||
<Card>
|
||||
<CardHeader className="flex flex-row items-center justify-between pb-2">
|
||||
<CardTitle className="text-sm font-medium text-muted-foreground">
|
||||
Order Date
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<p className="text-lg font-semibold">
|
||||
{new Date(orderData.order_date).toLocaleDateString()}
|
||||
</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<Card>
|
||||
<CardHeader className="flex flex-row items-center justify-between pb-2">
|
||||
<CardTitle className="text-sm font-medium text-muted-foreground">
|
||||
Due Date
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<p className={`text-lg font-semibold ${isOverdue ? "text-destructive" : ""}`}>
|
||||
{orderData.due_date
|
||||
? new Date(orderData.due_date).toLocaleDateString()
|
||||
: "Not set"}
|
||||
{isOverdue && (
|
||||
<span className="ml-1 text-xs font-normal">(overdue)</span>
|
||||
)}
|
||||
</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<Card>
|
||||
<CardHeader className="flex flex-row items-center justify-between pb-2">
|
||||
<CardTitle className="text-sm font-medium text-muted-foreground">
|
||||
Order Total
|
||||
</CardTitle>
|
||||
<Euro className="h-4 w-4 text-accent" />
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<p className="text-2xl font-bold">
|
||||
{formatCurrency(
|
||||
itemsList.reduce((s, i) => s + Number(i.line_total || 0), 0)
|
||||
)}
|
||||
</p>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{itemsList.length} line item{itemsList.length !== 1 ? "s" : ""}
|
||||
</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<Card>
|
||||
<CardHeader className="flex flex-row items-center justify-between pb-2">
|
||||
<CardTitle className="text-sm font-medium text-muted-foreground">
|
||||
Units Remaining
|
||||
</CardTitle>
|
||||
<Package className="h-4 w-4 text-primary" />
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<p className="text-2xl font-bold font-mono">
|
||||
<span className={totalRemaining > 0 ? "text-foreground" : "text-accent"}>
|
||||
{totalRemaining}
|
||||
</span>
|
||||
<span className="text-sm font-normal text-muted-foreground ml-1">
|
||||
/ {totalOrdered}
|
||||
</span>
|
||||
</p>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{totalShipped} shipped
|
||||
</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<Card>
|
||||
<CardHeader className="flex flex-row items-center justify-between pb-2">
|
||||
<CardTitle className="text-sm font-medium text-muted-foreground">
|
||||
Fulfillment
|
||||
</CardTitle>
|
||||
<Truck className="h-4 w-4 text-primary" />
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<p className={`text-2xl font-bold font-mono ${fulfillmentPct === 100 ? "text-accent" : ""}`}>
|
||||
{fulfillmentPct}%
|
||||
</p>
|
||||
<Progress value={fulfillmentPct} className="mt-2 h-2" />
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
})()}
|
||||
|
||||
{orderData.customer_ref && (
|
||||
<div className="text-sm text-muted-foreground">
|
||||
Customer Reference:{" "}
|
||||
<span className="font-mono font-medium text-foreground">
|
||||
{orderData.customer_ref}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{orderData.notes && (
|
||||
<Card>
|
||||
<CardContent className="p-4 text-sm text-muted-foreground">
|
||||
{orderData.notes}
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
|
||||
{/* Line Items Table */}
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="flex items-center gap-2 text-base">
|
||||
<Package className="h-4 w-4 text-primary" />
|
||||
Order Items
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="p-0">
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>#</TableHead>
|
||||
<TableHead>Product</TableHead>
|
||||
<TableHead>SKU</TableHead>
|
||||
<TableHead className="text-right">Ordered</TableHead>
|
||||
<TableHead className="text-right">Shipped</TableHead>
|
||||
<TableHead className="text-right">Remaining</TableHead>
|
||||
<TableHead className="w-[120px]">Fulfillment</TableHead>
|
||||
<TableHead className="text-right">Unit Price</TableHead>
|
||||
<TableHead className="text-right">Line Total</TableHead>
|
||||
<TableHead>Notes</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{(orderData.items || []).map(
|
||||
(item: PurchaseOrderItem, idx: number) => {
|
||||
const ordered = Number(item.quantity);
|
||||
const shipped = Number(item.shipped_quantity || 0);
|
||||
const remaining = ordered - shipped;
|
||||
const pct = ordered > 0 ? Math.round((shipped / ordered) * 100) : 0;
|
||||
|
||||
return (
|
||||
<TableRow key={item.id}>
|
||||
<TableCell className="text-xs text-muted-foreground">
|
||||
{idx + 1}
|
||||
</TableCell>
|
||||
<TableCell className="font-medium">
|
||||
{item.product_name}
|
||||
</TableCell>
|
||||
<TableCell className="font-mono text-xs text-muted-foreground">
|
||||
{item.product_sku}
|
||||
</TableCell>
|
||||
<TableCell className="text-right font-mono">
|
||||
{ordered.toLocaleString()}
|
||||
</TableCell>
|
||||
<TableCell className="text-right font-mono">
|
||||
{shipped.toLocaleString()}
|
||||
</TableCell>
|
||||
<TableCell className="text-right font-mono font-semibold">
|
||||
<span className={remaining > 0 ? "text-foreground" : "text-accent"}>
|
||||
{remaining.toLocaleString()}
|
||||
</span>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<div className="flex flex-col gap-1">
|
||||
<div className="flex items-center justify-between text-xs">
|
||||
<span className="font-mono text-muted-foreground">
|
||||
{shipped}/{ordered}
|
||||
</span>
|
||||
<span className={pct === 100 ? "font-semibold text-accent" : "text-muted-foreground"}>
|
||||
{pct}%
|
||||
</span>
|
||||
</div>
|
||||
<Progress value={pct} className="h-1.5" />
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCell className="text-right font-mono">
|
||||
{formatCurrency(Number(item.unit_price))}
|
||||
</TableCell>
|
||||
<TableCell className="text-right font-mono font-semibold">
|
||||
{formatCurrency(Number(item.line_total || 0))}
|
||||
</TableCell>
|
||||
<TableCell className="text-xs text-muted-foreground">
|
||||
{item.notes || "-"}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
);
|
||||
}
|
||||
)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// EDIT MODE
|
||||
return (
|
||||
<div className="flex flex-col gap-6 p-6">
|
||||
<div className="flex items-center gap-4">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
onClick={() => setEditing(false)}
|
||||
>
|
||||
<ArrowLeft className="h-4 w-4" />
|
||||
</Button>
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold tracking-tight text-foreground">
|
||||
Edit Purchase Order
|
||||
</h1>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{orderData.po_number} - {orderData.customer_name}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="text-base">Order Details</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="flex flex-col gap-4">
|
||||
<div className="grid grid-cols-1 gap-4 md:grid-cols-3">
|
||||
<div className="flex flex-col gap-2">
|
||||
<Label htmlFor="po_number">PO Number</Label>
|
||||
<Input
|
||||
id="po_number"
|
||||
value={form.po_number}
|
||||
onChange={(e) =>
|
||||
setForm({ ...form, po_number: e.target.value })
|
||||
}
|
||||
className="font-mono"
|
||||
/>
|
||||
</div>
|
||||
<div className="flex flex-col gap-2">
|
||||
<Label htmlFor="customer_ref">Customer Reference</Label>
|
||||
<Input
|
||||
id="customer_ref"
|
||||
value={form.customer_ref}
|
||||
onChange={(e) =>
|
||||
setForm({ ...form, customer_ref: e.target.value })
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex flex-col gap-2">
|
||||
<Label htmlFor="status">Status</Label>
|
||||
<Select
|
||||
value={form.status}
|
||||
onValueChange={(v) => setForm({ ...form, status: v })}
|
||||
>
|
||||
<SelectTrigger id="status">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="draft">Draft</SelectItem>
|
||||
<SelectItem value="confirmed">Confirmed</SelectItem>
|
||||
<SelectItem value="in_production">In Production</SelectItem>
|
||||
<SelectItem value="shipped">Shipped</SelectItem>
|
||||
<SelectItem value="completed">Completed</SelectItem>
|
||||
<SelectItem value="cancelled">Cancelled</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
</div>
|
||||
<div className="grid grid-cols-1 gap-4 md:grid-cols-3">
|
||||
<div className="flex flex-col gap-2">
|
||||
<Label htmlFor="order_date">Order Date</Label>
|
||||
<Input
|
||||
id="order_date"
|
||||
type="date"
|
||||
value={form.order_date}
|
||||
onChange={(e) =>
|
||||
setForm({ ...form, order_date: e.target.value })
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex flex-col gap-2">
|
||||
<Label htmlFor="due_date">Due Date</Label>
|
||||
<Input
|
||||
id="due_date"
|
||||
type="date"
|
||||
value={form.due_date}
|
||||
onChange={(e) =>
|
||||
setForm({ ...form, due_date: e.target.value })
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex flex-col gap-2">
|
||||
<Label htmlFor="notes">Notes</Label>
|
||||
<Textarea
|
||||
id="notes"
|
||||
value={form.notes}
|
||||
onChange={(e) => setForm({ ...form, notes: e.target.value })}
|
||||
rows={2}
|
||||
/>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* Line Items */}
|
||||
<Card>
|
||||
<CardHeader className="flex flex-row items-center justify-between">
|
||||
<CardTitle className="flex items-center gap-2 text-base">
|
||||
<Package className="h-4 w-4 text-primary" />
|
||||
Line Items
|
||||
</CardTitle>
|
||||
<Button type="button" variant="outline" size="sm" onClick={addLine}>
|
||||
<Plus className="mr-2 h-3.5 w-3.5" />
|
||||
Add Line
|
||||
</Button>
|
||||
</CardHeader>
|
||||
<CardContent className="p-0">
|
||||
<div className="overflow-x-auto">
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead className="w-[40px]">#</TableHead>
|
||||
<TableHead>Product</TableHead>
|
||||
<TableHead className="w-[120px]">Quantity</TableHead>
|
||||
<TableHead className="w-[140px]">Unit Price</TableHead>
|
||||
<TableHead className="w-[140px] text-right">
|
||||
Line Total
|
||||
</TableHead>
|
||||
<TableHead>Notes</TableHead>
|
||||
<TableHead className="w-[50px]" />
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{items.map((item, index) => (
|
||||
<TableRow key={index}>
|
||||
<TableCell className="text-center text-xs text-muted-foreground">
|
||||
{index + 1}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Select
|
||||
value={item.product_id}
|
||||
onValueChange={(v) =>
|
||||
updateLine(index, "product_id", v)
|
||||
}
|
||||
>
|
||||
<SelectTrigger className="h-9">
|
||||
<SelectValue placeholder="Select product..." />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{products.map((p) => (
|
||||
<SelectItem key={p.id} value={String(p.id)}>
|
||||
<span className="font-mono text-xs text-muted-foreground mr-2">
|
||||
{p.sku}
|
||||
</span>
|
||||
{p.name}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Input
|
||||
type="number"
|
||||
min="1"
|
||||
value={item.quantity}
|
||||
onChange={(e) =>
|
||||
updateLine(index, "quantity", e.target.value)
|
||||
}
|
||||
className="h-9 font-mono"
|
||||
/>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<div className="relative">
|
||||
<span className="absolute left-3 top-1/2 -translate-y-1/2 text-xs text-muted-foreground">
|
||||
{'€'}
|
||||
</span>
|
||||
<Input
|
||||
type="number"
|
||||
step="0.01"
|
||||
min="0"
|
||||
value={item.unit_price}
|
||||
onChange={(e) =>
|
||||
updateLine(index, "unit_price", e.target.value)
|
||||
}
|
||||
className="h-9 pl-7 font-mono"
|
||||
/>
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCell className="text-right font-mono text-sm font-semibold">
|
||||
{formatCurrency(getLineTotal(item))}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Input
|
||||
value={item.notes}
|
||||
onChange={(e) =>
|
||||
updateLine(index, "notes", e.target.value)
|
||||
}
|
||||
placeholder="Optional"
|
||||
className="h-9 text-xs"
|
||||
/>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-8 w-8 text-destructive hover:text-destructive"
|
||||
onClick={() => removeLine(index)}
|
||||
disabled={items.length <= 1}
|
||||
>
|
||||
<Trash2 className="h-3.5 w-3.5" />
|
||||
</Button>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
<TableRow className="bg-muted/50">
|
||||
<TableCell colSpan={4} className="text-right font-semibold">
|
||||
Order Total
|
||||
</TableCell>
|
||||
<TableCell className="text-right font-mono text-base font-bold text-primary">
|
||||
{formatCurrency(orderTotal)}
|
||||
</TableCell>
|
||||
<TableCell colSpan={2} />
|
||||
</TableRow>
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<div className="flex justify-end gap-3">
|
||||
<Button variant="outline" onClick={() => setEditing(false)}>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button onClick={handleSave} disabled={loading}>
|
||||
<Save className="mr-2 h-4 w-4" />
|
||||
{loading ? "Saving..." : "Save Changes"}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user