﻿<?xml version="1.0" encoding="utf-8"?>
<ReportsExport>
  <Reports>
    <Report id="860BF96F-FD59-4DCE-A98A-7F6237AF8B39" codekey="LearningProgramEvaluationTGMV2" categoryCodekey="UserStats" name="Statusreport Lernprogramme 2016" description="Lerner nach Lernstand und Zertifikat">
      <MetaData created="2014-09-11T13:35:26" createdBy="Administrator adidas01 (Administrator)" createdBy_user_id="492" modified="2016-01-14T11:03:52" modifiedBy="Administrator adidas01" />
      <ExecutionDetails format="TableResult" commandType="SqlCommandOrQuery" exportHandler="" adminControl="" exportMultipleTablesToSheets="False" datesWithTime="False" extraParams="" />
      <Mandators mandatorMode="IncludeMandators" mandator_id="cd0bfa6a-8871-4dfd-84b7-205dee51434e" isStandard="False" isUsedByMenu="False">
        <Mandator mandatorName="adidas01" />
        <Mandator mandatorName="WEKA" />
      </Mandators>
      <Parameters>
        <Parameter id="51048431-df30-44f7-9352-5eabc7343903" isRequired="False" allowMultiSelect="False" name="Nachname" contextName="Nachname" defaultValue="" renderHint="Undefined" disableParameter="DontDisable" />
        <Parameter id="016bcbc3-58e0-462c-a4b9-a2a8864909a3" isRequired="True" allowMultiSelect="False" name="ZGVlernprogramm" contextName="Lernprogramm" defaultValue="" renderHint="Undefined" disableParameter="DontDisable" />
        <Parameter id="720dc59a-21f9-40d0-910b-d878bf1caca1" isRequired="False" allowMultiSelect="False" name="Zertifikat erhalten" contextName="Zertifikat erhalten" defaultValue="" renderHint="Undefined" disableParameter="DontDisable" />
      </Parameters>
      <Roles>
        <Role id="30" />
        <Role id="90" />
      </Roles>
      <command>select title as 'Lernprogramm',
COALESCE(titleForLearners, title) as 'Titel für Lerner'
from tblItems where id = @theme_id

-- list all users, which have the selected theme assigned via some targegroup/ Eduoffer with the following data

select v_Users.Nachname,
            v_Users.Vorname,
            case when tblStatusUserCourse.bestComplete is null then '' 
            else CAST(round(tblStatusUserCourse.bestComplete, 2) AS NVARCHAR) + '%' end as 'Bester Bearbeitungsstand',
            tblStatusUserCourse.bestCompleteDate as 'Datum',
			CASE WHEN EXISTS (select * from tblStatusUserItemHistory where tblStatusUserItemHistory.status = 2 AND tblStatusUserItemHistory.user_id = v_Users.intUserCn  and tblStatusUserItemHistory.item_id =  @theme_id)
			THEN 
			  (select MAX(startDate) from tblStatusUserItemHistory where tblStatusUserItemHistory.status = 2 AND tblStatusUserItemHistory.user_id = v_Users.intUserCn  and tblStatusUserItemHistory.item_id =  @theme_id)
			ELSE NULL
			END
			AS    'Zertifikat erhalten'
from v_Users 
	inner join tblUsersTargetGroups on tblUsersTargetGroups.UserCn = v_Users.intUserCn 
    inner join tblTargetGroupManagers on tblTargetGroupManagers.targetGroup_id = tblUsersTargetGroups.targetGroup_id 
               and tblTargetGroupManagers.user_id = @current_user_id 
	left join tblStatusUserCourse on v_Users.intUserCn = tblStatusUserCourse.userId
			and tblStatusUserCourse.theme_id = @theme_id
where (@nachname is null or v_Users.Nachname like '%' + @nachname + '%')
             and (@certificateReceived is null
				or (@certificateReceived = 0 
						AND NOT EXISTS (select * from tblStatusUserItemHistory where tblStatusUserItemHistory.status = 2 AND tblStatusUserItemHistory.user_id = v_Users.intUserCn  and tblStatusUserItemHistory.item_id =  @theme_id))
				or (@certificateReceived = 1 
						AND EXISTS (select * from tblStatusUserItemHistory where tblStatusUserItemHistory.status = 2 AND tblStatusUserItemHistory.user_id = v_Users.intUserCn  and tblStatusUserItemHistory.item_id =  @theme_id))
			 )
</command>
    </Report>
  </Reports>
  <Parameters>
    <Parameter id="51048431-df30-44f7-9352-5eabc7343903" mandator_id="7eeb6e0d-a451-4adb-9497-903debf6efe7" isSystem="False" name="Nachname" reportParameterType_id="6e221a70-58e9-46eb-b028-181b9983b2f6" queryParameterName="@nachname" />
    <Parameter id="016bcbc3-58e0-462c-a4b9-a2a8864909a3" mandator_id="7eeb6e0d-a451-4adb-9497-903debf6efe7" isSystem="False" name="ZGVlernprogramm" reportParameterType_id="c14c191e-64e2-4f07-a9fb-7e8c5cd9f15b" queryParameterName="@theme_id" />
    <Parameter id="720dc59a-21f9-40d0-910b-d878bf1caca1" mandator_id="7eeb6e0d-a451-4adb-9497-903debf6efe7" isSystem="False" name="Zertifikat erhalten" reportParameterType_id="63c946da-b479-4a42-a95b-9e8ee796f391" queryParameterName="@certificateReceived" />
  </Parameters>
  <ParameterTypes>
    <ParameterType id="6e221a70-58e9-46eb-b028-181b9983b2f6" isSystem="True" name="String" datatype="String" dataValueField="" dataTextField="" />
    <ParameterType id="c14c191e-64e2-4f07-a9fb-7e8c5cd9f15b" mandator_id="7eeb6e0d-a451-4adb-9497-903debf6efe7" isSystem="False" name="ZGVlearningProgramme" datatype="GuidDDL" dataValueField="id" dataTextField="title">
      <query>
        select distinct tblThemes.id, tblItems.title
        from tblThemes inner join tblItems on tblThemes.id = tblItems.id
        inner join tblModuleItems on tblThemes.id = tblModuleItems.item_id
        inner join tblEduOffersModules on tblEduOffersModules.seminar_id = tblModuleItems.module_id
        inner join tblEduOffersTargetGroups on tblEduOffersModules.eduOffer_id = tblEduOffersTargetGroups.eduOffer_id
        inner join tblUsersTargetGroups tg1 on tblEduOffersTargetGroups.targetGroup_id = tg1.targetGroup_id
        inner join tblUsersTargetGroups tg2 on tg2.UserCn = tg1.UserCn
        inner join tblTargetGroupManagers on tblTargetGroupManagers.targetGroup_id = tg2.targetGroup_id
        where tblTargetGroupManagers.user_id = @current_user_id
        and tblItems.deleted is null
        order by tblItems.title, tblThemes.id</query>
    </ParameterType>
    <ParameterType id="63c946da-b479-4a42-a95b-9e8ee796f391" isSystem="True" name="Boolean" datatype="StringDDL" dataValueField="Value" dataTextField="Text">
      <query>        SELECT 0 AS Value, 'Nein' AS Text
        UNION
        SELECT 1 AS Value, 'Ja' AS Text</query>
    </ParameterType>
  </ParameterTypes>
</ReportsExport>