<?xml version="1.0" encoding="ISO-8859-1"?>
<VUE name="RH000138"
	 label="RH. Rémunération brute moyenne"
	 title="= 'Rémunération brute moyenne ' +  SELECT.SEL_PERIODE_LABEL"
	 database="iCTI"
	 swf="*CTI_view1"
	 softCode="iCTI_rh">
	<SELECTIONS label="Paramètres de l'analyse" displayText="">
		<GROUP label="Période">
			<FIELD name="SEL_PERIODE" label="" UI="combo" width="250" default="" tree="true" >
				<OPTION dataLink="SEL_PERIODE_LIST" treeLevelField="lvl" dataField="cod" labelField="txt" />
			</FIELD>
		</GROUP>
		<GROUP label="Regroupement 1">
			<FIELD name="GROUPBY" label="" UI="combo" width="250" default="qualification" tree="true" >
				<OPTION data="qualification" label="Qualification" treeLevel="1" alias="qualification" cti="1" />
				<OPTION data="service" label="Service" treeLevel="1" alias="service" cti="1" />
			</FIELD>
		</GROUP>
		<GROUP label="Regroupement 2">
			<FIELD name="GROUPBY_2" label="" UI="combo" width="250" default="service" tree="true" >
				<OPTION data="qualification" label="Qualification" treeLevel="1" alias="qualification" cti="1" />
				<OPTION data="service" label="Service" treeLevel="1" alias="service" cti="1" />
			</FIELD>
		</GROUP>
	</SELECTIONS>
	<QUERIES>
		<QUERY type="comboLink" name="SEL_PERIODE_LIST">
			<SQL><select><![CDATA[

					SELECT
						1000 AS tri,
						  1 AS lvl,
						  'Années' AS txt,
						  'BETWEEN ' ||  to_char((date_trunc('YEAR'::text, NOW()) - interval '1 YEAR')::date, 'YYYYMM')::int || ' AND ' ||  to_char(((date_trunc('YEAR'::text, NOW()) - interval '1 YEAR') + interval '1 YEAR' - interval '1 DAY')::date, 'YYYYMM')::int AS cod
					UNION ALL
					SELECT 
						  1001 AS tri,
						  2 AS lvl,
						  'Année N-1' AS txt,
						  'BETWEEN ' ||  to_char((date_trunc('YEAR'::text, NOW()) - interval '1 YEAR')::date, 'YYYYMM')::int || ' AND ' ||  to_char(((date_trunc('YEAR'::text, NOW()) - interval '1 YEAR') + interval '1 YEAR' - interval '1 DAY')::date, 'YYYYMM')::int AS cod
					UNION ALL
					SELECT 
						  1002 AS tri,
						  2 AS lvl,
						  'Année N-2' AS txt,
						  'BETWEEN ' ||  to_char((date_trunc('YEAR'::text, NOW()) - interval '2 YEAR')::date, 'YYYYMM')::int || ' AND ' ||  to_char(((date_trunc('YEAR'::text, NOW()) - interval '2 YEAR') + interval '1 YEAR' - interval '1 DAY')::date, 'YYYYMM')::int AS cod
					UNION ALL
					SELECT 
						  2000 AS tri,
						  1 AS lvl,
						  'Périodes' AS txt,
						'BETWEEN ' ||  to_char((date_trunc('MONTH'::text, NOW()) - interval '3 MONTH')::date, 'YYYYMM')::int || ' AND ' ||  to_char(((date_trunc('MONTH'::text, NOW()) - interval '3 MONTH') + interval '3 MONTH' - interval '1 DAY')::date, 'YYYYMM')::int AS cod
					UNION ALL
					SELECT 
						2001 AS tri,
						2 AS lvl,
						'3 derniers mois' AS txt,
						'BETWEEN ' ||  to_char((date_trunc('MONTH'::text, NOW()) - interval '3 MONTH')::date, 'YYYYMM')::int || ' AND ' ||  to_char(((date_trunc('MONTH'::text, NOW()) - interval '3 MONTH') + interval '3 MONTH' - interval '1 DAY')::date, 'YYYYMM')::int AS cod
					UNION ALL
					SELECT 
						2002 AS tri,
						2 AS lvl,
						'6 derniers mois' AS txt,
						'BETWEEN ' ||  to_char((date_trunc('MONTH'::text, NOW()) - interval '6 MONTH')::date, 'YYYYMM')::int || ' AND ' ||  to_char(((date_trunc('MONTH'::text, NOW()) - interval '6 MONTH') + interval '6 MONTH' - interval '1 DAY')::date, 'YYYYMM')::int AS cod
					UNION ALL
					SELECT 
						2003 AS tri,
						2 AS lvl,
						'12 derniers mois' AS txt,
						'BETWEEN ' ||  to_char((date_trunc('MONTH'::text, NOW()) - interval '12 MONTH')::date, 'YYYYMM')::int || ' AND ' ||  to_char(((date_trunc('MONTH'::text, NOW()) - interval '12 MONTH') + interval '12 MONTH' - interval '1 DAY')::date, 'YYYYMM')::int AS cod
					UNION ALL
					SELECT 
						2004 AS tri,
						2 AS lvl,
						'18 derniers mois' AS txt,
						'BETWEEN ' ||  to_char((date_trunc('MONTH'::text, NOW()) - interval '18 MONTH')::date, 'YYYYMM')::int || ' AND ' ||  to_char(((date_trunc('MONTH'::text, NOW()) - interval '18 MONTH') + interval '18 MONTH' - interval '1 DAY')::date, 'YYYYMM')::int AS cod
					UNION ALL
					SELECT 
						2005 AS tri,
						2 AS lvl,
						'24 derniers mois' AS txt,
						'BETWEEN ' ||  to_char((date_trunc('MONTH'::text, NOW()) - interval '24 MONTH')::date, 'YYYYMM')::int || ' AND ' ||  to_char(((date_trunc('MONTH'::text, NOW()) - interval '24 MONTH') + interval '24 MONTH' - interval '1 DAY')::date, 'YYYYMM')::int AS cod

                ]]></select>
				<FIELDS>
					<FIELD name="tri" />
					<FIELD name="lvl" />
					<FIELD name="txt" />
					<FIELD name="cod" />
				</FIELDS>
			</SQL>
		</QUERY>
		<QUERY label="Paie">
			<SQL>
				<select>
					<![CDATA[
				
					DROP TABLE IF EXISTS select_nombre_mois
					;
					
					CREATE TEMP TABLE select_nombre_mois AS
						SELECT 
							base.cti_age((MAX(date) + interval '1 DAY')::date, MIN(date), 'nm') AS nombre_mois
						FROM base.p_calendrier
						WHERE date [SEL_PERIODE]
					;
				
					CTISELECT_TREE
                        WORKTABLE{RH000138_GRILLE_PAIE} 
                        GROUPBY1{paie_[GROUPBY]_id,, paie_[GROUPBY]_code,, paie_[GROUPBY]_texte}
                        GROUPBY2{paie_[GROUPBY_2]_id,, paie_[GROUPBY_2]_code,, paie_[GROUPBY_2]_texte}
                        OPTIONS{NOTZERO=1}
						ORDERBY{[VIEW.ORDERBY],, DESC}
                        INDICATORS{
							COUNT(DISTINCT p_sommes_mensuelles_ventilees_paie.salarie_id),,
							SUM(equivalent_temps_plein) / (SELECT nombre_mois FROM select_nombre_mois),,
							AVG(montant_brut),,
							base.cti_array_median(array_agg(montant_brut)),,
							AVG(montant_masse_salariale),,
							base.cti_array_median(array_agg(montant_masse_salariale))
                        }
					FROM rh.p_sommes_mensuelles_ventilees_paie
					WHERE p_sommes_mensuelles_ventilees_paie.mois_paie [SEL_PERIODE]
                ]]></select>
				<FIELDS>
					<INSERT name="CTISELECT_TREE_FIELDS"/>
					<FIELD name="SORT" /><!-- colonne exploitée pour le mécanisme de tri uniquement ORDERBY{indicateur[7]} -->
					<FIELD name="NBSAL" />
					<FIELD name="ETP" />
					<FIELD name="PAIE_MTBRMOY" />
					<FIELD name="PAIE_MTBRMED" />
					<FIELD name="PAIE_MTMSMOY" />
					<FIELD name="PAIE_MTMSMED" />
				</FIELDS>
			</SQL>
		</QUERY>
		<QUERY label="Planning">
			<SQL>
				<select><![CDATA[
					CTISELECT_TREE
                        WORKTABLE{RH000138_GRILLE_PAIE} 
                        GROUPBY1{p_sommes_mensuelles_ventilees_planning.planning_[GROUPBY]_id,, p_sommes_mensuelles_ventilees_planning.planning_[GROUPBY]_code,, p_sommes_mensuelles_ventilees_planning.planning_[GROUPBY]_texte}
                        GROUPBY1MODE{[GROUPBY_TAB]}
                        GROUPBY2{p_sommes_mensuelles_ventilees_planning.planning_[GROUPBY_2]_id,, p_sommes_mensuelles_ventilees_planning.planning_[GROUPBY_2]_code,, p_sommes_mensuelles_ventilees_planning.planning_[GROUPBY_2]_texte}
                        OPTIONS{NOTZERO=1}
						ORDERBY{[VIEW.ORDERBY],, DESC}
                        INDICATORS{
							COUNT(DISTINCT p_sommes_mensuelles_ventilees_planning.salarie_id),,
							SUM(equivalent_temps_plein) / (SELECT nombre_mois FROM select_nombre_mois),,
							AVG(montant_brut),,
							base.cti_array_median(array_agg(montant_brut)),,
							AVG(montant_masse_salariale),,
							base.cti_array_median(array_agg(montant_masse_salariale))
                        }
					FROM rh.p_sommes_mensuelles_ventilees_planning
					JOIN rh.p_taux_horaires_mensuels ON 
						p_taux_horaires_mensuels.salarie_id = p_sommes_mensuelles_ventilees_planning.salarie_id
						AND p_taux_horaires_mensuels.mois_paie = p_sommes_mensuelles_ventilees_planning.mois_paie
					WHERE p_sommes_mensuelles_ventilees_planning.mois_paie [SEL_PERIODE]
                ]]></select>
				<FIELDS>
					<INSERT name="CTISELECT_TREE_FIELDS"/>
					<FIELD name="SORT" /><!-- colonne exploitée pour le mécanisme de tri uniquement ORDERBY{indicateur[7]} -->
					<FIELD name="NBSAL" />
					<FIELD name="ETP" />
					<FIELD name="PLANNING_MTBRMOY" />
					<FIELD name="PLANNING_MTBRMED" />
					<FIELD name="PLANNING_MTMSMOY" />
					<FIELD name="PLANNING_MTMSMED" />
				</FIELDS>
			</SQL>
		</QUERY>
	</QUERIES>
	<PRESENTATION>
		<ONGLET label="Paie"  multiTab="true" queryNumber="0">
			<DATAGRID   title=""
						total="true"
						headerHeight="54"
						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="90"
						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="NBSAL"
						type="Number"
						width="70"
						fixed ="false"
						outputFormat="#"
						headerText="Nombre salariés"
						textAlign="right"/>
				<COLUMN dataField="ETP"
						type="Number"
						width="70"
						fixed ="false"
						outputFormat="#"
						headerText="ETP"
						textAlign="right"/>
				<COLUMN dataField="PAIE_MTBRMOY"
						type="Number"
						width="70"
						fixed ="false"
						outputFormat="#E"
						headerText="Montant brut moyen"
						textAlign="right"
						totalFunction="sum"/>
				<COLUMN dataField="PAIE_MTBRMED"
						type="Number"
						width="70"
						fixed ="false"
						outputFormat="#E"
						headerText="Montant brut median"
						textAlign="right"/>
				<COLUMN dataField="PAIE_MTMSMOY"
						type="Number"
						width="70"
						fixed ="false"
						outputFormat="#E"
						headerText="Montant masse salariale moyen"
						textAlign="right"/>
				<COLUMN dataField="PAIE_MTMSMED"
						type="Number"
						width="70"
						fixed ="false"
						outputFormat="#E"
						headerText="Montant masse salariale median"
						textAlign="right"/>
			</DATAGRID>
		</ONGLET>
		<ONGLET label="Planning"  multiTab="true" queryNumber="1">
			<DATAGRID   title=""
						total="true"
						headerHeight="54"
						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="90"
						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="NBSAL"
						type="Number"
						width="70"
						fixed ="false"
						outputFormat="#"
						headerText="Nombre salariés"
						textAlign="right"/>
				<COLUMN dataField="ETP"
						type="Number"
						width="70"
						fixed ="false"
						outputFormat="#"
						headerText="ETP"
						textAlign="right"/>
				<COLUMN dataField="PLANNING_MTBRMOY"
						type="Number"
						width="70"
						fixed ="false"
						outputFormat="#E"
						headerText="Montant brut moyen"
						textAlign="right"/>
				<COLUMN dataField="PLANNING_MTBRMED"
						type="Number"
						width="70"
						fixed ="false"
						outputFormat="#E"
						headerText="Montant brut median"
						textAlign="right"/>
				<COLUMN dataField="PLANNING_MTMSMOY"
						type="Number"
						width="70"
						fixed ="false"
						outputFormat="#E"
						headerText="Montant masse salariale moyen"
						textAlign="right"/>
				<COLUMN dataField="PLANNING_MTMSMED"
						type="Number"
						width="70"
						fixed ="false"
						outputFormat="#E"
						headerText="Montant masse salariale median"
						textAlign="right"/>
			</DATAGRID>
		</ONGLET>
	</PRESENTATION>
</VUE>
