﻿<?xml version="1.0" encoding="utf-8"?>
<ReportsExport>
  <Reports>
    <Report id="4DB682EB-5638-4C42-87E8-94730DE660A3" codekey="ERGO_e-Campus_Lernhistorie" categoryCodekey="UserStats" name="Lernhistorienimport" description="Listet alle erfolgreich bearbeiteten Bausteine pro User für den Zeitraum 01.01.2020 bis 31.12.2023 auf">
      <MetaData created="2021-03-08T16:19:24" createdBy="Administrator, Albrecht (Administrator)" createdBy_user_id="1" modified="2023-08-31T15:44:50" modifiedBy="ERGO_e-Campus, Administrator (Administrator)" modifiedBy_user_id="243" />
      <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" />
      <Roles />
      <command>
		declare @dateRangeStart datetime = '2020-01-01 00:00:00.000'
		declare @dateRangeEnd datetime = '2023-12-31 23:59:59.000'

		SELECT ISNULL(referenceScore_id,id) AS id, sum(educationTime) AS educationTime INTO #tmpScores 
		FROM tblUserItemScores WHERE created &gt;= @dateRangeStart and created &lt;= @dateRangeEnd
		GROUP BY ISNULL(referenceScore_id,id)

		  select
			  u.descUserCn as 'PNR',
			  u.Vorname as 'Vorname',
			  u.Nachname as 'Nachname',
			  case when i.itemType_id = 0 then 'Test'
			  else case when i.itemType_id = 1 then 'Lernprogramm'
			  else 'Modul'
			  end
			  end as 'Bausteintyp',
			  i.titleForLearners as 'Titel für Lerner',
			  h.startDate as 'Beginn',
			  h.endDate as 'Ende',
			  case when s.id is null then null
			  else (SELECT educationTime from #tmpScores where #tmpScores.id = s.id) 
			  end as 'IDD-Zeit',
			  l.learningDuration as 'Lerndauer'
		  from tblStatusUserItemHistory h
			  inner join v_Users u on u.intUserCn = h.user_id
			  inner join tblItems i on i.id = h.item_id
			  left join tblThemes l on l.id = i.id
			  left join tblUserItemScores as s on h.id = s.status_id
		  where h.status = 2 and
			  i.itemType_id in (0,1,1001) and
			  u.mandator_id = @current_mandator_id and
			  h.startDate &gt;= @dateRangeStart and
			  h.startDate &lt;= @dateRangeEnd and
			  not exists(select 1 from tblStatusUserItemHistory h2
				  where h.id &lt;&gt; h2.id
				  and h2.status = 2
				  and h.item_id = h2.item_id
				  and h.user_id = h2.user_id
				  and h.startDate &lt; h2.startDate
				)
		order by u.Nachname, u.Vorname, h.startDate
		
		drop table #tmpScores
      </command>
    </Report>
  </Reports>
</ReportsExport>