@dainamite/billing 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +658 -0
- package/LICENSE +21 -0
- package/README.md +77 -0
- package/dist/modules/billing/acl.js +20 -0
- package/dist/modules/billing/acl.js.map +7 -0
- package/dist/modules/billing/api/accounts/route.js +182 -0
- package/dist/modules/billing/api/accounts/route.js.map +7 -0
- package/dist/modules/billing/api/export/account/[id]/route.js +170 -0
- package/dist/modules/billing/api/export/account/[id]/route.js.map +7 -0
- package/dist/modules/billing/api/invoices/[id]/route.js +85 -0
- package/dist/modules/billing/api/invoices/[id]/route.js.map +7 -0
- package/dist/modules/billing/api/invoices/add-line/route.js +69 -0
- package/dist/modules/billing/api/invoices/add-line/route.js.map +7 -0
- package/dist/modules/billing/api/invoices/edit-line/route.js +78 -0
- package/dist/modules/billing/api/invoices/edit-line/route.js.map +7 -0
- package/dist/modules/billing/api/invoices/post/route.js +74 -0
- package/dist/modules/billing/api/invoices/post/route.js.map +7 -0
- package/dist/modules/billing/api/invoices/remove-line/route.js +69 -0
- package/dist/modules/billing/api/invoices/remove-line/route.js.map +7 -0
- package/dist/modules/billing/api/invoices/route.js +109 -0
- package/dist/modules/billing/api/invoices/route.js.map +7 -0
- package/dist/modules/billing/api/items/bulk/route.js +74 -0
- package/dist/modules/billing/api/items/bulk/route.js.map +7 -0
- package/dist/modules/billing/api/items/route.js +224 -0
- package/dist/modules/billing/api/items/route.js.map +7 -0
- package/dist/modules/billing/api/openapi.js +25 -0
- package/dist/modules/billing/api/openapi.js.map +7 -0
- package/dist/modules/billing/api/run-outcomes/route.js +122 -0
- package/dist/modules/billing/api/run-outcomes/route.js.map +7 -0
- package/dist/modules/billing/api/runs/retry-failed/route.js +70 -0
- package/dist/modules/billing/api/runs/retry-failed/route.js.map +7 -0
- package/dist/modules/billing/api/runs/route.js +143 -0
- package/dist/modules/billing/api/runs/route.js.map +7 -0
- package/dist/modules/billing/api/test-invoices/wipe/route.js +65 -0
- package/dist/modules/billing/api/test-invoices/wipe/route.js.map +7 -0
- package/dist/modules/billing/api/usage/route.js +138 -0
- package/dist/modules/billing/api/usage/route.js.map +7 -0
- package/dist/modules/billing/backend/billing/accounts/[id]/page.js +402 -0
- package/dist/modules/billing/backend/billing/accounts/[id]/page.js.map +7 -0
- package/dist/modules/billing/backend/billing/accounts/[id]/page.meta.js +25 -0
- package/dist/modules/billing/backend/billing/accounts/[id]/page.meta.js.map +7 -0
- package/dist/modules/billing/backend/billing/accounts/create/page.js +82 -0
- package/dist/modules/billing/backend/billing/accounts/create/page.js.map +7 -0
- package/dist/modules/billing/backend/billing/accounts/create/page.meta.js +25 -0
- package/dist/modules/billing/backend/billing/accounts/create/page.meta.js.map +7 -0
- package/dist/modules/billing/backend/billing/accounts/page.js +173 -0
- package/dist/modules/billing/backend/billing/accounts/page.js.map +7 -0
- package/dist/modules/billing/backend/billing/accounts/page.meta.js +18 -0
- package/dist/modules/billing/backend/billing/accounts/page.meta.js.map +7 -0
- package/dist/modules/billing/backend/billing/invoices/[id]/page.js +500 -0
- package/dist/modules/billing/backend/billing/invoices/[id]/page.js.map +7 -0
- package/dist/modules/billing/backend/billing/invoices/[id]/page.meta.js +25 -0
- package/dist/modules/billing/backend/billing/invoices/[id]/page.meta.js.map +7 -0
- package/dist/modules/billing/backend/billing/invoices/page.js +187 -0
- package/dist/modules/billing/backend/billing/invoices/page.js.map +7 -0
- package/dist/modules/billing/backend/billing/invoices/page.meta.js +18 -0
- package/dist/modules/billing/backend/billing/invoices/page.meta.js.map +7 -0
- package/dist/modules/billing/backend/billing/items/[id]/page.js +265 -0
- package/dist/modules/billing/backend/billing/items/[id]/page.js.map +7 -0
- package/dist/modules/billing/backend/billing/items/[id]/page.meta.js +25 -0
- package/dist/modules/billing/backend/billing/items/[id]/page.meta.js.map +7 -0
- package/dist/modules/billing/backend/billing/items/create/page.js +90 -0
- package/dist/modules/billing/backend/billing/items/create/page.js.map +7 -0
- package/dist/modules/billing/backend/billing/items/create/page.meta.js +25 -0
- package/dist/modules/billing/backend/billing/items/create/page.meta.js.map +7 -0
- package/dist/modules/billing/backend/billing/items/page.js +208 -0
- package/dist/modules/billing/backend/billing/items/page.js.map +7 -0
- package/dist/modules/billing/backend/billing/items/page.meta.js +18 -0
- package/dist/modules/billing/backend/billing/items/page.meta.js.map +7 -0
- package/dist/modules/billing/backend/billing/runs/[id]/page.js +293 -0
- package/dist/modules/billing/backend/billing/runs/[id]/page.js.map +7 -0
- package/dist/modules/billing/backend/billing/runs/[id]/page.meta.js +21 -0
- package/dist/modules/billing/backend/billing/runs/[id]/page.meta.js.map +7 -0
- package/dist/modules/billing/backend/billing/runs/page.js +341 -0
- package/dist/modules/billing/backend/billing/runs/page.js.map +7 -0
- package/dist/modules/billing/backend/billing/runs/page.meta.js +18 -0
- package/dist/modules/billing/backend/billing/runs/page.meta.js.map +7 -0
- package/dist/modules/billing/backend/billing/usage/create/page.js +100 -0
- package/dist/modules/billing/backend/billing/usage/create/page.js.map +7 -0
- package/dist/modules/billing/backend/billing/usage/create/page.meta.js +25 -0
- package/dist/modules/billing/backend/billing/usage/create/page.meta.js.map +7 -0
- package/dist/modules/billing/ce.js +56 -0
- package/dist/modules/billing/ce.js.map +7 -0
- package/dist/modules/billing/cli.js +67 -0
- package/dist/modules/billing/cli.js.map +7 -0
- package/dist/modules/billing/commands/accounts.js +157 -0
- package/dist/modules/billing/commands/accounts.js.map +7 -0
- package/dist/modules/billing/commands/index.js +6 -0
- package/dist/modules/billing/commands/index.js.map +7 -0
- package/dist/modules/billing/commands/invoices.js +401 -0
- package/dist/modules/billing/commands/invoices.js.map +7 -0
- package/dist/modules/billing/commands/items.js +317 -0
- package/dist/modules/billing/commands/items.js.map +7 -0
- package/dist/modules/billing/commands/runs.js +123 -0
- package/dist/modules/billing/commands/runs.js.map +7 -0
- package/dist/modules/billing/commands/usage.js +88 -0
- package/dist/modules/billing/commands/usage.js.map +7 -0
- package/dist/modules/billing/components/AccountForm.js +420 -0
- package/dist/modules/billing/components/AccountForm.js.map +7 -0
- package/dist/modules/billing/components/DetailFields.js +37 -0
- package/dist/modules/billing/components/DetailFields.js.map +7 -0
- package/dist/modules/billing/components/ItemForm.js +440 -0
- package/dist/modules/billing/components/ItemForm.js.map +7 -0
- package/dist/modules/billing/components/LineFormDialog.js +195 -0
- package/dist/modules/billing/components/LineFormDialog.js.map +7 -0
- package/dist/modules/billing/components/UsageForm.js +262 -0
- package/dist/modules/billing/components/UsageForm.js.map +7 -0
- package/dist/modules/billing/data/entities.js +433 -0
- package/dist/modules/billing/data/entities.js.map +7 -0
- package/dist/modules/billing/data/entityIds.js +12 -0
- package/dist/modules/billing/data/entityIds.js.map +7 -0
- package/dist/modules/billing/data/validators.js +396 -0
- package/dist/modules/billing/data/validators.js.map +7 -0
- package/dist/modules/billing/di.js +6 -0
- package/dist/modules/billing/di.js.map +7 -0
- package/dist/modules/billing/events.js +35 -0
- package/dist/modules/billing/events.js.map +7 -0
- package/dist/modules/billing/i18n/en.json +336 -0
- package/dist/modules/billing/i18n/pl.json +336 -0
- package/dist/modules/billing/index.js +17 -0
- package/dist/modules/billing/index.js.map +7 -0
- package/dist/modules/billing/lib/billPeriod.js +101 -0
- package/dist/modules/billing/lib/billPeriod.js.map +7 -0
- package/dist/modules/billing/lib/billRunEngine.js +256 -0
- package/dist/modules/billing/lib/billRunEngine.js.map +7 -0
- package/dist/modules/billing/lib/billRunLabel.js +8 -0
- package/dist/modules/billing/lib/billRunLabel.js.map +7 -0
- package/dist/modules/billing/lib/idempotency.js +13 -0
- package/dist/modules/billing/lib/idempotency.js.map +7 -0
- package/dist/modules/billing/lib/invoiceStatus.js +38 -0
- package/dist/modules/billing/lib/invoiceStatus.js.map +7 -0
- package/dist/modules/billing/lib/invoiceWriter.js +153 -0
- package/dist/modules/billing/lib/invoiceWriter.js.map +7 -0
- package/dist/modules/billing/lib/itemSelector.js +77 -0
- package/dist/modules/billing/lib/itemSelector.js.map +7 -0
- package/dist/modules/billing/lib/seeds/demo.js +130 -0
- package/dist/modules/billing/lib/seeds/demo.js.map +7 -0
- package/dist/modules/billing/lib/tenantLock.js +32 -0
- package/dist/modules/billing/lib/tenantLock.js.map +7 -0
- package/dist/modules/billing/lib/usageRater.js +150 -0
- package/dist/modules/billing/lib/usageRater.js.map +7 -0
- package/dist/modules/billing/lib/usageRunner.js +82 -0
- package/dist/modules/billing/lib/usageRunner.js.map +7 -0
- package/dist/modules/billing/migrations/Migration20260519000000_billing.js +144 -0
- package/dist/modules/billing/migrations/Migration20260519000000_billing.js.map +7 -0
- package/dist/modules/billing/setup.js +190 -0
- package/dist/modules/billing/setup.js.map +7 -0
- package/dist/modules/billing/subscribers/payment-captured-to-paid.js +47 -0
- package/dist/modules/billing/subscribers/payment-captured-to-paid.js.map +7 -0
- package/dist/modules/billing/translations.js +5 -0
- package/dist/modules/billing/translations.js.map +7 -0
- package/dist/modules/billing/workers/reap-stale-bill-runs.js +31 -0
- package/dist/modules/billing/workers/reap-stale-bill-runs.js.map +7 -0
- package/package.json +148 -0
- package/src/modules/billing/__integration__/TC-BILL-001.spec.ts +116 -0
- package/src/modules/billing/__integration__/TC-BILL-002.spec.ts +169 -0
- package/src/modules/billing/__integration__/TC-BILL-003.spec.ts +28 -0
- package/src/modules/billing/__integration__/meta.ts +4 -0
- package/src/modules/billing/__tests__/commands/invoices.test.ts +464 -0
- package/src/modules/billing/__tests__/commands/itemsBulk.test.ts +284 -0
- package/src/modules/billing/__tests__/lib/billPeriod.test.ts +131 -0
- package/src/modules/billing/__tests__/lib/billRunEngine.test.ts +561 -0
- package/src/modules/billing/__tests__/lib/idempotency.test.ts +81 -0
- package/src/modules/billing/__tests__/lib/invoiceStatus.test.ts +97 -0
- package/src/modules/billing/__tests__/lib/invoiceWriter.test.ts +119 -0
- package/src/modules/billing/__tests__/lib/itemSelector.test.ts +192 -0
- package/src/modules/billing/__tests__/lib/seedsDemo.test.ts +86 -0
- package/src/modules/billing/__tests__/lib/tenantLock.test.ts +126 -0
- package/src/modules/billing/__tests__/lib/usageRater.test.ts +190 -0
- package/src/modules/billing/__tests__/package-isolation.test.ts +223 -0
- package/src/modules/billing/__tests__/setup.test.ts +107 -0
- package/src/modules/billing/__tests__/validators.test.ts +594 -0
- package/src/modules/billing/acl.ts +16 -0
- package/src/modules/billing/api/accounts/route.ts +198 -0
- package/src/modules/billing/api/export/account/[id]/route.ts +233 -0
- package/src/modules/billing/api/invoices/[id]/route.ts +143 -0
- package/src/modules/billing/api/invoices/add-line/route.ts +74 -0
- package/src/modules/billing/api/invoices/edit-line/route.ts +97 -0
- package/src/modules/billing/api/invoices/post/route.ts +97 -0
- package/src/modules/billing/api/invoices/remove-line/route.ts +75 -0
- package/src/modules/billing/api/invoices/route.ts +167 -0
- package/src/modules/billing/api/items/bulk/route.ts +92 -0
- package/src/modules/billing/api/items/route.ts +255 -0
- package/src/modules/billing/api/openapi.ts +33 -0
- package/src/modules/billing/api/run-outcomes/route.ts +149 -0
- package/src/modules/billing/api/runs/retry-failed/route.ts +88 -0
- package/src/modules/billing/api/runs/route.ts +170 -0
- package/src/modules/billing/api/test-invoices/wipe/route.ts +87 -0
- package/src/modules/billing/api/usage/route.ts +148 -0
- package/src/modules/billing/backend/billing/accounts/[id]/page.meta.ts +23 -0
- package/src/modules/billing/backend/billing/accounts/[id]/page.tsx +574 -0
- package/src/modules/billing/backend/billing/accounts/create/page.meta.ts +23 -0
- package/src/modules/billing/backend/billing/accounts/create/page.tsx +101 -0
- package/src/modules/billing/backend/billing/accounts/page.meta.ts +16 -0
- package/src/modules/billing/backend/billing/accounts/page.tsx +222 -0
- package/src/modules/billing/backend/billing/invoices/[id]/page.meta.ts +23 -0
- package/src/modules/billing/backend/billing/invoices/[id]/page.tsx +613 -0
- package/src/modules/billing/backend/billing/invoices/page.meta.ts +16 -0
- package/src/modules/billing/backend/billing/invoices/page.tsx +245 -0
- package/src/modules/billing/backend/billing/items/[id]/page.meta.ts +23 -0
- package/src/modules/billing/backend/billing/items/[id]/page.tsx +366 -0
- package/src/modules/billing/backend/billing/items/create/page.meta.ts +23 -0
- package/src/modules/billing/backend/billing/items/create/page.tsx +110 -0
- package/src/modules/billing/backend/billing/items/page.meta.ts +16 -0
- package/src/modules/billing/backend/billing/items/page.tsx +272 -0
- package/src/modules/billing/backend/billing/runs/[id]/page.meta.ts +19 -0
- package/src/modules/billing/backend/billing/runs/[id]/page.tsx +404 -0
- package/src/modules/billing/backend/billing/runs/page.meta.ts +16 -0
- package/src/modules/billing/backend/billing/runs/page.tsx +426 -0
- package/src/modules/billing/backend/billing/usage/create/page.meta.ts +23 -0
- package/src/modules/billing/backend/billing/usage/create/page.tsx +120 -0
- package/src/modules/billing/ce.ts +74 -0
- package/src/modules/billing/cli.ts +89 -0
- package/src/modules/billing/commands/accounts.ts +205 -0
- package/src/modules/billing/commands/index.ts +13 -0
- package/src/modules/billing/commands/invoices.ts +542 -0
- package/src/modules/billing/commands/items.ts +438 -0
- package/src/modules/billing/commands/runs.ts +166 -0
- package/src/modules/billing/commands/usage.ts +118 -0
- package/src/modules/billing/components/AccountForm.tsx +517 -0
- package/src/modules/billing/components/DetailFields.tsx +60 -0
- package/src/modules/billing/components/ItemForm.tsx +558 -0
- package/src/modules/billing/components/LineFormDialog.tsx +253 -0
- package/src/modules/billing/components/UsageForm.tsx +326 -0
- package/src/modules/billing/data/entities.ts +533 -0
- package/src/modules/billing/data/entityIds.ts +25 -0
- package/src/modules/billing/data/validators.ts +562 -0
- package/src/modules/billing/di.ts +14 -0
- package/src/modules/billing/events.ts +47 -0
- package/src/modules/billing/i18n/en.json +336 -0
- package/src/modules/billing/i18n/pl.json +336 -0
- package/src/modules/billing/index.ts +22 -0
- package/src/modules/billing/lib/billPeriod.ts +181 -0
- package/src/modules/billing/lib/billRunEngine.ts +416 -0
- package/src/modules/billing/lib/billRunLabel.ts +14 -0
- package/src/modules/billing/lib/idempotency.ts +46 -0
- package/src/modules/billing/lib/invoiceStatus.ts +61 -0
- package/src/modules/billing/lib/invoiceWriter.ts +260 -0
- package/src/modules/billing/lib/itemSelector.ts +154 -0
- package/src/modules/billing/lib/seeds/demo.ts +199 -0
- package/src/modules/billing/lib/tenantLock.ts +87 -0
- package/src/modules/billing/lib/usageRater.ts +250 -0
- package/src/modules/billing/lib/usageRunner.ts +189 -0
- package/src/modules/billing/migrations/Migration20260519000000_billing.ts +175 -0
- package/src/modules/billing/setup.ts +252 -0
- package/src/modules/billing/subscribers/payment-captured-to-paid.ts +89 -0
- package/src/modules/billing/translations.ts +9 -0
- package/src/modules/billing/workers/reap-stale-bill-runs.ts +57 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { Building2 } from 'lucide-react'
|
|
3
|
+
|
|
4
|
+
const accountsIcon = React.createElement(Building2, { size: 16 })
|
|
5
|
+
|
|
6
|
+
export const metadata = {
|
|
7
|
+
requireAuth: true,
|
|
8
|
+
requireFeatures: ['billing.account.view'],
|
|
9
|
+
pageTitle: 'Billing Accounts',
|
|
10
|
+
pageTitleKey: 'billing.accounts.title',
|
|
11
|
+
pageGroup: 'Billing',
|
|
12
|
+
pageGroupKey: 'billing.nav.group',
|
|
13
|
+
pageOrder: 10,
|
|
14
|
+
icon: accountsIcon,
|
|
15
|
+
breadcrumb: [{ label: 'Billing Accounts', labelKey: 'billing.accounts.title' }],
|
|
16
|
+
} as const
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
import * as React from 'react'
|
|
3
|
+
import Link from 'next/link'
|
|
4
|
+
import { useRouter } from 'next/navigation'
|
|
5
|
+
import { Plus } from 'lucide-react'
|
|
6
|
+
import type { ColumnDef } from '@tanstack/react-table'
|
|
7
|
+
import { useT } from '@open-mercato/shared/lib/i18n/context'
|
|
8
|
+
import type { FilterDef, FilterValues } from '@open-mercato/ui/backend/FilterBar'
|
|
9
|
+
import { Page, PageBody } from '@open-mercato/ui/backend/Page'
|
|
10
|
+
import { DataTable } from '@open-mercato/ui/backend/DataTable'
|
|
11
|
+
import { Tag } from '@open-mercato/ui/primitives/tag'
|
|
12
|
+
import { Button } from '@open-mercato/ui/primitives/button'
|
|
13
|
+
import { readApiResultOrThrow } from '@open-mercato/ui/backend/utils/apiCall'
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Billing Accounts admin list.
|
|
17
|
+
*
|
|
18
|
+
* Search + filter by bill cycle / currency / active state. The
|
|
19
|
+
* "New account" CTA opens the create page; rows link into the detail
|
|
20
|
+
* page for inspect + edit + soft-delete.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
// API list rows are snake_case — the billing list endpoints project
|
|
24
|
+
// raw column names (see `api/accounts/route.ts` `fields`).
|
|
25
|
+
type BillingAccountRow = {
|
|
26
|
+
id: string
|
|
27
|
+
customer_id: string
|
|
28
|
+
name: string
|
|
29
|
+
currency_code: string
|
|
30
|
+
bill_cycle: 'monthly' | 'quarterly' | 'annually' | 'weekly'
|
|
31
|
+
bill_cycle_anchor: string
|
|
32
|
+
invoice_email: string
|
|
33
|
+
next_bill_date: string
|
|
34
|
+
last_bill_date: string | null
|
|
35
|
+
is_active: boolean
|
|
36
|
+
created_at: string
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
type ListResponse = {
|
|
40
|
+
items: BillingAccountRow[]
|
|
41
|
+
total: number
|
|
42
|
+
totalPages: number
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function formatDate(value: string | null | undefined): string {
|
|
46
|
+
if (!value) return '—'
|
|
47
|
+
const parsed = new Date(value)
|
|
48
|
+
return Number.isNaN(parsed.getTime()) ? value : parsed.toLocaleDateString()
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export default function BillingAccountsListPage() {
|
|
52
|
+
const t = useT()
|
|
53
|
+
const router = useRouter()
|
|
54
|
+
const [rows, setRows] = React.useState<BillingAccountRow[]>([])
|
|
55
|
+
const [page, setPage] = React.useState(1)
|
|
56
|
+
const [pageSize] = React.useState(25)
|
|
57
|
+
const [filters, setFilters] = React.useState<FilterValues>({})
|
|
58
|
+
const [search, setSearch] = React.useState('')
|
|
59
|
+
const [total, setTotal] = React.useState(0)
|
|
60
|
+
const [totalPages, setTotalPages] = React.useState(1)
|
|
61
|
+
const [loading, setLoading] = React.useState(true)
|
|
62
|
+
|
|
63
|
+
const filterDefs = React.useMemo<FilterDef[]>(
|
|
64
|
+
() => [
|
|
65
|
+
{
|
|
66
|
+
id: 'billCycle',
|
|
67
|
+
label: t('billing.accounts.filters.cycle', 'Bill cycle'),
|
|
68
|
+
type: 'select',
|
|
69
|
+
options: [
|
|
70
|
+
{ value: 'weekly', label: t('billing.cycle.weekly', 'Weekly') },
|
|
71
|
+
{ value: 'monthly', label: t('billing.cycle.monthly', 'Monthly') },
|
|
72
|
+
{ value: 'quarterly', label: t('billing.cycle.quarterly', 'Quarterly') },
|
|
73
|
+
{ value: 'annually', label: t('billing.cycle.annually', 'Annually') },
|
|
74
|
+
],
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
id: 'currencyCode',
|
|
78
|
+
label: t('billing.accounts.filters.currency', 'Currency'),
|
|
79
|
+
type: 'text',
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
id: 'isActive',
|
|
83
|
+
label: t('billing.accounts.filters.active', 'Active'),
|
|
84
|
+
type: 'select',
|
|
85
|
+
options: [
|
|
86
|
+
{ value: 'true', label: t('billing.common.active', 'Active') },
|
|
87
|
+
{ value: 'false', label: t('billing.common.inactive', 'Inactive') },
|
|
88
|
+
],
|
|
89
|
+
},
|
|
90
|
+
],
|
|
91
|
+
[t],
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
const loadRows = React.useCallback(async () => {
|
|
95
|
+
setLoading(true)
|
|
96
|
+
try {
|
|
97
|
+
const params = new URLSearchParams({
|
|
98
|
+
page: String(page),
|
|
99
|
+
pageSize: String(pageSize),
|
|
100
|
+
sortField: 'createdAt',
|
|
101
|
+
sortDir: 'desc',
|
|
102
|
+
})
|
|
103
|
+
if (search.trim()) params.set('search', search.trim())
|
|
104
|
+
if (typeof filters.billCycle === 'string' && filters.billCycle) {
|
|
105
|
+
params.set('billCycle', filters.billCycle)
|
|
106
|
+
}
|
|
107
|
+
if (typeof filters.currencyCode === 'string' && filters.currencyCode.trim()) {
|
|
108
|
+
params.set('currencyCode', filters.currencyCode.trim().toUpperCase())
|
|
109
|
+
}
|
|
110
|
+
if (filters.isActive === 'true') params.set('isActive', 'true')
|
|
111
|
+
if (filters.isActive === 'false') params.set('isActive', 'false')
|
|
112
|
+
const result = await readApiResultOrThrow<ListResponse>(
|
|
113
|
+
`/api/billing/accounts?${params.toString()}`,
|
|
114
|
+
)
|
|
115
|
+
setRows(result.items ?? [])
|
|
116
|
+
setTotal(result.total ?? 0)
|
|
117
|
+
setTotalPages(result.totalPages ?? 1)
|
|
118
|
+
} finally {
|
|
119
|
+
setLoading(false)
|
|
120
|
+
}
|
|
121
|
+
}, [filters.billCycle, filters.currencyCode, filters.isActive, page, pageSize, search])
|
|
122
|
+
|
|
123
|
+
React.useEffect(() => {
|
|
124
|
+
void loadRows()
|
|
125
|
+
}, [loadRows])
|
|
126
|
+
|
|
127
|
+
const columns = React.useMemo<ColumnDef<BillingAccountRow>[]>(
|
|
128
|
+
() => [
|
|
129
|
+
{
|
|
130
|
+
accessorKey: 'name',
|
|
131
|
+
header: t('billing.accounts.columns.name', 'Name'),
|
|
132
|
+
cell: ({ row }) => (
|
|
133
|
+
<span className="text-sm font-medium text-primary">{row.original.name}</span>
|
|
134
|
+
),
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
accessorKey: 'customer_id',
|
|
138
|
+
header: t('billing.accounts.columns.customer', 'Customer'),
|
|
139
|
+
cell: ({ row }) => (
|
|
140
|
+
<span className="font-mono text-xs">{row.original.customer_id}</span>
|
|
141
|
+
),
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
accessorKey: 'currency_code',
|
|
145
|
+
header: t('billing.accounts.columns.currency', 'Currency'),
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
accessorKey: 'bill_cycle',
|
|
149
|
+
header: t('billing.accounts.columns.cycle', 'Cycle'),
|
|
150
|
+
cell: ({ row }) => (
|
|
151
|
+
<span>
|
|
152
|
+
{row.original.bill_cycle}
|
|
153
|
+
<span className="text-muted-foreground"> · {row.original.bill_cycle_anchor}</span>
|
|
154
|
+
</span>
|
|
155
|
+
),
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
accessorKey: 'next_bill_date',
|
|
159
|
+
header: t('billing.accounts.columns.next_bill', 'Next bill'),
|
|
160
|
+
cell: ({ row }) => formatDate(row.original.next_bill_date),
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
accessorKey: 'last_bill_date',
|
|
164
|
+
header: t('billing.accounts.columns.last_bill', 'Last bill'),
|
|
165
|
+
cell: ({ row }) => formatDate(row.original.last_bill_date),
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
accessorKey: 'is_active',
|
|
169
|
+
header: t('billing.accounts.columns.status', 'Status'),
|
|
170
|
+
cell: ({ row }) =>
|
|
171
|
+
row.original.is_active ? (
|
|
172
|
+
<Tag variant="success">{t('billing.common.active', 'Active')}</Tag>
|
|
173
|
+
) : (
|
|
174
|
+
<Tag variant="default">{t('billing.common.inactive', 'Inactive')}</Tag>
|
|
175
|
+
),
|
|
176
|
+
},
|
|
177
|
+
],
|
|
178
|
+
[t],
|
|
179
|
+
)
|
|
180
|
+
|
|
181
|
+
return (
|
|
182
|
+
<Page>
|
|
183
|
+
<PageBody>
|
|
184
|
+
<DataTable
|
|
185
|
+
title={t('billing.accounts.title', 'Billing Accounts')}
|
|
186
|
+
actions={
|
|
187
|
+
<Button asChild>
|
|
188
|
+
<Link href="/backend/billing/accounts/create">
|
|
189
|
+
<Plus size={16} />
|
|
190
|
+
{t('billing.accounts.create.action', 'New account')}
|
|
191
|
+
</Link>
|
|
192
|
+
</Button>
|
|
193
|
+
}
|
|
194
|
+
refreshButton={{
|
|
195
|
+
label: t('billing.common.refresh', 'Refresh'),
|
|
196
|
+
onRefresh: loadRows,
|
|
197
|
+
isRefreshing: loading,
|
|
198
|
+
}}
|
|
199
|
+
columnChooser={{ auto: true }}
|
|
200
|
+
perspective={{ tableId: 'billing-accounts' }}
|
|
201
|
+
columns={columns}
|
|
202
|
+
data={rows}
|
|
203
|
+
onRowClick={(row) => router.push(`/backend/billing/accounts/${row.id}`)}
|
|
204
|
+
isLoading={loading}
|
|
205
|
+
pagination={{
|
|
206
|
+
page,
|
|
207
|
+
pageSize,
|
|
208
|
+
total,
|
|
209
|
+
totalPages,
|
|
210
|
+
onPageChange: setPage,
|
|
211
|
+
}}
|
|
212
|
+
filters={filterDefs}
|
|
213
|
+
filterValues={filters}
|
|
214
|
+
onFiltersApply={setFilters}
|
|
215
|
+
onFiltersClear={() => setFilters({})}
|
|
216
|
+
searchValue={search}
|
|
217
|
+
onSearchChange={setSearch}
|
|
218
|
+
/>
|
|
219
|
+
</PageBody>
|
|
220
|
+
</Page>
|
|
221
|
+
)
|
|
222
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { FileText } from 'lucide-react'
|
|
3
|
+
|
|
4
|
+
const invoiceIcon = React.createElement(FileText, { size: 16 })
|
|
5
|
+
|
|
6
|
+
export const metadata = {
|
|
7
|
+
requireAuth: true,
|
|
8
|
+
requireFeatures: ['billing.invoice.view'],
|
|
9
|
+
pageTitle: 'Billing Invoice',
|
|
10
|
+
pageTitleKey: 'billing.invoices.detail.title',
|
|
11
|
+
pageGroup: 'Billing',
|
|
12
|
+
pageGroupKey: 'billing.nav.group',
|
|
13
|
+
navHidden: true,
|
|
14
|
+
icon: invoiceIcon,
|
|
15
|
+
breadcrumb: [
|
|
16
|
+
{
|
|
17
|
+
label: 'Billing Invoices',
|
|
18
|
+
labelKey: 'billing.invoices.title',
|
|
19
|
+
href: '/backend/billing/invoices',
|
|
20
|
+
},
|
|
21
|
+
{ label: 'Invoice', labelKey: 'billing.invoices.detail.title' },
|
|
22
|
+
],
|
|
23
|
+
} as const
|