@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
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
import * as React from 'react'
|
|
3
|
+
import Link from 'next/link'
|
|
4
|
+
import { useT } from '@open-mercato/shared/lib/i18n/context'
|
|
5
|
+
import { Tag } from '@open-mercato/ui/primitives/tag'
|
|
6
|
+
import { readApiResultOrThrow } from '@open-mercato/ui/backend/utils/apiCall'
|
|
7
|
+
import { Stat, StatCard } from '../DetailFields'
|
|
8
|
+
import { formatMoney } from '../InvoicesTable'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Billing Account workspace header (Spec E §4 / Spec F, F8): what the
|
|
12
|
+
* operator needs at a glance, from ONE call to
|
|
13
|
+
* `GET /api/billing/accounts/{id}/summary`. Postpaid shows receivables;
|
|
14
|
+
* prepaid shows the balance. Informational — a failed load hides the cards.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export type AccountWorkspaceSummary = {
|
|
18
|
+
currency_code: string
|
|
19
|
+
open_amount: string
|
|
20
|
+
overdue_amount: string
|
|
21
|
+
overdue_count: number
|
|
22
|
+
credit_amount: string
|
|
23
|
+
billing_mode: 'postpaid' | 'prepaid'
|
|
24
|
+
bill_cycle: string
|
|
25
|
+
next_bill_date: string | null
|
|
26
|
+
last_invoice: { id: string; number: string; issue_date: string | null; total_gross: string } | null
|
|
27
|
+
prepaid: {
|
|
28
|
+
balance: string
|
|
29
|
+
balance_status: 'ok' | 'low' | 'exhausted'
|
|
30
|
+
credit_limit: string
|
|
31
|
+
last_statement: { id: string; period_start: string; period_end: string; closing_balance: string } | null
|
|
32
|
+
} | null
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function balanceVariant(status: 'ok' | 'low' | 'exhausted'): 'success' | 'warning' | 'error' {
|
|
36
|
+
if (status === 'exhausted') return 'error'
|
|
37
|
+
if (status === 'low') return 'warning'
|
|
38
|
+
return 'success'
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function AccountSummaryCards({ accountId, refreshKey = 0 }: { accountId: string; refreshKey?: number }) {
|
|
42
|
+
const t = useT()
|
|
43
|
+
const [summary, setSummary] = React.useState<AccountWorkspaceSummary | null>(null)
|
|
44
|
+
|
|
45
|
+
React.useEffect(() => {
|
|
46
|
+
let cancelled = false
|
|
47
|
+
readApiResultOrThrow<AccountWorkspaceSummary>(`/api/billing/accounts/${encodeURIComponent(accountId)}/summary`)
|
|
48
|
+
.then((result) => {
|
|
49
|
+
if (!cancelled) setSummary(result)
|
|
50
|
+
})
|
|
51
|
+
.catch(() => {
|
|
52
|
+
if (!cancelled) setSummary(null)
|
|
53
|
+
})
|
|
54
|
+
return () => {
|
|
55
|
+
cancelled = true
|
|
56
|
+
}
|
|
57
|
+
}, [accountId, refreshKey])
|
|
58
|
+
|
|
59
|
+
if (!summary) return null
|
|
60
|
+
const currency = summary.currency_code
|
|
61
|
+
const statusLabel = (status: 'ok' | 'low' | 'exhausted') =>
|
|
62
|
+
status === 'exhausted'
|
|
63
|
+
? t('billing.prepaid.status.exhausted', 'Exhausted')
|
|
64
|
+
: status === 'low'
|
|
65
|
+
? t('billing.prepaid.status.low', 'Low')
|
|
66
|
+
: t('billing.prepaid.status.ok', 'OK')
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<StatCard>
|
|
70
|
+
{summary.prepaid ? (
|
|
71
|
+
<>
|
|
72
|
+
<Stat
|
|
73
|
+
label={t('billing.accounts.summary.balance', 'Balance')}
|
|
74
|
+
value={
|
|
75
|
+
<span className="inline-flex items-center gap-2">
|
|
76
|
+
{formatMoney(summary.prepaid.balance, currency)}
|
|
77
|
+
<Tag variant={balanceVariant(summary.prepaid.balance_status)}>
|
|
78
|
+
{statusLabel(summary.prepaid.balance_status)}
|
|
79
|
+
</Tag>
|
|
80
|
+
</span>
|
|
81
|
+
}
|
|
82
|
+
/>
|
|
83
|
+
<Stat
|
|
84
|
+
label={t('billing.accounts.columns.credit_limit', 'Credit limit')}
|
|
85
|
+
value={formatMoney(summary.prepaid.credit_limit, currency)}
|
|
86
|
+
/>
|
|
87
|
+
</>
|
|
88
|
+
) : (
|
|
89
|
+
<>
|
|
90
|
+
<Stat
|
|
91
|
+
label={t('billing.accounts.summary.balance_due', 'Balance due')}
|
|
92
|
+
value={formatMoney(summary.open_amount, currency)}
|
|
93
|
+
/>
|
|
94
|
+
<Stat
|
|
95
|
+
label={t('billing.accounts.summary.overdue', 'Overdue')}
|
|
96
|
+
value={
|
|
97
|
+
<span className={Number(summary.overdue_amount) > 0 ? 'text-status-error-text' : undefined}>
|
|
98
|
+
{formatMoney(summary.overdue_amount, currency)} ({summary.overdue_count})
|
|
99
|
+
</span>
|
|
100
|
+
}
|
|
101
|
+
/>
|
|
102
|
+
<Stat
|
|
103
|
+
label={t('billing.accounts.summary.credit', 'Unapplied credit')}
|
|
104
|
+
value={formatMoney(summary.credit_amount, currency)}
|
|
105
|
+
/>
|
|
106
|
+
</>
|
|
107
|
+
)}
|
|
108
|
+
<Stat
|
|
109
|
+
label={t('billing.accounts.columns.next_bill', 'Next bill')}
|
|
110
|
+
value={
|
|
111
|
+
summary.next_bill_date ? (
|
|
112
|
+
<span>
|
|
113
|
+
{summary.next_bill_date}
|
|
114
|
+
<span className="ml-1 text-xs font-normal text-muted-foreground">· {summary.bill_cycle}</span>
|
|
115
|
+
</span>
|
|
116
|
+
) : (
|
|
117
|
+
'—'
|
|
118
|
+
)
|
|
119
|
+
}
|
|
120
|
+
/>
|
|
121
|
+
{summary.prepaid ? (
|
|
122
|
+
<Stat
|
|
123
|
+
label={t('billing.accounts.summary.last_statement', 'Last statement')}
|
|
124
|
+
value={
|
|
125
|
+
summary.prepaid.last_statement ? (
|
|
126
|
+
<Link
|
|
127
|
+
href={`/backend/billing/statements/${summary.prepaid.last_statement.id}`}
|
|
128
|
+
className="text-primary hover:underline"
|
|
129
|
+
>
|
|
130
|
+
{summary.prepaid.last_statement.period_start} – {summary.prepaid.last_statement.period_end}
|
|
131
|
+
</Link>
|
|
132
|
+
) : (
|
|
133
|
+
'—'
|
|
134
|
+
)
|
|
135
|
+
}
|
|
136
|
+
/>
|
|
137
|
+
) : (
|
|
138
|
+
<Stat
|
|
139
|
+
label={t('billing.accounts.summary.last_invoice', 'Last invoice')}
|
|
140
|
+
value={
|
|
141
|
+
summary.last_invoice ? (
|
|
142
|
+
<Link href={`/backend/billing/invoices/${summary.last_invoice.id}`} className="text-primary hover:underline">
|
|
143
|
+
{summary.last_invoice.number} · {formatMoney(summary.last_invoice.total_gross, currency)}
|
|
144
|
+
</Link>
|
|
145
|
+
) : (
|
|
146
|
+
'—'
|
|
147
|
+
)
|
|
148
|
+
}
|
|
149
|
+
/>
|
|
150
|
+
)}
|
|
151
|
+
</StatCard>
|
|
152
|
+
)
|
|
153
|
+
}
|