"use client"; import { useQuery } from "@tanstack/react-query"; import Link from "next/link"; import { accountingApi } from "@/lib/accounting-api"; import { useTenantId } from "@/hooks/useTenantId"; import { CompletionScoreboard } from "@/components/accounting/CompletionScoreboard"; import { PageHeader, StatCard, LoadingState, ErrorState, Badge, Button, Card, CardContent, } from "@/components/ds"; export default function AccountingDashboardPage() { const { tenantId, loading: tenantLoading } = useTenantId(); const healthQ = useQuery({ queryKey: ["accounting", "health"], queryFn: () => accountingApi.health(), }); const setupQ = useQuery({ queryKey: ["accounting", tenantId, "setup-status"], queryFn: () => accountingApi.setup.status(tenantId!), enabled: !!tenantId, }); const chartsQ = useQuery({ queryKey: ["accounting", tenantId, "charts"], queryFn: () => accountingApi.charts.list(tenantId!), enabled: !!tenantId, }); const accountsQ = useQuery({ queryKey: ["accounting", tenantId, "accounts"], queryFn: () => accountingApi.accounts.list(tenantId!), enabled: !!tenantId, }); const yearsQ = useQuery({ queryKey: ["accounting", tenantId, "fiscal-years"], queryFn: () => accountingApi.fiscal.listYears(tenantId!), enabled: !!tenantId, }); const vouchersQ = useQuery({ queryKey: ["accounting", tenantId, "vouchers"], queryFn: () => accountingApi.vouchers.list(tenantId!), enabled: !!tenantId, }); if (tenantLoading || !tenantId) return ; const err = chartsQ.error || accountsQ.error || yearsQ.error || vouchersQ.error || healthQ.error; if (err) { return ( { void chartsQ.refetch(); void accountsQ.refetch(); void yearsQ.refetch(); void vouchersQ.refetch(); }} /> ); } const loading = chartsQ.isLoading || accountsQ.isLoading || yearsQ.isLoading || vouchersQ.isLoading; if (loading) return ; const setup = setupQ.data; const setupIncomplete = setup && setup.percent < 100; return (
{healthQ.data ? ( سرویس {healthQ.data.version} ) : null}
} /> {setupIncomplete ? (

راه‌اندازی حسابداری

{setup!.completed_steps} از {setup!.total_steps} مرحله تکمیل شده ({setup!.percent}٪)

) : null}

آخرین اسناد

{(vouchersQ.data?.length ?? 0) === 0 ? (

هنوز سندی ثبت نشده است.

) : (
    {vouchersQ.data!.slice(0, 5).map((v) => (
  • {v.voucher_number} {v.status}
  • ))}
)}

دسترسی سریع

{[ ["/accounting/chart-of-accounts", "دفتر حساب‌ها"], ["/accounting/fiscal", "سال و دوره مالی"], ["/accounting/ledger", "دفتر کل"], ["/accounting/vouchers", "اسناد حسابداری"], ["/accounting/setup", "راه‌اندازی"], ["/accounting/reports", "گزارش‌ها"], ].map(([href, label]) => ( {label} ))}
); }