Move fis widgets SQL into scalar functions
Playwright Tests / test (push) Waiting to run

Add fis_wdg_* table functions for dashboard widgets and wire them into
FuchsDatabase.sqlproj; update the invoice list procs accordingly.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Stefan
2026-10-16 11:35:28 +02:00
co-authored by Copilot
parent a39ccb8bbc
commit 330c33e65d
20 changed files with 307 additions and 13 deletions
@@ -0,0 +1,55 @@
-- =============================================
-- One-off data migration: move the inline SQL of the sql_indicator / sql_table widgets in
-- [dbo].[fis_widgets] into the SSDT-tracked inline TVFs [dbo].[fis_wdg_*] (so the SQL is
-- compiled/validated by the database build) and replace [sql] with a minimal call.
-- Run once per environment AFTER deploying the schema containing the fis_wdg_* functions.
-- Idempotent. Old values are kept in #fis_widgets_sql_backup for the session.
-- =============================================
SET NOCOUNT ON;
SET XACT_ABORT ON;
SELECT [short_name], [sql] INTO #fis_widgets_sql_backup FROM [dbo].[fis_widgets] WHERE [type] IN ('sql_indicator', 'sql_table');
BEGIN TRANSACTION;
UPDATE [dbo].[fis_widgets] SET [sql] = N'SELECT * FROM [dbo].[fis_wdg_balance_net_thismonth](@authuser);' WHERE [short_name] = 'wdg_balance_net_thismonth';
PRINT CONCAT('wdg_balance_net_thismonth: ', @@ROWCOUNT);
UPDATE [dbo].[fis_widgets] SET [sql] = N'SELECT * FROM [dbo].[fis_wdg_bankingupload]();' WHERE [short_name] = 'wdg_bankingupload';
PRINT CONCAT('wdg_bankingupload: ', @@ROWCOUNT);
UPDATE [dbo].[fis_widgets] SET [sql] = N'SELECT * FROM [dbo].[fis_wdg_invoices_overdue]();' WHERE [short_name] = 'wdg_invoices_overdue';
PRINT CONCAT('wdg_invoices_overdue: ', @@ROWCOUNT);
UPDATE [dbo].[fis_widgets] SET [sql] = N'SELECT * FROM [dbo].[fis_wdg_invoices_overdue_sum]();' WHERE [short_name] = 'wdg_invoices_overdue_sum';
PRINT CONCAT('wdg_invoices_overdue_sum: ', @@ROWCOUNT);
UPDATE [dbo].[fis_widgets] SET [sql] = N'SELECT * FROM [dbo].[fis_wdg_invoices_reminded_fds]();' WHERE [short_name] = 'wdg_invoices_reminded_fds';
PRINT CONCAT('wdg_invoices_reminded_fds: ', @@ROWCOUNT);
UPDATE [dbo].[fis_widgets] SET [sql] = N'SELECT * FROM [dbo].[fis_wdg_invoices_today]();' WHERE [short_name] = 'wdg_invoices_today';
PRINT CONCAT('wdg_invoices_today: ', @@ROWCOUNT);
UPDATE [dbo].[fis_widgets] SET [sql] = N'SELECT * FROM [dbo].[fis_wdg_invoices_unpaid]();' WHERE [short_name] = 'wdg_invoices_unpaid';
PRINT CONCAT('wdg_invoices_unpaid: ', @@ROWCOUNT);
UPDATE [dbo].[fis_widgets] SET [sql] = N'SELECT * FROM [dbo].[fis_wdg_invoices_yesterday]();' WHERE [short_name] = 'wdg_invoices_yesterday';
PRINT CONCAT('wdg_invoices_yesterday: ', @@ROWCOUNT);
UPDATE [dbo].[fis_widgets] SET [sql] = N'SELECT * FROM [dbo].[fis_wdg_reminder_open10wd]();' WHERE [short_name] = 'wdg_reminder_open10wd';
PRINT CONCAT('wdg_reminder_open10wd: ', @@ROWCOUNT);
UPDATE [dbo].[fis_widgets] SET [sql] = N'SELECT * FROM [dbo].[fis_wdg_requests_today]();' WHERE [short_name] = 'wdg_requests_today';
PRINT CONCAT('wdg_requests_today: ', @@ROWCOUNT);
UPDATE [dbo].[fis_widgets] SET [sql] = N'SELECT * FROM [dbo].[fis_wdg_requestsforinvoice]();' WHERE [short_name] = 'wdg_requestsforinvoice';
PRINT CONCAT('wdg_requestsforinvoice: ', @@ROWCOUNT);
UPDATE [dbo].[fis_widgets] SET [sql] = N'SELECT * FROM [dbo].[fis_wdg_unbez_akonto]();' WHERE [short_name] = 'wdg_unbez_akonto';
PRINT CONCAT('wdg_unbez_akonto: ', @@ROWCOUNT);
-- Separate variant: wdg_invoices_reminded_fds now counts overdue invoices WITH a reminder (as its
-- name/label say); the former behaviour (overdue invoices WITHOUT a reminder) moves to the new
-- widget wdg_invoices_unreminded_fds, cloned from the existing row (subscriptions are not copied).
UPDATE [dbo].[fis_widgets] SET [sql] = N'SELECT * FROM [dbo].[fis_wdg_invoices_reminded_fds]();' WHERE [short_name] = 'wdg_invoices_reminded_fds';
INSERT INTO [dbo].[fis_widgets] ([short_name], [account], [type], [name], [description], [sql], [sql_admin_columns], [sql_datatypes], [url], [html], [visible_groups], [visible], [auth_module], [rendering_options], [server_options], [daycache], [personalized], [safemode], [variables])
SELECT 'wdg_invoices_unreminded_fds', [account], [type], N'Überfällige, ungemahnte Rechnungen (Intranet)', [description], N'SELECT * FROM [dbo].[fis_wdg_invoices_unreminded_fds]();', [sql_admin_columns], [sql_datatypes], [url], [html], [visible_groups], [visible], [auth_module], [rendering_options], [server_options], [daycache], [personalized], [safemode], [variables]
FROM [dbo].[fis_widgets]
WHERE [short_name] = 'wdg_invoices_reminded_fds'
AND NOT EXISTS (SELECT 0 FROM [dbo].[fis_widgets] WHERE [short_name] = 'wdg_invoices_unreminded_fds');
PRINT CONCAT('wdg_invoices_unreminded_fds inserted: ', @@ROWCOUNT);
COMMIT TRANSACTION;
-- Verify
SELECT [short_name], [type], [sql] FROM [dbo].[fis_widgets] WHERE [type] IN ('sql_indicator', 'sql_table') ORDER BY [short_name];