2025-09-13 03:50:57 +07:00
|
|
|
'use client'
|
|
|
|
|
|
2025-09-10 03:23:54 +07:00
|
|
|
import React from 'react'
|
|
|
|
|
import {
|
|
|
|
|
Card,
|
|
|
|
|
CardHeader,
|
|
|
|
|
CardContent,
|
|
|
|
|
Typography,
|
|
|
|
|
Table,
|
|
|
|
|
TableBody,
|
|
|
|
|
TableCell,
|
|
|
|
|
TableContainer,
|
|
|
|
|
TableHead,
|
|
|
|
|
TableRow,
|
|
|
|
|
Box,
|
|
|
|
|
Button,
|
|
|
|
|
IconButton
|
|
|
|
|
} from '@mui/material'
|
|
|
|
|
import Grid from '@mui/material/Grid2'
|
2025-09-13 03:50:57 +07:00
|
|
|
import { PurchaseOrder } from '@/types/services/purchaseOrder'
|
2025-09-10 03:23:54 +07:00
|
|
|
|
2025-09-13 03:50:57 +07:00
|
|
|
interface Props {
|
|
|
|
|
data?: PurchaseOrder
|
2025-09-10 03:23:54 +07:00
|
|
|
}
|
|
|
|
|
|
2025-09-13 03:50:57 +07:00
|
|
|
const PurchaseDetailInformation = ({ data }: Props) => {
|
|
|
|
|
const purchaseOrder = data
|
|
|
|
|
|
|
|
|
|
// Helper functions
|
|
|
|
|
const formatDate = (dateString: string): string => {
|
|
|
|
|
const date = new Date(dateString)
|
|
|
|
|
return date.toLocaleDateString('id-ID', {
|
|
|
|
|
day: '2-digit',
|
|
|
|
|
month: '2-digit',
|
|
|
|
|
year: 'numeric'
|
|
|
|
|
})
|
|
|
|
|
}
|
2025-09-10 03:23:54 +07:00
|
|
|
|
2025-09-13 03:50:57 +07:00
|
|
|
const formatCurrency = (amount: number): string => {
|
|
|
|
|
return new Intl.NumberFormat('id-ID').format(amount)
|
2025-09-10 03:23:54 +07:00
|
|
|
}
|
|
|
|
|
|
2025-09-13 03:50:57 +07:00
|
|
|
const getStatusLabel = (status: string): string => {
|
|
|
|
|
const statusMap: Record<string, string> = {
|
|
|
|
|
draft: 'Draft',
|
|
|
|
|
sent: 'Dikirim',
|
|
|
|
|
approved: 'Disetujui',
|
|
|
|
|
received: 'Diterima',
|
|
|
|
|
cancelled: 'Dibatalkan'
|
2025-09-10 03:23:54 +07:00
|
|
|
}
|
2025-09-13 03:50:57 +07:00
|
|
|
return statusMap[status] || status
|
|
|
|
|
}
|
2025-09-10 03:23:54 +07:00
|
|
|
|
2025-09-13 03:50:57 +07:00
|
|
|
const getStatusColor = (status: string): 'error' | 'success' | 'warning' | 'info' | 'default' => {
|
|
|
|
|
const colorMap: Record<string, 'error' | 'success' | 'warning' | 'info' | 'default'> = {
|
|
|
|
|
draft: 'default',
|
|
|
|
|
sent: 'warning',
|
|
|
|
|
approved: 'success',
|
|
|
|
|
received: 'info',
|
|
|
|
|
cancelled: 'error'
|
|
|
|
|
}
|
|
|
|
|
return colorMap[status] || 'info'
|
2025-09-10 03:23:54 +07:00
|
|
|
}
|
|
|
|
|
|
2025-09-13 03:50:57 +07:00
|
|
|
// Calculations
|
|
|
|
|
const totalQuantity = (purchaseOrder?.items ?? []).reduce((sum, item) => sum + (item?.quantity ?? 0), 0)
|
|
|
|
|
const total = (purchaseOrder?.items ?? []).reduce((sum, item) => sum + (item?.amount ?? 0) * item?.quantity, 0)
|
|
|
|
|
|
2025-09-10 03:23:54 +07:00
|
|
|
return (
|
|
|
|
|
<Card sx={{ width: '100%' }}>
|
|
|
|
|
<CardHeader
|
|
|
|
|
title={
|
|
|
|
|
<Box display='flex' justifyContent='space-between' alignItems='center'>
|
2025-09-13 03:50:57 +07:00
|
|
|
<Typography variant='h5' color={getStatusColor(purchaseOrder?.status ?? '')} sx={{ fontWeight: 'bold' }}>
|
|
|
|
|
{getStatusLabel(purchaseOrder?.status ?? '')}
|
2025-09-10 03:23:54 +07:00
|
|
|
</Typography>
|
|
|
|
|
<Box>
|
|
|
|
|
<Button startIcon={<i className='tabler-share' />} variant='outlined' size='small' sx={{ mr: 1 }}>
|
|
|
|
|
Bagikan
|
|
|
|
|
</Button>
|
|
|
|
|
<Button startIcon={<i className='tabler-printer' />} variant='outlined' size='small' sx={{ mr: 1 }}>
|
|
|
|
|
Print
|
|
|
|
|
</Button>
|
|
|
|
|
<IconButton>
|
|
|
|
|
<i className='tabler-dots-vertical' />
|
|
|
|
|
</IconButton>
|
|
|
|
|
</Box>
|
|
|
|
|
</Box>
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
<CardContent>
|
|
|
|
|
{/* Purchase Information */}
|
|
|
|
|
<Grid container spacing={3} sx={{ mb: 4 }}>
|
|
|
|
|
<Grid size={{ xs: 12, md: 6 }}>
|
|
|
|
|
<Box sx={{ mb: 2 }}>
|
|
|
|
|
<Typography variant='subtitle2' color='text.secondary'>
|
|
|
|
|
Vendor
|
|
|
|
|
</Typography>
|
|
|
|
|
<Typography variant='body1' color='primary' sx={{ fontWeight: 'medium', cursor: 'pointer' }}>
|
2025-09-13 03:50:57 +07:00
|
|
|
{purchaseOrder?.vendor?.name ?? ''}
|
2025-09-10 03:23:54 +07:00
|
|
|
</Typography>
|
|
|
|
|
</Box>
|
|
|
|
|
|
|
|
|
|
<Box>
|
|
|
|
|
<Typography variant='subtitle2' color='text.secondary'>
|
2025-09-13 03:50:57 +07:00
|
|
|
Tgl. Transaksi
|
2025-09-10 03:23:54 +07:00
|
|
|
</Typography>
|
2025-09-13 03:50:57 +07:00
|
|
|
<Typography variant='body1'>{formatDate(purchaseOrder?.transaction_date ?? '')}</Typography>
|
2025-09-10 03:23:54 +07:00
|
|
|
</Box>
|
|
|
|
|
</Grid>
|
|
|
|
|
|
|
|
|
|
<Grid size={{ xs: 12, md: 6 }}>
|
|
|
|
|
<Box sx={{ mb: 2 }}>
|
|
|
|
|
<Typography variant='subtitle2' color='text.secondary'>
|
|
|
|
|
Nomor
|
|
|
|
|
</Typography>
|
2025-09-13 03:50:57 +07:00
|
|
|
<Typography variant='body1'>{purchaseOrder?.po_number}</Typography>
|
2025-09-10 03:23:54 +07:00
|
|
|
</Box>
|
|
|
|
|
|
|
|
|
|
<Box>
|
|
|
|
|
<Typography variant='subtitle2' color='text.secondary'>
|
|
|
|
|
Tgl. Jatuh Tempo
|
|
|
|
|
</Typography>
|
2025-09-13 03:50:57 +07:00
|
|
|
<Typography variant='body1'>{formatDate(purchaseOrder?.due_date ?? '')}</Typography>
|
2025-09-10 03:23:54 +07:00
|
|
|
</Box>
|
|
|
|
|
</Grid>
|
|
|
|
|
</Grid>
|
|
|
|
|
|
|
|
|
|
{/* Products Table */}
|
|
|
|
|
<TableContainer>
|
|
|
|
|
<Table>
|
|
|
|
|
<TableHead>
|
|
|
|
|
<TableRow>
|
|
|
|
|
<TableCell>Produk</TableCell>
|
|
|
|
|
<TableCell>Deskripsi</TableCell>
|
|
|
|
|
<TableCell align='center'>Kuantitas</TableCell>
|
|
|
|
|
<TableCell align='center'>Satuan</TableCell>
|
|
|
|
|
<TableCell align='right'>Harga</TableCell>
|
|
|
|
|
<TableCell align='right'>Jumlah</TableCell>
|
|
|
|
|
</TableRow>
|
|
|
|
|
</TableHead>
|
|
|
|
|
<TableBody>
|
2025-09-13 03:50:57 +07:00
|
|
|
{(purchaseOrder?.items ?? []).map((item, index) => {
|
|
|
|
|
return (
|
|
|
|
|
<TableRow key={item.id}>
|
|
|
|
|
<TableCell>
|
|
|
|
|
<Typography variant='body2' color='primary' sx={{ cursor: 'pointer' }}>
|
|
|
|
|
{item.ingredient.name}
|
|
|
|
|
</Typography>
|
|
|
|
|
</TableCell>
|
|
|
|
|
<TableCell>{item.description}</TableCell>
|
|
|
|
|
<TableCell align='center'>{item.quantity}</TableCell>
|
|
|
|
|
<TableCell align='center'>{item.unit.name}</TableCell>
|
|
|
|
|
<TableCell align='right'>{formatCurrency(item.amount)}</TableCell>
|
|
|
|
|
<TableCell align='right'>{formatCurrency(item.amount * item.quantity)}</TableCell>
|
|
|
|
|
</TableRow>
|
|
|
|
|
)
|
|
|
|
|
})}
|
|
|
|
|
|
|
|
|
|
{/* Total Quantity Row */}
|
2025-09-10 03:23:54 +07:00
|
|
|
<TableRow>
|
|
|
|
|
<TableCell colSpan={2} sx={{ fontWeight: 'bold', borderTop: '2px solid #e0e0e0' }}>
|
|
|
|
|
Total Kuantitas
|
|
|
|
|
</TableCell>
|
|
|
|
|
<TableCell align='center' sx={{ fontWeight: 'bold', borderTop: '2px solid #e0e0e0' }}>
|
2025-09-13 03:50:57 +07:00
|
|
|
{totalQuantity}
|
2025-09-10 03:23:54 +07:00
|
|
|
</TableCell>
|
|
|
|
|
<TableCell sx={{ borderTop: '2px solid #e0e0e0' }}></TableCell>
|
|
|
|
|
<TableCell sx={{ borderTop: '2px solid #e0e0e0' }}></TableCell>
|
|
|
|
|
</TableRow>
|
|
|
|
|
</TableBody>
|
|
|
|
|
</Table>
|
|
|
|
|
</TableContainer>
|
|
|
|
|
|
|
|
|
|
{/* Summary Section */}
|
|
|
|
|
<Box sx={{ mt: 3 }}>
|
|
|
|
|
<Grid container spacing={2}>
|
|
|
|
|
<Grid size={{ xs: 12, md: 6 }}>{/* Empty space for left side */}</Grid>
|
|
|
|
|
<Grid size={{ xs: 12, md: 6 }}>
|
|
|
|
|
<Box sx={{ display: 'flex', flexDirection: 'column' }}>
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
display: 'flex',
|
|
|
|
|
justifyContent: 'space-between',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
py: 2,
|
|
|
|
|
'&:hover': {
|
|
|
|
|
backgroundColor: 'rgba(0, 0, 0, 0.04)',
|
|
|
|
|
transition: 'background-color 0.15s ease'
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Typography variant='h6' sx={{ fontWeight: 'bold' }}>
|
2025-09-13 03:50:57 +07:00
|
|
|
Total
|
2025-09-10 03:23:54 +07:00
|
|
|
</Typography>
|
|
|
|
|
<Typography variant='h6' sx={{ fontWeight: 'bold' }}>
|
2025-09-13 03:50:57 +07:00
|
|
|
{formatCurrency(total)}
|
2025-09-10 03:23:54 +07:00
|
|
|
</Typography>
|
|
|
|
|
</Box>
|
|
|
|
|
</Box>
|
|
|
|
|
</Grid>
|
|
|
|
|
</Grid>
|
|
|
|
|
</Box>
|
|
|
|
|
</CardContent>
|
|
|
|
|
</Card>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default PurchaseDetailInformation
|