<?xml version="1.0" encoding="ISO-8859-15"?>
<VUE name="ACTI000105" label="Activité. Evaluation valorisation en-cours" title="= 'Evaluation valorisation en-cours 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_ACTI000105.HTML"
    helpDokuWIkiDir="activite:comptabilisation_et_en_cours:evaluation_des_en_cours" 
    helpDokuWIkiFile="acti000105" 
>
	<VIEWPROPERTIES componentName="PROPERTIES_PRESTATIONS"/>
	<VIEWPROPERTIES>
		
	</VIEWPROPERTIES>
	<SELECTIONS label="Paramètres de l'analyse" displayText="= var display:String = '';
						display = display + 'Source en-cours : #B#' + SELECT.SOURCE_ENCOURS_LABEL + '#/B#';
						
						return display;
						">
		<GROUP label="Période comptable">
			<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="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>
			<FIELD name="GROUPBY" label="Regroupement" UI="combo" default="SER" width="200" tree="true">
				<OPTION label="PRESTATIONS_GROUPBY" data="" globalListProvider="PRESTATIONS_GROUPBY"/>
				<OPTION label="Mois d'activité" data="MOIA"/>
				<OPTION label="Mois de sortie" data="MOIS"/>
				<OPTION label="Mois de ventes" data="MOIV"/>
			</FIELD>
			<FIELD name="GROUPBY_TAB" 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" default="-1" width="200" tree="true">
				<OPTION label="" data="-1"/>
				<OPTION label="PRESTATIONS_GROUPBY" data="" globalListProvider="PRESTATIONS_GROUPBY"/>
				<OPTION label="Mois d'activité" data="MOIA"/>
				<OPTION label="Mois de sortie" data="MOIS"/>
				<OPTION label="Mois de ventes" data="MOIV"/>
			</FIELD>
		</GROUP>
		<GROUP label="">
			<FIELD name="GROUPBY_3" label="" UI="combo" default="-1" width="200" tree="true">
				<OPTION label="" data="-1"/>
				<OPTION label="PRESTATIONS_GROUPBY" data="" globalListProvider="PRESTATIONS_GROUPBY"/>
				<OPTION label="Mois d'activité" data="MOIA"/>
				<OPTION label="Mois de sortie" data="MOIS"/>
				<OPTION label="Mois de ventes" data="MOIV"/>
			</FIELD>
		</GROUP>
		<GROUP label="Source en-cours">
			<FIELD name="SOURCE_ENCOURS" label="" UI="combo" width="200" default="C" >
				<OPTION label="CTI Santé" data="C"/>
				<OPTION label="Prestataire facturation" data="P"/>
			</FIELD>
		</GROUP>
		
		
	</SELECTIONS>
	<SELECTIONS componentName="FILTRES_PRESTATIONS_SOUSSELECTIONS"/>
	<SELECTIONS componentName="FILTRES_PRESTATIONS_SELECTIONS"/>
	<SELECTIONS componentName="FILTRES_SEJOURS_SELECTIONS"/>
	<SELECTIONS componentName="FILTRES_PASSAGES_SELECTIONS" />
	<QUERIES>
		<QUERY label="">
			<SQL>
				<select><![CDATA[		
					DROP TABLE IF EXISTS ACTI000105_fac;
					CREATE TEMP TABLE ACTI000105_fac AS 
					SELECT 
						p_factures.no_sejour AS w_no_sejour,
						p_factures.no_facture_reference AS w_no_facture,
						p_factures_encours.date_encours AS w_date_encours,
						CASE WHEN p_factures_encours.no_facture LIKE '%EV%' THEN '1' ELSE '0' END AS w_from_vente,
						base.cti_array_accum(p_factures_encours.no_facture) AS w_no_facture_encours_array
					FROM activite.p_factures
						JOIN activite.p_sejours ON p_factures.no_sejour = p_sejours.no_sejour
						JOIN activite.t_lieux ON p_sejours.lieu_sortie_id = t_lieux.oid
						JOIN activite.t_services_facturation ON service_facturation_id = t_services_facturation.oid
						JOIN activite.p_factures_encours ON 
							(
								avec_facturation_intermediaire <> '1' AND p_factures.no_sejour = p_factures_encours.no_sejour OR
								avec_facturation_intermediaire = '1' AND p_factures.no_facture = p_factures_encours.no_facture_reference
							) AND
							(
								p_factures.no_facture LIKE '%.BG' AND p_factures_encours.no_facture LIKE '%.BG%' OR
								p_factures.no_facture NOT LIKE '%.BG' AND p_factures_encours.no_facture NOT LIKE '%.BG%'
							)
					WHERE p_factures.code_vente = '1' AND 
						p_factures_encours.code_sorti = '1' AND
						p_factures_encours.montant_encours_c <> 0 AND
						p_factures_encours.date_encours BETWEEN '[PERIODE]' AND '[TOPERIODE]' AND
						p_factures_encours.code_origine = '[SOURCE_ENCOURS]'
					GROUP BY 1,2,3,4
					ORDER BY 1,2;

					ANALYZE ACTI000105_fac;
				]]></select>
			</SQL>
			<SQL optimizer="V_SEJOURS_X" optimizer2="V_FACTURES_ENCOURS_LIGNES_C_X">
				<select><![CDATA[		
					CTIPREPAR_TREE
					WORKTABLE{ACTI000105_E}
					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{[VIEW.ACTIVITE_SIGNIFICATIVE_DATA],, [ACTIVITE_SIGNIFICATIVE_MODE],, [ACTIVITE_SIGNIFICATIVE_NUMBER]}
					INDICATORS{
						SUM(montant_encours_sorti),,
						SUM(CASE WHEN w_no_facture IS NULL THEN montant_encours_sorti ELSE 0 END),,
						SUM(CASE WHEN w_no_facture IS NOT NULL THEN montant_encours_sorti ELSE 0 END),,
						SUM(CASE WHEN w_from_vente = '1' THEN montant_encours_sorti ELSE 0 END),,
						0,,
						0,,
					}
					FROM #V_FACTURES_ENCOURS_LIGNES_C_X#
						JOIN activite.p_factures_encours ON v_factures_lignes_c_4.no_facture = p_factures_encours.no_facture
						LEFT JOIN ACTI000105_fac ON 
							p_factures_encours.no_sejour = w_no_sejour AND
							p_factures_encours.no_facture = ANY(w_no_facture_encours_array) AND
							p_factures_encours.date_encours = w_date_encours 
					WHERE 'TYP=EVALENC'='TYP=EVALENC' AND
						montant_encours_sorti <> 0 AND
						date_comptable BETWEEN '[PERIODE]' AND '[TOPERIODE]' AND
						p_factures_encours.code_origine = '[SOURCE_ENCOURS]'
						[VIEW.SEJOURS_SELECT]
						[VIEW.PRESTATIONS_SELECT]
						[VIEW.PASSAGES_SELECT]
				
				
				]]></select>
			</SQL>
			
			<SQL optimizer="V_SEJOURS_X" optimizer2="V_FACTURES_LIGNES_C_X">
				<select><![CDATA[		
					CTIPREPAR_TREE
					WORKTABLE{ACTI000105_V}
					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{[VIEW.ACTIVITE_SIGNIFICATIVE_DATA],, [ACTIVITE_SIGNIFICATIVE_MODE],, [ACTIVITE_SIGNIFICATIVE_NUMBER]}
					INDICATORS{
						0,,
						0,,
						0,,
						SUM(montant_comptabilise+montant_comptabilise_budget_global_1),,
						0,,
						0,,
					}
					FROM #V_FACTURES_LIGNES_C_X#
						JOIN activite.p_factures ON v_factures_lignes_c_4.no_facture = p_factures.no_facture
						JOIN #V_SEJOURS_X# ON v_sejours_1.no_sejour = v_factures_lignes_c_4.no_sejour
						JOIN ACTI000105_fac  ON 
							p_factures.no_facture_reference = w_no_facture AND
							w_from_vente = '0'
					WHERE (montant_comptabilise <> 0 OR montant_comptabilise_budget_global_1 <> 0) 
						[VIEW.SEJOURS_SELECT]
						[VIEW.PRESTATIONS_SELECT]
						[VIEW.PASSAGES_SELECT]
				
				
				]]></select>
			</SQL>
			<SQL>
				<select><![CDATA[
					SELECT oidt, labelt, textet, 
						oid1, code1, 
						oid2, code2, 
						oid3, code3, 
						oid, code, texte, level, 
						SUM(indicateurs[1]), 
						SUM(indicateurs[2]), 
						SUM(indicateurs[3]), 
						SUM(indicateurs[4]), 
						SUM(indicateurs[4] - indicateurs[3]),
						base.cti_division(SUM(indicateurs[4] - indicateurs[3]),SUM(indicateurs[4])) * 100
					FROM (
						SELECT 
							oidt, labelt, textet, 
							oid1, code1, 
							oid2, code2, 
							oid3, code3, 
							oid, code, texte, level, 
							indicateurs
							FROM ACTI000105_E
						UNION ALL
						SELECT 
							oidt, labelt, textet, 
							oid1, code1, 
							oid2, code2, 
							oid3, code3, 
							oid, code, texte, level, 
							indicateurs
							FROM ACTI000105_V
						) subview
					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="E_MTS"/>
					<FIELD name="E_MTSE"/>
					<FIELD name="E_MTSV"/>
					<FIELD name="V_MT"/>
					<FIELD name="E_MEC"/>
					<FIELD name="E_PEC"/>
					
				</FIELDS>
			</SQL>
					
		</QUERY>
		<QUERY type="propertiesLink" name="VIEWPROPERTIES" forRows="false">
		</QUERY>
	</QUERIES>
	<PRESENTATION>
		<VIEWLINKS>
			<VIEWLINK label="Liste des séjours" shortLabel="Liste séjours" view="ACTI000106.XML" componentName="PRESTATIONS_BASE_VIEWLINK" component3Name="STANDARD_BASE_VIEWLINK">
			</VIEWLINK>
		</VIEWLINKS>
		<ONGLET excelLabel="Ventes et Encours" label="Ventes et Encours" multiTab="true">
			
			<DATAGRID title="" total="true" showOthers="true" headerHeight="72" variableRowHeight="true" sortable="= SELECT.GROUPBY_2 == '-1' || SELECT.GROUPBY_TAB == 'TAB'" 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" totalComplement="TOTAL">
					<INSERT name="COLUMN_COD_MULTITAB_STYLES"/>
				</COLUMN>
				<COLUMN dataField="TXT" type="Char" minWidth="150" maxWidth="300" headerText="SELECT.GROUPBY_LABEL" headerTextCalc="true" textAlign="left" totalFunction="text" otherFunction="text" otherComplement="*ROW">
				</COLUMN>
				
				<COLUMN dataField="E_MTS" width="90" type="Number" outputFormat="#E" visible="true" headerText="En-cours@LF@Sortis@LF@Montant@LF@(A)" textAlign="right" totalFunction="sum" otherFunction="">
				</COLUMN>
				<COLUMN dataField="E_MTSE" width="90" type="Number" outputFormat="#E" visible="true" headerText="En-cours@LF@Dont@LF@Non facturés@LF@(B)" textAlign="right" totalFunction="sum" otherFunction="">
				</COLUMN>
				<COLUMN dataField="E_MTSV" width="90" type="Number" outputFormat="#E" visible="true" headerText="En-cours@LF@Dont@LF@Facturés@LF@(C)" textAlign="right" totalFunction="sum" otherFunction="">
				</COLUMN>
				<COLUMN dataField="V_MT" width="90" type="Number" outputFormat="#E" visible="true" headerText="Ventes@LF@Montant@LF@Facturés@LF@(D)" textAlign="right" totalFunction="sum" otherFunction="">
				</COLUMN>
				
				<COLUMN dataField="E_MEC" width="90" type="Number" outputFormat="#E" visible="true" headerText="Ecart@LF@@LF@@LF@(D-C)" textAlign="right" totalFunction="sum" otherFunction="">
				</COLUMN>
				<COLUMN dataField="E_PEC" width="90" type="Number" outputFormat="#,0%" visible="true" headerText="% Ecart@LF@@LF@@LF@(D-C)" textAlign="right" totalFunction="sum" otherFunction="">
				</COLUMN>
				
				
			</DATAGRID>
		</ONGLET>
	</PRESENTATION>
</VUE>
