@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,140 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
import * as React from 'react'
|
|
3
|
+
import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from '@open-mercato/ui/primitives/dialog'
|
|
4
|
+
import { Button } from '@open-mercato/ui/primitives/button'
|
|
5
|
+
import { Input } from '@open-mercato/ui/primitives/input'
|
|
6
|
+
import { Kbd, KbdShortcut } from '@open-mercato/ui/primitives/kbd'
|
|
7
|
+
import { useT } from '@open-mercato/shared/lib/i18n/context'
|
|
8
|
+
import { apiCallOrThrow } from '@open-mercato/ui/backend/utils/apiCall'
|
|
9
|
+
import { normalizeCrudServerError } from '@open-mercato/ui/backend/utils/serverErrors'
|
|
10
|
+
import { flash } from '@open-mercato/ui/backend/FlashMessages'
|
|
11
|
+
import { AccountPicker } from './AccountPicker'
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Manual payment entry (Spec C). With an account the payment is matched and
|
|
15
|
+
* applied as credit to the account's open invoices; without one it stays
|
|
16
|
+
* unmatched. `billAccountId` pre-selects the account (account page).
|
|
17
|
+
*/
|
|
18
|
+
export function ManualPaymentDialog({
|
|
19
|
+
open,
|
|
20
|
+
onClose,
|
|
21
|
+
onCreated,
|
|
22
|
+
billAccountId,
|
|
23
|
+
currencyCode,
|
|
24
|
+
}: {
|
|
25
|
+
open: boolean
|
|
26
|
+
onClose: () => void
|
|
27
|
+
onCreated: (paymentId: string) => void
|
|
28
|
+
billAccountId?: string
|
|
29
|
+
currencyCode?: string
|
|
30
|
+
}) {
|
|
31
|
+
const t = useT()
|
|
32
|
+
const today = new Date().toISOString().slice(0, 10)
|
|
33
|
+
const [receivedAt, setReceivedAt] = React.useState(today)
|
|
34
|
+
const [amount, setAmount] = React.useState('')
|
|
35
|
+
const [currency, setCurrency] = React.useState(currencyCode ?? 'PLN')
|
|
36
|
+
const [reference, setReference] = React.useState('')
|
|
37
|
+
const [payerName, setPayerName] = React.useState('')
|
|
38
|
+
const [accountId, setAccountId] = React.useState(billAccountId ?? '')
|
|
39
|
+
const [saving, setSaving] = React.useState(false)
|
|
40
|
+
|
|
41
|
+
React.useEffect(() => {
|
|
42
|
+
if (!open) return
|
|
43
|
+
setReceivedAt(new Date().toISOString().slice(0, 10))
|
|
44
|
+
setAmount('')
|
|
45
|
+
setReference('')
|
|
46
|
+
setPayerName('')
|
|
47
|
+
setAccountId(billAccountId ?? '')
|
|
48
|
+
setCurrency(currencyCode ?? 'PLN')
|
|
49
|
+
}, [billAccountId, currencyCode, open])
|
|
50
|
+
|
|
51
|
+
const submit = React.useCallback(async () => {
|
|
52
|
+
const value = Number.parseFloat(amount)
|
|
53
|
+
if (!(value > 0) || saving) {
|
|
54
|
+
flash(t('billing.payments.manual.amount_invalid', 'Amount must be greater than 0'), 'error')
|
|
55
|
+
return
|
|
56
|
+
}
|
|
57
|
+
setSaving(true)
|
|
58
|
+
try {
|
|
59
|
+
const call = await apiCallOrThrow<{ paymentId: string }>('/api/billing/payments', {
|
|
60
|
+
method: 'POST',
|
|
61
|
+
headers: { 'Content-Type': 'application/json' },
|
|
62
|
+
body: JSON.stringify({
|
|
63
|
+
receivedAt,
|
|
64
|
+
amount: value,
|
|
65
|
+
currencyCode: currency.trim().toUpperCase(),
|
|
66
|
+
...(reference.trim() ? { reference: reference.trim() } : {}),
|
|
67
|
+
...(payerName.trim() ? { payerName: payerName.trim() } : {}),
|
|
68
|
+
...(accountId ? { billAccountId: accountId } : {}),
|
|
69
|
+
}),
|
|
70
|
+
})
|
|
71
|
+
flash(t('billing.payments.manual.saved', 'Payment recorded'), 'success')
|
|
72
|
+
onClose()
|
|
73
|
+
if (call.result?.paymentId) onCreated(call.result.paymentId)
|
|
74
|
+
} catch (err) {
|
|
75
|
+
flash(normalizeCrudServerError(err).message || t('billing.payments.manual.failed', 'Could not record the payment'), 'error')
|
|
76
|
+
} finally {
|
|
77
|
+
setSaving(false)
|
|
78
|
+
}
|
|
79
|
+
}, [accountId, amount, currency, onClose, onCreated, payerName, receivedAt, reference, saving, t])
|
|
80
|
+
|
|
81
|
+
return (
|
|
82
|
+
<Dialog open={open} onOpenChange={(next) => (!next ? onClose() : undefined)}>
|
|
83
|
+
<DialogContent
|
|
84
|
+
onKeyDown={(event) => {
|
|
85
|
+
if ((event.metaKey || event.ctrlKey) && event.key === 'Enter') {
|
|
86
|
+
event.preventDefault()
|
|
87
|
+
void submit()
|
|
88
|
+
}
|
|
89
|
+
}}
|
|
90
|
+
>
|
|
91
|
+
<DialogHeader>
|
|
92
|
+
<DialogTitle>{t('billing.payments.manual.title', 'Record payment')}</DialogTitle>
|
|
93
|
+
</DialogHeader>
|
|
94
|
+
<div className="grid grid-cols-2 gap-3 py-2 text-sm">
|
|
95
|
+
<label className="flex flex-col gap-1">
|
|
96
|
+
<span className="text-muted-foreground">{t('billing.payments.columns.received', 'Received')}</span>
|
|
97
|
+
<Input type="date" value={receivedAt} onChange={(e) => setReceivedAt(e.currentTarget.value)} />
|
|
98
|
+
</label>
|
|
99
|
+
<label className="flex flex-col gap-1">
|
|
100
|
+
<span className="text-muted-foreground">{t('billing.payments.columns.amount', 'Amount')}</span>
|
|
101
|
+
<Input type="number" min="0" step="0.01" value={amount} onChange={(e) => setAmount(e.currentTarget.value)} />
|
|
102
|
+
</label>
|
|
103
|
+
<label className="flex flex-col gap-1">
|
|
104
|
+
<span className="text-muted-foreground">{t('billing.payments.fields.currency', 'Currency')}</span>
|
|
105
|
+
<Input value={currency} maxLength={3} disabled={Boolean(currencyCode)} onChange={(e) => setCurrency(e.currentTarget.value)} />
|
|
106
|
+
</label>
|
|
107
|
+
<label className="flex flex-col gap-1">
|
|
108
|
+
<span className="text-muted-foreground">{t('billing.payments.columns.payer', 'Payer')}</span>
|
|
109
|
+
<Input value={payerName} onChange={(e) => setPayerName(e.currentTarget.value)} />
|
|
110
|
+
</label>
|
|
111
|
+
<label className="col-span-2 flex flex-col gap-1">
|
|
112
|
+
<span className="text-muted-foreground">{t('billing.payments.columns.reference', 'Reference')}</span>
|
|
113
|
+
<Input value={reference} onChange={(e) => setReference(e.currentTarget.value)} />
|
|
114
|
+
</label>
|
|
115
|
+
{!billAccountId ? (
|
|
116
|
+
<div className="col-span-2 flex flex-col gap-1">
|
|
117
|
+
<span className="text-muted-foreground">{t('billing.payments.fields.account_optional', 'Billing account (optional)')}</span>
|
|
118
|
+
<AccountPicker value={accountId} onChange={setAccountId} currencyCode={currency.trim().toUpperCase()} billingMode="postpaid" />
|
|
119
|
+
</div>
|
|
120
|
+
) : null}
|
|
121
|
+
</div>
|
|
122
|
+
<DialogFooter>
|
|
123
|
+
<div className="flex w-full items-center justify-between gap-3">
|
|
124
|
+
<span className="text-xs text-muted-foreground">
|
|
125
|
+
<KbdShortcut keys={['Ctrl/⌘', 'Enter']} /> · <Kbd>Esc</Kbd>
|
|
126
|
+
</span>
|
|
127
|
+
<div className="flex items-center gap-2">
|
|
128
|
+
<Button type="button" variant="outline" onClick={onClose}>
|
|
129
|
+
{t('billing.common.cancel', 'Cancel')}
|
|
130
|
+
</Button>
|
|
131
|
+
<Button type="button" onClick={() => void submit()} disabled={saving}>
|
|
132
|
+
{t('billing.common.save', 'Save')}
|
|
133
|
+
</Button>
|
|
134
|
+
</div>
|
|
135
|
+
</div>
|
|
136
|
+
</DialogFooter>
|
|
137
|
+
</DialogContent>
|
|
138
|
+
</Dialog>
|
|
139
|
+
)
|
|
140
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
import * as React from 'react'
|
|
3
|
+
import { Input } from '@open-mercato/ui/primitives/input'
|
|
4
|
+
|
|
5
|
+
export type MoneyInputProps = Omit<React.ComponentProps<typeof Input>, 'type'> & {
|
|
6
|
+
/** ISO currency code shown as a read-only suffix; nothing is shown when empty. */
|
|
7
|
+
currencyCode?: string | null
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Number input with a read-only currency suffix (Spec F, F2). The currency
|
|
12
|
+
* comes from the parent Billing Account and is never editable here.
|
|
13
|
+
*/
|
|
14
|
+
export function MoneyInput({ currencyCode, className, ...inputProps }: MoneyInputProps) {
|
|
15
|
+
const code = currencyCode?.trim()
|
|
16
|
+
return (
|
|
17
|
+
<div className="relative">
|
|
18
|
+
<Input type="number" {...inputProps} className={code ? `pr-14 ${className ?? ''}` : className} />
|
|
19
|
+
{code ? (
|
|
20
|
+
<span className="pointer-events-none absolute inset-y-0 right-3 flex items-center text-xs font-medium text-muted-foreground">
|
|
21
|
+
{code}
|
|
22
|
+
</span>
|
|
23
|
+
) : null}
|
|
24
|
+
</div>
|
|
25
|
+
)
|
|
26
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
import * as React from 'react'
|
|
3
|
+
import {
|
|
4
|
+
Dialog,
|
|
5
|
+
DialogContent,
|
|
6
|
+
DialogDescription,
|
|
7
|
+
DialogFooter,
|
|
8
|
+
DialogHeader,
|
|
9
|
+
DialogTitle,
|
|
10
|
+
} from '@open-mercato/ui/primitives/dialog'
|
|
11
|
+
import { Button } from '@open-mercato/ui/primitives/button'
|
|
12
|
+
import { Input } from '@open-mercato/ui/primitives/input'
|
|
13
|
+
import { Kbd, KbdShortcut } from '@open-mercato/ui/primitives/kbd'
|
|
14
|
+
import { useT } from '@open-mercato/shared/lib/i18n/context'
|
|
15
|
+
import { apiCall } from '@open-mercato/ui/backend/utils/apiCall'
|
|
16
|
+
import { flash } from '@open-mercato/ui/backend/FlashMessages'
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Bank CSV upload (Spec C). Posts the file to `/api/billing/payments/import`
|
|
20
|
+
* and shows the batch summary (counts per outcome + first row errors).
|
|
21
|
+
* Cmd/Ctrl+Enter uploads, Escape closes.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
export type ImportSummary = {
|
|
25
|
+
importId: string
|
|
26
|
+
fileName: string
|
|
27
|
+
rowCount: number
|
|
28
|
+
counts: Record<string, number>
|
|
29
|
+
errors: Array<{ row: number; message: string }>
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const COUNT_KEYS = ['allocated', 'partially_allocated', 'matched', 'unmatched', 'duplicate', 'rejected'] as const
|
|
33
|
+
|
|
34
|
+
export function PaymentUploadDialog({
|
|
35
|
+
open,
|
|
36
|
+
onClose,
|
|
37
|
+
onImported,
|
|
38
|
+
}: {
|
|
39
|
+
open: boolean
|
|
40
|
+
onClose: () => void
|
|
41
|
+
onImported: (summary: ImportSummary) => void
|
|
42
|
+
}) {
|
|
43
|
+
const t = useT()
|
|
44
|
+
const [file, setFile] = React.useState<File | null>(null)
|
|
45
|
+
const [uploading, setUploading] = React.useState(false)
|
|
46
|
+
const [summary, setSummary] = React.useState<ImportSummary | null>(null)
|
|
47
|
+
|
|
48
|
+
React.useEffect(() => {
|
|
49
|
+
if (open) {
|
|
50
|
+
setFile(null)
|
|
51
|
+
setSummary(null)
|
|
52
|
+
}
|
|
53
|
+
}, [open])
|
|
54
|
+
|
|
55
|
+
const countLabel: Record<(typeof COUNT_KEYS)[number], string> = {
|
|
56
|
+
allocated: t('billing.payments.import.counts.allocated', 'Allocated'),
|
|
57
|
+
partially_allocated: t('billing.payments.import.counts.partially_allocated', 'Partially allocated'),
|
|
58
|
+
matched: t('billing.payments.import.counts.matched', 'Matched (credit)'),
|
|
59
|
+
unmatched: t('billing.payments.import.counts.unmatched', 'Unmatched'),
|
|
60
|
+
duplicate: t('billing.payments.import.counts.duplicate', 'Duplicates'),
|
|
61
|
+
rejected: t('billing.payments.import.counts.rejected', 'Rejected rows'),
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const upload = React.useCallback(async () => {
|
|
65
|
+
if (!file || uploading) return
|
|
66
|
+
setUploading(true)
|
|
67
|
+
try {
|
|
68
|
+
const form = new FormData()
|
|
69
|
+
form.set('file', file)
|
|
70
|
+
const call = await apiCall<ImportSummary & { error?: string }>('/api/billing/payments/import', { method: 'POST', body: form })
|
|
71
|
+
if (!call.ok || !call.result?.importId) {
|
|
72
|
+
flash(call.result?.error ?? t('billing.payments.import.failed', 'Import failed'), 'error')
|
|
73
|
+
return
|
|
74
|
+
}
|
|
75
|
+
setSummary(call.result)
|
|
76
|
+
onImported(call.result)
|
|
77
|
+
} finally {
|
|
78
|
+
setUploading(false)
|
|
79
|
+
}
|
|
80
|
+
}, [file, onImported, t, uploading])
|
|
81
|
+
|
|
82
|
+
return (
|
|
83
|
+
<Dialog open={open} onOpenChange={(next) => (!next ? onClose() : undefined)}>
|
|
84
|
+
<DialogContent
|
|
85
|
+
onKeyDown={(event) => {
|
|
86
|
+
if ((event.metaKey || event.ctrlKey) && event.key === 'Enter') {
|
|
87
|
+
event.preventDefault()
|
|
88
|
+
if (!summary) void upload()
|
|
89
|
+
else onClose()
|
|
90
|
+
}
|
|
91
|
+
}}
|
|
92
|
+
>
|
|
93
|
+
<DialogHeader>
|
|
94
|
+
<DialogTitle>{t('billing.payments.import.title', 'Upload bank payments')}</DialogTitle>
|
|
95
|
+
<DialogDescription>
|
|
96
|
+
{t(
|
|
97
|
+
'billing.payments.import.help',
|
|
98
|
+
'CSV with the header date,amount,currency,reference,payer_name,payer_account. Payments are matched by the invoice number in the reference.',
|
|
99
|
+
)}
|
|
100
|
+
</DialogDescription>
|
|
101
|
+
</DialogHeader>
|
|
102
|
+
{summary ? (
|
|
103
|
+
<div className="flex flex-col gap-3 text-sm">
|
|
104
|
+
<div className="text-muted-foreground">
|
|
105
|
+
{summary.fileName} · {t('billing.payments.import.rows', 'rows')}: {summary.rowCount}
|
|
106
|
+
</div>
|
|
107
|
+
<div className="grid grid-cols-2 gap-2">
|
|
108
|
+
{COUNT_KEYS.map((key) => (
|
|
109
|
+
<div key={key} className="flex items-center justify-between rounded-md border px-3 py-2">
|
|
110
|
+
<span className="text-muted-foreground">{countLabel[key]}</span>
|
|
111
|
+
<span className="font-medium tabular-nums">{summary.counts[key] ?? 0}</span>
|
|
112
|
+
</div>
|
|
113
|
+
))}
|
|
114
|
+
</div>
|
|
115
|
+
{summary.errors.length > 0 ? (
|
|
116
|
+
<div className="max-h-40 overflow-auto rounded-md border p-2 text-xs">
|
|
117
|
+
{summary.errors.slice(0, 20).map((error) => (
|
|
118
|
+
<div key={`${error.row}-${error.message}`}>
|
|
119
|
+
{t('billing.payments.import.line', 'Line')} {error.row}: {error.message}
|
|
120
|
+
</div>
|
|
121
|
+
))}
|
|
122
|
+
</div>
|
|
123
|
+
) : null}
|
|
124
|
+
</div>
|
|
125
|
+
) : (
|
|
126
|
+
<Input type="file" accept=".csv,text/csv" onChange={(event) => setFile(event.currentTarget.files?.[0] ?? null)} />
|
|
127
|
+
)}
|
|
128
|
+
<DialogFooter>
|
|
129
|
+
<div className="flex w-full items-center justify-between gap-3">
|
|
130
|
+
<span className="text-xs text-muted-foreground">
|
|
131
|
+
<KbdShortcut keys={['Ctrl/⌘', 'Enter']} /> · <Kbd>Esc</Kbd>
|
|
132
|
+
</span>
|
|
133
|
+
<div className="flex items-center gap-2">
|
|
134
|
+
<Button type="button" variant="outline" onClick={onClose}>
|
|
135
|
+
{summary ? t('billing.common.close', 'Close') : t('billing.common.cancel', 'Cancel')}
|
|
136
|
+
</Button>
|
|
137
|
+
{!summary ? (
|
|
138
|
+
<Button type="button" onClick={() => void upload()} disabled={!file || uploading}>
|
|
139
|
+
{uploading ? t('billing.payments.import.uploading', 'Uploading…') : t('billing.payments.import.action', 'Upload')}
|
|
140
|
+
</Button>
|
|
141
|
+
) : null}
|
|
142
|
+
</div>
|
|
143
|
+
</div>
|
|
144
|
+
</DialogFooter>
|
|
145
|
+
</DialogContent>
|
|
146
|
+
</Dialog>
|
|
147
|
+
)
|
|
148
|
+
}
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
import * as React from 'react'
|
|
3
|
+
import { useRouter } from 'next/navigation'
|
|
4
|
+
import type { LegacyColumnDef as ColumnDef } from '@tanstack/react-table/legacy'
|
|
5
|
+
import { useT } from '@open-mercato/shared/lib/i18n/context'
|
|
6
|
+
import type { FilterDef, FilterValues } from '@open-mercato/ui/backend/FilterBar'
|
|
7
|
+
import { BillingDataTable as DataTable } from './BillingDataTable'
|
|
8
|
+
import { Tag } from '@open-mercato/ui/primitives/tag'
|
|
9
|
+
import { readApiResultOrThrow } from '@open-mercato/ui/backend/utils/apiCall'
|
|
10
|
+
import { formatMoney } from './InvoicesTable'
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Billing payments table (Spec C) — shared by the Payments list page and the
|
|
14
|
+
* Payments section of a billing account. `billAccountId` / `importId` pin
|
|
15
|
+
* the list; row click opens the payment.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
export type PaymentRow = {
|
|
19
|
+
id: string
|
|
20
|
+
received_at: string
|
|
21
|
+
amount: string
|
|
22
|
+
currency_code: string
|
|
23
|
+
reference: string | null
|
|
24
|
+
payer_name: string | null
|
|
25
|
+
source: string
|
|
26
|
+
import_id: string | null
|
|
27
|
+
bill_account_id: string | null
|
|
28
|
+
bill_account_name: string | null
|
|
29
|
+
status: string
|
|
30
|
+
unallocated_amount: string
|
|
31
|
+
match_reason: string | null
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
type ListResponse = { items: PaymentRow[]; total: number; totalPages: number }
|
|
35
|
+
|
|
36
|
+
export const PAYMENT_STATUS_VARIANT: Record<string, 'success' | 'warning' | 'error' | 'neutral' | 'info' | 'default'> = {
|
|
37
|
+
allocated: 'success',
|
|
38
|
+
partially_allocated: 'info',
|
|
39
|
+
matched: 'info',
|
|
40
|
+
unmatched: 'warning',
|
|
41
|
+
ignored: 'neutral',
|
|
42
|
+
converted_to_topup: 'success',
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function usePaymentLabels() {
|
|
46
|
+
const t = useT()
|
|
47
|
+
return React.useMemo(
|
|
48
|
+
() => ({
|
|
49
|
+
status: (status: string) =>
|
|
50
|
+
({
|
|
51
|
+
unmatched: t('billing.payments.status.unmatched', 'Unmatched'),
|
|
52
|
+
matched: t('billing.payments.status.matched', 'Matched'),
|
|
53
|
+
partially_allocated: t('billing.payments.status.partially_allocated', 'Partially allocated'),
|
|
54
|
+
allocated: t('billing.payments.status.allocated', 'Allocated'),
|
|
55
|
+
ignored: t('billing.payments.status.ignored', 'Ignored'),
|
|
56
|
+
converted_to_topup: t('billing.payments.status.converted_to_topup', 'Converted to top-up'),
|
|
57
|
+
})[status] ?? status,
|
|
58
|
+
reason: (reason: string | null) =>
|
|
59
|
+
reason
|
|
60
|
+
? ({
|
|
61
|
+
no_reference: t('billing.payments.reason.no_reference', 'No invoice number found'),
|
|
62
|
+
currency_mismatch: t('billing.payments.reason.currency_mismatch', 'Currency differs from the invoice'),
|
|
63
|
+
invoice_already_paid: t('billing.payments.reason.invoice_already_paid', 'Invoice already paid — kept as credit'),
|
|
64
|
+
prepaid_account: t('billing.payments.reason.prepaid_account', 'Prepaid account — convert to a top-up'),
|
|
65
|
+
manual: t('billing.payments.reason.manual', 'Entered or assigned manually'),
|
|
66
|
+
})[reason] ?? reason
|
|
67
|
+
: '—',
|
|
68
|
+
}),
|
|
69
|
+
[t],
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export type PaymentsTableProps = {
|
|
74
|
+
title: string
|
|
75
|
+
tableId: string
|
|
76
|
+
billAccountId?: string
|
|
77
|
+
importId?: string
|
|
78
|
+
pageSize?: number
|
|
79
|
+
/** Bumped by the host to force a reload (e.g. after an upload). */
|
|
80
|
+
reloadKey?: number
|
|
81
|
+
actions?: React.ReactNode
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function PaymentsTable({ title, tableId, billAccountId, importId, pageSize = 25, reloadKey = 0, actions }: PaymentsTableProps) {
|
|
85
|
+
const t = useT()
|
|
86
|
+
const router = useRouter()
|
|
87
|
+
const labels = usePaymentLabels()
|
|
88
|
+
const [rows, setRows] = React.useState<PaymentRow[]>([])
|
|
89
|
+
const [page, setPage] = React.useState(1)
|
|
90
|
+
const [filters, setFilters] = React.useState<FilterValues>({})
|
|
91
|
+
const [search, setSearch] = React.useState('')
|
|
92
|
+
const [total, setTotal] = React.useState(0)
|
|
93
|
+
const [totalPages, setTotalPages] = React.useState(1)
|
|
94
|
+
const [loading, setLoading] = React.useState(true)
|
|
95
|
+
const [error, setError] = React.useState<string | null>(null)
|
|
96
|
+
|
|
97
|
+
const filterDefs = React.useMemo<FilterDef[]>(
|
|
98
|
+
() => [
|
|
99
|
+
{
|
|
100
|
+
id: 'status',
|
|
101
|
+
label: t('billing.payments.filters.status', 'Status'),
|
|
102
|
+
type: 'select',
|
|
103
|
+
options: ['unmatched', 'matched', 'partially_allocated', 'allocated', 'ignored', 'converted_to_topup'].map((value) => ({
|
|
104
|
+
value,
|
|
105
|
+
label: labels.status(value),
|
|
106
|
+
})),
|
|
107
|
+
},
|
|
108
|
+
],
|
|
109
|
+
[labels, t],
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
const load = React.useCallback(async () => {
|
|
113
|
+
setLoading(true)
|
|
114
|
+
setError(null)
|
|
115
|
+
try {
|
|
116
|
+
const params = new URLSearchParams({ page: String(page), pageSize: String(Math.min(pageSize, 100)) })
|
|
117
|
+
if (billAccountId) params.set('billAccountId', billAccountId)
|
|
118
|
+
if (importId) params.set('importId', importId)
|
|
119
|
+
if (search.trim()) params.set('search', search.trim())
|
|
120
|
+
if (typeof filters.status === 'string' && filters.status) params.set('status', filters.status)
|
|
121
|
+
const result = await readApiResultOrThrow<ListResponse>(`/api/billing/payments?${params.toString()}`)
|
|
122
|
+
setRows(result.items ?? [])
|
|
123
|
+
setTotal(result.total ?? 0)
|
|
124
|
+
setTotalPages(result.totalPages ?? 1)
|
|
125
|
+
} catch (err) {
|
|
126
|
+
setError(err instanceof Error ? err.message : t('billing.payments.error.load', 'Could not load payments'))
|
|
127
|
+
} finally {
|
|
128
|
+
setLoading(false)
|
|
129
|
+
}
|
|
130
|
+
// reloadKey forces a refetch from the host.
|
|
131
|
+
}, [billAccountId, filters.status, importId, page, pageSize, search, t, reloadKey]) // eslint-disable-line react-hooks/exhaustive-deps
|
|
132
|
+
|
|
133
|
+
React.useEffect(() => {
|
|
134
|
+
void load()
|
|
135
|
+
}, [load])
|
|
136
|
+
|
|
137
|
+
const columns = React.useMemo<ColumnDef<PaymentRow>[]>(() => {
|
|
138
|
+
const cols: ColumnDef<PaymentRow>[] = [
|
|
139
|
+
{
|
|
140
|
+
accessorKey: 'received_at',
|
|
141
|
+
header: t('billing.payments.columns.received', 'Received'),
|
|
142
|
+
cell: ({ row }) => row.original.received_at?.slice(0, 10) ?? '—',
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
accessorKey: 'amount',
|
|
146
|
+
header: t('billing.payments.columns.amount', 'Amount'),
|
|
147
|
+
cell: ({ row }) => formatMoney(row.original.amount, row.original.currency_code),
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
accessorKey: 'status',
|
|
151
|
+
header: t('billing.payments.columns.status', 'Status'),
|
|
152
|
+
cell: ({ row }) => <Tag variant={PAYMENT_STATUS_VARIANT[row.original.status] ?? 'default'}>{labels.status(row.original.status)}</Tag>,
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
accessorKey: 'unallocated_amount',
|
|
156
|
+
header: t('billing.payments.columns.unallocated', 'Unallocated'),
|
|
157
|
+
cell: ({ row }) => formatMoney(row.original.unallocated_amount, row.original.currency_code),
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
accessorKey: 'reference',
|
|
161
|
+
header: t('billing.payments.columns.reference', 'Reference'),
|
|
162
|
+
cell: ({ row }) => row.original.reference ?? '—',
|
|
163
|
+
meta: { truncate: true, maxWidth: '260px' },
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
accessorKey: 'payer_name',
|
|
167
|
+
header: t('billing.payments.columns.payer', 'Payer'),
|
|
168
|
+
cell: ({ row }) => row.original.payer_name ?? '—',
|
|
169
|
+
meta: { truncate: true, maxWidth: '180px' },
|
|
170
|
+
},
|
|
171
|
+
]
|
|
172
|
+
if (!billAccountId) {
|
|
173
|
+
cols.splice(3, 0, {
|
|
174
|
+
accessorKey: 'bill_account_name',
|
|
175
|
+
header: t('billing.payments.columns.account', 'Account'),
|
|
176
|
+
cell: ({ row }) => row.original.bill_account_name ?? '—',
|
|
177
|
+
meta: { truncate: true, maxWidth: '200px' },
|
|
178
|
+
})
|
|
179
|
+
}
|
|
180
|
+
return cols
|
|
181
|
+
}, [billAccountId, labels, t])
|
|
182
|
+
|
|
183
|
+
return (
|
|
184
|
+
<DataTable
|
|
185
|
+
title={title}
|
|
186
|
+
actions={actions}
|
|
187
|
+
refreshButton={{ label: t('billing.common.refresh', 'Refresh'), onRefresh: load, isRefreshing: loading }}
|
|
188
|
+
perspective={{ tableId }}
|
|
189
|
+
columns={columns}
|
|
190
|
+
data={rows}
|
|
191
|
+
error={error}
|
|
192
|
+
emptyState={t('billing.payments.empty', 'No payments yet.')}
|
|
193
|
+
isLoading={loading}
|
|
194
|
+
onRowClick={(row) => router.push(`/backend/billing/payments/${encodeURIComponent(row.id)}`)}
|
|
195
|
+
pagination={{ page, pageSize, total, totalPages, onPageChange: setPage }}
|
|
196
|
+
filters={filterDefs}
|
|
197
|
+
filterValues={filters}
|
|
198
|
+
onFiltersApply={(next) => {
|
|
199
|
+
setPage(1)
|
|
200
|
+
setFilters(next)
|
|
201
|
+
}}
|
|
202
|
+
onFiltersClear={() => {
|
|
203
|
+
setPage(1)
|
|
204
|
+
setFilters({})
|
|
205
|
+
}}
|
|
206
|
+
searchValue={search}
|
|
207
|
+
onSearchChange={(next) => {
|
|
208
|
+
setPage(1)
|
|
209
|
+
setSearch(next)
|
|
210
|
+
}}
|
|
211
|
+
/>
|
|
212
|
+
)
|
|
213
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
import * as React from 'react'
|
|
3
|
+
import { Send } from 'lucide-react'
|
|
4
|
+
import { useT } from '@open-mercato/shared/lib/i18n/context'
|
|
5
|
+
import { Button } from '@open-mercato/ui/primitives/button'
|
|
6
|
+
import { flash } from '@open-mercato/ui/backend/FlashMessages'
|
|
7
|
+
import { useConfirmDialog } from '@open-mercato/ui/backend/confirm-dialog'
|
|
8
|
+
import { apiCallOrThrow, readApiResultOrThrow } from '@open-mercato/ui/backend/utils/apiCall'
|
|
9
|
+
import { normalizeCrudServerError } from '@open-mercato/ui/backend/utils/serverErrors'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* "Post invoices" for a REAL Bill Run: posts every draft invoice the run
|
|
13
|
+
* wrote. Batches through `POST /api/billing/runs/{id}/post-drafts` (cursor
|
|
14
|
+
* paging) so large runs never become one long request, showing progress on
|
|
15
|
+
* the button. Renders nothing when the run has no drafts left.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
type BatchResult = {
|
|
19
|
+
posted: number
|
|
20
|
+
failed: Array<{ invoiceId: string; number: string; error: string; code: string | null }>
|
|
21
|
+
nextCursor: string | null
|
|
22
|
+
remaining: number
|
|
23
|
+
stoppedReason: string | null
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const BATCH_SIZE = 25
|
|
27
|
+
|
|
28
|
+
export function PostRunDraftsButton({ runId, onPosted }: { runId: string; onPosted: () => void }) {
|
|
29
|
+
const t = useT()
|
|
30
|
+
const { confirm, ConfirmDialogElement } = useConfirmDialog()
|
|
31
|
+
const [draftCount, setDraftCount] = React.useState<number | null>(null)
|
|
32
|
+
const [progress, setProgress] = React.useState<{ done: number; total: number } | null>(null)
|
|
33
|
+
|
|
34
|
+
const loadCount = React.useCallback(async () => {
|
|
35
|
+
try {
|
|
36
|
+
const params = new URLSearchParams({ billRunId: runId, status: 'draft', testRun: 'false', pageSize: '1' })
|
|
37
|
+
const result = await readApiResultOrThrow<{ total?: number }>(`/api/billing/invoices?${params.toString()}`)
|
|
38
|
+
setDraftCount(result.total ?? 0)
|
|
39
|
+
} catch {
|
|
40
|
+
setDraftCount(0)
|
|
41
|
+
}
|
|
42
|
+
}, [runId])
|
|
43
|
+
|
|
44
|
+
React.useEffect(() => {
|
|
45
|
+
void loadCount()
|
|
46
|
+
}, [loadCount])
|
|
47
|
+
|
|
48
|
+
const handlePost = React.useCallback(async () => {
|
|
49
|
+
if (!draftCount) return
|
|
50
|
+
const ok = await confirm({
|
|
51
|
+
title: t('billing.runs.post.confirm.title', 'Post the draft invoices of this run?'),
|
|
52
|
+
text: `${t(
|
|
53
|
+
'billing.runs.post.confirm.text',
|
|
54
|
+
'Each draft gets its final number, due date and frozen PDF; invoices set to auto-send are emailed. Posted invoices cannot be edited. Drafts:',
|
|
55
|
+
)} ${draftCount}`,
|
|
56
|
+
confirmText: t('billing.runs.post.confirm.button', 'Post invoices'),
|
|
57
|
+
})
|
|
58
|
+
if (!ok) return
|
|
59
|
+
const total = draftCount
|
|
60
|
+
let done = 0
|
|
61
|
+
let posted = 0
|
|
62
|
+
const failed: BatchResult['failed'] = []
|
|
63
|
+
let cursor: string | null = null
|
|
64
|
+
let stoppedReason: string | null = null
|
|
65
|
+
setProgress({ done, total })
|
|
66
|
+
try {
|
|
67
|
+
// Bounded by the draft count: every batch advances the cursor or stops.
|
|
68
|
+
for (let guard = 0; guard <= Math.ceil(total / BATCH_SIZE) + 1; guard += 1) {
|
|
69
|
+
const call: { result?: BatchResult | null } = await apiCallOrThrow<BatchResult>(
|
|
70
|
+
`/api/billing/runs/${encodeURIComponent(runId)}/post-drafts`,
|
|
71
|
+
{
|
|
72
|
+
method: 'POST',
|
|
73
|
+
headers: { 'Content-Type': 'application/json' },
|
|
74
|
+
body: JSON.stringify({ limit: BATCH_SIZE, ...(cursor ? { afterInvoiceId: cursor } : {}) }),
|
|
75
|
+
},
|
|
76
|
+
)
|
|
77
|
+
const batch = call.result
|
|
78
|
+
if (!batch) break
|
|
79
|
+
posted += batch.posted
|
|
80
|
+
failed.push(...batch.failed)
|
|
81
|
+
done += batch.posted + batch.failed.length
|
|
82
|
+
setProgress({ done: Math.min(done, total), total })
|
|
83
|
+
if (batch.stoppedReason) {
|
|
84
|
+
stoppedReason = batch.stoppedReason
|
|
85
|
+
break
|
|
86
|
+
}
|
|
87
|
+
if (batch.remaining === 0 || !batch.nextCursor || batch.nextCursor === cursor) break
|
|
88
|
+
cursor = batch.nextCursor
|
|
89
|
+
}
|
|
90
|
+
if (stoppedReason === 'billing.settings.incomplete') {
|
|
91
|
+
flash(
|
|
92
|
+
t('billing.invoices.post.settings_incomplete', 'Fill in the seller details in Settings → Billing before posting invoices.'),
|
|
93
|
+
'error',
|
|
94
|
+
)
|
|
95
|
+
} else if (failed.length > 0) {
|
|
96
|
+
const sample = failed
|
|
97
|
+
.slice(0, 3)
|
|
98
|
+
.map((f) => `${f.number}: ${f.error}`)
|
|
99
|
+
.join('; ')
|
|
100
|
+
flash(
|
|
101
|
+
`${t('billing.runs.post.partial', 'Posted')} ${posted} · ${t('billing.runs.post.failed', 'failed')} ${failed.length} — ${sample}`,
|
|
102
|
+
'warning',
|
|
103
|
+
)
|
|
104
|
+
} else {
|
|
105
|
+
flash(`${t('billing.runs.post.success', 'Invoices posted')}: ${posted}`, 'success')
|
|
106
|
+
}
|
|
107
|
+
} catch (err) {
|
|
108
|
+
const { message } = normalizeCrudServerError(err)
|
|
109
|
+
flash(message || t('billing.runs.post.error', 'Posting failed'), 'error')
|
|
110
|
+
} finally {
|
|
111
|
+
setProgress(null)
|
|
112
|
+
void loadCount()
|
|
113
|
+
onPosted()
|
|
114
|
+
}
|
|
115
|
+
}, [confirm, draftCount, onPosted, runId, t])
|
|
116
|
+
|
|
117
|
+
if (!draftCount && !progress) return ConfirmDialogElement
|
|
118
|
+
return (
|
|
119
|
+
<>
|
|
120
|
+
<Button type="button" onClick={() => void handlePost()} disabled={progress !== null}>
|
|
121
|
+
<Send size={16} />
|
|
122
|
+
{progress
|
|
123
|
+
? `${t('billing.runs.post.in_progress', 'Posting…')} ${progress.done}/${progress.total}`
|
|
124
|
+
: `${t('billing.runs.post.action', 'Post invoices')} (${draftCount})`}
|
|
125
|
+
</Button>
|
|
126
|
+
{ConfirmDialogElement}
|
|
127
|
+
</>
|
|
128
|
+
)
|
|
129
|
+
}
|