<?xml version="1.0" encoding="ISO-8859-1"?>
<VUE name="COMPTA000028" label="Balance comparative" title="= 'Comptabilité ' + SELECT.CH_LABEL + '. Balance comparative à ' + SELECT.MOIS_LABEL + ' (' + SELECT.TYPEPERIODE_LABEL + ')'" database="iCTI" swf="*CTI_view1" globals="COMPTA_globals.XML" componentsFile="COMPTA_components.XML" dboptimizer="COMPTA_dboptimizer.XML" softCode="iCTI_compta" helpFile="iCTI_COMPTA_COMPTA000028.HTML">
	<VIEWPROPERTIES>
		<PROPERTY name="DATA_FIELD" value="[EVAL 
        
                                    if ('[OPTION_SOLDE]' == 'D') {
                                                                    return 'v_historique_ecritures_1.montant_solde_debit';
                                                                }
                                    else {
                                            return 'v_historique_ecritures_1.montant_solde_credit';
                                         }
											EVAL]"/>
		<PROPERTY dataLink="VIEWPROPERTIES" nameField="name" valueField="value"/>
	</VIEWPROPERTIES>
	<SELECTIONS label="Paramètres de l'analyse" displayText="">
		<GROUP label="Comptabilité">
			<FIELD name="CH" label="" UI="combo" width="150" default="C">
				<OPTION data="C" label="Clinique"/>
				<OPTION data="H" label="Honoraires"/>
			</FIELD>
		</GROUP>
		<GROUP label="Période">
			<FIELD name="MOIS" label="" UI="combo" width="150" default="*FIRST" globalListProvider="MOIS">
			</FIELD>
			<FIELD name="TYPEPERIODE" label="" UI="combo" width="150" default="X">
				<OPTION data="X" label="Exercice"/>
				<OPTION data="A" label="Année civile"/>
				<OPTION data="12" label="12 derniers mois"/>
			</FIELD>
		</GROUP>
        <GROUP label="">
			<FIELD name="OPTION_SOLDE" label="Présentation" UI="combo" width="340" default="D" tree="true">
				<OPTION data="D" label="Afficher solde débiteur"/>
				<OPTION data="C" label="Afficher solde créditeur"/>
			</FIELD>
		</GROUP>
	</SELECTIONS>
	<SELECTIONS componentName="ECRITURES_SELECTIONS"/>
	<QUERIES>
		<QUERY>
			<SQL optimizer="V_HISTORIQUE_ECRITURES_X" cacheEnabled="true" select="

					(SELECT 
							'-9999999', arbre_classe_1_id, arbre_classe_1_code, 0, '',
							0, '',  0, '', 
							0, '',  0, '', 
							0, '', 
							arbre_classe_1_id, arbre_classe_1_code, arbre_classe_1_texte,
							1, 
						
							sum(CASE WHEN v_historique_ecritures_1.mois_comptable = [VIEW.AM2] THEN [VIEW.DATA_FIELD] ELSE 0 END), 
							sum(CASE WHEN v_historique_ecritures_1.mois_comptable = [VIEW.AM1] THEN [VIEW.DATA_FIELD] ELSE 0 END), 
							sum(CASE WHEN v_historique_ecritures_1.mois_comptable = [VIEW.AM0] THEN [VIEW.DATA_FIELD] ELSE 0 END), 
							sum(CASE WHEN v_historique_ecritures_1.mois_comptable = [VIEW.AM0] THEN [VIEW.DATA_FIELD] ELSE 0 END) -
								sum(CASE WHEN v_historique_ecritures_1.mois_comptable = [VIEW.AM1] THEN [VIEW.DATA_FIELD] ELSE 0 END),
							sum(CASE WHEN v_historique_ecritures_1.mois_comptable BETWEEN [VIEW.X2D] AND [VIEW.X2F] THEN [VIEW.DATA_FIELD] ELSE 0 END), 
							sum(CASE WHEN v_historique_ecritures_1.mois_comptable BETWEEN [VIEW.X1D] AND [VIEW.X1F] THEN [VIEW.DATA_FIELD] ELSE 0 END), 
							sum(CASE WHEN v_historique_ecritures_1.mois_comptable BETWEEN [VIEW.X0D] AND [VIEW.X0F] THEN [VIEW.DATA_FIELD] ELSE 0 END), 
							sum(CASE WHEN v_historique_ecritures_1.mois_comptable BETWEEN [VIEW.X0D] AND [VIEW.X0F] THEN [VIEW.DATA_FIELD] ELSE 0 END) -
								sum(CASE WHEN v_historique_ecritures_1.mois_comptable BETWEEN [VIEW.X1D] AND [VIEW.X1F] THEN [VIEW.DATA_FIELD] ELSE 0 END), 
							MAX(fin_exercice), MAX(ajustement)
						
					FROM compta.#V_HISTORIQUE_ECRITURES_X# 
					WHERE v_historique_ecritures_1.arbre_classe_1_id &lt;&gt; 0 AND
						(v_historique_ecritures_1.mois_comptable BETWEEN [VIEW.X0D] AND [VIEW.X0F] 
							OR v_historique_ecritures_1.mois_comptable BETWEEN [VIEW.X1D] AND [VIEW.X1F] 
							OR v_historique_ecritures_1.mois_comptable BETWEEN [VIEW.X2D] AND [VIEW.X2F]) 
							[VIEW.ECRITURES_SELECT]

					GROUP BY arbre_classe_1_id, arbre_classe_1_code, arbre_classe_1_texte
					)
					
					UNION ALL
					
					(SELECT 
							'-9999999', arbre_classe_1_id, arbre_classe_1_code, arbre_classe_2_id, arbre_classe_2_code,
							0, '',  0, '', 
							0, '',  0, '', 
							0, '', 
							arbre_classe_2_id, arbre_classe_2_code, arbre_classe_2_texte,
							2, 
						
							sum(CASE WHEN v_historique_ecritures_1.mois_comptable = [VIEW.AM2] THEN [VIEW.DATA_FIELD] ELSE 0 END), 
							sum(CASE WHEN v_historique_ecritures_1.mois_comptable = [VIEW.AM1] THEN [VIEW.DATA_FIELD] ELSE 0 END), 
							sum(CASE WHEN v_historique_ecritures_1.mois_comptable = [VIEW.AM0] THEN [VIEW.DATA_FIELD] ELSE 0 END), 
							sum(CASE WHEN v_historique_ecritures_1.mois_comptable = [VIEW.AM0] THEN [VIEW.DATA_FIELD] ELSE 0 END) -
								sum(CASE WHEN v_historique_ecritures_1.mois_comptable = [VIEW.AM1] THEN [VIEW.DATA_FIELD] ELSE 0 END),
							sum(CASE WHEN v_historique_ecritures_1.mois_comptable BETWEEN [VIEW.X2D] AND [VIEW.X2F] THEN [VIEW.DATA_FIELD] ELSE 0 END), 
							sum(CASE WHEN v_historique_ecritures_1.mois_comptable BETWEEN [VIEW.X1D] AND [VIEW.X1F] THEN [VIEW.DATA_FIELD] ELSE 0 END), 
							sum(CASE WHEN v_historique_ecritures_1.mois_comptable BETWEEN [VIEW.X0D] AND [VIEW.X0F] THEN [VIEW.DATA_FIELD] ELSE 0 END), 
							sum(CASE WHEN v_historique_ecritures_1.mois_comptable BETWEEN [VIEW.X0D] AND [VIEW.X0F] THEN [VIEW.DATA_FIELD] ELSE 0 END) -
								sum(CASE WHEN v_historique_ecritures_1.mois_comptable BETWEEN [VIEW.X1D] AND [VIEW.X1F] THEN [VIEW.DATA_FIELD] ELSE 0 END), 
							MAX(fin_exercice), MAX(ajustement)
						
					FROM compta.#V_HISTORIQUE_ECRITURES_X# 
					WHERE v_historique_ecritures_1.arbre_classe_2_id &lt;&gt; 0 AND
						(v_historique_ecritures_1.mois_comptable BETWEEN [VIEW.X0D] AND [VIEW.X0F] 
							OR v_historique_ecritures_1.mois_comptable BETWEEN [VIEW.X1D] AND [VIEW.X1F] 
							OR v_historique_ecritures_1.mois_comptable BETWEEN [VIEW.X2D] AND [VIEW.X2F]) 
							[VIEW.ECRITURES_SELECT]

					GROUP BY arbre_classe_1_id, arbre_classe_1_code, 
							arbre_classe_2_id, arbre_classe_2_code, arbre_classe_2_texte
					)
					
					UNION ALL
					
					(SELECT 
							'-9999999', arbre_classe_1_id, arbre_classe_1_code, arbre_classe_2_id, arbre_classe_2_code,
							arbre_classe_3_id, arbre_classe_3_code, 0, '', 
							0, '',  0, '', 
							0, '', 
							arbre_classe_3_id, arbre_classe_3_code, arbre_classe_3_texte,
							3, 
						
							sum(CASE WHEN v_historique_ecritures_1.mois_comptable = [VIEW.AM2] THEN [VIEW.DATA_FIELD] ELSE 0 END), 
							sum(CASE WHEN v_historique_ecritures_1.mois_comptable = [VIEW.AM1] THEN [VIEW.DATA_FIELD] ELSE 0 END), 
							sum(CASE WHEN v_historique_ecritures_1.mois_comptable = [VIEW.AM0] THEN [VIEW.DATA_FIELD] ELSE 0 END), 
							sum(CASE WHEN v_historique_ecritures_1.mois_comptable = [VIEW.AM0] THEN [VIEW.DATA_FIELD] ELSE 0 END) -
								sum(CASE WHEN v_historique_ecritures_1.mois_comptable = [VIEW.AM1] THEN [VIEW.DATA_FIELD] ELSE 0 END),
							sum(CASE WHEN v_historique_ecritures_1.mois_comptable BETWEEN [VIEW.X2D] AND [VIEW.X2F] THEN [VIEW.DATA_FIELD] ELSE 0 END), 
							sum(CASE WHEN v_historique_ecritures_1.mois_comptable BETWEEN [VIEW.X1D] AND [VIEW.X1F] THEN [VIEW.DATA_FIELD] ELSE 0 END), 
							sum(CASE WHEN v_historique_ecritures_1.mois_comptable BETWEEN [VIEW.X0D] AND [VIEW.X0F] THEN [VIEW.DATA_FIELD] ELSE 0 END), 
							sum(CASE WHEN v_historique_ecritures_1.mois_comptable BETWEEN [VIEW.X0D] AND [VIEW.X0F] THEN [VIEW.DATA_FIELD] ELSE 0 END) -
								sum(CASE WHEN v_historique_ecritures_1.mois_comptable BETWEEN [VIEW.X1D] AND [VIEW.X1F] THEN [VIEW.DATA_FIELD] ELSE 0 END), 
							MAX(fin_exercice), MAX(ajustement)
						
					FROM compta.#V_HISTORIQUE_ECRITURES_X# 
					WHERE v_historique_ecritures_1.arbre_classe_3_id &lt;&gt; 0 AND
						(v_historique_ecritures_1.mois_comptable BETWEEN [VIEW.X0D] AND [VIEW.X0F] 
							OR v_historique_ecritures_1.mois_comptable BETWEEN [VIEW.X1D] AND [VIEW.X1F] 
							OR v_historique_ecritures_1.mois_comptable BETWEEN [VIEW.X2D] AND [VIEW.X2F]) 
							[VIEW.ECRITURES_SELECT]

					GROUP BY arbre_classe_1_id, arbre_classe_1_code, arbre_classe_2_id, arbre_classe_2_code,
							arbre_classe_3_id, arbre_classe_3_code, arbre_classe_3_texte
					)
					
					UNION ALL
					
					(SELECT 
							'-9999999', arbre_classe_1_id, arbre_classe_1_code, arbre_classe_2_id, arbre_classe_2_code,
							arbre_classe_3_id, arbre_classe_3_code, arbre_classe_4_id, arbre_classe_4_code,
							0, '',  0, '', 
							0, '', 
							arbre_classe_4_id, arbre_classe_4_code, arbre_classe_4_texte,
							4, 
						
							sum(CASE WHEN v_historique_ecritures_1.mois_comptable = [VIEW.AM2] THEN [VIEW.DATA_FIELD] ELSE 0 END), 
							sum(CASE WHEN v_historique_ecritures_1.mois_comptable = [VIEW.AM1] THEN [VIEW.DATA_FIELD] ELSE 0 END), 
							sum(CASE WHEN v_historique_ecritures_1.mois_comptable = [VIEW.AM0] THEN [VIEW.DATA_FIELD] ELSE 0 END), 
							sum(CASE WHEN v_historique_ecritures_1.mois_comptable = [VIEW.AM0] THEN [VIEW.DATA_FIELD] ELSE 0 END) -
								sum(CASE WHEN v_historique_ecritures_1.mois_comptable = [VIEW.AM1] THEN [VIEW.DATA_FIELD] ELSE 0 END),
							sum(CASE WHEN v_historique_ecritures_1.mois_comptable BETWEEN [VIEW.X2D] AND [VIEW.X2F] THEN [VIEW.DATA_FIELD] ELSE 0 END), 
							sum(CASE WHEN v_historique_ecritures_1.mois_comptable BETWEEN [VIEW.X1D] AND [VIEW.X1F] THEN [VIEW.DATA_FIELD] ELSE 0 END), 
							sum(CASE WHEN v_historique_ecritures_1.mois_comptable BETWEEN [VIEW.X0D] AND [VIEW.X0F] THEN [VIEW.DATA_FIELD] ELSE 0 END), 
							sum(CASE WHEN v_historique_ecritures_1.mois_comptable BETWEEN [VIEW.X0D] AND [VIEW.X0F] THEN [VIEW.DATA_FIELD] ELSE 0 END) -
								sum(CASE WHEN v_historique_ecritures_1.mois_comptable BETWEEN [VIEW.X1D] AND [VIEW.X1F] THEN [VIEW.DATA_FIELD] ELSE 0 END), 
							MAX(fin_exercice), MAX(ajustement)
						
					FROM compta.#V_HISTORIQUE_ECRITURES_X# 
					WHERE v_historique_ecritures_1.arbre_classe_4_id &lt;&gt; 0 AND
						(v_historique_ecritures_1.mois_comptable BETWEEN [VIEW.X0D] AND [VIEW.X0F] 
							OR v_historique_ecritures_1.mois_comptable BETWEEN [VIEW.X1D] AND [VIEW.X1F] 
							OR v_historique_ecritures_1.mois_comptable BETWEEN [VIEW.X2D] AND [VIEW.X2F]) 
							[VIEW.ECRITURES_SELECT]

					GROUP BY arbre_classe_1_id, arbre_classe_1_code, arbre_classe_2_id, arbre_classe_2_code,
							arbre_classe_3_id, arbre_classe_3_code, 
							arbre_classe_4_id, arbre_classe_4_code, arbre_classe_4_texte
					)
					
					UNION ALL
					
					(SELECT 
							'-9999999', arbre_classe_1_id, arbre_classe_1_code, arbre_classe_2_id, arbre_classe_2_code,
							arbre_classe_3_id, arbre_classe_3_code, arbre_classe_4_id, arbre_classe_4_code,
							arbre_classe_5_id, arbre_classe_5_code, 0, '', 
							0, '', 
							arbre_classe_5_id, arbre_classe_5_code, arbre_classe_5_texte,
							5, 
						
							sum(CASE WHEN v_historique_ecritures_1.mois_comptable = [VIEW.AM2] THEN [VIEW.DATA_FIELD] ELSE 0 END), 
							sum(CASE WHEN v_historique_ecritures_1.mois_comptable = [VIEW.AM1] THEN [VIEW.DATA_FIELD] ELSE 0 END), 
							sum(CASE WHEN v_historique_ecritures_1.mois_comptable = [VIEW.AM0] THEN [VIEW.DATA_FIELD] ELSE 0 END), 
							sum(CASE WHEN v_historique_ecritures_1.mois_comptable = [VIEW.AM0] THEN [VIEW.DATA_FIELD] ELSE 0 END) -
								sum(CASE WHEN v_historique_ecritures_1.mois_comptable = [VIEW.AM1] THEN [VIEW.DATA_FIELD] ELSE 0 END),
							sum(CASE WHEN v_historique_ecritures_1.mois_comptable BETWEEN [VIEW.X2D] AND [VIEW.X2F] THEN [VIEW.DATA_FIELD] ELSE 0 END), 
							sum(CASE WHEN v_historique_ecritures_1.mois_comptable BETWEEN [VIEW.X1D] AND [VIEW.X1F] THEN [VIEW.DATA_FIELD] ELSE 0 END), 
							sum(CASE WHEN v_historique_ecritures_1.mois_comptable BETWEEN [VIEW.X0D] AND [VIEW.X0F] THEN [VIEW.DATA_FIELD] ELSE 0 END), 
							sum(CASE WHEN v_historique_ecritures_1.mois_comptable BETWEEN [VIEW.X0D] AND [VIEW.X0F] THEN [VIEW.DATA_FIELD] ELSE 0 END) -
								sum(CASE WHEN v_historique_ecritures_1.mois_comptable BETWEEN [VIEW.X1D] AND [VIEW.X1F] THEN [VIEW.DATA_FIELD] ELSE 0 END), 
							MAX(fin_exercice), MAX(ajustement)
						
					FROM compta.#V_HISTORIQUE_ECRITURES_X# 
					WHERE v_historique_ecritures_1.arbre_classe_5_id &lt;&gt; 0 AND
						(v_historique_ecritures_1.mois_comptable BETWEEN [VIEW.X0D] AND [VIEW.X0F] 
							OR v_historique_ecritures_1.mois_comptable BETWEEN [VIEW.X1D] AND [VIEW.X1F] 
							OR v_historique_ecritures_1.mois_comptable BETWEEN [VIEW.X2D] AND [VIEW.X2F]) 
							[VIEW.ECRITURES_SELECT]

					GROUP BY arbre_classe_1_id, arbre_classe_1_code, arbre_classe_2_id, arbre_classe_2_code,
							arbre_classe_3_id, arbre_classe_3_code, arbre_classe_4_id, arbre_classe_4_code,
							arbre_classe_5_id, arbre_classe_5_code, arbre_classe_5_texte
					)
					
					UNION ALL
					
					(SELECT 
							'-9999999', arbre_classe_1_id, arbre_classe_1_code, arbre_classe_2_id, arbre_classe_2_code,
							arbre_classe_3_id, arbre_classe_3_code, arbre_classe_4_id, arbre_classe_4_code,
							arbre_classe_5_id, arbre_classe_5_code, arbre_classe_6_id, arbre_classe_6_code,
							0, '', 
							arbre_classe_6_id, arbre_classe_6_code, arbre_classe_6_texte,
							6, 
						
							sum(CASE WHEN v_historique_ecritures_1.mois_comptable = [VIEW.AM2] THEN [VIEW.DATA_FIELD] ELSE 0 END), 
							sum(CASE WHEN v_historique_ecritures_1.mois_comptable = [VIEW.AM1] THEN [VIEW.DATA_FIELD] ELSE 0 END), 
							sum(CASE WHEN v_historique_ecritures_1.mois_comptable = [VIEW.AM0] THEN [VIEW.DATA_FIELD] ELSE 0 END), 
							sum(CASE WHEN v_historique_ecritures_1.mois_comptable = [VIEW.AM0] THEN [VIEW.DATA_FIELD] ELSE 0 END) -
								sum(CASE WHEN v_historique_ecritures_1.mois_comptable = [VIEW.AM1] THEN [VIEW.DATA_FIELD] ELSE 0 END),
							sum(CASE WHEN v_historique_ecritures_1.mois_comptable BETWEEN [VIEW.X2D] AND [VIEW.X2F] THEN [VIEW.DATA_FIELD] ELSE 0 END), 
							sum(CASE WHEN v_historique_ecritures_1.mois_comptable BETWEEN [VIEW.X1D] AND [VIEW.X1F] THEN [VIEW.DATA_FIELD] ELSE 0 END), 
							sum(CASE WHEN v_historique_ecritures_1.mois_comptable BETWEEN [VIEW.X0D] AND [VIEW.X0F] THEN [VIEW.DATA_FIELD] ELSE 0 END), 
							sum(CASE WHEN v_historique_ecritures_1.mois_comptable BETWEEN [VIEW.X0D] AND [VIEW.X0F] THEN [VIEW.DATA_FIELD] ELSE 0 END) -
								sum(CASE WHEN v_historique_ecritures_1.mois_comptable BETWEEN [VIEW.X1D] AND [VIEW.X1F] THEN [VIEW.DATA_FIELD] ELSE 0 END), 
							MAX(fin_exercice), MAX(ajustement)
						
					FROM compta.#V_HISTORIQUE_ECRITURES_X# 
					WHERE v_historique_ecritures_1.arbre_classe_6_id &lt;&gt; 0 AND
						(v_historique_ecritures_1.mois_comptable BETWEEN [VIEW.X0D] AND [VIEW.X0F] 
							OR v_historique_ecritures_1.mois_comptable BETWEEN [VIEW.X1D] AND [VIEW.X1F] 
							OR v_historique_ecritures_1.mois_comptable BETWEEN [VIEW.X2D] AND [VIEW.X2F]) 
							[VIEW.ECRITURES_SELECT]

					GROUP BY arbre_classe_1_id, arbre_classe_1_code, arbre_classe_2_id, arbre_classe_2_code,
							arbre_classe_3_id, arbre_classe_3_code, arbre_classe_4_id, arbre_classe_4_code,
							arbre_classe_5_id, arbre_classe_5_code, 
							arbre_classe_6_id, arbre_classe_6_code, arbre_classe_6_texte
					)
					
					UNION ALL
					
					(SELECT 
							'-9999999', arbre_classe_1_id, arbre_classe_1_code, arbre_classe_2_id, arbre_classe_2_code,
							arbre_classe_3_id, arbre_classe_3_code, arbre_classe_4_id, arbre_classe_4_code,
							arbre_classe_5_id, arbre_classe_5_code, arbre_classe_6_id, arbre_classe_6_code,
							arbre_classe_7_id, arbre_classe_7_code, 
							arbre_classe_7_id, arbre_classe_7_code, arbre_classe_7_texte,
							7, 
						
							sum(CASE WHEN v_historique_ecritures_1.mois_comptable = [VIEW.AM2] THEN [VIEW.DATA_FIELD] ELSE 0 END), 
							sum(CASE WHEN v_historique_ecritures_1.mois_comptable = [VIEW.AM1] THEN [VIEW.DATA_FIELD] ELSE 0 END), 
							sum(CASE WHEN v_historique_ecritures_1.mois_comptable = [VIEW.AM0] THEN [VIEW.DATA_FIELD] ELSE 0 END), 
							sum(CASE WHEN v_historique_ecritures_1.mois_comptable = [VIEW.AM0] THEN [VIEW.DATA_FIELD] ELSE 0 END) -
								sum(CASE WHEN v_historique_ecritures_1.mois_comptable = [VIEW.AM1] THEN [VIEW.DATA_FIELD] ELSE 0 END),
							sum(CASE WHEN v_historique_ecritures_1.mois_comptable BETWEEN [VIEW.X2D] AND [VIEW.X2F] THEN [VIEW.DATA_FIELD] ELSE 0 END), 
							sum(CASE WHEN v_historique_ecritures_1.mois_comptable BETWEEN [VIEW.X1D] AND [VIEW.X1F] THEN [VIEW.DATA_FIELD] ELSE 0 END), 
							sum(CASE WHEN v_historique_ecritures_1.mois_comptable BETWEEN [VIEW.X0D] AND [VIEW.X0F] THEN [VIEW.DATA_FIELD] ELSE 0 END), 
							sum(CASE WHEN v_historique_ecritures_1.mois_comptable BETWEEN [VIEW.X0D] AND [VIEW.X0F] THEN [VIEW.DATA_FIELD] ELSE 0 END) -
								sum(CASE WHEN v_historique_ecritures_1.mois_comptable BETWEEN [VIEW.X1D] AND [VIEW.X1F] THEN [VIEW.DATA_FIELD] ELSE 0 END), 
							MAX(fin_exercice), MAX(ajustement)
						
					FROM compta.#V_HISTORIQUE_ECRITURES_X# 
					WHERE v_historique_ecritures_1.arbre_classe_7_id &lt;&gt; 0 AND
						(v_historique_ecritures_1.mois_comptable BETWEEN [VIEW.X0D] AND [VIEW.X0F] 
							OR v_historique_ecritures_1.mois_comptable BETWEEN [VIEW.X1D] AND [VIEW.X1F] 
							OR v_historique_ecritures_1.mois_comptable BETWEEN [VIEW.X2D] AND [VIEW.X2F]) 
							[VIEW.ECRITURES_SELECT]

					GROUP BY arbre_classe_1_id, arbre_classe_1_code, arbre_classe_2_id, arbre_classe_2_code,
							arbre_classe_3_id, arbre_classe_3_code, arbre_classe_4_id, arbre_classe_4_code,
							arbre_classe_5_id, arbre_classe_5_code, arbre_classe_6_id, arbre_classe_6_code,
							arbre_classe_7_id, arbre_classe_7_code, arbre_classe_7_texte
					)
					
					UNION ALL
					
					(SELECT 
 
						'-9999999', 0, '',  0, '',  0, '',  0, '',  0, '',  0, '',  0, '',  
						-9999999, 'Total', 'Total',
						9, 
						
						sum(CASE WHEN v_historique_ecritures_1.mois_comptable = [VIEW.AM2] THEN [VIEW.DATA_FIELD] ELSE 0 END), 
						sum(CASE WHEN v_historique_ecritures_1.mois_comptable = [VIEW.AM1] THEN [VIEW.DATA_FIELD] ELSE 0 END), 
						sum(CASE WHEN v_historique_ecritures_1.mois_comptable = [VIEW.AM0] THEN [VIEW.DATA_FIELD] ELSE 0 END), 
						sum(CASE WHEN v_historique_ecritures_1.mois_comptable = [VIEW.AM0] THEN [VIEW.DATA_FIELD] ELSE 0 END) -
							sum(CASE WHEN v_historique_ecritures_1.mois_comptable = [VIEW.AM1] THEN [VIEW.DATA_FIELD] ELSE 0 END),
						sum(CASE WHEN v_historique_ecritures_1.mois_comptable BETWEEN [VIEW.X2D] AND [VIEW.X2F] THEN [VIEW.DATA_FIELD] ELSE 0 END), 
						sum(CASE WHEN v_historique_ecritures_1.mois_comptable BETWEEN [VIEW.X1D] AND [VIEW.X1F] THEN [VIEW.DATA_FIELD] ELSE 0 END), 
						sum(CASE WHEN v_historique_ecritures_1.mois_comptable BETWEEN [VIEW.X0D] AND [VIEW.X0F] THEN [VIEW.DATA_FIELD] ELSE 0 END), 
						sum(CASE WHEN v_historique_ecritures_1.mois_comptable BETWEEN [VIEW.X0D] AND [VIEW.X0F] THEN [VIEW.DATA_FIELD] ELSE 0 END) -
							sum(CASE WHEN v_historique_ecritures_1.mois_comptable BETWEEN [VIEW.X1D] AND [VIEW.X1F] THEN [VIEW.DATA_FIELD] ELSE 0 END), 
						MAX(fin_exercice), MAX(ajustement)
						
					FROM compta.#V_HISTORIQUE_ECRITURES_X# 
					WHERE 
						(v_historique_ecritures_1.mois_comptable BETWEEN [VIEW.X0D] AND [VIEW.X0F] 
							OR v_historique_ecritures_1.mois_comptable BETWEEN [VIEW.X1D] AND [VIEW.X1F] 
							OR v_historique_ecritures_1.mois_comptable BETWEEN [VIEW.X2D] AND [VIEW.X2F]) 
							[VIEW.ECRITURES_SELECT]


					)


					ORDER BY 2, 4, 6, 8, 10, 12, 14  ">
				<FIELDS>
					<FIELD name="TABD"/>
					<FIELD name="OID1"/>
					<FIELD name="COD1"/>
					<FIELD name="OID2"/>
					<FIELD name="COD2"/>
					<FIELD name="OID3"/>
					<FIELD name="COD3"/>
					<FIELD name="OID4"/>
					<FIELD name="COD4"/>
					<FIELD name="OID5"/>
					<FIELD name="COD5"/>
					<FIELD name="OID6"/>
					<FIELD name="COD6"/>
					<FIELD name="OID7"/>
					<FIELD name="COD7"/>
					<FIELD name="OID"/>
					<FIELD name="COD"/>
					<FIELD name="TXT"/>
					<FIELD name="LVL"/>
					<FIELD name="SOLM2"/>
					<FIELD name="SOLM1"/>
					<FIELD name="SOLM"/>
					<FIELD name="VARM"/>
					<FIELD name="SOLX2"/>
					<FIELD name="SOLX1"/>
					<FIELD name="SOLX"/>
					<FIELD name="VARX"/>
					<FIELD name="Q13"/>
					<FIELD name="QAJ"/>
				</FIELDS>
			</SQL>
		</QUERY>
		<QUERY type="propertiesLink" name="VIEWPROPERTIES" forSelections="false">
			<SQL select="SELECT 'M2', texte_court 
							FROM base.p_calendrier_mois
							WHERE mois = [MOIS] - 200
						UNION
						SELECT 'M1', texte_court 
							FROM base.p_calendrier_mois
							WHERE mois = [MOIS] - 100
						UNION
						SELECT 'M0', texte_court 
							FROM base.p_calendrier_mois
							WHERE mois = [MOIS]
						">
				<FIELDS>
					<FIELD name="name"/>
					<FIELD name="value"/>
				</FIELDS>
			</SQL>
			<SQL select="SELECT 'AM2', mois
							FROM base.p_calendrier_mois
							WHERE mois = [MOIS] - 200
						UNION
						SELECT 'AM1', mois
							FROM base.p_calendrier_mois
							WHERE mois = [MOIS] - 100
						UNION
						SELECT 'AM0', mois
							FROM base.p_calendrier_mois
							WHERE mois = [MOIS]
						">
				<FIELDS>
					<FIELD name="name"/>
					<FIELD name="value"/>
				</FIELDS>
			</SQL>
			<SQL enabled="[TYPEPERIODE!=X::false]" select="SELECT 'X2', exercice_comptable
							FROM base.p_calendrier_mois
							WHERE mois = [MOIS] - 200
						UNION
						SELECT 'X1', exercice_comptable
							FROM base.p_calendrier_mois
							WHERE mois = [MOIS] - 100
						UNION
						SELECT 'X0', exercice_comptable
							FROM base.p_calendrier_mois
							WHERE mois = [MOIS]						
						UNION
						SELECT 'X2D', exercice_mois_comptable_1
							FROM base.p_calendrier_mois
							WHERE mois = [MOIS] - 200
						UNION
						SELECT 'X2F', mois
							FROM base.p_calendrier_mois
							WHERE mois = [MOIS] - 200
						UNION
						SELECT 'X1D', exercice_mois_comptable_1
							FROM base.p_calendrier_mois
							WHERE mois = [MOIS] - 100
						UNION
						SELECT 'X1F', mois
							FROM base.p_calendrier_mois
							WHERE mois = [MOIS] - 100
						UNION
						SELECT 'X0D', exercice_mois_comptable_1
							FROM base.p_calendrier_mois
							WHERE mois = [MOIS]	
						UNION
						SELECT 'X0F', mois
							FROM base.p_calendrier_mois
							WHERE mois = [MOIS]	
						">
				<FIELDS>
					<FIELD name="name"/>
					<FIELD name="value"/>
				</FIELDS>
			</SQL>
			<SQL enabled="[TYPEPERIODE!=A::false]" select="SELECT 'X2', annee
							FROM base.p_calendrier_mois
							WHERE mois = [MOIS] - 200
						UNION
						SELECT 'X1', annee
							FROM base.p_calendrier_mois
							WHERE mois = [MOIS] - 100
						UNION
						SELECT 'X0', annee
							FROM base.p_calendrier_mois
							WHERE mois = [MOIS]
						UNION
						SELECT 'X2D', annee * 100 + 1
							FROM base.p_calendrier_mois
							WHERE mois = [MOIS] - 200
						UNION
						SELECT 'X2F', mois
							FROM base.p_calendrier_mois
							WHERE mois = [MOIS] - 200
						UNION
						SELECT 'X1D', annee * 100 + 1
							FROM base.p_calendrier_mois
							WHERE mois = [MOIS] - 100
						UNION
						SELECT 'X1F', mois
							FROM base.p_calendrier_mois
							WHERE mois = [MOIS] - 100
						UNION
						SELECT 'X0D', annee * 100 + 1
							FROM base.p_calendrier_mois
							WHERE mois = [MOIS]
						UNION
						SELECT 'X0F', mois
							FROM base.p_calendrier_mois
							WHERE mois = [MOIS]
						">
				<FIELDS>
					<FIELD name="name"/>
					<FIELD name="value"/>
				</FIELDS>
			</SQL>
			<SQL enabled="[TYPEPERIODE!=12::false]" select="SELECT 'X2', annee
							FROM base.p_calendrier_mois
							WHERE mois = [MOIS] - 200
						UNION
						SELECT 'X1', annee
							FROM base.p_calendrier_mois
							WHERE mois = [MOIS] - 100
						UNION
						SELECT 'X0', annee
							FROM base.p_calendrier_mois
							WHERE mois = [MOIS]
						UNION
						SELECT 'X2D', to_char(date_debut - interval '11 month','YYYYMM')::numeric
							FROM base.p_calendrier_mois
							WHERE mois = [MOIS] - 200
						UNION
						SELECT 'X2F', mois
							FROM base.p_calendrier_mois
							WHERE mois = [MOIS] - 200
						UNION
						SELECT 'X1D', to_char(date_debut - interval '11 month','YYYYMM')::numeric
							FROM base.p_calendrier_mois
							WHERE mois = [MOIS] - 100
						UNION
						SELECT 'X1F', mois
							FROM base.p_calendrier_mois
							WHERE mois = [MOIS] - 100
						UNION
						SELECT 'X0D', to_char(date_debut - interval '11 month','YYYYMM')::numeric
							FROM base.p_calendrier_mois
							WHERE mois = [MOIS]
						UNION
						SELECT 'X0F', mois
							FROM base.p_calendrier_mois
							WHERE mois = [MOIS]
						">
				<FIELDS>
					<FIELD name="name"/>
					<FIELD name="value"/>
				</FIELDS>
			</SQL>
		</QUERY>
	</QUERIES>
	<CALCFIELDS>
	</CALCFIELDS>
	<PRESENTATION>
		<VIEWLINKS>
             <VIEWLINK label="Evolution Temporelle" shortLabel="Evolution" view="COMPTA000039.XML" enabled="true" rowContext="false"  buttonType="EVOLUTION">
				<ARG name="MOIS" value="return SELECT.TOMOIS;" />
				<ARG name="OPTION_SOLDE" value="return SELECT.OPTION_SOLDE;" />
			</VIEWLINK>
            <VIEWLINK label="Liste des écritures" shortLabel="Ecritures" view="COMPTA000025.XML" componentName="ECRITURES_VIEWLINK">
				<ARG name="MOIS" value="if (COLUMN.NAME == 'SOLM2') {return VIEW.AM2}
										if (COLUMN.NAME == 'SOLM1') {return VIEW.AM1}
										if (COLUMN.NAME == 'SOLM') {return VIEW.AM0}
										if (COLUMN.NAME == 'SOLX2') {return VIEW.X2D}
										if (COLUMN.NAME == 'SOLX1') {return VIEW.X1D}
										if (COLUMN.NAME == 'SOLX') {return VIEW.X0D}
										return VIEW.X0D;
				"/>
				<ARG name="TOMOIS" value="if (COLUMN.NAME == 'SOLM2') {return VIEW.AM2}
										if (COLUMN.NAME == 'SOLM1') {return VIEW.AM1}
										if (COLUMN.NAME == 'SOLM') {return VIEW.AM0}
										if (COLUMN.NAME == 'SOLX2') {return VIEW.X2F}
										if (COLUMN.NAME == 'SOLX1') {return VIEW.X1F}
										if (COLUMN.NAME == 'SOLX') {return VIEW.X0F}
										return VIEW.X0F;
								"/>
				<ARG name="COMPTE_C" value="	if (SELECT.CH == 'C') {
													
													if (ROW.COD.length == 8) {return 'CP' + ROW.OID}
													return 'CL' + ROW.OID
													
												}"/>
				<ARG name="COMPTE_H" value="	if (SELECT.CH == 'H') {
													
													if (ROW.COD.length == 8) {return 'CP' + ROW.OID}
													return 'CL' + ROW.OID
													
												}"/>
			</VIEWLINK>
            
		</VIEWLINKS>
		<ONGLET excelLabel="Comparaison" label="Comparaison">
			<CHARTx title="Comparaison" type="lineChart" sortField="TXT" sortSeq="A" condition="Number(ROW.COD) &gt;= 100" maxItems="5" maxItemsSortOn="SOLX" maxItemsSortSeq="D" serieIsCategory="true">
				<CATEGORY field="TXT" type="Char"/>
				<SERIE field="SOLM01" displayName="VIEW.M1" displayNameCalc="true"/>
				<SERIE field="SOLM02" displayName="VIEW.M2" displayNameCalc="true"/>
				<SERIE field="SOLM04" displayName="VIEW.M3" displayNameCalc="true"/>
				<SERIE field="SOLM04" displayName="VIEW.M4" displayNameCalc="true"/>
				<SERIE field="SOLM05" displayName="VIEW.M5" displayNameCalc="true"/>
				<SERIE field="SOLM06" displayName="VIEW.M6" displayNameCalc="true"/>
				<SERIE field="SOLM07" displayName="VIEW.M7" displayNameCalc="true"/>
				<SERIE field="SOLM08" displayName="VIEW.M8" displayNameCalc="true"/>
				<SERIE field="SOLM09" displayName="VIEW.M9" displayNameCalc="true"/>
				<SERIE field="SOLM10" displayName="VIEW.M10" displayNameCalc="true"/>
				<SERIE field="SOLM11" displayName="VIEW.M11" displayNameCalc="true"/>
				<SERIE field="SOLM12" displayName="VIEW.M12" displayNameCalc="true"/>
			</CHARTx>
			<DATAGRID title="" total="true" sortable="false" tree="true" treeDefaultOpenLevel="1" treeLevelField="LVL" headerHeight="36" variableRowHeight="true" totalRowInRows="= ROW.OID == '-9999999'">
				<ROWSTYLE name="fontSize" value="10"/>
				<ROWSTYLE name="backgroundColor" value="0xFFD393" condition="ROW.COD.length == 1 "/>
				<ROWSTYLE name="fontWeight" value="bold" condition="ROW.COD.length &lt;= 4"/>
				<ROWSTYLEx name="borderSides" value="top bottom" condition="ROW.COD.length == 1"/>
				<ROWSTYLEx name="borderStyle" value="solid" condition="ROW.COD.length == 1"/>
				<ROWSTYLEx name="borderThickness" value="2" condition="ROW.COD.length == 1"/>
				<ROWSTYLEx name="rowHeight" value="36" condition="ROW.COD.length == 1"/>
				<ROWSTYLEx name="rowHeight" value="24" condition="ROW.COD.length == 2"/>
				<ROWSTYLEx name="rowHeight" value="24" condition="ROW.COD.length == 3"/>
				<ROWSTYLE name="fontSize" value="11" condition="ROW.COD.length  &lt;= 2"/>
				<COLUMN dataField="LVL" type="Number" headerText="lvl" width="40" visible="false"/>
				<COLUMN dataField="OID1" type="Char" visible="false"/>
				<COLUMN dataField="OID2" type="Char" visible="false"/>
				<COLUMN dataField="OID3" type="Char" visible="false"/>
				<COLUMN dataField="OID4" type="Char" visible="false"/>
				<COLUMN dataField="OID5" type="Char" visible="false"/>
				<COLUMN dataField="OID6" type="Char" visible="false"/>
				<COLUMN dataField="OID7" type="Char" visible="false"/>
				<COLUMN dataField="COD1" type="Char" visible="false"/>
				<COLUMN dataField="COD2" type="Char" visible="false"/>
				<COLUMN dataField="COD3" type="Char" visible="false"/>
				<COLUMN dataField="COD4" type="Char" visible="false"/>
				<COLUMN dataField="COD5" type="Char" visible="false"/>
				<COLUMN dataField="COD6" type="Char" visible="false"/>
				<COLUMN dataField="COD7" type="Char" visible="false"/>
				<COLUMN dataField="OID" type="Char" visible="false"/>
				<COLUMN dataField="COD" type="Char" width="120" visible="true" headerText="Compte" totalFunction="text" treeLevelPad="10" totalComplement="">
					<CELLSTYLEx name="paddingLeft" value="10" condition="ROW.LVL == '1'"/>
					<CELLSTYLEx name="paddingLeft" value="20" condition="ROW.LVL == '2'"/>
					<CELLSTYLEx name="paddingLeft" value="30" condition="ROW.LVL == '3'"/>
					<CELLSTYLEx name="paddingLeft" value="40" condition="ROW.LVL == '4'"/>
					<CELLSTYLEx name="paddingLeft" value="50" condition="ROW.LVL == '5'"/>
					<CELLSTYLEx name="paddingLeft" value="60" condition="ROW.LVL == '6'"/>
					<CELLSTYLEx name="paddingLeft" value="70" condition="ROW.LVL == '7'"/>
				</COLUMN>
				<COLUMN dataField="TXT" type="Char" minWidth="150" visible="true" headerText="Libellé" totalFunction="text" totalComplement="TOTAL">
					<CELLSTYLEx name="cellIndicator" value="circle, 5, right top, 0xFF6600" condition="ROW.QAJ == '1' || ROW.QAJ == '2'"/>
					<CELLSTYLEx name="paddingLeft" value="10" condition="ROW.LVL == '1'"/>
					<CELLSTYLEx name="paddingLeft" value="20" condition="ROW.LVL == '2'"/>
					<CELLSTYLEx name="paddingLeft" value="30" condition="ROW.LVL == '3'"/>
					<CELLSTYLEx name="paddingLeft" value="40" condition="ROW.LVL == '4'"/>
					<CELLSTYLEx name="paddingLeft" value="50" condition="ROW.LVL == '5'"/>
					<CELLSTYLEx name="paddingLeft" value="60" condition="ROW.LVL == '6'"/>
					<CELLSTYLEx name="paddingLeft" value="70" condition="ROW.LVL == '7'"/>
				</COLUMN>
				<COLUMN dataField="SOLM2" type="Number" outputFormat="#" width="80" fixed="false" headerText="VIEW.M2" headerTextCalc="true" align="right" selectable="true" totalFunction="sum" totalComplement=""/>
				<COLUMN dataField="SOLM1" type="Number" outputFormat="#" width="80" headerText="VIEW.M1" headerTextCalc="true" align="right" selectable="true" fixed="false" totalFunction="sum" totalComplement=""/>
				<COLUMN dataField="SOLM" type="Number" outputFormat="#" width="80" fixed="false" headerText="VIEW.M0" headerTextCalc="true" align="right" selectable="true" totalFunction="sum" totalComplement=""/>
				<COLUMN dataField="VARM" type="Number" outputFormat="#" width="80" fixed="false" headerText="'Var ' + VIEW.M0 + '/' + VIEW.M1" headerTextCalc="true" align="right" totalFunction="" totalComplement="">
				</COLUMN>
				<COLUMN dataField="SOLX2" type="Number" outputFormat="#" width="80" fixed="false" headerText="VIEW.X2" headerTextCalc="true" align="right" selectable="true" totalFunction="sum" totalComplement=""/>
				<COLUMN dataField="SOLX1" type="Number" outputFormat="#" width="80" fixed="false" headerText="VIEW.X1" headerTextCalc="true" align="right" selectable="true" totalFunction="sum" totalComplement=""/>
				<COLUMN dataField="SOLX" type="Number" outputFormat="#" width="80" fixed="false" headerText="VIEW.X0" headerTextCalc="true" align="right" selectable="true" totalFunction="sum" totalComplement=""/>
				<COLUMN dataField="VARX" type="Number" outputFormat="#" width="80" fixed="false" headerText="'Var ' + VIEW.X0 + '/' + VIEW.X1" headerTextCalc="true" align="right" totalFunction="" totalComplement="">
				</COLUMN>
				<COLUMN dataField="VARXP" type="Number" outputFormat="#%" width="70" fixed="false" headerText="'% ' + VIEW.X0 + '/' + VIEW.X1" headerTextCalc="true" align="right" totalFunction="" totalComplement="" calc="true">
					<CALC dataField="VARX"/>
					<CALC dataField="SOLX1" operator="/"/>
					<CALC dataField="*constant" value="100" operator="*"/>
				</COLUMN>
				<COLUMN dataField="TREESORTKEY" type="Char" width="200" fixed="false" visible="true"/>
				<COLUMN dataField="QAJ" type="Char" visible="false"/>
				<COLUMN dataField="Q13" type="Char" visible="false"/>
			</DATAGRID>
		</ONGLET>
	</PRESENTATION>
</VUE>
