'use client' import React from 'react' import PageLayout from '../../components/PageLayout' import InvoiceDetailModal from './components/InvoiceDetailModal' import { type AdminInvoice } from './hooks/getInvoices' import { useFinanceManagementPageState } from './hooks/useFinanceManagementPageState' function getStatusBadgeClass(status?: string) { if (status === 'paid') return 'bg-green-100 text-green-700' if (status === 'issued') return 'bg-indigo-100 text-indigo-700' if (status === 'draft') return 'bg-slate-100 text-slate-700' if (status === 'overdue') return 'bg-red-100 text-red-700' return 'bg-amber-100 text-amber-700' } function getStatusLabel(t: (key: string) => string, status?: string) { if (status === 'draft') return t('autofix.k5f6d9f11') if (status === 'issued') return t('autofix.kdc8f2ab2') if (status === 'paid') return t('autofix.k9d5b2d74') if (status === 'overdue') return t('autofix.k2f44ec11') if (status === 'canceled') return t('autofix.kcf31ed66') return status } function FinanceInvoiceActions({ invoice, pdfLoading, onViewPdf, onOpenDetails, t, }: { invoice: AdminInvoice pdfLoading: string | number | null onViewPdf: (invoice: AdminInvoice) => void onOpenDetails: (invoice: AdminInvoice) => void t: (key: string) => string }) { return ( ) } export default function FinanceManagementPage() { const { t, router, rates, vatLoading, vatError, timeframe, setTimeframe, billFilter, setBillFilter, diagLoading, diagError, diagData, selectedInvoice, setSelectedInvoice, detailModalOpen, setDetailModalOpen, emailDialogOpen, setEmailDialogOpen, reportEmail, setReportEmail, sendingReport, reportMsg, setReportMsg, invLoading, invError, reload, totals, filteredBills, exportBills, runPoolCheck, exportInvoice, pdfLoading, uploadModalOpen, setUploadModalOpen, uploadForm, setUploadForm, uploadFile, setUploadFile, uploading, uploadError, setUploadError, viewInvoicePdf, submitUploadInvoice, sendEmailReport, uploadPreview, } = useFinanceManagementPageState() return (
{t('autofix.k8070cd52')}

{t('autofix.k777299de')}

{t('autofix.k01ad6d49')}

{t('autofix.k73f7184d')}
EUR {totals.totalAll.toFixed(2)}
{t('autofix.k9b3082af')}
EUR {totals.totalRange.toFixed(2)}
{t('autofix.k9f4ec5e2')}
{filteredBills.length}
{t('autofix.kafb65833')}

{t('autofix.kf2180ff6')}

{t('autofix.k5ce7a5b0')}

{vatLoading && t('autofix.ka5d50257')} {vatError && {vatError}} {!vatLoading && !vatError && ( <> {t('autofix.k3e4a95bc').replace('{count}', String(rates.length)).replace('{examples}', rates.slice(0, 5).map((rate) => rate.country_code).join(', '))} )}

{t('autofix.k21f123af')}

setBillFilter((current) => ({ ...current, query: event.target.value }))} className="rounded-lg border border-slate-200 px-3 py-2 focus:ring-2 focus:ring-slate-900 focus:border-transparent" /> setBillFilter((current) => ({ ...current, from: event.target.value }))} className="rounded-lg border border-slate-200 px-3 py-2 focus:ring-2 focus:ring-slate-900 focus:border-transparent" /> setBillFilter((current) => ({ ...current, to: event.target.value }))} className="rounded-lg border border-slate-200 px-3 py-2 focus:ring-2 focus:ring-slate-900 focus:border-transparent" />
{reportMsg && (
{reportMsg.text}
)} {invError && (
{invError}
)} {(diagLoading || diagError || diagData) && (
{diagLoading &&
{t('autofix.k37d7b9c4')}
} {!diagLoading && diagError &&
{diagError}
} {!diagLoading && !diagError && diagData && (
{t('autofix.kf6a5a971').replace('{invoice}', String(diagData.invoice_id ?? '—'))}
{t('autofix.k81c0b74b')} {diagData.ok ? t('autofix.kaf7e90cc') : t('autofix.k6ba7f5b1')} {t('autofix.k77049179')} {diagData.reason}
{diagData.ok && (
{t('autofix.k4968eb2a')} {diagData.abonement_id} {t('autofix.kfaa8fc4a')} {diagData.will_book_count} {t('autofix.kd2e5e813')} {diagData.already_booked_count}
)} {Array.isArray(diagData.candidates) && diagData.candidates.length > 0 && (
{diagData.candidates.map((candidate: any) => ( ))}
{t('autofix.kf1b73a92')} {t('autofix.k2f9cd1e0')} {t('autofix.k1ddc3f42')} {t('autofix.kdb79aa30')} {t('autofix.k93e61ad1')}
{candidate.pool_name} #{candidate.coffee_table_id} {candidate.capsules_count} EUR {Number(candidate.amount_gross ?? candidate.amount_net ?? 0).toFixed(2)} {candidate.already_booked ? t('common.yes') : t('common.no')}
)}
)}
)} {invLoading ? ( <> ) : filteredBills.length === 0 ? ( ) : ( filteredBills.map((invoice) => ( { setSelectedInvoice(value) setDetailModalOpen(true) }} t={t} /> )) )}
{t('autofix.kf8f0c1f3')} {t('autofix.kf2b5c1a6')} {t('autofix.kd4af6368')} {t('autofix.k867f8265')} {t('autofix.k762eef76')} {t('autofix.k81c0b74b')} {t('autofix.k0afbbac4')}
{t('autofix.kbdb02e32')}
{invoice.invoice_number ?? invoice.id} {invoice.buyer_name ?? '—'} {invoice.issued_at ? new Date(invoice.issued_at).toLocaleDateString() : '—'} {(() => { if (!invoice.due_at) return const due = new Date(invoice.due_at) const now = new Date() const diffDays = Math.ceil((due.getTime() - now.getTime()) / (1000 * 60 * 60 * 24)) let cls = 'bg-green-100 text-green-700' if (invoice.status === 'paid') cls = 'bg-green-100 text-green-700' else if (diffDays < 0) cls = 'bg-red-100 text-red-700' else if (diffDays <= 3) cls = 'bg-red-100 text-red-700' else if (diffDays <= 7) cls = 'bg-amber-100 text-amber-700' return {due.toLocaleDateString()} })()} EUR {Number(invoice.total_gross ?? 0).toFixed(2)} {invoice.currency ?? 'EUR'} {getStatusLabel(t, invoice.status ?? '')}
{selectedInvoice && ( { setDetailModalOpen(false) setTimeout(() => setSelectedInvoice(null), 200) }} onStatusChanged={reload} onRunPoolCheck={(id) => { setDetailModalOpen(false) runPoolCheck(id) }} onExport={(invoice) => exportInvoice(invoice)} /> )} {uploadModalOpen && (

{t('autofix.kec5a5357')}

setUploadForm((current) => ({ ...current, buyer_name: event.target.value }))} placeholder={t('autofix.k1882bd75')} />
setUploadForm((current) => ({ ...current, buyer_email: event.target.value }))} placeholder={t('autofix.kf8c220d3')} />
setUploadForm((current) => ({ ...current, buyer_street: event.target.value }))} placeholder={t('autofix.k81c7c2f2')} />
setUploadForm((current) => ({ ...current, buyer_postal_code: event.target.value }))} placeholder="8010" />
setUploadForm((current) => ({ ...current, buyer_city: event.target.value }))} placeholder="Graz" />
setUploadForm((current) => ({ ...current, buyer_country: event.target.value }))} placeholder="Austria" />
setUploadForm((current) => ({ ...current, total_gross: event.target.value }))} placeholder="0.00" />
setUploadForm((current) => ({ ...current, vat_rate: event.target.value }))} placeholder="20" />
{t('autofix.k1f5a403a')}
{uploadForm.currency} {uploadPreview.net.toFixed(2)}
{t('autofix.k089e8c08')}
{uploadForm.currency} {uploadPreview.tax.toFixed(2)}
setUploadForm((current) => ({ ...current, issued_at: event.target.value }))} />
setUploadForm((current) => ({ ...current, due_at: event.target.value }))} />
setUploadFile(event.target.files?.[0] ?? null)} /> {uploadFile &&

{uploadFile.name}

}
{uploadError &&
{uploadError}
}
)} {emailDialogOpen && (

{t('autofix.kfdcad59b')}

{t('autofix.k45c3fd51').replace('{paid}', t('autofix.k9d5b2d74').toLowerCase())} {(billFilter.from || billFilter.to) && ( {t('autofix.kdd22a5f2').replace('{from}', billFilter.from || '…').replace('{to}', billFilter.to || '…')} )}
setReportEmail(event.target.value)} placeholder={t('autofix.k51ee3aae')} className="w-full rounded-lg border border-slate-200 px-3 py-2 text-sm text-slate-900 placeholder:text-slate-400 focus:ring-2 focus:ring-slate-900 focus:border-transparent" autoFocus onKeyDown={(event) => { if (event.key === 'Enter' && !sendingReport) sendEmailReport() }} />
)}
) }