﻿<?xml version="1.0" encoding="utf-8"?>
<ReportsExport>
  <Reports>
    <Report id="fe7eea00-6cc1-45f8-bdb8-b2436ba88454" codekey="Kosmos_TrainingsAmountPerMandator" categoryCodekey="Trainings" name="Anzahl Seminartermine je Veranstalter" description="">
      <MetaData created="2017-11-29T12:30:45" createdBy="Administrator Zentrale (Administrator)" createdBy_user_id="1" modified="2018-10-01T12:24:39" modifiedBy="Administrator Zentrale" />
      <ExecutionDetails format="TableResult" commandType="SqlCommandOrQuery" exportHandler="" adminControl="" exportMultipleTablesToSheets="False" datesWithTime="False" extraParams="" />
      <Mandators mandatorMode="OnlyOwner" mandator_id="0ab3e804-57cb-42a7-82a3-a6fd412d317d" mandatorName="Kosmos" isStandard="False" isUsedByMenu="False" />
      <Parameters>
        <Parameter id="a785aecc-668a-4609-9613-394bd4d708c2" isRequired="False" allowMultiSelect="False" name="Mandant" contextName="Mandant" defaultValue="" renderHint="Undefined" disableParameter="DontDisable" />
        <Parameter id="d8e4595f-8bdd-4a54-9298-8f378450e6a0" isRequired="True" allowMultiSelect="False" name="Zeitraum" contextName="Zeitraum" defaultValue="" renderHint="Undefined" disableParameter="DontDisable" />
      </Parameters>
      <Roles>
        <Role id="90" />
      </Roles>
      <command>
         ;
        WITH totals
        AS (SELECT parent_id,
        title,
        counters.*
        FROM(
        SELECT organizer,
        COUNT(*) AS total,
        SUM(CASE WHEN workflow = 0 AND isVirtual = 0 THEN 1 ELSE 0 END) AS countPull,
        SUM(CASE WHEN workflow = 1 AND isVirtual = 0 AND isMicroTraining = 0 THEN 1 ELSE 0 END) AS countPush,
        SUM(CASE WHEN isMicroTraining = 1 THEN 1 ELSE 0 END) AS countMicro,
        SUM(CASE WHEN workflow IN (0,1) AND isVirtual = 1 THEN 1 ELSE 0 END) as countVirtual
        FROM tblTrainings
        JOIN tblTrainingTitles ON tblTrainings.trainingTitle_id = tblTrainingTitles.id
        JOIN tblItems ON tblItems.id = tblTrainings.id AND tblItems.deleted IS NULL
        WHERE
					  ((@dateRange_start IS NULL AND startDate &lt;= @dateRange_end)
                    OR (@dateRange_end IS NULL AND startDate &gt;= @dateRange_start) 
                    OR (startDate &gt;= @dateRange_start AND startDate &lt;= @dateRange_end))
                GROUP BY organizer) AS counters
              JOIN tblOrganisationUnits ON tblOrganisationUnits.id = organizer
              WHERE @mandator_id IS NULL OR tblOrganisationUnits.mandator_id = @mandator_id), 
              
              
totalsCTE(organizer, 
        parent_id, 
        title, 
        fullName, 
        total, 
        countPull, 
        countPush, 
        countMicro,
        countVirtual)
    AS (SELECT organizer, 
               parent_id, 
               title, 
               CAST(title AS NVARCHAR(1024))AS fullName, 
               total, 
               countPull, 
               countPush, 
               countMicro,
               countVirtual
          FROM totals
         WHERE parent_id IS NULL
        UNION ALL
        SELECT t.organizer, 
               t.parent_id, 
               t.title, 
               CAST(totalsCTE.fullName + '/' + CAST(t.title AS NVARCHAR(1024))AS NVARCHAR(1024))AS fullName, 
               t.total, 
               t.countPull, 
               t.countPush, 
               t.countMicro,
               t.countVirtual
          FROM totals AS t
               INNER JOIN totalsCTE ON totalsCTE.organizer = t.parent_id)
    
SELECT fullName AS Veranstalter, total as 'Anzahl Termine', 
    countPush as 'Push-Seminare',
    countPull as 'Pull-Seminare',
    countMicro as 'Micro-Trainings',
    countVirtual as 'Virtuelle Seminare'
FROM totalsCTE ORDER BY fullName
</command>
    </Report>
  </Reports>
  <Parameters>
    <Parameter id="a785aecc-668a-4609-9613-394bd4d708c2" isSystem="True" name="Mandant" reportParameterType_id="6b8fa242-5449-45b3-a81a-65a7e5e3b51d" queryParameterName="@mandator_id" />
    <Parameter id="d8e4595f-8bdd-4a54-9298-8f378450e6a0" isSystem="True" name="Zeitraum" reportParameterType_id="abff13be-91c3-4ee1-93a3-7292f8e013ba" queryParameterName="@dateRange" />
  </Parameters>
  <ParameterTypes>
    <ParameterType id="6b8fa242-5449-45b3-a81a-65a7e5e3b51d" isSystem="True" name="Mandator" datatype="Mandator" dataValueField="" dataTextField="" />
    <ParameterType id="abff13be-91c3-4ee1-93a3-7292f8e013ba" isSystem="True" name="DateRange" datatype="DateRange" dataValueField="" dataTextField="" />
  </ParameterTypes>
</ReportsExport>