<?xml version="1.0" encoding="ISO-8859-1"?>
<VUE name="RH000022" 
	label="RH. Synthèse comparative" 
	title="RH. Synthèse comparative"
	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="rh000022"  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 + ' comparatif ' + group_by_label +
		' ('  +  SELECT.PERIODE_LABEL + ' à ' + SELECT.TOPERIODE_LABEL + ' vs ' + SELECT.PERIODE_D_LABEL + ' à ' + SELECT.TOPERIODE_D_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>
			<FIELD name="TOPERIODE" label="au" UI="combo" tree="true" width="200" default="2010-01-31" globalListProvider="PERIODE_FIN">
			</FIELD>
		</GROUP>
		<GROUP label="Période précédente">
			<FIELD name="PERIODE_D" label="" UI="combo" tree="true" width="200" default="2010-01-01" globalListProvider="PERIODE_DEBUT">
			</FIELD>
			<FIELD name="TOPERIODE_D" label="au" UI="combo" tree="true" width="200" default="2010-01-31" globalListProvider="PERIODE_FIN">
			</FIELD>
		</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="Pas de premier 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>
			<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.RH000022_P}
						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]}
						COLUMNBYDATECOMP{v_rh_view_1.date_fin_activite,, '[PERIODE]' ,, '[TOPERIODE]',, '[PERIODE_D]' ,, '[TOPERIODE_D]',,  ,,  ,, ,, }
						INDICATORS{
							[VIEW.INDICATEURS_CONTRAT]
						}
					FROM #V_CNT_X##V_ALL_X#
					WHERE 
						(v_rh_view_1.date_fin_activite BETWEEN '[PERIODE]' AND '[TOPERIODE]' OR
						v_rh_view_1.date_fin_activite BETWEEN '[PERIODE_D]' AND '[TOPERIODE_D]')
						[VIEW.SALARIES_SELECT]
						[VIEW.CONTRATS_SELECT]
						[VIEW.REFERENTIEL_SAE_SELECT]
						
						AND est_hors_periode IS DISTINCT FROM '1'

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

					CTIPREPAR_TREE
						WORKTABLE{TEMP.RH000022_P,, ADD}
						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]}
						COLUMNBYDATECOMP{v_rh_view_1.date_paie,, '[PERIODE]' ,, '[TOPERIODE]',, '[PERIODE_D]' ,, '[TOPERIODE_D]',,  ,,  ,, ALREADYEXISTS ,, }
						INDICATORS{
							[VIEW.INDICATEURS_PAIE]
						}
					FROM #V_HP_X##V_ALL_X#
					WHERE 
						(v_rh_view_1.date_paie BETWEEN '[PERIODE]' AND '[TOPERIODE]' OR
						v_rh_view_1.date_paie BETWEEN '[PERIODE_D]' AND '[TOPERIODE_D]')
						[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.RH000022_P,, ADD}
						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]}
						COLUMNBYDATECOMP{v_rh_view_1.date_fin_activite,, '[PERIODE]' ,, '[TOPERIODE]',, '[PERIODE_D]' ,, '[TOPERIODE_D]',,  ,,  ,, ALREADYEXISTS ,, }
						INDICATORS{
							[VIEW.INDICATEURS_ARRET]
						}	
					FROM #V_AT_X##V_ALL_X#
					WHERE 
						(v_rh_view_1.date_fin_activite BETWEEN '[PERIODE]' AND '[TOPERIODE]' OR
						v_rh_view_1.date_fin_activite BETWEEN '[PERIODE_D]' AND '[TOPERIODE_D]')
						[VIEW.SALARIES_SELECT]
						[VIEW.CONTRATS_SELECT]
						[VIEW.REFERENTIEL_SAE_SELECT]
						

				]]></select>
			</SQL>
			<SQL>
				<select><![CDATA[		
				
					DROP TABLE IF EXISTS TEMP.RH000022_T;
					CREATE TABLE TEMP.RH000022_T AS
					SELECT oidt, labelt, textet,  						oid1, code1,  						oid2, code2, oid3, code3, 						
					oid, code, texte, level,  						
					ARRAY[[VIEW.RUBRIQUES_RAPPORT]] as indicateurs_mois					
					FROM TEMP.RH000022_P						
					GROUP BY 1,2,3,4,5,6,7,8,9,10,11,12,13 ;
					
					UPDATE TEMP.RH000022_T SET level = 1, code1 = chr(255), code2 = chr(255), code3 = chr(255), code = '', texte = 'TOTAL' 
						WHERE level = 1 AND oidt <> -9999999 AND oid2 = -9999999;
					UPDATE TEMP.RH000022_T SET level = 1, code1 = chr(255), code2 = chr(255), code3 = chr(255), code = '', texte = 'TOTAL' 
						WHERE level = 9  AND oidt = -9999999;
					
					
					DROP TABLE IF EXISTS TEMP.RH000022_L;
					CREATE TABLE TEMP.RH000022_L AS
					SELECT 
						MAX(CASE WHEN oidt < 0 THEN level ELSE 0 END) AS level_s,
						MAX(CASE WHEN oidt >= 0 THEN level ELSE 0 END) AS level_t
					FROM TEMP.RH000022_T;
					
					SELECT 
						oidt, labelt, textet,  						
						oid1, code1,  						
						oid2, code2, 
						oid3, code3, 
						0 AS oid4, chr(1)::text AS code4,
						oid, code, code || ' ' || texte, 
						level,
						'#' AS output_format,
						CASE WHEN level = '1' AND level_s > 1 THEN 24 ELSE 20 END AS row_height, 
						CASE WHEN level = '1' THEN 0 WHEN level = '2' THEN 20 ELSE 40 END AS padding , 
						CASE WHEN level = '1' AND level_s > 1 THEN 14 ELSE 12 END AS font_size, 
						'bold' AS font_weight, 
						CASE WHEN level < '3' AND level_s > 1 THEN 2 WHEN level < '2' AND level_s > 1 THEN 2 ELSE 0 END AS border_thickness, 
						CASE WHEN level < '3' AND level_s > 1 THEN '0xFFFFFF' ELSE '' END AS color, 
						CASE 
							WHEN level = '1' AND level_s > 1 THEN '0x012B43' 
							WHEN level = '1' AND level_t > 1 THEN '0xFF8801' 
							WHEN level = '2' AND level_s > 1 THEN '0xFF8801'
							ELSE '0xFFFFFF' END AS background_color,
						0,0,0,0,0,0,0
					FROM TEMP.RH000022_T, TEMP.RH000022_L

					UNION

					SELECT 
						oidt, labelt, textet,						
						oid1,
						code1,  						
						CASE WHEN oid2 != -9999999 THEN oid2 ELSE t_rapports_rubriques.numero_rubrique * 10000 + t_rapports_rubriques.indicateur_id END AS oid2,
						code2,
						CASE WHEN oid3 != -9999999 THEN oid3 ELSE CASE WHEN oid2 != -9999999 THEN t_rapports_rubriques.numero_rubrique * 10000 + t_rapports_rubriques.indicateur_id ELSE oid3 END END AS oid3,
						code3,
						t_rapports_rubriques.numero_rubrique * 10000 + t_rapports_rubriques.indicateur_id AS oid4,
						trim(to_char(numero_rubrique,'0000'))::text AS code4,							
						t_rapports_rubriques.indicateur_id AS oid, 
						numero_rubrique::text AS code, 
						CASE WHEN t_rapports_rubriques.entete_etendue <> '' THEN t_rapports_rubriques.entete_etendue ELSE t_indicateurs.entete_etendue END AS texte,						
						CASE
							WHEN oid3 != -9999999 THEN 4
							WHEN oid2 != -9999999 THEN 3
							WHEN oid1 = -9999999 AND
								CASE
									WHEN oid2 != -9999999 THEN oid2
									ELSE t_rapports_rubriques.indicateur_id
								END != -9999999 THEN 2
							WHEN oid1 != -9999999 THEN 2
							ELSE 1
						END AS level,
						CASE WHEN t_rapports_rubriques.output_format <> '' THEN t_rapports_rubriques.output_format ELSE t_indicateurs.output_format END,
						t_rapports_rubriques.row_height, 
						(level * 20) + t_rapports_rubriques.padding , 
						t_rapports_rubriques.font_size, 
						t_rapports_rubriques.font_weight, 
						t_rapports_rubriques.border_thickness, 
						t_rapports_rubriques.color, 
						CASE WHEN t_rapports_rubriques.background_color <> '' THEN t_rapports_rubriques.background_color ELSE '0xFFFFFF' END,

						indicateurs_mois[numero_rubrique][1],
						indicateurs_mois[numero_rubrique][2],
						indicateurs_mois[numero_rubrique][2] - indicateurs_mois[numero_rubrique][1],
						base.cti_division(
							indicateurs_mois[numero_rubrique][2] - indicateurs_mois[numero_rubrique][1]
							,
							indicateurs_mois[numero_rubrique][1]
							)*100,
						indicateurs_mois[numero_rubrique][5],
						indicateurs_mois[numero_rubrique][5] - indicateurs_mois[numero_rubrique][2],
						base.cti_division(
							indicateurs_mois[numero_rubrique][5] - indicateurs_mois[numero_rubrique][2]
							,
							indicateurs_mois[numero_rubrique][2]
							)*100


					FROM TEMP.RH000022_T, TEMP.RH000022_L
						JOIN rh.t_rapports_rubriques ON rapport_id = [RAPPORT]
						JOIN rh.t_indicateurs ON indicateur_id = t_indicateurs.oid
					ORDER BY 4,6,8,10

				]]></select>
				<FIELDS>
					<INSERT name="CTISELECT_TREE_FIELDS4"/>
					<FIELD name="OUTFMT" />
					<FIELD name="ROWHEI" />
					<FIELD name="PAD" />
					<FIELD name="FNTSIZ" />
					<FIELD name="FNTWEI" />
					<FIELD name="BRDTHI" />
					<FIELD name="FNTCOL" />
					<FIELD name="BAKCOL" />
					<FIELD name="NP3"/>
					<FIELD name="NP2"/>
					<FIELD name="EP2"/>
					<FIELD name="PP2"/>
					<FIELD name="NP1"/>
					<FIELD name="EP1"/>
					<FIELD name="PP1"/>
				</FIELDS>
			</SQL>
		</QUERY>
		<QUERY type="propertiesLink" name="VIEWPROPERTIES" forSelections="false">
			<SQL>
				<select><![CDATA[	
				
					SELECT * FROM rh.cti_prepare_rapport_comp([RAPPORT]) AS (name text, value text)

				]]></select>
				<FIELDS>
					<FIELD name="name"/>
					<FIELD name="value"/>
				</FIELDS>
			</SQL>
		</QUERY>
	</QUERIES>
	<PRESENTATION>
		<VIEWLINKS>
		</VIEWLINKS>
		<ONGLET excelLabel="Evolution mensuelle" label="Evolution mensuelle" multiTab="true">
			<DATAGRID title="" total="false" showOthers="true" headerHeight="54" variableRowHeight="true" sortable="false" >
				<ROWSTYLE name="fontSize" value="10"/>
				<ROWSTYLE name="fontSize" value="= ROW.FNTSIZ.toString()" condition="Number(ROW.FNTSIZ) &gt;= 8"/>
				<ROWSTYLE name="fontWeight" value="bold" condition="ROW.FNTWEI == 'bold'"/>
				<ROWSTYLE name="rowHeight" value="= ROW.ROWHEI.toString()" condition="Number(ROW.ROWHEI) &gt; 0"/>
				<ROWSTYLE name="borderSides" value="top bottom" condition="Number(ROW.BRDTHI) &gt; 0"/>
				<ROWSTYLE name="borderStyle" value="solid" condition="Number(ROW.BRDTHI) &gt; 0"/>
				<ROWSTYLE name="borderThickness" value="= ROW.BRDTHI.toString()" condition="Number(ROW.BRDTHI) &gt; 0"/>
				<ROWSTYLE name="color" value="= ROW.FNTCOL.toString()" condition="ROW.FNTCOL != '' "/>
				<ROWSTYLE name="backgroundColor" value="= ROW.BAKCOL.toString()" condition="ROW.BAKCOL != '' "/>
				<COLUMN dataField="OUTFMT" type="Char" visible="false"/>
				<COLUMN dataField="ROWHEI" type="Char" visible="false"/>
				<COLUMN dataField="PAD" type="Char" visible="false"/>
				<COLUMN dataField="FNTSIZ" type="Char" visible="false"/>
				<COLUMN dataField="FNTWEI" type="Char" visible="false"/>
				<COLUMN dataField="BRDTHI" type="Char" visible="false"/>
				<COLUMN dataField="FNTCOL" type="Char" visible="false"/>
				<COLUMN dataField="BAKCOL" type="Char" visible="false"/>
				<COLUMN dataField="LVL" width="50" type="Char" visible="false" headerText="Code" textAlign="left" otherFunction="text" totalFunction="text">
				</COLUMN>
				<COLUMN dataField="OID1" width="60" type="Char" visible="false" headerText="Oid">
				</COLUMN>
				<COLUMN dataField="COD1" width="60" type="Char" visible="false" headerText="Oid">
				</COLUMN>
				<COLUMN dataField="OID2" width="60" type="Char" visible="false" headerText="Oid">
				</COLUMN>
				<COLUMN dataField="COD2" width="60" type="Char" visible="false" headerText="Oid">
				</COLUMN>
				<COLUMN dataField="OID3" width="60" type="Char" visible="false" headerText="Oid">
				</COLUMN>
				<COLUMN dataField="COD3" width="60" type="Char" visible="false" headerText="Oid">
				</COLUMN>
				<COLUMN dataField="OID4" width="60" type="Char" visible="false" headerText="Oid">
				</COLUMN>
				<COLUMN dataField="COD4" width="60" type="Char" visible="false" headerText="Oid">
				</COLUMN>
				<COLUMN dataField="OID" width="60" type="Char" visible="false" headerText="Oid">
				</COLUMN>
				<COLUMN dataField="COD" width="90" type="Char" visible="false" headerText="Code" textAlign="left" otherFunction="text" totalFunction="text" totalComplement="TOTAL">
				</COLUMN>
				<COLUMN dataField="TXT" type="Char" minWidth="50" headerText="Indicateur" textAlign="left" totalFunction="text" otherFunction="text" otherComplement="*ROW">
					<CELLSTYLE name="paddingLeft" value="= ROW.PAD" condition="Number(ROW.PAD) &gt; 0"/>
				</COLUMN>
				<COLUMN dataField="NP3" width="80" visibleCondition="VIEW.COLH3 != null" type="Number" outputFormat="= ROW.OUTFMT" fixed="false" selectable="false" headerText="VIEW.COLH3" headerTextCalc="true" textAlign="right" otherFunction="sum" totalFunction="sum">
				</COLUMN>
				<COLUMN dataField="NP2" width="80" visibleCondition="VIEW.COLH2 != null" type="Number" outputFormat="= ROW.OUTFMT" fixed="false" selectable="false" headerText="VIEW.COLH2" headerTextCalc="true" textAlign="right" otherFunction="sum" totalFunction="sum">
				</COLUMN>
				<COLUMN dataField="EP2" width="80" visibleCondition="VIEW.COLH3 != null" type="Number" outputFormat="= ROW.OUTFMT" fixed="false" selectable="false" headerText="VIEW.COLHE2" headerTextCalc="true" textAlign="right" otherFunction="sum" totalFunction="sum">
				</COLUMN>
				<COLUMN dataField="PP2" width="80" visibleCondition="VIEW.COLH3 != null" type="Number" outputFormat="#,00 %" fixed="false" selectable="false" headerText="VIEW.COLHP2" headerTextCalc="true" textAlign="right" otherFunction="sum" totalFunction="sum">
				</COLUMN>
				<COLUMN dataField="NP1" width="80" visibleCondition="VIEW.COLH1 != null" type="Number" outputFormat="= ROW.OUTFMT" fixed="false" selectable="false" headerText="VIEW.COLH1" headerTextCalc="true" textAlign="right" otherFunction="sum" totalFunction="sum">
				</COLUMN>
				<COLUMN dataField="EP1" width="80" visibleCondition="VIEW.COLH2 != null" type="Number" outputFormat="= ROW.OUTFMT" fixed="false" selectable="false" headerText="VIEW.COLHE1" headerTextCalc="true" textAlign="right" otherFunction="sum" totalFunction="sum">
				</COLUMN>
				<COLUMN dataField="PP1" width="80" visibleCondition="VIEW.COLH2 != null" type="Number" outputFormat="#,00 %" fixed="false" selectable="false" headerText="VIEW.COLHP1" headerTextCalc="true" textAlign="right" otherFunction="sum" totalFunction="sum">
				</COLUMN>
			</DATAGRID>
		</ONGLET>
	</PRESENTATION>
</VUE>