<?xml version="1.0" encoding="ISO-8859-1"?>
<VUE name="ECO000012" 
	label="ECO. Analyse stocks" 
	title="= 'Analyse des stocks par ' +  SELECT.GROUPBY_LABEL + ' de ' + SELECT.PERIODE_LABEL + ' à ' + SELECT.TOPERIODE_LABEL " 
	database="iCTI" 
	swf="*CTI_view1" 
	globals="ECO_globals.XML" 
	componentsFile="ECO_components.XML"
	dboptimizer="ECO_dboptimizer.XML"
	softCode="iCTI_eco">
	
	<VIEWPROPERTIES componentName="PROPERTIES_STOCK"/>
	<VIEWPROPERTIES componentName="PROPERTIES_GROUPBY"/>
	<VIEWPROPERTIES>
		<PROPERTY dataLink="VIEWPROPERTIES" nameField="name" valueField="value"/>
	</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="Regroupement">
			<FIELD name="GROUPBY" label="" UI="combo" width="200" default="CPA" tree="true">
                <OPTION label="Site" data="SIT" treeLevel="1"  globalListProvider="SITE_GROUPBY"/>
				<OPTION label="Article" data="ART" treeLevel="1"  globalListProvider="ARTICLE_GROUPBY"/>
				<OPTION label="Compte" data="CPA" treeLevel="1"  globalListProvider="COMPTE_ARTICLE_GROUPBY"/>
				<OPTION label="Lieu" data="LIE" treeLevel="1"  globalListProvider="LIEU_GROUPBY"/>
				<OPTION label="Année-Mois stock" 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="Site" data="SIT" treeLevel="1"  globalListProvider="SITE_GROUPBY"/>
				<OPTION label="Article" data="ART" treeLevel="1"  globalListProvider="ARTICLE_GROUPBY"/>
				<OPTION label="Compte" data="CPA" treeLevel="1"  globalListProvider="COMPTE_ARTICLE_GROUPBY"/>
				<OPTION label="Lieu" data="LIE" treeLevel="1"  globalListProvider="LIEU_GROUPBY"/>
				<OPTION label="Année-Mois stock" 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="Site" data="SIT" treeLevel="1"  globalListProvider="SITE_GROUPBY"/>
				<OPTION label="Article" data="ART" treeLevel="1"  globalListProvider="ARTICLE_GROUPBY"/>
				<OPTION label="Compte" data="CPA" treeLevel="1"  globalListProvider="COMPTE_ARTICLE_GROUPBY"/>
				<OPTION label="Lieu" data="LIE" treeLevel="1"  globalListProvider="LIEU_GROUPBY"/>
				<OPTION label="Année-Mois stock" globalListProvider="DATE_GROUPBY" treeLevel="1"  />				
				<OPTION label="Source de données" data="PVD" treeLevel="1"  globalListProvider="PROVIDER_GROUPBY"/>
			</FIELD>
		</GROUP>
        <GROUP label="Donnée">
			<FIELD name="DATA" label="" width="200" UI="combo" default="-1" tree="true">
				<OPTION label="Quantités et montants" data="-1"/>
				<OPTION label="Quantités uniquement" data="Q" />
				<OPTION label="Montants uniquement" data="M" />
			</FIELD>
		</GROUP>
	</SELECTIONS>
	
	<SELECTIONS componentName="FILTRES_STOCK_SIGNIFICATIF"/>
    <SELECTIONS componentName="FILTRES_STOCK_SELECTIONS"/>
	<SELECTIONS componentName="FILTRES_ARTICLE_SELECTIONS"/>
	<SELECTIONS componentName="FILTRES_PROVIDER_SELECTIONS"/>
	
	<QUERIES>
		<QUERY label=""> 
			<SQL optimizer="V_STOCK_MENSUEL_X" optimizer2="V_ALL_X">
				<select><![CDATA[		

					CTISELECT_TREE
						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.ECO_SIGNIFICATIVE_DATA],, [ECO_SIGNIFICATIVE_MODE],, [ECO_SIGNIFICATIVE_NUMBER]}
						OPTIONS{NOTZERO=1}
						INDICATORS{
							COUNT(DISTINCT unite_stockage_article_id),
							SUM(CASE WHEN date_debut = '[PERIODE]' THEN stock_quantite_debut ELSE 0 END),
							SUM(entree_quantite),
							SUM(sortie_quantite),
							SUM(entree_quantite) - SUM(sortie_quantite),
							SUM(CASE WHEN date_fin = '[TOPERIODE]' THEN stock_quantite_fin ELSE 0 END),
							
							SUM(CASE WHEN date_debut = '[PERIODE]' THEN stock_valeur_debut ELSE 0 END),
							SUM(entree_montant),
							SUM(sortie_montant),
							SUM(entree_montant) - SUM(sortie_montant),
							SUM(CASE WHEN date_fin = '[TOPERIODE]' THEN stock_valeur_fin ELSE 0 END),
							
							CASE WHEN COUNT(DISTINCT article_id) = 1
								THEN SUM(CASE WHEN date_debut = '[PERIODE]' THEN pump ELSE 0 END)
								ELSE 0 END,
							CASE WHEN COUNT(DISTINCT article_id) = 1
								THEN SUM(CASE WHEN date_fin = '[TOPERIODE]' THEN pump ELSE 0 END)
								ELSE 0 END,
								
							SUM(CASE WHEN date_debut = '[PERIODE]' THEN stock_valeur_debut_ttc ELSE 0 END),
							SUM(entree_montant_ttc),
							SUM(sortie_montant_ttc),
							SUM(entree_montant_ttc) - SUM(sortie_montant_ttc),
							SUM(CASE WHEN date_fin = '[TOPERIODE]' THEN stock_valeur_fin_ttc ELSE 0 END),
							
							CASE WHEN COUNT(DISTINCT article_id) = 1
								THEN SUM(CASE WHEN date_debut = '[PERIODE]' THEN pump_ttc ELSE 0 END)
								ELSE 0 END,
							CASE WHEN COUNT(DISTINCT article_id) = 1
								THEN SUM(CASE WHEN date_fin = '[TOPERIODE]' THEN pump_ttc ELSE 0 END)
								ELSE 0 END,
						}	
						INDICATORS_TEXT{
							MAX(CASE WHEN unite_stockage_article_id <> 0 AND unite_stockage_article_code <> 'UN' THEN unite_stockage_article_texte ELSE '' END)::text,,
						}	
					FROM #V_STOCK_MENSUEL_X##V_ALL_X#
					WHERE date_debut BETWEEN '[PERIODE]' AND '[TOPERIODE]'
						[VIEW.ARTICLE_SELECT]
                        [VIEW.STOCK_SELECT]
						[VIEW.PROVIDER_SELECT]
					
					
					AFTER{
						UPDATE w_table SET 
							indicateurs[2] = CASE WHEN indicateurs[1] = 1 THEN indicateurs[2] ELSE 0 END,
							indicateurs[3] = CASE WHEN indicateurs[1] = 1 THEN indicateurs[3] ELSE 0 END,
							indicateurs[4] = CASE WHEN indicateurs[1] = 1 THEN indicateurs[4] ELSE 0 END,
							indicateurs[5] = CASE WHEN indicateurs[1] = 1 THEN indicateurs[5] ELSE 0 END,
							indicateurs[6] = CASE WHEN indicateurs[1] = 1 THEN indicateurs[6] ELSE 0 END,
							indicateurs_text[1] = CASE WHEN indicateurs[1] = 1 THEN indicateurs_text[1] ELSE '' END
					}

				]]></select>
				<FIELDS>
					<INSERT name="CTISELECT_TREE_FIELDS"/>
					<FIELD name="QUST" />
					<FIELD name="QSTD" />
					<FIELD name="QENT" />
					<FIELD name="QSOR" />
					<FIELD name="QECA" />
					<FIELD name="QSTF" />
					
					<FIELD name="MSTD" />
					<FIELD name="MENT" />
					<FIELD name="MSOR" />
					<FIELD name="MECA" />
					<FIELD name="MSTF" />
					<FIELD name="PUMD" />
					<FIELD name="PUMF" />
					
					<FIELD name="MSTDTTC" />
					<FIELD name="MENTTTC" />
					<FIELD name="MSORTTC" />
					<FIELD name="MECATTC" />
					<FIELD name="MSTFTTC" />
					<FIELD name="PUMDTTC" />
					<FIELD name="PUMFTTC" />

					<FIELD name="FILLER" />
					
					<FIELD name="UNIT" />
				</FIELDS>
			</SQL>
		</QUERY>
		<QUERY type="propertiesLink" name="VIEWPROPERTIES" forSelections="false">
			<SQL>
				<select><![CDATA[
						SELECT 'X_PERIODE_D', greatest(to_date(to_char('[PERIODE]'::date - INTERVAL  '1 year', 'YYYY-MM-DD'), 'YYYY-MM-DD'), (SELECT min(to_date(mois,'YYYYMM')) FROM eco.p_chiffrier_production))::text
					UNION ALL
						SELECT 'X_TOPERIODE_D', greatest(to_date(to_char('[TOPERIODE]'::date - INTERVAL  '1 year', 'YYYY-MM-DD'), 'YYYY-MM-DD'), (SELECT min(to_date(mois,'YYYYMM')) FROM eco.p_chiffrier_production))::text
					UNION ALL
						SELECT 'X_PERIODE', greatest(to_date(to_char('[PERIODE]'::date - INTERVAL  '3 year', 'YYYY-MM-DD'), 'YYYY-MM-DD'), (SELECT min(to_date(mois,'YYYYMM')) FROM eco.p_chiffrier_production))::text
				]]></select>
				<FIELDS>
					<FIELD name="name" />
					<FIELD name="value" />
				</FIELDS>
			</SQL>
		</QUERY>
	</QUERIES>
	
	<PRESENTATION>
		<VIEWLINKS>
			<VIEWLINK label="Comparatif" shortLabel="Comparatif" view="ECO000019.XML" enabled="true" rowContext="false" componentName="ECO_VIEWLINK" buttonType="COMPARATIF">
				<ARG name="PERIODE_D" value="return VIEW.X_PERIODE_D;" />
				<ARG name="TOPERIODE_D" value="return VIEW.X_TOPERIODE_D;" />
			</VIEWLINK>
			<VIEWLINK label="Evolution" shortLabel="Evolution" view="ECO000013.XML" enabled="true" rowContext="false" componentName="ECO_VIEWLINK"  buttonType="EVOLUTION">
				<ARG name="PERIODICITE" value="'MONTH'" />
			</VIEWLINK>
			<VIEWLINK label="Détail article" shortLabel="Détail article" view="ECO000069.XML" componentName="ECO_VIEWLINK" component2Name="DATE_EVOL_VIEWLINK" >
				<ARGS name="SPEC" >
					<value><![CDATA[
						LINKVARIABLES['GROUPBY'] = 'AMCMD'
						LINKVARIABLES['GROUPBY_2'] = 'AMMVT'
						LINKVARIABLES['GROUPBY_3'] = 'AMSTO'
						LINKVARIABLES['TAB'] = 'AUTO'
						return 'OK';
			
					]]></value>
				</ARGS>
			</VIEWLINK>
		</VIEWLINKS>		
		
		<ONGLET label="Onglet" multiTab="true" >
		
				
			<DATAGRID 	title="" 
						total="true" 
						headerHeight="60" 
						selectRowInRows="= ROW.OID == '-9999997'" 
						otherRowInRows="= ROW.OID == '-9999998'" 
						totalRowInRows="= ROW.OID == '-9999999'"
						variableRowHeight="true" 
						sortable="= 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="100"
					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="UNIT" 
					type="Char" 
					width="50"
					fixed="false"
					headerText="Unité" 
					textAlign="left" 
					totalComplement="*ROW"
                    visibleCondition="SELECT.DATA == '-1' || SELECT.DATA == 'Q'"/>	
				<COLUMN dataField="QSTD" 
					type="Number" 
					width="80"
					outputFormat="#"
					visible="true"
					headerText="Quantité@LF@Stock début" 
					textAlign="right"
					totalComplement="*ROW"
                    visibleCondition="SELECT.DATA == '-1' || SELECT.DATA == 'Q'"/>
				<COLUMN dataField="QENT" 
					type="Number" 
					width="80"
					outputFormat="#"
					visible="true"
					headerText="Quantité@LF@Entrées" 
					textAlign="right"
					totalComplement="*ROW"
                    visibleCondition="SELECT.DATA == '-1' || SELECT.DATA == 'Q'"/>
				<COLUMN dataField="QSOR" 
					type="Number" 
					width="80"
					outputFormat="#"
					visible="true"
					headerText="Quantité@LF@Sorties" 
					textAlign="right"
					totalComplement="*ROW"
                    visibleCondition="SELECT.DATA == '-1' || SELECT.DATA == 'Q'"/>
				<COLUMN dataField="QECA" 
					type="Number" 
					width="80"
					outputFormat="#"
					visible="true"
					headerText="Quantité@LF@Ecart" 
					textAlign="right"
					totalComplement="*ROW"
                    visibleCondition="SELECT.DATA == '-1' || SELECT.DATA == 'Q'"/>
				<COLUMN dataField="QSTF" 
					type="Number" 
					width="80"
					outputFormat="#"
					visible="true"
					headerText="Quantité@LF@Stock fin" 
					textAlign="right"
					totalComplement="*ROW"
                    visibleCondition="SELECT.DATA == '-1' || SELECT.DATA == 'Q'"/>
					
					
				<COLUMN dataField="MSTD" 
					type="Number" 
					width="90"
					fixed="false"
					outputFormat="#,00E"
					visible="true"
					headerText="Valeur HT@LF@Stock début" 
					textAlign="right"
					totalComplement="*ROW"
                    visibleCondition="SELECT.DATA == '-1' || SELECT.DATA == 'M'"/>
				<COLUMNx dataField="PUMD" 
					type="Number" 
					width="90"
					outputFormat="#,0000E"
					visible="true"
					headerText="PUMP HT@LF@Stock début" 
					textAlign="right"
					totalComplement="*ROW"
                    visibleCondition="SELECT.DATA == '-1' || SELECT.DATA == 'M'" />
					
				<COLUMN dataField="MENT" 
					type="Number" 
					width="90"
					outputFormat="#,00E"
					visible="true"
					headerText="Montant HT@LF@Entrées" 
					textAlign="right"
					totalComplement="*ROW"
                    visibleCondition="SELECT.DATA == '-1' || SELECT.DATA == 'M'" />
				<COLUMN dataField="MSOR" 
					type="Number" 
					width="90"
					outputFormat="#,00E"
					visible="true"
					headerText="Montant HT@LF@Sorties" 
					textAlign="right"
					totalComplement="*ROW"
                    visibleCondition="SELECT.DATA == '-1' || SELECT.DATA == 'M'" />
				<COLUMN dataField="MECA" 
					type="Number" 
					width="90"
					outputFormat="#,00E"
					visible="true"
					headerText="Montant HT@LF@Ecart" 
					textAlign="right"
					totalComplement="*ROW"
                    visibleCondition="SELECT.DATA == '-1' || SELECT.DATA == 'M'" />
				<COLUMN dataField="MSTF" 
					type="Number" 
					width="90"
					outputFormat="#,00E"
					visible="true"
					headerText="Valeur HT@LF@Stock fin" 
					textAlign="right"
					totalComplement="*ROW"
                    visibleCondition="SELECT.DATA == '-1' || SELECT.DATA == 'M'" />
				<COLUMN dataField="PUMF" 
					type="Number" 
					width="90"
					outputFormat="#,0000E"
					visible="true"
					headerText="PUMP HT@LF@Stock fin" 
					textAlign="right"
					totalComplement="*ROW"
                    visibleCondition="SELECT.DATA == '-1' || SELECT.DATA == 'M'" />
					
				<COLUMN dataField="MSTDTTC" 
					type="Number" 
					width="90"
					outputFormat="#,00E"
					visible="true"
					headerText="Valeur TTC@LF@Stock début" 
					textAlign="right"
					totalComplement="*ROW"
                    visibleCondition="SELECT.DATA == '-1' || SELECT.DATA == 'M'"/>
				<COLUMNx dataField="PUMDTTC" 
					type="Number" 
					width="90"
					outputFormat="#,0000E"
					visible="true"
					headerText="PUMP TTC@LF@Stock début" 
					textAlign="right"
					totalComplement="*ROW"
                    visibleCondition="SELECT.DATA == '-1' || SELECT.DATA == 'M'" />
					
				<COLUMN dataField="MENTTTC" 
					type="Number" 
					width="90"
					outputFormat="#,00E"
					visible="true"
					headerText="Montant TTC@LF@Entrées" 
					textAlign="right"
					totalComplement="*ROW"
                    visibleCondition="SELECT.DATA == '-1' || SELECT.DATA == 'M'" />
				<COLUMN dataField="MSORTTC" 
					type="Number" 
					width="90"
					outputFormat="#,00E"
					visible="true"
					headerText="Montant TTC@LF@Sorties" 
					textAlign="right"
					totalComplement="*ROW"
                    visibleCondition="SELECT.DATA == '-1' || SELECT.DATA == 'M'" />
				<COLUMN dataField="MECATTC" 
					type="Number" 
					width="90"
					outputFormat="#,00E"
					visible="true"
					headerText="Montant TTC@LF@Ecart" 
					textAlign="right"
					totalComplement="*ROW"
                    visibleCondition="SELECT.DATA == '-1' || SELECT.DATA == 'M'" />
				<COLUMN dataField="MSTFTTC" 
					type="Number" 
					width="90"
					outputFormat="#,00E"
					visible="true"
					headerText="Valeur TTC@LF@Stock fin" 
					textAlign="right"
					totalComplement="*ROW"
                    visibleCondition="SELECT.DATA == '-1' || SELECT.DATA == 'M'" />
				<COLUMN dataField="PUMFTTC" 
					type="Number" 
					width="90"
					outputFormat="#,0000E"
					visible="true"
					headerText="PUMP TTC@LF@Stock fin" 
					textAlign="right"
					totalComplement="*ROW"
                    visibleCondition="SELECT.DATA == '-1' || SELECT.DATA == 'M'" />
				
			</DATAGRID>
		</ONGLET>
	</PRESENTATION>
</VUE>

			
