﻿<?xml version="1.0" encoding="utf-8"?>
<ReportsExport>
  <Reports>
    <Report id="d2a4f069-54ab-470d-b038-249af0529017" codekey="UserImportGDVCheck" categoryCodekey="CreditPoints" name="Check GDV Attributes" description="checking the mandatory fields for the exchangers for &quot;gutberaten&quot; if those fields are filled up correctly. Used mainly for CSV user import for checking data after importing.">
      <MetaData created="2014-03-24T13:20:39" createdBy="Thomas Fix (thomas.fix)" createdBy_user_id="3" modified="2014-06-11T17:30:29" modifiedBy="Thomas Fix" />
      <ExecutionDetails format="TableResult" commandType="SqlCommandOrQuery" exportHandler="" adminControl="" exportMultipleTablesToSheets="False" datesWithTime="False" extraParams="" />
      <Mandators mandatorMode="OnlyOwner" mandator_id="cf85efc9-150b-4eee-8c20-929a112b658c" isStandard="False" isUsedByMenu="False" />
      <Parameters>
        <Parameter id="0bc94ad9-3560-4769-844e-e665898a3ad7" isRequired="True" name="ContactDataTypes" contextName="ContactDataTypes" defaultValue="1" renderHint="Undefined" disableParameter="DontDisable" />
      </Parameters>
      <Roles />
      <command>
        -- DECLARE @current_mandator_id UNIQUEIDENTIFIER = 'CF85EFC9-150B-4EEE-8C20-929A112B658C'
        -- DECLARE @contactDataType INT = 1

        DECLARE @qualificationsTable TABLE(qualification_id UNIQUEIDENTIFIER)

        /* getting all qualifications with exchangers attached */
        INSERT INTO @qualificationsTable
        SELECT tblQualifications.id
        FROM tblQualifications INNER JOIN tblQualificationExchangers ON tblQualifications.id = tblQualificationExchangers.qualification_id
        WHERE tblQualificationExchangers.isActive = 1
        AND tblQualificationExchangers.exchangerCodeKey IN('GDVCREATEUSER','GDVEDITUSER')

        /* for all the existing qualifications we will find credit points*/
        SELECT DISTINCT Users.descUserCn AS 'Kennung',
        Users.intUserCn AS 'Benutzer ID',
        Users.registernumber AS 'gutberatenId',
        CASE
        WHEN NULLIF(Users.Vorname, '')IS NULL THEN 'X'
        ELSE ''
        END AS 'Vorname',
        CASE
        WHEN NULLIF(Users.Nachname, '')IS NULL THEN 'X'
        ELSE ''
        END AS 'Nachname',
        CASE
        WHEN Users.birthday IS NULL THEN 'X'
        ELSE ''
        END AS 'Geburtsdatum',
        CASE
        WHEN Users.gender = 0 THEN 'X'
        ELSE ''
        END AS 'Geschlecht',
        CASE
        WHEN tblUsersContacts.phone IS NULL
        OR NULLIF(LTRIM(RTRIM(tblUsersContacts.phone)), '')IS NULL THEN 'X'
        ELSE ''
        END AS 'Telefon',
        CASE
        WHEN tblUsersContacts.zipcode IS NULL
        OR NULLIF(LTRIM(RTRIM(tblUsersContacts.zipcode)), '')IS NULL THEN 'X'
        ELSE ''
        END AS 'PLZ',
        CASE
        WHEN tblUsersContacts.streetname IS NULL
        OR NULLIF(LTRIM(RTRIM(tblUsersContacts.streetname)), '')IS NULL THEN 'X'
        ELSE ''
        END AS 'Strasse',
        CASE
        WHEN tblUserGdvAttributes.isDataTransmission IS NULL THEN 'X'
        ELSE ''
        END AS 'Datenübermittlung',
        CASE
        WHEN tblUserGdvAttributes.isDataProtection IS NULL THEN 'X'
        ELSE ''
        END AS 'Datenschutz',
        CASE
        WHEN tblUserGdvAttributes.agentStatus IS NULL THEN 'X'
        ELSE ''
        END AS 'Personenkreis',
        CASE
        WHEN tblUserGdvAttributes.emailNotification IS NULL THEN 'X'
        ELSE ''
        END AS 'Email Benachrichtigung',
        CASE
        WHEN tblUserGdvAttributes.isTpService IS NULL THEN 'X'
        ELSE ''
        END AS 'TP Service',
        tblQualificationExchangers.exchangerCodeKey
        INTO #Helper
        FROM tblUserItemScoresQualifications INNER JOIN @qualificationsTable AS joinTable ON joinTable.qualification_id = tblUserItemScoresQualifications.qualification_id
        INNER JOIN tblUserItemScores ON tblUserItemScores.id = tblUserItemScoresQualifications.useritemscore_id
        INNER JOIN tblObjects ON tblObjects.id = joinTable.qualification_id
        INNER JOIN tblQualifications ON tblQualifications.id = tblObjects.id
        INNER JOIN tblQualificationExchangers ON tblQualificationExchangers.qualification_id = tblQualifications.id
        AND tblQualificationExchangers.exchangerCodeKey IN('GDVCREATEUSER','GDVEDITUSER')
        INNER JOIN tableUsers AS Users ON Users.intUserCn = tblUserItemScores.user_id
        LEFT JOIN tblUserGdvAttributes ON tblUserGdvAttributes.user_id = Users.intUserCn
        LEFT JOIN tblUsersContacts ON tblUsersContacts.user_id = Users.intUserCn
        AND tblUsersContacts.contactType_id = @contactDataType
        WHERE 1 = 1
        AND (
        /* firstname must be available*/
        ISNULL(Users.Vorname, '') = ''
        OR /* lastname must be available*/

        ISNULL(Users.Nachname, '') = ''
        OR /* missing information for gutberaten for this user*/

        tblUserGdvAttributes.id IS NULL
        OR /* agentStatus must be available*/
        tblUserGdvAttributes.agentStatus IS NULL
        /* phone streetnumber must be available*/
        OR tblUsersContacts.id IS NULL
        OR (tblUsersContacts.id IS NOT NULL
        AND NULLIF(LTRIM(RTRIM(tblUsersContacts.phone)), '')IS NULL)

        /* zip code must be available */
        OR tblUsersContacts.id IS NULL
        OR (tblUsersContacts.id IS NOT NULL
        AND NULLIF(LTRIM(RTRIM(tblUsersContacts.zipcode)), '')IS NULL)

        /* streetname or lockbox must be available */
        OR tblUsersContacts.id IS NULL
        OR (tblUsersContacts.id IS NOT NULL
        AND (NULLIF(LTRIM(RTRIM(tblUsersContacts.streetname)), '')IS NULL)
        )

        OR /* birthday must be available so not null*/
        CASE
        WHEN Users.intUserCn IS NOT NULL THEN Users.birthday
        ELSE NULL
        END IS NULL
        OR /* gender must be available and valid selection &amp;lt;&amp;gt; 0*/
CASE
WHEN Users.intUserCn IS NOT NULL THEN Users.gender
ELSE 0
END = 0)
AND
(
(
tblQualificationExchangers.exchangerCodeKey = 'GDVCREATEUSER' AND
(Users.registernumber IS NULL OR NULLIF(RTRIM(LTRIM(Users.registernumber)),'') IS NULL)
)
OR
(
tblQualificationExchangers.exchangerCodeKey = 'GDVEDITUSER' AND
(Users.registernumber IS NOT NULL AND NULLIF(RTRIM(LTRIM(Users.registernumber)),'') IS NOT NULL)
)
)
ORDER BY Users.intUserCn

DECLARE @newCol AS NVARCHAR(50)
IF @contactDataType = 1
BEGIN
SET @newCol = ' (geschäftlich)'
END
ELSE
BEGIN
SET @newCol = ' (private)'
END
EXEC ('EXEC tempdb..sp_rename ''#Helper.Telefon'', ''Telefon '+@newCol+''', ''COLUMN''')
EXEC ('EXEC tempdb..sp_rename ''#Helper.PLZ'', ''PLZ'+@newCol+''', ''COLUMN''')
EXEC ('EXEC tempdb..sp_rename ''#Helper.Strasse'', ''Strasse'+@newCol+''', ''COLUMN''')

SELECT * FROM #Helper

DROP TABLE #Helper</command>
    </Report>
  </Reports>
  <Parameters>
    <Parameter id="0bc94ad9-3560-4769-844e-e665898a3ad7" isSystem="True" name="ContactDataTypes" reportParameterType_id="48a87a08-ea57-46d0-a3ee-713cad78b4fd" queryParameterName="@contactDataType" />
  </Parameters>
  <ParameterTypes>
    <ParameterType id="48a87a08-ea57-46d0-a3ee-713cad78b4fd" isSystem="True" name="Auswahlliste Kontakttype" datatype="IntegerDDL" dataValueField="Key" dataTextField="Value">
      <query>
        SELECT 'Business' AS Value, 1 AS 'Key'
        UNION
        SELECT 'Private' AS Value, 2 AS 'Key'
      </query>
    </ParameterType>
  </ParameterTypes>
</ReportsExport>