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,20 @@
-- =============================================
-- Description: Dashboard widget 'wdg_unbez_akonto' (Unbezahlte Akontos älter als 5 Arbeitstage (ohne MFR !)).
-- Called from [dbo].[fis_widgets].[sql] as: SELECT * FROM [dbo].[fis_wdg_unbez_akonto]()
-- =============================================
CREATE FUNCTION [dbo].[fis_wdg_unbez_akonto]()
RETURNS TABLE
AS
RETURN
(
SELECT [Rechnung] = i.[invoiceId]
, [Name] = i.[InvoiceTitle] + CHAR(10) + ' (' + (SELECT TOP (1) c.[name] FROM [dbo].[mfr__companies] AS c WHERE i.[customerid] = c.[id]) + ')'
, [Betrag (net)] = FORMAT(i.[invoicebalance], N'#0.00€', 'de')
, [Datum] = FORMAT(i.[DateFinalized], 'dd.MM.yy', 'de')
, [Zahlungen] = FORMAT(ISNULL(pay.[Amount], 0.0), N'#0.00€', 'de')
, [order] = ROW_NUMBER() OVER (ORDER BY i.[DateFinalized], i.[DateSent])
FROM [dbo].[fds__invoices] AS i
LEFT JOIN [dbo].[fds__fn_InvoicePaymentAmounts]() AS pay ON pay.[InvId] = i.[id]
WHERE i.[InvoiceType] = 'i' AND i.[IsPayed] = 0 AND i.[iscanceled] = 0
AND i.[DateFinalized] < [dbo].[date_add](GETDATE(), '-5wd', 0)
);