<?xml version="1.0" encoding="ISO-8859-15"?>
<VUE name="ACTI000019" label="Activité. Séjours facturés 'clinique'" title="= 'Séjours clinique - ' + SELECT.QUELMONTANT2 + ' (' + SELECT.QUELLEDATE_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_ACTI000019.HTML">
	<VIEWPROPERTIES>
		<PROPERTY name="QUELLEDATE_FIELD" value="" >
            <value>
                <![CDATA[
                    [EVAL 
                        return ACTI_get_quelledate2("[QUELLEDATE]");
                    EVAL]
                ]]>
            </value>
        </PROPERTY>
	</VIEWPROPERTIES>
	<SELECTIONS label="Paramètres de l'analyse">
		<GROUP label="Période">
			<FIELD name="QUELLEDATE" label="" UI="combo" default="1" >
				<OPTION label="Date activité" data="1" data2="v_factures_lignes_c_4.date_fin"/>
				<OPTION label="Date sortie" data="2" data2="v_factures_lignes_c_4.date_fin_facture"/>
				<OPTION label="Date facture" data="3" data2="v_factures_lignes_c_4.date_facture"/>
				<OPTION label="Date vente" data="4" data2="v_factures_lignes_c_4.date_vente"/>
			</FIELD>
			<FIELD name="ALIAS_PERIODE" label="" UI="combo" width="220" default="CUM_LAST_MONTH" tree="true" globalListProvider="ALIAS_PERIODE" />
			<FIELD name="PERIODE" label="de" UI="combo" tree="true" width="200" default="2007-01-01" globalListProvider="DATE_DEBUT" >
			</FIELD>
			<FIELD name="TOPERIODE" label="à" UI="combo" tree="true" width="200" default="2007-01-31" globalListProvider="DATE_FIN" >
			</FIELD>
		</GROUP>
		<GROUP label="Donnée">
			<FIELD name="QUELMONTANT" label="" UI="combo" default="1" width="300">
				<OPTION label="Montant facturé" data="1" data2="Facturation"/>
				<OPTION label="Montant comptabilisé" data="2" data2="Comptabilisation"/>
				<OPTION label="Comparaison Facturé / Budget global" data="FACVSBG" data2="Comparaison Facturation / Budget global" condition="ENV.TYPEETS != '1'"/>
				<OPTION label="Montant valorisé des dossiers sortis non facturés" data="ENF" data2="Valorisation dossiers sortis non facturés"/>
				<OPTION label="Montant facturé et valorisé des dossiers sortis non facturés" data="MF-ENF" data2="Facturation et Valorisation dossiers sortis non facturés"/>
			</FIELD>
		</GROUP>
		<GROUP label="Détail">
			<FIELD name="OPTION_DET_RUB" label="Rubrique" UI="check" selectedValue="1" unselectedValue="0" default="0" showIfNotDefault="true" />
		</GROUP>
	</SELECTIONS>
	<SELECTIONS componentName="FILTRES_PRESTATIONS_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="
				
					SELECT v_sejours_1.no_sejour,
							
						nom || ' ' || prenom, 
						v_sejours_1.date_entree, 
						CASE WHEN v_sejours_1.date_sortie &lt;&gt; '2099-12-31' AND code_sorti = '1' THEN to_char(v_sejours_1.date_sortie,'YYYY-MM-DD') ELSE '' END::text, 
						
						CASE WHEN '[OPTION_DET_RUB]' = '1' THEN rubrique_facturation_code || ' ' || rubrique_facturation_texte ELSE '' END,
						
						[QUELMONTANT==1::
						SUM(montant_facture),
						SUM(montant_facture_1),
						SUM(montant_facture_2 + montant_facture_22),
						SUM(montant_facture_0),
						0,
						0,
						0,
						SUM(CASE WHEN origine_facturation_id = 3 THEN montant_facture_actes_inclus_dans_sejour ELSE 0 END),
						SUM(CASE WHEN COALESCE(origine_facturation_id,0) &lt;= 1 THEN montant_facture ELSE 0 END),
						SUM(CASE WHEN COALESCE(origine_facturation_id,0) = 2 THEN montant_facture ELSE 0 END),
						0
						]
						[QUELMONTANT==2::
						SUM(montant_comptabilise + COALESCE(montant_comptabilise_budget_global_1,0)),
						SUM(montant_comptabilise_1),
						SUM(montant_comptabilise_2 + montant_comptabilise_22),
						SUM(montant_comptabilise_0),
						0,
						0,
						0,
						SUM(CASE WHEN origine_facturation_id = 3 THEN montant_facture_actes_inclus_dans_sejour ELSE 0 END),
						0,
						0,
						SUM(COALESCE(montant_comptabilise_budget_global_1,0))
						]
						[QUELMONTANT==FACVSBG::
						0,
						SUM(montant_facture_1),
						SUM(COALESCE(montant_comptabilise_budget_global_1,0)),
						SUM(montant_facture_1 - COALESCE(montant_comptabilise_budget_global_1,0)),
						SUM(CASE WHEN montant_facture_1 &lt;&gt; 0 THEN nb_prestation * coefficient ELSE 0 END),
						SUM(CASE WHEN COALESCE(montant_comptabilise_budget_global_1,0) &lt;&gt; 0 THEN nb_prestation * coefficient ELSE 0 END),
						SUM(CASE WHEN montant_facture_1 &lt;&gt; 0 THEN nb_prestation * coefficient ELSE null END) 
							- SUM(CASE WHEN COALESCE(montant_comptabilise_budget_global_1,0) &lt;&gt; 0 THEN nb_prestation * coefficient ELSE 0 END),
						0,
						0,
						0,
						0
						]
						[QUELMONTANT==ENF::
						SUM(montant_encours),
						SUM(CASE WHEN code_sorti = '1' AND nb_non_groupe = 0 AND est_ligne_encours = '1' THEN montant_encours ELSE 0 END),
						SUM(CASE WHEN code_sorti = '1' AND nb_non_groupe &lt;&gt; 0 AND est_ligne_encours = '1' THEN montant_encours ELSE 0 END),
						SUM(CASE WHEN code_sorti &lt;&gt; '1' AND est_ligne_encours = '1' THEN montant_encours ELSE 0 END),
						0,
						0,
						0,
						0,
						0,
						0,
						0
						]
						[QUELMONTANT==MF-ENF::
						SUM(montant_facture + montant_encours),
						SUM(montant_facture),
						SUM(montant_encours),
						0,
						0,
						0,
						0,
						0,
						0,
						0,
						0
						]
						,
						SUM(nb_rubrique * coefficient),
						SUM(nb_prestation * coefficient)
					FROM #V_FACTURES_LIGNES_C_X#
						JOIN #V_SEJOURS_X# ON v_sejours_1.no_sejour = v_factures_lignes_c_4.no_sejour
						JOIN activite.p_patients ON v_sejours_1.no_patient = p_patients.no_patient
					WHERE v_factures_lignes_c_4.[VIEW.QUELLEDATE_FIELD] BETWEEN '[PERIODE]' AND '[TOPERIODE]'
						[QUELMONTANT==1::
							AND est_ligne_facturee = '1' 
						]
						[QUELMONTANT==2::
							AND est_ligne_comptabilisee = '1' 
						]
						[QUELMONTANT==FACVSBG::
							AND v_sejours_1.est_budget_global = 1 AND COALESCE(v_sejours_1.montant_comptabilise_budget_global_c,0) &lt;&gt; 0 AND (montant_facture_1 &lt;&gt; 0 OR COALESCE(montant_comptabilise_budget_global_1,0) &lt;&gt; 0)
						]
						[QUELMONTANT==ENF::
							AND est_ligne_encours = '1'
						]
						[QUELMONTANT==MF-ENF::
							AND (est_ligne_facturee = '1'  OR est_ligne_encours = '1')
						]
						[VIEW.SEJOURS_SELECT]
						[VIEW.PRESTATIONS_SELECT]
						[VIEW.PASSAGES_SELECT]
						
					GROUP BY 1,2,3,4,5

					ORDER BY 1	">
				<FIELDS>
					<FIELD name="SEJ"/>
					<FIELD name="NOM" ifHideNames="Non autorisé"/>
					
					<FIELD name="DENT"/>
					<FIELD name="DSOR"/>
					<FIELD name="RUB"/>
					<FIELD name="MT"/>
					<FIELD name="M1"/>
					<FIELD name="M2"/>
					<FIELD name="M3"/>
					<FIELD name="N1"/>
					<FIELD name="N2"/>
					<FIELD name="N3"/>
					<FIELD name="MTAS"/>
					<FIELD name="MTC"/>
					<FIELD name="MTH"/>
					<FIELD name="MTBG"/>
					<FIELD name="NR"/>
					<FIELD name="NP"/>
				</FIELDS>
			</SQL>
			<SQL optimizer="V_SEJOURS_X" optimizer2="V_FACTURES_LIGNES_C_X"
				select="
				
					SELECT '-9999999',
							
						COUNT(DISTINCT v_sejours_1.no_sejour)::text || ' séjours', 
						null, 
						null, 
						[QUELMONTANT==1::
						SUM(montant_facture),
						SUM(montant_facture_1),
						SUM(montant_facture_2 + montant_facture_22),
						SUM(montant_facture_0),
						0,
						0,
						0,
						SUM(CASE WHEN origine_facturation_id = 3 THEN montant_facture_actes_inclus_dans_sejour ELSE 0 END),
						SUM(CASE WHEN COALESCE(origine_facturation_id,0) &lt;= 1 THEN montant_facture ELSE 0 END),
						SUM(CASE WHEN COALESCE(origine_facturation_id,0) = 2 THEN montant_facture ELSE 0 END),
						0
						]
						[QUELMONTANT==2::
						SUM(montant_comptabilise + COALESCE(montant_comptabilise_budget_global_1,0)),
						SUM(montant_comptabilise_1),
						SUM(montant_comptabilise_2 + montant_comptabilise_22),
						SUM(montant_comptabilise_0),
						0,
						0,
						0,
						SUM(CASE WHEN origine_facturation_id = 3 THEN montant_facture_actes_inclus_dans_sejour ELSE 0 END),
						0,
						0,
						SUM(COALESCE(montant_comptabilise_budget_global_1,0))
						]
						[QUELMONTANT==FACVSBG::
						0,
						SUM(montant_facture_1),
						SUM(COALESCE(montant_comptabilise_budget_global_1,0)),
						SUM(montant_facture_1 - COALESCE(montant_comptabilise_budget_global_1,0)),
						SUM(CASE WHEN montant_facture_1 &lt;&gt; 0 THEN nb_prestation * coefficient ELSE 0 END),
						SUM(CASE WHEN COALESCE(montant_comptabilise_budget_global_1,0) &lt;&gt; 0 THEN nb_prestation * coefficient ELSE 0 END),
						SUM(CASE WHEN montant_facture_1 &lt;&gt; 0 THEN nb_prestation * coefficient ELSE 0 END) 
							- SUM(CASE WHEN COALESCE(montant_comptabilise_budget_global_1,0) &lt;&gt; 0 THEN nb_prestation * coefficient ELSE 0 END),
						0,
						0,
						0,
						0
						]
						[QUELMONTANT==ENF::
						SUM(montant_encours),
						SUM(CASE WHEN code_sorti = '1' AND nb_non_groupe = 0 AND montant_encours &lt;&gt; 0 THEN montant_encours ELSE 0 END),
						SUM(CASE WHEN code_sorti = '1' AND nb_non_groupe &lt;&gt; 0 AND montant_encours &lt;&gt; 0 THEN montant_encours ELSE 0 END),
						SUM(CASE WHEN code_sorti &lt;&gt; '1' AND montant_encours &lt;&gt; 0 THEN montant_encours ELSE 0 END),
						0,
						0,
						0,
						0,
						0,
						0,
						0
						]
						[QUELMONTANT==MF-ENF::
						SUM(montant_facture + montant_encours),
						SUM(montant_facture),
						SUM(montant_encours),
						0,
						0,
						0,
						0,
						0,
						0,
						0,
						0
						]
						,
						SUM(nb_rubrique * coefficient),
						SUM(nb_prestation * coefficient)
					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.[VIEW.QUELLEDATE_FIELD] BETWEEN '[PERIODE]' AND '[TOPERIODE]'
						[QUELMONTANT==1::
							AND est_ligne_facturee = '1' 
						]
						[QUELMONTANT==2::
							AND est_ligne_comptabilisee = '1' 
						]
						[QUELMONTANT==FACVSBG::
							AND v_sejours_1.est_budget_global = 1 AND COALESCE(v_sejours_1.montant_comptabilise_budget_global_c,0) &lt;&gt; 0 AND (montant_facture_1 &lt;&gt; 0 OR COALESCE(montant_comptabilise_budget_global_1,0) &lt;&gt; 0)
						]
						[QUELMONTANT==ENF::
							AND est_ligne_encours = '1'
						]
						[QUELMONTANT==MF-ENF::
							AND (est_ligne_facturee = '1'  OR est_ligne_encours = '1')
						]
						[VIEW.SEJOURS_SELECT]
						[VIEW.PRESTATIONS_SELECT]
						[VIEW.PASSAGES_SELECT]

					ORDER BY 1	">
				<FIELDS>
					<FIELD name="SEJ"/>
					<FIELD name="NOM" ifHideNames="Non autorisé"/>
					<FIELD name="DENT"/>
					<FIELD name="DSOR"/>
					<FIELD name="MT"/>
					<FIELD name="M1"/>
					<FIELD name="M2"/>
					<FIELD name="M3"/>
					<FIELD name="N1"/>
					<FIELD name="N2"/>
					<FIELD name="N3"/>
					<FIELD name="MTAS"/>
					<FIELD name="MTC"/>
					<FIELD name="MTH"/>
					<FIELD name="MTBG"/>
					<FIELD name="NR"/>
					<FIELD name="NP"/>
				</FIELDS>
			</SQL>
		</QUERY>
		<QUERY type="propertiesLink" name="VIEWPROPERTIES" forRows="false">
		</QUERY>
	</QUERIES>
	<PRESENTATION>
		<VIEWLINKS>
			<VIEWLINK label="Détail séjour" shortLabel="Détail séjour" view="ACTI000020.XML">
				<ARG name="SEJOUR" value="ROW.SEJ"/>
			</VIEWLINK>
		</VIEWLINKS>
		<ONGLET excelLabel="Facturation" label="Facturation">
			<DATAGRID title="" total="true" showOthers="true" key="RANG" headerHeight="48" totalRowInRows="= ROW.SEJ == '-9999999'">
				<COLUMN dataField="SEJ" width="100" type="Char" headerText="No séjour" textAlign="left" otherFunction="text" totalFunction="text" totalComplement="TOTAL">
				</COLUMN>
				<COLUMN dataField="RUB" width="100" type="Char" 
					visibleCondition="SELECT.OPTION_DET_RUB == '1'"
					headerText="Rubrique" textAlign="left" otherFunction="text" totalFunction="text" totalComplement="TOTAL">
				</COLUMN>
				<COLUMN dataField="SEJ" width="100" type="Char" headerText="No séjour" textAlign="left" otherFunction="text" totalFunction="text" totalComplement="TOTAL">
				</COLUMN>
				<COLUMN dataField="NOM" type="Char" minWidth="50" headerText="Nom" textAlign="left" totalFunction="text" totalComplement="*ROW">
				</COLUMN>
				<COLUMN dataField="DENT" width="60" type="Date" inputFormat="AAAA-MM-JJ" outputFormat="DD/MM/YY" fixed="false" headerText="Date entrée" textAlign="right" totalFunction="text">
				</COLUMN>
				<COLUMN dataField="DSOR" width="60" type="Date" inputFormat="AAAA-MM-JJ" outputFormat="DD/MM/YY" fixed="false" headerText="Date sortie" textAlign="right" totalFunction="text">
				</COLUMN>
				<COLUMN dataField="NR" width="80" type="Number" visibleCondition="SELECT.QUELMONTANT != 'FACVSBG' &amp;&amp; SELECT.RUBRIQUE != '-1'" outputFormat="#" headerText="Nombre" textAlign="right" totalFunction="sum" otherFunction="">
				</COLUMN>
				<COLUMN dataField="NP" width="80" type="Number" visibleCondition="SELECT.QUELMONTANT != 'FACVSBG' &amp;&amp; SELECT.PRESTATION != '-1'" outputFormat="#" headerText="Nombre" textAlign="right" totalFunction="sum" otherFunction="">
				</COLUMN>
				<COLUMN dataField="MT" width="80" type="Number" outputFormat="#E" visibleCondition="SELECT.QUELMONTANT != 'MF-ACTES' &amp;&amp; SELECT.QUELMONTANT != 'FACVSBG'" headerText="if (SELECT.QUELMONTANT == '1') {return 'Total Facturé'}
								if (SELECT.QUELMONTANT == '2') {return 'Total Comptabilisé'}
								if (SELECT.QUELMONTANT == 'ENF') {return 'Montant Valorisé'}
								if (SELECT.QUELMONTANT == 'MF-ENF') {return 'Montant Facturé + Valorisé'}
					" headerTextCalc="true" textAlign="right" totalFunction="sum" otherFunction="">
				</COLUMN>
				<COLUMN dataField="MTC" width="80" type="Number" visibleCondition="SELECT.QUELMONTANT == '1' &amp;&amp; ENV.TYPEETS != '1'" headerText="if (SELECT.QUELMONTANT == '1') {return 'Montant Séjour'}
								if (SELECT.QUELMONTANT == '2') {return ''}
								if (SELECT.QUELMONTANT == 'ENF') {return ''}
								if (SELECT.QUELMONTANT == 'MF-ENF') {return ''}
					" headerTextCalc="true" outputFormat="#E" textAlign="right" totalFunction="sum" otherFunction="">
				</COLUMN>
				<COLUMN dataField="MTAS" width="80" type="Number" visibleCondition="(SELECT.QUELMONTANT == '1' || SELECT.QUELMONTANT == '2') &amp;&amp; ENV.TYPEETS != '1'" headerText="if (SELECT.QUELMONTANT == '1') {return 'Dont actes dans séjour'}
								if (SELECT.QUELMONTANT == '2') {return 'Dont actes dans séjour'}
								if (SELECT.QUELMONTANT == 'ENF') {return ''}
								if (SELECT.QUELMONTANT == 'MF-ENF') {return ''}
					" headerTextCalc="true" outputFormat="#E" textAlign="right" totalFunction="sum" otherFunction="">
				</COLUMN>
				<COLUMN dataField="MTH" width="80" type="Number" visibleCondition="SELECT.QUELMONTANT == '1' &amp;&amp; ENV.TYPEETS != '1'" headerText="if (SELECT.QUELMONTANT == '1') {return 'Montant Actes'}
								if (SELECT.QUELMONTANT == '2') {return ''}
								if (SELECT.QUELMONTANT == 'ENF') {return ''}
								if (SELECT.QUELMONTANT == 'MF-ENF') {return ''}
					" headerTextCalc="true" outputFormat="#E" textAlign="right" totalFunction="sum" otherFunction="">
				</COLUMN>
				<COLUMN dataField="N1" width="80" type="Number" visibleCondition="SELECT.QUELMONTANT == 'FACVSBG' &amp;&amp; SELECT.PRESTATION != '-1'" headerText="if (SELECT.QUELMONTANT == 'FACVSBG') {return 'Nombre facturé AMO'}" headerTextCalc="true" outputFormat="#" textAlign="right" fixed="false" totalFunction="sum" otherFunction="">
				</COLUMN>
				<COLUMN dataField="M1" width="80" type="Number" visible="true" headerText="if (SELECT.QUELMONTANT == '1') {return 'Montant AMO'}
								if (SELECT.QUELMONTANT == '2') {return 'Montant AMO'}
								if (SELECT.QUELMONTANT == 'ENF') {return 'Montant (Groupés ou hors PMSI)'}
								if (SELECT.QUELMONTANT == 'MF-ENF') {return 'Montant Facturé'}
								if (SELECT.QUELMONTANT == 'FACVSBG') {return 'Montant facturé AMO'}
					" headerTextCalc="true" outputFormat="#E" textAlign="right" totalFunction="sum" otherFunction="">
				</COLUMN>
				<COLUMN dataField="MTBG" width="80" type="Number" visibleCondition="SELECT.QUELMONTANT == '2' &amp;&amp; ENV.TYPEETS != '1'" headerText="if (SELECT.QUELMONTANT == '1') {return ''}
								if (SELECT.QUELMONTANT == '2') {return 'Montant AMO BG'}
								if (SELECT.QUELMONTANT == 'ENF') {return ''}
								if (SELECT.QUELMONTANT == 'MF-ENF') {return ''}
					" headerTextCalc="true" outputFormat="#E" textAlign="right" totalFunction="sum" otherFunction="">
				</COLUMN>
				<COLUMN dataField="N2" width="80" type="Number" visibleCondition="SELECT.QUELMONTANT == 'FACVSBG' &amp;&amp; SELECT.PRESTATION != '-1'" headerText="if (SELECT.QUELMONTANT == 'FACVSBG') {return 'Nombre AMO BG'}" headerTextCalc="true" outputFormat="#" textAlign="right" fixed="false" totalFunction="sum" otherFunction="">
				</COLUMN>
				<COLUMN dataField="M2" width="80" type="Number" visible="true" headerText="if (SELECT.QUELMONTANT == '1') {return 'Montant AMC'}
								if (SELECT.QUELMONTANT == '2') {return 'Montant AMC'}
								if (SELECT.QUELMONTANT == 'ENF') {return 'Montant (Non groupés)'}
								if (SELECT.QUELMONTANT == 'MF-ENF') {return 'Montant Valorisé'}
								if (SELECT.QUELMONTANT == 'FACVSBG') {return 'Montant AMO BG'}
					" headerTextCalc="true" outputFormat="#E" textAlign="right" totalFunction="sum" otherFunction="">
				</COLUMN>
				<COLUMN dataField="N3" width="80" type="Number" visibleCondition="SELECT.QUELMONTANT == 'FACVSBG' &amp;&amp; SELECT.PRESTATION != '-1'" headerText="if (SELECT.QUELMONTANT == 'FACVSBG') {return 'Ecart nombre'}" headerTextCalc="true" outputFormat="#" textAlign="right" fixed="false" totalFunction="sum" otherFunction="">
				</COLUMN>
				<COLUMN dataField="M3" width="80" type="Number" visibleCondition="SELECT.QUELMONTANT != 'MF-ENF'" headerText="if (SELECT.QUELMONTANT == '1') {return 'Montant Patient'}
								if (SELECT.QUELMONTANT == '2') {return 'Montant Patient'}
								if (SELECT.QUELMONTANT == 'ENF') {return 'Montant (Présents)'}
								if (SELECT.QUELMONTANT == 'MF-ENF') {return ''}
								if (SELECT.QUELMONTANT == 'FACVSBG') {return 'Ecart montant'}
					" headerTextCalc="true" outputFormat="#E" textAlign="right" totalFunction="sum" otherFunction="">
				</COLUMN>
			</DATAGRID>
		</ONGLET>
	</PRESENTATION>
</VUE>
