﻿<?xml version="1.0" encoding="utf-8"?>
<ReportsExport>
  <Reports>
    <Report id="98233e9e-a83d-4278-b977-147dfe11b3b2" codekey="ERGO_e-Campus_Schnittstelle_SAP_HCM" categoryCodekey="UserStats" name="ERGO e-Campus Schnittstelle SAP HCM" description="">
      <MetaData created="2024-10-30T11:01:56" createdBy="Rolle, Administrator (Administrator)" createdBy_user_id="12" modified="2024-11-07T14:48:44" modifiedBy="Rolle, Administrator (Administrator)" modifiedBy_user_id="12" />
      <ExecutionDetails format="TableResult" commandType="SqlCommandOrQuery" exportHandler="" adminControl="" exportMultipleTablesToSheets="False" datesWithTime="False" extraParams="" />
      <Mandators mandatorMode="OnlyOwner" mandator_id="bfa70f6b-484c-49da-9ad7-1ccd8f0d684c" mandatorName="ERGO_e-Campus" isStandard="False" isUsedByMenu="False" />
      <Parameters>
        <Parameter id="2128c559-f147-4f64-ae0b-292b1ca7005f" isRequired="False" allowMultiSelect="False" name="Month" contextName="Monat" defaultValue="1" renderHint="DropDownList" disableParameter="DontDisable" />
        <Parameter id="d8e4595f-8bdd-4a54-9298-8f378450e6a0" isRequired="False" allowMultiSelect="False" name="Zeitraum" contextName="Auswertungszeitraum " defaultValue="" renderHint="Undefined" disableParameter="DontDisable" />
      </Parameters>
      <Roles>
        <Role id="90" />
      </Roles>
      <command>-- test data, if date range is set, month is ignored
--DECLARE @dateRange_start DATETIME = '2025-02-01'
--DECLARE @dateRange_end DATETIME = '2025-04-01'
--DECLARE @month INT = 7;


	  
DECLARE @now DATETIME = GETDATE();

DECLARE @year INT = 
IIF(@dateRange_start IS NULL OR @dateRange_end IS NULL,
	IIF(@month &lt; MONTH(@now), YEAR(@now), YEAR(@now) - 1),
	YEAR(@dateRange_start)
);

-- explicit start date, if both dates are set; beginning of the year based on the month, otherwise
DECLARE @startDate DATETIME = IIF(@dateRange_start IS NULL OR @dateRange_end IS NULL, DATEFROMPARTS(@year, 1, 1), @dateRange_start);

-- beginning of the next month, which might be next year
DECLARE @endDate DATETIME =
IIF(@dateRange_start IS NULL OR @dateRange_end IS NULL,
	IIF(
		@month = 12,
		DATEFROMPARTS(@year + 1, 1, 1),
		DATEFROMPARTS(@year, @month + 1, 1)
	),
	@dateRange_end
);

-- date ranges for which the data should be shown
DECLARE @dateRanges TABLE 
(
	"start" DATETIME,
	"end" DATETIME
);

DECLARE @currentDate DATETIME = @startDate;
DECLARE @nextDate DATETIME;
DECLARE @currentMonth INT = MONTH(@startDate);

WHILE (@currentDate &lt; @endDate)
BEGIN
	SET @nextDate = IIF(
		@currentMonth = 12,
		DATEFROMPARTS(@year + 1, 1, 1),
		DATEFROMPARTS(@year, @currentMonth + 1, 1)
	)

	IF (@nextDate > @endDate)
	BEGIN
		SET @nextDate = @endDate;
	END


	INSERT INTO @dateRanges ("start", "end") 
	VALUES 
	(
		@currentDate, 
		@nextDate
	)

	SET @currentDate = @nextDate;
	SET @currentMonth = @currentMonth + 1;

	IF (@currentMonth = 13)
	BEGIN
		SET @currentMonth = 1;
		SET @year = @year + 1;
	END
END

SELECT 
	PNR, 
	FORMAT("start", 'dd.MM.yyyy') Geltungsmonat, 
	ROUND(SUM(durationTheme)/60, 2) 'Summe WBT',
	ROUND(CONVERT(float, SUM(durationTraining)) / 60, 2) 'Summe Seminare'
FROM
	(SELECT
		descUserCn PNR,
		COALESCE(th.learningDuration, 0) durationTheme,
		COALESCE(t.durationMinutes, tt.durationMinutes, 0) durationTraining,
		dr."start"
		FROM 
			tblStatusUserItemHistory suih
			JOIN tableUsers u ON u.intUserCn = suih.user_id
			JOIN @dateRanges dr ON dr.start &lt;= suih.startDate AND dr."end" > suih.startDate
			LEFT JOIN tbltrainings t ON t.id = suih.item_id
			LEFT JOIN tblTrainingTitles tt ON tt.id = t.trainingTitle_id
			LEFT JOIN tblThemes th ON th.id = suih.item_id
		WHERE 
			status = 2
			AND (learningDuration &gt; 0 OR t.durationMinutes &gt; 0 OR tt.durationMinutes &gt; 0)
	) d
GROUP BY PNR, "start"
ORDER BY PNR, "start"</command>
    </Report>
  </Reports>
  <Parameters>
    <Parameter id="2128c559-f147-4f64-ae0b-292b1ca7005f" mandator_id="cf85efc9-150b-4eee-8c20-929a112b658c" isSystem="False" name="Month" reportParameterType_id="7982138a-efe6-48bb-bc83-9c1ebba6dcdf" queryParameterName="@month" />
    <Parameter id="d8e4595f-8bdd-4a54-9298-8f378450e6a0" isSystem="True" name="Zeitraum" reportParameterType_id="abff13be-91c3-4ee1-93a3-7292f8e013ba" queryParameterName="@dateRange" />
  </Parameters>
  <ParameterTypes>
    <ParameterType id="7982138a-efe6-48bb-bc83-9c1ebba6dcdf" mandator_id="cf85efc9-150b-4eee-8c20-929a112b658c" isSystem="False" name="Auswahlliste Monat (de)" datatype="IntegerDDL" dataValueField="" dataTextField="">
      <query>SELECT [value], [text] FROM (VALUES (1, 'Januar'),(2, 'Februar'),(3, 'März'),(4, 'April'),(5, 'Mai'),(6, 'Juni'),(7, 'Juli'),(7, 'August'),(9, 'September'),(10, 'Oktober'),(11, 'November'),(12, 'Dezember') ) AS KeyValues([value], [text])</query>
    </ParameterType>
    <ParameterType id="abff13be-91c3-4ee1-93a3-7292f8e013ba" isSystem="True" name="DateRange" datatype="DateRange" dataValueField="" dataTextField="" />
  </ParameterTypes>
</ReportsExport>