<?xml version="1.0" encoding="ISO-8859-1"?>
<VUE name="ECO000011" 
	label="ECO. Justificatif commandes" 
	title="= 'Justificatif des commandes' + ' (' + SELECT.DATE_BASE_LABEL + ' : ' +  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_COMMANDES"/>
	<VIEWPROPERTIES componentName="PROPERTIES_GROUPBY"/>
	<VIEWPROPERTIES componentName="PROPERTIES_DATA"/>
	
	<SELECTIONS label="Paramètres de l'analyse" displayText="">
		<GROUP label="Période">
			<FIELD name="DATE_BASE" label="" width="130" UI="combo" default="CMD" default2="date_commande">
				<OPTION label="Date commande" data="CMD" data2="date_commande"/>
				<OPTION label="Date engagement" data="ENG" data2="date_engagement"/>
			</FIELD>
			<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="FOU" 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="Commande" data="CMD" treeLevel="1"  />
				<OPTION label="Année-Mois Commande" 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' " 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="CMD" tree="true">
				<OPTION label="Commande" data="CMD" />
				<OPTION label="Ligne de commande" data="CML" />
			</FIELD>
		</GROUP>
	</SELECTIONS>
	
	<SELECTIONS componentName="FILTRES_COMMANDE_SELECTIONS"/>
	<SELECTIONS componentName="FILTRES_FOURNISSEUR_SELECTIONS"/>
	<SELECTIONS componentName="FILTRES_ARTICLE_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;" showIfNotDefault="true">
		
			<GROUP label="">
			<FIELD name="DATA01" label="Indicateur" UI="combo" width="210" default="0" tree="true" showIfNotDefault="true">
				<OPTION label="" data="-1"/>
				<OPTION label="" data="" globalListProvider="DATA_AP_IND" condition="dataItem.data6 &gt; 20 and dataItem.data6 &lt; 30"/>
			</FIELD>
			<!--FIELD name="INDICATEUR" label="Indicateur" UI="combo" width="210" default="0" tree="true" showIfNotDefault="true">
				<OPTION label="" data="0"/>
				<OPTION label="" data="" globalListProvider="DATA_AP_IND" condition="dataItem.data6 &gt; 20 and dataItem.data6 &lt; 30"/>
			</FIELD-->
		</GROUP>

	</SELECTIONS>
	
	<QUERIES>
		<QUERY label=""> 
			<SQL optimizer="V_LIGNES_COMMANDES_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]}
						INDICATORS{
							COUNT(DISTINCT unite_approvisionnement_article_id),,
							SUM(quantite_approvisionnement),,
							SUM(montant_commande_ht),,
							SUM(montant_commande_remise),,
							SUM(montant_commande_tva),,
							SUM(montant_commande_port),,
							SUM(montant_commande_ttc),,
							SUM(quantite_non_livraison_approvisionnement),,
							SUM(montant_non_livraison_ht),,
							SUM(montant_non_livraison_ttc),,
							base.cti_division(
								SUM(CASE WHEN montant_commande_ttc > 0 THEN montant_commande_ttc ELSE 0 END),
								SUM(CASE WHEN montant_commande_ttc > 0 THEN quantite_approvisionnement ELSE 0 END)
							),,
							count(DISTINCT article_id),,
							CASE WHEN count(DISTINCT article_id) = 1 THEN MAX(article_id) ELSE 0 END,,
						}
						INDICATORS_TEXT{
							COUNT(DISTINCT commande_id)::text || ' commandes, '::text || COUNT(*)::text || ' lignes'::text,,
							'',,
							'',,
							'',,
							'',,
							'',,
							MAX(CASE WHEN unite_approvisionnement_article_id <> 0 AND unite_approvisionnement_article_code <> 'UN' THEN unite_approvisionnement_article_texte ELSE '' END)::text,,
						}	
						INDICATORS_2_TEXT{
							MAX(CASE WHEN '[GROUPBY_2]' = 'CML' THEN ligne_commande_texte ELSE commande_reference END)::text,,
							MAX(date_commande)::text,,
							MAX(date_engagement)::text,,
							MAX(date_reception)::text,,
							MAX(lieu_code)::text,,
							MAX(gestionnaire_code)::text,,
							MAX(CASE WHEN unite_approvisionnement_article_id <> 0 AND unite_approvisionnement_article_code <> 'UN' THEN unite_approvisionnement_article_texte ELSE '' END)::text,,
						}	
					FROM #V_LIGNES_COMMANDES_X##V_ALL_X#
					WHERE [DATE_BASE2] BETWEEN '[PERIODE]' AND '[TOPERIODE]'
						[VIEW.ARTICLE_SELECT]
						[VIEW.FOURNISSEUR_SELECT]
						[VIEW.COMMANDE_SELECT]
						[VIEW.PROVIDER_SELECT]
					HAVING ([VIEW.DATASQL_FILTER] > 0)
					
					
					
				]]></select>
				<FIELDS>
					<INSERT name="CTISELECT_TREE_FIELDS"/>
					<FIELD name="QUST" />
					<FIELD name="QCMD" />
					<FIELD name="MCMDHT" />
					<FIELD name="MCMDREM" />
					<FIELD name="MCMDTVA" />
					<FIELD name="MCMDPOR" />
					<FIELD name="MCMDTTC" />
					<FIELD name="QRES" />
					<FIELD name="MRESHT" />
					<FIELD name="MRESTTC" />
					<FIELD name="PUMTTC" />
					<FIELD name="NART" />
					<FIELD name="ART" />
					
					<FIELD name="ARTI" />
					<FIELD name="DATE" />
					<FIELD name="DATG" />
					<FIELD name="DATR" />
					<FIELD name="LIEU" />
					<FIELD name="GEST" />
					<FIELD name="UNIT" />
				</FIELDS>
			</SQL>
		</QUERY>
	</QUERIES>
	
	<PRESENTATION>
		<VIEWLINKS>
			<VIEWLINK label="Détail mouvements" shortLabel="Détail mouvements" view="ECO000010.XML" componentName=""  rowContext="true"
				 visible="= ROW.DATR != ''">

				<ARGS name="ALL" >
					<value><![CDATA[
					
					if (SELECT.GROUPBY == 'CMD') {LINKVARIABLES['COMMANDE'] = ROW.COD1}
					if (SELECT.GROUPBY_2 == 'CMD') {LINKVARIABLES['COMMANDE'] = ROW.COD2}
					if (SELECT.GROUPBY_2 == 'CML' && ROW.ART != 0) {LINKVARIABLES['ARTICLE'] = 'DT' + ROW.ART}
					{LINKVARIABLES['PERIODE'] = ROW.DATE}
					{LINKVARIABLES['TOPERIODE'] = ROW.DATR}
					{LINKVARIABLES['GROUPBY'] = 'CMD'}
					{LINKVARIABLES['GROUPBY_2'] = 'MVT'}
					return 'OK';
			
					]]></value>
				</ARGS>
			</VIEWLINK>
			<VIEWLINK label="Détail article" shortLabel="Détail article" view="ECO000069.XML" componentName="ECO_VIEWLINK" component2Name="DATE_EVOL_VIEWLINK" 
				visible="= ROW.ART != 0">
				<ARGS name="SPEC" >
					<value><![CDATA[
						LINKVARIABLES['GROUPBY'] = 'AMCMD'
						LINKVARIABLES['GROUPBY_2'] = 'AMMVT'
						LINKVARIABLES['GROUPBY_3'] = 'AMSTO'
						LINKVARIABLES['TAB'] = 'AUTO'
						if (SELECT.GROUPBY_2 == 'CML' && ROW.ART != 0) {LINKVARIABLES['ARTICLE'] = 'DT' + ROW.ART}
						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="= SELECT.GROUPBY == '-1' || SELECT.GROUPBY_2 == '-1' || SELECT.GROUPBY_TAB == 'TAB'"> 
				
				<INSERT name="DATAGRID_MULTITAB_STYLES"/>
				
				<COLUMN dataField="OID"
					type="Number"
					visible="false" />
				<COLUMN dataField="ISAL"
					type="Number"
					visible="false" />
				<COLUMN dataField="COD" 
					type="Char" 
					minWidth="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="ARTI" 
					type="Char" 
					minWidth="110"
					headerText="if (SELECT.GROUPBY_2 == 'CML') {return 'Complément';} else {return 'Référence';}" 
					headerTextCalc="true"
					textAlign="left" 
					totalComplement=""/>
					
				<COLUMN dataField="DATE" 
					type="Date" 
					width="80"
					inputFormat="AAAA-MM-JJ"
					outputFormat="DD MMM YY"
					headerText="Comm." 
					textAlign="left" 
					totalComplement="*ROW"/>
					
				<COLUMN dataField="DATG" 
					type="Date" 
					width="80"
					inputFormat="AAAA-MM-JJ"
					outputFormat="MMM YY"
					headerText="Eng." 
					textAlign="left" 
					totalComplement="*ROW"/>
				<COLUMN dataField="DATR" 
					type="Date" 
					width="80"
					inputFormat="AAAA-MM-JJ"
					outputFormat="DD MMM YY"
					headerText="Récep." 
					textAlign="left" 
					totalComplement="*ROW"/>
				<COLUMN dataField="LIEU" 
					type="Char" 
					width="50"
					headerText="Lieu" 
					textAlign="left" 
					totalComplement="*ROW"/>
				<COLUMN dataField="GEST" 
					type="Char" 
					width="60"
					headerText="Gest" 
					textAlign="left" 
					totalComplement="*ROW"/>
				<COLUMN dataField="UNIT" 
					type="Char" 
					width="50"
					headerText="Unité" 
					textAlign="left" 
					totalComplement="*ROW"/>	
				<COLUMN dataField="QCMD" 
					type="Number" 
					width="80"
					outputFormat="#"
					visible="true"
					headerText="Quantité" 
					textAlign="right"
					totalComplement="*ROW" />
				<COLUMN dataField="MCMDHT" 
					type="Number" 
					width="80"
					outputFormat="#E"
					visible="true"
					headerText="Tarif HT" 
					textAlign="right"
					totalComplement="*ROW" />
				<COLUMN dataField="MCMDREM" 
					type="Number" 
					width="80"
					outputFormat="#E"
					visible="true"
					headerText="Remise" 
					textAlign="right"
					totalComplement="*ROW" />
				<COLUMN dataField="MCMDTVA" 
					type="Number" 
					width="80"
					outputFormat="#E"
					visible="true"
					headerText="TVA" 
					textAlign="right"
					totalComplement="*ROW" />
				<COLUMNx dataField="MCMDPOR" 
					type="Number" 
					width="80"
					outputFormat="#E"
					visible="true"
					headerText="Port" 
					textAlign="right"
					totalComplement="*ROW" />
				<COLUMN dataField="MCMDTTC" 
					type="Number" 
					width="80"
					outputFormat="#E"
					visible="true"
					headerText="Total TTC" 
					textAlign="right"
					totalComplement="*ROW" />
				<COLUMN dataField="PUMTTC" 
					type="Number" 
					width="80"
					outputFormat="#E,000"
					visible="true"
					headerText="PU Moyen TTC" 
					textAlign="right"
					totalComplement="*ROW" />
				<COLUMN dataField="QRES" 
					type="Number" 
					width="80"
					outputFormat="#"
					visible="true"
					headerText="Non livré Quantité" 
					textAlign="right"
					totalComplement="*ROW" />
				<COLUMN dataField="MRESHT" 
					type="Number" 
					width="80"
					outputFormat="#E"
					visible="true"
					headerText="Non livré HT" 
					textAlign="right"
					totalComplement="*ROW" />	
				<COLUMN dataField="MRESTTC" 
					type="Number" 
					width="80"
					outputFormat="#E"
					visible="true"
					headerText="Non livré TTC" 
					textAlign="right"
					totalComplement="*ROW" />
				<COLUMN dataField="ART"
					type="Number"
					visible="false" />				
			</DATAGRID>
		</ONGLET>
	</PRESENTATION>
</VUE>

			
