@dainamite/billing 0.20.0 → 0.22.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 +103 -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 +47 -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 +70 -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/de.json +880 -0
- package/dist/modules/billing/i18n/en.json +457 -21
- package/dist/modules/billing/i18n/es.json +880 -0
- package/dist/modules/billing/i18n/pl.json +458 -22
- 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 +133 -0
- package/dist/modules/billing/lib/invoiceDelivery.js.map +7 -0
- package/dist/modules/billing/lib/invoiceLanguages.js +28 -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 +276 -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 +171 -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__/i18n/dictionaries.test.ts +64 -0
- 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 +206 -0
- package/src/modules/billing/__tests__/lib/invoiceLanguages.test.ts +49 -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 +269 -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 +197 -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 +59 -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 +80 -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 +656 -6
- 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/de.json +880 -0
- package/src/modules/billing/i18n/en.json +457 -21
- package/src/modules/billing/i18n/es.json +880 -0
- package/src/modules/billing/i18n/pl.json +458 -22
- 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 +196 -0
- package/src/modules/billing/lib/invoiceLanguages.ts +57 -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 +329 -0
- package/src/modules/billing/lib/pdf/invoicePdf.ts +220 -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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../../src/modules/billing/backend/billing/invoices/%5Bid%5D/page.tsx"],
|
|
4
|
-
"sourcesContent": ["\"use client\"\nimport * as React from 'react'\nimport Link from 'next/link'\nimport { useParams } from 'next/navigation'\nimport type { LegacyColumnDef as ColumnDef } from '@tanstack/react-table/legacy'\nimport { Pencil, Plus, Trash2 } from 'lucide-react'\nimport { useT } from '@open-mercato/shared/lib/i18n/context'\nimport { Page, PageBody, PageHeader } from '@open-mercato/ui/backend/Page'\nimport { FormHeader } from '@open-mercato/ui/backend/forms'\nimport { DataTable } from '@open-mercato/ui/backend/DataTable'\nimport { Tag } from '@open-mercato/ui/primitives/tag'\nimport { Button } from '@open-mercato/ui/primitives/button'\nimport { IconButton } from '@open-mercato/ui/primitives/icon-button'\nimport { LoadingMessage, ErrorMessage } from '@open-mercato/ui/backend/detail'\nimport { flash } from '@open-mercato/ui/backend/FlashMessages'\nimport { useConfirmDialog } from '@open-mercato/ui/backend/confirm-dialog'\nimport {\n apiCallOrThrow,\n readApiResultOrThrow,\n} from '@open-mercato/ui/backend/utils/apiCall'\nimport { normalizeCrudServerError } from '@open-mercato/ui/backend/utils/serverErrors'\nimport { LineFormDialog, type LineFormValues } from '../../../../components/LineFormDialog'\nimport {\n DetailCard,\n DetailField,\n Stat,\n StatCard,\n} from '../../../../components/DetailFields'\nimport { billRunName } from '../../../../lib/billRunLabel'\n\ntype BillingInvoice = {\n id: string\n invoice_number: string\n status: 'draft' | 'posted' | 'paid' | 'void' | null\n currency_code: string\n issue_date: string | null\n due_date: string | null\n subtotal_net_amount: string\n grand_total_net_amount: string\n grand_total_gross_amount: string\n paid_total_amount: string\n outstanding_amount: string\n metadata: {\n bill_run_id?: string\n bill_account_id?: string\n bill_period_start?: string\n bill_period_end?: string\n test_run?: boolean\n } | null\n created_at: string\n updated_at: string\n}\n\ntype InvoiceLine = {\n id: string\n line_number: number\n kind: string\n description: string | null\n quantity: string\n currency_code: string\n unit_price_net: string\n total_net_amount: string\n total_gross_amount: string\n metadata: {\n billing_item_id?: string\n billing_type?: 'one_time' | 'recurring' | 'usage'\n operator_added?: boolean\n usage_tier_breakdown?: unknown\n } | null\n}\n\ntype DetailResponse = {\n invoice: BillingInvoice\n lines: InvoiceLine[]\n}\n\nfunction statusVariant(\n status: BillingInvoice['status'],\n): 'default' | 'success' | 'warning' | 'error' {\n switch (status) {\n case 'paid':\n return 'success'\n case 'posted':\n return 'warning'\n case 'void':\n return 'error'\n case 'draft':\n default:\n return 'default'\n }\n}\n\nfunction lineKindVariant(\n type: InvoiceLine['metadata'] extends infer M\n ? M extends { billing_type?: infer T }\n ? T\n : never\n : never,\n): 'default' | 'success' | 'warning' | 'error' {\n switch (type) {\n case 'one_time':\n return 'warning'\n case 'recurring':\n return 'success'\n case 'usage':\n return 'default'\n default:\n return 'default'\n }\n}\n\nfunction formatMoney(value: string, currency: string): string {\n const n = Number.parseFloat(value)\n if (!Number.isFinite(n)) return value\n try {\n return new Intl.NumberFormat('en-US', { style: 'currency', currency }).format(n)\n } catch {\n return `${value} ${currency}`\n }\n}\n\nexport default function BillingInvoiceDetailPage(props: { params?: { id?: string } }) {\n const t = useT()\n // OM serves backend pages through a catch-all route \u2014 the dynamic\n // `[id]` segment arrives as a page prop; `useParams()` is the fallback.\n const urlParams = useParams<{ id: string }>()\n const invoiceId = (props.params?.id ?? urlParams?.id ?? '') as string\n\n const [invoice, setInvoice] = React.useState<BillingInvoice | null>(null)\n const [lines, setLines] = React.useState<InvoiceLine[]>([])\n // Bill Run + Billing Account are stored as FK ids in invoice metadata;\n // resolve their human names so the detail card shows names, not UUIDs.\n const [accountName, setAccountName] = React.useState<string | null>(null)\n const [runName, setRunName] = React.useState<string | null>(null)\n const [error, setError] = React.useState<string | null>(null)\n const [loading, setLoading] = React.useState(true)\n const [posting, setPosting] = React.useState(false)\n const [wiping, setWiping] = React.useState(false)\n\n // Client-side pagination for invoice lines. Caps the table at 100 rows\n // per page (per the OM DataTable convention) \u2014 invoices typically have\n // <20 lines, but bulk import or a long-running usage-rated subscription\n // can exceed that.\n const [linesPage, setLinesPage] = React.useState(1)\n const linesPageSize = 100\n const visibleLines = React.useMemo(\n () => lines.slice((linesPage - 1) * linesPageSize, linesPage * linesPageSize),\n [lines, linesPage],\n )\n const linesTotalPages = Math.max(1, Math.ceil(lines.length / linesPageSize))\n\n // Inline line-edit dialog state. `dialogMode === null` \u2192 closed.\n const [dialogMode, setDialogMode] = React.useState<'add' | 'edit' | null>(null)\n const [dialogTargetLine, setDialogTargetLine] = React.useState<InvoiceLine | null>(null)\n const [dialogSubmitting, setDialogSubmitting] = React.useState(false)\n\n // Confirm flows: wipe-test + remove-line both use ConfirmDialog\n // (per UI AGENTS.md: NEVER `window.confirm`).\n const { confirm, ConfirmDialogElement } = useConfirmDialog()\n\n const load = React.useCallback(async () => {\n if (!invoiceId) return\n setError(null)\n setLoading(true)\n try {\n const data = await readApiResultOrThrow<DetailResponse>(\n `/api/billing/invoices/${invoiceId}`,\n )\n setInvoice(data.invoice)\n setLines(data.lines ?? [])\n } catch (err) {\n const { message } = normalizeCrudServerError(err)\n setError(message || t('billing.invoices.detail.error.load', 'Failed to load invoice'))\n } finally {\n setLoading(false)\n }\n }, [invoiceId, t])\n\n React.useEffect(() => {\n void load()\n }, [load])\n\n // Resolve the FK names once the invoice is loaded (one bounded\n // request each \u2014 Bill Run name is derived from its as-of date).\n const billRunId = invoice?.metadata?.bill_run_id\n const billAccountId = invoice?.metadata?.bill_account_id\n React.useEffect(() => {\n if (billAccountId) {\n readApiResultOrThrow<{ items: Array<{ name: string }> }>(\n `/api/billing/accounts?id=${billAccountId}&pageSize=1`,\n )\n .then((r) => setAccountName(r.items?.[0]?.name ?? null))\n .catch(() => setAccountName(null))\n }\n if (billRunId) {\n readApiResultOrThrow<{ items: Array<{ as_of_date: string }> }>(\n `/api/billing/runs?id=${billRunId}&pageSize=1`,\n )\n .then((r) => {\n const asOf = r.items?.[0]?.as_of_date\n setRunName(asOf ? billRunName(asOf) : null)\n })\n .catch(() => setRunName(null))\n }\n }, [billAccountId, billRunId])\n\n const handlePost = React.useCallback(async () => {\n if (!invoice) return\n setPosting(true)\n try {\n const call = await apiCallOrThrow<{ status: string; invoiceNumber: string }>(\n '/api/billing/invoices/post',\n {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ invoiceId: invoice.id }),\n },\n )\n flash(\n t('billing.invoices.post.success', 'Invoice posted') +\n ` (${call.result?.invoiceNumber ?? invoice.invoice_number})`,\n 'success',\n )\n void load()\n } catch (err) {\n const { message } = normalizeCrudServerError(err)\n flash(message || t('billing.invoices.post.error', 'Post failed'), 'error')\n } finally {\n setPosting(false)\n }\n }, [invoice, load, t])\n\n const handleWipeTest = React.useCallback(async () => {\n if (!invoice) return\n const ok = await confirm({\n title: t('billing.invoices.wipe.confirm.title', 'Wipe test invoices?'),\n text: t(\n 'billing.invoices.wipe.confirm.text',\n 'Every test invoice from this Bill Run will be permanently deleted. This cannot be undone.',\n ),\n confirmText: t('billing.invoices.wipe.confirm.button', 'Delete test invoices'),\n variant: 'destructive',\n })\n if (!ok) return\n setWiping(true)\n try {\n const billRunId = invoice.metadata?.bill_run_id\n const call = await apiCallOrThrow<{ invoicesRemoved: number }>(\n '/api/billing/test-invoices/wipe',\n {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify(billRunId ? { billRunId } : {}),\n },\n )\n flash(\n t('billing.invoices.wipe.success', 'Test invoices removed') +\n ` (${call.result?.invoicesRemoved ?? 0})`,\n 'success',\n )\n // The invoice we were looking at is hard-deleted \u2014 navigate away\n // on success by reloading; the detail load will 404 and the\n // user clicks back.\n void load()\n } catch (err) {\n const { message } = normalizeCrudServerError(err)\n flash(message || t('billing.invoices.wipe.error', 'Wipe failed'), 'error')\n } finally {\n setWiping(false)\n }\n }, [confirm, invoice, load, t])\n\n // \u2500\u2500\u2500 Line add / edit / remove \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n const handleSubmitLine = React.useCallback(\n async (values: LineFormValues) => {\n if (!invoice) return\n setDialogSubmitting(true)\n try {\n if (dialogMode === 'add') {\n await apiCallOrThrow('/api/billing/invoices/add-line', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n invoiceId: invoice.id,\n description: values.description,\n quantity: values.quantity,\n unitPriceNet: values.unitPriceNet,\n }),\n })\n flash(t('billing.invoices.lines.add.success', 'Line added'), 'success')\n } else if (dialogMode === 'edit' && dialogTargetLine) {\n await apiCallOrThrow('/api/billing/invoices/edit-line', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n invoiceId: invoice.id,\n invoiceLineId: dialogTargetLine.id,\n changes: {\n description: values.description,\n quantity: values.quantity,\n unitPriceNet: values.unitPriceNet,\n ...(values.totalNetAmount !== undefined\n ? { totalNetAmount: values.totalNetAmount }\n : {}),\n },\n }),\n })\n flash(t('billing.invoices.lines.edit.success', 'Line updated'), 'success')\n }\n setDialogMode(null)\n setDialogTargetLine(null)\n void load()\n } catch (err) {\n const { message } = normalizeCrudServerError(err)\n flash(message || t('billing.invoices.lines.save.error', 'Save failed'), 'error')\n } finally {\n setDialogSubmitting(false)\n }\n },\n [dialogMode, dialogTargetLine, invoice, load, t],\n )\n\n const handleRemoveLine = React.useCallback(\n async (line: InvoiceLine) => {\n if (!invoice) return\n const ok = await confirm({\n title: t('billing.invoices.lines.remove.confirm.title', 'Remove line?'),\n text: t(\n 'billing.invoices.lines.remove.confirm.text',\n 'The line will be deleted and recorded in the draft-edit audit log.',\n ),\n confirmText: t('billing.invoices.lines.remove.confirm.button', 'Remove line'),\n variant: 'destructive',\n })\n if (!ok) return\n try {\n await apiCallOrThrow('/api/billing/invoices/remove-line', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n invoiceId: invoice.id,\n invoiceLineId: line.id,\n }),\n })\n flash(t('billing.invoices.lines.remove.success', 'Line removed'), 'success')\n void load()\n } catch (err) {\n const { message } = normalizeCrudServerError(err)\n flash(message || t('billing.invoices.lines.remove.error', 'Remove failed'), 'error')\n }\n },\n [confirm, invoice, load, t],\n )\n\n const canEditLines = invoice?.status === 'draft'\n\n const lineColumns = React.useMemo<ColumnDef<InvoiceLine>[]>(\n () => [\n {\n accessorKey: 'line_number',\n header: '#',\n },\n {\n accessorKey: 'description',\n header: t('billing.invoices.lines.columns.description', 'Description'),\n cell: ({ row }) => {\n const type = row.original.metadata?.billing_type\n const operatorAdded = row.original.metadata?.operator_added === true\n return (\n <div className=\"flex flex-col gap-1\">\n <span>{row.original.description ?? '\u2014'}</span>\n <div className=\"flex items-center gap-1 flex-wrap\">\n {type ? <Tag variant={lineKindVariant(type)}>{type}</Tag> : null}\n {operatorAdded ? (\n <Tag variant=\"info\">\n {t('billing.invoices.lines.operator_added', 'Operator-added')}\n </Tag>\n ) : null}\n </div>\n </div>\n )\n },\n },\n {\n accessorKey: 'quantity',\n header: t('billing.invoices.lines.columns.quantity', 'Qty'),\n },\n {\n accessorKey: 'unit_price_net',\n header: t('billing.invoices.lines.columns.unit_price', 'Unit price'),\n cell: ({ row }) =>\n formatMoney(row.original.unit_price_net, row.original.currency_code),\n },\n {\n accessorKey: 'total_net_amount',\n header: t('billing.invoices.lines.columns.total', 'Total net'),\n cell: ({ row }) =>\n formatMoney(row.original.total_net_amount, row.original.currency_code),\n },\n {\n id: 'actions',\n header: '',\n cell: ({ row }) => {\n if (!canEditLines) return null\n return (\n <div className=\"flex items-center justify-end gap-1\">\n <IconButton\n type=\"button\"\n variant=\"ghost\"\n aria-label={t('billing.invoices.lines.actions.edit', 'Edit line')}\n onClick={() => {\n setDialogTargetLine(row.original)\n setDialogMode('edit')\n }}\n >\n <Pencil size={16} />\n </IconButton>\n <IconButton\n type=\"button\"\n variant=\"ghost\"\n aria-label={t('billing.invoices.lines.actions.remove', 'Remove line')}\n onClick={() => void handleRemoveLine(row.original)}\n >\n <Trash2 size={16} />\n </IconButton>\n </div>\n )\n },\n },\n ],\n [canEditLines, handleRemoveLine, t],\n )\n\n const dialogInitial = React.useMemo<Partial<LineFormValues> | undefined>(() => {\n if (dialogMode !== 'edit' || !dialogTargetLine) return undefined\n return {\n description: dialogTargetLine.description ?? '',\n quantity: Number.parseFloat(dialogTargetLine.quantity),\n unitPriceNet: Number.parseFloat(dialogTargetLine.unit_price_net),\n }\n }, [dialogMode, dialogTargetLine])\n\n if (error) {\n return (\n <Page>\n <PageHeader title={t('billing.invoices.detail.title', 'Billing Invoice')} />\n <PageBody>\n <ErrorMessage label={error} />\n </PageBody>\n </Page>\n )\n }\n if (loading || !invoice) {\n return (\n <Page>\n <PageHeader title={t('billing.invoices.detail.title', 'Billing Invoice')} />\n <PageBody>\n <LoadingMessage label={t('billing.invoices.detail.loading', 'Loading invoice\u2026')} />\n </PageBody>\n </Page>\n )\n }\n\n const isTest = invoice.metadata?.test_run === true\n const isDraft = invoice.status === 'draft'\n\n return (\n <Page>\n <FormHeader\n mode=\"detail\"\n backHref=\"/backend/billing/invoices\"\n entityTypeLabel={t('billing.invoices.detail.title', 'Billing Invoice')}\n title={invoice.invoice_number}\n statusBadge={\n <div className=\"flex items-center gap-2 flex-wrap\">\n <Tag variant={statusVariant(invoice.status)}>{invoice.status ?? '\u2014'}</Tag>\n {isTest ? <Tag variant=\"warning\">TEST</Tag> : null}\n </div>\n }\n actionsContent={\n <>\n {isDraft && !isTest ? (\n <Button onClick={handlePost} disabled={posting}>\n {posting\n ? t('billing.invoices.post.in_progress', 'Posting\u2026')\n : t('billing.invoices.post.action', 'Post invoice')}\n </Button>\n ) : null}\n {isTest ? (\n <Button\n variant=\"outline\"\n onClick={handleWipeTest}\n disabled={wiping}\n >\n {wiping\n ? t('billing.invoices.wipe.in_progress', 'Wiping\u2026')\n : t('billing.invoices.wipe.action', 'Wipe test invoices for this run')}\n </Button>\n ) : null}\n </>\n }\n />\n <PageBody>\n <div className=\"space-y-6\">\n <DetailCard>\n <DetailField label={t('billing.invoices.detail.field.period', 'Bill period')}>\n {invoice.metadata?.bill_period_start ?? '\u2014'} \u2192{' '}\n {invoice.metadata?.bill_period_end ?? '\u2014'}\n </DetailField>\n <DetailField label={t('billing.invoices.detail.field.bill_run', 'Bill Run')}>\n {invoice.metadata?.bill_run_id ? (\n <Link\n href={`/backend/billing/runs/${invoice.metadata.bill_run_id}`}\n className=\"text-primary hover:underline\"\n >\n {runName ?? invoice.metadata.bill_run_id}\n </Link>\n ) : (\n '\u2014'\n )}\n </DetailField>\n <DetailField\n label={t('billing.invoices.detail.field.account', 'Billing Account')}\n >\n {invoice.metadata?.bill_account_id ? (\n <Link\n href={`/backend/billing/accounts/${invoice.metadata.bill_account_id}`}\n className=\"text-primary hover:underline\"\n >\n {accountName ?? invoice.metadata.bill_account_id}\n </Link>\n ) : (\n '\u2014'\n )}\n </DetailField>\n <DetailField label={t('billing.invoices.detail.field.issued', 'Issued')}>\n {invoice.issue_date?.slice(0, 10) ?? '\u2014'}\n </DetailField>\n <DetailField label={t('billing.common.id', 'ID')}>\n <span className=\"font-mono text-xs\">{invoice.id}</span>\n </DetailField>\n </DetailCard>\n\n <StatCard>\n <Stat\n label={t('billing.invoices.detail.subtotal', 'Subtotal net')}\n value={formatMoney(invoice.subtotal_net_amount, invoice.currency_code)}\n />\n <Stat\n label={t('billing.invoices.detail.total', 'Grand total')}\n value={formatMoney(invoice.grand_total_gross_amount, invoice.currency_code)}\n />\n <Stat\n label={t('billing.invoices.detail.paid', 'Paid')}\n value={formatMoney(invoice.paid_total_amount, invoice.currency_code)}\n />\n <Stat\n label={t('billing.invoices.detail.outstanding', 'Outstanding')}\n value={formatMoney(invoice.outstanding_amount, invoice.currency_code)}\n />\n </StatCard>\n\n <div>\n <div className=\"flex items-center justify-between mb-2\">\n <h2 className=\"text-base font-semibold\">\n {t('billing.invoices.lines.title', 'Lines')}\n </h2>\n {canEditLines ? (\n <Button\n type=\"button\"\n variant=\"outline\"\n onClick={() => {\n setDialogTargetLine(null)\n setDialogMode('add')\n }}\n >\n <Plus size={16} />\n {t('billing.invoices.lines.add.action', 'Add line')}\n </Button>\n ) : null}\n </div>\n <DataTable\n columns={lineColumns}\n data={visibleLines}\n isLoading={false}\n pagination={{\n page: linesPage,\n pageSize: linesPageSize,\n total: lines.length,\n totalPages: linesTotalPages,\n onPageChange: setLinesPage,\n }}\n />\n </div>\n </div>\n\n <LineFormDialog\n open={dialogMode !== null}\n mode={dialogMode ?? 'add'}\n initial={dialogInitial}\n submitting={dialogSubmitting}\n onCancel={() => {\n setDialogMode(null)\n setDialogTargetLine(null)\n }}\n onSubmit={handleSubmitLine}\n />\n {Confirm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A,UAAU;AAAA;AAAA,MACZ;AAAA,MACC;AAAA,OACH;AAAA,KACF;AAEJ;",
|
|
6
|
-
"names": [
|
|
4
|
+
"sourcesContent": ["\"use client\"\nimport * as React from 'react'\nimport Link from 'next/link'\nimport { useParams, useRouter, useSearchParams } from 'next/navigation'\nimport type { LegacyColumnDef as ColumnDef } from '@tanstack/react-table/legacy'\nimport { FileDown, Mail, Pencil, Plus, Trash2 } from 'lucide-react'\nimport { useT } from '@open-mercato/shared/lib/i18n/context'\nimport { Page, PageBody, PageHeader } from '@open-mercato/ui/backend/Page'\nimport { FormHeader } from '@open-mercato/ui/backend/forms'\nimport { BillingDataTable as DataTable } from '../../../../components/BillingDataTable'\nimport { Tag } from '@open-mercato/ui/primitives/tag'\nimport { Button } from '@open-mercato/ui/primitives/button'\nimport { IconButton } from '@open-mercato/ui/primitives/icon-button'\nimport { LoadingMessage, ErrorMessage } from '@open-mercato/ui/backend/detail'\nimport { flash } from '@open-mercato/ui/backend/FlashMessages'\nimport { useConfirmDialog } from '@open-mercato/ui/backend/confirm-dialog'\nimport {\n apiCallOrThrow,\n readApiResultOrThrow,\n} from '@open-mercato/ui/backend/utils/apiCall'\nimport { normalizeCrudServerError } from '@open-mercato/ui/backend/utils/serverErrors'\nimport { LineFormDialog, type LineFormValues } from '../../../../components/LineFormDialog'\nimport { BillingSettingsLink } from '../../../../components/BillingSettingsLink'\nimport {\n DetailCard,\n DetailField,\n Stat,\n StatCard,\n} from '../../../../components/DetailFields'\nimport { billRunName } from '../../../../lib/billRunLabel'\nimport { invoicePdfHref, resolveInvoiceReturnTarget } from '../../../../lib/navigation'\nimport { CreateMemoDialog } from '../../../../components/CreateMemoDialog'\n\n// Spec 0: billing_invoices / billing_invoice_lines field names.\ntype BillingInvoice = {\n id: string\n number: string\n document_type: 'invoice' | 'credit_memo' | 'debit_memo' | 'receipt'\n status: 'draft' | 'posted' | 'partially_paid' | 'paid' | 'credited'\n test_run: boolean\n bill_account_id: string\n bill_account_name: string | null\n bill_run_id: string | null\n bill_date: string | null\n period_start: string | null\n period_end: string | null\n currency_code: string\n issue_date: string | null\n due_date: string | null\n subtotal_net: string\n tax_total: string\n total_gross: string\n paid_total: string\n outstanding: string\n days_overdue?: number\n pdf_attachment_id?: string | null\n // Spec D \u2014 corrective documents\n corrects_invoice_id?: string | null\n corrects_invoice_number?: string | null\n correction_reason?: string | null\n buyer_snapshot?: { invoice_email?: string } | null\n metadata?: { draft_number?: string; deliveries?: InvoiceDelivery[] } | null\n created_at: string\n updated_at: string\n}\n\n// Spec B: one entry per email attempt (metadata.deliveries).\ntype InvoiceDelivery = {\n at: string\n to: string\n status: 'sent' | 'failed'\n error?: string | null\n trigger: 'manual' | 'auto'\n}\n\ntype InvoiceLine = {\n id: string\n line_number: number\n billing_type: string\n description: string | null\n quantity: string\n currency_code: string\n unit_price_net: string\n tax_rate: string | number | null\n net_amount: string\n tax_amount: string\n gross_amount: string\n service_period_start: string | null\n service_period_end: string | null\n metadata: { operator_added?: boolean; usage_tier_breakdown?: unknown } | null\n}\n\n// Spec C: what settled this receivable (payments; Spec D: credit memos).\ntype InvoiceAllocation = {\n id: string\n source_type: 'payment' | 'credit_memo'\n source_id: string\n source_label: string | null\n amount: string\n currency_code: string\n allocated_by: string\n created_at: string\n}\n\ntype DetailResponse = {\n invoice: BillingInvoice\n lines: InvoiceLine[]\n allocations?: InvoiceAllocation[]\n corrections?: InvoiceCorrection[]\n}\n\n// Spec D: memos correcting this document.\ntype InvoiceCorrection = {\n id: string\n number: string\n document_type: 'credit_memo' | 'debit_memo'\n status: string\n total_gross: string\n currency_code: string\n}\n\nfunction statusVariant(\n status: BillingInvoice['status'],\n): 'default' | 'success' | 'warning' | 'error' {\n switch (status) {\n case 'paid':\n case 'credited':\n return 'success'\n case 'posted':\n case 'partially_paid':\n return 'warning'\n case 'draft':\n default:\n return 'default'\n }\n}\n\nfunction lineKindVariant(\n type: string,\n): 'default' | 'success' | 'warning' | 'error' {\n switch (type) {\n case 'one_time':\n return 'warning'\n case 'recurring':\n return 'success'\n case 'usage':\n return 'default'\n default:\n return 'default'\n }\n}\n\nfunction formatMoney(value: string, currency: string): string {\n const n = Number.parseFloat(value)\n if (!Number.isFinite(n)) return value\n try {\n return new Intl.NumberFormat('en-US', { style: 'currency', currency }).format(n)\n } catch {\n return `${value} ${currency}`\n }\n}\n\nexport default function BillingInvoiceDetailPage(props: { params?: { id?: string } }) {\n const t = useT()\n // OM serves backend pages through a catch-all route \u2014 the dynamic\n // `[id]` segment arrives as a page prop; `useParams()` is the fallback.\n const urlParams = useParams<{ id: string }>()\n const invoiceId = (props.params?.id ?? urlParams?.id ?? '') as string\n\n const [invoice, setInvoice] = React.useState<BillingInvoice | null>(null)\n const [lines, setLines] = React.useState<InvoiceLine[]>([])\n // Bill Run + Billing Account are stored as FK ids in invoice metadata;\n // resolve their human names so the detail card shows names, not UUIDs.\n const [accountName, setAccountName] = React.useState<string | null>(null)\n const [runName, setRunName] = React.useState<string | null>(null)\n const [error, setError] = React.useState<string | null>(null)\n const [loading, setLoading] = React.useState(true)\n const [posting, setPosting] = React.useState(false)\n const [settingsIncomplete, setSettingsIncomplete] = React.useState(false)\n\n // Client-side pagination for invoice lines. Caps the table at 100 rows\n // per page (per the OM DataTable convention) \u2014 invoices typically have\n // <20 lines, but bulk import or a long-running usage-rated subscription\n // can exceed that.\n const [linesPage, setLinesPage] = React.useState(1)\n const linesPageSize = 100\n const visibleLines = React.useMemo(\n () => lines.slice((linesPage - 1) * linesPageSize, linesPage * linesPageSize),\n [lines, linesPage],\n )\n const linesTotalPages = Math.max(1, Math.ceil(lines.length / linesPageSize))\n\n // Inline line-edit dialog state. `dialogMode === null` \u2192 closed.\n const [dialogMode, setDialogMode] = React.useState<'add' | 'edit' | null>(null)\n const [dialogTargetLine, setDialogTargetLine] = React.useState<InvoiceLine | null>(null)\n const [dialogSubmitting, setDialogSubmitting] = React.useState(false)\n\n // Confirm flows (remove line, send, memo delete) use ConfirmDialog\n // (per UI AGENTS.md: NEVER `window.confirm`).\n const { confirm, ConfirmDialogElement } = useConfirmDialog()\n const [allocations, setAllocations] = React.useState<InvoiceAllocation[]>([])\n const [corrections, setCorrections] = React.useState<InvoiceCorrection[]>([])\n const [memoDialog, setMemoDialog] = React.useState<'credit_memo' | 'debit_memo' | null>(null)\n const router = useRouter()\n const correctionColumns = React.useMemo<ColumnDef<InvoiceCorrection>[]>(\n () => [\n {\n accessorKey: 'number',\n header: t('billing.invoices.columns.number', 'Number'),\n cell: ({ row }) => (\n <Link href={`/backend/billing/invoices/${row.original.id}`} className=\"text-primary hover:underline\">\n {row.original.number}\n </Link>\n ),\n },\n {\n accessorKey: 'document_type',\n header: t('billing.invoices.columns.type', 'Type'),\n cell: ({ row }) =>\n row.original.document_type === 'credit_memo'\n ? t('billing.invoices.document_type.credit_memo', 'Credit memo')\n : t('billing.invoices.document_type.debit_memo', 'Debit memo'),\n },\n { accessorKey: 'status', header: t('billing.invoices.columns.status', 'Status') },\n {\n accessorKey: 'total_gross',\n header: t('billing.invoices.columns.total', 'Total'),\n cell: ({ row }) =>\n formatMoney(\n String((row.original.document_type === 'credit_memo' ? -1 : 1) * Number.parseFloat(row.original.total_gross)),\n row.original.currency_code,\n ),\n },\n ],\n [t],\n )\n const handleDeleteDraftMemo = React.useCallback(async () => {\n if (!invoice) return\n const ok = await confirm({\n title: t('billing.memo.delete.confirm', 'Delete this draft memo?'),\n text: t('billing.memo.delete.text', 'The draft and its lines are removed. Posted documents are never deleted.'),\n confirmText: t('billing.memo.delete.action', 'Delete draft'),\n variant: 'destructive',\n })\n if (!ok) return\n try {\n await apiCallOrThrow('/api/billing/invoices/delete-draft', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ invoiceId: invoice.id }),\n })\n flash(t('billing.memo.deleted', 'Draft memo deleted'), 'success')\n router.push(invoice.corrects_invoice_id ? `/backend/billing/invoices/${invoice.corrects_invoice_id}` : '/backend/billing/invoices')\n } catch (err) {\n flash(normalizeCrudServerError(err).message || t('billing.memo.delete.failed', 'Could not delete the draft'), 'error')\n }\n }, [confirm, invoice, router, t])\n const allocationColumns = React.useMemo<ColumnDef<InvoiceAllocation>[]>(\n () => [\n {\n accessorKey: 'source_label',\n header: t('billing.invoices.payments.source', 'Source'),\n cell: ({ row }) => (\n <Link\n href={\n row.original.source_type === 'payment'\n ? `/backend/billing/payments/${row.original.source_id}`\n : `/backend/billing/invoices/${row.original.source_id}`\n }\n className=\"text-primary hover:underline\"\n >\n {row.original.source_type === 'payment'\n ? `${t('billing.invoices.payments.payment', 'Payment')}${row.original.source_label ? ` \u00B7 ${row.original.source_label}` : ''}`\n : `${t('billing.invoices.payments.credit_memo', 'Credit memo')} ${row.original.source_label ?? ''}`}\n </Link>\n ),\n meta: { truncate: true, maxWidth: '320px' },\n },\n {\n accessorKey: 'amount',\n header: t('billing.payments.columns.amount', 'Amount'),\n cell: ({ row }) => formatMoney(row.original.amount, row.original.currency_code),\n },\n {\n accessorKey: 'created_at',\n header: t('billing.payments.allocations.at', 'When'),\n cell: ({ row }) => new Date(row.original.created_at).toLocaleDateString(),\n },\n ],\n [t],\n )\n const searchParams = useSearchParams()\n const backHref = resolveInvoiceReturnTarget({\n from: searchParams?.get('from'),\n accountId: searchParams?.get('accountId'),\n })\n const [sending, setSending] = React.useState(false)\n\n const load = React.useCallback(async () => {\n if (!invoiceId) return\n setError(null)\n setLoading(true)\n try {\n const data = await readApiResultOrThrow<DetailResponse>(\n `/api/billing/invoices/${invoiceId}`,\n )\n setInvoice(data.invoice)\n setLines(data.lines ?? [])\n setAllocations(data.allocations ?? [])\n setCorrections(data.corrections ?? [])\n } catch (err) {\n const { message } = normalizeCrudServerError(err)\n setError(message || t('billing.invoices.detail.error.load', 'Failed to load invoice'))\n } finally {\n setLoading(false)\n }\n }, [invoiceId, t])\n\n React.useEffect(() => {\n void load()\n }, [load])\n\n // Resolve the FK names once the invoice is loaded (one bounded\n // request each \u2014 Bill Run name is derived from its as-of date).\n const billRunId = invoice?.bill_run_id\n const billAccountId = invoice?.bill_account_id\n React.useEffect(() => {\n if (billAccountId) {\n readApiResultOrThrow<{ items: Array<{ name: string }> }>(\n `/api/billing/accounts?id=${billAccountId}&pageSize=1`,\n )\n .then((r) => setAccountName(r.items?.[0]?.name ?? null))\n .catch(() => setAccountName(null))\n }\n if (billRunId) {\n readApiResultOrThrow<{ items: Array<{ as_of_date: string }> }>(\n `/api/billing/runs?id=${billRunId}&pageSize=1`,\n )\n .then((r) => {\n const asOf = r.items?.[0]?.as_of_date\n setRunName(asOf ? billRunName(asOf) : null)\n })\n .catch(() => setRunName(null))\n }\n }, [billAccountId, billRunId])\n\n const handlePost = React.useCallback(async () => {\n if (!invoice) return\n setPosting(true)\n try {\n const call = await apiCallOrThrow<{ status: string; invoiceNumber: string }>(\n '/api/billing/invoices/post',\n {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ invoiceId: invoice.id }),\n },\n )\n flash(\n t('billing.invoices.post.success', 'Invoice posted') +\n ` (${call.result?.invoiceNumber ?? invoice.number})`,\n 'success',\n )\n void load()\n } catch (err) {\n const { message } = normalizeCrudServerError(err)\n const code = (err as { body?: { code?: string } } | null)?.body?.code\n if (code === 'billing.settings.incomplete') setSettingsIncomplete(true)\n flash(\n code === 'billing.settings.incomplete'\n ? t(\n 'billing.invoices.post.settings_incomplete',\n 'Fill in the seller details in Settings \u2192 Billing before posting invoices.',\n )\n : message || t('billing.invoices.post.error', 'Post failed'),\n 'error',\n )\n } finally {\n setPosting(false)\n }\n }, [invoice, load, t])\n\n const handleSend = React.useCallback(async () => {\n if (!invoice) return\n const recipient = invoice.buyer_snapshot?.invoice_email ?? ''\n const alreadySent = (invoice.metadata?.deliveries ?? []).some((d) => d.status === 'sent')\n const ok = await confirm({\n title: alreadySent\n ? t('billing.invoices.send.confirm.title_resend', 'Resend invoice?')\n : t('billing.invoices.send.confirm.title', 'Send invoice?'),\n text: t('billing.invoices.send.confirm.text', 'The PDF is emailed to {email}.').replace('{email}', recipient),\n confirmText: t('billing.invoices.send.action', 'Send'),\n })\n if (!ok) return\n setSending(true)\n try {\n const call = await apiCallOrThrow<{ status: 'sent' | 'failed'; error?: string | null }>(\n `/api/billing/invoices/${encodeURIComponent(invoice.id)}/send`,\n { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: '{}' },\n )\n if (call.result?.status === 'sent') {\n flash(t('billing.invoices.send.success', 'Invoice sent'), 'success')\n } else {\n flash(\n `${t('billing.invoices.send.failed', 'Sending failed')}${call.result?.error ? `: ${call.result.error}` : ''}`,\n 'error',\n )\n }\n void load()\n } catch (err) {\n const { message } = normalizeCrudServerError(err)\n flash(message || t('billing.invoices.send.failed', 'Sending failed'), 'error')\n } finally {\n setSending(false)\n }\n }, [confirm, invoice, load, t])\n\n // \u2500\u2500\u2500 Line add / edit / remove \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n const handleSubmitLine = React.useCallback(\n async (values: LineFormValues) => {\n if (!invoice) return\n setDialogSubmitting(true)\n try {\n if (dialogMode === 'add') {\n await apiCallOrThrow('/api/billing/invoices/add-line', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n invoiceId: invoice.id,\n description: values.description,\n quantity: values.quantity,\n unitPriceNet: values.unitPriceNet,\n ...(values.taxRate !== undefined ? { taxRate: values.taxRate } : {}),\n }),\n })\n flash(t('billing.invoices.lines.add.success', 'Line added'), 'success')\n } else if (dialogMode === 'edit' && dialogTargetLine) {\n await apiCallOrThrow('/api/billing/invoices/edit-line', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n invoiceId: invoice.id,\n invoiceLineId: dialogTargetLine.id,\n changes: {\n description: values.description,\n quantity: values.quantity,\n unitPriceNet: values.unitPriceNet,\n ...(values.totalNetAmount !== undefined\n ? { totalNetAmount: values.totalNetAmount }\n : {}),\n ...(values.taxRate !== undefined ? { taxRate: values.taxRate } : {}),\n },\n }),\n })\n flash(t('billing.invoices.lines.edit.success', 'Line updated'), 'success')\n }\n setDialogMode(null)\n setDialogTargetLine(null)\n void load()\n } catch (err) {\n const { message } = normalizeCrudServerError(err)\n flash(message || t('billing.invoices.lines.save.error', 'Save failed'), 'error')\n } finally {\n setDialogSubmitting(false)\n }\n },\n [dialogMode, dialogTargetLine, invoice, load, t],\n )\n\n const handleRemoveLine = React.useCallback(\n async (line: InvoiceLine) => {\n if (!invoice) return\n const ok = await confirm({\n title: t('billing.invoices.lines.remove.confirm.title', 'Remove line?'),\n text: t(\n 'billing.invoices.lines.remove.confirm.text',\n 'The line will be deleted and recorded in the draft-edit audit log.',\n ),\n confirmText: t('billing.invoices.lines.remove.confirm.button', 'Remove line'),\n variant: 'destructive',\n })\n if (!ok) return\n try {\n await apiCallOrThrow('/api/billing/invoices/remove-line', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n invoiceId: invoice.id,\n invoiceLineId: line.id,\n }),\n })\n flash(t('billing.invoices.lines.remove.success', 'Line removed'), 'success')\n void load()\n } catch (err) {\n const { message } = normalizeCrudServerError(err)\n flash(message || t('billing.invoices.lines.remove.error', 'Remove failed'), 'error')\n }\n },\n [confirm, invoice, load, t],\n )\n\n const canEditLines = invoice?.status === 'draft'\n\n // Newest first; deliveries are a short, append-only log on the invoice.\n const deliveries = React.useMemo(\n () => [...(invoice?.metadata?.deliveries ?? [])].reverse(),\n [invoice?.metadata?.deliveries],\n )\n const deliveryColumns = React.useMemo<ColumnDef<InvoiceDelivery>[]>(\n () => [\n {\n accessorKey: 'at',\n header: t('billing.invoices.deliveries.columns.at', 'When'),\n cell: ({ row }) => new Date(row.original.at).toLocaleString(),\n },\n { accessorKey: 'to', header: t('billing.invoices.deliveries.columns.to', 'Recipient') },\n {\n accessorKey: 'status',\n header: t('billing.invoices.deliveries.columns.status', 'Status'),\n cell: ({ row }) =>\n row.original.status === 'sent' ? (\n <Tag variant=\"success\">{t('billing.invoices.deliveries.status.sent', 'Sent')}</Tag>\n ) : (\n <Tag variant=\"error\">{t('billing.invoices.deliveries.status.failed', 'Failed')}</Tag>\n ),\n },\n {\n accessorKey: 'trigger',\n header: t('billing.invoices.deliveries.columns.trigger', 'Trigger'),\n cell: ({ row }) =>\n row.original.trigger === 'auto'\n ? t('billing.invoices.deliveries.trigger.auto', 'Automatic')\n : t('billing.invoices.deliveries.trigger.manual', 'Manual'),\n },\n {\n accessorKey: 'error',\n header: t('billing.invoices.deliveries.columns.error', 'Error'),\n cell: ({ row }) => row.original.error ?? '\u2014',\n meta: { truncate: true, maxWidth: '280px' },\n },\n ],\n [t],\n )\n\n const lineColumns = React.useMemo<ColumnDef<InvoiceLine>[]>(\n () => [\n {\n accessorKey: 'line_number',\n header: '#',\n },\n {\n accessorKey: 'description',\n header: t('billing.invoices.lines.columns.description', 'Description'),\n cell: ({ row }) => {\n const type = row.original.billing_type\n const operatorAdded = row.original.metadata?.operator_added === true\n return (\n <div className=\"flex flex-col gap-1\">\n <span>{row.original.description ?? '\u2014'}</span>\n <div className=\"flex items-center gap-1 flex-wrap\">\n {type ? <Tag variant={lineKindVariant(type)}>{type}</Tag> : null}\n {operatorAdded ? (\n <Tag variant=\"info\">\n {t('billing.invoices.lines.operator_added', 'Operator-added')}\n </Tag>\n ) : null}\n </div>\n </div>\n )\n },\n },\n {\n accessorKey: 'quantity',\n header: t('billing.invoices.lines.columns.quantity', 'Qty'),\n },\n {\n accessorKey: 'unit_price_net',\n header: t('billing.invoices.lines.columns.unit_price', 'Unit price'),\n cell: ({ row }) =>\n formatMoney(row.original.unit_price_net, row.original.currency_code),\n },\n {\n accessorKey: 'net_amount',\n header: t('billing.invoices.lines.columns.total', 'Total net'),\n cell: ({ row }) =>\n formatMoney(row.original.net_amount, row.original.currency_code),\n },\n {\n accessorKey: 'tax_rate',\n header: t('billing.invoices.lines.columns.tax_rate', 'VAT %'),\n cell: ({ row }) => (row.original.tax_rate != null ? `${Number(row.original.tax_rate)} %` : '\u2014'),\n },\n {\n accessorKey: 'tax_amount',\n header: t('billing.invoices.lines.columns.tax_amount', 'VAT'),\n cell: ({ row }) => formatMoney(row.original.tax_amount, row.original.currency_code),\n },\n {\n accessorKey: 'gross_amount',\n header: t('billing.invoices.lines.columns.gross', 'Gross'),\n cell: ({ row }) => formatMoney(row.original.gross_amount, row.original.currency_code),\n },\n {\n id: 'actions',\n header: '',\n cell: ({ row }) => {\n if (!canEditLines) return null\n return (\n <div className=\"flex items-center justify-end gap-1\">\n <IconButton\n type=\"button\"\n variant=\"ghost\"\n aria-label={t('billing.invoices.lines.actions.edit', 'Edit line')}\n onClick={() => {\n setDialogTargetLine(row.original)\n setDialogMode('edit')\n }}\n >\n <Pencil size={16} />\n </IconButton>\n <IconButton\n type=\"button\"\n variant=\"ghost\"\n aria-label={t('billing.invoices.lines.actions.remove', 'Remove line')}\n onClick={() => void handleRemoveLine(row.original)}\n >\n <Trash2 size={16} />\n </IconButton>\n </div>\n )\n },\n },\n ],\n [canEditLines, handleRemoveLine, t],\n )\n\n const dialogInitial = React.useMemo<Partial<LineFormValues> | undefined>(() => {\n if (dialogMode !== 'edit' || !dialogTargetLine) return undefined\n return {\n description: dialogTargetLine.description ?? '',\n quantity: Number.parseFloat(dialogTargetLine.quantity),\n unitPriceNet: Number.parseFloat(dialogTargetLine.unit_price_net),\n taxRate: dialogTargetLine.tax_rate != null ? Number.parseFloat(String(dialogTargetLine.tax_rate)) : undefined,\n }\n }, [dialogMode, dialogTargetLine])\n\n if (error) {\n return (\n <Page>\n <PageHeader title={t('billing.invoices.detail.title', 'Billing Invoice')} />\n <PageBody>\n <ErrorMessage label={error} />\n </PageBody>\n </Page>\n )\n }\n if (loading || !invoice) {\n return (\n <Page>\n <PageHeader title={t('billing.invoices.detail.title', 'Billing Invoice')} />\n <PageBody>\n <LoadingMessage label={t('billing.invoices.detail.loading', 'Loading invoice\u2026')} />\n </PageBody>\n </Page>\n )\n }\n\n const isTest = invoice.test_run === true\n const isDraft = invoice.status === 'draft'\n\n return (\n <Page>\n <FormHeader\n mode=\"detail\"\n backHref={backHref}\n entityTypeLabel={t('billing.invoices.detail.title', 'Billing Invoice')}\n title={invoice.number}\n statusBadge={\n <div className=\"flex items-center gap-2 flex-wrap\">\n <Tag variant={statusVariant(invoice.status)}>{invoice.status}</Tag>\n {invoice.document_type === 'credit_memo' ? (\n <Tag variant=\"info\">{t('billing.invoices.document_type.credit_memo', 'Credit memo')}</Tag>\n ) : invoice.document_type === 'debit_memo' ? (\n <Tag variant=\"info\">{t('billing.invoices.document_type.debit_memo', 'Debit memo')}</Tag>\n ) : null}\n {isTest ? (\n invoice.bill_run_id ? (\n <Link href={`/backend/billing/runs/${invoice.bill_run_id}`}>\n <Tag variant=\"warning\">{t('billing.invoices.test_run_tag', 'Test run')}</Tag>\n </Link>\n ) : (\n <Tag variant=\"warning\">{t('billing.invoices.test_run_tag', 'Test run')}</Tag>\n )\n ) : null}\n {(invoice.days_overdue ?? 0) > 0 ? (\n <Tag variant=\"error\">\n {t('billing.invoices.overdue_days', 'Overdue {days} d').replace('{days}', String(invoice.days_overdue))}\n </Tag>\n ) : null}\n </div>\n }\n actionsContent={\n <>\n {isDraft && !isTest ? (\n <Button onClick={handlePost} disabled={posting}>\n {posting\n ? t('billing.invoices.post.in_progress', 'Posting\u2026')\n : t('billing.invoices.post.action', 'Post invoice')}\n </Button>\n ) : null}\n <Button type=\"button\" variant=\"outline\" asChild>\n <a href={invoicePdfHref(invoice.id)} target=\"_blank\" rel=\"noopener noreferrer\">\n <FileDown size={16} />\n {isDraft\n ? t('billing.invoices.actions.pdf_preview', 'Preview PDF')\n : t('billing.invoices.actions.pdf', 'Download PDF')}\n </a>\n </Button>\n {!isDraft && !isTest && invoice.document_type !== 'receipt' ? (\n <Button type=\"button\" variant=\"outline\" onClick={() => void handleSend()} disabled={sending}>\n <Mail size={16} />\n {sending\n ? t('billing.invoices.send.in_progress', 'Sending\u2026')\n : (invoice.metadata?.deliveries ?? []).some((d) => d.status === 'sent')\n ? t('billing.invoices.send.resend', 'Resend')\n : t('billing.invoices.send.action', 'Send')}\n </Button>\n ) : null}\n {invoice.document_type === 'invoice' && !isTest && ['posted', 'partially_paid', 'paid'].includes(invoice.status) ? (\n <Button type=\"button\" variant=\"outline\" onClick={() => setMemoDialog('credit_memo')}>\n {t('billing.memo.create_credit.action', 'Create credit memo')}\n </Button>\n ) : null}\n {invoice.document_type === 'invoice' && !isTest && ['posted', 'partially_paid', 'paid', 'credited'].includes(invoice.status) ? (\n <Button type=\"button\" variant=\"outline\" onClick={() => setMemoDialog('debit_memo')}>\n {t('billing.memo.create_debit.action', 'Create debit memo')}\n </Button>\n ) : null}\n {isDraft && (invoice.document_type === 'credit_memo' || invoice.document_type === 'debit_memo') ? (\n <Button type=\"button\" variant=\"outline\" onClick={() => void handleDeleteDraftMemo()}>\n {t('billing.memo.delete.action', 'Delete draft')}\n </Button>\n ) : null}\n </>\n }\n />\n <PageBody>\n <div className=\"space-y-6\">\n {settingsIncomplete ? (\n <div className=\"flex flex-wrap items-center justify-between gap-3 rounded-md border border-status-warning-border bg-status-warning-bg px-4 py-3 text-sm text-status-warning-text\">\n <span>\n {t(\n 'billing.invoices.post.settings_incomplete',\n 'Fill in the seller details in Settings \u2192 Billing before posting invoices.',\n )}\n </span>\n <BillingSettingsLink />\n </div>\n ) : null}\n <DetailCard>\n <DetailField label={t('billing.invoices.detail.field.period', 'Bill period')}>\n {invoice.period_start?.slice(0, 10) ?? '\u2014'} \u2192{' '}\n {invoice.period_end?.slice(0, 10) ?? '\u2014'}\n </DetailField>\n <DetailField label={t('billing.invoices.detail.field.bill_run', 'Bill Run')}>\n {invoice.bill_run_id ? (\n <Link\n href={`/backend/billing/runs/${invoice.bill_run_id}`}\n className=\"text-primary hover:underline\"\n >\n {runName ?? invoice.bill_run_id}\n </Link>\n ) : (\n '\u2014'\n )}\n </DetailField>\n <DetailField\n label={t('billing.invoices.detail.field.account', 'Billing Account')}\n >\n {invoice.bill_account_id ? (\n <Link\n href={`/backend/billing/accounts/${invoice.bill_account_id}`}\n className=\"text-primary hover:underline\"\n >\n {accountName ?? invoice.bill_account_name ?? invoice.bill_account_id}\n </Link>\n ) : (\n '\u2014'\n )}\n </DetailField>\n <DetailField label={t('billing.invoices.detail.field.issued', 'Issued')}>\n {invoice.issue_date?.slice(0, 10) ?? '\u2014'}\n </DetailField>\n <DetailField label={t('billing.invoices.detail.field.due', 'Due')}>\n {invoice.due_date?.slice(0, 10) ?? '\u2014'}\n </DetailField>\n {invoice.corrects_invoice_id ? (\n <DetailField label={t('billing.memo.corrects', 'Corrects')}>\n <Link href={`/backend/billing/invoices/${invoice.corrects_invoice_id}`} className=\"text-primary hover:underline\">\n {invoice.corrects_invoice_number ?? invoice.corrects_invoice_id}\n </Link>\n </DetailField>\n ) : null}\n {invoice.correction_reason ? (\n <DetailField label={t('billing.memo.reason_label', 'Reason')}>{invoice.correction_reason}</DetailField>\n ) : null}\n {invoice.metadata?.draft_number ? (\n <DetailField label={t('billing.invoices.detail.field.draft_number', 'Draft number')}>\n <span className=\"font-mono text-xs\">{invoice.metadata.draft_number}</span>\n </DetailField>\n ) : null}\n <DetailField label={t('billing.common.id', 'ID')}>\n <span className=\"font-mono text-xs\">{invoice.id}</span>\n </DetailField>\n </DetailCard>\n\n <StatCard>\n <Stat\n label={t('billing.invoices.detail.subtotal', 'Subtotal net')}\n value={formatMoney(invoice.subtotal_net, invoice.currency_code)}\n />\n <Stat\n label={t('billing.invoices.detail.total', 'Grand total')}\n value={formatMoney(invoice.total_gross, invoice.currency_code)}\n />\n <Stat\n label={t('billing.invoices.detail.paid', 'Paid')}\n value={formatMoney(invoice.paid_total, invoice.currency_code)}\n />\n <Stat\n label={t('billing.invoices.detail.outstanding', 'Outstanding')}\n value={formatMoney(invoice.outstanding, invoice.currency_code)}\n />\n </StatCard>\n\n <div>\n <div className=\"flex items-center justify-between mb-2\">\n <h2 className=\"text-base font-semibold\">\n {t('billing.invoices.lines.title', 'Lines')}\n </h2>\n {canEditLines ? (\n <Button\n type=\"button\"\n variant=\"outline\"\n onClick={() => {\n setDialogTargetLine(null)\n setDialogMode('add')\n }}\n >\n <Plus size={16} />\n {t('billing.invoices.lines.add.action', 'Add line')}\n </Button>\n ) : null}\n </div>\n <DataTable\n columns={lineColumns}\n data={visibleLines}\n isLoading={false}\n pagination={{\n page: linesPage,\n pageSize: linesPageSize,\n total: lines.length,\n totalPages: linesTotalPages,\n onPageChange: setLinesPage,\n }}\n />\n </div>\n\n {corrections.length > 0 ? (\n <div>\n <h2 className=\"text-base font-semibold mb-2\">{t('billing.memo.corrections', 'Corrections')}</h2>\n <DataTable\n columns={correctionColumns}\n data={corrections}\n isLoading={false}\n pagination={{\n page: 1,\n pageSize: Math.max(corrections.length, 1),\n total: corrections.length,\n totalPages: 1,\n onPageChange: () => undefined,\n }}\n />\n </div>\n ) : null}\n\n {!isDraft ? (\n <div>\n <h2 className=\"text-base font-semibold mb-2\">{t('billing.invoices.payments.title', 'Payments')}</h2>\n <DataTable\n columns={allocationColumns}\n data={allocations}\n isLoading={false}\n emptyState={t('billing.invoices.payments.empty', 'No payments yet.')}\n pagination={{\n page: 1,\n pageSize: Math.max(allocations.length, 1),\n total: allocations.length,\n totalPages: 1,\n onPageChange: () => undefined,\n }}\n />\n </div>\n ) : null}\n\n {!isDraft ? (\n <div>\n <h2 className=\"text-base font-semibold mb-2\">\n {t('billing.invoices.deliveries.title', 'Email deliveries')}\n </h2>\n <DataTable\n columns={deliveryColumns}\n data={deliveries}\n isLoading={false}\n emptyState={t('billing.invoices.deliveries.empty', 'Not sent yet.')}\n pagination={{\n page: 1,\n pageSize: Math.max(deliveries.length, 1),\n total: deliveries.length,\n totalPages: 1,\n onPageChange: () => undefined,\n }}\n />\n </div>\n ) : null}\n </div>\n\n <LineFormDialog\n open={dialogMode !== null}\n mode={dialogMode ?? 'add'}\n initial={dialogInitial}\n submitting={dialogSubmitting}\n onCancel={() => {\n setDialogMode(null)\n setDialogTargetLine(null)\n }}\n onSubmit={handleSubmitLine}\n />\n {memoDialog ? (\n <CreateMemoDialog\n open\n type={memoDialog}\n invoiceId={invoice.id}\n invoiceNumber={invoice.number}\n currencyCode={invoice.currency_code}\n lines={lines.map((line) => ({\n id: line.id,\n description: line.description,\n quantity: line.quantity,\n unit_price_net: line.unit_price_net,\n tax_rate: line.tax_rate,\n }))}\n onClose={() => setMemoDialog(null)}\n onCreated={(memoId) => router.push(`/backend/billing/invoices/${memoId}`)}\n />\n ) : null}\n {ConfirmDialogElement}\n </PageBody>\n </Page>\n )\n}\n"],
|
|
5
|
+
"mappings": ";AAkNU,SA6eA,UA7eA,KA8VI,YA9VJ;AAjNV,YAAY,WAAW;AACvB,OAAO,UAAU;AACjB,SAAS,WAAW,WAAW,uBAAuB;AAEtD,SAAS,UAAU,MAAM,QAAQ,MAAM,cAAc;AACrD,SAAS,YAAY;AACrB,SAAS,MAAM,UAAU,kBAAkB;AAC3C,SAAS,kBAAkB;AAC3B,SAAS,oBAAoB,iBAAiB;AAC9C,SAAS,WAAW;AACpB,SAAS,cAAc;AACvB,SAAS,kBAAkB;AAC3B,SAAS,gBAAgB,oBAAoB;AAC7C,SAAS,aAAa;AACtB,SAAS,wBAAwB;AACjC;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,gCAAgC;AACzC,SAAS,sBAA2C;AACpD,SAAS,2BAA2B;AACpC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,mBAAmB;AAC5B,SAAS,gBAAgB,kCAAkC;AAC3D,SAAS,wBAAwB;AA0FjC,SAAS,cACP,QAC6C;AAC7C,UAAQ,QAAQ;AAAA,IACd,KAAK;AAAA,IACL,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AAAA,IACL,KAAK;AACH,aAAO;AAAA,IACT,KAAK;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E,YAAY;AAAA,gBACV,MAAM;AAAA,gBACN,UAAU,KAAK,IAAI,WAAW,QAAQ,CAAC;AAAA,gBACvC,OAAO,WAAW;AAAA,gBAClB,YAAY;AAAA,gBACZ,cAAc,MAAM;AAAA,cACtB;AAAA;AAAA,UACF;AAAA,WACF,IACE;AAAA,SACN;AAAA,MAEA;AAAA,QAAC;AAAA;AAAA,UACC,MAAM,eAAe;AAAA,UACrB,MAAM,cAAc;AAAA,UACpB,SAAS;AAAA,UACT,YAAY;AAAA,UACZ,UAAU,MAAM;AACd,0BAAc,IAAI;AAClB,gCAAoB,IAAI;AAAA,UAC1B;AAAA,UACA,UAAU;AAAA;AAAA,MACZ;AAAA,MACC,aACC;AAAA,QAAC;AAAA;AAAA,UACC,MAAI;AAAA,UACJ,MAAM;AAAA,UACN,WAAW,QAAQ;AAAA,UACnB,eAAe,QAAQ;AAAA,UACvB,cAAc,QAAQ;AAAA,UACtB,OAAO,MAAM,IAAI,CAAC,UAAU;AAAA,YAC1B,IAAI,KAAK;AAAA,YACT,aAAa,KAAK;AAAA,YAClB,UAAU,KAAK;AAAA,YACf,gBAAgB,KAAK;AAAA,YACrB,UAAU,KAAK;AAAA,UACjB,EAAE;AAAA,UACF,SAAS,MAAM,cAAc,IAAI;AAAA,UACjC,WAAW,CAAC,WAAW,OAAO,KAAK,6BAA6B,MAAM,EAAE;AAAA;AAAA,MAC1E,IACE;AAAA,MACH;AAAA,OACH;AAAA,KACF;AAEJ;",
|
|
6
|
+
"names": []
|
|
7
7
|
}
|
|
@@ -1,183 +1,17 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx
|
|
3
|
-
import * as React from "react";
|
|
4
|
-
import { useRouter } from "next/navigation";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
3
|
import { useT } from "@open-mercato/shared/lib/i18n/context";
|
|
6
4
|
import { Page, PageBody } from "@open-mercato/ui/backend/Page";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { readApiResultOrThrow } from "@open-mercato/ui/backend/utils/apiCall";
|
|
10
|
-
function formatDate(value) {
|
|
11
|
-
if (!value) return "\u2014";
|
|
12
|
-
const parsed = new Date(value);
|
|
13
|
-
return Number.isNaN(parsed.getTime()) ? value : parsed.toLocaleDateString();
|
|
14
|
-
}
|
|
15
|
-
function statusVariant(status) {
|
|
16
|
-
switch (status) {
|
|
17
|
-
case "paid":
|
|
18
|
-
return "success";
|
|
19
|
-
case "posted":
|
|
20
|
-
return "warning";
|
|
21
|
-
case "void":
|
|
22
|
-
return "error";
|
|
23
|
-
case "draft":
|
|
24
|
-
default:
|
|
25
|
-
return "default";
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
function formatMoney(value, currency) {
|
|
29
|
-
const n = Number.parseFloat(value);
|
|
30
|
-
if (!Number.isFinite(n)) return value;
|
|
31
|
-
try {
|
|
32
|
-
return new Intl.NumberFormat("en-US", { style: "currency", currency }).format(n);
|
|
33
|
-
} catch {
|
|
34
|
-
return `${value} ${currency}`;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
5
|
+
import { InvoicesTable } from "../../../components/InvoicesTable.js";
|
|
6
|
+
import { BillingSettingsLink } from "../../../components/BillingSettingsLink.js";
|
|
37
7
|
function BillingInvoicesListPage() {
|
|
38
8
|
const t = useT();
|
|
39
|
-
const router = useRouter();
|
|
40
|
-
const [rows, setRows] = React.useState([]);
|
|
41
|
-
const [page, setPage] = React.useState(1);
|
|
42
|
-
const [pageSize] = React.useState(25);
|
|
43
|
-
const [filters, setFilters] = React.useState({});
|
|
44
|
-
const [search, setSearch] = React.useState("");
|
|
45
|
-
const [total, setTotal] = React.useState(0);
|
|
46
|
-
const [totalPages, setTotalPages] = React.useState(1);
|
|
47
|
-
const [loading, setLoading] = React.useState(true);
|
|
48
|
-
const filterDefs = React.useMemo(
|
|
49
|
-
() => [
|
|
50
|
-
{
|
|
51
|
-
id: "status",
|
|
52
|
-
label: t("billing.invoices.filters.status", "Status"),
|
|
53
|
-
type: "select",
|
|
54
|
-
options: [
|
|
55
|
-
{ value: "draft", label: t("billing.invoices.status.draft", "Draft") },
|
|
56
|
-
{ value: "posted", label: t("billing.invoices.status.posted", "Posted") },
|
|
57
|
-
{ value: "paid", label: t("billing.invoices.status.paid", "Paid") },
|
|
58
|
-
{ value: "void", label: t("billing.invoices.status.void", "Void") }
|
|
59
|
-
]
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
id: "testRun",
|
|
63
|
-
label: t("billing.invoices.filters.test_run", "Test runs"),
|
|
64
|
-
type: "select",
|
|
65
|
-
options: [
|
|
66
|
-
{ value: "true", label: t("billing.invoices.filters.test_run.only", "Only test") },
|
|
67
|
-
{
|
|
68
|
-
value: "false",
|
|
69
|
-
label: t("billing.invoices.filters.test_run.exclude", "Exclude test")
|
|
70
|
-
}
|
|
71
|
-
]
|
|
72
|
-
}
|
|
73
|
-
],
|
|
74
|
-
[t]
|
|
75
|
-
);
|
|
76
|
-
const loadRows = React.useCallback(async () => {
|
|
77
|
-
setLoading(true);
|
|
78
|
-
try {
|
|
79
|
-
const params = new URLSearchParams({
|
|
80
|
-
page: String(page),
|
|
81
|
-
pageSize: String(pageSize)
|
|
82
|
-
});
|
|
83
|
-
if (search.trim()) params.set("search", search.trim());
|
|
84
|
-
if (typeof filters.status === "string" && filters.status) {
|
|
85
|
-
params.set("status", filters.status);
|
|
86
|
-
}
|
|
87
|
-
if (filters.testRun === "true" || filters.testRun === "false") {
|
|
88
|
-
params.set("testRun", String(filters.testRun));
|
|
89
|
-
}
|
|
90
|
-
const result = await readApiResultOrThrow(
|
|
91
|
-
`/api/billing/invoices?${params.toString()}`
|
|
92
|
-
);
|
|
93
|
-
setRows(result.items ?? []);
|
|
94
|
-
setTotal(result.total ?? 0);
|
|
95
|
-
setTotalPages(result.totalPages ?? 1);
|
|
96
|
-
} finally {
|
|
97
|
-
setLoading(false);
|
|
98
|
-
}
|
|
99
|
-
}, [filters.status, filters.testRun, page, pageSize, search]);
|
|
100
|
-
React.useEffect(() => {
|
|
101
|
-
void loadRows();
|
|
102
|
-
}, [loadRows]);
|
|
103
|
-
const columns = React.useMemo(
|
|
104
|
-
() => [
|
|
105
|
-
{
|
|
106
|
-
accessorKey: "invoice_number",
|
|
107
|
-
header: t("billing.invoices.columns.number", "Number"),
|
|
108
|
-
cell: ({ row }) => {
|
|
109
|
-
const isTest = row.original.metadata?.test_run === true;
|
|
110
|
-
return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
111
|
-
/* @__PURE__ */ jsx("span", { className: "text-sm font-medium text-primary", children: row.original.invoice_number }),
|
|
112
|
-
isTest ? /* @__PURE__ */ jsx(Tag, { variant: "warning", children: "TEST" }) : null
|
|
113
|
-
] });
|
|
114
|
-
}
|
|
115
|
-
},
|
|
116
|
-
{
|
|
117
|
-
accessorKey: "status",
|
|
118
|
-
header: t("billing.invoices.columns.status", "Status"),
|
|
119
|
-
cell: ({ row }) => /* @__PURE__ */ jsx(Tag, { variant: statusVariant(row.original.status), children: row.original.status ?? "\u2014" })
|
|
120
|
-
},
|
|
121
|
-
{
|
|
122
|
-
id: "period",
|
|
123
|
-
header: t("billing.invoices.columns.period", "Period"),
|
|
124
|
-
cell: ({ row }) => {
|
|
125
|
-
const start = row.original.metadata?.bill_period_start;
|
|
126
|
-
const end = row.original.metadata?.bill_period_end;
|
|
127
|
-
if (!start || !end) return "\u2014";
|
|
128
|
-
return /* @__PURE__ */ jsxs("span", { className: "text-xs", children: [
|
|
129
|
-
start,
|
|
130
|
-
" \u2192 ",
|
|
131
|
-
end
|
|
132
|
-
] });
|
|
133
|
-
}
|
|
134
|
-
},
|
|
135
|
-
{
|
|
136
|
-
id: "total",
|
|
137
|
-
header: t("billing.invoices.columns.total", "Total"),
|
|
138
|
-
cell: ({ row }) => formatMoney(row.original.grand_total_gross_amount, row.original.currency_code)
|
|
139
|
-
},
|
|
140
|
-
{
|
|
141
|
-
accessorKey: "outstanding_amount",
|
|
142
|
-
header: t("billing.invoices.columns.outstanding", "Outstanding"),
|
|
143
|
-
cell: ({ row }) => formatMoney(row.original.outstanding_amount, row.original.currency_code)
|
|
144
|
-
},
|
|
145
|
-
{
|
|
146
|
-
accessorKey: "issue_date",
|
|
147
|
-
header: t("billing.invoices.columns.issued", "Issued"),
|
|
148
|
-
cell: ({ row }) => formatDate(row.original.issue_date)
|
|
149
|
-
}
|
|
150
|
-
],
|
|
151
|
-
[t]
|
|
152
|
-
);
|
|
153
9
|
return /* @__PURE__ */ jsx(Page, { children: /* @__PURE__ */ jsx(PageBody, { children: /* @__PURE__ */ jsx(
|
|
154
|
-
|
|
10
|
+
InvoicesTable,
|
|
155
11
|
{
|
|
156
12
|
title: t("billing.invoices.title", "Billing Invoices"),
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
onRefresh: loadRows,
|
|
160
|
-
isRefreshing: loading
|
|
161
|
-
},
|
|
162
|
-
columnChooser: { auto: true },
|
|
163
|
-
perspective: { tableId: "billing-invoices" },
|
|
164
|
-
columns,
|
|
165
|
-
data: rows,
|
|
166
|
-
onRowClick: (row) => router.push(`/backend/billing/invoices/${row.id}`),
|
|
167
|
-
isLoading: loading,
|
|
168
|
-
pagination: {
|
|
169
|
-
page,
|
|
170
|
-
pageSize,
|
|
171
|
-
total,
|
|
172
|
-
totalPages,
|
|
173
|
-
onPageChange: setPage
|
|
174
|
-
},
|
|
175
|
-
filters: filterDefs,
|
|
176
|
-
filterValues: filters,
|
|
177
|
-
onFiltersApply: setFilters,
|
|
178
|
-
onFiltersClear: () => setFilters({}),
|
|
179
|
-
searchValue: search,
|
|
180
|
-
onSearchChange: setSearch
|
|
13
|
+
tableId: "billing-invoices",
|
|
14
|
+
actions: /* @__PURE__ */ jsx(BillingSettingsLink, {})
|
|
181
15
|
}
|
|
182
16
|
) }) });
|
|
183
17
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/modules/billing/backend/billing/invoices/page.tsx"],
|
|
4
|
-
"sourcesContent": ["\"use client\"\nimport * as React from 'react'\nimport {
|
|
5
|
-
"mappings": ";
|
|
4
|
+
"sourcesContent": ["\"use client\"\nimport * as React from 'react'\nimport { useT } from '@open-mercato/shared/lib/i18n/context'\nimport { Page, PageBody } from '@open-mercato/ui/backend/Page'\nimport { InvoicesTable } from '../../../components/InvoicesTable'\nimport { BillingSettingsLink } from '../../../components/BillingSettingsLink'\n\n/**\n * Billing Invoices list \u2014 what the operator opens every morning to review\n * and post drafts, and (Spec B) to chase overdue invoices.\n *\n * Billing documents only (`billing_invoices`); core Sales invoices are a\n * separate surface. The table itself is shared with the account page.\n */\nexport default function BillingInvoicesListPage() {\n const t = useT()\n return (\n <Page>\n <PageBody>\n <InvoicesTable title={t('billing.invoices.title', 'Billing Invoices')} tableId=\"billing-invoices\"\n actions={<BillingSettingsLink />}\n />\n </PageBody>\n </Page>\n )\n}\n"],
|
|
5
|
+
"mappings": ";AAoBmB;AAlBnB,SAAS,YAAY;AACrB,SAAS,MAAM,gBAAgB;AAC/B,SAAS,qBAAqB;AAC9B,SAAS,2BAA2B;AASrB,SAAR,0BAA2C;AAChD,QAAM,IAAI,KAAK;AACf,SACE,oBAAC,QACC,8BAAC,YACC;AAAA,IAAC;AAAA;AAAA,MAAc,OAAO,EAAE,0BAA0B,kBAAkB;AAAA,MAAG,SAAQ;AAAA,MAC7E,SAAS,oBAAC,uBAAoB;AAAA;AAAA,EAChC,GACF,GACF;AAEJ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
3
|
import * as React from "react";
|
|
4
4
|
import Link from "next/link";
|
|
5
|
-
import { Pencil } from "lucide-react";
|
|
6
|
-
import { useParams, useRouter } from "next/navigation";
|
|
5
|
+
import { Pencil, Repeat } from "lucide-react";
|
|
6
|
+
import { useParams, useRouter, useSearchParams } from "next/navigation";
|
|
7
7
|
import { useT } from "@open-mercato/shared/lib/i18n/context";
|
|
8
8
|
import { Page, PageBody, PageHeader } from "@open-mercato/ui/backend/Page";
|
|
9
9
|
import { FormHeader } from "@open-mercato/ui/backend/forms";
|
|
@@ -21,6 +21,8 @@ import {
|
|
|
21
21
|
ItemForm
|
|
22
22
|
} from "../../../../components/ItemForm.js";
|
|
23
23
|
import { DetailCard, DetailField } from "../../../../components/DetailFields.js";
|
|
24
|
+
import { resolveItemReturnTarget } from "../../../../lib/navigation.js";
|
|
25
|
+
import { ChangeItemPriceDialog } from "../../../../components/ChangeItemPriceDialog.js";
|
|
24
26
|
function formatDate(value) {
|
|
25
27
|
if (!value) return "\u2014";
|
|
26
28
|
const parsed = new Date(value);
|
|
@@ -55,7 +57,11 @@ function toFormValues(row) {
|
|
|
55
57
|
uomCode: row.uom_code ?? "",
|
|
56
58
|
subscriptionId: row.subscription_id ?? "",
|
|
57
59
|
subscriptionItemId: row.subscription_item_id ?? "",
|
|
58
|
-
isActive: row.is_active
|
|
60
|
+
isActive: row.is_active,
|
|
61
|
+
chargeTiming: row.charge_timing ?? "in_advance",
|
|
62
|
+
prorate: row.prorate ?? true,
|
|
63
|
+
taxRate: row.tax_rate != null ? String(Number(row.tax_rate)) : "",
|
|
64
|
+
priceBasis: row.price_basis === "gross" ? "gross" : "net"
|
|
59
65
|
};
|
|
60
66
|
if (row.type === "one_time" && typeof rate.amount === "number") {
|
|
61
67
|
out.oneTimeAmount = String(rate.amount);
|
|
@@ -86,7 +92,13 @@ function ItemView({ row }) {
|
|
|
86
92
|
/* @__PURE__ */ jsx(DetailField, { label: t("billing.items.columns.type", "Type"), children: /* @__PURE__ */ jsx(Tag, { variant: "info", children: row.type }) }),
|
|
87
93
|
/* @__PURE__ */ jsx(DetailField, { label: t("billing.items.columns.start", "Start"), children: formatDate(row.bill_start_date) }),
|
|
88
94
|
/* @__PURE__ */ jsx(DetailField, { label: t("billing.items.columns.end", "End"), children: formatDate(row.bill_end_date) }),
|
|
89
|
-
/* @__PURE__ */ jsx(DetailField, { label: t("billing.items.form.rate.title", "Rate"), children:
|
|
95
|
+
/* @__PURE__ */ jsx(DetailField, { label: t("billing.items.form.rate.title", "Rate"), children: /* @__PURE__ */ jsxs("span", { className: "inline-flex items-center gap-2", children: [
|
|
96
|
+
/* @__PURE__ */ jsxs("span", { className: "tabular-nums", children: [
|
|
97
|
+
formatRate(row),
|
|
98
|
+
row.bill_account_currency && formatRate(row) !== "\u2014" ? ` ${row.bill_account_currency}` : ""
|
|
99
|
+
] }),
|
|
100
|
+
/* @__PURE__ */ jsx(Tag, { variant: "neutral", children: row.price_basis === "gross" ? t("billing.items.price_basis.gross", "Gross") : t("billing.items.price_basis.net", "Net") })
|
|
101
|
+
] }) }),
|
|
90
102
|
/* @__PURE__ */ jsx(DetailField, { label: t("billing.items.columns.uom", "UoM"), children: row.uom_code || "\u2014" }),
|
|
91
103
|
/* @__PURE__ */ jsx(DetailField, { label: t("billing.items.form.subscription_id", "Subscription ID"), children: row.subscription_id || "\u2014" }),
|
|
92
104
|
/* @__PURE__ */ jsx(
|
|
@@ -97,6 +109,11 @@ function ItemView({ row }) {
|
|
|
97
109
|
}
|
|
98
110
|
),
|
|
99
111
|
/* @__PURE__ */ jsx(DetailField, { label: t("billing.items.detail.field.source_ref", "Source ref"), children: row.source_ref ? /* @__PURE__ */ jsx("span", { className: "font-mono text-xs", children: row.source_ref }) : "\u2014" }),
|
|
112
|
+
/* @__PURE__ */ jsx(DetailField, { label: t("billing.items.form.tax_rate", "VAT rate (%)"), children: row.tax_rate != null ? `${Number(row.tax_rate)} %` : "\u2014" }),
|
|
113
|
+
row.type === "recurring" ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
114
|
+
/* @__PURE__ */ jsx(DetailField, { label: t("billing.items.form.charge_timing", "Charge timing"), children: /* @__PURE__ */ jsx(Tag, { variant: "neutral", children: row.charge_timing === "in_arrears" ? t("billing.items.charge_timing.in_arrears", "In arrears") : t("billing.items.charge_timing.in_advance", "In advance") }) }),
|
|
115
|
+
/* @__PURE__ */ jsx(DetailField, { label: t("billing.items.form.prorate", "Prorate partial periods"), children: row.prorate === false ? t("billing.common.no", "No") : t("billing.common.yes", "Yes") })
|
|
116
|
+
] }) : null,
|
|
100
117
|
/* @__PURE__ */ jsx(DetailField, { label: t("billing.items.detail.field.billed_to", "Billed through"), children: row.billed_to_date ? formatDate(row.billed_to_date) : "\u2014" }),
|
|
101
118
|
row.currency_mismatch ? /* @__PURE__ */ jsx(
|
|
102
119
|
DetailField,
|
|
@@ -112,8 +129,11 @@ function ItemView({ row }) {
|
|
|
112
129
|
function BillingItemDetailPage(props) {
|
|
113
130
|
const t = useT();
|
|
114
131
|
const router = useRouter();
|
|
132
|
+
const [changePriceOpen, setChangePriceOpen] = React.useState(false);
|
|
115
133
|
const urlParams = useParams();
|
|
116
134
|
const itemId = props.params?.id ?? urlParams?.id ?? "";
|
|
135
|
+
const searchParams = useSearchParams();
|
|
136
|
+
const from = searchParams?.get("from") ?? null;
|
|
117
137
|
const [row, setRow] = React.useState(null);
|
|
118
138
|
const [loading, setLoading] = React.useState(true);
|
|
119
139
|
const [error, setError] = React.useState(null);
|
|
@@ -161,6 +181,10 @@ function BillingItemDetailPage(props) {
|
|
|
161
181
|
payload.uomCode = assembled.uomCode ?? null;
|
|
162
182
|
payload.subscriptionId = assembled.subscriptionId ?? null;
|
|
163
183
|
payload.subscriptionItemId = assembled.subscriptionItemId ?? null;
|
|
184
|
+
if (assembled.chargeTiming !== void 0) payload.chargeTiming = assembled.chargeTiming;
|
|
185
|
+
if (assembled.prorate !== void 0) payload.prorate = assembled.prorate;
|
|
186
|
+
if (assembled.taxRate !== void 0) payload.taxRate = assembled.taxRate;
|
|
187
|
+
if (assembled.priceBasis !== void 0) payload.priceBasis = assembled.priceBasis;
|
|
164
188
|
await apiCallOrThrow("/api/billing/items", {
|
|
165
189
|
method: "PUT",
|
|
166
190
|
headers: { "Content-Type": "application/json" },
|
|
@@ -198,13 +222,13 @@ function BillingItemDetailPage(props) {
|
|
|
198
222
|
body: JSON.stringify({ id: row.id })
|
|
199
223
|
});
|
|
200
224
|
flash(t("billing.items.detail.delete.success", "Item deleted"), "success");
|
|
201
|
-
router.push(
|
|
225
|
+
router.push(resolveItemReturnTarget({ from, billAccountId: row.bill_account_id }));
|
|
202
226
|
} catch (err) {
|
|
203
227
|
const { message } = normalizeCrudServerError(err);
|
|
204
228
|
flash(message || t("billing.items.detail.delete.error", "Delete failed"), "error");
|
|
205
229
|
setDeleting(false);
|
|
206
230
|
}
|
|
207
|
-
}, [confirm, router, row, t]);
|
|
231
|
+
}, [confirm, from, router, row, t]);
|
|
208
232
|
if (error) {
|
|
209
233
|
return /* @__PURE__ */ jsxs(Page, { children: [
|
|
210
234
|
/* @__PURE__ */ jsx(PageHeader, { title: t("billing.items.detail.title", "Billing Item") }),
|
|
@@ -222,11 +246,15 @@ function BillingItemDetailPage(props) {
|
|
|
222
246
|
FormHeader,
|
|
223
247
|
{
|
|
224
248
|
mode: "detail",
|
|
225
|
-
backHref:
|
|
249
|
+
backHref: resolveItemReturnTarget({ from, billAccountId: row.bill_account_id }),
|
|
226
250
|
entityTypeLabel: t("billing.items.detail.title", "Billing Item"),
|
|
227
251
|
title: row.description,
|
|
228
252
|
statusBadge: row.is_active ? /* @__PURE__ */ jsx(Tag, { variant: "success", children: t("billing.common.active", "Active") }) : /* @__PURE__ */ jsx(Tag, { variant: "default", children: t("billing.common.inactive", "Inactive") }),
|
|
229
253
|
actionsContent: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
254
|
+
!editing && row.type === "recurring" && row.is_active ? /* @__PURE__ */ jsxs(Button, { type: "button", variant: "outline", onClick: () => setChangePriceOpen(true), children: [
|
|
255
|
+
/* @__PURE__ */ jsx(Repeat, { size: 16 }),
|
|
256
|
+
t("billing.items.change_price.action", "Change price")
|
|
257
|
+
] }) : null,
|
|
230
258
|
!editing ? /* @__PURE__ */ jsxs(Button, { type: "button", onClick: () => setEditing(true), children: [
|
|
231
259
|
/* @__PURE__ */ jsx(Pencil, { size: 16 }),
|
|
232
260
|
t("billing.common.edit", "Edit")
|
|
@@ -250,11 +278,27 @@ function BillingItemDetailPage(props) {
|
|
|
250
278
|
{
|
|
251
279
|
mode: "edit",
|
|
252
280
|
initial: toFormValues(row),
|
|
281
|
+
accountCurrency: row.bill_account_currency ?? void 0,
|
|
282
|
+
accountBillingMode: row.bill_account_mode ?? void 0,
|
|
253
283
|
submitting: saving,
|
|
254
284
|
onSubmit: handleSubmit,
|
|
255
285
|
onCancel: () => setEditing(false)
|
|
256
286
|
}
|
|
257
287
|
) : /* @__PURE__ */ jsx(ItemView, { row }),
|
|
288
|
+
row.type === "recurring" ? /* @__PURE__ */ jsx(
|
|
289
|
+
ChangeItemPriceDialog,
|
|
290
|
+
{
|
|
291
|
+
open: changePriceOpen,
|
|
292
|
+
onOpenChange: setChangePriceOpen,
|
|
293
|
+
itemId: row.id,
|
|
294
|
+
currentPrice: typeof row.rate_json?.unit_price === "number" ? row.rate_json.unit_price : null,
|
|
295
|
+
currencyCode: row.bill_account_currency,
|
|
296
|
+
priceBasis: row.price_basis === "gross" ? "gross" : "net",
|
|
297
|
+
billStartDate: row.bill_start_date,
|
|
298
|
+
billEndDate: row.bill_end_date,
|
|
299
|
+
onChanged: (newItemId) => router.push(`/backend/billing/items/${encodeURIComponent(newItemId)}`)
|
|
300
|
+
}
|
|
301
|
+
) : null,
|
|
258
302
|
ConfirmDialogElement
|
|
259
303
|
] })
|
|
260
304
|
] });
|