<?xml version="1.0" encoding="ISO-8859-15"?>
<VUE name="ACTI000102" label="Activité. Analyse taux de facturation forfaits" title="= 'Taux de facturation forfaits par ' +  SELECT.GROUPBY_LABEL + ' (' + SELECT.PERIODE_LABEL + ' à ' + SELECT.TOPERIODE_LABEL + ')'" database="iCTI" swf="*CTI_view1" softCode="iCTI_activite" globals="ACTI_globals.XML" componentsFile="ACTI_components.XML" 
        helpFile="iCTI_ACTI_ACTI000102.HTML"
        helpDokuWIkiDir="activite:qualite:etudes:forfaits" 
        helpDokuWIkiFile="acti000102" 
>
	<VIEWPROPERTIES componentName="PROPERTIES_OCCUPATION"/>
	<VIEWPROPERTIES>
	
		<PROPERTY name="RUBRIQUE_SELECT" >
				<value><![CDATA[
					[EVAL 

						$select_type = substr('[RUBRIQUE]',0,2);
						$select_oid = substr('[RUBRIQUE]',2);
						if ($select_type == "LS") {
							$section = ACTI_get_section_id('[RUBRIQUE]');
							$select_oid = ACTI_get_classe_oid('[RUBRIQUE]');
						}
						if ($select_type == 'LI') {return "AND rubrique_facturation_id IN (SELECT to_id FROM activite.t_listes_contenu WHERE liste_id = $select_oid)";}
						if ($select_type == 'LS') {return "AND rubrique_facturation_section_id[" . $section . "] = $select_oid";}
						if ($select_type == 'SL') {return "AND rubrique_facturation_id NOT IN (SELECT to_id FROM activite.t_listes_contenu WHERE liste_id = $select_oid)";}
						if ($select_type == 'RU') {return "AND rubrique_facturation_id = $select_oid";}
						if ('[RUBRIQUE]' == 'SAISIECODE') {
							return "AND rubrique_facturation_id IN (SELECT oid FROM activite.t_rubriques_facturation WHERE " . sql_codes_list_a('[RUBRIQUE_CODES]', 'code') . ")"; 
						}
						return "AND rubrique_facturation_id = -1";
					EVAL]
				]]></value>
		</PROPERTY>
		
		<PROPERTY dataLink="VIEWPROPERTIES" nameField="name" valueField="value"/>
	</VIEWPROPERTIES>
	<SELECTIONS label="Paramètres de l'analyse">
		<GROUP>
			<FIELD name="ALIAS_PERIODE" label="" UI="combo" width="220" default="CUM_LAST_MONTH" tree="true" globalListProvider="ALIAS_PERIODE" />
            <FIELD name="PERIODE" label="Période" UI="combo" tree="true" width="200" default="2009-01-01" globalListProvider="DATE_DEBUT" >
			</FIELD>
			<FIELD name="TOPERIODE" label="à" UI="combo" tree="true" width="200" default="2009-01-31" globalListProvider="DATE_FIN" >
			</FIELD>
		</GROUP>
		<GROUP label="Regroupement">
			<FIELD name="GROUPBY" label="" UI="combo" width="200" default="SER" tree="true">
				<OPTION label="OCCUPATION_GROUPBY" data="" globalListProvider="OCCUPATION_GROUPBY"/>
				<OPTION label="Mois" data="MOIS"/>
			</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="" UI="combo" width="200" default="-1" tree="true">
				<OPTION label="" data="-1" treeLevel="1"/>
				<OPTION label="OCCUPATION_GROUPBY" data="" globalListProvider="OCCUPATION_GROUPBY"/>
				<OPTION label="Mois" data="MOIS"/>
			</FIELD>
			<FIELD name="GROUPBY_3" label="" UI="combo" width="200" default="-1" tree="true">
				<OPTION label="" data="-1" treeLevel="1"/>
				<OPTION label="OCCUPATION_GROUPBY" data="" globalListProvider="OCCUPATION_GROUPBY"/>
				<OPTION label="Mois" data="MOIS"/>
			</FIELD>
		</GROUP>
		
	</SELECTIONS>
	<SELECTIONS label="Modes de calcul" displayText="= var display:String = '';
						display = display + 'Rubriques : #B#' + SELECT.RUBRIQUE_LABEL + '#/B#\r';
						display = display + 'Modes de calcul : #B#' + VIEW.OPTADM_DAYOUT + '. ' + SELECT.QJMUT_LABEL  + '#/B#';
						return display;
						">
		<GROUP>
			<FIELD name="RUBRIQUE" label="Rubrique forfait" UI="combo" tree="true" width="400" default="-1" globalListProvider="RUBRIQUES" showIfNotDefault="true">
			</FIELD>
			<FIELD name="RUBRIQUE_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.RUBRIQUE == 'SAISIECODE' " />
		</GROUP>
		<GROUP label="Modes">
			<FIELD name="QJMUT" label="" UI="combo" default="f">
				<OPTION data="d" label="Si mutation, journée affectée à la premiere localisation"/>
				<OPTION data="f" label="Si mutation, journée affectée à la dernière localisation"/>
				<OPTION data="12" label="Si mutation, journée affectée à la localisation occupée à 12h"/>
				<OPTION data="prorata" label="Si mutation, journée affectée au prorata du temps passé"/>
			</FIELD>
		</GROUP>
		
	</SELECTIONS>
	<SELECTIONS componentName="FILTRES_OCCUPATION_SOUSSELECTIONS"/>
	<SELECTIONS componentName="FILTRES_MOUVEMENTS_SELECTIONS"/>
	<SELECTIONS componentName="FILTRES_SEJOURS_SELECTIONS"/>
	<SELECTIONS componentName="FILTRES_PASSAGES_SELECTIONS" />
	<QUERIES>
		<QUERY label="">
			
			<SQL optimizer="V_SEJOURS_X" optimizer2="V_FACTURES_LIGNES_C_X">
				<select><![CDATA[
										
					
					DROP SEQUENCE IF EXISTS ACTI000102_facforf_rub_seq
					.,
					CREATE TEMP SEQUENCE ACTI000102_facforf_rub_seq
					.,
					
					DROP TABLE IF EXISTS acti000102_facforf_rub
					.,
					CREATE TEMP TABLE acti000102_facforf_rub AS
					SELECT prestation_id, prestation_code, 
						nextval('ACTI000102_facforf_rub_seq'::regclass) AS columnby_sequence, nb_forf_facturees
					FROM (	
						SELECT prestation_id, prestation_code,    						
							SUM(nb_rubrique) AS nb_forf_facturees				
						FROM #V_FACTURES_LIGNES_C_X#
							JOIN #V_SEJOURS_X# ON v_sejours_1.no_sejour = v_factures_lignes_c_4.no_sejour
						WHERE 
							v_factures_lignes_c_4.date_fin BETWEEN '[PERIODE]' AND '[VIEW.TOPERIODE]'
							[VIEW.SEJOURS_SELECT]
							[VIEW.PASSAGES_SELECT]
							[VIEW.RUBRIQUE_SELECT]
						GROUP BY 1,2
						ORDER BY 2 
					) subview;
					
					CTISELECT_PROPERTY DISTINCT 'COLI' || columnby_sequence::text, CASE WHEN columnby_sequence <= 10 THEN prestation_id::text ELSE '-1' END FROM acti000102_facforf_rub				
					UNION 					
					CTISELECT_PROPERTY DISTINCT 'COLH' || columnby_sequence::text, prestation_code FROM acti000102_facforf_rub;
					
					DROP TABLE IF EXISTS acti000102_facforf
					.,
					CREATE TEMP TABLE acti000102_facforf AS
					SELECT v_sejours_1.no_sejour, 
						v_factures_lignes_c_4.date_fin,
						SUM(nb_rubrique * coefficient) AS nb_forf_facturees,
						SUM(montant_facture + montant_encours) AS montant_forf_facturees,
						SUM(CASE WHEN acti000102_facforf_rub.columnby_sequence = 1 THEN nb_rubrique * coefficient ELSE 0 END) AS nb_forf_facturees_1,
						SUM(CASE WHEN acti000102_facforf_rub.columnby_sequence = 2 THEN nb_rubrique * coefficient ELSE 0 END) AS nb_forf_facturees_2,
						SUM(CASE WHEN acti000102_facforf_rub.columnby_sequence = 3 THEN nb_rubrique * coefficient ELSE 0 END) AS nb_forf_facturees_3,
						SUM(CASE WHEN acti000102_facforf_rub.columnby_sequence = 4 THEN nb_rubrique * coefficient ELSE 0 END) AS nb_forf_facturees_4,
						SUM(CASE WHEN acti000102_facforf_rub.columnby_sequence = 5 THEN nb_rubrique * coefficient ELSE 0 END) AS nb_forf_facturees_5 	
					FROM #V_FACTURES_LIGNES_C_X#
							JOIN #V_SEJOURS_X# ON v_sejours_1.no_sejour = v_factures_lignes_c_4.no_sejour
						JOIN acti000102_facforf_rub ON v_factures_lignes_c_4.prestation_id = acti000102_facforf_rub.prestation_id
					WHERE 
							v_factures_lignes_c_4.date_fin BETWEEN '[PERIODE]' AND '[VIEW.TOPERIODE]'
							[VIEW.SEJOURS_SELECT] [VIEW.PASSAGES_SELECT]
					GROUP BY 1,2
					.,
					
					ALTER TABLE acti000102_facforf ADD CONSTRAINT acti000102_facforf_pkey PRIMARY KEY(no_sejour, date_fin);
				
				]]></select>
				
			</SQL>
			<SQL optimizer="V_SEJOURS_X" optimizer2="V_MOUVEMENTS_SEJOUR_X">
				<select><![CDATA[	
														
					CTISELECT_TREE
						WORKTABLE{acti000102}
						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]}
						SIGNIFDATA{COALESCE(nb_forf_facturees,0),, P,, 99.99}
					INDICATORS{
						COUNT(DISTINCT v_sejours_1.no_sejour),,
						SUM([VIEW.JOURNEES_FIELD] + nb_ambulatoires + nb_externes),,
						
						SUM(nb_forf_facturees_1),,
						SUM(nb_forf_facturees_2),,
						SUM(nb_forf_facturees_3),,
						SUM(nb_forf_facturees_4),,
						SUM(nb_forf_facturees_5),,
						base.cti_division(SUM(nb_forf_facturees_1), SUM([VIEW.JOURNEES_FIELD] + nb_ambulatoires + nb_externes)) * 100,,
						base.cti_division(SUM(nb_forf_facturees_2), SUM([VIEW.JOURNEES_FIELD] + nb_ambulatoires + nb_externes)) * 100,,
						base.cti_division(SUM(nb_forf_facturees_3), SUM([VIEW.JOURNEES_FIELD] + nb_ambulatoires + nb_externes)) * 100,,
						base.cti_division(SUM(nb_forf_facturees_4), SUM([VIEW.JOURNEES_FIELD] + nb_ambulatoires + nb_externes)) * 100,,
						base.cti_division(SUM(nb_forf_facturees_5), SUM([VIEW.JOURNEES_FIELD] + nb_ambulatoires + nb_externes)) * 100,,
					}
					
					FROM #V_SEJOURS_X#
						JOIN #V_MOUVEMENTS_SEJOUR_X# ON v_mouvements_sejour_2.no_sejour = v_sejours_1.no_sejour
						LEFT JOIN acti000102_facforf ON acti000102_facforf.no_sejour = v_mouvements_sejour_2.no_sejour AND
												acti000102_facforf.date_fin = v_mouvements_sejour_2.date
					WHERE 
							date BETWEEN '[PERIODE]' AND '[VIEW.TOPERIODE]' AND
							[VIEW.JOURNEES_FIELD] + nb_ambulatoires + nb_externes <> 0
							[VIEW.SEJOURS_SELECT] [VIEW.PASSAGES_SELECT]
							[VIEW.MOUVEMENTS_SELECT] AND est_mouvement_previsionnel <> '1';
						
				
						
				]]></select>
				<FIELDS>
					<INSERT name="CTISELECT_TREE_FIELDS"/>
					<FIELD name="NBSEJ"/>
					<FIELD name="NBJRN"/>
					<FIELD name="NBFACF1"/>
					<FIELD name="NBFACF2"/>
					<FIELD name="NBFACF3"/>
					<FIELD name="NBFACF4"/>
					<FIELD name="NBFACF5"/>
					<FIELD name="TXFACF1"/>
					<FIELD name="TXFACF2"/>
					<FIELD name="TXFACF3"/>
					<FIELD name="TXFACF4"/>
					<FIELD name="TXFACF5"/>
				</FIELDS>
			</SQL>
		</QUERY>
		<QUERY type="propertiesLink" name="VIEWPROPERTIES" forSelections="false">
			<SQL select="
				SELECT 'TOPERIODE', COALESCE(MAX(date),'[TOPERIODE]') FROM activite.p_mouvements_sejour WHERE date BETWEEN '[PERIODE]' AND '[TOPERIODE]'  AND est_mouvement_previsionnel &lt;&gt; '1'
				">
				<FIELDS>
					<FIELD name="name"/>
					<FIELD name="value"/>
				</FIELDS>
			</SQL>
		</QUERY>
	</QUERIES>
	<PRESENTATION>
		<VIEWLINKS>
			<VIEWLINK label="Justificatif des séjours" shortLabel="Liste séjours" view="ACTI000103.XML" componentName="OCC_BASE_VIEWLINK" component3Name="STANDARD_BASE_VIEWLINK">
				
			</VIEWLINK>

		</VIEWLINKS>
		<ONGLET excelLabel="Occupation" label="Occupation" multiTab="true" multiTabBreakField="TABD" multiTabBreakLabelField="TABDL" multiTabBreakLonglabelField="TABDLL">
			
			<DATAGRID title="" total="true" showOthers="true" headerHeight="48" selectRowInRows="= ROW.OID == '-9999997'" otherRowInRows="= ROW.OID == '-9999998'" totalRowInRows="= ROW.OID == '-9999999'">
				<INSERT name="DATAGRID_MULTITAB_STYLES"/>

				<COLUMN dataField="OID" width="60" type="Char" visible="false" headerText="Oid">
				</COLUMN>
				<COLUMN dataField="COD" width="70" type="Char" visible="true" headerText="Code" textAlign="left" otherFunction="text" totalFunction="text">
					<INSERT name="COLUMN_COD_MULTITAB_STYLES"/>
				</COLUMN>
				<COLUMN dataField="TXT" type="Char" minWidth="150" headerText="SELECT.GROUPBY_LABEL" headerTextCalc="true" textAlign="left" totalFunction="text" totalComplement="TOTAL" otherFunction="text" otherComplement="Autres">
				</COLUMN>
				
				<COLUMN dataField="NBSEJ" width="60" type="Number" selectable="true" visible="true" outputFormat="#" fixed="false" headerText="Nb total séjours" textAlign="right" totalFunction="sum" otherFunction="sum">
				</COLUMN>
				<COLUMN dataField="NBJRN" width="60" type="Number" selectable="true" visible="true" outputFormat="#" fixed="false" headerText="Nb total jours" textAlign="right" totalFunction="sum" otherFunction="sum">
				</COLUMN>
				
				
				<COLUMN dataField="NBFACF1" width="80" type="Number" outputFormat="#" fixed="false" visibleCondition="VIEW.COLH1 != null" headerText="'NB facturé\r' + VIEW.COLH1" columnData="= VIEW.COLI1" headerTextCalc="true" textAlign="right" totalFunction="sum" otherFunction="sum">
				</COLUMN>
				<COLUMN dataField="TXFACF1" width="70" type="Number" outputFormat="#,0%" fixed="false" visibleCondition="VIEW.COLH1 != null" headerText="'Taux\r' + VIEW.COLH1" columnData="= VIEW.COLI1" headerTextCalc="true" textAlign="right" totalFunction="sum" otherFunction="sum">
				</COLUMN>
				<COLUMN dataField="NBFACF2" width="80" type="Number" outputFormat="#" fixed="false" visibleCondition="VIEW.COLH2 != null" headerText="'NB facturé\r' + VIEW.COLH2" columnData="= VIEW.COLI2" headerTextCalc="true" textAlign="right" totalFunction="sum" otherFunction="sum">
				</COLUMN>
				<COLUMN dataField="TXFACF2" width="70" type="Number" outputFormat="#,0%" fixed="false" visibleCondition="VIEW.COLH2 != null" headerText="'Taux\r' + VIEW.COLH2" columnData="= VIEW.COLI2" headerTextCalc="true" textAlign="right" totalFunction="sum" otherFunction="sum">
				</COLUMN>
				<COLUMN dataField="NBFACF3" width="80" type="Number" outputFormat="#" fixed="false" visibleCondition="VIEW.COLH3 != null" headerText="'NB facturé\r' + VIEW.COLH3" columnData="= VIEW.COLI3" headerTextCalc="true" textAlign="right" totalFunction="sum" otherFunction="sum">
				</COLUMN>
				<COLUMN dataField="TXFACF3" width="70" type="Number" outputFormat="#,0%" fixed="false" visibleCondition="VIEW.COLH3 != null" headerText="'Taux\r' + VIEW.COLH3" columnData="= VIEW.COLI3" headerTextCalc="true" textAlign="right" totalFunction="sum" otherFunction="sum">
				</COLUMN>
				<COLUMN dataField="NBFACF4" width="80" type="Number" outputFormat="#" fixed="false" visibleCondition="VIEW.COLH4 != null" headerText="'NB facturé\r' + VIEW.COLH4" columnData="= VIEW.COLI4" headerTextCalc="true" textAlign="right" totalFunction="sum" otherFunction="sum">
				</COLUMN>
				<COLUMN dataField="TXFACF4" width="70" type="Number" outputFormat="#,0%" fixed="false" visibleCondition="VIEW.COLH4 != null" headerText="'Taux\r' + VIEW.COLH4" columnData="= VIEW.COLI4" headerTextCalc="true" textAlign="right" totalFunction="sum" otherFunction="sum">
				</COLUMN>
				<COLUMN dataField="NBFACF5" width="80" type="Number" outputFormat="#" fixed="false" visibleCondition="VIEW.COLH5 != null" headerText="'NB facturé\r' + VIEW.COLH5" columnData="= VIEW.COLI5" headerTextCalc="true" textAlign="right" totalFunction="sum" otherFunction="sum">
				</COLUMN>
				<COLUMN dataField="TXFACF5" width="70" type="Number" outputFormat="#,0%" fixed="false" visibleCondition="VIEW.COLH5 != null" headerText="'Taux\r' + VIEW.COLH5" columnData="= VIEW.COLI5" headerTextCalc="true" textAlign="right" totalFunction="sum" otherFunction="sum">
				</COLUMN>
			</DATAGRID>
		</ONGLET>
	</PRESENTATION>
</VUE>
