﻿<?xml version="1.0" encoding="utf-8"?>
<ReportsExport>
  <Reports>
    <Report id="9007c6fa-0997-4bd2-a22a-c214d2ba76c5" codekey="eduoffer_participants" categoryCodekey="UserStats" name="Teilnehmer eines Bildungsangebots" description="Liefert die Teilnehmer eines Bildungsangebotes in einem Zeitraum zurück.&#xD;&#xA;Listet die besten Bearbeitungsergebnisse deren Tests und WBTs zurück.">
      <MetaData created="2012-05-29T08:57:51" createdBy="Administrator BISS" createdBy_user_id="3" modified="2016-04-27T15:25:42" modifiedBy="Gabi Wappler" />
      <ExecutionDetails format="TableResult" commandType="SqlCommandOrQuery" exportHandler="" adminControl="" exportMultipleTablesToSheets="False" datesWithTime="False" extraParams="" />
      <Mandators mandatorMode="OnlyOwner" mandator_id="cf85efc9-150b-4eee-8c20-929a112b658c" mandatorName="BISS" isStandard="False" isUsedByMenu="False" />
      <Parameters>
        <Parameter id="fe768a68-c33b-4be0-815b-10405ccf541d" isRequired="True" allowMultiSelect="False" name="Bildungsangebot" contextName="Bildungsangebot" defaultValue="" renderHint="Undefined" disableParameter="DontDisable" />
        <Parameter id="d8e4595f-8bdd-4a54-9298-8f378450e6a0" isRequired="False" allowMultiSelect="False" name="Zeitraum" contextName="Zeitraum" defaultValue="" renderHint="Undefined" disableParameter="DontDisable" />
        <Parameter id="3ffd2115-d996-47eb-904a-d421d975b933" isRequired="False" allowMultiSelect="False" name="Modul abhängig vom Bildungsangebot" contextName="Modul abhängig vom Bildungsangebot" defaultValue="" renderHint="Undefined" disableParameter="DontDisable" />
        <Parameter id="033a2bac-97d9-42d1-afac-824cc2b010af" isRequired="False" allowMultiSelect="False" name="Baustein abhängig vom Modul" contextName="Baustein abhängig vom Modul" defaultValue="" renderHint="Undefined" disableParameter="DontDisable" />
        <Parameter id="b8910d72-fade-47b2-bd13-91259cda8fb3" isRequired="False" allowMultiSelect="False" name="Zielgruppe abhängig vom Bildungsangebot" contextName="Zielgruppe abhängig vom Bidlungsangebot" defaultValue="" renderHint="Undefined" disableParameter="DontDisable" />
        <Parameter id="8129bdea-c40f-4c95-a6ab-ddc5b2480108" isRequired="False" allowMultiSelect="False" name="Kennung" contextName="Kennung" defaultValue="" renderHint="Undefined" disableParameter="DontDisable" />
        <Parameter id="9acb8ae1-8340-454e-88c1-1bebcf132665" isRequired="False" allowMultiSelect="False" name="Lernstand" contextName="Lernstand" defaultValue="" renderHint="Undefined" disableParameter="DontDisable" />
        <Parameter id="7fa73e88-dee9-40ba-8979-db000be9e8ce" isRequired="False" allowMultiSelect="False" name="Test Status" contextName="Test Status" defaultValue="" renderHint="Undefined" disableParameter="DontDisable" />
      </Parameters>
      <Roles>
        <Role id="90" />
      </Roles>
      <command>
        --Information for debugging
        --DEBUG START
        --declare @eduOffer_id uniqueidentifier
        -- select TOP 1 @eduOffer_id = Edu.id FROM tblEduOffers AS Edu INNER JOIN tblMandators AS Mand ON Edu.mandator_id = Mand.id WHERE Mand.name = 'ELECT'
        --declare @dateRange_start datetime
        --set @dateRange_start = NULL -- '2014-02-01'
        --declare @dateRange_end datetime
        --set @dateRange_end = '2014-01-15'
        --declare @module_id uniqueidentifier
        --set @module_id = NULL
        --declare @item_id uniqueidentifier
        --set @item_id = NULL
        --declare @learnStatus INT
        --set @learnStatus = NULL
        --declare @testStatus INT
        --set @testStatus = NULL
        --declare @targetGroup INT
        --set @targetGroup = NULL
        --declare @logName NVARCHAR(50)
        --set @logName = NULL
        --DEBUG STOP
        -- The report without debugging information starts here


IF(@dateRange_start IS NOT NULL)
    SET @dateRange_start = CAST(CONVERT(NVARCHAR(32), @dateRange_start, 112)AS DATETIME)

IF(@dateRange_end IS NOT NULL)
    BEGIN
        SET @dateRange_end = CAST(CONVERT(NVARCHAR(32), @dateRange_end, 112)AS DATETIME)
        SET @dateRange_end = DATEADD(day, 1, @dateRange_end)
        SET @dateRange_end = DATEADD(second, -1, @dateRange_end)
    END

--set statistics time on
--Step 1: helping object for holding temporary information
CREATE TABLE #tmpResult(UserId INT, 
                        TestDescription VARCHAR(255)NULL, 
                        TestDate DATETIME NULL, 
                        TestResultState INT NULL, 
                        TestResultPercent DECIMAL(5, 2)NULL, 
                        ThemeDescription VARCHAR(255)NULL, 
                        ThemeStatus DECIMAL(5, 2)NULL)

CREATE TABLE #tgrUsers(user_id INT)
INSERT INTO #tgrUsers
SELECT DISTINCT tblUsersTargetGroups.UserCn
  FROM tblUsersTargetGroups
       INNER JOIN tblEduOffersTargetGroups ON tblEduOffersTargetGroups.eduOffer_id = @eduOffer_id
       INNER JOIN v_Users ON v_users.intUserCn = tblUsersTargetGroups.UserCn
                         AND tblUsersTargetGroups.targetGroup_id = tblEduOffersTargetGroups.targetGroup_id
                         AND (@targetGroup IS NULL OR tblEduOffersTargetGroups.targetGroup_id = @targetGroup)
                         AND (@logName IS NULL OR (descUserCn LIKE '%' + @logName + '%'))

--Step 2: preparing user information for the resultlist all potential users for the learning recomondation and targetgroups
-- get the themes that would be considered
;
WITH themes(theme_id, 
            title)
    AS (SELECT DISTINCT tblItems.id, 
                        tblItems.title
          FROM tblEduOffersModules
               INNER JOIN tblModuleItems ON tblModuleItems.module_id = tblEduOffersModules.module_id
                                        AND (@module_id IS NULL OR tblModuleItems.module_id = @module_id)
               INNER JOIN tblItems ON tblItems.id = tblModuleItems.item_id
                                  AND tblItems.itemType_id = 1
                                  AND (@item_id IS NULL OR tblItems.id = @item_id)
         WHERE tblEduOffersModules.eduOffer_id = @eduOffer_id AND tblItems.deleted IS NULL)


INSERT INTO #tmpResult
    SELECT #tgrUsers.user_id, 
                NULL, 
                NULL, 
                -2, 
                NULL, 
           themes.title, 
           tblStatusUserCourse.BestComplete
      FROM #tgrUsers --tblEduOffersTargetGroups
           CROSS JOIN themes
                      LEFT JOIN tblStatusUserCourse ON tblStatusUserCourse.theme_id = themes.theme_id
                                                   AND #tgrUsers.user_id = tblStatusUserCourse.UserId
 WHERE(((@dateRange_start IS NULL AND @dateRange_end IS NULL)
         OR (tblStatusUserCourse.BestCompleteDate IS NULL
         AND (@learnStatus IS NULL OR @learnStatus = 0))
         OR (@dateRange_start IS NULL
         AND tblStatusUserCourse.BestCompleteDate &lt; @dateRange_end)
         OR (@dateRange_end IS NULL
         AND tblStatusUserCourse.BestCompleteDate &gt; @dateRange_start)
         OR tblStatusUserCourse.BestCompleteDate BETWEEN @dateRange_start AND @dateRange_end))
          --AND tblItems.deleted IS NULL
  AND (@learnStatus IS NULL
        OR ((@learnStatus = 0 AND (tblStatusUserCourse.BestComplete IS NULL))
     OR (@learnStatus = 1
         AND ((tblStatusUserCourse.BestComplete &gt;= 0.0
           AND tblStatusUserCourse.BestComplete &lt; 100.0)
           OR (InProgress &gt;= 0.0 AND tblStatusUserCourse.BestComplete &lt; 100.0)))
         OR (@learnStatus = 2 AND tblStatusUserCourse.BestComplete = 100.0)))
--order by #tgrUsers.user_id
--select * from #tmpResult
;
WITH tests(test_id, 
           title)
    AS (SELECT tblItems.id, 
               title
          FROM tblEduOffersModules
               INNER JOIN tblModuleItems ON tblModuleItems.module_id = tblEduOffersModules.module_id
                                        AND (@module_id IS NULL OR tblModuleItems.module_id = @module_id)
               INNER JOIN tblItems ON tblItems.id = tblModuleItems.item_id
                                  AND tblItems.itemType_id = 0
                                  AND tblitems.deleted IS NULL
                                  AND (@item_id IS NULL OR tblItems.id = @item_id)
         WHERE tblEduOffersModules.eduOffer_id = @eduOffer_id), 

minDates(test_id, 
        user_id, 
        endDate, 
        percentage)
    AS (SELECT endDates.*, 
               tblTasStatsTestSessions.pctQuestions
          FROM(
               SELECT test_id, 
                      user_id, 
                      MIN(endDate)AS minDate
                 FROM tblTasStatsTestSessions
                WHERE EXISTS(
                             SELECT UserCn
                               FROM tblUsersTargetGroups
                                    JOIN tblEduOffersTargetGroups ON tblEduOffersTargetGroups.targetGroup_id = tblUsersTargetGroups.targetGroup_id
                                                                 AND tblEduOffersTargetGroups.eduOffer_id = @eduOffer_id
                              WHERE user_id = UserCn)
                GROUP BY test_id, 
                         user_id) AS endDates
              JOIN tblTasStatsTestSessions ON tblTasStatsTestSessions.user_id = endDates.user_id
                                          AND tblTasStatsTestSessions.test_id = endDates.test_id
                                          AND tblTasStatsTestSessions.endDate = endDates.minDate)

-- Step 3: reading information for the tests
INSERT INTO #tmpResult
    SELECT DISTINCT #tgrUsers.user_id, 
                    tests.title, 
                    firstDate.endDate, 
                    --TestsStats.endDate, 
                    CASE
                        WHEN firstDate.test_id IS NULL THEN 0
                        ELSE dbo.fn_GetUserItemStatus(#tgrUsers.user_id, tests.test_id)
                    END, 
                    firstDate.percentage, 
                NULL, 
                NULL
      FROM #tgrUsers
           CROSS JOIN tests
                      LEFT JOIN minDates AS firstDate ON firstDate.user_id = #tgrUsers.user_id AND firstDate.test_id = tests.test_id
 WHERE(((@dateRange_start IS NULL AND @dateRange_end IS NULL)
         OR (firstDate.endDate IS NULL AND @testStatus IS NULL)
         OR (@dateRange_start IS NULL AND firstDate.endDate &lt; @dateRange_end)
         OR (@dateRange_end IS NULL AND firstDate.endDate &gt; @dateRange_start)
         OR firstDate.endDate BETWEEN @dateRange_start AND @dateRange_end))
--order by #tgrUsers.user_id

-- Step 4: printing out the neccessary information
SELECT Nachname AS 'Name', 
       Vorname AS 'Vorname', 
       descUserCn AS 'Kennung', 
       division AS 'Abteilung', 
       companyAD AS 'Bereich', 
       area AS 'Status', 
       office AS 'Kostenstelle', 
       TestDescription AS 'Test - Bezeichnung', 
       TestDate AS 'Test - Datum', 
       CASE
           WHEN TestResultState = -1 THEN 'fehlerhaft'
           WHEN TestResultState = -2 THEN NULL
           WHEN TestResultState = 0 THEN 'unbearbeitet'
           WHEN TestResultState = 2 THEN 'bestanden'
           ELSE 'nicht bestanden'
       END AS 'Test - Ergebnis - Status', 
       TestResultPercent AS 'Test - Ergebnis - Prozentsatz', 
       ThemeDescription AS 'Lernprogramm - Bezeichnung', 
       ThemeStatus AS 'Lernprogramm - Lernstand (in %)',
       CASE
           WHEN ThemeStatus = 100 THEN 'Bearbeitet'
            WHEN ThemeStatus &gt;= 0 AND ThemeStatus &lt; 100 THEN 'In Bearbeitung'
           WHEN ThemeDescription IS NOT NULL THEN 'Nicht bearbeitet' --ThemeStatus IS NULL for all tests!!!
            ELSE NULL -- NULL if no info for theme
       END AS 'Lernprogramm-Ergebnis-Status'
       -- , TestResultState
  FROM #tmpResult
       INNER JOIN v_Users AS Usr ON #tmpResult.UserId = Usr.intUserCn
 WHERE(@logName IS NULL OR Usr.descUserCn LIKE '%' + @logName + '%')
  AND (@testStatus IS NULL
    OR (@testStatus = 0 AND (TestResultState = 3 OR ThemeDescription IS NOT NULL))
    OR (@testStatus = 1 AND (TestResultState = 2 OR ThemeDescription IS NOT NULL)))
 ORDER BY  UserId --Nachname, Vorname, ThemeDescription, TestDescription --

-- Step 5: removing temporary table from storage
DROP TABLE #tmpResult
DROP TABLE #tgrUsers

--set statistics time off
</command>
    </Report>
  </Reports>
  <Parameters>
    <Parameter id="fe768a68-c33b-4be0-815b-10405ccf541d" isSystem="True" name="Bildungsangebot" reportParameterType_id="1c8f3253-b45b-491e-8539-5214604e259c" queryParameterName="@eduOffer_id" />
    <Parameter id="d8e4595f-8bdd-4a54-9298-8f378450e6a0" isSystem="True" name="Zeitraum" reportParameterType_id="abff13be-91c3-4ee1-93a3-7292f8e013ba" queryParameterName="@dateRange" />
    <Parameter id="3ffd2115-d996-47eb-904a-d421d975b933" mandator_id="10701de5-e6e1-4fbe-a0e3-bbd024ce44c1" isSystem="False" name="Modul abhängig vom Bildungsangebot" reportParameterType_id="8ac04622-8de5-41e5-9afd-cfaeac9767fa" queryParameterName="@module_id" />
    <Parameter id="033a2bac-97d9-42d1-afac-824cc2b010af" mandator_id="10701de5-e6e1-4fbe-a0e3-bbd024ce44c1" isSystem="False" name="Baustein abhängig vom Modul" reportParameterType_id="7c7f5ebb-59b7-4acb-b09b-0805fbc5e8c3" queryParameterName="@item_id" />
    <Parameter id="b8910d72-fade-47b2-bd13-91259cda8fb3" mandator_id="10701de5-e6e1-4fbe-a0e3-bbd024ce44c1" isSystem="False" name="Zielgruppe abhängig vom Bildungsangebot" reportParameterType_id="b81e954b-f14d-48b5-b450-55af017a6cf0" queryParameterName="@targetGroup" />
    <Parameter id="8129bdea-c40f-4c95-a6ab-ddc5b2480108" mandator_id="10701de5-e6e1-4fbe-a0e3-bbd024ce44c1" isSystem="False" name="Kennung" reportParameterType_id="784536b8-bce0-427c-9682-a4269e086649" queryParameterName="@logName" />
    <Parameter id="9acb8ae1-8340-454e-88c1-1bebcf132665" mandator_id="10701de5-e6e1-4fbe-a0e3-bbd024ce44c1" isSystem="False" name="Lernstand" reportParameterType_id="c3b0fb66-e117-4ea8-89c1-e28df9d348b9" queryParameterName="@learnStatus" />
    <Parameter id="7fa73e88-dee9-40ba-8979-db000be9e8ce" mandator_id="10701de5-e6e1-4fbe-a0e3-bbd024ce44c1" isSystem="False" name="Test Status" reportParameterType_id="836ba1a1-b6ad-4b8e-8ef2-fef838611ccf" queryParameterName="@testStatus" />
    <Parameter id="22d867d1-0fa2-483a-92be-17d91508ea87" isSystem="True" name="Modul" reportParameterType_id="b141d3d7-0284-490f-8497-0345ae800ede" queryParameterName="@module_id" />
  </Parameters>
  <ParameterTypes>
    <ParameterType id="1c8f3253-b45b-491e-8539-5214604e259c" isSystem="True" name="EduOffer" datatype="EduOffer" dataValueField="" dataTextField="" />
    <ParameterType id="abff13be-91c3-4ee1-93a3-7292f8e013ba" isSystem="True" name="DateRange" datatype="DateRange" dataValueField="" dataTextField="" />
    <ParameterType id="8ac04622-8de5-41e5-9afd-cfaeac9767fa" mandator_id="10701de5-e6e1-4fbe-a0e3-bbd024ce44c1" isSystem="False" name="Auswahl liste modules" datatype="GuidDDL" dataValueField="value" dataTextField="text">
      <query>
        select id as value, title as text
        from tblItems
        inner join tblEduOffersModules on tblEduOffersModules.module_id = tblItems.id
        and tblEduOffersModules.eduOffer_id = @eduOffer_id
      </query>
      <Parameters>
        <Parameter id="fe768a68-c33b-4be0-815b-10405ccf541d" isRequired="False" allowMultiSelect="False" name="Bildungsangebot" contextName="Bildungsangebot" defaultValue="" renderHint="Undefined" disableParameter="DontDisable" />
      </Parameters>
    </ParameterType>
    <ParameterType id="7c7f5ebb-59b7-4acb-b09b-0805fbc5e8c3" mandator_id="10701de5-e6e1-4fbe-a0e3-bbd024ce44c1" isSystem="False" name="Auswahl liste Items" datatype="GuidDDL" dataValueField="id" dataTextField="title">
      <query>
        select tblItems.id, title from tblItems inner join tblModuleItems on module_id = @module_id and  item_id =  tblItems.id and itemType_id IN (0,1) order by itemType_id
      </query>
      <Parameters>
        <Parameter id="22d867d1-0fa2-483a-92be-17d91508ea87" isRequired="False" allowMultiSelect="False" name="Modul" contextName="Modul" defaultValue="" renderHint="Undefined" disableParameter="DontDisable" />
      </Parameters>
    </ParameterType>
    <ParameterType id="b81e954b-f14d-48b5-b450-55af017a6cf0" mandator_id="10701de5-e6e1-4fbe-a0e3-bbd024ce44c1" isSystem="False" name="Auswahlliste Zielgruppe vom Bilddungsabgebot" datatype="IntegerDDL" dataValueField="id" dataTextField="title">
      <query>
        select id, title
        from tblTargetGroups
        inner join tblEduOffersTargetGroups on targetGroup_id = id
        where tblEduOffersTargetGroups.eduOffer_id = @eduOffer_id
      </query>
      <Parameters>
        <Parameter id="fe768a68-c33b-4be0-815b-10405ccf541d" isRequired="False" allowMultiSelect="False" name="Bildungsangebot" contextName="Bildungsangebot" defaultValue="" renderHint="Undefined" disableParameter="DontDisable" />
      </Parameters>
    </ParameterType>
    <ParameterType id="784536b8-bce0-427c-9682-a4269e086649" mandator_id="10701de5-e6e1-4fbe-a0e3-bbd024ce44c1" isSystem="False" name="Kennung string" datatype="String" dataValueField="" dataTextField="" />
    <ParameterType id="c3b0fb66-e117-4ea8-89c1-e28df9d348b9" mandator_id="10701de5-e6e1-4fbe-a0e3-bbd024ce44c1" isSystem="False" name="Auswhalliste Lernstand" datatype="IntegerDDL" dataValueField="statusNo" dataTextField="statusText">
      <query>
        select 'Nicht bearbeitet' as statusText, 0 as statusNo
        union
        select 'in Bearbeitung' as statusText, 1 as statusNo
        union
        select 'Bearbeitet' as statusText, 2 as statusNo
      </query>
    </ParameterType>
    <ParameterType id="836ba1a1-b6ad-4b8e-8ef2-fef838611ccf" mandator_id="10701de5-e6e1-4fbe-a0e3-bbd024ce44c1" isSystem="False" name="Auswahlliste Test Status" datatype="IntegerDDL" dataValueField="statusNo" dataTextField="statusText">
      <query>
        select 'nicht bestanden' as statusText, 0 as statusNo
        union
        select 'bestanden' as statusText, 1 as statusNo
      </query>
    </ParameterType>
    <ParameterType id="b141d3d7-0284-490f-8497-0345ae800ede" isSystem="True" name="Module" datatype="Module" dataValueField="" dataTextField="" />
  </ParameterTypes>
</ReportsExport>