<?xml version="1.0" encoding="ISO-8859-1"?>
<VUE 
	name="ACTIS00121" 
	label="Actvité. Récapitulatif Quotidien Ateliers CORWIN" 
	title="= 'Récapitulatif Quotidien Ateliers CORWIN (' + SELECT.PERIODE_LABEL + ' à ' + SELECT.TOPERIODE_LABEL + ')'" 
	database="iCTI"
	swf="*CTI_view1"
	softCode="iCTI_activite"
	globals="ACTI_globals.XML"
	componentsFile="ACTI_components.XML">
		

	<SELECTIONS label="Paramètres de l'analyse"  displayText="">
		<GROUP label="Période">
			<FIELD name="ALIAS_PERIODE" label="" UI="combo" width="220" default="CUM_LAST_MONTH" tree="true" globalListProvider="ALIAS_PERIODE" />
            <FIELD name="PERIODE" label="Période" UI="combo" tree="true" width="200" default="2013-03-01" globalListProvider="DATE_DEBUT" >
			</FIELD>
			<FIELD name="TOPERIODE" label="à" UI="combo" tree="true" width="200" default="2013-03-01" globalListProvider="DATE_FIN" >
			</FIELD>
		</GROUP>
	</SELECTIONS>
	
	<QUERIES>
		<QUERY label="">
			<SQL>
				<select><![CDATA[
			
					-- Extraction des activités
					DROP SEQUENCE IF EXISTS w_PVCOMM_sequence;
					CREATE TEMP SEQUENCE w_PVCOMM_sequence;

					DROP TABLE IF EXISTS w_PVCOMM;
					CREATE TEMP TABLE w_PVCOMM AS
					SELECT 
						*,
						nextval('w_PVCOMM_sequence'::regclass) AS sequence,
						0::bigint AS sequence_jour
					FROM
					(
						SELECT PVCOMM.CODE,
							date(PVCOMM.DATE) AS DATE,
							PVCOMM.HEUREDEB,
							PVCOMM.MINDEB,
							PVCOMM.HEUREFIN,
							PVCOMM.MINFIN,
							CASE 
								WHEN PVCOMM.HEUREDEB < 13 AND PVCOMM.HEUREFIN < 13 THEN '1'
								WHEN PVCOMM.HEUREDEB >= 13 AND PVCOMM.HEUREFIN >= 13 THEN '2'
								ELSE '3' END AS PERIODE_TYPE,
							to_char(PVCOMM.HEUREDEB,'FM00') || 'h' || to_char(PVCOMM.MINDEB,'FM00') || ' à ' || to_char(PVCOMM.HEUREFIN,'FM00') || 'h' || to_char(PVCOMM.MINFIN,'FM00') AS PERIODE,
							C_PVATEL + C_PVACTI AS ACTI_CODE,
							COALESCE(PVACTI.LIBELLE, PVATEL.LIBELLE, (C_PVATEL + C_PVACTI)::text) AS ACTI_LIBELLE,
							0::numeric AS NB_INTERVENANTS_PREVUS,
							NULL::BIGINT[] AS INTERVENANTS_PREVUS,
							0::numeric AS NB_RESIDENTS_PREVUS,
							NULL::BIGINT[] AS RESIDENTS_PREVUS,
							0::numeric AS NB_INTERVENANTS_PRESENTS,
							NULL::BIGINT[] AS INTERVENANTS_PRESENTS,
							0::numeric AS NB_RESIDENTS_PRESENTS,
							NULL::BIGINT[] AS RESIDENTS_PRESENTS,
							''::text AS PYx
						FROM prod_corwin.PVCOMM	
						LEFT JOIN prod_corwin.PVACTI ON C_PVACTI = PVACTI.code
						LEFT JOIN prod_corwin.PVATEL ON C_PVATEL = PVATEL.code
						WHERE C_PVACTI <> 0 AND date(date) BETWEEN '[PERIODE]' AND '[TOPERIODE]'
						ORDER BY date, PVCOMM.CODE
					) subview;



					UPDATE w_PVCOMM
					SET sequence_jour = sequence - sequence_first + 1
					FROM (
						SELECT 
							date,
							periode_type,
							MIN(sequence) AS sequence_first
						FROM w_PVCOMM
						GROUP BY 1,2
					) subview
					WHERE w_PVCOMM.date = subview.date AND w_PVCOMM.periode_type = subview.periode_type;

					
					UPDATE w_PVCOMM
					SET 
						NB_INTERVENANTS_PREVUS = subview.NB_INTERVENANTS,
						INTERVENANTS_PREVUS = subview.INTERVENANTS
					FROM
						(SELECT C_PVCOMM, 
							base.cti_group_array3(C_INTERVEN) AS INTERVENANTS,
							count(DISTINCT C_INTERVEN) AS NB_INTERVENANTS
						FROM prod_corwin.PVCOMM2
						WHERE C_INTERVEN <> 0 AND PREVU = 1
						GROUP BY 1
						) subview
					WHERE w_PVCOMM.CODE = C_PVCOMM;


					UPDATE w_PVCOMM
					SET 
						NB_INTERVENANTS_PRESENTS = subview.NB_INTERVENANTS,
						INTERVENANTS_PRESENTS = subview.INTERVENANTS
					FROM
						(SELECT C_PVCOMM, 
							base.cti_group_array3(C_INTERVEN) AS INTERVENANTS,
							count(DISTINCT C_INTERVEN) AS NB_INTERVENANTS
						FROM prod_corwin.PVCOMM2
						WHERE C_INTERVEN <> 0 AND PRESENT = 1
						GROUP BY 1
						) subview
					WHERE w_PVCOMM.CODE = C_PVCOMM;


					UPDATE w_PVCOMM
					SET 
						NB_RESIDENTS_PREVUS = subview.NB_RESIDENTS,
						RESIDENTS_PREVUS = subview.RESIDENTS
					FROM
						(SELECT C_PVCOMM, 
							base.cti_group_array3(NUMID) AS RESIDENTS,
							count(DISTINCT NUMID) AS NB_RESIDENTS
						FROM prod_corwin.PVCOMM2
						WHERE NUMID <> 0 AND PREVU = 1
						GROUP BY 1
						) subview
					WHERE w_PVCOMM.CODE = C_PVCOMM;


					UPDATE w_PVCOMM
					SET 
						NB_RESIDENTS_PRESENTS = subview.NB_RESIDENTS,
						RESIDENTS_PRESENTS = subview.RESIDENTS
					FROM
						(SELECT C_PVCOMM, 
							base.cti_group_array3(NUMID) AS RESIDENTS,
							count(DISTINCT NUMID) AS NB_RESIDENTS
						FROM prod_corwin.PVCOMM2
						WHERE NUMID <> 0 AND PRESENT = 1
						GROUP BY 1
						) subview
					WHERE w_PVCOMM.CODE = C_PVCOMM;



					UPDATE w_PVCOMM
					SET PYx =
						CASE 
							WHEN PERIODE_TYPE <> '3' AND NB_RESIDENTS_PRESENTS > 1 AND NB_INTERVENANTS_PRESENTS = 1 THEN 'PY0'
							WHEN PERIODE_TYPE <> '3' AND NB_RESIDENTS_PRESENTS > 1 AND NB_INTERVENANTS_PRESENTS > 1 THEN 'PY2'
							WHEN PERIODE_TYPE <> '3' AND NB_RESIDENTS_PRESENTS = 1 AND NB_INTERVENANTS_PRESENTS = 1 THEN 'PY1'
							WHEN PERIODE_TYPE <> '3' AND NB_RESIDENTS_PRESENTS = 1 AND NB_INTERVENANTS_PRESENTS > 1 THEN 'PY3'
							WHEN PERIODE_TYPE = '3' AND NB_RESIDENTS_PRESENTS > 1 AND NB_INTERVENANTS_PRESENTS = 1 THEN 'PY4'
							WHEN PERIODE_TYPE = '3' AND NB_RESIDENTS_PRESENTS > 1 AND NB_INTERVENANTS_PRESENTS > 1 THEN 'PY6'
							WHEN PERIODE_TYPE = '3' AND NB_RESIDENTS_PRESENTS = 1 AND NB_INTERVENANTS_PRESENTS = 1 THEN 'PY5'
							WHEN PERIODE_TYPE = '3' AND NB_RESIDENTS_PRESENTS = 1 AND NB_INTERVENANTS_PRESENTS > 1 THEN 'PY7'
							ELSE '' END;


					DROP TABLE IF EXISTS w_PVCOMM_patients;
					CREATE TEMP TABLE w_PVCOMM_patients AS
					SELECT DATE,
						PERIODE_TYPE,
						COUNT(DISTINCT NUMID) AS NB_RESIDENTS,
						base.cti_group_array3(NOM || ' ' || PRENOM1) AS RESIDENTS
					FROM (
						SELECT DATE, PERIODE_TYPE, CASE WHEN RESIDENT.NOMARI <> '' THEN RESIDENT.NOMARI ELSE RESIDENT.NOM END AS NOM, RESIDENT.PRENOM1, PVCOMM2.NUMID
						FROM w_PVCOMM 
						JOIN prod_corwin.PVCOMM2 ON C_PVCOMM = w_PVCOMM .code
						JOIN prod_corwin.RESIDENT ON PVCOMM2.NUMID = RESIDENT.NUMID
						WHERE PRESENT = 1 AND PVCOMM2.NUMID <> 0
						ORDER BY 1,2,3,4
					) subview
					GROUP BY 1,2;


					DROP TABLE IF EXISTS w_PVCOMM_intervenants;
					CREATE TEMP TABLE w_PVCOMM_intervenants AS
					SELECT DATE,
						PERIODE_TYPE,
						COUNT(DISTINCT C_INTERVEN) AS NB_INTERVENANTS,
						base.cti_group_array3(NOM) AS INTERVENANTS
					FROM (
						SELECT DATE, PERIODE_TYPE, INTERVEN.NOM, INTERVEN.PRENOM, C_INTERVEN
						FROM w_PVCOMM 
						JOIN prod_corwin.PVCOMM2 ON C_PVCOMM = w_PVCOMM .code
						JOIN prod_corwin.INTERVEN ON C_INTERVEN = INTERVEN.CODE
						WHERE PRESENT = 1 AND C_INTERVEN <> 0
						ORDER BY DATE, periode_type, INTERVEN.NOM, INTERVEN.PRENOM
					) subview
					GROUP BY 1,2;

					
					DROP TABLE IF EXISTS w_PVCOMM_activite_patients;
					CREATE TEMP TABLE w_PVCOMM_activite_patients AS
					SELECT DATE,
						PERIODE_TYPE,
						sequence_jour,
						COUNT(DISTINCT NUMID) AS NB_RESIDENTS,
						base.cti_group_array3(NOM || ' ' || PRENOM1) AS RESIDENTS
					FROM (
						SELECT DATE, PERIODE_TYPE, sequence_jour, CASE WHEN RESIDENT.NOMARI <> '' THEN RESIDENT.NOMARI ELSE RESIDENT.NOM END AS NOM, RESIDENT.PRENOM1, PVCOMM2.NUMID
						FROM w_PVCOMM 
						JOIN prod_corwin.PVCOMM2 ON C_PVCOMM = w_PVCOMM .code
						JOIN prod_corwin.RESIDENT ON PVCOMM2.NUMID = RESIDENT.NUMID
						WHERE PRESENT = 1 AND PVCOMM2.NUMID <> 0
						ORDER BY 1,2,3,4,5
					) subview
					GROUP BY 1,2,3;


					DROP TABLE IF EXISTS w_PVCOMM_activite_intervenants;
					CREATE TEMP TABLE w_PVCOMM_activite_intervenants AS
					SELECT DATE,
						PERIODE_TYPE,
						sequence_jour,
						COUNT(DISTINCT C_INTERVEN) AS NB_INTERVENANTS,
						base.cti_group_array3(NOM) AS INTERVENANTS
					FROM (
						SELECT DATE, PERIODE_TYPE, sequence_jour, INTERVEN.NOM, INTERVEN.PRENOM, C_INTERVEN
						FROM w_PVCOMM 
						JOIN prod_corwin.PVCOMM2 ON C_PVCOMM = w_PVCOMM .code
						JOIN prod_corwin.INTERVEN ON C_INTERVEN = INTERVEN.CODE
						WHERE PRESENT = 1 AND C_INTERVEN <> 0
						ORDER BY DATE, periode_type, sequence_jour, INTERVEN.NOM, INTERVEN.PRENOM
					) subview
					GROUP BY 1,2,3;






					DROP TABLE IF EXISTS excel;
					CREATE TEMP TABLE excel (
						excel_date date,
						excel_date_code text,
						excel_date_id bigint,
						excel_date_texte text,
						excel_line bigint, 
						excel_line_code text, 
						excel_excel_line_type text default '', 
						excel_sequence_jour bigint default 0,
						excel_sequence_present bigint default 0,
						column_1_1 text default '', 
						column_1_2 text default '', 
						column_1_3 text default '', 
						column_1_4 text default '', 
						column_1_5 text default '',
						column_2_1 text default '', 
						column_2_2 text default '', 
						column_2_3 text default '', 
						column_2_4 text default '', 
						column_2_5 text default '');


					INSERT INTO excel (excel_date, excel_date_code, excel_date_id, excel_date_texte, excel_line, excel_line_code)
					SELECT
						DATE,
						DATE_code,
						DATE_id,
						DATE_texte,
						excel_line,
						to_char(excel_line,'FM000')
					FROM 
						(SELECT DATE, to_char(DATE,'YYYYMMDD') AS DATE_code, to_char(DATE,'DD/MM/YYYY') AS DATE_texte, to_char(DATE,'YYYYDDD')::bigint AS DATE_id 
						FROM 
						W_PVCOMM
						GROUP BY 1,2,3,4) subview,
						generate_series(1,100) AS excel_line;

						
						
					UPDATE excel
					SET 
						column_1_3 = 'RECAPITULATIF MATIN',
						column_2_3 = 'RECAPITULATIF APRES MIDI'
					WHERE excel_line = 1;


					UPDATE excel
					SET 
						column_1_3 = 'PATIENTS PRESENTS',
						column_1_4 = (SELECT COALESCE(NB_RESIDENTS,0) FROM w_PVCOMM_patients WHERE periode_type = '1' AND DATE = excel_date) ,
						column_1_5 = 'INTERVENANTS PRESENTS',
						column_2_3 = 'PATIENTS PRESENTS',
						column_2_4 = (SELECT COALESCE(NB_RESIDENTS,0) FROM w_PVCOMM_patients WHERE periode_type = '2' AND DATE = excel_date) ,
						column_2_5 = 'INTERVENANTS PRESENTS'
					WHERE excel_line = 2;


					
					UPDATE excel
					SET 
						column_1_3 = (SELECT COALESCE(RESIDENTS[excel_line - 1],'') FROM w_PVCOMM_patients WHERE periode_type = '1' AND DATE = excel_date) ,
						column_1_4 = (SELECT COALESCE(RESIDENTS[excel_line + 16],'') FROM w_PVCOMM_patients WHERE periode_type = '1' AND DATE = excel_date) ,
						column_1_5 = (SELECT COALESCE(INTERVENANTS[excel_line - 1],'') FROM w_PVCOMM_intervenants WHERE periode_type = '1' AND DATE = excel_date),
						column_2_3 = (SELECT COALESCE(RESIDENTS[excel_line - 1],'') FROM w_PVCOMM_patients WHERE periode_type = '2' AND DATE = excel_date) ,
						column_2_4 = (SELECT COALESCE(RESIDENTS[excel_line + 16],'') FROM w_PVCOMM_patients WHERE periode_type = '2' AND DATE = excel_date) ,
						column_2_5 = (SELECT COALESCE(INTERVENANTS[excel_line - 1],'') FROM w_PVCOMM_intervenants WHERE periode_type = '2' AND DATE = excel_date)
					WHERE excel_line BETWEEN 3 AND 19;

					UPDATE excel
					SET 
						column_1_2 = 'MATIN',
						column_2_2 = 'APRES MIDI'
					WHERE excel_line = 3;


					UPDATE excel
					SET 
						column_1_2 = (SELECT COALESCE(NB_INTERVENANTS,0) FROM w_PVCOMM_intervenants WHERE periode_type = '1' AND DATE = excel_date) ,
						column_2_2 = (SELECT COALESCE(NB_INTERVENANTS,0) FROM w_PVCOMM_intervenants WHERE periode_type = '2' AND DATE = excel_date) 
					WHERE excel_line = 4;


					UPDATE excel
					SET 
						excel_excel_line_type = CASE 
								WHEN excel_line = 20 THEN 'H'
								WHEN excel_line = 27 THEN 'H'
								WHEN excel_line = 34 THEN 'H'
								WHEN excel_line = 41 THEN 'H'
								WHEN excel_line = 48 THEN 'H'
								WHEN excel_line = 55 THEN 'H'
								WHEN excel_line BETWEEN 21 AND 25 THEN 'D'
								WHEN excel_line BETWEEN 28 AND 32 THEN 'D'
								WHEN excel_line BETWEEN 35 AND 39 THEN 'D'
								WHEN excel_line BETWEEN 42 AND 46 THEN 'D'
								WHEN excel_line BETWEEN 49 AND 53 THEN 'D'
								WHEN excel_line BETWEEN 56 AND 60 THEN 'D'
								WHEN excel_line = 26 THEN 'F'
								WHEN excel_line = 33 THEN 'F'
								WHEN excel_line = 40 THEN 'F'
								WHEN excel_line = 47 THEN 'F'
								WHEN excel_line = 54 THEN 'F'
								WHEN excel_line = 61 THEN 'F'
								ELSE '' END,
						excel_sequence_jour = CASE 
								WHEN excel_line BETWEEN 20 AND 26 THEN 1
								WHEN excel_line BETWEEN 27 AND 33 THEN 2
								WHEN excel_line BETWEEN 34 AND 40 THEN 3
								WHEN excel_line BETWEEN 41 AND 47 THEN 4
								WHEN excel_line BETWEEN 48 AND 54 THEN 5
								WHEN excel_line BETWEEN 55 AND 61 THEN 6
								ELSE 0 END,
						excel_sequence_present = CASE 
								WHEN excel_line BETWEEN 21 AND 26 THEN excel_line - 20
								WHEN excel_line BETWEEN 28 AND 33 THEN excel_line - 27
								WHEN excel_line BETWEEN 35 AND 40 THEN excel_line - 34
								WHEN excel_line BETWEEN 42 AND 47 THEN excel_line - 41
								WHEN excel_line BETWEEN 49 AND 54 THEN excel_line - 48
								WHEN excel_line BETWEEN 56 AND 61 THEN excel_line - 55
								ELSE 0 END
					WHERE excel_line >= 20;


					UPDATE excel
					SET 
						column_1_3 = (SELECT COALESCE(MAX(ACTI_LIBELLE),'') FROM w_PVCOMM WHERE sequence_jour = excel_sequence_jour AND periode_type = '1' AND DATE = excel_date) ,
						column_2_3 = (SELECT COALESCE(MAX(ACTI_LIBELLE),'') FROM w_PVCOMM WHERE sequence_jour = excel_sequence_jour AND periode_type = '2' AND DATE = excel_date) 
					WHERE excel_excel_line_type = 'H' AND excel_sequence_jour <> 0 ;

					UPDATE excel
					SET 
						column_1_1 = CASE excel_sequence_present WHEN 2 THEN 'Intervenants' WHEN 3 THEN 'Groupe' WHEN 4 THEN 'Individuel' END,
						column_1_2 = CASE excel_sequence_present 
						WHEN 1 THEN 'ATELIER ' || excel_sequence_jour::text 
						WHEN 2 THEN (SELECT COALESCE(NB_INTERVENANTS::text,'') FROM w_PVCOMM_activite_intervenants WHERE sequence_jour = excel_sequence_jour AND periode_type = '1' AND DATE = excel_date) 
						WHEN 3 THEN CASE WHEN (SELECT COALESCE(NB_INTERVENANTS::text,'') FROM w_PVCOMM_activite_intervenants WHERE sequence_jour = excel_sequence_jour AND periode_type = '1' AND DATE = excel_date) > 0 THEN 'OUI' ELSE 'NON' END 
						WHEN 4 THEN CASE WHEN (SELECT COALESCE(NB_INTERVENANTS::text,'') FROM w_PVCOMM_activite_intervenants WHERE sequence_jour = excel_sequence_jour AND periode_type = '1' AND DATE = excel_date) > 0 THEN 'NON' ELSE 'OUI' END 
						END,
						column_1_3 = (SELECT COALESCE(RESIDENTS[excel_sequence_present],'') FROM w_PVCOMM_activite_patients WHERE sequence_jour = excel_sequence_jour AND periode_type = '1' AND DATE = excel_date) ,
						column_1_4 = (SELECT COALESCE(RESIDENTS[excel_sequence_present + 6],'') FROM w_PVCOMM_activite_patients WHERE sequence_jour = excel_sequence_jour AND periode_type = '1' AND DATE = excel_date) ,
						column_1_5 = (SELECT COALESCE(INTERVENANTS[excel_sequence_present],'') FROM w_PVCOMM_activite_intervenants WHERE sequence_jour = excel_sequence_jour AND periode_type = '1' AND DATE = excel_date) 
					WHERE excel_excel_line_type IN ('D','F') AND 
						excel_sequence_jour <> 0 AND 
						excel_sequence_present <> 0 AND
						(SELECT COALESCE(NB_INTERVENANTS::text,'') FROM w_PVCOMM_activite_intervenants WHERE sequence_jour = excel_sequence_jour AND periode_type = '1' AND DATE = excel_date) > 0;
;
						
						
					UPDATE excel
					SET 
						column_2_1 = CASE excel_sequence_present WHEN 2 THEN 'Intervenants' WHEN 3 THEN 'Groupe' WHEN 4 THEN 'Individuel' END,
						column_2_2 = CASE excel_sequence_present
						WHEN 1 THEN 'ATELIER ' || excel_sequence_jour::text 
						WHEN 2 THEN (SELECT COALESCE(NB_INTERVENANTS::text,'') FROM w_PVCOMM_activite_intervenants WHERE sequence_jour = excel_sequence_jour AND periode_type = '2' AND DATE = excel_date) 
						WHEN 3 THEN CASE WHEN (SELECT COALESCE(NB_INTERVENANTS::text,'') FROM w_PVCOMM_activite_intervenants WHERE sequence_jour = excel_sequence_jour AND periode_type = '2' AND DATE = excel_date) > 0 THEN 'OUI' ELSE 'NON' END 
						WHEN 4 THEN CASE WHEN (SELECT COALESCE(NB_INTERVENANTS::text,'') FROM w_PVCOMM_activite_intervenants WHERE sequence_jour = excel_sequence_jour AND periode_type = '2' AND DATE = excel_date) > 0 THEN 'NON' ELSE 'OUI' END 
						END,column_2_3 = (SELECT COALESCE(RESIDENTS[excel_sequence_present],'') FROM w_PVCOMM_activite_patients WHERE sequence_jour = excel_sequence_jour AND periode_type = '2' AND DATE = excel_date) ,
						column_2_4 = (SELECT COALESCE(RESIDENTS[excel_sequence_present + 6],'') FROM w_PVCOMM_activite_patients WHERE sequence_jour = excel_sequence_jour AND periode_type = '2' AND DATE = excel_date) ,
						column_2_5 = (SELECT COALESCE(INTERVENANTS[excel_sequence_present],'') FROM w_PVCOMM_activite_intervenants WHERE sequence_jour = excel_sequence_jour AND periode_type = '2' AND DATE = excel_date) 
					WHERE excel_excel_line_type IN ('D','F') AND 
						excel_sequence_jour <> 0 AND 
						excel_sequence_present <> 0 AND
						(SELECT COALESCE(NB_INTERVENANTS::text,'') FROM w_PVCOMM_activite_intervenants WHERE sequence_jour = excel_sequence_jour AND periode_type = '2' AND DATE = excel_date) > 0;

					UPDATE excel
					SET 
						column_1_2 = (SELECT  COALESCE(MAX(PYx),'') FROM w_PVCOMM WHERE sequence_jour = excel_sequence_jour AND periode_type = '1' AND DATE = excel_date) ,
						column_2_2 = (SELECT  COALESCE(MAX(PYx),'') FROM w_PVCOMM WHERE sequence_jour = excel_sequence_jour AND periode_type = '2' AND DATE = excel_date) 
					WHERE excel_excel_line_type = 'F' AND excel_sequence_jour <> 0 ;


					



					]]></select>
				<FIELDS>
					
				</FIELDS>
			</SQL>
			
			<SQL>
				<select><![CDATA[
			
				
					CTISELECT_TREE
						GROUPBY1{excel_date_id,, excel_date_code,, excel_date_texte}
						GROUPBY1MODE{TAB}
						GROUPBY2{excel.excel_line,, excel_line_code,, excel_line_code}
						OPTIONS{}
						INDICATORS{
							COUNT(*),,
						}	
						INDICATORS_TEXT{
							MAX(column_1_1)::text,,
							MAX(column_1_2)::text,,
							MAX(column_1_3)::text,,
							MAX(column_1_4)::text,,
							MAX(column_1_5)::text,,
							MAX(column_2_1)::text,,
							MAX(column_2_2)::text,,
							MAX(column_2_3)::text,,
							MAX(column_2_4)::text,,
							MAX(column_2_5)::text,,
						}	
					FROM excel
					JOIN (SELECT excel_date, MAX(excel_line) AS excel_line
						FROM excel 
						WHERE column_1_1 <> '' OR column_1_2 <> '' OR column_1_3 <> '' OR column_1_4 <> '' OR column_1_5 <> '' OR
							column_2_1 <> '' OR column_2_2 <> '' OR column_2_3 <> '' OR column_2_4 <> '' OR column_2_5 <> ''
						GROUP BY 1) subview
						ON excel.excel_date = subview.excel_date AND excel.excel_line <= subview.excel_line
							
					AFTER{
						DELETE FROM w_table 
						WHERE (level = 9) OR
							(oidt = -9999999) OR
							(oidt <> -9999999 AND oid2 = -9999999).,
						UPDATE w_table 
							SET textet = substr(textet , 9 , 20),
							labelt = substr(textet , 9 , 20)
					}
					
					

				
				
					]]></select>
				<FIELDS>
					<INSERT name="CTISELECT_TREE_FIELDS"/>
					<FIELD name="COUNT"/>
					<FIELD name="COL11"/>
					<FIELD name="COL12"/>
					<FIELD name="COL13"/>
					<FIELD name="COL14"/>
					<FIELD name="COL15"/>
					<FIELD name="COL21"/>
					<FIELD name="COL22"/>
					<FIELD name="COL23"/>
					<FIELD name="COL24"/>
					<FIELD name="COL25"/>
				</FIELDS>
			</SQL>
	
		</QUERY>
		<QUERY type="propertiesLink" name="VIEWPROPERTIES" forRows="false">
		</QUERY>
	</QUERIES>
	<PRESENTATION>
		
		<ONGLET excelLabel="Ateliers" label="Ateliers" 
			multiTab="true" multiTabBreakField="TABD" multiTabBreakLabelField="TABDL" multiTabBreakLonglabelField="TABDLL">
			<DATAGRID title="" total="false" sortable="false" showOthers="false" headerHeight="0" >
				<INSERT name="DATAGRID_MULTITAB_STYLES"/>
				
				<ROWSTYLE name="backgroundColor" value="0xffd393" condition="ROW.OID == 1"/>
				<ROWSTYLE name="fontWeight" value="bold" condition="ROW.OID == 1"/>
				<ROWSTYLE name="fontWeight" value="bold" condition="ROW.OID == 2"/>
				<ROWSTYLE name="backgroundColor" value="0xffd393" condition="ROW.OID == 20"/>
				<ROWSTYLE name="fontWeight" value="bold" condition="ROW.OID == 20"/>
				<ROWSTYLE name="backgroundColor" value="0xffd393" condition="ROW.OID == 27"/>
				<ROWSTYLE name="fontWeight" value="bold" condition="ROW.OID == 27"/>
				<ROWSTYLE name="backgroundColor" value="0xffd393" condition="ROW.OID == 34"/>
				<ROWSTYLE name="fontWeight" value="bold" condition="ROW.OID == 34"/>
				<ROWSTYLE name="backgroundColor" value="0xffd393" condition="ROW.OID == 41"/>
				<ROWSTYLE name="fontWeight" value="bold" condition="ROW.OID == 41"/>
				<ROWSTYLE name="backgroundColor" value="0xffd393" condition="ROW.OID == 48"/>
				<ROWSTYLE name="fontWeight" value="bold" condition="ROW.OID == 48"/>
				<ROWSTYLE name="backgroundColor" value="0xffd393" condition="ROW.OID == 55"/>
				<ROWSTYLE name="fontWeight" value="bold" condition="ROW.OID == 55"/>

				<COLUMN dataField="OID" width="60" type="Char" visible="false" headerText="Oid">
				</COLUMN>

				<COLUMN dataField="COD" width="70" type="Char" visible="false" headerText="Code" textAlign="left" otherFunction="text" totalFunction="text">
					<INSERT name="COLUMN_COD_MULTITAB_STYLES"/>
				</COLUMN>
				<COLUMN dataField="TXT" type="Char" visible="false" minWidth="50" headerText="Texte"  textAlign="left"  >
				</COLUMN>

				<COLUMN dataField="COL11" type="Char" width="70" headerText="" textAlign="left"  >
				</COLUMN>
				<COLUMN dataField="COL12" type="Char" width="70" headerText="" textAlign="left"  >
					<CELLSTYLE name="fontWeight" value="bold" />
				</COLUMN>
				<COLUMN dataField="COL13" type="Char" width="170" headerText="" textAlign="left"  >
				</COLUMN>
				<COLUMN dataField="COL14" type="Char" width="170" headerText="" textAlign="left"  >
				</COLUMN>
				<COLUMN dataField="COL15" type="Char" width="140" headerText="" textAlign="left"  >
				</COLUMN>
				<COLUMN dataField="SEP" type="Char" width="20" headerText="" textAlign="left"  >
				</COLUMN>
				<COLUMN dataField="COL21" type="Char" width="70" headerText="" textAlign="left"  >
				</COLUMN>
				<COLUMN dataField="COL22" type="Char" width="70" headerText="" textAlign="left"  >
					<CELLSTYLE name="fontWeight" value="bold" />
				</COLUMN>
				<COLUMN dataField="COL23" type="Char" width="170" headerText="" textAlign="left"  >
				</COLUMN>
				<COLUMN dataField="COL24" type="Char" width="170" headerText="" textAlign="left"  >
				</COLUMN>
				<COLUMN dataField="COL25" type="Char" width="140" headerText="" textAlign="left"  >
				</COLUMN>
			</DATAGRID>
		</ONGLET>

	</PRESENTATION>
</VUE>