@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,5 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
buildInvoiceLinesFromItems,
|
|
3
|
+
buildRecurringLineDescriptors,
|
|
4
|
+
itemTaxRate,
|
|
5
|
+
writeDraftInvoice,
|
|
6
|
+
type InvoiceLineDescriptor,
|
|
7
|
+
} from '../../lib/invoiceWriter'
|
|
8
|
+
import type { EntityManager } from '@mikro-orm/postgresql'
|
|
9
|
+
import type { BillingAccount, BillingItem } from '../../data/entities'
|
|
3
10
|
|
|
4
11
|
function makeItem(overrides: Partial<BillingItem>): BillingItem {
|
|
5
12
|
return {
|
|
@@ -18,6 +25,8 @@ function makeItem(overrides: Partial<BillingItem>): BillingItem {
|
|
|
18
25
|
sourceRef: overrides.sourceRef ?? null,
|
|
19
26
|
currencyMismatch: overrides.currencyMismatch ?? false,
|
|
20
27
|
billedToDate: overrides.billedToDate ?? null,
|
|
28
|
+
taxRate: overrides.taxRate ?? '0',
|
|
29
|
+
priceBasis: overrides.priceBasis ?? 'net',
|
|
21
30
|
isActive: overrides.isActive ?? true,
|
|
22
31
|
createdAt: overrides.createdAt ?? new Date(),
|
|
23
32
|
updatedAt: overrides.updatedAt ?? new Date(),
|
|
@@ -37,11 +46,13 @@ describe('buildInvoiceLinesFromItems — recurring', () => {
|
|
|
37
46
|
billingItemId: 'a',
|
|
38
47
|
billingType: 'recurring',
|
|
39
48
|
description: 'MRC A',
|
|
40
|
-
|
|
49
|
+
unitPrice: '49.9900',
|
|
41
50
|
quantity: '1',
|
|
42
|
-
|
|
51
|
+
lineAmount: '49.9900',
|
|
52
|
+
priceBasis: 'net',
|
|
53
|
+
taxRate: '0',
|
|
43
54
|
})
|
|
44
|
-
expect(lines[1].
|
|
55
|
+
expect(lines[1].unitPrice).toBe('29.0000')
|
|
45
56
|
})
|
|
46
57
|
|
|
47
58
|
it('rounds unit_price half-up to 2dp before persisting', () => {
|
|
@@ -50,8 +61,8 @@ describe('buildInvoiceLinesFromItems — recurring', () => {
|
|
|
50
61
|
makeItem({ type: 'recurring', rateJson: { unit_price: 1.004 } }), // half-down → 1.00
|
|
51
62
|
]
|
|
52
63
|
const lines = buildInvoiceLinesFromItems(items)
|
|
53
|
-
expect(lines[0].
|
|
54
|
-
expect(lines[1].
|
|
64
|
+
expect(lines[0].unitPrice).toBe('1.0100')
|
|
65
|
+
expect(lines[1].unitPrice).toBe('1.0000')
|
|
55
66
|
})
|
|
56
67
|
|
|
57
68
|
it('skips a recurring item with malformed rateJson (defensive)', () => {
|
|
@@ -81,9 +92,11 @@ describe('buildInvoiceLinesFromItems — one_time', () => {
|
|
|
81
92
|
billingItemId: 'fee',
|
|
82
93
|
billingType: 'one_time',
|
|
83
94
|
description: 'Activation fee',
|
|
84
|
-
|
|
95
|
+
unitPrice: '99.0000',
|
|
85
96
|
quantity: '1',
|
|
86
|
-
|
|
97
|
+
lineAmount: '99.0000',
|
|
98
|
+
priceBasis: 'net',
|
|
99
|
+
taxRate: '0',
|
|
87
100
|
})
|
|
88
101
|
})
|
|
89
102
|
|
|
@@ -96,7 +109,7 @@ describe('buildInvoiceLinesFromItems — one_time', () => {
|
|
|
96
109
|
}),
|
|
97
110
|
]
|
|
98
111
|
const lines = buildInvoiceLinesFromItems(items)
|
|
99
|
-
expect(lines[0].
|
|
112
|
+
expect(lines[0].unitPrice).toBe('-25.5000')
|
|
100
113
|
})
|
|
101
114
|
})
|
|
102
115
|
|
|
@@ -117,3 +130,192 @@ describe('buildInvoiceLinesFromItems — mixed + usage exclusion', () => {
|
|
|
117
130
|
expect(lines.find((l) => l.billingItemId === 'metered')).toBeUndefined()
|
|
118
131
|
})
|
|
119
132
|
})
|
|
133
|
+
|
|
134
|
+
// ─── Spec B: VAT per line ────────────────────────────────────────
|
|
135
|
+
|
|
136
|
+
describe('itemTaxRate', () => {
|
|
137
|
+
it('reads the item rate and treats missing / invalid values as 0', () => {
|
|
138
|
+
expect(itemTaxRate({ taxRate: '23.0000' })).toBe('23')
|
|
139
|
+
expect(itemTaxRate({ taxRate: '8' })).toBe('8')
|
|
140
|
+
expect(itemTaxRate({ taxRate: undefined as unknown as string })).toBe('0')
|
|
141
|
+
expect(itemTaxRate({ taxRate: 'abc' })).toBe('0')
|
|
142
|
+
expect(itemTaxRate({ taxRate: '-5' })).toBe('0')
|
|
143
|
+
})
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
describe('line builders carry the item VAT rate (Spec B)', () => {
|
|
147
|
+
it('one_time and recurring lines take the item rate', () => {
|
|
148
|
+
const lines = buildInvoiceLinesFromItems([
|
|
149
|
+
makeItem({ id: 'r', type: 'recurring', taxRate: '23', rateJson: { unit_price: 100 } }),
|
|
150
|
+
makeItem({ id: 'o', type: 'one_time', taxRate: '8', rateJson: { amount: 50 } }),
|
|
151
|
+
])
|
|
152
|
+
expect(lines.map((l) => l.taxRate)).toEqual(['23', '8'])
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
it('proration and credit lines inherit the item rate', () => {
|
|
156
|
+
const item = { id: 'r', description: 'Plan', chargeTiming: 'in_advance' as const, taxRate: '23', priceBasis: 'net' as const }
|
|
157
|
+
const lines = buildRecurringLineDescriptors(item, [
|
|
158
|
+
{
|
|
159
|
+
kind: 'charge',
|
|
160
|
+
servicePeriodStart: new Date('2026-11-15T00:00:00Z'),
|
|
161
|
+
servicePeriodEnd: new Date('2026-11-30T00:00:00Z'),
|
|
162
|
+
amount: 53.33,
|
|
163
|
+
proration: { activeDays: 16, periodDays: 30 },
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
kind: 'credit',
|
|
167
|
+
servicePeriodStart: new Date('2026-12-10T00:00:00Z'),
|
|
168
|
+
servicePeriodEnd: new Date('2026-12-31T00:00:00Z'),
|
|
169
|
+
amount: -71,
|
|
170
|
+
proration: { activeDays: 22, periodDays: 31 },
|
|
171
|
+
},
|
|
172
|
+
] as never)
|
|
173
|
+
expect(lines.map((l) => l.taxRate)).toEqual(['23', '23'])
|
|
174
|
+
})
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
type Created = { entity: string; data: Record<string, unknown> }
|
|
178
|
+
|
|
179
|
+
function writerEm() {
|
|
180
|
+
const created: Created[] = []
|
|
181
|
+
const em = {
|
|
182
|
+
create: jest.fn((entity: { name: string }, data: Record<string, unknown>) => {
|
|
183
|
+
const row = { id: `${entity.name}-${created.length + 1}`, ...data }
|
|
184
|
+
created.push({ entity: entity.name, data: row })
|
|
185
|
+
return row
|
|
186
|
+
}),
|
|
187
|
+
persist: jest.fn(),
|
|
188
|
+
flush: jest.fn(async () => undefined),
|
|
189
|
+
}
|
|
190
|
+
return { em: em as unknown as EntityManager, created }
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const account = {
|
|
194
|
+
id: 'acc-1',
|
|
195
|
+
organizationId: 'org-1',
|
|
196
|
+
tenantId: 'tenant-1',
|
|
197
|
+
currencyCode: 'PLN',
|
|
198
|
+
} as BillingAccount
|
|
199
|
+
|
|
200
|
+
function line(amount: string, taxRate: string, priceBasis: 'net' | 'gross' = 'net'): InvoiceLineDescriptor {
|
|
201
|
+
return {
|
|
202
|
+
billingItemId: 'item',
|
|
203
|
+
billingType: 'recurring',
|
|
204
|
+
description: 'x',
|
|
205
|
+
unitPrice: amount,
|
|
206
|
+
quantity: '1',
|
|
207
|
+
lineAmount: amount,
|
|
208
|
+
priceBasis,
|
|
209
|
+
taxRate,
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const baseParams = {
|
|
214
|
+
account,
|
|
215
|
+
billDate: new Date('2026-11-01T00:00:00Z'),
|
|
216
|
+
period: { periodStart: new Date('2026-11-01T00:00:00Z'), periodEnd: new Date('2026-11-30T00:00:00Z') },
|
|
217
|
+
billRunId: 'run-1',
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
describe('writeDraftInvoice — VAT (Spec B, B-D2)', () => {
|
|
221
|
+
it('writes per-line VAT and sums rounded lines into the totals (mixed rates)', async () => {
|
|
222
|
+
const { em, created } = writerEm()
|
|
223
|
+
const written = await writeDraftInvoice(em, {
|
|
224
|
+
...baseParams,
|
|
225
|
+
mode: 'real',
|
|
226
|
+
lines: [line('100.0000', '23'), line('33.3300', '8'), line('15.0000', '0')],
|
|
227
|
+
})
|
|
228
|
+
const invoice = created.find((c) => c.entity === 'BillingInvoice')!.data
|
|
229
|
+
const lines = created.filter((c) => c.entity === 'BillingInvoiceLine').map((c) => c.data)
|
|
230
|
+
expect(lines.map((l) => [l.taxRate, l.netAmount, l.taxAmount, l.grossAmount])).toEqual([
|
|
231
|
+
['23', '100.0000', '23.0000', '123.0000'],
|
|
232
|
+
['8', '33.3300', '2.6700', '36.0000'],
|
|
233
|
+
['0', '15.0000', '0.0000', '15.0000'],
|
|
234
|
+
])
|
|
235
|
+
expect(invoice).toMatchObject({
|
|
236
|
+
subtotalNet: '148.3300',
|
|
237
|
+
taxTotal: '25.6700',
|
|
238
|
+
totalGross: '174.0000',
|
|
239
|
+
outstanding: '174.0000',
|
|
240
|
+
})
|
|
241
|
+
expect(written).toMatchObject({ totalNet: '148.3300', totalGross: '174.0000' })
|
|
242
|
+
})
|
|
243
|
+
|
|
244
|
+
it('rounds VAT per line half-up (0.005 edge)', async () => {
|
|
245
|
+
const { em, created } = writerEm()
|
|
246
|
+
// 0.05 × 23 % = 0.0115 → 0.01 ; 2.15 × 23 % = 0.4945 → 0.49 ; 0.5 × 5 % = 0.025 → 0.03
|
|
247
|
+
await writeDraftInvoice(em, {
|
|
248
|
+
...baseParams,
|
|
249
|
+
mode: 'real',
|
|
250
|
+
lines: [line('0.0500', '23'), line('2.1500', '23'), line('0.5000', '5')],
|
|
251
|
+
})
|
|
252
|
+
const taxes = created.filter((c) => c.entity === 'BillingInvoiceLine').map((c) => c.data.taxAmount)
|
|
253
|
+
expect(taxes).toEqual(['0.0100', '0.4900', '0.0300'])
|
|
254
|
+
})
|
|
255
|
+
|
|
256
|
+
it('keeps the sign on credit lines (negative net → negative VAT and gross)', async () => {
|
|
257
|
+
const { em, created } = writerEm()
|
|
258
|
+
await writeDraftInvoice(em, {
|
|
259
|
+
...baseParams,
|
|
260
|
+
mode: 'real',
|
|
261
|
+
lines: [line('100.0000', '23'), line('-40.0000', '23')],
|
|
262
|
+
})
|
|
263
|
+
const credit = created.filter((c) => c.entity === 'BillingInvoiceLine')[1].data
|
|
264
|
+
expect([credit.netAmount, credit.taxAmount, credit.grossAmount]).toEqual(['-40.0000', '-9.2000', '-49.2000'])
|
|
265
|
+
expect(created.find((c) => c.entity === 'BillingInvoice')!.data.totalGross).toBe('73.8000')
|
|
266
|
+
})
|
|
267
|
+
|
|
268
|
+
it('dry mode computes VAT totals without persisting', async () => {
|
|
269
|
+
const { em, created } = writerEm()
|
|
270
|
+
const written = await writeDraftInvoice(em, { ...baseParams, mode: 'dry', lines: [line('10.0000', '23')] })
|
|
271
|
+
expect(created).toHaveLength(0)
|
|
272
|
+
expect(written).toEqual({ invoiceId: null, invoiceNumber: null, totalNet: '10.0000', totalGross: '12.3000' })
|
|
273
|
+
})
|
|
274
|
+
})
|
|
275
|
+
|
|
276
|
+
// ─── Spec F: price basis (F-D2) ──────────────────────────────────
|
|
277
|
+
|
|
278
|
+
describe('writeDraftInvoice — gross price basis (Spec F)', () => {
|
|
279
|
+
it('reproduces a typed gross exactly (49.99 @ 23 %) and derives the net unit price', async () => {
|
|
280
|
+
const { em, created } = writerEm()
|
|
281
|
+
await writeDraftInvoice(em, { ...baseParams, mode: 'real', lines: [line('49.9900', '23', 'gross')] })
|
|
282
|
+
const persisted = created.find((c) => c.entity === 'BillingInvoiceLine')!.data
|
|
283
|
+
expect([persisted.netAmount, persisted.taxAmount, persisted.grossAmount]).toEqual(['40.6400', '9.3500', '49.9900'])
|
|
284
|
+
expect(persisted.unitPriceNet).toBe('40.6423')
|
|
285
|
+
expect(created.find((c) => c.entity === 'BillingInvoice')!.data.totalGross).toBe('49.9900')
|
|
286
|
+
})
|
|
287
|
+
|
|
288
|
+
it('keeps the net path unchanged (regression)', async () => {
|
|
289
|
+
const { em, created } = writerEm()
|
|
290
|
+
await writeDraftInvoice(em, { ...baseParams, mode: 'real', lines: [line('40.6400', '23')] })
|
|
291
|
+
const persisted = created.find((c) => c.entity === 'BillingInvoiceLine')!.data
|
|
292
|
+
expect([persisted.netAmount, persisted.taxAmount, persisted.grossAmount, persisted.unitPriceNet]).toEqual([
|
|
293
|
+
'40.6400',
|
|
294
|
+
'9.3500',
|
|
295
|
+
'49.9900',
|
|
296
|
+
'40.6400',
|
|
297
|
+
])
|
|
298
|
+
})
|
|
299
|
+
|
|
300
|
+
it('carries the item basis on one-time, recurring and prorated lines', () => {
|
|
301
|
+
const built = buildInvoiceLinesFromItems([
|
|
302
|
+
makeItem({ id: 'g', type: 'recurring', priceBasis: 'gross', rateJson: { unit_price: 60 } }),
|
|
303
|
+
makeItem({ id: 'n', type: 'one_time', rateJson: { amount: 10 } }),
|
|
304
|
+
])
|
|
305
|
+
expect(built.map((l) => l.priceBasis)).toEqual(['gross', 'net'])
|
|
306
|
+
const prorated = buildRecurringLineDescriptors(
|
|
307
|
+
{ id: 'g', description: 'Plan', chargeTiming: 'in_advance', taxRate: '23', priceBasis: 'gross' },
|
|
308
|
+
[
|
|
309
|
+
{
|
|
310
|
+
billingItemId: 'g',
|
|
311
|
+
kind: 'charge',
|
|
312
|
+
servicePeriodStart: new Date('2026-11-15T00:00:00Z'),
|
|
313
|
+
servicePeriodEnd: new Date('2026-11-30T00:00:00Z'),
|
|
314
|
+
amount: 32,
|
|
315
|
+
proration: { activeDays: 16, periodDays: 30 },
|
|
316
|
+
},
|
|
317
|
+
],
|
|
318
|
+
)
|
|
319
|
+
expect(prorated[0]).toMatchObject({ priceBasis: 'gross', lineAmount: '32.0000' })
|
|
320
|
+
})
|
|
321
|
+
})
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { itemBillingState } from '../../lib/itemBillingState'
|
|
2
|
+
|
|
3
|
+
const TODAY = '2026-11-15'
|
|
4
|
+
const recurring = (overrides: Record<string, unknown> = {}) => ({
|
|
5
|
+
type: 'recurring' as const,
|
|
6
|
+
is_active: true,
|
|
7
|
+
bill_start_date: '2026-11-01',
|
|
8
|
+
bill_end_date: null,
|
|
9
|
+
billed_to_date: null,
|
|
10
|
+
...overrides,
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
describe('itemBillingState', () => {
|
|
14
|
+
it('inactive and usage items short-circuit', () => {
|
|
15
|
+
expect(itemBillingState(recurring({ is_active: false }), TODAY).status).toBe('inactive')
|
|
16
|
+
expect(itemBillingState(recurring({ type: 'usage' }), TODAY).status).toBe('metered')
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
it('not billed yet: scheduled when it starts later, awaiting a run once started', () => {
|
|
20
|
+
expect(itemBillingState(recurring({ bill_start_date: '2026-12-01' }), TODAY)).toEqual({ status: 'scheduled', date: '2026-12-01' })
|
|
21
|
+
expect(itemBillingState(recurring(), TODAY)).toEqual({ status: 'awaiting_run', date: null })
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
it('recurring charged ahead is current; charged through a past day is due from the next day', () => {
|
|
25
|
+
expect(itemBillingState(recurring({ billed_to_date: '2026-12-14' }), TODAY)).toEqual({ status: 'current', date: '2026-12-14' })
|
|
26
|
+
expect(itemBillingState(recurring({ billed_to_date: '2026-11-15' }), TODAY).status).toBe('current')
|
|
27
|
+
expect(itemBillingState(recurring({ billed_to_date: '2026-10-31' }), TODAY)).toEqual({ status: 'due', date: '2026-11-01' })
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
it('recurring charged through its end date is fully billed', () => {
|
|
31
|
+
expect(
|
|
32
|
+
itemBillingState(recurring({ bill_end_date: '2026-11-30', billed_to_date: '2026-11-30T00:00:00.000Z' }), TODAY),
|
|
33
|
+
).toEqual({ status: 'fully_billed', date: '2026-11-30' })
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
it('one-time: billed once a run charged it', () => {
|
|
37
|
+
const fee = { ...recurring(), type: 'one_time' as const }
|
|
38
|
+
expect(itemBillingState({ ...fee, billed_to_date: '2026-11-30' }, TODAY).status).toBe('billed')
|
|
39
|
+
expect(itemBillingState(fee, TODAY).status).toBe('awaiting_run')
|
|
40
|
+
expect(itemBillingState({ ...fee, bill_start_date: '2027-01-01' }, TODAY).status).toBe('scheduled')
|
|
41
|
+
})
|
|
42
|
+
})
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
jest.mock('@open-mercato/shared/lib/commands/helpers', () => {
|
|
2
|
+
const actual = jest.requireActual('@open-mercato/shared/lib/commands/helpers')
|
|
3
|
+
return { ...actual, emitCrudSideEffects: jest.fn(async () => undefined) }
|
|
4
|
+
})
|
|
5
|
+
|
|
6
|
+
import { planPriceChange } from '../../lib/itemPriceChange'
|
|
7
|
+
import { computeRecurringLines } from '../../lib/servicePeriods'
|
|
8
|
+
import { changeItemPriceCommand } from '../../commands/items'
|
|
9
|
+
|
|
10
|
+
const iso = (date: Date | null) => (date ? date.toISOString().slice(0, 10) : null)
|
|
11
|
+
const d = (value: string) => new Date(`${value}T00:00:00.000Z`)
|
|
12
|
+
|
|
13
|
+
const recurring = {
|
|
14
|
+
type: 'recurring',
|
|
15
|
+
isActive: true,
|
|
16
|
+
deletedAt: null,
|
|
17
|
+
billStartDate: '2026-11-01',
|
|
18
|
+
billEndDate: null as string | null,
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
describe('planPriceChange', () => {
|
|
22
|
+
it('ends the current item the day before and keeps the original end date on the copy', () => {
|
|
23
|
+
const result = planPriceChange({ ...recurring, billEndDate: '2027-06-30' }, '2026-12-15')
|
|
24
|
+
if (!result.ok) throw new Error(result.error)
|
|
25
|
+
expect(iso(result.plan.oldItemEndDate)).toBe('2026-12-14')
|
|
26
|
+
expect(iso(result.plan.newItemStartDate)).toBe('2026-12-15')
|
|
27
|
+
expect(iso(result.plan.newItemEndDate)).toBe('2027-06-30')
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
it('refuses non-recurring, inactive, on/before start and after end', () => {
|
|
31
|
+
expect(planPriceChange({ ...recurring, type: 'one_time' }, '2026-12-15')).toEqual({
|
|
32
|
+
ok: false,
|
|
33
|
+
error: 'billing.item.price_change_recurring_only',
|
|
34
|
+
})
|
|
35
|
+
expect(planPriceChange({ ...recurring, isActive: false }, '2026-12-15')).toMatchObject({ error: 'billing.item.price_change_inactive' })
|
|
36
|
+
expect(planPriceChange(recurring, '2026-11-01')).toMatchObject({ error: 'billing.item.price_change_before_start' })
|
|
37
|
+
expect(planPriceChange({ ...recurring, billEndDate: '2026-12-31' }, '2027-01-01')).toMatchObject({
|
|
38
|
+
error: 'billing.item.price_change_after_end',
|
|
39
|
+
})
|
|
40
|
+
})
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
describe('price change never bills a day twice (engine maths)', () => {
|
|
44
|
+
// Monthly in advance, billed through Dec 13 at 30; price changes to 60 on Nov 24.
|
|
45
|
+
const base = {
|
|
46
|
+
chargeTiming: 'in_advance' as const,
|
|
47
|
+
billStartDate: d('2026-11-14'),
|
|
48
|
+
billedToDate: d('2026-12-13'),
|
|
49
|
+
isActive: true,
|
|
50
|
+
deletedAt: null,
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
it('prorate on: the old item credits Nov 24 – Dec 13, the new item charges the same days at the new price', () => {
|
|
54
|
+
const old = computeRecurringLines(
|
|
55
|
+
{ ...base, id: 'old', prorate: true, billEndDate: d('2026-11-23'), unitPrice: 30 },
|
|
56
|
+
{ billDate: d('2026-12-14'), cycle: 'monthly' },
|
|
57
|
+
)
|
|
58
|
+
const fresh = computeRecurringLines(
|
|
59
|
+
{ ...base, id: 'new', prorate: true, billStartDate: d('2026-11-24'), billEndDate: null, billedToDate: null, unitPrice: 60 },
|
|
60
|
+
{ billDate: d('2026-12-14'), cycle: 'monthly' },
|
|
61
|
+
)
|
|
62
|
+
const credit = old.lines.find((line) => line.kind === 'credit')!
|
|
63
|
+
expect([iso(credit.servicePeriodStart), iso(credit.servicePeriodEnd)]).toEqual(['2026-11-24', '2026-12-13'])
|
|
64
|
+
expect(credit.amount).toBeLessThan(0)
|
|
65
|
+
const recharge = fresh.lines.find((line) => iso(line.servicePeriodStart) === '2026-11-24')!
|
|
66
|
+
expect(iso(recharge.servicePeriodEnd)).toBe('2026-12-13')
|
|
67
|
+
expect(recharge.amount).toBeCloseTo(-credit.amount * 2, 1) // same days, double the price
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
it('prorate off: no credit, and the new item starts charging at its next full period', () => {
|
|
71
|
+
const old = computeRecurringLines(
|
|
72
|
+
{ ...base, id: 'old', prorate: false, billEndDate: d('2026-11-23'), unitPrice: 30 },
|
|
73
|
+
{ billDate: d('2026-12-14'), cycle: 'monthly' },
|
|
74
|
+
)
|
|
75
|
+
const fresh = computeRecurringLines(
|
|
76
|
+
{ ...base, id: 'new', prorate: false, billStartDate: d('2026-11-24'), billEndDate: null, billedToDate: null, unitPrice: 60 },
|
|
77
|
+
{ billDate: d('2026-12-14'), cycle: 'monthly' },
|
|
78
|
+
)
|
|
79
|
+
expect(old.lines).toHaveLength(0)
|
|
80
|
+
expect(fresh.lines.map((line) => [iso(line.servicePeriodStart), iso(line.servicePeriodEnd)])).toEqual([
|
|
81
|
+
['2026-12-14', '2027-01-13'],
|
|
82
|
+
])
|
|
83
|
+
})
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
describe('changeItemPriceCommand', () => {
|
|
87
|
+
const TENANT = '11111111-1111-4111-8111-111111111111'
|
|
88
|
+
const ORG = '22222222-2222-4222-8222-222222222222'
|
|
89
|
+
const ITEM = '33333333-3333-4333-8333-333333333333'
|
|
90
|
+
|
|
91
|
+
function env(record: Record<string, unknown> | null) {
|
|
92
|
+
const created: Record<string, unknown>[] = []
|
|
93
|
+
const em = {
|
|
94
|
+
findOne: jest.fn(async () => record),
|
|
95
|
+
create: jest.fn((_entity: unknown, data: Record<string, unknown>) => {
|
|
96
|
+
const row = { id: 'new-item', ...data }
|
|
97
|
+
created.push(row)
|
|
98
|
+
return row
|
|
99
|
+
}),
|
|
100
|
+
persist: jest.fn(),
|
|
101
|
+
flush: jest.fn(async () => undefined),
|
|
102
|
+
transactional: jest.fn(async (fn: (tem: unknown) => Promise<unknown>): Promise<unknown> => fn(em)),
|
|
103
|
+
fork: jest.fn((): unknown => em),
|
|
104
|
+
}
|
|
105
|
+
const ctx = {
|
|
106
|
+
container: { resolve: jest.fn((name: string) => (name === 'dataEngine' ? {} : em)) },
|
|
107
|
+
auth: { tenantId: TENANT, orgId: ORG },
|
|
108
|
+
selectedOrganizationId: ORG,
|
|
109
|
+
organizationIds: [ORG],
|
|
110
|
+
organizationScope: null,
|
|
111
|
+
}
|
|
112
|
+
return { ctx, created }
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
it('ends the item and creates a copy with the new price, keeping everything else', async () => {
|
|
116
|
+
const record: Record<string, unknown> = {
|
|
117
|
+
id: ITEM,
|
|
118
|
+
tenantId: TENANT,
|
|
119
|
+
organizationId: ORG,
|
|
120
|
+
billAccountId: 'acc',
|
|
121
|
+
type: 'recurring',
|
|
122
|
+
isActive: true,
|
|
123
|
+
deletedAt: null,
|
|
124
|
+
billStartDate: '2026-11-01',
|
|
125
|
+
billEndDate: null,
|
|
126
|
+
description: 'Plan',
|
|
127
|
+
rateJson: { unit_price: 49 },
|
|
128
|
+
chargeTiming: 'in_arrears',
|
|
129
|
+
prorate: false,
|
|
130
|
+
taxRate: '23',
|
|
131
|
+
priceBasis: 'gross',
|
|
132
|
+
sourceRef: 'cpq-123',
|
|
133
|
+
subscriptionId: 'sub-1',
|
|
134
|
+
}
|
|
135
|
+
const { ctx, created } = env(record)
|
|
136
|
+
const result = await changeItemPriceCommand.execute(
|
|
137
|
+
{ tenantId: TENANT, organizationId: ORG, id: ITEM, effectiveDate: d('2026-12-15'), unitPrice: 59 },
|
|
138
|
+
ctx as never,
|
|
139
|
+
)
|
|
140
|
+
expect(result).toEqual({ previousItemId: ITEM, newItemId: 'new-item' })
|
|
141
|
+
expect(iso(record.billEndDate as Date)).toBe('2026-12-14')
|
|
142
|
+
expect(created[0]).toMatchObject({
|
|
143
|
+
billAccountId: 'acc',
|
|
144
|
+
rateJson: { unit_price: 59 },
|
|
145
|
+
chargeTiming: 'in_arrears',
|
|
146
|
+
prorate: false,
|
|
147
|
+
taxRate: '23',
|
|
148
|
+
priceBasis: 'gross',
|
|
149
|
+
subscriptionId: 'sub-1',
|
|
150
|
+
sourceRef: null,
|
|
151
|
+
billedToDate: null,
|
|
152
|
+
})
|
|
153
|
+
expect(iso(created[0].billStartDate as Date)).toBe('2026-12-15')
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
it('maps planning errors to 422 with the code', async () => {
|
|
157
|
+
const { ctx } = env({ id: ITEM, type: 'one_time', isActive: true, deletedAt: null, billStartDate: '2026-11-01' })
|
|
158
|
+
await expect(
|
|
159
|
+
changeItemPriceCommand.execute(
|
|
160
|
+
{ tenantId: TENANT, organizationId: ORG, id: ITEM, effectiveDate: d('2026-12-15'), unitPrice: 59 },
|
|
161
|
+
ctx as never,
|
|
162
|
+
),
|
|
163
|
+
).rejects.toMatchObject({ status: 422, body: { code: 'billing.item.price_change_recurring_only' } })
|
|
164
|
+
})
|
|
165
|
+
})
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { counterpartAmount, lineVat, priceBasisOf, unitPriceNetOf } from '../../lib/lineAmounts'
|
|
2
|
+
import { billingItemCreateSchema, isTieredRate } from '../../data/validators'
|
|
3
|
+
|
|
4
|
+
describe('lineVat (Spec F, F-D2)', () => {
|
|
5
|
+
it('net basis: tax on top of the net', () => {
|
|
6
|
+
expect(lineVat({ amount: 49, priceBasis: 'net', taxRate: 23 })).toEqual({ net: 49, tax: 11.27, gross: 60.27 })
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
it('gross basis: the typed gross is reproduced exactly, for every cent', () => {
|
|
10
|
+
// Net-only storage cannot reach ~1 in 5 gross values at 23 %; the basis can.
|
|
11
|
+
for (let cents = 4900; cents <= 5100; cents += 1) {
|
|
12
|
+
const gross = cents / 100
|
|
13
|
+
const vat = lineVat({ amount: gross, priceBasis: 'gross', taxRate: 23 })
|
|
14
|
+
expect(vat.gross).toBe(gross)
|
|
15
|
+
expect(Math.round((vat.net + vat.tax) * 100)).toBe(cents)
|
|
16
|
+
}
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
it('gross basis: rounds once on the extended amount (quantity / proration)', () => {
|
|
20
|
+
// 3 × 12.30 gross = 36.90 → net 30.00, tax 6.90 (not 3 × rounded unit nets).
|
|
21
|
+
expect(lineVat({ amount: 36.9, priceBasis: 'gross', taxRate: 23 })).toEqual({ net: 30, tax: 6.9, gross: 36.9 })
|
|
22
|
+
// Prorated 16/30 of 49.99 gross = 26.66 (2 dp) → split on that amount.
|
|
23
|
+
const prorated = lineVat({ amount: 26.66, priceBasis: 'gross', taxRate: 23 })
|
|
24
|
+
expect(prorated.gross).toBe(26.66)
|
|
25
|
+
expect(prorated.net).toBe(21.67)
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
it('0 % VAT: net = gross on both bases; negative amounts keep their sign', () => {
|
|
29
|
+
expect(lineVat({ amount: 20, priceBasis: 'gross', taxRate: 0 })).toEqual({ net: 20, tax: 0, gross: 20 })
|
|
30
|
+
expect(lineVat({ amount: '-12.30', priceBasis: 'gross', taxRate: '23' })).toEqual({ net: -10, tax: -2.3, gross: -12.3 })
|
|
31
|
+
})
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
describe('price basis helpers', () => {
|
|
35
|
+
it('priceBasisOf treats anything but gross as net', () => {
|
|
36
|
+
expect(priceBasisOf('gross')).toBe('gross')
|
|
37
|
+
expect(priceBasisOf('net')).toBe('net')
|
|
38
|
+
expect(priceBasisOf(undefined)).toBe('net')
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
it('unitPriceNetOf keeps the net price and derives it from a gross one (4 dp)', () => {
|
|
42
|
+
expect(unitPriceNetOf(49, 'net', 23)).toBe('49.0000')
|
|
43
|
+
expect(unitPriceNetOf(60.27, 'gross', 23)).toBe('49.0000')
|
|
44
|
+
expect(unitPriceNetOf(10, 'gross', 0)).toBe('10.0000')
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
it('counterpartAmount shows the other side for the form preview', () => {
|
|
48
|
+
expect(counterpartAmount(49, 'net', 23)).toBe(60.27)
|
|
49
|
+
expect(counterpartAmount(60.27, 'gross', 23)).toBe(49)
|
|
50
|
+
})
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
describe('item validators — price basis', () => {
|
|
54
|
+
const base = {
|
|
55
|
+
tenantId: '11111111-1111-4111-8111-111111111111',
|
|
56
|
+
organizationId: '22222222-2222-4222-8222-222222222222',
|
|
57
|
+
billAccountId: '33333333-3333-4333-8333-333333333333',
|
|
58
|
+
billStartDate: '2026-11-14',
|
|
59
|
+
description: 'Plan',
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
it('accepts a gross basis on recurring and simple usage rates', () => {
|
|
63
|
+
expect(billingItemCreateSchema.safeParse({ ...base, type: 'recurring', rateJson: { unit_price: 60 }, priceBasis: 'gross' }).success).toBe(true)
|
|
64
|
+
expect(
|
|
65
|
+
billingItemCreateSchema.safeParse({ ...base, type: 'usage', uomCode: 'gb', rateJson: { unit_price: 0.5 }, priceBasis: 'gross' }).success,
|
|
66
|
+
).toBe(true)
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
it('rejects a gross basis on a tiered usage rate', () => {
|
|
70
|
+
const result = billingItemCreateSchema.safeParse({
|
|
71
|
+
...base,
|
|
72
|
+
type: 'usage',
|
|
73
|
+
uomCode: 'gb',
|
|
74
|
+
priceBasis: 'gross',
|
|
75
|
+
rateJson: { model: 'volume', tiers: [{ up_to: null, unit_price: 1 }] },
|
|
76
|
+
})
|
|
77
|
+
expect(result.success).toBe(false)
|
|
78
|
+
if (!result.success) expect(result.error.issues.map((i) => i.message)).toContain('billing.item.gross_tiered_unsupported')
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
it('isTieredRate recognises the tiered shape only', () => {
|
|
82
|
+
expect(isTieredRate({ model: 'graduated', tiers: [] })).toBe(true)
|
|
83
|
+
expect(isTieredRate({ unit_price: 1 })).toBe(false)
|
|
84
|
+
expect(isTieredRate(null)).toBe(false)
|
|
85
|
+
})
|
|
86
|
+
})
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ITEMS_LIST_HREF,
|
|
3
|
+
accountHref,
|
|
4
|
+
itemDetailHref,
|
|
5
|
+
resolveItemReturnTarget,
|
|
6
|
+
INVOICES_LIST_HREF,
|
|
7
|
+
invoiceDetailHref,
|
|
8
|
+
invoicePdfHref,
|
|
9
|
+
resolveInvoiceReturnTarget,
|
|
10
|
+
isAccountTab,
|
|
11
|
+
} from '../../lib/navigation'
|
|
12
|
+
|
|
13
|
+
describe('resolveItemReturnTarget', () => {
|
|
14
|
+
it('returns to the owning account by default', () => {
|
|
15
|
+
expect(resolveItemReturnTarget({ billAccountId: 'acc-1' })).toBe('/backend/billing/accounts/acc-1?tab=items')
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
it('returns to the items list when opened from it', () => {
|
|
19
|
+
expect(resolveItemReturnTarget({ from: 'items', billAccountId: 'acc-1' })).toBe(ITEMS_LIST_HREF)
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
it('ignores unknown `from` values', () => {
|
|
23
|
+
expect(resolveItemReturnTarget({ from: 'elsewhere', billAccountId: 'acc-1' })).toBe(accountHref('acc-1', 'items'))
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
it('falls back to the items list without an account', () => {
|
|
27
|
+
expect(resolveItemReturnTarget({})).toBe(ITEMS_LIST_HREF)
|
|
28
|
+
expect(resolveItemReturnTarget({ billAccountId: ' ' })).toBe(ITEMS_LIST_HREF)
|
|
29
|
+
expect(resolveItemReturnTarget({ from: null, billAccountId: null })).toBe(ITEMS_LIST_HREF)
|
|
30
|
+
})
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
describe('itemDetailHref', () => {
|
|
34
|
+
it('tags links from the items list', () => {
|
|
35
|
+
expect(itemDetailHref('it-1')).toBe('/backend/billing/items/it-1')
|
|
36
|
+
expect(itemDetailHref('it-1', { fromItemsList: true })).toBe('/backend/billing/items/it-1?from=items')
|
|
37
|
+
})
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
describe('invoice navigation (Spec B)', () => {
|
|
41
|
+
it('links to the invoice with a return-to-account marker when opened from an account', () => {
|
|
42
|
+
expect(invoiceDetailHref('inv-1')).toBe('/backend/billing/invoices/inv-1')
|
|
43
|
+
expect(invoiceDetailHref('inv-1', { fromAccountId: 'acc 1' })).toBe(
|
|
44
|
+
'/backend/billing/invoices/inv-1?from=account&accountId=acc%201',
|
|
45
|
+
)
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
it('returns to the account only when opened from it', () => {
|
|
49
|
+
expect(resolveInvoiceReturnTarget({ from: 'account', accountId: 'acc-1' })).toBe(accountHref('acc-1', 'invoices'))
|
|
50
|
+
expect(resolveInvoiceReturnTarget({ from: 'account', accountId: ' ' })).toBe(INVOICES_LIST_HREF)
|
|
51
|
+
expect(resolveInvoiceReturnTarget({ from: null, accountId: 'acc-1' })).toBe(INVOICES_LIST_HREF)
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
it('builds the PDF endpoint', () => {
|
|
55
|
+
expect(invoicePdfHref('inv-1')).toBe('/api/billing/invoices/inv-1/pdf')
|
|
56
|
+
})
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
describe('account workspace tabs (Spec F, F8)', () => {
|
|
60
|
+
it('deep-links a tab and leaves the default overview out of the URL', () => {
|
|
61
|
+
expect(accountHref('acc-1')).toBe('/backend/billing/accounts/acc-1')
|
|
62
|
+
expect(accountHref('acc-1', 'overview')).toBe('/backend/billing/accounts/acc-1')
|
|
63
|
+
expect(accountHref('acc-1', 'runs')).toBe('/backend/billing/accounts/acc-1?tab=runs')
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
it('recognises valid tab ids only', () => {
|
|
67
|
+
expect(isAccountTab('invoices')).toBe(true)
|
|
68
|
+
expect(isAccountTab('nope')).toBe(false)
|
|
69
|
+
expect(isAccountTab(null)).toBe(false)
|
|
70
|
+
})
|
|
71
|
+
})
|