diff --git a/src/components/pages/purchase/order/PurchaseOrderDetail.tsx b/src/components/pages/purchase/order/PurchaseOrderDetail.tsx index ab837e03..9e0a70f5 100644 --- a/src/components/pages/purchase/order/PurchaseOrderDetail.tsx +++ b/src/components/pages/purchase/order/PurchaseOrderDetail.tsx @@ -1,18 +1,67 @@ 'use client'; import { useMemo } from 'react'; +import { ColumnDef } from '@tanstack/react-table'; import ApprovalSteps, { formatGroupedApprovalsToApprovalSteps, } from '@/components/pages/ApprovalSteps'; +import Table from '@/components/Table'; import { BaseGroupedApproval } from '@/types/api/api-general'; import { PURCHASE_ORDER_APPROVAL_LINE } from '@/config/approval-line'; +import Card from '@/components/Card'; interface PurchaseOrderDetailProps { type?: 'detail' | 'edit'; } +interface PurchaseOrderItem { + id: number; + product: string; + productType: string; + quantity: number; + unit: string; + unitPrice: number; + total: number; +} + +interface PurchaseOrderInfo { + businessUnit: string; + area: string; + location: string; + warehouse: string; + vendorName: string; + vendorAddress: string; + dueDate: string; + number: string; + poNumber: string; +} + +const dummyPurchaseOrderInfo: PurchaseOrderInfo = { + businessUnit: 'PT MITRA BERLIAN UNGGAS', + area: 'Banten 2', + location: 'FARM PASIR TAPLOK', + warehouse: 'GUDANG PASIR TAPLOK 1', + vendorName: 'PT. CHAROEN POKPHAND JAYA FARM', + vendorAddress: '-', + dueDate: '13-Nov-2025 (1 hari)', + number: 'PR-MBU-01837', + poNumber: 'Belum dibuat', +}; + +const dummyPurchaseOrderItems: PurchaseOrderItem[] = [ + { + id: 1, + product: 'CP Vaksin', + productType: 'DOC', + quantity: 10000, + unit: 'Ekor', + unitPrice: 6500, + total: 65000000, + }, +]; + const dummyGroupedApprovals: BaseGroupedApproval[] = [ { step_number: 1, @@ -113,6 +162,8 @@ const dummyGroupedApprovals: BaseGroupedApproval[] = [ const PurchaseOrderDetail = ({ type = 'detail' }: PurchaseOrderDetailProps) => { // ===== STATIC DATA ===== + const purchaseOrderInfo = dummyPurchaseOrderInfo; + const purchaseOrderItems = dummyPurchaseOrderItems; const groupedApprovals = dummyGroupedApprovals; const latestApproval = groupedApprovals[groupedApprovals.length - 1]?.approvals[0]; @@ -133,16 +184,270 @@ const PurchaseOrderDetail = ({ type = 'detail' }: PurchaseOrderDetailProps) => { } }, [groupedApprovals, latestApproval]); + const totalBeforeTax = useMemo(() => { + return purchaseOrderItems.reduce((sum, item) => sum + item.total, 0); + }, [purchaseOrderItems]); + + const formatCurrency = (value: number) => { + return new Intl.NumberFormat('id-ID', { + style: 'currency', + currency: 'IDR', + minimumFractionDigits: 2, + }).format(value); + }; + + const formatNumber = (value: number) => { + return new Intl.NumberFormat('id-ID').format(value); + }; + + const purchaseOrderColumns: ColumnDef[] = [ + { + accessorKey: 'product', + header: 'Produk', + }, + { + accessorKey: 'productType', + header: 'Jenis Produk', + }, + { + accessorKey: 'quantity', + header: 'Jumlah', + cell: (props) => formatNumber(props.getValue() as number), + }, + { + accessorKey: 'unit', + header: 'Satuan', + }, + { + accessorKey: 'unitPrice', + header: 'Harga Satuan', + cell: (props) => formatCurrency(props.getValue() as number), + }, + { + accessorKey: 'total', + header: 'Total (Rp.)', + cell: (props) => formatCurrency(props.getValue() as number), + }, + ]; + + const summaryData = [ + { + label: 'Total Sebelum Pajak', + value: totalBeforeTax, + }, + { + label: 'Total Pembayaran', + value: totalBeforeTax, + }, + ]; + + const summaryColumns: ColumnDef<(typeof summaryData)[0]>[] = [ + { + accessorKey: 'label', + header: '', + cell: (props) => ( + + {props.getValue() as string} + + ), + }, + { + accessorKey: 'value', + header: '', + cell: (props) => ( + + {formatCurrency(props.getValue() as number)} + + ), + }, + ]; + return (
{/* Steps */} {approvalSteps.length > 0 ? ( - +
+ +
) : (

Status approval tidak tersedia

)} + + {/* Detail Purchase Order */} + + {/* Order Information */} +
+

+ Informasi Pesanan +

+
+ {/* Kolom 1 */} +
+
+
+ + Unit Bisnis + + + {purchaseOrderInfo.businessUnit} + +
+
+
+
+ + Area + + + {purchaseOrderInfo.area} + +
+
+
+
+ + Lokasi + + + {purchaseOrderInfo.location} + +
+
+
+
+ + Gudang Penyimpanan + + + {purchaseOrderInfo.warehouse} + +
+
+
+ + {/* Kolom 2 */} +
+
+
+ + Nama Vendor + + + {purchaseOrderInfo.vendorName} + +
+
+
+
+ + Alamat Vendor + + + {purchaseOrderInfo.vendorAddress} + +
+
+
+
+ + Tgl. Jatuh Tempo + + + {purchaseOrderInfo.dueDate} + +
+
+
+
+ + Nomor + + + {purchaseOrderInfo.number} + +
+
+
+
+ + Nomor PO + + + {purchaseOrderInfo.poNumber} + +
+
+
+
+
+ + {/* Item Pembelian Section */} +
+

+ Item Pembelian +

+
+ {/* Product Table */} +
+ + data={purchaseOrderItems} + columns={purchaseOrderColumns} + isLoading={false} + className={{ + containerClassName: 'm-0', + tableWrapperClassName: 'overflow-x-auto', + tableClassName: 'w-full table-auto', + headerRowClassName: 'bg-gray-50 border-b border-gray-200', + headerColumnClassName: + 'px-6 py-4 text-sm font-semibold text-gray-700 text-left', + bodyRowClassName: + 'border-b border-gray-100 hover:bg-gray-50 transition-colors', + bodyColumnClassName: 'px-6 py-4 text-sm text-gray-900', + paginationClassName: 'hidden', + }} + /> +
+ + {/* Bottom Section - Catatan dan Total */} +
+ {/* Catatan Section */} +
+

Catatan

+
+
+ + {/* Summary Section */} +
+ + + + + + ); };