feat: include purchase items and total amount in purchase management table

This commit is contained in:
Yoga Pangestu 2026-04-20 22:57:44 +07:00
parent 70e0ba9760
commit f1cda67e23
2 changed files with 41 additions and 1 deletions

View File

@ -18,7 +18,7 @@ class PurchaseController extends Controller
public function index(): Response
{
return Inertia::render('admin/manage/purchase/index', [
'purchases' => Purchase::latest()->get(),
'purchases' => Purchase::with(['items.product'])->latest()->get(),
]);
}

View File

@ -25,6 +25,46 @@ export const getColumns = ({ onDelete }: ColumnProps): ColumnDef<Purchase>[] =>
},
meta: { title: "Tanggal" },
},
{
accessorKey: "items",
header: ({ column }) => (
<DataTableColumnHeader column={column} title="Item" />
),
cell: ({ row }) => {
const purchase = row.original;
const items = purchase.items;
if (!items || !Array.isArray(items) || items.length === 0) {
return <span className="text-muted-foreground text-xs italic">-</span>;
}
return (
<div className="flex flex-col gap-1">
{items.map((item, i) => (
<div key={i} className="text-xs whitespace-nowrap">
<span className="text-muted-foreground">{item.product?.name || 'Produk N/A'}:</span>{' '}
<span className="font-medium text-primary">{item.quantity} x {item.unit_price_formatted}</span>
</div>
))}
</div>
);
},
meta: { title: "Item" },
},
{
accessorKey: "total",
header: ({ column }) => (
<DataTableColumnHeader column={column} title="Total" />
),
cell: ({ row }) => {
return (
<span className="font-bold text-primary">
{row.original.total_formatted}
</span>
);
},
meta: { title: "Total" },
},
{
accessorKey: "note",
header: "Catatan",