@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,90 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { useRouter, useSearchParams } from "next/navigation";
|
|
5
|
+
import { useT } from "@open-mercato/shared/lib/i18n/context";
|
|
6
|
+
import { Page, PageBody, PageHeader } from "@open-mercato/ui/backend/Page";
|
|
7
|
+
import { LoadingMessage } from "@open-mercato/ui/backend/detail";
|
|
8
|
+
import { flash } from "@open-mercato/ui/backend/FlashMessages";
|
|
9
|
+
import {
|
|
10
|
+
apiCallOrThrow,
|
|
11
|
+
readApiResultOrThrow
|
|
12
|
+
} from "@open-mercato/ui/backend/utils/apiCall";
|
|
13
|
+
import { normalizeCrudServerError } from "@open-mercato/ui/backend/utils/serverErrors";
|
|
14
|
+
import { ItemForm } from "../../../../components/ItemForm.js";
|
|
15
|
+
function CreateBillingItemPage() {
|
|
16
|
+
const t = useT();
|
|
17
|
+
const router = useRouter();
|
|
18
|
+
const searchParams = useSearchParams();
|
|
19
|
+
const preselectedAccountId = searchParams.get("billAccountId") ?? "";
|
|
20
|
+
const [accounts, setAccounts] = React.useState(null);
|
|
21
|
+
const [submitting, setSubmitting] = React.useState(false);
|
|
22
|
+
React.useEffect(() => {
|
|
23
|
+
let cancelled = false;
|
|
24
|
+
void (async () => {
|
|
25
|
+
try {
|
|
26
|
+
const result = await readApiResultOrThrow(
|
|
27
|
+
"/api/billing/accounts?pageSize=100&sortField=name&sortDir=asc"
|
|
28
|
+
);
|
|
29
|
+
if (!cancelled) setAccounts(result.items ?? []);
|
|
30
|
+
} catch {
|
|
31
|
+
if (!cancelled) setAccounts([]);
|
|
32
|
+
}
|
|
33
|
+
})();
|
|
34
|
+
return () => {
|
|
35
|
+
cancelled = true;
|
|
36
|
+
};
|
|
37
|
+
}, []);
|
|
38
|
+
const handleSubmit = React.useCallback(
|
|
39
|
+
async (payload) => {
|
|
40
|
+
setSubmitting(true);
|
|
41
|
+
try {
|
|
42
|
+
const call = await apiCallOrThrow(
|
|
43
|
+
"/api/billing/items",
|
|
44
|
+
{
|
|
45
|
+
method: "POST",
|
|
46
|
+
headers: { "Content-Type": "application/json" },
|
|
47
|
+
body: JSON.stringify(payload)
|
|
48
|
+
}
|
|
49
|
+
);
|
|
50
|
+
const id = call.result?.id;
|
|
51
|
+
flash(t("billing.items.create.success", "Billing item created"), "success");
|
|
52
|
+
if (id) {
|
|
53
|
+
router.push(`/backend/billing/items/${id}`);
|
|
54
|
+
} else {
|
|
55
|
+
router.push("/backend/billing/items");
|
|
56
|
+
}
|
|
57
|
+
} catch (err) {
|
|
58
|
+
const { message } = normalizeCrudServerError(err);
|
|
59
|
+
flash(
|
|
60
|
+
message || t("billing.items.create.error", "Failed to create item"),
|
|
61
|
+
"error"
|
|
62
|
+
);
|
|
63
|
+
} finally {
|
|
64
|
+
setSubmitting(false);
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
[router, t]
|
|
68
|
+
);
|
|
69
|
+
const handleCancel = React.useCallback(() => {
|
|
70
|
+
router.push("/backend/billing/items");
|
|
71
|
+
}, [router]);
|
|
72
|
+
return /* @__PURE__ */ jsxs(Page, { children: [
|
|
73
|
+
/* @__PURE__ */ jsx(PageHeader, { title: t("billing.items.create.title", "Create Billing Item") }),
|
|
74
|
+
/* @__PURE__ */ jsx(PageBody, { children: accounts === null ? /* @__PURE__ */ jsx(LoadingMessage, { label: t("billing.items.create.loading", "Loading accounts\u2026") }) : /* @__PURE__ */ jsx(
|
|
75
|
+
ItemForm,
|
|
76
|
+
{
|
|
77
|
+
mode: "create",
|
|
78
|
+
accountOptions: accounts,
|
|
79
|
+
initial: preselectedAccountId ? { billAccountId: preselectedAccountId } : void 0,
|
|
80
|
+
submitting,
|
|
81
|
+
onSubmit: handleSubmit,
|
|
82
|
+
onCancel: handleCancel
|
|
83
|
+
}
|
|
84
|
+
) })
|
|
85
|
+
] });
|
|
86
|
+
}
|
|
87
|
+
export {
|
|
88
|
+
CreateBillingItemPage as default
|
|
89
|
+
};
|
|
90
|
+
//# sourceMappingURL=page.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../../../src/modules/billing/backend/billing/items/create/page.tsx"],
|
|
4
|
+
"sourcesContent": ["\"use client\"\nimport * as React from 'react'\nimport { useRouter, useSearchParams } from 'next/navigation'\nimport { useT } from '@open-mercato/shared/lib/i18n/context'\nimport { Page, PageBody, PageHeader } from '@open-mercato/ui/backend/Page'\nimport { LoadingMessage } from '@open-mercato/ui/backend/detail'\nimport { flash } from '@open-mercato/ui/backend/FlashMessages'\nimport {\n apiCallOrThrow,\n readApiResultOrThrow,\n} from '@open-mercato/ui/backend/utils/apiCall'\nimport { normalizeCrudServerError } from '@open-mercato/ui/backend/utils/serverErrors'\nimport { ItemForm, type AccountOption, type AssembledItemPayload } from '../../../../components/ItemForm'\n\n/**\n * `/backend/billing/items/create` \u2014 create a Billing Item.\n *\n * Loads the account list once on mount to drive the account picker.\n * Supports `?billAccountId=<id>` deep-link so the parent account\n * page (when we add an \"Add item\" CTA there) can pre-select.\n *\n * POSTs `/api/billing/items`. On success, navigates to the item's\n * detail page so the operator can edit further if needed.\n */\nexport default function CreateBillingItemPage() {\n const t = useT()\n const router = useRouter()\n const searchParams = useSearchParams()\n const preselectedAccountId = searchParams.get('billAccountId') ?? ''\n\n const [accounts, setAccounts] = React.useState<AccountOption[] | null>(null)\n const [submitting, setSubmitting] = React.useState(false)\n\n React.useEffect(() => {\n let cancelled = false\n void (async () => {\n try {\n const result = await readApiResultOrThrow<{ items: AccountOption[] }>(\n '/api/billing/accounts?pageSize=100&sortField=name&sortDir=asc',\n )\n if (!cancelled) setAccounts(result.items ?? [])\n } catch {\n if (!cancelled) setAccounts([])\n }\n })()\n return () => {\n cancelled = true\n }\n }, [])\n\n const handleSubmit = React.useCallback(\n async (payload: AssembledItemPayload) => {\n setSubmitting(true)\n try {\n const call = await apiCallOrThrow<{ id: string; deduplicated: boolean }>(\n '/api/billing/items',\n {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify(payload),\n },\n )\n const id = call.result?.id\n flash(t('billing.items.create.success', 'Billing item created'), 'success')\n if (id) {\n router.push(`/backend/billing/items/${id}`)\n } else {\n router.push('/backend/billing/items')\n }\n } catch (err) {\n const { message } = normalizeCrudServerError(err)\n flash(\n message || t('billing.items.create.error', 'Failed to create item'),\n 'error',\n )\n } finally {\n setSubmitting(false)\n }\n },\n [router, t],\n )\n\n const handleCancel = React.useCallback(() => {\n router.push('/backend/billing/items')\n }, [router])\n\n return (\n <Page>\n <PageHeader title={t('billing.items.create.title', 'Create Billing Item')} />\n <PageBody>\n {accounts === null ? (\n <LoadingMessage label={t('billing.items.create.loading', 'Loading accounts\u2026')} />\n ) : (\n <ItemForm\n mode=\"create\"\n accountOptions={accounts}\n initial={\n preselectedAccountId\n ? { billAccountId: preselectedAccountId }\n : undefined\n }\n submitting={submitting}\n onSubmit={handleSubmit}\n onCancel={handleCancel}\n />\n )}\n </PageBody>\n </Page>\n )\n}\n"],
|
|
5
|
+
"mappings": ";AAuFI,SACE,KADF;AAtFJ,YAAY,WAAW;AACvB,SAAS,WAAW,uBAAuB;AAC3C,SAAS,YAAY;AACrB,SAAS,MAAM,UAAU,kBAAkB;AAC3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AA8B,uBAAuB;AAAA,UAClE;AAAA,QACF;AAAA,MACF,UAAE;AACA,sBAAc,KAAK;AAAA,MACrB;AAAA,IACF;AAAA,IACA,CAAC,QAAQ,CAAC;AAAA,EACZ;AAEA,QAAM,eAAe,MAAM,YAAY,MAAM;AAC3C,WAAO,KAAK,wBAAwB;AAAA,EACtC,GAAG,CAAC,MAAM,CAAC;AAEX,SACE,qBAAC,QACC;AAAA,wBAAC,cAAW,OAAO,EAAE,8BAA8B,qBAAqB,GAAG;AAAA,IAC3E,oBAAC,YACE,uBAAa,OACZ,oBAAC,kBAAe,OAAO,EAAE,gCAAgC,wBAAmB,GAAG,IAE/E;AAAA,MAAC;AAAA;AAAA,QACC,MAAK;AAAA,QACL,gBAAgB;AAAA,QAChB,SACE,uBACI,EAAE,eAAe,qBAAqB,IACtC;AAAA,QAEN;AAAA,QACA,UAAU;AAAA,QACV,UAAU;AAAA;AAAA,IACZ,GAEJ;AAAA,KACF;AAEJ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Receipt } from "lucide-react";
|
|
3
|
+
const itemIcon = React.createElement(Receipt, { size: 16 });
|
|
4
|
+
const metadata = {
|
|
5
|
+
requireAuth: true,
|
|
6
|
+
requireFeatures: ["billing.item.manage"],
|
|
7
|
+
pageTitle: "Create Billing Item",
|
|
8
|
+
pageTitleKey: "billing.items.create.title",
|
|
9
|
+
pageGroup: "Billing",
|
|
10
|
+
pageGroupKey: "billing.nav.group",
|
|
11
|
+
navHidden: true,
|
|
12
|
+
icon: itemIcon,
|
|
13
|
+
breadcrumb: [
|
|
14
|
+
{
|
|
15
|
+
label: "Billing Items",
|
|
16
|
+
labelKey: "billing.items.title",
|
|
17
|
+
href: "/backend/billing/items"
|
|
18
|
+
},
|
|
19
|
+
{ label: "Create", labelKey: "billing.items.create.title" }
|
|
20
|
+
]
|
|
21
|
+
};
|
|
22
|
+
export {
|
|
23
|
+
metadata
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=page.meta.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../../../src/modules/billing/backend/billing/items/create/page.meta.ts"],
|
|
4
|
+
"sourcesContent": ["import React from 'react'\nimport { Receipt } from 'lucide-react'\n\nconst itemIcon = React.createElement(Receipt, { size: 16 })\n\nexport const metadata = {\n requireAuth: true,\n requireFeatures: ['billing.item.manage'],\n pageTitle: 'Create Billing Item',\n pageTitleKey: 'billing.items.create.title',\n pageGroup: 'Billing',\n pageGroupKey: 'billing.nav.group',\n navHidden: true,\n icon: itemIcon,\n breadcrumb: [\n {\n label: 'Billing Items',\n labelKey: 'billing.items.title',\n href: '/backend/billing/items',\n },\n { label: 'Create', labelKey: 'billing.items.create.title' },\n ],\n} as const\n"],
|
|
5
|
+
"mappings": "AAAA,OAAO,WAAW;AAClB,SAAS,eAAe;AAExB,MAAM,WAAW,MAAM,cAAc,SAAS,EAAE,MAAM,GAAG,CAAC;AAEnD,MAAM,WAAW;AAAA,EACtB,aAAa;AAAA,EACb,iBAAiB,CAAC,qBAAqB;AAAA,EACvC,WAAW;AAAA,EACX,cAAc;AAAA,EACd,WAAW;AAAA,EACX,cAAc;AAAA,EACd,WAAW;AAAA,EACX,MAAM;AAAA,EACN,YAAY;AAAA,IACV;AAAA,MACE,OAAO;AAAA,MACP,UAAU;AAAA,MACV,MAAM;AAAA,IACR;AAAA,IACA,EAAE,OAAO,UAAU,UAAU,6BAA6B;AAAA,EAC5D;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import Link from "next/link";
|
|
5
|
+
import { useRouter, useSearchParams } from "next/navigation";
|
|
6
|
+
import { Plus } from "lucide-react";
|
|
7
|
+
import { useT } from "@open-mercato/shared/lib/i18n/context";
|
|
8
|
+
import { Page, PageBody } from "@open-mercato/ui/backend/Page";
|
|
9
|
+
import { DataTable } from "@open-mercato/ui/backend/DataTable";
|
|
10
|
+
import { Tag } from "@open-mercato/ui/primitives/tag";
|
|
11
|
+
import { Button } from "@open-mercato/ui/primitives/button";
|
|
12
|
+
import { readApiResultOrThrow } from "@open-mercato/ui/backend/utils/apiCall";
|
|
13
|
+
function formatDate(value) {
|
|
14
|
+
if (!value) return "\u2014";
|
|
15
|
+
const parsed = new Date(value);
|
|
16
|
+
return Number.isNaN(parsed.getTime()) ? value : parsed.toLocaleDateString();
|
|
17
|
+
}
|
|
18
|
+
function typeVariant(type) {
|
|
19
|
+
switch (type) {
|
|
20
|
+
case "recurring":
|
|
21
|
+
return "success";
|
|
22
|
+
case "one_time":
|
|
23
|
+
return "warning";
|
|
24
|
+
case "usage":
|
|
25
|
+
return "info";
|
|
26
|
+
default:
|
|
27
|
+
return "default";
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function BillingItemsListPage() {
|
|
31
|
+
const t = useT();
|
|
32
|
+
const router = useRouter();
|
|
33
|
+
const searchParams = useSearchParams();
|
|
34
|
+
const initialAccountId = searchParams.get("billAccountId") ?? "";
|
|
35
|
+
const [rows, setRows] = React.useState([]);
|
|
36
|
+
const [page, setPage] = React.useState(1);
|
|
37
|
+
const [pageSize] = React.useState(25);
|
|
38
|
+
const [filters, setFilters] = React.useState(
|
|
39
|
+
initialAccountId ? { billAccountId: initialAccountId } : {}
|
|
40
|
+
);
|
|
41
|
+
const [total, setTotal] = React.useState(0);
|
|
42
|
+
const [totalPages, setTotalPages] = React.useState(1);
|
|
43
|
+
const [loading, setLoading] = React.useState(true);
|
|
44
|
+
const [search, setSearch] = React.useState("");
|
|
45
|
+
const accountNames = React.useMemo(() => {
|
|
46
|
+
const map = {};
|
|
47
|
+
for (const r of rows) {
|
|
48
|
+
if (r.bill_account_name) map[r.bill_account_id] = r.bill_account_name;
|
|
49
|
+
}
|
|
50
|
+
return map;
|
|
51
|
+
}, [rows]);
|
|
52
|
+
const filterDefs = React.useMemo(
|
|
53
|
+
() => [
|
|
54
|
+
{
|
|
55
|
+
id: "type",
|
|
56
|
+
label: t("billing.items.filters.type", "Type"),
|
|
57
|
+
type: "select",
|
|
58
|
+
options: [
|
|
59
|
+
{ value: "one_time", label: t("billing.items.type.one_time", "One-time") },
|
|
60
|
+
{ value: "recurring", label: t("billing.items.type.recurring", "Recurring") },
|
|
61
|
+
{ value: "usage", label: t("billing.items.type.usage", "Usage") }
|
|
62
|
+
]
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
id: "billAccountId",
|
|
66
|
+
label: t("billing.items.filters.account", "Billing Account"),
|
|
67
|
+
type: "text",
|
|
68
|
+
formatValue: (id) => accountNames[id] ?? id
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
id: "subscriptionId",
|
|
72
|
+
label: t("billing.items.filters.subscription", "Subscription ID"),
|
|
73
|
+
type: "text"
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
id: "isActive",
|
|
77
|
+
label: t("billing.items.filters.active", "Active"),
|
|
78
|
+
type: "select",
|
|
79
|
+
options: [
|
|
80
|
+
{ value: "true", label: t("billing.common.active", "Active") },
|
|
81
|
+
{ value: "false", label: t("billing.common.inactive", "Inactive") }
|
|
82
|
+
]
|
|
83
|
+
}
|
|
84
|
+
],
|
|
85
|
+
[t, accountNames]
|
|
86
|
+
);
|
|
87
|
+
const loadRows = React.useCallback(async () => {
|
|
88
|
+
setLoading(true);
|
|
89
|
+
try {
|
|
90
|
+
const params = new URLSearchParams({
|
|
91
|
+
page: String(page),
|
|
92
|
+
pageSize: String(pageSize),
|
|
93
|
+
sortField: "createdAt",
|
|
94
|
+
sortDir: "desc"
|
|
95
|
+
});
|
|
96
|
+
if (search.trim()) params.set("search", search.trim());
|
|
97
|
+
if (typeof filters.type === "string" && filters.type) {
|
|
98
|
+
params.set("type", filters.type);
|
|
99
|
+
}
|
|
100
|
+
if (typeof filters.billAccountId === "string" && filters.billAccountId.trim()) {
|
|
101
|
+
params.set("billAccountId", filters.billAccountId.trim());
|
|
102
|
+
}
|
|
103
|
+
if (typeof filters.subscriptionId === "string" && filters.subscriptionId.trim()) {
|
|
104
|
+
params.set("subscriptionId", filters.subscriptionId.trim());
|
|
105
|
+
}
|
|
106
|
+
if (filters.isActive === "true" || filters.isActive === "false") {
|
|
107
|
+
params.set("isActive", String(filters.isActive));
|
|
108
|
+
}
|
|
109
|
+
const result = await readApiResultOrThrow(
|
|
110
|
+
`/api/billing/items?${params.toString()}`
|
|
111
|
+
);
|
|
112
|
+
setRows(result.items ?? []);
|
|
113
|
+
setTotal(result.total ?? 0);
|
|
114
|
+
setTotalPages(result.totalPages ?? 1);
|
|
115
|
+
} finally {
|
|
116
|
+
setLoading(false);
|
|
117
|
+
}
|
|
118
|
+
}, [filters.billAccountId, filters.isActive, filters.subscriptionId, filters.type, page, pageSize, search]);
|
|
119
|
+
React.useEffect(() => {
|
|
120
|
+
void loadRows();
|
|
121
|
+
}, [loadRows]);
|
|
122
|
+
const columns = React.useMemo(
|
|
123
|
+
() => [
|
|
124
|
+
{
|
|
125
|
+
accessorKey: "description",
|
|
126
|
+
header: t("billing.items.columns.description", "Description"),
|
|
127
|
+
cell: ({ row }) => /* @__PURE__ */ jsx("span", { className: "text-sm font-medium text-primary", children: row.original.description })
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
accessorKey: "type",
|
|
131
|
+
header: t("billing.items.columns.type", "Type"),
|
|
132
|
+
cell: ({ row }) => /* @__PURE__ */ jsx(Tag, { variant: typeVariant(row.original.type), children: row.original.type })
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
accessorKey: "bill_account_id",
|
|
136
|
+
header: t("billing.items.columns.account", "Account"),
|
|
137
|
+
cell: ({ row }) => /* @__PURE__ */ jsx(
|
|
138
|
+
Link,
|
|
139
|
+
{
|
|
140
|
+
href: `/backend/billing/accounts/${row.original.bill_account_id}`,
|
|
141
|
+
className: "text-sm text-primary hover:underline",
|
|
142
|
+
onClick: (e) => e.stopPropagation(),
|
|
143
|
+
children: row.original.bill_account_name ?? row.original.bill_account_id
|
|
144
|
+
}
|
|
145
|
+
)
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
accessorKey: "bill_start_date",
|
|
149
|
+
header: t("billing.items.columns.start", "Start"),
|
|
150
|
+
cell: ({ row }) => formatDate(row.original.bill_start_date)
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
accessorKey: "bill_end_date",
|
|
154
|
+
header: t("billing.items.columns.end", "End"),
|
|
155
|
+
cell: ({ row }) => formatDate(row.original.bill_end_date)
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
accessorKey: "uom_code",
|
|
159
|
+
header: t("billing.items.columns.uom", "UoM"),
|
|
160
|
+
cell: ({ row }) => row.original.uom_code ?? "\u2014"
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
accessorKey: "is_active",
|
|
164
|
+
header: t("billing.items.columns.status", "Status"),
|
|
165
|
+
cell: ({ row }) => row.original.is_active ? /* @__PURE__ */ jsx(Tag, { variant: "success", children: t("billing.common.active", "Active") }) : /* @__PURE__ */ jsx(Tag, { variant: "default", children: t("billing.common.inactive", "Inactive") })
|
|
166
|
+
}
|
|
167
|
+
],
|
|
168
|
+
[t]
|
|
169
|
+
);
|
|
170
|
+
return /* @__PURE__ */ jsx(Page, { children: /* @__PURE__ */ jsx(PageBody, { children: /* @__PURE__ */ jsx(
|
|
171
|
+
DataTable,
|
|
172
|
+
{
|
|
173
|
+
title: t("billing.items.title", "Billing Items"),
|
|
174
|
+
actions: /* @__PURE__ */ jsx(Button, { asChild: true, children: /* @__PURE__ */ jsxs(Link, { href: "/backend/billing/items/create", children: [
|
|
175
|
+
/* @__PURE__ */ jsx(Plus, { size: 16 }),
|
|
176
|
+
t("billing.items.create.action", "New item")
|
|
177
|
+
] }) }),
|
|
178
|
+
refreshButton: {
|
|
179
|
+
label: t("billing.common.refresh", "Refresh"),
|
|
180
|
+
onRefresh: loadRows,
|
|
181
|
+
isRefreshing: loading
|
|
182
|
+
},
|
|
183
|
+
columnChooser: { auto: true },
|
|
184
|
+
perspective: { tableId: "billing-items" },
|
|
185
|
+
columns,
|
|
186
|
+
data: rows,
|
|
187
|
+
onRowClick: (row) => router.push(`/backend/billing/items/${row.id}`),
|
|
188
|
+
isLoading: loading,
|
|
189
|
+
pagination: {
|
|
190
|
+
page,
|
|
191
|
+
pageSize,
|
|
192
|
+
total,
|
|
193
|
+
totalPages,
|
|
194
|
+
onPageChange: setPage
|
|
195
|
+
},
|
|
196
|
+
filters: filterDefs,
|
|
197
|
+
filterValues: filters,
|
|
198
|
+
onFiltersApply: setFilters,
|
|
199
|
+
onFiltersClear: () => setFilters({}),
|
|
200
|
+
searchValue: search,
|
|
201
|
+
onSearchChange: setSearch
|
|
202
|
+
}
|
|
203
|
+
) }) });
|
|
204
|
+
}
|
|
205
|
+
export {
|
|
206
|
+
BillingItemsListPage as default
|
|
207
|
+
};
|
|
208
|
+
//# sourceMappingURL=page.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../../src/modules/billing/backend/billing/items/page.tsx"],
|
|
4
|
+
"sourcesContent": ["\"use client\"\nimport * as React from 'react'\nimport Link from 'next/link'\nimport { useRouter, useSearchParams } from 'next/navigation'\nimport { Plus } from 'lucide-react'\nimport type { ColumnDef } from '@tanstack/react-table'\nimport { useT } from '@open-mercato/shared/lib/i18n/context'\nimport type { FilterDef, FilterValues } from '@open-mercato/ui/backend/FilterBar'\nimport { Page, PageBody } from '@open-mercato/ui/backend/Page'\nimport { DataTable } from '@open-mercato/ui/backend/DataTable'\nimport { Tag } from '@open-mercato/ui/primitives/tag'\nimport { Button } from '@open-mercato/ui/primitives/button'\nimport { readApiResultOrThrow } from '@open-mercato/ui/backend/utils/apiCall'\n\n/**\n * Billing Items admin list.\n *\n * Filters: type (one_time / recurring / usage), bill account, active.\n * Items are typically integration-driven (CPQ connector creates them\n * on subscription events), so the most common UI use is *inspecting*\n * what's there \u2014 but the \"New item\" CTA is available for manual\n * entry / one-off adjustments.\n */\n\n// API list rows are snake_case (see `api/items/route.ts` `fields`).\ntype BillingItemRow = {\n id: string\n bill_account_id: string\n bill_account_name: string | null\n type: 'one_time' | 'recurring' | 'usage'\n description: string\n bill_start_date: string\n bill_end_date: string | null\n uom_code: string | null\n subscription_id: string | null\n source_ref: string | null\n is_active: boolean\n created_at: string\n}\n\ntype ListResponse = {\n items: BillingItemRow[]\n total: number\n totalPages: number\n}\n\nfunction formatDate(value: string | null | undefined): string {\n if (!value) return '\u2014'\n const parsed = new Date(value)\n return Number.isNaN(parsed.getTime()) ? value : parsed.toLocaleDateString()\n}\n\nfunction typeVariant(\n type: BillingItemRow['type'],\n): 'default' | 'success' | 'warning' | 'info' {\n switch (type) {\n case 'recurring':\n return 'success'\n case 'one_time':\n return 'warning'\n case 'usage':\n return 'info'\n default:\n return 'default'\n }\n}\n\nexport default function BillingItemsListPage() {\n const t = useT()\n const router = useRouter()\n const searchParams = useSearchParams()\n // Deep-link from the account detail page: `?billAccountId=<id>` pre-\n // filters the list so the operator lands on \"items for this account\".\n const initialAccountId = searchParams.get('billAccountId') ?? ''\n\n const [rows, setRows] = React.useState<BillingItemRow[]>([])\n const [page, setPage] = React.useState(1)\n const [pageSize] = React.useState(25)\n const [filters, setFilters] = React.useState<FilterValues>(\n initialAccountId ? { billAccountId: initialAccountId } : {},\n )\n const [total, setTotal] = React.useState(0)\n const [totalPages, setTotalPages] = React.useState(1)\n const [loading, setLoading] = React.useState(true)\n const [search, setSearch] = React.useState('')\n\n // Resolve account id \u2192 name from the loaded rows (each carries\n // `bill_account_name` from the items route's afterList hook) so the\n // active `billAccountId` filter chip shows a name, not a UUID.\n const accountNames = React.useMemo(() => {\n const map: Record<string, string> = {}\n for (const r of rows) {\n if (r.bill_account_name) map[r.bill_account_id] = r.bill_account_name\n }\n return map\n }, [rows])\n\n const filterDefs = React.useMemo<FilterDef[]>(\n () => [\n {\n id: 'type',\n label: t('billing.items.filters.type', 'Type'),\n type: 'select',\n options: [\n { value: 'one_time', label: t('billing.items.type.one_time', 'One-time') },\n { value: 'recurring', label: t('billing.items.type.recurring', 'Recurring') },\n { value: 'usage', label: t('billing.items.type.usage', 'Usage') },\n ],\n },\n {\n id: 'billAccountId',\n label: t('billing.items.filters.account', 'Billing Account'),\n type: 'text',\n formatValue: (id: string) => accountNames[id] ?? id,\n },\n {\n id: 'subscriptionId',\n label: t('billing.items.filters.subscription', 'Subscription ID'),\n type: 'text',\n },\n {\n id: 'isActive',\n label: t('billing.items.filters.active', 'Active'),\n type: 'select',\n options: [\n { value: 'true', label: t('billing.common.active', 'Active') },\n { value: 'false', label: t('billing.common.inactive', 'Inactive') },\n ],\n },\n ],\n [t, accountNames],\n )\n\n const loadRows = React.useCallback(async () => {\n setLoading(true)\n try {\n const params = new URLSearchParams({\n page: String(page),\n pageSize: String(pageSize),\n sortField: 'createdAt',\n sortDir: 'desc',\n })\n if (search.trim()) params.set('search', search.trim())\n if (typeof filters.type === 'string' && filters.type) {\n params.set('type', filters.type)\n }\n if (typeof filters.billAccountId === 'string' && filters.billAccountId.trim()) {\n params.set('billAccountId', filters.billAccountId.trim())\n }\n if (typeof filters.subscriptionId === 'string' && filters.subscriptionId.trim()) {\n params.set('subscriptionId', filters.subscriptionId.trim())\n }\n if (filters.isActive === 'true' || filters.isActive === 'false') {\n params.set('isActive', String(filters.isActive))\n }\n const result = await readApiResultOrThrow<ListResponse>(\n `/api/billing/items?${params.toString()}`,\n )\n setRows(result.items ?? [])\n setTotal(result.total ?? 0)\n setTotalPages(result.totalPages ?? 1)\n } finally {\n setLoading(false)\n }\n }, [filters.billAccountId, filters.isActive, filters.subscriptionId, filters.type, page, pageSize, search])\n\n React.useEffect(() => {\n void loadRows()\n }, [loadRows])\n\n const columns = React.useMemo<ColumnDef<BillingItemRow>[]>(\n () => [\n {\n accessorKey: 'description',\n header: t('billing.items.columns.description', 'Description'),\n cell: ({ row }) => (\n <span className=\"text-sm font-medium text-primary\">\n {row.original.description}\n </span>\n ),\n },\n {\n accessorKey: 'type',\n header: t('billing.items.columns.type', 'Type'),\n cell: ({ row }) => (\n <Tag variant={typeVariant(row.original.type)}>{row.original.type}</Tag>\n ),\n },\n {\n accessorKey: 'bill_account_id',\n header: t('billing.items.columns.account', 'Account'),\n cell: ({ row }) => (\n <Link\n href={`/backend/billing/accounts/${row.original.bill_account_id}`}\n className=\"text-sm text-primary hover:underline\"\n onClick={(e) => e.stopPropagation()}\n >\n {row.original.bill_account_name ?? row.original.bill_account_id}\n </Link>\n ),\n },\n {\n accessorKey: 'bill_start_date',\n header: t('billing.items.columns.start', 'Start'),\n cell: ({ row }) => formatDate(row.original.bill_start_date),\n },\n {\n accessorKey: 'bill_end_date',\n header: t('billing.items.columns.end', 'End'),\n cell: ({ row }) => formatDate(row.original.bill_end_date),\n },\n {\n accessorKey: 'uom_code',\n header: t('billing.items.columns.uom', 'UoM'),\n cell: ({ row }) => row.original.uom_code ?? '\u2014',\n },\n {\n accessorKey: 'is_active',\n header: t('billing.items.columns.status', 'Status'),\n cell: ({ row }) =>\n row.original.is_active ? (\n <Tag variant=\"success\">{t('billing.common.active', 'Active')}</Tag>\n ) : (\n <Tag variant=\"default\">{t('billing.common.inactive', 'Inactive')}</Tag>\n ),\n },\n ],\n [t],\n )\n\n return (\n <Page>\n <PageBody>\n <DataTable\n title={t('billing.items.title', 'Billing Items')}\n actions={\n <Button asChild>\n <Link href=\"/backend/billing/items/create\">\n <Plus size={16} />\n {t('billing.items.create.action', 'New item')}\n </Link>\n </Button>\n }\n refreshButton={{\n label: t('billing.common.refresh', 'Refresh'),\n onRefresh: loadRows,\n isRefreshing: loading,\n }}\n columnChooser={{ auto: true }}\n perspective={{ tableId: 'billing-items' }}\n columns={columns}\n data={rows}\n onRowClick={(row) => router.push(`/backend/billing/items/${row.id}`)}\n isLoading={loading}\n pagination={{\n page,\n pageSize,\n total,\n totalPages,\n onPageChange: setPage,\n }}\n filters={filterDefs}\n filterValues={filters}\n onFiltersApply={setFilters}\n onFiltersClear={() => setFilters({})}\n searchValue={search}\n onSearchChange={setSearch}\n />\n </PageBody>\n </Page>\n )\n}\n"],
|
|
5
|
+
"mappings": ";AAgLU,cA6DI,YA7DJ;AA/KV,YAAY,WAAW;AACvB,OAAO,UAAU;AACjB,SAAS,WAAW,uBAAuB;AAC3C,SAAS,YAAY;AAErB,SAAS,YAAY;AAErB,SAAS,MAAM,gBAAgB;AAC/B,SAAS,iBAAiB;AAC1B,SAAS,WAAW;AACpB,SAAS,cAAc;AACvB,SAAS,4BAA4B;AAkCrC,SAAS,WAAW,OAA0C;AAC5D,MAAI,CAAC,MAAO,QAAO;AACnB,QAAM,SAAS,IAAI,KAAK,KAAK;AAC7B,SAAO,OAAO,MAAM,OAAO,QAAQ,CAAC,IAAI,QAAQ,OAAO,mBAAmB;AAC5E;AAEA,SAAS,YACP,MAC4C;AAC5C,UAAQ,MAAM;AAAA,IACZ,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT;AACE,aAAO;AAAA,EACX;AACF;AAEe,SAAR,uBAAwC;AAC7C,QAAM,IAAI,KAAK;AACf,QAAM,SAAS,UAAU;AACzB,QAAM,eAAe,gBAAgB;AAGrC,QAAM,mBAAmB,aAAa,IAAI,eAAe,KAAK;AAE9D,QAAM,CAAC,MAAM,OAAO,IAAI,MAAM,SAA2B,CAAC,CAAC;AAC3D,QAAM,CAAC,MAAM,OAAO,IAAI,MAAM,SAAS,CAAC;AACxC,QAAM,CAAC,QAAQ,IAAI,MAAM,SAAS,EAAE;AACpC,QAAM,CAAC,SAAS,UAAU,IAAI,MAAM;AAAA,IAClC,mBAAmB,EAAE,eAAe,iBA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,gCAAgC,QAAQ;AAAA,QAClD,MAAM,CAAC,EAAE,IAAI,MACX,IAAI,SAAS,YACX,oBAAC,OAAI,SAAQ,WAAW,YAAE,yBAAyB,QAAQ,GAAE,IAE7D,oBAAC,OAAI,SAAQ,WAAW,YAAE,2BAA2B,UAAU,GAAE;AAAA,MAEvE;AAAA,IACF;AAAA,IACA,CAAC,CAAC;AAAA,EACJ;AAEA,SACE,oBAAC,QACC,8BAAC,YACC;AAAA,IAAC;AAAA;AAAA,MACC,OAAO,EAAE,uBAAuB,eAAe;AAAA,MAC/C,SACE,oBAAC,UAAO,SAAO,MACb,+BAAC,QAAK,MAAK,iCACT;AAAA,4BAAC,QAAK,MAAM,IAAI;AAAA,QACf,EAAE,+BAA+B,UAAU;AAAA,SAC9C,GACF;AAAA,MAEF,eAAe;AAAA,QACb,OAAO,EAAE,0BAA0B,SAAS;AAAA,QAC5C,WAAW;AAAA,QACX,cAAc;AAAA,MAChB;AAAA,MACA,eAAe,EAAE,MAAM,KAAK;AAAA,MAC5B,aAAa,EAAE,SAAS,gBAAgB;AAAA,MACxC;AAAA,MACA,MAAM;AAAA,MACN,YAAY,CAAC,QAAQ,OAAO,KAAK,0BAA0B,IAAI,EAAE,EAAE;AAAA,MACnE,WAAW;AAAA,MACX,YAAY;AAAA,QACV;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA,cAAc;AAAA,MAChB;AAAA,MACA,SAAS;AAAA,MACT,cAAc;AAAA,MACd,gBAAgB;AAAA,MAChB,gBAAgB,MAAM,WAAW,CAAC,CAAC;AAAA,MACnC,aAAa;AAAA,MACb,gBAAgB;AAAA;AAAA,EAClB,GACF,GACF;AAEJ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Receipt } from "lucide-react";
|
|
3
|
+
const itemsIcon = React.createElement(Receipt, { size: 16 });
|
|
4
|
+
const metadata = {
|
|
5
|
+
requireAuth: true,
|
|
6
|
+
requireFeatures: ["billing.item.view"],
|
|
7
|
+
pageTitle: "Billing Items",
|
|
8
|
+
pageTitleKey: "billing.items.title",
|
|
9
|
+
pageGroup: "Billing",
|
|
10
|
+
pageGroupKey: "billing.nav.group",
|
|
11
|
+
pageOrder: 20,
|
|
12
|
+
icon: itemsIcon,
|
|
13
|
+
breadcrumb: [{ label: "Billing Items", labelKey: "billing.items.title" }]
|
|
14
|
+
};
|
|
15
|
+
export {
|
|
16
|
+
metadata
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=page.meta.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../../src/modules/billing/backend/billing/items/page.meta.ts"],
|
|
4
|
+
"sourcesContent": ["import React from 'react'\nimport { Receipt } from 'lucide-react'\n\nconst itemsIcon = React.createElement(Receipt, { size: 16 })\n\nexport const metadata = {\n requireAuth: true,\n requireFeatures: ['billing.item.view'],\n pageTitle: 'Billing Items',\n pageTitleKey: 'billing.items.title',\n pageGroup: 'Billing',\n pageGroupKey: 'billing.nav.group',\n pageOrder: 20,\n icon: itemsIcon,\n breadcrumb: [{ label: 'Billing Items', labelKey: 'billing.items.title' }],\n} as const\n"],
|
|
5
|
+
"mappings": "AAAA,OAAO,WAAW;AAClB,SAAS,eAAe;AAExB,MAAM,YAAY,MAAM,cAAc,SAAS,EAAE,MAAM,GAAG,CAAC;AAEpD,MAAM,WAAW;AAAA,EACtB,aAAa;AAAA,EACb,iBAAiB,CAAC,mBAAmB;AAAA,EACrC,WAAW;AAAA,EACX,cAAc;AAAA,EACd,WAAW;AAAA,EACX,cAAc;AAAA,EACd,WAAW;AAAA,EACX,MAAM;AAAA,EACN,YAAY,CAAC,EAAE,OAAO,iBAAiB,UAAU,sBAAsB,CAAC;AAC1E;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|