@dainamite/billing 0.19.0 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +172 -0
- package/README.md +14 -0
- package/dist/modules/billing/acl.js +13 -1
- package/dist/modules/billing/acl.js.map +2 -2
- package/dist/modules/billing/api/accounts/[id]/summary/route.js +52 -0
- package/dist/modules/billing/api/accounts/[id]/summary/route.js.map +7 -0
- package/dist/modules/billing/api/accounts/route.js +46 -4
- package/dist/modules/billing/api/accounts/route.js.map +2 -2
- package/dist/modules/billing/api/export/account/[id]/route.js +16 -12
- package/dist/modules/billing/api/export/account/[id]/route.js.map +2 -2
- package/dist/modules/billing/api/invoices/[id]/memos/route.js +54 -0
- package/dist/modules/billing/api/invoices/[id]/memos/route.js.map +7 -0
- package/dist/modules/billing/api/invoices/[id]/pdf/route.js +69 -0
- package/dist/modules/billing/api/invoices/[id]/pdf/route.js.map +7 -0
- package/dist/modules/billing/api/invoices/[id]/route.js +44 -24
- package/dist/modules/billing/api/invoices/[id]/route.js.map +2 -2
- package/dist/modules/billing/api/invoices/[id]/send/route.js +107 -0
- package/dist/modules/billing/api/invoices/[id]/send/route.js.map +7 -0
- package/dist/modules/billing/api/invoices/add-line/route.js +3 -3
- package/dist/modules/billing/api/invoices/add-line/route.js.map +2 -2
- package/dist/modules/billing/api/invoices/delete-draft/route.js +33 -0
- package/dist/modules/billing/api/invoices/delete-draft/route.js.map +7 -0
- package/dist/modules/billing/api/invoices/edit-line/route.js +3 -3
- package/dist/modules/billing/api/invoices/edit-line/route.js.map +2 -2
- package/dist/modules/billing/api/invoices/post/route.js +2 -2
- package/dist/modules/billing/api/invoices/post/route.js.map +2 -2
- package/dist/modules/billing/api/invoices/remove-line/route.js +3 -3
- package/dist/modules/billing/api/invoices/remove-line/route.js.map +2 -2
- package/dist/modules/billing/api/invoices/route.js +45 -46
- package/dist/modules/billing/api/invoices/route.js.map +2 -2
- package/dist/modules/billing/api/items/bulk/route.js +1 -1
- package/dist/modules/billing/api/items/bulk/route.js.map +2 -2
- package/dist/modules/billing/api/items/change-price/route.js +44 -0
- package/dist/modules/billing/api/items/change-price/route.js.map +7 -0
- package/dist/modules/billing/api/items/route.js +19 -7
- package/dist/modules/billing/api/items/route.js.map +2 -2
- package/dist/modules/billing/api/payment-imports/[id]/route.js +49 -0
- package/dist/modules/billing/api/payment-imports/[id]/route.js.map +7 -0
- package/dist/modules/billing/api/payment-imports/route.js +57 -0
- package/dist/modules/billing/api/payment-imports/route.js.map +7 -0
- package/dist/modules/billing/api/payments/[id]/route.js +60 -0
- package/dist/modules/billing/api/payments/[id]/route.js.map +7 -0
- package/dist/modules/billing/api/payments/allocate/route.js +35 -0
- package/dist/modules/billing/api/payments/allocate/route.js.map +7 -0
- package/dist/modules/billing/api/payments/assign/route.js +36 -0
- package/dist/modules/billing/api/payments/assign/route.js.map +7 -0
- package/dist/modules/billing/api/payments/convert-to-topup/route.js +35 -0
- package/dist/modules/billing/api/payments/convert-to-topup/route.js.map +7 -0
- package/dist/modules/billing/api/payments/ignore/route.js +35 -0
- package/dist/modules/billing/api/payments/ignore/route.js.map +7 -0
- package/dist/modules/billing/api/payments/import/route.js +63 -0
- package/dist/modules/billing/api/payments/import/route.js.map +7 -0
- package/dist/modules/billing/api/payments/restore/route.js +35 -0
- package/dist/modules/billing/api/payments/restore/route.js.map +7 -0
- package/dist/modules/billing/api/payments/route.js +114 -0
- package/dist/modules/billing/api/payments/route.js.map +7 -0
- package/dist/modules/billing/api/payments/unallocate/route.js +35 -0
- package/dist/modules/billing/api/payments/unallocate/route.js.map +7 -0
- package/dist/modules/billing/api/payments/unassign/route.js +35 -0
- package/dist/modules/billing/api/payments/unassign/route.js.map +7 -0
- package/dist/modules/billing/api/run-outcomes/route.js +44 -7
- package/dist/modules/billing/api/run-outcomes/route.js.map +2 -2
- package/dist/modules/billing/api/runs/[id]/post-drafts/route.js +61 -0
- package/dist/modules/billing/api/runs/[id]/post-drafts/route.js.map +7 -0
- package/dist/modules/billing/api/runs/[id]/route.js +53 -0
- package/dist/modules/billing/api/runs/[id]/route.js.map +7 -0
- package/dist/modules/billing/api/runs/retry-failed/route.js +3 -3
- package/dist/modules/billing/api/runs/retry-failed/route.js.map +2 -2
- package/dist/modules/billing/api/runs/route.js +11 -5
- package/dist/modules/billing/api/runs/route.js.map +2 -2
- package/dist/modules/billing/api/settings/number-preview/route.js +42 -0
- package/dist/modules/billing/api/settings/number-preview/route.js.map +7 -0
- package/dist/modules/billing/api/settings/route.js +92 -0
- package/dist/modules/billing/api/settings/route.js.map +7 -0
- package/dist/modules/billing/api/statements/route.js +3 -0
- package/dist/modules/billing/api/statements/route.js.map +2 -2
- package/dist/modules/billing/api/test-invoices/wipe/route.js +2 -2
- package/dist/modules/billing/api/test-invoices/wipe/route.js.map +2 -2
- package/dist/modules/billing/backend/billing/accounts/[id]/page.js +121 -232
- package/dist/modules/billing/backend/billing/accounts/[id]/page.js.map +2 -2
- package/dist/modules/billing/backend/billing/accounts/create/page.js +6 -0
- package/dist/modules/billing/backend/billing/accounts/create/page.js.map +2 -2
- package/dist/modules/billing/backend/billing/accounts/page.js +63 -4
- package/dist/modules/billing/backend/billing/accounts/page.js.map +2 -2
- package/dist/modules/billing/backend/billing/invoices/[id]/page.js +297 -65
- package/dist/modules/billing/backend/billing/invoices/[id]/page.js.map +3 -3
- package/dist/modules/billing/backend/billing/invoices/page.js +6 -172
- package/dist/modules/billing/backend/billing/invoices/page.js.map +2 -2
- package/dist/modules/billing/backend/billing/items/[id]/page.js +51 -7
- package/dist/modules/billing/backend/billing/items/[id]/page.js.map +2 -2
- package/dist/modules/billing/backend/billing/items/create/page.js +9 -6
- package/dist/modules/billing/backend/billing/items/create/page.js.map +2 -2
- package/dist/modules/billing/backend/billing/items/page.js +8 -2
- package/dist/modules/billing/backend/billing/items/page.js.map +2 -2
- package/dist/modules/billing/backend/billing/payments/[id]/page.js +297 -0
- package/dist/modules/billing/backend/billing/payments/[id]/page.js.map +7 -0
- package/dist/modules/billing/backend/billing/payments/[id]/page.meta.js +21 -0
- package/dist/modules/billing/backend/billing/payments/[id]/page.meta.js.map +7 -0
- package/dist/modules/billing/backend/billing/payments/imports/[id]/page.js +74 -0
- package/dist/modules/billing/backend/billing/payments/imports/[id]/page.js.map +7 -0
- package/dist/modules/billing/backend/billing/payments/imports/[id]/page.meta.js +21 -0
- package/dist/modules/billing/backend/billing/payments/imports/[id]/page.meta.js.map +7 -0
- package/dist/modules/billing/backend/billing/payments/page.js +58 -0
- package/dist/modules/billing/backend/billing/payments/page.js.map +7 -0
- package/dist/modules/billing/backend/billing/payments/page.meta.js +18 -0
- package/dist/modules/billing/backend/billing/payments/page.meta.js.map +7 -0
- package/dist/modules/billing/backend/billing/runs/[id]/page.js +49 -14
- package/dist/modules/billing/backend/billing/runs/[id]/page.js.map +2 -2
- package/dist/modules/billing/backend/billing/runs/page.js +58 -7
- package/dist/modules/billing/backend/billing/runs/page.js.map +2 -2
- package/dist/modules/billing/backend/billing/statements/[id]/page.js +61 -6
- package/dist/modules/billing/backend/billing/statements/[id]/page.js.map +2 -2
- package/dist/modules/billing/backend/billing/statements/page.js +1 -1
- package/dist/modules/billing/backend/billing/statements/page.js.map +2 -2
- package/dist/modules/billing/backend/billing/topups/page.js +1 -1
- package/dist/modules/billing/backend/billing/topups/page.js.map +2 -2
- package/dist/modules/billing/backend/billing/transactions/page.js +1 -1
- package/dist/modules/billing/backend/billing/transactions/page.js.map +2 -2
- package/dist/modules/billing/backend/billing/usage/create/page.js +3 -2
- package/dist/modules/billing/backend/billing/usage/create/page.js.map +2 -2
- package/dist/modules/billing/backend/config/billing/page.js +472 -0
- package/dist/modules/billing/backend/config/billing/page.js.map +7 -0
- package/dist/modules/billing/backend/config/billing/page.meta.js +19 -0
- package/dist/modules/billing/backend/config/billing/page.meta.js.map +7 -0
- package/dist/modules/billing/ce.js.map +2 -2
- package/dist/modules/billing/cli.js +22 -1
- package/dist/modules/billing/cli.js.map +2 -2
- package/dist/modules/billing/commands/accounts.js +6 -0
- package/dist/modules/billing/commands/accounts.js.map +2 -2
- package/dist/modules/billing/commands/index.js +3 -0
- package/dist/modules/billing/commands/index.js.map +2 -2
- package/dist/modules/billing/commands/invoices.js +272 -170
- package/dist/modules/billing/commands/invoices.js.map +2 -2
- package/dist/modules/billing/commands/items.js +108 -0
- package/dist/modules/billing/commands/items.js.map +2 -2
- package/dist/modules/billing/commands/memos.js +179 -0
- package/dist/modules/billing/commands/memos.js.map +7 -0
- package/dist/modules/billing/commands/payments.js +379 -0
- package/dist/modules/billing/commands/payments.js.map +7 -0
- package/dist/modules/billing/commands/runs.js +154 -7
- package/dist/modules/billing/commands/runs.js.map +2 -2
- package/dist/modules/billing/commands/settings.js +59 -0
- package/dist/modules/billing/commands/settings.js.map +7 -0
- package/dist/modules/billing/commands/topups.js +9 -2
- package/dist/modules/billing/commands/topups.js.map +2 -2
- package/dist/modules/billing/commands/transactions.js +2 -2
- package/dist/modules/billing/commands/transactions.js.map +2 -2
- package/dist/modules/billing/components/AccountForm.js +149 -42
- package/dist/modules/billing/components/AccountForm.js.map +2 -2
- package/dist/modules/billing/components/AccountInvoicesSection.js +64 -0
- package/dist/modules/billing/components/AccountInvoicesSection.js.map +7 -0
- package/dist/modules/billing/components/AccountPaymentsSection.js +43 -0
- package/dist/modules/billing/components/AccountPaymentsSection.js.map +7 -0
- package/dist/modules/billing/components/AccountPicker.js +56 -0
- package/dist/modules/billing/components/AccountPicker.js.map +7 -0
- package/dist/modules/billing/components/AllocatePaymentDialog.js +134 -0
- package/dist/modules/billing/components/AllocatePaymentDialog.js.map +7 -0
- package/dist/modules/billing/components/BillingDataTable.js +21 -0
- package/dist/modules/billing/components/BillingDataTable.js.map +7 -0
- package/dist/modules/billing/components/BillingSettingsLink.js +19 -0
- package/dist/modules/billing/components/BillingSettingsLink.js.map +7 -0
- package/dist/modules/billing/components/ChangeItemPriceDialog.js +158 -0
- package/dist/modules/billing/components/ChangeItemPriceDialog.js.map +7 -0
- package/dist/modules/billing/components/CreateMemoDialog.js +200 -0
- package/dist/modules/billing/components/CreateMemoDialog.js.map +7 -0
- package/dist/modules/billing/components/CustomerLabel.js +33 -0
- package/dist/modules/billing/components/CustomerLabel.js.map +7 -0
- package/dist/modules/billing/components/InvoicesTable.js +270 -0
- package/dist/modules/billing/components/InvoicesTable.js.map +7 -0
- package/dist/modules/billing/components/ItemForm.js +176 -44
- package/dist/modules/billing/components/ItemForm.js.map +2 -2
- package/dist/modules/billing/components/ItemPriceField.js +46 -0
- package/dist/modules/billing/components/ItemPriceField.js.map +7 -0
- package/dist/modules/billing/components/LineFormDialog.js +25 -2
- package/dist/modules/billing/components/LineFormDialog.js.map +2 -2
- package/dist/modules/billing/components/ManualPaymentDialog.js +122 -0
- package/dist/modules/billing/components/ManualPaymentDialog.js.map +7 -0
- package/dist/modules/billing/components/MoneyInput.js +14 -0
- package/dist/modules/billing/components/MoneyInput.js.map +7 -0
- package/dist/modules/billing/components/PaymentUploadDialog.js +115 -0
- package/dist/modules/billing/components/PaymentUploadDialog.js.map +7 -0
- package/dist/modules/billing/components/PaymentsTable.js +171 -0
- package/dist/modules/billing/components/PaymentsTable.js.map +7 -0
- package/dist/modules/billing/components/PostRunDraftsButton.js +105 -0
- package/dist/modules/billing/components/PostRunDraftsButton.js.map +7 -0
- package/dist/modules/billing/components/PrepaidPanel.js +14 -4
- package/dist/modules/billing/components/PrepaidPanel.js.map +2 -2
- package/dist/modules/billing/components/RunCyclesSection.js +209 -0
- package/dist/modules/billing/components/RunCyclesSection.js.map +7 -0
- package/dist/modules/billing/components/TestRunActions.js +127 -0
- package/dist/modules/billing/components/TestRunActions.js.map +7 -0
- package/dist/modules/billing/components/account/AccountItemsTab.js +157 -0
- package/dist/modules/billing/components/account/AccountItemsTab.js.map +7 -0
- package/dist/modules/billing/components/account/AccountRunBillingDialog.js +122 -0
- package/dist/modules/billing/components/account/AccountRunBillingDialog.js.map +7 -0
- package/dist/modules/billing/components/account/AccountRunsTab.js +152 -0
- package/dist/modules/billing/components/account/AccountRunsTab.js.map +7 -0
- package/dist/modules/billing/components/account/AccountStatementsTab.js +98 -0
- package/dist/modules/billing/components/account/AccountStatementsTab.js.map +7 -0
- package/dist/modules/billing/components/account/AccountSummaryCards.js +125 -0
- package/dist/modules/billing/components/account/AccountSummaryCards.js.map +7 -0
- package/dist/modules/billing/components/account/AccountUsageTab.js +91 -0
- package/dist/modules/billing/components/account/AccountUsageTab.js.map +7 -0
- package/dist/modules/billing/components/account/AccountView.js +73 -0
- package/dist/modules/billing/components/account/AccountView.js.map +7 -0
- package/dist/modules/billing/components/account/accountRow.js +39 -0
- package/dist/modules/billing/components/account/accountRow.js.map +7 -0
- package/dist/modules/billing/components/customerNames.js +42 -0
- package/dist/modules/billing/components/customerNames.js.map +7 -0
- package/dist/modules/billing/data/entities.js +615 -59
- package/dist/modules/billing/data/entities.js.map +2 -2
- package/dist/modules/billing/data/entityIds.js +10 -1
- package/dist/modules/billing/data/entityIds.js.map +2 -2
- package/dist/modules/billing/data/validators.js +269 -15
- package/dist/modules/billing/data/validators.js.map +2 -2
- package/dist/modules/billing/events.js +70 -0
- package/dist/modules/billing/events.js.map +2 -2
- package/dist/modules/billing/i18n/en.json +457 -21
- package/dist/modules/billing/i18n/pl.json +457 -21
- package/dist/modules/billing/index.js +6 -2
- package/dist/modules/billing/index.js.map +2 -2
- package/dist/modules/billing/lib/accountFinancials.js +58 -0
- package/dist/modules/billing/lib/accountFinancials.js.map +7 -0
- package/dist/modules/billing/lib/accountLock.js +14 -0
- package/dist/modules/billing/lib/accountLock.js.map +7 -0
- package/dist/modules/billing/lib/accountStatus.js +9 -7
- package/dist/modules/billing/lib/accountStatus.js.map +2 -2
- package/dist/modules/billing/lib/accountSummary.js +106 -0
- package/dist/modules/billing/lib/accountSummary.js.map +7 -0
- package/dist/modules/billing/lib/allocation.js +356 -0
- package/dist/modules/billing/lib/allocation.js.map +7 -0
- package/dist/modules/billing/lib/allocationEvents.js +22 -0
- package/dist/modules/billing/lib/allocationEvents.js.map +7 -0
- package/dist/modules/billing/lib/billPeriod.js +15 -1
- package/dist/modules/billing/lib/billPeriod.js.map +2 -2
- package/dist/modules/billing/lib/billRunEngine.js +241 -106
- package/dist/modules/billing/lib/billRunEngine.js.map +2 -2
- package/dist/modules/billing/lib/billRunLabel.js.map +1 -1
- package/dist/modules/billing/lib/billingSettings.js +116 -0
- package/dist/modules/billing/lib/billingSettings.js.map +7 -0
- package/dist/modules/billing/lib/commandRoute.js +81 -0
- package/dist/modules/billing/lib/commandRoute.js.map +7 -0
- package/dist/modules/billing/lib/customerLookup.js +97 -0
- package/dist/modules/billing/lib/customerLookup.js.map +7 -0
- package/dist/modules/billing/lib/dateOnly.js +13 -0
- package/dist/modules/billing/lib/dateOnly.js.map +7 -0
- package/dist/modules/billing/lib/documentParties.js +16 -0
- package/dist/modules/billing/lib/documentParties.js.map +7 -0
- package/dist/modules/billing/lib/documentTypes.js +27 -0
- package/dist/modules/billing/lib/documentTypes.js.map +7 -0
- package/dist/modules/billing/lib/dueDate.js +18 -0
- package/dist/modules/billing/lib/dueDate.js.map +7 -0
- package/dist/modules/billing/lib/iban.js +29 -0
- package/dist/modules/billing/lib/iban.js.map +7 -0
- package/dist/modules/billing/lib/invoiceDelivery.js +131 -0
- package/dist/modules/billing/lib/invoiceDelivery.js.map +7 -0
- package/dist/modules/billing/lib/invoiceLanguages.js +16 -0
- package/dist/modules/billing/lib/invoiceLanguages.js.map +7 -0
- package/dist/modules/billing/lib/invoiceWriter.js +107 -99
- package/dist/modules/billing/lib/invoiceWriter.js.map +2 -2
- package/dist/modules/billing/lib/itemBillingState.js +27 -0
- package/dist/modules/billing/lib/itemBillingState.js.map +7 -0
- package/dist/modules/billing/lib/itemPriceChange.js +18 -0
- package/dist/modules/billing/lib/itemPriceChange.js.map +7 -0
- package/dist/modules/billing/lib/itemSelector.js.map +2 -2
- package/dist/modules/billing/lib/lineAmounts.js +32 -0
- package/dist/modules/billing/lib/lineAmounts.js.map +7 -0
- package/dist/modules/billing/lib/memoGuards.js +25 -0
- package/dist/modules/billing/lib/memoGuards.js.map +7 -0
- package/dist/modules/billing/lib/navigation.js +48 -0
- package/dist/modules/billing/lib/navigation.js.map +7 -0
- package/dist/modules/billing/lib/numbering.js +120 -0
- package/dist/modules/billing/lib/numbering.js.map +7 -0
- package/dist/modules/billing/lib/overdue.js +36 -0
- package/dist/modules/billing/lib/overdue.js.map +7 -0
- package/dist/modules/billing/lib/paymentCsv.js +125 -0
- package/dist/modules/billing/lib/paymentCsv.js.map +7 -0
- package/dist/modules/billing/lib/paymentGateway.js +15 -0
- package/dist/modules/billing/lib/paymentGateway.js.map +7 -0
- package/dist/modules/billing/lib/paymentImport.js +164 -0
- package/dist/modules/billing/lib/paymentImport.js.map +7 -0
- package/dist/modules/billing/lib/paymentMatcher.js +36 -0
- package/dist/modules/billing/lib/paymentMatcher.js.map +7 -0
- package/dist/modules/billing/lib/pdf/attachmentStore.js +46 -0
- package/dist/modules/billing/lib/pdf/attachmentStore.js.map +7 -0
- package/dist/modules/billing/lib/pdf/fonts/embeddedFonts.js +7 -0
- package/dist/modules/billing/lib/pdf/fonts/embeddedFonts.js.map +7 -0
- package/dist/modules/billing/lib/pdf/invoiceModel.js +194 -0
- package/dist/modules/billing/lib/pdf/invoiceModel.js.map +7 -0
- package/dist/modules/billing/lib/pdf/invoicePdf.js +165 -0
- package/dist/modules/billing/lib/pdf/invoicePdf.js.map +7 -0
- package/dist/modules/billing/lib/pdf/invoiceTemplate.js +274 -0
- package/dist/modules/billing/lib/pdf/invoiceTemplate.js.map +7 -0
- package/dist/modules/billing/lib/prepaidConfig.js +17 -25
- package/dist/modules/billing/lib/prepaidConfig.js.map +2 -2
- package/dist/modules/billing/lib/prepaidConsume.js +26 -7
- package/dist/modules/billing/lib/prepaidConsume.js.map +2 -2
- package/dist/modules/billing/lib/prepaidPeriodClose.js +277 -158
- package/dist/modules/billing/lib/prepaidPeriodClose.js.map +2 -2
- package/dist/modules/billing/lib/prepaidTaxPoint.js +37 -0
- package/dist/modules/billing/lib/prepaidTaxPoint.js.map +7 -0
- package/dist/modules/billing/lib/seeds/demo.js +51 -3
- package/dist/modules/billing/lib/seeds/demo.js.map +2 -2
- package/dist/modules/billing/lib/seeds/paymentsSample.js +93 -0
- package/dist/modules/billing/lib/seeds/paymentsSample.js.map +7 -0
- package/dist/modules/billing/lib/seeds/sellerSettings.js +41 -0
- package/dist/modules/billing/lib/seeds/sellerSettings.js.map +7 -0
- package/dist/modules/billing/lib/servicePeriods.js +121 -0
- package/dist/modules/billing/lib/servicePeriods.js.map +7 -0
- package/dist/modules/billing/lib/tenantLock.js.map +1 -1
- package/dist/modules/billing/lib/testRunCleanup.js +24 -0
- package/dist/modules/billing/lib/testRunCleanup.js.map +7 -0
- package/dist/modules/billing/lib/topupCapture.js +2 -2
- package/dist/modules/billing/lib/topupCapture.js.map +2 -2
- package/dist/modules/billing/lib/topupReceipt.js +58 -79
- package/dist/modules/billing/lib/topupReceipt.js.map +2 -2
- package/dist/modules/billing/lib/usageRater.js.map +1 -1
- package/dist/modules/billing/lib/usageRunner.js +14 -6
- package/dist/modules/billing/lib/usageRunner.js.map +2 -2
- package/dist/modules/billing/lib/vat.js +39 -0
- package/dist/modules/billing/lib/vat.js.map +7 -0
- package/dist/modules/billing/migrations/Migration20261114000000_billing_customer_kind.js +15 -0
- package/dist/modules/billing/migrations/Migration20261114000000_billing_customer_kind.js.map +7 -0
- package/dist/modules/billing/migrations/Migration20261114100000_billing_cycle_semantics.js +25 -0
- package/dist/modules/billing/migrations/Migration20261114100000_billing_cycle_semantics.js.map +7 -0
- package/dist/modules/billing/migrations/Migration20261115000000_billing_invoice_ledger.js +115 -0
- package/dist/modules/billing/migrations/Migration20261115000000_billing_invoice_ledger.js.map +7 -0
- package/dist/modules/billing/migrations/Migration20261116000000_billing_invoice_documents.js +47 -0
- package/dist/modules/billing/migrations/Migration20261116000000_billing_invoice_documents.js.map +7 -0
- package/dist/modules/billing/migrations/Migration20261117000000_billing_payments.js +89 -0
- package/dist/modules/billing/migrations/Migration20261117000000_billing_payments.js.map +7 -0
- package/dist/modules/billing/migrations/Migration20261118000000_billing_memos.js +17 -0
- package/dist/modules/billing/migrations/Migration20261118000000_billing_memos.js.map +7 -0
- package/dist/modules/billing/migrations/Migration20261119000000_billing_operator_feedback.js +27 -0
- package/dist/modules/billing/migrations/Migration20261119000000_billing_operator_feedback.js.map +7 -0
- package/dist/modules/billing/migrations/Migration20261120000000_billing_allocation_scope_indexes.js +29 -0
- package/dist/modules/billing/migrations/Migration20261120000000_billing_allocation_scope_indexes.js.map +7 -0
- package/dist/modules/billing/setup.js +7 -184
- package/dist/modules/billing/setup.js.map +2 -2
- package/dist/modules/billing/subscribers/credit-memo-auto-send.js +16 -0
- package/dist/modules/billing/subscribers/credit-memo-auto-send.js.map +7 -0
- package/dist/modules/billing/subscribers/debit-memo-apply-credit.js +16 -0
- package/dist/modules/billing/subscribers/debit-memo-apply-credit.js.map +7 -0
- package/dist/modules/billing/subscribers/debit-memo-auto-send.js +16 -0
- package/dist/modules/billing/subscribers/debit-memo-auto-send.js.map +7 -0
- package/dist/modules/billing/subscribers/invoice-apply-credit.js +34 -0
- package/dist/modules/billing/subscribers/invoice-apply-credit.js.map +7 -0
- package/dist/modules/billing/subscribers/invoice-auto-send.js +30 -0
- package/dist/modules/billing/subscribers/invoice-auto-send.js.map +7 -0
- package/dist/modules/billing/subscribers/payment-captured-to-paid.js +69 -33
- package/dist/modules/billing/subscribers/payment-captured-to-paid.js.map +2 -2
- package/dist/modules/billing/subscribers/prepaid-topup-captured.js +4 -6
- package/dist/modules/billing/subscribers/prepaid-topup-captured.js.map +2 -2
- package/dist/modules/billing/workers/reap-stale-bill-runs.js +2 -2
- package/dist/modules/billing/workers/reap-stale-bill-runs.js.map +2 -2
- package/generated/entities/billing_account/index.ts +26 -0
- package/generated/entities/billing_account_balance/index.ts +13 -0
- package/generated/entities/billing_account_transaction/index.ts +21 -0
- package/generated/entities/billing_account_usage/index.ts +18 -0
- package/generated/entities/billing_allocation/index.ts +18 -0
- package/generated/entities/billing_document_sequence/index.ts +11 -0
- package/generated/entities/billing_draft_invoice_edit/index.ts +14 -0
- package/generated/entities/billing_invoice/index.ts +38 -0
- package/generated/entities/billing_invoice_line/index.ts +24 -0
- package/generated/entities/billing_item/index.ts +26 -0
- package/generated/entities/billing_payment/index.ts +25 -0
- package/generated/entities/billing_payment_import/index.ts +14 -0
- package/generated/entities/billing_run/index.ts +20 -0
- package/generated/entities/billing_run_outcome/index.ts +18 -0
- package/generated/entities/billing_settings/index.ts +26 -0
- package/generated/entities/billing_statement/index.ts +22 -0
- package/generated/entities/billing_topup/index.ts +20 -0
- package/generated/entities.ids.generated.ts +35 -0
- package/package.json +15 -10
- package/src/modules/billing/__integration__/TC-BILL-004.spec.ts +170 -0
- package/src/modules/billing/__integration__/TC-BILL-005.spec.ts +134 -0
- package/src/modules/billing/__integration__/TC-BILL-006.spec.ts +101 -0
- package/src/modules/billing/__integration__/TC-BILL-007.spec.ts +140 -0
- package/src/modules/billing/__integration__/TC-BILL-008.spec.ts +108 -0
- package/src/modules/billing/__integration__/TC-BILL-009.spec.ts +113 -0
- package/src/modules/billing/__integration__/TC-BILL-010.spec.ts +118 -0
- package/src/modules/billing/__integration__/TC-BILL-011.spec.ts +142 -0
- package/src/modules/billing/__integration__/TC-BILL-012.spec.ts +115 -0
- package/src/modules/billing/__integration__/TC-BILL-013.spec.ts +118 -0
- package/src/modules/billing/__integration__/sellerSettings.ts +24 -0
- package/src/modules/billing/__tests__/commands/invoices.test.ts +437 -355
- package/src/modules/billing/__tests__/commands/itemsBulk.test.ts +33 -0
- package/src/modules/billing/__tests__/commands/memos.test.ts +205 -0
- package/src/modules/billing/__tests__/commands/payments.test.ts +241 -0
- package/src/modules/billing/__tests__/commands/runsDelete.test.ts +146 -0
- package/src/modules/billing/__tests__/commands/runsPostDrafts.test.ts +106 -0
- package/src/modules/billing/__tests__/commands/topups.test.ts +11 -0
- package/src/modules/billing/__tests__/entityRegistry.test.ts +326 -0
- package/src/modules/billing/__tests__/events.test.ts +142 -0
- package/src/modules/billing/__tests__/helpers/prepaidMockEm.ts +28 -11
- package/src/modules/billing/__tests__/lib/accountFinancials.test.ts +53 -0
- package/src/modules/billing/__tests__/lib/accountSummary.test.ts +97 -0
- package/src/modules/billing/__tests__/lib/allocation.test.ts +319 -0
- package/src/modules/billing/__tests__/lib/billRunEngine.test.ts +231 -20
- package/src/modules/billing/__tests__/lib/billingSettings.test.ts +109 -0
- package/src/modules/billing/__tests__/lib/customerLookup.test.ts +156 -0
- package/src/modules/billing/__tests__/lib/dueDate.test.ts +35 -0
- package/src/modules/billing/__tests__/lib/iban.test.ts +38 -0
- package/src/modules/billing/__tests__/lib/invoiceDelivery.test.ts +189 -0
- package/src/modules/billing/__tests__/lib/invoiceWriter.test.ts +212 -10
- package/src/modules/billing/__tests__/lib/itemBillingState.test.ts +42 -0
- package/src/modules/billing/__tests__/lib/itemPriceChange.test.ts +165 -0
- package/src/modules/billing/__tests__/lib/lineAmounts.test.ts +86 -0
- package/src/modules/billing/__tests__/lib/navigation.test.ts +71 -0
- package/src/modules/billing/__tests__/lib/numbering.test.ts +91 -0
- package/src/modules/billing/__tests__/lib/overdue.test.ts +36 -0
- package/src/modules/billing/__tests__/lib/paymentCsv.test.ts +148 -0
- package/src/modules/billing/__tests__/lib/paymentImport.test.ts +113 -0
- package/src/modules/billing/__tests__/lib/paymentsSample.test.ts +73 -0
- package/src/modules/billing/__tests__/lib/pdf/invoicePdf.test.ts +199 -0
- package/src/modules/billing/__tests__/lib/pdf/invoicePdfService.test.ts +147 -0
- package/src/modules/billing/__tests__/lib/prepaidPeriodClose.test.ts +374 -98
- package/src/modules/billing/__tests__/lib/prepaidTaxPoint.test.ts +118 -0
- package/src/modules/billing/__tests__/lib/seedsDemo.test.ts +53 -2
- package/src/modules/billing/__tests__/lib/sellerSettings.test.ts +28 -0
- package/src/modules/billing/__tests__/lib/servicePeriods.test.ts +190 -0
- package/src/modules/billing/__tests__/lib/topupCapture.test.ts +6 -28
- package/src/modules/billing/__tests__/lib/topupReceipt.test.ts +21 -52
- package/src/modules/billing/__tests__/lib/vat.test.ts +51 -0
- package/src/modules/billing/__tests__/package-isolation.test.ts +22 -8
- package/src/modules/billing/__tests__/setup.test.ts +13 -4
- package/src/modules/billing/__tests__/validators.test.ts +193 -3
- package/src/modules/billing/acl.ts +12 -0
- package/src/modules/billing/api/accounts/[id]/summary/route.ts +62 -0
- package/src/modules/billing/api/accounts/route.ts +58 -4
- package/src/modules/billing/api/export/account/[id]/route.ts +20 -18
- package/src/modules/billing/api/invoices/[id]/memos/route.ts +63 -0
- package/src/modules/billing/api/invoices/[id]/pdf/route.ts +79 -0
- package/src/modules/billing/api/invoices/[id]/route.ts +57 -70
- package/src/modules/billing/api/invoices/[id]/send/route.ts +127 -0
- package/src/modules/billing/api/invoices/add-line/route.ts +3 -3
- package/src/modules/billing/api/invoices/delete-draft/route.ts +33 -0
- package/src/modules/billing/api/invoices/edit-line/route.ts +4 -4
- package/src/modules/billing/api/invoices/post/route.ts +7 -6
- package/src/modules/billing/api/invoices/remove-line/route.ts +3 -3
- package/src/modules/billing/api/invoices/route.ts +81 -86
- package/src/modules/billing/api/items/bulk/route.ts +2 -1
- package/src/modules/billing/api/items/change-price/route.ts +54 -0
- package/src/modules/billing/api/items/route.ts +23 -7
- package/src/modules/billing/api/payment-imports/[id]/route.ts +49 -0
- package/src/modules/billing/api/payment-imports/route.ts +57 -0
- package/src/modules/billing/api/payments/[id]/route.ts +63 -0
- package/src/modules/billing/api/payments/allocate/route.ts +35 -0
- package/src/modules/billing/api/payments/assign/route.ts +36 -0
- package/src/modules/billing/api/payments/convert-to-topup/route.ts +35 -0
- package/src/modules/billing/api/payments/ignore/route.ts +35 -0
- package/src/modules/billing/api/payments/import/route.ts +72 -0
- package/src/modules/billing/api/payments/restore/route.ts +35 -0
- package/src/modules/billing/api/payments/route.ts +147 -0
- package/src/modules/billing/api/payments/unallocate/route.ts +35 -0
- package/src/modules/billing/api/payments/unassign/route.ts +35 -0
- package/src/modules/billing/api/run-outcomes/route.ts +50 -7
- package/src/modules/billing/api/runs/[id]/post-drafts/route.ts +71 -0
- package/src/modules/billing/api/runs/[id]/route.ts +59 -0
- package/src/modules/billing/api/runs/retry-failed/route.ts +4 -3
- package/src/modules/billing/api/runs/route.ts +17 -9
- package/src/modules/billing/api/settings/number-preview/route.ts +46 -0
- package/src/modules/billing/api/settings/route.ts +116 -0
- package/src/modules/billing/api/statements/route.ts +5 -0
- package/src/modules/billing/api/test-invoices/wipe/route.ts +2 -2
- package/src/modules/billing/backend/billing/accounts/[id]/page.tsx +151 -372
- package/src/modules/billing/backend/billing/accounts/create/page.tsx +6 -0
- package/src/modules/billing/backend/billing/accounts/page.tsx +71 -5
- package/src/modules/billing/backend/billing/invoices/[id]/page.tsx +445 -96
- package/src/modules/billing/backend/billing/invoices/page.tsx +8 -227
- package/src/modules/billing/backend/billing/items/[id]/page.tsx +75 -6
- package/src/modules/billing/backend/billing/items/create/page.tsx +13 -8
- package/src/modules/billing/backend/billing/items/page.tsx +19 -3
- package/src/modules/billing/backend/billing/payments/[id]/page.meta.ts +19 -0
- package/src/modules/billing/backend/billing/payments/[id]/page.tsx +415 -0
- package/src/modules/billing/backend/billing/payments/imports/[id]/page.meta.ts +19 -0
- package/src/modules/billing/backend/billing/payments/imports/[id]/page.tsx +106 -0
- package/src/modules/billing/backend/billing/payments/page.meta.ts +16 -0
- package/src/modules/billing/backend/billing/payments/page.tsx +56 -0
- package/src/modules/billing/backend/billing/runs/[id]/page.tsx +50 -19
- package/src/modules/billing/backend/billing/runs/page.tsx +60 -9
- package/src/modules/billing/backend/billing/statements/[id]/page.tsx +87 -6
- package/src/modules/billing/backend/billing/statements/page.tsx +2 -2
- package/src/modules/billing/backend/billing/topups/page.tsx +2 -2
- package/src/modules/billing/backend/billing/transactions/page.tsx +2 -2
- package/src/modules/billing/backend/billing/usage/create/page.tsx +3 -2
- package/src/modules/billing/backend/config/billing/page.meta.ts +21 -0
- package/src/modules/billing/backend/config/billing/page.tsx +549 -0
- package/src/modules/billing/ce.ts +8 -7
- package/src/modules/billing/cli.ts +31 -1
- package/src/modules/billing/commands/accounts.ts +6 -0
- package/src/modules/billing/commands/index.ts +3 -0
- package/src/modules/billing/commands/invoices.ts +371 -238
- package/src/modules/billing/commands/items.ts +143 -0
- package/src/modules/billing/commands/memos.ts +218 -0
- package/src/modules/billing/commands/payments.ts +428 -0
- package/src/modules/billing/commands/runs.ts +208 -6
- package/src/modules/billing/commands/settings.ts +77 -0
- package/src/modules/billing/commands/topups.ts +12 -3
- package/src/modules/billing/commands/transactions.ts +2 -2
- package/src/modules/billing/components/AccountForm.tsx +199 -53
- package/src/modules/billing/components/AccountInvoicesSection.tsx +75 -0
- package/src/modules/billing/components/AccountPaymentsSection.tsx +42 -0
- package/src/modules/billing/components/AccountPicker.tsx +70 -0
- package/src/modules/billing/components/AllocatePaymentDialog.tsx +167 -0
- package/src/modules/billing/components/BillingDataTable.tsx +34 -0
- package/src/modules/billing/components/BillingSettingsLink.tsx +25 -0
- package/src/modules/billing/components/ChangeItemPriceDialog.tsx +180 -0
- package/src/modules/billing/components/CreateMemoDialog.tsx +232 -0
- package/src/modules/billing/components/CustomerLabel.tsx +53 -0
- package/src/modules/billing/components/InvoicesTable.tsx +344 -0
- package/src/modules/billing/components/ItemForm.tsx +233 -44
- package/src/modules/billing/components/ItemPriceField.tsx +81 -0
- package/src/modules/billing/components/LineFormDialog.tsx +25 -1
- package/src/modules/billing/components/ManualPaymentDialog.tsx +140 -0
- package/src/modules/billing/components/MoneyInput.tsx +26 -0
- package/src/modules/billing/components/PaymentUploadDialog.tsx +148 -0
- package/src/modules/billing/components/PaymentsTable.tsx +213 -0
- package/src/modules/billing/components/PostRunDraftsButton.tsx +129 -0
- package/src/modules/billing/components/PrepaidPanel.tsx +20 -7
- package/src/modules/billing/components/RunCyclesSection.tsx +298 -0
- package/src/modules/billing/components/TestRunActions.tsx +152 -0
- package/src/modules/billing/components/account/AccountItemsTab.tsx +192 -0
- package/src/modules/billing/components/account/AccountRunBillingDialog.tsx +147 -0
- package/src/modules/billing/components/account/AccountRunsTab.tsx +201 -0
- package/src/modules/billing/components/account/AccountStatementsTab.tsx +120 -0
- package/src/modules/billing/components/account/AccountSummaryCards.tsx +153 -0
- package/src/modules/billing/components/account/AccountUsageTab.tsx +122 -0
- package/src/modules/billing/components/account/AccountView.tsx +101 -0
- package/src/modules/billing/components/account/accountRow.ts +70 -0
- package/src/modules/billing/components/customerNames.ts +62 -0
- package/src/modules/billing/data/entities.ts +685 -15
- package/src/modules/billing/data/entityIds.ts +25 -11
- package/src/modules/billing/data/validators.ts +388 -8
- package/src/modules/billing/events.ts +82 -3
- package/src/modules/billing/i18n/en.json +457 -21
- package/src/modules/billing/i18n/pl.json +457 -21
- package/src/modules/billing/index.ts +6 -2
- package/src/modules/billing/lib/accountFinancials.ts +84 -0
- package/src/modules/billing/lib/accountLock.ts +32 -0
- package/src/modules/billing/lib/accountStatus.ts +11 -9
- package/src/modules/billing/lib/accountSummary.ts +172 -0
- package/src/modules/billing/lib/allocation.ts +515 -0
- package/src/modules/billing/lib/allocationEvents.ts +26 -0
- package/src/modules/billing/lib/billPeriod.ts +19 -0
- package/src/modules/billing/lib/billRunEngine.ts +362 -162
- package/src/modules/billing/lib/billRunLabel.ts +1 -1
- package/src/modules/billing/lib/billingSettings.ts +145 -0
- package/src/modules/billing/lib/commandRoute.ts +112 -0
- package/src/modules/billing/lib/customerLookup.ts +157 -0
- package/src/modules/billing/lib/dateOnly.ts +22 -0
- package/src/modules/billing/lib/documentParties.ts +23 -0
- package/src/modules/billing/lib/documentTypes.ts +37 -0
- package/src/modules/billing/lib/dueDate.ts +26 -0
- package/src/modules/billing/lib/iban.ts +36 -0
- package/src/modules/billing/lib/invoiceDelivery.ts +197 -0
- package/src/modules/billing/lib/invoiceLanguages.ts +34 -0
- package/src/modules/billing/lib/invoiceWriter.ts +162 -148
- package/src/modules/billing/lib/itemBillingState.ts +67 -0
- package/src/modules/billing/lib/itemPriceChange.ts +56 -0
- package/src/modules/billing/lib/itemSelector.ts +4 -1
- package/src/modules/billing/lib/lineAmounts.ts +61 -0
- package/src/modules/billing/lib/memoGuards.ts +41 -0
- package/src/modules/billing/lib/navigation.ts +64 -0
- package/src/modules/billing/lib/numbering.ts +174 -0
- package/src/modules/billing/lib/overdue.ts +60 -0
- package/src/modules/billing/lib/paymentCsv.ts +171 -0
- package/src/modules/billing/lib/paymentGateway.ts +52 -0
- package/src/modules/billing/lib/paymentImport.ts +228 -0
- package/src/modules/billing/lib/paymentMatcher.ts +88 -0
- package/src/modules/billing/lib/pdf/attachmentStore.ts +60 -0
- package/src/modules/billing/lib/pdf/fonts/NotoSans-Bold.ttf +0 -0
- package/src/modules/billing/lib/pdf/fonts/NotoSans-Regular.ttf +0 -0
- package/src/modules/billing/lib/pdf/fonts/OFL.txt +93 -0
- package/src/modules/billing/lib/pdf/fonts/embeddedFonts.ts +9 -0
- package/src/modules/billing/lib/pdf/invoiceModel.ts +328 -0
- package/src/modules/billing/lib/pdf/invoicePdf.ts +216 -0
- package/src/modules/billing/lib/pdf/invoiceTemplate.ts +338 -0
- package/src/modules/billing/lib/prepaidConfig.ts +27 -36
- package/src/modules/billing/lib/prepaidConsume.ts +29 -6
- package/src/modules/billing/lib/prepaidPeriodClose.ts +410 -242
- package/src/modules/billing/lib/prepaidTaxPoint.ts +76 -0
- package/src/modules/billing/lib/seeds/demo.ts +79 -6
- package/src/modules/billing/lib/seeds/paymentsSample.ts +136 -0
- package/src/modules/billing/lib/seeds/sellerSettings.ts +78 -0
- package/src/modules/billing/lib/servicePeriods.ts +226 -0
- package/src/modules/billing/lib/tenantLock.ts +1 -1
- package/src/modules/billing/lib/testRunCleanup.ts +42 -0
- package/src/modules/billing/lib/topupCapture.ts +3 -4
- package/src/modules/billing/lib/topupReceipt.ts +70 -103
- package/src/modules/billing/lib/usageRater.ts +1 -1
- package/src/modules/billing/lib/usageRunner.ts +17 -5
- package/src/modules/billing/lib/vat.ts +56 -0
- package/src/modules/billing/migrations/Migration20261114000000_billing_customer_kind.ts +25 -0
- package/src/modules/billing/migrations/Migration20261114100000_billing_cycle_semantics.ts +37 -0
- package/src/modules/billing/migrations/Migration20261115000000_billing_invoice_ledger.ts +132 -0
- package/src/modules/billing/migrations/Migration20261116000000_billing_invoice_documents.ts +58 -0
- package/src/modules/billing/migrations/Migration20261117000000_billing_payments.ts +97 -0
- package/src/modules/billing/migrations/Migration20261118000000_billing_memos.ts +21 -0
- package/src/modules/billing/migrations/Migration20261119000000_billing_operator_feedback.ts +39 -0
- package/src/modules/billing/migrations/Migration20261120000000_billing_allocation_scope_indexes.ts +35 -0
- package/src/modules/billing/setup.ts +11 -237
- package/src/modules/billing/subscribers/credit-memo-auto-send.ts +15 -0
- package/src/modules/billing/subscribers/debit-memo-apply-credit.ts +15 -0
- package/src/modules/billing/subscribers/debit-memo-auto-send.ts +15 -0
- package/src/modules/billing/subscribers/invoice-apply-credit.ts +39 -0
- package/src/modules/billing/subscribers/invoice-auto-send.ts +46 -0
- package/src/modules/billing/subscribers/payment-captured-to-paid.ts +84 -62
- package/src/modules/billing/subscribers/prepaid-topup-captured.ts +4 -8
- package/src/modules/billing/workers/reap-stale-bill-runs.ts +4 -4
- package/dist/modules/billing/lib/invoiceStatus.js +0 -38
- package/dist/modules/billing/lib/invoiceStatus.js.map +0 -7
- package/src/modules/billing/__tests__/lib/invoiceStatus.test.ts +0 -97
- package/src/modules/billing/lib/invoiceStatus.ts +0 -61
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { test, expect, type APIRequestContext } from '@playwright/test'
|
|
2
|
+
import { getAuthToken, apiRequest } from '@open-mercato/core/helpers/integration/api'
|
|
3
|
+
import { ensureSellerSettings } from './sellerSettings'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* TC-BILL-009: Payments — CSV import, auto-matching, allocation, credit (Spec C)
|
|
7
|
+
* Category: BILL — API
|
|
8
|
+
* Priority: High
|
|
9
|
+
* Spec: .ai/specs/2026-11-14-billing-payments.md
|
|
10
|
+
*
|
|
11
|
+
* 1. Two posted invoices on a fresh account (monthly, two bill dates).
|
|
12
|
+
* 2. Upload a CSV: half of invoice 1, invoice 2 + 30 overpayment, a junk
|
|
13
|
+
* line, a EUR line → counts; invoice 1 partially paid, invoice 2 paid,
|
|
14
|
+
* the 30 overpayment applied to invoice 1 as credit.
|
|
15
|
+
* 3. Account summary shows the remaining open amount; re-upload = duplicates.
|
|
16
|
+
* 4. The junk payment is assigned to the account manually → credit applied.
|
|
17
|
+
*
|
|
18
|
+
* Self-contained (own account + items). Uses JSON upload (`{ fileName, content }`).
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
const uniq = () => Date.now().toString(36) + Math.random().toString(36).slice(2, 6)
|
|
22
|
+
|
|
23
|
+
type InvoiceRow = { id: string; number: string; status: string; total_gross: string; outstanding: string; bill_date: string | null }
|
|
24
|
+
|
|
25
|
+
async function postedInvoices(request: APIRequestContext, token: string): Promise<{ accountId: string; invoices: InvoiceRow[] }> {
|
|
26
|
+
const account = await apiRequest(request, 'POST', '/api/billing/accounts', {
|
|
27
|
+
token,
|
|
28
|
+
data: {
|
|
29
|
+
customerId: `cust-${uniq()}`,
|
|
30
|
+
name: `Payments ${uniq()}`,
|
|
31
|
+
currencyCode: 'PLN',
|
|
32
|
+
billCycle: 'monthly',
|
|
33
|
+
billCycleAnchor: '1',
|
|
34
|
+
invoiceEmail: `pay-${uniq()}@example.com`,
|
|
35
|
+
nextBillDate: '2026-09-01',
|
|
36
|
+
invoiceAddress: { line1: 'ul. Testowa 1', city: 'Warszawa', postal_code: '00-001', country: 'PL' },
|
|
37
|
+
},
|
|
38
|
+
})
|
|
39
|
+
expect(account.ok(), `POST account status was ${account.status()}`).toBeTruthy()
|
|
40
|
+
const accountId = ((await account.json()) as { id: string }).id
|
|
41
|
+
const item = await apiRequest(request, 'POST', '/api/billing/items', {
|
|
42
|
+
token,
|
|
43
|
+
data: { billAccountId: accountId, type: 'recurring', billStartDate: '2026-09-01', description: 'Plan', rateJson: { unit_price: 100 }, taxRate: 0 },
|
|
44
|
+
})
|
|
45
|
+
expect(item.ok()).toBeTruthy()
|
|
46
|
+
// Catch-up: as of 2026-10-15 → bill dates 2026-09-01 and 2026-10-01 → two drafts.
|
|
47
|
+
const run = await apiRequest(request, 'POST', '/api/billing/runs', {
|
|
48
|
+
token,
|
|
49
|
+
data: { mode: 'real', asOfDate: '2026-10-15', scopedAccountIds: [accountId] },
|
|
50
|
+
})
|
|
51
|
+
expect(run.ok()).toBeTruthy()
|
|
52
|
+
const list = async () =>
|
|
53
|
+
((await (await apiRequest(request, 'GET', `/api/billing/invoices?billAccountId=${accountId}&testRun=false`, { token })).json()) as {
|
|
54
|
+
items: InvoiceRow[]
|
|
55
|
+
}).items.sort((a, b) => String(a.bill_date).localeCompare(String(b.bill_date)))
|
|
56
|
+
for (const draft of await list()) {
|
|
57
|
+
const post = await apiRequest(request, 'POST', '/api/billing/invoices/post', { token, data: { invoiceId: draft.id } })
|
|
58
|
+
expect(post.ok(), `POST post status was ${post.status()}`).toBeTruthy()
|
|
59
|
+
}
|
|
60
|
+
const invoices = await list()
|
|
61
|
+
expect(invoices).toHaveLength(2)
|
|
62
|
+
return { accountId, invoices }
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
test.describe('TC-BILL-009: payments import and allocation', () => {
|
|
66
|
+
let token: string
|
|
67
|
+
|
|
68
|
+
test.beforeAll(async ({ request }) => {
|
|
69
|
+
token = await getAuthToken(request, 'admin')
|
|
70
|
+
await ensureSellerSettings(request, token)
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
test('CSV upload allocates, applies credit, detects duplicates; manual assign applies credit', async ({ request }) => {
|
|
74
|
+
const { accountId, invoices } = await postedInvoices(request, token)
|
|
75
|
+
const [first, second] = invoices
|
|
76
|
+
const junkRef = `misc ${uniq()}`
|
|
77
|
+
const content = [
|
|
78
|
+
'date,amount,currency,reference,payer_name,payer_account',
|
|
79
|
+
`2026-11-20,50.00,PLN,"Part of ${first.number}",QA,`,
|
|
80
|
+
`2026-11-20,130.00,PLN,"${second.number} with extra",QA,`,
|
|
81
|
+
`2026-11-21,20.00,PLN,${junkRef},Someone,`,
|
|
82
|
+
`2026-11-21,10.00,EUR,${first.number},QA,`,
|
|
83
|
+
].join('\n')
|
|
84
|
+
|
|
85
|
+
const upload = await apiRequest(request, 'POST', '/api/billing/payments/import', { token, data: { fileName: 'qa.csv', content } })
|
|
86
|
+
expect(upload.ok(), `import status was ${upload.status()}`).toBeTruthy()
|
|
87
|
+
const summary = (await upload.json()) as { importId: string; counts: Record<string, number> }
|
|
88
|
+
expect(summary.counts).toMatchObject({ allocated: 2, unmatched: 2, duplicate: 0, rejected: 0 })
|
|
89
|
+
|
|
90
|
+
const detail = async (id: string) =>
|
|
91
|
+
((await (await apiRequest(request, 'GET', `/api/billing/invoices/${id}`, { token })).json()) as { invoice: InvoiceRow }).invoice
|
|
92
|
+
// 50 + 30 credit from the overpayment → invoice 1: 80 of 100 paid.
|
|
93
|
+
expect(await detail(first.id)).toMatchObject({ status: 'partially_paid' })
|
|
94
|
+
expect(Number((await detail(first.id)).outstanding)).toBeCloseTo(20, 2)
|
|
95
|
+
expect(await detail(second.id)).toMatchObject({ status: 'paid' })
|
|
96
|
+
|
|
97
|
+
const again = await apiRequest(request, 'POST', '/api/billing/payments/import', { token, data: { fileName: 'qa.csv', content } })
|
|
98
|
+
expect(((await again.json()) as { counts: Record<string, number> }).counts).toMatchObject({ duplicate: 4, allocated: 0 })
|
|
99
|
+
|
|
100
|
+
const junk = ((await (await apiRequest(request, 'GET', `/api/billing/payments?search=${encodeURIComponent(junkRef)}`, { token })).json()) as {
|
|
101
|
+
items: Array<{ id: string; status: string }>
|
|
102
|
+
}).items[0]
|
|
103
|
+
expect(junk.status).toBe('unmatched')
|
|
104
|
+
const assign = await apiRequest(request, 'POST', '/api/billing/payments/assign', { token, data: { paymentId: junk.id, billAccountId: accountId } })
|
|
105
|
+
expect(assign.ok(), `assign status was ${assign.status()}`).toBeTruthy()
|
|
106
|
+
expect(await detail(first.id)).toMatchObject({ status: 'paid' })
|
|
107
|
+
|
|
108
|
+
const summaryRes = await apiRequest(request, 'GET', `/api/billing/accounts/${accountId}/summary`, { token })
|
|
109
|
+
const ar = (await summaryRes.json()) as { open_amount: string; credit_amount: string }
|
|
110
|
+
expect(Number(ar.open_amount)).toBeCloseTo(0, 2)
|
|
111
|
+
expect(Number(ar.credit_amount)).toBeCloseTo(0, 2)
|
|
112
|
+
})
|
|
113
|
+
})
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { test, expect, type APIRequestContext } from '@playwright/test'
|
|
2
|
+
import { getAuthToken, apiRequest } from '@open-mercato/core/helpers/integration/api'
|
|
3
|
+
import { ensureSellerSettings } from './sellerSettings'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* TC-BILL-010: Credit and debit memos (Spec D)
|
|
7
|
+
* Category: BILL — API
|
|
8
|
+
* Priority: High
|
|
9
|
+
* Spec: .ai/specs/2026-11-14-billing-credit-debit-memos.md
|
|
10
|
+
*
|
|
11
|
+
* 1. Post an invoice (100 net, 0 % VAT for simple maths).
|
|
12
|
+
* 2. Partial credit memo (30) → draft `DRAFT-…` → post → `CN/…` number,
|
|
13
|
+
* original partially paid with 70 outstanding, memo settled.
|
|
14
|
+
* 3. A second credit of 80 is refused at creation (exceeds 100 − 30).
|
|
15
|
+
* 4. Debit memo (+15) → post → invoice-series number, own due date and
|
|
16
|
+
* outstanding; the original lists both corrections.
|
|
17
|
+
*
|
|
18
|
+
* Self-contained (own account + item). Posted documents stay (no void).
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
const uniq = () => Date.now().toString(36) + Math.random().toString(36).slice(2, 6)
|
|
22
|
+
|
|
23
|
+
type Doc = { id: string; number: string; status: string; outstanding: string; total_gross: string; due_date: string | null }
|
|
24
|
+
|
|
25
|
+
async function postedInvoice(request: APIRequestContext, token: string): Promise<{ invoice: Doc; lineId: string }> {
|
|
26
|
+
const account = await apiRequest(request, 'POST', '/api/billing/accounts', {
|
|
27
|
+
token,
|
|
28
|
+
data: {
|
|
29
|
+
customerId: `cust-${uniq()}`,
|
|
30
|
+
name: `Memos ${uniq()}`,
|
|
31
|
+
currencyCode: 'PLN',
|
|
32
|
+
billCycle: 'monthly',
|
|
33
|
+
billCycleAnchor: '1',
|
|
34
|
+
invoiceEmail: `memo-${uniq()}@example.com`,
|
|
35
|
+
nextBillDate: '2026-10-01',
|
|
36
|
+
invoiceAddress: { line1: 'ul. Testowa 1', city: 'Warszawa', postal_code: '00-001', country: 'PL' },
|
|
37
|
+
},
|
|
38
|
+
})
|
|
39
|
+
expect(account.ok()).toBeTruthy()
|
|
40
|
+
const accountId = ((await account.json()) as { id: string }).id
|
|
41
|
+
const item = await apiRequest(request, 'POST', '/api/billing/items', {
|
|
42
|
+
token,
|
|
43
|
+
data: { billAccountId: accountId, type: 'recurring', billStartDate: '2026-10-01', description: 'Plan', rateJson: { unit_price: 100 }, taxRate: 0 },
|
|
44
|
+
})
|
|
45
|
+
expect(item.ok()).toBeTruthy()
|
|
46
|
+
const run = await apiRequest(request, 'POST', '/api/billing/runs', { token, data: { mode: 'real', asOfDate: '2026-10-15', scopedAccountIds: [accountId] } })
|
|
47
|
+
expect(run.ok()).toBeTruthy()
|
|
48
|
+
const list = await apiRequest(request, 'GET', `/api/billing/invoices?billAccountId=${accountId}&testRun=false`, { token })
|
|
49
|
+
const [draft] = ((await list.json()) as { items: Doc[] }).items
|
|
50
|
+
const post = await apiRequest(request, 'POST', '/api/billing/invoices/post', { token, data: { invoiceId: draft.id } })
|
|
51
|
+
expect(post.ok()).toBeTruthy()
|
|
52
|
+
const detail = (await (await apiRequest(request, 'GET', `/api/billing/invoices/${draft.id}`, { token })).json()) as {
|
|
53
|
+
invoice: Doc
|
|
54
|
+
lines: Array<{ id: string }>
|
|
55
|
+
}
|
|
56
|
+
return { invoice: detail.invoice, lineId: detail.lines[0].id }
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async function getDoc(request: APIRequestContext, token: string, id: string) {
|
|
60
|
+
return (await (await apiRequest(request, 'GET', `/api/billing/invoices/${id}`, { token })).json()) as {
|
|
61
|
+
invoice: Doc
|
|
62
|
+
corrections: Array<{ id: string; document_type: string }>
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
test.describe('TC-BILL-010: credit and debit memos', () => {
|
|
67
|
+
let token: string
|
|
68
|
+
|
|
69
|
+
test.beforeAll(async ({ request }) => {
|
|
70
|
+
token = await getAuthToken(request, 'admin')
|
|
71
|
+
await ensureSellerSettings(request, token)
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
test('credit memo settles the original; over-credit refused; debit memo is payable', async ({ request }) => {
|
|
75
|
+
const { invoice, lineId } = await postedInvoice(request, token)
|
|
76
|
+
|
|
77
|
+
const credit = await apiRequest(request, 'POST', `/api/billing/invoices/${invoice.id}/memos`, {
|
|
78
|
+
token,
|
|
79
|
+
data: { type: 'credit_memo', reason: 'Goodwill', lines: [{ correctsLineId: lineId, description: 'Plan (part)', quantity: 1, unitPriceNet: 30 }] },
|
|
80
|
+
})
|
|
81
|
+
expect(credit.ok(), `create memo status ${credit.status()}`).toBeTruthy()
|
|
82
|
+
const { memoId, number } = (await credit.json()) as { memoId: string; number: string }
|
|
83
|
+
expect(number).toMatch(/^DRAFT-/)
|
|
84
|
+
|
|
85
|
+
const postMemo = await apiRequest(request, 'POST', '/api/billing/invoices/post', { token, data: { invoiceId: memoId } })
|
|
86
|
+
expect(postMemo.ok(), `post memo status ${postMemo.status()}`).toBeTruthy()
|
|
87
|
+
expect(((await postMemo.json()) as { invoiceNumber: string }).invoiceNumber).toMatch(/^CN\//)
|
|
88
|
+
|
|
89
|
+
const afterCredit = await getDoc(request, token, invoice.id)
|
|
90
|
+
expect(afterCredit.invoice.status).toBe('partially_paid')
|
|
91
|
+
expect(Number(afterCredit.invoice.outstanding)).toBeCloseTo(70, 2)
|
|
92
|
+
expect((await getDoc(request, token, memoId)).invoice).toMatchObject({ status: 'paid' })
|
|
93
|
+
|
|
94
|
+
const tooMuch = await apiRequest(request, 'POST', `/api/billing/invoices/${invoice.id}/memos`, {
|
|
95
|
+
token,
|
|
96
|
+
data: { type: 'credit_memo', reason: 'Too much', lines: [{ correctsLineId: lineId, description: 'Plan', quantity: 1, unitPriceNet: 80 }] },
|
|
97
|
+
})
|
|
98
|
+
expect(tooMuch.status()).toBe(409)
|
|
99
|
+
expect(((await tooMuch.json()) as { code: string }).code).toBe('billing.memo.exceeds_invoice')
|
|
100
|
+
|
|
101
|
+
const debit = await apiRequest(request, 'POST', `/api/billing/invoices/${invoice.id}/memos`, {
|
|
102
|
+
token,
|
|
103
|
+
data: { type: 'debit_memo', reason: 'Missed fee', lines: [{ description: 'Installation', quantity: 1, unitPriceNet: 15, taxRate: 0 }] },
|
|
104
|
+
})
|
|
105
|
+
expect(debit.ok()).toBeTruthy()
|
|
106
|
+
const debitId = ((await debit.json()) as { memoId: string }).memoId
|
|
107
|
+
const postDebit = await apiRequest(request, 'POST', '/api/billing/invoices/post', { token, data: { invoiceId: debitId } })
|
|
108
|
+
expect(postDebit.ok()).toBeTruthy()
|
|
109
|
+
expect(((await postDebit.json()) as { invoiceNumber: string }).invoiceNumber).toMatch(/^INV\//)
|
|
110
|
+
const debitDoc = (await getDoc(request, token, debitId)).invoice
|
|
111
|
+
expect(debitDoc.status).toBe('posted')
|
|
112
|
+
expect(debitDoc.due_date).toBeTruthy()
|
|
113
|
+
expect(Number(debitDoc.outstanding)).toBeCloseTo(15, 2)
|
|
114
|
+
|
|
115
|
+
const corrections = (await getDoc(request, token, invoice.id)).corrections.map((c) => c.document_type).sort()
|
|
116
|
+
expect(corrections).toEqual(['credit_memo', 'debit_memo'])
|
|
117
|
+
})
|
|
118
|
+
})
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { test, expect, type APIRequestContext } from '@playwright/test'
|
|
2
|
+
import { getAuthToken, apiRequest } from '@open-mercato/core/helpers/integration/api'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* TC-BILL-011: Prepaid period close — catch-up, charge timing, tax point (Spec F)
|
|
6
|
+
* Category: BILL — API
|
|
7
|
+
* Priority: High
|
|
8
|
+
* Spec: .ai/specs/2026-11-15-billing-operator-feedback.md (F4, F4b, F5)
|
|
9
|
+
*
|
|
10
|
+
* The operator's report (F4), against the real database: a prepaid account
|
|
11
|
+
* with next bill date 2026-11-14, a 99 setup fee and a 49 monthly plan in
|
|
12
|
+
* advance. ONE real run as of 2026-12-14 must close BOTH bill dates:
|
|
13
|
+
* - Nov 14: setup fee + plan for Nov 14 – Dec 13,
|
|
14
|
+
* - Dec 14: plan for Dec 14 – Jan 13,
|
|
15
|
+
* and leave next_bill_date = 2027-01-14. Then, with the tax point switched to
|
|
16
|
+
* `consumption`, a 10 net @ 23 % plan debits 12.30.
|
|
17
|
+
* Self-contained: own accounts (soft-deleted after); the tax point is
|
|
18
|
+
* restored to `topup` in a finally block. Serial — the tax point is org-wide.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
const uniq = () => Date.now().toString(36) + Math.random().toString(36).slice(2, 6)
|
|
22
|
+
|
|
23
|
+
type Cycle = { bill_date: string; status: string; total_debit?: string }
|
|
24
|
+
type Txn = { type: string; amount: string; source_ref: string | null }
|
|
25
|
+
|
|
26
|
+
async function createPrepaidAccount(request: APIRequestContext, token: string, nextBillDate: string): Promise<string> {
|
|
27
|
+
const res = await apiRequest(request, 'POST', '/api/billing/accounts', {
|
|
28
|
+
token,
|
|
29
|
+
data: {
|
|
30
|
+
customerId: `cust-${uniq()}`,
|
|
31
|
+
name: `Prepaid ${uniq()}`,
|
|
32
|
+
currencyCode: 'EUR',
|
|
33
|
+
billCycle: 'monthly',
|
|
34
|
+
billCycleAnchor: '14',
|
|
35
|
+
invoiceEmail: `inv-${uniq()}@example.com`,
|
|
36
|
+
invoiceLanguage: 'en',
|
|
37
|
+
nextBillDate,
|
|
38
|
+
billingMode: 'prepaid',
|
|
39
|
+
invoiceAddress: { line1: 'ul. Testowa 1', city: 'Warszawa', postal_code: '00-001', country: 'PL' },
|
|
40
|
+
},
|
|
41
|
+
})
|
|
42
|
+
expect(res.ok(), `POST account status was ${res.status()}`).toBeTruthy()
|
|
43
|
+
return ((await res.json()) as { id: string }).id
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async function createItem(request: APIRequestContext, token: string, data: Record<string, unknown>): Promise<void> {
|
|
47
|
+
const res = await apiRequest(request, 'POST', '/api/billing/items', { token, data })
|
|
48
|
+
expect(res.ok(), `POST item status was ${res.status()}`).toBeTruthy()
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async function realRun(request: APIRequestContext, token: string, accountId: string, asOfDate: string): Promise<Cycle[]> {
|
|
52
|
+
const run = await apiRequest(request, 'POST', '/api/billing/runs', {
|
|
53
|
+
token,
|
|
54
|
+
data: { mode: 'real', asOfDate, scopedAccountIds: [accountId] },
|
|
55
|
+
})
|
|
56
|
+
expect(run.ok(), `POST run status was ${run.status()}`).toBeTruthy()
|
|
57
|
+
const { billRunId } = (await run.json()) as { billRunId: string }
|
|
58
|
+
const outcomes = await apiRequest(request, 'GET', `/api/billing/run-outcomes?billRunId=${billRunId}`, { token })
|
|
59
|
+
const body = (await outcomes.json()) as { items: Array<{ bill_account_id: string; cycles: Cycle[] | null }> }
|
|
60
|
+
return body.items.find((row) => row.bill_account_id === accountId)?.cycles ?? []
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async function charges(request: APIRequestContext, token: string, accountId: string): Promise<Txn[]> {
|
|
64
|
+
const res = await apiRequest(request, 'GET', `/api/billing/transactions?billAccountId=${accountId}&pageSize=50`, { token })
|
|
65
|
+
const rows = ((await res.json()) as { items: Txn[] }).items
|
|
66
|
+
return rows.filter((row) => row.type === 'recurring' || row.type === 'one_time')
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async function nextBillDate(request: APIRequestContext, token: string, accountId: string): Promise<string> {
|
|
70
|
+
const res = await apiRequest(request, 'GET', `/api/billing/accounts?id=${accountId}&pageSize=1`, { token })
|
|
71
|
+
return ((await res.json()) as { items: Array<{ next_bill_date: string }> }).items[0].next_bill_date.slice(0, 10)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
test.describe.serial('TC-BILL-011: prepaid period close (Spec F)', () => {
|
|
75
|
+
let token: string
|
|
76
|
+
const accounts: string[] = []
|
|
77
|
+
|
|
78
|
+
test.beforeAll(async ({ request }) => {
|
|
79
|
+
token = await getAuthToken(request, 'admin')
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
test.afterAll(async ({ request }) => {
|
|
83
|
+
for (const id of accounts) {
|
|
84
|
+
await apiRequest(request, 'DELETE', '/api/billing/accounts', { token, data: { id } })
|
|
85
|
+
}
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
test('one real run closes every due bill date, in advance (the F4 report)', async ({ request }) => {
|
|
89
|
+
const accountId = await createPrepaidAccount(request, token, '2026-11-14')
|
|
90
|
+
accounts.push(accountId)
|
|
91
|
+
await createItem(request, token, {
|
|
92
|
+
billAccountId: accountId,
|
|
93
|
+
type: 'one_time',
|
|
94
|
+
billStartDate: '2026-11-14',
|
|
95
|
+
description: 'Setup fee',
|
|
96
|
+
rateJson: { amount: 99 },
|
|
97
|
+
})
|
|
98
|
+
await createItem(request, token, {
|
|
99
|
+
billAccountId: accountId,
|
|
100
|
+
type: 'recurring',
|
|
101
|
+
billStartDate: '2026-11-14',
|
|
102
|
+
description: 'Plan',
|
|
103
|
+
rateJson: { unit_price: 49 },
|
|
104
|
+
chargeTiming: 'in_advance',
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
const cycles = await realRun(request, token, accountId, '2026-12-14')
|
|
108
|
+
expect(cycles.map((c) => [c.bill_date, c.status, c.total_debit])).toEqual([
|
|
109
|
+
['2026-11-14', 'charged', '148.0000'],
|
|
110
|
+
['2026-12-14', 'charged', '49.0000'],
|
|
111
|
+
])
|
|
112
|
+
expect(await nextBillDate(request, token, accountId)).toBe('2027-01-14')
|
|
113
|
+
const refs = (await charges(request, token, accountId)).map((t) => t.source_ref ?? '')
|
|
114
|
+
expect(refs).toHaveLength(3)
|
|
115
|
+
expect(refs.filter((ref) => ref.startsWith('one_time-'))).toHaveLength(1)
|
|
116
|
+
expect(refs.some((ref) => ref.endsWith('-charge-2026-11-14-2026-12-13'))).toBe(true)
|
|
117
|
+
expect(refs.some((ref) => ref.endsWith('-charge-2026-12-14-2027-01-13'))).toBe(true)
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
test('tax at billing: a 10 net @ 23 % plan debits 12.30', async ({ request }) => {
|
|
121
|
+
const set = (prepaidTaxPoint: 'topup' | 'consumption') =>
|
|
122
|
+
apiRequest(request, 'PUT', '/api/billing/settings', { token, data: { prepaidTaxPoint } })
|
|
123
|
+
try {
|
|
124
|
+
expect((await set('consumption')).ok()).toBeTruthy()
|
|
125
|
+
const accountId = await createPrepaidAccount(request, token, '2026-11-14')
|
|
126
|
+
accounts.push(accountId)
|
|
127
|
+
await createItem(request, token, {
|
|
128
|
+
billAccountId: accountId,
|
|
129
|
+
type: 'recurring',
|
|
130
|
+
billStartDate: '2026-11-14',
|
|
131
|
+
description: 'Plan (VAT at billing)',
|
|
132
|
+
rateJson: { unit_price: 10 },
|
|
133
|
+
taxRate: 23,
|
|
134
|
+
chargeTiming: 'in_advance',
|
|
135
|
+
})
|
|
136
|
+
await realRun(request, token, accountId, '2026-11-14')
|
|
137
|
+
expect((await charges(request, token, accountId)).map((t) => t.amount)).toEqual(['-12.3000'])
|
|
138
|
+
} finally {
|
|
139
|
+
await set('topup')
|
|
140
|
+
}
|
|
141
|
+
})
|
|
142
|
+
})
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { test, expect, type APIRequestContext } from '@playwright/test'
|
|
2
|
+
import { getAuthToken, apiRequest } from '@open-mercato/core/helpers/integration/api'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* TC-BILL-012: Delete test / dry Bill Runs (Spec F, F1)
|
|
6
|
+
* Category: BILL — API
|
|
7
|
+
* Priority: High
|
|
8
|
+
* Spec: .ai/specs/2026-11-15-billing-operator-feedback.md (F-D1)
|
|
9
|
+
*
|
|
10
|
+
* - deleting a test run removes the run, its outcomes and its test invoices;
|
|
11
|
+
* - a dry run deletes cleanly (no invoices);
|
|
12
|
+
* - a real run is refused with 422 `billing.run.delete_real_forbidden`;
|
|
13
|
+
* - the `mode` list filter narrows runs.
|
|
14
|
+
* Self-contained: own account (soft-deleted after). The real run is scoped to
|
|
15
|
+
* an account with nothing due, so it writes no documents.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
const uniq = () => Date.now().toString(36) + Math.random().toString(36).slice(2, 6)
|
|
19
|
+
|
|
20
|
+
async function createAccount(request: APIRequestContext, token: string, nextBillDate: string): Promise<string> {
|
|
21
|
+
const res = await apiRequest(request, 'POST', '/api/billing/accounts', {
|
|
22
|
+
token,
|
|
23
|
+
data: {
|
|
24
|
+
customerId: `cust-${uniq()}`,
|
|
25
|
+
name: `Run delete ${uniq()}`,
|
|
26
|
+
currencyCode: 'PLN',
|
|
27
|
+
billCycle: 'monthly',
|
|
28
|
+
billCycleAnchor: '1',
|
|
29
|
+
invoiceEmail: `inv-${uniq()}@example.com`,
|
|
30
|
+
invoiceLanguage: 'en',
|
|
31
|
+
nextBillDate,
|
|
32
|
+
invoiceAddress: { line1: 'ul. Testowa 1', city: 'Warszawa', postal_code: '00-001', country: 'PL' },
|
|
33
|
+
},
|
|
34
|
+
})
|
|
35
|
+
expect(res.ok(), `POST account status was ${res.status()}`).toBeTruthy()
|
|
36
|
+
const accountId = ((await res.json()) as { id: string }).id
|
|
37
|
+
const item = await apiRequest(request, 'POST', '/api/billing/items', {
|
|
38
|
+
token,
|
|
39
|
+
data: { billAccountId: accountId, type: 'recurring', billStartDate: nextBillDate, description: 'Plan', rateJson: { unit_price: 100 } },
|
|
40
|
+
})
|
|
41
|
+
expect(item.ok(), `POST item status was ${item.status()}`).toBeTruthy()
|
|
42
|
+
return accountId
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async function trigger(
|
|
46
|
+
request: APIRequestContext,
|
|
47
|
+
token: string,
|
|
48
|
+
accountId: string,
|
|
49
|
+
mode: 'real' | 'test' | 'dry',
|
|
50
|
+
asOfDate: string,
|
|
51
|
+
): Promise<string> {
|
|
52
|
+
const run = await apiRequest(request, 'POST', '/api/billing/runs', {
|
|
53
|
+
token,
|
|
54
|
+
data: { mode, asOfDate, scopedAccountIds: [accountId] },
|
|
55
|
+
})
|
|
56
|
+
expect(run.ok(), `POST run (${mode}) status was ${run.status()}`).toBeTruthy()
|
|
57
|
+
return ((await run.json()) as { billRunId: string }).billRunId
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
test.describe('TC-BILL-012: delete test / dry Bill Runs (Spec F)', () => {
|
|
61
|
+
let token: string
|
|
62
|
+
const accounts: string[] = []
|
|
63
|
+
|
|
64
|
+
test.beforeAll(async ({ request }) => {
|
|
65
|
+
token = await getAuthToken(request, 'admin')
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
test.afterAll(async ({ request }) => {
|
|
69
|
+
for (const id of accounts) {
|
|
70
|
+
await apiRequest(request, 'DELETE', '/api/billing/accounts', { token, data: { id } })
|
|
71
|
+
}
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
test('a test run is deleted with its test invoices and outcomes', async ({ request }) => {
|
|
75
|
+
const accountId = await createAccount(request, token, '2026-08-01')
|
|
76
|
+
accounts.push(accountId)
|
|
77
|
+
const runId = await trigger(request, token, accountId, 'test', '2026-09-15')
|
|
78
|
+
|
|
79
|
+
const before = await apiRequest(request, 'GET', `/api/billing/invoices?billAccountId=${accountId}&testRun=true`, { token })
|
|
80
|
+
expect(((await before.json()) as { items: unknown[] }).items.length).toBe(2)
|
|
81
|
+
|
|
82
|
+
const filtered = await apiRequest(request, 'GET', `/api/billing/runs?mode=test&id=${runId}`, { token })
|
|
83
|
+
expect(((await filtered.json()) as { items: unknown[] }).items).toHaveLength(1)
|
|
84
|
+
|
|
85
|
+
const del = await apiRequest(request, 'DELETE', `/api/billing/runs/${runId}`, { token })
|
|
86
|
+
expect(del.status()).toBe(200)
|
|
87
|
+
expect(await del.json()).toEqual({ ok: true, invoicesRemoved: 2 })
|
|
88
|
+
|
|
89
|
+
const after = await apiRequest(request, 'GET', `/api/billing/invoices?billAccountId=${accountId}&testRun=true`, { token })
|
|
90
|
+
expect(((await after.json()) as { items: unknown[] }).items).toHaveLength(0)
|
|
91
|
+
const run = await apiRequest(request, 'GET', `/api/billing/runs?id=${runId}`, { token })
|
|
92
|
+
expect(((await run.json()) as { items: unknown[] }).items).toHaveLength(0)
|
|
93
|
+
const outcomes = await apiRequest(request, 'GET', `/api/billing/run-outcomes?billRunId=${runId}`, { token })
|
|
94
|
+
expect(((await outcomes.json()) as { items: unknown[] }).items).toHaveLength(0)
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
test('a dry run deletes cleanly', async ({ request }) => {
|
|
98
|
+
const accountId = await createAccount(request, token, '2026-08-01')
|
|
99
|
+
accounts.push(accountId)
|
|
100
|
+
const runId = await trigger(request, token, accountId, 'dry', '2026-08-15')
|
|
101
|
+
const del = await apiRequest(request, 'DELETE', `/api/billing/runs/${runId}`, { token })
|
|
102
|
+
expect(del.status()).toBe(200)
|
|
103
|
+
expect(((await del.json()) as { invoicesRemoved: number }).invoicesRemoved).toBe(0)
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
test('a real run is never deleted', async ({ request }) => {
|
|
107
|
+
// Nothing due up to the as-of date → the real run writes no documents.
|
|
108
|
+
const accountId = await createAccount(request, token, '2030-01-01')
|
|
109
|
+
accounts.push(accountId)
|
|
110
|
+
const runId = await trigger(request, token, accountId, 'real', '2026-08-15')
|
|
111
|
+
const del = await apiRequest(request, 'DELETE', `/api/billing/runs/${runId}`, { token })
|
|
112
|
+
expect(del.status()).toBe(422)
|
|
113
|
+
expect(((await del.json()) as { code: string }).code).toBe('billing.run.delete_real_forbidden')
|
|
114
|
+
})
|
|
115
|
+
})
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { test, expect } from '@playwright/test'
|
|
2
|
+
import { getAuthToken, apiRequest } from '@open-mercato/core/helpers/integration/api'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* TC-BILL-013: Gross-basis item price reaches the invoice exactly (Spec F, F3)
|
|
6
|
+
* Category: BILL — API
|
|
7
|
+
* Priority: Medium
|
|
8
|
+
* Spec: .ai/specs/2026-11-15-billing-operator-feedback.md (F-D2)
|
|
9
|
+
*
|
|
10
|
+
* A recurring item entered as 49.99 GROSS at 23 % VAT: the test draft line
|
|
11
|
+
* carries gross 49.99 (net 40.64 + VAT 9.35) — a value net-only storage
|
|
12
|
+
* could not reproduce. The item API echoes `price_basis`. A gross basis on a
|
|
13
|
+
* tiered usage rate is refused (422).
|
|
14
|
+
* Self-contained: own account (soft-deleted after), test drafts wiped.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
const uniq = () => Date.now().toString(36) + Math.random().toString(36).slice(2, 6)
|
|
18
|
+
|
|
19
|
+
test.describe('TC-BILL-013: gross price basis (Spec F)', () => {
|
|
20
|
+
let token: string
|
|
21
|
+
let accountId: string | null = null
|
|
22
|
+
let runId: string | null = null
|
|
23
|
+
|
|
24
|
+
test.beforeAll(async ({ request }) => {
|
|
25
|
+
token = await getAuthToken(request, 'admin')
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
test.afterEach(async ({ request }) => {
|
|
29
|
+
if (runId) {
|
|
30
|
+
await apiRequest(request, 'DELETE', `/api/billing/runs/${runId}`, { token })
|
|
31
|
+
runId = null
|
|
32
|
+
}
|
|
33
|
+
if (accountId) {
|
|
34
|
+
await apiRequest(request, 'DELETE', '/api/billing/accounts', { token, data: { id: accountId } })
|
|
35
|
+
accountId = null
|
|
36
|
+
}
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
test('the typed gross is the invoice gross', async ({ request }) => {
|
|
40
|
+
const account = await apiRequest(request, 'POST', '/api/billing/accounts', {
|
|
41
|
+
token,
|
|
42
|
+
data: {
|
|
43
|
+
customerId: `cust-${uniq()}`,
|
|
44
|
+
name: `Gross ${uniq()}`,
|
|
45
|
+
currencyCode: 'PLN',
|
|
46
|
+
billCycle: 'monthly',
|
|
47
|
+
billCycleAnchor: '1',
|
|
48
|
+
invoiceEmail: `inv-${uniq()}@example.com`,
|
|
49
|
+
invoiceLanguage: 'pl',
|
|
50
|
+
nextBillDate: '2026-11-01',
|
|
51
|
+
invoiceAddress: { line1: 'ul. Testowa 1', city: 'Warszawa', postal_code: '00-001', country: 'PL' },
|
|
52
|
+
},
|
|
53
|
+
})
|
|
54
|
+
expect(account.ok()).toBeTruthy()
|
|
55
|
+
accountId = ((await account.json()) as { id: string }).id
|
|
56
|
+
|
|
57
|
+
const item = await apiRequest(request, 'POST', '/api/billing/items', {
|
|
58
|
+
token,
|
|
59
|
+
data: {
|
|
60
|
+
billAccountId: accountId,
|
|
61
|
+
type: 'recurring',
|
|
62
|
+
billStartDate: '2026-11-01',
|
|
63
|
+
description: 'Internet (brutto)',
|
|
64
|
+
rateJson: { unit_price: 49.99 },
|
|
65
|
+
taxRate: 23,
|
|
66
|
+
priceBasis: 'gross',
|
|
67
|
+
},
|
|
68
|
+
})
|
|
69
|
+
expect(item.ok(), `POST item status was ${item.status()}`).toBeTruthy()
|
|
70
|
+
const items = await apiRequest(request, 'GET', `/api/billing/items?billAccountId=${accountId}`, { token })
|
|
71
|
+
expect(((await items.json()) as { items: Array<{ price_basis: string }> }).items[0].price_basis).toBe('gross')
|
|
72
|
+
|
|
73
|
+
const run = await apiRequest(request, 'POST', '/api/billing/runs', {
|
|
74
|
+
token,
|
|
75
|
+
data: { mode: 'test', asOfDate: '2026-11-01', scopedAccountIds: [accountId] },
|
|
76
|
+
})
|
|
77
|
+
expect(run.ok()).toBeTruthy()
|
|
78
|
+
runId = ((await run.json()) as { billRunId: string }).billRunId
|
|
79
|
+
|
|
80
|
+
const list = await apiRequest(request, 'GET', `/api/billing/invoices?billAccountId=${accountId}&testRun=true`, { token })
|
|
81
|
+
const invoiceId = ((await list.json()) as { items: Array<{ id: string }> }).items[0].id
|
|
82
|
+
const detail = await apiRequest(request, 'GET', `/api/billing/invoices/${invoiceId}`, { token })
|
|
83
|
+
const body = (await detail.json()) as { lines: Array<{ net_amount: string; tax_amount: string; gross_amount: string }> }
|
|
84
|
+
expect(body.lines.map((l) => [Number(l.net_amount), Number(l.tax_amount), Number(l.gross_amount)])).toEqual([[40.64, 9.35, 49.99]])
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
test('a gross basis on a tiered usage rate is refused', async ({ request }) => {
|
|
88
|
+
const account = await apiRequest(request, 'POST', '/api/billing/accounts', {
|
|
89
|
+
token,
|
|
90
|
+
data: {
|
|
91
|
+
customerId: `cust-${uniq()}`,
|
|
92
|
+
name: `Tiered ${uniq()}`,
|
|
93
|
+
currencyCode: 'PLN',
|
|
94
|
+
billCycle: 'monthly',
|
|
95
|
+
billCycleAnchor: '1',
|
|
96
|
+
invoiceEmail: `inv-${uniq()}@example.com`,
|
|
97
|
+
invoiceLanguage: 'en',
|
|
98
|
+
nextBillDate: '2026-11-01',
|
|
99
|
+
invoiceAddress: { line1: 'ul. Testowa 1', city: 'Warszawa', postal_code: '00-001', country: 'PL' },
|
|
100
|
+
},
|
|
101
|
+
})
|
|
102
|
+
accountId = ((await account.json()) as { id: string }).id
|
|
103
|
+
const item = await apiRequest(request, 'POST', '/api/billing/items', {
|
|
104
|
+
token,
|
|
105
|
+
data: {
|
|
106
|
+
billAccountId: accountId,
|
|
107
|
+
type: 'usage',
|
|
108
|
+
uomCode: 'gb',
|
|
109
|
+
billStartDate: '2026-11-01',
|
|
110
|
+
description: 'Data',
|
|
111
|
+
priceBasis: 'gross',
|
|
112
|
+
rateJson: { model: 'volume', tiers: [{ up_to: null, unit_price: 1 }] },
|
|
113
|
+
},
|
|
114
|
+
})
|
|
115
|
+
expect(item.status()).toBeGreaterThanOrEqual(400)
|
|
116
|
+
expect(item.status()).toBeLessThan(500)
|
|
117
|
+
})
|
|
118
|
+
})
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { expect, type APIRequestContext } from '@playwright/test'
|
|
2
|
+
import { apiRequest } from '@open-mercato/core/helpers/integration/api'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Spec B: posting needs the seller details (legal name, address, tax id,
|
|
6
|
+
* IBAN). Integration tests fill them for the test organization before
|
|
7
|
+
* posting. Idempotent — a PUT of the same values.
|
|
8
|
+
*/
|
|
9
|
+
export async function ensureSellerSettings(request: APIRequestContext, token: string): Promise<void> {
|
|
10
|
+
const res = await apiRequest(request, 'PUT', '/api/billing/settings', {
|
|
11
|
+
token,
|
|
12
|
+
data: {
|
|
13
|
+
legalName: 'QA Seller sp. z o.o.',
|
|
14
|
+
sellerAddress: { line1: 'ul. Testowa 10', city: 'Kraków', postal_code: '30-001', country: 'PL' },
|
|
15
|
+
taxId: 'PL1234563218',
|
|
16
|
+
bankName: 'QA Bank',
|
|
17
|
+
iban: 'PL61109010140000071219812874',
|
|
18
|
+
bic: 'WBKPPLPP',
|
|
19
|
+
defaultPaymentTermsDays: 14,
|
|
20
|
+
defaultTaxRate: 23,
|
|
21
|
+
},
|
|
22
|
+
})
|
|
23
|
+
expect(res.ok(), `PUT settings status was ${res.status()}`).toBeTruthy()
|
|
24
|
+
}
|