@dainamite/billing 0.19.0 → 0.21.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 +172 -0
- package/README.md +14 -0
- package/dist/modules/billing/acl.js +13 -1
- package/dist/modules/billing/acl.js.map +2 -2
- package/dist/modules/billing/api/accounts/[id]/summary/route.js +52 -0
- package/dist/modules/billing/api/accounts/[id]/summary/route.js.map +7 -0
- package/dist/modules/billing/api/accounts/route.js +46 -4
- package/dist/modules/billing/api/accounts/route.js.map +2 -2
- package/dist/modules/billing/api/export/account/[id]/route.js +16 -12
- package/dist/modules/billing/api/export/account/[id]/route.js.map +2 -2
- package/dist/modules/billing/api/invoices/[id]/memos/route.js +54 -0
- package/dist/modules/billing/api/invoices/[id]/memos/route.js.map +7 -0
- package/dist/modules/billing/api/invoices/[id]/pdf/route.js +69 -0
- package/dist/modules/billing/api/invoices/[id]/pdf/route.js.map +7 -0
- package/dist/modules/billing/api/invoices/[id]/route.js +44 -24
- package/dist/modules/billing/api/invoices/[id]/route.js.map +2 -2
- package/dist/modules/billing/api/invoices/[id]/send/route.js +107 -0
- package/dist/modules/billing/api/invoices/[id]/send/route.js.map +7 -0
- package/dist/modules/billing/api/invoices/add-line/route.js +3 -3
- package/dist/modules/billing/api/invoices/add-line/route.js.map +2 -2
- package/dist/modules/billing/api/invoices/delete-draft/route.js +33 -0
- package/dist/modules/billing/api/invoices/delete-draft/route.js.map +7 -0
- package/dist/modules/billing/api/invoices/edit-line/route.js +3 -3
- package/dist/modules/billing/api/invoices/edit-line/route.js.map +2 -2
- package/dist/modules/billing/api/invoices/post/route.js +2 -2
- package/dist/modules/billing/api/invoices/post/route.js.map +2 -2
- package/dist/modules/billing/api/invoices/remove-line/route.js +3 -3
- package/dist/modules/billing/api/invoices/remove-line/route.js.map +2 -2
- package/dist/modules/billing/api/invoices/route.js +45 -46
- package/dist/modules/billing/api/invoices/route.js.map +2 -2
- package/dist/modules/billing/api/items/bulk/route.js +1 -1
- package/dist/modules/billing/api/items/bulk/route.js.map +2 -2
- package/dist/modules/billing/api/items/change-price/route.js +44 -0
- package/dist/modules/billing/api/items/change-price/route.js.map +7 -0
- package/dist/modules/billing/api/items/route.js +19 -7
- package/dist/modules/billing/api/items/route.js.map +2 -2
- package/dist/modules/billing/api/payment-imports/[id]/route.js +49 -0
- package/dist/modules/billing/api/payment-imports/[id]/route.js.map +7 -0
- package/dist/modules/billing/api/payment-imports/route.js +57 -0
- package/dist/modules/billing/api/payment-imports/route.js.map +7 -0
- package/dist/modules/billing/api/payments/[id]/route.js +60 -0
- package/dist/modules/billing/api/payments/[id]/route.js.map +7 -0
- package/dist/modules/billing/api/payments/allocate/route.js +35 -0
- package/dist/modules/billing/api/payments/allocate/route.js.map +7 -0
- package/dist/modules/billing/api/payments/assign/route.js +36 -0
- package/dist/modules/billing/api/payments/assign/route.js.map +7 -0
- package/dist/modules/billing/api/payments/convert-to-topup/route.js +35 -0
- package/dist/modules/billing/api/payments/convert-to-topup/route.js.map +7 -0
- package/dist/modules/billing/api/payments/ignore/route.js +35 -0
- package/dist/modules/billing/api/payments/ignore/route.js.map +7 -0
- package/dist/modules/billing/api/payments/import/route.js +63 -0
- package/dist/modules/billing/api/payments/import/route.js.map +7 -0
- package/dist/modules/billing/api/payments/restore/route.js +35 -0
- package/dist/modules/billing/api/payments/restore/route.js.map +7 -0
- package/dist/modules/billing/api/payments/route.js +114 -0
- package/dist/modules/billing/api/payments/route.js.map +7 -0
- package/dist/modules/billing/api/payments/unallocate/route.js +35 -0
- package/dist/modules/billing/api/payments/unallocate/route.js.map +7 -0
- package/dist/modules/billing/api/payments/unassign/route.js +35 -0
- package/dist/modules/billing/api/payments/unassign/route.js.map +7 -0
- package/dist/modules/billing/api/run-outcomes/route.js +44 -7
- package/dist/modules/billing/api/run-outcomes/route.js.map +2 -2
- package/dist/modules/billing/api/runs/[id]/post-drafts/route.js +61 -0
- package/dist/modules/billing/api/runs/[id]/post-drafts/route.js.map +7 -0
- package/dist/modules/billing/api/runs/[id]/route.js +53 -0
- package/dist/modules/billing/api/runs/[id]/route.js.map +7 -0
- package/dist/modules/billing/api/runs/retry-failed/route.js +3 -3
- package/dist/modules/billing/api/runs/retry-failed/route.js.map +2 -2
- package/dist/modules/billing/api/runs/route.js +11 -5
- package/dist/modules/billing/api/runs/route.js.map +2 -2
- package/dist/modules/billing/api/settings/number-preview/route.js +42 -0
- package/dist/modules/billing/api/settings/number-preview/route.js.map +7 -0
- package/dist/modules/billing/api/settings/route.js +92 -0
- package/dist/modules/billing/api/settings/route.js.map +7 -0
- package/dist/modules/billing/api/statements/route.js +3 -0
- package/dist/modules/billing/api/statements/route.js.map +2 -2
- package/dist/modules/billing/api/test-invoices/wipe/route.js +2 -2
- package/dist/modules/billing/api/test-invoices/wipe/route.js.map +2 -2
- package/dist/modules/billing/backend/billing/accounts/[id]/page.js +121 -232
- package/dist/modules/billing/backend/billing/accounts/[id]/page.js.map +2 -2
- package/dist/modules/billing/backend/billing/accounts/create/page.js +6 -0
- package/dist/modules/billing/backend/billing/accounts/create/page.js.map +2 -2
- package/dist/modules/billing/backend/billing/accounts/page.js +63 -4
- package/dist/modules/billing/backend/billing/accounts/page.js.map +2 -2
- package/dist/modules/billing/backend/billing/invoices/[id]/page.js +297 -65
- package/dist/modules/billing/backend/billing/invoices/[id]/page.js.map +3 -3
- package/dist/modules/billing/backend/billing/invoices/page.js +6 -172
- package/dist/modules/billing/backend/billing/invoices/page.js.map +2 -2
- package/dist/modules/billing/backend/billing/items/[id]/page.js +51 -7
- package/dist/modules/billing/backend/billing/items/[id]/page.js.map +2 -2
- package/dist/modules/billing/backend/billing/items/create/page.js +9 -6
- package/dist/modules/billing/backend/billing/items/create/page.js.map +2 -2
- package/dist/modules/billing/backend/billing/items/page.js +8 -2
- package/dist/modules/billing/backend/billing/items/page.js.map +2 -2
- package/dist/modules/billing/backend/billing/payments/[id]/page.js +297 -0
- package/dist/modules/billing/backend/billing/payments/[id]/page.js.map +7 -0
- package/dist/modules/billing/backend/billing/payments/[id]/page.meta.js +21 -0
- package/dist/modules/billing/backend/billing/payments/[id]/page.meta.js.map +7 -0
- package/dist/modules/billing/backend/billing/payments/imports/[id]/page.js +74 -0
- package/dist/modules/billing/backend/billing/payments/imports/[id]/page.js.map +7 -0
- package/dist/modules/billing/backend/billing/payments/imports/[id]/page.meta.js +21 -0
- package/dist/modules/billing/backend/billing/payments/imports/[id]/page.meta.js.map +7 -0
- package/dist/modules/billing/backend/billing/payments/page.js +58 -0
- package/dist/modules/billing/backend/billing/payments/page.js.map +7 -0
- package/dist/modules/billing/backend/billing/payments/page.meta.js +18 -0
- package/dist/modules/billing/backend/billing/payments/page.meta.js.map +7 -0
- package/dist/modules/billing/backend/billing/runs/[id]/page.js +49 -14
- package/dist/modules/billing/backend/billing/runs/[id]/page.js.map +2 -2
- package/dist/modules/billing/backend/billing/runs/page.js +58 -7
- package/dist/modules/billing/backend/billing/runs/page.js.map +2 -2
- package/dist/modules/billing/backend/billing/statements/[id]/page.js +61 -6
- package/dist/modules/billing/backend/billing/statements/[id]/page.js.map +2 -2
- package/dist/modules/billing/backend/billing/statements/page.js +1 -1
- package/dist/modules/billing/backend/billing/statements/page.js.map +2 -2
- package/dist/modules/billing/backend/billing/topups/page.js +1 -1
- package/dist/modules/billing/backend/billing/topups/page.js.map +2 -2
- package/dist/modules/billing/backend/billing/transactions/page.js +1 -1
- package/dist/modules/billing/backend/billing/transactions/page.js.map +2 -2
- package/dist/modules/billing/backend/billing/usage/create/page.js +3 -2
- package/dist/modules/billing/backend/billing/usage/create/page.js.map +2 -2
- package/dist/modules/billing/backend/config/billing/page.js +472 -0
- package/dist/modules/billing/backend/config/billing/page.js.map +7 -0
- package/dist/modules/billing/backend/config/billing/page.meta.js +19 -0
- package/dist/modules/billing/backend/config/billing/page.meta.js.map +7 -0
- package/dist/modules/billing/ce.js.map +2 -2
- package/dist/modules/billing/cli.js +22 -1
- package/dist/modules/billing/cli.js.map +2 -2
- package/dist/modules/billing/commands/accounts.js +6 -0
- package/dist/modules/billing/commands/accounts.js.map +2 -2
- package/dist/modules/billing/commands/index.js +3 -0
- package/dist/modules/billing/commands/index.js.map +2 -2
- package/dist/modules/billing/commands/invoices.js +272 -170
- package/dist/modules/billing/commands/invoices.js.map +2 -2
- package/dist/modules/billing/commands/items.js +108 -0
- package/dist/modules/billing/commands/items.js.map +2 -2
- package/dist/modules/billing/commands/memos.js +179 -0
- package/dist/modules/billing/commands/memos.js.map +7 -0
- package/dist/modules/billing/commands/payments.js +379 -0
- package/dist/modules/billing/commands/payments.js.map +7 -0
- package/dist/modules/billing/commands/runs.js +154 -7
- package/dist/modules/billing/commands/runs.js.map +2 -2
- package/dist/modules/billing/commands/settings.js +59 -0
- package/dist/modules/billing/commands/settings.js.map +7 -0
- package/dist/modules/billing/commands/topups.js +9 -2
- package/dist/modules/billing/commands/topups.js.map +2 -2
- package/dist/modules/billing/commands/transactions.js +2 -2
- package/dist/modules/billing/commands/transactions.js.map +2 -2
- package/dist/modules/billing/components/AccountForm.js +149 -42
- package/dist/modules/billing/components/AccountForm.js.map +2 -2
- package/dist/modules/billing/components/AccountInvoicesSection.js +64 -0
- package/dist/modules/billing/components/AccountInvoicesSection.js.map +7 -0
- package/dist/modules/billing/components/AccountPaymentsSection.js +43 -0
- package/dist/modules/billing/components/AccountPaymentsSection.js.map +7 -0
- package/dist/modules/billing/components/AccountPicker.js +56 -0
- package/dist/modules/billing/components/AccountPicker.js.map +7 -0
- package/dist/modules/billing/components/AllocatePaymentDialog.js +134 -0
- package/dist/modules/billing/components/AllocatePaymentDialog.js.map +7 -0
- package/dist/modules/billing/components/BillingDataTable.js +21 -0
- package/dist/modules/billing/components/BillingDataTable.js.map +7 -0
- package/dist/modules/billing/components/BillingSettingsLink.js +19 -0
- package/dist/modules/billing/components/BillingSettingsLink.js.map +7 -0
- package/dist/modules/billing/components/ChangeItemPriceDialog.js +158 -0
- package/dist/modules/billing/components/ChangeItemPriceDialog.js.map +7 -0
- package/dist/modules/billing/components/CreateMemoDialog.js +200 -0
- package/dist/modules/billing/components/CreateMemoDialog.js.map +7 -0
- package/dist/modules/billing/components/CustomerLabel.js +33 -0
- package/dist/modules/billing/components/CustomerLabel.js.map +7 -0
- package/dist/modules/billing/components/InvoicesTable.js +270 -0
- package/dist/modules/billing/components/InvoicesTable.js.map +7 -0
- package/dist/modules/billing/components/ItemForm.js +176 -44
- package/dist/modules/billing/components/ItemForm.js.map +2 -2
- package/dist/modules/billing/components/ItemPriceField.js +46 -0
- package/dist/modules/billing/components/ItemPriceField.js.map +7 -0
- package/dist/modules/billing/components/LineFormDialog.js +25 -2
- package/dist/modules/billing/components/LineFormDialog.js.map +2 -2
- package/dist/modules/billing/components/ManualPaymentDialog.js +122 -0
- package/dist/modules/billing/components/ManualPaymentDialog.js.map +7 -0
- package/dist/modules/billing/components/MoneyInput.js +14 -0
- package/dist/modules/billing/components/MoneyInput.js.map +7 -0
- package/dist/modules/billing/components/PaymentUploadDialog.js +115 -0
- package/dist/modules/billing/components/PaymentUploadDialog.js.map +7 -0
- package/dist/modules/billing/components/PaymentsTable.js +171 -0
- package/dist/modules/billing/components/PaymentsTable.js.map +7 -0
- package/dist/modules/billing/components/PostRunDraftsButton.js +105 -0
- package/dist/modules/billing/components/PostRunDraftsButton.js.map +7 -0
- package/dist/modules/billing/components/PrepaidPanel.js +14 -4
- package/dist/modules/billing/components/PrepaidPanel.js.map +2 -2
- package/dist/modules/billing/components/RunCyclesSection.js +209 -0
- package/dist/modules/billing/components/RunCyclesSection.js.map +7 -0
- package/dist/modules/billing/components/TestRunActions.js +127 -0
- package/dist/modules/billing/components/TestRunActions.js.map +7 -0
- package/dist/modules/billing/components/account/AccountItemsTab.js +157 -0
- package/dist/modules/billing/components/account/AccountItemsTab.js.map +7 -0
- package/dist/modules/billing/components/account/AccountRunBillingDialog.js +122 -0
- package/dist/modules/billing/components/account/AccountRunBillingDialog.js.map +7 -0
- package/dist/modules/billing/components/account/AccountRunsTab.js +152 -0
- package/dist/modules/billing/components/account/AccountRunsTab.js.map +7 -0
- package/dist/modules/billing/components/account/AccountStatementsTab.js +98 -0
- package/dist/modules/billing/components/account/AccountStatementsTab.js.map +7 -0
- package/dist/modules/billing/components/account/AccountSummaryCards.js +125 -0
- package/dist/modules/billing/components/account/AccountSummaryCards.js.map +7 -0
- package/dist/modules/billing/components/account/AccountUsageTab.js +91 -0
- package/dist/modules/billing/components/account/AccountUsageTab.js.map +7 -0
- package/dist/modules/billing/components/account/AccountView.js +73 -0
- package/dist/modules/billing/components/account/AccountView.js.map +7 -0
- package/dist/modules/billing/components/account/accountRow.js +39 -0
- package/dist/modules/billing/components/account/accountRow.js.map +7 -0
- package/dist/modules/billing/components/customerNames.js +42 -0
- package/dist/modules/billing/components/customerNames.js.map +7 -0
- package/dist/modules/billing/data/entities.js +615 -59
- package/dist/modules/billing/data/entities.js.map +2 -2
- package/dist/modules/billing/data/entityIds.js +10 -1
- package/dist/modules/billing/data/entityIds.js.map +2 -2
- package/dist/modules/billing/data/validators.js +269 -15
- package/dist/modules/billing/data/validators.js.map +2 -2
- package/dist/modules/billing/events.js +70 -0
- package/dist/modules/billing/events.js.map +2 -2
- package/dist/modules/billing/i18n/en.json +457 -21
- package/dist/modules/billing/i18n/pl.json +457 -21
- package/dist/modules/billing/index.js +6 -2
- package/dist/modules/billing/index.js.map +2 -2
- package/dist/modules/billing/lib/accountFinancials.js +58 -0
- package/dist/modules/billing/lib/accountFinancials.js.map +7 -0
- package/dist/modules/billing/lib/accountLock.js +14 -0
- package/dist/modules/billing/lib/accountLock.js.map +7 -0
- package/dist/modules/billing/lib/accountStatus.js +9 -7
- package/dist/modules/billing/lib/accountStatus.js.map +2 -2
- package/dist/modules/billing/lib/accountSummary.js +106 -0
- package/dist/modules/billing/lib/accountSummary.js.map +7 -0
- package/dist/modules/billing/lib/allocation.js +356 -0
- package/dist/modules/billing/lib/allocation.js.map +7 -0
- package/dist/modules/billing/lib/allocationEvents.js +22 -0
- package/dist/modules/billing/lib/allocationEvents.js.map +7 -0
- package/dist/modules/billing/lib/billPeriod.js +15 -1
- package/dist/modules/billing/lib/billPeriod.js.map +2 -2
- package/dist/modules/billing/lib/billRunEngine.js +241 -106
- package/dist/modules/billing/lib/billRunEngine.js.map +2 -2
- package/dist/modules/billing/lib/billRunLabel.js.map +1 -1
- package/dist/modules/billing/lib/billingSettings.js +116 -0
- package/dist/modules/billing/lib/billingSettings.js.map +7 -0
- package/dist/modules/billing/lib/commandRoute.js +81 -0
- package/dist/modules/billing/lib/commandRoute.js.map +7 -0
- package/dist/modules/billing/lib/customerLookup.js +97 -0
- package/dist/modules/billing/lib/customerLookup.js.map +7 -0
- package/dist/modules/billing/lib/dateOnly.js +13 -0
- package/dist/modules/billing/lib/dateOnly.js.map +7 -0
- package/dist/modules/billing/lib/documentParties.js +16 -0
- package/dist/modules/billing/lib/documentParties.js.map +7 -0
- package/dist/modules/billing/lib/documentTypes.js +27 -0
- package/dist/modules/billing/lib/documentTypes.js.map +7 -0
- package/dist/modules/billing/lib/dueDate.js +18 -0
- package/dist/modules/billing/lib/dueDate.js.map +7 -0
- package/dist/modules/billing/lib/iban.js +29 -0
- package/dist/modules/billing/lib/iban.js.map +7 -0
- package/dist/modules/billing/lib/invoiceDelivery.js +131 -0
- package/dist/modules/billing/lib/invoiceDelivery.js.map +7 -0
- package/dist/modules/billing/lib/invoiceLanguages.js +16 -0
- package/dist/modules/billing/lib/invoiceLanguages.js.map +7 -0
- package/dist/modules/billing/lib/invoiceWriter.js +107 -99
- package/dist/modules/billing/lib/invoiceWriter.js.map +2 -2
- package/dist/modules/billing/lib/itemBillingState.js +27 -0
- package/dist/modules/billing/lib/itemBillingState.js.map +7 -0
- package/dist/modules/billing/lib/itemPriceChange.js +18 -0
- package/dist/modules/billing/lib/itemPriceChange.js.map +7 -0
- package/dist/modules/billing/lib/itemSelector.js.map +2 -2
- package/dist/modules/billing/lib/lineAmounts.js +32 -0
- package/dist/modules/billing/lib/lineAmounts.js.map +7 -0
- package/dist/modules/billing/lib/memoGuards.js +25 -0
- package/dist/modules/billing/lib/memoGuards.js.map +7 -0
- package/dist/modules/billing/lib/navigation.js +48 -0
- package/dist/modules/billing/lib/navigation.js.map +7 -0
- package/dist/modules/billing/lib/numbering.js +120 -0
- package/dist/modules/billing/lib/numbering.js.map +7 -0
- package/dist/modules/billing/lib/overdue.js +36 -0
- package/dist/modules/billing/lib/overdue.js.map +7 -0
- package/dist/modules/billing/lib/paymentCsv.js +125 -0
- package/dist/modules/billing/lib/paymentCsv.js.map +7 -0
- package/dist/modules/billing/lib/paymentGateway.js +15 -0
- package/dist/modules/billing/lib/paymentGateway.js.map +7 -0
- package/dist/modules/billing/lib/paymentImport.js +164 -0
- package/dist/modules/billing/lib/paymentImport.js.map +7 -0
- package/dist/modules/billing/lib/paymentMatcher.js +36 -0
- package/dist/modules/billing/lib/paymentMatcher.js.map +7 -0
- package/dist/modules/billing/lib/pdf/attachmentStore.js +46 -0
- package/dist/modules/billing/lib/pdf/attachmentStore.js.map +7 -0
- package/dist/modules/billing/lib/pdf/fonts/embeddedFonts.js +7 -0
- package/dist/modules/billing/lib/pdf/fonts/embeddedFonts.js.map +7 -0
- package/dist/modules/billing/lib/pdf/invoiceModel.js +194 -0
- package/dist/modules/billing/lib/pdf/invoiceModel.js.map +7 -0
- package/dist/modules/billing/lib/pdf/invoicePdf.js +165 -0
- package/dist/modules/billing/lib/pdf/invoicePdf.js.map +7 -0
- package/dist/modules/billing/lib/pdf/invoiceTemplate.js +274 -0
- package/dist/modules/billing/lib/pdf/invoiceTemplate.js.map +7 -0
- package/dist/modules/billing/lib/prepaidConfig.js +17 -25
- package/dist/modules/billing/lib/prepaidConfig.js.map +2 -2
- package/dist/modules/billing/lib/prepaidConsume.js +26 -7
- package/dist/modules/billing/lib/prepaidConsume.js.map +2 -2
- package/dist/modules/billing/lib/prepaidPeriodClose.js +277 -158
- package/dist/modules/billing/lib/prepaidPeriodClose.js.map +2 -2
- package/dist/modules/billing/lib/prepaidTaxPoint.js +37 -0
- package/dist/modules/billing/lib/prepaidTaxPoint.js.map +7 -0
- package/dist/modules/billing/lib/seeds/demo.js +51 -3
- package/dist/modules/billing/lib/seeds/demo.js.map +2 -2
- package/dist/modules/billing/lib/seeds/paymentsSample.js +93 -0
- package/dist/modules/billing/lib/seeds/paymentsSample.js.map +7 -0
- package/dist/modules/billing/lib/seeds/sellerSettings.js +41 -0
- package/dist/modules/billing/lib/seeds/sellerSettings.js.map +7 -0
- package/dist/modules/billing/lib/servicePeriods.js +121 -0
- package/dist/modules/billing/lib/servicePeriods.js.map +7 -0
- package/dist/modules/billing/lib/tenantLock.js.map +1 -1
- package/dist/modules/billing/lib/testRunCleanup.js +24 -0
- package/dist/modules/billing/lib/testRunCleanup.js.map +7 -0
- package/dist/modules/billing/lib/topupCapture.js +2 -2
- package/dist/modules/billing/lib/topupCapture.js.map +2 -2
- package/dist/modules/billing/lib/topupReceipt.js +58 -79
- package/dist/modules/billing/lib/topupReceipt.js.map +2 -2
- package/dist/modules/billing/lib/usageRater.js.map +1 -1
- package/dist/modules/billing/lib/usageRunner.js +14 -6
- package/dist/modules/billing/lib/usageRunner.js.map +2 -2
- package/dist/modules/billing/lib/vat.js +39 -0
- package/dist/modules/billing/lib/vat.js.map +7 -0
- package/dist/modules/billing/migrations/Migration20261114000000_billing_customer_kind.js +15 -0
- package/dist/modules/billing/migrations/Migration20261114000000_billing_customer_kind.js.map +7 -0
- package/dist/modules/billing/migrations/Migration20261114100000_billing_cycle_semantics.js +25 -0
- package/dist/modules/billing/migrations/Migration20261114100000_billing_cycle_semantics.js.map +7 -0
- package/dist/modules/billing/migrations/Migration20261115000000_billing_invoice_ledger.js +115 -0
- package/dist/modules/billing/migrations/Migration20261115000000_billing_invoice_ledger.js.map +7 -0
- package/dist/modules/billing/migrations/Migration20261116000000_billing_invoice_documents.js +47 -0
- package/dist/modules/billing/migrations/Migration20261116000000_billing_invoice_documents.js.map +7 -0
- package/dist/modules/billing/migrations/Migration20261117000000_billing_payments.js +89 -0
- package/dist/modules/billing/migrations/Migration20261117000000_billing_payments.js.map +7 -0
- package/dist/modules/billing/migrations/Migration20261118000000_billing_memos.js +17 -0
- package/dist/modules/billing/migrations/Migration20261118000000_billing_memos.js.map +7 -0
- package/dist/modules/billing/migrations/Migration20261119000000_billing_operator_feedback.js +27 -0
- package/dist/modules/billing/migrations/Migration20261119000000_billing_operator_feedback.js.map +7 -0
- package/dist/modules/billing/migrations/Migration20261120000000_billing_allocation_scope_indexes.js +29 -0
- package/dist/modules/billing/migrations/Migration20261120000000_billing_allocation_scope_indexes.js.map +7 -0
- package/dist/modules/billing/setup.js +7 -184
- package/dist/modules/billing/setup.js.map +2 -2
- package/dist/modules/billing/subscribers/credit-memo-auto-send.js +16 -0
- package/dist/modules/billing/subscribers/credit-memo-auto-send.js.map +7 -0
- package/dist/modules/billing/subscribers/debit-memo-apply-credit.js +16 -0
- package/dist/modules/billing/subscribers/debit-memo-apply-credit.js.map +7 -0
- package/dist/modules/billing/subscribers/debit-memo-auto-send.js +16 -0
- package/dist/modules/billing/subscribers/debit-memo-auto-send.js.map +7 -0
- package/dist/modules/billing/subscribers/invoice-apply-credit.js +34 -0
- package/dist/modules/billing/subscribers/invoice-apply-credit.js.map +7 -0
- package/dist/modules/billing/subscribers/invoice-auto-send.js +30 -0
- package/dist/modules/billing/subscribers/invoice-auto-send.js.map +7 -0
- package/dist/modules/billing/subscribers/payment-captured-to-paid.js +69 -33
- package/dist/modules/billing/subscribers/payment-captured-to-paid.js.map +2 -2
- package/dist/modules/billing/subscribers/prepaid-topup-captured.js +4 -6
- package/dist/modules/billing/subscribers/prepaid-topup-captured.js.map +2 -2
- package/dist/modules/billing/workers/reap-stale-bill-runs.js +2 -2
- package/dist/modules/billing/workers/reap-stale-bill-runs.js.map +2 -2
- package/generated/entities/billing_account/index.ts +26 -0
- package/generated/entities/billing_account_balance/index.ts +13 -0
- package/generated/entities/billing_account_transaction/index.ts +21 -0
- package/generated/entities/billing_account_usage/index.ts +18 -0
- package/generated/entities/billing_allocation/index.ts +18 -0
- package/generated/entities/billing_document_sequence/index.ts +11 -0
- package/generated/entities/billing_draft_invoice_edit/index.ts +14 -0
- package/generated/entities/billing_invoice/index.ts +38 -0
- package/generated/entities/billing_invoice_line/index.ts +24 -0
- package/generated/entities/billing_item/index.ts +26 -0
- package/generated/entities/billing_payment/index.ts +25 -0
- package/generated/entities/billing_payment_import/index.ts +14 -0
- package/generated/entities/billing_run/index.ts +20 -0
- package/generated/entities/billing_run_outcome/index.ts +18 -0
- package/generated/entities/billing_settings/index.ts +26 -0
- package/generated/entities/billing_statement/index.ts +22 -0
- package/generated/entities/billing_topup/index.ts +20 -0
- package/generated/entities.ids.generated.ts +35 -0
- package/package.json +15 -10
- package/src/modules/billing/__integration__/TC-BILL-004.spec.ts +170 -0
- package/src/modules/billing/__integration__/TC-BILL-005.spec.ts +134 -0
- package/src/modules/billing/__integration__/TC-BILL-006.spec.ts +101 -0
- package/src/modules/billing/__integration__/TC-BILL-007.spec.ts +140 -0
- package/src/modules/billing/__integration__/TC-BILL-008.spec.ts +108 -0
- package/src/modules/billing/__integration__/TC-BILL-009.spec.ts +113 -0
- package/src/modules/billing/__integration__/TC-BILL-010.spec.ts +118 -0
- package/src/modules/billing/__integration__/TC-BILL-011.spec.ts +142 -0
- package/src/modules/billing/__integration__/TC-BILL-012.spec.ts +115 -0
- package/src/modules/billing/__integration__/TC-BILL-013.spec.ts +118 -0
- package/src/modules/billing/__integration__/sellerSettings.ts +24 -0
- package/src/modules/billing/__tests__/commands/invoices.test.ts +437 -355
- package/src/modules/billing/__tests__/commands/itemsBulk.test.ts +33 -0
- package/src/modules/billing/__tests__/commands/memos.test.ts +205 -0
- package/src/modules/billing/__tests__/commands/payments.test.ts +241 -0
- package/src/modules/billing/__tests__/commands/runsDelete.test.ts +146 -0
- package/src/modules/billing/__tests__/commands/runsPostDrafts.test.ts +106 -0
- package/src/modules/billing/__tests__/commands/topups.test.ts +11 -0
- package/src/modules/billing/__tests__/entityRegistry.test.ts +326 -0
- package/src/modules/billing/__tests__/events.test.ts +142 -0
- package/src/modules/billing/__tests__/helpers/prepaidMockEm.ts +28 -11
- package/src/modules/billing/__tests__/lib/accountFinancials.test.ts +53 -0
- package/src/modules/billing/__tests__/lib/accountSummary.test.ts +97 -0
- package/src/modules/billing/__tests__/lib/allocation.test.ts +319 -0
- package/src/modules/billing/__tests__/lib/billRunEngine.test.ts +231 -20
- package/src/modules/billing/__tests__/lib/billingSettings.test.ts +109 -0
- package/src/modules/billing/__tests__/lib/customerLookup.test.ts +156 -0
- package/src/modules/billing/__tests__/lib/dueDate.test.ts +35 -0
- package/src/modules/billing/__tests__/lib/iban.test.ts +38 -0
- package/src/modules/billing/__tests__/lib/invoiceDelivery.test.ts +189 -0
- package/src/modules/billing/__tests__/lib/invoiceWriter.test.ts +212 -10
- package/src/modules/billing/__tests__/lib/itemBillingState.test.ts +42 -0
- package/src/modules/billing/__tests__/lib/itemPriceChange.test.ts +165 -0
- package/src/modules/billing/__tests__/lib/lineAmounts.test.ts +86 -0
- package/src/modules/billing/__tests__/lib/navigation.test.ts +71 -0
- package/src/modules/billing/__tests__/lib/numbering.test.ts +91 -0
- package/src/modules/billing/__tests__/lib/overdue.test.ts +36 -0
- package/src/modules/billing/__tests__/lib/paymentCsv.test.ts +148 -0
- package/src/modules/billing/__tests__/lib/paymentImport.test.ts +113 -0
- package/src/modules/billing/__tests__/lib/paymentsSample.test.ts +73 -0
- package/src/modules/billing/__tests__/lib/pdf/invoicePdf.test.ts +199 -0
- package/src/modules/billing/__tests__/lib/pdf/invoicePdfService.test.ts +147 -0
- package/src/modules/billing/__tests__/lib/prepaidPeriodClose.test.ts +374 -98
- package/src/modules/billing/__tests__/lib/prepaidTaxPoint.test.ts +118 -0
- package/src/modules/billing/__tests__/lib/seedsDemo.test.ts +53 -2
- package/src/modules/billing/__tests__/lib/sellerSettings.test.ts +28 -0
- package/src/modules/billing/__tests__/lib/servicePeriods.test.ts +190 -0
- package/src/modules/billing/__tests__/lib/topupCapture.test.ts +6 -28
- package/src/modules/billing/__tests__/lib/topupReceipt.test.ts +21 -52
- package/src/modules/billing/__tests__/lib/vat.test.ts +51 -0
- package/src/modules/billing/__tests__/package-isolation.test.ts +22 -8
- package/src/modules/billing/__tests__/setup.test.ts +13 -4
- package/src/modules/billing/__tests__/validators.test.ts +193 -3
- package/src/modules/billing/acl.ts +12 -0
- package/src/modules/billing/api/accounts/[id]/summary/route.ts +62 -0
- package/src/modules/billing/api/accounts/route.ts +58 -4
- package/src/modules/billing/api/export/account/[id]/route.ts +20 -18
- package/src/modules/billing/api/invoices/[id]/memos/route.ts +63 -0
- package/src/modules/billing/api/invoices/[id]/pdf/route.ts +79 -0
- package/src/modules/billing/api/invoices/[id]/route.ts +57 -70
- package/src/modules/billing/api/invoices/[id]/send/route.ts +127 -0
- package/src/modules/billing/api/invoices/add-line/route.ts +3 -3
- package/src/modules/billing/api/invoices/delete-draft/route.ts +33 -0
- package/src/modules/billing/api/invoices/edit-line/route.ts +4 -4
- package/src/modules/billing/api/invoices/post/route.ts +7 -6
- package/src/modules/billing/api/invoices/remove-line/route.ts +3 -3
- package/src/modules/billing/api/invoices/route.ts +81 -86
- package/src/modules/billing/api/items/bulk/route.ts +2 -1
- package/src/modules/billing/api/items/change-price/route.ts +54 -0
- package/src/modules/billing/api/items/route.ts +23 -7
- package/src/modules/billing/api/payment-imports/[id]/route.ts +49 -0
- package/src/modules/billing/api/payment-imports/route.ts +57 -0
- package/src/modules/billing/api/payments/[id]/route.ts +63 -0
- package/src/modules/billing/api/payments/allocate/route.ts +35 -0
- package/src/modules/billing/api/payments/assign/route.ts +36 -0
- package/src/modules/billing/api/payments/convert-to-topup/route.ts +35 -0
- package/src/modules/billing/api/payments/ignore/route.ts +35 -0
- package/src/modules/billing/api/payments/import/route.ts +72 -0
- package/src/modules/billing/api/payments/restore/route.ts +35 -0
- package/src/modules/billing/api/payments/route.ts +147 -0
- package/src/modules/billing/api/payments/unallocate/route.ts +35 -0
- package/src/modules/billing/api/payments/unassign/route.ts +35 -0
- package/src/modules/billing/api/run-outcomes/route.ts +50 -7
- package/src/modules/billing/api/runs/[id]/post-drafts/route.ts +71 -0
- package/src/modules/billing/api/runs/[id]/route.ts +59 -0
- package/src/modules/billing/api/runs/retry-failed/route.ts +4 -3
- package/src/modules/billing/api/runs/route.ts +17 -9
- package/src/modules/billing/api/settings/number-preview/route.ts +46 -0
- package/src/modules/billing/api/settings/route.ts +116 -0
- package/src/modules/billing/api/statements/route.ts +5 -0
- package/src/modules/billing/api/test-invoices/wipe/route.ts +2 -2
- package/src/modules/billing/backend/billing/accounts/[id]/page.tsx +151 -372
- package/src/modules/billing/backend/billing/accounts/create/page.tsx +6 -0
- package/src/modules/billing/backend/billing/accounts/page.tsx +71 -5
- package/src/modules/billing/backend/billing/invoices/[id]/page.tsx +445 -96
- package/src/modules/billing/backend/billing/invoices/page.tsx +8 -227
- package/src/modules/billing/backend/billing/items/[id]/page.tsx +75 -6
- package/src/modules/billing/backend/billing/items/create/page.tsx +13 -8
- package/src/modules/billing/backend/billing/items/page.tsx +19 -3
- package/src/modules/billing/backend/billing/payments/[id]/page.meta.ts +19 -0
- package/src/modules/billing/backend/billing/payments/[id]/page.tsx +415 -0
- package/src/modules/billing/backend/billing/payments/imports/[id]/page.meta.ts +19 -0
- package/src/modules/billing/backend/billing/payments/imports/[id]/page.tsx +106 -0
- package/src/modules/billing/backend/billing/payments/page.meta.ts +16 -0
- package/src/modules/billing/backend/billing/payments/page.tsx +56 -0
- package/src/modules/billing/backend/billing/runs/[id]/page.tsx +50 -19
- package/src/modules/billing/backend/billing/runs/page.tsx +60 -9
- package/src/modules/billing/backend/billing/statements/[id]/page.tsx +87 -6
- package/src/modules/billing/backend/billing/statements/page.tsx +2 -2
- package/src/modules/billing/backend/billing/topups/page.tsx +2 -2
- package/src/modules/billing/backend/billing/transactions/page.tsx +2 -2
- package/src/modules/billing/backend/billing/usage/create/page.tsx +3 -2
- package/src/modules/billing/backend/config/billing/page.meta.ts +21 -0
- package/src/modules/billing/backend/config/billing/page.tsx +549 -0
- package/src/modules/billing/ce.ts +8 -7
- package/src/modules/billing/cli.ts +31 -1
- package/src/modules/billing/commands/accounts.ts +6 -0
- package/src/modules/billing/commands/index.ts +3 -0
- package/src/modules/billing/commands/invoices.ts +371 -238
- package/src/modules/billing/commands/items.ts +143 -0
- package/src/modules/billing/commands/memos.ts +218 -0
- package/src/modules/billing/commands/payments.ts +428 -0
- package/src/modules/billing/commands/runs.ts +208 -6
- package/src/modules/billing/commands/settings.ts +77 -0
- package/src/modules/billing/commands/topups.ts +12 -3
- package/src/modules/billing/commands/transactions.ts +2 -2
- package/src/modules/billing/components/AccountForm.tsx +199 -53
- package/src/modules/billing/components/AccountInvoicesSection.tsx +75 -0
- package/src/modules/billing/components/AccountPaymentsSection.tsx +42 -0
- package/src/modules/billing/components/AccountPicker.tsx +70 -0
- package/src/modules/billing/components/AllocatePaymentDialog.tsx +167 -0
- package/src/modules/billing/components/BillingDataTable.tsx +34 -0
- package/src/modules/billing/components/BillingSettingsLink.tsx +25 -0
- package/src/modules/billing/components/ChangeItemPriceDialog.tsx +180 -0
- package/src/modules/billing/components/CreateMemoDialog.tsx +232 -0
- package/src/modules/billing/components/CustomerLabel.tsx +53 -0
- package/src/modules/billing/components/InvoicesTable.tsx +344 -0
- package/src/modules/billing/components/ItemForm.tsx +233 -44
- package/src/modules/billing/components/ItemPriceField.tsx +81 -0
- package/src/modules/billing/components/LineFormDialog.tsx +25 -1
- package/src/modules/billing/components/ManualPaymentDialog.tsx +140 -0
- package/src/modules/billing/components/MoneyInput.tsx +26 -0
- package/src/modules/billing/components/PaymentUploadDialog.tsx +148 -0
- package/src/modules/billing/components/PaymentsTable.tsx +213 -0
- package/src/modules/billing/components/PostRunDraftsButton.tsx +129 -0
- package/src/modules/billing/components/PrepaidPanel.tsx +20 -7
- package/src/modules/billing/components/RunCyclesSection.tsx +298 -0
- package/src/modules/billing/components/TestRunActions.tsx +152 -0
- package/src/modules/billing/components/account/AccountItemsTab.tsx +192 -0
- package/src/modules/billing/components/account/AccountRunBillingDialog.tsx +147 -0
- package/src/modules/billing/components/account/AccountRunsTab.tsx +201 -0
- package/src/modules/billing/components/account/AccountStatementsTab.tsx +120 -0
- package/src/modules/billing/components/account/AccountSummaryCards.tsx +153 -0
- package/src/modules/billing/components/account/AccountUsageTab.tsx +122 -0
- package/src/modules/billing/components/account/AccountView.tsx +101 -0
- package/src/modules/billing/components/account/accountRow.ts +70 -0
- package/src/modules/billing/components/customerNames.ts +62 -0
- package/src/modules/billing/data/entities.ts +685 -15
- package/src/modules/billing/data/entityIds.ts +25 -11
- package/src/modules/billing/data/validators.ts +388 -8
- package/src/modules/billing/events.ts +82 -3
- package/src/modules/billing/i18n/en.json +457 -21
- package/src/modules/billing/i18n/pl.json +457 -21
- package/src/modules/billing/index.ts +6 -2
- package/src/modules/billing/lib/accountFinancials.ts +84 -0
- package/src/modules/billing/lib/accountLock.ts +32 -0
- package/src/modules/billing/lib/accountStatus.ts +11 -9
- package/src/modules/billing/lib/accountSummary.ts +172 -0
- package/src/modules/billing/lib/allocation.ts +515 -0
- package/src/modules/billing/lib/allocationEvents.ts +26 -0
- package/src/modules/billing/lib/billPeriod.ts +19 -0
- package/src/modules/billing/lib/billRunEngine.ts +362 -162
- package/src/modules/billing/lib/billRunLabel.ts +1 -1
- package/src/modules/billing/lib/billingSettings.ts +145 -0
- package/src/modules/billing/lib/commandRoute.ts +112 -0
- package/src/modules/billing/lib/customerLookup.ts +157 -0
- package/src/modules/billing/lib/dateOnly.ts +22 -0
- package/src/modules/billing/lib/documentParties.ts +23 -0
- package/src/modules/billing/lib/documentTypes.ts +37 -0
- package/src/modules/billing/lib/dueDate.ts +26 -0
- package/src/modules/billing/lib/iban.ts +36 -0
- package/src/modules/billing/lib/invoiceDelivery.ts +197 -0
- package/src/modules/billing/lib/invoiceLanguages.ts +34 -0
- package/src/modules/billing/lib/invoiceWriter.ts +162 -148
- package/src/modules/billing/lib/itemBillingState.ts +67 -0
- package/src/modules/billing/lib/itemPriceChange.ts +56 -0
- package/src/modules/billing/lib/itemSelector.ts +4 -1
- package/src/modules/billing/lib/lineAmounts.ts +61 -0
- package/src/modules/billing/lib/memoGuards.ts +41 -0
- package/src/modules/billing/lib/navigation.ts +64 -0
- package/src/modules/billing/lib/numbering.ts +174 -0
- package/src/modules/billing/lib/overdue.ts +60 -0
- package/src/modules/billing/lib/paymentCsv.ts +171 -0
- package/src/modules/billing/lib/paymentGateway.ts +52 -0
- package/src/modules/billing/lib/paymentImport.ts +228 -0
- package/src/modules/billing/lib/paymentMatcher.ts +88 -0
- package/src/modules/billing/lib/pdf/attachmentStore.ts +60 -0
- package/src/modules/billing/lib/pdf/fonts/NotoSans-Bold.ttf +0 -0
- package/src/modules/billing/lib/pdf/fonts/NotoSans-Regular.ttf +0 -0
- package/src/modules/billing/lib/pdf/fonts/OFL.txt +93 -0
- package/src/modules/billing/lib/pdf/fonts/embeddedFonts.ts +9 -0
- package/src/modules/billing/lib/pdf/invoiceModel.ts +328 -0
- package/src/modules/billing/lib/pdf/invoicePdf.ts +216 -0
- package/src/modules/billing/lib/pdf/invoiceTemplate.ts +338 -0
- package/src/modules/billing/lib/prepaidConfig.ts +27 -36
- package/src/modules/billing/lib/prepaidConsume.ts +29 -6
- package/src/modules/billing/lib/prepaidPeriodClose.ts +410 -242
- package/src/modules/billing/lib/prepaidTaxPoint.ts +76 -0
- package/src/modules/billing/lib/seeds/demo.ts +79 -6
- package/src/modules/billing/lib/seeds/paymentsSample.ts +136 -0
- package/src/modules/billing/lib/seeds/sellerSettings.ts +78 -0
- package/src/modules/billing/lib/servicePeriods.ts +226 -0
- package/src/modules/billing/lib/tenantLock.ts +1 -1
- package/src/modules/billing/lib/testRunCleanup.ts +42 -0
- package/src/modules/billing/lib/topupCapture.ts +3 -4
- package/src/modules/billing/lib/topupReceipt.ts +70 -103
- package/src/modules/billing/lib/usageRater.ts +1 -1
- package/src/modules/billing/lib/usageRunner.ts +17 -5
- package/src/modules/billing/lib/vat.ts +56 -0
- package/src/modules/billing/migrations/Migration20261114000000_billing_customer_kind.ts +25 -0
- package/src/modules/billing/migrations/Migration20261114100000_billing_cycle_semantics.ts +37 -0
- package/src/modules/billing/migrations/Migration20261115000000_billing_invoice_ledger.ts +132 -0
- package/src/modules/billing/migrations/Migration20261116000000_billing_invoice_documents.ts +58 -0
- package/src/modules/billing/migrations/Migration20261117000000_billing_payments.ts +97 -0
- package/src/modules/billing/migrations/Migration20261118000000_billing_memos.ts +21 -0
- package/src/modules/billing/migrations/Migration20261119000000_billing_operator_feedback.ts +39 -0
- package/src/modules/billing/migrations/Migration20261120000000_billing_allocation_scope_indexes.ts +35 -0
- package/src/modules/billing/setup.ts +11 -237
- package/src/modules/billing/subscribers/credit-memo-auto-send.ts +15 -0
- package/src/modules/billing/subscribers/debit-memo-apply-credit.ts +15 -0
- package/src/modules/billing/subscribers/debit-memo-auto-send.ts +15 -0
- package/src/modules/billing/subscribers/invoice-apply-credit.ts +39 -0
- package/src/modules/billing/subscribers/invoice-auto-send.ts +46 -0
- package/src/modules/billing/subscribers/payment-captured-to-paid.ts +84 -62
- package/src/modules/billing/subscribers/prepaid-topup-captured.ts +4 -8
- package/src/modules/billing/workers/reap-stale-bill-runs.ts +4 -4
- package/dist/modules/billing/lib/invoiceStatus.js +0 -38
- package/dist/modules/billing/lib/invoiceStatus.js.map +0 -7
- package/src/modules/billing/__tests__/lib/invoiceStatus.test.ts +0 -97
- package/src/modules/billing/lib/invoiceStatus.ts +0 -61
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
import * as React from 'react'
|
|
3
|
+
import { useRouter } from 'next/navigation'
|
|
4
|
+
import type { LegacyColumnDef as ColumnDef } from '@tanstack/react-table/legacy'
|
|
5
|
+
import { useT } from '@open-mercato/shared/lib/i18n/context'
|
|
6
|
+
import { BillingDataTable as DataTable } from '../BillingDataTable'
|
|
7
|
+
import { Tag } from '@open-mercato/ui/primitives/tag'
|
|
8
|
+
import { readApiResultOrThrow } from '@open-mercato/ui/backend/utils/apiCall'
|
|
9
|
+
import { itemBillingState, type ItemBillingState } from '../../lib/itemBillingState'
|
|
10
|
+
import { formatDate } from './accountRow'
|
|
11
|
+
|
|
12
|
+
// Snake_case projection of `GET /api/billing/items` (see its `fields`).
|
|
13
|
+
type AccountItemRow = {
|
|
14
|
+
id: string
|
|
15
|
+
description: string
|
|
16
|
+
type: 'one_time' | 'recurring' | 'usage'
|
|
17
|
+
bill_start_date: string
|
|
18
|
+
bill_end_date: string | null
|
|
19
|
+
billed_to_date: string | null
|
|
20
|
+
rate_json: Record<string, unknown> | null
|
|
21
|
+
charge_timing: 'in_advance' | 'in_arrears'
|
|
22
|
+
price_basis?: 'net' | 'gross'
|
|
23
|
+
uom_code: string | null
|
|
24
|
+
is_active: boolean
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function localToday(): string {
|
|
28
|
+
const now = new Date()
|
|
29
|
+
const month = String(now.getMonth() + 1).padStart(2, '0')
|
|
30
|
+
const date = String(now.getDate()).padStart(2, '0')
|
|
31
|
+
return `${now.getFullYear()}-${month}-${date}`
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function stateVariant(state: ItemBillingState): 'success' | 'warning' | 'neutral' | 'info' {
|
|
35
|
+
switch (state.status) {
|
|
36
|
+
case 'billed':
|
|
37
|
+
case 'current':
|
|
38
|
+
case 'fully_billed':
|
|
39
|
+
return 'success'
|
|
40
|
+
case 'awaiting_run':
|
|
41
|
+
case 'due':
|
|
42
|
+
return 'warning'
|
|
43
|
+
case 'metered':
|
|
44
|
+
return 'info'
|
|
45
|
+
default:
|
|
46
|
+
return 'neutral'
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The account's billing items (workspace Items tab): what each item costs,
|
|
52
|
+
* its term, how far it has been billed and — against today — whether a Bill
|
|
53
|
+
* Run still has to charge it.
|
|
54
|
+
*/
|
|
55
|
+
export function AccountItemsTab({ accountId, currencyCode }: { accountId: string; currencyCode?: string }) {
|
|
56
|
+
const t = useT()
|
|
57
|
+
const router = useRouter()
|
|
58
|
+
const [rows, setRows] = React.useState<AccountItemRow[]>([])
|
|
59
|
+
const [page, setPage] = React.useState(1)
|
|
60
|
+
const [total, setTotal] = React.useState(0)
|
|
61
|
+
const [totalPages, setTotalPages] = React.useState(1)
|
|
62
|
+
const [loading, setLoading] = React.useState(true)
|
|
63
|
+
const pageSize = 25
|
|
64
|
+
const today = React.useMemo(() => localToday(), [])
|
|
65
|
+
|
|
66
|
+
const load = React.useCallback(async () => {
|
|
67
|
+
setLoading(true)
|
|
68
|
+
try {
|
|
69
|
+
const result = await readApiResultOrThrow<{ items: AccountItemRow[]; total: number; totalPages: number }>(
|
|
70
|
+
`/api/billing/items?billAccountId=${accountId}&page=${page}` + `&pageSize=${pageSize}&sortField=createdAt&sortDir=desc`,
|
|
71
|
+
)
|
|
72
|
+
setRows(result.items ?? [])
|
|
73
|
+
setTotal(result.total ?? 0)
|
|
74
|
+
setTotalPages(result.totalPages ?? 1)
|
|
75
|
+
} finally {
|
|
76
|
+
setLoading(false)
|
|
77
|
+
}
|
|
78
|
+
}, [accountId, page])
|
|
79
|
+
|
|
80
|
+
React.useEffect(() => {
|
|
81
|
+
void load()
|
|
82
|
+
}, [load])
|
|
83
|
+
|
|
84
|
+
const typeLabel = React.useCallback(
|
|
85
|
+
(row: AccountItemRow) => {
|
|
86
|
+
if (row.type === 'one_time') return t('billing.items.form.type.one_time', 'One-time charge')
|
|
87
|
+
if (row.type === 'usage') return t('billing.items.form.type.usage', 'Usage (metered)')
|
|
88
|
+
return row.charge_timing === 'in_arrears'
|
|
89
|
+
? t('billing.accounts.items.recurring_arrears', 'Recurring · in arrears')
|
|
90
|
+
: t('billing.accounts.items.recurring_advance', 'Recurring · in advance')
|
|
91
|
+
},
|
|
92
|
+
[t],
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
const rateLabel = React.useCallback(
|
|
96
|
+
(row: AccountItemRow) => {
|
|
97
|
+
const rate = row.rate_json ?? {}
|
|
98
|
+
const amount = typeof rate.amount === 'number' ? rate.amount : typeof rate.unit_price === 'number' ? rate.unit_price : null
|
|
99
|
+
if (amount === null) {
|
|
100
|
+
return 'model' in rate ? `${t('billing.accounts.items.tiered', 'Tiered')} (${String(rate.model)})` : '—'
|
|
101
|
+
}
|
|
102
|
+
const perUnit = row.type === 'usage' && row.uom_code ? ` / ${row.uom_code}` : ''
|
|
103
|
+
const basis = row.price_basis === 'gross' ? t('billing.items.price_basis.gross', 'Gross') : t('billing.items.price_basis.net', 'Net')
|
|
104
|
+
return `${amount}${currencyCode ? ` ${currencyCode}` : ''}${perUnit} · ${basis}`
|
|
105
|
+
},
|
|
106
|
+
[currencyCode, t],
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
const stateLabel = React.useCallback(
|
|
110
|
+
(state: ItemBillingState) => {
|
|
111
|
+
const date = state.date ? formatDate(state.date) : ''
|
|
112
|
+
switch (state.status) {
|
|
113
|
+
case 'inactive':
|
|
114
|
+
return t('billing.common.inactive', 'Inactive')
|
|
115
|
+
case 'metered':
|
|
116
|
+
return t('billing.accounts.items.state.metered', 'Billed from usage')
|
|
117
|
+
case 'scheduled':
|
|
118
|
+
return `${t('billing.accounts.items.state.scheduled', 'Starts')} ${date}`
|
|
119
|
+
case 'awaiting_run':
|
|
120
|
+
return t('billing.accounts.items.state.awaiting_run', 'Not billed yet')
|
|
121
|
+
case 'billed':
|
|
122
|
+
return t('billing.accounts.items.state.billed', 'Billed')
|
|
123
|
+
case 'current':
|
|
124
|
+
return `${t('billing.accounts.items.state.current', 'Billed through')} ${date}`
|
|
125
|
+
case 'due':
|
|
126
|
+
return `${t('billing.accounts.items.state.due', 'Due since')} ${date}`
|
|
127
|
+
case 'fully_billed':
|
|
128
|
+
return t('billing.accounts.items.state.fully_billed', 'Fully billed')
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
[t],
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
const columns = React.useMemo<ColumnDef<AccountItemRow>[]>(
|
|
135
|
+
() => [
|
|
136
|
+
{
|
|
137
|
+
accessorKey: 'description',
|
|
138
|
+
header: t('billing.items.columns.description', 'Description'),
|
|
139
|
+
cell: ({ row }) => <span className="text-sm font-medium text-primary">{row.original.description}</span>,
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
accessorKey: 'type',
|
|
143
|
+
header: t('billing.items.columns.type', 'Type'),
|
|
144
|
+
cell: ({ row }) => <span className="text-sm">{typeLabel(row.original)}</span>,
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
accessorKey: 'rate_json',
|
|
148
|
+
header: t('billing.items.form.rate.title', 'Rate'),
|
|
149
|
+
cell: ({ row }) => <span className="text-sm tabular-nums">{rateLabel(row.original)}</span>,
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
accessorKey: 'bill_start_date',
|
|
153
|
+
header: t('billing.accounts.items.term', 'Term'),
|
|
154
|
+
cell: ({ row }) =>
|
|
155
|
+
`${formatDate(row.original.bill_start_date)} – ${
|
|
156
|
+
row.original.bill_end_date ? formatDate(row.original.bill_end_date) : t('billing.accounts.items.open_ended', 'open-ended')
|
|
157
|
+
}`,
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
accessorKey: 'billed_to_date',
|
|
161
|
+
header: t('billing.accounts.items.billed_through', 'Billed through'),
|
|
162
|
+
cell: ({ row }) =>
|
|
163
|
+
row.original.type === 'recurring' && row.original.billed_to_date ? formatDate(row.original.billed_to_date) : '—',
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
id: 'billing_state',
|
|
167
|
+
header: t('billing.accounts.items.state', 'Billing'),
|
|
168
|
+
cell: ({ row }) => {
|
|
169
|
+
const state = itemBillingState(row.original, today)
|
|
170
|
+
return <Tag variant={stateVariant(state)}>{stateLabel(state)}</Tag>
|
|
171
|
+
},
|
|
172
|
+
},
|
|
173
|
+
],
|
|
174
|
+
[rateLabel, stateLabel, t, today, typeLabel],
|
|
175
|
+
)
|
|
176
|
+
|
|
177
|
+
return (
|
|
178
|
+
<DataTable
|
|
179
|
+
title={t('billing.accounts.detail.items.title', 'Items')}
|
|
180
|
+
columns={columns}
|
|
181
|
+
data={rows}
|
|
182
|
+
isLoading={loading}
|
|
183
|
+
onRowClick={(row) => router.push(`/backend/billing/items/${row.id}`)}
|
|
184
|
+
pagination={{ page, pageSize, total, totalPages, onPageChange: setPage }}
|
|
185
|
+
emptyState={
|
|
186
|
+
<div className="rounded-lg border bg-card p-6 text-center text-sm text-muted-foreground">
|
|
187
|
+
{t('billing.accounts.detail.items.empty', 'No items for this account yet.')}
|
|
188
|
+
</div>
|
|
189
|
+
}
|
|
190
|
+
/>
|
|
191
|
+
)
|
|
192
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
import * as React from 'react'
|
|
3
|
+
import { Play } from 'lucide-react'
|
|
4
|
+
import { useT } from '@open-mercato/shared/lib/i18n/context'
|
|
5
|
+
import { Button } from '@open-mercato/ui/primitives/button'
|
|
6
|
+
import { Input } from '@open-mercato/ui/primitives/input'
|
|
7
|
+
import { Kbd, KbdShortcut } from '@open-mercato/ui/primitives/kbd'
|
|
8
|
+
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@open-mercato/ui/primitives/select'
|
|
9
|
+
import {
|
|
10
|
+
Dialog,
|
|
11
|
+
DialogContent,
|
|
12
|
+
DialogDescription,
|
|
13
|
+
DialogFooter,
|
|
14
|
+
DialogHeader,
|
|
15
|
+
DialogTitle,
|
|
16
|
+
} from '@open-mercato/ui/primitives/dialog'
|
|
17
|
+
import { flash } from '@open-mercato/ui/backend/FlashMessages'
|
|
18
|
+
import { apiCallOrThrow, readApiResultOrThrow } from '@open-mercato/ui/backend/utils/apiCall'
|
|
19
|
+
import { normalizeCrudServerError } from '@open-mercato/ui/backend/utils/serverErrors'
|
|
20
|
+
import type { BillRunMode } from '../TestRunActions'
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* "Run billing" for one account (Spec E, E2-D3 / Spec F, F8): mode (Test by
|
|
24
|
+
* default) + as-of date → `POST /api/billing/runs` with
|
|
25
|
+
* `scopedAccountIds: [id]`. On success the dialog closes with a one-line
|
|
26
|
+
* summary; the workspace switches to its Bill runs tab, where the run (with
|
|
27
|
+
* its mode, documents and cleanup actions) is listed.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
type OutcomeRow = { status: string; error_message: string | null; cycles: Array<{ status: string }> | null }
|
|
31
|
+
|
|
32
|
+
function todayIso(): string {
|
|
33
|
+
return new Date().toISOString().slice(0, 10)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export type AccountRunBillingDialogProps = {
|
|
37
|
+
accountId: string
|
|
38
|
+
open: boolean
|
|
39
|
+
onOpenChange: (open: boolean) => void
|
|
40
|
+
/** Called after a run finished — the workspace closes the dialog and refreshes. */
|
|
41
|
+
onCompleted: (billRunId: string) => void
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function AccountRunBillingDialog({ accountId, open, onOpenChange, onCompleted }: AccountRunBillingDialogProps) {
|
|
45
|
+
const t = useT()
|
|
46
|
+
const [mode, setMode] = React.useState<BillRunMode>('test')
|
|
47
|
+
const [asOfDate, setAsOfDate] = React.useState<string>(todayIso())
|
|
48
|
+
const [running, setRunning] = React.useState(false)
|
|
49
|
+
|
|
50
|
+
React.useEffect(() => {
|
|
51
|
+
if (open) {
|
|
52
|
+
setMode('test')
|
|
53
|
+
setAsOfDate(todayIso())
|
|
54
|
+
}
|
|
55
|
+
}, [open])
|
|
56
|
+
|
|
57
|
+
const handleRun = React.useCallback(async () => {
|
|
58
|
+
setRunning(true)
|
|
59
|
+
try {
|
|
60
|
+
const call = await apiCallOrThrow<{ billRunId: string | null }>('/api/billing/runs', {
|
|
61
|
+
method: 'POST',
|
|
62
|
+
headers: { 'Content-Type': 'application/json' },
|
|
63
|
+
body: JSON.stringify({ mode, asOfDate, scopedAccountIds: [accountId] }),
|
|
64
|
+
})
|
|
65
|
+
const billRunId = call.result?.billRunId
|
|
66
|
+
if (!billRunId) throw new Error(t('billing.runs.trigger.error', 'Failed to trigger run'))
|
|
67
|
+
const outcomes = await readApiResultOrThrow<{ items: OutcomeRow[] }>(
|
|
68
|
+
`/api/billing/run-outcomes?billRunId=${encodeURIComponent(billRunId)}&pageSize=1`,
|
|
69
|
+
)
|
|
70
|
+
const outcome = outcomes.items?.[0]
|
|
71
|
+
if (!outcome) {
|
|
72
|
+
flash(t('billing.accounts.run.nothing_due', 'Nothing is due up to this date — the next bill date is later.'), 'info')
|
|
73
|
+
} else if (outcome.status === 'failed') {
|
|
74
|
+
flash(`${t('billing.accounts.run.failed', 'Bill run failed')}: ${outcome.error_message ?? ''}`, 'error')
|
|
75
|
+
} else {
|
|
76
|
+
const cycles = (outcome.cycles ?? []).filter((cycle) => cycle.status !== 'empty').length
|
|
77
|
+
flash(`${t('billing.accounts.run.done', 'Bill run completed — bill dates with charges:')} ${cycles}`, 'success')
|
|
78
|
+
}
|
|
79
|
+
onCompleted(billRunId)
|
|
80
|
+
} catch (err) {
|
|
81
|
+
const { message } = normalizeCrudServerError(err)
|
|
82
|
+
flash(message || t('billing.runs.trigger.error', 'Failed to trigger run'), 'error')
|
|
83
|
+
} finally {
|
|
84
|
+
setRunning(false)
|
|
85
|
+
}
|
|
86
|
+
}, [accountId, asOfDate, mode, onCompleted, t])
|
|
87
|
+
|
|
88
|
+
const handleKeyDown = React.useCallback(
|
|
89
|
+
(event: React.KeyboardEvent<HTMLDivElement>) => {
|
|
90
|
+
if ((event.metaKey || event.ctrlKey) && event.key === 'Enter') {
|
|
91
|
+
event.preventDefault()
|
|
92
|
+
if (!running) void handleRun()
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
[handleRun, running],
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
return (
|
|
99
|
+
<Dialog open={open} onOpenChange={(next) => (!running ? onOpenChange(next) : undefined)}>
|
|
100
|
+
<DialogContent onKeyDown={handleKeyDown}>
|
|
101
|
+
<DialogHeader>
|
|
102
|
+
<DialogTitle>{t('billing.accounts.run.title', 'Run billing for this account')}</DialogTitle>
|
|
103
|
+
<DialogDescription>
|
|
104
|
+
{t(
|
|
105
|
+
'billing.accounts.run.description',
|
|
106
|
+
'Bills every due cycle of this account up to the as-of date. Test and dry runs change nothing on the account.',
|
|
107
|
+
)}
|
|
108
|
+
</DialogDescription>
|
|
109
|
+
</DialogHeader>
|
|
110
|
+
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2">
|
|
111
|
+
<label className="flex flex-col gap-1 text-sm">
|
|
112
|
+
<span className="text-muted-foreground">{t('billing.runs.trigger.dialog.mode', 'Mode')}</span>
|
|
113
|
+
<Select value={mode} onValueChange={(next) => setMode(next === 'real' || next === 'dry' ? next : 'test')}>
|
|
114
|
+
<SelectTrigger>
|
|
115
|
+
<SelectValue />
|
|
116
|
+
</SelectTrigger>
|
|
117
|
+
<SelectContent>
|
|
118
|
+
<SelectItem value="test">{t('billing.runs.trigger.dialog.mode.test', 'Test — drafts tagged for cleanup')}</SelectItem>
|
|
119
|
+
<SelectItem value="dry">{t('billing.runs.trigger.dialog.mode.dry', 'Dry-run — no rows written')}</SelectItem>
|
|
120
|
+
<SelectItem value="real">{t('billing.runs.trigger.dialog.mode.real', 'Real — create draft invoices')}</SelectItem>
|
|
121
|
+
</SelectContent>
|
|
122
|
+
</Select>
|
|
123
|
+
</label>
|
|
124
|
+
<label className="flex flex-col gap-1 text-sm">
|
|
125
|
+
<span className="text-muted-foreground">{t('billing.runs.trigger.dialog.as_of_date', 'As-of date')}</span>
|
|
126
|
+
<Input type="date" value={asOfDate} onChange={(event) => setAsOfDate(event.currentTarget.value)} />
|
|
127
|
+
</label>
|
|
128
|
+
</div>
|
|
129
|
+
<DialogFooter className="flex items-center justify-between gap-3 sm:justify-between">
|
|
130
|
+
<span className="text-xs text-muted-foreground">
|
|
131
|
+
<KbdShortcut keys={['Ctrl/⌘', 'Enter']} /> {t('billing.accounts.run.submit_hint', 'to run,')} <Kbd>Esc</Kbd>{' '}
|
|
132
|
+
{t('billing.accounts.run.close_hint', 'to close')}
|
|
133
|
+
</span>
|
|
134
|
+
<div className="flex items-center gap-2">
|
|
135
|
+
<Button type="button" variant="outline" onClick={() => onOpenChange(false)} disabled={running}>
|
|
136
|
+
{t('billing.common.cancel', 'Cancel')}
|
|
137
|
+
</Button>
|
|
138
|
+
<Button type="button" onClick={() => void handleRun()} disabled={running}>
|
|
139
|
+
<Play size={16} />
|
|
140
|
+
{running ? t('billing.accounts.run.running', 'Running…') : t('billing.accounts.run.action', 'Run billing')}
|
|
141
|
+
</Button>
|
|
142
|
+
</div>
|
|
143
|
+
</DialogFooter>
|
|
144
|
+
</DialogContent>
|
|
145
|
+
</Dialog>
|
|
146
|
+
)
|
|
147
|
+
}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
import * as React from 'react'
|
|
3
|
+
import Link from 'next/link'
|
|
4
|
+
import type { LegacyColumnDef as ColumnDef } from '@tanstack/react-table/legacy'
|
|
5
|
+
import { useT } from '@open-mercato/shared/lib/i18n/context'
|
|
6
|
+
import { BillingDataTable as DataTable } from '../BillingDataTable'
|
|
7
|
+
import { Tag } from '@open-mercato/ui/primitives/tag'
|
|
8
|
+
import { readApiResultOrThrow } from '@open-mercato/ui/backend/utils/apiCall'
|
|
9
|
+
import { RowActions } from '@open-mercato/ui/backend/RowActions'
|
|
10
|
+
import { useTestRunCleanup, type BillRunMode } from '../TestRunActions'
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Bill Runs tab of the account workspace (Spec E §4 / Spec F, F8): this
|
|
14
|
+
* account's run outcomes, newest first, from
|
|
15
|
+
* `GET /api/billing/run-outcomes?billAccountId=` (server-paginated).
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
type OutcomeCycle = {
|
|
19
|
+
bill_date: string
|
|
20
|
+
status: string
|
|
21
|
+
invoice_id: string | null
|
|
22
|
+
invoice_number?: string | null
|
|
23
|
+
statement_id?: string | null
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
type OutcomeRow = {
|
|
27
|
+
id: string
|
|
28
|
+
bill_run_id: string
|
|
29
|
+
run_mode: BillRunMode | null
|
|
30
|
+
run_as_of_date: string | null
|
|
31
|
+
status: string
|
|
32
|
+
error_message: string | null
|
|
33
|
+
draft_invoice_id: string | null
|
|
34
|
+
invoice_number: string | null
|
|
35
|
+
cycles: OutcomeCycle[] | null
|
|
36
|
+
created_at: string
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
type ListResponse = { items: OutcomeRow[]; total: number; totalPages: number }
|
|
40
|
+
|
|
41
|
+
const PAGE_SIZE = 20
|
|
42
|
+
|
|
43
|
+
function statusVariant(status: string): 'success' | 'warning' | 'error' | 'neutral' {
|
|
44
|
+
if (status === 'success') return 'success'
|
|
45
|
+
if (status === 'failed') return 'error'
|
|
46
|
+
if (status === 'success_with_warnings' || status.startsWith('skipped')) return 'warning'
|
|
47
|
+
return 'neutral'
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function AccountRunsTab({ accountId, refreshKey = 0 }: { accountId: string; refreshKey?: number }) {
|
|
51
|
+
const t = useT()
|
|
52
|
+
const [rows, setRows] = React.useState<OutcomeRow[]>([])
|
|
53
|
+
const [page, setPage] = React.useState(1)
|
|
54
|
+
const [total, setTotal] = React.useState(0)
|
|
55
|
+
const [totalPages, setTotalPages] = React.useState(1)
|
|
56
|
+
const [loading, setLoading] = React.useState(true)
|
|
57
|
+
const [error, setError] = React.useState<string | null>(null)
|
|
58
|
+
const cleanup = useTestRunCleanup()
|
|
59
|
+
|
|
60
|
+
const load = React.useCallback(async () => {
|
|
61
|
+
setLoading(true)
|
|
62
|
+
setError(null)
|
|
63
|
+
try {
|
|
64
|
+
const params = new URLSearchParams({
|
|
65
|
+
billAccountId: accountId,
|
|
66
|
+
page: String(page),
|
|
67
|
+
pageSize: String(PAGE_SIZE),
|
|
68
|
+
sortField: 'createdAt',
|
|
69
|
+
sortDir: 'desc',
|
|
70
|
+
})
|
|
71
|
+
const result = await readApiResultOrThrow<ListResponse>(`/api/billing/run-outcomes?${params.toString()}`)
|
|
72
|
+
setRows(result.items ?? [])
|
|
73
|
+
setTotal(result.total ?? 0)
|
|
74
|
+
setTotalPages(result.totalPages ?? 1)
|
|
75
|
+
} catch {
|
|
76
|
+
setError(t('billing.accounts.runs.error', 'Failed to load bill runs'))
|
|
77
|
+
} finally {
|
|
78
|
+
setLoading(false)
|
|
79
|
+
}
|
|
80
|
+
}, [accountId, page, t])
|
|
81
|
+
|
|
82
|
+
React.useEffect(() => {
|
|
83
|
+
void load()
|
|
84
|
+
}, [load, refreshKey])
|
|
85
|
+
|
|
86
|
+
const columns = React.useMemo<ColumnDef<OutcomeRow>[]>(
|
|
87
|
+
() => [
|
|
88
|
+
{
|
|
89
|
+
accessorKey: 'created_at',
|
|
90
|
+
header: t('billing.accounts.runs.columns.when', 'Run at'),
|
|
91
|
+
cell: ({ row }) => (
|
|
92
|
+
<Link href={`/backend/billing/runs/${row.original.bill_run_id}`} className="text-primary hover:underline">
|
|
93
|
+
{new Date(row.original.created_at).toLocaleString()}
|
|
94
|
+
</Link>
|
|
95
|
+
),
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
accessorKey: 'run_mode',
|
|
99
|
+
header: t('billing.runs.detail.field.mode', 'Mode'),
|
|
100
|
+
cell: ({ row }) =>
|
|
101
|
+
row.original.run_mode === 'dry' ? (
|
|
102
|
+
<Tag variant="warning">{t('billing.runs.mode.dry_run', 'Dry-run')}</Tag>
|
|
103
|
+
) : row.original.run_mode === 'test' ? (
|
|
104
|
+
<Tag variant="warning">{t('billing.runs.mode.test', 'Test')}</Tag>
|
|
105
|
+
) : (
|
|
106
|
+
<Tag variant="default">{t('billing.runs.mode.real', 'Real')}</Tag>
|
|
107
|
+
),
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
accessorKey: 'run_as_of_date',
|
|
111
|
+
header: t('billing.runs.columns.as_of_date', 'As-of date'),
|
|
112
|
+
cell: ({ row }) => row.original.run_as_of_date ?? '—',
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
accessorKey: 'status',
|
|
116
|
+
header: t('billing.runs.outcomes.columns.status', 'Status'),
|
|
117
|
+
cell: ({ row }) => <Tag variant={statusVariant(row.original.status)}>{row.original.status}</Tag>,
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
id: 'cycles',
|
|
121
|
+
header: t('billing.accounts.runs.columns.cycles', 'Bill dates'),
|
|
122
|
+
cell: ({ row }) => {
|
|
123
|
+
const cycles = row.original.cycles ?? []
|
|
124
|
+
if (cycles.length === 0) return '—'
|
|
125
|
+
return cycles.map((cycle) => cycle.bill_date).join(', ')
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
id: 'documents',
|
|
130
|
+
header: t('billing.accounts.runs.columns.documents', 'Documents'),
|
|
131
|
+
cell: ({ row }) => {
|
|
132
|
+
const cycles = row.original.cycles ?? []
|
|
133
|
+
const links = cycles.flatMap((cycle) =>
|
|
134
|
+
cycle.invoice_id
|
|
135
|
+
? [
|
|
136
|
+
<Link key={cycle.invoice_id} href={`/backend/billing/invoices/${cycle.invoice_id}`} className="text-primary hover:underline">
|
|
137
|
+
{cycle.invoice_number ?? cycle.invoice_id.slice(0, 8)}
|
|
138
|
+
</Link>,
|
|
139
|
+
]
|
|
140
|
+
: cycle.statement_id
|
|
141
|
+
? [
|
|
142
|
+
<Link key={cycle.statement_id} href={`/backend/billing/statements/${cycle.statement_id}`} className="text-primary hover:underline">
|
|
143
|
+
{t('billing.runs.cycles.statement', 'Statement')} {cycle.bill_date}
|
|
144
|
+
</Link>,
|
|
145
|
+
]
|
|
146
|
+
: [],
|
|
147
|
+
)
|
|
148
|
+
if (links.length === 0) return row.original.error_message ?? '—'
|
|
149
|
+
return <span className="flex flex-wrap gap-x-3 gap-y-1">{links}</span>
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
],
|
|
153
|
+
[t],
|
|
154
|
+
)
|
|
155
|
+
|
|
156
|
+
return (
|
|
157
|
+
<>
|
|
158
|
+
<DataTable
|
|
159
|
+
title={t('billing.accounts.tabs.runs', 'Bill runs')}
|
|
160
|
+
columns={columns}
|
|
161
|
+
data={rows}
|
|
162
|
+
isLoading={loading}
|
|
163
|
+
error={error}
|
|
164
|
+
pagination={{ page, pageSize: PAGE_SIZE, total, totalPages, onPageChange: setPage }}
|
|
165
|
+
emptyState={t('billing.accounts.runs.empty', 'No bill runs for this account yet.')}
|
|
166
|
+
rowActions={(row) => (
|
|
167
|
+
<RowActions
|
|
168
|
+
items={[
|
|
169
|
+
{ id: 'open', label: t('billing.runs.actions.open', 'Open'), href: `/backend/billing/runs/${row.bill_run_id}` },
|
|
170
|
+
...(row.run_mode === 'test'
|
|
171
|
+
? [
|
|
172
|
+
{
|
|
173
|
+
id: 'wipe',
|
|
174
|
+
label: t('billing.runs.wipe.action', 'Wipe test invoices'),
|
|
175
|
+
onSelect: async () => {
|
|
176
|
+
if ((await cleanup.wipe(row.bill_run_id)) !== null) void load()
|
|
177
|
+
},
|
|
178
|
+
},
|
|
179
|
+
]
|
|
180
|
+
: []),
|
|
181
|
+
...(row.run_mode === 'test' || row.run_mode === 'dry'
|
|
182
|
+
? [
|
|
183
|
+
{
|
|
184
|
+
id: 'delete',
|
|
185
|
+
label: t('billing.runs.delete.action', 'Delete run'),
|
|
186
|
+
destructive: true,
|
|
187
|
+
onSelect: async () => {
|
|
188
|
+
const removed = await cleanup.remove({ runId: row.bill_run_id, mode: row.run_mode ?? 'test' })
|
|
189
|
+
if (removed !== null) void load()
|
|
190
|
+
},
|
|
191
|
+
},
|
|
192
|
+
]
|
|
193
|
+
: []),
|
|
194
|
+
]}
|
|
195
|
+
/>
|
|
196
|
+
)}
|
|
197
|
+
/>
|
|
198
|
+
{cleanup.ConfirmDialogElement}
|
|
199
|
+
</>
|
|
200
|
+
)
|
|
201
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
import * as React from 'react'
|
|
3
|
+
import { useRouter } from 'next/navigation'
|
|
4
|
+
import type { LegacyColumnDef as ColumnDef } from '@tanstack/react-table/legacy'
|
|
5
|
+
import { useT } from '@open-mercato/shared/lib/i18n/context'
|
|
6
|
+
import { BillingDataTable as DataTable } from '../BillingDataTable'
|
|
7
|
+
import { readApiResultOrThrow } from '@open-mercato/ui/backend/utils/apiCall'
|
|
8
|
+
import { formatMoney } from '../InvoicesTable'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Statements tab of a prepaid account workspace (Spec E §4 / Spec F, F8):
|
|
12
|
+
* the account's consumption statements, newest period first
|
|
13
|
+
* (`GET /api/billing/statements?billAccountId=`, server-paginated).
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
type StatementRow = {
|
|
17
|
+
id: string
|
|
18
|
+
period_start: string
|
|
19
|
+
period_end: string
|
|
20
|
+
currency_code: string
|
|
21
|
+
opening_balance: string
|
|
22
|
+
total_topups: string
|
|
23
|
+
total_usage: string
|
|
24
|
+
total_recurring: string
|
|
25
|
+
closing_balance: string
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
type ListResponse = { items: StatementRow[]; total: number; totalPages: number }
|
|
29
|
+
|
|
30
|
+
const PAGE_SIZE = 20
|
|
31
|
+
|
|
32
|
+
function day(value: string): string {
|
|
33
|
+
return value ? value.slice(0, 10) : '—'
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function AccountStatementsTab({ accountId, refreshKey = 0 }: { accountId: string; refreshKey?: number }) {
|
|
37
|
+
const t = useT()
|
|
38
|
+
const router = useRouter()
|
|
39
|
+
const [rows, setRows] = React.useState<StatementRow[]>([])
|
|
40
|
+
const [page, setPage] = React.useState(1)
|
|
41
|
+
const [total, setTotal] = React.useState(0)
|
|
42
|
+
const [totalPages, setTotalPages] = React.useState(1)
|
|
43
|
+
const [loading, setLoading] = React.useState(true)
|
|
44
|
+
const [error, setError] = React.useState<string | null>(null)
|
|
45
|
+
|
|
46
|
+
const load = React.useCallback(async () => {
|
|
47
|
+
setLoading(true)
|
|
48
|
+
setError(null)
|
|
49
|
+
try {
|
|
50
|
+
const params = new URLSearchParams({
|
|
51
|
+
billAccountId: accountId,
|
|
52
|
+
page: String(page),
|
|
53
|
+
pageSize: String(PAGE_SIZE),
|
|
54
|
+
sortField: 'periodEnd',
|
|
55
|
+
sortDir: 'desc',
|
|
56
|
+
})
|
|
57
|
+
const result = await readApiResultOrThrow<ListResponse>(`/api/billing/statements?${params.toString()}`)
|
|
58
|
+
setRows(result.items ?? [])
|
|
59
|
+
setTotal(result.total ?? 0)
|
|
60
|
+
setTotalPages(result.totalPages ?? 1)
|
|
61
|
+
} catch {
|
|
62
|
+
setError(t('billing.accounts.statements.error', 'Failed to load statements'))
|
|
63
|
+
} finally {
|
|
64
|
+
setLoading(false)
|
|
65
|
+
}
|
|
66
|
+
}, [accountId, page, t])
|
|
67
|
+
|
|
68
|
+
React.useEffect(() => {
|
|
69
|
+
void load()
|
|
70
|
+
}, [load, refreshKey])
|
|
71
|
+
|
|
72
|
+
const columns = React.useMemo<ColumnDef<StatementRow>[]>(
|
|
73
|
+
() => [
|
|
74
|
+
{
|
|
75
|
+
accessorKey: 'period_start',
|
|
76
|
+
header: t('billing.statements.columns.period', 'Period'),
|
|
77
|
+
cell: ({ row }) => `${day(row.original.period_start)} – ${day(row.original.period_end)}`,
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
accessorKey: 'opening_balance',
|
|
81
|
+
header: t('billing.statements.columns.opening', 'Opening'),
|
|
82
|
+
cell: ({ row }) => formatMoney(row.original.opening_balance, row.original.currency_code),
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
accessorKey: 'total_topups',
|
|
86
|
+
header: t('billing.statements.columns.topups', 'Top-ups'),
|
|
87
|
+
cell: ({ row }) => formatMoney(row.original.total_topups, row.original.currency_code),
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
accessorKey: 'total_usage',
|
|
91
|
+
header: t('billing.statements.columns.usage', 'Usage'),
|
|
92
|
+
cell: ({ row }) => formatMoney(row.original.total_usage, row.original.currency_code),
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
accessorKey: 'total_recurring',
|
|
96
|
+
header: t('billing.statements.columns.charges', 'Charges'),
|
|
97
|
+
cell: ({ row }) => formatMoney(row.original.total_recurring, row.original.currency_code),
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
accessorKey: 'closing_balance',
|
|
101
|
+
header: t('billing.statements.columns.closing', 'Closing'),
|
|
102
|
+
cell: ({ row }) => formatMoney(row.original.closing_balance, row.original.currency_code),
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
[t],
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
return (
|
|
109
|
+
<DataTable
|
|
110
|
+
title={t('billing.accounts.tabs.statements', 'Statements')}
|
|
111
|
+
columns={columns}
|
|
112
|
+
data={rows}
|
|
113
|
+
isLoading={loading}
|
|
114
|
+
error={error}
|
|
115
|
+
onRowClick={(row) => router.push(`/backend/billing/statements/${row.id}`)}
|
|
116
|
+
pagination={{ page, pageSize: PAGE_SIZE, total, totalPages, onPageChange: setPage }}
|
|
117
|
+
emptyState={t('billing.accounts.statements.empty', 'No statements yet — they are written when a period closes.')}
|
|
118
|
+
/>
|
|
119
|
+
)
|
|
120
|
+
}
|