<?xml version="1.0" encoding="ISO-8859-1"?>
<VUE name="RH000020" 
	label="RH. Rapport personnalisé" 
	title="RH. Rapport personnalisé" 
	database="iCTI" 
	swf="*CTI_view1" 
	globals="RH_globals.XML"
	dboptimizer="RH_dboptimizer.XML"
	componentsFile="RH_components.XML" 
	softCode="iCTI_rh"
	helpDokuWIkiDir="rh:vues:rapports_et_syntheses" helpDokuWIkiFile="rh000020"  helpFile="">
	<title><![CDATA[=	
		
		var group_by_label = '';
		if (SELECT.GROUPBY != '-1') {
			group_by_label = ' par ' + SELECT.GROUPBY_LABEL;
		}
		if (SELECT.GROUPBY_2 != '-1') {
			group_by_label = group_by_label + ' et ' + SELECT.GROUPBY_2_LABEL;
		}

		return SELECT.RAPPORT_LABEL + group_by_label +
		' ('  +  SELECT.PERIODE_LABEL + ' à ' + SELECT.TOPERIODE_LABEL + ')'
		
	]]></title>
	<VIEWPROPERTIES componentName="PROPERTIES_GROUPBY"/>
	<VIEWPROPERTIES>
		<PROPERTY dataLink="VIEWPROPERTIES" nameField="name" valueField="value"/>
	</VIEWPROPERTIES>
	<SELECTIONS label="Paramètres de l'analyse" displayText="">
		<GROUP label="Période">
			<FIELD name="ALIAS_PERIODE" label="" UI="combo" width="220" default="CUM_LAST_MONTH" tree="true" globalListProvider="ALIAS_PERIODE" />
			<FIELD name="PERIODE" label="" UI="combo" tree="true" width="200" default="2010-01-01" globalListProvider="PERIODE_DEBUT" />
			<FIELD name="TOPERIODE" label="au" UI="combo" tree="true" width="200" default="2010-01-31" globalListProvider="PERIODE_FIN" />
		</GROUP>
		<GROUP label="Rapport">
			<FIELD name="RAPPORT" label="" width="200" UI="combo" tree="true" default="-1" globalListProvider="RAPPORTS">
			</FIELD>
		</GROUP>
		<GROUP label="Regroupement">
			<FIELD name="GROUPBY" label="" UI="combo" width="250" default="ENT" tree="true" >
				<OPTION label="Entreprise" data="ENT" treeLevel="1" globalListProvider="ENTREPRISE_GROUPBY"/>
				<OPTION label="[DICT.RH.SALARIE#1]" data="SAL" treeLevel="1" globalListProvider="SALARIE_GROUPBY"/>
				<OPTION label="[DICT.RH.CONTRAT#1]" data="CNT" treeLevel="1" globalListProvider="CONTRAT_GROUPBY"/>
				<OPTION label="Référentiel SAE" data="REFERENTIEL_SAE" treeLevel="1" globalListProvider="REFERENTIEL_SAE_GROUPBY"/>
			</FIELD>
			<FIELD name="GROUPBY_TAB" width="100" label="Présentation" UI="combo" default="AUTO" visible="= SELECT.GROUPBY_2 != '-1' ">
				<OPTION label="Automatique" data="AUTO"/>
				<OPTION label="Arbre" data="TREE"/>
				<OPTION label="Onglet" data="TAB"/>
			</FIELD>
		</GROUP>
		<GROUP label="">
			<FIELD name="GROUPBY_2" label="" width="250" UI="combo" default="-1" tree="true" >
				<OPTION label="Pas de second niveau" data="-1"/>
				<OPTION label="Entreprise" data="ENT" treeLevel="1" globalListProvider="ENTREPRISE_GROUPBY"/>
				<OPTION label="[DICT.RH.SALARIE#1]" data="SAL" treeLevel="1" globalListProvider="SALARIE_GROUPBY"/>
				<OPTION label="[DICT.RH.CONTRAT#1]" data="CNT" treeLevel="1" globalListProvider="CONTRAT_GROUPBY"/>
				<OPTION label="Référentiel SAE" data="REFERENTIEL_SAE" treeLevel="1" globalListProvider="REFERENTIEL_SAE_GROUPBY"/>
			</FIELD>
		</GROUP>
		<GROUP label="">
			<FIELD name="GROUPBY_3" label="" width="250" UI="combo" default="-1" tree="true" >
				<OPTION label="Pas de troisième niveau" data="-1"/>
				<OPTION label="Entreprise" data="ENT" treeLevel="1" globalListProvider="ENTREPRISE_GROUPBY"/>
				<OPTION label="[DICT.RH.SALARIE#1]" data="SAL" treeLevel="1" globalListProvider="SALARIE_GROUPBY"/>
				<OPTION label="[DICT.RH.CONTRAT#1]" data="CNT" treeLevel="1" globalListProvider="CONTRAT_GROUPBY"/>
				<OPTION label="Référentiel SAE" data="REFERENTIEL_SAE" treeLevel="1" globalListProvider="REFERENTIEL_SAE_GROUPBY"/>
			</FIELD>
		</GROUP>
	</SELECTIONS>
	<SELECTIONS componentName="FILTRES_SALCNT_SOUSSELECTIONS"/>
	<SELECTIONS componentName="FILTRES_SALARIES_SELECTIONS"/>
	<SELECTIONS componentName="FILTRES_CONTRATS_SELECTIONS"/>
	<SELECTIONS componentName="FILTRES_REFERENTIEL_SAE_SELECTIONS"/>
	<QUERIES>
		<QUERY label=""> 
			<SQL optimizer="V_CNT_X" optimizer2="V_ALL_X">
				<select><![CDATA[		

					CTIPREPAR_TREE
						WORKTABLE{TEMP.RH00020_P_C}
						GROUPBY1{[VIEW.GROUPBY_OID_FIELD],, [VIEW.GROUPBY_COD_FIELD],, [VIEW.GROUPBY_TXT_FIELD]}
						GROUPBY1MODE{[GROUPBY_TAB],,1}
						GROUPBY2{[VIEW.GROUPBY_2_OID_FIELD],, [VIEW.GROUPBY_2_COD_FIELD],, [VIEW.GROUPBY_2_TXT_FIELD]}
						GROUPBY3{[VIEW.GROUPBY_3_OID_FIELD],, [VIEW.GROUPBY_3_COD_FIELD],, [VIEW.GROUPBY_3_TXT_FIELD]}
						INDICATORS{
							[VIEW.INDICATEURS_CONTRAT]
						}	
					FROM #V_CNT_X##V_ALL_X#
					WHERE 1=1
                        AND v_rh_view_1.date_fin_activite BETWEEN '[PERIODE]' AND '[TOPERIODE]'
                        AND est_hors_periode IS DISTINCT FROM '1'
                        AND fictif <> '1'
						[VIEW.SALARIES_SELECT]
						[VIEW.CONTRATS_SELECT]
						[VIEW.REFERENTIEL_SAE_SELECT]

				]]></select>
			</SQL>
			<SQL optimizer="V_HP_X" optimizer2="V_ALL_X">
				<select><![CDATA[		

					CTIPREPAR_TREE
						WORKTABLE{TEMP.RH00020_P_H}
						GROUPBY1{[VIEW.GROUPBY_OID_FIELD],, [VIEW.GROUPBY_COD_FIELD],, [VIEW.GROUPBY_TXT_FIELD]}
						GROUPBY1MODE{[GROUPBY_TAB]}
						GROUPBY2{[VIEW.GROUPBY_2_OID_FIELD],, [VIEW.GROUPBY_2_COD_FIELD],, [VIEW.GROUPBY_2_TXT_FIELD]}
						GROUPBY3{[VIEW.GROUPBY_3_OID_FIELD],, [VIEW.GROUPBY_3_COD_FIELD],, [VIEW.GROUPBY_3_TXT_FIELD]}
						INDICATORS{
							[VIEW.INDICATEURS_PAIE]
						}	
					FROM #V_HP_X##V_ALL_X#
					WHERE 1=1
                        AND v_rh_view_1.date_paie BETWEEN '[PERIODE]' AND '[TOPERIODE]'
						[VIEW.SALARIES_SELECT]
						[VIEW.CONTRATS_SELECT]
						[VIEW.REFERENTIEL_SAE_SELECT]
				]]></select>
			</SQL>
			<SQL optimizer="V_AT_X" optimizer2="V_ALL_X">
				<select><![CDATA[		

					CTIPREPAR_TREE
						WORKTABLE{TEMP.RH00020_P_A}
						GROUPBY1{[VIEW.GROUPBY_OID_FIELD],, [VIEW.GROUPBY_COD_FIELD],, [VIEW.GROUPBY_TXT_FIELD]}
						GROUPBY1MODE{[GROUPBY_TAB]}
						GROUPBY2{[VIEW.GROUPBY_2_OID_FIELD],, [VIEW.GROUPBY_2_COD_FIELD],, [VIEW.GROUPBY_2_TXT_FIELD]}
						GROUPBY3{[VIEW.GROUPBY_3_OID_FIELD],, [VIEW.GROUPBY_3_COD_FIELD],, [VIEW.GROUPBY_3_TXT_FIELD]}
						INDICATORS{
							[VIEW.INDICATEURS_ARRET]
						}	
					FROM #V_AT_X##V_ALL_X#
					WHERE 1=1
                        AND v_rh_view_1.date_fin_activite BETWEEN '[PERIODE]' AND '[TOPERIODE]'
						[VIEW.SALARIES_SELECT]
						[VIEW.CONTRATS_SELECT]
						[VIEW.REFERENTIEL_SAE_SELECT]

				]]></select>
			</SQL>
			<SQL optimizer="V_PLA_X" optimizer2="V_ALL_X">
				<select><![CDATA[		

					CTIPREPAR_TREE
						WORKTABLE{TEMP.RH00020_P_P}
						GROUPBY1{[VIEW.GROUPBY_OID_FIELD],, [VIEW.GROUPBY_COD_FIELD],, [VIEW.GROUPBY_TXT_FIELD]}
						GROUPBY1MODE{[GROUPBY_TAB]}
						GROUPBY2{[VIEW.GROUPBY_2_OID_FIELD],, [VIEW.GROUPBY_2_COD_FIELD],, [VIEW.GROUPBY_2_TXT_FIELD]}
						GROUPBY3{[VIEW.GROUPBY_3_OID_FIELD],, [VIEW.GROUPBY_3_COD_FIELD],, [VIEW.GROUPBY_3_TXT_FIELD]}
						INDICATORS{
							[VIEW.INDICATEURS_PLANNING]
						}	
					FROM #V_PLA_X##V_ALL_X#
					WHERE 1=1
                        AND v_rh_view_1.date_fin_activite BETWEEN '[PERIODE]' AND '[TOPERIODE]'
						[VIEW.SALARIES_SELECT]
						[VIEW.CONTRATS_SELECT]
						[VIEW.REFERENTIEL_SAE_SELECT]

				]]></select>
			</SQL>
			<SQL>
				<select><![CDATA[

				CTIPREPAR_TREE
					WORKTABLE{TEMP.RH00020_P_CAL}
					INDICATORS{
						[VIEW.INDICATEURS_CALENDRIER]
					}
				FROM base.v_calendrier_indicateurs_1
				WHERE 1=1
					AND v_calendrier_indicateurs_1.date BETWEEN '[PERIODE]' AND '[TOPERIODE]'
				;

				]]></select>
			</SQL>
			<SQL>
				<select><![CDATA[ 

				DROP TABLE IF EXISTS tables_rapports
				;

				CREATE TEMP TABLE tables_rapports AS
					SELECT COUNT(*), work_table_sequence
					FROM TEMP.RH00020_P_A
					GROUP BY 2
					UNION ALL SELECT COUNT(*), work_table_sequence
					FROM TEMP.RH00020_P_H
					GROUP BY 2
					UNION ALL SELECT COUNT(*), work_table_sequence
					FROM TEMP.RH00020_P_C
					GROUP BY 2
					UNION ALL SELECT COUNT(*), work_table_sequence
					FROM TEMP.RH00020_P_P
					GROUP BY 2
				;

				-- Selection de la table de paramétres disposants du plus de données
				DROP TABLE IF EXISTS table_selectionnee
				;

				CREATE TEMP TABLE table_selectionnee AS
					SELECT MAX(work_table_sequence) AS work_table_sequence
					FROM tables_rapports
					WHERE count = (SELECT MAX(count) FROM tables_rapports)
				;

				-- Position des indicateurs/valeurs CALENDRIER dans le tableau des indicateurs
				DROP TABLE IF EXISTS calendrier
				;

				CREATE TEMP TABLE calendrier AS
					SELECT
						array_positions(indicateurs, (array_remove(indicateurs, NULL))[1]) AS positions,
						array_remove(indicateurs, NULL) AS valeurs
					FROM TEMP.RH00020_P_CAL
				;

				]]></select>
			</SQL>
			<SQL>
				<select><![CDATA[

				DROP TABLE IF EXISTS donnees
				;

				CREATE TEMP TABLE donnees AS 
					SELECT * FROM TEMP.RH00020_P_A
					UNION ALL SELECT * FROM TEMP.RH00020_P_H
					UNION ALL SELECT * FROM TEMP.RH00020_P_C
					UNION ALL SELECT * FROM TEMP.RH00020_P_P
					UNION ALL SELECT * FROM TEMP.RH00020_P_CAL
				;

				-- Choix arbitraire
				-- Ajout des indicateurs CALENDRIER dans le tableau d'indicateurs de la table disposant du plus de données
				UPDATE donnees
					SET
						indicateurs = subview.replace_indicateurs
					FROM (
						SELECT
							oid1,
							oid2,
							oid3,
							base.cti_array_update_by_indexes(indicateurs, calendrier.positions, calendrier.valeurs) AS replace_indicateurs
						FROM donnees, calendrier
						WHERE work_table_sequence = (SELECT work_table_sequence FROM table_selectionnee)
					) AS subview
						WHERE
							donnees.oid1 != -9999999 AND
							donnees.oid1 = subview.oid1 AND
							donnees.oid2 = subview.oid2 AND
							donnees.oid3 = subview.oid3 AND
							work_table_sequence = (SELECT work_table_sequence FROM table_selectionnee)
				;

				]]></select>
			</SQL>
			<SQL>
				<select><![CDATA[		

					SELECT oidt, labelt, textet, 
						oid1, code1, 
						oid2, code2, 
						oid3, code3, 
						oid, code, texte, level, 
						[VIEW.RUBRIQUES_RAPPORT]
					FROM donnees
					GROUP BY 1,2,3,4,5,6,7,8,9,10,11,12,13
					ORDER BY labelt,oidt,code1,oid1,code2,oid2,code3,oid3

				]]></select>
				<FIELDS>
					<INSERT name="CTISELECT_TREE_FIELDS"/>
					<FIELD name="IN01" />
					<FIELD name="IN02" />
					<FIELD name="IN03" />
					<FIELD name="IN04" />
					<FIELD name="IN05" />
					<FIELD name="IN06" />
					<FIELD name="IN07" />
					<FIELD name="IN08" />
					<FIELD name="IN09" />
					<FIELD name="IN10" />
					<FIELD name="IN11" />
					<FIELD name="IN12" />
					<FIELD name="IN13" />
					<FIELD name="IN14" />
					<FIELD name="IN15" />
					<FIELD name="IN16" />
					<FIELD name="IN17" />
					<FIELD name="IN18" />
					<FIELD name="IN19" />
					<FIELD name="IN20" />
				</FIELDS>
			</SQL>
		</QUERY>
		<QUERY type="propertiesLink" name="VIEWPROPERTIES" forSelections="false">
			<SQL>
				<select><![CDATA[	
				
					SELECT * FROM rh.cti_prepare_rapport([RAPPORT]) AS (name text, value text)

				]]></select>
				<FIELDS>
					<FIELD name="name"/>
					<FIELD name="value"/>
				</FIELDS>
			</SQL>
		</QUERY>
	</QUERIES>
	<PRESENTATION>
		<VIEWLINKS>
		</VIEWLINKS>
		<ONGLET label="Onglet" multiTab="true" >
			<DATAGRID 	title="" 
						total="true" 
						headerHeight="40" 
						selectRowInRows="= ROW.OID == '-9999997'" 
						otherRowInRows="= ROW.OID == '-9999998'" 
						totalRowInRows="= ROW.OID == '-9999999'"
						variableRowHeight="true" 
						sortable="= SELECT.GROUPBY_3 == '-1' &amp;&amp; (SELECT.GROUPBY_2 == '-1' || SELECT.GROUPBY_TAB == 'TAB')"> 
				<INSERT name="DATAGRID_MULTITAB_STYLES"/>
				<COLUMN dataField="OID"
					type="Number"
					visible="false" />
				<COLUMN dataField="COD" 
					type="Char" 
					width="120"
					outputFormat="#"
					headerText="Code" 
					textAlign="left" 
					totalComplement="*ROW">
					<INSERT name="COLUMN_COD_MULTITAB_STYLES"/>
				</COLUMN>
				<COLUMN dataField="TXT" 
					type="Char" 
					minWidth="110"
					headerText="Texte" 
					textAlign="left" 
					totalComplement="*ROW"/>
				<COLUMN dataField="IN01" 
					width="= Number(VIEW.IW1)" 
					type="Number" 
					outputFormat="= VIEW.IO1" 
					fixed="false" 
					visibleCondition="VIEW.IC1 != null" 
					headerText="VIEW.IH1" 
					headerTextCalc="true" 
					textAlign="right" 
					totalFunction="sum" 
					otherFunction="" 
					/>
				<COLUMN dataField="IN02" 
					width="= Number(VIEW.IW2)" 
					type="Number" 
					outputFormat="= VIEW.IO2" 
					fixed="false" 
					visibleCondition="VIEW.IC2 != null" 
					headerText="VIEW.IH2" 
					headerTextCalc="true" 
					textAlign="right" 
					totalFunction="sum" 
					otherFunction="" 
					/>
				<COLUMN dataField="IN03" 
					width="= Number(VIEW.IW3)" 
					type="Number" 
					outputFormat="= VIEW.IO3" 
					fixed="false" 
					visibleCondition="VIEW.IC3 != null" 
					headerText="VIEW.IH3" 
					headerTextCalc="true" 
					textAlign="right" 
					totalFunction="sum" 
					otherFunction="" 
					/>
				<COLUMN dataField="IN04" 
					width="= Number(VIEW.IW4)" 
					type="Number" 
					outputFormat="= VIEW.IO4" 
					fixed="false" 
					visibleCondition="VIEW.IC4 != null" 
					headerText="VIEW.IH4" 
					headerTextCalc="true" 
					textAlign="right" 
					totalFunction="sum" 
					otherFunction="" 
					/>
				<COLUMN dataField="IN05" 
					width="= Number(VIEW.IW5)" 
					type="Number" 
					outputFormat="= VIEW.IO5" 
					fixed="false" 
					visibleCondition="VIEW.IC5 != null" 
					headerText="VIEW.IH5" 
					headerTextCalc="true" 
					textAlign="right" 
					totalFunction="sum" 
					otherFunction="" 
					/>
				<COLUMN dataField="IN06" 
					width="= Number(VIEW.IW6)" 
					type="Number" 
					outputFormat="= VIEW.IO6" 
					fixed="false" 
					visibleCondition="VIEW.IC6 != null" 
					headerText="VIEW.IH6" 
					headerTextCalc="true" 
					textAlign="right" 
					totalFunction="sum" 
					otherFunction="" 
					/>
				<COLUMN dataField="IN07" 
					width="= Number(VIEW.IW7)" 
					type="Number" 
					outputFormat="= VIEW.IO7" 
					fixed="false" 
					visibleCondition="VIEW.IC7 != null" 
					headerText="VIEW.IH7" 
					headerTextCalc="true" 
					textAlign="right" 
					totalFunction="sum" 
					otherFunction="" 
					/>
				<COLUMN dataField="IN08" 
					width="= Number(VIEW.IW8)" 
					type="Number" 
					outputFormat="= VIEW.IO8" 
					fixed="false" 
					visibleCondition="VIEW.IC8 != null" 
					headerText="VIEW.IH8" 
					headerTextCalc="true" 
					textAlign="right" 
					totalFunction="sum" 
					otherFunction="" 
					/>
				<COLUMN dataField="IN09" 
					width="= Number(VIEW.IW9)" 
					type="Number" 
					outputFormat="= VIEW.IO9" 
					fixed="false" 
					visibleCondition="VIEW.IC9 != null" 
					headerText="VIEW.IH9" 
					headerTextCalc="true" 
					textAlign="right" 
					totalFunction="sum" 
					otherFunction="" 
					/>
				<COLUMN dataField="IN10" 
					width="= Number(VIEW.IW10)" 
					type="Number" 
					outputFormat="= VIEW.IO10" 
					fixed="false" 
					visibleCondition="VIEW.IC10 != null" 
					headerText="VIEW.IH10" 
					headerTextCalc="true" 
					textAlign="right" 
					totalFunction="sum" 
					otherFunction="" 
					/>
				<COLUMN dataField="IN11" 
					width="= Number(VIEW.IW11)" 
					type="Number" 
					outputFormat="= VIEW.IO11" 
					fixed="false" 
					visibleCondition="VIEW.IC11 != null" 
					headerText="VIEW.IH11" 
					headerTextCalc="true" 
					textAlign="right" 
					totalFunction="sum" 
					otherFunction="" 
					/>
				<COLUMN dataField="IN12" 
					width="= Number(VIEW.IW12)" 
					type="Number" 
					outputFormat="= VIEW.IO12" 
					fixed="false" 
					visibleCondition="VIEW.IC12 != null" 
					headerText="VIEW.IH12" 
					headerTextCalc="true" 
					textAlign="right" 
					totalFunction="sum" 
					otherFunction="" 
					/>
				<COLUMN dataField="IN13" 
					width="= Number(VIEW.IW13)" 
					type="Number" 
					outputFormat="= VIEW.IO13" 
					fixed="false" 
					visibleCondition="VIEW.IC13 != null" 
					headerText="VIEW.IH13" 
					headerTextCalc="true" 
					textAlign="right" 
					totalFunction="sum" 
					otherFunction="" 
					/>
				<COLUMN dataField="IN14" 
					width="= Number(VIEW.IW14)" 
					type="Number" 
					outputFormat="= VIEW.IO14" 
					fixed="false" 
					visibleCondition="VIEW.IC14 != null" 
					headerText="VIEW.IH14" 
					headerTextCalc="true" 
					textAlign="right" 
					totalFunction="sum" 
					otherFunction="" 
					/>
				<COLUMN dataField="IN15" 
					width="= Number(VIEW.IW15)" 
					type="Number" 
					outputFormat="= VIEW.IO15" 
					fixed="false" 
					visibleCondition="VIEW.IC15 != null" 
					headerText="VIEW.IH15" 
					headerTextCalc="true" 
					textAlign="right" 
					totalFunction="sum" 
					otherFunction="" 
					/>
				<COLUMN dataField="IN16" 
					width="= Number(VIEW.IW16)" 
					type="Number" 
					outputFormat="= VIEW.IO16" 
					fixed="false" 
					visibleCondition="VIEW.IC16 != null" 
					headerText="VIEW.IH16" 
					headerTextCalc="true" 
					textAlign="right" 
					totalFunction="sum" 
					otherFunction="" 
					/>
				<COLUMN dataField="IN17" 
					width="= Number(VIEW.IW17)" 
					type="Number" 
					outputFormat="= VIEW.IO17" 
					fixed="false" 
					visibleCondition="VIEW.IC17 != null" 
					headerText="VIEW.IH17" 
					headerTextCalc="true" 
					textAlign="right" 
					totalFunction="sum" 
					otherFunction="" 
					/>
				<COLUMN dataField="IN18" 
					width="= Number(VIEW.IW18)" 
					type="Number" 
					outputFormat="= VIEW.IO18" 
					fixed="false" 
					visibleCondition="VIEW.IC18 != null" 
					headerText="VIEW.IH18" 
					headerTextCalc="true" 
					textAlign="right" 
					totalFunction="sum" 
					otherFunction="" 
					/>
				<COLUMN dataField="IN19" 
					width="= Number(VIEW.IW19)" 
					type="Number" 
					outputFormat="= VIEW.IO19" 
					fixed="false" 
					visibleCondition="VIEW.IC19 != null" 
					headerText="VIEW.IH19" 
					headerTextCalc="true" 
					textAlign="right" 
					totalFunction="sum" 
					otherFunction="" 
					/>
				<COLUMN dataField="IN20" 
					width="= Number(VIEW.IW20)" 
					type="Number" 
					outputFormat="= VIEW.IO20" 
					fixed="false" 
					visibleCondition="VIEW.IC20 != null" 
					headerText="VIEW.IH20" 
					headerTextCalc="true" 
					textAlign="right" 
					totalFunction="sum" 
					otherFunction="" 
					/>
			</DATAGRID>
		</ONGLET>
	</PRESENTATION>
</VUE>