@dainamite/billing 0.20.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 +90 -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 +11 -7
- 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 +2 -2
- 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 +2 -2
- 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 +2 -2
- 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 +43 -6
- 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 +1 -1
- package/dist/modules/billing/api/runs/retry-failed/route.js.map +2 -2
- package/dist/modules/billing/api/runs/route.js +9 -3
- 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/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 +269 -167
- 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 +151 -4
- 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 +560 -4
- 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 +50 -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 +237 -102
- package/dist/modules/billing/lib/billRunEngine.js.map +2 -2
- 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/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/generated/entities/billing_account/index.ts +3 -0
- package/generated/entities/billing_allocation/index.ts +18 -0
- package/generated/entities/billing_document_sequence/index.ts +11 -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 +4 -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 +0 -1
- package/generated/entities/billing_run_outcome/index.ts +1 -0
- package/generated/entities/billing_settings/index.ts +26 -0
- package/generated/entities/billing_statement/index.ts +1 -0
- package/generated/entities.ids.generated.ts +7 -0
- package/package.json +5 -1
- 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 +436 -354
- 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 +8 -1
- 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 +228 -17
- 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 +13 -11
- 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 +2 -2
- package/src/modules/billing/api/invoices/delete-draft/route.ts +33 -0
- package/src/modules/billing/api/invoices/edit-line/route.ts +2 -2
- package/src/modules/billing/api/invoices/post/route.ts +7 -6
- package/src/modules/billing/api/invoices/remove-line/route.ts +2 -2
- 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 +49 -6
- 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 +2 -1
- package/src/modules/billing/api/runs/route.ts +15 -7
- 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 +70 -4
- package/src/modules/billing/backend/billing/invoices/[id]/page.tsx +444 -95
- 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 +18 -2
- 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 +49 -18
- package/src/modules/billing/backend/billing/runs/page.tsx +59 -8
- package/src/modules/billing/backend/billing/statements/[id]/page.tsx +86 -5
- package/src/modules/billing/backend/billing/statements/page.tsx +1 -1
- package/src/modules/billing/backend/billing/topups/page.tsx +1 -1
- package/src/modules/billing/backend/billing/transactions/page.tsx +1 -1
- 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/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 +364 -231
- 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 +205 -3
- 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 +19 -6
- 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 +654 -5
- package/src/modules/billing/data/entityIds.ts +9 -0
- package/src/modules/billing/data/validators.ts +388 -8
- package/src/modules/billing/events.ts +56 -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 +350 -150
- 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 +407 -239
- 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/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/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
|
@@ -4,11 +4,11 @@ import { useRouter } from 'next/navigation'
|
|
|
4
4
|
import { Plus, SlidersHorizontal } from 'lucide-react'
|
|
5
5
|
import type { LegacyColumnDef as ColumnDef } from '@tanstack/react-table/legacy'
|
|
6
6
|
import { useT } from '@open-mercato/shared/lib/i18n/context'
|
|
7
|
-
import { DataTable } from '
|
|
7
|
+
import { BillingDataTable as DataTable } from './BillingDataTable'
|
|
8
8
|
import { Tag } from '@open-mercato/ui/primitives/tag'
|
|
9
9
|
import { Button } from '@open-mercato/ui/primitives/button'
|
|
10
10
|
import { flash } from '@open-mercato/ui/backend/FlashMessages'
|
|
11
|
-
import { apiCallOrThrow, readApiResultOrThrow } from '@open-mercato/ui/backend/utils/apiCall'
|
|
11
|
+
import { apiCall, apiCallOrThrow, readApiResultOrThrow } from '@open-mercato/ui/backend/utils/apiCall'
|
|
12
12
|
import { normalizeCrudServerError } from '@open-mercato/ui/backend/utils/serverErrors'
|
|
13
13
|
import { StatCard, Stat } from './DetailFields'
|
|
14
14
|
|
|
@@ -89,6 +89,17 @@ export function PrepaidPanel({
|
|
|
89
89
|
const [adjAmount, setAdjAmount] = React.useState('')
|
|
90
90
|
const [adjReason, setAdjReason] = React.useState('')
|
|
91
91
|
const [adjSubmitting, setAdjSubmitting] = React.useState(false)
|
|
92
|
+
// Spec 0 (E-D1): online top-ups need the optional payment gateways module.
|
|
93
|
+
const [gatewayTopups, setGatewayTopups] = React.useState(false)
|
|
94
|
+
React.useEffect(() => {
|
|
95
|
+
let cancelled = false
|
|
96
|
+
void apiCall<{ capabilities?: { gatewayTopups?: boolean } }>('/api/billing/settings').then((call) => {
|
|
97
|
+
if (!cancelled) setGatewayTopups(call.ok && call.result?.capabilities?.gatewayTopups === true)
|
|
98
|
+
})
|
|
99
|
+
return () => {
|
|
100
|
+
cancelled = true
|
|
101
|
+
}
|
|
102
|
+
}, [])
|
|
92
103
|
const pageSize = 10
|
|
93
104
|
|
|
94
105
|
const loadStatus = React.useCallback(async () => {
|
|
@@ -286,10 +297,12 @@ export function PrepaidPanel({
|
|
|
286
297
|
<div className="flex flex-wrap items-center gap-2">
|
|
287
298
|
{!topupOpen && !adjustOpen ? (
|
|
288
299
|
<>
|
|
289
|
-
|
|
290
|
-
<
|
|
291
|
-
|
|
292
|
-
|
|
300
|
+
{gatewayTopups ? (
|
|
301
|
+
<Button type="button" onClick={() => setTopupOpen(true)}>
|
|
302
|
+
<Plus size={16} />
|
|
303
|
+
{t('billing.prepaid.topup.action', 'Top up')}
|
|
304
|
+
</Button>
|
|
305
|
+
) : null}
|
|
293
306
|
<Button type="button" variant="outline" onClick={() => setAdjustOpen(true)}>
|
|
294
307
|
<SlidersHorizontal size={16} />
|
|
295
308
|
{t('billing.prepaid.adjust.action', 'Adjust')}
|
|
@@ -0,0 +1,298 @@
|
|
|
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
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Spec A — per-bill-date breakdown of a Bill Run.
|
|
11
|
+
*
|
|
12
|
+
* Every run bills all due cycles, so one account outcome can stand for
|
|
13
|
+
* several invoices. These two tables flatten the outcomes currently shown
|
|
14
|
+
* on the run page into:
|
|
15
|
+
* - Cycles: one row per (account, bill date) with its status and invoice;
|
|
16
|
+
* - Skipped items: diagnostics such as partial periods not prorated.
|
|
17
|
+
* Both are paginated client-side over the already-loaded outcome page.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
export type RunCycle = {
|
|
21
|
+
bill_date: string
|
|
22
|
+
period_start: string | null
|
|
23
|
+
period_end: string | null
|
|
24
|
+
/** `charged` = prepaid charges debited from the balance (Spec F). */
|
|
25
|
+
status: 'invoiced' | 'charged' | 'previewed' | 'empty' | 'skipped_existing'
|
|
26
|
+
line_count: number
|
|
27
|
+
total_net: string
|
|
28
|
+
invoice_id: string | null
|
|
29
|
+
invoice_number?: string | null
|
|
30
|
+
/** Prepaid only: what left the balance, and the period's statement. */
|
|
31
|
+
total_debit?: string
|
|
32
|
+
statement_id?: string | null
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export type RunCycleOutcome = {
|
|
36
|
+
bill_account_id: string
|
|
37
|
+
bill_account_name: string | null
|
|
38
|
+
cycles?: RunCycle[] | null
|
|
39
|
+
warnings: Record<string, unknown> | null
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
type CycleRow = RunCycle & { key: string; accountId: string; accountName: string }
|
|
43
|
+
|
|
44
|
+
type SkippedRow = {
|
|
45
|
+
key: string
|
|
46
|
+
accountId: string
|
|
47
|
+
accountName: string
|
|
48
|
+
itemId: string
|
|
49
|
+
reason: string
|
|
50
|
+
periodStart: string | null
|
|
51
|
+
periodEnd: string | null
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const PAGE_SIZE = 50
|
|
55
|
+
|
|
56
|
+
function cycleVariant(status: RunCycle['status']): 'success' | 'info' | 'neutral' | 'warning' {
|
|
57
|
+
switch (status) {
|
|
58
|
+
case 'invoiced':
|
|
59
|
+
case 'charged':
|
|
60
|
+
return 'success'
|
|
61
|
+
case 'previewed':
|
|
62
|
+
return 'info'
|
|
63
|
+
case 'skipped_existing':
|
|
64
|
+
return 'warning'
|
|
65
|
+
default:
|
|
66
|
+
return 'neutral'
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function usePagedRows<T>(rows: T[]): { page: number; setPage: (page: number) => void; pageRows: T[]; totalPages: number } {
|
|
71
|
+
const [page, setPage] = React.useState(1)
|
|
72
|
+
const totalPages = Math.max(1, Math.ceil(rows.length / PAGE_SIZE))
|
|
73
|
+
const safePage = Math.min(page, totalPages)
|
|
74
|
+
const pageRows = React.useMemo(
|
|
75
|
+
() => rows.slice((safePage - 1) * PAGE_SIZE, safePage * PAGE_SIZE),
|
|
76
|
+
[rows, safePage],
|
|
77
|
+
)
|
|
78
|
+
return { page: safePage, setPage, pageRows, totalPages }
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function RunCyclesSection({ outcomes }: { outcomes: RunCycleOutcome[] }) {
|
|
82
|
+
const t = useT()
|
|
83
|
+
|
|
84
|
+
const cycleRows = React.useMemo<CycleRow[]>(
|
|
85
|
+
() =>
|
|
86
|
+
outcomes.flatMap((outcome) =>
|
|
87
|
+
(outcome.cycles ?? []).map((cycle) => ({
|
|
88
|
+
...cycle,
|
|
89
|
+
key: `${outcome.bill_account_id}:${cycle.bill_date}`,
|
|
90
|
+
accountId: outcome.bill_account_id,
|
|
91
|
+
accountName: outcome.bill_account_name ?? outcome.bill_account_id,
|
|
92
|
+
})),
|
|
93
|
+
),
|
|
94
|
+
[outcomes],
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
const skippedRows = React.useMemo<SkippedRow[]>(
|
|
98
|
+
() =>
|
|
99
|
+
outcomes.flatMap((outcome) => {
|
|
100
|
+
const skipped = (outcome.warnings?.skipped_items ?? []) as Array<Record<string, unknown>>
|
|
101
|
+
return skipped.map((entry, index) => ({
|
|
102
|
+
key: `${outcome.bill_account_id}:${index}`,
|
|
103
|
+
accountId: outcome.bill_account_id,
|
|
104
|
+
accountName: outcome.bill_account_name ?? outcome.bill_account_id,
|
|
105
|
+
itemId: String(entry.item_id ?? ''),
|
|
106
|
+
reason: String(entry.reason ?? ''),
|
|
107
|
+
periodStart: typeof entry.service_period_start === 'string' ? entry.service_period_start : null,
|
|
108
|
+
periodEnd: typeof entry.service_period_end === 'string' ? entry.service_period_end : null,
|
|
109
|
+
}))
|
|
110
|
+
}),
|
|
111
|
+
[outcomes],
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
const hasPrepaid = React.useMemo(() => cycleRows.some((row) => row.total_debit !== undefined), [cycleRows])
|
|
115
|
+
|
|
116
|
+
const statusLabel = React.useCallback(
|
|
117
|
+
(status: RunCycle['status']) => {
|
|
118
|
+
switch (status) {
|
|
119
|
+
case 'invoiced':
|
|
120
|
+
return t('billing.runs.cycles.status.invoiced', 'Invoiced')
|
|
121
|
+
case 'charged':
|
|
122
|
+
return t('billing.runs.cycles.status.charged', 'Charged to balance')
|
|
123
|
+
case 'previewed':
|
|
124
|
+
return t('billing.runs.cycles.status.previewed', 'Preview')
|
|
125
|
+
case 'skipped_existing':
|
|
126
|
+
return t('billing.runs.cycles.status.skipped_existing', 'Skipped — already billed')
|
|
127
|
+
default:
|
|
128
|
+
return t('billing.runs.cycles.status.empty', 'Nothing to bill')
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
[t],
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
const reasonLabel = React.useCallback(
|
|
135
|
+
(reason: string) => {
|
|
136
|
+
switch (reason) {
|
|
137
|
+
case 'partial-period-not-prorated':
|
|
138
|
+
return t('billing.runs.skipped.reason.partial_not_prorated', 'Partial period, proration off')
|
|
139
|
+
case 'ended-after-billing-no-credit':
|
|
140
|
+
return t('billing.runs.skipped.reason.ended_no_credit', 'Ended after billing, proration off — no credit')
|
|
141
|
+
case 'period-cap-reached':
|
|
142
|
+
return t('billing.runs.skipped.reason.period_cap', 'Too many periods for one bill date')
|
|
143
|
+
default:
|
|
144
|
+
return reason
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
[t],
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
const cycleColumns = React.useMemo<ColumnDef<CycleRow>[]>(
|
|
151
|
+
() => [
|
|
152
|
+
{
|
|
153
|
+
accessorKey: 'accountName',
|
|
154
|
+
header: t('billing.runs.outcomes.columns.account', 'Account'),
|
|
155
|
+
cell: ({ row }) => (
|
|
156
|
+
<Link href={`/backend/billing/accounts/${row.original.accountId}`} className="text-sm text-primary hover:underline">
|
|
157
|
+
{row.original.accountName}
|
|
158
|
+
</Link>
|
|
159
|
+
),
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
accessorKey: 'bill_date',
|
|
163
|
+
header: t('billing.runs.cycles.columns.bill_date', 'Bill date'),
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
accessorKey: 'period_start',
|
|
167
|
+
header: t('billing.runs.cycles.columns.service_period', 'Service period'),
|
|
168
|
+
cell: ({ row }) =>
|
|
169
|
+
row.original.period_start && row.original.period_end
|
|
170
|
+
? `${row.original.period_start} – ${row.original.period_end}`
|
|
171
|
+
: '—',
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
accessorKey: 'status',
|
|
175
|
+
header: t('billing.runs.outcomes.columns.status', 'Status'),
|
|
176
|
+
cell: ({ row }) => <Tag variant={cycleVariant(row.original.status)}>{statusLabel(row.original.status)}</Tag>,
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
accessorKey: 'line_count',
|
|
180
|
+
header: t('billing.runs.cycles.columns.lines', 'Lines'),
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
accessorKey: 'total_net',
|
|
184
|
+
header: t('billing.runs.cycles.columns.total_net', 'Net total'),
|
|
185
|
+
cell: ({ row }) => <span className="font-mono tabular-nums">{row.original.total_net}</span>,
|
|
186
|
+
},
|
|
187
|
+
...(hasPrepaid
|
|
188
|
+
? [
|
|
189
|
+
{
|
|
190
|
+
accessorKey: 'total_debit',
|
|
191
|
+
header: t('billing.runs.cycles.columns.total_debit', 'Charged to balance'),
|
|
192
|
+
cell: ({ row }: { row: { original: CycleRow } }) =>
|
|
193
|
+
row.original.total_debit !== undefined ? (
|
|
194
|
+
<span className="font-mono tabular-nums">{row.original.total_debit}</span>
|
|
195
|
+
) : (
|
|
196
|
+
'—'
|
|
197
|
+
),
|
|
198
|
+
} satisfies ColumnDef<CycleRow>,
|
|
199
|
+
]
|
|
200
|
+
: []),
|
|
201
|
+
{
|
|
202
|
+
accessorKey: 'invoice_id',
|
|
203
|
+
header: t('billing.runs.cycles.columns.document', 'Document'),
|
|
204
|
+
cell: ({ row }) =>
|
|
205
|
+
row.original.invoice_id ? (
|
|
206
|
+
<Link href={`/backend/billing/invoices/${row.original.invoice_id}`} className="text-sm text-primary hover:underline">
|
|
207
|
+
{row.original.invoice_number ?? row.original.invoice_id}
|
|
208
|
+
</Link>
|
|
209
|
+
) : row.original.statement_id ? (
|
|
210
|
+
<Link href={`/backend/billing/statements/${row.original.statement_id}`} className="text-sm text-primary hover:underline">
|
|
211
|
+
{t('billing.runs.cycles.statement', 'Statement')}
|
|
212
|
+
</Link>
|
|
213
|
+
) : (
|
|
214
|
+
'—'
|
|
215
|
+
),
|
|
216
|
+
},
|
|
217
|
+
],
|
|
218
|
+
[hasPrepaid, statusLabel, t],
|
|
219
|
+
)
|
|
220
|
+
|
|
221
|
+
const skippedColumns = React.useMemo<ColumnDef<SkippedRow>[]>(
|
|
222
|
+
() => [
|
|
223
|
+
{
|
|
224
|
+
accessorKey: 'accountName',
|
|
225
|
+
header: t('billing.runs.outcomes.columns.account', 'Account'),
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
accessorKey: 'itemId',
|
|
229
|
+
header: t('billing.runs.skipped.columns.item', 'Item'),
|
|
230
|
+
cell: ({ row }) => (
|
|
231
|
+
<Link href={`/backend/billing/items/${row.original.itemId}`} className="text-sm text-primary hover:underline">
|
|
232
|
+
{row.original.itemId}
|
|
233
|
+
</Link>
|
|
234
|
+
),
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
accessorKey: 'reason',
|
|
238
|
+
header: t('billing.runs.skipped.columns.reason', 'Reason'),
|
|
239
|
+
cell: ({ row }) => reasonLabel(row.original.reason),
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
accessorKey: 'periodStart',
|
|
243
|
+
header: t('billing.runs.cycles.columns.service_period', 'Service period'),
|
|
244
|
+
cell: ({ row }) =>
|
|
245
|
+
row.original.periodStart ? `${row.original.periodStart} – ${row.original.periodEnd ?? '…'}` : '—',
|
|
246
|
+
},
|
|
247
|
+
],
|
|
248
|
+
[reasonLabel, t],
|
|
249
|
+
)
|
|
250
|
+
|
|
251
|
+
const cyclesPaging = usePagedRows(cycleRows)
|
|
252
|
+
const skippedPaging = usePagedRows(skippedRows)
|
|
253
|
+
|
|
254
|
+
if (cycleRows.length === 0 && skippedRows.length === 0) return null
|
|
255
|
+
|
|
256
|
+
return (
|
|
257
|
+
<>
|
|
258
|
+
{cycleRows.length > 0 ? (
|
|
259
|
+
<div>
|
|
260
|
+
<h2 className="text-base font-semibold mb-1">{t('billing.runs.cycles.title', 'Cycles')}</h2>
|
|
261
|
+
<p className="text-sm text-muted-foreground mb-2">
|
|
262
|
+
{t(
|
|
263
|
+
'billing.runs.cycles.help',
|
|
264
|
+
'One row per account and bill date — a run bills every due cycle up to its as-of date.',
|
|
265
|
+
)}
|
|
266
|
+
</p>
|
|
267
|
+
<DataTable
|
|
268
|
+
columns={cycleColumns}
|
|
269
|
+
data={cyclesPaging.pageRows}
|
|
270
|
+
pagination={{
|
|
271
|
+
page: cyclesPaging.page,
|
|
272
|
+
pageSize: PAGE_SIZE,
|
|
273
|
+
total: cycleRows.length,
|
|
274
|
+
totalPages: cyclesPaging.totalPages,
|
|
275
|
+
onPageChange: cyclesPaging.setPage,
|
|
276
|
+
}}
|
|
277
|
+
/>
|
|
278
|
+
</div>
|
|
279
|
+
) : null}
|
|
280
|
+
{skippedRows.length > 0 ? (
|
|
281
|
+
<div>
|
|
282
|
+
<h2 className="text-base font-semibold mb-2">{t('billing.runs.skipped.title', 'Skipped items')}</h2>
|
|
283
|
+
<DataTable
|
|
284
|
+
columns={skippedColumns}
|
|
285
|
+
data={skippedPaging.pageRows}
|
|
286
|
+
pagination={{
|
|
287
|
+
page: skippedPaging.page,
|
|
288
|
+
pageSize: PAGE_SIZE,
|
|
289
|
+
total: skippedRows.length,
|
|
290
|
+
totalPages: skippedPaging.totalPages,
|
|
291
|
+
onPageChange: skippedPaging.setPage,
|
|
292
|
+
}}
|
|
293
|
+
/>
|
|
294
|
+
</div>
|
|
295
|
+
) : null}
|
|
296
|
+
</>
|
|
297
|
+
)
|
|
298
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
import * as React from 'react'
|
|
3
|
+
import { Eraser, Trash2 } from 'lucide-react'
|
|
4
|
+
import { useT } from '@open-mercato/shared/lib/i18n/context'
|
|
5
|
+
import { Button } from '@open-mercato/ui/primitives/button'
|
|
6
|
+
import { flash } from '@open-mercato/ui/backend/FlashMessages'
|
|
7
|
+
import { useConfirmDialog } from '@open-mercato/ui/backend/confirm-dialog'
|
|
8
|
+
import { apiCallOrThrow } from '@open-mercato/ui/backend/utils/apiCall'
|
|
9
|
+
import { normalizeCrudServerError } from '@open-mercato/ui/backend/utils/serverErrors'
|
|
10
|
+
|
|
11
|
+
export type BillRunMode = 'real' | 'test' | 'dry'
|
|
12
|
+
|
|
13
|
+
export function billRunMode(run: { dry_run?: boolean | null; test_mode?: boolean | null }): BillRunMode {
|
|
14
|
+
if (run.dry_run) return 'dry'
|
|
15
|
+
if (run.test_mode) return 'test'
|
|
16
|
+
return 'real'
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type TestRunActionsProps = {
|
|
20
|
+
runId: string
|
|
21
|
+
mode: BillRunMode
|
|
22
|
+
/** Test drafts the run wrote (from the run summary), for the confirm text. */
|
|
23
|
+
draftsCount?: number
|
|
24
|
+
onWiped?: (invoicesRemoved: number) => void
|
|
25
|
+
onDeleted?: (invoicesRemoved: number) => void
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Confirm-then-call cleanup flows for a test / dry Bill Run (Spec F, F1),
|
|
30
|
+
* shared by the run detail page, the runs list row action and the account
|
|
31
|
+
* "Run billing" dialog. Each call resolves to the removed invoice count, or
|
|
32
|
+
* `null` when the operator cancelled or the call failed (already flashed).
|
|
33
|
+
*/
|
|
34
|
+
export function useTestRunCleanup() {
|
|
35
|
+
const t = useT()
|
|
36
|
+
const { confirm, ConfirmDialogElement } = useConfirmDialog()
|
|
37
|
+
const [busy, setBusy] = React.useState<'wipe' | 'delete' | null>(null)
|
|
38
|
+
|
|
39
|
+
const wipe = React.useCallback(
|
|
40
|
+
async (runId: string): Promise<number | null> => {
|
|
41
|
+
const ok = await confirm({
|
|
42
|
+
title: t('billing.runs.wipe.confirm.title', 'Wipe test invoices?'),
|
|
43
|
+
text: t(
|
|
44
|
+
'billing.runs.wipe.confirm.text',
|
|
45
|
+
'Every test invoice from this Bill Run will be permanently deleted. The run itself stays. This cannot be undone.',
|
|
46
|
+
),
|
|
47
|
+
confirmText: t('billing.runs.wipe.confirm.button', 'Delete test invoices'),
|
|
48
|
+
variant: 'destructive',
|
|
49
|
+
})
|
|
50
|
+
if (!ok) return null
|
|
51
|
+
setBusy('wipe')
|
|
52
|
+
try {
|
|
53
|
+
const call = await apiCallOrThrow<{ invoicesRemoved: number }>('/api/billing/test-invoices/wipe', {
|
|
54
|
+
method: 'POST',
|
|
55
|
+
headers: { 'Content-Type': 'application/json' },
|
|
56
|
+
body: JSON.stringify({ billRunId: runId }),
|
|
57
|
+
})
|
|
58
|
+
const removed = call.result?.invoicesRemoved ?? 0
|
|
59
|
+
flash(`${t('billing.runs.wipe.success', 'Test invoices removed')} (${removed})`, 'success')
|
|
60
|
+
return removed
|
|
61
|
+
} catch (err) {
|
|
62
|
+
const { message } = normalizeCrudServerError(err)
|
|
63
|
+
flash(message || t('billing.runs.wipe.error', 'Wipe failed'), 'error')
|
|
64
|
+
return null
|
|
65
|
+
} finally {
|
|
66
|
+
setBusy(null)
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
[confirm, t],
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
const remove = React.useCallback(
|
|
73
|
+
async (params: { runId: string; mode: BillRunMode; draftsCount?: number }): Promise<number | null> => {
|
|
74
|
+
const text =
|
|
75
|
+
params.mode === 'test' && typeof params.draftsCount === 'number' && params.draftsCount > 0
|
|
76
|
+
? `${t('billing.runs.delete.confirm.text_with_invoices', 'The run, its results and its test invoices will be permanently deleted. Test invoices:')} ${params.draftsCount}`
|
|
77
|
+
: t('billing.runs.delete.confirm.text', 'The run and its results will be permanently deleted.')
|
|
78
|
+
const ok = await confirm({
|
|
79
|
+
title: t('billing.runs.delete.confirm.title', 'Delete this run?'),
|
|
80
|
+
text,
|
|
81
|
+
confirmText: t('billing.runs.delete.confirm.button', 'Delete run'),
|
|
82
|
+
variant: 'destructive',
|
|
83
|
+
})
|
|
84
|
+
if (!ok) return null
|
|
85
|
+
setBusy('delete')
|
|
86
|
+
try {
|
|
87
|
+
const call = await apiCallOrThrow<{ invoicesRemoved: number }>(
|
|
88
|
+
`/api/billing/runs/${encodeURIComponent(params.runId)}`,
|
|
89
|
+
{ method: 'DELETE' },
|
|
90
|
+
)
|
|
91
|
+
flash(t('billing.runs.delete.success', 'Run deleted'), 'success')
|
|
92
|
+
return call.result?.invoicesRemoved ?? 0
|
|
93
|
+
} catch (err) {
|
|
94
|
+
const { message } = normalizeCrudServerError(err)
|
|
95
|
+
flash(message || t('billing.runs.delete.error', 'Delete failed'), 'error')
|
|
96
|
+
return null
|
|
97
|
+
} finally {
|
|
98
|
+
setBusy(null)
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
[confirm, t],
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
return { wipe, remove, busy, ConfirmDialogElement }
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Cleanup buttons for a test / dry Bill Run: "Wipe test invoices" keeps the
|
|
109
|
+
* run, "Delete run" removes it with its test invoices. Renders nothing for
|
|
110
|
+
* real runs (they are never deleted).
|
|
111
|
+
*/
|
|
112
|
+
export function TestRunActions({ runId, mode, draftsCount, onWiped, onDeleted }: TestRunActionsProps) {
|
|
113
|
+
const t = useT()
|
|
114
|
+
const { wipe, remove, busy, ConfirmDialogElement } = useTestRunCleanup()
|
|
115
|
+
|
|
116
|
+
if (mode === 'real') return null
|
|
117
|
+
return (
|
|
118
|
+
<>
|
|
119
|
+
{mode === 'test' ? (
|
|
120
|
+
<Button
|
|
121
|
+
type="button"
|
|
122
|
+
variant="outline"
|
|
123
|
+
disabled={busy !== null}
|
|
124
|
+
onClick={async () => {
|
|
125
|
+
const removed = await wipe(runId)
|
|
126
|
+
if (removed !== null) onWiped?.(removed)
|
|
127
|
+
}}
|
|
128
|
+
>
|
|
129
|
+
<Eraser size={16} />
|
|
130
|
+
{busy === 'wipe'
|
|
131
|
+
? t('billing.runs.wipe.in_progress', 'Wiping…')
|
|
132
|
+
: t('billing.runs.wipe.action', 'Wipe test invoices')}
|
|
133
|
+
</Button>
|
|
134
|
+
) : null}
|
|
135
|
+
<Button
|
|
136
|
+
type="button"
|
|
137
|
+
variant="destructive"
|
|
138
|
+
disabled={busy !== null}
|
|
139
|
+
onClick={async () => {
|
|
140
|
+
const removed = await remove({ runId, mode, draftsCount })
|
|
141
|
+
if (removed !== null) onDeleted?.(removed)
|
|
142
|
+
}}
|
|
143
|
+
>
|
|
144
|
+
<Trash2 size={16} />
|
|
145
|
+
{busy === 'delete'
|
|
146
|
+
? t('billing.runs.delete.in_progress', 'Deleting…')
|
|
147
|
+
: t('billing.runs.delete.action', 'Delete run')}
|
|
148
|
+
</Button>
|
|
149
|
+
{ConfirmDialogElement}
|
|
150
|
+
</>
|
|
151
|
+
)
|
|
152
|
+
}
|
|
@@ -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
|
+
}
|