feat: implement set-based invoice payment calculations and enhance email logging configuration
Playwright Tests / test (push) Canceled after 0s

This commit is contained in:
Stefan
2026-09-16 22:31:27 +02:00
parent 944a5bb442
commit 86f6a60860
8 changed files with 268 additions and 12 deletions
@@ -0,0 +1,31 @@
-- =============================================
-- One-off data migration (fis_widgets rows are data, not schema — run once per environment
-- after deploying the schema that adds [dbo].[fds__fn_InvoicePaymentAmounts] and the
-- [PaymentAmount]/[OpenAmount] columns of [dbo].[fds__fn_unpaidInvoices]).
--
-- Both widgets called the scalar [fds__fn_InvoicePaymentAmount](Id) once per invoice row. That
-- function declares a table variable, so SQL Server cannot inline it and re-runs the whole
-- banking TVF per row (~0.5 s each): wdg_invoices_overdue_sum took ~100 s over 187 unpaid
-- invoices and timed out the 90 s widget command; wdg_unbez_akonto took ~5 s (hidden by daycache).
-- Set-based replacements give identical totals in < 0.5 s.
-- Idempotent: each UPDATE only rewrites the old text and is a no-op once applied.
-- =============================================
SET NOCOUNT ON;
UPDATE [dbo].[fis_widgets]
SET [sql] = REPLACE([sql], N'[invoicebalance] - [dbo].[fds__fn_InvoicePaymentAmount](Id)', N'[OpenAmount]')
WHERE [short_name] = 'wdg_invoices_overdue_sum'
AND [sql] LIKE N'%[[]dbo].[[]fds__fn_InvoicePaymentAmount](Id)%';
PRINT CONCAT('wdg_invoices_overdue_sum rows updated: ', @@ROWCOUNT);
UPDATE [dbo].[fis_widgets]
SET [sql] = REPLACE(REPLACE([sql]
, N'[dbo].[fds__fn_InvoicePaymentAmount]([id])', N'ISNULL(pay.[Amount], 0.0)')
, N'FROM [dbo].[fds__invoices] as i where', N'FROM [dbo].[fds__invoices] as i LEFT JOIN [dbo].[fds__fn_InvoicePaymentAmounts]() as pay ON pay.[InvId] = i.[id] where')
WHERE [short_name] = 'wdg_unbez_akonto'
AND [sql] LIKE N'%[[]dbo].[[]fds__fn_InvoicePaymentAmount]([[]id])%'
AND [sql] LIKE N'%FROM [[]dbo].[[]fds__invoices] as i where%';
PRINT CONCAT('wdg_unbez_akonto rows updated: ', @@ROWCOUNT);
-- Verify: nothing on the dashboard still calls the per-row scalar function.
SELECT [short_name], [sql] FROM [dbo].[fis_widgets] WHERE [sql] LIKE N'%fds__fn_InvoicePaymentAmount](%';