Files
Fuchs_Intranet/Fuchs_Database/dbo/Functions/fis_wdg_requests_today.sql
T
StefanandCopilot 330c33e65d
Playwright Tests / test (push) Waiting to run
Move fis widgets SQL into scalar functions
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>
2026-10-16 11:35:28 +02:00

21 lines
995 B
Transact-SQL

-- =============================================
-- Description: Dashboard widget 'wdg_requests_today' (Aufträge terminiert für heute).
-- Called from [dbo].[fis_widgets].[sql] as: SELECT * FROM [dbo].[fis_wdg_requests_today]()
-- =============================================
CREATE FUNCTION [dbo].[fis_wdg_requests_today]()
RETURNS TABLE
AS
RETURN
(
WITH osrq AS (
SELECT s.[id], s.[name], s.[externalid], s.[customerId]
, [last_appointment] = MAX(CAST(a.[startdatetime] as date)), [#a] = COUNT(*)
FROM [dbo].[mfr__servicerequests] AS s
JOIN [dbo].[mfr__appointments] AS a ON s.[id] = a.[ServiceRequestId]
WHERE s.[state] IN ('Scheduled', 'Released', 'InProgress')
GROUP BY s.[id], s.[name], s.[externalid], s.[customerId])
SELECT [Nummer] = [externalid], [Auftrag] = [name], [Kunde] = [dbo].[fds__getCompanyName]([customerId])
FROM osrq
WHERE [last_appointment] = CAST(GETDATE() as date)
);