Files
Stefan 10ecdfa2e4 Add Fuchs_Database SSDT project (schema source of truth)
Adds the SQL Server Data Tools project for the fuchs_fds database — tables,
table types, functions and stored procedures that the backend calls (e.g.
fds__getInvoice, fds__merge_bankingtransactions, fds__tt__bankingtransactions,
fds__admin_getReportCatalog, fis_* auth). Build/model caches (bin, obj,
*.dbmdl, *.jfm, *.user) are git-ignored.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-05 14:50:54 +02:00

64 lines
2.1 KiB
Transact-SQL

-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[fds__r_getBalanceTrendByMonth]
@year int
,@month int,
@authuser varchar(100)
AS
BEGIN
SET NOCOUNT ON;
DECLARE @today date = GETDATE()
DECLARE @tomorrow date = DATEADD(DAY,1,@today);
IF [dbo].[fis_getModuleAuth]('fds_reports', @authuser) < 2
THROW 60000, N'not authorized', 1;
set @month = ISNULL(@month, Month(@today));
set @year= ISNULL(@year, Year(@year));
DECLARE @Admin [dbo].[fds__tt__admin_ReportAdminTable];
--Admin Table
INSERT INTO @Admin
VALUES (
'bbm'
,'UmsatzTrend für Monat ' + FORMAT(@Month, '00') + ' / ' + FORMAT(@year, '0000')
,'UmsatzTrend für Monat ' + FORMAT(@Month, '00') + ' / ' + FORMAT(@year, '0000')
,'' + FORMAT(GETDATE(), 'yyyy-MM-dd HH:mm')
,''
,'chart' --typ
, '{ "charttype": "line", "x1_label_angle": -90, "color": "e0301e", "linewidth": 2, "valuelabels": false, "marker": "none", "colorpalette": "00B050;00B050;00B050", "x1_column": "date", "y1_column": "Value", "y1_title": "Actuals", "x1_title": "", "series_column": "series", "legend_position": "bottom", "show_datalabel": true, "datalabelfontsizescale": 0.6, "height": 600, "width": 1200, "x1_labelformat": "ddd, dd/MM"}' --settings
, ''
, 0)
SELECT * FROM @Admin;
with inv as(
select
[InvoiceBalance] = SUM( ISNULL(_i.[InvoiceBalance],0) )
,[Dateofcreation] = CAST([Datecreated] as date)
,[seq] = ROW_NUMBER() OVER (ORDER BY CAST([Datecreated] as date))
FROM [dbo].[fds__invoices] as _i where _i.IsFinal = 1 and month([Datecreated]) = @Month and YEAR([Datecreated]) = @year
GROUP BY CAST([Datecreated] as date)
)
SELECT
--[Monat] = FORMAT( inv.[Dateofcreation], 'yyyy - MM', 'de')
--,[Umsatz] = FORMAT( ISNULL(inv.[InvoiceBalance],0) , '#0.00', 'de')
[series] = 'Umsatz'
,[date] = CAST(inv.[Dateofcreation] as date)
,[value] = CAST( SUM( ISNULL(inv.[InvoiceBalance],0) ) OVER (ORDER BY [seq]) as numeric(9,2))
FROM inv
ORDER BY [seq]
END