<?xml version="1.0" encoding="ISO-8859-1"?>
<VUE name="COMPTA000045" 
	label="Analytique. Prévisions / Réalisations analytiques" 
	title="= 'Analytique. Prévisions / Réalisations ' + SELECT.DATA_LABEL + ' (' + SELECT.MOIS_LABEL + ' ' + SELECT.ANNEE_LABEL + ')'" 
	database="AS400_SHS" swf="*CTI_view1" 
	softCode="iCTI_specifique">
	
	<VIEWPROPERTIES>
		<PROPERTYx dataLink="VIEWPROPERTIES" nameField="name" valueField="value" />
		<PROPERTY name="SHSENV" value="180" />
		<PROPERTY name="FILE" value="[EVAL 
											if ('[DATA]' == 'P') {return 'YHP$2';}
											return 'YHP$1';
										EVAL]" />
		<PROPERTY name="SANA_D" value="[EVAL 
											if ('[SANA_D]' == '-1') {return '0';}
											return '[SANA_D]';
										EVAL]" />
		<PROPERTY name="SANA_F" value="[EVAL 
											if ('[SANA_D]' == '-1') {return '9999';}
											if ('[SANA_F]' == '-1') {return '9999';}
											if ('[SANA_F]' == '-2') {return '[SANA_D]';}
											return '[SANA_F]';
										EVAL]" />
										
		<PROPERTY name="CPTE_D" value="[EVAL 
											if ('[CPTE_D]' == '-1') {return '0';}
											return substr('[CPTE_D]' . '00000000',0,8);
										EVAL]" />
		<PROPERTY name="CPTE_F" value="[EVAL 
											if ('[CPTE_D]' == '-1') {return '99999999';}
											if ('[CPTE_F]' == '-1') {return '99999999';}
											if ('[CPTE_F]' == '-2') {return substr('[CPTE_D]' . '99999999',0,8);}
											return substr('[CPTE_F]' . '99999999',0,8);
										EVAL]" />
									
		<PROPERTY name="FCT_1_SELECT" value="[EVAL 
											if ('[FCT_1]' == '-2') {return &quot; AND YHSANA IN (SELECT A7SANA FROM PIANBU180.A7L21 WHERE A7TYPE = '1' AND A7CATA &lt;&gt; '')  &quot; ;}
											if ('[FCT_1]' != '-1') {return &quot; AND YHSANA IN (SELECT A7SANA FROM PIANBU180.A7L21 WHERE A7TYPE = '1' AND A7CATA = '[FCT_1]')  &quot; ;}
												return '';
										EVAL]" />
		<PROPERTY name="FCT_2_SELECT" value="[EVAL 
											if ('[FCT_2]' == '-2') {return &quot; AND YHSANA IN (SELECT A7SANA FROM PIANBU180.A7L21 WHERE A7TYPE = '2' AND A7CATA &lt;&gt; '')  &quot; ;}
											if ('[FCT_2]' != '-1') {return &quot; AND YHSANA IN (SELECT A7SANA FROM PIANBU180.A7L21 WHERE A7TYPE = '2' AND A7CATA = '[FCT_2]')  &quot; ;}
											return '';
										EVAL]" />
		<PROPERTY name="FCT_3_SELECT" value="[EVAL 
											if ('[FCT_3]' == '-2') {return &quot; AND YHSANA IN (SELECT A7SANA FROM PIANBU180.A7L21 WHERE A7TYPE = '3' AND A7CATA &lt;&gt; '')  &quot; ;}
											if ('[FCT_3]' != '-1') {return &quot; AND YHSANA IN (SELECT A7SANA FROM PIANBU180.A7L21 WHERE A7TYPE = '3' AND A7CATA = '[FCT_3]')  &quot; ;}
											return '';
										EVAL]" />
		<PROPERTY name="FCT_4_SELECT" value="[EVAL 
											if ('[FCT_4]' == '-2') {return &quot; AND YHSANA IN (SELECT A7SANA FROM PIANBU180.A7L21 WHERE A7TYPE = '4' AND A7CATA &lt;&gt; '')  &quot; ;}
											if ('[FCT_4]' != '-1') {return &quot; AND YHSANA IN (SELECT A7SANA FROM PIANBU180.A7L21 WHERE A7TYPE = '4' AND A7CATA = '[FCT_4]')  &quot; ;}
											return '';
										EVAL]" />
		
		<PROPERTY name="GROUPBY_CODE_FIELD" value="[EVAL 
											if ('[GROUPBY]' == 'S') {return 'YHSANA';}
											if ('[GROUPBY]' == 'C') {return 'YHCPTE';}
											if ('[GROUPBY]' == 'C1') {return 'YHCPT1';}
											if ('[GROUPBY]' == 'C2') {return 'YHCPT2';}
											if ('[GROUPBY]' == 'C3') {return 'YHCPT3';}
											if ('[GROUPBY]' == 'F1') {return 'A7CATA_1';}
											if ('[GROUPBY]' == 'F2') {return 'A7CATA_2';}
											if ('[GROUPBY]' == 'F3') {return 'A7CATA_3';}
											if ('[GROUPBY]' == 'F4') {return 'A7CATA_4';}
											return 'YHSANA';
										EVAL]" />
		<PROPERTY name="GROUPBY_TEXT_FIELD" value="[EVAL 
											if ('[GROUPBY]' == 'S') {return 'ANINT3';}
											if ('[GROUPBY]' == 'C') {return 'PEINT3';}
											if ('[GROUPBY]' == 'C1') {return 'PGINT1';}
											if ('[GROUPBY]' == 'C2') {return 'PGINT2';}
											if ('[GROUPBY]' == 'C3') {return 'PGINT3';}
											if ('[GROUPBY]' == 'F1') {return 'CGINT3_1';}
											if ('[GROUPBY]' == 'F2') {return 'CGINT3_2';}
											if ('[GROUPBY]' == 'F3') {return 'CGINT3_3';}
											if ('[GROUPBY]' == 'F4') {return 'CGINT3_4';}
											return 'ANINT3';
										EVAL]" />	
		<PROPERTY name="CHAPBY_CODE_FIELD" value="[EVAL 
											if ('[CHAPBY]' == 'S') {return 'YHSANA';}
											if ('[CHAPBY]' == 'C') {return 'YHCPTE';}
											if ('[CHAPBY]' == 'C1') {return 'YHCPT1';}
											if ('[CHAPBY]' == 'C2') {return 'YHCPT2';}
											if ('[CHAPBY]' == 'C3') {return 'YHCPT3';}
											if ('[CHAPBY]' == 'F1') {return 'A7CATA_1';}
											if ('[CHAPBY]' == 'F2') {return 'A7CATA_2';}
											if ('[CHAPBY]' == 'F3') {return 'A7CATA_3';}
											if ('[CHAPBY]' == 'F4') {return 'A7CATA_4';}
											return 'YHSANA';
										EVAL]" />
		<PROPERTY name="CHAPBY_TEXT_FIELD" value="[EVAL 
											if ('[CHAPBY]' == 'S') {return 'ANINT3';}
											if ('[CHAPBY]' == 'C') {return 'PEINT3';}
											if ('[CHAPBY]' == 'C1') {return 'PGINT1';}
											if ('[CHAPBY]' == 'C2') {return 'PGINT2';}
											if ('[CHAPBY]' == 'C3') {return 'PGINT3';}
											if ('[CHAPBY]' == 'F1') {return 'CGINT3_1';}
											if ('[CHAPBY]' == 'F2') {return 'CGINT3_2';}
											if ('[CHAPBY]' == 'F3') {return 'CGINT3_3';}
											if ('[CHAPBY]' == 'F4') {return 'CGINT3_4';}
											
											return 'ANINT3';
										EVAL]" />								
	</VIEWPROPERTIES>
	
	<SELECTIONS label="Paramètres de l'analyse" displayText="= var display:String = '';
				if (SELECT.SANA_D != '-1') {
				display = display + 'Section analytique : #B#' ;
				if (SELECT.SANA_F == '-1') {
					display = display + 'à partir de ' + SELECT.SANA_D_LABEL ;
				}
				else {
					if (SELECT.SANA_F == '-2') {
						display = display + SELECT.SANA_D_LABEL ;
					}
					else {
						display = display + 'entre ' + SELECT.SANA_D_LABEL + ' et ' + SELECT.SANA_F_LABEL;
					}
				}
				display = display  + '#/B# ';
				}
				if (SELECT.CPTE_D != '-1') {
				display = display + 'Compte : #B#' ;
				if (SELECT.CPTE_F == '-1') {
					display = display + 'à partir de ' + SELECT.CPTE_D_LABEL ;
				}
				else {
					if (SELECT.CPTE_F == '-2') {
						display = display + SELECT.CPTE_D_LABEL ;
					}
					else {
						display = display + 'entre ' + SELECT.CPTE_D_LABEL + ' et ' + SELECT.CPTE_F_LABEL;
					}
				}
				display = display  + '#/B#';
				}
				if (SELECT.FCT_1 != '-1') {
					display = display + 'Fonction 1 : #B#' + SELECT.FCT_1_LABEL  + '#/B# ' ;
				}
				if (SELECT.FCT_2 != '-1') {
					display = display + 'Fonction 2 : #B#' + SELECT.FCT_2_LABEL  + '#/B# ' ;
				}
				if (SELECT.FCT_3 != '-1') {
					display = display + 'Fonction 3 : #B#' + SELECT.FCT_3_LABEL  + '#/B# ' ;
				}
				if (SELECT.FCT_4 != '-1') {
					display = display + 'Fonction 4 : #B#' + SELECT.FCT_4_LABEL  + '#/B# ' ;
				}
				return display;
	
	
		">
		<GROUP label="Période">
			<FIELD name="ANNEE" label="" UI="combo" width="80" default="2009"  >
				<OPTION label="2010" data="2010"/>
				<OPTION label="2009" data="2009"/>
				<OPTION label="2008" data="2008"/>
				<OPTION label="2007" data="2007"/>
				<OPTION label="2006" data="2006"/>
			</FIELD>

			<FIELD name="MOIS" label="" UI="combo" width="150" default="12"  >
				<OPTION label="Décembre" data="12"/>
				<OPTION label="Novembre" data="11"/>
				<OPTION label="Octobre" data="10"/>
				<OPTION label="Septembre"  data="09"/>
				<OPTION label="Aout" data="08"/>
				<OPTION label="Juillet" data="07"/>
				<OPTION label="Juin" data="06"/>
				<OPTION label="Mai"  data="05"/>
				<OPTION label="Avril" data="04"/>
				<OPTION label="Mars" data="03"/>
				<OPTION label="Février" data="02"/>
				<OPTION label="Janvier"  data="01"/>
			</FIELD>
		</GROUP>
		<GROUP label="Données">
			<FIELD name="DATA" label="" UI="combo" width="200" default="A"  >
				<OPTION label="Avant répartition" data="A"/>
				<OPTION label="Après répartition" data="P"/>
			</FIELD>
		</GROUP>
		
		<GROUP label="Section">
			<FIELD name="SANA_D" label="" UI="combo" width="250" default="-1" default2="" showIfNotDefault="true" >
				<OPTION label="Pas de sélection" data="-1"/>
				<OPTION dataLink="SECTIONS" dataField="cod" labelField="txt" />
			</FIELD>
			<FIELD name="SANA_F" label="à" UI="combo" width="250" default="-1" default2="" visible="= SELECT.SANA_D != '-1'" showIfNotDefault="true">
				<OPTION label="Pas de sélection" data="-1"/>
				<OPTION label="Une seule sélection" data="-2"/>
				<OPTION dataLink="SECTIONS" dataField="cod" labelField="txt" />
			</FIELD>
		</GROUP>
		
		<GROUP label="Compte">
			<FIELD name="CPTE_D" tree="true" label="" UI="combo" width="250" default="-1" default2="" showIfNotDefault="true" >
				<OPTION label="Pas de sélection" data="-1" treeLevel="1"/>
				<OPTION dataLink="COMPTES" dataField="cod" labelField="txt" treeLevelField="lvl"  />
			</FIELD>
			<FIELD name="CPTE_F" tree="true" label="à" UI="combo" width="250" default="-1" default2="" visible="= SELECT.CPTE_D != '-1'" showIfNotDefault="true">
				<OPTION label="Pas de sélection" data="-1" treeLevel="1" />
				<OPTION label="Une seule sélection" data="-2" treeLevel="1"/>
				<OPTION dataLink="COMPTES" dataField="cod" labelField="txt" treeLevelField="lvl" />
			</FIELD>
		</GROUP>
		
		<GROUP label="Fonctions">
			<FIELD name="FCT_1" tree="false" label="1" UI="combo" width="250" default="-1" default2="" showIfNotDefault="true" >
				<OPTION label="Pas de sélection" data="-1" treeLevel="1"/>
				<OPTION label="Fonctions renseignées" data="-2" treeLevel="1"/>
				<OPTION dataLink="FONCTIONS_1" dataField="cod" labelField="txt"  />
			</FIELD>
			<FIELD name="FCT_2" tree="false" label="2" UI="combo" width="250" default="-1" default2="" showIfNotDefault="true" >
				<OPTION label="Pas de sélection" data="-1" treeLevel="1"/>
				<OPTION label="Fonctions renseignées" data="-2" treeLevel="1"/>
				<OPTION dataLink="FONCTIONS_2" dataField="cod" labelField="txt"  />
			</FIELD>
		</GROUP>
		<GROUP label=" ">
			<FIELD name="FCT_3" tree="false" label="3" UI="combo" width="250" default="-1" default2="" showIfNotDefault="true" >
				<OPTION label="Pas de sélection" data="-1" treeLevel="1"/>
				<OPTION label="Fonctions renseignées" data="-2" treeLevel="1"/>
				<OPTION dataLink="FONCTIONS_3" dataField="cod" labelField="txt"  />
			</FIELD>
			<FIELD name="FCT_4" tree="false" label="4" UI="combo" width="250" default="-1" default2="" showIfNotDefault="true" >
				<OPTION label="Pas de sélection" data="-1" treeLevel="1"/>
				<OPTION label="Fonctions renseignées" data="-2" treeLevel="1"/>
				<OPTION dataLink="FONCTIONS_4" dataField="cod" labelField="txt"  />
			</FIELD>
		</GROUP>
			
		
		<GROUP label="Chapitre">
			<FIELD name="CHAPBY" label="" UI="combo" width="200" default="-1"  >
				<OPTION label="Pas de chapitre" data="-1"/>
				<OPTION label="Section" data="S"/>
				<OPTION label="Classe" data="C1"/>
				<OPTION label="Sous-classe" data="C2"/>
				<OPTION label="Compte à 3 chiffres" data="C3"/>
				<OPTION label="Compte" data="C"/>
				<OPTION label="Fonction 1" data="F1"/>
				<OPTION label="Fonction 2" data="F2"/>
				<OPTION label="Fonction 3" data="F3"/>
				<OPTION label="Fonction 4" data="F4"/>
			</FIELD>
		</GROUP>
		<GROUP label="Regroupement">
			<FIELD name="GROUPBY" label="" UI="combo" width="200" default="S"  >
				<OPTION label="Section" data="S"/>
				<OPTION label="Classe" data="C1"/>
				<OPTION label="Sous-classe" data="C2"/>
				<OPTION label="Compte à 3 chiffres" data="C3"/>
				<OPTION label="Compte" data="C"/>
				<OPTION label="Fonction 1" data="F1"/>
				<OPTION label="Fonction 2" data="F2"/>
				<OPTION label="Fonction 3" data="F3"/>
				<OPTION label="Fonction 4" data="F4"/>
			</FIELD>
		</GROUP>
	</SELECTIONS>
	
	
	
	

	<QUERIES>
	
		<QUERY label=""> 
			<SQL enabled="[CHAPBY!=-1::false]"
				select="
				
				(SELECT '0', [VIEW.GROUPBY_CODE_FIELD], 0, [VIEW.GROUPBY_CODE_FIELD], [VIEW.GROUPBY_TEXT_FIELD], 
				SUM(YGMPRA), 
				SUM(YHMPRA), 
				SUM(YHMP2A), 
				SUM(YHMPRA - YHMP2A), 
				CASE WHEN SUM(YHMP2A) &lt;&gt;0 THEN (SUM(YHMPRA + 0.0000) - SUM(YHMP2A)) / SUM(YHMP2A) * 100 ELSE 0 END ,
				CASE WHEN SUM(YGMPRA) &lt;&gt;0 THEN SUM(YHMPRA + 0.0000) / SUM(YGMPRA) * 100 ELSE 0 END
				FROM 
					(SELECT 
					DIGITS(YHCPTE) AS YHCPTE, 
					PEINT3 AS PEINT3,
					SUBSTR(DIGITS(YHCPTE),1,1) AS YHCPT1, 
					PGL01AN_1.PGINT3 AS PGINT1,
					SUBSTR(DIGITS(YHCPTE),1,2) AS YHCPT2, 
					PGL01AN_2.PGINT3 AS PGINT2,
					SUBSTR(DIGITS(YHCPTE),1,3) AS YHCPT3, 
					PGL01AN_3.PGINT3 AS PGINT3,
					DIGITS(YHSANA) YHSANA,
					ANINT3 AS ANINT3,
					A7CATA_1,
					A7CATA_2,
					A7CATA_3,
					A7CATA_4,
					CGINT3_1,
					CGINT3_2,
					CGINT3_3,
					CGINT3_4,
					CASE WHEN substr(DIGITS(YHCPTE),1,1) = '6' THEN 0 - YGMPRA ELSE YGMPRA END AS YGMPRA,
					CASE WHEN substr(DIGITS(YHCPTE),1,1) = '6' THEN 0 - YHMPRA ELSE YHMPRA END AS YHMPRA,
					CASE WHEN substr(DIGITS(YHCPTE),1,1) = '6' THEN 0 - YHMP2A ELSE YHMP2A END AS YHMP2A
					FROM pianbu180.[VIEW.FILE]
					LEFT JOIN pianbu180.pel01an ON (YHCPTE = PECPTE)
					LEFT JOIN pianbu180.pgl01an PGL01AN_1 ON (SUBSTR(DIGITS(YHCPTE),1,1) = PGL01AN_1.PGCLAS)
					LEFT JOIN pianbu180.pgl01an PGL01AN_2 ON (SUBSTR(DIGITS(YHCPTE),1,2) = PGL01AN_2.PGCLAS)
					LEFT JOIN pianbu180.pgl01an PGL01AN_3 ON (SUBSTR(DIGITS(YHCPTE),1,3) = PGL01AN_3.PGCLAS)
					LEFT JOIN 
					(SELECT ANSANA, ANINT3, 
						CASE WHEN A7L21_1.A7CATA IS NOT NULL THEN A7L21_1.A7CATA ELSE '***' END AS A7CATA_1, 
						CASE WHEN A7L21_1.A7CATA IS NOT NULL THEN A7L21_1.CGINT3 ELSE 'Fonction 1 non renseignée' END AS CGINT3_1, 
						CASE WHEN A7L21_2.A7CATA IS NOT NULL THEN A7L21_2.A7CATA ELSE '***' END AS A7CATA_2, 
						CASE WHEN A7L21_2.A7CATA IS NOT NULL THEN A7L21_2.CGINT3 ELSE 'Fonction 2 non renseignée' END AS CGINT3_2, 
						CASE WHEN A7L21_3.A7CATA IS NOT NULL THEN A7L21_3.A7CATA ELSE '***' END AS A7CATA_3, 
						CASE WHEN A7L21_3.A7CATA IS NOT NULL THEN A7L21_3.CGINT3 ELSE 'Fonction 3 non renseignée' END AS CGINT3_3, 
						CASE WHEN A7L21_4.A7CATA IS NOT NULL THEN A7L21_4.A7CATA ELSE '***' END AS A7CATA_4, 
						CASE WHEN A7L21_4.A7CATA IS NOT NULL THEN A7L21_4.CGINT3 ELSE 'Fonction 4 non renseignée' END AS CGINT3_4
						
						FROM pianbu180.anl01an
						LEFT JOIN 
							(SELECT A7SANA, A7CATA, CGINT3 FROM pianbu180.A7L21, pianbu180.CGL01 WHERE A7CATA = CGCATA AND A7TYPE = '1') A7L21_1
						 ON (ANSANA = A7L21_1.A7SANA)
						LEFT JOIN 
							(SELECT A7SANA, A7CATA, CGINT3 FROM pianbu180.A7L21, pianbu180.CGL01 WHERE A7CATA = CGCATA AND A7TYPE = '2') A7L21_2
						 ON (ANSANA = A7L21_2.A7SANA)
						LEFT JOIN 
							(SELECT A7SANA, A7CATA, CGINT3 FROM pianbu180.A7L21, pianbu180.CGL01 WHERE A7CATA = CGCATA AND A7TYPE = '3') A7L21_3
						 ON (ANSANA = A7L21_3.A7SANA)
						LEFT JOIN 
							(SELECT A7SANA, A7CATA, CGINT3 FROM pianbu180.A7L21, pianbu180.CGL01 WHERE A7CATA = CGCATA AND A7TYPE = '4') A7L21_4
						 ON (ANSANA = A7L21_4.A7SANA)

					) SUBVIEW ON (YHSANA = ANSANA)
					WHERE YHANEE = [ANNEE] and yhmois &lt;= [MOIS] 
						AND YHCPTE &gt;= [VIEW.CPTE_D] AND YHCPTE &lt;= [VIEW.CPTE_F]
						AND YHSANA &gt;= [VIEW.SANA_D] AND YHSANA &lt;= [VIEW.SANA_F]
						[VIEW.FCT_1_SELECT]
						[VIEW.FCT_2_SELECT]
						[VIEW.FCT_3_SELECT]
						[VIEW.FCT_4_SELECT]
					) SUBVIEW
				
				GROUP BY [VIEW.GROUPBY_CODE_FIELD], [VIEW.GROUPBY_TEXT_FIELD])
				UNION
				(SELECT '999', '0', 0, '', '', 
				SUM(YGMPRA), 
				SUM(YHMPRA), 
				SUM(YHMP2A), 
				SUM(YHMPRA - YHMP2A), 
				CASE WHEN SUM(YHMP2A) &lt;&gt;0 THEN (SUM(YHMPRA + 0.0000) - SUM(YHMP2A)) / SUM(YHMP2A) * 100 ELSE 0 END ,
				CASE WHEN SUM(YGMPRA) &lt;&gt;0 THEN SUM(YHMPRA + 0.0000) / SUM(YGMPRA) * 100 ELSE 0 END
				FROM 
					(SELECT 
					CASE WHEN substr(DIGITS(YHCPTE),1,1) = '6' THEN 0 - YGMPRA ELSE YGMPRA END AS YGMPRA,
					CASE WHEN substr(DIGITS(YHCPTE),1,1) = '6' THEN 0 - YHMPRA ELSE YHMPRA END AS YHMPRA,
					CASE WHEN substr(DIGITS(YHCPTE),1,1) = '6' THEN 0 - YHMP2A ELSE YHMP2A END AS YHMP2A
					FROM pianbu180.[VIEW.FILE]
					WHERE YHANEE = [ANNEE] and yhmois &lt;= [MOIS] 
						AND YHCPTE &gt;= [VIEW.CPTE_D] AND YHCPTE &lt;= [VIEW.CPTE_F]
						AND YHSANA &gt;= [VIEW.SANA_D] AND YHSANA &lt;= [VIEW.SANA_F]
						[VIEW.FCT_1_SELECT]
						[VIEW.FCT_2_SELECT]
						[VIEW.FCT_3_SELECT]
						[VIEW.FCT_4_SELECT]
					) SUBVIEW
				)
				ORDER BY 2, 3                                                
				
				
				" >
				<FIELDS>
					<FIELD name="LVL" />
					<FIELD name="SANA" />
					<FIELD name="CPTE" />
					<FIELD name="CODE" />
					<FIELD name="TEXT" />
					<FIELD name="PREV" />
					<FIELD name="REAL" />
					<FIELD name="REAP" />
					<FIELD name="REAE" />
					<FIELD name="REAPE" />
					<FIELD name="REAPV" />
				</FIELDS>
			</SQL>
			
			<SQL enabled="[CHAPBY==-1::false]"
				select="
				(SELECT '2', [VIEW.CHAPBY_CODE_FIELD], [VIEW.GROUPBY_CODE_FIELD], [VIEW.GROUPBY_CODE_FIELD], [VIEW.GROUPBY_TEXT_FIELD], 
				SUM(YGMPRA), 
				SUM(YHMPRA), 
				SUM(YHMP2A), 
				SUM(YHMPRA - YHMP2A), 
				CASE WHEN SUM(YHMP2A) &lt;&gt;0 THEN (SUM(YHMPRA + 0.0000) - SUM(YHMP2A)) / SUM(YHMP2A) * 100 ELSE 0 END ,
				CASE WHEN SUM(YGMPRA) &lt;&gt;0 THEN SUM(YHMPRA + 0.0000) / SUM(YGMPRA) * 100 ELSE 0 END
				FROM 
					(SELECT 
					DIGITS(YHCPTE) AS YHCPTE, 
					PEINT3 AS PEINT3,
					SUBSTR(DIGITS(YHCPTE),1,1) AS YHCPT1, 
					PGL01AN_1.PGINT3 AS PGINT1,
					SUBSTR(DIGITS(YHCPTE),1,2) AS YHCPT2, 
					PGL01AN_2.PGINT3 AS PGINT2,
					SUBSTR(DIGITS(YHCPTE),1,3) AS YHCPT3, 
					PGL01AN_3.PGINT3 AS PGINT3,
					DIGITS(YHSANA) AS YHSANA,
					ANINT3 AS ANINT3,
					A7CATA_1,
					A7CATA_2,
					A7CATA_3,
					A7CATA_4,
					CGINT3_1,
					CGINT3_2,
					CGINT3_3,
					CGINT3_4,
					CASE WHEN substr(DIGITS(YHCPTE),1,1) = '6' THEN 0 - YGMPRA ELSE YGMPRA END AS YGMPRA,
					CASE WHEN substr(DIGITS(YHCPTE),1,1) = '6' THEN 0 - YHMPRA ELSE YHMPRA END AS YHMPRA,
					CASE WHEN substr(DIGITS(YHCPTE),1,1) = '6' THEN 0 - YHMP2A ELSE YHMP2A END AS YHMP2A
					FROM pianbu180.[VIEW.FILE]
					LEFT JOIN pianbu180.pel01an ON (YHCPTE = PECPTE)
					LEFT JOIN pianbu180.pgl01an PGL01AN_1 ON (SUBSTR(DIGITS(YHCPTE),1,1) = PGL01AN_1.PGCLAS)
					LEFT JOIN pianbu180.pgl01an PGL01AN_2 ON (SUBSTR(DIGITS(YHCPTE),1,2) = PGL01AN_2.PGCLAS)
					LEFT JOIN pianbu180.pgl01an PGL01AN_3 ON (SUBSTR(DIGITS(YHCPTE),1,3) = PGL01AN_3.PGCLAS)
					LEFT JOIN 
					(SELECT ANSANA, ANINT3, 
						CASE WHEN A7L21_1.A7CATA IS NOT NULL THEN A7L21_1.A7CATA ELSE '***' END AS A7CATA_1, 
						CASE WHEN A7L21_1.A7CATA IS NOT NULL THEN A7L21_1.CGINT3 ELSE 'Fonction 1 non renseignée' END AS CGINT3_1, 
						CASE WHEN A7L21_2.A7CATA IS NOT NULL THEN A7L21_2.A7CATA ELSE '***' END AS A7CATA_2, 
						CASE WHEN A7L21_2.A7CATA IS NOT NULL THEN A7L21_2.CGINT3 ELSE 'Fonction 2 non renseignée' END AS CGINT3_2, 
						CASE WHEN A7L21_3.A7CATA IS NOT NULL THEN A7L21_3.A7CATA ELSE '***' END AS A7CATA_3, 
						CASE WHEN A7L21_3.A7CATA IS NOT NULL THEN A7L21_3.CGINT3 ELSE 'Fonction 3 non renseignée' END AS CGINT3_3, 
						CASE WHEN A7L21_4.A7CATA IS NOT NULL THEN A7L21_4.A7CATA ELSE '***' END AS A7CATA_4, 
						CASE WHEN A7L21_4.A7CATA IS NOT NULL THEN A7L21_4.CGINT3 ELSE 'Fonction 4 non renseignée' END AS CGINT3_4
						
						FROM pianbu180.anl01an
						LEFT JOIN 
							(SELECT A7SANA, A7CATA, CGINT3 FROM pianbu180.A7L21, pianbu180.CGL01 WHERE A7CATA = CGCATA AND A7TYPE = '1') A7L21_1
						 ON (ANSANA = A7L21_1.A7SANA)
						LEFT JOIN 
							(SELECT A7SANA, A7CATA, CGINT3 FROM pianbu180.A7L21, pianbu180.CGL01 WHERE A7CATA = CGCATA AND A7TYPE = '2') A7L21_2
						 ON (ANSANA = A7L21_2.A7SANA)
						LEFT JOIN 
							(SELECT A7SANA, A7CATA, CGINT3 FROM pianbu180.A7L21, pianbu180.CGL01 WHERE A7CATA = CGCATA AND A7TYPE = '3') A7L21_3
						 ON (ANSANA = A7L21_3.A7SANA)
						LEFT JOIN 
							(SELECT A7SANA, A7CATA, CGINT3 FROM pianbu180.A7L21, pianbu180.CGL01 WHERE A7CATA = CGCATA AND A7TYPE = '4') A7L21_4
						 ON (ANSANA = A7L21_4.A7SANA)

					) SUBVIEW ON (YHSANA = ANSANA)
					WHERE YHANEE = [ANNEE] and yhmois &lt;= [MOIS] 
						AND YHCPTE &gt;= [VIEW.CPTE_D] AND YHCPTE &lt;= [VIEW.CPTE_F]
						AND YHSANA &gt;= [VIEW.SANA_D] AND YHSANA &lt;= [VIEW.SANA_F]
						[VIEW.FCT_1_SELECT]
						[VIEW.FCT_2_SELECT]
						[VIEW.FCT_3_SELECT]
						[VIEW.FCT_4_SELECT]
					) SUBVIEW
				GROUP BY [VIEW.CHAPBY_CODE_FIELD], [VIEW.GROUPBY_CODE_FIELD], [VIEW.GROUPBY_TEXT_FIELD]
				) 
				UNION
				(SELECT '1', [VIEW.CHAPBY_CODE_FIELD], '', [VIEW.CHAPBY_CODE_FIELD], [VIEW.CHAPBY_TEXT_FIELD], 
				SUM(YGMPRA), 
				SUM(YHMPRA), 
				SUM(YHMP2A), 
				SUM(YHMPRA - YHMP2A), 
				CASE WHEN SUM(YHMP2A) &lt;&gt;0 THEN (SUM(YHMPRA + 0.0000) - SUM(YHMP2A)) / SUM(YHMP2A) * 100 ELSE 0 END ,
				CASE WHEN SUM(YGMPRA) &lt;&gt;0 THEN SUM(YHMPRA + 0.0000) / SUM(YGMPRA) * 100 ELSE 0 END
				FROM 
					(SELECT 
					DIGITS(YHCPTE) AS YHCPTE, 
					PEINT3 AS PEINT3,
					SUBSTR(DIGITS(YHCPTE),1,1) AS YHCPT1, 
					PGL01AN_1.PGINT3 AS PGINT1,
					SUBSTR(DIGITS(YHCPTE),1,2) AS YHCPT2, 
					PGL01AN_2.PGINT3 AS PGINT2,
					SUBSTR(DIGITS(YHCPTE),1,3) AS YHCPT3, 
					PGL01AN_3.PGINT3 AS PGINT3,
					DIGITS(YHSANA) AS YHSANA,
					ANINT3 AS ANINT3,
					A7CATA_1,
					A7CATA_2,
					A7CATA_3,
					A7CATA_4,
					CGINT3_1,
					CGINT3_2,
					CGINT3_3,
					CGINT3_4,
					CASE WHEN substr(DIGITS(YHCPTE),1,1) = '6' THEN 0 - YGMPRA ELSE YGMPRA END AS YGMPRA,
					CASE WHEN substr(DIGITS(YHCPTE),1,1) = '6' THEN 0 - YHMPRA ELSE YHMPRA END AS YHMPRA,
					CASE WHEN substr(DIGITS(YHCPTE),1,1) = '6' THEN 0 - YHMP2A ELSE YHMP2A END AS YHMP2A
					FROM pianbu180.[VIEW.FILE]
					LEFT JOIN pianbu180.pel01an ON (YHCPTE = PECPTE)
					LEFT JOIN pianbu180.pgl01an PGL01AN_1 ON (SUBSTR(DIGITS(YHCPTE),1,1) = PGL01AN_1.PGCLAS)
					LEFT JOIN pianbu180.pgl01an PGL01AN_2 ON (SUBSTR(DIGITS(YHCPTE),1,2) = PGL01AN_2.PGCLAS)
					LEFT JOIN pianbu180.pgl01an PGL01AN_3 ON (SUBSTR(DIGITS(YHCPTE),1,3) = PGL01AN_3.PGCLAS)
					LEFT JOIN 
					(SELECT ANSANA, ANINT3, 
						CASE WHEN A7L21_1.A7CATA IS NOT NULL THEN A7L21_1.A7CATA ELSE '***' END AS A7CATA_1, 
						CASE WHEN A7L21_1.A7CATA IS NOT NULL THEN A7L21_1.CGINT3 ELSE 'Fonction 1 non renseignée' END AS CGINT3_1, 
						CASE WHEN A7L21_2.A7CATA IS NOT NULL THEN A7L21_2.A7CATA ELSE '***' END AS A7CATA_2, 
						CASE WHEN A7L21_2.A7CATA IS NOT NULL THEN A7L21_2.CGINT3 ELSE 'Fonction 2 non renseignée' END AS CGINT3_2, 
						CASE WHEN A7L21_3.A7CATA IS NOT NULL THEN A7L21_3.A7CATA ELSE '***' END AS A7CATA_3, 
						CASE WHEN A7L21_3.A7CATA IS NOT NULL THEN A7L21_3.CGINT3 ELSE 'Fonction 3 non renseignée' END AS CGINT3_3, 
						CASE WHEN A7L21_4.A7CATA IS NOT NULL THEN A7L21_4.A7CATA ELSE '***' END AS A7CATA_4, 
						CASE WHEN A7L21_4.A7CATA IS NOT NULL THEN A7L21_4.CGINT3 ELSE 'Fonction 4 non renseignée' END AS CGINT3_4
						
						FROM pianbu180.anl01an
						LEFT JOIN 
							(SELECT A7SANA, A7CATA, CGINT3 FROM pianbu180.A7L21, pianbu180.CGL01 WHERE A7CATA = CGCATA AND A7TYPE = '1') A7L21_1
						 ON (ANSANA = A7L21_1.A7SANA)
						LEFT JOIN 
							(SELECT A7SANA, A7CATA, CGINT3 FROM pianbu180.A7L21, pianbu180.CGL01 WHERE A7CATA = CGCATA AND A7TYPE = '2') A7L21_2
						 ON (ANSANA = A7L21_2.A7SANA)
						LEFT JOIN 
							(SELECT A7SANA, A7CATA, CGINT3 FROM pianbu180.A7L21, pianbu180.CGL01 WHERE A7CATA = CGCATA AND A7TYPE = '3') A7L21_3
						 ON (ANSANA = A7L21_3.A7SANA)
						LEFT JOIN 
							(SELECT A7SANA, A7CATA, CGINT3 FROM pianbu180.A7L21, pianbu180.CGL01 WHERE A7CATA = CGCATA AND A7TYPE = '4') A7L21_4
						 ON (ANSANA = A7L21_4.A7SANA)

					) SUBVIEW ON (YHSANA = ANSANA)
					WHERE YHANEE = [ANNEE] and yhmois &lt;= [MOIS] 
						AND YHCPTE &gt;= [VIEW.CPTE_D] AND YHCPTE &lt;= [VIEW.CPTE_F]
						AND YHSANA &gt;= [VIEW.SANA_D] AND YHSANA &lt;= [VIEW.SANA_F]
						[VIEW.FCT_1_SELECT]
						[VIEW.FCT_2_SELECT]
						[VIEW.FCT_3_SELECT]
						[VIEW.FCT_4_SELECT]
					) SUBVIEW
				GROUP BY [VIEW.CHAPBY_CODE_FIELD], [VIEW.CHAPBY_TEXT_FIELD]
				)
				UNION
				(SELECT '999', '0', '', '', '', 
				SUM(YGMPRA), 
				SUM(YHMPRA), 
				SUM(YHMP2A), 
				SUM(YHMPRA - YHMP2A), 
				CASE WHEN SUM(YHMP2A) &lt;&gt;0 THEN (SUM(YHMPRA + 0.0000) - SUM(YHMP2A)) / SUM(YHMP2A) * 100 ELSE 0 END ,
				CASE WHEN SUM(YGMPRA) &lt;&gt;0 THEN SUM(YHMPRA + 0.0000) / SUM(YGMPRA) * 100 ELSE 0 END
				FROM 
					(SELECT 
					CASE WHEN substr(DIGITS(YHCPTE),1,1) = '6' THEN 0 - YGMPRA ELSE YGMPRA END AS YGMPRA,
					CASE WHEN substr(DIGITS(YHCPTE),1,1) = '6' THEN 0 - YHMPRA ELSE YHMPRA END AS YHMPRA,
					CASE WHEN substr(DIGITS(YHCPTE),1,1) = '6' THEN 0 - YHMP2A ELSE YHMP2A END AS YHMP2A
					FROM pianbu180.[VIEW.FILE]
					WHERE YHANEE = [ANNEE] and yhmois &lt;= [MOIS] 
						AND YHCPTE &gt;= [VIEW.CPTE_D] AND YHCPTE &lt;= [VIEW.CPTE_F]
						AND YHSANA &gt;= [VIEW.SANA_D] AND YHSANA &lt;= [VIEW.SANA_F]
						[VIEW.FCT_1_SELECT]
						[VIEW.FCT_2_SELECT]
						[VIEW.FCT_3_SELECT]
						[VIEW.FCT_4_SELECT]
						) SUBVIEW
				)
				
				ORDER BY 2, 3                                                   
				
				
				" >
				<FIELDS>
					<FIELD name="LVL" />
					<FIELD name="SANA" />
					<FIELD name="CPTE" />
					<FIELD name="CODE" />
					<FIELD name="TEXT" />
					<FIELD name="PREV" />
					<FIELD name="REAL" />
					<FIELD name="REAP" />
					<FIELD name="REAE" />
					<FIELD name="REAPE" />
					<FIELD name="REAPV" />
				</FIELDS>
			</SQL>
			
			
			
			
		</QUERY>
		
		
		<QUERY type="propertiesLink" name="VIEWPROPERTIES" forRows="false"> 
			
			
			
		</QUERY>
		
		<QUERY type="comboLink" name="SECTIONS" forRows="false"> 
			<SQL select="SELECT ANSANA, DIGITS(ANSANA) || ' ' || ANINT3 FROM PIANBU180.ANL01AN 
			WHERE ANSANA IN (SELECT DISTINCT A7SANA FROM PIANBU180.A7P01)
			ORDER BY ANSANA">
				<FIELDS>
					<FIELD name="cod" />
					<FIELD name="txt" />
				</FIELDS>
			</SQL>
		</QUERY>
		
		<QUERY type="comboLink" name="COMPTES" forRows="false"> 
			<SQL select="
			(SELECT DIGITS(PECPTE), DIGITS(PECPTE) || ' ' || PEINT3 , '4' FROM PIANBU180.PEL01AN 
			WHERE PECPTE IN (SELECT DISTINCT A7CPTE FROM PIANBU180.A7P01))
			UNION
			(SELECT TRIM(PGCLAS), TRIM(PGCLAS) || ' ' || PGINT3 , '1' FROM PIANBU180.PGL01AN                                  
			WHERE TRIM(PGCLAS) IN (SELECT DISTINCT SUBSTR(DIGITS(A7CPTE),1,1)   
			FROM PIANBU180.A7P01))                                       
			UNION
			(SELECT TRIM(PGCLAS), TRIM(PGCLAS) || ' ' || PGINT3 , '2' FROM PIANBU180.PGL01AN                                  
			WHERE TRIM(PGCLAS) IN (SELECT DISTINCT SUBSTR(DIGITS(A7CPTE) , 1 , 2)   
			FROM PIANBU180.A7P01)) 
			UNION
			(SELECT TRIM(PGCLAS), TRIM(PGCLAS) || ' ' || PGINT3 , '3' FROM PIANBU180.PGL01AN                                  
			WHERE TRIM(PGCLAS) IN (SELECT DISTINCT SUBSTR(DIGITS(A7CPTE) , 1 , 3)   
			FROM PIANBU180.A7P01)) 
			UNION
			(SELECT DISTINCT SUBSTR(DIGITS(PECPTE) , 1 , 3), SUBSTR(DIGITS(PECPTE) , 1 , 3) , '3' FROM PIANBU180.PEL01AN                                  
			WHERE SUBSTR(DIGITS(PECPTE) , 1 , 3) NOT IN (SELECT PGCLAS FROM PIANBU180.PGL01AN)
			AND SUBSTR(DIGITS(PECPTE) , 1 , 3) IN (SELECT DISTINCT SUBSTR(DIGITS(A7CPTE) , 1 , 3) FROM PIANBU180.A7P01))
			
			
			
			ORDER BY 1">
				<FIELDS>
					<FIELD name="cod" />
					<FIELD name="txt" />
					<FIELD name="lvl" />
				</FIELDS>
			</SQL>
		</QUERY>
		
		<QUERY type="comboLink" name="FONCTIONS_1" forRows="false"> 
			<SQL select="SELECT CGCATA, CGCATA || ' ' || CGINT3 
				FROM PIANBU180.CGL01 
				WHERE CGCATA IN (SELECT DISTINCT A7CATA FROM PIANBU180.A7L21 WHERE A7TYPE = '1')
				ORDER BY 1">
				<FIELDS>
					<FIELD name="cod" />
					<FIELD name="txt" />
				</FIELDS>
			</SQL>
		</QUERY>
		
		<QUERY type="comboLink" name="FONCTIONS_2" forRows="false"> 
			<SQL select="SELECT CGCATA, CGCATA || ' ' || CGINT3 
				FROM PIANBU180.CGL01 
				WHERE CGCATA IN (SELECT DISTINCT A7CATA FROM PIANBU180.A7L21 WHERE A7TYPE = '2')
				ORDER BY 1">
				<FIELDS>
					<FIELD name="cod" />
					<FIELD name="txt" />
				</FIELDS>
			</SQL>
		</QUERY>
		
		<QUERY type="comboLink" name="FONCTIONS_3" forRows="false"> 
			<SQL select="SELECT CGCATA, CGCATA || ' ' || CGINT3 
				FROM PIANBU180.CGL01 
				WHERE CGCATA IN (SELECT DISTINCT A7CATA FROM PIANBU180.A7L21 WHERE A7TYPE = '3')
				ORDER BY 1">
				<FIELDS>
					<FIELD name="cod" />
					<FIELD name="txt" />
				</FIELDS>
			</SQL>
		</QUERY>
		
		<QUERY type="comboLink" name="FONCTIONS_4" forRows="false"> 
			<SQL select="SELECT CGCATA, CGCATA || ' ' || CGINT3 
				FROM PIANBU180.CGL01 
				WHERE CGCATA IN (SELECT DISTINCT A7CATA FROM PIANBU180.A7L21 WHERE A7TYPE = '4')
				ORDER BY 1">
				<FIELDS>
					<FIELD name="cod" />
					<FIELD name="txt" />
				</FIELDS>
			</SQL>
		</QUERY>
		
		
	</QUERIES>
	
	<PRESENTATION>
	
		<VIEWLINKS>
		
			
		
		</VIEWLINKS>
	
		<ONGLET excelLabel="Interventions endoscopie" label="Interventions endoscopie" >
		
			
			<CHARTx title="Prévisions/Réalisations" type="columnChart" subType="" 
				maxItems="20" maxItemsSortOn="REAL" maxItemsSortSeq="D" 
				sortField="CODE" sortSeq="A">
				<CATEGORY field="CODE" 
					type="Char"
					/>
				<SERIE field="REAP" displayName="Réalisations X-1" />
				<SERIE field="PREV" displayName="Prévisions" />
				<SERIE field="REAL" displayName="Réalisé" />
			</CHARTx>
			
			<DATAGRID title="" total="true" headerHeight="36" sortable="false" variableRowHeight="true"
				totalRowInRows="= ROW.LVL == '999'">
				
				<ROWSTYLE name="backgroundColor" value="0xFFD393" condition="ROW.LVL == '1' "/>
				<ROWSTYLE name="fontWeight" value="bold" condition="ROW.LVL == '1' "/>
				<ROWSTYLE name="borderSides" value="top bottom" condition="ROW.LVL == '1' "/>
				<ROWSTYLE name="borderStyle" value="solid" condition="ROW.LVL == '1' "/>
				<ROWSTYLE name="borderThickness" value="2" condition="ROW.LVL == '1' "/>
				<ROWSTYLE name="rowHeight" value="24" condition="ROW.LVL == '1' "/>
				
				<COLUMN dataField="LVL" 
					width="100"
					type="Char" 
					visible="false"
					headerText="Compte" 
					textAlign="right" 
					totalFunction="sum"
					otherFunction="sum">
				</COLUMN>
				
				<COLUMN dataField="SANA"
					type="Number"
					outputFormat="#"
					headerText="Section analytique" 
					visible="false"
					width="100"
					textAlign="right" 
					totalFunction="text"
					otherFunction="text">
				</COLUMN>
				
				
				
				<COLUMN dataField="CPTE" 
					width="100"
					type="Char" 
					visible="false"
					headerText="Compte" 
					textAlign="right" 
					totalFunction="sum"
					otherFunction="sum">
				</COLUMN>
				
				<COLUMN dataField="CODE"
					type="Char"
					headerText="Section/Compte" 
					visible="true"
					width="100"
					textAlign="right" 
					totalFunction="text"
					totalComplement="TOTAL"
					otherFunction="text">
					<CELLSTYLE name="paddingLeft" value="15" condition="ROW.LVL == '2'"/>
				</COLUMN>
				
				<COLUMN dataField="TEXT"
					type="Char"
					headerText="Intitulé" 
					visible="true"
					minWidth="200"
					textAlign="right" 
					totalFunction="text"
					otherFunction="text">
					<CELLSTYLE name="paddingLeft" value="15" condition="ROW.LVL == '2'"/>
				</COLUMN>
				
				<COLUMN dataField="PREV" 
					width="110"
					type="Number" 
					outputFormat="#E" 
					currency="" 
					currencyAlign="right"
					headerText="Prévisions" 
					textAlign="right" 
					totalFunction="sum"
					otherFunction="sum">
				</COLUMN>
				
				<COLUMN dataField="REAL" 
					width="110"
					type="Number" 
					outputFormat="#E" 
					currency="" 
					currencyAlign="right"
					headerText="Réalisations" 
					textAlign="right" 
					totalFunction="sum"
					otherFunction="sum">
				</COLUMN>
				
				<COLUMN dataField="REAP" 
					width="110"
					type="Number" 
					outputFormat="#E" 
					currency="" 
					currencyAlign="right"
					headerText="Réalisations (X-1)" 
					textAlign="right" 
					totalFunction="sum"
					otherFunction="sum">
				</COLUMN>
				
				<COLUMN dataField="REAE" 
					width="110"
					type="Number" 
					outputFormat="#E" 
					currency="" 
					currencyAlign="right"
					headerText="Evolution X / X-1" 
					textAlign="right" 
					totalFunction="sum"
					otherFunction="sum">
				</COLUMN>
				
				<COLUMN dataField="REAPE" 
					width="100"
					type="Number" 
					outputFormat="#,00%" 
					currency="" 
					currencyAlign="right"
					headerText="% Evolution X / X-1" 
					textAlign="right" 
					totalFunction="sum"
					otherFunction="sum">
				</COLUMN>
				
				<COLUMN dataField="REAPV" 
					width="100"
					type="Number" 
					outputFormat="#,00%" 
					currency="" 
					currencyAlign="right"
					headerText="% Prévision" 
					textAlign="right" 
					totalFunction="sum"
					otherFunction="sum">
				</COLUMN>
				
				
			</DATAGRID>
		
		</ONGLET>
		
				
				
	</PRESENTATION>
	
</VUE>

			
