<?xml version="1.0" encoding="ISO-8859-1"?>
<VUE name="ECO001067" 
	label="ECO. Comparatif stock calculé" 
	database="iCTI" 
	swf="*CTI_view1" 
	globals="ECO_globals.XML" 
	componentsFile="ECO_components.XML"
	dboptimizer="ECO_dboptimizer.XML"
	softCode="iCTI_eco"
	contexte="MVS"
	viewType="COMP">	

	<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;
		}
		
		var date_label = '( '+ ''+VIEW.COMPAREPERIODETXT+' : '+ VIEW.PERIODE_D_LABEL + ' à ' +  VIEW.TOPERIODE_D_LABEL + ' vs ' + ' N : '+ SELECT.PERIODE_LABEL + ' à ' + SELECT.TOPERIODE_LABEL + ')';

		
		return 'Comparaison stock calculé ' + group_by_label + ' ' + date_label;
		
	]]></title>
	
	<VIEWPROPERTIES>
		<PROPERTY dataLink="VIEWPROPERTIES" nameField="name" valueField="value" />
	</VIEWPROPERTIES>
	<VIEWPROPERTIES componentName="PROPERTIES_MOUVEMENTS"/>
	<VIEWPROPERTIES componentName="PROPERTIES_GROUPBY"/>
	<VIEWPROPERTIES>
		<PROPERTY name="VIEWTYPE" value="COMP"/>
		<PROPERTY dataLink="VIEWPROPERTIES" nameField="name" valueField="value"/>
		<PROPERTY dataLink="DATA_VIEWPROPERTIES" nameField="name" valueField="value" />
	</VIEWPROPERTIES>
	<VIEWPROPERTIES>
		<PROPERTY name="COMPAREPERIODETXT">
			<value><![CDATA[[EVAL 
					
                $TYPE_COMPARAISON_TXT = '[TYPE_COMPARAISON]';
                if($TYPE_COMPARAISON_TXT == '2'){
                    return 'N-1'; 
                } else {
                        return 'N-2';
                }
                
					
			EVAL]]]></value>
		</PROPERTY>
	</VIEWPROPERTIES>

	<SELECTIONS label="Paramètres de l'analyse" displayText="">
		<GROUP label="Période">
			<FIELD name="ALIAS_PERIODE" label="" UI="combo" width="180" 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="TYPE_COMPARAISON" label="" UI="combo" default="2" width="130">
				<OPTION label="Période N-1" data="2" />
				<OPTION label="Période N-2" data="1" />
				<OPTION label="Saisie période" data="S" />
			</FIELD>
			<FIELD name="PERIODE_D" label="" UI="combo" tree="true" width="200" default="2010-01-01" globalListProvider="PERIODE_DEBUT" visible="= SELECT.TYPE_COMPARAISON == 'S'" />
			<FIELD name="TOPERIODE_D" label="au" UI="combo" tree="true" width="200" default="2010-01-31" globalListProvider="PERIODE_FIN" visible="= SELECT.TYPE_COMPARAISON == 'S'" />
		</GROUP>
		<GROUP label="Regroupement">
			<FIELD name="GROUPBY" label="" UI="combo" width="200" default="CPA" tree="true">
				<OPTION label="Article" data="ART" treeLevel="1"  globalListProvider="ARTICLE_GROUPBY"/>
				<OPTION label="Compte" data="CPA" treeLevel="1"  globalListProvider="COMPTE_ARTICLE_GROUPBY"/>
				<OPTION label="Fournisseur" data="FOU" treeLevel="1"  globalListProvider="FOURNISSEUR_GROUPBY"/>
				<OPTION label="Gestionnaire" data="GES" treeLevel="1"  globalListProvider="GESTIONNAIRE_GROUPBY"/>
				<OPTION label="Lieu" data="LIE" treeLevel="1"  globalListProvider="LIEU_GROUPBY"/>
                <OPTION label="Pole" data="POL" treeLevel="1"  globalListProvider="POLE_GROUPBY"/>
				<OPTION label="Unité fonctionnelle" data="UFO" treeLevel="1"  globalListProvider="UNITE_FONCTIONNELLE_GROUPBY"/>
				<OPTION label="Type de mouvement" data="TYM" treeLevel="1"  globalListProvider="TYPE_MOUVEMENT_GROUPBY"/>
				<OPTION label="Année-Mois mouvement" globalListProvider="DATE_GROUPBY" treeLevel="1"  />				
				<OPTION label="Source de données" data="PVD" treeLevel="1"  globalListProvider="PROVIDER_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="200" UI="combo" default="-1" tree="true">
				<OPTION label="Pas de second niveau" data="-1"/>
				<OPTION label="Article" data="ART" treeLevel="1"  globalListProvider="ARTICLE_GROUPBY"/>
				<OPTION label="Compte" data="CPA" treeLevel="1"  globalListProvider="COMPTE_ARTICLE_GROUPBY"/>
				<OPTION label="Fournisseur" data="FOU" treeLevel="1"  globalListProvider="FOURNISSEUR_GROUPBY"/>
				<OPTION label="Gestionnaire" data="GES" treeLevel="1"  globalListProvider="GESTIONNAIRE_GROUPBY"/>
				<OPTION label="Lieu" data="LIE" treeLevel="1"  globalListProvider="LIEU_GROUPBY"/>
                <OPTION label="Pole" data="POL" treeLevel="1"  globalListProvider="POLE_GROUPBY"/>
				<OPTION label="Unité fonctionnelle" data="UFO" treeLevel="1"  globalListProvider="UNITE_FONCTIONNELLE_GROUPBY"/>
				<OPTION label="Type de mouvement" data="TYM" treeLevel="1"  globalListProvider="TYPE_MOUVEMENT_GROUPBY"/>
				<OPTION label="Année-Mois mouvement" globalListProvider="DATE_GROUPBY" treeLevel="1"  />				
				<OPTION label="Source de données" data="PVD" treeLevel="1"  globalListProvider="PROVIDER_GROUPBY"/>
			</FIELD>
		</GROUP>
		<GROUP label="">
			<FIELD name="GROUPBY_3" label="" width="200" UI="combo" default="-1" tree="true">
				<OPTION label="Pas de troisième niveau" data="-1"/>
				<OPTION label="Article" data="ART" treeLevel="1"  globalListProvider="ARTICLE_GROUPBY"/>
				<OPTION label="Compte" data="CPA" treeLevel="1"  globalListProvider="COMPTE_ARTICLE_GROUPBY"/>
				<OPTION label="Fournisseur" data="FOU" treeLevel="1"  globalListProvider="FOURNISSEUR_GROUPBY"/>
				<OPTION label="Gestionnaire" data="GES" treeLevel="1"  globalListProvider="GESTIONNAIRE_GROUPBY"/>
				<OPTION label="Lieu" data="LIE" treeLevel="1"  globalListProvider="LIEU_GROUPBY"/>
                <OPTION label="Pole" data="POL" treeLevel="1"  globalListProvider="POLE_GROUPBY"/>
				<OPTION label="Unité fonctionnelle" data="UFO" treeLevel="1"  globalListProvider="UNITE_FONCTIONNELLE_GROUPBY"/>
				<OPTION label="Type de mouvement" data="TYM" treeLevel="1"  globalListProvider="TYPE_MOUVEMENT_GROUPBY"/>
				<OPTION label="Année-Mois mouvement" globalListProvider="DATE_GROUPBY" treeLevel="1"  />				
				<OPTION label="Source de données" data="PVD" treeLevel="1"  globalListProvider="PROVIDER_GROUPBY"/>
			</FIELD>
		</GROUP>
	</SELECTIONS>
	
	<SELECTIONS componentName="FILTRES_DTA_SELECTIONS"/>
	
	<SELECTIONS componentName="FILTRES_MOUVEMENT_SIGNIFICATIF"/>
	<SELECTIONS componentName="FILTRES_ARTICLE_SELECTIONS"/>
	<SELECTIONS componentName="FILTRES_FOURNISSEUR_SELECTIONS"/>
	<SELECTIONS componentName="FILTRES_MOUVEMENT_SELECTIONS"/>
	<SELECTIONS componentName="FILTRES_PROVIDER_SELECTIONS"/>
	
	<QUERIES>
		<INCLUDE_COMPONENT componentName="QUERIES_COL" ></INCLUDE_COMPONENT>
		<INCLUDE_COMPONENT componentName="QUERIES_COMP" ></INCLUDE_COMPONENT>
		
		<QUERY type="propertiesLink" name="VIEWPROPERTIES" forSelections="false">
			<SQL>
				<select><![CDATA[	
					SELECT 'PERIODE_D' , CASE WHEN '[TYPE_COMPARAISON]' = '2' THEN date('[PERIODE]'::date + interval '1 day' - interval '1 year' - interval '1 day')  WHEN '[TYPE_COMPARAISON]' = '1' THEN date('[PERIODE]'::date + interval '1 day' - interval '2 year' - interval '1 day') ELSE '[PERIODE_D]' END::text
					UNION
					SELECT 'TOPERIODE_D' , CASE WHEN '[TYPE_COMPARAISON]' = '2' THEN date('[TOPERIODE]'::date + interval '1 day' - interval '1 year' - interval '1 day') WHEN '[TYPE_COMPARAISON]' = '1' THEN date('[TOPERIODE]'::date + interval '1 day' - interval '2 year' - interval '1 day') ELSE '[TOPERIODE_D]' END::text
					UNION
					SELECT 'PERIODE_D_LABEL', CASE WHEN  CASE WHEN '[TYPE_COMPARAISON]' = '2' THEN date('[PERIODE]'::date + interval '1 day' - interval '1 year' - interval '1 day') WHEN '[TYPE_COMPARAISON]' = '1' THEN date('[PERIODE]'::date + interval '1 day' - interval '2 year' - interval '1 day') ELSE '[PERIODE_D]' END = p_calendrier_mois.date_debut THEN p_calendrier_mois.texte ELSE p_calendrier.texte END
					FROM base.p_calendrier
						JOIN base.p_calendrier_mois ON p_calendrier.mois = p_calendrier_mois.mois
					WHERE date = CASE WHEN '[TYPE_COMPARAISON]' = '2' THEN date('[PERIODE]'::date + interval '1 day' - interval '1 year' - interval '1 day') WHEN '[TYPE_COMPARAISON]' = '1' THEN date('[PERIODE]'::date + interval '1 day' - interval '2 year' - interval '1 day') ELSE '[PERIODE_D]' END
					UNION
					SELECT 'TOPERIODE_D_LABEL', CASE WHEN  CASE WHEN '[TYPE_COMPARAISON]' = '2' THEN date('[TOPERIODE]'::date + interval '1 day' - interval '1 year' - interval '1 day') WHEN '[TYPE_COMPARAISON]' = '1' THEN date('[TOPERIODE]'::date + interval '1 day' - interval '2 year' - interval '1 day') ELSE '[TOPERIODE_D]' END = p_calendrier_mois.date_fin THEN p_calendrier_mois.texte ELSE p_calendrier.texte_court END
					FROM base.p_calendrier
						JOIN base.p_calendrier_mois ON p_calendrier.mois = p_calendrier_mois.mois
					WHERE date = CASE WHEN '[TYPE_COMPARAISON]' = '2' THEN date('[TOPERIODE]'::date + interval '1 day' - interval '1 year' - interval '1 day') WHEN '[TYPE_COMPARAISON]' = '1' THEN date('[TOPERIODE]'::date + interval '1 day' - interval '2 year' - interval '1 day') ELSE '[TOPERIODE_D]' END
					UNION
						SELECT 'X_PERIODE', greatest(('[PERIODE]'::date - '3 years'::interval)::date, (SELECT (min(mois)::text||'01')::date FROM eco.p_chiffrier_production))::text
				]]></select>
				<FIELDS>
					<FIELD name="name" />
					<FIELD name="value" />
				</FIELDS>
			</SQL>
		</QUERY>
	</QUERIES>
	<INCLUDE_COMPONENT componentName="PRESENTATION_COMP" ></INCLUDE_COMPONENT>
</VUE>
