<?xml version="1.0" encoding="ISO-8859-1"?>
<VUE name="COMPTA000038" label="Analyse Banque" title="= 'Comptabilité ' + SELECT.CH_LABEL + '. Banque '  + ' (' + SELECT.MOIS_LABEL + ' - ' + SELECT.TOMOIS_LABEL + ')'" database="iCTI" swf="*CTI_view1" globals="COMPTA_globals.XML" dboptimizer="COMPTA_dboptimizer.XML" componentsFile="COMPTA_components.XML" softCode="iCTI_compta" helpFile="iCTI_COMPTA_COMPTA000038.HTML">
	<VIEWPROPERTIES>
		<PROPERTY name="ECRITURES_SELECT" value="[EVAL 
							$select = '';
							
							$select = $select . &quot;AND v_historique_ecritures_1.clinique_honoraire = '[CH]' &quot; ;

							

							if ('[CH]' == 'C' &amp; '[COMPTE_C]' != '-1') {
								if (substr('[COMPTE_C]',0,2) == 'LI') {
									$select = $select . ' AND v_historique_ecritures_1.compte_id IN (SELECT to_id FROM compta.t_listes_contenu WHERE liste_id = ' . substr('[COMPTE_C]',2) . ')';
								}
								if (substr('[COMPTE_C]',0,2) == 'SL') {
									$select = $select . ' AND v_historique_ecritures_1.compte_id NOT IN (SELECT to_id FROM compta.t_listes_contenu WHERE liste_id = ' . substr('[COMPTE_C]',2) . ')';
								}
								if ('[COMPTE_C]' == 'SAISIECODE') {
									$select = $select . &quot; AND v_historique_ecritures_1.compte_id IN (SELECT oid FROM compta.t_comptes WHERE &quot; . sql_codes_list_a('[COMPTE_C_CODES]', 'numero') . &quot;)&quot;; 
								}
								if (substr('[COMPTE_C]',0,2) == 'CP') {
									$select = $select . ' AND v_historique_ecritures_1.compte_id = ' . substr('[COMPTE_C]',2); 
								}
								if (substr('[COMPTE_C]',0,2) == 'CL') {
									$select = $select . ' AND (';
									$select = $select . ' v_historique_ecritures_1.classe_1_id = ' . substr('[COMPTE_C]',2); 
									$select = $select . ' OR ';
									$select = $select . ' v_historique_ecritures_1.classe_2_id = ' . substr('[COMPTE_C]',2); 
									$select = $select . ' OR ';
									$select = $select . ' v_historique_ecritures_1.classe_3_id = ' . substr('[COMPTE_C]',2); 
									$select = $select . ' )';
								}
								
								$select = $select . ' ';
							}
												
							if ('[CH]' == 'H' &amp; '[COMPTE_H]' != '-1') {
								if (substr('[COMPTE_H]',0,2) == 'LI') {
									$select = $select. ' AND v_historique_ecritures_1.compte_id IN (SELECT to_id FROM compta.t_listes_contenu WHERE liste_id = ' . substr('[COMPTE_H]',2) . ')';
								}
								if (substr('[COMPTE_H]',0,2) == 'SL') {
									$select = $select. ' AND v_historique_ecritures_1.compte_id NOT IN (SELECT to_id FROM compta.t_listes_contenu WHERE liste_id = ' . substr('[COMPTE_H]',2) . ')';
								}
								if ('[COMPTE_H]' == 'SAISIECODE') {
									$select = $select . &quot; AND v_historique_ecritures_1.compte_id IN (SELECT oid FROM compta.t_comptes WHERE &quot; . sql_codes_list_a('[COMPTE_H_CODES]', 'numero') . &quot;)&quot;; 
								}
								if (substr('[COMPTE_H]',0,2) == 'CP') {
									$select = $select. ' AND v_historique_ecritures_1.compte_id = ' . substr('[COMPTE_H]',2); 
								}
								if (substr('[COMPTE_H]',0,2) == 'CL') {
									$select = $select . ' AND (';
									$select = $select . ' v_historique_ecritures_1.classe_1_id = ' . substr('[COMPTE_H]',2); 
									$select = $select . ' OR ';
									$select = $select . ' v_historique_ecritures_1.classe_2_id = ' . substr('[COMPTE_H]',2); 
									$select = $select . ' OR ';
									$select = $select . ' v_historique_ecritures_1.classe_3_id = ' . substr('[COMPTE_H]',2); 
									$select = $select . ' )';
								}
								$select = $select . ' ';
							}
												
												
													
							return $select;
																
			EVAL]"/>
		<PROPERTY name="COMPTES_SELECT" value="[EVAL 
							$select = '';
							
							$select = $select . &quot; clinique_honoraire = '[CH]' AND banque = '1' &quot; ;


							if ('[CH]' == 'C' &amp; '[COMPTE_C]' != '-1') {
								if (substr('[COMPTE_C]',0,2) == 'LI') {
									$select = $select . ' AND oid IN (SELECT to_id FROM compta.t_listes_contenu WHERE liste_id = ' . substr('[COMPTE_C]',2) . ')';
								}
								if (substr('[COMPTE_C]',0,2) == 'SL') {
									$select = $select . ' AND oid NOT IN (SELECT to_id FROM compta.t_listes_contenu WHERE liste_id = ' . substr('[COMPTE_C]',2) . ')';
								}
								if ('[COMPTE_C]' == 'SAISIECODE') {
									$select = $select . ' AND ' . sql_codes_list_a('[COMPTE_C_CODES]', 'numero') . ' ' ; 
								}
								if (substr('[COMPTE_C]',0,2) == 'CP') {
									$select = $select . ' AND oid = ' . substr('[COMPTE_C]',2); 
								}
								if (substr('[COMPTE_C]',0,2) == 'CL') {
									$select = $select . ' AND (';
									$select = $select . ' classe_1_id = ' . substr('[COMPTE_C]',2); 
									$select = $select . ' OR ';
									$select = $select . ' classe_2_id = ' . substr('[COMPTE_C]',2); 
									$select = $select . ' OR ';
									$select = $select . ' classe_3_id = ' . substr('[COMPTE_C]',2); 
									$select = $select . ' )';
								}
								
								$select = $select . ' ';
							}
												
							if ('[CH]' == 'H' &amp; '[COMPTE_H]' != '-1') {
								if (substr('[COMPTE_H]',0,2) == 'LI') {
									$select = $select. ' AND oid IN (SELECT to_id FROM compta.t_listes_contenu WHERE liste_id = ' . substr('[COMPTE_H]',2) . ')';
								}
								if (substr('[COMPTE_H]',0,2) == 'SL') {
									$select = $select. ' AND oid NOT IN (SELECT to_id FROM compta.t_listes_contenu WHERE liste_id = ' . substr('[COMPTE_H]',2) . ')';
								}
								if ('[COMPTE_H]' == 'SAISIECODE') {
									$select = $select . ' AND ' . sql_codes_list_a('[COMPTE_H_CODES]', 'numero') . ' ' ; 
								}
								if (substr('[COMPTE_H]',0,2) == 'CP') {
									$select = $select. ' AND oid = ' . substr('[COMPTE_H]',2); 
								}
								if (substr('[COMPTE_H]',0,2) == 'CL') {
									$select = $select . ' AND (';
									$select = $select . ' classe_1_id = ' . substr('[COMPTE_H]',2); 
									$select = $select . ' OR ';
									$select = $select . ' classe_2_id = ' . substr('[COMPTE_H]',2); 
									$select = $select . ' OR ';
									$select = $select . ' classe_3_id = ' . substr('[COMPTE_H]',2); 
									$select = $select . ' )';
								}
								$select = $select . ' ';
							}
												
												
													
							return $select;
																
			EVAL]"/>
		<PROPERTY name="GROUPBY_FIELDS" value="[EVAL 
						
							if ('[GROUPBY]' == 'MOI') {return 'mois::text, mois_texte';}
							if ('[GROUPBY]' == 'SEM') {return 'semaine::text, semaine_texte';}
							if ('[GROUPBY]' == 'JOU') {return 'date::text, date_texte';}
							return 'mois, mois_texte';
								
																
			EVAL]"/>
		<PROPERTY name="SOLDE_PROGESSIF_CONDITION" value="[EVAL 
						
							if ('[GROUPBY]' == 'MOI') {return &quot;dernier_jour_mois = '1'&quot;;}
							if ('[GROUPBY]' == 'SEM') {return &quot;dernier_jour_semaine = '1'&quot;;}
							if ('[GROUPBY]' == 'JOU') {return &quot;'1' = '1'&quot;;}
							return &quot;dernier_jour_semaine = '1'&quot;;
								
																
			EVAL]"/>
		<PROPERTY dataLink="VIEWPROPERTIES" nameField="name" valueField="value"/>
	</VIEWPROPERTIES>
	<SELECTIONS label="Paramètres de l'analyse" displayText="= var display:String = '';
	
						
					display = display + '  #B#Compte banque#/B# : ';
					if (SELECT.CH == 'C') {
						if (SELECT.COMPTE_C != 'SAISIECODE') {
							display = display + SELECT.COMPTE_C_LABEL;
						}
						else {
							display = display + SELECT.COMPTE_C_CODES;
						}
					}
					else {
						display = display + '  #B#Compte#/B# : ';
						if (SELECT.COMPTE_H != 'SAISIECODE') {
							display = display + SELECT.COMPTE_H_LABEL;
						}
						else {
							display = display + SELECT.COMPTE_H_CODES;
						}
					}
							
						
					
					return display;
					">
		<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="TOMOIS" label="" UI="combo" width="150" default="*FIRST" globalListProvider="MOIS">
			</FIELD>
		</GROUP>
		<GROUP label="">
			<FIELD name="COMPTE_C" label="Compte" UI="combo" width="300" tree="true" default="-1" globalListProvider="COMPTES_BANQUE_C" showIfNotDefault="true" visible="= SELECT.CH == 'C'">
			</FIELD>
			<FIELD name="COMPTE_C_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.CH == 'C' &amp;&amp; SELECT.COMPTE_C == 'SAISIECODE' "/>
		</GROUP>
		<GROUP label="">
			<FIELD name="COMPTE_H" label="Compte" UI="combo" width="300" tree="true" default="-1" globalListProvider="COMPTES_BANQUE_H" showIfNotDefault="true" visible="= SELECT.CH == 'H'">
			</FIELD>
			<FIELD name="COMPTE_H_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.CH == 'H' &amp;&amp; SELECT.COMPTE_H == 'SAISIECODE' "/>
		</GROUP>
		<GROUP label="">
			<FIELD name="GROUPBY" label="Niveau de détail" UI="combo" width="200" default="MOI">
				<OPTION data="MOI" label="Mois"/>
				<OPTION data="SEM" label="Semaine"/>
				<OPTION data="JOU" label="Jour"/>
			</FIELD>
		</GROUP>
	</SELECTIONS>
	<QUERIES>
		<QUERY>
			<SQL optimizer="V_HISTORIQUE_ECRITURES_X" cacheEnabled="true" select="
					DROP TABLE IF EXISTS temp_table;

					CREATE TEMP TABLE temp_table AS
					SELECT p_calendrier.date, 
						p_calendrier.texte_court as date_texte, 
						p_calendrier.mois, 
						p_calendrier_mois.texte as mois_texte, 
						p_calendrier.dernier_jour as dernier_jour_mois, 
						CASE WHEN jour_semaine = '7' THEN '1' ELSE '' END AS dernier_jour_semaine, 
						p_calendrier.semaine, 
						CASE WHEN jour_semaine = '7' THEN p_calendrier.texte_court ELSE '' END AS semaine_texte, 
						p_calendrier.jour_semaine, 
						CASE WHEN montant_debit IS NOT NULL THEN montant_debit ELSE 0 END AS montant_debit, 
						CASE WHEN montant_credit IS NOT NULL THEN montant_credit ELSE 0 END AS montant_credit, 
						CASE WHEN montant_debit IS NOT NULL THEN montant_debit - montant_credit ELSE 0 END AS montant_solde_debit, 
						0.00 as montant_solde_debit_progressif
					FROM base.p_calendrier_mois, base.p_calendrier
					LEFT JOIN 
					(SELECT date_ecriture, SUM(montant_debit) as montant_debit, SUM(montant_credit) as montant_credit
					FROM compta.v_historique_ecritures_1
					WHERE compte_banque = '1' AND journal_a_nouveaux &lt;&gt; '1' AND ecriture_consolidee &lt;= '0' [VIEW.ECRITURES_SELECT]
					GROUP BY date_ecriture) subview
					ON (date = subview.date_ecriture)
					WHERE 
						p_calendrier_mois.mois = p_calendrier.mois AND p_calendrier.mois &lt;= [TOMOIS]
						AND
						date &lt;= (SELECT max(date_ecriture) FROM compta.p_historique_ecritures WHERE compte_id IN (SELECT oid FROM compta.t_comptes WHERE banque = '1') AND clinique_honoraire = 'C') 
						AND
						date &gt;= (SELECT min(date_ecriture) FROM compta.p_historique_ecritures WHERE compte_id IN (SELECT oid FROM compta.t_comptes WHERE banque = '1') AND clinique_honoraire = 'C') 
						ORDER BY date;

					UPDATE temp_table set montant_solde_debit_progressif = (SELECT SUM(montant_solde_debit) 
						FROM temp_table temp_table_x WHERE temp_table.date &gt;= temp_table_x.date);
						
					UPDATE temp_table set montant_solde_debit_progressif = montant_solde_debit_progressif
						+ (SELECT SUM(solde_initial) FROM compta.t_comptes WHERE [VIEW.COMPTES_SELECT]);
						
					UPDATE temp_table SET semaine_texte = date_texte, dernier_jour_mois = '1', dernier_jour_semaine = '1' WHERE date = (SELECT MAX(date) FROM temp_table);
					
					UPDATE temp_table SET semaine_texte = (SELECT max(semaine_texte) FROM temp_table temp_table_x WHERE temp_table_x.semaine = temp_table.semaine);

					
					(SELECT [VIEW.GROUPBY_FIELDS], MIN(date), MAX(date), SUM(montant_debit), sum(montant_credit), SUM(montant_solde_debit), 
						SUM (CASE WHEN [VIEW.SOLDE_PROGESSIF_CONDITION] THEN montant_solde_debit_progressif ELSE null END)
					FROM temp_table 
					WHERE mois BETWEEN [MOIS] AND [TOMOIS]
					GROUP BY [VIEW.GROUPBY_FIELDS])
					
					UNION ALL
					
					(SELECT '-9999999', 'TOTAL', MIN(date), MAX(date), SUM(montant_debit), sum(montant_credit), SUM(montant_solde_debit), 
						SUM (CASE WHEN date = (SELECT MAX(date) FROM temp_table) THEN montant_solde_debit_progressif ELSE null END)
					FROM temp_table 
					WHERE mois BETWEEN [MOIS] AND [TOMOIS])
					
					
					ORDER BY 1;



					">
				<FIELDS>
					<FIELD name="COD"/>
					<FIELD name="TXT"/>
					<FIELD name="MIN"/>
					<FIELD name="MAX"/>
					<FIELD name="DEB"/>
					<FIELD name="CRE"/>
					<FIELD name="SOL"/>
					<FIELD name="SOLP"/>
				</FIELDS>
			</SQL>
		</QUERY>
		<QUERY type="propertiesLink" name="VIEWPROPERTIES" forSelections="false">
			<SQL>
				<select><![CDATA[
                    SELECT  semaine,min(date),'D' from base.p_calendrier where date BETWEEN [MOIS] AND [TOMOIS] GROUP BY 1  
                    UNION ALL
                    SELECT  semaine,max(date),'F' from base.p_calendrier where date BETWEEN [MOIS] AND [TOMOIS] GROUP BY 1 
                    order by 2 
				]]></select>
				<FIELDS>
					<FIELD name="name"/>
					<FIELD name="value"/>
					<FIELD name="value1"/>
					<FIELD name="value2"/>
				</FIELDS>
			</SQL>
		</QUERY>
	</QUERIES>
	<PRESENTATION>
		<VIEWLINKS>
			<VIEWLINK label="Liste des écritures" shortLabel="Ecritures" view="COMPTA000069.XML" componentName="">
				<ARG name="SENS" value="	if (COLUMN.NAME == 'DEB') {return 'D'}
											if (COLUMN.NAME == 'CRE') {return 'C'}"/>
				<ARG name="MOIS" value="  if (SELECT.GROUPBY == 'MOI' ) {return ROW.COD}
                                          if (SELECT.GROUPBY == 'SEM' ) {return ROW.MIN}
                                          if (SELECT.GROUPBY == 'JOU' ) {return ROW.COD}
								"/>				
                <ARG name="TOMOIS" value="if (SELECT.GROUPBY == 'MOI' ) {return ROW.COD}
                                          if (SELECT.GROUPBY == 'SEM' ) {return ROW.MAX}
                                          if (SELECT.GROUPBY == 'JOU' ) {return ROW.COD}
								"/>
				<ARG name="COMPTE_C" value="	if ((SELECT.CH == 'C') &amp;&amp; (SELECT.COMPTE_C != '-1')) {return SELECT.COMPTE_C}
												if ((SELECT.CH == 'C') &amp;&amp; (SELECT.COMPTE_C == '-1')) {return '-1'}	
                                                    "/>
                <ARG name="COMPTE_C_CODES" value="	if ((SELECT.CH == 'C') &amp;&amp; (SELECT.COMPTE_C == 'SAISIECODE')) {return SELECT.COMPTE_C_CODES}
                                                    "/>
				<ARG name="COMPTE_H" value="	if ((SELECT.CH == 'H') &amp;&amp; (SELECT.COMPTE_H != '-1')) {return SELECT.COMPTE_H}
												if ((SELECT.CH == 'H') &amp;&amp; (SELECT.COMPTE_H == '-1')) {return '-1'}	
                                                    "/>
                <ARG name="COMPTE_H_CODES" value="	if ((SELECT.CH == 'H') &amp;&amp; (SELECT.COMPTE_H == 'SAISIECODE')) {return SELECT.COMPTE_H_CODES}
                                                    "/>
			</VIEWLINK>
		</VIEWLINKS>
		<ONGLET excelLabel="Analyse écritures" label="Analyse écritures">
			<CHART title="Banques" type="mixedChart" subType="overlaid" sortField="COD" sortSeq="A" maxItems="12" maxItemsSortOn="COD" maxItemsSortSeq="D">
				<CATEGORY field="TXT" type="Char"/>
				<SERIE field="SOL" displayName="Ecart" type="column"/>
				<SERIE field="SOLP" displayName="Solde" type="line"/>
			</CHART>
			<DATAGRID title="" total="true" headerHeight="36" sortable="false" totalRowInRows="= ROW.COD == '-9999999'">
				<ROWSTYLE name="fontSize" value="10"/>
				<COLUMN dataField="COD" type="Char" outputFormat="#" width="120" visible="true" headerText="Code" totalFunction="text" totalComplement="">
				</COLUMN>				
                <COLUMN dataField="MIN" type="date" width="120" visible="false" headerText="MIN" totalFunction="text" totalComplement="">
				</COLUMN>				
                <COLUMN dataField="MAX" type="date" width="120" visible="false" headerText="MAX" totalFunction="text" totalComplement="">
				</COLUMN>
				<COLUMN dataField="TXT" type="Char" outputFormat="#" minWidth="60" visible="true" headerText="SELECT.GROUPBY_LABEL" headerTextCalc="true" totalFunction="text" totalComplement="TOTAL">
				</COLUMN>
				<COLUMN dataField="DEB" type="Number" outputFormat="#,00E" width="110" fixed="false" headerText="Encaissements" align="right" totalFunction="sum" totalComplement="" selectable="true"/>
				<COLUMN dataField="CRE" type="Number" outputFormat="#,00E" width="110" fixed="false" headerText="Décaissements" align="right" totalFunction="sum" totalComplement="" selectable="true"/>
				<COLUMN dataField="SOL" type="Number" outputFormat="#,00E" width="110" fixed="false" headerText="Ecart" align="right" totalFunction="sum" totalComplement=""/>
				<COLUMN dataField="SOLP" type="Number" outputFormat="#,00E" width="110" fixed="false" headerText="Solde" align="right" totalFunction="sum" totalComplement=""/>
			</DATAGRID>
		</ONGLET>
	</PRESENTATION>
</VUE>
