update report
This commit is contained in:
parent
d059f31eaa
commit
e551ae7feb
@ -22,10 +22,9 @@ const DailyPOSReport = () => {
|
||||
startDate: new Date(),
|
||||
endDate: new Date()
|
||||
})
|
||||
const [filterType, setFilterType] = useState<'single' | 'range'>('single') // 'single' or 'range'
|
||||
const [filterType, setFilterType] = useState<'single' | 'range'>('single')
|
||||
const [isGeneratingPDF, setIsGeneratingPDF] = useState(false)
|
||||
|
||||
// Use selectedDate for single date filter, or dateRange for range filter
|
||||
const getDateParams = () => {
|
||||
if (filterType === 'single') {
|
||||
return {
|
||||
@ -66,12 +65,10 @@ const DailyPOSReport = () => {
|
||||
setNow(new Date())
|
||||
}, [])
|
||||
|
||||
// Format date for input field (YYYY-MM-DD)
|
||||
const formatDateForInput = (date: Date) => {
|
||||
return date.toISOString().split('T')[0]
|
||||
}
|
||||
|
||||
// Get display text for the report period
|
||||
const getReportPeriodText = () => {
|
||||
if (filterType === 'single') {
|
||||
return `${formatDateDDMMYYYY(selectedDate)} - ${formatDateDDMMYYYY(selectedDate)}`
|
||||
@ -80,13 +77,10 @@ const DailyPOSReport = () => {
|
||||
}
|
||||
}
|
||||
|
||||
// Get report title based on filter type
|
||||
const getReportTitle = () => {
|
||||
if (filterType === 'single') {
|
||||
return 'Laporan Transaksi'
|
||||
} else {
|
||||
const daysDiff = Math.ceil((dateRange.endDate.getTime() - dateRange.startDate.getTime()) / (1000 * 3600 * 24)) + 1
|
||||
// return `Laporan Transaksi ${daysDiff} Hari`
|
||||
return `Laporan Transaksi`
|
||||
}
|
||||
}
|
||||
@ -99,27 +93,17 @@ const DailyPOSReport = () => {
|
||||
return
|
||||
}
|
||||
|
||||
// Set loading state
|
||||
setIsGeneratingPDF(true)
|
||||
|
||||
try {
|
||||
// Import jsPDF dan html2canvas
|
||||
const jsPDF = (await import('jspdf')).default
|
||||
const html2canvas = (await import('html2canvas')).default
|
||||
|
||||
// Pastikan element terlihat penuh
|
||||
const originalOverflow = reportElement.style.overflow
|
||||
reportElement.style.overflow = 'visible'
|
||||
|
||||
// Wait untuk memastikan rendering selesai
|
||||
await new Promise(resolve => setTimeout(resolve, 300))
|
||||
|
||||
console.log('Starting PDF generation...')
|
||||
|
||||
// Update loading message
|
||||
console.log('Capturing content...')
|
||||
|
||||
// Capture canvas dengan setting yang optimal
|
||||
const canvas = await html2canvas(reportElement, {
|
||||
scale: 1.5,
|
||||
useCORS: true,
|
||||
@ -132,18 +116,12 @@ const DailyPOSReport = () => {
|
||||
width: reportElement.scrollWidth,
|
||||
scrollX: 0,
|
||||
scrollY: 0,
|
||||
// Pastikan capture semua content
|
||||
windowWidth: Math.max(reportElement.scrollWidth, window.innerWidth),
|
||||
windowHeight: Math.max(reportElement.scrollHeight, window.innerHeight)
|
||||
})
|
||||
|
||||
console.log('Canvas captured:', canvas.width, 'x', canvas.height)
|
||||
console.log('Generating PDF pages...')
|
||||
|
||||
// Restore overflow
|
||||
reportElement.style.overflow = originalOverflow
|
||||
|
||||
// Create PDF
|
||||
const pdf = new jsPDF({
|
||||
orientation: 'portrait',
|
||||
unit: 'mm',
|
||||
@ -151,43 +129,30 @@ const DailyPOSReport = () => {
|
||||
compress: true
|
||||
})
|
||||
|
||||
// A4 dimensions
|
||||
const pdfWidth = 210
|
||||
const pdfHeight = 297
|
||||
const margin = 5 // Small margin to prevent cutoff
|
||||
const margin = 5
|
||||
|
||||
// Calculate scaling
|
||||
const availableWidth = pdfWidth - 2 * margin
|
||||
const availableHeight = pdfHeight - 2 * margin
|
||||
|
||||
const imgWidth = availableWidth
|
||||
const imgHeight = (canvas.height * availableWidth) / canvas.width
|
||||
|
||||
console.log('PDF dimensions - Canvas:', canvas.width, 'x', canvas.height)
|
||||
console.log('PDF dimensions - Image:', imgWidth, 'x', imgHeight)
|
||||
console.log('Available height per page:', availableHeight)
|
||||
|
||||
// Split content across pages
|
||||
let yPosition = margin
|
||||
let sourceY = 0
|
||||
let pageCount = 1
|
||||
let remainingHeight = imgHeight
|
||||
|
||||
while (remainingHeight > 0) {
|
||||
console.log(`Processing page ${pageCount}, remaining height: ${remainingHeight}`)
|
||||
|
||||
if (pageCount > 1) {
|
||||
pdf.addPage()
|
||||
yPosition = margin
|
||||
}
|
||||
|
||||
// Calculate how much content fits on this page
|
||||
const heightForThisPage = Math.min(remainingHeight, availableHeight)
|
||||
|
||||
// Calculate source dimensions for cropping
|
||||
const sourceHeight = (heightForThisPage * canvas.height) / imgHeight
|
||||
|
||||
// Create temporary canvas for this page portion
|
||||
const tempCanvas = document.createElement('canvas')
|
||||
const tempCtx = tempCanvas.getContext('2d')
|
||||
|
||||
@ -198,41 +163,21 @@ const DailyPOSReport = () => {
|
||||
tempCanvas.width = canvas.width
|
||||
tempCanvas.height = sourceHeight
|
||||
|
||||
// Draw the portion we need
|
||||
tempCtx.drawImage(
|
||||
canvas,
|
||||
0,
|
||||
sourceY,
|
||||
canvas.width,
|
||||
sourceHeight, // Source rectangle
|
||||
0,
|
||||
0,
|
||||
canvas.width,
|
||||
sourceHeight // Destination rectangle
|
||||
)
|
||||
tempCtx.drawImage(canvas, 0, sourceY, canvas.width, sourceHeight, 0, 0, canvas.width, sourceHeight)
|
||||
|
||||
// Convert to image data
|
||||
const pageImageData = tempCanvas.toDataURL('image/jpeg', 0.9)
|
||||
|
||||
// Add to PDF
|
||||
pdf.addImage(pageImageData, 'JPEG', margin, yPosition, imgWidth, heightForThisPage)
|
||||
|
||||
// Update for next page
|
||||
sourceY += sourceHeight
|
||||
remainingHeight -= heightForThisPage
|
||||
pageCount++
|
||||
|
||||
// Safety check to prevent infinite loop
|
||||
if (pageCount > 20) {
|
||||
console.warn('Too many pages, breaking loop')
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`Generated ${pageCount - 1} pages`)
|
||||
console.log('Finalizing PDF...')
|
||||
|
||||
// Add metadata
|
||||
pdf.setProperties({
|
||||
title: getReportTitle(),
|
||||
subject: 'Transaction Report',
|
||||
@ -240,23 +185,16 @@ const DailyPOSReport = () => {
|
||||
creator: 'Apskel'
|
||||
})
|
||||
|
||||
// Generate filename
|
||||
const fileName =
|
||||
filterType === 'single'
|
||||
? `laporan-transaksi-${formatDateForInput(selectedDate)}.pdf`
|
||||
: `laporan-transaksi-${formatDateForInput(dateRange.startDate)}-to-${formatDateForInput(dateRange.endDate)}.pdf`
|
||||
|
||||
console.log('Saving PDF:', fileName)
|
||||
|
||||
// Save PDF
|
||||
pdf.save(fileName)
|
||||
|
||||
console.log('PDF generated successfully!')
|
||||
} catch (error) {
|
||||
console.error('Error generating PDF:', error)
|
||||
alert(`Terjadi kesalahan saat membuat PDF: ${error}`)
|
||||
} finally {
|
||||
// Reset loading state
|
||||
setIsGeneratingPDF(false)
|
||||
}
|
||||
}
|
||||
@ -268,15 +206,9 @@ const DailyPOSReport = () => {
|
||||
<div className='fixed inset-0 z-50 flex items-center justify-center bg-black bg-opacity-50 backdrop-blur-sm'>
|
||||
<div className='bg-white rounded-lg shadow-xl p-8 max-w-sm w-full mx-4'>
|
||||
<div className='text-center'>
|
||||
{/* Animated Spinner */}
|
||||
<div className='inline-block animate-spin rounded-full h-12 w-12 border-4 border-gray-200 border-t-purple-600 mb-4'></div>
|
||||
|
||||
{/* Loading Message */}
|
||||
<h3 className='text-lg font-semibold text-gray-800 mb-2'>{message}</h3>
|
||||
|
||||
<p className='text-sm text-gray-600'>Mohon tunggu, proses ini mungkin membutuhkan beberapa detik...</p>
|
||||
|
||||
{/* Progress Steps */}
|
||||
<div className='mt-6 space-y-2'>
|
||||
<div className='flex items-center text-xs text-gray-500'>
|
||||
<div className='w-2 h-2 bg-green-500 rounded-full mr-2 flex-shrink-0'></div>
|
||||
@ -297,12 +229,25 @@ const DailyPOSReport = () => {
|
||||
)
|
||||
}
|
||||
|
||||
// Group products by category
|
||||
const groupedProducts =
|
||||
products?.data?.reduce(
|
||||
(acc, item) => {
|
||||
const categoryName = item.category_name || 'Tidak Berkategori'
|
||||
if (!acc[categoryName]) {
|
||||
acc[categoryName] = []
|
||||
}
|
||||
acc[categoryName].push(item)
|
||||
return acc
|
||||
},
|
||||
{} as Record<string, any[]>
|
||||
) || {}
|
||||
|
||||
return (
|
||||
<div className='min-h-screen'>
|
||||
<LoadingOverlay isVisible={isGeneratingPDF} message='Membuat PDF Laporan...' />
|
||||
{/* Control Panel */}
|
||||
|
||||
<ReportGeneratorComponent
|
||||
// Props wajib
|
||||
reportTitle='Laporan Penjualan'
|
||||
filterType={filterType}
|
||||
selectedDate={selectedDate}
|
||||
@ -311,15 +256,9 @@ const DailyPOSReport = () => {
|
||||
onSingleDateChange={setSelectedDate}
|
||||
onDateRangeChange={setDateRange}
|
||||
onGeneratePDF={handleGeneratePDF}
|
||||
// Props opsional
|
||||
// isGenerating={isGenerating}
|
||||
// customQuickActions={customQuickActions}
|
||||
// labels={customLabels}
|
||||
/>
|
||||
|
||||
{/* Report Template */}
|
||||
<div ref={reportRef} className='max-w-4xl mx-auto bg-white min-h-[297mm]' style={{ width: '210mm' }}>
|
||||
{/* Header */}
|
||||
<ReportHeader
|
||||
outlet={outlet}
|
||||
reportTitle={getReportTitle()}
|
||||
@ -331,54 +270,55 @@ const DailyPOSReport = () => {
|
||||
|
||||
{/* Performance Summary */}
|
||||
<div className='p-8'>
|
||||
<h3 className='text-2xl font-bold mb-6' style={{ color: '#36175e' }}>
|
||||
<h3 className='text-3xl font-bold mb-8' style={{ color: '#36175e' }}>
|
||||
Ringkasan
|
||||
</h3>
|
||||
|
||||
<div className='space-y-4'>
|
||||
<div className='flex justify-between items-center py-2 border-b border-gray-200'>
|
||||
<span className='text-lg text-gray-700'>Total Penjualan</span>
|
||||
<span className='text-lg font-semibold text-gray-800'>
|
||||
<div className='space-y-5'>
|
||||
<div className='flex justify-between items-center py-3 border-b border-gray-200'>
|
||||
<span className='text-xl text-gray-700'>Total Penjualan</span>
|
||||
<span className='text-xl font-semibold text-gray-800'>
|
||||
{formatCurrency(profitLoss?.summary.total_revenue ?? 0)}
|
||||
</span>
|
||||
</div>
|
||||
<div className='flex justify-between items-center py-2 border-b border-gray-200'>
|
||||
<span className='text-lg text-gray-700'>Total Diskon</span>
|
||||
<span className='text-lg font-semibold text-gray-800'>
|
||||
<div className='flex justify-between items-center py-3 border-b border-gray-200'>
|
||||
<span className='text-xl text-gray-700'>Total Diskon</span>
|
||||
<span className='text-xl font-semibold text-gray-800'>
|
||||
{formatCurrency(profitLoss?.summary.total_discount ?? 0)}
|
||||
</span>
|
||||
</div>
|
||||
<div className='flex justify-between items-center py-2 border-b border-gray-200'>
|
||||
<span className='text-lg text-gray-700'>Total Pajak</span>
|
||||
<span className='text-lg font-semibold text-gray-800'>
|
||||
<div className='flex justify-between items-center py-3 border-b border-gray-200'>
|
||||
<span className='text-xl text-gray-700'>Total Pajak</span>
|
||||
<span className='text-xl font-semibold text-gray-800'>
|
||||
{formatCurrency(profitLoss?.summary.total_tax ?? 0)}
|
||||
</span>
|
||||
</div>
|
||||
<div className='flex justify-between items-center py-2 border-b border-gray-200'>
|
||||
<span className='text-lg text-gray-700 font-bold'>Total</span>
|
||||
<span className='text-lg font-bold text-gray-800'>
|
||||
<div className='flex justify-between items-center py-3 border-b-2 border-gray-300'>
|
||||
<span className='text-xl text-gray-700 font-bold'>Total</span>
|
||||
<span className='text-xl font-bold text-gray-800'>
|
||||
{formatCurrency(profitLoss?.summary.total_revenue ?? 0)}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Invoice */}
|
||||
<div className='px-8 pb-8'>
|
||||
<h3 className='text-2xl font-bold mb-6' style={{ color: '#36175e' }}>
|
||||
<h3 className='text-3xl font-bold mb-8' style={{ color: '#36175e' }}>
|
||||
Invoice
|
||||
</h3>
|
||||
|
||||
<div className='space-y-4'>
|
||||
<div className='flex justify-between items-center py-2 border-b border-gray-200'>
|
||||
<span className='text-lg text-gray-700'>Total Invoice</span>
|
||||
<span className='text-lg font-semibold text-gray-800'>{profitLoss?.summary.total_orders ?? 0}</span>
|
||||
<div className='space-y-5'>
|
||||
<div className='flex justify-between items-center py-3 border-b border-gray-200'>
|
||||
<span className='text-xl text-gray-700'>Total Invoice</span>
|
||||
<span className='text-xl font-semibold text-gray-800'>{profitLoss?.summary.total_orders ?? 0}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Payment Method Summary */}
|
||||
<div className='px-8 pb-8'>
|
||||
<h3 className='text-2xl font-bold mb-6' style={{ color: '#36175e' }}>
|
||||
<h3 className='text-3xl font-bold mb-8' style={{ color: '#36175e' }}>
|
||||
Ringkasan Metode Pembayaran
|
||||
</h3>
|
||||
|
||||
@ -386,20 +326,20 @@ const DailyPOSReport = () => {
|
||||
<table className='w-full'>
|
||||
<thead>
|
||||
<tr className='text-gray-800 border-b-2 border-gray-300'>
|
||||
<th className='text-left text-lg p-3 font-semibold'>Metode Pembayaran</th>
|
||||
<th className='text-center text-lg p-3 font-semibold'>Tipe</th>
|
||||
<th className='text-center text-lg p-3 font-semibold'>Jumlah Order</th>
|
||||
<th className='text-right text-lg p-3 font-semibold'>Total Amount</th>
|
||||
<th className='text-center text-lg p-3 font-semibold'>Persentase</th>
|
||||
<th className='text-left text-xl p-4 font-semibold'>Metode Pembayaran</th>
|
||||
<th className='text-center text-xl p-4 font-semibold'>Tipe</th>
|
||||
<th className='text-center text-xl p-4 font-semibold'>Jumlah Order</th>
|
||||
<th className='text-right text-xl p-4 font-semibold'>Total Amount</th>
|
||||
<th className='text-center text-xl p-4 font-semibold'>Persentase</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{paymentAnalytics?.data?.map((payment, index) => (
|
||||
<tr key={index} className={index % 2 === 0 ? 'bg-white' : 'bg-gray-50'}>
|
||||
<td className='p-3 text-lg font-medium text-gray-800'>{payment.payment_method_name}</td>
|
||||
<td className='p-3 text-center'>
|
||||
<td className='p-4 text-xl font-medium text-gray-800'>{payment.payment_method_name}</td>
|
||||
<td className='p-4 text-center'>
|
||||
<span
|
||||
className={`px-2 py-1 rounded-full text-base font-medium ${
|
||||
className={`px-3 py-1 rounded-full text-lg font-medium ${
|
||||
payment.payment_method_type === 'cash'
|
||||
? 'bg-green-100 text-green-800'
|
||||
: 'bg-blue-100 text-blue-800'
|
||||
@ -408,11 +348,11 @@ const DailyPOSReport = () => {
|
||||
{payment.payment_method_type.toUpperCase()}
|
||||
</span>
|
||||
</td>
|
||||
<td className='p-3 text-lg text-center text-gray-700'>{payment.order_count}</td>
|
||||
<td className='p-3 text-lg text-right font-semibold text-gray-800'>
|
||||
<td className='p-4 text-xl text-center text-gray-700'>{payment.order_count}</td>
|
||||
<td className='p-4 text-xl text-right font-semibold text-gray-800'>
|
||||
{formatCurrency(payment.total_amount)}
|
||||
</td>
|
||||
<td className='p-3 text-lg text-center font-medium' style={{ color: '#36175e' }}>
|
||||
<td className='p-4 text-xl text-center font-medium' style={{ color: '#36175e' }}>
|
||||
{(payment.percentage ?? 0).toFixed(1)}%
|
||||
</td>
|
||||
</tr>
|
||||
@ -420,13 +360,13 @@ const DailyPOSReport = () => {
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr className='text-gray-800 border-t-2 border-gray-300'>
|
||||
<td className='p-3 text-lg font-bold'>TOTAL</td>
|
||||
<td className='p-3'></td>
|
||||
<td className='p-3 text-lg text-center font-bold'>{paymentAnalytics?.summary.total_orders ?? 0}</td>
|
||||
<td className='p-3 text-lg text-right font-bold'>
|
||||
<td className='p-4 text-xl font-bold'>TOTAL</td>
|
||||
<td className='p-4'></td>
|
||||
<td className='p-4 text-xl text-center font-bold'>{paymentAnalytics?.summary.total_orders ?? 0}</td>
|
||||
<td className='p-4 text-xl text-right font-bold'>
|
||||
{formatCurrency(paymentAnalytics?.summary.total_amount ?? 0)}
|
||||
</td>
|
||||
<td className='p-3 text-center font-bold'></td>
|
||||
<td className='p-4 text-center font-bold'></td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
@ -435,7 +375,7 @@ const DailyPOSReport = () => {
|
||||
|
||||
{/* Category Summary */}
|
||||
<div className='px-8 pb-8'>
|
||||
<h3 className='text-2xl font-bold mb-6' style={{ color: '#36175e' }}>
|
||||
<h3 className='text-3xl font-bold mb-8' style={{ color: '#36175e' }}>
|
||||
Ringkasan Kategori
|
||||
</h3>
|
||||
|
||||
@ -443,17 +383,17 @@ const DailyPOSReport = () => {
|
||||
<table className='w-full'>
|
||||
<thead>
|
||||
<tr className='text-gray-800 border-b-2 border-gray-300'>
|
||||
<th className='text-left text-lg p-3 font-semibold'>Nama</th>
|
||||
<th className='text-center text-lg p-3 font-semibold'>Qty</th>
|
||||
<th className='text-right text-lg p-3 font-semibold'>Pendapatan</th>
|
||||
<th className='text-left text-xl p-4 font-semibold'>Nama</th>
|
||||
<th className='text-center text-xl p-4 font-semibold'>Qty</th>
|
||||
<th className='text-right text-xl p-4 font-semibold'>Pendapatan</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{category?.data?.map((c, index) => (
|
||||
<tr key={index} className={index % 2 === 0 ? 'bg-white' : 'bg-gray-50'}>
|
||||
<td className='p-3 text-lg font-medium text-gray-800'>{c.category_name}</td>
|
||||
<td className='p-3 text-lg text-center text-gray-700'>{c.total_quantity}</td>
|
||||
<td className='p-3 text-lg text-right font-semibold' style={{ color: '#36175e' }}>
|
||||
<td className='p-4 text-xl font-medium text-gray-800'>{c.category_name}</td>
|
||||
<td className='p-4 text-xl text-center text-gray-700'>{c.total_quantity}</td>
|
||||
<td className='p-4 text-xl text-right font-semibold' style={{ color: '#36175e' }}>
|
||||
{formatCurrency(c.total_revenue)}
|
||||
</td>
|
||||
</tr>
|
||||
@ -461,9 +401,9 @@ const DailyPOSReport = () => {
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr className='text-gray-800 border-t-2 border-gray-300'>
|
||||
<td className='p-3 text-lg font-bold'>TOTAL</td>
|
||||
<td className='p-3 text-lg text-center font-bold'>{categorySummary?.totalQuantity ?? 0}</td>
|
||||
<td className='p-3 text-lg text-right font-bold'>
|
||||
<td className='p-4 text-xl font-bold'>TOTAL</td>
|
||||
<td className='p-4 text-xl text-center font-bold'>{categorySummary?.totalQuantity ?? 0}</td>
|
||||
<td className='p-4 text-xl text-right font-bold'>
|
||||
{formatCurrency(categorySummary?.totalRevenue ?? 0)}
|
||||
</td>
|
||||
</tr>
|
||||
@ -472,134 +412,129 @@ const DailyPOSReport = () => {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Transaction Summary */}
|
||||
{/* Product Summary - Dipisah per kategori dengan tabel terpisah */}
|
||||
<div className='px-8 pb-8'>
|
||||
<h3 className='text-2xl font-bold mb-6' style={{ color: '#36175e' }}>
|
||||
Ringkasan Item
|
||||
<h3 className='text-3xl font-bold mb-8 pb-4' style={{ color: '#36175e', pageBreakAfter: 'avoid' }}>
|
||||
Ringkasan Item Per Kategori
|
||||
</h3>
|
||||
|
||||
<div className='bg-gray-50 rounded-lg border border-gray-200 overflow-visible'>
|
||||
<div className='overflow-x-auto'>
|
||||
<table className='w-full table-fixed' style={{ minWidth: '100%' }}>
|
||||
<colgroup>
|
||||
<col style={{ width: '50%' }} />
|
||||
<col style={{ width: '20%' }} />
|
||||
<col style={{ width: '30%' }} />
|
||||
</colgroup>
|
||||
<thead>
|
||||
<tr className='text-gray-800 border-b-2 border-gray-300'>
|
||||
<th className='text-left text-lg p-3 font-semibold border-r border-gray-300'>Produk</th>
|
||||
<th className='text-center text-lg p-3 font-semibold border-r border-gray-300'>Qty</th>
|
||||
<th className='text-right text-lg p-3 font-semibold'>Pendapatan</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{(() => {
|
||||
// Group products by category
|
||||
const groupedProducts =
|
||||
products?.data?.reduce(
|
||||
(acc, item) => {
|
||||
const categoryName = item.category_name || 'Tidak Berkategori'
|
||||
if (!acc[categoryName]) {
|
||||
acc[categoryName] = []
|
||||
}
|
||||
acc[categoryName].push(item)
|
||||
return acc
|
||||
},
|
||||
{} as Record<string, any[]>
|
||||
) || {}
|
||||
<div className='space-y-12'>
|
||||
{Object.keys(groupedProducts)
|
||||
.sort()
|
||||
.map(categoryName => {
|
||||
const categoryProducts = groupedProducts[categoryName]
|
||||
const categoryTotalQty = categoryProducts.reduce((sum, item) => sum + (item.quantity_sold || 0), 0)
|
||||
const categoryTotalRevenue = categoryProducts.reduce((sum, item) => sum + (item.revenue || 0), 0)
|
||||
|
||||
const rows: JSX.Element[] = []
|
||||
let globalIndex = 0
|
||||
return (
|
||||
<div
|
||||
key={categoryName}
|
||||
className='mb-12 break-inside-avoid'
|
||||
style={{
|
||||
pageBreakInside: 'avoid',
|
||||
breakInside: 'avoid',
|
||||
display: 'block',
|
||||
marginTop: '24px',
|
||||
marginBottom: '24px',
|
||||
paddingTop: '12px',
|
||||
paddingBottom: '12px'
|
||||
}}
|
||||
>
|
||||
{/* Category Title */}
|
||||
<h4
|
||||
className='text-2xl font-bold mb-0 px-4 py-4 bg-gray-100 rounded-t-lg'
|
||||
style={{
|
||||
color: '#36175e',
|
||||
pageBreakAfter: 'avoid',
|
||||
breakAfter: 'avoid'
|
||||
}}
|
||||
>
|
||||
{categoryName.toUpperCase()}
|
||||
</h4>
|
||||
|
||||
// Sort categories alphabetically
|
||||
Object.keys(groupedProducts)
|
||||
.sort()
|
||||
.forEach(categoryName => {
|
||||
const categoryProducts = groupedProducts[categoryName]
|
||||
|
||||
// Category header row
|
||||
rows.push(
|
||||
<tr
|
||||
key={`category-${categoryName}`}
|
||||
className='bg-gray-100 border-b border-gray-300'
|
||||
style={{ pageBreakInside: 'avoid' }}
|
||||
>
|
||||
<td
|
||||
className='p-3 text-lg font-bold text-gray-900 border-r border-gray-300'
|
||||
style={{ color: '#36175e' }}
|
||||
>
|
||||
{categoryName.toUpperCase()}
|
||||
</td>
|
||||
<td className='p-3 border-r border-gray-300'></td>
|
||||
<td className='p-3'></td>
|
||||
{/* Category Table */}
|
||||
<div
|
||||
className='bg-gray-50 rounded-b-lg border-l-2 border-r-2 border-b-2 border-gray-300'
|
||||
style={{
|
||||
pageBreakInside: 'avoid',
|
||||
breakInside: 'avoid'
|
||||
}}
|
||||
>
|
||||
<table className='w-full' style={{ borderCollapse: 'collapse', tableLayout: 'fixed' }}>
|
||||
<colgroup>
|
||||
<col style={{ width: '50%' }} />
|
||||
<col style={{ width: '20%' }} />
|
||||
<col style={{ width: '30%' }} />
|
||||
</colgroup>
|
||||
<thead>
|
||||
<tr className='text-gray-800 border-b-2 border-gray-300 bg-gray-100'>
|
||||
<th className='text-left text-xl p-5 font-semibold border-r border-gray-300'>Produk</th>
|
||||
<th className='text-center text-xl p-5 font-semibold border-r border-gray-300'>Qty</th>
|
||||
<th className='text-right text-xl p-5 font-semibold'>Pendapatan</th>
|
||||
</tr>
|
||||
)
|
||||
|
||||
// Product rows for this category
|
||||
categoryProducts.forEach((item, index) => {
|
||||
globalIndex++
|
||||
rows.push(
|
||||
</thead>
|
||||
<tbody>
|
||||
{categoryProducts.map((item, index) => (
|
||||
<tr
|
||||
key={`product-${item.product_name}-${index}`}
|
||||
className={`${globalIndex % 2 === 0 ? 'bg-white' : 'bg-gray-50'} border-b border-gray-200`}
|
||||
key={index}
|
||||
className={index % 2 === 0 ? 'bg-white' : 'bg-gray-50'}
|
||||
style={{ pageBreakInside: 'avoid' }}
|
||||
>
|
||||
<td
|
||||
className='p-3 text-lg pl-6 font-medium text-gray-800 border-r border-gray-200'
|
||||
style={{ wordWrap: 'break-word' }}
|
||||
>
|
||||
<td className='p-5 text-xl font-medium text-gray-800 border-r border-gray-200'>
|
||||
{item.product_name}
|
||||
</td>
|
||||
<td className='p-3 text-lg text-center text-gray-700 border-r border-gray-200'>
|
||||
<td className='p-5 text-xl text-center text-gray-700 border-r border-gray-200'>
|
||||
{item.quantity_sold}
|
||||
</td>
|
||||
<td className='p-3 text-lg text-right font-semibold text-gray-800'>
|
||||
<td className='p-5 text-xl text-right font-semibold text-gray-800'>
|
||||
{formatCurrency(item.revenue)}
|
||||
</td>
|
||||
</tr>
|
||||
)
|
||||
})
|
||||
|
||||
// Category subtotal row
|
||||
const categoryTotalQty = categoryProducts.reduce(
|
||||
(sum, item) => sum + (item.quantity_sold || 0),
|
||||
0
|
||||
)
|
||||
const categoryTotalRevenue = categoryProducts.reduce(
|
||||
(sum, item) => sum + (item.revenue || 0),
|
||||
0
|
||||
)
|
||||
|
||||
rows.push(
|
||||
<tr
|
||||
key={`subtotal-${categoryName}`}
|
||||
className='bg-gray-200 border-b-2 border-gray-400'
|
||||
style={{ pageBreakInside: 'avoid' }}
|
||||
>
|
||||
<td className='p-3 text-lg pl-6 font-semibold text-gray-800 border-r border-gray-400'>
|
||||
))}
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr className='bg-gray-200 border-t-2 border-gray-400' style={{ pageBreakInside: 'avoid' }}>
|
||||
<td className='p-5 text-xl font-bold text-gray-800 border-r border-gray-400'>
|
||||
Subtotal {categoryName}
|
||||
</td>
|
||||
<td className='p-3 text-lg text-center font-semibold text-gray-800 border-r border-gray-400'>
|
||||
<td className='p-5 text-xl text-center font-bold text-gray-800 border-r border-gray-400'>
|
||||
{categoryTotalQty}
|
||||
</td>
|
||||
<td className='p-3 text-lg text-right font-semibold text-gray-800'>
|
||||
<td className='p-5 text-xl text-right font-bold text-gray-800'>
|
||||
{formatCurrency(categoryTotalRevenue)}
|
||||
</td>
|
||||
</tr>
|
||||
)
|
||||
})
|
||||
</tfoot>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
|
||||
return rows
|
||||
})()}
|
||||
</tbody>
|
||||
{/* Grand Total */}
|
||||
<div
|
||||
className='bg-purple-50 rounded-lg border-2 border-purple-300 mt-6'
|
||||
style={{
|
||||
pageBreakInside: 'avoid',
|
||||
breakInside: 'avoid'
|
||||
}}
|
||||
>
|
||||
<table className='w-full' style={{ borderCollapse: 'collapse' }}>
|
||||
<tfoot>
|
||||
<tr className='text-gray-800 border-t-2 border-gray-300' style={{ pageBreakInside: 'avoid' }}>
|
||||
<td className='p-3 text-lg font-bold border-r border-gray-300'>TOTAL KESELURUHAN</td>
|
||||
<td className='p-3 text-lg text-center font-bold border-r border-gray-300'>
|
||||
<tr className='text-gray-800'>
|
||||
<td
|
||||
className='p-5 text-2xl font-bold border-r-2 border-purple-300'
|
||||
style={{ width: '50%', color: '#36175e' }}
|
||||
>
|
||||
TOTAL KESELURUHAN
|
||||
</td>
|
||||
<td
|
||||
className='p-5 text-2xl text-center font-bold border-r-2 border-purple-300'
|
||||
style={{ width: '20%', color: '#36175e' }}
|
||||
>
|
||||
{productSummary.totalQuantitySold ?? 0}
|
||||
</td>
|
||||
<td className='p-3 text-lg text-right font-bold'>
|
||||
<td className='p-5 text-2xl text-right font-bold' style={{ width: '30%', color: '#36175e' }}>
|
||||
{formatCurrency(productSummary.totalRevenue ?? 0)}
|
||||
</td>
|
||||
</tr>
|
||||
@ -611,7 +546,7 @@ const DailyPOSReport = () => {
|
||||
|
||||
{/* Footer */}
|
||||
<div className='px-8 py-6 border-t-2 border-gray-200 mt-8'>
|
||||
<div className='flex justify-between items-center text-sm text-gray-600'>
|
||||
<div className='flex justify-between items-center text-base text-gray-600'>
|
||||
<p>© 2025 Apskel - Sistem POS Terpadu</p>
|
||||
<p></p>
|
||||
<p>Dicetak pada: {now.toLocaleDateString('id-ID')}</p>
|
||||
|
||||
@ -38,8 +38,8 @@ const ReportHeader: FC<ReportHeaderProps> = ({
|
||||
<Box sx={{ p: theme.spacing(8, 8, 6) }}>
|
||||
<Box sx={{ textAlign: 'center' }}>
|
||||
<Typography
|
||||
variant='h3'
|
||||
component='h2'
|
||||
variant='h1'
|
||||
component='h1'
|
||||
sx={{
|
||||
fontWeight: 700,
|
||||
color: '#222222'
|
||||
@ -49,7 +49,7 @@ const ReportHeader: FC<ReportHeaderProps> = ({
|
||||
</Typography>
|
||||
{periode && (
|
||||
<Typography
|
||||
variant='body1'
|
||||
variant='h5'
|
||||
sx={{
|
||||
color: '#222222',
|
||||
mt: 2
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user