@dainamite/billing 0.20.0 → 0.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +103 -0
- package/dist/modules/billing/acl.js +13 -1
- package/dist/modules/billing/acl.js.map +2 -2
- package/dist/modules/billing/api/accounts/[id]/summary/route.js +52 -0
- package/dist/modules/billing/api/accounts/[id]/summary/route.js.map +7 -0
- package/dist/modules/billing/api/accounts/route.js +47 -4
- package/dist/modules/billing/api/accounts/route.js.map +2 -2
- package/dist/modules/billing/api/export/account/[id]/route.js +11 -7
- package/dist/modules/billing/api/export/account/[id]/route.js.map +2 -2
- package/dist/modules/billing/api/invoices/[id]/memos/route.js +54 -0
- package/dist/modules/billing/api/invoices/[id]/memos/route.js.map +7 -0
- package/dist/modules/billing/api/invoices/[id]/pdf/route.js +70 -0
- package/dist/modules/billing/api/invoices/[id]/pdf/route.js.map +7 -0
- package/dist/modules/billing/api/invoices/[id]/route.js +44 -24
- package/dist/modules/billing/api/invoices/[id]/route.js.map +2 -2
- package/dist/modules/billing/api/invoices/[id]/send/route.js +107 -0
- package/dist/modules/billing/api/invoices/[id]/send/route.js.map +7 -0
- package/dist/modules/billing/api/invoices/add-line/route.js +2 -2
- package/dist/modules/billing/api/invoices/add-line/route.js.map +2 -2
- package/dist/modules/billing/api/invoices/delete-draft/route.js +33 -0
- package/dist/modules/billing/api/invoices/delete-draft/route.js.map +7 -0
- package/dist/modules/billing/api/invoices/edit-line/route.js +2 -2
- package/dist/modules/billing/api/invoices/edit-line/route.js.map +2 -2
- package/dist/modules/billing/api/invoices/post/route.js +2 -2
- package/dist/modules/billing/api/invoices/post/route.js.map +2 -2
- package/dist/modules/billing/api/invoices/remove-line/route.js +2 -2
- package/dist/modules/billing/api/invoices/remove-line/route.js.map +2 -2
- package/dist/modules/billing/api/invoices/route.js +45 -46
- package/dist/modules/billing/api/invoices/route.js.map +2 -2
- package/dist/modules/billing/api/items/bulk/route.js +1 -1
- package/dist/modules/billing/api/items/bulk/route.js.map +2 -2
- package/dist/modules/billing/api/items/change-price/route.js +44 -0
- package/dist/modules/billing/api/items/change-price/route.js.map +7 -0
- package/dist/modules/billing/api/items/route.js +19 -7
- package/dist/modules/billing/api/items/route.js.map +2 -2
- package/dist/modules/billing/api/payment-imports/[id]/route.js +49 -0
- package/dist/modules/billing/api/payment-imports/[id]/route.js.map +7 -0
- package/dist/modules/billing/api/payment-imports/route.js +57 -0
- package/dist/modules/billing/api/payment-imports/route.js.map +7 -0
- package/dist/modules/billing/api/payments/[id]/route.js +60 -0
- package/dist/modules/billing/api/payments/[id]/route.js.map +7 -0
- package/dist/modules/billing/api/payments/allocate/route.js +35 -0
- package/dist/modules/billing/api/payments/allocate/route.js.map +7 -0
- package/dist/modules/billing/api/payments/assign/route.js +36 -0
- package/dist/modules/billing/api/payments/assign/route.js.map +7 -0
- package/dist/modules/billing/api/payments/convert-to-topup/route.js +35 -0
- package/dist/modules/billing/api/payments/convert-to-topup/route.js.map +7 -0
- package/dist/modules/billing/api/payments/ignore/route.js +35 -0
- package/dist/modules/billing/api/payments/ignore/route.js.map +7 -0
- package/dist/modules/billing/api/payments/import/route.js +63 -0
- package/dist/modules/billing/api/payments/import/route.js.map +7 -0
- package/dist/modules/billing/api/payments/restore/route.js +35 -0
- package/dist/modules/billing/api/payments/restore/route.js.map +7 -0
- package/dist/modules/billing/api/payments/route.js +114 -0
- package/dist/modules/billing/api/payments/route.js.map +7 -0
- package/dist/modules/billing/api/payments/unallocate/route.js +35 -0
- package/dist/modules/billing/api/payments/unallocate/route.js.map +7 -0
- package/dist/modules/billing/api/payments/unassign/route.js +35 -0
- package/dist/modules/billing/api/payments/unassign/route.js.map +7 -0
- package/dist/modules/billing/api/run-outcomes/route.js +43 -6
- package/dist/modules/billing/api/run-outcomes/route.js.map +2 -2
- package/dist/modules/billing/api/runs/[id]/post-drafts/route.js +61 -0
- package/dist/modules/billing/api/runs/[id]/post-drafts/route.js.map +7 -0
- package/dist/modules/billing/api/runs/[id]/route.js +53 -0
- package/dist/modules/billing/api/runs/[id]/route.js.map +7 -0
- package/dist/modules/billing/api/runs/retry-failed/route.js +1 -1
- package/dist/modules/billing/api/runs/retry-failed/route.js.map +2 -2
- package/dist/modules/billing/api/runs/route.js +9 -3
- package/dist/modules/billing/api/runs/route.js.map +2 -2
- package/dist/modules/billing/api/settings/number-preview/route.js +42 -0
- package/dist/modules/billing/api/settings/number-preview/route.js.map +7 -0
- package/dist/modules/billing/api/settings/route.js +92 -0
- package/dist/modules/billing/api/settings/route.js.map +7 -0
- package/dist/modules/billing/api/statements/route.js +3 -0
- package/dist/modules/billing/api/statements/route.js.map +2 -2
- package/dist/modules/billing/api/test-invoices/wipe/route.js +2 -2
- package/dist/modules/billing/api/test-invoices/wipe/route.js.map +2 -2
- package/dist/modules/billing/backend/billing/accounts/[id]/page.js +121 -232
- package/dist/modules/billing/backend/billing/accounts/[id]/page.js.map +2 -2
- package/dist/modules/billing/backend/billing/accounts/create/page.js +6 -0
- package/dist/modules/billing/backend/billing/accounts/create/page.js.map +2 -2
- package/dist/modules/billing/backend/billing/accounts/page.js +63 -4
- package/dist/modules/billing/backend/billing/accounts/page.js.map +2 -2
- package/dist/modules/billing/backend/billing/invoices/[id]/page.js +297 -65
- package/dist/modules/billing/backend/billing/invoices/[id]/page.js.map +3 -3
- package/dist/modules/billing/backend/billing/invoices/page.js +6 -172
- package/dist/modules/billing/backend/billing/invoices/page.js.map +2 -2
- package/dist/modules/billing/backend/billing/items/[id]/page.js +51 -7
- package/dist/modules/billing/backend/billing/items/[id]/page.js.map +2 -2
- package/dist/modules/billing/backend/billing/items/create/page.js +9 -6
- package/dist/modules/billing/backend/billing/items/create/page.js.map +2 -2
- package/dist/modules/billing/backend/billing/items/page.js +8 -2
- package/dist/modules/billing/backend/billing/items/page.js.map +2 -2
- package/dist/modules/billing/backend/billing/payments/[id]/page.js +297 -0
- package/dist/modules/billing/backend/billing/payments/[id]/page.js.map +7 -0
- package/dist/modules/billing/backend/billing/payments/[id]/page.meta.js +21 -0
- package/dist/modules/billing/backend/billing/payments/[id]/page.meta.js.map +7 -0
- package/dist/modules/billing/backend/billing/payments/imports/[id]/page.js +74 -0
- package/dist/modules/billing/backend/billing/payments/imports/[id]/page.js.map +7 -0
- package/dist/modules/billing/backend/billing/payments/imports/[id]/page.meta.js +21 -0
- package/dist/modules/billing/backend/billing/payments/imports/[id]/page.meta.js.map +7 -0
- package/dist/modules/billing/backend/billing/payments/page.js +58 -0
- package/dist/modules/billing/backend/billing/payments/page.js.map +7 -0
- package/dist/modules/billing/backend/billing/payments/page.meta.js +18 -0
- package/dist/modules/billing/backend/billing/payments/page.meta.js.map +7 -0
- package/dist/modules/billing/backend/billing/runs/[id]/page.js +49 -14
- package/dist/modules/billing/backend/billing/runs/[id]/page.js.map +2 -2
- package/dist/modules/billing/backend/billing/runs/page.js +58 -7
- package/dist/modules/billing/backend/billing/runs/page.js.map +2 -2
- package/dist/modules/billing/backend/billing/statements/[id]/page.js +61 -6
- package/dist/modules/billing/backend/billing/statements/[id]/page.js.map +2 -2
- package/dist/modules/billing/backend/billing/statements/page.js +1 -1
- package/dist/modules/billing/backend/billing/statements/page.js.map +2 -2
- package/dist/modules/billing/backend/billing/topups/page.js +1 -1
- package/dist/modules/billing/backend/billing/topups/page.js.map +2 -2
- package/dist/modules/billing/backend/billing/transactions/page.js +1 -1
- package/dist/modules/billing/backend/billing/transactions/page.js.map +2 -2
- package/dist/modules/billing/backend/billing/usage/create/page.js +3 -2
- package/dist/modules/billing/backend/billing/usage/create/page.js.map +2 -2
- package/dist/modules/billing/backend/config/billing/page.js +472 -0
- package/dist/modules/billing/backend/config/billing/page.js.map +7 -0
- package/dist/modules/billing/backend/config/billing/page.meta.js +19 -0
- package/dist/modules/billing/backend/config/billing/page.meta.js.map +7 -0
- package/dist/modules/billing/cli.js +22 -1
- package/dist/modules/billing/cli.js.map +2 -2
- package/dist/modules/billing/commands/accounts.js +6 -0
- package/dist/modules/billing/commands/accounts.js.map +2 -2
- package/dist/modules/billing/commands/index.js +3 -0
- package/dist/modules/billing/commands/index.js.map +2 -2
- package/dist/modules/billing/commands/invoices.js +269 -167
- package/dist/modules/billing/commands/invoices.js.map +2 -2
- package/dist/modules/billing/commands/items.js +108 -0
- package/dist/modules/billing/commands/items.js.map +2 -2
- package/dist/modules/billing/commands/memos.js +179 -0
- package/dist/modules/billing/commands/memos.js.map +7 -0
- package/dist/modules/billing/commands/payments.js +379 -0
- package/dist/modules/billing/commands/payments.js.map +7 -0
- package/dist/modules/billing/commands/runs.js +151 -4
- package/dist/modules/billing/commands/runs.js.map +2 -2
- package/dist/modules/billing/commands/settings.js +59 -0
- package/dist/modules/billing/commands/settings.js.map +7 -0
- package/dist/modules/billing/commands/topups.js +9 -2
- package/dist/modules/billing/commands/topups.js.map +2 -2
- package/dist/modules/billing/commands/transactions.js +2 -2
- package/dist/modules/billing/commands/transactions.js.map +2 -2
- package/dist/modules/billing/components/AccountForm.js +149 -42
- package/dist/modules/billing/components/AccountForm.js.map +2 -2
- package/dist/modules/billing/components/AccountInvoicesSection.js +64 -0
- package/dist/modules/billing/components/AccountInvoicesSection.js.map +7 -0
- package/dist/modules/billing/components/AccountPaymentsSection.js +43 -0
- package/dist/modules/billing/components/AccountPaymentsSection.js.map +7 -0
- package/dist/modules/billing/components/AccountPicker.js +56 -0
- package/dist/modules/billing/components/AccountPicker.js.map +7 -0
- package/dist/modules/billing/components/AllocatePaymentDialog.js +134 -0
- package/dist/modules/billing/components/AllocatePaymentDialog.js.map +7 -0
- package/dist/modules/billing/components/BillingDataTable.js +21 -0
- package/dist/modules/billing/components/BillingDataTable.js.map +7 -0
- package/dist/modules/billing/components/BillingSettingsLink.js +19 -0
- package/dist/modules/billing/components/BillingSettingsLink.js.map +7 -0
- package/dist/modules/billing/components/ChangeItemPriceDialog.js +158 -0
- package/dist/modules/billing/components/ChangeItemPriceDialog.js.map +7 -0
- package/dist/modules/billing/components/CreateMemoDialog.js +200 -0
- package/dist/modules/billing/components/CreateMemoDialog.js.map +7 -0
- package/dist/modules/billing/components/CustomerLabel.js +33 -0
- package/dist/modules/billing/components/CustomerLabel.js.map +7 -0
- package/dist/modules/billing/components/InvoicesTable.js +270 -0
- package/dist/modules/billing/components/InvoicesTable.js.map +7 -0
- package/dist/modules/billing/components/ItemForm.js +176 -44
- package/dist/modules/billing/components/ItemForm.js.map +2 -2
- package/dist/modules/billing/components/ItemPriceField.js +46 -0
- package/dist/modules/billing/components/ItemPriceField.js.map +7 -0
- package/dist/modules/billing/components/LineFormDialog.js +25 -2
- package/dist/modules/billing/components/LineFormDialog.js.map +2 -2
- package/dist/modules/billing/components/ManualPaymentDialog.js +122 -0
- package/dist/modules/billing/components/ManualPaymentDialog.js.map +7 -0
- package/dist/modules/billing/components/MoneyInput.js +14 -0
- package/dist/modules/billing/components/MoneyInput.js.map +7 -0
- package/dist/modules/billing/components/PaymentUploadDialog.js +115 -0
- package/dist/modules/billing/components/PaymentUploadDialog.js.map +7 -0
- package/dist/modules/billing/components/PaymentsTable.js +171 -0
- package/dist/modules/billing/components/PaymentsTable.js.map +7 -0
- package/dist/modules/billing/components/PostRunDraftsButton.js +105 -0
- package/dist/modules/billing/components/PostRunDraftsButton.js.map +7 -0
- package/dist/modules/billing/components/PrepaidPanel.js +14 -4
- package/dist/modules/billing/components/PrepaidPanel.js.map +2 -2
- package/dist/modules/billing/components/RunCyclesSection.js +209 -0
- package/dist/modules/billing/components/RunCyclesSection.js.map +7 -0
- package/dist/modules/billing/components/TestRunActions.js +127 -0
- package/dist/modules/billing/components/TestRunActions.js.map +7 -0
- package/dist/modules/billing/components/account/AccountItemsTab.js +157 -0
- package/dist/modules/billing/components/account/AccountItemsTab.js.map +7 -0
- package/dist/modules/billing/components/account/AccountRunBillingDialog.js +122 -0
- package/dist/modules/billing/components/account/AccountRunBillingDialog.js.map +7 -0
- package/dist/modules/billing/components/account/AccountRunsTab.js +152 -0
- package/dist/modules/billing/components/account/AccountRunsTab.js.map +7 -0
- package/dist/modules/billing/components/account/AccountStatementsTab.js +98 -0
- package/dist/modules/billing/components/account/AccountStatementsTab.js.map +7 -0
- package/dist/modules/billing/components/account/AccountSummaryCards.js +125 -0
- package/dist/modules/billing/components/account/AccountSummaryCards.js.map +7 -0
- package/dist/modules/billing/components/account/AccountUsageTab.js +91 -0
- package/dist/modules/billing/components/account/AccountUsageTab.js.map +7 -0
- package/dist/modules/billing/components/account/AccountView.js +73 -0
- package/dist/modules/billing/components/account/AccountView.js.map +7 -0
- package/dist/modules/billing/components/account/accountRow.js +39 -0
- package/dist/modules/billing/components/account/accountRow.js.map +7 -0
- package/dist/modules/billing/components/customerNames.js +42 -0
- package/dist/modules/billing/components/customerNames.js.map +7 -0
- package/dist/modules/billing/data/entities.js +560 -4
- package/dist/modules/billing/data/entities.js.map +2 -2
- package/dist/modules/billing/data/entityIds.js +10 -1
- package/dist/modules/billing/data/entityIds.js.map +2 -2
- package/dist/modules/billing/data/validators.js +269 -15
- package/dist/modules/billing/data/validators.js.map +2 -2
- package/dist/modules/billing/events.js +50 -0
- package/dist/modules/billing/events.js.map +2 -2
- package/dist/modules/billing/i18n/de.json +880 -0
- package/dist/modules/billing/i18n/en.json +457 -21
- package/dist/modules/billing/i18n/es.json +880 -0
- package/dist/modules/billing/i18n/pl.json +458 -22
- package/dist/modules/billing/index.js +6 -2
- package/dist/modules/billing/index.js.map +2 -2
- package/dist/modules/billing/lib/accountFinancials.js +58 -0
- package/dist/modules/billing/lib/accountFinancials.js.map +7 -0
- package/dist/modules/billing/lib/accountLock.js +14 -0
- package/dist/modules/billing/lib/accountLock.js.map +7 -0
- package/dist/modules/billing/lib/accountStatus.js +9 -7
- package/dist/modules/billing/lib/accountStatus.js.map +2 -2
- package/dist/modules/billing/lib/accountSummary.js +106 -0
- package/dist/modules/billing/lib/accountSummary.js.map +7 -0
- package/dist/modules/billing/lib/allocation.js +356 -0
- package/dist/modules/billing/lib/allocation.js.map +7 -0
- package/dist/modules/billing/lib/allocationEvents.js +22 -0
- package/dist/modules/billing/lib/allocationEvents.js.map +7 -0
- package/dist/modules/billing/lib/billPeriod.js +15 -1
- package/dist/modules/billing/lib/billPeriod.js.map +2 -2
- package/dist/modules/billing/lib/billRunEngine.js +237 -102
- package/dist/modules/billing/lib/billRunEngine.js.map +2 -2
- package/dist/modules/billing/lib/billingSettings.js +116 -0
- package/dist/modules/billing/lib/billingSettings.js.map +7 -0
- package/dist/modules/billing/lib/commandRoute.js +81 -0
- package/dist/modules/billing/lib/commandRoute.js.map +7 -0
- package/dist/modules/billing/lib/customerLookup.js +97 -0
- package/dist/modules/billing/lib/customerLookup.js.map +7 -0
- package/dist/modules/billing/lib/dateOnly.js +13 -0
- package/dist/modules/billing/lib/dateOnly.js.map +7 -0
- package/dist/modules/billing/lib/documentParties.js +16 -0
- package/dist/modules/billing/lib/documentParties.js.map +7 -0
- package/dist/modules/billing/lib/documentTypes.js +27 -0
- package/dist/modules/billing/lib/documentTypes.js.map +7 -0
- package/dist/modules/billing/lib/dueDate.js +18 -0
- package/dist/modules/billing/lib/dueDate.js.map +7 -0
- package/dist/modules/billing/lib/iban.js +29 -0
- package/dist/modules/billing/lib/iban.js.map +7 -0
- package/dist/modules/billing/lib/invoiceDelivery.js +133 -0
- package/dist/modules/billing/lib/invoiceDelivery.js.map +7 -0
- package/dist/modules/billing/lib/invoiceLanguages.js +28 -0
- package/dist/modules/billing/lib/invoiceLanguages.js.map +7 -0
- package/dist/modules/billing/lib/invoiceWriter.js +107 -99
- package/dist/modules/billing/lib/invoiceWriter.js.map +2 -2
- package/dist/modules/billing/lib/itemBillingState.js +27 -0
- package/dist/modules/billing/lib/itemBillingState.js.map +7 -0
- package/dist/modules/billing/lib/itemPriceChange.js +18 -0
- package/dist/modules/billing/lib/itemPriceChange.js.map +7 -0
- package/dist/modules/billing/lib/itemSelector.js.map +2 -2
- package/dist/modules/billing/lib/lineAmounts.js +32 -0
- package/dist/modules/billing/lib/lineAmounts.js.map +7 -0
- package/dist/modules/billing/lib/memoGuards.js +25 -0
- package/dist/modules/billing/lib/memoGuards.js.map +7 -0
- package/dist/modules/billing/lib/navigation.js +48 -0
- package/dist/modules/billing/lib/navigation.js.map +7 -0
- package/dist/modules/billing/lib/numbering.js +120 -0
- package/dist/modules/billing/lib/numbering.js.map +7 -0
- package/dist/modules/billing/lib/overdue.js +36 -0
- package/dist/modules/billing/lib/overdue.js.map +7 -0
- package/dist/modules/billing/lib/paymentCsv.js +125 -0
- package/dist/modules/billing/lib/paymentCsv.js.map +7 -0
- package/dist/modules/billing/lib/paymentGateway.js +15 -0
- package/dist/modules/billing/lib/paymentGateway.js.map +7 -0
- package/dist/modules/billing/lib/paymentImport.js +164 -0
- package/dist/modules/billing/lib/paymentImport.js.map +7 -0
- package/dist/modules/billing/lib/paymentMatcher.js +36 -0
- package/dist/modules/billing/lib/paymentMatcher.js.map +7 -0
- package/dist/modules/billing/lib/pdf/attachmentStore.js +46 -0
- package/dist/modules/billing/lib/pdf/attachmentStore.js.map +7 -0
- package/dist/modules/billing/lib/pdf/fonts/embeddedFonts.js +7 -0
- package/dist/modules/billing/lib/pdf/fonts/embeddedFonts.js.map +7 -0
- package/dist/modules/billing/lib/pdf/invoiceModel.js +194 -0
- package/dist/modules/billing/lib/pdf/invoiceModel.js.map +7 -0
- package/dist/modules/billing/lib/pdf/invoicePdf.js +165 -0
- package/dist/modules/billing/lib/pdf/invoicePdf.js.map +7 -0
- package/dist/modules/billing/lib/pdf/invoiceTemplate.js +276 -0
- package/dist/modules/billing/lib/pdf/invoiceTemplate.js.map +7 -0
- package/dist/modules/billing/lib/prepaidConfig.js +17 -25
- package/dist/modules/billing/lib/prepaidConfig.js.map +2 -2
- package/dist/modules/billing/lib/prepaidConsume.js +26 -7
- package/dist/modules/billing/lib/prepaidConsume.js.map +2 -2
- package/dist/modules/billing/lib/prepaidPeriodClose.js +277 -158
- package/dist/modules/billing/lib/prepaidPeriodClose.js.map +2 -2
- package/dist/modules/billing/lib/prepaidTaxPoint.js +37 -0
- package/dist/modules/billing/lib/prepaidTaxPoint.js.map +7 -0
- package/dist/modules/billing/lib/seeds/demo.js +51 -3
- package/dist/modules/billing/lib/seeds/demo.js.map +2 -2
- package/dist/modules/billing/lib/seeds/paymentsSample.js +93 -0
- package/dist/modules/billing/lib/seeds/paymentsSample.js.map +7 -0
- package/dist/modules/billing/lib/seeds/sellerSettings.js +41 -0
- package/dist/modules/billing/lib/seeds/sellerSettings.js.map +7 -0
- package/dist/modules/billing/lib/servicePeriods.js +121 -0
- package/dist/modules/billing/lib/servicePeriods.js.map +7 -0
- package/dist/modules/billing/lib/testRunCleanup.js +24 -0
- package/dist/modules/billing/lib/testRunCleanup.js.map +7 -0
- package/dist/modules/billing/lib/topupCapture.js +2 -2
- package/dist/modules/billing/lib/topupCapture.js.map +2 -2
- package/dist/modules/billing/lib/topupReceipt.js +58 -79
- package/dist/modules/billing/lib/topupReceipt.js.map +2 -2
- package/dist/modules/billing/lib/usageRater.js.map +1 -1
- package/dist/modules/billing/lib/usageRunner.js +14 -6
- package/dist/modules/billing/lib/usageRunner.js.map +2 -2
- package/dist/modules/billing/lib/vat.js +39 -0
- package/dist/modules/billing/lib/vat.js.map +7 -0
- package/dist/modules/billing/migrations/Migration20261114000000_billing_customer_kind.js +15 -0
- package/dist/modules/billing/migrations/Migration20261114000000_billing_customer_kind.js.map +7 -0
- package/dist/modules/billing/migrations/Migration20261114100000_billing_cycle_semantics.js +25 -0
- package/dist/modules/billing/migrations/Migration20261114100000_billing_cycle_semantics.js.map +7 -0
- package/dist/modules/billing/migrations/Migration20261115000000_billing_invoice_ledger.js +115 -0
- package/dist/modules/billing/migrations/Migration20261115000000_billing_invoice_ledger.js.map +7 -0
- package/dist/modules/billing/migrations/Migration20261116000000_billing_invoice_documents.js +47 -0
- package/dist/modules/billing/migrations/Migration20261116000000_billing_invoice_documents.js.map +7 -0
- package/dist/modules/billing/migrations/Migration20261117000000_billing_payments.js +89 -0
- package/dist/modules/billing/migrations/Migration20261117000000_billing_payments.js.map +7 -0
- package/dist/modules/billing/migrations/Migration20261118000000_billing_memos.js +17 -0
- package/dist/modules/billing/migrations/Migration20261118000000_billing_memos.js.map +7 -0
- package/dist/modules/billing/migrations/Migration20261119000000_billing_operator_feedback.js +27 -0
- package/dist/modules/billing/migrations/Migration20261119000000_billing_operator_feedback.js.map +7 -0
- package/dist/modules/billing/migrations/Migration20261120000000_billing_allocation_scope_indexes.js +29 -0
- package/dist/modules/billing/migrations/Migration20261120000000_billing_allocation_scope_indexes.js.map +7 -0
- package/dist/modules/billing/setup.js +7 -184
- package/dist/modules/billing/setup.js.map +2 -2
- package/dist/modules/billing/subscribers/credit-memo-auto-send.js +16 -0
- package/dist/modules/billing/subscribers/credit-memo-auto-send.js.map +7 -0
- package/dist/modules/billing/subscribers/debit-memo-apply-credit.js +16 -0
- package/dist/modules/billing/subscribers/debit-memo-apply-credit.js.map +7 -0
- package/dist/modules/billing/subscribers/debit-memo-auto-send.js +16 -0
- package/dist/modules/billing/subscribers/debit-memo-auto-send.js.map +7 -0
- package/dist/modules/billing/subscribers/invoice-apply-credit.js +34 -0
- package/dist/modules/billing/subscribers/invoice-apply-credit.js.map +7 -0
- package/dist/modules/billing/subscribers/invoice-auto-send.js +30 -0
- package/dist/modules/billing/subscribers/invoice-auto-send.js.map +7 -0
- package/dist/modules/billing/subscribers/payment-captured-to-paid.js +69 -33
- package/dist/modules/billing/subscribers/payment-captured-to-paid.js.map +2 -2
- package/dist/modules/billing/subscribers/prepaid-topup-captured.js +4 -6
- package/dist/modules/billing/subscribers/prepaid-topup-captured.js.map +2 -2
- package/generated/entities/billing_account/index.ts +3 -0
- package/generated/entities/billing_allocation/index.ts +18 -0
- package/generated/entities/billing_document_sequence/index.ts +11 -0
- package/generated/entities/billing_invoice/index.ts +38 -0
- package/generated/entities/billing_invoice_line/index.ts +24 -0
- package/generated/entities/billing_item/index.ts +4 -0
- package/generated/entities/billing_payment/index.ts +25 -0
- package/generated/entities/billing_payment_import/index.ts +14 -0
- package/generated/entities/billing_run/index.ts +0 -1
- package/generated/entities/billing_run_outcome/index.ts +1 -0
- package/generated/entities/billing_settings/index.ts +26 -0
- package/generated/entities/billing_statement/index.ts +1 -0
- package/generated/entities.ids.generated.ts +7 -0
- package/package.json +5 -1
- package/src/modules/billing/__integration__/TC-BILL-004.spec.ts +171 -0
- package/src/modules/billing/__integration__/TC-BILL-005.spec.ts +134 -0
- package/src/modules/billing/__integration__/TC-BILL-006.spec.ts +101 -0
- package/src/modules/billing/__integration__/TC-BILL-007.spec.ts +140 -0
- package/src/modules/billing/__integration__/TC-BILL-008.spec.ts +108 -0
- package/src/modules/billing/__integration__/TC-BILL-009.spec.ts +113 -0
- package/src/modules/billing/__integration__/TC-BILL-010.spec.ts +118 -0
- package/src/modules/billing/__integration__/TC-BILL-011.spec.ts +142 -0
- package/src/modules/billing/__integration__/TC-BILL-012.spec.ts +115 -0
- package/src/modules/billing/__integration__/TC-BILL-013.spec.ts +118 -0
- package/src/modules/billing/__integration__/sellerSettings.ts +24 -0
- package/src/modules/billing/__tests__/commands/invoices.test.ts +436 -354
- package/src/modules/billing/__tests__/commands/itemsBulk.test.ts +33 -0
- package/src/modules/billing/__tests__/commands/memos.test.ts +205 -0
- package/src/modules/billing/__tests__/commands/payments.test.ts +241 -0
- package/src/modules/billing/__tests__/commands/runsDelete.test.ts +146 -0
- package/src/modules/billing/__tests__/commands/runsPostDrafts.test.ts +106 -0
- package/src/modules/billing/__tests__/commands/topups.test.ts +11 -0
- package/src/modules/billing/__tests__/entityRegistry.test.ts +8 -1
- package/src/modules/billing/__tests__/helpers/prepaidMockEm.ts +28 -11
- package/src/modules/billing/__tests__/i18n/dictionaries.test.ts +64 -0
- package/src/modules/billing/__tests__/lib/accountFinancials.test.ts +53 -0
- package/src/modules/billing/__tests__/lib/accountSummary.test.ts +97 -0
- package/src/modules/billing/__tests__/lib/allocation.test.ts +319 -0
- package/src/modules/billing/__tests__/lib/billRunEngine.test.ts +228 -17
- package/src/modules/billing/__tests__/lib/billingSettings.test.ts +109 -0
- package/src/modules/billing/__tests__/lib/customerLookup.test.ts +156 -0
- package/src/modules/billing/__tests__/lib/dueDate.test.ts +35 -0
- package/src/modules/billing/__tests__/lib/iban.test.ts +38 -0
- package/src/modules/billing/__tests__/lib/invoiceDelivery.test.ts +206 -0
- package/src/modules/billing/__tests__/lib/invoiceLanguages.test.ts +49 -0
- package/src/modules/billing/__tests__/lib/invoiceWriter.test.ts +212 -10
- package/src/modules/billing/__tests__/lib/itemBillingState.test.ts +42 -0
- package/src/modules/billing/__tests__/lib/itemPriceChange.test.ts +165 -0
- package/src/modules/billing/__tests__/lib/lineAmounts.test.ts +86 -0
- package/src/modules/billing/__tests__/lib/navigation.test.ts +71 -0
- package/src/modules/billing/__tests__/lib/numbering.test.ts +91 -0
- package/src/modules/billing/__tests__/lib/overdue.test.ts +36 -0
- package/src/modules/billing/__tests__/lib/paymentCsv.test.ts +148 -0
- package/src/modules/billing/__tests__/lib/paymentImport.test.ts +113 -0
- package/src/modules/billing/__tests__/lib/paymentsSample.test.ts +73 -0
- package/src/modules/billing/__tests__/lib/pdf/invoicePdf.test.ts +269 -0
- package/src/modules/billing/__tests__/lib/pdf/invoicePdfService.test.ts +147 -0
- package/src/modules/billing/__tests__/lib/prepaidPeriodClose.test.ts +374 -98
- package/src/modules/billing/__tests__/lib/prepaidTaxPoint.test.ts +118 -0
- package/src/modules/billing/__tests__/lib/seedsDemo.test.ts +53 -2
- package/src/modules/billing/__tests__/lib/sellerSettings.test.ts +28 -0
- package/src/modules/billing/__tests__/lib/servicePeriods.test.ts +190 -0
- package/src/modules/billing/__tests__/lib/topupCapture.test.ts +6 -28
- package/src/modules/billing/__tests__/lib/topupReceipt.test.ts +21 -52
- package/src/modules/billing/__tests__/lib/vat.test.ts +51 -0
- package/src/modules/billing/__tests__/package-isolation.test.ts +22 -8
- package/src/modules/billing/__tests__/setup.test.ts +13 -4
- package/src/modules/billing/__tests__/validators.test.ts +197 -3
- package/src/modules/billing/acl.ts +12 -0
- package/src/modules/billing/api/accounts/[id]/summary/route.ts +62 -0
- package/src/modules/billing/api/accounts/route.ts +59 -4
- package/src/modules/billing/api/export/account/[id]/route.ts +13 -11
- package/src/modules/billing/api/invoices/[id]/memos/route.ts +63 -0
- package/src/modules/billing/api/invoices/[id]/pdf/route.ts +80 -0
- package/src/modules/billing/api/invoices/[id]/route.ts +57 -70
- package/src/modules/billing/api/invoices/[id]/send/route.ts +127 -0
- package/src/modules/billing/api/invoices/add-line/route.ts +2 -2
- package/src/modules/billing/api/invoices/delete-draft/route.ts +33 -0
- package/src/modules/billing/api/invoices/edit-line/route.ts +2 -2
- package/src/modules/billing/api/invoices/post/route.ts +7 -6
- package/src/modules/billing/api/invoices/remove-line/route.ts +2 -2
- package/src/modules/billing/api/invoices/route.ts +81 -86
- package/src/modules/billing/api/items/bulk/route.ts +2 -1
- package/src/modules/billing/api/items/change-price/route.ts +54 -0
- package/src/modules/billing/api/items/route.ts +23 -7
- package/src/modules/billing/api/payment-imports/[id]/route.ts +49 -0
- package/src/modules/billing/api/payment-imports/route.ts +57 -0
- package/src/modules/billing/api/payments/[id]/route.ts +63 -0
- package/src/modules/billing/api/payments/allocate/route.ts +35 -0
- package/src/modules/billing/api/payments/assign/route.ts +36 -0
- package/src/modules/billing/api/payments/convert-to-topup/route.ts +35 -0
- package/src/modules/billing/api/payments/ignore/route.ts +35 -0
- package/src/modules/billing/api/payments/import/route.ts +72 -0
- package/src/modules/billing/api/payments/restore/route.ts +35 -0
- package/src/modules/billing/api/payments/route.ts +147 -0
- package/src/modules/billing/api/payments/unallocate/route.ts +35 -0
- package/src/modules/billing/api/payments/unassign/route.ts +35 -0
- package/src/modules/billing/api/run-outcomes/route.ts +49 -6
- package/src/modules/billing/api/runs/[id]/post-drafts/route.ts +71 -0
- package/src/modules/billing/api/runs/[id]/route.ts +59 -0
- package/src/modules/billing/api/runs/retry-failed/route.ts +2 -1
- package/src/modules/billing/api/runs/route.ts +15 -7
- package/src/modules/billing/api/settings/number-preview/route.ts +46 -0
- package/src/modules/billing/api/settings/route.ts +116 -0
- package/src/modules/billing/api/statements/route.ts +5 -0
- package/src/modules/billing/api/test-invoices/wipe/route.ts +2 -2
- package/src/modules/billing/backend/billing/accounts/[id]/page.tsx +151 -372
- package/src/modules/billing/backend/billing/accounts/create/page.tsx +6 -0
- package/src/modules/billing/backend/billing/accounts/page.tsx +70 -4
- package/src/modules/billing/backend/billing/invoices/[id]/page.tsx +444 -95
- package/src/modules/billing/backend/billing/invoices/page.tsx +8 -227
- package/src/modules/billing/backend/billing/items/[id]/page.tsx +75 -6
- package/src/modules/billing/backend/billing/items/create/page.tsx +13 -8
- package/src/modules/billing/backend/billing/items/page.tsx +18 -2
- package/src/modules/billing/backend/billing/payments/[id]/page.meta.ts +19 -0
- package/src/modules/billing/backend/billing/payments/[id]/page.tsx +415 -0
- package/src/modules/billing/backend/billing/payments/imports/[id]/page.meta.ts +19 -0
- package/src/modules/billing/backend/billing/payments/imports/[id]/page.tsx +106 -0
- package/src/modules/billing/backend/billing/payments/page.meta.ts +16 -0
- package/src/modules/billing/backend/billing/payments/page.tsx +56 -0
- package/src/modules/billing/backend/billing/runs/[id]/page.tsx +49 -18
- package/src/modules/billing/backend/billing/runs/page.tsx +59 -8
- package/src/modules/billing/backend/billing/statements/[id]/page.tsx +86 -5
- package/src/modules/billing/backend/billing/statements/page.tsx +1 -1
- package/src/modules/billing/backend/billing/topups/page.tsx +1 -1
- package/src/modules/billing/backend/billing/transactions/page.tsx +1 -1
- package/src/modules/billing/backend/billing/usage/create/page.tsx +3 -2
- package/src/modules/billing/backend/config/billing/page.meta.ts +21 -0
- package/src/modules/billing/backend/config/billing/page.tsx +549 -0
- package/src/modules/billing/cli.ts +31 -1
- package/src/modules/billing/commands/accounts.ts +6 -0
- package/src/modules/billing/commands/index.ts +3 -0
- package/src/modules/billing/commands/invoices.ts +364 -231
- package/src/modules/billing/commands/items.ts +143 -0
- package/src/modules/billing/commands/memos.ts +218 -0
- package/src/modules/billing/commands/payments.ts +428 -0
- package/src/modules/billing/commands/runs.ts +205 -3
- package/src/modules/billing/commands/settings.ts +77 -0
- package/src/modules/billing/commands/topups.ts +12 -3
- package/src/modules/billing/commands/transactions.ts +2 -2
- package/src/modules/billing/components/AccountForm.tsx +199 -53
- package/src/modules/billing/components/AccountInvoicesSection.tsx +75 -0
- package/src/modules/billing/components/AccountPaymentsSection.tsx +42 -0
- package/src/modules/billing/components/AccountPicker.tsx +70 -0
- package/src/modules/billing/components/AllocatePaymentDialog.tsx +167 -0
- package/src/modules/billing/components/BillingDataTable.tsx +34 -0
- package/src/modules/billing/components/BillingSettingsLink.tsx +25 -0
- package/src/modules/billing/components/ChangeItemPriceDialog.tsx +180 -0
- package/src/modules/billing/components/CreateMemoDialog.tsx +232 -0
- package/src/modules/billing/components/CustomerLabel.tsx +53 -0
- package/src/modules/billing/components/InvoicesTable.tsx +344 -0
- package/src/modules/billing/components/ItemForm.tsx +233 -44
- package/src/modules/billing/components/ItemPriceField.tsx +81 -0
- package/src/modules/billing/components/LineFormDialog.tsx +25 -1
- package/src/modules/billing/components/ManualPaymentDialog.tsx +140 -0
- package/src/modules/billing/components/MoneyInput.tsx +26 -0
- package/src/modules/billing/components/PaymentUploadDialog.tsx +148 -0
- package/src/modules/billing/components/PaymentsTable.tsx +213 -0
- package/src/modules/billing/components/PostRunDraftsButton.tsx +129 -0
- package/src/modules/billing/components/PrepaidPanel.tsx +19 -6
- package/src/modules/billing/components/RunCyclesSection.tsx +298 -0
- package/src/modules/billing/components/TestRunActions.tsx +152 -0
- package/src/modules/billing/components/account/AccountItemsTab.tsx +192 -0
- package/src/modules/billing/components/account/AccountRunBillingDialog.tsx +147 -0
- package/src/modules/billing/components/account/AccountRunsTab.tsx +201 -0
- package/src/modules/billing/components/account/AccountStatementsTab.tsx +120 -0
- package/src/modules/billing/components/account/AccountSummaryCards.tsx +153 -0
- package/src/modules/billing/components/account/AccountUsageTab.tsx +122 -0
- package/src/modules/billing/components/account/AccountView.tsx +101 -0
- package/src/modules/billing/components/account/accountRow.ts +70 -0
- package/src/modules/billing/components/customerNames.ts +62 -0
- package/src/modules/billing/data/entities.ts +656 -6
- package/src/modules/billing/data/entityIds.ts +9 -0
- package/src/modules/billing/data/validators.ts +388 -8
- package/src/modules/billing/events.ts +56 -3
- package/src/modules/billing/i18n/de.json +880 -0
- package/src/modules/billing/i18n/en.json +457 -21
- package/src/modules/billing/i18n/es.json +880 -0
- package/src/modules/billing/i18n/pl.json +458 -22
- package/src/modules/billing/index.ts +6 -2
- package/src/modules/billing/lib/accountFinancials.ts +84 -0
- package/src/modules/billing/lib/accountLock.ts +32 -0
- package/src/modules/billing/lib/accountStatus.ts +11 -9
- package/src/modules/billing/lib/accountSummary.ts +172 -0
- package/src/modules/billing/lib/allocation.ts +515 -0
- package/src/modules/billing/lib/allocationEvents.ts +26 -0
- package/src/modules/billing/lib/billPeriod.ts +19 -0
- package/src/modules/billing/lib/billRunEngine.ts +350 -150
- package/src/modules/billing/lib/billingSettings.ts +145 -0
- package/src/modules/billing/lib/commandRoute.ts +112 -0
- package/src/modules/billing/lib/customerLookup.ts +157 -0
- package/src/modules/billing/lib/dateOnly.ts +22 -0
- package/src/modules/billing/lib/documentParties.ts +23 -0
- package/src/modules/billing/lib/documentTypes.ts +37 -0
- package/src/modules/billing/lib/dueDate.ts +26 -0
- package/src/modules/billing/lib/iban.ts +36 -0
- package/src/modules/billing/lib/invoiceDelivery.ts +196 -0
- package/src/modules/billing/lib/invoiceLanguages.ts +57 -0
- package/src/modules/billing/lib/invoiceWriter.ts +162 -148
- package/src/modules/billing/lib/itemBillingState.ts +67 -0
- package/src/modules/billing/lib/itemPriceChange.ts +56 -0
- package/src/modules/billing/lib/itemSelector.ts +4 -1
- package/src/modules/billing/lib/lineAmounts.ts +61 -0
- package/src/modules/billing/lib/memoGuards.ts +41 -0
- package/src/modules/billing/lib/navigation.ts +64 -0
- package/src/modules/billing/lib/numbering.ts +174 -0
- package/src/modules/billing/lib/overdue.ts +60 -0
- package/src/modules/billing/lib/paymentCsv.ts +171 -0
- package/src/modules/billing/lib/paymentGateway.ts +52 -0
- package/src/modules/billing/lib/paymentImport.ts +228 -0
- package/src/modules/billing/lib/paymentMatcher.ts +88 -0
- package/src/modules/billing/lib/pdf/attachmentStore.ts +60 -0
- package/src/modules/billing/lib/pdf/fonts/NotoSans-Bold.ttf +0 -0
- package/src/modules/billing/lib/pdf/fonts/NotoSans-Regular.ttf +0 -0
- package/src/modules/billing/lib/pdf/fonts/OFL.txt +93 -0
- package/src/modules/billing/lib/pdf/fonts/embeddedFonts.ts +9 -0
- package/src/modules/billing/lib/pdf/invoiceModel.ts +329 -0
- package/src/modules/billing/lib/pdf/invoicePdf.ts +220 -0
- package/src/modules/billing/lib/pdf/invoiceTemplate.ts +338 -0
- package/src/modules/billing/lib/prepaidConfig.ts +27 -36
- package/src/modules/billing/lib/prepaidConsume.ts +29 -6
- package/src/modules/billing/lib/prepaidPeriodClose.ts +407 -239
- package/src/modules/billing/lib/prepaidTaxPoint.ts +76 -0
- package/src/modules/billing/lib/seeds/demo.ts +79 -6
- package/src/modules/billing/lib/seeds/paymentsSample.ts +136 -0
- package/src/modules/billing/lib/seeds/sellerSettings.ts +78 -0
- package/src/modules/billing/lib/servicePeriods.ts +226 -0
- package/src/modules/billing/lib/testRunCleanup.ts +42 -0
- package/src/modules/billing/lib/topupCapture.ts +3 -4
- package/src/modules/billing/lib/topupReceipt.ts +70 -103
- package/src/modules/billing/lib/usageRater.ts +1 -1
- package/src/modules/billing/lib/usageRunner.ts +17 -5
- package/src/modules/billing/lib/vat.ts +56 -0
- package/src/modules/billing/migrations/Migration20261114000000_billing_customer_kind.ts +25 -0
- package/src/modules/billing/migrations/Migration20261114100000_billing_cycle_semantics.ts +37 -0
- package/src/modules/billing/migrations/Migration20261115000000_billing_invoice_ledger.ts +132 -0
- package/src/modules/billing/migrations/Migration20261116000000_billing_invoice_documents.ts +58 -0
- package/src/modules/billing/migrations/Migration20261117000000_billing_payments.ts +97 -0
- package/src/modules/billing/migrations/Migration20261118000000_billing_memos.ts +21 -0
- package/src/modules/billing/migrations/Migration20261119000000_billing_operator_feedback.ts +39 -0
- package/src/modules/billing/migrations/Migration20261120000000_billing_allocation_scope_indexes.ts +35 -0
- package/src/modules/billing/setup.ts +11 -237
- package/src/modules/billing/subscribers/credit-memo-auto-send.ts +15 -0
- package/src/modules/billing/subscribers/debit-memo-apply-credit.ts +15 -0
- package/src/modules/billing/subscribers/debit-memo-auto-send.ts +15 -0
- package/src/modules/billing/subscribers/invoice-apply-credit.ts +39 -0
- package/src/modules/billing/subscribers/invoice-auto-send.ts +46 -0
- package/src/modules/billing/subscribers/payment-captured-to-paid.ts +84 -62
- package/src/modules/billing/subscribers/prepaid-topup-captured.ts +4 -8
- package/dist/modules/billing/lib/invoiceStatus.js +0 -38
- package/dist/modules/billing/lib/invoiceStatus.js.map +0 -7
- package/src/modules/billing/__tests__/lib/invoiceStatus.test.ts +0 -97
- package/src/modules/billing/lib/invoiceStatus.ts +0 -61
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import { PDFDocument } from 'pdf-lib'
|
|
2
|
+
import {
|
|
3
|
+
buildInvoiceDocumentModel,
|
|
4
|
+
type DocumentTranslate,
|
|
5
|
+
type PdfInvoice,
|
|
6
|
+
type PdfLine,
|
|
7
|
+
} from '../../../lib/pdf/invoiceModel'
|
|
8
|
+
import fontkit from '@pdf-lib/fontkit'
|
|
9
|
+
import { TABLE_COLUMNS, renderInvoicePdf, sanitizeForFont, wrap } from '../../../lib/pdf/invoiceTemplate'
|
|
10
|
+
import { NOTO_SANS_BOLD_BASE64 } from '../../../lib/pdf/fonts/embeddedFonts'
|
|
11
|
+
import en from '../../../i18n/en.json'
|
|
12
|
+
import pl from '../../../i18n/pl.json'
|
|
13
|
+
import es from '../../../i18n/es.json'
|
|
14
|
+
import de from '../../../i18n/de.json'
|
|
15
|
+
import type { InvoiceLanguageCode } from '../../../lib/invoiceLanguages'
|
|
16
|
+
|
|
17
|
+
const translator = (dict: Record<string, string>): DocumentTranslate => (key, fallback) => dict[key] ?? fallback
|
|
18
|
+
|
|
19
|
+
const invoice: PdfInvoice = {
|
|
20
|
+
number: 'INV/2026/11/0007',
|
|
21
|
+
documentType: 'invoice',
|
|
22
|
+
status: 'posted',
|
|
23
|
+
testRun: false,
|
|
24
|
+
issueDate: '2026-11-14',
|
|
25
|
+
dueDate: '2026-11-28',
|
|
26
|
+
billDate: '2026-11-01',
|
|
27
|
+
periodStart: '2026-11-01',
|
|
28
|
+
periodEnd: '2026-11-30',
|
|
29
|
+
currencyCode: 'PLN',
|
|
30
|
+
subtotalNet: '148.3300',
|
|
31
|
+
taxTotal: '25.6700',
|
|
32
|
+
totalGross: '174.0000',
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const line = (overrides: Partial<PdfLine> = {}): PdfLine => ({
|
|
36
|
+
description: 'Internet 300 Mb/s',
|
|
37
|
+
quantity: '1.0000',
|
|
38
|
+
unitPriceNet: '100.0000',
|
|
39
|
+
taxRate: '23',
|
|
40
|
+
netAmount: '100.0000',
|
|
41
|
+
taxAmount: '23.0000',
|
|
42
|
+
grossAmount: '123.0000',
|
|
43
|
+
servicePeriodStart: '2026-11-01',
|
|
44
|
+
servicePeriodEnd: '2026-11-30',
|
|
45
|
+
...overrides,
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
const lines = [
|
|
49
|
+
line(),
|
|
50
|
+
line({ description: 'Wsparcie priorytetowe', unitPriceNet: '33.3300', taxRate: '8', netAmount: '33.3300', taxAmount: '2.6700', grossAmount: '36.0000' }),
|
|
51
|
+
line({ description: 'Kopie zapasowe', unitPriceNet: '15.0000', taxRate: '0', netAmount: '15.0000', taxAmount: '0.0000', grossAmount: '15.0000', servicePeriodStart: null, servicePeriodEnd: null }),
|
|
52
|
+
]
|
|
53
|
+
|
|
54
|
+
const seller = {
|
|
55
|
+
legalName: 'Żółta Łódź sp. z o.o.',
|
|
56
|
+
address: { line1: 'ul. Świętokrzyska 1', city: 'Kraków', postal_code: '30-001', country: 'PL' },
|
|
57
|
+
taxId: 'PL1234563218',
|
|
58
|
+
bankName: 'Bank Śląski',
|
|
59
|
+
iban: 'PL61109010140000071219812874',
|
|
60
|
+
bic: 'WBKPPLPP',
|
|
61
|
+
footer: 'KRS 0000000000\nKapitał zakładowy 5 000 zł',
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const buyer = { name: 'Jan Kowalski', address: { line1: 'ul. Testowa 1', city: 'Warszawa', postal_code: '00-001', country: 'PL' }, taxId: null }
|
|
65
|
+
|
|
66
|
+
const DICTIONARIES: Record<InvoiceLanguageCode, Record<string, string>> = { en, pl, es, de }
|
|
67
|
+
|
|
68
|
+
function model(language: InvoiceLanguageCode, overrides: Partial<PdfInvoice> = {}, docLines: PdfLine[] = lines) {
|
|
69
|
+
return buildInvoiceDocumentModel({
|
|
70
|
+
invoice: { ...invoice, ...overrides },
|
|
71
|
+
lines: docLines,
|
|
72
|
+
seller,
|
|
73
|
+
buyer,
|
|
74
|
+
language,
|
|
75
|
+
translate: translator(DICTIONARIES[language]),
|
|
76
|
+
})
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
describe('buildInvoiceDocumentModel', () => {
|
|
80
|
+
it('builds English labels, en-GB dates and the payment title with the invoice number', () => {
|
|
81
|
+
const m = model('en')
|
|
82
|
+
expect(m.title).toBe('VAT invoice')
|
|
83
|
+
expect(m.meta).toEqual(
|
|
84
|
+
expect.arrayContaining([
|
|
85
|
+
['Number', 'INV/2026/11/0007'],
|
|
86
|
+
['Issue date', '14/11/2026'],
|
|
87
|
+
['Due date', '28/11/2026'],
|
|
88
|
+
]),
|
|
89
|
+
)
|
|
90
|
+
expect(m.payment?.lines).toEqual(
|
|
91
|
+
expect.arrayContaining(['IBAN: PL61 1090 1014 0000 0712 1981 2874', 'Transfer title: INV/2026/11/0007']),
|
|
92
|
+
)
|
|
93
|
+
expect(m.watermark).toBeNull()
|
|
94
|
+
expect(m.pageLabel(1, 3)).toBe('Page 1 of 3')
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
it('builds Polish labels and pl-PL money / dates', () => {
|
|
98
|
+
const m = model('pl')
|
|
99
|
+
expect(m.title).toBe('Faktura VAT')
|
|
100
|
+
expect(m.meta).toEqual(expect.arrayContaining([['Data wystawienia', '14.11.2026'], ['Termin płatności', '28.11.2026']]))
|
|
101
|
+
expect(m.totals[2]).toEqual(['Do zapłaty', '174,00 zł'])
|
|
102
|
+
expect(m.payment?.lines).toContain('Tytuł przelewu: INV/2026/11/0007')
|
|
103
|
+
expect(m.seller.heading).toBe('Sprzedawca')
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
it('builds Spanish labels and es-ES money / dates (invoice and credit memo)', () => {
|
|
107
|
+
const m = model('es', { currencyCode: 'EUR', totalGross: '1234.5600' })
|
|
108
|
+
expect(m.title).toBe('Factura')
|
|
109
|
+
expect(m.meta).toEqual(expect.arrayContaining([['Fecha de emisión', '14/11/2026']]))
|
|
110
|
+
expect(m.table.headers).toEqual(expect.arrayContaining(['Cant.', 'Precio unit.', '% IVA', 'IVA']))
|
|
111
|
+
expect(m.totals[0][0]).toBe('Base imponible')
|
|
112
|
+
expect(m.totals[2]).toEqual(['Total a pagar', '1234,56 €'])
|
|
113
|
+
// The payment matcher looks for the invoice number in the transfer title.
|
|
114
|
+
expect(m.payment?.lines).toContain('Concepto: INV/2026/11/0007')
|
|
115
|
+
expect(m.seller.heading).toBe('Emisor')
|
|
116
|
+
expect(m.buyer.heading).toBe('Cliente')
|
|
117
|
+
expect(m.vatSummary.heading).toBe('Resumen de IVA')
|
|
118
|
+
expect(m.pageLabel(1, 2)).not.toContain('{')
|
|
119
|
+
const memo = model('es', { documentType: 'credit_memo', correctsNumber: 'INV/2026/10/0003', correctsIssueDate: '2026-10-05' })
|
|
120
|
+
expect(memo.title).toBe('Factura rectificativa')
|
|
121
|
+
expect(memo.meta).toEqual(expect.arrayContaining([['Rectifica', 'INV/2026/10/0003 de 05/10/2026']]))
|
|
122
|
+
expect(memo.totals[2][0]).toBe('Total abonado')
|
|
123
|
+
expect(memo.payment?.lines.join(' ')).toContain('INV/2026/10/0003')
|
|
124
|
+
expect(model('es', { status: 'draft' }).watermark).toBe('BORRADOR')
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
it('builds German labels and de-DE money / dates (invoice and credit memo)', () => {
|
|
128
|
+
const m = model('de', { currencyCode: 'EUR', totalGross: '1234.5600' })
|
|
129
|
+
expect(m.title).toBe('Rechnung')
|
|
130
|
+
expect(m.meta).toEqual(expect.arrayContaining([['Leistungszeitraum', '01.11.2026 – 30.11.2026']]))
|
|
131
|
+
expect(m.table.headers).toEqual(expect.arrayContaining(['Anz.', 'Einzelpreis netto', 'USt. %', 'USt.']))
|
|
132
|
+
expect(m.totals[2]).toEqual(['Zahlbetrag', '1.234,56 €'])
|
|
133
|
+
expect(m.payment?.lines).toContain('Verwendungszweck: INV/2026/11/0007')
|
|
134
|
+
expect(m.seller.heading).toBe('Rechnungssteller')
|
|
135
|
+
expect(m.buyer.heading).toBe('Rechnungsempfänger')
|
|
136
|
+
const memo = model('de', { documentType: 'credit_memo', correctsNumber: 'INV/2026/10/0003', correctsIssueDate: '2026-10-05' })
|
|
137
|
+
expect(memo.title).toBe('Rechnungskorrektur')
|
|
138
|
+
expect(memo.meta).toEqual(expect.arrayContaining([['Korrigiert', 'INV/2026/10/0003 vom 05.10.2026']]))
|
|
139
|
+
expect(memo.totals[2][0]).toBe('Gutgeschriebener Betrag')
|
|
140
|
+
expect(model('de', { status: 'draft' }).watermark).toBe('ENTWURF')
|
|
141
|
+
})
|
|
142
|
+
|
|
143
|
+
it('groups the VAT summary by rate (highest first) and it adds up to the totals', () => {
|
|
144
|
+
const m = model('en')
|
|
145
|
+
expect(m.vatSummary.rows.map((r) => r[0])).toEqual(['23 %', '8 %', '0 %'])
|
|
146
|
+
const parse = (s: string) => Number.parseFloat(s.replace(/[^0-9.-]/g, ''))
|
|
147
|
+
const vat = m.vatSummary.rows.reduce((sum, r) => sum + parse(r[2]), 0)
|
|
148
|
+
expect(vat.toFixed(2)).toBe('25.67')
|
|
149
|
+
})
|
|
150
|
+
|
|
151
|
+
it('prints the service period on lines that carry one, once', () => {
|
|
152
|
+
const m = model('en')
|
|
153
|
+
expect(m.table.rows[0][1]).toBe('Internet 300 Mb/s (01/11/2026 – 30/11/2026)')
|
|
154
|
+
expect(m.table.rows[2][1]).toBe('Kopie zapasowe')
|
|
155
|
+
const dated = model('en', {}, [line({ description: 'Plan · 2026-11-15 – 2026-11-30' })])
|
|
156
|
+
expect(dated.table.rows[0][1]).toBe('Plan · 2026-11-15 – 2026-11-30')
|
|
157
|
+
})
|
|
158
|
+
|
|
159
|
+
it('watermarks drafts (no issue / due date yet) and test documents', () => {
|
|
160
|
+
const draft = model('en', { status: 'draft', number: 'DRAFT-1A2B3C4D', issueDate: null, dueDate: null })
|
|
161
|
+
expect(draft.watermark).toBe('DRAFT')
|
|
162
|
+
expect(draft.meta).toEqual(expect.arrayContaining([['Issue date', '—']]))
|
|
163
|
+
expect(model('pl', { status: 'draft', testRun: true }).watermark).toBe('TEST')
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
it('has no payment block without an IBAN or for receipts; credit memos show their settlement', () => {
|
|
167
|
+
expect(
|
|
168
|
+
buildInvoiceDocumentModel({ invoice, lines, seller: { ...seller, iban: null }, buyer, language: 'en', translate: translator({}) }).payment,
|
|
169
|
+
).toBeNull()
|
|
170
|
+
expect(model('en', { documentType: 'receipt' }).payment).toBeNull()
|
|
171
|
+
const memo = model('en', {
|
|
172
|
+
documentType: 'credit_memo',
|
|
173
|
+
correctsNumber: 'INV/2026/10/0003',
|
|
174
|
+
correctsIssueDate: '2026-10-05',
|
|
175
|
+
correctionReason: 'Wrong price',
|
|
176
|
+
})
|
|
177
|
+
expect(memo.title).toBe('Credit memo')
|
|
178
|
+
// Spec D: a credit memo shows how it settles instead of payment instructions.
|
|
179
|
+
expect(memo.payment?.heading).toBe('Settlement')
|
|
180
|
+
expect(memo.payment?.lines.join(' ')).toContain('Settled against invoice INV/2026/10/0003')
|
|
181
|
+
expect(memo.payment?.lines.join(' ')).not.toContain('IBAN')
|
|
182
|
+
expect(memo.totals[2][0]).toBe('Total credited')
|
|
183
|
+
expect(memo.meta).toEqual(
|
|
184
|
+
expect.arrayContaining([
|
|
185
|
+
['Corrects', 'INV/2026/10/0003 of 05/10/2026'],
|
|
186
|
+
['Reason', 'Wrong price'],
|
|
187
|
+
]),
|
|
188
|
+
)
|
|
189
|
+
const debit = model('pl', { documentType: 'debit_memo', correctsNumber: 'INV/2026/10/0003' })
|
|
190
|
+
expect(debit.title).toBe('Nota obciążeniowa')
|
|
191
|
+
expect(debit.payment?.lines).toContain('Tytuł przelewu: INV/2026/11/0007')
|
|
192
|
+
})
|
|
193
|
+
|
|
194
|
+
it('splits the footer into lines and falls back to English for unknown languages', () => {
|
|
195
|
+
expect(model('en').footer).toEqual(['KRS 0000000000', 'Kapitał zakładowy 5 000 zł'])
|
|
196
|
+
const unknown = buildInvoiceDocumentModel({ invoice, lines, seller, buyer, language: 'xx', translate: translator({}) })
|
|
197
|
+
expect(unknown.meta[1]).toEqual(['Issue date', '14/11/2026'])
|
|
198
|
+
})
|
|
199
|
+
})
|
|
200
|
+
|
|
201
|
+
describe('renderInvoicePdf', () => {
|
|
202
|
+
it('renders a one-page A4 document with Polish text and the embedded font', async () => {
|
|
203
|
+
const bytes = await renderInvoicePdf(model('pl'))
|
|
204
|
+
const doc = await PDFDocument.load(bytes)
|
|
205
|
+
expect(doc.getPageCount()).toBe(1)
|
|
206
|
+
const [page] = doc.getPages()
|
|
207
|
+
expect(Math.round(page.getWidth())).toBe(595)
|
|
208
|
+
expect(doc.getTitle()).toBe('Faktura VAT INV/2026/11/0007')
|
|
209
|
+
}, 30_000)
|
|
210
|
+
|
|
211
|
+
it('paginates long invoices, repeating the table on every page', async () => {
|
|
212
|
+
const rows = (n: number) =>
|
|
213
|
+
Array.from({ length: n }, (_, i) =>
|
|
214
|
+
line({ description: `Usługa nr ${i + 1}`, servicePeriodStart: null, servicePeriodEnd: null }),
|
|
215
|
+
)
|
|
216
|
+
const pages = async (n: number) =>
|
|
217
|
+
(await PDFDocument.load(await renderInvoicePdf(model('pl', { status: 'draft' }, rows(n))))).getPageCount()
|
|
218
|
+
// ~31 single-line rows fit under the header on page 1, ~44 on later pages;
|
|
219
|
+
// the VAT summary, totals and payment block follow the last row.
|
|
220
|
+
expect(await pages(10)).toBe(1)
|
|
221
|
+
expect(await pages(40)).toBe(2)
|
|
222
|
+
expect(await pages(80)).toBe(3)
|
|
223
|
+
}, 30_000)
|
|
224
|
+
|
|
225
|
+
it.each(['es', 'de'] as const)('renders a one-page %s document with its own title and diacritics', async (language) => {
|
|
226
|
+
const m = model(language, { currencyCode: 'EUR' })
|
|
227
|
+
const doc = await PDFDocument.load(await renderInvoicePdf(m))
|
|
228
|
+
expect(doc.getPageCount()).toBe(1)
|
|
229
|
+
expect(doc.getTitle()).toBe(`${m.title} INV/2026/11/0007`)
|
|
230
|
+
}, 30_000)
|
|
231
|
+
|
|
232
|
+
it.each(['en', 'es', 'de', 'pl'] as const)(
|
|
233
|
+
'fits %s column headers in their columns with the real font (no mid-word split, at most 3 lines)',
|
|
234
|
+
async (language) => {
|
|
235
|
+
const doc = await PDFDocument.create()
|
|
236
|
+
doc.registerFontkit(fontkit)
|
|
237
|
+
const bold = await doc.embedFont(Buffer.from(NOTO_SANS_BOLD_BASE64, 'base64'), { subset: true })
|
|
238
|
+
// Same size / padding the template uses for table headers (SMALL_SIZE = 8, 3pt each side).
|
|
239
|
+
model(language).table.headers.forEach((header, i) => {
|
|
240
|
+
const width = TABLE_COLUMNS[i] - 6
|
|
241
|
+
const lines = wrap(header, bold, 8, width)
|
|
242
|
+
expect({ header, lines: lines.length }).toEqual({ header, lines: expect.any(Number) })
|
|
243
|
+
expect(lines.length).toBeLessThanOrEqual(3)
|
|
244
|
+
// Every wrapped line is a whole word (or words): no word was cut by characters.
|
|
245
|
+
const words = new Set(header.split(/\s+/))
|
|
246
|
+
for (const part of lines) for (const w of part.split(' ')) expect({ header, word: w, whole: words.has(w) }).toEqual({ header, word: w, whole: true })
|
|
247
|
+
})
|
|
248
|
+
},
|
|
249
|
+
)
|
|
250
|
+
|
|
251
|
+
it('wraps long descriptions instead of overflowing the column', async () => {
|
|
252
|
+
const long = line({ description: 'Bardzo długi opis usługi '.repeat(12) })
|
|
253
|
+
const bytes = await renderInvoicePdf(model('en', {}, [long]))
|
|
254
|
+
expect((await PDFDocument.load(bytes)).getPageCount()).toBe(1)
|
|
255
|
+
}, 30_000)
|
|
256
|
+
|
|
257
|
+
it('never throws on characters outside the font (they become "?")', async () => {
|
|
258
|
+
const exotic = buildInvoiceDocumentModel({
|
|
259
|
+
invoice,
|
|
260
|
+
lines: [line({ description: 'Тест 中文 🚀' })],
|
|
261
|
+
seller,
|
|
262
|
+
buyer: { ...buyer, name: 'Ελληνικά' },
|
|
263
|
+
language: 'en',
|
|
264
|
+
translate: translator({}),
|
|
265
|
+
})
|
|
266
|
+
await expect(renderInvoicePdf(exotic)).resolves.toBeInstanceOf(Uint8Array)
|
|
267
|
+
expect(sanitizeForFont('Zażółć 🚀', new Set([...'Zażółć '].map((c) => c.codePointAt(0)!)))).toBe('Zażółć ?')
|
|
268
|
+
}, 30_000)
|
|
269
|
+
})
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
jest.mock('../../../lib/pdf/invoiceTemplate', () => ({
|
|
2
|
+
renderInvoicePdf: jest.fn(async () => new Uint8Array([37, 80, 68, 70])),
|
|
3
|
+
}))
|
|
4
|
+
jest.mock('../../../lib/pdf/attachmentStore', () => ({
|
|
5
|
+
storeAttachment: jest.fn(async () => 'att-new'),
|
|
6
|
+
readAttachment: jest.fn(async () => null),
|
|
7
|
+
attachmentIdFromUrl: jest.requireActual('../../../lib/pdf/attachmentStore').attachmentIdFromUrl,
|
|
8
|
+
}))
|
|
9
|
+
|
|
10
|
+
import { renderInvoicePdf } from '../../../lib/pdf/invoiceTemplate'
|
|
11
|
+
import { readAttachment, storeAttachment } from '../../../lib/pdf/attachmentStore'
|
|
12
|
+
import { freezeInvoicePdf, getInvoicePdf, pdfFileName } from '../../../lib/pdf/invoicePdf'
|
|
13
|
+
import { BillingAccount, BillingInvoice, BillingInvoiceLine, BillingSettings } from '../../../data/entities'
|
|
14
|
+
import type { InvoiceDocumentModel } from '../../../lib/pdf/invoiceModel'
|
|
15
|
+
|
|
16
|
+
const scope = { tenantId: 't-1', organizationId: 'o-1' }
|
|
17
|
+
const loadTranslator = async () => (_key: string, fallback: string) => fallback
|
|
18
|
+
|
|
19
|
+
function invoiceRow(overrides: Record<string, unknown> = {}) {
|
|
20
|
+
return {
|
|
21
|
+
id: 'inv-1',
|
|
22
|
+
...scope,
|
|
23
|
+
billAccountId: 'acc-1',
|
|
24
|
+
number: 'INV/2026/11/0001',
|
|
25
|
+
documentType: 'invoice',
|
|
26
|
+
status: 'posted',
|
|
27
|
+
testRun: false,
|
|
28
|
+
issueDate: new Date('2026-11-14T00:00:00Z'),
|
|
29
|
+
dueDate: new Date('2026-11-28T00:00:00Z'),
|
|
30
|
+
currencyCode: 'PLN',
|
|
31
|
+
subtotalNet: '100.0000',
|
|
32
|
+
taxTotal: '23.0000',
|
|
33
|
+
totalGross: '123.0000',
|
|
34
|
+
pdfAttachmentId: null,
|
|
35
|
+
sellerSnapshot: { legal_name: 'Frozen Seller', tax_id: 'PL-FROZEN', iban: 'PL61109010140000071219812874', logo_attachment_id: null },
|
|
36
|
+
buyerSnapshot: { name: 'Frozen Buyer', invoice_language: 'pl' },
|
|
37
|
+
...overrides,
|
|
38
|
+
} as unknown as BillingInvoice
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function makeEm() {
|
|
42
|
+
return {
|
|
43
|
+
find: jest.fn(async (entity: unknown) =>
|
|
44
|
+
entity === BillingInvoiceLine
|
|
45
|
+
? [
|
|
46
|
+
{
|
|
47
|
+
description: 'Plan',
|
|
48
|
+
quantity: '1',
|
|
49
|
+
unitPriceNet: '100',
|
|
50
|
+
taxRate: '23',
|
|
51
|
+
netAmount: '100',
|
|
52
|
+
taxAmount: '23',
|
|
53
|
+
grossAmount: '123',
|
|
54
|
+
},
|
|
55
|
+
]
|
|
56
|
+
: [],
|
|
57
|
+
),
|
|
58
|
+
findOne: jest.fn(async (entity: unknown) => {
|
|
59
|
+
if (entity === BillingSettings) return { organizationId: 'o-1', legalName: 'Live Seller', taxId: 'PL-LIVE' }
|
|
60
|
+
if (entity === BillingAccount) return { id: 'acc-1', name: 'Live Buyer', invoiceLanguage: 'en', invoiceEmail: 'x@y.z' }
|
|
61
|
+
return null
|
|
62
|
+
}),
|
|
63
|
+
execute: jest.fn(async (): Promise<Array<{ logo_url: string | null }>> => [{ logo_url: null }]),
|
|
64
|
+
nativeUpdate: jest.fn(async () => 1),
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const lastModel = () => (renderInvoicePdf as jest.Mock).mock.calls.at(-1)?.[0] as InvoiceDocumentModel
|
|
69
|
+
|
|
70
|
+
beforeEach(() => jest.clearAllMocks())
|
|
71
|
+
|
|
72
|
+
describe('invoice PDF service', () => {
|
|
73
|
+
it('renders drafts live with live parties and never stores them', async () => {
|
|
74
|
+
const em = makeEm()
|
|
75
|
+
const draft = invoiceRow({ status: 'draft', number: 'DRAFT-1A2B3C4D', sellerSnapshot: null, buyerSnapshot: null })
|
|
76
|
+
const pdf = await getInvoicePdf(em as never, draft, { loadTranslator })
|
|
77
|
+
expect(pdf).toMatchObject({ fileName: 'DRAFT-1A2B3C4D.pdf', frozen: false })
|
|
78
|
+
expect(lastModel().seller.lines[0]).toBe('Live Seller')
|
|
79
|
+
expect(lastModel().buyer.lines[0]).toBe('Live Buyer')
|
|
80
|
+
expect(lastModel().watermark).toBe('DRAFT')
|
|
81
|
+
expect(storeAttachment).not.toHaveBeenCalled()
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
it('serves the frozen attachment of a posted document without re-rendering', async () => {
|
|
85
|
+
;(readAttachment as jest.Mock).mockResolvedValueOnce({ bytes: new Uint8Array([1, 2]), mimeType: 'application/pdf', fileName: 'x.pdf' })
|
|
86
|
+
const pdf = await getInvoicePdf(makeEm() as never, invoiceRow({ pdfAttachmentId: 'att-1' }), { loadTranslator })
|
|
87
|
+
expect(pdf).toMatchObject({ frozen: true, fileName: 'INV-2026-11-0001.pdf' })
|
|
88
|
+
expect(Array.from(pdf.bytes)).toEqual([1, 2])
|
|
89
|
+
expect(renderInvoicePdf).not.toHaveBeenCalled()
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
it('freezes a posted document lazily on first request, from the frozen snapshots', async () => {
|
|
93
|
+
const em = makeEm()
|
|
94
|
+
const invoice = invoiceRow()
|
|
95
|
+
const pdf = await getInvoicePdf(em as never, invoice, { loadTranslator })
|
|
96
|
+
expect(pdf.frozen).toBe(true)
|
|
97
|
+
expect(storeAttachment).toHaveBeenCalledWith(em, scope, expect.objectContaining({
|
|
98
|
+
entityId: 'billing:billing_invoice',
|
|
99
|
+
recordId: 'inv-1',
|
|
100
|
+
mimeType: 'application/pdf',
|
|
101
|
+
fileName: 'INV-2026-11-0001.pdf',
|
|
102
|
+
}))
|
|
103
|
+
// Conditional claim: only sets the column when still empty.
|
|
104
|
+
expect(em.nativeUpdate).toHaveBeenCalledWith(
|
|
105
|
+
BillingInvoice,
|
|
106
|
+
expect.objectContaining({ id: 'inv-1', pdfAttachmentId: null }),
|
|
107
|
+
{ pdfAttachmentId: 'att-new' },
|
|
108
|
+
)
|
|
109
|
+
expect(invoice.pdfAttachmentId).toBe('att-new')
|
|
110
|
+
expect(lastModel().seller.lines[0]).toBe('Frozen Seller')
|
|
111
|
+
expect(lastModel().buyer.lines[0]).toBe('Frozen Buyer')
|
|
112
|
+
expect(lastModel().watermark).toBeNull()
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
it('is idempotent and refuses to freeze drafts or test documents', async () => {
|
|
116
|
+
await expect(freezeInvoicePdf(makeEm() as never, invoiceRow({ pdfAttachmentId: 'att-1' }))).resolves.toEqual({
|
|
117
|
+
attachmentId: 'att-1',
|
|
118
|
+
bytes: null,
|
|
119
|
+
})
|
|
120
|
+
expect(storeAttachment).not.toHaveBeenCalled()
|
|
121
|
+
await expect(freezeInvoicePdf(makeEm() as never, invoiceRow({ status: 'draft' }))).rejects.toThrow()
|
|
122
|
+
await expect(freezeInvoicePdf(makeEm() as never, invoiceRow({ testRun: true }))).rejects.toThrow()
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
it('falls back to a fresh render when the stored file is unreadable', async () => {
|
|
126
|
+
const spy = jest.spyOn(console, 'warn').mockImplementation(() => undefined)
|
|
127
|
+
const pdf = await getInvoicePdf(makeEm() as never, invoiceRow({ pdfAttachmentId: 'att-lost' }), { loadTranslator })
|
|
128
|
+
expect(pdf.frozen).toBe(true)
|
|
129
|
+
expect(renderInvoicePdf).toHaveBeenCalledTimes(1)
|
|
130
|
+
expect(storeAttachment).not.toHaveBeenCalled()
|
|
131
|
+
spy.mockRestore()
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
it('uses the organization logo only when it is one of our attachments', async () => {
|
|
135
|
+
const em = makeEm()
|
|
136
|
+
em.execute.mockResolvedValueOnce([{ logo_url: '/api/attachments/file/12345678-1234-4234-8234-123456789012' }])
|
|
137
|
+
;(readAttachment as jest.Mock).mockResolvedValueOnce({ bytes: new Uint8Array([9]), mimeType: 'image/png', fileName: 'l.png' })
|
|
138
|
+
await getInvoicePdf(em as never, invoiceRow({ status: 'draft' }), { loadTranslator })
|
|
139
|
+
expect(readAttachment).toHaveBeenCalledWith(em, scope, '12345678-1234-4234-8234-123456789012')
|
|
140
|
+
expect((renderInvoicePdf as jest.Mock).mock.calls[0][1]).toEqual({ logo: { bytes: new Uint8Array([9]), mimeType: 'image/png' } })
|
|
141
|
+
})
|
|
142
|
+
|
|
143
|
+
it('builds safe file names from document numbers', () => {
|
|
144
|
+
expect(pdfFileName({ number: 'INV/2026/11/0001' })).toBe('INV-2026-11-0001.pdf')
|
|
145
|
+
expect(pdfFileName({ number: 'FV 1/"x"' })).toBe('FV-1-x-.pdf')
|
|
146
|
+
})
|
|
147
|
+
})
|