<?xml version="1.0" encoding="ISO-8859-1"?>
<VUE name="ECO000084" 
	label="ECO. Justificatif Consommations nomminatives" 
	title="= 'Achats et consommations UCD ' + 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_MOUVEMENTS"/>
	<VIEWPROPERTIES componentName="PROPERTIES_GROUPBY"/>
	<VIEWPROPERTIES componentName="PROPERTIES_DATA"/>
	
	<SELECTIONS label="Paramètres de l'analyse" displayText="">
		<GROUP label="Période">
			<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">
			<GROUP label="Regroupement">
			<FIELD name="GROUPBY" label="" UI="combo" width="200" default="-1" tree="true">
				<OPTION label="Pas de premier 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="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="Unité fonctionnelle" data="UFO" treeLevel="1"  globalListProvider="UNITE_FONCTIONNELLE_GROUPBY"/>
				<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' " update="= if(SELECT.GROUPBY != '-1') {return 'no_update'} else {return 'AUTO'}">
				<OPTION label="Automatique" data="AUTO"/>
				<OPTION label="Arbre" data="TREE"/>
				<OPTION label="Onglet" data="TAB"/>
			</FIELD>
		</GROUP>
		<GROUP label="Niveau de détail">
			<FIELD name="GROUPBY_2" label="" width="200" UI="combo" default="UCD" tree="false">
				<!-- <OPTION label="Article" data="ART" treeLevel="1"  globalListProvider="ARTICLE_GROUPBY"/> -->
				<OPTION label="UCD" data="UCD" treeLevel="1"/>
			</FIELD>
		</GROUP>
			<FIELD name="GROUPBY_3" label="" width="200" UI="combo" default="-1" tree="true" visible="false">
				<OPTION label="-1" data="-1" />
			</FIELD>
		</GROUP>
	</SELECTIONS>
	<SELECTIONS componentName="FILTRES_ARTICLE_SELECTIONS"/>
	<SELECTIONS componentName="FILTRES_FOURNISSEUR_SELECTIONS"/>
	<SELECTIONS componentName="FILTRES_MOUVEMENT_SELECTIONS"/>
	<SELECTIONS componentName="FILTRES_PROVIDER_SELECTIONS"/>
	<SELECTIONS label="Filtre Indicateur" collapsible="true" displayText="= var display:String = '';

					if (SELECT.DATA01  != '-1') {
						display = display + '  #B#Indicateur#/B# = ' + SELECT.DATA01_LABEL;
					}
					return display;">
		
			<GROUP label="">
			<FIELD name="DATA01" label="Indicateur" UI="combo" width="210" default="-1" tree="true">
				<OPTION label="" data="-1"/>
				<OPTION label="" data="" globalListProvider="DATA_AP_IND" condition="dataItem.data5 &gt; 10 and dataItem.data5 &lt; 20"/>
			</FIELD>
		</GROUP>
	</SELECTIONS>
	<QUERIES>
		<QUERY>
			<SQL optimizer="V_LIGNES_COMMANDES_X" optimizer2="V_ALL_X">
				<select><![CDATA[	
					CTIPREPAR_TREE
						WORKTABLE{ECO000084_CMD}
						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]}
					INDICATORS{
						(MAX(ARRAY[CASE WHEN quantite_livraison_approvisionnement = 0 THEN  '1900-01-01' ELSE date_reception::text END,base.cti_division(CASE WHEN montant_liquidation_ttc != 0 THEN montant_liquidation_ttc ELSE montant_commande_ttc END,quantite_livraison_approvisionnement)::text]))[2]::numeric,, 
					}
					FROM #V_LIGNES_COMMANDES_X##V_ALL_X#
					WHERE date_reception < '[TOPERIODE]' AND ucd_id != 0
						[VIEW.ARTICLE_SELECT]
						[VIEW.FOURNISSEUR_SELECT]
						[VIEW.PROVIDER_SELECT]
				
				]]></select>				
			</SQL>
			<SQL optimizer="V_STOCK_MENSUEL_X" optimizer2="V_ALL_X">
				<select><![CDATA[	
					CTIPREPAR_TREE
						WORKTABLE{ECO000084_STO}
						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]}
					INDICATORS{
						(MAX(ARRAY[CASE WHEN pump = 0 THEN  '1900-01-01' ELSE date_fin::text END,pump::text]))[2]::numeric,, 
					}
					FROM #V_STOCK_MENSUEL_X##V_ALL_X#
					WHERE date_fin < '[TOPERIODE]' AND ucd_id != 0
						[VIEW.ARTICLE_SELECT]
						[VIEW.FOURNISSEUR_SELECT]
						[VIEW.PROVIDER_SELECT]
				
				]]></select>				
			</SQL>
			<SQL optimizer="V_MOUVEMENTS_ARTICLES_X" optimizer2="V_ALL_X">
				<select><![CDATA[		

					CTISELECT_TREE
						WORKTABLE{ECO000084}
						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]}
						INDICATORS{
							(MAX(ARRAY[CASE WHEN prix_unitaire_calcule != 0 THEN date::text ELSE '1900-01-01'::text END ,prix_unitaire_calcule::text]))[2]::numeric,, 
							(MAX(ARRAY[CASE WHEN prix_unitaire > 0 AND  type_mouvement_id IN (select to_id from eco.t_classes JOIN eco.t_classes_sections on classe_id = t_classes.oid JOIN eco.t_classes_sections_elements ON section_id = t_classes_sections.oid WHERE t_classes.code = 'CTI_TYPMVT' AND t_classes_sections.code = '00') THEN date::text ELSE '1900-01-01'::text END,prix_unitaire::text]))[2]::numeric,, 
							SUM(CASE WHEN gere_en_stock != '0' AND  date BETWEEN '[PERIODE]' AND '[TOPERIODE]' AND  type_mouvement_id IN ((select to_id from eco.t_classes JOIN eco.t_classes_sections on classe_id = t_classes.oid JOIN eco.t_classes_sections_elements ON section_id = t_classes_sections.oid WHERE t_classes.code = 'CTI_TYPMVT' AND t_classes_sections.code = '00')) THEN entree_quantite ELSE 0 END),, 
							SUM(quantite_ligne_facture),,
							SUM(CASE WHEN gere_en_stock != '0' AND date BETWEEN '[PERIODE]' AND '[TOPERIODE]' AND type_mouvement_id IN ((select to_id from eco.t_classes JOIN eco.t_classes_sections on classe_id = t_classes.oid JOIN eco.t_classes_sections_elements ON section_id = t_classes_sections.oid WHERE t_classes.code = 'CTI_TYPMVT' AND t_classes_sections.code = '01')) AND unite_fonctionnelle_id NOT IN (select to_id from eco.t_listes_contenu JOIN eco.t_listes on liste_id = t_listes.oid WHERE code = 'CTI_UFPER') THEN sortie_quantite ELSE 0 END),,	
							0,,
						}
					FROM #V_MOUVEMENTS_ARTICLES_X##V_ALL_X#
					WHERE (date BETWEEN '[PERIODE]' AND '[TOPERIODE]') AND ucd_id != 0
						AND ( type_mouvement_id IN (select to_id from eco.t_classes JOIN eco.t_classes_sections on classe_id = t_classes.oid JOIN eco.t_classes_sections_elements ON section_id = t_classes_sections.oid WHERE t_classes.code = 'CTI_TYPMVT' AND t_classes_sections.code = '00')
						 OR type_mouvement_id IN (select to_id from eco.t_classes JOIN eco.t_classes_sections on classe_id = t_classes.oid JOIN eco.t_classes_sections_elements ON section_id = t_classes_sections.oid WHERE t_classes.code = 'CTI_TYPMVT' AND t_classes_sections.code = '01'))
						[VIEW.ARTICLE_SELECT]
						[VIEW.FOURNISSEUR_SELECT]
						[VIEW.MOUVEMENT_SELECT]
						[VIEW.PROVIDER_SELECT]
					AFTER{
						UPDATE ECO000084
						SET indicateurs[2] = ECO000084_CMD.indicateurs[1]
						FROM ECO000084_CMD
						WHERE ECO000084_CMD.OIDT = ECO000084.OIDT AND
                            ECO000084_CMD.OID1 = ECO000084.OID1 AND
                            ECO000084_CMD.OID2 = ECO000084.OID2 AND
                            ECO000084_CMD.OID3 = ECO000084.OID3
							.,
						UPDATE ECO000084
						SET indicateurs[1] = ECO000084_STO.indicateurs[1]
						FROM ECO000084_STO
						WHERE ECO000084_STO.OIDT = ECO000084.OIDT AND
                            ECO000084_STO.OID1 = ECO000084.OID1 AND
                            ECO000084_STO.OID2 = ECO000084.OID2 AND
                            ECO000084_STO.OID3 = ECO000084.OID3
					}
				]]></select>
				<FIELDS>
					<INSERT name="CTISELECT_TREE_FIELDS"/>
					<FIELD name="DATA01" />
					<FIELD name="DATA02" />
					<FIELD name="DATA03" />
					<FIELD name="DATA04" />
					<FIELD name="DATA05" />
					<FIELD name="DATA06" />
				</FIELDS>
			</SQL>
		
		</QUERY>
			
			
	</QUERIES>
	
	<PRESENTATION>
		<VIEWLINKS>
			<VIEWLINK label="Liste des mouvements" shortLabel="Liste mouvements" view="ECO000010.XML" componentName="ECO_VIEWLINK" >
				<ARGS name="SPEC" >
					<value><![CDATA[
						LINKVARIABLES['GROUPBY'] = '-1'
						LINKVARIABLES['GROUPBY_2'] = 'MVT'
						LINKVARIABLES['DATA01'] = '-1'
						switch (COLUMN.NAME.substring(0,3)) {
							case '' :
							case 'OID' :
							case 'COD' :
							case 'TXT' :
							case 'UNI' :
								break;
							default :
							var result:int = int(COLUMN.NAME.substr(COLUMN.NAME.length-4,2));
							switch (SELECT[COLUMN.NAME.substring(0,COLUMN.NAME.length-2)]) {
								case '4.2' :
									result = result - 1;
									break;
								case '4.3' :
									result = result - 2;
									break;
								case '4.4' :
									result = result - 2;
									break;
								default :
									break;
							};
							if (result < 10) LINKVARIABLES['DATA01'] = SELECT[COLUMN.NAME.substring(0,COLUMN.NAME.length-4)+'0'+result.toString()];
							else LINKVARIABLES['DATA01'] = SELECT[COLUMN.NAME.substring(0,COLUMN.NAME.length-4)+result.toString()];
							break;
							};
						return 'OK';
			
					]]></value>
				</ARGS>
			</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="40" 
						selectRowInRows="= ROW.OID == '-9999997'" 
						otherRowInRows="= ROW.OID == '-9999998'" 
						totalRowInRows="= ROW.OID == '-9999999'"
						variableRowHeight="true" 
						sortable="true"> 
				
				<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="DATA01" type="Number" width="90" fixed="false" outputFormat=",000E" selectable="true" headerText="PUMP" headerTextCalc="false" description="Prix moyen des ventes" visible="true"/>
				<COLUMN dataField="DATA02" type="Number" width="90" outputFormat=",000E" selectable="true" headerText="Prix d'achat" headerTextCalc="false" description="Prix moyen des achats" visible="trrue" />
				<COLUMN dataField="DATA03" type="Number" width="90" outputFormat="" selectable="true" headerText="Qté achetée" headerTextCalc="false" description="Quantité livrée sur période" visible="true" />
				<COLUMN dataField="DATA04" type="Number" width="90" outputFormat="" selectable="true" headerText="Qté rétrocédée" headerTextCalc="false" description="Quantité rétrocédée sur période" visible="true" />
				<COLUMN dataField="DATA05" type="Number" width="90" outputFormat="" selectable="true" headerText="Qté délivrée" headerTextCalc="false" description="Qauntité consommée sur période" visible="true" />
				<COLUMN dataField="DATA06" type="Number" width="90" outputFormat="" selectable="true" headerText="Qté délivrée HEPAD" headerTextCalc="false" description="Quantité consommée en HEAPD sur période" visible="true" />
			</DATAGRID>
		</ONGLET>
	</PRESENTATION>
</VUE>

			
