feat: add categories at daily report

This commit is contained in:
efrilm
2025-08-14 02:07:55 +07:00
parent a13597725b
commit 7a8bd59bb4
3 changed files with 173 additions and 67 deletions
@@ -4,7 +4,8 @@ import {
useProductSalesAnalytics,
useProfitLossAnalytics,
useSalesAnalytics,
usePaymentAnalytics
usePaymentAnalytics,
useCategoryAnalytics
} from '@/services/queries/analytics'
import { useOutletById } from '@/services/queries/outlets'
import { formatCurrency, formatDate, formatDateDDMMYYYY, formatDatetime } from '@/utils/transform'
@@ -45,6 +46,7 @@ const DailyPOSReport = () => {
const { data: profitLoss } = useProfitLossAnalytics(dateParams)
const { data: products } = useProductSalesAnalytics(dateParams)
const { data: paymentAnalytics } = usePaymentAnalytics(dateParams)
const { data: category } = useCategoryAnalytics(dateParams)
const productSummary = {
totalQuantitySold: products?.data?.reduce((sum, item) => sum + (item?.quantity_sold || 0), 0) || 0,
@@ -60,6 +62,13 @@ const DailyPOSReport = () => {
totalQuantity: profitLoss?.product_data?.reduce((sum, item) => sum + (item?.quantity_sold || 0), 0) || 0
}
const categorySummary = {
totalRevenue: category?.data?.reduce((sum, item) => sum + (item?.total_revenue || 0), 0) || 0,
orderCount: category?.data?.reduce((sum, item) => sum + (item?.order_count || 0), 0) || 0,
productCount: category?.data?.reduce((sum, item) => sum + (item?.product_count || 0), 0) || 0,
totalQuantity: category?.data?.reduce((sum, item) => sum + (item?.total_quantity || 0), 0) || 0
}
useEffect(() => {
setNow(new Date())
}, [])
@@ -199,13 +208,13 @@ const DailyPOSReport = () => {
{/* Performance Summary */}
<div className='p-8'>
<h3 className='text-xl font-bold mb-6' style={{ color: '#36175e' }}>
1. Ringkasan Kinerja
1. Ringkasan
</h3>
<div className='grid grid-cols-2 gap-6'>
<div className='space-y-4'>
<div className='flex justify-between items-center py-2 border-b border-gray-200'>
<span className='text-gray-700'>TOTAL PENJUALAN (termasuk rasik)</span>
<span className='text-gray-700'>Total Penjualan (termasuk rasik)</span>
<span className='font-semibold text-gray-800'>
{formatCurrency(profitLoss?.summary.total_revenue ?? 0)}
</span>
@@ -359,7 +368,50 @@ const DailyPOSReport = () => {
<td className='p-3 text-right font-bold'>
{formatCurrency(paymentAnalytics?.summary.total_amount ?? 0)}
</td>
<td className='p-3 text-center font-bold'>100.0%</td>
<td className='p-3 text-center font-bold'></td>
</tr>
</tfoot>
</table>
</div>
</div>
{/* Category Summary */}
<div className='px-8 pb-8'>
<h3 className='text-xl font-bold mb-6' style={{ color: '#36175e' }}>
2. Ringkasan Kategori
</h3>
<div className='bg-gray-50 rounded-lg border border-gray-200 overflow-hidden'>
<table className='w-full'>
<thead>
<tr style={{ backgroundColor: '#36175e' }} className='text-white'>
<th className='text-left p-3 font-semibold'>Nama</th>
<th className='text-center p-3 font-semibold'>Total Produk</th>
<th className='text-center p-3 font-semibold'>Qty</th>
<th className='text-right p-3 font-semibold'>Jumlah Order</th>
<th className='text-center p-3 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 font-medium text-gray-800'>{c.category_name}</td>
<td className='p-3 text-center text-gray-700'>{c.product_count}</td>
<td className='p-3 text-center text-gray-700'>{c.total_quantity}</td>
<td className='p-3 text-center text-gray-700'>{c.order_count}</td>
<td className='p-3 text-right font-semibold' style={{ color: '#36175e' }}>
{formatCurrency(c.total_revenue)}
</td>
</tr>
)) || []}
</tbody>
<tfoot>
<tr style={{ backgroundColor: '#36175e' }} className='text-white'>
<td className='p-3 font-bold'>TOTAL</td>
<td className='p-3 text-center font-bold'>{categorySummary?.productCount ?? 0}</td>
<td className='p-3 text-center font-bold'>{categorySummary?.totalQuantity ?? 0}</td>
<td className='p-3 text-center font-bold'>{categorySummary?.orderCount ?? 0}</td>
<td className='p-3 text-right font-bold'>{formatCurrency(categorySummary?.totalRevenue ?? 0)}</td>
</tr>
</tfoot>
</table>
@@ -369,7 +421,7 @@ const DailyPOSReport = () => {
{/* Transaction Summary */}
<div className='px-8 pb-8'>
<h3 className='text-xl font-bold mb-6' style={{ color: '#36175e' }}>
3. Ringkasan Transaksi
4. Ringkasan Item
</h3>
<div className='bg-gray-50 rounded-lg border border-gray-200 overflow-hidden'>