@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,170 @@
|
|
|
1
|
+
import { test, expect, type APIRequestContext } from '@playwright/test'
|
|
2
|
+
import { getAuthToken, apiRequest } from '@open-mercato/core/helpers/integration/api'
|
|
3
|
+
import { login } from '@open-mercato/core/helpers/integration/auth'
|
|
4
|
+
import {
|
|
5
|
+
createPersonFixture,
|
|
6
|
+
deleteEntityIfExists,
|
|
7
|
+
} from '@open-mercato/core/helpers/integration/crmFixtures'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* TC-BILL-004: B2C billing accounts, invoice-language picklist, return-to-account navigation
|
|
11
|
+
* Category: BILL — API + UI
|
|
12
|
+
* Priority: High
|
|
13
|
+
* Spec: .ai/specs/2026-11-14-billing-account-workspace.md (Phase 1, D21–D23)
|
|
14
|
+
*
|
|
15
|
+
* Self-contained: creates its own person, account and item; removes them
|
|
16
|
+
* in teardown. Avoids `GET /api/billing/accounts?id=` (known CI flake, see
|
|
17
|
+
* TC-BILL-001) — reads back through the `customerKind` + `search` filters.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
const uniq = () => Date.now().toString(36) + Math.random().toString(36).slice(2, 6)
|
|
21
|
+
|
|
22
|
+
function accountPayload(overrides: Record<string, unknown> = {}) {
|
|
23
|
+
return {
|
|
24
|
+
customerId: `cust-${uniq()}`,
|
|
25
|
+
name: `B2C Account ${uniq()}`,
|
|
26
|
+
currencyCode: 'PLN',
|
|
27
|
+
billCycle: 'monthly',
|
|
28
|
+
billCycleAnchor: '1',
|
|
29
|
+
invoiceEmail: `inv-${uniq()}@example.com`,
|
|
30
|
+
invoiceLanguage: 'pl',
|
|
31
|
+
nextBillDate: '2026-12-01',
|
|
32
|
+
invoiceAddress: { line1: 'ul. Testowa 1', city: 'Warszawa', postal_code: '00-001', country: 'PL' },
|
|
33
|
+
...overrides,
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async function createAccount(
|
|
38
|
+
request: APIRequestContext,
|
|
39
|
+
token: string,
|
|
40
|
+
data: Record<string, unknown>,
|
|
41
|
+
): Promise<string> {
|
|
42
|
+
const res = await apiRequest(request, 'POST', '/api/billing/accounts', { token, data })
|
|
43
|
+
expect(res.ok(), `POST /api/billing/accounts status was ${res.status()}`).toBeTruthy()
|
|
44
|
+
const body = (await res.json()) as { id?: string }
|
|
45
|
+
expect(body.id).toBeTruthy()
|
|
46
|
+
return body.id as string
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async function createItem(request: APIRequestContext, token: string, billAccountId: string): Promise<string> {
|
|
50
|
+
const res = await apiRequest(request, 'POST', '/api/billing/items', {
|
|
51
|
+
token,
|
|
52
|
+
data: {
|
|
53
|
+
billAccountId,
|
|
54
|
+
type: 'recurring',
|
|
55
|
+
billStartDate: '2026-12-01',
|
|
56
|
+
description: `Internet 300 ${uniq()}`,
|
|
57
|
+
rateJson: { unit_price: 79 },
|
|
58
|
+
},
|
|
59
|
+
})
|
|
60
|
+
expect(res.ok(), `POST /api/billing/items status was ${res.status()}`).toBeTruthy()
|
|
61
|
+
return ((await res.json()) as { id: string }).id
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
test.describe('TC-BILL-004: B2C accounts + navigation', () => {
|
|
65
|
+
let token: string
|
|
66
|
+
const accountIds: string[] = []
|
|
67
|
+
const itemIds: string[] = []
|
|
68
|
+
const personIds: string[] = []
|
|
69
|
+
|
|
70
|
+
test.beforeAll(async ({ request }) => {
|
|
71
|
+
token = await getAuthToken(request, 'admin')
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
test.afterEach(async ({ request }) => {
|
|
75
|
+
while (itemIds.length) {
|
|
76
|
+
await apiRequest(request, 'DELETE', '/api/billing/items', { token, data: { id: itemIds.pop() } })
|
|
77
|
+
}
|
|
78
|
+
while (accountIds.length) {
|
|
79
|
+
await apiRequest(request, 'DELETE', '/api/billing/accounts', { token, data: { id: accountIds.pop() } })
|
|
80
|
+
}
|
|
81
|
+
while (personIds.length) {
|
|
82
|
+
await deleteEntityIfExists(request, token, '/api/customers/people', personIds.pop() ?? null)
|
|
83
|
+
}
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
test('creates a person (B2C) account and filters by customer kind', async ({ request }) => {
|
|
87
|
+
const suffix = uniq()
|
|
88
|
+
const personId = await createPersonFixture(request, token, {
|
|
89
|
+
firstName: 'Jan',
|
|
90
|
+
lastName: `Kowalski ${suffix}`,
|
|
91
|
+
displayName: `Jan Kowalski ${suffix}`,
|
|
92
|
+
primaryEmail: `jan-${suffix}@example.com`,
|
|
93
|
+
})
|
|
94
|
+
personIds.push(personId)
|
|
95
|
+
const name = `B2C ${suffix}`
|
|
96
|
+
accountIds.push(
|
|
97
|
+
await createAccount(request, token, accountPayload({ customerId: personId, customerKind: 'person', name })),
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
const persons = await apiRequest(
|
|
101
|
+
request,
|
|
102
|
+
'GET',
|
|
103
|
+
`/api/billing/accounts?customerKind=person&search=${encodeURIComponent(name)}`,
|
|
104
|
+
{ token },
|
|
105
|
+
)
|
|
106
|
+
const personRows = ((await persons.json()) as { items: Array<{ name: string; customer_kind: string }> }).items
|
|
107
|
+
expect(personRows.find((row) => row.name === name)?.customer_kind).toBe('person')
|
|
108
|
+
|
|
109
|
+
const companies = await apiRequest(
|
|
110
|
+
request,
|
|
111
|
+
'GET',
|
|
112
|
+
`/api/billing/accounts?customerKind=company&search=${encodeURIComponent(name)}`,
|
|
113
|
+
{ token },
|
|
114
|
+
)
|
|
115
|
+
const companyRows = ((await companies.json()) as { items: Array<{ name: string }> }).items
|
|
116
|
+
expect(companyRows.some((row) => row.name === name)).toBe(false)
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
test('defaults customer kind to company', async ({ request }) => {
|
|
120
|
+
const name = `Company ${uniq()}`
|
|
121
|
+
accountIds.push(await createAccount(request, token, accountPayload({ name })))
|
|
122
|
+
const res = await apiRequest(
|
|
123
|
+
request,
|
|
124
|
+
'GET',
|
|
125
|
+
`/api/billing/accounts?customerKind=company&search=${encodeURIComponent(name)}`,
|
|
126
|
+
{ token },
|
|
127
|
+
)
|
|
128
|
+
const rows = ((await res.json()) as { items: Array<{ name: string; customer_kind: string }> }).items
|
|
129
|
+
expect(rows.find((row) => row.name === name)?.customer_kind).toBe('company')
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
test('rejects an invoice language the template does not support', async ({ request }) => {
|
|
133
|
+
const res = await apiRequest(request, 'POST', '/api/billing/accounts', {
|
|
134
|
+
token,
|
|
135
|
+
data: accountPayload({ invoiceLanguage: 'de' }),
|
|
136
|
+
})
|
|
137
|
+
expect(res.status()).toBe(400)
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
test('item pages return to the owning account; from the items list they return to the list', async ({
|
|
141
|
+
page,
|
|
142
|
+
request,
|
|
143
|
+
}) => {
|
|
144
|
+
const accountId = await createAccount(request, token, accountPayload())
|
|
145
|
+
accountIds.push(accountId)
|
|
146
|
+
const itemId = await createItem(request, token, accountId)
|
|
147
|
+
itemIds.push(itemId)
|
|
148
|
+
|
|
149
|
+
await login(page, 'admin')
|
|
150
|
+
|
|
151
|
+
// FormHeader's back link is the anchor rendering the "←" glyph. (The
|
|
152
|
+
// detail body also links to the account, so match the header link only.)
|
|
153
|
+
const backLink = page.locator('a', { hasText: '←' }).first()
|
|
154
|
+
|
|
155
|
+
// Opened in account context → back goes to the account's Items tab (Spec F, F8).
|
|
156
|
+
await page.goto(`/backend/billing/items/${itemId}`, { waitUntil: 'domcontentloaded' })
|
|
157
|
+
await expect(backLink).toHaveAttribute('href', `/backend/billing/accounts/${accountId}?tab=items`)
|
|
158
|
+
|
|
159
|
+
// Opened from the global Items list → back goes to the list.
|
|
160
|
+
await page.goto(`/backend/billing/items/${itemId}?from=items`, { waitUntil: 'domcontentloaded' })
|
|
161
|
+
await expect(backLink).toHaveAttribute('href', '/backend/billing/items')
|
|
162
|
+
|
|
163
|
+
// "Add item" from an account → Cancel returns to that account's Items tab.
|
|
164
|
+
await page.goto(`/backend/billing/items/create?billAccountId=${accountId}`, {
|
|
165
|
+
waitUntil: 'domcontentloaded',
|
|
166
|
+
})
|
|
167
|
+
await page.getByRole('button', { name: /cancel/i }).first().click()
|
|
168
|
+
await expect(page).toHaveURL(new RegExp(`/backend/billing/accounts/${accountId}\\?tab=items$`))
|
|
169
|
+
})
|
|
170
|
+
})
|
|
@@ -0,0 +1,134 @@
|
|
|
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-005: Bill Run catches up on every due cycle (Spec A)
|
|
6
|
+
* Category: BILL — API
|
|
7
|
+
* Priority: High
|
|
8
|
+
* Spec: .ai/specs/2026-11-14-billing-cycle-semantics.md
|
|
9
|
+
*
|
|
10
|
+
* An account whose next bill date lies three cycles before the as-of date,
|
|
11
|
+
* with one monthly in-advance item:
|
|
12
|
+
* - a dry run previews 3 cycles and writes no invoice;
|
|
13
|
+
* - a test run writes 3 TEST drafts (one per bill date), each covering its
|
|
14
|
+
* own month, and leaves the account untouched;
|
|
15
|
+
* - a legacy `catchUp` flag in the body is accepted and ignored.
|
|
16
|
+
* Self-contained: creates its own account + item, wipes its test drafts.
|
|
17
|
+
* Scoped with `scopedAccountIds` so other tenant data can't interfere.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
const uniq = () => Date.now().toString(36) + Math.random().toString(36).slice(2, 6)
|
|
21
|
+
|
|
22
|
+
type Cycle = { bill_date: string; period_start: string | null; period_end: string | null; status: string; invoice_id: string | null }
|
|
23
|
+
|
|
24
|
+
async function createAccountWithItem(request: APIRequestContext, token: string): Promise<string> {
|
|
25
|
+
const account = await apiRequest(request, 'POST', '/api/billing/accounts', {
|
|
26
|
+
token,
|
|
27
|
+
data: {
|
|
28
|
+
customerId: `cust-${uniq()}`,
|
|
29
|
+
name: `Catch-up ${uniq()}`,
|
|
30
|
+
currencyCode: 'PLN',
|
|
31
|
+
billCycle: 'monthly',
|
|
32
|
+
billCycleAnchor: '1',
|
|
33
|
+
invoiceEmail: `inv-${uniq()}@example.com`,
|
|
34
|
+
invoiceLanguage: 'en',
|
|
35
|
+
nextBillDate: '2026-08-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
|
+
|
|
42
|
+
const item = await apiRequest(request, 'POST', '/api/billing/items', {
|
|
43
|
+
token,
|
|
44
|
+
data: {
|
|
45
|
+
billAccountId: accountId,
|
|
46
|
+
type: 'recurring',
|
|
47
|
+
billStartDate: '2026-08-01',
|
|
48
|
+
description: 'Internet 300',
|
|
49
|
+
rateJson: { unit_price: 100 },
|
|
50
|
+
chargeTiming: 'in_advance',
|
|
51
|
+
},
|
|
52
|
+
})
|
|
53
|
+
expect(item.ok(), `POST item status was ${item.status()}`).toBeTruthy()
|
|
54
|
+
return accountId
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async function runCycles(
|
|
58
|
+
request: APIRequestContext,
|
|
59
|
+
token: string,
|
|
60
|
+
accountId: string,
|
|
61
|
+
mode: 'dry' | 'test',
|
|
62
|
+
): Promise<{ billRunId: string; cycles: Cycle[] }> {
|
|
63
|
+
const run = await apiRequest(request, 'POST', '/api/billing/runs', {
|
|
64
|
+
token,
|
|
65
|
+
data: { mode, asOfDate: '2026-10-15', scopedAccountIds: [accountId], catchUp: true },
|
|
66
|
+
})
|
|
67
|
+
expect(run.ok(), `POST run (${mode}) status was ${run.status()}`).toBeTruthy()
|
|
68
|
+
const { billRunId } = (await run.json()) as { billRunId: string }
|
|
69
|
+
|
|
70
|
+
const outcomes = await apiRequest(request, 'GET', `/api/billing/run-outcomes?billRunId=${billRunId}`, { token })
|
|
71
|
+
const body = (await outcomes.json()) as { items: Array<{ bill_account_id: string; cycles: Cycle[] | null }> }
|
|
72
|
+
const outcome = body.items.find((row) => row.bill_account_id === accountId)
|
|
73
|
+
expect(outcome, 'outcome for the scoped account').toBeTruthy()
|
|
74
|
+
return { billRunId, cycles: outcome?.cycles ?? [] }
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
test.describe('TC-BILL-005: Bill Run catch-up (Spec A)', () => {
|
|
78
|
+
let token: string
|
|
79
|
+
let accountId: string | null = null
|
|
80
|
+
const testRunIds: string[] = []
|
|
81
|
+
|
|
82
|
+
test.beforeAll(async ({ request }) => {
|
|
83
|
+
token = await getAuthToken(request, 'admin')
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
test.afterEach(async ({ request }) => {
|
|
87
|
+
while (testRunIds.length) {
|
|
88
|
+
await apiRequest(request, 'POST', '/api/billing/test-invoices/wipe', {
|
|
89
|
+
token,
|
|
90
|
+
data: { billRunId: testRunIds.pop() },
|
|
91
|
+
})
|
|
92
|
+
}
|
|
93
|
+
if (accountId) {
|
|
94
|
+
await apiRequest(request, 'DELETE', '/api/billing/accounts', { token, data: { id: accountId } })
|
|
95
|
+
accountId = null
|
|
96
|
+
}
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
test('dry run previews every due cycle without writing invoices', async ({ request }) => {
|
|
100
|
+
accountId = await createAccountWithItem(request, token)
|
|
101
|
+
const { cycles } = await runCycles(request, token, accountId, 'dry')
|
|
102
|
+
expect(cycles.map((c) => [c.bill_date, c.status, c.invoice_id])).toEqual([
|
|
103
|
+
['2026-08-01', 'previewed', null],
|
|
104
|
+
['2026-09-01', 'previewed', null],
|
|
105
|
+
['2026-10-01', 'previewed', null],
|
|
106
|
+
])
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
test('test run writes one TEST draft per bill date, each for its own month', async ({ request }) => {
|
|
110
|
+
accountId = await createAccountWithItem(request, token)
|
|
111
|
+
const { billRunId, cycles } = await runCycles(request, token, accountId, 'test')
|
|
112
|
+
testRunIds.push(billRunId)
|
|
113
|
+
|
|
114
|
+
expect(cycles.map((c) => [c.bill_date, c.period_start, c.period_end, c.status])).toEqual([
|
|
115
|
+
['2026-08-01', '2026-08-01', '2026-08-31', 'invoiced'],
|
|
116
|
+
['2026-09-01', '2026-09-01', '2026-09-30', 'invoiced'],
|
|
117
|
+
['2026-10-01', '2026-10-01', '2026-10-31', 'invoiced'],
|
|
118
|
+
])
|
|
119
|
+
expect(new Set(cycles.map((c) => c.invoice_id)).size).toBe(3)
|
|
120
|
+
|
|
121
|
+
const invoices = await apiRequest(
|
|
122
|
+
request,
|
|
123
|
+
'GET',
|
|
124
|
+
`/api/billing/invoices?billAccountId=${accountId}&testRun=true`,
|
|
125
|
+
{ token },
|
|
126
|
+
)
|
|
127
|
+
const invoiceRows = ((await invoices.json()) as { items: unknown[] }).items
|
|
128
|
+
expect(invoiceRows).toHaveLength(3)
|
|
129
|
+
|
|
130
|
+
// Test mode never advances the account: a second dry run still sees 3 cycles.
|
|
131
|
+
const again = await runCycles(request, token, accountId, 'dry')
|
|
132
|
+
expect(again.cycles).toHaveLength(3)
|
|
133
|
+
})
|
|
134
|
+
})
|
|
@@ -0,0 +1,101 @@
|
|
|
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-006: Billing-owned invoice ledger (Spec 0)
|
|
7
|
+
* Category: BILL — API
|
|
8
|
+
* Priority: High
|
|
9
|
+
* Spec: .ai/specs/2026-11-14-billing-standalone-invoice-ledger.md
|
|
10
|
+
*
|
|
11
|
+
* 1. A real Bill Run for a fresh account writes a draft numbered `DRAFT-…`.
|
|
12
|
+
* 2. Posting assigns the series number (default mask `INV/{YYYY}/{MM}/{SEQUENCE_NUM_MONTH:4}`),
|
|
13
|
+
* status `posted`, outstanding = gross; a second post → 409.
|
|
14
|
+
* 3. The document lives in billing only — core sales never lists it.
|
|
15
|
+
*
|
|
16
|
+
* Self-contained: its own account + item, scoped run. Posted documents are
|
|
17
|
+
* immutable by design (no delete), so they stay in the test database.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
const uniq = () => Date.now().toString(36) + Math.random().toString(36).slice(2, 6)
|
|
21
|
+
|
|
22
|
+
type InvoiceRow = { id: string; number: string; status: string; total_gross: string; outstanding: string; document_type: string }
|
|
23
|
+
|
|
24
|
+
async function createBilledAccount(request: APIRequestContext, token: string): Promise<string> {
|
|
25
|
+
const account = await apiRequest(request, 'POST', '/api/billing/accounts', {
|
|
26
|
+
token,
|
|
27
|
+
data: {
|
|
28
|
+
customerId: `cust-${uniq()}`,
|
|
29
|
+
name: `Ledger ${uniq()}`,
|
|
30
|
+
currencyCode: 'PLN',
|
|
31
|
+
billCycle: 'monthly',
|
|
32
|
+
billCycleAnchor: '1',
|
|
33
|
+
invoiceEmail: `inv-${uniq()}@example.com`,
|
|
34
|
+
nextBillDate: '2026-10-01',
|
|
35
|
+
invoiceAddress: { line1: 'ul. Testowa 1', city: 'Warszawa', postal_code: '00-001', country: 'PL' },
|
|
36
|
+
},
|
|
37
|
+
})
|
|
38
|
+
expect(account.ok(), `POST account status was ${account.status()}`).toBeTruthy()
|
|
39
|
+
const accountId = ((await account.json()) as { id: string }).id
|
|
40
|
+
const item = await apiRequest(request, 'POST', '/api/billing/items', {
|
|
41
|
+
token,
|
|
42
|
+
data: {
|
|
43
|
+
billAccountId: accountId,
|
|
44
|
+
type: 'recurring',
|
|
45
|
+
billStartDate: '2026-10-01',
|
|
46
|
+
description: 'Internet 300',
|
|
47
|
+
rateJson: { unit_price: 79 },
|
|
48
|
+
},
|
|
49
|
+
})
|
|
50
|
+
expect(item.ok(), `POST item status was ${item.status()}`).toBeTruthy()
|
|
51
|
+
return accountId
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async function listInvoices(request: APIRequestContext, token: string, accountId: string): Promise<InvoiceRow[]> {
|
|
55
|
+
const res = await apiRequest(request, 'GET', `/api/billing/invoices?billAccountId=${accountId}&testRun=false`, { token })
|
|
56
|
+
expect(res.ok()).toBeTruthy()
|
|
57
|
+
return ((await res.json()) as { items: InvoiceRow[] }).items
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
test.describe('TC-BILL-006: billing-owned invoice ledger', () => {
|
|
61
|
+
let token: string
|
|
62
|
+
|
|
63
|
+
test.beforeAll(async ({ request }) => {
|
|
64
|
+
token = await getAuthToken(request, 'admin')
|
|
65
|
+
// Spec B: posting is blocked until the seller details are filled.
|
|
66
|
+
await ensureSellerSettings(request, token)
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
test('draft → post assigns the series number; the document never appears in core sales', async ({ request }) => {
|
|
70
|
+
const accountId = await createBilledAccount(request, token)
|
|
71
|
+
|
|
72
|
+
const run = await apiRequest(request, 'POST', '/api/billing/runs', {
|
|
73
|
+
token,
|
|
74
|
+
data: { mode: 'real', asOfDate: '2026-10-15', scopedAccountIds: [accountId] },
|
|
75
|
+
})
|
|
76
|
+
expect(run.ok(), `POST run status was ${run.status()}`).toBeTruthy()
|
|
77
|
+
|
|
78
|
+
const [draft] = await listInvoices(request, token, accountId)
|
|
79
|
+
expect(draft).toMatchObject({ status: 'draft', document_type: 'invoice' })
|
|
80
|
+
expect(draft.number).toMatch(/^DRAFT-/)
|
|
81
|
+
|
|
82
|
+
const post = await apiRequest(request, 'POST', '/api/billing/invoices/post', { token, data: { invoiceId: draft.id } })
|
|
83
|
+
expect(post.ok(), `POST post status was ${post.status()}`).toBeTruthy()
|
|
84
|
+
const posted = (await post.json()) as { invoiceNumber: string; status: string }
|
|
85
|
+
expect(posted.status).toBe('posted')
|
|
86
|
+
expect(posted.invoiceNumber).toMatch(/^INV\/\d{4}\/\d{2}\/\d{4}$/)
|
|
87
|
+
|
|
88
|
+
const [after] = await listInvoices(request, token, accountId)
|
|
89
|
+
expect(after).toMatchObject({ id: draft.id, status: 'posted', number: posted.invoiceNumber })
|
|
90
|
+
expect(after.outstanding).toBe(after.total_gross)
|
|
91
|
+
|
|
92
|
+
const again = await apiRequest(request, 'POST', '/api/billing/invoices/post', { token, data: { invoiceId: draft.id } })
|
|
93
|
+
expect(again.status()).toBe(409)
|
|
94
|
+
|
|
95
|
+
const sales = await apiRequest(request, 'GET', `/api/sales/invoices?search=${encodeURIComponent(posted.invoiceNumber)}`, { token })
|
|
96
|
+
if (sales.ok()) {
|
|
97
|
+
const salesItems = ((await sales.json()) as { items?: Array<{ id: string }> }).items ?? []
|
|
98
|
+
expect(salesItems.some((row) => row.id === draft.id)).toBe(false)
|
|
99
|
+
}
|
|
100
|
+
})
|
|
101
|
+
})
|
|
@@ -0,0 +1,140 @@
|
|
|
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-007: Invoice documents — VAT, due date, PDF (Spec B)
|
|
7
|
+
* Category: BILL — API
|
|
8
|
+
* Priority: High
|
|
9
|
+
* Spec: .ai/specs/2026-11-14-billing-invoice-documents.md
|
|
10
|
+
*
|
|
11
|
+
* 1. Items carry VAT rates (23 % explicit, 0 % explicit) → the draft has
|
|
12
|
+
* per-line VAT and totals = Σ lines.
|
|
13
|
+
* 2. The draft PDF renders (watermarked preview) before posting.
|
|
14
|
+
* 3. Posting sets due date = issue date + the account's terms (7 days) and
|
|
15
|
+
* freezes the PDF; the list exposes due_date / days_overdue.
|
|
16
|
+
* 4. The account summary counts the posted invoice as open, not overdue.
|
|
17
|
+
*
|
|
18
|
+
* Self-contained: own account + items, scoped run. Posted documents are
|
|
19
|
+
* immutable by design, so they stay in the test database.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
const uniq = () => Date.now().toString(36) + Math.random().toString(36).slice(2, 6)
|
|
23
|
+
|
|
24
|
+
type InvoiceRow = {
|
|
25
|
+
id: string
|
|
26
|
+
number: string
|
|
27
|
+
status: string
|
|
28
|
+
subtotal_net: string
|
|
29
|
+
tax_total: string
|
|
30
|
+
total_gross: string
|
|
31
|
+
issue_date: string | null
|
|
32
|
+
due_date: string | null
|
|
33
|
+
days_overdue: number
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async function createAccountWithVatItems(request: APIRequestContext, token: string): Promise<string> {
|
|
37
|
+
const account = await apiRequest(request, 'POST', '/api/billing/accounts', {
|
|
38
|
+
token,
|
|
39
|
+
data: {
|
|
40
|
+
customerId: `cust-${uniq()}`,
|
|
41
|
+
name: `VAT ${uniq()}`,
|
|
42
|
+
currencyCode: 'PLN',
|
|
43
|
+
billCycle: 'monthly',
|
|
44
|
+
billCycleAnchor: '1',
|
|
45
|
+
invoiceEmail: `vat-${uniq()}@example.com`,
|
|
46
|
+
invoiceLanguage: 'pl',
|
|
47
|
+
nextBillDate: '2026-10-01',
|
|
48
|
+
paymentTermsDays: 7,
|
|
49
|
+
invoiceAddress: { line1: 'ul. Kupującego 1', city: 'Warszawa', postal_code: '00-001', country: 'PL' },
|
|
50
|
+
},
|
|
51
|
+
})
|
|
52
|
+
expect(account.ok(), `POST account status was ${account.status()}`).toBeTruthy()
|
|
53
|
+
const accountId = ((await account.json()) as { id: string }).id
|
|
54
|
+
for (const [description, unitPrice, taxRate] of [
|
|
55
|
+
['Internet 300', 100, 23],
|
|
56
|
+
['Usługa zwolniona', 15, 0],
|
|
57
|
+
] as const) {
|
|
58
|
+
const item = await apiRequest(request, 'POST', '/api/billing/items', {
|
|
59
|
+
token,
|
|
60
|
+
data: {
|
|
61
|
+
billAccountId: accountId,
|
|
62
|
+
type: 'recurring',
|
|
63
|
+
billStartDate: '2026-10-01',
|
|
64
|
+
description,
|
|
65
|
+
rateJson: { unit_price: unitPrice },
|
|
66
|
+
taxRate,
|
|
67
|
+
},
|
|
68
|
+
})
|
|
69
|
+
expect(item.ok(), `POST item status was ${item.status()}`).toBeTruthy()
|
|
70
|
+
}
|
|
71
|
+
return accountId
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async function listInvoices(request: APIRequestContext, token: string, accountId: string): Promise<InvoiceRow[]> {
|
|
75
|
+
const res = await apiRequest(request, 'GET', `/api/billing/invoices?billAccountId=${accountId}&testRun=false`, { token })
|
|
76
|
+
expect(res.ok()).toBeTruthy()
|
|
77
|
+
return ((await res.json()) as { items: InvoiceRow[] }).items
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
test.describe('TC-BILL-007: VAT, due date and PDF', () => {
|
|
81
|
+
let token: string
|
|
82
|
+
|
|
83
|
+
test.beforeAll(async ({ request }) => {
|
|
84
|
+
token = await getAuthToken(request, 'admin')
|
|
85
|
+
await ensureSellerSettings(request, token)
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
test('VAT per line, draft PDF preview, due date and frozen PDF at post', async ({ request }) => {
|
|
89
|
+
const accountId = await createAccountWithVatItems(request, token)
|
|
90
|
+
const run = await apiRequest(request, 'POST', '/api/billing/runs', {
|
|
91
|
+
token,
|
|
92
|
+
data: { mode: 'real', asOfDate: '2026-10-15', scopedAccountIds: [accountId] },
|
|
93
|
+
})
|
|
94
|
+
expect(run.ok(), `POST run status was ${run.status()}`).toBeTruthy()
|
|
95
|
+
|
|
96
|
+
const [draft] = await listInvoices(request, token, accountId)
|
|
97
|
+
expect(draft).toMatchObject({ status: 'draft' })
|
|
98
|
+
// 100 @ 23 % + 15 @ 0 %
|
|
99
|
+
expect(Number(draft.subtotal_net)).toBeCloseTo(115, 2)
|
|
100
|
+
expect(Number(draft.tax_total)).toBeCloseTo(23, 2)
|
|
101
|
+
expect(Number(draft.total_gross)).toBeCloseTo(138, 2)
|
|
102
|
+
|
|
103
|
+
const detail = await apiRequest(request, 'GET', `/api/billing/invoices/${draft.id}`, { token })
|
|
104
|
+
const { lines } = (await detail.json()) as { lines: Array<{ tax_rate: string; tax_amount: string }> }
|
|
105
|
+
expect(lines.map((l) => Number(l.tax_rate)).sort((a, b) => a - b)).toEqual([0, 23])
|
|
106
|
+
|
|
107
|
+
const preview = await apiRequest(request, 'GET', `/api/billing/invoices/${draft.id}/pdf`, { token })
|
|
108
|
+
expect(preview.status()).toBe(200)
|
|
109
|
+
expect(preview.headers()['content-type']).toContain('application/pdf')
|
|
110
|
+
expect((await preview.body()).subarray(0, 4).toString()).toBe('%PDF')
|
|
111
|
+
|
|
112
|
+
const post = await apiRequest(request, 'POST', '/api/billing/invoices/post', { token, data: { invoiceId: draft.id } })
|
|
113
|
+
expect(post.ok(), `POST post status was ${post.status()}`).toBeTruthy()
|
|
114
|
+
|
|
115
|
+
const [posted] = await listInvoices(request, token, accountId)
|
|
116
|
+
expect(posted.status).toBe('posted')
|
|
117
|
+
const issue = new Date(`${posted.issue_date!.slice(0, 10)}T00:00:00Z`)
|
|
118
|
+
const due = new Date(`${posted.due_date!.slice(0, 10)}T00:00:00Z`)
|
|
119
|
+
expect((due.getTime() - issue.getTime()) / 86_400_000).toBe(7)
|
|
120
|
+
expect(posted.days_overdue).toBe(0)
|
|
121
|
+
|
|
122
|
+
const frozen = await apiRequest(request, 'GET', `/api/billing/invoices/${draft.id}/pdf?download=1`, { token })
|
|
123
|
+
expect(frozen.status()).toBe(200)
|
|
124
|
+
expect(frozen.headers()['content-disposition']).toContain('attachment')
|
|
125
|
+
|
|
126
|
+
const summary = await apiRequest(request, 'GET', `/api/billing/accounts/${accountId}/summary`, { token })
|
|
127
|
+
expect(summary.ok()).toBeTruthy()
|
|
128
|
+
const body = (await summary.json()) as { open_amount: string; overdue_count: number }
|
|
129
|
+
expect(Number(body.open_amount)).toBeCloseTo(138, 2)
|
|
130
|
+
expect(body.overdue_count).toBe(0)
|
|
131
|
+
|
|
132
|
+
const overdueOnly = await apiRequest(
|
|
133
|
+
request,
|
|
134
|
+
'GET',
|
|
135
|
+
`/api/billing/invoices?billAccountId=${accountId}&overdue=true`,
|
|
136
|
+
{ token },
|
|
137
|
+
)
|
|
138
|
+
expect(((await overdueOnly.json()) as { items: unknown[] }).items).toHaveLength(0)
|
|
139
|
+
})
|
|
140
|
+
})
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { readFileSync, existsSync } from 'node:fs'
|
|
2
|
+
import { tmpdir } from 'node:os'
|
|
3
|
+
import { join } from 'node:path'
|
|
4
|
+
import { test, expect, type APIRequestContext } from '@playwright/test'
|
|
5
|
+
import { getAuthToken, apiRequest } from '@open-mercato/core/helpers/integration/api'
|
|
6
|
+
import { ensureSellerSettings } from './sellerSettings'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* TC-BILL-008: Sending invoices by email (Spec B)
|
|
10
|
+
* Category: BILL — API
|
|
11
|
+
* Priority: High
|
|
12
|
+
* Spec: .ai/specs/2026-11-14-billing-invoice-documents.md
|
|
13
|
+
*
|
|
14
|
+
* 1. A draft cannot be sent (409 billing.invoice.not_posted).
|
|
15
|
+
* 2. A posted invoice is sent through the platform `sendEmail()`; with
|
|
16
|
+
* `OM_TEST_MODE` the message is captured (recipient + subject) and the
|
|
17
|
+
* attempt is logged in `metadata.deliveries`.
|
|
18
|
+
* 3. A placeholder address (`@invalid.local`) is refused with 422.
|
|
19
|
+
*
|
|
20
|
+
* Delivery status may be `sent` or `failed` depending on whether the test
|
|
21
|
+
* instance has an outbound transport; either way exactly one attempt is
|
|
22
|
+
* logged. The capture-file assertion runs only when the server shares this
|
|
23
|
+
* machine's temp dir (local runs).
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
const uniq = () => Date.now().toString(36) + Math.random().toString(36).slice(2, 6)
|
|
27
|
+
const capturePath = process.env.OM_TEST_EMAIL_CAPTURE_PATH?.trim() || join(tmpdir(), 'open-mercato-email-capture.jsonl')
|
|
28
|
+
|
|
29
|
+
async function postedInvoiceFor(request: APIRequestContext, token: string, invoiceEmail: string) {
|
|
30
|
+
const account = await apiRequest(request, 'POST', '/api/billing/accounts', {
|
|
31
|
+
token,
|
|
32
|
+
data: {
|
|
33
|
+
customerId: `cust-${uniq()}`,
|
|
34
|
+
name: `Send ${uniq()}`,
|
|
35
|
+
currencyCode: 'PLN',
|
|
36
|
+
billCycle: 'monthly',
|
|
37
|
+
billCycleAnchor: '1',
|
|
38
|
+
invoiceEmail,
|
|
39
|
+
nextBillDate: '2026-10-01',
|
|
40
|
+
invoiceAddress: { line1: 'ul. Testowa 1', city: 'Warszawa', postal_code: '00-001', country: 'PL' },
|
|
41
|
+
},
|
|
42
|
+
})
|
|
43
|
+
expect(account.ok(), `POST account status was ${account.status()}`).toBeTruthy()
|
|
44
|
+
const accountId = ((await account.json()) as { id: string }).id
|
|
45
|
+
const item = await apiRequest(request, 'POST', '/api/billing/items', {
|
|
46
|
+
token,
|
|
47
|
+
data: { billAccountId: accountId, type: 'recurring', billStartDate: '2026-10-01', description: 'Plan', rateJson: { unit_price: 50 } },
|
|
48
|
+
})
|
|
49
|
+
expect(item.ok()).toBeTruthy()
|
|
50
|
+
const run = await apiRequest(request, 'POST', '/api/billing/runs', {
|
|
51
|
+
token,
|
|
52
|
+
data: { mode: 'real', asOfDate: '2026-10-15', scopedAccountIds: [accountId] },
|
|
53
|
+
})
|
|
54
|
+
expect(run.ok()).toBeTruthy()
|
|
55
|
+
const list = await apiRequest(request, 'GET', `/api/billing/invoices?billAccountId=${accountId}&testRun=false`, { token })
|
|
56
|
+
const [draft] = ((await list.json()) as { items: Array<{ id: string }> }).items
|
|
57
|
+
return { accountId, invoiceId: draft.id }
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
test.describe('TC-BILL-008: send invoice by email', () => {
|
|
61
|
+
let token: string
|
|
62
|
+
|
|
63
|
+
test.beforeAll(async ({ request }) => {
|
|
64
|
+
token = await getAuthToken(request, 'admin')
|
|
65
|
+
await ensureSellerSettings(request, token)
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
test('draft refused; posted invoice sent and logged', async ({ request }) => {
|
|
69
|
+
const email = `send-${uniq()}@example.com`
|
|
70
|
+
const { invoiceId } = await postedInvoiceFor(request, token, email)
|
|
71
|
+
|
|
72
|
+
const early = await apiRequest(request, 'POST', `/api/billing/invoices/${invoiceId}/send`, { token, data: {} })
|
|
73
|
+
expect(early.status()).toBe(409)
|
|
74
|
+
|
|
75
|
+
const post = await apiRequest(request, 'POST', '/api/billing/invoices/post', { token, data: { invoiceId } })
|
|
76
|
+
expect(post.ok()).toBeTruthy()
|
|
77
|
+
const { invoiceNumber } = (await post.json()) as { invoiceNumber: string }
|
|
78
|
+
|
|
79
|
+
const send = await apiRequest(request, 'POST', `/api/billing/invoices/${invoiceId}/send`, { token, data: {} })
|
|
80
|
+
expect(send.status()).toBe(200)
|
|
81
|
+
const result = (await send.json()) as { to: string; status: 'sent' | 'failed' }
|
|
82
|
+
expect(result.to).toBe(email)
|
|
83
|
+
expect(['sent', 'failed']).toContain(result.status)
|
|
84
|
+
|
|
85
|
+
const detail = await apiRequest(request, 'GET', `/api/billing/invoices/${invoiceId}`, { token })
|
|
86
|
+
const { invoice } = (await detail.json()) as {
|
|
87
|
+
invoice: { metadata: { deliveries?: Array<{ to: string; status: string; trigger: string }> } }
|
|
88
|
+
}
|
|
89
|
+
expect(invoice.metadata.deliveries).toEqual([expect.objectContaining({ to: email, trigger: 'manual', status: result.status })])
|
|
90
|
+
|
|
91
|
+
if (existsSync(capturePath)) {
|
|
92
|
+
const captured = readFileSync(capturePath, 'utf8')
|
|
93
|
+
.split('\n')
|
|
94
|
+
.filter(Boolean)
|
|
95
|
+
.map((line) => JSON.parse(line) as { to: string; subject: string })
|
|
96
|
+
expect(captured.some((m) => m.to === email && m.subject.includes(invoiceNumber))).toBe(true)
|
|
97
|
+
}
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
test('placeholder address is refused with 422', async ({ request }) => {
|
|
101
|
+
const { invoiceId } = await postedInvoiceFor(request, token, `shell-${uniq()}@invalid.local`)
|
|
102
|
+
const post = await apiRequest(request, 'POST', '/api/billing/invoices/post', { token, data: { invoiceId } })
|
|
103
|
+
expect(post.ok()).toBeTruthy()
|
|
104
|
+
const send = await apiRequest(request, 'POST', `/api/billing/invoices/${invoiceId}/send`, { token, data: {} })
|
|
105
|
+
expect(send.status()).toBe(422)
|
|
106
|
+
expect(((await send.json()) as { code: string }).code).toBe('billing.invoice.email_invalid')
|
|
107
|
+
})
|
|
108
|
+
})
|