@dainamite/billing 0.19.0 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +172 -0
- package/README.md +14 -0
- package/dist/modules/billing/acl.js +13 -1
- package/dist/modules/billing/acl.js.map +2 -2
- package/dist/modules/billing/api/accounts/[id]/summary/route.js +52 -0
- package/dist/modules/billing/api/accounts/[id]/summary/route.js.map +7 -0
- package/dist/modules/billing/api/accounts/route.js +46 -4
- package/dist/modules/billing/api/accounts/route.js.map +2 -2
- package/dist/modules/billing/api/export/account/[id]/route.js +16 -12
- package/dist/modules/billing/api/export/account/[id]/route.js.map +2 -2
- package/dist/modules/billing/api/invoices/[id]/memos/route.js +54 -0
- package/dist/modules/billing/api/invoices/[id]/memos/route.js.map +7 -0
- package/dist/modules/billing/api/invoices/[id]/pdf/route.js +69 -0
- package/dist/modules/billing/api/invoices/[id]/pdf/route.js.map +7 -0
- package/dist/modules/billing/api/invoices/[id]/route.js +44 -24
- package/dist/modules/billing/api/invoices/[id]/route.js.map +2 -2
- package/dist/modules/billing/api/invoices/[id]/send/route.js +107 -0
- package/dist/modules/billing/api/invoices/[id]/send/route.js.map +7 -0
- package/dist/modules/billing/api/invoices/add-line/route.js +3 -3
- package/dist/modules/billing/api/invoices/add-line/route.js.map +2 -2
- package/dist/modules/billing/api/invoices/delete-draft/route.js +33 -0
- package/dist/modules/billing/api/invoices/delete-draft/route.js.map +7 -0
- package/dist/modules/billing/api/invoices/edit-line/route.js +3 -3
- package/dist/modules/billing/api/invoices/edit-line/route.js.map +2 -2
- package/dist/modules/billing/api/invoices/post/route.js +2 -2
- package/dist/modules/billing/api/invoices/post/route.js.map +2 -2
- package/dist/modules/billing/api/invoices/remove-line/route.js +3 -3
- package/dist/modules/billing/api/invoices/remove-line/route.js.map +2 -2
- package/dist/modules/billing/api/invoices/route.js +45 -46
- package/dist/modules/billing/api/invoices/route.js.map +2 -2
- package/dist/modules/billing/api/items/bulk/route.js +1 -1
- package/dist/modules/billing/api/items/bulk/route.js.map +2 -2
- package/dist/modules/billing/api/items/change-price/route.js +44 -0
- package/dist/modules/billing/api/items/change-price/route.js.map +7 -0
- package/dist/modules/billing/api/items/route.js +19 -7
- package/dist/modules/billing/api/items/route.js.map +2 -2
- package/dist/modules/billing/api/payment-imports/[id]/route.js +49 -0
- package/dist/modules/billing/api/payment-imports/[id]/route.js.map +7 -0
- package/dist/modules/billing/api/payment-imports/route.js +57 -0
- package/dist/modules/billing/api/payment-imports/route.js.map +7 -0
- package/dist/modules/billing/api/payments/[id]/route.js +60 -0
- package/dist/modules/billing/api/payments/[id]/route.js.map +7 -0
- package/dist/modules/billing/api/payments/allocate/route.js +35 -0
- package/dist/modules/billing/api/payments/allocate/route.js.map +7 -0
- package/dist/modules/billing/api/payments/assign/route.js +36 -0
- package/dist/modules/billing/api/payments/assign/route.js.map +7 -0
- package/dist/modules/billing/api/payments/convert-to-topup/route.js +35 -0
- package/dist/modules/billing/api/payments/convert-to-topup/route.js.map +7 -0
- package/dist/modules/billing/api/payments/ignore/route.js +35 -0
- package/dist/modules/billing/api/payments/ignore/route.js.map +7 -0
- package/dist/modules/billing/api/payments/import/route.js +63 -0
- package/dist/modules/billing/api/payments/import/route.js.map +7 -0
- package/dist/modules/billing/api/payments/restore/route.js +35 -0
- package/dist/modules/billing/api/payments/restore/route.js.map +7 -0
- package/dist/modules/billing/api/payments/route.js +114 -0
- package/dist/modules/billing/api/payments/route.js.map +7 -0
- package/dist/modules/billing/api/payments/unallocate/route.js +35 -0
- package/dist/modules/billing/api/payments/unallocate/route.js.map +7 -0
- package/dist/modules/billing/api/payments/unassign/route.js +35 -0
- package/dist/modules/billing/api/payments/unassign/route.js.map +7 -0
- package/dist/modules/billing/api/run-outcomes/route.js +44 -7
- package/dist/modules/billing/api/run-outcomes/route.js.map +2 -2
- package/dist/modules/billing/api/runs/[id]/post-drafts/route.js +61 -0
- package/dist/modules/billing/api/runs/[id]/post-drafts/route.js.map +7 -0
- package/dist/modules/billing/api/runs/[id]/route.js +53 -0
- package/dist/modules/billing/api/runs/[id]/route.js.map +7 -0
- package/dist/modules/billing/api/runs/retry-failed/route.js +3 -3
- package/dist/modules/billing/api/runs/retry-failed/route.js.map +2 -2
- package/dist/modules/billing/api/runs/route.js +11 -5
- package/dist/modules/billing/api/runs/route.js.map +2 -2
- package/dist/modules/billing/api/settings/number-preview/route.js +42 -0
- package/dist/modules/billing/api/settings/number-preview/route.js.map +7 -0
- package/dist/modules/billing/api/settings/route.js +92 -0
- package/dist/modules/billing/api/settings/route.js.map +7 -0
- package/dist/modules/billing/api/statements/route.js +3 -0
- package/dist/modules/billing/api/statements/route.js.map +2 -2
- package/dist/modules/billing/api/test-invoices/wipe/route.js +2 -2
- package/dist/modules/billing/api/test-invoices/wipe/route.js.map +2 -2
- package/dist/modules/billing/backend/billing/accounts/[id]/page.js +121 -232
- package/dist/modules/billing/backend/billing/accounts/[id]/page.js.map +2 -2
- package/dist/modules/billing/backend/billing/accounts/create/page.js +6 -0
- package/dist/modules/billing/backend/billing/accounts/create/page.js.map +2 -2
- package/dist/modules/billing/backend/billing/accounts/page.js +63 -4
- package/dist/modules/billing/backend/billing/accounts/page.js.map +2 -2
- package/dist/modules/billing/backend/billing/invoices/[id]/page.js +297 -65
- package/dist/modules/billing/backend/billing/invoices/[id]/page.js.map +3 -3
- package/dist/modules/billing/backend/billing/invoices/page.js +6 -172
- package/dist/modules/billing/backend/billing/invoices/page.js.map +2 -2
- package/dist/modules/billing/backend/billing/items/[id]/page.js +51 -7
- package/dist/modules/billing/backend/billing/items/[id]/page.js.map +2 -2
- package/dist/modules/billing/backend/billing/items/create/page.js +9 -6
- package/dist/modules/billing/backend/billing/items/create/page.js.map +2 -2
- package/dist/modules/billing/backend/billing/items/page.js +8 -2
- package/dist/modules/billing/backend/billing/items/page.js.map +2 -2
- package/dist/modules/billing/backend/billing/payments/[id]/page.js +297 -0
- package/dist/modules/billing/backend/billing/payments/[id]/page.js.map +7 -0
- package/dist/modules/billing/backend/billing/payments/[id]/page.meta.js +21 -0
- package/dist/modules/billing/backend/billing/payments/[id]/page.meta.js.map +7 -0
- package/dist/modules/billing/backend/billing/payments/imports/[id]/page.js +74 -0
- package/dist/modules/billing/backend/billing/payments/imports/[id]/page.js.map +7 -0
- package/dist/modules/billing/backend/billing/payments/imports/[id]/page.meta.js +21 -0
- package/dist/modules/billing/backend/billing/payments/imports/[id]/page.meta.js.map +7 -0
- package/dist/modules/billing/backend/billing/payments/page.js +58 -0
- package/dist/modules/billing/backend/billing/payments/page.js.map +7 -0
- package/dist/modules/billing/backend/billing/payments/page.meta.js +18 -0
- package/dist/modules/billing/backend/billing/payments/page.meta.js.map +7 -0
- package/dist/modules/billing/backend/billing/runs/[id]/page.js +49 -14
- package/dist/modules/billing/backend/billing/runs/[id]/page.js.map +2 -2
- package/dist/modules/billing/backend/billing/runs/page.js +58 -7
- package/dist/modules/billing/backend/billing/runs/page.js.map +2 -2
- package/dist/modules/billing/backend/billing/statements/[id]/page.js +61 -6
- package/dist/modules/billing/backend/billing/statements/[id]/page.js.map +2 -2
- package/dist/modules/billing/backend/billing/statements/page.js +1 -1
- package/dist/modules/billing/backend/billing/statements/page.js.map +2 -2
- package/dist/modules/billing/backend/billing/topups/page.js +1 -1
- package/dist/modules/billing/backend/billing/topups/page.js.map +2 -2
- package/dist/modules/billing/backend/billing/transactions/page.js +1 -1
- package/dist/modules/billing/backend/billing/transactions/page.js.map +2 -2
- package/dist/modules/billing/backend/billing/usage/create/page.js +3 -2
- package/dist/modules/billing/backend/billing/usage/create/page.js.map +2 -2
- package/dist/modules/billing/backend/config/billing/page.js +472 -0
- package/dist/modules/billing/backend/config/billing/page.js.map +7 -0
- package/dist/modules/billing/backend/config/billing/page.meta.js +19 -0
- package/dist/modules/billing/backend/config/billing/page.meta.js.map +7 -0
- package/dist/modules/billing/ce.js.map +2 -2
- package/dist/modules/billing/cli.js +22 -1
- package/dist/modules/billing/cli.js.map +2 -2
- package/dist/modules/billing/commands/accounts.js +6 -0
- package/dist/modules/billing/commands/accounts.js.map +2 -2
- package/dist/modules/billing/commands/index.js +3 -0
- package/dist/modules/billing/commands/index.js.map +2 -2
- package/dist/modules/billing/commands/invoices.js +272 -170
- package/dist/modules/billing/commands/invoices.js.map +2 -2
- package/dist/modules/billing/commands/items.js +108 -0
- package/dist/modules/billing/commands/items.js.map +2 -2
- package/dist/modules/billing/commands/memos.js +179 -0
- package/dist/modules/billing/commands/memos.js.map +7 -0
- package/dist/modules/billing/commands/payments.js +379 -0
- package/dist/modules/billing/commands/payments.js.map +7 -0
- package/dist/modules/billing/commands/runs.js +154 -7
- package/dist/modules/billing/commands/runs.js.map +2 -2
- package/dist/modules/billing/commands/settings.js +59 -0
- package/dist/modules/billing/commands/settings.js.map +7 -0
- package/dist/modules/billing/commands/topups.js +9 -2
- package/dist/modules/billing/commands/topups.js.map +2 -2
- package/dist/modules/billing/commands/transactions.js +2 -2
- package/dist/modules/billing/commands/transactions.js.map +2 -2
- package/dist/modules/billing/components/AccountForm.js +149 -42
- package/dist/modules/billing/components/AccountForm.js.map +2 -2
- package/dist/modules/billing/components/AccountInvoicesSection.js +64 -0
- package/dist/modules/billing/components/AccountInvoicesSection.js.map +7 -0
- package/dist/modules/billing/components/AccountPaymentsSection.js +43 -0
- package/dist/modules/billing/components/AccountPaymentsSection.js.map +7 -0
- package/dist/modules/billing/components/AccountPicker.js +56 -0
- package/dist/modules/billing/components/AccountPicker.js.map +7 -0
- package/dist/modules/billing/components/AllocatePaymentDialog.js +134 -0
- package/dist/modules/billing/components/AllocatePaymentDialog.js.map +7 -0
- package/dist/modules/billing/components/BillingDataTable.js +21 -0
- package/dist/modules/billing/components/BillingDataTable.js.map +7 -0
- package/dist/modules/billing/components/BillingSettingsLink.js +19 -0
- package/dist/modules/billing/components/BillingSettingsLink.js.map +7 -0
- package/dist/modules/billing/components/ChangeItemPriceDialog.js +158 -0
- package/dist/modules/billing/components/ChangeItemPriceDialog.js.map +7 -0
- package/dist/modules/billing/components/CreateMemoDialog.js +200 -0
- package/dist/modules/billing/components/CreateMemoDialog.js.map +7 -0
- package/dist/modules/billing/components/CustomerLabel.js +33 -0
- package/dist/modules/billing/components/CustomerLabel.js.map +7 -0
- package/dist/modules/billing/components/InvoicesTable.js +270 -0
- package/dist/modules/billing/components/InvoicesTable.js.map +7 -0
- package/dist/modules/billing/components/ItemForm.js +176 -44
- package/dist/modules/billing/components/ItemForm.js.map +2 -2
- package/dist/modules/billing/components/ItemPriceField.js +46 -0
- package/dist/modules/billing/components/ItemPriceField.js.map +7 -0
- package/dist/modules/billing/components/LineFormDialog.js +25 -2
- package/dist/modules/billing/components/LineFormDialog.js.map +2 -2
- package/dist/modules/billing/components/ManualPaymentDialog.js +122 -0
- package/dist/modules/billing/components/ManualPaymentDialog.js.map +7 -0
- package/dist/modules/billing/components/MoneyInput.js +14 -0
- package/dist/modules/billing/components/MoneyInput.js.map +7 -0
- package/dist/modules/billing/components/PaymentUploadDialog.js +115 -0
- package/dist/modules/billing/components/PaymentUploadDialog.js.map +7 -0
- package/dist/modules/billing/components/PaymentsTable.js +171 -0
- package/dist/modules/billing/components/PaymentsTable.js.map +7 -0
- package/dist/modules/billing/components/PostRunDraftsButton.js +105 -0
- package/dist/modules/billing/components/PostRunDraftsButton.js.map +7 -0
- package/dist/modules/billing/components/PrepaidPanel.js +14 -4
- package/dist/modules/billing/components/PrepaidPanel.js.map +2 -2
- package/dist/modules/billing/components/RunCyclesSection.js +209 -0
- package/dist/modules/billing/components/RunCyclesSection.js.map +7 -0
- package/dist/modules/billing/components/TestRunActions.js +127 -0
- package/dist/modules/billing/components/TestRunActions.js.map +7 -0
- package/dist/modules/billing/components/account/AccountItemsTab.js +157 -0
- package/dist/modules/billing/components/account/AccountItemsTab.js.map +7 -0
- package/dist/modules/billing/components/account/AccountRunBillingDialog.js +122 -0
- package/dist/modules/billing/components/account/AccountRunBillingDialog.js.map +7 -0
- package/dist/modules/billing/components/account/AccountRunsTab.js +152 -0
- package/dist/modules/billing/components/account/AccountRunsTab.js.map +7 -0
- package/dist/modules/billing/components/account/AccountStatementsTab.js +98 -0
- package/dist/modules/billing/components/account/AccountStatementsTab.js.map +7 -0
- package/dist/modules/billing/components/account/AccountSummaryCards.js +125 -0
- package/dist/modules/billing/components/account/AccountSummaryCards.js.map +7 -0
- package/dist/modules/billing/components/account/AccountUsageTab.js +91 -0
- package/dist/modules/billing/components/account/AccountUsageTab.js.map +7 -0
- package/dist/modules/billing/components/account/AccountView.js +73 -0
- package/dist/modules/billing/components/account/AccountView.js.map +7 -0
- package/dist/modules/billing/components/account/accountRow.js +39 -0
- package/dist/modules/billing/components/account/accountRow.js.map +7 -0
- package/dist/modules/billing/components/customerNames.js +42 -0
- package/dist/modules/billing/components/customerNames.js.map +7 -0
- package/dist/modules/billing/data/entities.js +615 -59
- package/dist/modules/billing/data/entities.js.map +2 -2
- package/dist/modules/billing/data/entityIds.js +10 -1
- package/dist/modules/billing/data/entityIds.js.map +2 -2
- package/dist/modules/billing/data/validators.js +269 -15
- package/dist/modules/billing/data/validators.js.map +2 -2
- package/dist/modules/billing/events.js +70 -0
- package/dist/modules/billing/events.js.map +2 -2
- package/dist/modules/billing/i18n/en.json +457 -21
- package/dist/modules/billing/i18n/pl.json +457 -21
- package/dist/modules/billing/index.js +6 -2
- package/dist/modules/billing/index.js.map +2 -2
- package/dist/modules/billing/lib/accountFinancials.js +58 -0
- package/dist/modules/billing/lib/accountFinancials.js.map +7 -0
- package/dist/modules/billing/lib/accountLock.js +14 -0
- package/dist/modules/billing/lib/accountLock.js.map +7 -0
- package/dist/modules/billing/lib/accountStatus.js +9 -7
- package/dist/modules/billing/lib/accountStatus.js.map +2 -2
- package/dist/modules/billing/lib/accountSummary.js +106 -0
- package/dist/modules/billing/lib/accountSummary.js.map +7 -0
- package/dist/modules/billing/lib/allocation.js +356 -0
- package/dist/modules/billing/lib/allocation.js.map +7 -0
- package/dist/modules/billing/lib/allocationEvents.js +22 -0
- package/dist/modules/billing/lib/allocationEvents.js.map +7 -0
- package/dist/modules/billing/lib/billPeriod.js +15 -1
- package/dist/modules/billing/lib/billPeriod.js.map +2 -2
- package/dist/modules/billing/lib/billRunEngine.js +241 -106
- package/dist/modules/billing/lib/billRunEngine.js.map +2 -2
- package/dist/modules/billing/lib/billRunLabel.js.map +1 -1
- package/dist/modules/billing/lib/billingSettings.js +116 -0
- package/dist/modules/billing/lib/billingSettings.js.map +7 -0
- package/dist/modules/billing/lib/commandRoute.js +81 -0
- package/dist/modules/billing/lib/commandRoute.js.map +7 -0
- package/dist/modules/billing/lib/customerLookup.js +97 -0
- package/dist/modules/billing/lib/customerLookup.js.map +7 -0
- package/dist/modules/billing/lib/dateOnly.js +13 -0
- package/dist/modules/billing/lib/dateOnly.js.map +7 -0
- package/dist/modules/billing/lib/documentParties.js +16 -0
- package/dist/modules/billing/lib/documentParties.js.map +7 -0
- package/dist/modules/billing/lib/documentTypes.js +27 -0
- package/dist/modules/billing/lib/documentTypes.js.map +7 -0
- package/dist/modules/billing/lib/dueDate.js +18 -0
- package/dist/modules/billing/lib/dueDate.js.map +7 -0
- package/dist/modules/billing/lib/iban.js +29 -0
- package/dist/modules/billing/lib/iban.js.map +7 -0
- package/dist/modules/billing/lib/invoiceDelivery.js +131 -0
- package/dist/modules/billing/lib/invoiceDelivery.js.map +7 -0
- package/dist/modules/billing/lib/invoiceLanguages.js +16 -0
- package/dist/modules/billing/lib/invoiceLanguages.js.map +7 -0
- package/dist/modules/billing/lib/invoiceWriter.js +107 -99
- package/dist/modules/billing/lib/invoiceWriter.js.map +2 -2
- package/dist/modules/billing/lib/itemBillingState.js +27 -0
- package/dist/modules/billing/lib/itemBillingState.js.map +7 -0
- package/dist/modules/billing/lib/itemPriceChange.js +18 -0
- package/dist/modules/billing/lib/itemPriceChange.js.map +7 -0
- package/dist/modules/billing/lib/itemSelector.js.map +2 -2
- package/dist/modules/billing/lib/lineAmounts.js +32 -0
- package/dist/modules/billing/lib/lineAmounts.js.map +7 -0
- package/dist/modules/billing/lib/memoGuards.js +25 -0
- package/dist/modules/billing/lib/memoGuards.js.map +7 -0
- package/dist/modules/billing/lib/navigation.js +48 -0
- package/dist/modules/billing/lib/navigation.js.map +7 -0
- package/dist/modules/billing/lib/numbering.js +120 -0
- package/dist/modules/billing/lib/numbering.js.map +7 -0
- package/dist/modules/billing/lib/overdue.js +36 -0
- package/dist/modules/billing/lib/overdue.js.map +7 -0
- package/dist/modules/billing/lib/paymentCsv.js +125 -0
- package/dist/modules/billing/lib/paymentCsv.js.map +7 -0
- package/dist/modules/billing/lib/paymentGateway.js +15 -0
- package/dist/modules/billing/lib/paymentGateway.js.map +7 -0
- package/dist/modules/billing/lib/paymentImport.js +164 -0
- package/dist/modules/billing/lib/paymentImport.js.map +7 -0
- package/dist/modules/billing/lib/paymentMatcher.js +36 -0
- package/dist/modules/billing/lib/paymentMatcher.js.map +7 -0
- package/dist/modules/billing/lib/pdf/attachmentStore.js +46 -0
- package/dist/modules/billing/lib/pdf/attachmentStore.js.map +7 -0
- package/dist/modules/billing/lib/pdf/fonts/embeddedFonts.js +7 -0
- package/dist/modules/billing/lib/pdf/fonts/embeddedFonts.js.map +7 -0
- package/dist/modules/billing/lib/pdf/invoiceModel.js +194 -0
- package/dist/modules/billing/lib/pdf/invoiceModel.js.map +7 -0
- package/dist/modules/billing/lib/pdf/invoicePdf.js +165 -0
- package/dist/modules/billing/lib/pdf/invoicePdf.js.map +7 -0
- package/dist/modules/billing/lib/pdf/invoiceTemplate.js +274 -0
- package/dist/modules/billing/lib/pdf/invoiceTemplate.js.map +7 -0
- package/dist/modules/billing/lib/prepaidConfig.js +17 -25
- package/dist/modules/billing/lib/prepaidConfig.js.map +2 -2
- package/dist/modules/billing/lib/prepaidConsume.js +26 -7
- package/dist/modules/billing/lib/prepaidConsume.js.map +2 -2
- package/dist/modules/billing/lib/prepaidPeriodClose.js +277 -158
- package/dist/modules/billing/lib/prepaidPeriodClose.js.map +2 -2
- package/dist/modules/billing/lib/prepaidTaxPoint.js +37 -0
- package/dist/modules/billing/lib/prepaidTaxPoint.js.map +7 -0
- package/dist/modules/billing/lib/seeds/demo.js +51 -3
- package/dist/modules/billing/lib/seeds/demo.js.map +2 -2
- package/dist/modules/billing/lib/seeds/paymentsSample.js +93 -0
- package/dist/modules/billing/lib/seeds/paymentsSample.js.map +7 -0
- package/dist/modules/billing/lib/seeds/sellerSettings.js +41 -0
- package/dist/modules/billing/lib/seeds/sellerSettings.js.map +7 -0
- package/dist/modules/billing/lib/servicePeriods.js +121 -0
- package/dist/modules/billing/lib/servicePeriods.js.map +7 -0
- package/dist/modules/billing/lib/tenantLock.js.map +1 -1
- package/dist/modules/billing/lib/testRunCleanup.js +24 -0
- package/dist/modules/billing/lib/testRunCleanup.js.map +7 -0
- package/dist/modules/billing/lib/topupCapture.js +2 -2
- package/dist/modules/billing/lib/topupCapture.js.map +2 -2
- package/dist/modules/billing/lib/topupReceipt.js +58 -79
- package/dist/modules/billing/lib/topupReceipt.js.map +2 -2
- package/dist/modules/billing/lib/usageRater.js.map +1 -1
- package/dist/modules/billing/lib/usageRunner.js +14 -6
- package/dist/modules/billing/lib/usageRunner.js.map +2 -2
- package/dist/modules/billing/lib/vat.js +39 -0
- package/dist/modules/billing/lib/vat.js.map +7 -0
- package/dist/modules/billing/migrations/Migration20261114000000_billing_customer_kind.js +15 -0
- package/dist/modules/billing/migrations/Migration20261114000000_billing_customer_kind.js.map +7 -0
- package/dist/modules/billing/migrations/Migration20261114100000_billing_cycle_semantics.js +25 -0
- package/dist/modules/billing/migrations/Migration20261114100000_billing_cycle_semantics.js.map +7 -0
- package/dist/modules/billing/migrations/Migration20261115000000_billing_invoice_ledger.js +115 -0
- package/dist/modules/billing/migrations/Migration20261115000000_billing_invoice_ledger.js.map +7 -0
- package/dist/modules/billing/migrations/Migration20261116000000_billing_invoice_documents.js +47 -0
- package/dist/modules/billing/migrations/Migration20261116000000_billing_invoice_documents.js.map +7 -0
- package/dist/modules/billing/migrations/Migration20261117000000_billing_payments.js +89 -0
- package/dist/modules/billing/migrations/Migration20261117000000_billing_payments.js.map +7 -0
- package/dist/modules/billing/migrations/Migration20261118000000_billing_memos.js +17 -0
- package/dist/modules/billing/migrations/Migration20261118000000_billing_memos.js.map +7 -0
- package/dist/modules/billing/migrations/Migration20261119000000_billing_operator_feedback.js +27 -0
- package/dist/modules/billing/migrations/Migration20261119000000_billing_operator_feedback.js.map +7 -0
- package/dist/modules/billing/migrations/Migration20261120000000_billing_allocation_scope_indexes.js +29 -0
- package/dist/modules/billing/migrations/Migration20261120000000_billing_allocation_scope_indexes.js.map +7 -0
- package/dist/modules/billing/setup.js +7 -184
- package/dist/modules/billing/setup.js.map +2 -2
- package/dist/modules/billing/subscribers/credit-memo-auto-send.js +16 -0
- package/dist/modules/billing/subscribers/credit-memo-auto-send.js.map +7 -0
- package/dist/modules/billing/subscribers/debit-memo-apply-credit.js +16 -0
- package/dist/modules/billing/subscribers/debit-memo-apply-credit.js.map +7 -0
- package/dist/modules/billing/subscribers/debit-memo-auto-send.js +16 -0
- package/dist/modules/billing/subscribers/debit-memo-auto-send.js.map +7 -0
- package/dist/modules/billing/subscribers/invoice-apply-credit.js +34 -0
- package/dist/modules/billing/subscribers/invoice-apply-credit.js.map +7 -0
- package/dist/modules/billing/subscribers/invoice-auto-send.js +30 -0
- package/dist/modules/billing/subscribers/invoice-auto-send.js.map +7 -0
- package/dist/modules/billing/subscribers/payment-captured-to-paid.js +69 -33
- package/dist/modules/billing/subscribers/payment-captured-to-paid.js.map +2 -2
- package/dist/modules/billing/subscribers/prepaid-topup-captured.js +4 -6
- package/dist/modules/billing/subscribers/prepaid-topup-captured.js.map +2 -2
- package/dist/modules/billing/workers/reap-stale-bill-runs.js +2 -2
- package/dist/modules/billing/workers/reap-stale-bill-runs.js.map +2 -2
- package/generated/entities/billing_account/index.ts +26 -0
- package/generated/entities/billing_account_balance/index.ts +13 -0
- package/generated/entities/billing_account_transaction/index.ts +21 -0
- package/generated/entities/billing_account_usage/index.ts +18 -0
- package/generated/entities/billing_allocation/index.ts +18 -0
- package/generated/entities/billing_document_sequence/index.ts +11 -0
- package/generated/entities/billing_draft_invoice_edit/index.ts +14 -0
- package/generated/entities/billing_invoice/index.ts +38 -0
- package/generated/entities/billing_invoice_line/index.ts +24 -0
- package/generated/entities/billing_item/index.ts +26 -0
- package/generated/entities/billing_payment/index.ts +25 -0
- package/generated/entities/billing_payment_import/index.ts +14 -0
- package/generated/entities/billing_run/index.ts +20 -0
- package/generated/entities/billing_run_outcome/index.ts +18 -0
- package/generated/entities/billing_settings/index.ts +26 -0
- package/generated/entities/billing_statement/index.ts +22 -0
- package/generated/entities/billing_topup/index.ts +20 -0
- package/generated/entities.ids.generated.ts +35 -0
- package/package.json +15 -10
- package/src/modules/billing/__integration__/TC-BILL-004.spec.ts +170 -0
- package/src/modules/billing/__integration__/TC-BILL-005.spec.ts +134 -0
- package/src/modules/billing/__integration__/TC-BILL-006.spec.ts +101 -0
- package/src/modules/billing/__integration__/TC-BILL-007.spec.ts +140 -0
- package/src/modules/billing/__integration__/TC-BILL-008.spec.ts +108 -0
- package/src/modules/billing/__integration__/TC-BILL-009.spec.ts +113 -0
- package/src/modules/billing/__integration__/TC-BILL-010.spec.ts +118 -0
- package/src/modules/billing/__integration__/TC-BILL-011.spec.ts +142 -0
- package/src/modules/billing/__integration__/TC-BILL-012.spec.ts +115 -0
- package/src/modules/billing/__integration__/TC-BILL-013.spec.ts +118 -0
- package/src/modules/billing/__integration__/sellerSettings.ts +24 -0
- package/src/modules/billing/__tests__/commands/invoices.test.ts +437 -355
- package/src/modules/billing/__tests__/commands/itemsBulk.test.ts +33 -0
- package/src/modules/billing/__tests__/commands/memos.test.ts +205 -0
- package/src/modules/billing/__tests__/commands/payments.test.ts +241 -0
- package/src/modules/billing/__tests__/commands/runsDelete.test.ts +146 -0
- package/src/modules/billing/__tests__/commands/runsPostDrafts.test.ts +106 -0
- package/src/modules/billing/__tests__/commands/topups.test.ts +11 -0
- package/src/modules/billing/__tests__/entityRegistry.test.ts +326 -0
- package/src/modules/billing/__tests__/events.test.ts +142 -0
- package/src/modules/billing/__tests__/helpers/prepaidMockEm.ts +28 -11
- package/src/modules/billing/__tests__/lib/accountFinancials.test.ts +53 -0
- package/src/modules/billing/__tests__/lib/accountSummary.test.ts +97 -0
- package/src/modules/billing/__tests__/lib/allocation.test.ts +319 -0
- package/src/modules/billing/__tests__/lib/billRunEngine.test.ts +231 -20
- package/src/modules/billing/__tests__/lib/billingSettings.test.ts +109 -0
- package/src/modules/billing/__tests__/lib/customerLookup.test.ts +156 -0
- package/src/modules/billing/__tests__/lib/dueDate.test.ts +35 -0
- package/src/modules/billing/__tests__/lib/iban.test.ts +38 -0
- package/src/modules/billing/__tests__/lib/invoiceDelivery.test.ts +189 -0
- package/src/modules/billing/__tests__/lib/invoiceWriter.test.ts +212 -10
- package/src/modules/billing/__tests__/lib/itemBillingState.test.ts +42 -0
- package/src/modules/billing/__tests__/lib/itemPriceChange.test.ts +165 -0
- package/src/modules/billing/__tests__/lib/lineAmounts.test.ts +86 -0
- package/src/modules/billing/__tests__/lib/navigation.test.ts +71 -0
- package/src/modules/billing/__tests__/lib/numbering.test.ts +91 -0
- package/src/modules/billing/__tests__/lib/overdue.test.ts +36 -0
- package/src/modules/billing/__tests__/lib/paymentCsv.test.ts +148 -0
- package/src/modules/billing/__tests__/lib/paymentImport.test.ts +113 -0
- package/src/modules/billing/__tests__/lib/paymentsSample.test.ts +73 -0
- package/src/modules/billing/__tests__/lib/pdf/invoicePdf.test.ts +199 -0
- package/src/modules/billing/__tests__/lib/pdf/invoicePdfService.test.ts +147 -0
- package/src/modules/billing/__tests__/lib/prepaidPeriodClose.test.ts +374 -98
- package/src/modules/billing/__tests__/lib/prepaidTaxPoint.test.ts +118 -0
- package/src/modules/billing/__tests__/lib/seedsDemo.test.ts +53 -2
- package/src/modules/billing/__tests__/lib/sellerSettings.test.ts +28 -0
- package/src/modules/billing/__tests__/lib/servicePeriods.test.ts +190 -0
- package/src/modules/billing/__tests__/lib/topupCapture.test.ts +6 -28
- package/src/modules/billing/__tests__/lib/topupReceipt.test.ts +21 -52
- package/src/modules/billing/__tests__/lib/vat.test.ts +51 -0
- package/src/modules/billing/__tests__/package-isolation.test.ts +22 -8
- package/src/modules/billing/__tests__/setup.test.ts +13 -4
- package/src/modules/billing/__tests__/validators.test.ts +193 -3
- package/src/modules/billing/acl.ts +12 -0
- package/src/modules/billing/api/accounts/[id]/summary/route.ts +62 -0
- package/src/modules/billing/api/accounts/route.ts +58 -4
- package/src/modules/billing/api/export/account/[id]/route.ts +20 -18
- package/src/modules/billing/api/invoices/[id]/memos/route.ts +63 -0
- package/src/modules/billing/api/invoices/[id]/pdf/route.ts +79 -0
- package/src/modules/billing/api/invoices/[id]/route.ts +57 -70
- package/src/modules/billing/api/invoices/[id]/send/route.ts +127 -0
- package/src/modules/billing/api/invoices/add-line/route.ts +3 -3
- package/src/modules/billing/api/invoices/delete-draft/route.ts +33 -0
- package/src/modules/billing/api/invoices/edit-line/route.ts +4 -4
- package/src/modules/billing/api/invoices/post/route.ts +7 -6
- package/src/modules/billing/api/invoices/remove-line/route.ts +3 -3
- package/src/modules/billing/api/invoices/route.ts +81 -86
- package/src/modules/billing/api/items/bulk/route.ts +2 -1
- package/src/modules/billing/api/items/change-price/route.ts +54 -0
- package/src/modules/billing/api/items/route.ts +23 -7
- package/src/modules/billing/api/payment-imports/[id]/route.ts +49 -0
- package/src/modules/billing/api/payment-imports/route.ts +57 -0
- package/src/modules/billing/api/payments/[id]/route.ts +63 -0
- package/src/modules/billing/api/payments/allocate/route.ts +35 -0
- package/src/modules/billing/api/payments/assign/route.ts +36 -0
- package/src/modules/billing/api/payments/convert-to-topup/route.ts +35 -0
- package/src/modules/billing/api/payments/ignore/route.ts +35 -0
- package/src/modules/billing/api/payments/import/route.ts +72 -0
- package/src/modules/billing/api/payments/restore/route.ts +35 -0
- package/src/modules/billing/api/payments/route.ts +147 -0
- package/src/modules/billing/api/payments/unallocate/route.ts +35 -0
- package/src/modules/billing/api/payments/unassign/route.ts +35 -0
- package/src/modules/billing/api/run-outcomes/route.ts +50 -7
- package/src/modules/billing/api/runs/[id]/post-drafts/route.ts +71 -0
- package/src/modules/billing/api/runs/[id]/route.ts +59 -0
- package/src/modules/billing/api/runs/retry-failed/route.ts +4 -3
- package/src/modules/billing/api/runs/route.ts +17 -9
- package/src/modules/billing/api/settings/number-preview/route.ts +46 -0
- package/src/modules/billing/api/settings/route.ts +116 -0
- package/src/modules/billing/api/statements/route.ts +5 -0
- package/src/modules/billing/api/test-invoices/wipe/route.ts +2 -2
- package/src/modules/billing/backend/billing/accounts/[id]/page.tsx +151 -372
- package/src/modules/billing/backend/billing/accounts/create/page.tsx +6 -0
- package/src/modules/billing/backend/billing/accounts/page.tsx +71 -5
- package/src/modules/billing/backend/billing/invoices/[id]/page.tsx +445 -96
- package/src/modules/billing/backend/billing/invoices/page.tsx +8 -227
- package/src/modules/billing/backend/billing/items/[id]/page.tsx +75 -6
- package/src/modules/billing/backend/billing/items/create/page.tsx +13 -8
- package/src/modules/billing/backend/billing/items/page.tsx +19 -3
- package/src/modules/billing/backend/billing/payments/[id]/page.meta.ts +19 -0
- package/src/modules/billing/backend/billing/payments/[id]/page.tsx +415 -0
- package/src/modules/billing/backend/billing/payments/imports/[id]/page.meta.ts +19 -0
- package/src/modules/billing/backend/billing/payments/imports/[id]/page.tsx +106 -0
- package/src/modules/billing/backend/billing/payments/page.meta.ts +16 -0
- package/src/modules/billing/backend/billing/payments/page.tsx +56 -0
- package/src/modules/billing/backend/billing/runs/[id]/page.tsx +50 -19
- package/src/modules/billing/backend/billing/runs/page.tsx +60 -9
- package/src/modules/billing/backend/billing/statements/[id]/page.tsx +87 -6
- package/src/modules/billing/backend/billing/statements/page.tsx +2 -2
- package/src/modules/billing/backend/billing/topups/page.tsx +2 -2
- package/src/modules/billing/backend/billing/transactions/page.tsx +2 -2
- package/src/modules/billing/backend/billing/usage/create/page.tsx +3 -2
- package/src/modules/billing/backend/config/billing/page.meta.ts +21 -0
- package/src/modules/billing/backend/config/billing/page.tsx +549 -0
- package/src/modules/billing/ce.ts +8 -7
- package/src/modules/billing/cli.ts +31 -1
- package/src/modules/billing/commands/accounts.ts +6 -0
- package/src/modules/billing/commands/index.ts +3 -0
- package/src/modules/billing/commands/invoices.ts +371 -238
- package/src/modules/billing/commands/items.ts +143 -0
- package/src/modules/billing/commands/memos.ts +218 -0
- package/src/modules/billing/commands/payments.ts +428 -0
- package/src/modules/billing/commands/runs.ts +208 -6
- package/src/modules/billing/commands/settings.ts +77 -0
- package/src/modules/billing/commands/topups.ts +12 -3
- package/src/modules/billing/commands/transactions.ts +2 -2
- package/src/modules/billing/components/AccountForm.tsx +199 -53
- package/src/modules/billing/components/AccountInvoicesSection.tsx +75 -0
- package/src/modules/billing/components/AccountPaymentsSection.tsx +42 -0
- package/src/modules/billing/components/AccountPicker.tsx +70 -0
- package/src/modules/billing/components/AllocatePaymentDialog.tsx +167 -0
- package/src/modules/billing/components/BillingDataTable.tsx +34 -0
- package/src/modules/billing/components/BillingSettingsLink.tsx +25 -0
- package/src/modules/billing/components/ChangeItemPriceDialog.tsx +180 -0
- package/src/modules/billing/components/CreateMemoDialog.tsx +232 -0
- package/src/modules/billing/components/CustomerLabel.tsx +53 -0
- package/src/modules/billing/components/InvoicesTable.tsx +344 -0
- package/src/modules/billing/components/ItemForm.tsx +233 -44
- package/src/modules/billing/components/ItemPriceField.tsx +81 -0
- package/src/modules/billing/components/LineFormDialog.tsx +25 -1
- package/src/modules/billing/components/ManualPaymentDialog.tsx +140 -0
- package/src/modules/billing/components/MoneyInput.tsx +26 -0
- package/src/modules/billing/components/PaymentUploadDialog.tsx +148 -0
- package/src/modules/billing/components/PaymentsTable.tsx +213 -0
- package/src/modules/billing/components/PostRunDraftsButton.tsx +129 -0
- package/src/modules/billing/components/PrepaidPanel.tsx +20 -7
- package/src/modules/billing/components/RunCyclesSection.tsx +298 -0
- package/src/modules/billing/components/TestRunActions.tsx +152 -0
- package/src/modules/billing/components/account/AccountItemsTab.tsx +192 -0
- package/src/modules/billing/components/account/AccountRunBillingDialog.tsx +147 -0
- package/src/modules/billing/components/account/AccountRunsTab.tsx +201 -0
- package/src/modules/billing/components/account/AccountStatementsTab.tsx +120 -0
- package/src/modules/billing/components/account/AccountSummaryCards.tsx +153 -0
- package/src/modules/billing/components/account/AccountUsageTab.tsx +122 -0
- package/src/modules/billing/components/account/AccountView.tsx +101 -0
- package/src/modules/billing/components/account/accountRow.ts +70 -0
- package/src/modules/billing/components/customerNames.ts +62 -0
- package/src/modules/billing/data/entities.ts +685 -15
- package/src/modules/billing/data/entityIds.ts +25 -11
- package/src/modules/billing/data/validators.ts +388 -8
- package/src/modules/billing/events.ts +82 -3
- package/src/modules/billing/i18n/en.json +457 -21
- package/src/modules/billing/i18n/pl.json +457 -21
- package/src/modules/billing/index.ts +6 -2
- package/src/modules/billing/lib/accountFinancials.ts +84 -0
- package/src/modules/billing/lib/accountLock.ts +32 -0
- package/src/modules/billing/lib/accountStatus.ts +11 -9
- package/src/modules/billing/lib/accountSummary.ts +172 -0
- package/src/modules/billing/lib/allocation.ts +515 -0
- package/src/modules/billing/lib/allocationEvents.ts +26 -0
- package/src/modules/billing/lib/billPeriod.ts +19 -0
- package/src/modules/billing/lib/billRunEngine.ts +362 -162
- package/src/modules/billing/lib/billRunLabel.ts +1 -1
- package/src/modules/billing/lib/billingSettings.ts +145 -0
- package/src/modules/billing/lib/commandRoute.ts +112 -0
- package/src/modules/billing/lib/customerLookup.ts +157 -0
- package/src/modules/billing/lib/dateOnly.ts +22 -0
- package/src/modules/billing/lib/documentParties.ts +23 -0
- package/src/modules/billing/lib/documentTypes.ts +37 -0
- package/src/modules/billing/lib/dueDate.ts +26 -0
- package/src/modules/billing/lib/iban.ts +36 -0
- package/src/modules/billing/lib/invoiceDelivery.ts +197 -0
- package/src/modules/billing/lib/invoiceLanguages.ts +34 -0
- package/src/modules/billing/lib/invoiceWriter.ts +162 -148
- package/src/modules/billing/lib/itemBillingState.ts +67 -0
- package/src/modules/billing/lib/itemPriceChange.ts +56 -0
- package/src/modules/billing/lib/itemSelector.ts +4 -1
- package/src/modules/billing/lib/lineAmounts.ts +61 -0
- package/src/modules/billing/lib/memoGuards.ts +41 -0
- package/src/modules/billing/lib/navigation.ts +64 -0
- package/src/modules/billing/lib/numbering.ts +174 -0
- package/src/modules/billing/lib/overdue.ts +60 -0
- package/src/modules/billing/lib/paymentCsv.ts +171 -0
- package/src/modules/billing/lib/paymentGateway.ts +52 -0
- package/src/modules/billing/lib/paymentImport.ts +228 -0
- package/src/modules/billing/lib/paymentMatcher.ts +88 -0
- package/src/modules/billing/lib/pdf/attachmentStore.ts +60 -0
- package/src/modules/billing/lib/pdf/fonts/NotoSans-Bold.ttf +0 -0
- package/src/modules/billing/lib/pdf/fonts/NotoSans-Regular.ttf +0 -0
- package/src/modules/billing/lib/pdf/fonts/OFL.txt +93 -0
- package/src/modules/billing/lib/pdf/fonts/embeddedFonts.ts +9 -0
- package/src/modules/billing/lib/pdf/invoiceModel.ts +328 -0
- package/src/modules/billing/lib/pdf/invoicePdf.ts +216 -0
- package/src/modules/billing/lib/pdf/invoiceTemplate.ts +338 -0
- package/src/modules/billing/lib/prepaidConfig.ts +27 -36
- package/src/modules/billing/lib/prepaidConsume.ts +29 -6
- package/src/modules/billing/lib/prepaidPeriodClose.ts +410 -242
- package/src/modules/billing/lib/prepaidTaxPoint.ts +76 -0
- package/src/modules/billing/lib/seeds/demo.ts +79 -6
- package/src/modules/billing/lib/seeds/paymentsSample.ts +136 -0
- package/src/modules/billing/lib/seeds/sellerSettings.ts +78 -0
- package/src/modules/billing/lib/servicePeriods.ts +226 -0
- package/src/modules/billing/lib/tenantLock.ts +1 -1
- package/src/modules/billing/lib/testRunCleanup.ts +42 -0
- package/src/modules/billing/lib/topupCapture.ts +3 -4
- package/src/modules/billing/lib/topupReceipt.ts +70 -103
- package/src/modules/billing/lib/usageRater.ts +1 -1
- package/src/modules/billing/lib/usageRunner.ts +17 -5
- package/src/modules/billing/lib/vat.ts +56 -0
- package/src/modules/billing/migrations/Migration20261114000000_billing_customer_kind.ts +25 -0
- package/src/modules/billing/migrations/Migration20261114100000_billing_cycle_semantics.ts +37 -0
- package/src/modules/billing/migrations/Migration20261115000000_billing_invoice_ledger.ts +132 -0
- package/src/modules/billing/migrations/Migration20261116000000_billing_invoice_documents.ts +58 -0
- package/src/modules/billing/migrations/Migration20261117000000_billing_payments.ts +97 -0
- package/src/modules/billing/migrations/Migration20261118000000_billing_memos.ts +21 -0
- package/src/modules/billing/migrations/Migration20261119000000_billing_operator_feedback.ts +39 -0
- package/src/modules/billing/migrations/Migration20261120000000_billing_allocation_scope_indexes.ts +35 -0
- package/src/modules/billing/setup.ts +11 -237
- package/src/modules/billing/subscribers/credit-memo-auto-send.ts +15 -0
- package/src/modules/billing/subscribers/debit-memo-apply-credit.ts +15 -0
- package/src/modules/billing/subscribers/debit-memo-auto-send.ts +15 -0
- package/src/modules/billing/subscribers/invoice-apply-credit.ts +39 -0
- package/src/modules/billing/subscribers/invoice-auto-send.ts +46 -0
- package/src/modules/billing/subscribers/payment-captured-to-paid.ts +84 -62
- package/src/modules/billing/subscribers/prepaid-topup-captured.ts +4 -8
- package/src/modules/billing/workers/reap-stale-bill-runs.ts +4 -4
- package/dist/modules/billing/lib/invoiceStatus.js +0 -38
- package/dist/modules/billing/lib/invoiceStatus.js.map +0 -7
- package/src/modules/billing/__tests__/lib/invoiceStatus.test.ts +0 -97
- package/src/modules/billing/lib/invoiceStatus.ts +0 -61
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { Eraser, Trash2 } from "lucide-react";
|
|
5
|
+
import { useT } from "@open-mercato/shared/lib/i18n/context";
|
|
6
|
+
import { Button } from "@open-mercato/ui/primitives/button";
|
|
7
|
+
import { flash } from "@open-mercato/ui/backend/FlashMessages";
|
|
8
|
+
import { useConfirmDialog } from "@open-mercato/ui/backend/confirm-dialog";
|
|
9
|
+
import { apiCallOrThrow } from "@open-mercato/ui/backend/utils/apiCall";
|
|
10
|
+
import { normalizeCrudServerError } from "@open-mercato/ui/backend/utils/serverErrors";
|
|
11
|
+
function billRunMode(run) {
|
|
12
|
+
if (run.dry_run) return "dry";
|
|
13
|
+
if (run.test_mode) return "test";
|
|
14
|
+
return "real";
|
|
15
|
+
}
|
|
16
|
+
function useTestRunCleanup() {
|
|
17
|
+
const t = useT();
|
|
18
|
+
const { confirm, ConfirmDialogElement } = useConfirmDialog();
|
|
19
|
+
const [busy, setBusy] = React.useState(null);
|
|
20
|
+
const wipe = React.useCallback(
|
|
21
|
+
async (runId) => {
|
|
22
|
+
const ok = await confirm({
|
|
23
|
+
title: t("billing.runs.wipe.confirm.title", "Wipe test invoices?"),
|
|
24
|
+
text: t(
|
|
25
|
+
"billing.runs.wipe.confirm.text",
|
|
26
|
+
"Every test invoice from this Bill Run will be permanently deleted. The run itself stays. This cannot be undone."
|
|
27
|
+
),
|
|
28
|
+
confirmText: t("billing.runs.wipe.confirm.button", "Delete test invoices"),
|
|
29
|
+
variant: "destructive"
|
|
30
|
+
});
|
|
31
|
+
if (!ok) return null;
|
|
32
|
+
setBusy("wipe");
|
|
33
|
+
try {
|
|
34
|
+
const call = await apiCallOrThrow("/api/billing/test-invoices/wipe", {
|
|
35
|
+
method: "POST",
|
|
36
|
+
headers: { "Content-Type": "application/json" },
|
|
37
|
+
body: JSON.stringify({ billRunId: runId })
|
|
38
|
+
});
|
|
39
|
+
const removed = call.result?.invoicesRemoved ?? 0;
|
|
40
|
+
flash(`${t("billing.runs.wipe.success", "Test invoices removed")} (${removed})`, "success");
|
|
41
|
+
return removed;
|
|
42
|
+
} catch (err) {
|
|
43
|
+
const { message } = normalizeCrudServerError(err);
|
|
44
|
+
flash(message || t("billing.runs.wipe.error", "Wipe failed"), "error");
|
|
45
|
+
return null;
|
|
46
|
+
} finally {
|
|
47
|
+
setBusy(null);
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
[confirm, t]
|
|
51
|
+
);
|
|
52
|
+
const remove = React.useCallback(
|
|
53
|
+
async (params) => {
|
|
54
|
+
const text = params.mode === "test" && typeof params.draftsCount === "number" && params.draftsCount > 0 ? `${t("billing.runs.delete.confirm.text_with_invoices", "The run, its results and its test invoices will be permanently deleted. Test invoices:")} ${params.draftsCount}` : t("billing.runs.delete.confirm.text", "The run and its results will be permanently deleted.");
|
|
55
|
+
const ok = await confirm({
|
|
56
|
+
title: t("billing.runs.delete.confirm.title", "Delete this run?"),
|
|
57
|
+
text,
|
|
58
|
+
confirmText: t("billing.runs.delete.confirm.button", "Delete run"),
|
|
59
|
+
variant: "destructive"
|
|
60
|
+
});
|
|
61
|
+
if (!ok) return null;
|
|
62
|
+
setBusy("delete");
|
|
63
|
+
try {
|
|
64
|
+
const call = await apiCallOrThrow(
|
|
65
|
+
`/api/billing/runs/${encodeURIComponent(params.runId)}`,
|
|
66
|
+
{ method: "DELETE" }
|
|
67
|
+
);
|
|
68
|
+
flash(t("billing.runs.delete.success", "Run deleted"), "success");
|
|
69
|
+
return call.result?.invoicesRemoved ?? 0;
|
|
70
|
+
} catch (err) {
|
|
71
|
+
const { message } = normalizeCrudServerError(err);
|
|
72
|
+
flash(message || t("billing.runs.delete.error", "Delete failed"), "error");
|
|
73
|
+
return null;
|
|
74
|
+
} finally {
|
|
75
|
+
setBusy(null);
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
[confirm, t]
|
|
79
|
+
);
|
|
80
|
+
return { wipe, remove, busy, ConfirmDialogElement };
|
|
81
|
+
}
|
|
82
|
+
function TestRunActions({ runId, mode, draftsCount, onWiped, onDeleted }) {
|
|
83
|
+
const t = useT();
|
|
84
|
+
const { wipe, remove, busy, ConfirmDialogElement } = useTestRunCleanup();
|
|
85
|
+
if (mode === "real") return null;
|
|
86
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
87
|
+
mode === "test" ? /* @__PURE__ */ jsxs(
|
|
88
|
+
Button,
|
|
89
|
+
{
|
|
90
|
+
type: "button",
|
|
91
|
+
variant: "outline",
|
|
92
|
+
disabled: busy !== null,
|
|
93
|
+
onClick: async () => {
|
|
94
|
+
const removed = await wipe(runId);
|
|
95
|
+
if (removed !== null) onWiped?.(removed);
|
|
96
|
+
},
|
|
97
|
+
children: [
|
|
98
|
+
/* @__PURE__ */ jsx(Eraser, { size: 16 }),
|
|
99
|
+
busy === "wipe" ? t("billing.runs.wipe.in_progress", "Wiping\u2026") : t("billing.runs.wipe.action", "Wipe test invoices")
|
|
100
|
+
]
|
|
101
|
+
}
|
|
102
|
+
) : null,
|
|
103
|
+
/* @__PURE__ */ jsxs(
|
|
104
|
+
Button,
|
|
105
|
+
{
|
|
106
|
+
type: "button",
|
|
107
|
+
variant: "destructive",
|
|
108
|
+
disabled: busy !== null,
|
|
109
|
+
onClick: async () => {
|
|
110
|
+
const removed = await remove({ runId, mode, draftsCount });
|
|
111
|
+
if (removed !== null) onDeleted?.(removed);
|
|
112
|
+
},
|
|
113
|
+
children: [
|
|
114
|
+
/* @__PURE__ */ jsx(Trash2, { size: 16 }),
|
|
115
|
+
busy === "delete" ? t("billing.runs.delete.in_progress", "Deleting\u2026") : t("billing.runs.delete.action", "Delete run")
|
|
116
|
+
]
|
|
117
|
+
}
|
|
118
|
+
),
|
|
119
|
+
ConfirmDialogElement
|
|
120
|
+
] });
|
|
121
|
+
}
|
|
122
|
+
export {
|
|
123
|
+
TestRunActions,
|
|
124
|
+
billRunMode,
|
|
125
|
+
useTestRunCleanup
|
|
126
|
+
};
|
|
127
|
+
//# sourceMappingURL=TestRunActions.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/modules/billing/components/TestRunActions.tsx"],
|
|
4
|
+
"sourcesContent": ["\"use client\"\nimport * as React from 'react'\nimport { Eraser, Trash2 } from 'lucide-react'\nimport { useT } from '@open-mercato/shared/lib/i18n/context'\nimport { Button } from '@open-mercato/ui/primitives/button'\nimport { flash } from '@open-mercato/ui/backend/FlashMessages'\nimport { useConfirmDialog } from '@open-mercato/ui/backend/confirm-dialog'\nimport { apiCallOrThrow } from '@open-mercato/ui/backend/utils/apiCall'\nimport { normalizeCrudServerError } from '@open-mercato/ui/backend/utils/serverErrors'\n\nexport type BillRunMode = 'real' | 'test' | 'dry'\n\nexport function billRunMode(run: { dry_run?: boolean | null; test_mode?: boolean | null }): BillRunMode {\n if (run.dry_run) return 'dry'\n if (run.test_mode) return 'test'\n return 'real'\n}\n\nexport type TestRunActionsProps = {\n runId: string\n mode: BillRunMode\n /** Test drafts the run wrote (from the run summary), for the confirm text. */\n draftsCount?: number\n onWiped?: (invoicesRemoved: number) => void\n onDeleted?: (invoicesRemoved: number) => void\n}\n\n/**\n * Confirm-then-call cleanup flows for a test / dry Bill Run (Spec F, F1),\n * shared by the run detail page, the runs list row action and the account\n * \"Run billing\" dialog. Each call resolves to the removed invoice count, or\n * `null` when the operator cancelled or the call failed (already flashed).\n */\nexport function useTestRunCleanup() {\n const t = useT()\n const { confirm, ConfirmDialogElement } = useConfirmDialog()\n const [busy, setBusy] = React.useState<'wipe' | 'delete' | null>(null)\n\n const wipe = React.useCallback(\n async (runId: string): Promise<number | null> => {\n const ok = await confirm({\n title: t('billing.runs.wipe.confirm.title', 'Wipe test invoices?'),\n text: t(\n 'billing.runs.wipe.confirm.text',\n 'Every test invoice from this Bill Run will be permanently deleted. The run itself stays. This cannot be undone.',\n ),\n confirmText: t('billing.runs.wipe.confirm.button', 'Delete test invoices'),\n variant: 'destructive',\n })\n if (!ok) return null\n setBusy('wipe')\n try {\n const call = await apiCallOrThrow<{ invoicesRemoved: number }>('/api/billing/test-invoices/wipe', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ billRunId: runId }),\n })\n const removed = call.result?.invoicesRemoved ?? 0\n flash(`${t('billing.runs.wipe.success', 'Test invoices removed')} (${removed})`, 'success')\n return removed\n } catch (err) {\n const { message } = normalizeCrudServerError(err)\n flash(message || t('billing.runs.wipe.error', 'Wipe failed'), 'error')\n return null\n } finally {\n setBusy(null)\n }\n },\n [confirm, t],\n )\n\n const remove = React.useCallback(\n async (params: { runId: string; mode: BillRunMode; draftsCount?: number }): Promise<number | null> => {\n const text =\n params.mode === 'test' && typeof params.draftsCount === 'number' && params.draftsCount > 0\n ? `${t('billing.runs.delete.confirm.text_with_invoices', 'The run, its results and its test invoices will be permanently deleted. Test invoices:')} ${params.draftsCount}`\n : t('billing.runs.delete.confirm.text', 'The run and its results will be permanently deleted.')\n const ok = await confirm({\n title: t('billing.runs.delete.confirm.title', 'Delete this run?'),\n text,\n confirmText: t('billing.runs.delete.confirm.button', 'Delete run'),\n variant: 'destructive',\n })\n if (!ok) return null\n setBusy('delete')\n try {\n const call = await apiCallOrThrow<{ invoicesRemoved: number }>(\n `/api/billing/runs/${encodeURIComponent(params.runId)}`,\n { method: 'DELETE' },\n )\n flash(t('billing.runs.delete.success', 'Run deleted'), 'success')\n return call.result?.invoicesRemoved ?? 0\n } catch (err) {\n const { message } = normalizeCrudServerError(err)\n flash(message || t('billing.runs.delete.error', 'Delete failed'), 'error')\n return null\n } finally {\n setBusy(null)\n }\n },\n [confirm, t],\n )\n\n return { wipe, remove, busy, ConfirmDialogElement }\n}\n\n/**\n * Cleanup buttons for a test / dry Bill Run: \"Wipe test invoices\" keeps the\n * run, \"Delete run\" removes it with its test invoices. Renders nothing for\n * real runs (they are never deleted).\n */\nexport function TestRunActions({ runId, mode, draftsCount, onWiped, onDeleted }: TestRunActionsProps) {\n const t = useT()\n const { wipe, remove, busy, ConfirmDialogElement } = useTestRunCleanup()\n\n if (mode === 'real') return null\n return (\n <>\n {mode === 'test' ? (\n <Button\n type=\"button\"\n variant=\"outline\"\n disabled={busy !== null}\n onClick={async () => {\n const removed = await wipe(runId)\n if (removed !== null) onWiped?.(removed)\n }}\n >\n <Eraser size={16} />\n {busy === 'wipe'\n ? t('billing.runs.wipe.in_progress', 'Wiping\u2026')\n : t('billing.runs.wipe.action', 'Wipe test invoices')}\n </Button>\n ) : null}\n <Button\n type=\"button\"\n variant=\"destructive\"\n disabled={busy !== null}\n onClick={async () => {\n const removed = await remove({ runId, mode, draftsCount })\n if (removed !== null) onDeleted?.(removed)\n }}\n >\n <Trash2 size={16} />\n {busy === 'delete'\n ? t('billing.runs.delete.in_progress', 'Deleting\u2026')\n : t('billing.runs.delete.action', 'Delete run')}\n </Button>\n {ConfirmDialogElement}\n </>\n )\n}\n"],
|
|
5
|
+
"mappings": ";AAqHI,mBAWM,KATF,YAFJ;AApHJ,YAAY,WAAW;AACvB,SAAS,QAAQ,cAAc;AAC/B,SAAS,YAAY;AACrB,SAAS,cAAc;AACvB,SAAS,aAAa;AACtB,SAAS,wBAAwB;AACjC,SAAS,sBAAsB;AAC/B,SAAS,gCAAgC;AAIlC,SAAS,YAAY,KAA4E;AACtG,MAAI,IAAI,QAAS,QAAO;AACxB,MAAI,IAAI,UAAW,QAAO;AAC1B,SAAO;AACT;AAiBO,SAAS,oBAAoB;AAClC,QAAM,IAAI,KAAK;AACf,QAAM,EAAE,SAAS,qBAAqB,IAAI,iBAAiB;AAC3D,QAAM,CAAC,MAAM,OAAO,IAAI,MAAM,SAAmC,IAAI;AAErE,QAAM,OAAO,MAAM;AAAA,IACjB,OAAO,UAA0C;AAC/C,YAAM,KAAK,MAAM,QAAQ;AAAA,QACvB,OAAO,EAAE,mCAAmC,qBAAqB;AAAA,QACjE,MAAM;AAAA,UACJ;AAAA,UACA;AAAA,QACF;AAAA,QACA,aAAa,EAAE,oCAAoC,sBAAsB;AAAA,QACzE,SAAS;AAAA,MACX,CAAC;AACD,UAAI,CAAC,GAAI,QAAO;AAChB,cAAQ,MAAM;AACd,UAAI;AACF,cAAM,OAAO,MAAM,eA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"react";
|
|
4
|
+
import { useRouter } from "next/navigation";
|
|
5
|
+
import { useT } from "@open-mercato/shared/lib/i18n/context";
|
|
6
|
+
import { BillingDataTable as DataTable } from "../BillingDataTable.js";
|
|
7
|
+
import { Tag } from "@open-mercato/ui/primitives/tag";
|
|
8
|
+
import { readApiResultOrThrow } from "@open-mercato/ui/backend/utils/apiCall";
|
|
9
|
+
import { itemBillingState } from "../../lib/itemBillingState.js";
|
|
10
|
+
import { formatDate } from "./accountRow.js";
|
|
11
|
+
function localToday() {
|
|
12
|
+
const now = /* @__PURE__ */ new Date();
|
|
13
|
+
const month = String(now.getMonth() + 1).padStart(2, "0");
|
|
14
|
+
const date = String(now.getDate()).padStart(2, "0");
|
|
15
|
+
return `${now.getFullYear()}-${month}-${date}`;
|
|
16
|
+
}
|
|
17
|
+
function stateVariant(state) {
|
|
18
|
+
switch (state.status) {
|
|
19
|
+
case "billed":
|
|
20
|
+
case "current":
|
|
21
|
+
case "fully_billed":
|
|
22
|
+
return "success";
|
|
23
|
+
case "awaiting_run":
|
|
24
|
+
case "due":
|
|
25
|
+
return "warning";
|
|
26
|
+
case "metered":
|
|
27
|
+
return "info";
|
|
28
|
+
default:
|
|
29
|
+
return "neutral";
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function AccountItemsTab({ accountId, currencyCode }) {
|
|
33
|
+
const t = useT();
|
|
34
|
+
const router = useRouter();
|
|
35
|
+
const [rows, setRows] = React.useState([]);
|
|
36
|
+
const [page, setPage] = React.useState(1);
|
|
37
|
+
const [total, setTotal] = React.useState(0);
|
|
38
|
+
const [totalPages, setTotalPages] = React.useState(1);
|
|
39
|
+
const [loading, setLoading] = React.useState(true);
|
|
40
|
+
const pageSize = 25;
|
|
41
|
+
const today = React.useMemo(() => localToday(), []);
|
|
42
|
+
const load = React.useCallback(async () => {
|
|
43
|
+
setLoading(true);
|
|
44
|
+
try {
|
|
45
|
+
const result = await readApiResultOrThrow(
|
|
46
|
+
`/api/billing/items?billAccountId=${accountId}&page=${page}&pageSize=${pageSize}&sortField=createdAt&sortDir=desc`
|
|
47
|
+
);
|
|
48
|
+
setRows(result.items ?? []);
|
|
49
|
+
setTotal(result.total ?? 0);
|
|
50
|
+
setTotalPages(result.totalPages ?? 1);
|
|
51
|
+
} finally {
|
|
52
|
+
setLoading(false);
|
|
53
|
+
}
|
|
54
|
+
}, [accountId, page]);
|
|
55
|
+
React.useEffect(() => {
|
|
56
|
+
void load();
|
|
57
|
+
}, [load]);
|
|
58
|
+
const typeLabel = React.useCallback(
|
|
59
|
+
(row) => {
|
|
60
|
+
if (row.type === "one_time") return t("billing.items.form.type.one_time", "One-time charge");
|
|
61
|
+
if (row.type === "usage") return t("billing.items.form.type.usage", "Usage (metered)");
|
|
62
|
+
return row.charge_timing === "in_arrears" ? t("billing.accounts.items.recurring_arrears", "Recurring \xB7 in arrears") : t("billing.accounts.items.recurring_advance", "Recurring \xB7 in advance");
|
|
63
|
+
},
|
|
64
|
+
[t]
|
|
65
|
+
);
|
|
66
|
+
const rateLabel = React.useCallback(
|
|
67
|
+
(row) => {
|
|
68
|
+
const rate = row.rate_json ?? {};
|
|
69
|
+
const amount = typeof rate.amount === "number" ? rate.amount : typeof rate.unit_price === "number" ? rate.unit_price : null;
|
|
70
|
+
if (amount === null) {
|
|
71
|
+
return "model" in rate ? `${t("billing.accounts.items.tiered", "Tiered")} (${String(rate.model)})` : "\u2014";
|
|
72
|
+
}
|
|
73
|
+
const perUnit = row.type === "usage" && row.uom_code ? ` / ${row.uom_code}` : "";
|
|
74
|
+
const basis = row.price_basis === "gross" ? t("billing.items.price_basis.gross", "Gross") : t("billing.items.price_basis.net", "Net");
|
|
75
|
+
return `${amount}${currencyCode ? ` ${currencyCode}` : ""}${perUnit} \xB7 ${basis}`;
|
|
76
|
+
},
|
|
77
|
+
[currencyCode, t]
|
|
78
|
+
);
|
|
79
|
+
const stateLabel = React.useCallback(
|
|
80
|
+
(state) => {
|
|
81
|
+
const date = state.date ? formatDate(state.date) : "";
|
|
82
|
+
switch (state.status) {
|
|
83
|
+
case "inactive":
|
|
84
|
+
return t("billing.common.inactive", "Inactive");
|
|
85
|
+
case "metered":
|
|
86
|
+
return t("billing.accounts.items.state.metered", "Billed from usage");
|
|
87
|
+
case "scheduled":
|
|
88
|
+
return `${t("billing.accounts.items.state.scheduled", "Starts")} ${date}`;
|
|
89
|
+
case "awaiting_run":
|
|
90
|
+
return t("billing.accounts.items.state.awaiting_run", "Not billed yet");
|
|
91
|
+
case "billed":
|
|
92
|
+
return t("billing.accounts.items.state.billed", "Billed");
|
|
93
|
+
case "current":
|
|
94
|
+
return `${t("billing.accounts.items.state.current", "Billed through")} ${date}`;
|
|
95
|
+
case "due":
|
|
96
|
+
return `${t("billing.accounts.items.state.due", "Due since")} ${date}`;
|
|
97
|
+
case "fully_billed":
|
|
98
|
+
return t("billing.accounts.items.state.fully_billed", "Fully billed");
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
[t]
|
|
102
|
+
);
|
|
103
|
+
const columns = React.useMemo(
|
|
104
|
+
() => [
|
|
105
|
+
{
|
|
106
|
+
accessorKey: "description",
|
|
107
|
+
header: t("billing.items.columns.description", "Description"),
|
|
108
|
+
cell: ({ row }) => /* @__PURE__ */ jsx("span", { className: "text-sm font-medium text-primary", children: row.original.description })
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
accessorKey: "type",
|
|
112
|
+
header: t("billing.items.columns.type", "Type"),
|
|
113
|
+
cell: ({ row }) => /* @__PURE__ */ jsx("span", { className: "text-sm", children: typeLabel(row.original) })
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
accessorKey: "rate_json",
|
|
117
|
+
header: t("billing.items.form.rate.title", "Rate"),
|
|
118
|
+
cell: ({ row }) => /* @__PURE__ */ jsx("span", { className: "text-sm tabular-nums", children: rateLabel(row.original) })
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
accessorKey: "bill_start_date",
|
|
122
|
+
header: t("billing.accounts.items.term", "Term"),
|
|
123
|
+
cell: ({ row }) => `${formatDate(row.original.bill_start_date)} \u2013 ${row.original.bill_end_date ? formatDate(row.original.bill_end_date) : t("billing.accounts.items.open_ended", "open-ended")}`
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
accessorKey: "billed_to_date",
|
|
127
|
+
header: t("billing.accounts.items.billed_through", "Billed through"),
|
|
128
|
+
cell: ({ row }) => row.original.type === "recurring" && row.original.billed_to_date ? formatDate(row.original.billed_to_date) : "\u2014"
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
id: "billing_state",
|
|
132
|
+
header: t("billing.accounts.items.state", "Billing"),
|
|
133
|
+
cell: ({ row }) => {
|
|
134
|
+
const state = itemBillingState(row.original, today);
|
|
135
|
+
return /* @__PURE__ */ jsx(Tag, { variant: stateVariant(state), children: stateLabel(state) });
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
],
|
|
139
|
+
[rateLabel, stateLabel, t, today, typeLabel]
|
|
140
|
+
);
|
|
141
|
+
return /* @__PURE__ */ jsx(
|
|
142
|
+
DataTable,
|
|
143
|
+
{
|
|
144
|
+
title: t("billing.accounts.detail.items.title", "Items"),
|
|
145
|
+
columns,
|
|
146
|
+
data: rows,
|
|
147
|
+
isLoading: loading,
|
|
148
|
+
onRowClick: (row) => router.push(`/backend/billing/items/${row.id}`),
|
|
149
|
+
pagination: { page, pageSize, total, totalPages, onPageChange: setPage },
|
|
150
|
+
emptyState: /* @__PURE__ */ jsx("div", { className: "rounded-lg border bg-card p-6 text-center text-sm text-muted-foreground", children: t("billing.accounts.detail.items.empty", "No items for this account yet.") })
|
|
151
|
+
}
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
export {
|
|
155
|
+
AccountItemsTab
|
|
156
|
+
};
|
|
157
|
+
//# sourceMappingURL=AccountItemsTab.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/modules/billing/components/account/AccountItemsTab.tsx"],
|
|
4
|
+
"sourcesContent": ["\"use client\"\nimport * as React from 'react'\nimport { useRouter } from 'next/navigation'\nimport type { LegacyColumnDef as ColumnDef } from '@tanstack/react-table/legacy'\nimport { useT } from '@open-mercato/shared/lib/i18n/context'\nimport { BillingDataTable as DataTable } from '../BillingDataTable'\nimport { Tag } from '@open-mercato/ui/primitives/tag'\nimport { readApiResultOrThrow } from '@open-mercato/ui/backend/utils/apiCall'\nimport { itemBillingState, type ItemBillingState } from '../../lib/itemBillingState'\nimport { formatDate } from './accountRow'\n\n// Snake_case projection of `GET /api/billing/items` (see its `fields`).\ntype AccountItemRow = {\n id: string\n description: string\n type: 'one_time' | 'recurring' | 'usage'\n bill_start_date: string\n bill_end_date: string | null\n billed_to_date: string | null\n rate_json: Record<string, unknown> | null\n charge_timing: 'in_advance' | 'in_arrears'\n price_basis?: 'net' | 'gross'\n uom_code: string | null\n is_active: boolean\n}\n\nfunction localToday(): string {\n const now = new Date()\n const month = String(now.getMonth() + 1).padStart(2, '0')\n const date = String(now.getDate()).padStart(2, '0')\n return `${now.getFullYear()}-${month}-${date}`\n}\n\nfunction stateVariant(state: ItemBillingState): 'success' | 'warning' | 'neutral' | 'info' {\n switch (state.status) {\n case 'billed':\n case 'current':\n case 'fully_billed':\n return 'success'\n case 'awaiting_run':\n case 'due':\n return 'warning'\n case 'metered':\n return 'info'\n default:\n return 'neutral'\n }\n}\n\n/**\n * The account's billing items (workspace Items tab): what each item costs,\n * its term, how far it has been billed and \u2014 against today \u2014 whether a Bill\n * Run still has to charge it.\n */\nexport function AccountItemsTab({ accountId, currencyCode }: { accountId: string; currencyCode?: string }) {\n const t = useT()\n const router = useRouter()\n const [rows, setRows] = React.useState<AccountItemRow[]>([])\n const [page, setPage] = React.useState(1)\n const [total, setTotal] = React.useState(0)\n const [totalPages, setTotalPages] = React.useState(1)\n const [loading, setLoading] = React.useState(true)\n const pageSize = 25\n const today = React.useMemo(() => localToday(), [])\n\n const load = React.useCallback(async () => {\n setLoading(true)\n try {\n const result = await readApiResultOrThrow<{ items: AccountItemRow[]; total: number; totalPages: number }>(\n `/api/billing/items?billAccountId=${accountId}&page=${page}` + `&pageSize=${pageSize}&sortField=createdAt&sortDir=desc`,\n )\n setRows(result.items ?? [])\n setTotal(result.total ?? 0)\n setTotalPages(result.totalPages ?? 1)\n } finally {\n setLoading(false)\n }\n }, [accountId, page])\n\n React.useEffect(() => {\n void load()\n }, [load])\n\n const typeLabel = React.useCallback(\n (row: AccountItemRow) => {\n if (row.type === 'one_time') return t('billing.items.form.type.one_time', 'One-time charge')\n if (row.type === 'usage') return t('billing.items.form.type.usage', 'Usage (metered)')\n return row.charge_timing === 'in_arrears'\n ? t('billing.accounts.items.recurring_arrears', 'Recurring \u00B7 in arrears')\n : t('billing.accounts.items.recurring_advance', 'Recurring \u00B7 in advance')\n },\n [t],\n )\n\n const rateLabel = React.useCallback(\n (row: AccountItemRow) => {\n const rate = row.rate_json ?? {}\n const amount = typeof rate.amount === 'number' ? rate.amount : typeof rate.unit_price === 'number' ? rate.unit_price : null\n if (amount === null) {\n return 'model' in rate ? `${t('billing.accounts.items.tiered', 'Tiered')} (${String(rate.model)})` : '\u2014'\n }\n const perUnit = row.type === 'usage' && row.uom_code ? ` / ${row.uom_code}` : ''\n const basis = row.price_basis === 'gross' ? t('billing.items.price_basis.gross', 'Gross') : t('billing.items.price_basis.net', 'Net')\n return `${amount}${currencyCode ? ` ${currencyCode}` : ''}${perUnit} \u00B7 ${basis}`\n },\n [currencyCode, t],\n )\n\n const stateLabel = React.useCallback(\n (state: ItemBillingState) => {\n const date = state.date ? formatDate(state.date) : ''\n switch (state.status) {\n case 'inactive':\n return t('billing.common.inactive', 'Inactive')\n case 'metered':\n return t('billing.accounts.items.state.metered', 'Billed from usage')\n case 'scheduled':\n return `${t('billing.accounts.items.state.scheduled', 'Starts')} ${date}`\n case 'awaiting_run':\n return t('billing.accounts.items.state.awaiting_run', 'Not billed yet')\n case 'billed':\n return t('billing.accounts.items.state.billed', 'Billed')\n case 'current':\n return `${t('billing.accounts.items.state.current', 'Billed through')} ${date}`\n case 'due':\n return `${t('billing.accounts.items.state.due', 'Due since')} ${date}`\n case 'fully_billed':\n return t('billing.accounts.items.state.fully_billed', 'Fully billed')\n }\n },\n [t],\n )\n\n const columns = React.useMemo<ColumnDef<AccountItemRow>[]>(\n () => [\n {\n accessorKey: 'description',\n header: t('billing.items.columns.description', 'Description'),\n cell: ({ row }) => <span className=\"text-sm font-medium text-primary\">{row.original.description}</span>,\n },\n {\n accessorKey: 'type',\n header: t('billing.items.columns.type', 'Type'),\n cell: ({ row }) => <span className=\"text-sm\">{typeLabel(row.original)}</span>,\n },\n {\n accessorKey: 'rate_json',\n header: t('billing.items.form.rate.title', 'Rate'),\n cell: ({ row }) => <span className=\"text-sm tabular-nums\">{rateLabel(row.original)}</span>,\n },\n {\n accessorKey: 'bill_start_date',\n header: t('billing.accounts.items.term', 'Term'),\n cell: ({ row }) =>\n `${formatDate(row.original.bill_start_date)} \u2013 ${\n row.original.bill_end_date ? formatDate(row.original.bill_end_date) : t('billing.accounts.items.open_ended', 'open-ended')\n }`,\n },\n {\n accessorKey: 'billed_to_date',\n header: t('billing.accounts.items.billed_through', 'Billed through'),\n cell: ({ row }) =>\n row.original.type === 'recurring' && row.original.billed_to_date ? formatDate(row.original.billed_to_date) : '\u2014',\n },\n {\n id: 'billing_state',\n header: t('billing.accounts.items.state', 'Billing'),\n cell: ({ row }) => {\n const state = itemBillingState(row.original, today)\n return <Tag variant={stateVariant(state)}>{stateLabel(state)}</Tag>\n },\n },\n ],\n [rateLabel, stateLabel, t, today, typeLabel],\n )\n\n return (\n <DataTable\n title={t('billing.accounts.detail.items.title', 'Items')}\n columns={columns}\n data={rows}\n isLoading={loading}\n onRowClick={(row) => router.push(`/backend/billing/items/${row.id}`)}\n pagination={{ page, pageSize, total, totalPages, onPageChange: setPage }}\n emptyState={\n <div className=\"rounded-lg border bg-card p-6 text-center text-sm text-muted-foreground\">\n {t('billing.accounts.detail.items.empty', 'No items for this account yet.')}\n </div>\n }\n />\n )\n}\n"],
|
|
5
|
+
"mappings": ";AA0I2B;AAzI3B,YAAY,WAAW;AACvB,SAAS,iBAAiB;AAE1B,SAAS,YAAY;AACrB,SAAS,oBAAoB,iBAAiB;AAC9C,SAAS,WAAW;AACpB,SAAS,4BAA4B;AACrC,SAAS,wBAA+C;AACxD,SAAS,kBAAkB;AAiB3B,SAAS,aAAqB;AAC5B,QAAM,MAAM,oBAAI,KAAK;AACrB,QAAM,QAAQ,OAAO,IAAI,SAAS,IAAI,CAAC,EAAE,SAAS,GAAG,GAAG;AACxD,QAAM,OAAO,OAAO,IAAI,QAAQ,CAAC,EAAE,SAAS,GAAG,GAAG;AAClD,SAAO,GAAG,IAAI,YAAY,CAAC,IAAI,KAAK,IAAI,IAAI;AAC9C;AAEA,SAAS,aAAa,OAAqE;AACzF,UAAQ,MAAM,QAAQ;AAAA,IACpB,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AAAA,IACL,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT;AACE,aAAO;AAAA,EACX;AACF;AAOO,SAAS,gBAAgB,EAAE,WAAW,aAAa,GAAiD;AACzG,QAAM,IAAI,KAAK;AACf,QAAM,SAAS,UAAU;AACzB,QAAM,CAAC,MAAM,OAAO,IAAI,MAAM,SAA2B,CAAC,CAAC;AAC3D,QAAM,CAAC,MAAM,OAAO,IAAI,MAAM,SAAS,CAAC;AACxC,QAAM,CAAC,OAAO,QAAQ,IAAI,MAAM,SAAS,CAAC;AAC1C,QAAM,CAAC,YAAY,aAAa,IAAI,MAAM,SAAS,CAAC;AACpD,QAAM,CAAC,SAAS,UAAU,IAAI,MAAM,SAAS,IAAI;AACjD,QAAM,WAAW;AACjB,QAAM,QAAQ,MAAM,QAAQ,MAAM,WAAW,GAAG,CAAC,CAAC;AAElD,QA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0,0 +1,122 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { Play } from "lucide-react";
|
|
5
|
+
import { useT } from "@open-mercato/shared/lib/i18n/context";
|
|
6
|
+
import { Button } from "@open-mercato/ui/primitives/button";
|
|
7
|
+
import { Input } from "@open-mercato/ui/primitives/input";
|
|
8
|
+
import { Kbd, KbdShortcut } from "@open-mercato/ui/primitives/kbd";
|
|
9
|
+
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@open-mercato/ui/primitives/select";
|
|
10
|
+
import {
|
|
11
|
+
Dialog,
|
|
12
|
+
DialogContent,
|
|
13
|
+
DialogDescription,
|
|
14
|
+
DialogFooter,
|
|
15
|
+
DialogHeader,
|
|
16
|
+
DialogTitle
|
|
17
|
+
} from "@open-mercato/ui/primitives/dialog";
|
|
18
|
+
import { flash } from "@open-mercato/ui/backend/FlashMessages";
|
|
19
|
+
import { apiCallOrThrow, readApiResultOrThrow } from "@open-mercato/ui/backend/utils/apiCall";
|
|
20
|
+
import { normalizeCrudServerError } from "@open-mercato/ui/backend/utils/serverErrors";
|
|
21
|
+
function todayIso() {
|
|
22
|
+
return (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
23
|
+
}
|
|
24
|
+
function AccountRunBillingDialog({ accountId, open, onOpenChange, onCompleted }) {
|
|
25
|
+
const t = useT();
|
|
26
|
+
const [mode, setMode] = React.useState("test");
|
|
27
|
+
const [asOfDate, setAsOfDate] = React.useState(todayIso());
|
|
28
|
+
const [running, setRunning] = React.useState(false);
|
|
29
|
+
React.useEffect(() => {
|
|
30
|
+
if (open) {
|
|
31
|
+
setMode("test");
|
|
32
|
+
setAsOfDate(todayIso());
|
|
33
|
+
}
|
|
34
|
+
}, [open]);
|
|
35
|
+
const handleRun = React.useCallback(async () => {
|
|
36
|
+
setRunning(true);
|
|
37
|
+
try {
|
|
38
|
+
const call = await apiCallOrThrow("/api/billing/runs", {
|
|
39
|
+
method: "POST",
|
|
40
|
+
headers: { "Content-Type": "application/json" },
|
|
41
|
+
body: JSON.stringify({ mode, asOfDate, scopedAccountIds: [accountId] })
|
|
42
|
+
});
|
|
43
|
+
const billRunId = call.result?.billRunId;
|
|
44
|
+
if (!billRunId) throw new Error(t("billing.runs.trigger.error", "Failed to trigger run"));
|
|
45
|
+
const outcomes = await readApiResultOrThrow(
|
|
46
|
+
`/api/billing/run-outcomes?billRunId=${encodeURIComponent(billRunId)}&pageSize=1`
|
|
47
|
+
);
|
|
48
|
+
const outcome = outcomes.items?.[0];
|
|
49
|
+
if (!outcome) {
|
|
50
|
+
flash(t("billing.accounts.run.nothing_due", "Nothing is due up to this date \u2014 the next bill date is later."), "info");
|
|
51
|
+
} else if (outcome.status === "failed") {
|
|
52
|
+
flash(`${t("billing.accounts.run.failed", "Bill run failed")}: ${outcome.error_message ?? ""}`, "error");
|
|
53
|
+
} else {
|
|
54
|
+
const cycles = (outcome.cycles ?? []).filter((cycle) => cycle.status !== "empty").length;
|
|
55
|
+
flash(`${t("billing.accounts.run.done", "Bill run completed \u2014 bill dates with charges:")} ${cycles}`, "success");
|
|
56
|
+
}
|
|
57
|
+
onCompleted(billRunId);
|
|
58
|
+
} catch (err) {
|
|
59
|
+
const { message } = normalizeCrudServerError(err);
|
|
60
|
+
flash(message || t("billing.runs.trigger.error", "Failed to trigger run"), "error");
|
|
61
|
+
} finally {
|
|
62
|
+
setRunning(false);
|
|
63
|
+
}
|
|
64
|
+
}, [accountId, asOfDate, mode, onCompleted, t]);
|
|
65
|
+
const handleKeyDown = React.useCallback(
|
|
66
|
+
(event) => {
|
|
67
|
+
if ((event.metaKey || event.ctrlKey) && event.key === "Enter") {
|
|
68
|
+
event.preventDefault();
|
|
69
|
+
if (!running) void handleRun();
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
[handleRun, running]
|
|
73
|
+
);
|
|
74
|
+
return /* @__PURE__ */ jsx(Dialog, { open, onOpenChange: (next) => !running ? onOpenChange(next) : void 0, children: /* @__PURE__ */ jsxs(DialogContent, { onKeyDown: handleKeyDown, children: [
|
|
75
|
+
/* @__PURE__ */ jsxs(DialogHeader, { children: [
|
|
76
|
+
/* @__PURE__ */ jsx(DialogTitle, { children: t("billing.accounts.run.title", "Run billing for this account") }),
|
|
77
|
+
/* @__PURE__ */ jsx(DialogDescription, { children: t(
|
|
78
|
+
"billing.accounts.run.description",
|
|
79
|
+
"Bills every due cycle of this account up to the as-of date. Test and dry runs change nothing on the account."
|
|
80
|
+
) })
|
|
81
|
+
] }),
|
|
82
|
+
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 gap-4 sm:grid-cols-2", children: [
|
|
83
|
+
/* @__PURE__ */ jsxs("label", { className: "flex flex-col gap-1 text-sm", children: [
|
|
84
|
+
/* @__PURE__ */ jsx("span", { className: "text-muted-foreground", children: t("billing.runs.trigger.dialog.mode", "Mode") }),
|
|
85
|
+
/* @__PURE__ */ jsxs(Select, { value: mode, onValueChange: (next) => setMode(next === "real" || next === "dry" ? next : "test"), children: [
|
|
86
|
+
/* @__PURE__ */ jsx(SelectTrigger, { children: /* @__PURE__ */ jsx(SelectValue, {}) }),
|
|
87
|
+
/* @__PURE__ */ jsxs(SelectContent, { children: [
|
|
88
|
+
/* @__PURE__ */ jsx(SelectItem, { value: "test", children: t("billing.runs.trigger.dialog.mode.test", "Test \u2014 drafts tagged for cleanup") }),
|
|
89
|
+
/* @__PURE__ */ jsx(SelectItem, { value: "dry", children: t("billing.runs.trigger.dialog.mode.dry", "Dry-run \u2014 no rows written") }),
|
|
90
|
+
/* @__PURE__ */ jsx(SelectItem, { value: "real", children: t("billing.runs.trigger.dialog.mode.real", "Real \u2014 create draft invoices") })
|
|
91
|
+
] })
|
|
92
|
+
] })
|
|
93
|
+
] }),
|
|
94
|
+
/* @__PURE__ */ jsxs("label", { className: "flex flex-col gap-1 text-sm", children: [
|
|
95
|
+
/* @__PURE__ */ jsx("span", { className: "text-muted-foreground", children: t("billing.runs.trigger.dialog.as_of_date", "As-of date") }),
|
|
96
|
+
/* @__PURE__ */ jsx(Input, { type: "date", value: asOfDate, onChange: (event) => setAsOfDate(event.currentTarget.value) })
|
|
97
|
+
] })
|
|
98
|
+
] }),
|
|
99
|
+
/* @__PURE__ */ jsxs(DialogFooter, { className: "flex items-center justify-between gap-3 sm:justify-between", children: [
|
|
100
|
+
/* @__PURE__ */ jsxs("span", { className: "text-xs text-muted-foreground", children: [
|
|
101
|
+
/* @__PURE__ */ jsx(KbdShortcut, { keys: ["Ctrl/\u2318", "Enter"] }),
|
|
102
|
+
" ",
|
|
103
|
+
t("billing.accounts.run.submit_hint", "to run,"),
|
|
104
|
+
" ",
|
|
105
|
+
/* @__PURE__ */ jsx(Kbd, { children: "Esc" }),
|
|
106
|
+
" ",
|
|
107
|
+
t("billing.accounts.run.close_hint", "to close")
|
|
108
|
+
] }),
|
|
109
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
110
|
+
/* @__PURE__ */ jsx(Button, { type: "button", variant: "outline", onClick: () => onOpenChange(false), disabled: running, children: t("billing.common.cancel", "Cancel") }),
|
|
111
|
+
/* @__PURE__ */ jsxs(Button, { type: "button", onClick: () => void handleRun(), disabled: running, children: [
|
|
112
|
+
/* @__PURE__ */ jsx(Play, { size: 16 }),
|
|
113
|
+
running ? t("billing.accounts.run.running", "Running\u2026") : t("billing.accounts.run.action", "Run billing")
|
|
114
|
+
] })
|
|
115
|
+
] })
|
|
116
|
+
] })
|
|
117
|
+
] }) });
|
|
118
|
+
}
|
|
119
|
+
export {
|
|
120
|
+
AccountRunBillingDialog
|
|
121
|
+
};
|
|
122
|
+
//# sourceMappingURL=AccountRunBillingDialog.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/modules/billing/components/account/AccountRunBillingDialog.tsx"],
|
|
4
|
+
"sourcesContent": ["\"use client\"\nimport * as React from 'react'\nimport { Play } from 'lucide-react'\nimport { useT } from '@open-mercato/shared/lib/i18n/context'\nimport { Button } from '@open-mercato/ui/primitives/button'\nimport { Input } from '@open-mercato/ui/primitives/input'\nimport { Kbd, KbdShortcut } from '@open-mercato/ui/primitives/kbd'\nimport { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@open-mercato/ui/primitives/select'\nimport {\n Dialog,\n DialogContent,\n DialogDescription,\n DialogFooter,\n DialogHeader,\n DialogTitle,\n} from '@open-mercato/ui/primitives/dialog'\nimport { flash } from '@open-mercato/ui/backend/FlashMessages'\nimport { apiCallOrThrow, readApiResultOrThrow } from '@open-mercato/ui/backend/utils/apiCall'\nimport { normalizeCrudServerError } from '@open-mercato/ui/backend/utils/serverErrors'\nimport type { BillRunMode } from '../TestRunActions'\n\n/**\n * \"Run billing\" for one account (Spec E, E2-D3 / Spec F, F8): mode (Test by\n * default) + as-of date \u2192 `POST /api/billing/runs` with\n * `scopedAccountIds: [id]`. On success the dialog closes with a one-line\n * summary; the workspace switches to its Bill runs tab, where the run (with\n * its mode, documents and cleanup actions) is listed.\n */\n\ntype OutcomeRow = { status: string; error_message: string | null; cycles: Array<{ status: string }> | null }\n\nfunction todayIso(): string {\n return new Date().toISOString().slice(0, 10)\n}\n\nexport type AccountRunBillingDialogProps = {\n accountId: string\n open: boolean\n onOpenChange: (open: boolean) => void\n /** Called after a run finished \u2014 the workspace closes the dialog and refreshes. */\n onCompleted: (billRunId: string) => void\n}\n\nexport function AccountRunBillingDialog({ accountId, open, onOpenChange, onCompleted }: AccountRunBillingDialogProps) {\n const t = useT()\n const [mode, setMode] = React.useState<BillRunMode>('test')\n const [asOfDate, setAsOfDate] = React.useState<string>(todayIso())\n const [running, setRunning] = React.useState(false)\n\n React.useEffect(() => {\n if (open) {\n setMode('test')\n setAsOfDate(todayIso())\n }\n }, [open])\n\n const handleRun = React.useCallback(async () => {\n setRunning(true)\n try {\n const call = await apiCallOrThrow<{ billRunId: string | null }>('/api/billing/runs', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ mode, asOfDate, scopedAccountIds: [accountId] }),\n })\n const billRunId = call.result?.billRunId\n if (!billRunId) throw new Error(t('billing.runs.trigger.error', 'Failed to trigger run'))\n const outcomes = await readApiResultOrThrow<{ items: OutcomeRow[] }>(\n `/api/billing/run-outcomes?billRunId=${encodeURIComponent(billRunId)}&pageSize=1`,\n )\n const outcome = outcomes.items?.[0]\n if (!outcome) {\n flash(t('billing.accounts.run.nothing_due', 'Nothing is due up to this date \u2014 the next bill date is later.'), 'info')\n } else if (outcome.status === 'failed') {\n flash(`${t('billing.accounts.run.failed', 'Bill run failed')}: ${outcome.error_message ?? ''}`, 'error')\n } else {\n const cycles = (outcome.cycles ?? []).filter((cycle) => cycle.status !== 'empty').length\n flash(`${t('billing.accounts.run.done', 'Bill run completed \u2014 bill dates with charges:')} ${cycles}`, 'success')\n }\n onCompleted(billRunId)\n } catch (err) {\n const { message } = normalizeCrudServerError(err)\n flash(message || t('billing.runs.trigger.error', 'Failed to trigger run'), 'error')\n } finally {\n setRunning(false)\n }\n }, [accountId, asOfDate, mode, onCompleted, t])\n\n const handleKeyDown = React.useCallback(\n (event: React.KeyboardEvent<HTMLDivElement>) => {\n if ((event.metaKey || event.ctrlKey) && event.key === 'Enter') {\n event.preventDefault()\n if (!running) void handleRun()\n }\n },\n [handleRun, running],\n )\n\n return (\n <Dialog open={open} onOpenChange={(next) => (!running ? onOpenChange(next) : undefined)}>\n <DialogContent onKeyDown={handleKeyDown}>\n <DialogHeader>\n <DialogTitle>{t('billing.accounts.run.title', 'Run billing for this account')}</DialogTitle>\n <DialogDescription>\n {t(\n 'billing.accounts.run.description',\n 'Bills every due cycle of this account up to the as-of date. Test and dry runs change nothing on the account.',\n )}\n </DialogDescription>\n </DialogHeader>\n <div className=\"grid grid-cols-1 gap-4 sm:grid-cols-2\">\n <label className=\"flex flex-col gap-1 text-sm\">\n <span className=\"text-muted-foreground\">{t('billing.runs.trigger.dialog.mode', 'Mode')}</span>\n <Select value={mode} onValueChange={(next) => setMode(next === 'real' || next === 'dry' ? next : 'test')}>\n <SelectTrigger>\n <SelectValue />\n </SelectTrigger>\n <SelectContent>\n <SelectItem value=\"test\">{t('billing.runs.trigger.dialog.mode.test', 'Test \u2014 drafts tagged for cleanup')}</SelectItem>\n <SelectItem value=\"dry\">{t('billing.runs.trigger.dialog.mode.dry', 'Dry-run \u2014 no rows written')}</SelectItem>\n <SelectItem value=\"real\">{t('billing.runs.trigger.dialog.mode.real', 'Real \u2014 create draft invoices')}</SelectItem>\n </SelectContent>\n </Select>\n </label>\n <label className=\"flex flex-col gap-1 text-sm\">\n <span className=\"text-muted-foreground\">{t('billing.runs.trigger.dialog.as_of_date', 'As-of date')}</span>\n <Input type=\"date\" value={asOfDate} onChange={(event) => setAsOfDate(event.currentTarget.value)} />\n </label>\n </div>\n <DialogFooter className=\"flex items-center justify-between gap-3 sm:justify-between\">\n <span className=\"text-xs text-muted-foreground\">\n <KbdShortcut keys={['Ctrl/\u2318', 'Enter']} /> {t('billing.accounts.run.submit_hint', 'to run,')} <Kbd>Esc</Kbd>{' '}\n {t('billing.accounts.run.close_hint', 'to close')}\n </span>\n <div className=\"flex items-center gap-2\">\n <Button type=\"button\" variant=\"outline\" onClick={() => onOpenChange(false)} disabled={running}>\n {t('billing.common.cancel', 'Cancel')}\n </Button>\n <Button type=\"button\" onClick={() => void handleRun()} disabled={running}>\n <Play size={16} />\n {running ? t('billing.accounts.run.running', 'Running\u2026') : t('billing.accounts.run.action', 'Run billing')}\n </Button>\n </div>\n </DialogFooter>\n </DialogContent>\n </Dialog>\n )\n}\n"],
|
|
5
|
+
"mappings": ";AAoGQ,SACE,KADF;AAnGR,YAAY,WAAW;AACvB,SAAS,YAAY;AACrB,SAAS,YAAY;AACrB,SAAS,cAAc;AACvB,SAAS,aAAa;AACtB,SAAS,KAAK,mBAAmB;AACjC,SAAS,QAAQ,eAAe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"use client";
|
|
2
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import Link from "next/link";
|
|
5
|
+
import { useT } from "@open-mercato/shared/lib/i18n/context";
|
|
6
|
+
import { BillingDataTable as DataTable } from "../BillingDataTable.js";
|
|
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 } from "../TestRunActions.js";
|
|
11
|
+
const PAGE_SIZE = 20;
|
|
12
|
+
function statusVariant(status) {
|
|
13
|
+
if (status === "success") return "success";
|
|
14
|
+
if (status === "failed") return "error";
|
|
15
|
+
if (status === "success_with_warnings" || status.startsWith("skipped")) return "warning";
|
|
16
|
+
return "neutral";
|
|
17
|
+
}
|
|
18
|
+
function AccountRunsTab({ accountId, refreshKey = 0 }) {
|
|
19
|
+
const t = useT();
|
|
20
|
+
const [rows, setRows] = React.useState([]);
|
|
21
|
+
const [page, setPage] = React.useState(1);
|
|
22
|
+
const [total, setTotal] = React.useState(0);
|
|
23
|
+
const [totalPages, setTotalPages] = React.useState(1);
|
|
24
|
+
const [loading, setLoading] = React.useState(true);
|
|
25
|
+
const [error, setError] = React.useState(null);
|
|
26
|
+
const cleanup = useTestRunCleanup();
|
|
27
|
+
const load = React.useCallback(async () => {
|
|
28
|
+
setLoading(true);
|
|
29
|
+
setError(null);
|
|
30
|
+
try {
|
|
31
|
+
const params = new URLSearchParams({
|
|
32
|
+
billAccountId: accountId,
|
|
33
|
+
page: String(page),
|
|
34
|
+
pageSize: String(PAGE_SIZE),
|
|
35
|
+
sortField: "createdAt",
|
|
36
|
+
sortDir: "desc"
|
|
37
|
+
});
|
|
38
|
+
const result = await readApiResultOrThrow(`/api/billing/run-outcomes?${params.toString()}`);
|
|
39
|
+
setRows(result.items ?? []);
|
|
40
|
+
setTotal(result.total ?? 0);
|
|
41
|
+
setTotalPages(result.totalPages ?? 1);
|
|
42
|
+
} catch {
|
|
43
|
+
setError(t("billing.accounts.runs.error", "Failed to load bill runs"));
|
|
44
|
+
} finally {
|
|
45
|
+
setLoading(false);
|
|
46
|
+
}
|
|
47
|
+
}, [accountId, page, t]);
|
|
48
|
+
React.useEffect(() => {
|
|
49
|
+
void load();
|
|
50
|
+
}, [load, refreshKey]);
|
|
51
|
+
const columns = React.useMemo(
|
|
52
|
+
() => [
|
|
53
|
+
{
|
|
54
|
+
accessorKey: "created_at",
|
|
55
|
+
header: t("billing.accounts.runs.columns.when", "Run at"),
|
|
56
|
+
cell: ({ row }) => /* @__PURE__ */ jsx(Link, { href: `/backend/billing/runs/${row.original.bill_run_id}`, className: "text-primary hover:underline", children: new Date(row.original.created_at).toLocaleString() })
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
accessorKey: "run_mode",
|
|
60
|
+
header: t("billing.runs.detail.field.mode", "Mode"),
|
|
61
|
+
cell: ({ row }) => row.original.run_mode === "dry" ? /* @__PURE__ */ jsx(Tag, { variant: "warning", children: t("billing.runs.mode.dry_run", "Dry-run") }) : row.original.run_mode === "test" ? /* @__PURE__ */ jsx(Tag, { variant: "warning", children: t("billing.runs.mode.test", "Test") }) : /* @__PURE__ */ jsx(Tag, { variant: "default", children: t("billing.runs.mode.real", "Real") })
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
accessorKey: "run_as_of_date",
|
|
65
|
+
header: t("billing.runs.columns.as_of_date", "As-of date"),
|
|
66
|
+
cell: ({ row }) => row.original.run_as_of_date ?? "\u2014"
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
accessorKey: "status",
|
|
70
|
+
header: t("billing.runs.outcomes.columns.status", "Status"),
|
|
71
|
+
cell: ({ row }) => /* @__PURE__ */ jsx(Tag, { variant: statusVariant(row.original.status), children: row.original.status })
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
id: "cycles",
|
|
75
|
+
header: t("billing.accounts.runs.columns.cycles", "Bill dates"),
|
|
76
|
+
cell: ({ row }) => {
|
|
77
|
+
const cycles = row.original.cycles ?? [];
|
|
78
|
+
if (cycles.length === 0) return "\u2014";
|
|
79
|
+
return cycles.map((cycle) => cycle.bill_date).join(", ");
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
id: "documents",
|
|
84
|
+
header: t("billing.accounts.runs.columns.documents", "Documents"),
|
|
85
|
+
cell: ({ row }) => {
|
|
86
|
+
const cycles = row.original.cycles ?? [];
|
|
87
|
+
const links = cycles.flatMap(
|
|
88
|
+
(cycle) => cycle.invoice_id ? [
|
|
89
|
+
/* @__PURE__ */ jsx(Link, { href: `/backend/billing/invoices/${cycle.invoice_id}`, className: "text-primary hover:underline", children: cycle.invoice_number ?? cycle.invoice_id.slice(0, 8) }, cycle.invoice_id)
|
|
90
|
+
] : cycle.statement_id ? [
|
|
91
|
+
/* @__PURE__ */ jsxs(Link, { href: `/backend/billing/statements/${cycle.statement_id}`, className: "text-primary hover:underline", children: [
|
|
92
|
+
t("billing.runs.cycles.statement", "Statement"),
|
|
93
|
+
" ",
|
|
94
|
+
cycle.bill_date
|
|
95
|
+
] }, cycle.statement_id)
|
|
96
|
+
] : []
|
|
97
|
+
);
|
|
98
|
+
if (links.length === 0) return row.original.error_message ?? "\u2014";
|
|
99
|
+
return /* @__PURE__ */ jsx("span", { className: "flex flex-wrap gap-x-3 gap-y-1", children: links });
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
],
|
|
103
|
+
[t]
|
|
104
|
+
);
|
|
105
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
106
|
+
/* @__PURE__ */ jsx(
|
|
107
|
+
DataTable,
|
|
108
|
+
{
|
|
109
|
+
title: t("billing.accounts.tabs.runs", "Bill runs"),
|
|
110
|
+
columns,
|
|
111
|
+
data: rows,
|
|
112
|
+
isLoading: loading,
|
|
113
|
+
error,
|
|
114
|
+
pagination: { page, pageSize: PAGE_SIZE, total, totalPages, onPageChange: setPage },
|
|
115
|
+
emptyState: t("billing.accounts.runs.empty", "No bill runs for this account yet."),
|
|
116
|
+
rowActions: (row) => /* @__PURE__ */ jsx(
|
|
117
|
+
RowActions,
|
|
118
|
+
{
|
|
119
|
+
items: [
|
|
120
|
+
{ id: "open", label: t("billing.runs.actions.open", "Open"), href: `/backend/billing/runs/${row.bill_run_id}` },
|
|
121
|
+
...row.run_mode === "test" ? [
|
|
122
|
+
{
|
|
123
|
+
id: "wipe",
|
|
124
|
+
label: t("billing.runs.wipe.action", "Wipe test invoices"),
|
|
125
|
+
onSelect: async () => {
|
|
126
|
+
if (await cleanup.wipe(row.bill_run_id) !== null) void load();
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
] : [],
|
|
130
|
+
...row.run_mode === "test" || row.run_mode === "dry" ? [
|
|
131
|
+
{
|
|
132
|
+
id: "delete",
|
|
133
|
+
label: t("billing.runs.delete.action", "Delete run"),
|
|
134
|
+
destructive: true,
|
|
135
|
+
onSelect: async () => {
|
|
136
|
+
const removed = await cleanup.remove({ runId: row.bill_run_id, mode: row.run_mode ?? "test" });
|
|
137
|
+
if (removed !== null) void load();
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
] : []
|
|
141
|
+
]
|
|
142
|
+
}
|
|
143
|
+
)
|
|
144
|
+
}
|
|
145
|
+
),
|
|
146
|
+
cleanup.ConfirmDialogElement
|
|
147
|
+
] });
|
|
148
|
+
}
|
|
149
|
+
export {
|
|
150
|
+
AccountRunsTab
|
|
151
|
+
};
|
|
152
|
+
//# sourceMappingURL=AccountRunsTab.js.map
|