feat: implement reports page with analytical charts and data grids, and add payment status tracking to submissions.
This commit is contained in:
+58
-1
@@ -62,7 +62,7 @@ export async function getMyOrders(creator_id: string) {
|
||||
where: { creator_id },
|
||||
include: {
|
||||
available_items: true,
|
||||
submissions: { select: { id: true } }
|
||||
submissions: { select: { id: true, payment_status: true } }
|
||||
},
|
||||
orderBy: { date: 'desc' }
|
||||
})
|
||||
@@ -222,12 +222,28 @@ export async function updateSubmissionPayment(submission_id: string, bill: numbe
|
||||
})
|
||||
revalidatePath(`/my-orders`)
|
||||
revalidatePath(`/my-purchases`)
|
||||
revalidatePath(`/reports`)
|
||||
return { success: true }
|
||||
} catch (e) {
|
||||
return { success: false, error: 'Gagal menyimpan tagihan.' }
|
||||
}
|
||||
}
|
||||
|
||||
export async function updateBulkSubmissionPayment(submission_ids: string[], payment_status: string) {
|
||||
try {
|
||||
await prisma.submission.updateMany({
|
||||
where: { id: { in: submission_ids } },
|
||||
data: { payment_status }
|
||||
})
|
||||
revalidatePath(`/my-orders`)
|
||||
revalidatePath(`/my-purchases`)
|
||||
revalidatePath(`/reports`)
|
||||
return { success: true }
|
||||
} catch (e) {
|
||||
return { success: false, error: 'Gagal mengubah status tagihan massal.' }
|
||||
}
|
||||
}
|
||||
|
||||
// === SUBMISSION (PESANAN SAYA) ===
|
||||
export async function getUserSubmission(order_id: string, user_id: string) {
|
||||
return await prisma.submission.findFirst({
|
||||
@@ -300,3 +316,44 @@ export async function submitOrder(data: {
|
||||
return { success: false, error: 'Gagal mengirim pesanan.' }
|
||||
}
|
||||
}
|
||||
|
||||
// === REPORT ACTIONS ===
|
||||
export async function getSubmittorReport(user_id: string, startDate?: Date, endDate?: Date) {
|
||||
return await prisma.submission.findMany({
|
||||
where: {
|
||||
user_id,
|
||||
order: {
|
||||
status: 'CLOSE',
|
||||
...(startDate && endDate ? { date: { gte: startDate, lte: endDate } } : {})
|
||||
}
|
||||
},
|
||||
include: {
|
||||
order: {
|
||||
include: { creator: true }
|
||||
},
|
||||
items: true
|
||||
},
|
||||
orderBy: {
|
||||
order: { date: 'desc' }
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export async function getCreatorReport(creator_id: string, startDate?: Date, endDate?: Date) {
|
||||
return await prisma.order.findMany({
|
||||
where: {
|
||||
creator_id,
|
||||
status: 'CLOSE',
|
||||
...(startDate && endDate ? { date: { gte: startDate, lte: endDate } } : {})
|
||||
},
|
||||
include: {
|
||||
submissions: {
|
||||
include: {
|
||||
user: true,
|
||||
items: true
|
||||
}
|
||||
}
|
||||
},
|
||||
orderBy: { date: 'desc' }
|
||||
})
|
||||
}
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 25 KiB |
@@ -0,0 +1,46 @@
|
||||
import { ImageResponse } from 'next/og'
|
||||
|
||||
export const size = {
|
||||
width: 32,
|
||||
height: 32,
|
||||
}
|
||||
export const contentType = 'image/png'
|
||||
|
||||
export default function Icon() {
|
||||
return new ImageResponse(
|
||||
(
|
||||
<div
|
||||
style={{
|
||||
width: '100%',
|
||||
height: '100%',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
background: 'linear-gradient(to bottom right, #1B2CC1, #121E85)',
|
||||
borderRadius: '8px',
|
||||
}}
|
||||
>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="20"
|
||||
height="20"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="white"
|
||||
strokeWidth="2"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
>
|
||||
<path d="M9.937 15.5A2 2 0 0 0 8.5 14.063l-6.135-1.582a.5.5 0 0 1 0-.962L8.5 9.936A2 2 0 0 0 9.937 8.5l1.582-6.135a.5.5 0 0 1 .963 0L14.063 8.5A2 2 0 0 0 15.5 9.937l6.135 1.581a.5.5 0 0 1 0 .964L15.5 14.063a2 2 0 0 0-1.437 1.437l-1.582 6.135a.5.5 0 0 1-.963 0z" />
|
||||
<path d="M20 3v4" />
|
||||
<path d="M22 5h-4" />
|
||||
<path d="M4 17v2" />
|
||||
<path d="M5 18H3" />
|
||||
</svg>
|
||||
</div>
|
||||
),
|
||||
{
|
||||
...size,
|
||||
}
|
||||
)
|
||||
}
|
||||
@@ -325,6 +325,16 @@ export default function MyOrdersPage() {
|
||||
<span className="text-xs font-bold text-slate-700 dark:text-slate-300">
|
||||
{order.submissions.length} Orang Menitip
|
||||
</span>
|
||||
{isClosed && order.submissions.length > 0 && (
|
||||
<div className="flex items-center gap-1.5 ml-1 sm:ml-2 sm:border-l border-slate-200 dark:border-slate-700 sm:pl-3">
|
||||
<span className="text-[10px] font-black text-emerald-700 dark:text-emerald-400 bg-emerald-50 dark:bg-emerald-950/50 px-1.5 py-0.5 rounded">
|
||||
Lunas: {order.submissions.filter((s: any) => s.payment_status === 'LUNAS').length}
|
||||
</span>
|
||||
<span className="text-[10px] font-black text-rose-700 dark:text-rose-400 bg-rose-50 dark:bg-rose-950/50 px-1.5 py-0.5 rounded">
|
||||
Belum: {order.submissions.filter((s: any) => s.payment_status !== 'LUNAS').length}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="w-1 h-1 rounded-full bg-slate-300 dark:bg-slate-600 hidden sm:block"></div>
|
||||
@@ -505,7 +515,7 @@ export default function MyOrdersPage() {
|
||||
function CreateOrderModal({ userId, onSuccess, initialData }: { userId: string, onSuccess: () => void, initialData?: any }) {
|
||||
const [title, setTitle] = useState(initialData ? `${initialData.title} (Copy)` : '')
|
||||
const [allowCustom, setAllowCustom] = useState(initialData ? initialData.allow_custom : false)
|
||||
const [items, setItems] = useState(
|
||||
const [items, setItems] = useState<{ id: string; name: string }[]>(
|
||||
initialData && initialData.available_items?.length > 0
|
||||
? initialData.available_items.map((ai: any) => ({ id: Math.random().toString(), name: ai.name }))
|
||||
: [{ id: '1', name: '' }]
|
||||
@@ -514,8 +524,8 @@ function CreateOrderModal({ userId, onSuccess, initialData }: { userId: string,
|
||||
const [error, setError] = useState('')
|
||||
|
||||
const addItem = () => setItems([...items, { id: Math.random().toString(), name: '' }])
|
||||
const removeItem = (id: string) => setItems(items.filter(i => i.id !== id))
|
||||
const updateItem = (id: string, name: string) => setItems(items.map(i => i.id === id ? { ...i, name } : i))
|
||||
const removeItem = (id: string) => setItems(items.filter((i: { id: string; name: string }) => i.id !== id))
|
||||
const updateItem = (id: string, name: string) => setItems(items.map((i: { id: string; name: string }) => i.id === id ? { ...i, name } : i))
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault()
|
||||
@@ -523,7 +533,7 @@ function CreateOrderModal({ userId, onSuccess, initialData }: { userId: string,
|
||||
|
||||
if (!title.trim()) return setError('Judul PO wajib diisi.')
|
||||
|
||||
const validItems = items.filter(i => i.name.trim()).map(i => i.name.trim())
|
||||
const validItems = items.filter((i: { id: string; name: string }) => i.name.trim()).map((i: { id: string; name: string }) => i.name.trim())
|
||||
if (!allowCustom && validItems.length === 0) {
|
||||
return setError('Wajib menambahkan minimal 1 menu pilihan jika tidak mengizinkan custom item.')
|
||||
}
|
||||
@@ -611,7 +621,7 @@ function CreateOrderModal({ userId, onSuccess, initialData }: { userId: string,
|
||||
</div>
|
||||
|
||||
<div className="space-y-2.5">
|
||||
{items.map((item, index) => (
|
||||
{items.map((item: { id: string; name: string }, index: number) => (
|
||||
<div key={item.id} className="flex gap-2 items-center p-2 rounded-xl border border-slate-200/90 dark:border-slate-800 bg-slate-50/50 dark:bg-slate-800/30">
|
||||
<span className="text-xs font-bold text-slate-400 w-5 text-center">{index + 1}.</span>
|
||||
<Input
|
||||
|
||||
@@ -173,7 +173,7 @@ export default function MyPurchasesPage() {
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex flex-col h-full space-y-4">
|
||||
<div className="flex flex-col space-y-4 max-h-[calc(100vh-260px)] overflow-y-auto pr-2 scrollbar-thin">
|
||||
<div className="space-y-4 max-h-[calc(100vh-260px)] overflow-y-auto pr-2 scrollbar-thin pb-4">
|
||||
{paginatedPurchases.map((sub) => {
|
||||
const date = new Date(sub.order.date)
|
||||
const isOrderOpen = sub.order.status === 'OPEN'
|
||||
@@ -181,16 +181,15 @@ export default function MyPurchasesPage() {
|
||||
return (
|
||||
<div
|
||||
key={sub.id}
|
||||
className="flex flex-col md:flex-row h-full md:h-auto rounded-2xl border border-slate-200/90 dark:border-slate-800 bg-white dark:bg-slate-900 shadow-sm hover:shadow-md hover:border-[#1B2CC1]/40 transition-all overflow-hidden items-start md:items-stretch"
|
||||
className="flex flex-col md:flex-row rounded-2xl border border-slate-200/90 dark:border-slate-800 bg-white dark:bg-slate-900 shadow-sm hover:shadow-md hover:border-[#1B2CC1]/40 transition-all overflow-hidden divide-y md:divide-y-0 md:divide-x divide-slate-100 dark:divide-slate-800/80"
|
||||
>
|
||||
{/* Left: Info */}
|
||||
<div className="flex-1 p-5 md:border-r border-slate-100 dark:border-slate-800/80 flex flex-col justify-center">
|
||||
<div className="flex justify-between items-start gap-4 mb-3">
|
||||
<h3 className="text-xl font-bold text-slate-900 dark:text-white line-clamp-2 flex-1 min-w-0 leading-snug">
|
||||
<div className="w-full md:flex-1 p-4 md:p-5 flex flex-col">
|
||||
<div className="flex flex-wrap items-center gap-2 sm:gap-3 mb-4">
|
||||
<h3 className="text-xl font-bold text-slate-900 dark:text-white line-clamp-2 min-w-0 leading-snug">
|
||||
{sub.order.title}
|
||||
</h3>
|
||||
<div className="flex flex-col sm:flex-row items-end sm:items-center gap-2 shrink-0">
|
||||
<span className="text-[11px] text-slate-400 font-semibold bg-slate-100/80 dark:bg-slate-800 px-2.5 py-1 rounded-full whitespace-nowrap">
|
||||
<span className="text-[11px] text-slate-400 font-semibold bg-slate-100/80 dark:bg-slate-800 px-2.5 py-1 rounded-full whitespace-nowrap">
|
||||
{format(date, 'EEEE, dd MMM yyyy', { locale: idLocale })}
|
||||
</span>
|
||||
<span className={cn(
|
||||
@@ -203,7 +202,6 @@ export default function MyPurchasesPage() {
|
||||
)}>
|
||||
● PO {sub.order.status}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-2.5 pt-3 border-t border-slate-100 dark:border-slate-800/60">
|
||||
@@ -228,8 +226,8 @@ export default function MyPurchasesPage() {
|
||||
</div>
|
||||
|
||||
{/* Middle: Items List */}
|
||||
<div className="w-full md:w-64 p-5 md:border-r border-slate-100 dark:border-slate-800/80 flex flex-col justify-center">
|
||||
<div className="flex items-center justify-between mb-2 border-t md:border-t-0 pt-4 md:pt-0 border-slate-100 dark:border-slate-800/60">
|
||||
<div className="w-full md:w-64 p-4 md:p-5 flex flex-col">
|
||||
<div className="flex items-center justify-between mb-3">
|
||||
<span className="text-[11px] font-bold uppercase tracking-wider text-slate-400 block">
|
||||
Pesanan Anda ({sub.items.reduce((acc: number, curr: any) => acc + curr.qty, 0)} item)
|
||||
</span>
|
||||
@@ -255,7 +253,7 @@ export default function MyPurchasesPage() {
|
||||
</div>
|
||||
|
||||
{/* Right: Actions & Billing */}
|
||||
<div className="w-full md:w-56 p-5 bg-slate-50/60 dark:bg-slate-800/40 flex flex-col justify-center gap-3 mt-auto md:mt-0">
|
||||
<div className="w-full md:w-56 p-4 md:p-5 bg-slate-50/50 dark:bg-slate-800/20 flex flex-col justify-center gap-3">
|
||||
<div className="flex flex-col gap-1 mb-1">
|
||||
<div className="flex items-center justify-between gap-2">
|
||||
<span className="text-[10px] font-bold uppercase tracking-wider text-slate-400 block">
|
||||
|
||||
@@ -0,0 +1,292 @@
|
||||
'use client'
|
||||
|
||||
import { useEffect, useRef, useState } from 'react'
|
||||
import { getCreatorReport, getSubmittorReport } from '@/app/actions'
|
||||
import { Card } from '@/components/ui/card'
|
||||
import { Loader2, TrendingUp, TrendingDown, Wallet, ArrowRightLeft, Calendar as CalendarIcon } from 'lucide-react'
|
||||
import { cn } from '@/lib/utils'
|
||||
import ReportCharts from '@/components/ReportCharts'
|
||||
import ReportDataGrid from '@/components/ReportDataGrid'
|
||||
import ReportByPersonGrid from '@/components/ReportByPersonGrid'
|
||||
import {
|
||||
getISOWeek, getYear,
|
||||
startOfISOWeek, endOfISOWeek,
|
||||
startOfMonth, endOfMonth,
|
||||
setISOWeek, setYear as dfSetYear
|
||||
} from 'date-fns'
|
||||
|
||||
// ── Helpers ──────────────────────────────────────────────
|
||||
function getWeekValue(date: Date) {
|
||||
const y = getYear(date)
|
||||
const w = getISOWeek(date)
|
||||
return `${y}-W${w.toString().padStart(2, '0')}`
|
||||
}
|
||||
|
||||
function getMonthValue(date: Date) {
|
||||
const y = date.getFullYear()
|
||||
const m = date.getMonth() + 1
|
||||
return `${y}-${m.toString().padStart(2, '0')}`
|
||||
}
|
||||
|
||||
function getIntervalFromFilter(type: 'WEEK' | 'MONTH', value: string): { start: Date; end: Date } | null {
|
||||
if (!value) return null
|
||||
|
||||
if (type === 'WEEK') {
|
||||
const match = value.match(/^(\d{4})-W(\d{2})$/)
|
||||
if (!match) return null
|
||||
const year = parseInt(match[1])
|
||||
const week = parseInt(match[2])
|
||||
// Use Jan 4 of the year as anchor (always in ISO week 1), then shift to target week
|
||||
const anchor = new Date(year, 0, 4)
|
||||
const withWeek = setISOWeek(anchor, week)
|
||||
const withYear = dfSetYear(withWeek, year)
|
||||
return { start: startOfISOWeek(withYear), end: endOfISOWeek(withYear) }
|
||||
} else {
|
||||
const match = value.match(/^(\d{4})-(\d{2})$/)
|
||||
if (!match) return null
|
||||
const d = new Date(parseInt(match[1]), parseInt(match[2]) - 1, 1)
|
||||
return { start: startOfMonth(d), end: endOfMonth(d) }
|
||||
}
|
||||
}
|
||||
|
||||
export default function ReportsPage() {
|
||||
const [activeTab, setActiveTab] = useState<'SUBMITTOR' | 'CREATOR'>('SUBMITTOR')
|
||||
const [creatorTab, setCreatorTab] = useState<'BY_ORDER' | 'BY_PERSON'>('BY_ORDER')
|
||||
|
||||
const [filterType, setFilterType] = useState<'WEEK' | 'MONTH'>('WEEK')
|
||||
const [filterValue, setFilterValue] = useState<string>(getWeekValue(new Date()))
|
||||
|
||||
const pickerRef = useRef<HTMLInputElement>(null)
|
||||
const [userId, setUserId] = useState<string | null>(null)
|
||||
const [submittorData, setSubmittorData] = useState<any[]>([])
|
||||
const [creatorData, setCreatorData] = useState<any[]>([])
|
||||
const [loading, setLoading] = useState(true)
|
||||
|
||||
// Initial load: get userId
|
||||
useEffect(() => {
|
||||
const id = localStorage.getItem('user_id')
|
||||
if (id) setUserId(id)
|
||||
}, [])
|
||||
|
||||
// Re-fetch every time userId, filterType, or filterValue changes
|
||||
useEffect(() => {
|
||||
if (!userId) return
|
||||
loadData(userId)
|
||||
}, [userId, filterType, filterValue])
|
||||
|
||||
const loadData = async (id: string) => {
|
||||
setLoading(true)
|
||||
const interval = getIntervalFromFilter(filterType, filterValue)
|
||||
const [subRes, creRes] = await Promise.all([
|
||||
getSubmittorReport(id, interval?.start, interval?.end),
|
||||
getCreatorReport(id, interval?.start, interval?.end)
|
||||
])
|
||||
setSubmittorData(subRes)
|
||||
setCreatorData(creRes)
|
||||
setLoading(false)
|
||||
}
|
||||
|
||||
const handleFilterTypeChange = (newType: 'WEEK' | 'MONTH') => {
|
||||
setFilterType(newType)
|
||||
setFilterValue(newType === 'WEEK' ? getWeekValue(new Date()) : getMonthValue(new Date()))
|
||||
}
|
||||
|
||||
const formatRupiah = (n: number) =>
|
||||
new Intl.NumberFormat('id-ID', { style: 'currency', currency: 'IDR', maximumFractionDigits: 0 }).format(n)
|
||||
|
||||
// ── Summary calcs ──────────────────────────────────────
|
||||
const totalPengeluaran = submittorData.reduce((acc, s) => acc + (s.payment_status === 'LUNAS' ? Number(s.bill) || 0 : 0), 0)
|
||||
const totalHutang = submittorData.reduce((acc, s) => acc + (s.payment_status !== 'LUNAS' ? Number(s.bill) || 0 : 0), 0)
|
||||
|
||||
let totalOmzet = 0
|
||||
let totalPiutang = 0
|
||||
creatorData.forEach(order => {
|
||||
order.submissions.forEach((sub: any) => {
|
||||
totalOmzet += Number(sub.bill) || 0
|
||||
if (sub.payment_status !== 'LUNAS') totalPiutang += Number(sub.bill) || 0
|
||||
})
|
||||
})
|
||||
|
||||
const filterLabel = filterType === 'WEEK' ? `Minggu ${filterValue}` : `Bulan ${filterValue}`
|
||||
|
||||
return (
|
||||
<div className="space-y-6 animate-in fade-in duration-500 pb-12">
|
||||
|
||||
{/* ── Header: Tab Switcher (left) + Filter Controls (right) ── */}
|
||||
<div className="flex flex-col md:flex-row md:items-center justify-between gap-4 bg-white dark:bg-slate-900 px-4 py-3 rounded-2xl border border-slate-200/80 dark:border-slate-800 shadow-sm">
|
||||
|
||||
{/* Tab Switcher — positioned where the title was */}
|
||||
<div className="flex items-center bg-slate-100 dark:bg-slate-800/80 p-1 rounded-xl text-xs font-bold">
|
||||
<button
|
||||
onClick={() => setActiveTab('SUBMITTOR')}
|
||||
className={cn(
|
||||
'px-5 py-2 rounded-lg transition-all duration-300 flex items-center justify-center gap-2',
|
||||
activeTab === 'SUBMITTOR'
|
||||
? 'bg-white dark:bg-slate-900 text-[#1B2CC1] dark:text-white shadow-sm font-black'
|
||||
: 'text-slate-500 hover:text-slate-900 dark:hover:text-white'
|
||||
)}
|
||||
>
|
||||
<TrendingDown className="w-4 h-4" /> Pengeluaran Saya
|
||||
</button>
|
||||
<button
|
||||
onClick={() => setActiveTab('CREATOR')}
|
||||
className={cn(
|
||||
'px-5 py-2 rounded-lg transition-all duration-300 flex items-center justify-center gap-2',
|
||||
activeTab === 'CREATOR'
|
||||
? 'bg-white dark:bg-slate-900 text-[#1B2CC1] dark:text-white shadow-sm font-black'
|
||||
: 'text-slate-500 hover:text-slate-900 dark:hover:text-white'
|
||||
)}
|
||||
>
|
||||
<TrendingUp className="w-4 h-4" /> Omzet (Kreator)
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Filter Controls */}
|
||||
<div className="flex items-center gap-2 flex-wrap">
|
||||
{/* Type toggle */}
|
||||
<div className="flex items-center bg-slate-100 dark:bg-slate-800 rounded-xl p-1 gap-1">
|
||||
{(['WEEK', 'MONTH'] as const).map(t => (
|
||||
<button
|
||||
key={t}
|
||||
onClick={() => handleFilterTypeChange(t)}
|
||||
className={cn(
|
||||
'px-3 py-1.5 rounded-lg text-xs font-bold transition-all',
|
||||
filterType === t
|
||||
? 'bg-white dark:bg-slate-700 text-[#1B2CC1] shadow-sm'
|
||||
: 'text-slate-500 hover:text-slate-800 dark:hover:text-slate-200'
|
||||
)}
|
||||
>
|
||||
{t === 'WEEK' ? 'Mingguan' : 'Bulanan'}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* Date Picker */}
|
||||
<div
|
||||
onClick={() => pickerRef.current?.showPicker()}
|
||||
className="flex items-center gap-2 bg-white dark:bg-slate-900 border border-slate-200 dark:border-slate-700 rounded-xl px-3 py-2 shadow-sm cursor-pointer hover:border-[#1B2CC1]/50 transition-colors select-none"
|
||||
>
|
||||
<input
|
||||
ref={pickerRef}
|
||||
type={filterType === 'WEEK' ? 'week' : 'month'}
|
||||
value={filterValue}
|
||||
onChange={e => setFilterValue(e.target.value)}
|
||||
className="text-sm font-bold text-slate-700 dark:text-slate-200 bg-transparent border-none outline-none cursor-pointer w-[140px] [&::-webkit-calendar-picker-indicator]:hidden [&::-webkit-inner-spin-button]:hidden"
|
||||
/>
|
||||
<CalendarIcon className="w-4 h-4 text-slate-400 shrink-0" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Loading overlay */}
|
||||
{loading && (
|
||||
<div className="flex items-center justify-center py-16 gap-3 text-slate-400">
|
||||
<Loader2 className="w-6 h-6 animate-spin text-[#1B2CC1]" />
|
||||
<span className="text-sm font-semibold">Memuat data {filterLabel}...</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* ── SUBMITTOR TAB ── */}
|
||||
{!loading && activeTab === 'SUBMITTOR' && (
|
||||
<div className="space-y-6 animate-in slide-in-from-left-2 duration-300">
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<Card className="rounded-2xl border-none bg-gradient-to-br from-emerald-500 to-emerald-700 text-white shadow-lg shadow-emerald-500/20">
|
||||
<div className="p-4 flex items-center gap-4">
|
||||
<div className="w-14 h-14 rounded-full bg-white/20 flex items-center justify-center backdrop-blur-sm shrink-0">
|
||||
<Wallet className="w-6 h-6 text-white" />
|
||||
</div>
|
||||
<div className="flex flex-col">
|
||||
<span className="text-emerald-100 font-bold text-xs tracking-wide uppercase mb-1">Total Pengeluaran (Lunas)</span>
|
||||
<h2 className="text-2xl font-black leading-none mb-1">{formatRupiah(totalPengeluaran)}</h2>
|
||||
<p className="text-xs text-emerald-100">
|
||||
Dari {submittorData.filter(s => s.payment_status === 'LUNAS').length} pesanan lunas.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
<Card className="rounded-2xl border-none bg-gradient-to-br from-rose-500 to-rose-700 text-white shadow-lg shadow-rose-500/20">
|
||||
<div className="p-4 flex items-center gap-4">
|
||||
<div className="w-14 h-14 rounded-full bg-white/20 flex items-center justify-center backdrop-blur-sm shrink-0">
|
||||
<ArrowRightLeft className="w-6 h-6 text-white" />
|
||||
</div>
|
||||
<div className="flex flex-col">
|
||||
<span className="text-rose-100 font-bold text-xs tracking-wide uppercase mb-1">Hutang Pribadi (Belum Bayar)</span>
|
||||
<h2 className="text-2xl font-black leading-none mb-1">{formatRupiah(totalHutang)}</h2>
|
||||
<p className="text-xs text-rose-100">
|
||||
{submittorData.filter(s => s.payment_status !== 'LUNAS').length} tagihan masih gantung.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
<ReportCharts type="SUBMITTOR" data={submittorData} />
|
||||
<ReportDataGrid type="SUBMITTOR" data={submittorData} />
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* ── CREATOR TAB ── */}
|
||||
{!loading && activeTab === 'CREATOR' && (
|
||||
<div className="space-y-6 animate-in slide-in-from-right-2 duration-300">
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<Card className="rounded-2xl border-none bg-gradient-to-br from-[#1B2CC1] to-[#121E85] text-white shadow-lg shadow-[#1B2CC1]/20">
|
||||
<div className="p-4 flex items-center gap-4">
|
||||
<div className="w-14 h-14 rounded-full bg-white/20 flex items-center justify-center backdrop-blur-sm shrink-0">
|
||||
<TrendingUp className="w-6 h-6 text-white" />
|
||||
</div>
|
||||
<div className="flex flex-col">
|
||||
<span className="text-blue-200 font-bold text-xs tracking-wide uppercase mb-1">Total Omzet Dikelola</span>
|
||||
<h2 className="text-2xl font-black leading-none mb-1">{formatRupiah(totalOmzet)}</h2>
|
||||
<p className="text-xs text-blue-200">Dari {creatorData.length} PO yang Anda buat.</p>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
<Card className="rounded-2xl border-none bg-gradient-to-br from-amber-500 to-amber-600 text-white shadow-lg shadow-amber-500/20">
|
||||
<div className="p-4 flex items-center gap-4">
|
||||
<div className="w-14 h-14 rounded-full bg-white/20 flex items-center justify-center backdrop-blur-sm shrink-0">
|
||||
<ArrowRightLeft className="w-6 h-6 text-white" />
|
||||
</div>
|
||||
<div className="flex flex-col">
|
||||
<span className="text-amber-100 font-bold text-xs tracking-wide uppercase mb-1">Total Piutang (Belum Dibayar)</span>
|
||||
<h2 className="text-2xl font-black leading-none mb-1">{formatRupiah(totalPiutang)}</h2>
|
||||
<p className="text-xs text-amber-100">Uang Anda yang masih tertahan di teman-teman.</p>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
<ReportCharts type="CREATOR" data={creatorData} />
|
||||
|
||||
{/* Sub-Tabs */}
|
||||
<div className="flex items-center bg-slate-100 dark:bg-slate-800/80 p-1 rounded-xl text-xs font-bold w-full sm:w-auto">
|
||||
{(['BY_ORDER', 'BY_PERSON'] as const).map(tab => (
|
||||
<button
|
||||
key={tab}
|
||||
onClick={() => setCreatorTab(tab)}
|
||||
className={cn(
|
||||
'flex-1 sm:flex-none px-5 py-2 rounded-lg transition-all duration-200 flex items-center justify-center gap-1.5',
|
||||
creatorTab === tab
|
||||
? 'bg-white dark:bg-slate-900 text-[#1B2CC1] dark:text-white shadow-sm font-black'
|
||||
: 'text-slate-500 hover:text-slate-900 dark:hover:text-white'
|
||||
)}
|
||||
>
|
||||
{tab === 'BY_ORDER' ? 'Berdasarkan PO' : 'Berdasarkan Orang'}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{creatorTab === 'BY_ORDER' ? (
|
||||
<ReportDataGrid type="CREATOR" data={creatorData} />
|
||||
) : (
|
||||
<ReportByPersonGrid
|
||||
data={creatorData}
|
||||
onUpdate={() => { if (userId) loadData(userId) }}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import { useEffect, useState } from 'react'
|
||||
import { usePathname } from 'next/navigation'
|
||||
import { Menu, Calendar, Store, ClipboardList, Package, User, FileText } from 'lucide-react'
|
||||
import { Menu, Calendar, Store, ClipboardList, Package, User, FileText, BarChart2 } from 'lucide-react'
|
||||
import { buttonVariants } from '@/components/ui/button'
|
||||
import { cn } from '@/lib/utils'
|
||||
import Link from 'next/link'
|
||||
@@ -47,6 +47,13 @@ export function Header({ onMenuClick }: { onMenuClick: () => void }) {
|
||||
badge: 'Akun',
|
||||
Icon: User
|
||||
}
|
||||
case '/reports':
|
||||
return {
|
||||
title: 'Laporan Keuangan',
|
||||
subtitle: 'Pantau omzet, pengeluaran, dan hutang piutang Anda.',
|
||||
badge: 'Laporan',
|
||||
Icon: BarChart2
|
||||
}
|
||||
default:
|
||||
if (pathname.startsWith('/my-orders/')) {
|
||||
return {
|
||||
@@ -57,9 +64,9 @@ export function Header({ onMenuClick }: { onMenuClick: () => void }) {
|
||||
}
|
||||
}
|
||||
return {
|
||||
title: 'TitipIn Dashboard',
|
||||
title: 'TitipIn',
|
||||
subtitle: 'Sistem Titip Pesanan Bersama',
|
||||
badge: 'Dashboard',
|
||||
badge: 'App',
|
||||
Icon: Store
|
||||
}
|
||||
}
|
||||
@@ -102,9 +109,9 @@ export function Header({ onMenuClick }: { onMenuClick: () => void }) {
|
||||
{/* Right: Date info & Quick Action */}
|
||||
<div className="flex items-center gap-3">
|
||||
{todayStr && (
|
||||
<div className="hidden md:flex items-center gap-2 px-3 py-1.5 rounded-xl bg-slate-100/70 dark:bg-slate-800/60 border border-slate-200/60 dark:border-slate-800 text-xs font-medium text-slate-600 dark:text-slate-300 animate-in fade-in">
|
||||
<Calendar className="w-3.5 h-3.5 text-[#1B2CC1]" />
|
||||
<span>{todayStr}</span>
|
||||
<div className="flex items-center gap-2 px-3 py-1.5 rounded-xl bg-slate-100/70 dark:bg-slate-800/60 border border-slate-200/60 dark:border-slate-800 text-[10px] sm:text-xs font-medium text-slate-600 dark:text-slate-300 animate-in fade-in font-bold">
|
||||
<Calendar className="w-3.5 h-3.5 text-[#1B2CC1] shrink-0" />
|
||||
<span className='font-bold whitespace-nowrap'>{todayStr}</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -9,6 +9,7 @@ const navItems = [
|
||||
{ name: 'Open Order', href: '/' },
|
||||
{ name: 'Jasa Order Saya', href: '/my-orders' },
|
||||
{ name: 'Pesanan Saya', href: '/my-purchases' },
|
||||
{ name: 'Laporan', href: '/reports' },
|
||||
{ name: 'Profile', href: '/profile' },
|
||||
]
|
||||
|
||||
|
||||
@@ -0,0 +1,315 @@
|
||||
'use client'
|
||||
|
||||
import React, { useState, useEffect } from 'react'
|
||||
import { Card } from '@/components/ui/card'
|
||||
import { ChevronDown, ChevronUp, Users, CheckCircle2, Package, InboxIcon, ChevronLeft, ChevronRight, Search } from 'lucide-react'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter, DialogDescription } from '@/components/ui/dialog'
|
||||
import { updateBulkSubmissionPayment } from '@/app/actions'
|
||||
import { format } from 'date-fns'
|
||||
|
||||
const ITEMS_PER_PAGE = 5
|
||||
|
||||
const formatRupiah = (value: number) =>
|
||||
new Intl.NumberFormat('id-ID', { style: 'currency', currency: 'IDR', maximumFractionDigits: 0 }).format(value)
|
||||
|
||||
export default function ReportByPersonGrid({ data, onUpdate }: { data: any[]; onUpdate: () => void }) {
|
||||
const [expandedRows, setExpandedRows] = useState<Record<string, boolean>>({})
|
||||
const [currentPage, setCurrentPage] = useState(1)
|
||||
const [searchQuery, setSearchQuery] = useState('')
|
||||
const [modalOpen, setModalOpen] = useState(false)
|
||||
const [saving, setSaving] = useState(false)
|
||||
const [target, setTarget] = useState<{ ids: string[]; label: string; amount: number }>({ ids: [], label: '', amount: 0 })
|
||||
|
||||
// Reset page + search when data changes (e.g. filter changed)
|
||||
useEffect(() => {
|
||||
setCurrentPage(1)
|
||||
setExpandedRows({})
|
||||
setSearchQuery('')
|
||||
}, [data])
|
||||
|
||||
// Reset page when search changes
|
||||
useEffect(() => {
|
||||
setCurrentPage(1)
|
||||
}, [searchQuery])
|
||||
|
||||
const toggleRow = (id: string) =>
|
||||
setExpandedRows(prev => ({ ...prev, [id]: !prev[id] }))
|
||||
|
||||
// Group by user
|
||||
const usersMap = new Map<string, any>()
|
||||
data.forEach(order => {
|
||||
order.submissions.forEach((sub: any) => {
|
||||
if (!usersMap.has(sub.user.id)) {
|
||||
usersMap.set(sub.user.id, {
|
||||
user: sub.user,
|
||||
totalPiutang: 0,
|
||||
totalPaid: 0,
|
||||
submissions: []
|
||||
})
|
||||
}
|
||||
const obj = usersMap.get(sub.user.id)
|
||||
const amount = Number(sub.bill) || 0
|
||||
if (sub.payment_status !== 'LUNAS') obj.totalPiutang += amount
|
||||
else obj.totalPaid += amount
|
||||
obj.submissions.push({ ...sub, orderTitle: order.title, orderDate: order.date })
|
||||
})
|
||||
})
|
||||
|
||||
const userList = Array.from(usersMap.values())
|
||||
.map(obj => ({
|
||||
...obj,
|
||||
// Sort each person's PO list by order date, newest first
|
||||
submissions: [...obj.submissions].sort(
|
||||
(a: any, b: any) => new Date(b.orderDate).getTime() - new Date(a.orderDate).getTime()
|
||||
)
|
||||
}))
|
||||
.sort((a, b) => b.totalPiutang - a.totalPiutang)
|
||||
|
||||
const q = searchQuery.toLowerCase().trim()
|
||||
const filteredUserList = q
|
||||
? userList.filter(u => u.user.name?.toLowerCase().includes(q))
|
||||
: userList
|
||||
|
||||
const totalPages = Math.ceil(filteredUserList.length / ITEMS_PER_PAGE)
|
||||
const paginatedList = filteredUserList.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE)
|
||||
|
||||
const openModal = (e: React.MouseEvent, ids: string[], label: string, amount: number) => {
|
||||
e.stopPropagation()
|
||||
setTarget({ ids, label, amount })
|
||||
setModalOpen(true)
|
||||
}
|
||||
|
||||
const handleConfirm = async () => {
|
||||
if (!target.ids.length) return
|
||||
setSaving(true)
|
||||
const res = await updateBulkSubmissionPayment(target.ids, 'LUNAS')
|
||||
setSaving(false)
|
||||
if (res.success) {
|
||||
setModalOpen(false)
|
||||
onUpdate()
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Card className="rounded-2xl border border-slate-200/90 dark:border-slate-800 bg-white dark:bg-slate-900 shadow-sm overflow-hidden">
|
||||
<div className="bg-slate-50/50 dark:bg-slate-800/40 px-4 py-3 border-b border-slate-100 dark:border-slate-800 flex flex-col sm:flex-row sm:items-center gap-3">
|
||||
<div className="flex items-center gap-2 flex-1">
|
||||
<Users className="w-4 h-4 text-[#1B2CC1] shrink-0" />
|
||||
<h3 className="text-sm font-black text-slate-800 dark:text-slate-200">Detail Piutang Berdasarkan Orang</h3>
|
||||
</div>
|
||||
<div className="flex items-center gap-2 bg-white dark:bg-slate-900 border border-slate-200 dark:border-slate-700 rounded-lg px-3 py-1.5 w-full sm:w-48">
|
||||
<Search className="w-3.5 h-3.5 text-slate-400 shrink-0" />
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Cari nama pemesan..."
|
||||
value={searchQuery}
|
||||
onChange={e => setSearchQuery(e.target.value)}
|
||||
className="text-xs font-medium bg-transparent border-none outline-none w-full text-slate-700 dark:text-slate-200 placeholder:text-slate-400"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{userList.length === 0 ? (
|
||||
<div className="flex flex-col items-center justify-center py-16 gap-3 text-slate-400">
|
||||
<InboxIcon className="w-10 h-10 opacity-40" />
|
||||
<p className="text-sm font-semibold">Tidak ada data pemesan di periode ini.</p>
|
||||
</div>
|
||||
) : filteredUserList.length === 0 ? (
|
||||
<div className="flex flex-col items-center justify-center py-16 gap-3 text-slate-400">
|
||||
<Search className="w-10 h-10 opacity-40" />
|
||||
<p className="text-sm font-semibold">Tidak ada hasil untuk "{searchQuery}".</p>
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<div className="overflow-x-auto">
|
||||
<table className="w-full text-sm text-left">
|
||||
<thead className="text-xs text-slate-500 uppercase bg-slate-50/30 dark:bg-slate-900/50">
|
||||
<tr>
|
||||
<th className="px-6 py-4 font-bold w-8"></th>
|
||||
<th className="px-6 py-4 font-bold">Nama Pemesan</th>
|
||||
<th className="px-6 py-4 font-bold text-center">Total PO</th>
|
||||
<th className="px-6 py-4 font-bold text-right">Total Piutang</th>
|
||||
<th className="px-6 py-4 font-bold text-center">Aksi</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="divide-y divide-slate-100 dark:divide-slate-800">
|
||||
{paginatedList.map((userObj) => {
|
||||
const isExpanded = !!expandedRows[userObj.user.id]
|
||||
const unpaid = userObj.submissions.filter((s: any) => s.payment_status !== 'LUNAS')
|
||||
|
||||
return (
|
||||
<React.Fragment key={userObj.user.id}>
|
||||
<tr
|
||||
onClick={() => toggleRow(userObj.user.id)}
|
||||
className={cn(
|
||||
'hover:bg-slate-50/50 dark:hover:bg-slate-800/40 cursor-pointer transition-colors group',
|
||||
isExpanded && 'bg-slate-50/30 dark:bg-slate-800/20'
|
||||
)}
|
||||
>
|
||||
<td className="px-6 py-4">
|
||||
<button className="text-slate-400 group-hover:text-[#1B2CC1] transition-colors p-1 rounded-full hover:bg-blue-50 dark:hover:bg-blue-900/30">
|
||||
{isExpanded ? <ChevronUp className="w-4 h-4" /> : <ChevronDown className="w-4 h-4" />}
|
||||
</button>
|
||||
</td>
|
||||
<td className="px-6 py-4">
|
||||
<div className="flex items-center gap-3">
|
||||
{userObj.user.photo ? (
|
||||
<img src={userObj.user.photo} alt={userObj.user.name} className="w-8 h-8 rounded-full object-cover ring-2 ring-slate-100 dark:ring-slate-800" />
|
||||
) : (
|
||||
<div className="w-8 h-8 rounded-full bg-[#1B2CC1]/10 text-[#1B2CC1] flex items-center justify-center font-bold text-xs ring-2 ring-slate-100 dark:ring-slate-800">
|
||||
{userObj.user.name.charAt(0).toUpperCase()}
|
||||
</div>
|
||||
)}
|
||||
<p className="font-bold text-slate-800 dark:text-slate-200">{userObj.user.name}</p>
|
||||
</div>
|
||||
</td>
|
||||
<td className="px-6 py-4 text-center font-semibold text-slate-600 dark:text-slate-400">
|
||||
{userObj.submissions.length} PO
|
||||
</td>
|
||||
<td className="px-6 py-4 text-right">
|
||||
{userObj.totalPiutang > 0 ? (
|
||||
<p className="font-black text-rose-600 dark:text-rose-400">{formatRupiah(userObj.totalPiutang)}</p>
|
||||
) : (
|
||||
<p className="font-bold text-emerald-600 dark:text-emerald-400">Lunas Semua</p>
|
||||
)}
|
||||
{userObj.totalPaid > 0 && (
|
||||
<p className="text-[10px] text-slate-500 font-semibold mt-0.5">Lunas: {formatRupiah(userObj.totalPaid)}</p>
|
||||
)}
|
||||
</td>
|
||||
<td className="px-6 py-4 text-center">
|
||||
{unpaid.length > 0 ? (
|
||||
<Button
|
||||
onClick={(e) => openModal(e, unpaid.map((s: any) => s.id), `Semua tagihan ${userObj.user.name}`, userObj.totalPiutang)}
|
||||
size="sm"
|
||||
className="h-8 text-[11px] font-bold bg-[#1B2CC1] text-white hover:bg-[#121E85] shadow-sm shadow-[#1B2CC1]/30 gap-1 px-3"
|
||||
>
|
||||
<CheckCircle2 className="w-3.5 h-3.5" /> Lunasi Semua
|
||||
</Button>
|
||||
):( <span className="text-[10px] font-bold text-slate-400">Selesai</span>)}
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
{isExpanded && (
|
||||
<tr className="bg-slate-50 dark:bg-slate-900/60">
|
||||
<td colSpan={5} className="px-6 py-5 border-l-4 border-l-[#1B2CC1]">
|
||||
<div className="pl-8 space-y-3">
|
||||
<h4 className="text-[11px] font-bold uppercase tracking-wider text-slate-500 flex items-center gap-1.5">
|
||||
<Package className="w-3.5 h-3.5" /> Rincian Hutang per PO
|
||||
</h4>
|
||||
<div className="overflow-hidden border border-slate-200/80 dark:border-slate-700 rounded-xl bg-white dark:bg-slate-800">
|
||||
<table className="w-full text-xs">
|
||||
<thead className="bg-slate-100/50 dark:bg-slate-700/30 text-slate-500 uppercase font-semibold">
|
||||
<tr>
|
||||
<th className="px-4 py-2.5 text-left">Judul PO</th>
|
||||
<th className="px-4 py-2.5 text-left">Tgl Order</th>
|
||||
<th className="px-4 py-2.5 text-left">Status</th>
|
||||
<th className="px-4 py-2.5 text-right">Tagihan</th>
|
||||
<th className="px-4 py-2.5 text-center">Aksi</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="divide-y divide-slate-100 dark:divide-slate-700/50">
|
||||
{userObj.submissions.map((sub: any) => {
|
||||
const isUnpaid = sub.payment_status !== 'LUNAS'
|
||||
return (
|
||||
<tr key={sub.id}>
|
||||
<td className="px-4 py-2.5 font-bold text-slate-800 dark:text-slate-200">{sub.orderTitle}</td>
|
||||
<td className="px-4 py-2.5 text-slate-500 font-medium">
|
||||
{format(new Date(sub.orderDate), 'dd MMM yyyy')}
|
||||
</td>
|
||||
<td className="px-4 py-2.5">
|
||||
<span className={cn(
|
||||
'text-[9px] font-bold px-1.5 py-0.5 rounded uppercase',
|
||||
!isUnpaid
|
||||
? 'text-emerald-700 bg-emerald-100 dark:text-emerald-400 dark:bg-emerald-950/40'
|
||||
: 'text-rose-700 bg-rose-100 dark:text-rose-400 dark:bg-rose-950/40'
|
||||
)}>
|
||||
{isUnpaid ? 'Belum' : 'Lunas'}
|
||||
</span>
|
||||
</td>
|
||||
<td className={cn('px-4 py-2.5 text-right font-black', isUnpaid ? 'text-rose-600 dark:text-rose-400' : 'text-emerald-600 dark:text-emerald-400')}>
|
||||
{sub.bill ? formatRupiah(sub.bill) : 'Rp0'}
|
||||
</td>
|
||||
<td className="px-4 py-2.5 text-center">
|
||||
{isUnpaid ? (
|
||||
<Button
|
||||
onClick={(e) => openModal(e, [sub.id], `PO: ${sub.orderTitle}`, Number(sub.bill) || 0)}
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="h-6 text-[10px] px-2 font-bold border-[#1B2CC1]/40 text-[#1B2CC1] hover:bg-[#1B2CC1] hover:text-white transition-colors"
|
||||
>
|
||||
Lunasi
|
||||
</Button>
|
||||
) : (
|
||||
<span className="text-[10px] font-bold text-slate-400">Selesai</span>
|
||||
)}
|
||||
</td>
|
||||
</tr>
|
||||
)
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
)}
|
||||
</React.Fragment>
|
||||
)
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
{/* Pagination */}
|
||||
{totalPages > 1 && (
|
||||
<div className="flex items-center justify-between px-6 py-4 bg-slate-50/50 dark:bg-slate-900/50 border-t border-slate-100 dark:border-slate-800">
|
||||
<p className="text-xs font-medium text-slate-500">
|
||||
Halaman <span className="font-bold text-slate-700 dark:text-slate-300">{currentPage}</span> dari{' '}
|
||||
<span className="font-bold text-slate-700 dark:text-slate-300">{totalPages}</span>
|
||||
</p>
|
||||
<div className="flex items-center gap-1">
|
||||
<button onClick={() => setCurrentPage(p => Math.max(1, p - 1))} disabled={currentPage === 1} className="p-1.5 rounded-lg border border-slate-200 dark:border-slate-700 disabled:opacity-40 hover:bg-slate-100 dark:hover:bg-slate-800 transition-colors">
|
||||
<ChevronLeft className="w-3.5 h-3.5" />
|
||||
</button>
|
||||
<button onClick={() => setCurrentPage(p => Math.min(totalPages, p + 1))} disabled={currentPage === totalPages} className="p-1.5 rounded-lg border border-slate-200 dark:border-slate-700 disabled:opacity-40 hover:bg-slate-100 dark:hover:bg-slate-800 transition-colors">
|
||||
<ChevronRight className="w-3.5 h-3.5" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</Card>
|
||||
|
||||
{/* Confirmation Modal */}
|
||||
<Dialog open={modalOpen} onOpenChange={setModalOpen}>
|
||||
<DialogContent className="sm:max-w-md rounded-2xl">
|
||||
<DialogHeader>
|
||||
<DialogTitle className="text-xl font-black text-slate-900 dark:text-white flex items-center gap-2">
|
||||
<CheckCircle2 className="w-6 h-6 text-emerald-500" />
|
||||
Konfirmasi Pelunasan
|
||||
</DialogTitle>
|
||||
<DialogDescription className="text-slate-500 pt-2">
|
||||
Tandai <strong className="text-slate-800 dark:text-slate-200">{target.label}</strong> sebagai <strong>LUNAS</strong>?
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<div className="bg-slate-50 dark:bg-slate-900/50 p-4 rounded-xl border border-slate-100 dark:border-slate-800 my-2">
|
||||
<p className="text-xs font-bold text-slate-500 uppercase tracking-wider mb-1">Total Nominal</p>
|
||||
<p className="text-2xl font-black text-emerald-600 dark:text-emerald-400">{formatRupiah(target.amount)}</p>
|
||||
</div>
|
||||
<DialogFooter className="gap-2 sm:gap-0">
|
||||
<Button variant="outline" onClick={() => setModalOpen(false)} disabled={saving} className="rounded-xl font-bold">
|
||||
Batal
|
||||
</Button>
|
||||
<Button onClick={handleConfirm} disabled={saving} className="rounded-xl font-bold bg-emerald-600 hover:bg-emerald-700 text-white shadow-md shadow-emerald-600/20">
|
||||
{saving ? 'Menyimpan...' : 'Ya, Simpan Pelunasan'}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
'use client'
|
||||
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { BarChart, Bar, XAxis, YAxis, Tooltip, ResponsiveContainer, CartesianGrid, Cell } from 'recharts'
|
||||
|
||||
export default function ReportCharts({ type, data }: { type: 'SUBMITTOR' | 'CREATOR', data: any[] }) {
|
||||
|
||||
const formatRupiah = (value: number) => {
|
||||
return new Intl.NumberFormat('id-ID', { style: 'currency', currency: 'IDR', maximumFractionDigits: 0 }).format(value)
|
||||
}
|
||||
|
||||
// Prepare chart data based on type
|
||||
let chartData: any[] = []
|
||||
|
||||
if (type === 'SUBMITTOR') {
|
||||
chartData = [...data]
|
||||
.filter(sub => sub.order.status === 'CLOSE')
|
||||
.sort((a, b) => new Date(a.order.date).getTime() - new Date(b.order.date).getTime()) // oldest → newest
|
||||
.map(sub => ({
|
||||
name: sub.order.title.length > 15 ? sub.order.title.substring(0, 15) + '...' : sub.order.title,
|
||||
fullTitle: sub.order.title,
|
||||
Total: sub.bill || 0,
|
||||
status: sub.payment_status
|
||||
}))
|
||||
} else {
|
||||
chartData = [...data]
|
||||
.filter(order => order.status === 'CLOSE')
|
||||
.sort((a, b) => new Date(a.date).getTime() - new Date(b.date).getTime()) // oldest → newest
|
||||
.map(order => {
|
||||
const total = order.submissions.reduce((acc: number, sub: any) => acc + (sub.bill || 0), 0)
|
||||
return {
|
||||
name: order.title.length > 15 ? order.title.substring(0, 15) + '...' : order.title,
|
||||
fullTitle: order.title,
|
||||
Total: total,
|
||||
status: order.status
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// If no data to show
|
||||
if (chartData.length === 0) {
|
||||
return (
|
||||
<Card className="rounded-2xl border border-slate-200/90 dark:border-slate-800 bg-white dark:bg-slate-900 shadow-sm">
|
||||
<CardContent className="p-12 text-center">
|
||||
<p className="text-slate-500 text-xs font-medium">Belum ada data transaksi yang cukup untuk ditampilkan di grafik.</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)
|
||||
}
|
||||
|
||||
const CustomTooltip = ({ active, payload, label }: any) => {
|
||||
if (active && payload && payload.length) {
|
||||
return (
|
||||
<div className="bg-white dark:bg-slate-900 p-3 border border-slate-200 dark:border-slate-800 rounded-xl shadow-lg">
|
||||
<p className="font-bold text-xs text-slate-800 dark:text-slate-200 mb-1">{payload[0].payload.fullTitle}</p>
|
||||
<p className="text-sm font-black text-[#1B2CC1]">
|
||||
{formatRupiah(payload[0].value)}
|
||||
</p>
|
||||
<p className="text-[10px] text-slate-500 mt-1 uppercase font-bold tracking-wider">
|
||||
Status: {payload[0].payload.status}
|
||||
</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
<Card className="rounded-2xl border border-slate-200/90 dark:border-slate-800 bg-white dark:bg-slate-900 shadow-sm overflow-hidden">
|
||||
<CardHeader className="bg-slate-50/50 dark:bg-slate-800/40 border-b border-slate-100 dark:border-slate-800 p-4">
|
||||
<CardTitle className="text-sm font-black text-slate-800 dark:text-slate-200">
|
||||
{type === 'SUBMITTOR' ? 'Grafik Pengeluaran per PO' : 'Grafik Omzet per PO'}
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="p-4 sm:p-6 h-[300px] w-full">
|
||||
<ResponsiveContainer width="100%" height="100%">
|
||||
<BarChart data={chartData} margin={{ top: 10, right: 10, left: -20, bottom: 0 }}>
|
||||
<CartesianGrid strokeDasharray="3 3" vertical={false} stroke="#e2e8f0" />
|
||||
<XAxis
|
||||
dataKey="name"
|
||||
axisLine={false}
|
||||
tickLine={false}
|
||||
tick={{ fontSize: 10, fill: '#64748b' }}
|
||||
dy={10}
|
||||
/>
|
||||
<YAxis
|
||||
axisLine={false}
|
||||
tickLine={false}
|
||||
tick={{ fontSize: 10, fill: '#64748b' }}
|
||||
tickFormatter={(value) => `Rp${value / 1000}k`}
|
||||
/>
|
||||
<Tooltip cursor={{ fill: 'rgba(27, 44, 193, 0.05)' }} content={<CustomTooltip />} />
|
||||
<Bar dataKey="Total" radius={[4, 4, 0, 0]}>
|
||||
{chartData.map((entry, index) => (
|
||||
<Cell
|
||||
key={`cell-${index}`}
|
||||
fill={type === 'SUBMITTOR'
|
||||
? (entry.status === 'LUNAS' ? '#10b981' : '#f43f5e') // Emerald or Rose
|
||||
: '#1B2CC1' // Primary for creator
|
||||
}
|
||||
/>
|
||||
))}
|
||||
</Bar>
|
||||
</BarChart>
|
||||
</ResponsiveContainer>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,339 @@
|
||||
'use client'
|
||||
|
||||
import React, { useState, useEffect } from 'react'
|
||||
import { Card } from '@/components/ui/card'
|
||||
import { ChevronDown, ChevronUp, Package, Users, Receipt, Calendar, Wallet, TrendingUp, InboxIcon, ChevronLeft, ChevronRight, Search } from 'lucide-react'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { format } from 'date-fns'
|
||||
|
||||
const ITEMS_PER_PAGE = 5
|
||||
|
||||
function PaginationBar({ currentPage, totalPages, onPage }: { currentPage: number; totalPages: number; onPage: (p: number) => void }) {
|
||||
if (totalPages <= 1) return null
|
||||
return (
|
||||
<div className="flex items-center justify-between px-6 py-4 bg-slate-50/50 dark:bg-slate-900/50 border-t border-slate-100 dark:border-slate-800">
|
||||
<p className="text-xs font-medium text-slate-500">
|
||||
Halaman <span className="font-bold text-slate-700 dark:text-slate-300">{currentPage}</span> dari{' '}
|
||||
<span className="font-bold text-slate-700 dark:text-slate-300">{totalPages}</span>
|
||||
</p>
|
||||
<div className="flex items-center gap-1">
|
||||
<button
|
||||
onClick={() => onPage(Math.max(1, currentPage - 1))}
|
||||
disabled={currentPage === 1}
|
||||
className="p-1.5 rounded-lg border border-slate-200 dark:border-slate-700 disabled:opacity-40 hover:bg-slate-100 dark:hover:bg-slate-800 transition-colors"
|
||||
>
|
||||
<ChevronLeft className="w-3.5 h-3.5" />
|
||||
</button>
|
||||
<button
|
||||
onClick={() => onPage(Math.min(totalPages, currentPage + 1))}
|
||||
disabled={currentPage === totalPages}
|
||||
className="p-1.5 rounded-lg border border-slate-200 dark:border-slate-700 disabled:opacity-40 hover:bg-slate-100 dark:hover:bg-slate-800 transition-colors"
|
||||
>
|
||||
<ChevronRight className="w-3.5 h-3.5" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function EmptyState({ label }: { label: string }) {
|
||||
return (
|
||||
<div className="flex flex-col items-center justify-center py-16 gap-3 text-slate-400">
|
||||
<InboxIcon className="w-10 h-10 opacity-40" />
|
||||
<p className="text-sm font-semibold">{label}</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const formatRupiah = (value: number) =>
|
||||
new Intl.NumberFormat('id-ID', { style: 'currency', currency: 'IDR', maximumFractionDigits: 0 }).format(value)
|
||||
|
||||
export default function ReportDataGrid({ type, data }: { type: 'SUBMITTOR' | 'CREATOR'; data: any[] }) {
|
||||
const [expandedRows, setExpandedRows] = useState<Record<string, boolean>>({})
|
||||
const [currentPage, setCurrentPage] = useState(1)
|
||||
const [searchQuery, setSearchQuery] = useState('')
|
||||
|
||||
// Reset page + search when data changes (e.g. filter changed)
|
||||
useEffect(() => {
|
||||
setCurrentPage(1)
|
||||
setExpandedRows({})
|
||||
setSearchQuery('')
|
||||
}, [data])
|
||||
|
||||
// Reset page when search changes
|
||||
useEffect(() => {
|
||||
setCurrentPage(1)
|
||||
}, [searchQuery])
|
||||
|
||||
const q = searchQuery.toLowerCase().trim()
|
||||
|
||||
const filteredData = q
|
||||
? data.filter(item => {
|
||||
if (type === 'SUBMITTOR') {
|
||||
return (
|
||||
item.order?.title?.toLowerCase().includes(q) ||
|
||||
item.order?.creator?.name?.toLowerCase().includes(q)
|
||||
)
|
||||
} else {
|
||||
return item.title?.toLowerCase().includes(q)
|
||||
}
|
||||
})
|
||||
: data
|
||||
|
||||
const totalPages = Math.ceil(filteredData.length / ITEMS_PER_PAGE)
|
||||
const paginatedData = filteredData.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE)
|
||||
|
||||
const toggleRow = (id: string) =>
|
||||
setExpandedRows(prev => ({ ...prev, [id]: !prev[id] }))
|
||||
|
||||
/* ─────────────── SUBMITTOR TABLE ─────────────── */
|
||||
if (type === 'SUBMITTOR') {
|
||||
return (
|
||||
<Card className="rounded-2xl border border-slate-200/90 dark:border-slate-800 bg-white dark:bg-slate-900 shadow-sm overflow-hidden">
|
||||
<div className="bg-slate-50/50 dark:bg-slate-800/40 px-4 py-3 border-b border-slate-100 dark:border-slate-800 flex flex-col sm:flex-row sm:items-center gap-3">
|
||||
<div className="flex items-center gap-2 flex-1">
|
||||
<Wallet className="w-4 h-4 text-[#1B2CC1] shrink-0" />
|
||||
<h3 className="text-sm font-black text-slate-800 dark:text-slate-200">Detail Pengeluaran Anda</h3>
|
||||
</div>
|
||||
<div className="flex items-center gap-2 bg-white dark:bg-slate-900 border border-slate-200 dark:border-slate-700 rounded-lg px-3 py-1.5 w-full sm:w-52">
|
||||
<Search className="w-3.5 h-3.5 text-slate-400 shrink-0" />
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Cari judul PO atau kreator..."
|
||||
value={searchQuery}
|
||||
onChange={e => setSearchQuery(e.target.value)}
|
||||
className="text-xs font-medium bg-transparent border-none outline-none w-full text-slate-700 dark:text-slate-200 placeholder:text-slate-400"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{data.length === 0 ? (
|
||||
<EmptyState label="Tidak ada transaksi di periode ini." />
|
||||
) : filteredData.length === 0 ? (
|
||||
<EmptyState label={`Tidak ada hasil untuk "${searchQuery}".`} />
|
||||
) : (
|
||||
<>
|
||||
<div className="overflow-x-auto">
|
||||
<table className="w-full text-sm text-left">
|
||||
<thead className="text-xs text-slate-500 uppercase bg-slate-50/30 dark:bg-slate-900/50">
|
||||
<tr>
|
||||
<th className="px-6 py-4 font-bold w-8"></th>
|
||||
<th className="px-6 py-4 font-bold">Judul PO & Kreator</th>
|
||||
<th className="px-6 py-4 font-bold">Tanggal</th>
|
||||
<th className="px-6 py-4 font-bold">Status Bayar</th>
|
||||
<th className="px-6 py-4 font-bold text-right">Total Tagihan</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="divide-y divide-slate-100 dark:divide-slate-800">
|
||||
{paginatedData.map((sub: any) => {
|
||||
const isExpanded = !!expandedRows[sub.id]
|
||||
return (
|
||||
<React.Fragment key={sub.id}>
|
||||
<tr
|
||||
onClick={() => toggleRow(sub.id)}
|
||||
className={cn(
|
||||
'hover:bg-slate-50/50 dark:hover:bg-slate-800/40 cursor-pointer transition-colors group',
|
||||
isExpanded && 'bg-slate-50/30 dark:bg-slate-800/20'
|
||||
)}
|
||||
>
|
||||
<td className="px-6 py-4">
|
||||
<button className="text-slate-400 group-hover:text-[#1B2CC1] transition-colors p-1 rounded-full hover:bg-blue-50 dark:hover:bg-blue-900/30">
|
||||
{isExpanded ? <ChevronUp className="w-4 h-4" /> : <ChevronDown className="w-4 h-4" />}
|
||||
</button>
|
||||
</td>
|
||||
<td className="px-6 py-4">
|
||||
<p className="font-bold text-slate-800 dark:text-slate-200">{sub.order.title}</p>
|
||||
<p className="text-[11px] text-slate-500 flex items-center gap-1 mt-0.5">
|
||||
<Users className="w-3 h-3" /> {sub.order.creator.name}
|
||||
</p>
|
||||
</td>
|
||||
<td className="px-6 py-4 text-xs text-slate-600 dark:text-slate-400">
|
||||
{format(new Date(sub.order.date), 'dd MMM yyyy')}
|
||||
</td>
|
||||
<td className="px-6 py-4">
|
||||
<span className={cn(
|
||||
'inline-flex px-2 py-0.5 rounded-full text-[10px] font-black tracking-wide',
|
||||
sub.payment_status === 'LUNAS'
|
||||
? 'bg-emerald-50 text-emerald-700 dark:bg-emerald-950/50 dark:text-emerald-400 border border-emerald-200/80'
|
||||
: 'bg-rose-50 text-rose-700 dark:bg-rose-950/50 dark:text-rose-400 border border-rose-200/80'
|
||||
)}>
|
||||
{sub.payment_status === 'LUNAS' ? 'LUNAS' : 'BELUM BAYAR'}
|
||||
</span>
|
||||
</td>
|
||||
<td className="px-6 py-4 text-right font-black text-slate-900 dark:text-white">
|
||||
{sub.bill ? formatRupiah(sub.bill) : '-'}
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
{isExpanded && (
|
||||
<tr className="bg-slate-50 dark:bg-slate-900/60">
|
||||
<td colSpan={5} className="px-6 py-5 border-l-4 border-l-[#1B2CC1]">
|
||||
<div className="pl-8">
|
||||
<h4 className="text-[11px] font-bold uppercase tracking-wider text-slate-500 mb-3 flex items-center gap-1.5">
|
||||
<Package className="w-3.5 h-3.5" /> Item yang Anda Pesan
|
||||
</h4>
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-2">
|
||||
{sub.items.map((item: any) => (
|
||||
<div key={item.id} className="bg-white dark:bg-slate-800 border border-slate-200/60 dark:border-slate-700 px-3 py-2 rounded-xl flex items-center justify-between shadow-sm">
|
||||
<span className="text-xs font-semibold text-slate-700 dark:text-slate-300 pr-2">{item.name}</span>
|
||||
<span className="text-xs font-black text-[#1B2CC1] bg-blue-50 dark:bg-blue-900/30 px-2 py-0.5 rounded-md">{item.qty}x</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
)}
|
||||
</React.Fragment>
|
||||
)
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<PaginationBar currentPage={currentPage} totalPages={totalPages} onPage={setCurrentPage} />
|
||||
</>
|
||||
)}
|
||||
</Card>
|
||||
)
|
||||
}
|
||||
|
||||
/* ─────────────── CREATOR TABLE ─────────────── */
|
||||
return (
|
||||
<Card className="rounded-2xl border border-slate-200/90 dark:border-slate-800 bg-white dark:bg-slate-900 shadow-sm overflow-hidden">
|
||||
<div className="bg-slate-50/50 dark:bg-slate-800/40 px-4 py-3 border-b border-slate-100 dark:border-slate-800 flex flex-col sm:flex-row sm:items-center gap-3">
|
||||
<div className="flex items-center gap-2 flex-1">
|
||||
<TrendingUp className="w-4 h-4 text-[#1B2CC1] shrink-0" />
|
||||
<h3 className="text-sm font-black text-slate-800 dark:text-slate-200">Riwayat Omzet per PO</h3>
|
||||
</div>
|
||||
<div className="flex items-center gap-2 bg-white dark:bg-slate-900 border border-slate-200 dark:border-slate-700 rounded-lg px-3 py-1.5 w-full sm:w-52">
|
||||
<Search className="w-3.5 h-3.5 text-slate-400 shrink-0" />
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Cari judul PO..."
|
||||
value={searchQuery}
|
||||
onChange={e => setSearchQuery(e.target.value)}
|
||||
className="text-xs font-medium bg-transparent border-none outline-none w-full text-slate-700 dark:text-slate-200 placeholder:text-slate-400"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{data.length === 0 ? (
|
||||
<EmptyState label="Tidak ada PO di periode ini." />
|
||||
) : filteredData.length === 0 ? (
|
||||
<EmptyState label={`Tidak ada hasil untuk "${searchQuery}".`} />
|
||||
) : (
|
||||
<>
|
||||
<div className="overflow-x-auto">
|
||||
<table className="w-full text-sm text-left">
|
||||
<thead className="text-xs text-slate-500 uppercase bg-slate-50/30 dark:bg-slate-900/50">
|
||||
<tr>
|
||||
<th className="px-6 py-4 font-bold w-8"></th>
|
||||
<th className="px-6 py-4 font-bold">Judul PO</th>
|
||||
<th className="px-6 py-4 font-bold">Status</th>
|
||||
<th className="px-6 py-4 font-bold text-center">Peserta</th>
|
||||
<th className="px-6 py-4 font-bold text-right">Total Omzet PO</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="divide-y divide-slate-100 dark:divide-slate-800">
|
||||
{paginatedData.map((order: any) => {
|
||||
const isExpanded = !!expandedRows[order.id]
|
||||
const totalOmzet = order.submissions.reduce((acc: number, sub: any) => acc + (Number(sub.bill) || 0), 0)
|
||||
const totalPiutang = order.submissions.reduce((acc: number, sub: any) => acc + (sub.payment_status !== 'LUNAS' ? (Number(sub.bill) || 0) : 0), 0)
|
||||
|
||||
return (
|
||||
<React.Fragment key={order.id}>
|
||||
<tr
|
||||
onClick={() => toggleRow(order.id)}
|
||||
className={cn(
|
||||
'hover:bg-slate-50/50 dark:hover:bg-slate-800/40 cursor-pointer transition-colors group',
|
||||
isExpanded && 'bg-slate-50/30 dark:bg-slate-800/20'
|
||||
)}
|
||||
>
|
||||
<td className="px-6 py-4">
|
||||
<button className="text-slate-400 group-hover:text-[#1B2CC1] transition-colors p-1 rounded-full hover:bg-blue-50 dark:hover:bg-blue-900/30">
|
||||
{isExpanded ? <ChevronUp className="w-4 h-4" /> : <ChevronDown className="w-4 h-4" />}
|
||||
</button>
|
||||
</td>
|
||||
<td className="px-6 py-4">
|
||||
<p className="font-bold text-slate-800 dark:text-slate-200">{order.title}</p>
|
||||
<p className="text-[11px] text-slate-500 flex items-center gap-1 mt-0.5">
|
||||
<Calendar className="w-3 h-3" /> {format(new Date(order.date), 'dd MMM yyyy')}
|
||||
</p>
|
||||
</td>
|
||||
<td className="px-6 py-4">
|
||||
<span className={cn(
|
||||
'inline-flex items-center px-2 py-0.5 rounded-full text-[10px] font-black tracking-wide',
|
||||
order.status === 'CLOSE' ? 'bg-rose-50 text-rose-700 dark:bg-rose-950/50 dark:text-rose-400 border border-rose-200/80' : 'bg-slate-100 text-slate-700 dark:bg-slate-800 dark:text-slate-300 border border-slate-200/90'
|
||||
)}>
|
||||
● {order.status}
|
||||
</span>
|
||||
</td>
|
||||
<td className="px-6 py-4 text-center font-semibold text-slate-700 dark:text-slate-300">
|
||||
{order.submissions.length} Orang
|
||||
</td>
|
||||
<td className="px-6 py-4 text-right">
|
||||
<p className="font-black text-slate-900 dark:text-white">{formatRupiah(totalOmzet)}</p>
|
||||
{totalPiutang > 0 && (
|
||||
<p className="text-[10px] text-rose-500 font-bold mt-0.5">Piutang: {formatRupiah(totalPiutang)}</p>
|
||||
)}
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
{isExpanded && (
|
||||
<tr className="bg-slate-50 dark:bg-slate-900/60">
|
||||
<td colSpan={5} className="px-6 py-5 border-l-4 border-l-[#1B2CC1]">
|
||||
<div className="pl-8 space-y-3">
|
||||
<h4 className="text-[11px] font-bold uppercase tracking-wider text-slate-500 flex items-center gap-1.5">
|
||||
<Receipt className="w-3.5 h-3.5" /> Breakdown Pemesan
|
||||
</h4>
|
||||
{order.submissions.length === 0 ? (
|
||||
<p className="text-xs text-slate-400 italic">Belum ada pemesan.</p>
|
||||
) : (
|
||||
<div className="overflow-hidden border border-slate-200/80 dark:border-slate-700 rounded-xl bg-white dark:bg-slate-800">
|
||||
<table className="w-full text-xs">
|
||||
<thead className="bg-slate-100/50 dark:bg-slate-700/30 text-slate-500 uppercase font-semibold">
|
||||
<tr>
|
||||
<th className="px-4 py-2.5 text-left">Nama</th>
|
||||
<th className="px-4 py-2.5 text-left">Status</th>
|
||||
<th className="px-4 py-2.5 text-right">Tagihan</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="divide-y divide-slate-100 dark:divide-slate-700/50">
|
||||
{order.submissions.map((sub: any) => (
|
||||
<tr key={sub.id}>
|
||||
<td className="px-4 py-2.5 font-semibold text-slate-800 dark:text-slate-200">{sub.user.name}</td>
|
||||
<td className="px-4 py-2.5">
|
||||
<span className={cn(
|
||||
'text-[9px] font-bold px-1.5 py-0.5 rounded uppercase',
|
||||
sub.payment_status === 'LUNAS'
|
||||
? 'text-emerald-700 bg-emerald-100 dark:text-emerald-400 dark:bg-emerald-950/40'
|
||||
: 'text-rose-700 bg-rose-100 dark:text-rose-400 dark:bg-rose-950/40'
|
||||
)}>
|
||||
{sub.payment_status === 'LUNAS' ? 'Lunas' : 'Belum'}
|
||||
</span>
|
||||
</td>
|
||||
<td className="px-4 py-2.5 text-right font-black text-slate-700 dark:text-slate-300">
|
||||
{sub.bill ? formatRupiah(sub.bill) : '-'}
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
)}
|
||||
</React.Fragment>
|
||||
)
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<PaginationBar currentPage={currentPage} totalPages={totalPages} onPage={setCurrentPage} />
|
||||
</>
|
||||
)}
|
||||
</Card>
|
||||
)
|
||||
}
|
||||
@@ -11,9 +11,9 @@ import {
|
||||
UserCircle,
|
||||
Sparkles,
|
||||
X,
|
||||
Layers,
|
||||
ArrowUpRight,
|
||||
Info
|
||||
Info,
|
||||
BarChart2
|
||||
} from 'lucide-react'
|
||||
import { checkUser } from '@/app/actions'
|
||||
|
||||
@@ -21,7 +21,7 @@ const menuItems = [
|
||||
{ name: 'Open Order', href: '/', icon: Store, desc: 'Daftar PO live hari ini' },
|
||||
{ name: 'Jasa Order Saya', href: '/my-orders', icon: ClipboardList, desc: 'Kelola PO buatan Anda' },
|
||||
{ name: 'Pesanan Saya', href: '/my-purchases', icon: ShoppingBag, desc: 'Riwayat titipan Anda' },
|
||||
{ name: 'Profile', href: '/profile', icon: UserCircle, desc: 'Pengaturan akun' },
|
||||
{ name: 'Laporan', href: '/reports', icon: BarChart2, desc: 'Ringkasan transaksi' },
|
||||
]
|
||||
|
||||
export function Sidebar({ isOpen, onClose }: { isOpen?: boolean; onClose?: () => void }) {
|
||||
@@ -163,7 +163,7 @@ export function Sidebar({ isOpen, onClose }: { isOpen?: boolean; onClose?: () =>
|
||||
<div className="w-5 h-5 rounded-lg bg-[#1B2CC1]/10 text-[#1B2CC1] flex items-center justify-center">
|
||||
<Info className="w-3 h-3" />
|
||||
</div>
|
||||
<span>Auto Rekap WhatsApp</span>
|
||||
<span>Auto Rekap</span>
|
||||
</div>
|
||||
<p className="text-[11px] text-slate-500 dark:text-slate-400 leading-relaxed">
|
||||
Gunakan Generator Rekap pada detail PO untuk salin ringkasan belanja otomatis ke chat grup.
|
||||
|
||||
Reference in New Issue
Block a user