mirror of
https://github.com/Since-3/since3-portal.git
synced 2026-10-12 19:51:17 +00:00
58 lines
2 KiB
TypeScript
58 lines
2 KiB
TypeScript
import { getClientId } from "@/modules/shared/queries/profile"
|
|
import { getInvoices, getProductTemplates, peekNextInvoiceNumber } from "@/modules/shared/queries/invoices"
|
|
import { getStammdaten } from "@/modules/shared/queries/stammdaten"
|
|
import { BillingDialog, type BillingPrefill } from "@/modules/shared/ui/components/billing-dialog"
|
|
import { InvoicesTable } from "@/modules/shared/ui/components/invoices-table"
|
|
|
|
async function AdminBillingDialog({ profileId }: { profileId: string }) {
|
|
const [stammdaten, templates, nextInvoiceNumber] = await Promise.all([
|
|
getStammdaten(profileId),
|
|
getProductTemplates(),
|
|
peekNextInvoiceNumber(),
|
|
])
|
|
|
|
const client = stammdaten?.client
|
|
const prefill: BillingPrefill | null = client
|
|
? {
|
|
companyName: client.company_name,
|
|
billingStreet: client.billing_street ?? client.street,
|
|
billingPostalCode: client.billing_postal_code ?? client.postal_code,
|
|
billingCity: client.billing_city ?? client.city,
|
|
billingCountry: client.billing_country ?? client.country,
|
|
}
|
|
: null
|
|
|
|
return (
|
|
<BillingDialog
|
|
profileId={profileId}
|
|
prefill={prefill}
|
|
nextInvoiceNumber={nextInvoiceNumber}
|
|
templates={templates}
|
|
/>
|
|
)
|
|
}
|
|
|
|
export async function BillingPanel({
|
|
profileId,
|
|
isAdmin,
|
|
}: {
|
|
profileId: string
|
|
isAdmin: boolean
|
|
}) {
|
|
const clientId = await getClientId(profileId)
|
|
const invoices = clientId ? await getInvoices(clientId) : []
|
|
|
|
return (
|
|
<div className="flex w-full flex-col gap-6 md:gap-8">
|
|
<div className="flex w-full flex-wrap items-center justify-between gap-3">
|
|
<h1 className="text-2xl font-semibold md:text-3xl">Rechnungen</h1>
|
|
</div>
|
|
<InvoicesTable
|
|
profileId={profileId}
|
|
invoices={invoices}
|
|
isAdmin={isAdmin}
|
|
actions={isAdmin ? <AdminBillingDialog profileId={profileId} /> : undefined}
|
|
/>
|
|
</div>
|
|
)
|
|
}
|