﻿<?xml version="1.0" encoding="utf-8"?>
<ReportsExport>
  <Reports>
    <Report id="c64252c8-f459-45cf-abc5-2a09f9df71f0" codekey="WW_ItemsWithEducationTime" categoryCodekey="CreditPoints" name="Trainingsdaten" description="Der Report exportiert alle im aktuellen Mandanten vorhandenen Bausteine und Module, denen eine Bildungszeit zugeordnet ist.">
      <MetaData created="2018-11-23T16:13:56" createdBy="Rolle Administrator (Administrator)" createdBy_user_id="12" modified="2019-03-28T13:10:53" modifiedBy="Rolle Administrator" />
      <ExecutionDetails format="TableResult" commandType="SqlCommandOrQuery" exportHandler="" adminControl="" exportMultipleTablesToSheets="False" datesWithTime="False" extraParams="" />
      <Mandators mandatorMode="IncludeMandators" mandator_id="96ba2868-8baf-4e69-b1fb-d2cc6d6832e8" mandatorName="Wuerttembergische" isStandard="False" isUsedByMenu="False">
        <Mandator mandatorName="Wuerttembergische" />
        <Mandator mandatorName="Wuestenrot" />
      </Mandators>
      <Roles>
        <Role id="90" />
      </Roles>
      <command>-- DECLARE @current_mandator_id UNIQUEIDENTIFIER = (select top 1 id from tblMandators where name = 'wuerttembergische')

-- Mapping for learningContent
CREATE TABLE #TMPLEARNINGCONTENT
(
	learningContent NVARCHAR(50),
	codekey NVARCHAR(2)
)
INSERT INTO #TMPLEARNINGCONTENT (learningContent,codekey)
	VALUES	('Insurance1','01'),
			('Insurance2','02'),
			('Insurance3','03'),
			('Insurance4','05'),
			('Insurance5General','06'),
			('Insurance6Business','04'),
			('Consulting','07')

-- mapping for learningType
CREATE TABLE #TMPLEARNINGTYPE
(
	learningType INT,
	codekey NVARCHAR(2)
)
INSERT INTO #TMPLEARNINGTYPE (learningType,codekey)
	VALUES	(1,'01'), -- Präsenzveranstaltung
			(2,'02'), -- Einzeltraining
			(3,'12'), -- Blended Learning
			(4,'03'), -- gesteuertes eLearning
			(5,'13')  -- selbstgesteuertes eLearning

-- retrieve the data
SELECT
	REPLACE(tblItems.id,'-','') AS [ID des Bausteins],
	'DE' AS [Sprache],
	ISNULL(tblItems.titleForLearners,tblItems.title) AS [Titel des Bausteins],
    CASE
		WHEN (itemType_id=1001 AND ((SELECT TOP 1 scoringMode FROM tblModules WHERE tblModules.id = tblItems.id) = 2))  -- Modules with ScoringMode "Sum of Items"
			THEN (SELECT ISNULL(SUM(educationTime),0) FROM tblModuleItems JOIN tblItems MO ON tblModuleItems.item_id = MO.id
                                       WHERE tblModuleItems.module_id = tblItems.id)
		ELSE FORMAT(tblItems.educationTime,'000')
	END
    AS Bildungszeit,
	ISNULL(#TMPLEARNINGCONTENT.codekey,'') AS [Lerninhalt],
	ISNULL(#TMPLEARNINGTYPE.codekey,'') AS [Lernform],
        'IDD' AS Zielgruppe

FROM tblItems
	LEFT JOIN #TMPLEARNINGCONTENT ON tblItems.learningContent = #TMPLEARNINGCONTENT.learningContent COLLATE DATABASE_DEFAULT
	LEFT JOIN #TMPLEARNINGTYPE ON tblItems.learningType_id = #TMPLEARNINGTYPE.learningType

	WHERE tblItems.mandator_id = @current_mandator_id
	AND tblItems.deleted IS NULL
	AND ((tblItems.educationTime &gt; 0)
			OR ((tblItems.itemType_id = 1001) AND ((SELECT TOP 1 scoringMode FROM tblModules WHERE tblModules.id = tblItems.id) = 2))
		)

	-- ((tblmodules.scoringMode = 2) OR ((tblmodules.scoringMode = 1) AND (tblItems.educationTime &gt; 0)))

-- clean up
DROP TABLE #TMPLEARNINGCONTENT
DROP TABLE #TMPLEARNINGTYPE
</command>
    </Report>
  </Reports>
</ReportsExport>