<?xml version="1.0" encoding="ISO-8859-15"?>
<COMPONENTS>
	
	<COMPONENT name="DAYS_SELECTIONS" label="Jours de la semaine" >
	
		<VIEWPROPERTIES>
			
			<PROPERTY name="JOURS_SELECT">
				<value><![CDATA[[EVAL 
				
					$select = '';
					$cumul = '[LUN]' . '[MAR]' . '[MER]' . '[JEU]' . '[VEN]' . '[SAM]' . '[DIM]';
					
					if ($cumul != '1234567') {
						if ($cumul == '0000000') {
							$select = "AND jour_semaine > 10";
						}
						else {
							$select = "AND jour_semaine IN (";
							if ('[LUN]' == '1') { $select .= "1,"; }
							if ('[MAR]' == '2') { $select .= "2,"; }
							if ('[MER]' == '3') { $select .= "3,"; }
							if ('[JEU]' == '4') { $select .= "4,"; }
							if ('[VEN]' == '5') { $select .= "5,"; }
							if ('[SAM]' == '6') { $select .= "6,"; }
							if ('[DIM]' == '7') { $select .= "7,"; }
							$select = substr($select, 0, -1) . ")";
						}
					}
					return $select;
					
				EVAL]]]></value>
			</PROPERTY>
			
		</VIEWPROPERTIES>
		
		<SELECTIONS label="Jours de la semaine" collapsible="true" displayText="= var display:String = '';

			var cumul:String = SELECT.LUN + SELECT.MAR + SELECT.MER + SELECT.JEU + SELECT.VEN + SELECT.SAM + SELECT.DIM;
			
			if (cumul == '1234500') { display += 'Jours : #B# Hors week-end #/B#';}
			else if (cumul == '0000067') { display += 'Jours : #B# Week-end #/B#';}
			else if (cumul != '1234567') {
				display += 'Jours :#B#';
				if (SELECT.LUN == '1') { display += ' Lun';}
				if (SELECT.MAR == '2') { display += ' Mar';}
				if (SELECT.MER == '3') { display += ' Mer';}
				if (SELECT.JEU == '4') { display += ' Jeu';}
				if (SELECT.VEN == '5') { display += ' Ven';}
				if (SELECT.SAM == '6') { display += ' Sam';}
				if (SELECT.DIM == '7') { display += ' Dim';}
				display += '#/B#';
			}
			return display;
		"> 
			
			<GROUP label=" ">
				<FIELD name="LUN" label="Lun" UI="check" selectedValue="1" unselectedValue="0" default="1" showIfNotDefault="true" />
				<FIELD name="MAR" label="Mar" UI="check" selectedValue="2" unselectedValue="0" default="2" showIfNotDefault="true" />
				<FIELD name="MER" label="Mer" UI="check" selectedValue="3" unselectedValue="0" default="3" showIfNotDefault="true" />
				<FIELD name="JEU" label="Jeu" UI="check" selectedValue="4" unselectedValue="0" default="4" showIfNotDefault="true" />
				<FIELD name="VEN" label="Ven" UI="check" selectedValue="5" unselectedValue="0" default="5" showIfNotDefault="true" />
				<FIELD name="SAM" label="Sam" UI="check" selectedValue="6" unselectedValue="0" default="6" showIfNotDefault="true" />
				<FIELD name="DIM" label="Dim" UI="check" selectedValue="7" unselectedValue="0" default="7" showIfNotDefault="true" />
			</GROUP>
		</SELECTIONS>
		
		<QUERIES />
		
	</COMPONENT>

	<COMPONENT name="FILTRES_SEJOURS_SELECTIONS" label="Filtre séjours" >
	
		<VIEWPROPERTIES>
			
			<PROPERTY name="SEJOURS_SELECT">
				<value>
					<![CDATA[
						[EVAL 
							$select = "";
							$select = $select . ACTI_standard_field_select("type_sejour", '', '[TYPESEJOUR]', "", "");
                            $select = $select . ACTI_standard_field_select("forme_activite", '', '[FORMEACTIVITE]', "", "");
							$select = $select . ACTI_standard_field_select("filiere_soin_principale", 't_filiere_soin', '[FILIERESOINSEJOUR]', "", "");
							$select = $select . ACTI_standard_field_select("v_sejours_lieu_1.mode_traitement", '', '[MODETRAITEMENT]', "", "");
							$select = $select . ACTI_standard_field_select("duree_sejour", '', '[T_DUREE_SEJOUR]|[DUREE_SEJOUR]|[DUREE_SEJOUR2]', '', "");
							$select = $select . ACTI_standard_field_select("duree_occupation", '', '[T_DUREE_OCCUP]|[DUREE_OCCUP]|[DUREE_OCCUP2]', '', "");
							$select = $select . ACTI_standard_field_select("heure_entree", '', '[HEURE_ENTREE]|[HEURE_ENTREE_OPERATOR]|[HEURE_ENTREE_FIELD1]|[HEURE_ENTREE_FIELD2]', '', "");
							$select = $select . ACTI_standard_field_select("heure_sortie", '', '[HEURE_SORTIE]|[HEURE_SORTIE_OPERATOR]|[HEURE_SORTIE_FIELD1]|[HEURE_SORTIE_FIELD2]', '', "");
							
							$select = $select . ACTI_standard_field_select("lieu_sortie_service", 't_services_facturation', '[SERVICE_SEJOUR]', '[SERVICE_SEJOUR_CODES]', "");
							$select = $select . ACTI_standard_field_select("lieu_sortie_unite_fonctionnelle", 't_unites_fonctionnelles', '[UF_SEJOUR]', '[UF_SEJOUR_CODES]', "");
							$select = $select . ACTI_standard_field_select("lieu_sortie_activite", 't_activites', '[ACTIVITE_SEJOUR]', '[ACTIVITE_SEJOUR_CODES]', "");
							$select = $select . ACTI_standard_field_select("lieu_sortie_etage", 't_etages', '[ETAGE_SEJOUR]', '[ETAGE_SEJOUR_CODES]', "");
							
                            $select = $select . ACTI_standard_field_select("lieu_sortie_gir", 't_gir', '[GIR_SEJOUR]', '[GIR_SEJOUR_CODES]', "");
							
							$select = $select . ACTI_standard_field_select("medecin_adm_sejour", 't_medecins_administratifs', '[MEDECIN_SEJOUR]', '[MEDECIN_SEJOUR_CODES]', "");
							$select = $select . ACTI_standard_field_select("medecin_traitant", 't_medecins_traitants_administratifs', '[MEDECIN_TRAITANT]', '[MEDECIN_TRAITANT_CODES_CODES]', "");
							
							$select = $select . ACTI_standard_field_select("mco", '', '[MCO_M][MCO_C][MCO_O][MCO_S][MCO_H]', "", "");
							$select = $select . ACTI_standard_field_select("cas", '', '[CAS_C][CAS_K][CAS_X][CAS_N][CAS_O][CAS_S][CAS_W]', "", "");
							$select = $select . ACTI_standard_field_select("v_sejours_1.ghs", 't_ghs_c', '[GHS]', '[GHS_CODES]', "");
							$select = $select . ACTI_standard_field_select("ghm", 't_ghm_c', '[GHM]', '[GHM_CODES]', "");
							$select = $select . ACTI_standard_field_select("severite_cti", 't_severites_cti', '[CTISEV]', '[SEVCTI_CODES]', "");
							
							$select = $select . ACTI_standard_field_select("v_sejours_gme_1.gme", 't_gme_c', '[GME]', '[GME_CODES]', "");
							$select = $select . ACTI_standard_field_select("cm", 't_gme_c', '[CM]', '[CM_CODES]', "");
							$select = $select . ACTI_standard_field_select("gn", 't_gme_c', '[GN]', '[GN_CODES]', "");
							$select = $select . ACTI_standard_field_select("rgme", 't_gme_c', '[RGME]', '[RGME_CODES]', "");
							
							$select = $select . ACTI_standard_field_select("v_sejours_ghmgme_1.ghmgme", 'v_ghmgme_1', '[HME]', '[HME_CODES]', "");

							$select = $select . ACTI_standard_field_select("v_sejours_parametres_personnalises_1.parametre_personnalise_1", '', '[PARAMETRE_PERSONNALISE_SEJOUR_1]', '[PARAMETRE_PERSONNALISE_SEJOUR_1_CODES]', "");
							$select = $select . ACTI_standard_field_select("v_sejours_parametres_personnalises_1.parametre_personnalise_2", '', '[PARAMETRE_PERSONNALISE_SEJOUR_2]', '[PARAMETRE_PERSONNALISE_SEJOUR_2_CODES]', "");
							
							$select = $select . ACTI_standard_field_select("budget_cle", 't_budget_cle', '[BUDGET_CLE]', '[BUDGET_CLE_CODES]', "");
							
							$select = $select . ACTI_standard_field_select("v_sejours_finess_1.finess", '', '[FINESS]', "", "");
							$select = $select . ACTI_standard_field_select("provider", '', '[PROVIDER]', "", "");
							
							$select = $select . ACTI_standard_field_select("mode_entree", '', '[MODE_ENTREE]', "", "");
							$select = $select . ACTI_standard_field_select("mode_sortie", '', '[MODE_SORTIE]', "", "");
							$select = $select . ACTI_standard_field_select("provenance", '', '[PROVENANCE]', "", "");
							$select = $select . ACTI_standard_field_select("destination", '', '[DESTINATION]', "", "");
							$select = $select . ACTI_standard_field_select("etablissement_provenance", '', '[ETABLISSEMENT_PROVENANCE]', "", "");
							$select = $select . ACTI_standard_field_select("etablissement_destination", '', '[ETABLISSEMENT_DESTINATION]', "", "");

							$select = $select . ACTI_standard_field_select("etat_sejour", '', '[ETAT_SEJOUR]', "", "");
                            $select = $select . ACTI_standard_field_select("v_risque_1.risque", '', '[RISQUE]', "", "");
                            $select = $select . ACTI_standard_field_select("traitement_epmsi", '', '[CHAMP]', "", "");
							
							$select = $select . ACTI_standard_field_select("prestation_avec", 't_prestations', '[PRESTATION_AVEC]', '[PRESTATION_AVEC_CODES]', "");
							$select = $select . ACTI_standard_field_select("rubrique_facturation_avec", 't_rubriques_facturation', '[RUBRIQUE_AVEC]', '[RUBRIQUE_AVEC_CODES]', "");
							$select = $select . ACTI_standard_field_select("compte_produit_avec", 't_compte', '[COMPTE_AVEC]', '[COMPTE_AVEC_CODES]', "");
							
							// Le filtre sur le statut du séjour est explicité ci-dessous car les filtres '[PERIODE]' et '[TOPERIODE]'
							// ne sont pas re-parsés quand on passe par la fonction ACTI_standard_field_select()
					
							// Statut du séjour sur période -----------------------------------------------------------
							if ('[STATUT_SEJOUR]' != '-1') {
								switch('[STATUT_SEJOUR]') {
									case '1' :
										// Séjour entier sur période
										$select .= "
											AND (v_sejours_1.date_entree BETWEEN '[PERIODE]' AND '[TOPERIODE]')
											AND	(v_sejours_1.date_sortie BETWEEN '[PERIODE]' AND '[TOPERIODE]')
										";
										break;
									case '2' :
										// Sortie sur période
										$select .= "
											AND (v_sejours_1.date_sortie BETWEEN '[PERIODE]' AND '[TOPERIODE]')
										";
										break;
									case '3' :
										// Admission sur période
										$select .= "
											AND (v_sejours_1.date_entree BETWEEN '[PERIODE]' AND '[TOPERIODE]')
										";
										break;
									case '4' :
										// Admission hors période
										$select .= "
											AND (v_sejours_1.date_entree NOT BETWEEN '[PERIODE]' AND '[TOPERIODE]')
										";
										break;
									case '5' :
										// Sortie hors période
										$select .= "
											AND (v_sejours_1.date_sortie NOT BETWEEN '[PERIODE]' AND '[TOPERIODE]')
										";
										break;
								}
							}
							 
							return $select;
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
		</VIEWPROPERTIES>
		
		<SELECTIONS label="Filtre séjours" collapsible="true" displayText="= var display:String = '';
		
						if (SELECT.FINESS  != '-1') {
							display = display + '  Etablissement : #B#' + SELECT.FINESS_LABEL + '#/B#';
						}
						
						if (SELECT.RISQUE  != '-1') {
							display = display + '  Risque : #B#' + SELECT.RISQUE_LABEL + '#/B#';
						}
						
						if (SELECT.TYPESEJOUR != '-1') {
							display = display + '  Type séjour : #B#' + SELECT.TYPESEJOUR_LABEL + '#/B#';
						}
                        if (SELECT.FORMEACTIVITE != '-1') {
							display = display + '  Forme activité : #B#' + SELECT.FORMEACTIVITE_LABEL + '#/B#';
						}
						if (SELECT.FILIERESOINSEJOUR != '-1') {
							display = display + '  Filière soins séjour : #B#' + SELECT.FILIERESOINSEJOUR_LABEL + '#/B#';
						}
						if (SELECT.MODETRAITEMENT != '-1') {
							display = display + '  Mode de traitement : #B#' + SELECT.MODETRAITEMENT_LABEL + '#/B#';
						}
						var CKXNOSW:String = SELECT.CAS_C + SELECT.CAS_K + SELECT.CAS_X + SELECT.CAS_N + SELECT.CAS_O + SELECT.CAS_S + SELECT.CAS_W;
						if (CKXNOSW != 'CKXNOS*') {
							display += '  C.A.S. : #B#';

							var display_cas:String = '';
							var display_shortCas:String = '';
							if (SELECT.CAS_C == 'C') {
								display_cas += 'Chirurgie (C) ';
								display_shortCas += 'Chi (C) ';
							}
							if (SELECT.CAS_K == 'K') {
								display_cas += 'Techniques peu invasives (K) ';
								display_shortCas += 'Tech (K) ';
							}
							if (SELECT.CAS_X == 'X') {
								display_cas += 'Sans Acte classant (X) ';
								display_shortCas += 'Sans acte (X) ';
							}
							if (SELECT.CAS_N == 'N') {
								display_cas += 'Nouveaux-nés (N) ';
								display_shortCas += 'NN (N) ';
							}
							if (SELECT.CAS_O == 'O') {
								display_cas += 'Obstétrique ';
								display_shortCas += 'Obst (O) ';
							}
							if (SELECT.CAS_S == 'S') {
								display_cas += 'Séance (S) ';
								display_shortCas += 'Séance (S) ';
							}
							if (SELECT.CAS_W == '*') {
								display_cas += 'Non groupés ou Non PMSI ';
								display_shortCas += 'N/A (*) ';
							}
							
							if (display_cas.length > 50) {
								display += display_shortCas;
							}
							else {
								display += display_cas;
							}
							
							display += '#/B#';
						}
						
						if (SELECT.GHM  != '-1') {
							if (SELECT.GHM != 'SAISIECODE') {
								display = display + '  GHM : #B#' + SELECT.GHM_LABEL + '#/B#';
							}
							else {
								display = display + '  GHM : #B#' + SELECT.GHM_CODES + '#/B#';
							}
						}						
                        
                        if (SELECT.CTISEV  != '-1') {
                            if (SELECT.CTISEV != 'SAISIECODE') {
                                display = display + ' Sévérité CTI : #B#' + SELECT.CTISEV_LABEL + '#/B#';
                            }                            
							else {
                                display = display + '  Sévérité CTI : #B#' + SELECT.CTISEV_LABEL + '#/B#';
                                }
						}
						
						if (SELECT.GHS  != '-1') {
							if (SELECT.GHS != 'SAISIECODE') {
								display = display + '  GHS : #B#' + SELECT.GHS_LABEL + '#/B#';
							}
							else {
								display = display + '  GHS : #B#' + SELECT.GHS_CODES + '#/B#';
							}
						}
						if (SELECT.GME  != '-1') {
							if (SELECT.GME != 'SAISIECODE') {
								display = display + '  GME : #B#' + SELECT.GME_LABEL + '#/B#';
							}
							else {
								display = display + '  GME : #B#' + SELECT.GME_CODES + '#/B#';
							}
						}
						if (SELECT.HME  != '-1') {
							if (SELECT.HME != 'SAISIECODE') {
								display = display + '  GHM-GME : #B#' + SELECT.HME_LABEL + '#/B#';
							}
							else {
								display = display + '  GHM-GME : #B#' + SELECT.HME_CODES + '#/B#';
							}
						}
                        if (SELECT.GIR_SEJOUR  != '-1') {
							if (SELECT.GIR_SEJOUR != 'SAISIECODE') {
								display = display + '  GIR sortie : #B#' + SELECT.GIR_SEJOUR_LABEL + '#/B#';
							}
							else {
								display = display + '  GIR sortie : #B#' + SELECT.GIR_SEJOUR_CODES + '#/B#';
							}
						}
						if (SELECT.SERVICE_SEJOUR  != '-1') {
							if (SELECT.SERVICE_SEJOUR != 'SAISIECODE') {
								display = display + '  [DICT.ACTI.SERVICE] sortie : #B#' + SELECT.SERVICE_SEJOUR_LABEL + '#/B#';
							}
							else {
								display = display + '  [DICT.ACTI.SERVICE] sortie : #B#' + SELECT.SERVICE_SEJOUR_CODES + '#/B#';
							}
						}
						if (SELECT.UF_SEJOUR  != '-1') {
							if (SELECT.UF_SEJOUR != 'SAISIECODE') {
								display = display + '  [DICT.ACTI.UF] sortie : #B#' + SELECT.UF_SEJOUR_LABEL + '#/B#';
							}
							else {
								display = display + '  [DICT.ACTI.UF] sortie : #B#' + SELECT.UF_SEJOUR_CODES + '#/B#';
							}
						}
						if (SELECT.ACTIVITE_SEJOUR  != '-1') {
							if (SELECT.ACTIVITE_SEJOUR != 'SAISIECODE') {
								display = display + '  [DICT.ACTI.ACTIVITE] sortie : #B#' + SELECT.ACTIVITE_SEJOUR_LABEL + '#/B#';
							}
							else {
								display = display + '  [DICT.ACTI.ACTIVITE] sortie : #B#' + SELECT.ACTIVITE_SEJOUR_CODES + '#/B#';
							}
						}
						if (SELECT.ETAGE_SEJOUR  != '-1') {
							if (SELECT.ETAGE_SEJOUR != 'SAISIECODE') {
								display = display + '  [DICT.ACTI.ETAGE] sortie : #B#' + SELECT.ETAGE_SEJOUR_LABEL + '#/B#';
							}
							else {
								display = display + '  [DICT.ACTI.ETAGE] sortie : #B#' + SELECT.ETAGE_SEJOUR_CODES + '#/B#';
							}
						}
						if (SELECT.MEDECIN_SEJOUR  != '-1') {
							if (SELECT.MEDECIN_SEJOUR != 'SAISIECODE') {
								if (SELECT.MEDECIN_SEJOUR.toString().substr(0,2) != 'SP') {
									display = display + '  Médecin séjour: #B#' + SELECT.MEDECIN_SEJOUR_LABEL + '#/B#';
								}
								else {
									display = display + '  Spécialité médecin séjour: #B#' + SELECT.MEDECIN_SEJOUR_LABEL + '#/B#';
								}
							}
							else {
								display = display + '  Médecin séjour : #B#' + SELECT.MEDECIN_SEJOUR_CODES + '#/B#';
							}
						}						
                        
                        if (SELECT.MEDECIN_TRAITANT  != '-1') {
							if (SELECT.MEDECIN_TRAITANT != 'SAISIECODE') {
									display = display + '  Médecin traitant: #B#' + SELECT.MEDECIN_TRAITANT_LABEL + '#/B#';
							}
							else {
								display = display + '  Médecin traitant : #B#' + SELECT.MEDECIN_SEJOUR_CODES + '#/B#';
							}
						}
						if (SELECT.BUDGET_CLE  != '-1') {
							if (SELECT.BUDGET_CLE != 'SAISIECODE') {
								display = display + '  Clé budgétaire : #B#' + SELECT.BUDGET_CLE_LABEL + '#/B#';
							}
							else {
								display = display + '  Clé budgétaire : #B#' + SELECT.BUDGET_CLE_CODES + '#/B#';
							}
						}
						if (SELECT.PARAMETRE_PERSONNALISE_SEJOUR_1  != '-1') {
							display = display + '  [DICT.ACTI.PARAMETRE_PERSONNALISE_SEJOUR_1] : #B#' + SELECT.PARAMETRE_PERSONNALISE_SEJOUR_1_LABEL + '#/B#';
						}
						if (SELECT.PARAMETRE_PERSONNALISE_SEJOUR_2  != '-1') {
							display = display + '  [DICT.ACTI.PARAMETRE_PERSONNALISE_SEJOUR_2] : #B#' + SELECT.PARAMETRE_PERSONNALISE_SEJOUR_2_LABEL + '#/B#';
						}
						if (SELECT.MCO_M + SELECT.MCO_C + SELECT.MCO_O + SELECT.MCO_S + SELECT.MCO_H != 'MCOS*') {
							display += '  ASO : #B#';
							if (SELECT.MCO_M + SELECT.MCO_C + SELECT.MCO_O + SELECT.MCO_S == 'MCOS') {
								display += 'M.C.O. ';
							}
							else {
								if (SELECT.MCO_M == 'M') {
									display += 'Médecine ';
								}
								if (SELECT.MCO_C == 'C') {
									display += 'Chirurgie ';
								}
								if (SELECT.MCO_O == 'O') {
									display += 'Obstétrique ';
								}
								if (SELECT.MCO_S == 'S') {
									display += 'Séance ';
								}
								if (SELECT.MCO_H == '*') {
									display += 'Non groupés ou Non PMSI ';
								}
							}
							display += '#/B#';
						}
						if (SELECT.T_DUREE_SEJOUR  != '-1') {
							display += '  Durée séjour : #B#';
							if (SELECT.T_DUREE_SEJOUR != 'I') {
								display += SELECT.T_DUREE_SEJOUR_LABEL;
							}
							else {
								if (SELECT.DUREE_SEJOUR != '') {
									if (SELECT.DUREE_SEJOUR2 != '') {
										display += '#GE# ' + SELECT.DUREE_SEJOUR + ' et #LE# ' + SELECT.DUREE_SEJOUR2 + ' jour(s)';
									}
									else {
										display += '#GE# ' + SELECT.DUREE_SEJOUR + ' jour(s)';
									}
								}
								else {
									display += '#LE# ' + SELECT.DUREE_SEJOUR2 + ' jour(s)';
								}
							}
							display += '#/B#';
						}
						if (SELECT.T_DUREE_OCCUP != '-1') {
							display += '  Durée occupation: #B#';
							if (SELECT.T_DUREE_OCCUP != 'I') {
								display += SELECT.T_DUREE_OCCUP_LABEL;
							}
							else {
								if (SELECT.DUREE_OCCUP != '') {
									if (SELECT.DUREE_OCCUP2 != '') {
										display += '#GE# ' + SELECT.DUREE_OCCUP + ' et #LE# ' + SELECT.DUREE_OCCUP2 + ' nuit(s)';
									}
									else {
										display += '#GE# ' + SELECT.DUREE_OCCUP+ ' nuit(s)';
									}
								}
								else {
									display += '#LE# ' + SELECT.DUREE_OCCUP2 + ' nuit(s)';
								}
							}
							display += '#/B#';
						}
						
						if (SELECT.PROVIDER  != '-1') {
							display = display + '  Logiciel administratif : #B#' + SELECT.PROVIDER_LABEL + '#/B#';
						}
						
						if (SELECT.HEURE_ENTREE  != '-1') {
							if (SELECT.HEURE_ENTREE_OPERATOR == '1') {
								display = display + '  Heure d\'entrée : #B# Avant ' + SELECT.HEURE_ENTREE_FIELD1_LABEL + '#/B#';
							}
							else if (SELECT.HEURE_ENTREE_OPERATOR == '2') {
								display = display + '  Heure d\'entrée : #B# Après ' + SELECT.HEURE_ENTREE_FIELD1_LABEL + '#/B#';
							}
							else {
								display = display + '  Heure d\'entrée : #B# Entre ' + SELECT.HEURE_ENTREE_FIELD1_LABEL + ' et ' + SELECT.HEURE_ENTREE_FIELD2_LABEL + '#/B#';
							}
						}
						
						if (SELECT.HEURE_SORTIE  != '-1') {
							if (SELECT.HEURE_SORTIE_OPERATOR == '1') {
								display = display + '  Heure de sortie : #B# Avant ' + SELECT.HEURE_SORTIE_FIELD1_LABEL + '#/B#';
							}
							else if (SELECT.HEURE_SORTIE_OPERATOR == '2') {
								display = display + '  Heure de sortie : #B# Après ' + SELECT.HEURE_SORTIE_FIELD1_LABEL + '#/B#';
							}
							else {
								display = display + '  Heure de sortie : #B# Entre ' + SELECT.HEURE_SORTIE_FIELD1_LABEL + ' et ' + SELECT.HEURE_SORTIE_FIELD2_LABEL + '#/B#';
							}
						}
						if (SELECT.MODE_ENTREE  != '-1') {
							display = display + '  Mode entrée : #B#' + SELECT.MODE_ENTREE_LABEL + '#/B#';
						}
						if (SELECT.PROVENANCE  != '-1') {
							display = display + '  Provenance : #B#' + SELECT.PROVENANCE_LABEL + '#/B#';
						}
						if (SELECT.ETABLISSEMENT_PROVENANCE  != '-1') {
							display = display + '  Etablissement d\'origine: #B#' + SELECT.ETABLISSEMENT_DESTINATION_LABEL + '#/B#';
						}
						if (SELECT.MODE_SORTIE  != '-1') {
							display = display + '  Mode sortie : #B#' + SELECT.MODE_SORTIE_LABEL + '#/B#';
						}
						if (SELECT.DESTINATION  != '-1') {
							display = display + '  Destination : #B#' + SELECT.DESTINATION_LABEL + '#/B#';
						}
						if (SELECT.ETABLISSEMENT_DESTINATION  != '-1') {
							display = display + '  Etablissement de destination: #B#' + SELECT.ETABLISSEMENT_DESTINATION_LABEL + '#/B#';
						}
                        if (SELECT.ETAT_SEJOUR  != '-1') {
							display += '  Etat du séjour : #B#'+SELECT.ETAT_SEJOUR_LABEL+'#/B#';
						}
						if (SELECT.STATUT_SEJOUR  != '-1') {
							display += '  Statut séjour : #B#'+SELECT.STATUT_SEJOUR_LABEL+'#/B#';
						}
					if (SELECT.CHAMP != '-1') {
						display = display + '  Champ e-PMSI : #B#' + SELECT.CHAMP_LABEL + '#/B#';
					}
						if (SELECT.PRESTATION_AVEC  != '-1') {
							if (SELECT.PRESTATION_AVEC != 'SAISIECODE') {
								display = display + '  Avec Prestation : #B#' + SELECT.PRESTATION_AVEC_LABEL + '#/B#';
							}
							else {
								display = display + '  Avec Prestation : #B#' + SELECT.PRESTATION_AVEC_CODES + '#/B#';
							}
						}
						if (SELECT.RUBRIQUE_AVEC  != '-1') {
							if (SELECT.RUBRIQUE_AVEC != 'SAISIECODE') {
								display = display + '  Avec Rubrique : #B#' + SELECT.RUBRIQUE_AVEC_LABEL + '#/B#';
							}
							else {
								display = display + '  Avec Rubrique : #B#' + SELECT.RUBRIQUE_AVEC_CODES + '#/B#';
							}
						}
						if (SELECT.COMPTE_AVEC  != '-1') {
							if (SELECT.COMPTE_AVEC != 'SAISIECODE') {
								display = display + '  Avec Compte : #B#' + SELECT.COMPTE_AVEC_LABEL + '#/B#';
							}
							else {
								display = display + '  Avec Compte : #B#' + SELECT.COMPTE_AVEC_CODES + '#/B#';
							}
						}
						if (display != '') {
							display = '#B#Filtres séjours#/B# = ' + display;
						}
						return display;
						" 
				>
			<GROUP label="Etat séjour">
				<FIELD name="ETAT_SEJOUR" label="" UI="combo" tree="true" width="400" default="-1" showIfNotDefault="true">
					<OPTION label="Pas de sélection" data="-1" lvl="1"/>
                    <OPTION dataLink="ETAT_SEJOUR" treeLevelField="lvl" dataField="cod"  labelField="txt" aliasField="alias" ctiField="cti" />
				</FIELD>
			</GROUP>
            <GROUP>
				<FIELD name="FORMEACTIVITE" label="Forme d'activité" UI="combo" tree="true" globalListProvider="FORMEACTIVITE" width="400" default="-1" showIfNotDefault="true" />
			</GROUP>
			<GROUP>
				<FIELD name="FILIERESOINSEJOUR" label="Filière de soin" UI="combo" tree="true" globalListProvider="FILIERESOIN" width="400" default="-1" showIfNotDefault="true" />
			</GROUP>
			<GROUP>
				<FIELD name="TYPESEJOUR" label="Type séjour" UI="combo" tree="true" globalListProvider="TYPESEJOUR" width="200" default="-1" showIfNotDefault="true" />
			</GROUP>
			<GROUP>
				<FIELD name="MODETRAITEMENT" label="Mode de traitement" UI="combo" tree="true" globalListProvider="MODESTRAITEMENT" width="400" default="-1" showIfNotDefault="true" />
			</GROUP>
			
			
			<GROUP>
				<FIELD name="SERVICE_SEJOUR" label="[DICT.ACTI.SERVICE] sortie" UI="combo" tree="true" width="400" default="-1" globalListProvider="SERVICES" showIfNotDefault="true" 
					visible="= VIEW.CONTEXTE != 'OCCUPATION'  "/>
				<FIELD name="SERVICE_SEJOUR_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.SERVICE_SEJOUR == 'SAISIECODE' " />
			</GROUP>
			<GROUP>
				<FIELD name="UF_SEJOUR" label="[DICT.ACTI.UF] sortie" UI="combo" tree="true" width="400" default="-1" globalListProvider="UF" showIfNotDefault="true" />
				<FIELD name="UF_SEJOUR_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.UF_SEJOUR == 'SAISIECODE' " />
			</GROUP>
			<GROUP>
				<FIELD name="ACTIVITE_SEJOUR" label="[DICT.ACTI.ACTIVITE] sortie" UI="combo" tree="true" width="400" default="-1" globalListProvider="ACTIVITES" showIfNotDefault="true" 
					visible="= VIEW.CONTEXTE != 'OCCUPATION' &amp;&amp; 
							VIEW.CONTEXTE != 'PRESTATIONS' &amp;&amp; 
							VIEW.CONTEXTE != 'PRESTATIONS_H'  "/>
				<FIELD name="ACTIVITE_SEJOUR_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.ACTIVITE_SEJOUR == 'SAISIECODE' " />
			</GROUP>
			<GROUP>
				<FIELD name="ETAGE_SEJOUR" label="[DICT.ACTI.ETAGE] sortie" UI="combo" width="200" tree="true" default="-1" globalListProvider="ETAGES" showIfNotDefault="true" />
				<FIELD name="ETAGE_SEJOUR_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.ETAGE_SEJOUR == 'SAISIECODE' " />
			</GROUP>
						
			<GROUP>
				<FIELD name="T_DUREE_SEJOUR" label="Durée de séjour" UI="combo" tree="true" width="200" default="-1" globalListProvider="T_DUREE_SEJOUR" showIfNotDefault="true" />
				<FIELD name="DUREE_SEJOUR" label="" UI="numberInterval" width="125" default="" default2="" visible="= SELECT.T_DUREE_SEJOUR == 'I'" />
				<FIELD name="T_DUREE_OCCUP" label="Durée d'occupation" UI="combo" tree="true" width="200" default="-1" globalListProvider="T_DUREE_OCCUP" showIfNotDefault="true" />
				<FIELD name="DUREE_OCCUP" label="" UI="numberInterval" width="125" default="" default2="" visible="= SELECT.T_DUREE_OCCUP == 'I'" />
			</GROUP>
						
			<GROUP label="Modes entrée">
				<FIELD name="MODE_ENTREE" label="" UI="combo" tree="true" width="200" default="-1" globalListProvider="MODE_ENTREE" showIfNotDefault="true" />
				<FIELD name="PROVENANCE" label="Prov." labelWidth="40" UI="combo" tree="true" width="200" default="-1" globalListProvider="PROVENANCES" showIfNotDefault="true" />
				<FIELD name="ETABLISSEMENT_PROVENANCE" label="Etab." labelWidth="40" UI="combo" tree="true" width="200" default="-1" globalListProvider="ETABLISSEMENTS_PROVENANCE" showIfNotDefault="true" />
			</GROUP>
			<GROUP label="Modes sortie">
				<FIELD name="MODE_SORTIE" label="" UI="combo" tree="true" width="200" default="-1" globalListProvider="MODE_SORTIE" showIfNotDefault="true" />
				<FIELD name="DESTINATION" label="Dest." labelWidth="40" UI="combo" tree="true" width="200" default="-1" globalListProvider="DESTINATIONS" showIfNotDefault="true" />
				<FIELD name="ETABLISSEMENT_DESTINATION" label="Etab." labelWidth="40" UI="combo" tree="true" width="200" default="-1" globalListProvider="ETABLISSEMENTS_DESTINATION" showIfNotDefault="true" />
			</GROUP>
			<GROUP label="Statut séjour">
				<FIELD name="STATUT_SEJOUR" label="" UI="combo" tree="true" width="400" default="-1" showIfNotDefault="true">
					<OPTION label="Pas de sélection" data="-1" lvl="1"/>
					<OPTION label="Admission avant période" data="4" lvl="1"/>
					<OPTION label="Admission sur période" data="3" lvl="1"/>
					<OPTION label="Séjour entier sur période" data="1" lvl="1"/>
					<OPTION label="Sortie sur période" data="2" lvl="1"/>
					<OPTION label="Sortie après période" data="5" lvl="1"/>
				</FIELD>
			</GROUP>
			
			<GROUP label="Risque séjour">
				<FIELD name="RISQUE" label="" UI="combo" width="400" tree="true" default="-1" globalListProvider="RISQUE" showIfNotDefault="true" />
			</GROUP>
			
			<GROUP label="C.A.S.">
				<FIELD name="CAS_C" label="Chirurgie (C)" UI="check" selectedValue="C" unselectedValue="" default="C" showIfNotDefault="true" />
				<FIELD name="CAS_K" label="Techniques peu invasives (K)" UI="check" selectedValue="K" unselectedValue="" default="K" showIfNotDefault="true" />
				<FIELD name="CAS_X" label="Sans Acte classant (X)" UI="check" selectedValue="X" unselectedValue="" default="X" showIfNotDefault="true" />
			</GROUP>
			<GROUP label = " ">
				<FIELD name="CAS_N" label="Nouveaux-nés (N)" UI="check" selectedValue="N" unselectedValue="" default="N" showIfNotDefault="true" />
				<FIELD name="CAS_O" label="Obstétrique (O)" UI="check" selectedValue="O" unselectedValue="" default="O" showIfNotDefault="true" />
				<FIELD name="CAS_S" label="Séances (S)" UI="check" selectedValue="S" unselectedValue="" default="S" showIfNotDefault="true" />
				<FIELD name="CAS_W" label="Non groupés ou Non PMSI" UI="check" selectedValue="*" unselectedValue="" default="*" showIfNotDefault="true" />
			</GROUP>

			<GROUP>
				<FIELD name="GHM" label="GHM" UI="combo" tree="true" width="400" default="-1" globalListProvider="GHM" showIfNotDefault="true" />
				<FIELD name="GHM_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.GHM == 'SAISIECODE' " />
			</GROUP>
            <GROUP label="Sévérité CTI">
					<FIELD name="CTISEV" label="" UI="combo" tree="true" width="400" default="-1" showIfNotDefault="true">
                        <OPTION label="Pas de sélection" data="-1" lvl="1"/>
                        <OPTION label="Saisie code" treeLevel="1"  data="SAISIECODE"/>
                        <OPTION dataLink="SEVCTI" treeLevelField="lvl" dataField="cod"  labelField="txt" />
                    </FIELD>
                    <FIELD name="SEVCTI_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.CTISEV == 'SAISIECODE' " />
            </GROUP>
						
			<GROUP label="ASo">
				<FIELD name="MCO_M" label="Médecine" UI="check" selectedValue="M" unselectedValue="" default="M" showIfNotDefault="true" />
				<FIELD name="MCO_C" label="Chirurgie" UI="check" selectedValue="C" unselectedValue="" default="C" showIfNotDefault="true" />
				<FIELD name="MCO_O" label="Obstétrique" UI="check" selectedValue="O" unselectedValue="" default="O" showIfNotDefault="true" />
				<FIELD name="MCO_S" label="Séances" UI="check" selectedValue="S" unselectedValue="" default="S" showIfNotDefault="true" />
				<FIELD name="MCO_H" label="Hors GHM ou N/A" UI="check" selectedValue="*" unselectedValue="" default="*" showIfNotDefault="true" />
			</GROUP>
			
			<GROUP>
				<FIELD name="GHS" label="GHS" UI="combo" tree="true" width="400" default="-1" globalListProvider="GHS" showIfNotDefault="true" />
				<FIELD name="GHS_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.GHS == 'SAISIECODE' " />
			</GROUP>
			
			<GROUP>
				<FIELD name="GME" label="GME" UI="combo" tree="true" width="400" default="-1" globalListProvider="GME" showIfNotDefault="true" />
				<FIELD name="GME_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.GME == 'SAISIECODE' " />
			</GROUP>
			<GROUP>
				<FIELD name="HME" label="GHM-GME" UI="combo" tree="true" width="400" default="-1" globalListProvider="HME" showIfNotDefault="true" />
				<FIELD name="HME_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.HME == 'SAISIECODE' " />
			</GROUP>

            <GROUP>
				<FIELD name="GIR_SEJOUR" label="GIR" UI="combo" tree="true" width="400" default="-1" globalListProvider="GIR" showIfNotDefault="true" />
				<FIELD name="GIR_SEJOUR_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.GIR_SEJOUR == 'SAISIECODE' " />
			</GROUP>            

			<GROUP>
				<FIELD name="MEDECIN_TRAITANT" label="Médecin traitant" UI="combo" tree="true" width="400" default="-1" 
					globalListProvider="MEDECINSTRAITANT" showIfNotDefault="true"/>
				<FIELD name="MEDECIN_TRAITANT_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.MEDECIN_TRAITANT == 'SAISIECODE' " />
			</GROUP>			
            
            <GROUP>
				<FIELD name="MEDECIN_SEJOUR" label="Médecin séjour" UI="combo" tree="true" width="400" default="-1" 
					globalListProvider="MEDECINSSEJOUR" showIfNotDefault="true"/>
				<FIELD name="MEDECIN_SEJOUR_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.MEDECIN_SEJOUR == 'SAISIECODE' " />
			</GROUP>
			
			<GROUP>
				<FIELD name="BUDGET_CLE" label="Clé budgétaire" UI="combo" tree="true" width="400" default="-1" 
					globalListProvider="BUDGET_CLE" showIfNotDefault="true" visible="= VIEW.CONTEXTE != 'OCCUPATION' &amp;&amp; VIEW.CONTEXTE != 'PRESTATIONS_H'"/>
				<FIELD name="BUDGET_CLE_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.BUDGET_CLE == 'SAISIECODE' " />
			</GROUP>
			
			<GROUP>
				<FIELD name="PARAMETRE_PERSONNALISE_SEJOUR_1" label="[DICT.ACTI.PARAMETRE_PERSONNALISE_SEJOUR_1]" 
					UI="combo" tree="true" width="400" default="-1" 
					globalListProvider="PARAMETRE_PERSONNALISE_SEJOUR_1" 
					visible="= '[DICT.ACTI.PARAMETRE_PERSONNALISE_SEJOUR_1]' != 'NULL'"
					showIfNotDefault="true" />
				<FIELD name="PARAMETRE_PERSONNALISE_SEJOUR_1_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.PARAMETRE_PERSONNALISE_SEJOUR_1 == 'SAISIECODE' " />
			</GROUP>
			
			<GROUP>
				<FIELD name="PARAMETRE_PERSONNALISE_SEJOUR_2" label="[DICT.ACTI.PARAMETRE_PERSONNALISE_SEJOUR_2]" 
					UI="combo" tree="true" width="400" default="-1" 
					globalListProvider="PARAMETRE_PERSONNALISE_SEJOUR_2" 
					visible="= '[DICT.ACTI.PARAMETRE_PERSONNALISE_SEJOUR_2]' != 'NULL'"
					showIfNotDefault="true" />
				<FIELD name="PARAMETRE_PERSONNALISE_SEJOUR_2_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.PARAMETRE_PERSONNALISE_SEJOUR_1 == 'SAISIECODE' " />
			</GROUP>
			
			
			<GROUP label="Logiciel administratif">
				<FIELD name="PROVIDER" label="" UI="combo" width="400" default="-1" globalListProvider="PROVIDERS" />
			</GROUP>
			
			<GROUP label="Etablissement">
				<FIELD name="FINESS" label="" UI="combo" width="400" tree="true" default="-1" globalListProvider="FINESS" showIfNotDefault="true" />
			</GROUP>
		
			<GROUP label="Heure d'entrée">
				<FIELD name="HEURE_ENTREE" width="200" label="" UI="combo" showIfNotDefault="true" default="-1">
					<OPTION label="Pas de sélection" data="-1" />
					<OPTION label="Entrée" data="1" />
				</FIELD>
				<FIELD name="HEURE_ENTREE_OPERATOR" width="70" label="" UI="combo" default="2" visible="= SELECT.HEURE_ENTREE != '-1' ">
					<OPTION label="avant" data="1" />
					<OPTION label="après" data="2" />
					<OPTION label="entre" data="3" />
				</FIELD>
				<FIELD name="HEURE_ENTREE_FIELD1" width="70" label="" UI="combo" default="20" visible="= SELECT.HEURE_ENTREE != '-1' " globalListProvider="HEURES" />
				<FIELD name="HEURE_ENTREE_FIELD2" width="70" label="et" UI="combo" default="20" visible="= (SELECT.HEURE_ENTREE != '-1') &amp;&amp; (SELECT.HEURE_ENTREE_OPERATOR == '3') " globalListProvider="HEURES" />
			</GROUP>
			
			<GROUP label="Heure de sortie">
				<FIELD name="HEURE_SORTIE" width="200" label="" UI="combo" showIfNotDefault="true" default="-1">
					<OPTION label="Pas de sélection" data="-1" />
					<OPTION label="Sortie" data="1" />
				</FIELD>
				<FIELD name="HEURE_SORTIE_OPERATOR" width="70" label="" UI="combo" default="2" visible="= SELECT.HEURE_SORTIE != '-1' ">
					<OPTION label="avant" data="1" />
					<OPTION label="après" data="2" />
					<OPTION label="entre" data="3" />
				</FIELD>
				<FIELD name="HEURE_SORTIE_FIELD1" width="70" label="" UI="combo" default="20" visible="= SELECT.HEURE_SORTIE != '-1' " globalListProvider="HEURES" />
				<FIELD name="HEURE_SORTIE_FIELD2" width="70" label="et" UI="combo" default="20" visible="= (SELECT.HEURE_SORTIE != '-1') &amp;&amp; (SELECT.HEURE_SORTIE_OPERATOR == '3') " globalListProvider="HEURES" />
			</GROUP>
			<GROUP label="Champ e-PMSI">
				<FIELD name="CHAMP" label="" UI="combo" tree="true" width="400" default="-1" showIfNotDefault="true" globalListProvider="CHAMP" />
			</GROUP>
			<GROUP label="Prestations (avec)" direction="vertical" collapsible="true"  visible="= VIEW.SHOW_FILTER_AVEC_PRESTATION != 'false'">
				<GROUP>
					<FIELD name="PRESTATION_AVEC" label="Avec Prestation" UI="combo" tree="true" width="400" default="-1" globalListProvider="PRESTATIONS" showIfNotDefault="true" />
					<FIELD name="PRESTATION_AVEC_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.PRESTATION_AVEC == 'SAISIECODE' " />
				</GROUP>
				<GROUP>
					<FIELD name="RUBRIQUE_AVEC" label="Avec Rubrique facturée" UI="combo" tree="true" width="400" default="-1" globalListProvider="RUBRIQUES" showIfNotDefault="true" />
					<FIELD name="RUBRIQUE_AVEC_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.RUBRIQUE_AVEC == 'SAISIECODE' " />
				</GROUP>
				<GROUP>
					<FIELD name="COMPTE_AVEC" label="Avec Compte" UI="combo" tree="true" width="400" default="-1" globalListProvider="COMPTE" showIfNotDefault="true" />
					<FIELD name="COMPTE_AVEC_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.COMPTE_AVEC == 'SAISIECODE' " />
				</GROUP>
			</GROUP>
		</SELECTIONS>
		<QUERIES>
            <QUERY type="comboLink" name="ETAT_SEJOUR" forRows="false"> 
                <SQL select="SELECT oid, texte, level, is_cti, CASE WHEN oid = 'DT2' THEN '1' ELSE '' END AS alias FROM activite.v_etat_sejour_2" >
                    <FIELDS>
                        <FIELD name="cod" />
                        <FIELD name="txt" />
                        <FIELD name="lvl" />
                        <FIELD name="cti" />
						<FIELD name="alias" />
                    </FIELDS>
                </SQL>
            </QUERY>
            <QUERY type="comboLink" name="SEVCTI"> 
                <SQL select="SELECT severite_id::text, severite_id || ' : ' ||severite_texte::text, '1' FROM activite.t_severites_cti where severite_id != '0'">
                    <FIELDS>
                        <FIELD name="cod" />
                        <FIELD name="txt" />
                        <FIELD name="lvl" />
                    </FIELDS>
                </SQL>
            </QUERY>
		</QUERIES>
	
	</COMPONENT>
    
    <COMPONENT name="FILTRES_SEJOURS_UF_SELECTIONS" label="Filtre séjours" >
	
		<VIEWPROPERTIES>
			
			<PROPERTY name="SEJOURS_UF_SELECT">
				<value>
					<![CDATA[
						[EVAL 
							$select = "";
							$select = $select . ACTI_standard_field_select("type_sejour", '', '[TYPESEJOUR]', "", "");
                            $select = $select . ACTI_standard_field_select("forme_activite", '', '[FORMEACTIVITE]', "", "");
							$select = $select . ACTI_standard_field_select("filiere_soin_principale", 't_filiere_soin', '[FILIERESOINSEJOUR]', "", "");
							$select = $select . ACTI_standard_field_select("v_sejours_lieu_1.mode_traitement", '', '[MODETRAITEMENT]', "", "");
							$select = $select . ACTI_standard_field_select("duree_sejour", '', '[T_DUREE_SEJOUR]|[DUREE_SEJOUR]|[DUREE_SEJOUR2]', '', "");
							$select = $select . ACTI_standard_field_select("duree_occupation", '', '[T_DUREE_OCCUP]|[DUREE_OCCUP]|[DUREE_OCCUP2]', '', "");
							$select = $select . ACTI_standard_field_select("heure_entree", '', '[HEURE_ENTREE]|[HEURE_ENTREE_OPERATOR]|[HEURE_ENTREE_FIELD1]|[HEURE_ENTREE_FIELD2]', '', "");
							$select = $select . ACTI_standard_field_select("heure_sortie", '', '[HEURE_SORTIE]|[HEURE_SORTIE_OPERATOR]|[HEURE_SORTIE_FIELD1]|[HEURE_SORTIE_FIELD2]', '', "");
							
							$select = $select . ACTI_standard_field_select("lieu_sortie_service", 't_services_facturation', '[SERVICE_SEJOUR]', '[SERVICE_SEJOUR_CODES]', "");
							$select = $select . ACTI_standard_field_select("lieu_sortie_unite_fonctionnelle", 't_unites_fonctionnelles', '[UF_SEJOUR]', '[UF_SEJOUR_CODES]', "");
							$select = $select . ACTI_standard_field_select("lieu_sortie_activite", 't_activites', '[ACTIVITE_SEJOUR]', '[ACTIVITE_SEJOUR_CODES]', "");
							$select = $select . ACTI_standard_field_select("lieu_sortie_etage", 't_etages', '[ETAGE_SEJOUR]', '[ETAGE_SEJOUR_CODES]', "");
							
							$select = $select . ACTI_standard_field_select("medecin_adm_sejour", 't_medecins_administratifs', '[MEDECIN_SEJOUR]', '[MEDECIN_SEJOUR_CODES]', "");
							$select = $select . ACTI_standard_field_select("medecin_traitant", 't_medecins_traitants_administratifs', '[MEDECIN_TRAITANT]', '[MEDECIN_TRAITANT_CODES_CODES]', "");
							
							$select = $select . ACTI_standard_field_select("mco", '', '[MCO_M][MCO_C][MCO_O][MCO_S][MCO_H]', "", "");
							$select = $select . ACTI_standard_field_select("cas", '', '[CAS_C][CAS_K][CAS_X][CAS_N][CAS_O][CAS_S][CAS_W]', "", "");
							$select = $select . ACTI_standard_field_select("v_sejours_1.ghs", 't_ghs_c', '[GHS]', '[GHS_CODES]', "");
							$select = $select . ACTI_standard_field_select("ghm", 't_ghm_c', '[GHM]', '[GHM_CODES]', "");
							
							$select = $select . ACTI_standard_field_select("gme", 't_gme_c', '[GME]', '[GME_CODES]', "");

							$select = $select . ACTI_standard_field_select("v_sejours_parametres_personnalises_1.parametre_personnalise_1", '', '[PARAMETRE_PERSONNALISE_SEJOUR_1]', '[PARAMETRE_PERSONNALISE_SEJOUR_1_CODES]', "");
							$select = $select . ACTI_standard_field_select("v_sejours_parametres_personnalises_1.parametre_personnalise_2", '', '[PARAMETRE_PERSONNALISE_SEJOUR_2]', '[PARAMETRE_PERSONNALISE_SEJOUR_2_CODES]', "");
							
							$select = $select . ACTI_standard_field_select("budget_cle", 't_budget_cle', '[BUDGET_CLE]', '[BUDGET_CLE_CODES]', "");
							
							$select = $select . ACTI_standard_field_select("finess", '', '[FINESS]', "", "");
							$select = $select . ACTI_standard_field_select("provider", '', '[PROVIDER]', "", "");
							
							$select = $select . ACTI_standard_field_select("mode_entree", '', '[MODE_ENTREE]', "", "");
							$select = $select . ACTI_standard_field_select("mode_sortie", '', '[MODE_SORTIE]', "", "");
							$select = $select . ACTI_standard_field_select("provenance", '', '[PROVENANCE]', "", "");
							$select = $select . ACTI_standard_field_select("destination", '', '[DESTINATION]', "", "");
							$select = $select . ACTI_standard_field_select("etablissement_provenance", '', '[ETABLISSEMENT_PROVENANCE]', "", "");
							$select = $select . ACTI_standard_field_select("etablissement_destination", '', '[ETABLISSEMENT_DESTINATION]', "", "");

							$select = $select . ACTI_standard_field_select("etat_sejour", '', '[ETAT_SEJOUR]', "", "");
                            $select = $select . ACTI_standard_field_select("v_risque_1.risque", '', '[RISQUE]', "", "");

							// Le filtre sur le statut du séjour est explicité ci-dessous car les filtres '[PERIODE]' et '[TOPERIODE]'
							// ne sont pas re-parsés quand on passe par la fonction ACTI_standard_field_select()
					
							// Statut du séjour sur période -----------------------------------------------------------
							if ('[STATUT_SEJOUR]' != '-1') {
								switch('[STATUT_SEJOUR]') {
									case '1' :
										// Séjour entier sur période
										$select .= "
											AND (v_sejours_1.date_entree BETWEEN '[PERIODE]' AND '[TOPERIODE]')
											AND	(v_sejours_1.date_sortie BETWEEN '[PERIODE]' AND '[TOPERIODE]')
										";
										break;
									case '2' :
										// Sortie sur période
										$select .= "
											AND (v_sejours_1.date_sortie BETWEEN '[PERIODE]' AND '[TOPERIODE]')
										";
										break;
									case '3' :
										// Admission sur période
										$select .= "
											AND (v_sejours_1.date_entree BETWEEN '[PERIODE]' AND '[TOPERIODE]')
										";
										break;
									case '4' :
										// Admission hors période
										$select .= "
											AND (v_sejours_1.date_entree NOT BETWEEN '[PERIODE]' AND '[TOPERIODE]')
										";
										break;
									case '5' :
										// Sortie hors période
										$select .= "
											AND (v_sejours_1.date_sortie NOT BETWEEN '[PERIODE]' AND '[TOPERIODE]')
										";
										break;
								}
							}
							 
							return $select;
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
		</VIEWPROPERTIES>
		
		<SELECTIONS label="Filtre séjours" collapsible="true" displayText="= var display:String = '';
		
						if (SELECT.FINESS  != '-1') {
							display = display + '  Etablissement : #B#' + SELECT.FINESS_LABEL + '#/B#';
						}
						
						if (SELECT.RISQUE  != '-1') {
							display = display + '  Risque : #B#' + SELECT.RISQUE_LABEL + '#/B#';
						}
						
						if (SELECT.TYPESEJOUR != '-1') {
							display = display + '  Type séjour : #B#' + SELECT.TYPESEJOUR_LABEL + '#/B#';
						}
                        if (SELECT.FORMEACTIVITE != '-1') {
							display = display + '  Forme activité : #B#' + SELECT.FORMEACTIVITE_LABEL + '#/B#';
						}
						if (SELECT.FILIERESOINSEJOUR != '-1') {
							display = display + '  Filière soins séjour : #B#' + SELECT.FILIERESOINSEJOUR_LABEL + '#/B#';
						}
						if (SELECT.MODETRAITEMENT != '-1') {
							display = display + '  Mode de traitement : #B#' + SELECT.MODETRAITEMENT_LABEL + '#/B#';
						}
						var CKXNOSW:String = SELECT.CAS_C + SELECT.CAS_K + SELECT.CAS_X + SELECT.CAS_N + SELECT.CAS_O + SELECT.CAS_S + SELECT.CAS_W;
						if (CKXNOSW != 'CKXNOS*') {
							display += '  C.A.S. : #B#';

							var display_cas:String = '';
							var display_shortCas:String = '';
							if (SELECT.CAS_C == 'C') {
								display_cas += 'Chirurgie (C) ';
								display_shortCas += 'Chi (C) ';
							}
							if (SELECT.CAS_K == 'K') {
								display_cas += 'Techniques peu invasives (K) ';
								display_shortCas += 'Tech (K) ';
							}
							if (SELECT.CAS_X == 'X') {
								display_cas += 'Sans Acte classant (X) ';
								display_shortCas += 'Sans acte (X) ';
							}
							if (SELECT.CAS_N == 'N') {
								display_cas += 'Nouveaux-nés (N) ';
								display_shortCas += 'NN (N) ';
							}
							if (SELECT.CAS_O == 'O') {
								display_cas += 'Obstétrique ';
								display_shortCas += 'Obst (O) ';
							}
							if (SELECT.CAS_S == 'S') {
								display_cas += 'Séance (S) ';
								display_shortCas += 'Séance (S) ';
							}
							if (SELECT.CAS_W == '*') {
								display_cas += 'Non groupés ou Non PMSI ';
								display_shortCas += 'N/A (*) ';
							}
							
							if (display_cas.length > 50) {
								display += display_shortCas;
							}
							else {
								display += display_cas;
							}
							
							display += '#/B#';
						}
						
						if (SELECT.GHM  != '-1') {
							if (SELECT.GHM != 'SAISIECODE') {
								display = display + '  GHM : #B#' + SELECT.GHM_LABEL + '#/B#';
							}
							else {
								display = display + '  GHM : #B#' + SELECT.GHM_CODES + '#/B#';
							}
						}
						
						if (SELECT.GHS  != '-1') {
							if (SELECT.GHS != 'SAISIECODE') {
								display = display + '  GHS : #B#' + SELECT.GHS_LABEL + '#/B#';
							}
							else {
								display = display + '  GHS : #B#' + SELECT.GHS_CODES + '#/B#';
							}
						}
						if (SELECT.GME  != '-1') {
							if (SELECT.GME != 'SAISIECODE') {
								display = display + '  GME : #B#' + SELECT.GME_LABEL + '#/B#';
							}
							else {
								display = display + '  GME : #B#' + SELECT.GME_CODES + '#/B#';
							}
						}
						if (SELECT.SERVICE_SEJOUR  != '-1') {
							if (SELECT.SERVICE_SEJOUR != 'SAISIECODE') {
								display = display + '  [DICT.ACTI.SERVICE] sortie : #B#' + SELECT.SERVICE_SEJOUR_LABEL + '#/B#';
							}
							else {
								display = display + '  [DICT.ACTI.SERVICE] sortie : #B#' + SELECT.SERVICE_SEJOUR_CODES + '#/B#';
							}
						}
						if (SELECT.UF_SEJOUR  != '-1') {
							if (SELECT.UF_SEJOUR != 'SAISIECODE') {
								display = display + '  [DICT.ACTI.UF] sortie : #B#' + SELECT.UF_SEJOUR_LABEL + '#/B#';
							}
							else {
								display = display + '  [DICT.ACTI.UF] sortie : #B#' + SELECT.UF_SEJOUR_CODES + '#/B#';
							}
						}
						if (SELECT.ACTIVITE_SEJOUR  != '-1') {
							if (SELECT.ACTIVITE_SEJOUR != 'SAISIECODE') {
								display = display + '  [DICT.ACTI.ACTIVITE] sortie : #B#' + SELECT.ACTIVITE_SEJOUR_LABEL + '#/B#';
							}
							else {
								display = display + '  [DICT.ACTI.ACTIVITE] sortie : #B#' + SELECT.ACTIVITE_SEJOUR_CODES + '#/B#';
							}
						}
						if (SELECT.ETAGE_SEJOUR  != '-1') {
							if (SELECT.ETAGE_SEJOUR != 'SAISIECODE') {
								display = display + '  [DICT.ACTI.ETAGE] sortie : #B#' + SELECT.ETAGE_SEJOUR_LABEL + '#/B#';
							}
							else {
								display = display + '  [DICT.ACTI.ETAGE] sortie : #B#' + SELECT.ETAGE_SEJOUR_CODES + '#/B#';
							}
						}
						if (SELECT.MEDECIN_SEJOUR  != '-1') {
							if (SELECT.MEDECIN_SEJOUR != 'SAISIECODE') {
								if (SELECT.MEDECIN_SEJOUR.toString().substr(0,2) != 'SP') {
									display = display + '  Médecin séjour: #B#' + SELECT.MEDECIN_SEJOUR_LABEL + '#/B#';
								}
								else {
									display = display + '  Spécialité médecin séjour: #B#' + SELECT.MEDECIN_SEJOUR_LABEL + '#/B#';
								}
							}
							else {
								display = display + '  Médecin séjour : #B#' + SELECT.MEDECIN_SEJOUR_CODES + '#/B#';
							}
						}
						if (SELECT.BUDGET_CLE  != '-1') {
							if (SELECT.BUDGET_CLE != 'SAISIECODE') {
								display = display + '  Clé budgétaire : #B#' + SELECT.BUDGET_CLE_LABEL + '#/B#';
							}
							else {
								display = display + '  Clé budgétaire : #B#' + SELECT.BUDGET_CLE_CODES + '#/B#';
							}
						}
						if (SELECT.PARAMETRE_PERSONNALISE_SEJOUR_1  != '-1') {
							display = display + '  [DICT.ACTI.PARAMETRE_PERSONNALISE_SEJOUR_1] : #B#' + SELECT.PARAMETRE_PERSONNALISE_SEJOUR_1_LABEL + '#/B#';
						}
						if (SELECT.PARAMETRE_PERSONNALISE_SEJOUR_2  != '-1') {
							display = display + '  [DICT.ACTI.PARAMETRE_PERSONNALISE_SEJOUR_2] : #B#' + SELECT.PARAMETRE_PERSONNALISE_SEJOUR_2_LABEL + '#/B#';
						}
						if (SELECT.MCO_M + SELECT.MCO_C + SELECT.MCO_O + SELECT.MCO_S + SELECT.MCO_H != 'MCOS*') {
							display += '  ASO : #B#';
							if (SELECT.MCO_M + SELECT.MCO_C + SELECT.MCO_O + SELECT.MCO_S == 'MCOS') {
								display += 'M.C.O. ';
							}
							else {
								if (SELECT.MCO_M == 'M') {
									display += 'Médecine ';
								}
								if (SELECT.MCO_C == 'C') {
									display += 'Chirurgie ';
								}
								if (SELECT.MCO_O == 'O') {
									display += 'Obstétrique ';
								}
								if (SELECT.MCO_S == 'S') {
									display += 'Séance ';
								}
								if (SELECT.MCO_H == '*') {
									display += 'Non groupés ou Non PMSI ';
								}
							}
							display += '#/B#';
						}
						if (SELECT.T_DUREE_SEJOUR  != '-1') {
							display += '  Durée séjour : #B#';
							if (SELECT.T_DUREE_SEJOUR != 'I') {
								display += SELECT.T_DUREE_OCCUP_LABEL;
							}
							else {
								if (SELECT.DUREE_SEJOUR != '') {
									if (SELECT.DUREE_SEJOUR2 != '') {
										display += '#GE# ' + SELECT.DUREE_SEJOUR + ' et #LE# ' + SELECT.DUREE_SEJOUR2 + ' jour(s)';
									}
									else {
										display += '#GE# ' + SELECT.DUREE_SEJOUR + ' jour(s)';
									}
								}
								else {
									display += '#LE# ' + SELECT.DUREE_SEJOUR2 + ' jour(s)';
								}
							}
							display += '#/B#';
						}
						
						if (SELECT.PROVIDER  != '-1') {
							display = display + '  Logiciel administratif : #B#' + SELECT.PROVIDER_LABEL + '#/B#';
						}
						
						if (SELECT.HEURE_ENTREE  != '-1') {
							if (SELECT.HEURE_ENTREE_OPERATOR == '1') {
								display = display + '  Heure d\'entrée : #B# Avant ' + SELECT.HEURE_ENTREE_FIELD1_LABEL + '#/B#';
							}
							else if (SELECT.HEURE_ENTREE_OPERATOR == '2') {
								display = display + '  Heure d\'entrée : #B# Après ' + SELECT.HEURE_ENTREE_FIELD1_LABEL + '#/B#';
							}
							else {
								display = display + '  Heure d\'entrée : #B# Entre ' + SELECT.HEURE_ENTREE_FIELD1_LABEL + ' et ' + SELECT.HEURE_ENTREE_FIELD2_LABEL + '#/B#';
							}
						}
						
						if (SELECT.HEURE_SORTIE  != '-1') {
							if (SELECT.HEURE_SORTIE_OPERATOR == '1') {
								display = display + '  Heure de sortie : #B# Avant ' + SELECT.HEURE_SORTIE_FIELD1_LABEL + '#/B#';
							}
							else if (SELECT.HEURE_SORTIE_OPERATOR == '2') {
								display = display + '  Heure de sortie : #B# Après ' + SELECT.HEURE_SORTIE_FIELD1_LABEL + '#/B#';
							}
							else {
								display = display + '  Heure de sortie : #B# Entre ' + SELECT.HEURE_SORTIE_FIELD1_LABEL + ' et ' + SELECT.HEURE_SORTIE_FIELD2_LABEL + '#/B#';
							}
						}
						if (SELECT.MODE_ENTREE  != '-1') {
							display = display + '  Mode entrée : #B#' + SELECT.MODE_ENTREE_LABEL + '#/B#';
						}
						if (SELECT.PROVENANCE  != '-1') {
							display = display + '  Provenance : #B#' + SELECT.PROVENANCE_LABEL + '#/B#';
						}
						if (SELECT.ETABLISSEMENT_PROVENANCE  != '-1') {
							display = display + '  Etablissement d\'origine: #B#' + SELECT.ETABLISSEMENT_DESTINATION_LABEL + '#/B#';
						}
						if (SELECT.MODE_SORTIE  != '-1') {
							display = display + '  Mode sortie : #B#' + SELECT.MODE_SORTIE_LABEL + '#/B#';
						}
						if (SELECT.DESTINATION  != '-1') {
							display = display + '  Destination : #B#' + SELECT.DESTINATION_LABEL + '#/B#';
						}
						if (SELECT.ETABLISSEMENT_DESTINATION  != '-1') {
							display = display + '  Etablissement de destination: #B#' + SELECT.ETABLISSEMENT_DESTINATION_LABEL + '#/B#';
						}
						if (SELECT.ETAT_SEJOUR  != '-1') {
							display += '  Etat séjour : #B#'+SELECT.ETAT_SEJOUR_LABEL+'#/B#';
						}
						if (SELECT.STATUT_SEJOUR  != '-1') {
							display += '  Statut séjour : #B#'+SELECT.STATUT_SEJOUR_LABEL+'#/B#';
						}
						
						if (display != '') {
							display = '#B#Filtres séjours#/B# = ' + display;
						}
						return display;
						" 
				>
			<GROUP>
				<FIELD name="TYPESEJOUR" label="Type séjour" UI="combo" tree="true" globalListProvider="TYPESEJOUR" width="400" default="-1" showIfNotDefault="true" />
			</GROUP>
            <GROUP>
				<FIELD name="FORMEACTIVITE" label="Forme d'activité" UI="combo" tree="true" globalListProvider="FORMEACTIVITE" width="400" default="-1" showIfNotDefault="true" />
			</GROUP>
			<GROUP>
				<FIELD name="FILIERESOINSEJOUR" label="Filière de soin" UI="combo" tree="true" globalListProvider="FILIERESOIN" width="400" default="-1" showIfNotDefault="true" />
			</GROUP>			
			<GROUP>
				<FIELD name="UF_SEJOUR" label="[DICT.ACTI.UF] sortie" UI="combo" tree="true" width="400" default="-1" globalListProvider="UF" showIfNotDefault="true" />
				<FIELD name="UF_SEJOUR_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.UF_SEJOUR == 'SAISIECODE' " />
			</GROUP>
			<GROUP>
				<FIELD name="MEDECIN_SEJOUR" label="Médecin séjour" UI="combo" tree="true" width="400" default="-1" 
					globalListProvider="MEDECINSSEJOUR" showIfNotDefault="true"
					visible="= VIEW.CONTEXTE != 'OCCUPATION'"/>
				<FIELD name="MEDECIN_SEJOUR_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.MEDECIN_SEJOUR == 'SAISIECODE' " />
			</GROUP>
			<GROUP label="Etablissement">
				<FIELD name="FINESS" label="" UI="combo" width="400" tree="true" default="-1" globalListProvider="FINESS" showIfNotDefault="true" />
			</GROUP>
		</SELECTIONS>

		<QUERIES>
		</QUERIES>
	
	</COMPONENT>

	<COMPONENT name="FILTRES_SEJOURS_RAPPORTS_SELECTIONS" label="Filtre séjours pour rapports" >
	
		<VIEWPROPERTIES>
		
		
			<PROPERTY name="BUDGET_SELECT">
				<value>
					<![CDATA[
						[EVAL 
							$BUDGET_select = "";
							$BUDGET_select = $BUDGET_select . ACTI_standard_field_select("budget_cle", 't_budget_cle', '[BUDGET_CLE]', '[BUDGET_CLE_CODES]', "");
	
							return $BUDGET_select;
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
		
			
		
			<PROPERTY name="TYPESEJOUR_SELECT">
				<value>
					<![CDATA[
						[EVAL 
							if (substr('[TYPESEJOUR]',0,2) == 'DT') { ACTI_standard_field_select("type_sejour", '', '[TYPESEJOUR]', "", "");}
							return '';
						EVAL]
					]]>
				</value>
			</PROPERTY>
            
            <PROPERTY name="FORMEACTIVITE_SELECT">
				<value>
					<![CDATA[
						[EVAL 
							if (substr('[FORMEACTIVITE]',0,2) == 'DT') {return 'AND forme_activite_id = ' . substr('[FORMEACTIVITE]',2);}
							return '';
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="FINESS_SELECT">
				<value>
					<![CDATA[
						[EVAL 
							if (substr('[FINESS]',0,2) == 'DT') {return 'AND finess_id = ' . substr('[FINESS]',2);}
							return '';
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="ETAGE_PLACES_SELECT">
				<value>
					<![CDATA[
						[EVAL 
							$PLACE_select = "";
							
							$TSE_select = ACTI_standard_field_select("type_sejour", '', '[TYPESEJOUR]', "", "");
							$MTR_select = ACTI_standard_field_select("mode_traitement", '', '[MODETRAITEMENT]', "", "");
							$FIN_select = ACTI_standard_field_select("finess", '', '[FINESS]', "", "");
							
                            $mode = substr('[ETAGE_SEJOUR]', 0, 2); 
							$oid = substr('[ETAGE_SEJOUR]',2);
                            if ($mode == 'LS') {
                                $section = ACTI_get_section_id('[ETAGE_SEJOUR]');
                                $oid = ACTI_get_classe_oid('[ETAGE_SEJOUR]');
                            }
							$ETA_select = "";
							if ($mode == 'LI') {$ETA_select = "etage_id = ANY (array(SELECT to_id FROM activite.t_listes_contenu WHERE liste_id = $oid)::bigint[])";}
							if ($mode == 'LS') {$ETA_select = "etage_section_id[" . $section . "] = $oid";}
							if ($mode == 'SL') {$ETA_select = "etage_id != ALL (array(SELECT to_id FROM activite.t_listes_contenu WHERE liste_id = $oid)::bigint[])";}
							if ($mode == 'ET') {$ETA_select = "etage_id = $oid";}
							if ('[ETAGE_SEJOUR]' == 'SAISIECODE') {
								$ETA_select = "etage_id = ANY (array(SELECT oid FROM activite.t_etages WHERE " . sql_codes_list_a('[ETAGE_SEJOUR_CODES]', 'code') . ")::bigint[])"; 
							}
							
							$mode = substr('[SERVICE_SEJOUR]', 0, 2); 
							$oid = substr('[SERVICE_SEJOUR]',2);
                            if ($mode == 'LS') {
                                $section = ACTI_get_section_id('[SERVICE_SEJOUR]');
                                $oid = ACTI_get_classe_oid('[SERVICE_SEJOUR]');
                            }
							$SER_select = "";
							if ($mode == 'LI') {$SER_select = "service_id = ANY (array(SELECT to_id FROM activite.t_listes_contenu WHERE liste_id = $oid)::bigint[])";}
							if ($mode == 'LS') {$SER_select = "service_section_id[" . $section . "] = $oid";}
							if ($mode == 'SL') {$SER_select = "service_id != ALL (array(SELECT to_id FROM activite.t_listes_contenu WHERE liste_id = $oid)::bigint[])";}
							if ($mode == 'SF') {$SER_select = "service_id = $oid";}
							if ('[SERVICE_SEJOUR]' == 'SAISIECODE') {
								$SER_select = "service_id = ANY (array(SELECT oid FROM activite.t_services_facturation WHERE " . sql_codes_list_a('[SERVICE_SEJOUR_CODES]', 'code') . ")::bigint[])"; 
							}
							
							$mode = substr('[UF_SEJOUR]', 0, 2); 
							$oid = substr('[UF_SEJOUR]',2);
                            if ($mode == 'LS') {
                                $section = ACTI_get_section_id('[UF_SEJOUR]');
                                $oid = ACTI_get_classe_oid('[UF_SEJOUR]');
                            }
							$UF_select = "";
							if ($mode == 'LI') {$UF_select = "uf_id = ANY (array(SELECT to_id FROM activite.t_listes_contenu WHERE liste_id = $oid)::bigint[])";}
							if ($mode == 'LS') {$UF_select = "uf_section_id[" . $section . "] = $oid";}
							if ($mode == 'SL') {$UF_select = "uf_id != ALL (array(SELECT to_id FROM activite.t_listes_contenu WHERE liste_id = $oid)::bigint[])";}
							if ($mode == 'UF') {$UF_select = "uf_id = $oid";}
							if ('[UF_SEJOUR]' == 'SAISIECODE') {
								$UF_select = "uf_id = ANY (array(SELECT oid FROM activite.t_unites_fonctionnelles WHERE " . sql_codes_list_a('[UF_SEJOUR_CODES]', 'code') . ")::bigint[])"; 
							}
							
							$mode = substr('[UM_SEJOUR]', 0, 2); 
							$oid = substr('[UM_SEJOUR]',2);
                            if ($mode == 'LS') {
                                $section = ACTI_get_section_id('[UM_SEJOUR]');
                                $oid = ACTI_get_classe_oid('[UM_SEJOUR]');
                            }
							$UM_select = "";
							$select_id2 = substr('[UM_SEJOUR]',2);
							$select_id3 = substr('[UM_SEJOUR]',3);
							if ($mode == 'LI') {$UM_select = "um_id = ANY (array(SELECT to_id FROM activite.t_listes_contenu WHERE liste_id = $oid)::bigint[])";}
							if ($mode == 'LS') {$UM_select = "um_section_id[" . $section . "] = $oid";}
							if ($mode == 'SL') {$UM_select = "um_id != ALL (array(SELECT to_id FROM activite.t_listes_contenu WHERE liste_id = $oid)::bigint[])";}
							if ($mode == 'UM') {$UM_select = "um_id = $oid";}
							if ('[UM_SEJOUR]' == 'SAISIECODE') {
								$UM_select = "um_id = ANY (array(SELECT oid FROM activite.t_unites_fonctionnelles WHERE " . sql_codes_list_a('[UM_SEJOUR_CODES]', 'code') . ")::bigint[])"; 
							}
							
							
							$PLACE_select = "AND (parent_type = 'ETA'";
							if ($ETA_select != "") {
								$PLACE_select = "$PLACE_select AND $ETA_select";
							}
							$PLACE_select = "$PLACE_select OR parent_type = 'SER'";
							if ($SER_select != "") {
								$PLACE_select = "$PLACE_select AND $SER_select";
							}
							$PLACE_select = "$PLACE_select OR parent_type = 'UF'";
							if ($UF_select != "") {
								$PLACE_select = "$PLACE_select AND $UF_select";
							}
							$PLACE_select = "$PLACE_select OR parent_type = 'UM'";
							if ($UM_select != "") {
								$PLACE_select = "$PLACE_select AND $UM_select";
							}
							$PLACE_select = "$PLACE_select)";
							
							if ($TSE_select  != "") {
								$PLACE_select = "$PLACE_select $TSE_select";
							}
							if ($MTR_select  != "") {
								$PLACE_select = "$PLACE_select $MTR_select";
							}
							if ($FIN_select  != "") {
								$PLACE_select = "$PLACE_select $FIN_select";
							}
							
							return $PLACE_select;
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="MODETRAITEMENT_SELECT">
				<value>
					<![CDATA[
						[EVAL 
							if (substr('[MODETRAITEMENT]',0,2) == 'MT') {return 'AND mode_traitement_id = ' . substr('[MODETRAITEMENT]',2);}
							return '';
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GHS_SELECT">
				<value>
					<![CDATA[
						[EVAL 
							if (substr('[GHS]',0,2) == 'LI') {return 'AND ghs_id = ANY (array(SELECT to_id FROM activite.t_listes_contenu WHERE liste_id = ' . substr('[GHS]',2) . ')::bigint[])';}
							if (substr('[GHS]',0,2) == 'SL') {return 'AND ghs_id != ALL (array(SELECT to_id FROM activite.t_listes_contenu WHERE liste_id = ' . substr('[GHS]',2) . ')::bigint[])';}
							if (substr('[GHS]',0,2) == 'GH') {return 'AND ghs_id = ' . substr('[GHS]',2);}
							if ('[GHS]' == 'SAISIECODE') {
								return " AND ghs_id = ANY (array(SELECT oid FROM base.t_ghs WHERE " . sql_codes_list_n('[GHS_CODES]', 'code') . ")::bigint[])"; 
							}
							return '';
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="SERVICE_SEJOUR_SELECT">
				<value>
					<![CDATA[
						[EVAL 
							$mode = substr('[SERVICE_SEJOUR]', 0, 2); 
							$oid = substr('[SERVICE_SEJOUR]',2);
                            if ($mode == 'LS') {
                                $section = ACTI_get_section_id('[SERVICE_SEJOUR]');
                                $oid = ACTI_get_classe_oid('[SERVICE_SEJOUR]');
                            }
                            if ($mode == 'LI') {return "AND lieu_reference_service_id = ANY (array(SELECT to_id FROM activite.t_listes_contenu WHERE liste_id = $oid)::bigint[])";}
							if ($mode == 'LS') {return "AND lieu_reference_service_section_id[" . $section . "] = $oid";}
							if ($mode == 'SL') {return "AND lieu_reference_service_id != ALL (array(SELECT to_id FROM activite.t_listes_contenu WHERE liste_id = $oid)::bigint[])";}
							if ($mode == 'SF') {return "AND lieu_reference_service_id = $oid";}
							if ('[SERVICE_SEJOUR]' == 'SAISIECODE') {
								return " AND lieu_reference_service_id = ANY (array(SELECT oid FROM activite.t_services_facturation WHERE " . sql_codes_list_a('[SERVICE_SEJOUR_CODES]', 'code') . ")::bigint[])"; 
							}
							return '';
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="UF_SEJOUR_SELECT">
				<value>
					<![CDATA[
						[EVAL 
							$mode = substr('[UF_SEJOUR]', 0, 2); 
							$oid = substr('[UF_SEJOUR]',2);
                            if ($mode == 'LS') {
                                $section = ACTI_get_section_id('[UF_SEJOUR]');
                                $oid = ACTI_get_classe_oid('[UF_SEJOUR]');
                            }
                            if ($mode == 'LI') {return "AND lieu_reference_unite_fonctionnelle_id = ANY (array(SELECT to_id FROM activite.t_listes_contenu WHERE liste_id = $oid)::bigint[])";}
							if ($mode == 'LS') {return "AND lieu_reference_unite_fonctionnelle_section_id[" . $section . "] = $oid";}
							if ($mode == 'SL') {return "AND lieu_reference_unite_fonctionnelle_id != ALL (array(SELECT to_id FROM activite.t_listes_contenu WHERE liste_id = $oid)::bigint[])";}
							if ($mode == 'SF') {return "AND lieu_reference_unite_fonctionnelle_id = $oid";}
							if ('[UF_SEJOUR]' == 'SAISIECODE') {
								return " AND lieu_reference_unite_fonctionnelle_id = ANY (array(SELECT oid FROM activite.t_unites_fonctionnelles WHERE " . sql_codes_list_a('[UF_SEJOUR_CODES]', 'code') . ")::bigint[])"; 
							}
							return '';
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="ACTIVITE_SEJOUR_SELECT">
				<value>
					<![CDATA[
						[EVAL 
							if (substr('[ACTIVITE_SEJOUR]',0,2) == 'LI') {return 'AND lieu_reference_activite_id = ANY (array(SELECT to_id FROM activite.t_listes_contenu WHERE liste_id = ' . substr('[ACTIVITE_SEJOUR]',2) . ')::bigint[])';}
							if (substr('[ACTIVITE_SEJOUR]',0,2) == 'SL') {return 'AND lieu_reference_activite_id != ALL (array(SELECT to_id FROM activite.t_listes_contenu WHERE liste_id = ' . substr('[ACTIVITE_SEJOUR]',2) . ')::bigint[])';}
							if (substr('[ACTIVITE_SEJOUR]',0,2) == 'AC') {return 'AND lieu_reference_activite_id = ' . substr('[ACTIVITE_SEJOUR]',2);}
							if ('[ACTIVITE_SEJOUR]' == 'SAISIECODE') {
								return " AND lieu_reference_activite_id = ANY (array(SELECT oid FROM activite.t_activites WHERE " . sql_codes_list_a('[ACTIVITE_SEJOUR_CODES]', 'code') . ")::bigint[])"; 
							}
							return '';
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="ETAGE_SEJOUR_SELECT">
				<value>
					<![CDATA[
						[EVAL 
							$mode = substr('[ETAGE_SEJOUR]', 0, 2); 
							$oid = substr('[ETAGE_SEJOUR]',2);
                            if ($mode == 'LS') {
                                $section = ACTI_get_section_id('[ETAGE_SEJOUR]');
                                $oid = ACTI_get_classe_oid('[ETAGE_SEJOUR]');
                            }
                            if ($mode == 'LI') {return "AND lieu_reference_etage_id = ANY (array(SELECT to_id FROM activite.t_listes_contenu WHERE liste_id = $oid)::bigint[])";}
							if ($mode == 'LS') {return "AND lieu_reference_etage_section_id[" . $section . "] = $oid";}
							if ($mode == 'SL') {return "AND lieu_reference_etage_id != ALL (array(SELECT to_id FROM activite.t_listes_contenu WHERE liste_id = $oid)::bigint[])";}
							if ($mode == 'ET') {return "AND lieu_reference_etage_id = $oid";}
							if ('[ETAGE_SEJOUR]' == 'SAISIECODE') {
								return " AND lieu_reference_etage_id = ANY (array(SELECT oid FROM activite.t_etages WHERE " . sql_codes_list_a('[ETAGE_SEJOUR_CODES]', 'code') . ")::bigint[])"; 
							}
							return '';
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="MEDECIN_SEJOUR_SELECT">
				<value>
					<![CDATA[
						[EVAL 
							$mode = substr('[MEDECIN_SEJOUR]', 0, 2); 
							$oid = substr('[MEDECIN_SEJOUR]',2);
                            if ($mode == 'LS') {
                                $section = ACTI_get_section_id('[MEDECIN_SEJOUR]');
                                $oid = ACTI_get_classe_oid('[MEDECIN_SEJOUR]');
                            }
                            if ($mode == 'LI') {return "AND medecin_adm_reference_id = ANY (array(SELECT to_id FROM activite.t_listes_contenu WHERE liste_id = $oid)::bigint[])";}
							if ($mode == 'LS') {return "AND medecin_adm_reference_section_id[" . $section . "] = $oid";}
							if ($mode == 'SL') {return "AND medecin_adm_reference_id != ALL (array(SELECT to_id FROM activite.t_listes_contenu WHERE liste_id = $oid)::bigint[])";}
							if ($mode == 'MA') {return "AND medecin_adm_reference_id = $oid";}
							if ($mode == 'MD') {return "AND medecin_reference_id = $oid";}
							if ($mode == 'SP') {return "AND medecin_reference_specialite_id = $oid";}
							if ('[MEDECIN_SEJOUR]' == 'SAISIECODE') {
								return " AND medecin_adm_reference_id = ANY (array(SELECT oid FROM activite.t_medecins_administratifs WHERE " . sql_codes_list_a('[MEDECIN_SEJOUR_CODES]', 'code') . ")::bigint[])"; 
							}
							return '';
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			
			
			
			<PROPERTY name="RAPPORT_SELECT">
				<value>
					<![CDATA[
						[EVAL 
							$select = 
								"[VIEW.TYPESEJOUR_SELECT] [VIEW.FORMEACTIVITE_SELECT] [VIEW.SERVICE_SEJOUR_SELECT] [VIEW.UF_SEJOUR_SELECT] [VIEW.ACTIVITE_SEJOUR_SELECT]  
								[VIEW.ETAGE_SEJOUR_SELECT] [VIEW.MEDECIN_SEJOUR_SELECT] [VIEW.GHS_SELECT] [VIEW.MODETRAITEMENT_SELECT] [VIEW.FINESS_SELECT]" ;
								
								
							$select = $select . ACTI_standard_field_select("budget_cle", 't_budget_cle', '[BUDGET_CLE]', '[BUDGET_CLE_CODES]', "");
							$select = $select . ACTI_standard_field_select("cas", '', '[CAS_C][CAS_K][CAS_X][CAS_N][CAS_O][CAS_S][CAS_W]', "", "");
							$select = $select . ACTI_standard_field_select("ghm", 't_ghm_c', '[GHM]', '[GHM_CODES]', "");
							
							return $select;
						EVAL]
					]]>
				</value>
			</PROPERTY>

		</VIEWPROPERTIES>
	
		
		<SELECTIONS label="Filtres" displayText="= var display:String = '';
						if (SELECT.TYPESEJOUR != '-1') {
							display = display + '  Type séjour : #B#' + SELECT.TYPESEJOUR_LABEL + '#/B#';
						}
                        if (SELECT.FORMEACTIVITE != '-1') {
							display = display + '  Forme activité : #B#' + SELECT.FORMEACTIVITE_LABEL + '#/B#';
						}
						if (SELECT.FILIERESOINSEJOUR != '-1') {
							display = display + '  Filière soins séjour : #B#' + SELECT.FILIERESOINSEJOUR_LABEL + '#/B#';
						}
						if (SELECT.FINESS != '-1') {
							display = display + '  établissement : #B#' + SELECT.FINESS_LABEL + '#/B#';
						}
						if (SELECT.MODETRAITEMENT != '-1') {
							display = display + '  Mode de traitement : #B#' + SELECT.MODETRAITEMENT_LABEL + '#/B#';
						}
						if (SELECT.SERVICE_SEJOUR  != '-1') {
							if (SELECT.SERVICE_SEJOUR != 'SAISIECODE') {
								display = display + '  [DICT.ACTI.SERVICE] : #B#' + SELECT.SERVICE_SEJOUR_LABEL + '#/B#';
							}
							else {
								display = display + '  [DICT.ACTI.SERVICE] : #B#' + SELECT.SERVICE_SEJOUR_CODES + '#/B#';
							}
						}
						if (SELECT.UF_SEJOUR  != '-1') {
							if (SELECT.UF_SEJOUR != 'SAISIECODE') {
								display = display + '  [DICT.ACTI.UF] : #B#' + SELECT.UF_SEJOUR_LABEL + '#/B#';
							}
							else {
								display = display + '  [DICT.ACTI.UF] : #B#' + SELECT.UF_SEJOUR_CODES + '#/B#';
							}
						}
						if (SELECT.ACTIVITE_SEJOUR  != '-1') {
							if (SELECT.ACTIVITE_SEJOUR != 'SAISIECODE') {
								display = display + '  [DICT.ACTI.ACTIVITE] : #B#' + SELECT.ACTIVITE_SEJOUR_LABEL + '#/B#';
							}
							else {
								display = display + '  [DICT.ACTI.ACTIVITE] : #B#' + SELECT.ACTIVITE_SEJOUR_CODES + '#/B#';
							}
						}
						if (SELECT.ETAGE_SEJOUR  != '-1') {
							if (SELECT.ETAGE_SEJOUR != 'SAISIECODE') {
								display = display + '  [DICT.ACTI.ETAGE] : #B#' + SELECT.ETAGE_SEJOUR_LABEL + '#/B#';
							}
							else {
								display = display + '  [DICT.ACTI.ETAGE] : #B#' + SELECT.ETAGE_SEJOUR_CODES + '#/B#';
							}
						}
						if (SELECT.GHS  != '-1') {
							if (SELECT.GHS != 'SAISIECODE') {
								display = display + '  GHS : #B#' + SELECT.GHS_LABEL + '#/B#';
							}
							else {
								display = display + '  GHS : #B#' + SELECT.GHS_CODES + '#/B#';
							}
						}
						if (SELECT.PARAMETRE_PERSONNALISE_SEJOUR_1  != '-1') {
							display = display + '  [DICT.ACTI.PARAMETRE_PERSONNALISE_SEJOUR_1] : #B#' + SELECT.PARAMETRE_PERSONNALISE_SEJOUR_1_LABEL + '#/B#';
						}
						if (SELECT.PARAMETRE_PERSONNALISE_SEJOUR_2  != '-1') {
							display = display + '  [DICT.ACTI.PARAMETRE_PERSONNALISE_SEJOUR_2] : #B#' + SELECT.PARAMETRE_PERSONNALISE_SEJOUR_2_LABEL + '#/B#';
						}
						if (SELECT.MEDECIN_SEJOUR  != '-1') {
							if (SELECT.MEDECIN_SEJOUR != 'SAISIECODE') {
								if (SELECT.MEDECIN_SEJOUR.toString().substr(0,2) != 'SP') {
									display = display + '  Médecin séjour: #B#' + SELECT.MEDECIN_SEJOUR_LABEL + '#/B#';
								}
								else {
									display = display + '  Spécialité médecin séjour: #B#' + SELECT.MEDECIN_SEJOUR_LABEL + '#/B#';
								}
							}
							else {
								display = display + '  Médecin séjour : #B#' + SELECT.MEDECIN_SEJOUR_CODES + '#/B#';
							}
						}
						if (SELECT.BUDGET_CLE  != '-1') {
							if (SELECT.BUDGET_CLE != 'SAISIECODE') {
								display = display + '  Clé budgétaire : #B#' + SELECT.BUDGET_CLE_LABEL + '#/B#';
							}
							else {
								display = display + '  Clé budgétaire : #B#' + SELECT.BUDGET_CLE_CODES + '#/B#';
							}
						}
						
						
						if (display != '') {
							display = '#B#Filtres#/B# = ' + display;
						}
						return display;
						" 
				>
				
			<GROUP>
				<FIELD name="TYPESEJOUR" label="Type séjour" UI="combo" tree="true" globalListProvider="TYPESEJOUR" width="200" default="-1" showIfNotDefault="true" />
			</GROUP>
            <GROUP>
				<FIELD name="FORMEACTIVITE" label="Forme d'activité" UI="combo" tree="true" globalListProvider="FORMEACTIVITE" width="200" default="-1" showIfNotDefault="true" />
			</GROUP>
			<GROUP>
				<FIELD visible="false" name="FILIERESOINSEJOUR" label="Filière de soin" UI="combo" tree="true" globalListProvider="FILIERESOIN" width="400" default="-1" showIfNotDefault="true" />
			</GROUP>
			<GROUP>
				<FIELD name="MODETRAITEMENT" label="Mode de traitement" UI="combo" globalListProvider="MODESTRAITEMENT" width="300" default="-1" showIfNotDefault="true" />
			</GROUP>
			<GROUP>
				<FIELD name="SERVICE_SEJOUR" label="[DICT.ACTI.SERVICE] sortie" UI="combo" tree="true" width="400" default="-1" globalListProvider="SERVICES" showIfNotDefault="true" />
				<FIELD name="SERVICE_SEJOUR_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.SERVICE_SEJOUR == 'SAISIECODE' " />
			</GROUP>
			<GROUP>
				<FIELD name="UF_SEJOUR" label="[DICT.ACTI.UF] sortie" UI="combo" tree="true" width="400" default="-1" globalListProvider="UF" showIfNotDefault="true" />
				<FIELD name="UF_SEJOUR_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.UF_SEJOUR == 'SAISIECODE' " />
			</GROUP>
			<GROUP>
				<FIELD name="ACTIVITE_SEJOUR" label="[DICT.ACTI.ACTIVITE] sortie" UI="combo" tree="true" width="400" default="-1" globalListProvider="ACTIVITES" showIfNotDefault="true" />
				<FIELD name="ACTIVITE_SEJOUR_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.ACTIVITE_SEJOUR == 'SAISIECODE' " />
			</GROUP>
			<GROUP>
				<FIELD name="ETAGE_SEJOUR" label="[DICT.ACTI.ETAGE] sortie" UI="combo" width="200" tree="true" default="-1" globalListProvider="ETAGES" showIfNotDefault="true" />
				<FIELD name="ETAGE_SEJOUR_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.ETAGE_SEJOUR == 'SAISIECODE' " />
			</GROUP>
			
			<GROUP label="C.A.S.">
				<FIELD name="CAS_C" label="Chirurgie (C)" UI="check" selectedValue="C" unselectedValue="" default="C" showIfNotDefault="true" />
				<FIELD name="CAS_K" label="Techniques peu invasives (K)" UI="check" selectedValue="K" unselectedValue="" default="K" showIfNotDefault="true" />
				<FIELD name="CAS_X" label="Sans Acte classant (X)" UI="check" selectedValue="X" unselectedValue="" default="X" showIfNotDefault="true" />
			</GROUP>
			<GROUP label = " ">
				<FIELD name="CAS_N" label="Nouveaux-nés (N)" UI="check" selectedValue="N" unselectedValue="" default="N" showIfNotDefault="true" />
				<FIELD name="CAS_O" label="Obstétrique (O)" UI="check" selectedValue="O" unselectedValue="" default="O" showIfNotDefault="true" />
				<FIELD name="CAS_S" label="Séances (S)" UI="check" selectedValue="S" unselectedValue="" default="S" showIfNotDefault="true" />
				<FIELD name="CAS_W" label="Non groupés ou Non PMSI" UI="check" selectedValue="*" unselectedValue="" default="*" showIfNotDefault="true" />
			</GROUP>
			<GROUP>
				<FIELD name="GHM" label="GHM" UI="combo" tree="true" width="400" default="-1" globalListProvider="GHM" showIfNotDefault="true" />
				<FIELD name="GHM_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.GHM == 'SAISIECODE' " />
			</GROUP>
			<GROUP>
				<FIELD name="GME" label="GME" UI="combo" tree="true" width="400" default="-1" globalListProvider="GME" showIfNotDefault="true" />
				<FIELD name="GME_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.GME == 'SAISIECODE' " />
			</GROUP>
			<GROUP>
				<FIELD name="GHS" label="GHS" UI="combo" tree="true" width="400" default="-1" globalListProvider="GHS" showIfNotDefault="true" />
				<FIELD name="GHS_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.GHS == 'SAISIECODE' " />
			</GROUP>
			<GROUP label="Etablissement">
				<FIELD name="FINESS" label="" UI="combo" width="200" tree="true" default="-1" globalListProvider="FINESS" showIfNotDefault="true"  />
			</GROUP>
			<GROUP>
				<FIELD name="PARAMETRE_PERSONNALISE_SEJOUR_1" label="[DICT.ACTI.PARAMETRE_PERSONNALISE_SEJOUR_1]" 
					UI="combo" tree="true" width="400" default="-1" 
					globalListProvider="PARAMETRE_PERSONNALISE_SEJOUR_1" 
					visible="= '[DICT.ACTI.PARAMETRE_PERSONNALISE_SEJOUR_1]' != 'NULL'"
					showIfNotDefault="true" />
				<FIELD name="PARAMETRE_PERSONNALISE_SEJOUR_1_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.PARAMETRE_PERSONNALISE_SEJOUR_1 == 'SAISIECODE' " />
			</GROUP>
			<GROUP>
				<FIELD name="PARAMETRE_PERSONNALISE_SEJOUR_2" label="[DICT.ACTI.PARAMETRE_PERSONNALISE_SEJOUR_2]" 
					UI="combo" tree="true" width="400" default="-1" 
					globalListProvider="PARAMETRE_PERSONNALISE_SEJOUR_2" 
					visible="= '[DICT.ACTI.PARAMETRE_PERSONNALISE_SEJOUR_2]' != 'NULL'"
					showIfNotDefault="true" />
				<FIELD name="PARAMETRE_PERSONNALISE_SEJOUR_2_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.PARAMETRE_PERSONNALISE_SEJOUR_1 == 'SAISIECODE' " />
			</GROUP>
			<GROUP>
				<FIELD name="MEDECIN_SEJOUR" label="Médecin séjour" UI="combo" tree="true" width="400" default="-1" globalListProvider="MEDECINSSEJOUR" showIfNotDefault="true" />
				<FIELD name="MEDECIN_SEJOUR_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.MEDECIN_SEJOUR == 'SAISIECODE' " />
			</GROUP>
			
			<GROUP>
				<FIELD name="BUDGET_CLE" label="Clé budgétaire" UI="combo" tree="true" width="400" default="-1" 
					globalListProvider="BUDGET_CLE" showIfNotDefault="true"/>
				<FIELD name="BUDGET_CLE_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.BUDGET_CLE == 'SAISIECODE' " />
			</GROUP>
			
		</SELECTIONS>

		<QUERIES />
	
	</COMPONENT>
	
	<COMPONENT name="FILTRES_MOUVEMENTS_SELECTIONS" label="Filtre mouvements" >
	
		<VIEWPROPERTIES>
		
			<PROPERTY name="ETAGE_PLACES_SELECT">
				<value>
					<![CDATA[
						[EVAL 
							$select = "";
							$TSE_select = ACTI_standard_field_select("type_sejour", '', '[TYPESEJOUR]', "", "");
							$MTR_select = ACTI_standard_field_select("mode_traitement", '', '[MODETRAITEMENT]', "", "");
							$FIN_select = ACTI_standard_field_select("finess", '', '[FINESS]', "", "");
							
							$SER_select = ACTI_standard_field_select("service", 't_services_facturation', '[SERVICE_MOUVEMENT]', '[SERVICE_MOUVEMENT_CODES]', "");
							$UF_select = ACTI_standard_field_select("uf", 't_unites_fonctionnelles', '[UF_MOUVEMENT]', '[UF_MOUVEMENT_CODES]', "");
							$UM_select = ACTI_standard_field_select("um", 't_unites_medicales', '[UM_MOUVEMENT]', '[UM_MOUVEMENT_CODES]', "");
							$ETA_select = ACTI_standard_field_select("etage", 't_etages', '[ETAGE_MOUVEMENT]', '[ETAGE_MOUVEMENT_CODES]', "");
							
							if ($MTR_select  != "") {
								$SER_select = "$SER_select $MTR_select";
							}
							
							$select = "AND (parent_type = 'ETA'";
							if ($ETA_select != "") {
								$select = "$select $ETA_select";
							}
							$select = "$select OR parent_type = 'SER'";
							if ($SER_select != "") {
								$select = "$select $SER_select";
							}
							$select = "$select OR parent_type = 'UF'";
							if ($UF_select != "") {
								$select = "$select $UF_select";
							}
							$select = "$select OR parent_type = 'UM'";
							if ($UM_select != "") {
								$select = "$select $UM_select";
							}
							$select = "$select)";
							
							if ($TSE_select  != "") {
								$select = "$select $TSE_select";
							} 
							if ($FIN_select  != "") {
								$select = "$select $FIN_select";
							}
							 
							return $select;
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			
			<PROPERTY name="MOUVEMENTS_SELECT">
				<value>
					<![CDATA[
						[EVAL 
						
							$select = "";
							$select = $select . ACTI_standard_field_select("pole", 't_pole', '[POLE_MOUVEMENT]', "", "");
							$select = $select . ACTI_standard_field_select("lieu_service", 't_services_facturation', '[SERVICE_MOUVEMENT]', '[SERVICE_MOUVEMENT_CODES]', "");
							$select = $select . ACTI_standard_field_select("lieu_unite_fonctionnelle", 't_unites_fonctionnelles', '[UF_MOUVEMENT]', '[UF_MOUVEMENT_CODES]', "");
							$select = $select . ACTI_standard_field_select("lieu_unite_medicale", 't_unites_medicales', '[UM_MOUVEMENT]', '[UM_MOUVEMENT_CODES]', "");
							$select = $select . ACTI_standard_field_select("lieu_activite", 't_activites', '[ACTIVITE_MOUVEMENT]', '[ACTIVITE_MOUVEMENT_CODES]', "");
							$select = $select . ACTI_standard_field_select("lieu_etage", 't_etages', '[ETAGE_MOUVEMENT]', '[ETAGE_MOUVEMENT_CODES]', "");
							$select = $select . ACTI_standard_field_select("lieu_lit", 't_lits', '[LIT_MOUVEMENT]', '[LIT_MOUVEMENT_CODES]', "");
                            $select = $select . ACTI_standard_field_select("lieu_gir", 't_gir', '[GIR_MOUVEMENT]', '[GIR_MOUVEMENT_CODES]', "");
							
							$select = $select . ACTI_standard_field_select("medecin_adm_mouvement", 't_medecins_administratifs', '[MEDECIN_MOUVEMENT]', '[MEDECIN_MOUVEMENT_CODES]', "");
							
							 
							return $select;

						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="PERIODE_ENHANCED">
				<value>
					<![CDATA[
						[EVAL 
							
							//<?
							
							// On distingue le cas où l'analyse ne se fait que sur un jour car j'ai constaté que les requêtes prenaient plus de temps
							// pour les vues sur l'occupation quand les deux paramètres du BETWEEN (en date) étaient égaux
							if ('[PERIODE]' == '[TOPERIODE]') {
								$select = " date = '[PERIODE]' ";
							}
							else {
								$select = " date BETWEEN '[PERIODE]' AND '[TOPERIODE]' ";
							};
							 
							return $select;
							
							?>
						EVAL]
					]]>
				</value>
			</PROPERTY>
			<PROPERTY dataLink="OPTADM_DAYOUT_VIEWPROPERTIES" nameField="name" valueField="value" />
		</VIEWPROPERTIES>
		
		<SELECTIONS label="Filtre mouvements" collapsible="true" displayText="= var display:String = '';
					
						if (SELECT.POLE_MOUVEMENT  != '-1') {
							display = display + '  Pole : #B#' + SELECT.POLE_MOUVEMENT_LABEL + '#/B#';
						}
                        if (SELECT.SERVICE_MOUVEMENT  != '-1') {
							if (SELECT.SERVICE_MOUVEMENT != 'SAISIECODE') {
								display = display + '  [DICT.ACTI.SERVICE] : #B#' + SELECT.SERVICE_MOUVEMENT_LABEL + '#/B#';
							}
							else {
								display = display + '  [DICT.ACTI.SERVICE] : #B#' + SELECT.SERVICE_MOUVEMENT_CODES + '#/B#';
							}
						}
						if (SELECT.ACTIVITE_MOUVEMENT  != '-1') {
							if (SELECT.ACTIVITE_MOUVEMENT != 'SAISIECODE') {
								display = display + '  [DICT.ACTI.ACTIVITE] : #B#' + SELECT.ACTIVITE_MOUVEMENT_LABEL + '#/B#';
							}
							else {
								display = display + '  [DICT.ACTI.ACTIVITE] : #B#' + SELECT.ACTIVITE_MOUVEMENT_CODES + '#/B#';
							}
						}
						if (SELECT.ETAGE_MOUVEMENT  != '-1') {
							if (SELECT.ETAGE_MOUVEMENT != 'SAISIECODE') {
								display = display + '  [DICT.ACTI.ETAGE] : #B#' + SELECT.ETAGE_MOUVEMENT_LABEL + '#/B#';
							}
							else {
								display = display + '  [DICT.ACTI.ETAGE] : #B#' + SELECT.ETAGE_MOUVEMENT_CODES + '#/B#';
							}
						}
						if (SELECT.LIT_MOUVEMENT  != '-1') {
							if (SELECT.LIT_MOUVEMENT != 'SAISIECODE') {
								display = display + '  Lit : #B#' + SELECT.LIT_MOUVEMENT_LABEL + '#/B#';
							}
							else {
								display = display + '  Lit : #B#' + SELECT.LIT_MOUVEMENT_CODES + '#/B#';
							}
						}
						if (SELECT.UM_MOUVEMENT  != '-1') {
							if (SELECT.UM_MOUVEMENT != 'SAISIECODE') {
								display = display + '  [DICT.ACTI.UM] : #B#' + SELECT.UM_MOUVEMENT_LABEL + '#/B#';
							}
							else {
								display = display + '  [DICT.ACTI.UM] : #B#' + SELECT.UM_MOUVEMENT_CODES + '#/B#';
							}
						}
						if (SELECT.UF_MOUVEMENT  != '-1') {
							if (SELECT.UF_MOUVEMENT != 'SAISIECODE') {
								display = display + '  [DICT.ACTI.UF] : #B#' + SELECT.UF_MOUVEMENT_LABEL + '#/B#';
							}
							else {
								display = display + '  [DICT.ACTI.UF] : #B#' + SELECT.UF_MOUVEMENT_CODES + '#/B#';
							}
						}
						if (SELECT.MEDECIN_MOUVEMENT  != '-1') {
							if (SELECT.MEDECIN_MOUVEMENT != 'SAISIECODE') {
								if (SELECT.MEDECIN_MOUVEMENT.toString().substr(0,2) != 'SP') {
									display = display + '  Médecin séjour: #B#' + SELECT.MEDECIN_MOUVEMENT_LABEL + '#/B#';
								}
								else {
									display = display + '  Spécialité médecin séjour: #B#' + SELECT.MEDECIN_MOUVEMENT_LABEL + '#/B#';
								}
							}
							else {
								display = display + '  Médecin séjour : #B#' + SELECT.MEDECIN_MOUVEMENT_CODES + '#/B#';
							}
						}
                        if (SELECT.GIR_MOUVEMENT  != '-1') {
							if (SELECT.GIR_MOUVEMENT != 'SAISIECODE') {
								display = display + '  GIR : #B#' + SELECT.GIR_MOUVEMENT_LABEL + '#/B#';
							}
							else {
								display = display + '  GIR : #B#' + SELECT.GIR_MOUVEMENT_CODES + '#/B#';
							}
						}
						
						
						if (display != '') {
							display = '#B#Filtres mouvements#/B# = ' + display;
						}
						return display;
						" 
				>
			
            <GROUP>
				<FIELD name="POLE_MOUVEMENT" label="Pole" UI="combo" tree="true" width="300" default="-1" globalListProvider="POLE" showIfNotDefault="true" />
			</GROUP>
			<GROUP>
				<FIELD name="SERVICE_MOUVEMENT" label="[DICT.ACTI.SERVICE]" UI="combo" tree="true" width="300" default="-1" globalListProvider="SERVICES" showIfNotDefault="true" />
				<FIELD name="SERVICE_MOUVEMENT_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.SERVICE_MOUVEMENT == 'SAISIECODE' " />
			</GROUP>
			<GROUP>
				<FIELD name="ACTIVITE_MOUVEMENT" label="[DICT.ACTI.ACTIVITE]" UI="combo" tree="true" width="300" default="-1" globalListProvider="ACTIVITES" showIfNotDefault="true" />
				<FIELD name="ACTIVITE_MOUVEMENT_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.ACTIVITE_MOUVEMENT == 'SAISIECODE' " />
			</GROUP>
			<GROUP>
				<FIELD name="ETAGE_MOUVEMENT" label="[DICT.ACTI.ETAGE]" UI="combo" tree="true" width="300" default="-1" globalListProvider="ETAGES" showIfNotDefault="true" />
				<FIELD name="ETAGE_MOUVEMENT_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.ETAGE_MOUVEMENT == 'SAISIECODE' " />
			</GROUP>
			<GROUP>
				<FIELD name="LIT_MOUVEMENT" label="Lit" UI="combo" tree="true" width="300" default="-1" globalListProvider="LITS" showIfNotDefault="true" />
				<FIELD name="LIT_MOUVEMENT_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.LIT_MOUVEMENT == 'SAISIECODE' " />
			</GROUP>
			<GROUP>
				<FIELD name="UM_MOUVEMENT" label="[DICT.ACTI.UM]" UI="combo" tree="true" width="300" default="-1" globalListProvider="UM" showIfNotDefault="true" />
				<FIELD name="UM_MOUVEMENT_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.UM_MOUVEMENT == 'SAISIECODE' " />
			</GROUP>
			<GROUP>
				<FIELD name="UF_MOUVEMENT" label="[DICT.ACTI.UF]" UI="combo" tree="true" width="300" default="-1" globalListProvider="UF" showIfNotDefault="true" />
				<FIELD name="UF_MOUVEMENT_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.UF_MOUVEMENT == 'SAISIECODE' " />
			</GROUP>
			<GROUP>
				<FIELD name="MEDECIN_MOUVEMENT" label="Médecin" UI="combo" tree="true" width="300" default="-1" globalListProvider="MEDECINSSEJOUR" showIfNotDefault="true" />
				<FIELD name="MEDECIN_MOUVEMENT_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.MEDECIN_MOUVEMENT == 'SAISIECODE' " />
			</GROUP>
            <GROUP>
				<FIELD name="GIR_MOUVEMENT" label="GIR" UI="combo" tree="true" width="300" default="-1" globalListProvider="GIR" showIfNotDefault="true" />
				<FIELD name="GIR_MOUVEMENT_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.GIR == 'SAISIECODE' " />
			</GROUP>
			
		</SELECTIONS>
		<QUERIES>
			<QUERY type="propertiesLink" name="OPTADM_DAYOUT_VIEWPROPERTIES" forRows="false"> 
				<SQL>
					<select>
						<![CDATA[
							SELECT	
								code,
								valeur2
							FROM activite.t_divers WHERE code = 'OPTADM_DAYOUT'
						]]>
					</select>
					<FIELDS>
						<FIELD name="name" />
						<FIELD name="value" />
					</FIELDS>
				</SQL>
			</QUERY>
		</QUERIES>
	</COMPONENT>
	
    <COMPONENT name="FILTRES_PASSAGES_SELECTIONS" label="Filtre passage" >
		<VIEWPROPERTIES>
			<PROPERTY name="PASSAGES_SELECT">
				<value>
					<![CDATA[
						[EVAL 
						
							$select = "";
							
							$select = $select . ACTI_standard_field_select("lieu_service_passage", 'activite.v_mouvements_sejour_2', '[SERVICE_PASSAGE]', '[SERVICE_PASSAGE_CODES]', "");
							$select = $select . ACTI_standard_field_select("lieu_unite_fonctionnelle_passage", 'activite.v_mouvements_sejour_2', '[UF_PASSAGE]', '[UF_PASSAGE_CODES]', "");
							$select = $select . ACTI_standard_field_select("lieu_unite_medicale_passage", 'activite.v_mouvements_sejour_2', '[UM_PASSAGE]', '[UM_PASSAGE_CODES]', "");
							$select = $select . ACTI_standard_field_select("lieu_etage_passage", 'activite.v_mouvements_sejour_2', '[ETAGE_PASSAGE]', '[ETAGE_PASSAGE_CODES]', "");
								 
							return $select;

						EVAL]
					]]>
				</value>
			</PROPERTY>
			
		</VIEWPROPERTIES>
		<SELECTIONS label="Filtre passage (tous les séjour qui sont passés par)" collapsible="true" displayText="= var display:String = '';
						
							if (SELECT.SERVICE_PASSAGE  != '-1') {
								if (SELECT.SERVICE_PASSAGE != 'SAISIECODE') {
									display = display + '  [DICT.ACTI.SERVICE] : #B#' + SELECT.SERVICE_PASSAGE_LABEL + '#/B#';
								}
								else {
									display = display + '  [DICT.ACTI.SERVICE] : #B#' + SELECT.SERVICE_PASSAGE_CODES + '#/B#';
								}
							}
							if (SELECT.ETAGE_PASSAGE  != '-1') {
								if (SELECT.ETAGE_PASSAGE != 'SAISIECODE') {
									display = display + '  [DICT.ACTI.ETAGE] : #B#' + SELECT.ETAGE_PASSAGE_LABEL + '#/B#';
								}
								else {
									display = display + '  [DICT.ACTI.ETAGE] : #B#' + SELECT.ETAGE_PASSAGE_CODES + '#/B#';
								}
							}
							if (SELECT.UM_PASSAGE  != '-1') {
								if (SELECT.UM_PASSAGE != 'SAISIECODE') {
									display = display + '  [DICT.ACTI.UM] : #B#' + SELECT.UM_PASSAGE_LABEL + '#/B#';
								}
								else {
									display = display + '  [DICT.ACTI.UM] : #B#' + SELECT.UM_PASSAGE_CODES + '#/B#';
								}
							}
							if (SELECT.UF_PASSAGE  != '-1') {
								if (SELECT.UF_PASSAGE != 'SAISIECODE') {
									display = display + '  [DICT.ACTI.UF] : #B#' + SELECT.UF_PASSAGE_LABEL + '#/B#';
								}
								else {
									display = display + '  [DICT.ACTI.UF] : #B#' + SELECT.UF_PASSAGE_CODES + '#/B#';
								}
							}							
							if (display != '') {
								display = '#B#Filtres passages#/B# = ' + display;
							}
							return display;
							" 
					>
				
				<GROUP>
					<FIELD name="SERVICE_PASSAGE" label="[DICT.ACTI.SERVICE]" UI="combo" tree="true" width="300" default="-1" globalListProvider="SERVICES" showIfNotDefault="true" />
					<FIELD name="SERVICE_PASSAGE_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.SERVICE_PASSAGE == 'SAISIECODE' " />
				</GROUP>
				<GROUP>
					<FIELD name="ETAGE_PASSAGE" label="[DICT.ACTI.ETAGE]" UI="combo" tree="true" width="300" default="-1" globalListProvider="ETAGES" showIfNotDefault="true" />
					<FIELD name="ETAGE_PASSAGE_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.ETAGE_PASSAGE == 'SAISIECODE' " />
				</GROUP>
				<GROUP>
					<FIELD name="UM_PASSAGE" label="[DICT.ACTI.UM]" UI="combo" tree="true" width="300" default="-1" globalListProvider="UM" showIfNotDefault="true" />
					<FIELD name="UM_PASSAGE_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.UM_PASSAGE == 'SAISIECODE' " />
				</GROUP>
				<GROUP>
					<FIELD name="UF_PASSAGE" label="[DICT.ACTI.UF]" UI="combo" tree="true" width="300" default="-1" globalListProvider="UF" showIfNotDefault="true" />
					<FIELD name="UF_PASSAGE_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.UF_PASSAGE == 'SAISIECODE' " />
				</GROUP>
				
		</SELECTIONS>
	</COMPONENT>
	
    <COMPONENT name="FILTRES_PATIENTS_SELECTIONS" label="Filtre patients" >
	
		<VIEWPROPERTIES>
		
			<PROPERTY name="PATIENTS_SELECT">
				<value>
					<![CDATA[
						[EVAL 
							$select = "";
							
							$select = $select . ACTI_standard_field_select("sexe", 'v_sejours_1', '[SEXE_PATIENT]', "", "");
							$select = $select . ACTI_standard_field_select("age", 'v_sejours_1', '[T_AGE_PATIENT]|[AGE_PATIENT]|[AGE_PATIENT2]', '', "");
							$select = $select . ACTI_standard_field_select("code_postal", 'v_codes_postaux_2', '[ORIGINEGEO_PATIENT]', '', "");
							return $select;
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
		</VIEWPROPERTIES>
		
		<SELECTIONS label="Filtre patients" collapsible="true" displayText="= var display:String = '';
						
						if (SELECT.SEXE_PATIENT  != '-1') {
							display = display + '  Sexe : #B#' + SELECT.SEXE_PATIENT_LABEL + '#/B#';
						}

						if (SELECT.T_AGE_PATIENT  != '-1') {
							var debut:String = '  Age : #B#';
							var fin:String = '#/B#';
							if (SELECT.T_AGE_PATIENT != 'I') {
								display += debut + SELECT.T_AGE_PATIENT_LABEL + fin;
							}
							else {
								if (SELECT.AGE_PATIENT != '') {
									if (SELECT.AGE_PATIENT2 != '') {
										display += debut + '#GE# ' + SELECT.AGE_PATIENT + ' et #LE# ' + SELECT.AGE_PATIENT2 + ' an(s)' + fin;
									}
									else {
										display += debut + '#GE# ' + SELECT.AGE_PATIENT + ' an(s)' + fin;
									}
								}
								else {
									if (SELECT.AGE_PATIENT2 != '') {
										display += debut + '#LE# ' + SELECT.AGE_PATIENT2 + ' an(s)' + fin;
									}
								}
							}
						}
						if (SELECT.ORIGINEGEO_PATIENT  != '-1') {
							display = display + '  originaire de : #B#';
							if (SELECT.ORIGINEGEO_PATIENT.substr(0,2) == 'TS') {
								display = display + 'Territoire de santé ' + SELECT.ORIGINEGEO_PATIENT_LABEL;
							}
							else if (SELECT.ORIGINEGEO_PATIENT.substr(0,2) == 'GP') {
								display = display + 'Code PMSI  ' + SELECT.ORIGINEGEO_PATIENT_LABEL;
							}
							else {
								if (SELECT.ORIGINEGEO_PATIENT.substr(0,2) == 'CP' || SELECT.ORIGINEGEO_PATIENT.substr(0,2) == 'LS') {
									display = display + 'Code postal ' + SELECT.ORIGINEGEO_PATIENT_LABEL;
								}
								else {
									display = display + SELECT.ORIGINEGEO_PATIENT_LABEL;
								}
							}
							display = display + '#/B#';
						}
						
						if (display != '') {
							display = '#B#Filtres patients#/B# = ' + display;
						}
						return display;
		">
			
			<GROUP>
				<FIELD name="T_AGE_PATIENT" label="Age" UI="combo" width="200" default="-1" tree="true" globalListProvider="T_AGE" showIfNotDefault="true" />
				<FIELD name="AGE_PATIENT" label="Age" UI="numberInterval" width="100" default="" default2="" hidable="= SELECT.T_AGE_PATIENT == '-1'" visible="= SELECT.T_AGE_PATIENT == 'I'" />
			</GROUP>			
			<GROUP>
				<FIELD name="SEXE_PATIENT" label="Sexe" UI="combo" tree="true" globalListProvider="SEXE" width="200" default="-1" showIfNotDefault="true" />
			</GROUP>
			<GROUP>
				<FIELD name="ORIGINEGEO_PATIENT" label="Origine Géo." UI="combo" tree="true" globalListProvider="CODE_POSTAL" width="200" default="-1" showIfNotDefault="true" />
			</GROUP>
			
		</SELECTIONS>

		<QUERIES />
		
	</COMPONENT>
	
    <COMPONENT name="FILTRES_PRESTATIONS_CA_SELECTIONS" label="Prestations" >
	
		<VIEWPROPERTIES>
				
			<PROPERTY name="PRESTATIONS_CA_SELECT">
				<value>
					<![CDATA[
						[EVAL 
							$select = "";

							$select = $select . ACTI_standard_field_select("rubrique_facturation", 't_rubriques_facturation', '[RUBRIQUE]', '[RUBRIQUE_CODES]', "");
							$select = $select . ACTI_standard_field_select("rubrique_facturation", 't_rubriques_facturation', '[RUBRIQUE_CA]', '[RUBRIQUE_CODES]', "");
							
							return $select;
						EVAL]
					]]>
				</value>
			</PROPERTY>
            
			
		</VIEWPROPERTIES>
		
		<SELECTIONS label="Filtre prestations" collapsible="true" displayText="= var display:String = '';
					
						if (SELECT.RUBRIQUE  != '-1') {
							display = display + '  Rubrique facturée : #B#' + SELECT.RUBRIQUE_LABEL + '#/B#';
						}
						if (SELECT.RUBRIQUE_CA  != '-1') {
							display = display + '  Rubrique facturée : #B#' + SELECT.RUBRIQUE_CA_LABEL + '#/B#';
						}
						if (SELECT.TYPESEJOUR != '-1') {
							display = display + '  Type séjour : #B#' + SELECT.TYPESEJOUR_LABEL + '#/B#';
						}
						if (SELECT.MEDECIN_SEJOUR  != '-1') {
							if (SELECT.MEDECIN_SEJOUR != 'SAISIECODE') {
								if (SELECT.MEDECIN_SEJOUR.toString().substr(0,2) != 'SP') {
									display = display + '  Médecin séjour: #B#' + SELECT.MEDECIN_SEJOUR_LABEL + '#/B#';
								}
								else {
									display = display + '  Spécialité médecin séjour: #B#' + SELECT.MEDECIN_SEJOUR_LABEL + '#/B#';
								}
							}
							else {
								display = display + '  Médecin séjour : #B#' + SELECT.MEDECIN_SEJOUR_CODES + '#/B#';
							}
						}
                        if (SELECT.FORMEACTIVITE != '-1') {
							display = display + '  Forme activité : #B#' + SELECT.FORMEACTIVITE_LABEL + '#/B#';
						}
						if (SELECT.FINESS  != '-1') {
							display = display + '  Etablissement : #B#' + SELECT.FINESS_LABEL + '#/B#';
						}

						return display;
						" >

			<GROUP visible="false">
				<FIELD name="RUBRIQUE" label="Rubrique facturée" UI="combo" tree="true" width="400" default="-1" globalListProvider="RUBRIQUES" showIfNotDefault="true"  visible="false"/>
				<FIELD name="RUBRIQUE_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.RUBRIQUE == 'SAISIECODE' "  />
			</GROUP>

		</SELECTIONS>
		
		<QUERIES />
		
	</COMPONENT>

	
	<COMPONENT name="FILTRES_PRESTATIONS_SELECTIONS" label="Prestations" >
	
		<VIEWPROPERTIES>
				
			<PROPERTY name="PRESTATIONS_SELECT">
				<value>
					<![CDATA[
						[EVAL 
							$select = "";
							$select = $select . ACTI_standard_field_select("prestation", 't_prestations', '[PRESTATION]', '[PRESTATION_CODES]', "");
							$select = $select . ACTI_standard_field_select("rubrique_facturation", 't_rubriques_facturation', '[RUBRIQUE]', '[RUBRIQUE_CODES]', "");
							$select = $select . ACTI_standard_field_select("rubrique_facturation", 't_rubriques_facturation', '[RUBRIQUE_CA]', '[RUBRIQUE_CODES]', "");
							$select = $select . ACTI_standard_field_select("compte_produit", 't_compte', '[COMPTE]', '[COMPTE_CODES]', "");
							$select = $select . ACTI_standard_field_select("compte_produit_analytique", 't_compte', '[COMPTANA]', '[COMPTANA_CODES]', "");
							$select = $select . ACTI_standard_field_select("lpp", 't_lpp_c', '[LPP]', '[LPP_CODES]', "");
							$select = $select . ACTI_standard_field_select("ucd", 't_ucd_c', '[UCD]', '[UCD_CODES]', "");
							
                            $select = $select . ACTI_standard_field_select("pole", 't_pole', '[POLE_MOUVEMENT]', "", "");
							$select = $select . ACTI_standard_field_select("lieu_ligne_service", 't_services_facturation', '[SERVICE_MOUVEMENT]', '[SERVICE_MOUVEMENT_CODES]', "");
							$select = $select . ACTI_standard_field_select("lieu_ligne_activite", 't_activites', '[ACTIVITE_MOUVEMENT]', '[ACTIVITE_MOUVEMENT_CODES]', "");
							$select = $select . ACTI_standard_field_select("lieu_ligne_etage", 't_etages', '[ETAGE_MOUVEMENT]', '[ETAGE_MOUVEMENT_CODES]', "");
							$select = $select . ACTI_standard_field_select("lieu_ligne_unite_medicale", 't_unites_medicales', '[UM_MOUVEMENT]', '[UM_MOUVEMENT_CODES]', "");
							$select = $select . ACTI_standard_field_select("lieu_ligne_unite_fonctionnelle", 't_unites_fonctionnelles', '[UF_MOUVEMENT]', '[UF_MOUVEMENT_CODES]', "");
							$select = $select . ACTI_standard_field_select("lieu_ligne_lit", 't_lits', '[LIT_MOUVEMENT]', '[LIT_MOUVEMENT_CODES]', "");
							
							return $select;
						EVAL]
					]]>
				</value>
			</PROPERTY>
            
            <PROPERTY name="MOUVEMENTS_SELECT">
				<value>
					<![CDATA[
						[EVAL 
							$select = "";
                            
							$select = $select . ACTI_standard_field_select("lieu_service", 't_services_facturation', '[SERVICE_MOUVEMENT]', '[SERVICE_MOUVEMENT_CODES]', "");
							$select = $select . ACTI_standard_field_select("lieu_activite", 't_activites', '[ACTIVITE_MOUVEMENT]', '[ACTIVITE_MOUVEMENT_CODES]', "");
							$select = $select . ACTI_standard_field_select("lieu_etage", 't_etages', '[ETAGE_MOUVEMENT]', '[ETAGE_MOUVEMENT_CODES]', "");
							$select = $select . ACTI_standard_field_select("lieu_unite_medicale", 't_unites_medicales', '[UM_MOUVEMENT]', '[UM_MOUVEMENT_CODES]', "");
							$select = $select . ACTI_standard_field_select("lieu_unite_fonctionnelle", 't_unites_fonctionnelles', '[UF_MOUVEMENT]', '[UF_MOUVEMENT_CODES]', "");
							$select = $select . ACTI_standard_field_select("lieu_lit", 't_lits', '[LIT_MOUVEMENT]', '[LIT_MOUVEMENT_CODES]', "");
							
							return $select;
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
		</VIEWPROPERTIES>
		
		<SELECTIONS label="Filtre prestations" collapsible="true" displayText="= var display:String = '';
					
						if (SELECT.PRESTATION  != '-1') {
							if (SELECT.PRESTATION === 'SAISIECODE') {
								display = display + '  Prestation : #B#' + SELECT.PRESTATION_CODES + '#/B#';
							}
							else {
								display = display + '  Prestation : #B#' + SELECT.PRESTATION_LABEL + '#/B#';
							}
						}
						if (SELECT.RUBRIQUE  != '-1') {
							if (SELECT.RUBRIQUE === 'SAISIECODE') {
								display = display + '  Rubrique facturée : #B#' + SELECT.RUBRIQUE_CODES + '#/B#';
							} else {
								display = display + '  Rubrique facturée : #B#' + SELECT.RUBRIQUE_LABEL + '#/B#';
							}
						}						
						if (SELECT.RUBRIQUE_CA  != '-1') {
							display = display + '  Rubrique facturée : #B#' + SELECT.RUBRIQUE_CA_LABEL + '#/B#';
						}
						if (SELECT.LPP  != '-1') {
							if (SELECT.LPP != 'SAISIECODE') {
								display = display + '  LPP : #B#' + SELECT.LPP_LABEL + '#/B#';
							}
							else {
								display = display + '  LPP : #B#' + SELECT.LPP_CODES + '#/B#';
							}
						}
						if (SELECT.UCD  != '-1') {
							if (SELECT.UCD != 'SAISIECODE') {
								display = display + '  UCD : #B#' + SELECT.UCD_LABEL + '#/B#';
							}
							else {
								display = display + '  UCD : #B#' + SELECT.UCD_CODES + '#/B#';
							}
						}
						if (SELECT.COMPTE  != '-1') {
							display = display + '  Compte : #B#' + SELECT.COMPTE_LABEL + '#/B#';
						}
						if (SELECT.COMPTANA  != '-1') {
							display = display + '  Compte analytique : #B#' + SELECT.COMPTANA_LABEL + '#/B#';
						}
						if (SELECT.POLE_MOUVEMENT  != '-1') {
							display = display + '  Pole : #B#' + SELECT.POLE_MOUVEMENT_LABEL + '#/B#';
						}
						if (SELECT.SERVICE_MOUVEMENT  != '-1') {
							if (SELECT.SERVICE_MOUVEMENT != 'SAISIECODE') {
								display = display + '  [DICT.ACTI.SERVICE] : #B#' + SELECT.SERVICE_MOUVEMENT_LABEL + '#/B#';
							}
							else {
								display = display + '  [DICT.ACTI.SERVICE] : #B#' + SELECT.SERVICE_MOUVEMENT_CODES + '#/B#';
							}
						}
						if (SELECT.ACTIVITE_MOUVEMENT  != '-1') {
							if (SELECT.ACTIVITE_MOUVEMENT != 'SAISIECODE') {
								display = display + '  [DICT.ACTI.ACTIVITE] : #B#' + SELECT.ACTIVITE_MOUVEMENT_LABEL + '#/B#';
							}
							else {
								display = display + '  [DICT.ACTI.ACTIVITE] : #B#' + SELECT.ACTIVITE_MOUVEMENT_CODES + '#/B#';
							}
						}
						if (SELECT.ETAGE_MOUVEMENT  != '-1') {
							if (SELECT.ETAGE_MOUVEMENT != 'SAISIECODE') {
								display = display + '  [DICT.ACTI.ETAGE] : #B#' + SELECT.ETAGE_MOUVEMENT_LABEL + '#/B#';
							}
							else {
								display = display + '  [DICT.ACTI.ETAGE] : #B#' + SELECT.ETAGE_MOUVEMENT_CODES + '#/B#';
							}
						}
						if (SELECT.UM_MOUVEMENT  != '-1') {
							if (SELECT.UM_MOUVEMENT != 'SAISIECODE') {
								display = display + '  [DICT.ACTI.UM] : #B#' + SELECT.UM_MOUVEMENT_LABEL + '#/B#';
							}
							else {
								display = display + '  [DICT.ACTI.UM] : #B#' + SELECT.UM_MOUVEMENT_CODES + '#/B#';
							}
						}
						if (SELECT.UF_MOUVEMENT  != '-1') {
							if (SELECT.UF_MOUVEMENT != 'SAISIECODE') {
								display = display + '  Unité fonctionnelle : #B#' + SELECT.UF_MOUVEMENT_LABEL + '#/B#';
							}
							else {
								display = display + '  Unité fonctionnelle : #B#' + SELECT.UF_MOUVEMENT_CODES + '#/B#';
							}
						}
						if (SELECT.LIT_MOUVEMENT  != '-1') {
							if (SELECT.LIT_MOUVEMENT != 'SAISIECODE') {
								display = display + '  Lit : #B#' + SELECT.LIT_MOUVEMENT_LABEL + '#/B#';
							}
							else {
								display = display + '  Lit : #B#' + SELECT.LIT_MOUVEMENT_CODES + '#/B#';
							}
						}
						if (display != '') {
							display = '#B#Filtres prestations#/B# = ' + display;
						}
						return display;
						" >
			<GROUP>
				<FIELD name="PRESTATION" label="Prestation" UI="combo" tree="true" width="400" default="-1" globalListProvider="PRESTATIONS" showIfNotDefault="true" />
				<FIELD name="PRESTATION_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.PRESTATION == 'SAISIECODE' " />
			</GROUP>
			<GROUP>
				<FIELD name="RUBRIQUE" label="Rubrique facturée" UI="combo" tree="true" width="400" default="-1" globalListProvider="RUBRIQUES" showIfNotDefault="true" />
				<FIELD name="RUBRIQUE_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.RUBRIQUE == 'SAISIECODE' " />
			</GROUP>
			<GROUP>
				<FIELD name="LPP" label="LPP" UI="combo" tree="true" width="400" default="-1" globalListProvider="LPP" showIfNotDefault="true" />
				<FIELD name="LPP_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.LPP == 'SAISIECODE' " />
			</GROUP>
			<GROUP>
				<FIELD name="UCD" label="UCD" UI="combo" tree="true" width="400" default="-1" globalListProvider="UCD" showIfNotDefault="true" />
				<FIELD name="UCD_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.UCD == 'SAISIECODE' " />
			</GROUP>
			<GROUP>
				<FIELD name="COMPTE" label="Compte" UI="combo" tree="true" width="400" default="-1" globalListProvider="COMPTE" showIfNotDefault="true" />
				<FIELD name="COMPTE_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.COMPTE == 'SAISIECODE' " />
			</GROUP>
			<GROUP>
				<FIELD name="COMPTANA" label="Compte analytique" UI="combo" tree="true" width="400" default="-1" globalListProvider="COMPTE" showIfNotDefault="true" />
				<FIELD name="COMPTANA_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.COMPTANA == 'SAISIECODE' " />
			</GROUP>
            <GROUP>
				<FIELD name="POLE_MOUVEMENT" label="Pole" UI="combo" tree="true" width="400" default="-1" globalListProvider="POLE" showIfNotDefault="true" />
			</GROUP>
			<GROUP>
				<FIELD name="SERVICE_MOUVEMENT" label="[DICT.ACTI.SERVICE] mouvement" UI="combo" tree="true" width="400" default="-1" globalListProvider="SERVICES" showIfNotDefault="true" />
				<FIELD name="SERVICE_MOUVEMENT_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.SERVICE_MOUVEMENT == 'SAISIECODE' " />
			</GROUP>
			<GROUP>
				<FIELD name="ACTIVITE_MOUVEMENT" label="[DICT.ACTI.ACTIVITE] mouvement" UI="combo" tree="true" width="400" default="-1" globalListProvider="ACTIVITES" showIfNotDefault="true" />
				<FIELD name="ACTIVITE_MOUVEMENT_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.ACTIVITE_MOUVEMENT == 'SAISIECODE' " />
			</GROUP>
			<GROUP>
				<FIELD name="ETAGE_MOUVEMENT" label="[DICT.ACTI.ETAGE] mouvement" UI="combo" tree="true" width="400" default="-1" globalListProvider="ETAGES" showIfNotDefault="true" />
				<FIELD name="ETAGE_MOUVEMENT_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.ETAGE_MOUVEMENT == 'SAISIECODE' " />
			</GROUP>
			<GROUP>
				<FIELD name="UM_MOUVEMENT" label="[DICT.ACTI.UM]" UI="combo" tree="true" width="400" default="-1" globalListProvider="UM" showIfNotDefault="true" />
				<FIELD name="UM_MOUVEMENT_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.UM_MOUVEMENT == 'SAISIECODE' " />
			</GROUP>
			<GROUP>
				<FIELD name="UF_MOUVEMENT" label="[DICT.ACTI.UF]" UI="combo" tree="true" width="400" default="-1" globalListProvider="UF" showIfNotDefault="true" />
				<FIELD name="UF_MOUVEMENT_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.UF_MOUVEMENT == 'SAISIECODE' " />
			</GROUP>
			<GROUP>
				<FIELD name="LIT_MOUVEMENT" label="[DICT.ACTI.LIT]" UI="combo" tree="true" width="400" default="-1" globalListProvider="LITS" showIfNotDefault="true" />
				<FIELD name="LIT_MOUVEMENT_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.LIT_MOUVEMENT == 'SAISIECODE' " />
			</GROUP>
		</SELECTIONS>
		
		<QUERIES />
		
	</COMPONENT>
	
	<COMPONENT name="FILTRES_PRESTATIONS_H_SELECTIONS" label="Actes" >
	
		<VIEWPROPERTIES>
		
			
			<PROPERTY name="ACTES_SELECT">
				<value>
					<![CDATA[
						[EVAL 
						
							$select = "";
							$select = $select . ACTI_standard_field_select("acte", 't_actes_c', '[ACTE]', '[ACTE_CODES]', "");
							$select = $select . ACTI_standard_field_select("prestation", 't_prestations', '[PRESTATION]', '[PRESTATION_CODES]', "");
							$select = $select . ACTI_standard_field_select("protocole", 't_protocoles', '[PROTOCOLE]', '[PROTOCOLE_CODES]', "");
							
							$select = $select . ACTI_standard_field_select("medecin_adm_facture", 't_medecins_administratifs', '[MEDECINEXECUTANT]', '[MEDECINEXECUTANT_CODES]', "");
							
							$select = $select . ACTI_standard_field_select("lieu_ligne_service", 't_services_facturation', '[SERVICE_MOUVEMENT]', '[SERVICE_MOUVEMENT_CODES]', "");
							$select = $select . ACTI_standard_field_select("lieu_ligne_activite", 't_activites', '[ACTIVITE_MOUVEMENT]', '[ACTIVITE_MOUVEMENT_CODES]', "");
							$select = $select . ACTI_standard_field_select("lieu_ligne_etage", 't_etages', '[ETAGE_MOUVEMENT]', '[ETAGE_MOUVEMENT_CODES]', "");
							$select = $select . ACTI_standard_field_select("lieu_ligne_unite_medicale", 't_unites_medicales', '[UM_MOUVEMENT]', '[UM_MOUVEMENT_CODES]', "");
							$select = $select . ACTI_standard_field_select("lieu_ligne_unite_fonctionnelle", 't_unites_fonctionnelles', '[UF_MOUVEMENT]', '[UF_MOUVEMENT_CODES]', "");
							$select = $select . ACTI_standard_field_select("lieu_ligne_lit", 't_lits', '[LIT_MOUVEMENT]', '[LIT_MOUVEMENT_CODES]', "");

							return $select;
							
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			
			
			

		</VIEWPROPERTIES>
	
		
		<SELECTIONS label="Filtre actes" collapsible="true" displayText="= var display:String = '';
					
						if (SELECT.PRESTATION  != '-1') {
							if (SELECT.PRESTATION != 'SAISIECODE') {
								display = display + '  Prestation : #B#' + SELECT.PRESTATION_LABEL + '#/B#';
							}
							else {
								display = display + '  Prestation : #B#' + SELECT.PRESTATION_CODES + '#/B#';
							}
						}
						if (SELECT.ACTE  != '-1') {
							if (SELECT.ACTE != 'SAISIECODE') {
								display = display + '  Acte : #B#' + SELECT.ACTE_LABEL + '#/B#';
							}
							else {
								display = display + '  Acte : #B#' + SELECT.ACTE_CODES + '#/B#';
							}
						}
						if (SELECT.PROTOCOLE  != '-1') {
							if (SELECT.PROTOCOLE != 'SAISIECODE') {
								display = display + '  Protocole : #B#' + SELECT.PROTOCOLE_LABEL + '#/B#';
							}
							else {
								display = display + '  Protocole : #B#' + SELECT.PROTOCOLE_CODES + '#/B#';
							}
						}
						if (SELECT.MEDECINEXECUTANT  != '-1') {
							if (SELECT.MEDECINEXECUTANT != 'SAISIECODE') {
								if (SELECT.MEDECINEXECUTANT.toString().substr(0,2) != 'SP') {
									display = display + '  Médecin exécutant: #B#' + SELECT.MEDECINEXECUTANT_LABEL + '#/B#';
								}
								else {
									display = display + '  Spécialité médecin exécutant: #B#' + SELECT.MEDECINEXECUTANT_LABEL + '#/B#';
								}
							}
							else {
								display = display + '  Médecin exécutant : #B#' + SELECT.MEDECINEXECUTANT_CODES + '#/B#';
							}
						}
						if (SELECT.POLE_MOUVEMENT  != '-1') {
							display = display + '  Pole : #B#' + SELECT.POLE_MOUVEMENT_LABEL + '#/B#';
						}
						if (SELECT.SERVICE_MOUVEMENT  != '-1') {
							if (SELECT.SERVICE_MOUVEMENT != 'SAISIECODE') {
								display = display + '  [DICT.ACTI.SERVICE] : #B#' + SELECT.SERVICE_MOUVEMENT_LABEL + '#/B#';
							}
							else {
								display = display + '  [DICT.ACTI.SERVICE] : #B#' + SELECT.SERVICE_MOUVEMENT_CODES + '#/B#';
							}
						}
						if (SELECT.UF_MOUVEMENT  != '-1') {
							if (SELECT.UF_MOUVEMENT != 'SAISIECODE') {
								display = display + '  [DICT.ACTI.UF] : #B#' + SELECT.UF_MOUVEMENT_LABEL + '#/B#';
							}
							else {
								display = display + '  [DICT.ACTI.UF] : #B#' + SELECT.UF_MOUVEMENT_CODES + '#/B#';
							}
						}
						if (SELECT.LIT_MOUVEMENT  != '-1') {
							if (SELECT.LIT_MOUVEMENT != 'SAISIECODE') {
								display = display + '  Lit : #B#' + SELECT.LIT_MOUVEMENT_LABEL + '#/B#';
							}
							else {
								display = display + '  Lit : #B#' + SELECT.LIT_MOUVEMENT_CODES + '#/B#';
							}
						}
						if (SELECT.ACTIVITE_MOUVEMENT  != '-1') {
							if (SELECT.ACTIVITE_MOUVEMENT != 'SAISIECODE') {
								display = display + '  [DICT.ACTI.ACTIVITE] : #B#' + SELECT.ACTIVITE_MOUVEMENT_LABEL + '#/B#';
							}
							else {
								display = display + '  [DICT.ACTI.ACTIVITE] : #B#' + SELECT.ACTIVITE_MOUVEMENT_CODES + '#/B#';
							}
						}
						if (SELECT.ETAGE_MOUVEMENT  != '-1') {
							if (SELECT.ETAGE_MOUVEMENT != 'SAISIECODE') {
								display = display + '  [DICT.ACTI.ETAGE] : #B#' + SELECT.ETAGE_MOUVEMENT_LABEL + '#/B#';
							}
							else {
								display = display + '  [DICT.ACTI.ETAGE] : #B#' + SELECT.ETAGE_MOUVEMENT_CODES + '#/B#';
							}
						}
						
						if (display != '') {
							display = '#B#Filtres actes#/B# = ' + display;
						}
						return display;
						" >
			
			<GROUP>
				<FIELD name="PRESTATION" label="Prestation" UI="combo" tree="true" width="300" default="-1" globalListProvider="PRESTATIONSACTES" showIfNotDefault="true" />
				<FIELD name="PRESTATION_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.PRESTATION == 'SAISIECODE' " />
			</GROUP>
			<GROUP>
				<FIELD name="ACTE" label="Acte" UI="combo" tree="true" width="300" default="-1" globalListProvider="ACTES" showIfNotDefault="true" />
				<FIELD name="ACTE_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.ACTE == 'SAISIECODE' " />
			</GROUP>
			<GROUP>
				<FIELD name="PROTOCOLE" label="Protocole" UI="combo" tree="true" width="300" default="-1" globalListProvider="PROTOCOLES" showIfNotDefault="true" />
				<FIELD name="PROTOCOLE_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.PROTOCOLE == 'SAISIECODE' " />
			</GROUP>
			<GROUP>
				<FIELD name="MEDECINEXECUTANT" label="Médecin exécutant" UI="combo" tree="true" width="300" default="-1" globalListProvider="MEDECINSEXECUTANT" showIfNotDefault="true" />
				<FIELD name="MEDECINEXECUTANT_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.MEDECINEXECUTANT == 'SAISIECODE' " />
			</GROUP>
            <GROUP>
				<FIELD name="POLE_MOUVEMENT" label="Pole" UI="combo" tree="true" width="300" default="-1" globalListProvider="POLE" showIfNotDefault="true" />
			</GROUP>
			<GROUP>
				<FIELD name="SERVICE_MOUVEMENT" label="[DICT.ACTI.SERVICE] mouvement" UI="combo" tree="true" width="300" default="-1" globalListProvider="SERVICES" showIfNotDefault="true" />
				<FIELD name="SERVICE_MOUVEMENT_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.SERVICE_MOUVEMENT == 'SAISIECODE' " />
			</GROUP>
			<GROUP>
				<FIELD name="UF_MOUVEMENT" label="[DICT.ACTI.UF]" UI="combo" tree="true" width="300" default="-1" globalListProvider="UF" showIfNotDefault="true" />
				<FIELD name="UF_MOUVEMENT_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.UF_MOUVEMENT == 'SAISIECODE' " />
			</GROUP>
			<GROUP>
				<FIELD name="LIT_MOUVEMENT" label="Lit" UI="combo" tree="true" width="300" default="-1" globalListProvider="LITS" showIfNotDefault="true" />
				<FIELD name="LIT_MOUVEMENT_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.LIT_MOUVEMENT == 'SAISIECODE' " />
			</GROUP>
			<GROUP>
				<FIELD name="UM_MOUVEMENT" label="[DICT.ACTI.UM]" UI="combo" tree="true" width="300" default="-1" globalListProvider="UM" showIfNotDefault="true" />
				<FIELD name="UM_MOUVEMENT_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.UM_MOUVEMENT == 'SAISIECODE' " />
			</GROUP>
			<GROUP>
				<FIELD name="ACTIVITE_MOUVEMENT" label="[DICT.ACTI.ACTIVITE] mouvement" UI="combo" tree="true" width="300" default="-1" globalListProvider="ACTIVITES" showIfNotDefault="true" />
				<FIELD name="ACTIVITE_MOUVEMENT_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.ACTIVITE_MOUVEMENT == 'SAISIECODE' " />
			</GROUP>
			<GROUP>
				<FIELD name="ETAGE_MOUVEMENT" label="[DICT.ACTI.ETAGE] mouvement" UI="combo" tree="true" width="300" default="-1" globalListProvider="ETAGES" showIfNotDefault="true" />
				<FIELD name="ETAGE_MOUVEMENT_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.ETAGE_MOUVEMENT == 'SAISIECODE' " />
			</GROUP>
			
		</SELECTIONS>

		<QUERIES />
	
	</COMPONENT>
	
	<COMPONENT name="FILTRES_CLIENTS_SELECTIONS" label="Comptes clients" >
	
		<VIEWPROPERTIES>
				
			<PROPERTY name="CLIENTS_SELECT">
				<value>
					<![CDATA[
						[EVAL 
							$select = "";
							$select = $select . ACTI_standard_field_select("prestation", 't_prestations', '[PRESTATION]', '[PRESTATION_CODES]', "");
							$select = $select . ACTI_standard_field_select("rubrique_comptabilisation", 't_rubriques_facturation', '[RUBRIQUE]', '[RUBRIQUE_CODES]', "");
							$select = $select . ACTI_standard_field_select("tiers_payant", 't_tiers_payant', '[TIERS]', '[TIERS_CODES]', "");

							return $select;
						EVAL]
					]]>
				</value>
			</PROPERTY>

			
		</VIEWPROPERTIES>
		
		<SELECTIONS label="Filtre compte client" collapsible="true" displayText="= var display:String = '';
					
						if (SELECT.TIERS  != '-1') {
							display = display + '  Tiers payant : #B#' + SELECT.TIERS_LABEL + '#/B#';
						}
						if (SELECT.PRESTATION  != '-1') {
							display = display + '  Prestation : #B#' + SELECT.PRESTATION_LABEL + '#/B#';
						}
						if (SELECT.RUBRIQUE  != '-1') {
							display = display + '  Rubrique facturée : #B#' + SELECT.RUBRIQUE_LABEL + '#/B#';
						}
						
						
						if (display != '') {
							display = '#B#Filtres compte client#/B# = ' + display;
						}
						return display;
						">
			<GROUP>
				<FIELD name="TIERS" label="Tiers payant" UI="combo" tree="true" width="300" showIfNotDefault="true" default="-1" globalListProvider="TIERS">
				</FIELD>
			</GROUP>
			<GROUP>
				<FIELD name="PRESTATION" label="Prestation" UI="combo" tree="true" width="300" default="-1" globalListProvider="PRESTATIONS">
				</FIELD>
			</GROUP>
			<GROUP>
				<FIELD name="RUBRIQUE" label="Rubrique" UI="combo" tree="true" width="300" default="-1" globalListProvider="RUBRIQUES">
				</FIELD>
			</GROUP>
			
		</SELECTIONS>
		
		<QUERIES />
		
	</COMPONENT>
	
	<COMPONENT name="FILTRES_CLIENTS_H_SELECTIONS" label="Comptes clients" >
	
		<VIEWPROPERTIES>
				
			<PROPERTY name="CLIENTS_MEDECIN_SELECT">
				<value>
					<![CDATA[
						[EVAL 
							$select = "";
							$select = $select . ACTI_standard_field_select("medecin_adm_comptabilise", 't_rubriques_facturation', '[MEDECINCOMPTABILISE]', '[MEDECINCOMPTABILISE_CODES]', "");
							return $select;
						EVAL]
					]]>
				</value>
			</PROPERTY>
            <PROPERTY name="CLIENTS_TIERS_SELECT">
				<value>
					<![CDATA[
						[EVAL 
							$select = "";
							$select = $select . ACTI_standard_field_select("tiers_payant", 't_tiers_payant', '[TIERS]', '[TIERS_CODES]', "");

							return $select;
						EVAL]
					]]>
				</value>
			</PROPERTY>

			
		</VIEWPROPERTIES>
		
		<SELECTIONS label="Filtre compte client" collapsible="true" displayText="= var display:String = '';
					
						if (SELECT.TIERS  != '-1') {
							display = display + '  Tiers payant : #B#' + SELECT.TIERS_LABEL + '#/B#';
						}
						if (SELECT.MEDECINCOMPTABILISE  != '-1') {
							if (SELECT.MEDECINCOMPTABILISE != 'SAISIECODE') {
								if (SELECT.MEDECINCOMPTABILISE.toString().substr(0,2) != 'SP') {
									display = display + '  Médecin exécutant: #B#' + SELECT.MEDECINCOMPTABILISE_LABEL + '#/B#';
								}
								else {
									display = display + '  Spécialité médecin exécutant: #B#' + SELECT.MEDECINCOMPTABILISE_LABEL + '#/B#';
								}
							}
							else {
								display = display + '  Médecin exécutant : #B#' + SELECT.MEDECINCOMPTABILISE_CODES + '#/B#';
							}
						}
						
						if (display != '') {
							display = '#B#Filtres compte client#/B# = ' + display;
						}
						return display;
						">
			<GROUP>
				<FIELD name="TIERS" label="Tiers payant" UI="combo" tree="true" width="300" showIfNotDefault="true" default="-1" globalListProvider="TIERS">
				</FIELD>
			</GROUP>
			<GROUP>
				<FIELD name="MEDECINCOMPTABILISE" label="Médecin exécutant" UI="combo" tree="true" width="280" default="-1" globalListProvider="MEDECINSEXECUTANT" showIfNotDefault="true">
				</FIELD>
				<FIELD name="MEDECINCOMPTABILISE_CODES" label="Codes" UI="text" width="150" default="" showIfNotDefault="true" visible="= SELECT.MEDECINCOMPTABILISE == 'SAISIECODE' " />
			</GROUP>
		</SELECTIONS>
		
		<QUERIES />
		
	</COMPONENT>
	
	<COMPONENT name="FILTRES_ETATDOSSIERS_SELECTIONS" label="Etat dossiers de séjour" >
	
		<VIEWPROPERTIES>
				
			<PROPERTY name="ETATDOSSIERS_SELECT">
				<value>
					<![CDATA[
						[EVAL 
							$select = "";
							$select = $select . ACTI_standard_field_select("v_factures_reference_1.tiers_payant", 't_tiers_payant', '[TIERS]', '[TIERS_CODES]', "");

							return $select;
						EVAL]
					]]>
				</value>
			</PROPERTY>

			
		</VIEWPROPERTIES>
		
		<SELECTIONS label="Filtre tiers" collapsible="true" displayText="= var display:String = '';
		
						if (SELECT.CLIHON  != '-1') {
							display = display + ' #B#' + SELECT.CLIHON_LABEL + '#/B#';
						}
					
						if (SELECT.TIERS  != '-1') {
							display = display + '  Tiers payant : #B#' + SELECT.TIERS_LABEL + '#/B#';
						}

						
						if (display != '') {
							display = '#B#Filtres tiers#/B# = ' + display;
						}
						return display;
						">
			<GROUP>
				<FIELD name="CLIHON" label="C/H" UI="combo" default="C" showIfNotDefault="true">
					<OPTION label="Clinique et Honoraires" data="-1"/>
					<OPTION label="Clinique" data="C"/>
					<OPTION label="Honoraires" data="H"/>
				</FIELD>
			</GROUP>
			<GROUP>
				<FIELD name="TIERS" label="Tiers payant" UI="combo" tree="true" width="300" default="-1" globalListProvider="TIERS" showIfNotDefault="true">
				</FIELD>
			</GROUP>
			
		</SELECTIONS>
		
		<QUERIES />
		
	</COMPONENT>
	
	<COMPONENT name="FILTRES_REJETS_SELECTIONS" label="Rejets" >
	
		<VIEWPROPERTIES>
		
			<PROPERTY name="REJETS_SELECT">
				<value>
					<![CDATA[
						[EVAL 
						
							$select = "";
							$select = $select . ACTI_standard_field_select("rejet", '', '[REJET]', '', "");
							
							return $select;

						EVAL]
					]]>
				</value>
			</PROPERTY>

		</VIEWPROPERTIES>
		
		<SELECTIONS label="Filtre rejets" collapsible="true" displayText="= var display:String = '';
					
						if (SELECT.REJET  != '-1') {
							display = display + '  Type rejet : #B#' + SELECT.REJET_LABEL + '#/B#';
						}
						
						
						if (display != '') {
							display = '#B#Filtres rejets#/B# = ' + display;
						}
						return display;
						" >
			
			<GROUP>
				<FIELD name="REJET" label="Rejet" UI="combo" tree="true" width="250" default="-1" globalListProvider="REJETS" showIfNotDefault="true" />
			</GROUP>
			
		</SELECTIONS>
		
		<QUERIES />
	
	</COMPONENT>
	
	<COMPONENT name="FILTRES_ETAT_SEJOURS_SOUSSELECTIONS" label="Sous sélections Séjours" >
	
		<VIEWPROPERTIES>
	
			<PROPERTY name="ACTIVITE_SIGNIFICATIVE_DATA">
				<value>
					<![CDATA[
						[EVAL 
							return 'v_sejours_1.nb_sejours';
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="ACTIVITE_SIGNIFICATIVE_PERCENT">
				<value>
					<![CDATA[
						[EVAL 
							if ('[ACTIVITE_SIGNIFICATIVE_MODE]' != 'N' && '[ACTIVITE_SIGNIFICATIVE_BASE]' != '-1') {return intval('[ACTIVITE_SIGNIFICATIVE_NUMBER]');}
							return 0;
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="ACTIVITE_SIGNIFICATIVE_NUMBER">
				<value>
					<![CDATA[
						[EVAL 
							if ('[ACTIVITE_SIGNIFICATIVE_MODE]' == 'N' && '[ACTIVITE_SIGNIFICATIVE_BASE]' != '-1') {return intval('[ACTIVITE_SIGNIFICATIVE_NUMBER]');}
							return 0;
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="ACTIVITE_SIGNIFICATIVE_OID_COL">
				<value>
					<![CDATA[
						[EVAL 
							return "CASE WHEN [VIEW.SOUSSELECT_OID_WHENIN] THEN -9999997 ELSE -9999998 END ";
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="ACTIVITE_SIGNIFICATIVE_TXT_COL">
				<value>
					<![CDATA[
						[EVAL 
							return  "CASE WHEN [VIEW.SOUSSELECT_OID_WHENIN] THEN 'Données significatives ([VIEW.SOUSSELECT_SELECT_PERCENT])' ELSE 'Autres ([VIEW.SOUSSELECT_OTHER_PERCENT])' END ";
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY dataLink="SOUSSELECT_VIEWPROPERTIES" nameField="name" valueField="value" />
			
		</VIEWPROPERTIES>
		
		<SELECTIONS label="Données significatives" collapsible="true" displayText="= var display:String = '';

					if (SELECT.ACTIVITE_SIGNIFICATIVE_BASE == 'REGSEJ') {
						if (SELECT.ACTIVITE_SIGNIFICATIVE_MODE == 'P') {
							display = display + 'Lignes représentant ' + SELECT.ACTIVITE_SIGNIFICATIVE_NUMBER + '% du classement sorties';
						}
						if (SELECT.ACTIVITE_SIGNIFICATIVE_MODE == 'N') {
							display = display + SELECT.ACTIVITE_SIGNIFICATIVE_NUMBER + ' premieres lignes du classement sorties';
						}
					}

					if (display != '') {
						display = '#B#Activité significative#/B# = ' + display;
					}
					return display;
					" 
					>
		
			<GROUP label="Basée sur">
				<FIELD name="ACTIVITE_SIGNIFICATIVE_BASE" label="" width="250" UI="combo" default="-1" tree="false" showIfNotDefault="true">
					<OPTION data="-1" label="Toutes les lignes" />
					<OPTION data="REGSEJ" label="Sélection selon le classement sorties" />
				</FIELD>
				<FIELD name="ACTIVITE_SIGNIFICATIVE_MODE" label="" UI="combo" default="P" visible="= SELECT.ACTIVITE_SIGNIFICATIVE_BASE != '-1'" >
					<OPTION data="P" label="En pourcentage" />
					<OPTION data="N" label="En nombre" />
				</FIELD>
				<FIELD name="ACTIVITE_SIGNIFICATIVE_NUMBER" label="nombre ou %" UI="text" width="50" default="" visible="= SELECT.ACTIVITE_SIGNIFICATIVE_BASE != '-1'" />
			</GROUP>

		</SELECTIONS>

		<QUERIES>
			
			<QUERY type="propertiesLink" name="SOUSSELECT_VIEWPROPERTIES" forRows="false" forSelections="false"> 
			
				<SQL>
					<select>
						<![CDATA[
							SELECT name, value 
								FROM activite.get_oids_from_classement(
									'', 
									'[DOUBLEQUOTES([VIEW.GROUPBY])DOUBLEQUOTES]', 
									'[VIEW.ACTIVITE_SIGNIFICATIVE_DATA]' , 
									[VIEW.ACTIVITE_SIGNIFICATIVE_PERCENT], 
									[VIEW.ACTIVITE_SIGNIFICATIVE_NUMBER], 
									'[DOUBLEQUOTES(date_sortie BETWEEN '[PERIODE]' AND '[TOPERIODE]' AND code_sorti = '1')DOUBLEQUOTES]',
									'[DOUBLEQUOTES([VIEW.SEJOURS_SELECT] )DOUBLEQUOTES]',
									''
									) AS (name text, value text)
						]]>
					</select>
					<FIELDS>
						<FIELD name="name" />
						<FIELD name="value" />
					</FIELDS>
				</SQL>
				
			</QUERY>
			
		</QUERIES>
	
	</COMPONENT>
	
	<COMPONENT name="FILTRES_OCCUPATION_SOUSSELECTIONS" label="Sous sélections Séjours" >
	
		<VIEWPROPERTIES>
	
			<PROPERTY name="ACTIVITE_SIGNIFICATIVE_DATA">
				<value>
					<![CDATA[
						[EVAL 
							if ('[ACTIVITE_SIGNIFICATIVE_BASE]' == 'REGSEJ') {
								return 'v_mouvements_sejour_2.nb_sejours';
							}
							if ('[ACTIVITE_SIGNIFICATIVE_BASE]' == 'REGJRN') {
								return 'v_mouvements_sejour_2.nb_journees_classement';
							}
							return 'v_mouvements_sejour_2.nb_journees_classement';
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="ACTIVITE_SIGNIFICATIVE_PERCENT">
				<value>
					<![CDATA[
						[EVAL 
							if ('[ACTIVITE_SIGNIFICATIVE_MODE]' != 'N' && '[ACTIVITE_SIGNIFICATIVE_BASE]' != '-1') {return intval('[ACTIVITE_SIGNIFICATIVE_NUMBER]');}
							return 0;
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="ACTIVITE_SIGNIFICATIVE_NUMBER">
				<value>
					<![CDATA[
						[EVAL 
							if ('[ACTIVITE_SIGNIFICATIVE_MODE]' == 'N' && '[ACTIVITE_SIGNIFICATIVE_BASE]' != '-1') {return intval('[ACTIVITE_SIGNIFICATIVE_NUMBER]');}
							return 0;
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="ACTIVITE_SIGNIFICATIVE_OID_COL">
				<value>
					<![CDATA[
						[EVAL 
							return "CASE WHEN [VIEW.SOUSSELECT_OID_WHENIN] THEN -9999997 ELSE -9999998 END ";
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="ACTIVITE_SIGNIFICATIVE_TXT_COL">
				<value>
					<![CDATA[
						[EVAL 
							return  "CASE WHEN [VIEW.SOUSSELECT_OID_WHENIN] THEN 'Données significatives ([VIEW.SOUSSELECT_SELECT_PERCENT])' ELSE 'Autres ([VIEW.SOUSSELECT_OTHER_PERCENT])' END ";
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
		</VIEWPROPERTIES>
		
		<SELECTIONS label="Données significatives" collapsible="true" displayText="= var display:String = '';

					if (SELECT.ACTIVITE_SIGNIFICATIVE_BASE == 'REGSEJ') {
						if (SELECT.ACTIVITE_SIGNIFICATIVE_MODE == 'P') {
							display = display + 'Lignes représentant ' + SELECT.ACTIVITE_SIGNIFICATIVE_NUMBER + '% du classement séjours';
						}
						if (SELECT.ACTIVITE_SIGNIFICATIVE_MODE == 'N') {
							display = display + SELECT.ACTIVITE_SIGNIFICATIVE_NUMBER + ' premieres lignes du classement séjours';
						}
					}
					if (SELECT.ACTIVITE_SIGNIFICATIVE_BASE == 'REGJRN') {
						if (SELECT.ACTIVITE_SIGNIFICATIVE_MODE == 'P') {
							display = display + 'Lignes représentant ' + SELECT.ACTIVITE_SIGNIFICATIVE_NUMBER + '% du classement journées';
						}
						if (SELECT.ACTIVITE_SIGNIFICATIVE_MODE == 'N') {
							display = display + SELECT.ACTIVITE_SIGNIFICATIVE_NUMBER + ' premieres lignes du classement journées';
						}
					}

					if (display != '') {
						display = '#B#Activité significative#/B# = ' + display;
					}
					return display;
					" 
					>
		
			<GROUP label="Basée sur">
				<FIELD name="ACTIVITE_SIGNIFICATIVE_BASE" label="" width="250" UI="combo" default="-1" tree="false" showIfNotDefault="true">
					<OPTION data="-1" label="Toutes les lignes" />
					<OPTION data="REGSEJ" label="Sélection selon le classement séjours" />
					<OPTION data="REGJRN" label="Sélection selon le classement journées" />
				</FIELD>
				<FIELD name="ACTIVITE_SIGNIFICATIVE_MODE" label="" UI="combo"  default="P" visible="= SELECT.ACTIVITE_SIGNIFICATIVE_BASE != '-1'" >
					<OPTION data="P" label="En pourcentage" />
					<OPTION data="N" label="En nombre" />
				</FIELD>
				<FIELD name="ACTIVITE_SIGNIFICATIVE_NUMBER" label="nombre ou %" UI="text" width="50" default="" visible="= SELECT.ACTIVITE_SIGNIFICATIVE_BASE != '-1'" />
			</GROUP>

		</SELECTIONS>
	
	</COMPONENT>
	
	<COMPONENT name="FILTRES_OCCUPATIONQ_SOUSSELECTIONS" label="Sous sélections Séjours" >
	
		<VIEWPROPERTIES>
	
			<PROPERTY name="ACTIVITE_SIGNIFICATIVE_DATA">
					<value>
						<![CDATA[
							[EVAL 
								return 'v_mouvements_sejour_2.nb_journees_classement';
							EVAL]
						]]>
					</value>
				</PROPERTY>
			
			<PROPERTY name="ACTIVITE_SIGNIFICATIVE_PERCENT">
					<value>
						<![CDATA[
							[EVAL 
								if ('[ACTIVITE_SIGNIFICATIVE_MODE]' != 'N' && '[ACTIVITE_SIGNIFICATIVE_BASE]' != '-1') {return intval('[ACTIVITE_SIGNIFICATIVE_NUMBER]');}
								return 0;
							EVAL]
						]]>
					</value>
				</PROPERTY>
			
			<PROPERTY name="ACTIVITE_SIGNIFICATIVE_NUMBER">
					<value>
						<![CDATA[
							[EVAL 
								if ('[ACTIVITE_SIGNIFICATIVE_MODE]' == 'N' && '[ACTIVITE_SIGNIFICATIVE_BASE]' != '-1') {return intval('[ACTIVITE_SIGNIFICATIVE_NUMBER]');}
								return 0;
							EVAL]
						]]>
					</value>
				</PROPERTY>
			
			<PROPERTY name="ACTIVITE_SIGNIFICATIVE_OID_COL">
					<value>
						<![CDATA[
							[EVAL 
								return "CASE WHEN [VIEW.SOUSSELECT_OID_WHENIN] THEN -9999997 ELSE -9999998 END ";
							EVAL]
						]]>
					</value>
				</PROPERTY>
			
			<PROPERTY name="ACTIVITE_SIGNIFICATIVE_TXT_COL">
					<value>
						<![CDATA[
							[EVAL 
								return  "CASE WHEN [VIEW.SOUSSELECT_OID_WHENIN] THEN 'Données significatives ([VIEW.SOUSSELECT_SELECT_PERCENT])' ELSE 'Autres ([VIEW.SOUSSELECT_OTHER_PERCENT])' END ";
							EVAL]
						]]>
					</value>
				</PROPERTY>
			
			<PROPERTY dataLink="SOUSSELECT_VIEWPROPERTIES" nameField="name" valueField="value" />
			
		</VIEWPROPERTIES>
		
		<SELECTIONS label="Données significatives" collapsible="true" displayText="= var display:String = '';

					if (SELECT.ACTIVITE_SIGNIFICATIVE_BASE == 'REGSEJ') {
						if (SELECT.ACTIVITE_SIGNIFICATIVE_MODE == 'P') {
							display = display + 'Lignes représentant ' + SELECT.ACTIVITE_SIGNIFICATIVE_NUMBER + '% du classement séjours';
						}
						if (SELECT.ACTIVITE_SIGNIFICATIVE_MODE == 'N') {
							display = display + SELECT.ACTIVITE_SIGNIFICATIVE_NUMBER + ' premieres lignes du classement séjours';
						}
					}
					if (SELECT.ACTIVITE_SIGNIFICATIVE_BASE == 'REGJRN') {
						if (SELECT.ACTIVITE_SIGNIFICATIVE_MODE == 'P') {
							display = display + 'Lignes représentant ' + SELECT.ACTIVITE_SIGNIFICATIVE_NUMBER + '% du classement journées';
						}
						if (SELECT.ACTIVITE_SIGNIFICATIVE_MODE == 'N') {
							display = display + SELECT.ACTIVITE_SIGNIFICATIVE_NUMBER + ' premieres lignes du classement journées';
						}
					}

					if (display != '') {
						display = '#B#Activité significative#/B# = ' + display;
					}
					return display;
					" 
					>
		
			<GROUP label="Basée sur">
				<FIELD name="ACTIVITE_SIGNIFICATIVE_BASE" label="" width="250" UI="combo" default="-1" tree="false" showIfNotDefault="true">
					<OPTION data="-1" label="Toutes les lignes" />
					<OPTION data="REGSEJ" label="Sélection selon le classement séjours" />
					<OPTION data="REGJRN" label="Sélection selon le classement journées" />
				</FIELD>
				<FIELD name="ACTIVITE_SIGNIFICATIVE_MODE" label="" UI="combo"  default="P" visible="= SELECT.ACTIVITE_SIGNIFICATIVE_BASE != '-1'" >
					<OPTION data="P" label="En pourcentage" />
					<OPTION data="N" label="En nombre" />
				</FIELD>
				<FIELD name="ACTIVITE_SIGNIFICATIVE_NUMBER" label="nombre ou %" UI="text" width="50" default="" visible="= SELECT.ACTIVITE_SIGNIFICATIVE_BASE != '-1'" />
			</GROUP>
		
		</SELECTIONS>
		
		<QUERIES>
			
			<QUERY type="propertiesLink" name="SOUSSELECT_VIEWPROPERTIES" forRows="false" forSelections="false"> 
				<SQL>
					<select>
						<![CDATA[
							SELECT 'TOPERIODE', date FROM activite.p_mouvements_sejour WHERE date <= '[TOPERIODE]' ORDER BY date DESC LIMIT 1
						]]>
					</select>
					<FIELDS>
						<FIELD name="name" />
						<FIELD name="value" />
					</FIELDS>
				</SQL>
				
				<SQL>
					<select>
						<![CDATA[
							SELECT 'PERIODE', date FROM base.p_calendrier WHERE date <= '[VIEW.TOPERIODE]' ORDER BY date DESC LIMIT 1 OFFSET [NBJOURS] - 1
						]]>
					</select>
					<FIELDS>
						<FIELD name="name" />
						<FIELD name="value" />
					</FIELDS>
				</SQL>
				
				<SQL>
					<select>
						<![CDATA[
							SELECT name, value 
								FROM activite.get_oids_from_classement(
									'', 
									'[DOUBLEQUOTES([VIEW.GROUPBY])DOUBLEQUOTES]', 
									'[VIEW.ACTIVITE_SIGNIFICATIVE_DATA]' , 
									[VIEW.ACTIVITE_SIGNIFICATIVE_PERCENT], 
									[VIEW.ACTIVITE_SIGNIFICATIVE_NUMBER], 
									'[DOUBLEQUOTES(date_sortie BETWEEN '[VIEW.PERIODE]' AND '[VIEW.TOPERIODE]' )DOUBLEQUOTES]',
									'[DOUBLEQUOTES([VIEW.SEJOURS_SELECT] )DOUBLEQUOTES]',
									''
									) AS (name text, value text)
						]]>
					</select>
					<FIELDS>
						<FIELD name="name" />
						<FIELD name="value" />
					</FIELDS>
				</SQL>
				
			</QUERY>
			
		</QUERIES>
	
	</COMPONENT>
	
	<COMPONENT name="FILTRES_PRESTATIONS_SOUSSELECTIONS" label="Sous sélections prestations" >
	
		<VIEWPROPERTIES>
	
			<PROPERTY name="ACTIVITE_SIGNIFICATIVE_DATA">
				<value>
					<![CDATA[
						[EVAL 
							if ('[ACTIVITE_SIGNIFICATIVE_BASE]' == 'REGNB') {
								return 'v_factures_lignes_c_4.nb_rubrique * v_factures_lignes_c_4.coefficient';
							}
							if ('[ACTIVITE_SIGNIFICATIVE_BASE]' == 'REGCA') {
								return 'v_factures_lignes_c_4.montant_facture';
							}
							return '';
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
		</VIEWPROPERTIES>
		
		<SELECTIONS label="Données significatives" collapsible="true" displayText="= var display:String = '';

					if (SELECT.ACTIVITE_SIGNIFICATIVE_BASE == 'REGNB') {
						if (SELECT.ACTIVITE_SIGNIFICATIVE_MODE == 'P') {
							display = display + 'Lignes représentant ' + SELECT.ACTIVITE_SIGNIFICATIVE_NUMBER + '% du classement nombre';
						}
						if (SELECT.ACTIVITE_SIGNIFICATIVE_MODE == 'N') {
							display = display + SELECT.ACTIVITE_SIGNIFICATIVE_NUMBER + ' premieres lignes du classement séjours';
						}
					}
					if (SELECT.ACTIVITE_SIGNIFICATIVE_BASE == 'REGCA') {
						if (SELECT.ACTIVITE_SIGNIFICATIVE_MODE == 'P') {
							display = display + 'Lignes représentant ' + SELECT.ACTIVITE_SIGNIFICATIVE_NUMBER + '% du classement C.A.';
						}
						if (SELECT.ACTIVITE_SIGNIFICATIVE_MODE == 'N') {
							display = display + SELECT.ACTIVITE_SIGNIFICATIVE_NUMBER + ' premieres lignes du classement C.A.';
						}
					}

					if (display != '') {
						display = '#B#Activité significative#/B# = ' + display;
					}
					return display;
					" 
					>
		
			<GROUP label="Basée sur">
				<FIELD name="ACTIVITE_SIGNIFICATIVE_BASE" label="" width="250" UI="combo" default="-1" tree="false" showIfNotDefault="true">
					<OPTION data="-1" label="Toutes les lignes" />
					<OPTION data="REGCA" label="Sélection selon le classement C.A." />
					<OPTION data="REGSEJ" label="Sélection selon le classement nombre" />
				</FIELD>
				<FIELD name="ACTIVITE_SIGNIFICATIVE_MODE" label="" UI="combo"  default="P" visible="= SELECT.ACTIVITE_SIGNIFICATIVE_BASE != '-1'" >
					<OPTION data="P" label="En pourcentage" />
					<OPTION data="N" label="En nombre" />
				</FIELD>
				<FIELD name="ACTIVITE_SIGNIFICATIVE_NUMBER" label="nombre ou %" UI="text" width="50" default="" visible="= SELECT.ACTIVITE_SIGNIFICATIVE_BASE != '-1'" />
			</GROUP>

		</SELECTIONS>

	</COMPONENT>
	
	<COMPONENT name="FILTRES_PRESTATIONS_H_SOUSSELECTIONS" label="Sous sélections prestations" >
	
		<VIEWPROPERTIES>
	
			<PROPERTY name="ACTIVITE_SIGNIFICATIVE_DATA">
				<value>
					<![CDATA[
						[EVAL 
							if ('[ACTIVITE_SIGNIFICATIVE_BASE]' == 'REGNB') {
								return 'v_factures_lignes_h_3.nb_rubrique * v_factures_lignes_h_3.coefficient';
							}
							if ('[ACTIVITE_SIGNIFICATIVE_BASE]' == 'REGCA') {
								return 'v_factures_lignes_h_3.montant_facture';
							}
							return '';
						EVAL]
					]]>
				</value>
			</PROPERTY>
		</VIEWPROPERTIES>
		
		<SELECTIONS label="Données significatives" collapsible="true" displayText="= var display:String = '';

					if (SELECT.ACTIVITE_SIGNIFICATIVE_BASE == 'REGNB') {
						if (SELECT.ACTIVITE_SIGNIFICATIVE_MODE == 'P') {
							display = display + 'Lignes représentant ' + SELECT.ACTIVITE_SIGNIFICATIVE_NUMBER + '% du classement nombre';
						}
						if (SELECT.ACTIVITE_SIGNIFICATIVE_MODE == 'N') {
							display = display + SELECT.ACTIVITE_SIGNIFICATIVE_NUMBER + ' premieres lignes du classement nombre';
						}
					}
					if (SELECT.ACTIVITE_SIGNIFICATIVE_BASE == 'REGCA') {
						if (SELECT.ACTIVITE_SIGNIFICATIVE_MODE == 'P') {
							display = display + 'Lignes représentant ' + SELECT.ACTIVITE_SIGNIFICATIVE_NUMBER + '% du classement C.A.';
						}
						if (SELECT.ACTIVITE_SIGNIFICATIVE_MODE == 'N') {
							display = display + SELECT.ACTIVITE_SIGNIFICATIVE_NUMBER + ' premieres lignes du classement C.A.';
						}
					}

					if (display != '') {
						display = '#B#Données significatives#/B# = ' + display;
					}
					return display;
					" 
					>
		
			<GROUP label="Basée sur">
				<FIELD name="ACTIVITE_SIGNIFICATIVE_BASE" label="" width="250" UI="combo" default="-1" tree="false" showIfNotDefault="true">
					<OPTION data="-1" label="Toutes les lignes" />
					<OPTION data="REGCA" label="Sélection selon le classement C.A." />
					<OPTION data="REGNB" label="Sélection selon le classement nombre" />
				</FIELD>
				<FIELD name="ACTIVITE_SIGNIFICATIVE_MODE" label="" UI="combo"  default="P" visible="= SELECT.ACTIVITE_SIGNIFICATIVE_BASE != '-1'" >
					<OPTION data="P" label="En pourcentage" />
					<OPTION data="N" label="En nombre" />
				</FIELD>
				<FIELD name="ACTIVITE_SIGNIFICATIVE_NUMBER" label="nombre ou %" UI="text" width="50" default="" visible="= SELECT.ACTIVITE_SIGNIFICATIVE_BASE != '-1'" />
			</GROUP>

		</SELECTIONS>
	
	</COMPONENT>
	
	<COMPONENT name="FILTRES_REJETS_SOUSSELECTIONS" label="Sous sélections rejets" >
	
		<VIEWPROPERTIES>
	
			<PROPERTY name="ACTIVITE_SIGNIFICATIVE_DATA">
				<value>
					<![CDATA[
						[EVAL 
							if ('[ACTIVITE_SIGNIFICATIVE_BASE]' == 'REGNR') {
								return '1';
							}
							return '';
						EVAL]
					]]>
				</value>
			</PROPERTY>

		</VIEWPROPERTIES>
		
		<SELECTIONS label="Données significatives" collapsible="true" displayText="= var display:String = '';

					if (SELECT.ACTIVITE_SIGNIFICATIVE_BASE == 'REGNR') {
						if (SELECT.ACTIVITE_SIGNIFICATIVE_MODE == 'P') {
							display = display + 'Lignes représentant ' + SELECT.ACTIVITE_SIGNIFICATIVE_NUMBER + '% du classement nombre';
						}
						if (SELECT.ACTIVITE_SIGNIFICATIVE_MODE == 'N') {
							display = display + SELECT.ACTIVITE_SIGNIFICATIVE_NUMBER + ' premieres lignes du classement nombre';
						}
					}
					

					if (display != '') {
						display = '#B#Données significatives#/B# = ' + display;
					}
					return display;
					" 
					>
		
			<GROUP label="Basée sur">
				<FIELD name="ACTIVITE_SIGNIFICATIVE_BASE" label="" width="250" UI="combo" default="-1" tree="false" showIfNotDefault="true">
					<OPTION data="-1" label="Toutes les lignes" />
					<OPTION data="REGNR" label="Sélection selon le classement nombre" />
				</FIELD>
				<FIELD name="ACTIVITE_SIGNIFICATIVE_MODE" label="" UI="combo"  default="P" visible="= SELECT.ACTIVITE_SIGNIFICATIVE_BASE != '-1'" >
					<OPTION data="P" label="En pourcentage" />
					<OPTION data="N" label="En nombre" />
				</FIELD>
				<FIELD name="ACTIVITE_SIGNIFICATIVE_NUMBER" label="nombre ou %" UI="text" width="50" default="" visible="= SELECT.ACTIVITE_SIGNIFICATIVE_BASE != '-1'" />
			</GROUP>

		</SELECTIONS>
	
	</COMPONENT>
	
	<COMPONENT name="FILTRES_ETAT_SEJOURS_SOUSSELECTIONS" label="Sous sélections prestations" >
	
		<VIEWPROPERTIES>
	
			<PROPERTY name="ACTIVITE_SIGNIFICATIVE_DATA">
				<value>
					<![CDATA[
						[EVAL 
							if ('[ACTIVITE_SIGNIFICATIVE_BASE]' == 'REGFA') {
								return 'v_factures_2.nb_factures';
							}
							return '';
						EVAL]
					]]>
				</value>
			</PROPERTY>

		</VIEWPROPERTIES>
		
		<SELECTIONS label="Données significatives" collapsible="true" displayText="= var display:String = '';

					if (SELECT.ACTIVITE_SIGNIFICATIVE_BASE == 'REGFA') {
						if (SELECT.ACTIVITE_SIGNIFICATIVE_MODE == 'P') {
							display = display + 'Lignes représentant ' + SELECT.ACTIVITE_SIGNIFICATIVE_NUMBER + '% du classement nombre factures';
						}
						if (SELECT.ACTIVITE_SIGNIFICATIVE_MODE == 'N') {
							display = display + SELECT.ACTIVITE_SIGNIFICATIVE_NUMBER + ' premieres lignes du classement nombre factures';
						}
					}
					
					if (display != '') {
						display = '#B#Données significatives#/B# = ' + display;
					}
					return display;
					" 
					>
		
			<GROUP label="Basée sur">
				<FIELD name="ACTIVITE_SIGNIFICATIVE_BASE" label="" width="250" UI="combo" default="-1" tree="false" showIfNotDefault="true">
					<OPTION data="-1" label="Toutes les lignes" />
					<OPTION data="REGFA" label="Sélection selon le classement nombre factures" />
				</FIELD>
				<FIELD name="ACTIVITE_SIGNIFICATIVE_MODE" label="" UI="combo" default="P" visible="= SELECT.ACTIVITE_SIGNIFICATIVE_BASE != '-1'" >
					<OPTION data="P" label="En pourcentage" />
					<OPTION data="N" label="En nombre" />
				</FIELD>
				<FIELD name="ACTIVITE_SIGNIFICATIVE_NUMBER" label="nombre ou %" UI="text" width="50" default="" visible="= SELECT.ACTIVITE_SIGNIFICATIVE_BASE != '-1'" />
			</GROUP>

		</SELECTIONS>
	
	</COMPONENT>
	
	<COMPONENT name="PROPERTIES_PRESTATIONS" label="Propriétés diverses prestations" >
	
		<VIEWPROPERTIES>
		
			<PROPERTY name="CONTEXTE" value="PRESTATIONS" >
			</PROPERTY>
		
			<PROPERTY name="GROUPBY_OID_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_PRESTATION_field_id("[GROUPBY]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_COD_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_PRESTATION_field_code("[GROUPBY]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_TXT_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_PRESTATION_field_texte("[GROUPBY]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_2_OID_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_PRESTATION_field_id("[GROUPBY_2]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_2_COD_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_PRESTATION_field_code("[GROUPBY_2]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_2_TXT_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_PRESTATION_field_texte("[GROUPBY_2]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_3_OID_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_PRESTATION_field_id("[GROUPBY_3]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_3_COD_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_PRESTATION_field_code("[GROUPBY_3]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_3_TXT_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_PRESTATION_field_texte("[GROUPBY_3]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="COLUMNBY_OID_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_PRESTATION_field_id("[COLUMNBY]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="COLUMNBY_COD_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_PRESTATION_field_code("[COLUMNBY]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="COLUMNBY_TXT_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_PRESTATION_field_texte("[COLUMNBY]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>			
			
			
			<PROPERTY name="COLUMNBY_FO_OID_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_PRESTATION_2_field_id("[COLUMNBY]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="COLUMNBY_FO_COD_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_PRESTATION_2_field_code("[COLUMNBY]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="COLUMNBY_FO_TXT_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_PRESTATION_2_field_texte("[COLUMNBY]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
            
             <PROPERTY name="COLUMNBY_MVT_OID_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_MOUVEMENT_field_id("[COLUMNBY]", "empty");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="COLUMNBY_MVT_COD_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_MOUVEMENT_field_code("[COLUMNBY]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="COLUMNBY_MVT_TXT_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_MOUVEMENT_field_texte("[COLUMNBY]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
            
            <PROPERTY name="GROUPBY_MVT_OID_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_MOUVEMENT_field_id("[GROUPBY]", "empty");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_MVT_COD_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_MOUVEMENT_field_code("[GROUPBY]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_MVT_TXT_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_MOUVEMENT_field_texte("[GROUPBY]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_MVT_2_OID_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_MOUVEMENT_field_id("[GROUPBY_2]", "empty");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_MVT_2_COD_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_MOUVEMENT_field_code("[GROUPBY_2]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_MVT_2_TXT_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_MOUVEMENT_field_texte("[GROUPBY_2]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_MVT_3_OID_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_MOUVEMENT_field_id("[GROUPBY_3]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_MVT_3_COD_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_MOUVEMENT_field_code("[GROUPBY_3]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_MVT_3_TXT_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_MOUVEMENT_field_texte("[GROUPBY_3]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>

			<PROPERTY name="QUELLEDATE_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_get_quelledate2("[QUELLEDATE]");
						EVAL]
					]]>
				</value>
			</PROPERTY>
		</VIEWPROPERTIES>
		
	</COMPONENT>
	
	<COMPONENT name="PROPERTIES_PRESTATIONS_H" label="Propriétés diverses prestations honoraires" >
	
		<VIEWPROPERTIES>
		
			<PROPERTY name="CONTEXTE" value="PRESTATIONS_H" >
			</PROPERTY>
			
			
			<PROPERTY name="GROUPBY_OID_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_PRESTATION_H_field_id("[GROUPBY]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_COD_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_PRESTATION_H_field_code("[GROUPBY]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_TXT_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_PRESTATION_H_field_texte("[GROUPBY]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_2_OID_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_PRESTATION_H_field_id("[GROUPBY_2]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_2_COD_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_PRESTATION_H_field_code("[GROUPBY_2]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_2_TXT_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_PRESTATION_H_field_texte("[GROUPBY_2]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_3_OID_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_PRESTATION_H_field_id("[GROUPBY_3]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_3_COD_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_PRESTATION_H_field_code("[GROUPBY_3]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_3_TXT_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_PRESTATION_H_field_texte("[GROUPBY_3]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="COLUMNBY_OID_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_PRESTATION_H_field_id("[COLUMNBY]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="COLUMNBY_COD_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_PRESTATION_H_field_code("[COLUMNBY]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="COLUMNBY_TXT_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_PRESTATION_H_field_texte("[COLUMNBY]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>

			<PROPERTY name="QUELLEDATE_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_get_quelledate2("[QUELLEDATE]");
						EVAL]
					]]>
				</value>
			</PROPERTY>

		
		</VIEWPROPERTIES>
		
	</COMPONENT>
	
	<COMPONENT name="PROPERTIES_ANALYSE_TT" label="Propriétés diverses analyse de temps des traitements" >
	
		<VIEWPROPERTIES>
		
			<PROPERTY name="CONTEXTE" value="ANALYSE_TT" >
			</PROPERTY>
					<PROPERTY name="CLIHON">
				<value>
					<![CDATA[
						[EVAL 
							$prefixe = '';
							if ('[CLIHON]' == 'C') {return '_c';}
							if ('[CLIHON]' == 'H') {return '_h';}

							return '';
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="DATE_GBY">
				<value><![CDATA[[EVAL 
	
							if('[GROUPBY]' == 'ANNEE' || '[GROUPBY]' == 'TRIM' || '[GROUPBY]' == 'JOUR' || '[GROUPBY]' == 'NUMEROTRIM' || '[GROUPBY]' == 'NUMEROMOIS' || '[GROUPBY]' == 'NUMEROJOUR' || '[GROUPBY]' == 'SEMAINEANNE' || '[GROUPBY]' == 'JOURS' || '[GROUPBY]' == 'SEMAINEWE' ) {return 'v_factures_reference_1.date_fin_facture';}
							if('[GROUPBY]' == 'ANNEEF' || '[GROUPBY]' == 'TRIMF' || '[GROUPBY]' == 'JOURF' || '[GROUPBY]' == 'NUMEROTRIMF' || '[GROUPBY]' == 'NUMEROMOISF' || '[GROUPBY]' == 'NUMEROJOURF' || '[GROUPBY]' == 'SEMAINEANNEF' || '[GROUPBY]' == 'JOURSF' || '[GROUPBY]' == 'SEMAINEWEF' ) {return 'v_factures_reference_1.date_facture';}
							if('[GROUPBY]' == 'ANNEEEX' || '[GROUPBY]' == 'TRIMEX' || '[GROUPBY]' == 'JOUREX' || '[GROUPBY]' == 'NUMEROTRIMEX' || '[GROUPBY]' == 'NUMEROMOISEX' || '[GROUPBY]' == 'NUMEROJOUREX' || '[GROUPBY]' == 'SEMAINEANNEEX' || '[GROUPBY]' == 'JOURSEX' || '[GROUPBY]' == 'SEMAINEWEEX' ) {return 'v_factures_reference_1.date_expedition';}
							return 'v_factures_reference_1.date_fin_facture';
				EVAL]]]></value>
			</PROPERTY>
			<PROPERTY name="LEVELD_VIEW">
				<value>
					<![CDATA[
						[EVAL 
							if ('[QDETAIL_TIERS]' == '1') {return 'v_factures_reference_tiers_1';}
							if ('[TIERS]' != '-1') {return 'v_factures_reference_tiers_1';}
							
							return "v_factures_reference_1";
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="LEVEL00_VIEW">
				<value>
					<![CDATA[
						[EVAL 
							if ('[TIERS]' != '-1') {return 'v_factures_reference_tiers_1';}
							
							return "v_factures_reference_1";
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			
			<PROPERTY name="LEVEL10_VIEW">
				<value>
					<![CDATA[
						[EVAL 
							return "v_factures_reference_1";
						EVAL]
					]]>
				</value>
			</PROPERTY>

			<PROPERTY name="LEVEL20_VIEW">
				<value>
					<![CDATA[
						[EVAL 
							if ('[TIERS]' != '-1') {return 'v_factures_reference_tiers_1';}
							
							if ('[GROUPBY]' == 'TTP') {return 'v_factures_reference_tiers_1';}
							if ('[GROUPBY]' == 'TRG') {return 'v_factures_reference_tiers_1';}
							if ('[GROUPBY]' == 'TPY') {return 'v_factures_reference_tiers_1';}
							if ('[GROUPBY]' == 'TPYCLS01') {return 'v_factures_reference_tiers_1';}
							if ('[GROUPBY]' == 'TPYCLS02') {return 'v_factures_reference_tiers_1';}
							if ('[GROUPBY]' == 'TPYCLS03') {return 'v_factures_reference_tiers_1';}
							
							if ('[GROUPBY_2]' == 'TTP') {return 'v_factures_reference_tiers_1';}
							if ('[GROUPBY_2]' == 'TRG') {return 'v_factures_reference_tiers_1';}
							if ('[GROUPBY_2]' == 'TPY') {return 'v_factures_reference_tiers_1';}
							if ('[GROUPBY_2]' == 'TPYCLS01') {return 'v_factures_reference_tiers_1';}
							if ('[GROUPBY_2]' == 'TPYCLS02') {return 'v_factures_reference_tiers_1';}
							if ('[GROUPBY_2]' == 'TPYCLS03') {return 'v_factures_reference_tiers_1';}
							
							return "v_factures_reference_1";
						EVAL]
					]]>
				</value>
			</PROPERTY>
			<PROPERTY name="LEVEL01_VIEW">
				<value>
					<![CDATA[
						[EVAL 
							if ('[TIERS]' != '-1') {return 'v_factures_reference_tiers_1';}
							
							return "v_factures_lignes_c_4";
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			
			<PROPERTY name="LEVEL11_VIEW">
				<value>
					<![CDATA[
						[EVAL 
							return "v_factures_lignes_c_4";
						EVAL]
					]]>
				</value>
			</PROPERTY>

			<PROPERTY name="LEVEL21_VIEW">
				<value>
					<![CDATA[
						[EVAL 
							if ('[TIERS]' != '-1') {return 'v_factures_reference_tiers_1';}
							
							if ('[GROUPBY]' == 'TTP') {return 'v_factures_reference_tiers_1';}
							if ('[GROUPBY]' == 'TRG') {return 'v_factures_reference_tiers_1';}
							if ('[GROUPBY]' == 'TPY') {return 'v_factures_reference_tiers_1';}
							if ('[GROUPBY]' == 'TPYCLS01') {return 'v_factures_reference_tiers_1';}
							if ('[GROUPBY]' == 'TPYCLS02') {return 'v_factures_reference_tiers_1';}
							if ('[GROUPBY]' == 'TPYCLS03') {return 'v_factures_reference_tiers_1';}
							
							if ('[GROUPBY_2]' == 'TTP') {return 'v_factures_reference_tiers_1';}
							if ('[GROUPBY_2]' == 'TRG') {return 'v_factures_reference_tiers_1';}
							if ('[GROUPBY_2]' == 'TPY') {return 'v_factures_reference_tiers_1';}
							if ('[GROUPBY_2]' == 'TPYCLS01') {return 'v_factures_reference_tiers_1';}
							if ('[GROUPBY_2]' == 'TPYCLS02') {return 'v_factures_reference_tiers_1';}
							if ('[GROUPBY_2]' == 'TPYCLS03') {return 'v_factures_reference_tiers_1';}
							
							return "v_factures_lignes_c_4";
						EVAL]
					]]>
				</value>
			</PROPERTY>			
			<PROPERTY name="LEVEL02_VIEW">
				<value>
					<![CDATA[
						[EVAL 
							if ('[TIERS]' != '-1') {return 'v_factures_reference_tiers_1';}
							
							return "v_factures_lignes_c_4";
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			
			<PROPERTY name="LEVEL12_VIEW">
				<value>
					<![CDATA[
						[EVAL 
							return "v_factures_lignes_c_4";
						EVAL]
					]]>
				</value>
			</PROPERTY>

			<PROPERTY name="LEVEL22_VIEW">
				<value>
					<![CDATA[
						[EVAL 
							if ('[TIERS]' != '-1') {return 'v_factures_reference_tiers_1';}
							
							if ('[GROUPBY]' == 'TTP') {return 'v_factures_reference_tiers_1';}
							if ('[GROUPBY]' == 'TRG') {return 'v_factures_reference_tiers_1';}
							if ('[GROUPBY]' == 'TPY') {return 'v_factures_reference_tiers_1';}
							if ('[GROUPBY]' == 'TPYCLS01') {return 'v_factures_reference_tiers_1';}
							if ('[GROUPBY]' == 'TPYCLS02') {return 'v_factures_reference_tiers_1';}
							if ('[GROUPBY]' == 'TPYCLS03') {return 'v_factures_reference_tiers_1';}
							
							if ('[GROUPBY_2]' == 'TTP') {return 'v_factures_reference_tiers_1';}
							if ('[GROUPBY_2]' == 'TRG') {return 'v_factures_reference_tiers_1';}
							if ('[GROUPBY_2]' == 'TPY') {return 'v_factures_reference_tiers_1';}
							if ('[GROUPBY_2]' == 'TPYCLS01') {return 'v_factures_reference_tiers_1';}
							if ('[GROUPBY_2]' == 'TPYCLS02') {return 'v_factures_reference_tiers_1';}
							if ('[GROUPBY_2]' == 'TPYCLS03') {return 'v_factures_reference_tiers_1';}
							
							return "v_factures_lignes_c_4";
						EVAL]
					]]>
				</value>
			</PROPERTY>
			<PROPERTY name="LEVEL03_VIEW">
				<value>
					<![CDATA[
						[EVAL 
							if ('[TIERS]' != '-1') {return 'v_factures_reference_tiers_1';}
							
							return "v_factures_reference_1";
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			
			<PROPERTY name="LEVEL13_VIEW">
				<value>
					<![CDATA[
						[EVAL 
							return "v_factures_reference_1";
						EVAL]
					]]>
				</value>
			</PROPERTY>

			<PROPERTY name="LEVEL23_VIEW">
				<value>
					<![CDATA[
						[EVAL 
							if ('[TIERS]' != '-1') {return 'v_factures_reference_tiers_1';}
							
							if ('[GROUPBY]' == 'TTP') {return 'v_factures_reference_tiers_1';}
							if ('[GROUPBY]' == 'TRG') {return 'v_factures_reference_tiers_1';}
							if ('[GROUPBY]' == 'TPY') {return 'v_factures_reference_tiers_1';}
							if ('[GROUPBY]' == 'TPYCLS01') {return 'v_factures_reference_tiers_1';}
							if ('[GROUPBY]' == 'TPYCLS02') {return 'v_factures_reference_tiers_1';}
							if ('[GROUPBY]' == 'TPYCLS03') {return 'v_factures_reference_tiers_1';}
							
							if ('[GROUPBY_2]' == 'TTP') {return 'v_factures_reference_tiers_1';}
							if ('[GROUPBY_2]' == 'TRG') {return 'v_factures_reference_tiers_1';}
							if ('[GROUPBY_2]' == 'TPY') {return 'v_factures_reference_tiers_1';}
							if ('[GROUPBY_2]' == 'TPYCLS01') {return 'v_factures_reference_tiers_1';}
							if ('[GROUPBY_2]' == 'TPYCLS02') {return 'v_factures_reference_tiers_1';}
							if ('[GROUPBY_2]' == 'TPYCLS03') {return 'v_factures_reference_tiers_1';}
							
							return "v_factures_reference_1";
						EVAL]
					]]>
				</value>
			</PROPERTY>			
			<PROPERTY name="LEVEL04_VIEW">
				<value>
					<![CDATA[
						[EVAL 
							
							return "v_facture_solde_tiers_c_1";
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			
			<PROPERTY name="LEVEL14_VIEW">
				<value>
					<![CDATA[
						[EVAL 
							return "v_facture_solde_tiers_c_1";
						EVAL]
					]]>
				</value>
			</PROPERTY>

			<PROPERTY name="LEVEL24_VIEW">
				<value>
					<![CDATA[
						[EVAL 
							
							if ('[GROUPBY]' == 'TTP') {return 'v_factures_reference_tiers_1';}
							if ('[GROUPBY]' == 'TRG') {return 'v_factures_reference_tiers_1';}
							if ('[GROUPBY]' == 'TPY') {return 'v_factures_reference_tiers_1';}
							if ('[GROUPBY]' == 'TPYCLS01') {return 'v_factures_reference_tiers_1';}
							if ('[GROUPBY]' == 'TPYCLS02') {return 'v_factures_reference_tiers_1';}
							if ('[GROUPBY]' == 'TPYCLS03') {return 'v_factures_reference_tiers_1';}
							
							if ('[GROUPBY_2]' == 'TTP') {return 'v_factures_reference_tiers_1';}
							if ('[GROUPBY_2]' == 'TRG') {return 'v_factures_reference_tiers_1';}
							if ('[GROUPBY_2]' == 'TPY') {return 'v_factures_reference_tiers_1';}
							if ('[GROUPBY_2]' == 'TPYCLS01') {return 'v_factures_reference_tiers_1';}
							if ('[GROUPBY_2]' == 'TPYCLS02') {return 'v_factures_reference_tiers_1';}
							if ('[GROUPBY_2]' == 'TPYCLS03') {return 'v_factures_reference_tiers_1';}
							
							return "v_facture_solde_tiers_c_1";
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_OID_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_ANALYSE_TT_field_id("[GROUPBY]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_COD_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_ANALYSE_TT_field_code("[GROUPBY]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_TXT_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_ANALYSE_TT_field_texte("[GROUPBY]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_2_OID_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_ANALYSE_TT_field_id("[GROUPBY_2]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_2_COD_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_ANALYSE_TT_field_code("[GROUPBY_2]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_2_TXT_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_ANALYSE_TT_field_texte("[GROUPBY_2]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
		
		</VIEWPROPERTIES>
		
	</COMPONENT>
	
	<COMPONENT name="PROPERTIES_REJETS" label="Propriétés diverses prestations honoraires" >
		
		<VIEWPROPERTIES>
		
			<PROPERTY name="CONTEXTE" value="REJETS" >
			</PROPERTY>
			
			
			<PROPERTY name="GROUPBY_OID_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_REJET_field_id("[GROUPBY]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_COD_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_REJET_field_code("[GROUPBY]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_TXT_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_REJET_field_texte("[GROUPBY]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_2_OID_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_REJET_field_id("[GROUPBY_2]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_2_COD_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_REJET_field_code("[GROUPBY_2]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_2_TXT_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_REJET_field_texte("[GROUPBY_2]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_3_OID_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_REJET_field_id("[GROUPBY_3]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_3_COD_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_REJET_field_code("[GROUPBY_3]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_3_TXT_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_REJET_field_texte("[GROUPBY_3]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="COLUMNBY_OID_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_REJET_field_id("[COLUMNBY]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="COLUMNBY_COD_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_REJET_field_code("[COLUMNBY]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="COLUMNBY_TXT_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_REJET_field_texte("[COLUMNBY]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			
		</VIEWPROPERTIES>
		
	</COMPONENT>
	
	<COMPONENT name="PROPERTIES_OCCUPATION" label="Propriétés diverses SELECT occupation" >
	
		<VIEWPROPERTIES>
		
			<PROPERTY name="CONTEXTE" value="OCCUPATION" >
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_OID_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_MOUVEMENT_field_id("[GROUPBY]", "lieu_etage");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_COD_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_MOUVEMENT_field_code("[GROUPBY]", "lieu_etage");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_TXT_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_MOUVEMENT_field_texte("[GROUPBY]", "lieu_etage");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_2_OID_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_MOUVEMENT_field_id("[GROUPBY_2]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_2_COD_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_MOUVEMENT_field_code("[GROUPBY_2]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_2_TXT_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_MOUVEMENT_field_texte("[GROUPBY_2]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_3_OID_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_MOUVEMENT_field_id("[GROUPBY_3]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_3_COD_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_MOUVEMENT_field_code("[GROUPBY_3]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_3_TXT_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_MOUVEMENT_field_texte("[GROUPBY_3]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="COLUMNBY_OID_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_MOUVEMENT_field_id("[COLUMNBY]", "lieu_etage");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="COLUMNBY_COD_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_MOUVEMENT_field_code("[COLUMNBY]", "lieu_etage");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="COLUMNBY_TXT_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_MOUVEMENT_field_texte("[COLUMNBY]", "lieu_etage");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			
			<PROPERTY name="GROUPBY_PLACES_OID_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_PLACES_field_id("[GROUPBY]", "-111");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_PLACES_COD_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_PLACES_field_code("[GROUPBY]", "-111");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_PLACES_TXT_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_PLACES_field_texte("[GROUPBY]", "-111");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_2_PLACES_OID_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_PLACES_field_id("[GROUPBY_2]", "-111");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_2_PLACES_COD_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_PLACES_field_code("[GROUPBY_2]", "-111");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_2_PLACES_TXT_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_PLACES_field_texte("[GROUPBY_2]", "-111");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_3_PLACES_OID_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_PLACES_field_id("[GROUPBY_3]", "-111");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_3_PLACES_COD_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_PLACES_field_code("[GROUPBY_3]", "-111");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_3_PLACES_TXT_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_PLACES_field_texte("[GROUPBY_3]", "-111");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="COLUMNBY_PLACES_OID_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_PLACES_field_id("[COLUMNBY]", "-111");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="COLUMNBY_PLACES_COD_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_PLACES_field_code("[COLUMNBY]", "-111");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="COLUMNBY_PLACES_TXT_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_PLACES_field_texte("[COLUMNBY]", "-111");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			
			<PROPERTY name="ACTIVITE_SIGNIFICATIVE_DATA">
				<value>
					<![CDATA[ 
						[EVAL 
							if ('[ACTIVITE_SIGNIFICATIVE_BASE]' == '-1') {
								return '';
							}
							if ('[ACTIVITE_SIGNIFICATIVE_BASE]' == 'REGSEJ') {
								return 'nb_entrees_directes + nb_externes + nb_ambulatoires';
							}
							if ('[ACTIVITE_SIGNIFICATIVE_BASE]' == 'REGJRN') {
								return '[VIEW.JOURNEES_FIELD] + nb_externes + nb_ambulatoires';
							}
							return 'v_mouvements_sejour_2.nb_journees_classement';
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="DISPLAY_TAUX">
				<value>
					<![CDATA[
						[EVAL 
							if (substr('[GROUPBY]',0,3) == 'SER') {return "1";}
							if (substr('[GROUPBY]',0,6) == 'SERCLS') {return "1";}
							if (substr('[GROUPBY]',0,3) == 'ETA') {return "1";}
							if (substr('[GROUPBY]',0,6) == 'ETACLS') {return "1";}
							if (substr('[GROUPBY]',0,3) == 'FIN') {return "1";}
							if (substr('[GROUPBY]',0,6) == 'FINCLS') {return "1";}
							return '0';
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="PLACES_FIELD">
				<value>
					<![CDATA[
						[EVAL 
							if ('[QPLACES]' == 'THEO') {return "nb_lits_theoriques";}
							return "nb_lits_ouverts";
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="PLACES_CP_FIELD">
				<value>
					<![CDATA[
						[EVAL 
							if ('[QPLACES]' == 'THEO') {return "nb_lits_cp_theoriques";}
							return "nb_lits_cp_ouverts";
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="JOURNEES_FIELD">
				<value>
					<![CDATA[
						[EVAL 
							$field = 'nb_jours';
							if ('[QJMUT]' == 'd') {$field = $field . '_d';}
							else {
								if ('[QJMUT]' == 'f') {$field = $field . '_f';}
								else {
									if ('[QJMUT]' == '12') {$field = $field . '_12';}
									else {
										if ('[QJMUT]' == 'prorata') {$field = $field . '_prorata';}
										else {
											$field = $field . '_f';
										}
									}
								}
							}
							return $field;
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="CP_FIELD">
				<value>
					<![CDATA[
						[EVAL 
							$field = 'nb_jours_cp';
							
							if ('[QJMUT]' == 'd') {$field = $field . '_d';}
							else {
								if ('[QJMUT]' == 'f') {$field = $field . '_f';}
								else {
									if ('[QJMUT]' == '12') {$field = $field . '_12';}
									else {
										$field = $field . '_f';
									}
								}
							}
							return $field;
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="MUTATION_FIELD">
				<value>
					<![CDATA[
						[EVAL 
							if ('[GROUPBY]' == 'SER') {return 'service';}
							if ('[GROUPBY]' == 'SERCLS01') {return 'service';}
							if ('[GROUPBY]' == 'SERCLS02') {return 'service';}
							if ('[GROUPBY]' == 'SERCLS03') {return 'service';}
							if ('[GROUPBY]' == 'SERCLS04') {return 'service';}
							if ('[GROUPBY]' == 'SERCLS05') {return 'service';}
							if ('[GROUPBY]' == 'UFT') {return 'service';}
							if ('[GROUPBY]' == 'UFTCLS01') {return 'service';}
							if ('[GROUPBY]' == 'UFTCLS02') {return 'service';}
							if ('[GROUPBY]' == 'UFTCLS03') {return 'service';}
							if ('[GROUPBY]' == 'UFTCLS04') {return 'service';}
							if ('[GROUPBY]' == 'UFTCLS05') {return 'service';}
							if ('[GROUPBY]' == 'ACT') {return 'activite';}
							if ('[GROUPBY]' == 'ACTCLS01') {return 'activite';}
							if ('[GROUPBY]' == 'ACTCLS02') {return 'activite';}
							if ('[GROUPBY]' == 'ACTCLS03') {return 'activite';}
							if ('[GROUPBY]' == 'ACTCLS04') {return 'activite';}
							if ('[GROUPBY]' == 'ACTCLS05') {return 'activite';}
							if ('[GROUPBY]' == 'ETA') {return 'etage';}
							if ('[GROUPBY]' == 'ETACLS01') {return 'etage';}
							if ('[GROUPBY]' == 'ETACLS02') {return 'etage';}
							if ('[GROUPBY]' == 'ETACLS03') {return 'etage';}
							if ('[GROUPBY]' == 'ETACLS04') {return 'etage';}
							if ('[GROUPBY]' == 'ETACLS05') {return 'etage';}
                            if (substr('[GROUPBY]',0,6) == 'ETACLS') {return 'etage';}
							if ('[GROUPBY]' == 'UM') {return 'unite_medicale';}
							if ('[GROUPBY]' == 'UMDCLS01') {return 'unite_medicale';}
							if ('[GROUPBY]' == 'UMDCLS02') {return 'unite_medicale';}
							if ('[GROUPBY]' == 'UMDCLS03') {return 'unite_medicale';}
							if ('[GROUPBY]' == 'UMDCLS04') {return 'unite_medicale';}
							if ('[GROUPBY]' == 'UMDCLS05') {return 'unite_medicale';}
							return 'service';
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="MUTATION_FIELD_TEXT">
				<value>
					<![CDATA[
						[EVAL 
							if ('[GROUPBY]' == 'SER') {return 'Serv';}
							if ('[GROUPBY]' == 'SERCLS01') {return 'Serv';}
							if ('[GROUPBY]' == 'SERCLS02') {return 'Serv';}
							if ('[GROUPBY]' == 'SERCLS03') {return 'Serv';}
							if ('[GROUPBY]' == 'SERCLS04') {return 'Serv';}
							if ('[GROUPBY]' == 'SERCLS05') {return 'Serv';}
							if ('[GROUPBY]' == 'UFT') {return 'Serv';}
							if ('[GROUPBY]' == 'UFTCLS01') {return 'Serv';}
							if ('[GROUPBY]' == 'UFTCLS02') {return 'Serv';}
							if ('[GROUPBY]' == 'UFTCLS03') {return 'Serv';}
							if ('[GROUPBY]' == 'UFTCLS04') {return 'Serv';}
							if ('[GROUPBY]' == 'UFTCLS05') {return 'Serv';}
							if ('[GROUPBY]' == 'ACT') {return 'Acti';}
							if ('[GROUPBY]' == 'ACTCLS01') {return 'Acti';}
							if ('[GROUPBY]' == 'ACTCLS02') {return 'Acti';}
							if ('[GROUPBY]' == 'ACTCLS03') {return 'Acti';}
							if ('[GROUPBY]' == 'ACTCLS04') {return 'Acti';}
							if ('[GROUPBY]' == 'ACTCLS05') {return 'Acti';}
							if ('[GROUPBY]' == 'ETA') {return 'Etage';}
							if ('[GROUPBY]' == 'ETACLS01') {return 'Etage';}
							if ('[GROUPBY]' == 'ETACLS02') {return 'Etage';}
							if ('[GROUPBY]' == 'ETACLS03') {return 'Etage';}
							if ('[GROUPBY]' == 'ETACLS04') {return 'Etage';}
							if ('[GROUPBY]' == 'ETACLS05') {return 'Etage';}
                            if (substr('[GROUPBY]',0,6) == 'ETACLS') {return 'Etage';}
							if ('[GROUPBY]' == 'UM') {return 'UM';}
							if ('[GROUPBY]' == 'UMDCLS01') {return 'UM';}
							if ('[GROUPBY]' == 'UMDCLS02') {return 'UM';}
							if ('[GROUPBY]' == 'UMDCLS03') {return 'UM';}
							if ('[GROUPBY]' == 'UMDCLS04') {return 'UM';}
							if ('[GROUPBY]' == 'UMDCLS05') {return 'UM';}
							return 'Serv';
						EVAL]
					]]>
				</value>
			</PROPERTY>
	
			<!--
			<PROPERTY name="DATA_SELECT_2">
				<value><![CDATA[[EVAL 
					
					switch ('[DATA]') {
						case 'NED':
							return 'AND nb_entrees_directes > 0';
							break;
						case 'NEM':
							return 'AND (nb_entrees_directes > 0 OR nb_entrees_mutation_[VIEW.MUTATION_FIELD] > 0)';
							break;
						case 'NSD':
							return 'AND nb_sorties_directes > 0';
							break;
						case 'NSM':
							return 'AND (nb_sorties_directes > 0 OR nb_sorties_mutation_[VIEW.MUTATION_FIELD] > 0)';
							break;
						case 'NJN':
							return 'AND [VIEW.JOURNEES_FIELD] > 0';
							break;
						case 'NEX':
							return 'AND nb_externes > 0';
							break;
						case 'NAM':
							return 'AND nb_ambulatoires > 0';
							break;
						case 'NEDA':
							return 'AND (nb_entrees_directes > 0 OR nb_ambulatoires > 0)';
							break;
						case 'NSDA':
							return 'AND (nb_sorties_directes > 0 OR nb_ambulatoires > 0)';
							break;
						case 'NEDXA':
							return 'AND (nb_entrees_directes > 0 OR nb_externes > 0 OR nb_ambulatoires > 0)';
							break;
						case 'NSDXA':
							return 'AND (nb_sorties_directes > 0 OR nb_externes > 0 OR nb_ambulatoires > 0)';
							break;
						case 'NSDXBB':
							return 'AND (nb_sorties_directes > 0 OR nb_bebes > 0 OR nb_ambulatoires > 0)';
							break;
						case 'NJNXA':
							return 'AND ([VIEW.JOURNEES_FIELD] > 0 OR nb_externes > 0 OR nb_ambulatoires > 0)';
							break;
						case 'NEDXAS':
							return 'AND (nb_entrees_directes > 0 OR nb_externes > 0 OR nb_ambulatoires > 0 OR nb_seances > 0)';
							break;
						case 'NSDXAS':
							return 'AND (nb_sorties_directes > 0 OR nb_externes > 0 OR nb_ambulatoires > 0 OR nb_seances > 0)';
							break;
						case 'NSDXASSH':
							return "AND (nb_sorties_directes > 0 OR nb_externes > 0 OR nb_ambulatoires > 0 OR CASE WHEN type_sejour = '5' THEN nb_seances ELSE 0 END > 0)";
							break;
						case 'NJNXAS':
							return 'AND ([VIEW.JOURNEES_FIELD] > 0 OR nb_externes > 0 OR nb_ambulatoires > 0 OR nb_seances > 0)';
							break;
						case 'NSE':
							return "AND nb_seances > 0";
							break;
						case 'NSEDIA':
							return "AND nb_seances_dialyse > 0";
							break;
						case 'NSECHM':
							return "AND nb_seances_chimio > 0";
							break;
						case 'NSEDIV':
							return "AND nb_seances_autre > 0";
							break;
						case 'NBB':
							return "AND nb_bebes > 0";
							break;
						case 'NCP':
							return "AND [VIEW.CP_FIELD] > 0";
							break;
						case 'NJO':
							return "";
							break;
						case 'NJNM':
							return 'AND [VIEW.JOURNEES_FIELD] > 0';
							break;
						case 'NEXM':
							return 'AND nb_externes > 0';
							break;
						case 'NAMM':
							return 'AND nb_ambulatoires > 0';
							break;
						case 'NSEM':
							return "AND nb_seances > 0";
							break;
						case 'NJNXAM':
							return 'AND ([VIEW.JOURNEES_FIELD] > 0 OR nb_externes > 0 OR nb_ambulatoires > 0)';
							break;
						case 'TAU':
							return 'AND ([VIEW.JOURNEES_FIELD] > 0 OR nb_ambulatoires > 0 OR nb_seances_dans_taux > 0)';
							break;
						default:
							return '';
					}
			EVAL]]]></value>
		</PROPERTY>
			
			<PROPERTY name="CDATA_2">
				<value><![CDATA[[EVAL 
					
					switch ('[DATA]') {
						case 'NED':
							return 'SUM(CASE WHEN COLUMNCHECKSEQUENCE THEN nb_entrees_directes ELSE null END)';
							break;
						case 'NEM':
							return 'SUM(CASE WHEN COLUMNCHECKSEQUENCE THEN nb_entrees_directes + nb_entrees_mutation_[VIEW.MUTATION_FIELD] ELSE null END)';
							break;
						case 'NSD':
							return 'SUM(CASE WHEN COLUMNCHECKSEQUENCE THEN nb_sorties_directes ELSE null END)';
							break;
						case 'NSM':
							return 'SUM(CASE WHEN COLUMNCHECKSEQUENCE THEN nb_sorties_directes + nb_sorties_mutation_[VIEW.MUTATION_FIELD] ELSE null END)';
							break;
						case 'NJN':
							return 'SUM(CASE WHEN COLUMNCHECKSEQUENCE THEN [VIEW.JOURNEES_FIELD] ELSE null END)';
							break;
						case 'NEX':
							return 'SUM(CASE WHEN COLUMNCHECKSEQUENCE THEN nb_externes ELSE null END)';
							break;
						case 'NAM':
							return 'SUM(CASE WHEN COLUMNCHECKSEQUENCE THEN nb_ambulatoires ELSE null END)';
							break;
						case 'NEDA':
							return 'SUM(CASE WHEN COLUMNCHECKSEQUENCE THEN nb_entrees_directes + nb_ambulatoires ELSE null END)';
							break;
						case 'NSDA':
							return 'SUM(CASE WHEN COLUMNCHECKSEQUENCE THEN nb_sorties_directes + nb_ambulatoires ELSE null END)';
							break;
						case 'NEDXA':
							return 'SUM(CASE WHEN COLUMNCHECKSEQUENCE THEN nb_entrees_directes + nb_externes + nb_ambulatoires ELSE null END)';
							break;
						case 'NSDXA':
							return 'SUM(CASE WHEN COLUMNCHECKSEQUENCE THEN nb_sorties_directes + nb_externes + nb_ambulatoires ELSE null END)';
							break;
						case 'NSDXBB':
							return 'SUM(CASE WHEN COLUMNCHECKSEQUENCE THEN nb_sorties_directes + nb_bebes + nb_ambulatoires ELSE null END)';
							break;
						case 'NJNXA':
							return 'SUM(CASE WHEN COLUMNCHECKSEQUENCE THEN [VIEW.JOURNEES_FIELD] + nb_externes + nb_ambulatoires ELSE null END)';
							break;
						case 'NEDXAS':
							return 'SUM(CASE WHEN COLUMNCHECKSEQUENCE THEN nb_entrees_directes + nb_externes + nb_ambulatoires + nb_seances_dans_taux ELSE null END)';
							break;
						case 'NSDXAS':
							return 'SUM(CASE WHEN COLUMNCHECKSEQUENCE THEN nb_sorties_directes + nb_externes + nb_ambulatoires + nb_seances_dans_taux ELSE null END)';
							break;
						case 'NSDXASSH':
							return "SUM(CASE WHEN COLUMNCHECKSEQUENCE THEN nb_sorties_directes + nb_externes + nb_ambulatoires + CASE WHEN type_sejour = '5' THEN nb_seances ELSE 0 END ELSE null END)";
							break;	
						case 'NJNXAS':
							return 'SUM(CASE WHEN COLUMNCHECKSEQUENCE THEN [VIEW.JOURNEES_FIELD] + nb_externes + nb_ambulatoires + nb_seances_dans_taux ELSE null END)';
							break;
						case 'NSE':
							return "SUM(CASE WHEN COLUMNCHECKSEQUENCE THEN nb_seances ELSE null END)";
							break;
						case 'NSEDIA':
							return "SUM(CASE WHEN COLUMNCHECKSEQUENCE THEN nb_seances_dialyse ELSE null END)";
							break;
						case 'NSECHM':
							return "SUM(CASE WHEN COLUMNCHECKSEQUENCE THEN nb_seances_chimio ELSE null END)";
							break;
						case 'NSEDIV':
							return "SUM(CASE WHEN COLUMNCHECKSEQUENCE THEN nb_seances_autre ELSE null END)";
							break;
						case 'NBB':
							return "SUM(CASE WHEN COLUMNCHECKSEQUENCE THEN nb_bebes ELSE null END)";
							break;
						case 'NCP':
							return "SUM(CASE WHEN COLUMNCHECKSEQUENCE THEN [VIEW.CP_FIELD] ELSE null END)";
							break;
						case 'NJO':
							return "COUNT(DISTINCT CASE WHEN COLUMNCHECKSEQUENCE THEN date ELSE null END)";
							break;
						case 'NJNM':
							if ('[MOY]' == 'O') {
								return "base.cti_division(SUM(CASE WHEN COLUMNCHECKSEQUENCE THEN [VIEW.JOURNEES_FIELD] ELSE null END), COUNT(CASE WHEN COLUMNCHECKSEQUENCE THEN DISTINCT date ELSE null END))";
							}
							else {
								return "base.cti_division(SUM(CASE WHEN COLUMNCHECKSEQUENCE THEN [VIEW.JOURNEES_FIELD] ELSE null END), MAX(date(date)) - MIN(date(date)) + 1)";
							}
							break;
						case 'NEXM':
							if ('[MOY]' == 'O') {
								return "base.cti_division(SUM(CASE WHEN COLUMNCHECKSEQUENCE THEN nb_externes ELSE null END), COUNT(DISTINCT CASE WHEN COLUMNCHECKSEQUENCE THEN date ELSE null END))";
							}
							else {
								return "base.cti_division(SUM(CASE WHEN COLUMNCHECKSEQUENCE THEN nb_externes ELSE null END), MAX(date(date)) - MIN(date(date)) + 1)";
							}
							break;
						case 'NAMM':
							if ('[MOY]' == 'O') {
								return "base.cti_division(SUM(CASE WHEN COLUMNCHECKSEQUENCE THEN nb_ambulatoires ELSE null END), COUNT(DISTINCT CASE WHEN COLUMNCHECKSEQUENCE THEN date ELSE null END))";


							}
							else {
								return "base.cti_division(SUM(CASE WHEN COLUMNCHECKSEQUENCE THEN nb_ambulatoires ELSE null END), MAX(date(date)) - MIN(date(date)) + 1)";
							}
							break;
						case 'NSEM':
							if ('[MOY]' == 'O') {
								return "base.cti_division(SUM(CASE WHEN COLUMNCHECKSEQUENCE THEN nb_seances ELSE null END), COUNT(DISTINCT CASE WHEN COLUMNCHECKSEQUENCE THEN date ELSE null END))";
							}
							else {
								return "base.cti_division(SUM(CASE WHEN COLUMNCHECKSEQUENCE THEN nb_seances ELSE null END), MAX(date(date)) - MIN(date(date)) + 1)";
							}
							break;
						case 'NJNXAM':
							if ('[MOY]' == 'O') {
								return "base.cti_division(SUM(CASE WHEN COLUMNCHECKSEQUENCE THEN [VIEW.JOURNEES_FIELD] + nb_externes + nb_ambulatoires ELSE null END), COUNT(DISTINCT CASE WHEN COLUMNCHECKSEQUENCE THEN date ELSE null END))";
							}
							else {
								return "base.cti_division(SUM(CASE WHEN COLUMNCHECKSEQUENCE THEN [VIEW.JOURNEES_FIELD] + nb_externes + nb_ambulatoires ELSE null END), MAX(date(date)) - MIN(date(date)) + 1)";
							}
							break;
						case 'TAU':
							return "SUM(CASE WHEN COLUMNCHECKSEQUENCE THEN [VIEW.JOURNEES_FIELD] + nb_ambulatoires + nb_seances_dans_taux ELSE null END)";
							break;
						default:
							return '0';
					}
			EVAL]]]></value>
		</PROPERTY>
		-->
		
		</VIEWPROPERTIES>

	</COMPONENT>
    
    
    <COMPONENT name="PROPERTIES_OCCUPATION_BLOC" label="Propriétés diverses SELECT occupation bloc" >
	
		<VIEWPROPERTIES>
		
			<PROPERTY name="CONTEXTE" value="OCCUPATION_BLOC" >
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_OID_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_OCCUPATION_BLOC_field_id("[GROUPBY]", "lieu_etage");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_COD_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_OCCUPATION_BLOC_field_code("[GROUPBY]", "lieu_etage");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_TXT_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_OCCUPATION_BLOC_field_texte("[GROUPBY]", "lieu_etage");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_2_OID_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_OCCUPATION_BLOC_field_id("[GROUPBY_2]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_2_COD_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_OCCUPATION_BLOC_field_code("[GROUPBY_2]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_2_TXT_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_OCCUPATION_BLOC_field_texte("[GROUPBY_2]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_3_OID_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_OCCUPATION_BLOC_field_id("[GROUPBY_3]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_3_COD_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_OCCUPATION_BLOC_field_code("[GROUPBY_3]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_3_TXT_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_OCCUPATION_BLOC_field_texte("[GROUPBY_3]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="COLUMNBY_OID_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_OCCUPATION_BLOC_field_id("[COLUMNBY]", "lieu_etage");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="COLUMNBY_COD_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_OCCUPATION_BLOC_field_code("[COLUMNBY]", "lieu_etage");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="COLUMNBY_TXT_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_OCCUPATION_BLOC_field_texte("[COLUMNBY]", "lieu_etage");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			
			
			
			<PROPERTY name="ACTIVITE_SIGNIFICATIVE_DATA">
				<value>
					<![CDATA[ 
						[EVAL 
							if ('[ACTIVITE_SIGNIFICATIVE_BASE]' == '-1') {
								return '';
							}
							if ('[ACTIVITE_SIGNIFICATIVE_BASE]' == 'REGSEJ') {
								return 'nb_entrees_directes + nb_externes + nb_ambulatoires';
							}
							if ('[ACTIVITE_SIGNIFICATIVE_BASE]' == 'REGJRN') {
								return '[VIEW.JOURNEES_FIELD] + nb_externes + nb_ambulatoires';
							}
							return 'v_mouvements_sejour_2.nb_journees_classement';
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			
		
		</VIEWPROPERTIES>

	</COMPONENT>
	
	<COMPONENT name="PROPERTIES_RAPPORT" label="Propriétés diverses SELECT rapports" >
	
		<VIEWPROPERTIES>
		
			<PROPERTY name="CONTEXTE" value="RAPPORT" >
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_OID_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_RAPPORT_field_id("[GROUPBY]", "lieu_etage");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_COD_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_RAPPORT_field_code("[GROUPBY]", "lieu_etage");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_TXT_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_RAPPORT_field_texte("[GROUPBY]", "lieu_etage");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			
			<PROPERTY name="GROUPBY_2_OID_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_RAPPORT_field_id("[GROUPBY_2]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_2_COD_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_RAPPORT_field_code("[GROUPBY_2]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_2_TXT_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_RAPPORT_field_texte("[GROUPBY_2]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_3_OID_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_RAPPORT_field_id("[GROUPBY_3]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_3_COD_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_RAPPORT_field_code("[GROUPBY_3]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_3_TXT_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_RAPPORT_field_texte("[GROUPBY_3]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			
			<PROPERTY name="GROUPBY_PLACES_OID_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_RAPPORT_PLACES_field_id("[GROUPBY]", "-111");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_PLACES_COD_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_RAPPORT_PLACES_field_code("[GROUPBY]", "-111");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_PLACES_TXT_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_RAPPORT_PLACES_field_texte("[GROUPBY]", "-111");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			
			<PROPERTY name="GROUPBY_2_PLACES_OID_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_RAPPORT_PLACES_field_id("[GROUPBY_2]", "-111");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_2_PLACES_COD_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_RAPPORT_PLACES_field_code("[GROUPBY_2]", "-111");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_2_PLACES_TXT_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_RAPPORT_PLACES_field_texte("[GROUPBY_2]", "-111");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_3_PLACES_OID_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_RAPPORT_PLACES_field_id("[GROUPBY_3]", "-111");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_3_PLACES_COD_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_RAPPORT_PLACES_field_code("[GROUPBY_3]", "-111");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_3_PLACES_TXT_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_RAPPORT_PLACES_field_texte("[GROUPBY_3]", "-111");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			
			
			<PROPERTY name="GROUPBY_BUDGET_OID_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_RAPPORT_BUDGET_field_id("[GROUPBY]", "-111");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_BUDGET_COD_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_RAPPORT_BUDGET_field_code("[GROUPBY]", "-111");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_BUDGET_TXT_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_RAPPORT_BUDGET_field_texte("[GROUPBY]", "-111");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			
			<PROPERTY name="GROUPBY_2_BUDGET_OID_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_RAPPORT_BUDGET_field_id("[GROUPBY_2]", "-111");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_2_BUDGET_COD_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_RAPPORT_BUDGET_field_code("[GROUPBY_2]", "-111");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_2_BUDGET_TXT_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_RAPPORT_BUDGET_field_texte("[GROUPBY_2]", "-111");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_3_BUDGET_OID_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_RAPPORT_BUDGET_field_id("[GROUPBY_3]", "-111");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_3_BUDGET_COD_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_RAPPORT_BUDGET_field_code("[GROUPBY_3]", "-111");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_3_BUDGET_TXT_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_RAPPORT_BUDGET_field_texte("[GROUPBY_3]", "-111");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			
			
			<PROPERTY name="GROUPBY_BUDGET_OID_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_RAPPORT_BUDGET_field_id("[GROUPBY]", "-111");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_BUDGET_COD_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_RAPPORT_BUDGET_field_code("[GROUPBY]", "-111");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_BUDGET_TXT_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_RAPPORT_BUDGET_field_texte("[GROUPBY]", "-111");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			
			<PROPERTY name="GROUPBY_2_BUDGET_OID_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_RAPPORT_BUDGET_field_id("[GROUPBY_2]", "-111");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_2_BUDGET_COD_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_RAPPORT_BUDGET_field_code("[GROUPBY_2]", "-111");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_2_BUDGET_TXT_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_RAPPORT_BUDGET_field_texte("[GROUPBY_2]", "-111");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_3_BUDGET_OID_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_RAPPORT_BUDGET_field_id("[GROUPBY_3]", "-111");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_3_BUDGET_COD_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_RAPPORT_BUDGET_field_code("[GROUPBY_3]", "-111");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_3_BUDGET_TXT_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_RAPPORT_BUDGET_field_texte("[GROUPBY_3]", "-111");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
		</VIEWPROPERTIES>

	</COMPONENT>
	
	<COMPONENT name="PROPERTIES_ETATDOSSIERS" label="Propriétés diverses état dossiers de séjour" >
	
		<VIEWPROPERTIES>
		
			<PROPERTY dataLink="PROPERTIES_ETATDOSSIERS_QUERY" nameField="name" valueField="value" />
		
			<PROPERTY name="CONTEXTE" value="ETATDOSSIERS" >
			</PROPERTY>
		
			<PROPERTY name="CLIHON">
				<value>
					<![CDATA[
						[EVAL 
							$prefixe = '';
							if ('[CLIHON]' == 'C') {return '_c';}
							if ('[CLIHON]' == 'H') {return '_h';}

							return '';
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="DATE_GBY">
				<value><![CDATA[[EVAL 
	
							if('[GROUPBY]' == 'ANNEEF' || '[GROUPBY]' == 'TRIMF' || '[GROUPBY]' == 'JOURF' || '[GROUPBY]' == 'NUMEROTRIMF' || '[GROUPBY]' == 'NUMEROMOISF' || '[GROUPBY]' == 'NUMEROJOURF' || '[GROUPBY]' == 'SEMAINEANNEF' || '[GROUPBY]' == 'JOURSF' || '[GROUPBY]' == 'SEMAINEWEF' 
                            || '[GROUPBY_2]' == 'ANNEEF' || '[GROUPBY_2]' == 'TRIMF' || '[GROUPBY_2]' == 'JOURF' || '[GROUPBY_2]' == 'NUMEROTRIMF' || '[GROUPBY_2]' == 'NUMEROMOISF' || '[GROUPBY_2]' == 'NUMEROJOURF' || '[GROUPBY_2]' == 'SEMAINEANNEF' || '[GROUPBY_2]' == 'JOURSF' || '[GROUPBY_2]' == 'SEMAINEWEF'
                            || '[GROUPBY_3]' == 'ANNEEF' || '[GROUPBY_3]' == 'TRIMF' || '[GROUPBY_3]' == 'JOURF' || '[GROUPBY_3]' == 'NUMEROTRIMF' || '[GROUPBY_3]' == 'NUMEROMOISF' || '[GROUPBY_3]' == 'NUMEROJOURF' || '[GROUPBY_3]' == 'SEMAINEANNEF' || '[GROUPBY_3]' == 'JOURSF' || '[GROUPBY_3]' == 'SEMAINEWEF') 
                            {return 'v_factures_reference_1.date_fin_facture';}
							if('[GROUPBY]' == 'ANNEEEX' || '[GROUPBY]' == 'TRIMEX' || '[GROUPBY]' == 'JOUREX' || '[GROUPBY]' == 'NUMEROTRIMEX' || '[GROUPBY]' == 'NUMEROMOISEX' || '[GROUPBY]' == 'NUMEROJOUREX' || '[GROUPBY]' == 'SEMAINEANNEEX' || '[GROUPBY]' == 'JOURSEX' || '[GROUPBY]' == 'SEMAINEWEEX' 
                            || '[GROUPBY_2]' == 'ANNEEEX' || '[GROUPBY_2]' == 'TRIMEX' || '[GROUPBY_2]' == 'JOUREX' || '[GROUPBY_2]' == 'NUMEROTRIMEX' || '[GROUPBY_2]' == 'NUMEROMOISEX' || '[GROUPBY_2]' == 'NUMEROJOUREX' || '[GROUPBY_2]' == 'SEMAINEANNEEX' || '[GROUPBY_2]' == 'JOURSEX' || '[GROUPBY_2]' == 'SEMAINEWEEX'
                            || '[GROUPBY_3]' == 'ANNEEEX' || '[GROUPBY_3]' == 'TRIMEX' || '[GROUPBY_3]' == 'JOUREX' || '[GROUPBY_3]' == 'NUMEROTRIMEX' || '[GROUPBY_3]' == 'NUMEROMOISEX' || '[GROUPBY_3]' == 'NUMEROJOUREX' || '[GROUPBY_3]' == 'SEMAINEANNEEX' || '[GROUPBY_3]' == 'JOURSEX' || '[GROUPBY_3]' == 'SEMAINEWEEX') 
                            {return 'v_factures_reference_1.date_expedition';}
							
                            return 'v_factures_reference_1.date_fin_facture';
				EVAL]]]></value>
			</PROPERTY>
			<PROPERTY name="LEVELD_VIEW">
				<value>
					<![CDATA[
						[EVAL 
							if ('[QDETAIL_TIERS]' == '1') {return 'v_factures_reference_tiers_1';}
							if ('[TIERS]' != '-1') {return 'v_factures_reference_tiers_1';}
							
							return "v_factures_reference_1";
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="LEVEL0_VIEW">
				<value>
					<![CDATA[
						[EVAL 
							if ('[TIERS]' != '-1') {return 'v_factures_reference_tiers_1';}
							
							return "v_factures_reference_1";
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			
			<PROPERTY name="LEVEL1_VIEW">
				<value>
					<![CDATA[
						[EVAL 
							if ('[TIERS]' != '-1') {return 'v_factures_reference_tiers_1';}
						
							if ('[GROUPBY]' == 'TTP') {return 'v_factures_reference_tiers_1';}
							if ('[GROUPBY]' == 'TRG') {return 'v_factures_reference_tiers_1';}
							if ('[GROUPBY]' == 'TPY') {return 'v_factures_reference_tiers_1';}
							if (substr('[GROUPBY]',0,6) == 'TPYCLS') {return 'v_factures_reference_tiers_1';}
							
							return "v_factures_reference_1";
						EVAL]
					]]>
				</value>
			</PROPERTY>

			<PROPERTY name="LEVEL2_VIEW">
				<value>
					<![CDATA[
						[EVAL 
							if ('[TIERS]' != '-1') {return 'v_factures_reference_tiers_1';}
							
							if ('[GROUPBY]' == 'TTP') {return 'v_factures_reference_tiers_1';}
							if ('[GROUPBY]' == 'TRG') {return 'v_factures_reference_tiers_1';}
							if ('[GROUPBY]' == 'TPY') {return 'v_factures_reference_tiers_1';}
							if (substr('[GROUPBY]',0,6) == 'TPYCLS') {return 'v_factures_reference_tiers_1';}
							
							if ('[GROUPBY_2]' == 'TTP') {return 'v_factures_reference_tiers_1';}
							if ('[GROUPBY_2]' == 'TRG') {return 'v_factures_reference_tiers_1';}
							if ('[GROUPBY_2]' == 'TPY') {return 'v_factures_reference_tiers_1';}
							if (substr('[GROUPBY_2]',0,6) == 'TPYCLS') {return 'v_factures_reference_tiers_1';}
							
							return "v_factures_reference_1";
						EVAL]
					]]>
				</value>
			</PROPERTY>
			<PROPERTY name="LEVEL3_VIEW">
				<value>
					<![CDATA[
						[EVAL 
							if ('[TIERS]' != '-1') {return 'v_factures_reference_tiers_1';}
							
							if ('[GROUPBY]' == 'TTP') {return 'v_factures_reference_tiers_1';}
							if ('[GROUPBY]' == 'TRG') {return 'v_factures_reference_tiers_1';}
							if ('[GROUPBY]' == 'TPY') {return 'v_factures_reference_tiers_1';}
							if (substr('[GROUPBY]',0,6) == 'TPYCLS') {return 'v_factures_reference_tiers_1';}
							
							if ('[GROUPBY_2]' == 'TTP') {return 'v_factures_reference_tiers_1';}
							if ('[GROUPBY_2]' == 'TRG') {return 'v_factures_reference_tiers_1';}
							if ('[GROUPBY_2]' == 'TPY') {return 'v_factures_reference_tiers_1';}
							if (substr('[GROUPBY_2]',0,6) == 'TPYCLS') {return 'v_factures_reference_tiers_1';}
							
							if ('[GROUPBY_3]' == 'TTP') {return 'v_factures_reference_tiers_1';}
							if ('[GROUPBY_3]' == 'TRG') {return 'v_factures_reference_tiers_1';}
							if ('[GROUPBY_3]' == 'TPY') {return 'v_factures_reference_tiers_1';}
							if (substr('[GROUPBY_3]',0,6) == 'TPYCLS') {return 'v_factures_reference_tiers_1';}
							
							return "v_factures_reference_1";
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_OID_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_ETATDOSSIER_field_id("[GROUPBY]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_COD_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_ETATDOSSIER_field_code("[GROUPBY]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_TXT_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_ETATDOSSIER_field_texte("[GROUPBY]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_2_OID_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_ETATDOSSIER_field_id("[GROUPBY_2]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_2_COD_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_ETATDOSSIER_field_code("[GROUPBY_2]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_2_TXT_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_ETATDOSSIER_field_texte("[GROUPBY_2]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_3_OID_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_ETATDOSSIER_field_id("[GROUPBY_3]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_3_COD_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_ETATDOSSIER_field_code("[GROUPBY_3]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_3_TXT_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_ETATDOSSIER_field_texte("[GROUPBY_3]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="COLUMNBY_OID_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_ETATDOSSIER_field_id("[COLUMNBY]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="COLUMNBY_COD_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_ETATDOSSIER_field_code("[COLUMNBY]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="COLUMNBY_TXT_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_ETATDOSSIER_field_texte("[COLUMNBY]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>

            <PROPERTY name="QUELLEDATE_FIELD" value="" >
                <value>
                    <![CDATA[
                        [EVAL 
                            return ACTI_get_quelledate2_etat_dossier("[QUELLEDATE]");
                        EVAL]
                    ]]>
                </value>
            </PROPERTY>
			
		</VIEWPROPERTIES>
		
		<QUERIES>
			
			<QUERY type="propertiesLink" name="PROPERTIES_ETATDOSSIERS_QUERY" forRows="false" forSelections="false"> 
			
				<SQL>
					<select>
						<![CDATA[
							SELECT 'NOW_ACTIVITE', valeur_date FROM activite.t_divers WHERE code = 'NOW';
						]]>
					</select>
					<FIELDS>
						<FIELD name="name" />
						<FIELD name="value" />
					</FIELDS>
				</SQL>
				
				<SQL>
					<select>
						<![CDATA[
							SELECT 'NOW_ACTIVITE_TXT', valeur_date FROM activite.t_divers WHERE code = 'NOW';
						]]>
					</select>
					<FIELDS>
						<FIELD name="name" />
						<FIELD name="value" />
					</FIELDS>
				</SQL>
				
				<SQL>
					<select>
						<![CDATA[
							SELECT 'NOW_ACTIVITE_GE', CASE WHEN date('[TOPERIODE]'::date + interval '2 day') >= valeur_date THEN '1' ELSE '0' END 
							FROM activite.t_divers WHERE code = 'NOW';
						]]>
					</select>
					<FIELDS>
						<FIELD name="name" />
						<FIELD name="value" />
					</FIELDS>
				</SQL>
                
                <SQL>
					<select>
						<![CDATA[
							SELECT 'NFACBG', CASE WHEN count(*) > 0 THEN '1' ELSE '0' END
                            FROM activite.p_factures_reference
                            WHERE nb_non_calcules_bg > 0
						]]>
					</select>
					<FIELDS>
						<FIELD name="name" />
						<FIELD name="value" />
					</FIELDS>
				</SQL>
                
				
			</QUERY>
			
		</QUERIES>
		
	</COMPONENT>
	
	<COMPONENT name="PROPERTIES_COMPTE_CLIENT" label="Propriétés diverses compte client" >
	
		<VIEWPROPERTIES>
		
			<PROPERTY name="CONTEXTE" value="CLIENT" >
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_OID_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_CLIENT_field_id("[GROUPBY]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_COD_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_CLIENT_field_code("[GROUPBY]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_TXT_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_CLIENT_field_texte("[GROUPBY]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_2_OID_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_CLIENT_field_id("[GROUPBY_2]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_2_COD_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_CLIENT_field_code("[GROUPBY_2]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_2_TXT_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_CLIENT_field_texte("[GROUPBY_2]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_3_OID_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_CLIENT_field_id("[GROUPBY_3]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_3_COD_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_CLIENT_field_code("[GROUPBY_3]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_3_TXT_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_CLIENT_field_texte("[GROUPBY_3]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="COLUMNBY_OID_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_CLIENT_field_id("[COLUMNBY]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="COLUMNBY_COD_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_CLIENT_field_code("[COLUMNBY]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="COLUMNBY_TXT_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_CLIENT_field_texte("[COLUMNBY]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			
		</VIEWPROPERTIES>
		
	</COMPONENT>
	
	<COMPONENT name="PROPERTIES_COMPTE_CLIENT_H" label="Propriétés diverses compte client" >
	
		<VIEWPROPERTIES>
		
			<PROPERTY name="CONTEXTE" value="CLIENT_H" >
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_OID_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_CLIENT_H_field_id("[GROUPBY]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_COD_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_CLIENT_H_field_code("[GROUPBY]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_TXT_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_CLIENT_H_field_texte("[GROUPBY]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_2_OID_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_CLIENT_H_field_id("[GROUPBY_2]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_2_COD_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_CLIENT_H_field_code("[GROUPBY_2]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_2_TXT_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_CLIENT_H_field_texte("[GROUPBY_2]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_3_OID_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_CLIENT_H_field_id("[GROUPBY_3]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_3_COD_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_CLIENT_H_field_code("[GROUPBY_3]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="GROUPBY_3_TXT_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_CLIENT_H_field_texte("[GROUPBY_3]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="COLUMNBY_OID_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_CLIENT_H_field_id("[COLUMNBY]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="COLUMNBY_COD_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_CLIENT_H_field_code("[COLUMNBY]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
			
			<PROPERTY name="COLUMNBY_TXT_FIELD" value="" >
				<value>
					<![CDATA[
						[EVAL 
							return ACTI_CLIENT_H_field_texte("[COLUMNBY]", "");
						EVAL]
					]]>
				</value>
			</PROPERTY>
	
		</VIEWPROPERTIES>
		
	</COMPONENT>
	
	<COMPONENT name="STANDARD_BASE_VIEWLINK">
	
		<ARG name="ORIGINEGEO_PATIENT">
			<value>
				<![CDATA[
					if (SELECT.GROUPBY_2.substr(0,6) == 'CDPCLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2} 
					if (SELECT.GROUPBY.substr(0,6) == 'CDPCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1} 
					if (SELECT.GROUPBY_2 == 'CODEPOST' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'CP' + ROW.OID2}
					if (SELECT.GROUPBY == 'CODEPOST') {return 'CP' + ROW.OID1}
					if (SELECT.GROUPBY_2 == 'DEPARTEMENT' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'DP' + ROW.OID2}
					if (SELECT.GROUPBY == 'DEPARTEMENT') {return 'DP' + ROW.OID1}
					if (SELECT.GROUPBY_2 == 'TERSANTE' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'TS' + ROW.OID2}
					if (SELECT.GROUPBY == 'TERSANTE') {return 'TS' + ROW.OID1}
					if (SELECT.GROUPBY_2 == 'CODEGEOPMSI' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'GP' + ROW.OID2}
					if (SELECT.GROUPBY == 'CODEGEOPMSI') {return 'GP' + ROW.OID1}
				]]>
			</value>
		</ARG>
		
		<ARG name="TYPESEJOUR">
			<value>
				<![CDATA[
					if (SELECT.GROUPBY_3 == 'TSE' && ROW.OID2 != '0' && ROW.OID3 != '-9999999') {return 'DT' + ROW.OID3}
					if (SELECT.GROUPBY_2 == 'TSE' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'DT' + ROW.OID2}
					if (SELECT.GROUPBY == 'TSE') {return 'DT' + ROW.OID1}
				]]>
			</value>
		</ARG>
        
        <ARG name="FORMEACTIVITE">
			<value>
				<![CDATA[
					if (SELECT.GROUPBY_3.substr(0,6) == 'FOACLS' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'LS' + SELECT.GROUPBY_3.substr(6,2) + ROW.OID3} 
					if (SELECT.GROUPBY_3 == 'FOA' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'DT' + ROW.OID3} 
					if (SELECT.GROUPBY_2.substr(0,6) == 'FOACLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2} 
                    if (SELECT.GROUPBY_2 == 'FOA' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'DT' + ROW.OID2} 
                    if (SELECT.GROUPBY.substr(0,6) == 'FOACLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1} 
                    if (SELECT.GROUPBY == 'FOA') {return 'DT' + ROW.OID1} 
				]]>
			</value>
		</ARG>
		
		<ARG name="FILIERESOINSEJOUR">
			<value>
				<![CDATA[
					if (SELECT.GROUPBY_2.substr(0,6) == 'FSPCLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,1) + ROW.OID2} 
                    if (SELECT.GROUPBY_2 == 'FSP' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'DT' + ROW.OID2} 
                    if (SELECT.GROUPBY.substr(0,6) == 'FSPCLS') {return 'LS' + SELECT.GROUPBY.substr(6,1) + ROW.OID1} 
                    if (SELECT.GROUPBY == 'FSP') {return 'DT' + ROW.OID1} 
				]]>
			</value>
		</ARG>
		
		<ARG name="T_AGE_PATIENT">
			<value><![CDATA[ 
				
				if (SELECT.GROUPBY_2.substr(0,6) == 'AGECLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2} 
				if (SELECT.GROUPBY_2 == 'AGE' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'AG' + ROW.OID2} 
				if (SELECT.GROUPBY.substr(0,6) == 'AGECLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1} 
				if (SELECT.GROUPBY == 'AGE') {return 'AG' + ROW.OID1} 
				
			]]></value>
		</ARG>
		
		<ARG name="SEXE_PATIENT">
			<value><![CDATA[ 
				
				if (SELECT.GROUPBY_2 == 'SEXE' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {
					if (Number(ROW.OID2) < 3) {return ROW.OID2;} else { return 3;}
				} 
				if (SELECT.GROUPBY == 'SEXE') {
					if (Number(ROW.OID1) < 3) {return ROW.OID1;} else { return 3;}
				} 
				
			]]></value>
		</ARG>
		
		<ARG name="T_DUREE_SEJOUR">
			<value><![CDATA[ 
				
				if (SELECT.GROUPBY_2.substr(0,6) == 'DSJCLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2} 
				if (SELECT.GROUPBY_2 == 'DUREE_SEJOUR' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'DU' + ROW.OID2} 
				if (SELECT.GROUPBY.substr(0,6) == 'DSJCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1} 
				if (SELECT.GROUPBY == 'DUREE_SEJOUR') {return 'DU' + ROW.OID1} 
				
			]]></value>
		</ARG>
        <ARG name="T_DUREE_OCCUP">
			<value><![CDATA[ 
				if (SELECT.GROUPBY_3 == 'DUREE_OCCUP' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'DO' + ROW.OID3} 
				if (SELECT.GROUPBY_2 == 'DUREE_OCCUP' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'DO' + ROW.OID2} 
				if (SELECT.GROUPBY == 'DUREE_OCCUP') {return 'DO' + ROW.OID1} 
				
			]]></value>
		</ARG>
		
		<ARG name="MODETRAITEMENT">
			<value>
				<![CDATA[
					if (SELECT.GROUPBY_2 == 'MTR' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'MT' + ROW.OID2}
					if (SELECT.GROUPBY == 'MTR') {return 'MT' + ROW.OID1}
				]]>
			</value>
		</ARG>
		
		<ARG name="GHS">
			<value>
				<![CDATA[
					if (SELECT.GROUPBY_2 == 'GHS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'GH' + ROW.OID2}
					if (SELECT.GROUPBY == 'GHS') {return 'GH' + ROW.OID1}
				]]>
			</value>
		</ARG>
		
		<ARG name="GHM">
			<value>
				<![CDATA[
					if (SELECT.GROUPBY_3.substr(0,6) == 'GHMCLS' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'LS' + SELECT.GROUPBY_3.substr(6,2) + ROW.OID3} 
					if (SELECT.GROUPBY_3 == 'GHM' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'GM' + ROW.OID3} 
					if (SELECT.GROUPBY_3 == 'GHM5' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'G5' + ROW.OID3} 
					if (SELECT.GROUPBY_3 == 'CMD' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'CM' + ROW.OID3} 
					if (SELECT.GROUPBY_3 == 'GHMSEV' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'SV' + ROW.OID3}
				
					if (SELECT.GROUPBY_2.substr(0,6) == 'GHMCLS' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2} 
					if (SELECT.GROUPBY_2 == 'GHM' && ROW.OID2 != '-9999999') {return 'GM' + ROW.OID2} 
					if (SELECT.GROUPBY_2 == 'GHM5' && ROW.OID2 != '-9999999') {return 'G5' + ROW.OID2} 
					if (SELECT.GROUPBY_2 == 'CMD' && ROW.OID2 != '-9999999') {return 'CM' + ROW.OID2} 
					if (SELECT.GROUPBY_2 == 'GHMSEV' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'SV' + ROW.OID2}
					if (SELECT.GROUPBY.substr(0,6) == 'GHMCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1} 
					if (SELECT.GROUPBY == 'GHM') {return 'GM' + ROW.OID1} 
					if (SELECT.GROUPBY == 'GHM5') {return 'G5' + ROW.OID1} 
					if (SELECT.GROUPBY == 'CMD') {return 'CM' + ROW.OID1} 
					if (SELECT.GROUPBY == 'GHMSEV') {return 'SV' + ROW.OID1}
				]]>
			</value>
		</ARG>
		<ARG name="GME">
			<value>
				<![CDATA[
                    if (SELECT.GROUPBY_3.substr(0,6) == 'GMECLS' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'LS' + SELECT.GROUPBY_3.substr(6,2) + ROW.OID3} 
					if (SELECT.GROUPBY_3 == 'GME' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'GM' + ROW.OID3} 
					if (SELECT.GROUPBY_3 == 'CM' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'CM' + ROW.OID3} 
					if (SELECT.GROUPBY_3 == 'GN' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'GN' + ROW.OID3} 
					if (SELECT.GROUPBY_3 == 'RGME' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'RG' + ROW.OID3} 
					if (SELECT.GROUPBY_2.substr(0,6) == 'GMECLS' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2} 
					if (SELECT.GROUPBY_2 == 'GME' && ROW.OID2 != '-9999999') {return 'GM' + ROW.OID2} 
					if (SELECT.GROUPBY_2 == 'CM' && ROW.OID2 != '-9999999') {return 'CM' + ROW.OID2} 
					if (SELECT.GROUPBY_2 == 'GN' && ROW.OID2 != '-9999999') {return 'GN' + ROW.OID2} 
					if (SELECT.GROUPBY_2 == 'RGME' && ROW.OID2 != '-9999999') {return 'RG' + ROW.OID2} 
					if (SELECT.GROUPBY.substr(0,6) == 'GMECLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1} 
					if (SELECT.GROUPBY == 'GME') {return 'GM' + ROW.OID1} 
					if (SELECT.GROUPBY == 'CM') {return 'CM' + ROW.OID1} 					
					if (SELECT.GROUPBY == 'GN') {return 'GN' + ROW.OID1} 
					if (SELECT.GROUPBY == 'RGME') {return 'RG' + ROW.OID1} 
				]]>
			</value>
		</ARG>
		<ARG name="HME">
			<value>
				<![CDATA[
					if (SELECT.GROUPBY_3.substr(0,6) == 'HMECLS' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'LS' + SELECT.GROUPBY_3.substr(6,2) + ROW.OID3} 
					if (SELECT.GROUPBY_3 == '5ME' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'G5' + ROW.OID3} 
					if (SELECT.GROUPBY_3 == 'CCM' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'CM' + ROW.OID3} 					
					if (SELECT.GROUPBY_3 == 'HME' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'GM' + ROW.OID3}
					if (SELECT.GROUPBY_2.substr(0,6) == 'GHMCLS' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2} 
					if (SELECT.GROUPBY_2 == '5ME' && ROW.OID2 != '-9999999') {return 'G5' + ROW.OID2} 
					if (SELECT.GROUPBY_2 == 'CCM' && ROW.OID2 != '-9999999') {return 'CM' + ROW.OID2} 					
					if (SELECT.GROUPBY_2 == 'HME' && ROW.OID2 != '-9999999') {return 'GM' + ROW.OID2} 
					if (SELECT.GROUPBY.substr(0,6) == 'HMECLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1}
					if (SELECT.GROUPBY == '5ME') {return 'G5' + ROW.OID1} 
					if (SELECT.GROUPBY == 'CCM') {return 'CM' + ROW.OID1} 
					if (SELECT.GROUPBY == 'HME') {return 'GM' + ROW.OID1} 
				]]>
			</value>
		</ARG>

		<ARG name="ETAT_SEJOUR">
			<value>
				<![CDATA[
					if (SELECT.GROUPBY_3.substr(0,6) == 'EDSCLS' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'LS' + SELECT.GROUPBY_3.substr(6,2) + ROW.OID3} 
					if (SELECT.GROUPBY_3 == 'EDS' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'DT' + ROW.OID3} 
 
					if (SELECT.GROUPBY_2.substr(0,6) == 'EDSCLS' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2} 
					if (SELECT.GROUPBY_2 == 'EDS' && ROW.OID2 != '-9999999') {return  'DT' + ROW.OID2} 

					if (SELECT.GROUPBY.substr(0,6) == 'EDSCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1} 
					if (SELECT.GROUPBY == 'EDS') {return 'DT' + ROW.OID1} 

				]]>
			</value>
		</ARG>
		<ARG name="CHAMP">
			<value>
				<![CDATA[
					if (SELECT.GROUPBY_3 == 'ETAT_PMSI' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return  ROW.OID3}
					if (SELECT.GROUPBY_2 == 'ETAT_PMSI' && ROW.OID2 != '-9999999') {return  ROW.OID2} 
					if (SELECT.GROUPBY == 'ETAT_PMSI') {return  ROW.OID1} 

				]]>
			</value>
		</ARG>
		<ARG name="MCO_H">
			<value>
				<![CDATA[
					if (SELECT.GROUPBY_2 == 'MCO' && ROW.COD2 != '*') {return '0'} 
					if (SELECT.GROUPBY == 'MCO' && ROW.COD != '*') {return '0'} 
				]]>
			</value>
		</ARG>
		
		<ARG name="MCO_M">
			<value>
				<![CDATA[
					if (SELECT.GROUPBY_2 == 'MCO' && ROW.COD2 != 'M') {return '0'} 
					if (SELECT.GROUPBY == 'MCO' && ROW.COD != 'M') {return '0'} 
				]]>
			</value>
		</ARG>
		
		<ARG name="MCO_C">
			<value>
				<![CDATA[
					if (SELECT.GROUPBY_2 == 'MCO' && ROW.COD2 != 'C') {return '0'} 
					if (SELECT.GROUPBY == 'MCO' && ROW.COD != 'C') {return '0'} 
				]]>
			</value>
		</ARG>
		
		<ARG name="MCO_O">
			<value>
				<![CDATA[
					if (SELECT.GROUPBY_2 == 'MCO' && ROW.COD2 != 'O') {return '0'} 
					if (SELECT.GROUPBY == 'MCO' && ROW.COD != 'O') {return '0'} 
				]]>
			</value>
		</ARG>
		
		<ARG name="MCO_S">
			<value>
				<![CDATA[
					if (SELECT.GROUPBY_2 == 'MCO' && ROW.COD2 != 'S') {return '0'} 
					if (SELECT.GROUPBY == 'MCO' && ROW.COD != 'S') {return '0'} 
				]]>
			</value>
		</ARG>	
		
		
		<ARG name="CAS_C">
			<value>
				<![CDATA[
					if (SELECT.GROUPBY_2 == 'CAS' && ROW.COD2 != 'C') {return '0'} 
					if (SELECT.GROUPBY == 'CAS' && ROW.COD != 'C') {return '0'} 
				]]>
			</value>
		</ARG>
		
		<ARG name="CAS_K">
			<value>
				<![CDATA[
					if (SELECT.GROUPBY_2 == 'CAS' && ROW.COD2 != 'K') {return '0'} 
					if (SELECT.GROUPBY == 'CAS' && ROW.COD != 'K') {return '0'} 
				]]>
			</value>
		</ARG>
		
		<ARG name="CAS_X">
			<value>
				<![CDATA[
					if (SELECT.GROUPBY_2 == 'CAS' && ROW.COD2 != 'X') {return '0'} 
					if (SELECT.GROUPBY == 'CAS' && ROW.COD != 'X') {return '0'} 
				]]>
			</value>
		</ARG>
		
		<ARG name="CAS_N">
			<value>
				<![CDATA[
					if (SELECT.GROUPBY_2 == 'CAS' && ROW.COD2 != 'N') {return '0'} 
					if (SELECT.GROUPBY == 'CAS' && ROW.COD != 'N') {return '0'} 
				]]>
			</value>
		</ARG>
		
		<ARG name="CAS_O">
			<value>
				<![CDATA[
					if (SELECT.GROUPBY_2 == 'CAS' && ROW.COD2 != 'O') {return '0'} 
					if (SELECT.GROUPBY == 'CAS' && ROW.COD != 'O') {return '0'} 
				]]>
			</value>
		</ARG>
				
		<ARG name="CAS_S">
			<value>
				<![CDATA[
					if (SELECT.GROUPBY_2 == 'CAS' && ROW.COD2 != 'S') {return '0'} 
					if (SELECT.GROUPBY == 'CAS' && ROW.COD != 'S') {return '0'} 
				]]>
			</value>
		</ARG>	
		
		<ARG name="CAS_W">
			<value>
				<![CDATA[
					if (SELECT.GROUPBY_2 == 'CAS' && ROW.COD2 != 'W') {return '0'} 
					if (SELECT.GROUPBY == 'CAS' && ROW.COD != 'W') {return '0'} 
				]]>
			</value>
		</ARG>
		
		<ARG name="FINESS">
			<value>
				<![CDATA[
					if (SELECT.GROUPBY_2.substr(0,6) == 'FINCLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2} 
					if (SELECT.GROUPBY_2 == 'FIN' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'DT' + ROW.OID2} 
					if (SELECT.GROUPBY.substr(0,6) == 'FINCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1} 
					if (SELECT.GROUPBY == 'FIN') {return 'DT' + ROW.OID1} 
				]]>
			</value>
		</ARG>
		<ARG name="PARAMETRE_PERSONNALISE_SEJOUR_1">
			<value>
				<![CDATA[
					if (SELECT.GROUPBY_2.substr(0,6) == 'PS1CLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2} 
					if (SELECT.GROUPBY_2 == 'PS1' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'DT' + ROW.OID2} 
					if (SELECT.GROUPBY.substr(0,6) == 'PS1CLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1} 
					if (SELECT.GROUPBY == 'PS1') {return 'DT' + ROW.OID1} 
				]]>
			</value>
		</ARG>
		
		<ARG name="PARAMETRE_PERSONNALISE_SEJOUR_2">
			<value>
				<![CDATA[
					if (SELECT.GROUPBY_2.substr(0,6) == 'PS2CLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2} 
					if (SELECT.GROUPBY_2 == 'PS2' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'DT' + ROW.OID2} 
					if (SELECT.GROUPBY.substr(0,6) == 'PS2CLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1} 
					if (SELECT.GROUPBY == 'PS2') {return 'DT' + ROW.OID1} 
				]]>
			</value>
		</ARG>
		
		<ARG name="BUDGET_CLE">
			<value>
				<![CDATA[
					if (SELECT.GROUPBY_2.substr(0,6) == 'BUCCLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'BUC' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'DT' + ROW.OID2;} 
					if (SELECT.GROUPBY.substr(0,6) == 'BUCCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1;} 
					if (SELECT.GROUPBY == 'BUC') {return 'DT' + ROW.OID1;} 
				]]>
			</value>
		</ARG>
	
		<ARG name="MODE_ENTREE">
			<value><![CDATA[
				
				if (SELECT.GROUPBY_2 == 'MODE_ENTREE' && ROW.OID2 != '0') {return 'ME' + ROW.COD2}
				if (SELECT.GROUPBY == 'MODE_ENTREE') {return 'ME' + ROW.COD1}
				if (SELECT.GROUPBY_2 == 'PROVENANCE' && ROW.OID2 != '0') {return 'ME' + ROW.COD2.substr(0,1)}
				if (SELECT.GROUPBY == 'PROVENANCE') {return 'ME' + ROW.COD1.substr(0,1)}
				
			]]></value>
		</ARG>
		
		<ARG name="PROVENANCE">
			<value><![CDATA[
				
				if (SELECT.GROUPBY_2 == 'PROVENANCE' && ROW.OID2 != '0') {return 'PR' + ROW.COD2.substr(1,1)}
				if (SELECT.GROUPBY == 'PROVENANCE') {return 'PR' + ROW.COD1.substr(1,1)}
				
			]]></value>
		</ARG>
	
		<ARG name="ETABLISSEMENT_PROVENANCE">
			<value><![CDATA[
				
				if (SELECT.GROUPBY_2 == 'ETABLISSEMENT_PROVENANCE' && ROW.OID2 != '0') {return  ROW.OID2}
				if (SELECT.GROUPBY == 'ETABLISSEMENT_PROVENANCE') {return ROW.OID1}
				
			]]></value>
		</ARG>
	
		<ARG name="MODE_SORTIE">
			<value><![CDATA[
				
				if (SELECT.GROUPBY_2 == 'MODE_SORTIE' && ROW.OID2 != '0') {return 'MS' + ROW.COD2}
				if (SELECT.GROUPBY == 'MODE_SORTIE') {return 'MS' + ROW.COD1}
				if (SELECT.GROUPBY_2 == 'DESTINATION' && ROW.OID2 != '0') {return 'MS' + ROW.COD2.substr(0,1)}
				if (SELECT.GROUPBY == 'DESTINATION') {return 'MS' + ROW.COD1.substr(0,1)}
				
			]]></value>
		</ARG>
		
		<ARG name="DESTINATION">
			<value><![CDATA[
				
				if (SELECT.GROUPBY_2 == 'DESTINATION' && ROW.OID2 != '0') {return 'DS' + ROW.COD2.substr(1,1)}
				if (SELECT.GROUPBY == 'DESTINATION') {return 'DS' + ROW.COD1.substr(1,1)}
				
			]]></value>
		</ARG>

		<ARG name="ETABLISSEMENT_PROVENANCE">
			<value><![CDATA[
				
				if (SELECT.GROUPBY_3 == 'ETAB_PROV' && ROW.OID3 != '0' &&  ROW.OID3 != '-9999999') {return ROW.COD3}
				if (SELECT.GROUPBY_2 == 'ETAB_PROV' && ROW.OID2 != '0') {return ROW.OID2}
				if (SELECT.GROUPBY == 'ETAB_PROV') {return ROW.OID1}
				
			]]></value>
		</ARG>
        <ARG name="ETABLISSEMENT_DESTINATION">
			<value><![CDATA[
				
				if (SELECT.GROUPBY_3 == 'ETAB_DEST' && ROW.OID3 != '0' &&  ROW.OID3 != '-9999999') {return ROW.COD3}
				if (SELECT.GROUPBY_2 == 'ETAB_DEST' && ROW.OID2 != '0') {return ROW.OID2}
				if (SELECT.GROUPBY == 'ETAB_DEST') {return ROW.OID1}
				
			]]></value>
		</ARG>
	
		<ARG name="SERVICE_SEJOUR">
			<value>
				<![CDATA[
					if (SELECT.GROUPBY_2.substr(0,6) == 'SORCLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2} 
					if (SELECT.GROUPBY_2 == 'SOR' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'SF' + ROW.OID2} 
					if (SELECT.GROUPBY.substr(0,6) == 'SORCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1} 
					if (SELECT.GROUPBY == 'SOR') {return 'SF' + ROW.OID1} 
				]]>
			</value>
		</ARG>		
		<ARG name="UF_SEJOUR">
			<value>
				<![CDATA[
					if (SELECT.GROUPBY_3.substr(0,6) == 'UFSCLS' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'LS' + SELECT.GROUPBY_3.substr(6,2) + ROW.OID3} 
					if (SELECT.GROUPBY_3 == 'UFS' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'UF' + ROW.OID3} 
					if (SELECT.GROUPBY_2.substr(0,6) == 'UFSCLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2} 
					if (SELECT.GROUPBY_2 == 'UFS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'UF' + ROW.OID2} 
					if (SELECT.GROUPBY.substr(0,6) == 'UFSCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1} 
					if (SELECT.GROUPBY == 'UFS') {return 'UF' + ROW.OID1}
				]]>
			</value>
		</ARG>		
		<ARG name="ETAGE_SEJOUR">
			<value>
				<![CDATA[
					if (SELECT.GROUPBY_2.substr(0,6) == 'ESOCLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2} 
					if (SELECT.GROUPBY_2 == 'ESO' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'ET' + ROW.OID2} 
					if (SELECT.GROUPBY.substr(0,6) == 'ESOCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1} 
					if (SELECT.GROUPBY == 'ESO') {return 'ET' + ROW.OID1}
				]]>
			</value>
		</ARG>	
        <ARG name="GIR_SEJOUR">
			<value>
				<![CDATA[
					if (SELECT.GROUPBY_2.substr(0,6) == 'GRSCLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2} 
					if (SELECT.GROUPBY_2 == 'GRS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'ET' + ROW.OID2} 
					if (SELECT.GROUPBY.substr(0,6) == 'GRSCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1} 
					if (SELECT.GROUPBY == 'GRS') {return 'DT' + ROW.OID1} 
				]]>
			</value>
		</ARG>			
		<ARG name="EXPERT_CONTROLE">
			<value><![CDATA[
				
				if (SELECT.GROUPBY_2.substr(0,6) == 'EXCCLS' && ROW.OID2 != '0') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2} 
				if (SELECT.GROUPBY_2 == 'EXC' && ROW.OID2 != '0') {return 'DT' + ROW.OID2} 
				if (SELECT.GROUPBY.substr(0,6) == 'EXCCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1} 
				if (SELECT.GROUPBY == 'EXC') {return 'DT' + ROW.OID1} 
				
			]]></value>
		</ARG>
		<ARG name="RISQUE">
			<value>
				<![CDATA[
					if (SELECT.GROUPBY_2 == 'RIS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'DT' + ROW.OID2}  
                    if (SELECT.GROUPBY == 'RIS') {return 'DT' + ROW.OID1} 
				]]>
			</value>
		</ARG>
        <ARG name="CTISEV">
			<value><![CDATA[
				
				if (SELECT.GROUPBY_3 == 'SEVCTI' && ROW.COD3 != '' && ROW.OID3 != '-9999999') {return  ROW.COD3}
				if (SELECT.GROUPBY_2 == 'SEVCTI' && ROW.COD2 != '' && ROW.OID2 != '-9999999') {return  ROW.COD2}
				if (SELECT.GROUPBY == 'SEVCTI' && ROW.OID1 != '-9999999') {return  ROW.COD1}
				
			]]></value>
		</ARG>
	</COMPONENT>
	
	<COMPONENT name="PERIODICITE_VIEWLINK"  >
		
		<ARG name="PERIODICITE">
			<value><![CDATA[
				var annee_periode:String = parseInt(SELECT.PERIODE.substr(0,4));
				var mois_periode:String = parseInt(SELECT.PERIODE.substr(5,2));
				var jour_periode:String = parseInt(SELECT.PERIODE.substr(8,2));
				var annee_toperiode:String = parseInt(SELECT.TOPERIODE.substr(0,4));
				var mois_toperiode:String = parseInt(SELECT.TOPERIODE.substr(5,2));
				var jour_toperiode:String = parseInt(SELECT.TOPERIODE.substr(8,2));
				
				if (annee_periode > annee_toperiode) {return 'MONTH';}
				else if (annee_toperiode > annee_periode) {return 'QUARTER';}
				else if (mois_toperiode > mois_periode || mois_periode > mois_toperiode) {return 'MONTH';}
				else if (jour_toperiode - jour_periode > 7) {return 'WEEK2';}
				else {return 'DAY';}
			]]></value>
		</ARG>
		
	</COMPONENT>
	
	<COMPONENT name="OCC_BASE_VIEWLINK"  >
		
		<ARG name="PERIODE">
			<value><![CDATA[
			
				
				
				var annee_periode:String = SELECT.PERIODE.substr(0,4);
				var mois_periode:String = SELECT.PERIODE.substr(5,2);
				var annee_toperiode:String = SELECT.TOPERIODE.substr(0,4);
				var mois_toperiode:String = SELECT.TOPERIODE.substr(5,2);
				
				var mois_debut:int = 0;
				var mois_debut_string:String = '';
				var annee:String = '';

				function getDateFromWeek(code:String,day:int) {
					var annee:String =  code.substr(0,4);
					var date:Date = new Date(int(annee),0,1);
					date.setTime(date.getTime() + 1000*60*60*24*(7*(int(code.substr(4,6))-1)-(date.getDay()+7)%6+day));
					var year = date.getFullYear();
					var month = date.getMonth()+1;
					var day = date.getDate();
					if(month < 10){
						month = 0 + month;
					}
					if(day < 10){
						day = 0 + day;
					}
					return year + '-' + month + '-' + day;
				}
				
				if(ROW.OID === '-9999999'){
					return SELECT.PERIODE;
				}

				if (SELECT.GROUPBY == 'SEMAINEANNE' || SELECT.GROUPBY_2 == 'SEMAINEANNE' || SELECT.GROUPBY_3 == 'SEMAINEANNE' ) {
					if(SELECT.GROUPBY == 'SEMAINEANNE' || SELECT.GROUPBY_2 == 'SEMAINEANNE'){
							row_cod = (SELECT.GROUPBY == 'SEMAINEANNE') ? ROW.COD1 : ROW.COD2;
					} 
					else {
							row_cod = ROW.COD3;
					}
					if (SELECT.GROUPBY == 'ANNEE' || SELECT.GROUPBY_2 == 'ANNEE' ) {
						var annee:String =  (SELECT.GROUPBY == 'SEMAINEANNE') ?  ROW.COD2.substr(0,4) : ROW.COD1.substr(0,4);
						return getDateFromWeek(annee+row_cod,0);
					}
					else{
						var date:String = getDateFromWeek(annee_toperiode + row_cod,6);
						var month:int = parseInt(date.substr(5,2));
						var day:int = parseInt(date.substr(8,2));
						var toDay:int = parseInt(SELECT.TOPERIODE.substr(8,2));	

						if (month <= parseInt(mois_toperiode) && day <= toDay) {
							return getDateFromWeek(annee_toperiode+row_cod,0);
						}
						else {
								return getDateFromWeek((parseInt(annee_toperiode)).toString()+row_cod,0);
						}
					}
				}
				
				if (SELECT.GROUPBY == 'JOUR' || SELECT.GROUPBY_2 == 'JOUR') {
					
					if (SELECT.GROUPBY == 'JOUR') {
						return ROW.COD1;
					}
					else if (ROW.COD == ROW.COD2) {
						return ROW.COD2;
					}
				}
				if (SELECT.GROUPBY == 'JOURS' || SELECT.GROUPBY_2 == 'JOURS' || SELECT.GROUPBY_3 == 'JOURS' ) {
					
					if (SELECT.GROUPBY == 'JOURS') {
						
						return annee_periode+'-'+ROW.COD1;
					}
					else if (ROW.COD == ROW.COD2) {
						return annee_periode+'-'+ROW.COD2;
					} else if(ROW.COD == ROW.COD3) {
						return annee_periode+'-'+ROW.COD3;
					}
				}
				if (SELECT.GROUPBY == 'MOIS' || SELECT.GROUPBY_2 == 'MOIS') {
					
					var mois:String = '';
					
					if (SELECT.GROUPBY == 'MOIS') {
						
						annee = ROW.COD1.substr(0,4);
						mois = ROW.COD1.substr(-2);
						
						if (annee == annee_periode && mois == mois_periode) {
							return SELECT.PERIODE;
						}
						else {
							return annee + mois;
						}
					}
					else {
						
						annee = ROW.COD2.substr(0,4);
						mois = ROW.COD2.substr(-2);
						
						if (ROW.COD == ROW.COD2) {
							
							if (annee == annee_periode && mois == mois_periode) {
								return SELECT.PERIODE;
							}
							else {
								return annee + mois;
							}
						}
						else {
							
							if (SELECT.GROUPBY == 'ANNEE' && ROW.COD1 != annee_periode) {
								return ROW.COD1 + '01';
							}
							else {
								return SELECT.PERIODE;
							}
						}
					}
				}
				else if (SELECT.GROUPBY == 'NUMEROMOIS' || SELECT.GROUPBY_2 == 'NUMEROMOIS') {
					
					if (SELECT.GROUPBY == 'NUMEROMOIS') {
						
						if (parseInt(ROW.COD1) <= parseInt(mois_toperiode)) {
							return annee_toperiode + ROW.COD1;
						}
						else {
							return (parseInt(annee_toperiode) - 1).toString() + ROW.COD1;
						}
					}
					else {
						
						mois_debut = 1 + 3 * (parseInt(ROW.COD1.substr(-1)) - 1);
						mois_debut_string = mois_debut < 10 ? '0' + mois_debut.toString() : mois_debut.toString();
						annee = ROW.COD1.substr(0,4);
						
						if (SELECT.GROUPBY == 'ANNEE') {
							
							if (ROW.COD == ROW.COD2) {
								return ROW.COD1 + ROW.COD2;
							}
							else {
								
								if (ROW.COD1 == annee_periode) {
									return SELECT.PERIODE;
								}
								else {
									return ROW.COD1 + '01';
								}
							}
						}
						else if (SELECT.GROUPBY == 'TRIM') {
						
							if (ROW.COD == ROW.COD2) {
								return annee + ROW.COD2;
							}
							else {
								if (annee == annee_periode && mois_debut <= parseInt(mois_periode)) {
									return SELECT.PERIODE;
								}
								else {
									return annee + mois_debut_string;
								}
							}
						}
						else if (SELECT.GROUPBY == 'NUMEROTRIM') {
							
							if (ROW.COD ==  ROW.COD2) {
								
								if (parseInt(ROW.COD2) <= parseInt(mois_toperiode)) {
									return annee_toperiode + ROW.COD2
								}
								else {
									return (parseInt(annee_toperiode) - 1).toString() + ROW.COD2;
								}
							}
							else {
								
								if (mois_debut <= parseInt(mois_toperiode)) {
									return annee_toperiode + mois_debut_string;
								}
								else {
									return (parseInt(annee_toperiode) - 1).toString() + mois_debut_string;
								}
							}
						}
						else {
							
							if (ROW.COD == ROW.COD2) {
								
								if (parseInt(ROW.COD2) <= parseInt(mois_toperiode)) {
									return annee_toperiode + ROW.COD2;
								}
								else {
									return (parseInt(annee_toperiode) - 1).toString() + ROW.COD2;
								}
							}
							else {
								return SELECT.PERIODE;
							}
						}
					}
				}
				else if (SELECT.GROUPBY == 'TRIM' || SELECT.GROUPBY_2 == 'TRIM') {
					
					if (SELECT.GROUPBY == 'TRIM') {
					
						annee = ROW.COD1.substr(0,4);
						mois_debut = 1 + 3 * (parseInt(ROW.COD1.substr(-1)) - 1);
						mois_debut_string = mois_debut < 10 ? '0' + mois_debut.toString() : mois_debut.toString();
						
						if (annee == annee_periode && mois_debut <= parseInt(mois_periode)) {
							return SELECT.PERIODE;
						}
						else {
							return annee + mois_debut_string;
						}
					}
					else {
					
						annee = ROW.COD2.substr(0,4);
						mois_debut = 1 + 3 * (parseInt(ROW.COD2.substr(-1)) - 1);
						mois_debut_string = mois_debut < 10 ? '0' + mois_debut.toString() : mois_debut.toString();
						
						if (ROW.COD == ROW.COD2) {
							
							if (annee == annee_periode && mois_debut <= parseInt(mois_periode)) {
								return SELECT.PERIODE;
							}
							else {
								return annee + mois_debut_string;
							}
						}
						else {
							
							if (SELECT.GROUPBY == 'ANNEE' && ROW.COD1 != annee_periode) {
								return ROW.COD1 + '01';
							}
							else {
								return SELECT.PERIODE;
							}
						}
					}
				}
				else if (SELECT.GROUPBY == 'NUMEROTRIM' || SELECT.GROUPBY_2 == 'NUMEROTRIM') {
					
					mois_debut = 1 + 3 * (parseInt(ROW.COD2.substr(-1)) - 1);
					mois_debut_string = mois_debut < 10 ? '0' + mois_debut.toString() : mois_debut.toString();
					
					if (SELECT.GROUPBY == 'NUMEROTRIM') {
					
						mois_debut = 1 + 3 * (parseInt(ROW.COD1.substr(-1)) - 1);
						mois_debut_string = mois_debut < 10 ? '0' + mois_debut.toString() : mois_debut.toString();
						
						if (mois_debut <= parseInt(mois_toperiode)) {
							return annee_toperiode + mois_debut_string;
						}
						else {
							return (parseInt(annee_toperiode) -1).toString() + mois_debut_string;
						}
					}
					else if (SELECT.GROUPBY == 'ANNEE') {

						if (ROW.COD == ROW.COD2) {
							
							if (ROW.COD1 == annee_periode && mois_debut <= parseInt(mois_periode)) {
								return SELECT.PERIODE;
							}
							else {
								return ROW.COD1 + mois_debut_string;
							}
						}
						else {
							
							if (ROW.COD1 == annee_periode) {
								return SELECT.PERIODE;
							}
							else {
								return ROW.COD1 + '01';
							}
						}
					}
					else {
						
						if (ROW.COD == ROW.COD2) {
							
							if (mois_debut <= parseInt(mois_toperiode)) {
								return annee_toperiode + mois_debut_string;
							}
							else {
								return (parseInt(annee_toperiode) - 1).toString() + mois_debut_string;
							}
						}
						else {
							return SELECT.PERIODE;
						}
					}
				}
				else if (SELECT.GROUPBY == 'ANNEE'|| SELECT.GROUPBY_2 == 'ANNEE') {
				
					var row_cod:String = (SELECT.GROUPBY == 'ANNEE') ? ROW.COD1 : ROW.COD2;
					
					if (row_cod == annee_periode) {
						return SELECT.PERIODE;
					}
					else {
						return row_cod + '01';
					}
				}
				else {
                   var periode_comparatif:String = SELECT.PERIODE;
                    
                    if (COLUMN.NAME == 'D1_OLD') {periode_comparatif =  VIEW.PERIODE_D;}
                    if (COLUMN.NAME == 'D1_NOW') {periode_comparatif = SELECT.PERIODE;}
                    if (COLUMN.NAME == 'D2_OLD') {periode_comparatif = VIEW.PERIODE_D;}
                    if (COLUMN.NAME == 'D2_NOW') {periode_comparatif = SELECT.PERIODE;}
                    if (COLUMN.NAME == 'CA_MOY_OLD') {periode_comparatif = VIEW.PERIODE_D;}
                    if (COLUMN.NAME == 'CA_MOY_NOW') {periode_comparatif = SELECT.PERIODE;}
                    if (COLUMN.NAME == 'F1') {periode_comparatif = SELECT.PERIODE}
                    if (COLUMN.NAME == 'F2') {periode_comparatif = SELECT.PERIODE}
                    if (COLUMN.NAME == 'F3') {periode_comparatif = SELECT.PERIODE}
                    if (COLUMN.NAME == 'F4') {periode_comparatif = SELECT.PERIODE}
                    if (COLUMN.NAME == 'F5') {periode_comparatif = SELECT.PERIODE}
                    if (COLUMN.NAME == 'F6') {periode_comparatif = SELECT.PERIODE}
                    if (COLUMN.NAME == 'F7') {periode_comparatif = SELECT.PERIODE}
                    if (COLUMN.NAME == 'F8') {periode_comparatif = SELECT.PERIODE}
                    if (COLUMN.NAME == 'F9') {periode_comparatif = SELECT.PERIODE}
                    if (COLUMN.NAME == 'F10') {periode_comparatif = SELECT.PERIODE}
                    if (COLUMN.NAME == 'F11') {periode_comparatif = SELECT.PERIODE}
                    if (COLUMN.NAME == 'F12') {periode_comparatif = SELECT.PERIODE}
                    if (COLUMN.NAME == 'F13') {periode_comparatif = SELECT.PERIODE}
                    if (COLUMN.NAME == 'F14') {periode_comparatif = SELECT.PERIODE}
                    if (COLUMN.NAME == 'F15') {periode_comparatif = SELECT.PERIODE}
                    if (COLUMN.NAME == 'D1') {periode_comparatif = VIEW.PERIODE_D}
                    if (COLUMN.NAME == 'D2') {periode_comparatif = VIEW.PERIODE_D}
                    if (COLUMN.NAME == 'D3') {periode_comparatif = VIEW.PERIODE_D}
                    if (COLUMN.NAME == 'D4') {periode_comparatif = VIEW.PERIODE_D}
                    if (COLUMN.NAME == 'D5') {periode_comparatif = VIEW.PERIODE_D}
                    if (COLUMN.NAME == 'D6') {periode_comparatif = VIEW.PERIODE_D}
                    if (COLUMN.NAME == 'D7') {periode_comparatif = VIEW.PERIODE_D}
                    if (COLUMN.NAME == 'D8') {periode_comparatif = VIEW.PERIODE_D}
                    if (COLUMN.NAME == 'D9') {periode_comparatif = VIEW.PERIODE_D}
                    if (COLUMN.NAME == 'D10') {periode_comparatif = VIEW.PERIODE_D}
                    if (COLUMN.NAME == 'D11') {periode_comparatif = VIEW.PERIODE_D}
                    if (COLUMN.NAME == 'D12') {periode_comparatif = VIEW.PERIODE_D}
                    if (COLUMN.NAME == 'D13') {periode_comparatif = VIEW.PERIODE_D}
                    if (COLUMN.NAME == 'D14') {periode_comparatif = VIEW.PERIODE_D}
                    if (COLUMN.NAME == 'D15') {periode_comparatif = VIEW.PERIODE_D}
                    if (COLUMN.NAME == 'L1') {periode_comparatif = VIEW.PERIODE_D2}
                    if (COLUMN.NAME == 'L2') {periode_comparatif = VIEW.PERIODE_D2}
                    if (COLUMN.NAME == 'L3') {periode_comparatif = VIEW.PERIODE_D2}
                    if (COLUMN.NAME == 'L4') {periode_comparatif = VIEW.PERIODE_D2}
                    if (COLUMN.NAME == 'L5') {periode_comparatif = VIEW.PERIODE_D2}
                    if (COLUMN.NAME == 'L6') {periode_comparatif = VIEW.PERIODE_D2}
                    if (COLUMN.NAME == 'L7') {periode_comparatif = VIEW.PERIODE_D2}
                    if (COLUMN.NAME == 'L8') {periode_comparatif = VIEW.PERIODE_D2}
                    if (COLUMN.NAME == 'L9') {periode_comparatif = VIEW.PERIODE_D2}
                    if (COLUMN.NAME == 'L10') {periode_comparatif = VIEW.PERIODE_D2}
                    if (COLUMN.NAME == 'L11') {periode_comparatif = VIEW.PERIODE_D2}
                    if (COLUMN.NAME == 'L12') {periode_comparatif = VIEW.PERIODE_D2}
                    if (COLUMN.NAME == 'L13') {periode_comparatif = VIEW.PERIODE_D2}
                    if (COLUMN.NAME == 'L14') {periode_comparatif = VIEW.PERIODE_D2}
                    if (COLUMN.NAME == 'L15') {periode_comparatif = VIEW.PERIODE_D2}
					return periode_comparatif;
				}
				
				
				
				
			]]></value>
		</ARG>
		
		<ARG name="TOPERIODE">
			<value><![CDATA[

				var annee_periode:String = SELECT.PERIODE.substr(0,4);
				var mois_periode:String = SELECT.PERIODE.substr(5,2);
				var annee_toperiode:String = SELECT.TOPERIODE.substr(0,4);
				var mois_toperiode:String = SELECT.TOPERIODE.substr(5,2);
				
				var mois_debut:int = 0;
				var mois_fin:int = 0;
				var mois_fin_string:String = '';
				var annee:String = '';
            
				function getDateFromWeek(code:String,day:int) {
					var annee:String =  code.substr(0,4);
					var date:Date = new Date(int(annee),0,1);
					date.setTime(date.getTime() + 1000*60*60*24*(7*(int(code.substr(4,6))-1)-(date.getDay()+7)%6+day));
					var year = date.getFullYear();
					var month = date.getMonth()+1;
					var day = date.getDate();
					if(month < 10){
						month = 0 + month;
					}
					if(day < 10){
						day = 0 + day;
					}
					return year + '-' + month + '-' + day;
				}

				if(ROW.OID === '-9999999'){
					return SELECT.TOPERIODE;
				}

				if (SELECT.GROUPBY == 'SEMAINEANNE' || SELECT.GROUPBY_2 == 'SEMAINEANNE' || SELECT.GROUPBY_3 == 'SEMAINEANNE' ) {
						if(SELECT.GROUPBY == 'SEMAINEANNE' || SELECT.GROUPBY_2 == 'SEMAINEANNE'){
							row_cod = (SELECT.GROUPBY == 'SEMAINEANNE') ? ROW.COD1 : ROW.COD2;
						}else {
							row_cod = ROW.COD3;
						}
					if (SELECT.GROUPBY == 'ANNEE' || SELECT.GROUPBY_2 == 'ANNEE') {
						var ANNEE:String =  (SELECT.GROUPBY == 'SEMAINEANNE') ?  ROW.COD2.substr(0,4) : ROW.COD1.substr(0,4);
						return getDateFromWeek(ANNEE+row_cod,6);
					}
					else{
						var date:String = getDateFromWeek(annee_toperiode + row_cod,6);
						var month:int = parseInt(date.substr(5,2));
						var day:int = parseInt(date.substr(8,2));
						var toDay:int = parseInt(SELECT.TOPERIODE.substr(8,2));					
						if (month <= parseInt(mois_toperiode) && day <= toDay) {
							return getDateFromWeek(annee_toperiode+row_cod,6);
						}
						else {
								return getDateFromWeek((parseInt(annee_toperiode)).toString()+row_cod,0);
						}
					}
				}
				
				if (SELECT.GROUPBY == 'JOUR' || SELECT.GROUPBY_2 == 'JOUR') {
					
					if (SELECT.GROUPBY == 'JOUR') {
						return ROW.COD1;
					}
					else if (ROW.COD == ROW.COD2) {
						return ROW.COD2;
					}
				}
				if (SELECT.GROUPBY == 'JOURS' || SELECT.GROUPBY_2 == 'JOURS' || SELECT.GROUPBY_3 == 'JOURS' ) {
					
					if (SELECT.GROUPBY == 'JOURS') {
						
						return annee_periode+'-'+ROW.COD1;
					}
					else if (ROW.COD == ROW.COD2) {
						return annee_periode+'-'+ROW.COD2;
					} else if(ROW.COD == ROW.COD3) {
						return annee_periode+'-'+ROW.COD3;
					}
				}
				if (SELECT.GROUPBY == 'MOIS' || SELECT.GROUPBY_2 == 'MOIS') {
					
					var mois:String = '';
					
					if (SELECT.GROUPBY == 'MOIS') {
						
						annee = ROW.COD1.substr(0,4);
						mois = ROW.COD1.substr(-2);
						
						if (annee == annee_toperiode && mois == mois_toperiode) {
							return SELECT.TOPERIODE;
						}
						else {
							return annee + mois;
						}
					}
					else {
						
						annee = ROW.COD2.substr(0,4);
						mois = ROW.COD2.substr(-2);
						
						if (ROW.COD == ROW.COD2) {
							
							if (annee == annee_toperiode && mois == mois_toperiode) {
								return SELECT.TOPERIODE;
							}
							else {
								return annee + mois;
							}
						}
						else {
							
							if (SELECT.GROUPBY == 'ANNEE' && ROW.COD1 != annee_toperiode) {
								return ROW.COD1 + '12';
							}
							else {
								return SELECT.TOPERIODE;
							}
						}
					}
				}
				else if (SELECT.GROUPBY == 'NUMEROMOIS' || SELECT.GROUPBY_2 == 'NUMEROMOIS') {
					
					if (SELECT.GROUPBY == 'NUMEROMOIS') {
						
						if (parseInt(ROW.COD1) <= parseInt(mois_toperiode)) {
							return annee_toperiode + ROW.COD1;
						}
						else {
							return (parseInt(annee_toperiode) - 1).toString() + ROW.COD1;
						}
					}
					else {
					
						mois_debut = 1 + 3 * (parseInt(ROW.COD1.substr(-1)) - 1);
						mois_fin = 3 * parseInt(ROW.COD1.substr(-1));
						mois_fin_string = mois_fin < 10 ? '0' + mois_fin.toString() : mois_fin.toString();
						annee = ROW.COD1.substr(0,4);
						
						if (SELECT.GROUPBY == 'ANNEE') {
							
							if (ROW.COD == ROW.COD2) {
								return ROW.COD1 + ROW.COD2;
							}
							else {
								
								if (ROW.COD1 == annee_toperiode) {
									return SELECT.TOPERIODE;
								}
								else {
									return ROW.COD1 + '12';
								}
							}
						}
						else if (SELECT.GROUPBY == 'TRIM') {
						
							if (ROW.COD == ROW.COD2) {
								return annee + ROW.COD2;
							}
							else {
								
								if (annee == annee_toperiode && mois_fin >= parseInt(mois_toperiode)) {
									return SELECT.TOPERIODE;
								}
								else {
									return annee + mois_fin_string;
								}
							}
						}
						else if (SELECT.GROUPBY == 'NUMEROTRIM') {
							
							if (ROW.COD ==  ROW.COD2) {
								
								if (parseInt(ROW.COD2) <= parseInt(mois_toperiode)) {
									return annee_toperiode + ROW.COD2
								}
								else {
									return (parseInt(annee_toperiode) - 1).toString() + ROW.COD2;
								}
							}
							else {
								
								if (mois_fin <= parseInt(mois_toperiode)) {
									return annee_toperiode + mois_fin_string;
								}
								else {
									
									if (mois_debut <= parseInt(mois_toperiode)) {
										return SELECT.TOPERIODE;
									}
									else {
										return (parseInt(annee_toperiode) - 1).toString() + mois_fin_string;
									}
								}
							}
						}
						else {
							
							if (ROW.COD == ROW.COD2) {
								
								if (parseInt(ROW.COD2) <= parseInt(mois_toperiode)) {
									return annee_toperiode + ROW.COD2;
								}
								else {
									return (parseInt(annee_toperiode) - 1).toString() + ROW.COD2;
								}
							}
							else {
								return SELECT.TOPERIODE;
							}
						}
					}
				}
				else if (SELECT.GROUPBY == 'TRIM' || SELECT.GROUPBY_2 == 'TRIM') {
					
					if (SELECT.GROUPBY == 'TRIM') {
					
						annee = ROW.COD1.substr(0,4);
						mois_fin = 3 * parseInt(ROW.COD1.substr(-1));
						mois_fin_string = mois_fin < 10 ? '0' + mois_fin.toString() : mois_fin.toString();
						
						if (annee == annee_periode && mois_fin >= parseInt(mois_toperiode)) {
							return SELECT.TOPERIODE;
						}
						else {
							return annee + mois_fin_string;
						}
					}
					else {
					
						annee = ROW.COD2.substr(0,4);
						mois_fin = 3 * parseInt(ROW.COD2.substr(-1));
						mois_fin_string = mois_fin < 10 ? '0' + mois_fin.toString() : mois_fin.toString();
						
						if (ROW.COD == ROW.COD2) {
							
							if (annee == annee_toperiode && mois_fin >= parseInt(mois_toperiode)) {
								return SELECT.TOPERIODE;
							}
							else {
								return annee + mois_fin_string;
							}
						}
						else {
							
							if (SELECT.GROUPBY == 'ANNEE' && ROW.COD1 != annee_toperiode) {
								return ROW.COD1 + '12';
							}
							else {
								return SELECT.TOPERIODE;
							}
						}
					}
				}
				else if (SELECT.GROUPBY == 'NUMEROTRIM' || SELECT.GROUPBY_2 == 'NUMEROTRIM') {
					
					mois_debut = 1 + 3 * (parseInt(ROW.COD2.substr(-1)) - 1);
					mois_fin = 3 * parseInt(ROW.COD2.substr(-1));
					mois_fin_string = mois_fin < 10 ? '0' + mois_fin.toString() : mois_fin.toString();
					
					if (SELECT.GROUPBY == 'NUMEROTRIM') {
					
						mois_debut = 1 + 3 * (parseInt(ROW.COD1.substr(-1)) - 1);
						mois_fin = 3 * parseInt(ROW.COD1.substr(-1));
						mois_fin_string = mois_fin < 10 ? '0' + mois_fin.toString() : mois_fin.toString();
						
						if (mois_fin <= parseInt(mois_toperiode)) {
							return annee_toperiode + mois_fin_string;
						}
						else {
							
							if (mois_debut <= parseInt(mois_toperiode)) {
								return SELECT.TOPERIODE;
							}
							else {
								return (parseInt(annee_toperiode) -1).toString() + mois_fin_string;
							}
						}
					}
					else if (SELECT.GROUPBY == 'ANNEE') {

						if (ROW.COD == ROW.COD2) {
							
							if (ROW.COD1 == annee_toperiode && mois_fin >= parseInt(mois_toperiode)) {
								return SELECT.TOPERIODE;
							}
							else {
								return ROW.COD1 + mois_fin_string;
							}
						}
						else {
							
							if (ROW.COD1 == annee_toperiode) {
								return SELECT.TOPERIODE;
							}
							else {
								return ROW.COD1 + '12';
							}
						}
					}
					else {
						
						if (ROW.COD == ROW.COD2) {
							
							if (mois_fin <= parseInt(mois_toperiode)) {
								return annee_toperiode + mois_fin_string;
							}
							else {
								
								if (mois_debut <= mois_toperiode) {
									return SELECT.TOPERIODE;
								}
								else {
									return (parseInt(annee_toperiode) -1).toString() + mois_fin_string;
								}
							}
						}
						else {
							return SELECT.TOPERIODE;
						}
					}
				}
				else if (SELECT.GROUPBY == 'ANNEE'|| SELECT.GROUPBY_2 == 'ANNEE') {
				
					var row_cod:String = (SELECT.GROUPBY == 'ANNEE') ? ROW.COD1 : ROW.COD2;
					
					if (row_cod == annee_toperiode) {
						return SELECT.TOPERIODE;
					}
					else {
						return row_cod + '12';
					}
				}
				else {
                            var to_periode_comparatif:String = SELECT.TOPERIODE;
							if (COLUMN.NAME == 'D1_OLD') {to_periode_comparatif = VIEW.TOPERIODE_D;}
                            if (COLUMN.NAME == 'D1_NOW') {to_periode_comparatif =  SELECT.TOPERIODE;}
                            if (COLUMN.NAME == 'D2_OLD') {to_periode_comparatif =  VIEW.TOPERIODE_D;}
                            if (COLUMN.NAME == 'D2_NOW') {to_periode_comparatif =  SELECT.TOPERIODE;}
                            if (COLUMN.NAME == 'CA_MOY_OLD') {to_periode_comparatif =  VIEW.TOPERIODE_D;}
                            if (COLUMN.NAME == 'CA_MOY_NOW') {to_periode_comparatif =  SELECT.TOPERIODE;}
                            if (COLUMN.NAME == 'F1') {to_periode_comparatif =  SELECT.TOPERIODE}
                            if (COLUMN.NAME == 'F2') {to_periode_comparatif =  SELECT.TOPERIODE}
                            if (COLUMN.NAME == 'F3') {to_periode_comparatif =  SELECT.TOPERIODE}
                            if (COLUMN.NAME == 'F4') {to_periode_comparatif =  SELECT.TOPERIODE}
                            if (COLUMN.NAME == 'F5') {to_periode_comparatif =  SELECT.TOPERIODE}
                            if (COLUMN.NAME == 'F6') {to_periode_comparatif =  SELECT.TOPERIODE}
                            if (COLUMN.NAME == 'F7') {to_periode_comparatif =  SELECT.TOPERIODE}
                            if (COLUMN.NAME == 'F8') {to_periode_comparatif =  SELECT.TOPERIODE}
                            if (COLUMN.NAME == 'F9') {to_periode_comparatif =  SELECT.TOPERIODE}
                            if (COLUMN.NAME == 'F10') {to_periode_comparatif =  SELECT.TOPERIODE}
                            if (COLUMN.NAME == 'F11') {to_periode_comparatif =  SELECT.TOPERIODE}
                            if (COLUMN.NAME == 'F12') {to_periode_comparatif =  SELECT.TOPERIODE}
                            if (COLUMN.NAME == 'F13') {to_periode_comparatif =  SELECT.TOPERIODE}
                            if (COLUMN.NAME == 'F14') {to_periode_comparatif =  SELECT.TOPERIODE}
                            if (COLUMN.NAME == 'F15') {to_periode_comparatif =  SELECT.TOPERIODE}
                            if (COLUMN.NAME == 'D1') {to_periode_comparatif =  VIEW.TOPERIODE_D}
                            if (COLUMN.NAME == 'D2') {to_periode_comparatif =  VIEW.TOPERIODE_D}
                            if (COLUMN.NAME == 'D3') {to_periode_comparatif =  VIEW.TOPERIODE_D}
                            if (COLUMN.NAME == 'D4') {to_periode_comparatif =  VIEW.TOPERIODE_D}
                            if (COLUMN.NAME == 'D5') {to_periode_comparatif =  VIEW.TOPERIODE_D}
                            if (COLUMN.NAME == 'D6') {to_periode_comparatif =  VIEW.TOPERIODE_D}
                            if (COLUMN.NAME == 'D7') {to_periode_comparatif =  VIEW.TOPERIODE_D}
                            if (COLUMN.NAME == 'D8') {to_periode_comparatif =  VIEW.TOPERIODE_D}
                            if (COLUMN.NAME == 'D9') {to_periode_comparatif =  VIEW.TOPERIODE_D}
                            if (COLUMN.NAME == 'D10') {to_periode_comparatif =  VIEW.TOPERIODE_D}
                            if (COLUMN.NAME == 'D11') {to_periode_comparatif =  VIEW.TOPERIODE_D}
                            if (COLUMN.NAME == 'D12') {to_periode_comparatif =  VIEW.TOPERIODE_D}
                            if (COLUMN.NAME == 'D13') {to_periode_comparatif =  VIEW.TOPERIODE_D}
                            if (COLUMN.NAME == 'D14') {to_periode_comparatif =  VIEW.TOPERIODE_D}
                            if (COLUMN.NAME == 'D15') {to_periode_comparatif =  VIEW.TOPERIODE_D}
                            if (COLUMN.NAME == 'L1') {to_periode_comparatif =  VIEW.TOPERIODE_D2}
                            if (COLUMN.NAME == 'L2') {to_periode_comparatif =  VIEW.TOPERIODE_D2}
                            if (COLUMN.NAME == 'L3') {to_periode_comparatif =  VIEW.TOPERIODE_D2}
                            if (COLUMN.NAME == 'L4') {to_periode_comparatif =  VIEW.TOPERIODE_D2}
                            if (COLUMN.NAME == 'L5') {to_periode_comparatif =  VIEW.TOPERIODE_D2}
                            if (COLUMN.NAME == 'L6') {to_periode_comparatif =  VIEW.TOPERIODE_D2}
                            if (COLUMN.NAME == 'L7') {to_periode_comparatif =  VIEW.TOPERIODE_D2}
                            if (COLUMN.NAME == 'L8') {to_periode_comparatif =  VIEW.TOPERIODE_D2}
                            if (COLUMN.NAME == 'L9') {to_periode_comparatif =  VIEW.TOPERIODE_D2}
                            if (COLUMN.NAME == 'L10') {to_periode_comparatif =  VIEW.TOPERIODE_D2}
                            if (COLUMN.NAME == 'L11') {to_periode_comparatif =  VIEW.TOPERIODE_D2}
                            if (COLUMN.NAME == 'L12') {to_periode_comparatif =  VIEW.TOPERIODE_D2}
                            if (COLUMN.NAME == 'L13') {to_periode_comparatif =  VIEW.TOPERIODE_D2}
                            if (COLUMN.NAME == 'L14') {to_periode_comparatif =  VIEW.TOPERIODE_D2}
                            if (COLUMN.NAME == 'L15') {to_periode_comparatif =  VIEW.TOPERIODE_D2}
                            return to_periode_comparatif;
				}
				
			]]></value>
		</ARG>
        
        <ARG name="POLE_MOUVEMENT">
			<value>
				<![CDATA[
					if (SELECT.GROUPBY_2.substr(0,6) == 'POLCLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2} 
					if (SELECT.GROUPBY_2 == 'POL' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'DT' + ROW.OID2} 
					if (SELECT.GROUPBY.substr(0,6) == 'POLCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1} 
					if (SELECT.GROUPBY == 'POL'&& ROW.OID1 !== '-9999999') {return 'DT' + ROW.OID1} 
					;
				]]>
			</value>
		</ARG>
		
		
		<ARG name="SERVICE_MOUVEMENT">
			<value>
				<![CDATA[
					if (SELECT.GROUPBY_2.substr(0,6) == 'SERCLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2} 
					if (SELECT.GROUPBY_2 == 'SER' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'SF' + ROW.OID2} 
					if (SELECT.GROUPBY.substr(0,6) == 'SERCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1} 
					if (SELECT.GROUPBY == 'SER' && ROW.OID1 !== '-9999999') {return 'SF' + ROW.OID1}
					;
				]]>
			</value>
		</ARG>
		
		
		
		<ARG name="ETAGE_MOUVEMENT">
			<value>
				<![CDATA[
					if (SELECT.GROUPBY_2.substr(0,6) == 'ETACLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2} 
					if (SELECT.GROUPBY_2 == 'ETA' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'ET' + ROW.OID2} 
					if (SELECT.GROUPBY.substr(0,6) == 'ETACLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1} 
					if (SELECT.GROUPBY == 'ETA' && ROW.OID1 !== '-9999999') {return 'ET' + ROW.OID1} 
					;
				]]>
			</value>
		</ARG>
		
		<ARG name="MEDECIN_MOUVEMENT">
			<value>
				<![CDATA[
					if (SELECT.GROUPBY_2.substr(0,6) == 'MDACLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2} 
					if (SELECT.GROUPBY_2 == 'MDA' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'MA' + ROW.OID2} 
					if (SELECT.GROUPBY_2 == 'MED' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'MD' + ROW.OID2} 
					if (SELECT.GROUPBY_2 == 'SPM' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'SP' + ROW.OID2} 
					if (SELECT.GROUPBY.substr(0,6) == 'MDACLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1} 
					if (SELECT.GROUPBY == 'MDA' && ROW.OID1 !== '-9999999') {return 'MA' + ROW.OID1} 
					if (SELECT.GROUPBY == 'MED' && ROW.OID1 !== '-9999999') {return 'MD' + ROW.OID1} 
					if (SELECT.GROUPBY == 'SPM' && ROW.OID1 !== '-9999999') {return 'SP' + ROW.OID1} 
					;
				]]>
			</value>
		</ARG>
		
		<ARG name="ACTIVITE_MOUVEMENT">
			<value>
				<![CDATA[
					if (SELECT.GROUPBY_2.substr(0,6) == 'ACTCLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2} 
					if (SELECT.GROUPBY_2 == 'ACT' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'AC' + ROW.OID2} 
					if (SELECT.GROUPBY.substr(0,6) == 'ACTCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1} 
					if (SELECT.GROUPBY == 'ACT' && ROW.OID1 !== '-9999999') {return 'AC' + ROW.OID1} 
					;
				]]>
			</value>
		</ARG>
		
		<ARG name="UM_MOUVEMENT">
			<value>
				<![CDATA[
					if (SELECT.GROUPBY_2.substr(0,6) == 'UMDCLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2} 
					if (SELECT.GROUPBY_2 == 'UM' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'UM' + ROW.OID2} 
					if (SELECT.GROUPBY.substr(0,6) == 'UMDCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1} 
					if (SELECT.GROUPBY == 'UM' && ROW.OID1 !== '-9999999') {return 'UM' + ROW.OID1} 
					;
				]]>
			</value>
		</ARG>
		
		<ARG name="UF_MOUVEMENT">
			<value>
				<![CDATA[
					if (SELECT.GROUPBY_2.substr(0,6) == 'UFTCLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2} 
					if (SELECT.GROUPBY_2 == 'UF' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'UF' + ROW.OID2} 
					if (SELECT.GROUPBY.substr(0,6) == 'UFTCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1} 
					if (SELECT.GROUPBY == 'UF' && ROW.OID1 !== '-9999999') {return 'UF' + ROW.OID1} 
					;
				]]>
			</value>
		</ARG>
		
		<ARG name="LIT_MOUVEMENT">
			<value>
				<![CDATA[
					if (SELECT.GROUPBY_2.substr(0,6) == 'LITCLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2} 
					if (SELECT.GROUPBY_2 == 'LIT' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LT' + ROW.OID2} 
					if (SELECT.GROUPBY.substr(0,6) == 'LITCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1} 
					if (SELECT.GROUPBY == 'LIT' && ROW.OID1 !== '-9999999') {return 'LT' + ROW.OID1} 
					;
				]]>
			</value>
		</ARG>
        
        <ARG name="GIR_MOUVEMENT">
			<value>
				<![CDATA[
					if (SELECT.GROUPBY_2.substr(0,6) == 'GIRCLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2} 
					if (SELECT.GROUPBY_2 == 'GIR' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LT' + ROW.OID2} 
					if (SELECT.GROUPBY.substr(0,6) == 'GIRCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1} 
					if (SELECT.GROUPBY == 'GIR' && ROW.OID1 !== '-9999999') {return 'DT' + ROW.OID1} 
					;
				]]>
			</value>
		</ARG>
		
		
		<ARG name="MEDECIN_SEJOUR">
			<value>
				<![CDATA[
					if (SELECT.COLUMNBY.substr(0,6) == 'MDACLS' && COLUMN.DATA != '') {return 'LS' + SELECT.COLUMNBY.substr(6,2) + COLUMN.DATA} 
					if (SELECT.COLUMNBY == 'MDA' && COLUMN.DATA != '') {return 'MA' + COLUMN.DATA} 
					if (SELECT.COLUMNBY == 'MED' && COLUMN.DATA != '') {return 'MD' + COLUMN.DATA} 
					if (SELECT.COLUMNBY == 'SPM' && COLUMN.DATA != '') {return 'SP' + COLUMN.DATA} 
					if (SELECT.GROUPBY_2.substr(0,6) == 'MDACLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2} 
					if (SELECT.GROUPBY_2 == 'MDA' && ROW.OID2 != '-9999999') {return 'MA' + ROW.OID2} 
					if (SELECT.GROUPBY_2 == 'MED' && ROW.OID2 != '-9999999') {return 'MD' + ROW.OID2} 
					if (SELECT.GROUPBY_2 == 'SPM' && ROW.OID2 != '-9999999') {return 'SP' + ROW.OID2} 
					if (SELECT.GROUPBY.substr(0,6) == 'MDACLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1} 
					if (SELECT.GROUPBY == 'MDA' && ROW.OID1 !== '-9999999') {return 'MA' + ROW.OID1} 
					if (SELECT.GROUPBY == 'MED' && ROW.OID1 !== '-9999999') {return 'MD' + ROW.OID1} 
					if (SELECT.GROUPBY == 'SPM' && ROW.OID1 !== '-9999999') {return 'SP' + ROW.OID1} 
					;
				]]>
			</value>
		</ARG>
		
		<!--
		<ARG name="T_AGE_PATIENT">
			<value><![CDATA[
				
				if (SELECT.GROUPBY_2.substr(0,6) == 'AGECLS' && ROW.OID2 != '0') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2} 
				if (SELECT.GROUPBY_2 == 'AGE' && ROW.OID2 != '0') {return 'AG' + ROW.OID2}
				if (SELECT.GROUPBY.substr(0,6) == 'AGECLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1} 
				if (SELECT.GROUPBY == 'AGE') {return 'AG' + ROW.OID1}
				
			]]></value>
		</ARG>
		
		<ARG name="ORIGINEGEO_PATIENT">
			<value><![CDATA[
				
				if (SELECT.GROUPBY_2.substr(0,6) == 'CDPCLS' && ROW.OID2 != '0') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2} 
				if (SELECT.GROUPBY_2 == 'DEPARTEMENT' && ROW.OID2 != '0') {return 'DP' + ROW.OID2}
				if (SELECT.GROUPBY_2 == 'CODEGEOPMSI' && ROW.OID2 != '0') {return 'GP' + ROW.OID2}
				if (SELECT.GROUPBY_2 == 'CODEPOST' && ROW.OID2 != '0') {return 'CP' + ROW.OID2}
				if (SELECT.GROUPBY_2 == 'TERSANTE' && ROW.OID2 != '0') {return 'TS' + ROW.OID2}
				if (SELECT.GROUPBY.substr(0,6) == 'CDPCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1} 
				if (SELECT.GROUPBY == 'DEPARTEMENT') {return 'DP' + ROW.OID1}
				if (SELECT.GROUPBY == 'CODEGEOPMSI') {return 'GP' + ROW.OID1}
				if (SELECT.GROUPBY == 'CODEPOST') {return 'CP' + ROW.OID1}
				if (SELECT.GROUPBY == 'TERSANTE') {return 'TS' + ROW.OID1}
				
			]]></value>
		</ARG>
		-->
		
		
		<ARG name="LUN"><value><![CDATA[ 
			
			/*	
				On ne sélectionne pas le jour uniquement si le deuxième niveau de regroupement est 'jour'
				et si la ligne sélectionnée ne correspond pas au jour traité.
				Exemple : Regroupement par mois puis par jour. Si on clique sur la ligne du mardi, on ne le sélectionne pas ;
				si on clique sur la ligne du lundi ou sur une ligne de mois, on le sélectionne.
				Même comportement pour tous les autres jours
			*/
			
			if (SELECT.GROUPBY_2 == 'NUMEROJOUR' && !isNaN(ROW.COD2) && SELECT.GROUPBY != 'JOUR') {
				if (ROW.COD2 == '1') {return '1';}
				else {return '0';}
			}
			if (SELECT.GROUPBY == 'NUMEROJOUR') {
				if (ROW.COD1 == '1') {return '1';}
				else {return '0';}
			}
			if (SELECT.GROUPBY == 'JOUR') {return '1';}
			if (SELECT.GROUPBY == 'SEMAINEWE' && (SELECT.GROUPBY_2 != 'JOUR' || ROW.COD == ROW.COD1)) {
				if (ROW.COD1 == 'SEM') {return '1';} else { return '0';}
			}
			if (SELECT.GROUPBY_2 == 'SEMAINEWE' && ROW.COD == ROW.COD2) {
				if (ROW.COD2 == 'SEM') {return '1';} else { return '0';}
			}
			
		]]></value></ARG>
		
		<ARG name="MAR"><value><![CDATA[ 
			
			if (SELECT.GROUPBY_2 == 'NUMEROJOUR' && !isNaN(ROW.COD2) && SELECT.GROUPBY != 'JOUR') {
				if (ROW.COD2 == '2') {return '2';}
				else {return '0';}
			}
			if (SELECT.GROUPBY == 'NUMEROJOUR') {
				if (ROW.COD1 == '2') {return '2';}
				else {return '0';}
			}
			if (SELECT.GROUPBY == 'JOUR') {return '2';}
			if (SELECT.GROUPBY == 'SEMAINEWE' && (SELECT.GROUPBY_2 != 'JOUR' || ROW.COD == ROW.COD1)) {
				if (ROW.COD1 == 'SEM') {return '2';} else { return '0';}
			}
			if (SELECT.GROUPBY_2 == 'SEMAINEWE' && ROW.COD == ROW.COD2) {
				if (ROW.COD2 == 'SEM') {return '2';} else { return '0';}
			}
			
		]]></value></ARG>
		
		<ARG name="MER"><value><![CDATA[ 
			
			if (SELECT.GROUPBY_2 == 'NUMEROJOUR' && !isNaN(ROW.COD2) && SELECT.GROUPBY != 'JOUR') {
				if (ROW.COD2 == '3') {return '3';}
				else {return '0';}
			}
			if (SELECT.GROUPBY == 'NUMEROJOUR') {
				if (ROW.COD1 == '3') {return '3';}
				else {return '0';}
			}
			if (SELECT.GROUPBY == 'JOUR') {return '3';}
			if (SELECT.GROUPBY == 'SEMAINEWE' && (SELECT.GROUPBY_2 != 'JOUR' || ROW.COD == ROW.COD1)) {
				if (ROW.COD1 == 'SEM') {return '3';} else { return '0';}
			}
			if (SELECT.GROUPBY_2 == 'SEMAINEWE' && ROW.COD == ROW.COD2) {
				if (ROW.COD2 == 'SEM') {return '3';} else { return '0';}
			}
			
		]]></value></ARG>
		
		<ARG name="JEU"><value><![CDATA[ 
			
			if (SELECT.GROUPBY_2 == 'NUMEROJOUR' && !isNaN(ROW.COD2) && SELECT.GROUPBY != 'JOUR') {
				if (ROW.COD2 == '4') {return '4';}
				else {return '0';}
			}
			if (SELECT.GROUPBY == 'NUMEROJOUR') {
				if (ROW.COD1 == '4') {return '4';}
				else {return '0';}
			}
			if (SELECT.GROUPBY == 'JOUR') {return '4';}
			if (SELECT.GROUPBY == 'SEMAINEWE' && (SELECT.GROUPBY_2 != 'JOUR' || ROW.COD == ROW.COD1)) {
				if (ROW.COD1 == 'SEM') {return '4';} else { return '0';}
			}
			if (SELECT.GROUPBY_2 == 'SEMAINEWE' && ROW.COD == ROW.COD2) {
				if (ROW.COD2 == 'SEM') {return '4';} else { return '0';}
			}
			
		]]></value></ARG>
		
		<ARG name="VEN"><value><![CDATA[ 
			
			if (SELECT.GROUPBY_2 == 'NUMEROJOUR' && !isNaN(ROW.COD2) && SELECT.GROUPBY != 'JOUR') {
				if (ROW.COD2 == '5') {return '5';}
				else {return '0';}
			}
			if (SELECT.GROUPBY == 'NUMEROJOUR') {
				if (ROW.COD1 == '5') {return '5';}
				else {return '0';}
			}
			if (SELECT.GROUPBY == 'JOUR') {return '5';}
			if (SELECT.GROUPBY == 'SEMAINEWE' && (SELECT.GROUPBY_2 != 'JOUR' || ROW.COD == ROW.COD1)) {
				if (ROW.COD1 == 'SEM') {return '5';} else { return '0';}
			}
			if (SELECT.GROUPBY_2 == 'SEMAINEWE' && ROW.COD == ROW.COD2) {
				if (ROW.COD2 == 'SEM') {return '5';} else { return '0';}
			}
			
		]]></value></ARG>
		
		<ARG name="SAM"><value><![CDATA[ 
			
			if (SELECT.GROUPBY_2 == 'NUMEROJOUR' && !isNaN(ROW.COD2) && SELECT.GROUPBY != 'JOUR') {
				if (ROW.COD2 == '6') {return '6';}
				else {return '0';}
			}
			if (SELECT.GROUPBY == 'NUMEROJOUR') {
				if (ROW.COD1 == '6') {return '6';}
				else {return '0';}
			}
			if (SELECT.GROUPBY == 'JOUR') {return '6';}
			if (SELECT.GROUPBY == 'SEMAINEWE' && (SELECT.GROUPBY_2 != 'JOUR' || ROW.COD == ROW.COD1)) {
				if (ROW.COD1 == 'SEM') {return '0';} else { return '6';}
			}
			if (SELECT.GROUPBY_2 == 'SEMAINEWE' && ROW.COD == ROW.COD2) {
				if (ROW.COD2 == 'SEM') {return '0';} else { return '6';}
			}
			
		]]></value></ARG>
		
		<ARG name="DIM"><value><![CDATA[ 
			
			if (SELECT.GROUPBY_2 == 'NUMEROJOUR' && !isNaN(ROW.COD2) && SELECT.GROUPBY != 'JOUR') {
				if (ROW.COD2 == '7') {return '7';}
				else {return '0';}
			}
			if (SELECT.GROUPBY == 'NUMEROJOUR') {
				if (ROW.COD1 == '7') {return '7';}
				else {return '0';}
			}
			if (SELECT.GROUPBY == 'JOUR') {return '7';}
			if (SELECT.GROUPBY == 'SEMAINEWE' && (SELECT.GROUPBY_2 != 'JOUR' || ROW.COD == ROW.COD1)) {
				if (ROW.COD1 == 'SEM') {return '0';} else { return '7';}
			}
			if (SELECT.GROUPBY_2 == 'SEMAINEWE' && ROW.COD == ROW.COD2) {
				if (ROW.COD2 == 'SEM') {return '0';} else { return '7';}
			}
			
		]]></value></ARG>
		<ARG name="DATA">
			<value><![CDATA[ 
						
				var data:String = 'NSEJ';

				if (SELECT.DATA != 'NSEJ') {
					data = SELECT.DATA;
				} 	

				switch (COLUMN.NAME) {
						
					case 'ENT' :			data = 'NED'; 			break;
					case 'ENTMS' :			data = 'NEM';	        break;
					case 'ENTME' :			data = 'NEM';           break;
					case 'SOR' :			data = 'NSD';			break;
					case 'SORM' :			data = 'NSM';		    break;
					case 'SORHON' :			data = 'NSDXAS';		break;
					case 'JRN' :			data = 'NJN';			break;
					case 'JRNM' :			data = 'JRN';			break;
					case 'AMB' :			data = 'NAM';			break;
					case 'AMBM' :			data = 'NAMM';			break;
					case 'SEA' :			data = 'NSE';			break;
					case 'SEAM' :			data = 'NSEM';			break;
					case 'JRNHON' :			data = 'NJNAS';			break;
					case 'GMP' :			data = 'GMP';		    break;
					case 'NONSOR' :			data = 'NNONSOR';		break;
					case 'SORFAC' :			data = 'NSFAC';			break;
					case 'SORNONFAC' :		data = 'NSNFAC';		break;
					case 'JRNSOR' :			data = 'NJN';			break;
					case 'JRNSORHON' :		data = 'NJNAS';			break;
					case 'JRNSORHONFAC' :	data = 'JRNSORHONFAC';	break;
					case 'URG' :			data = 'URG';			break;
					case 'URGM' :			data = 'URG';			break;
					case 'BB' :				data = 'BB';			break;
					case 'BBM' :			data = 'BB';			break;
					case 'EXT' :			data = 'NEX';			break;
					case 'EXTM' :			data = 'NEX';			break;
					case 'JRNSORFAC' :		data = 'JRNSORFAC';		break;
					case 'NCP' :			data = 'CP';			break;
					case 'DECES' :			data = 'DECES';			break;					
				}
				return data;
					
			]]></value>
		</ARG>
		<ARG name="STATUT_SEJOUR">
			<value><![CDATA[ 
				
				var s:String = '';
				switch (COLUMN.NAME) {
					case 'FULL' :			s = '1';	break; 
					case 'SORPER' :			s = '2';	break; 
					case 'JRNSOR' :			s = '2';	break; 
					case 'JRNSORHON' :		s = '2';	break; 
					case 'JRNSORHONFAC' :	s = '2';	break; 
					case 'ENTPER' :			s = '3';	break; 
					case 'ENTPRE' :			s = '4';	break; 
					case 'SORPOST' :		s = '5';	break; 
                    case 'DECES' :	    	s = '2';	break;
					default :				s = '-1';	break; 
				}
				return s;
				
			]]></value>
		</ARG>		
	</COMPONENT>

	<COMPONENT name="ETA_DOS_BASE_VIEWLINK" >
		<ARG name="PERIODE">
			<value><![CDATA[
			
				var annee_periode:String = SELECT.PERIODE.substr(0,4);
				var mois_periode:String = SELECT.PERIODE.substr(5,2);
				var annee_toperiode:String = SELECT.TOPERIODE.substr(0,4);
				var mois_toperiode:String = SELECT.TOPERIODE.substr(5,2);
				
				var mois_debut:int = 0;
				var mois_debut_string:String = '';
				var annee:String = '';
				
				function getDateFromWeek(code:String,day:int) {
					var annee:String =  code.substr(0,4);
					var date:Date = new Date(int(annee),0,1);
					date.setTime(date.getTime() + 1000*60*60*24*(7*(int(code.substr(4,6))-1)-(date.getDay()+7)%6+day));
					var year = date.getFullYear();
					var month = date.getMonth()+1;
					var day = date.getDate();
					if(month < 10){
						month = 0 + month;
					}
					if(day < 10){
						day = 0 + day;
					}
					return year + '-' + month + '-' + day;
				}

				if(ROW.OID === '-9999999'){
					return SELECT.PERIODE;
				}
				
		// TRAITEMENT DATE SORTIE
				
				if (SELECT.GROUPBY == 'SEMAINEANNE' || SELECT.GROUPBY_2 == 'SEMAINEANNE' || SELECT.GROUPBY_3 == 'SEMAINEANNE' ) {
					if(SELECT.GROUPBY == 'SEMAINEANNE' || SELECT.GROUPBY_2 == 'SEMAINEANNE'){
							row_cod = (SELECT.GROUPBY == 'SEMAINEANNE') ? ROW.COD1 : ROW.COD2;
					} 
					else {
							row_cod = ROW.COD3;
					}
					if (SELECT.GROUPBY == 'ANNEE' || SELECT.GROUPBY_2 == 'ANNEE' ) {
						var annee:String =  (SELECT.GROUPBY == 'SEMAINEANNE') ?  ROW.COD2.substr(0,4) : ROW.COD1.substr(0,4);
						return getDateFromWeek(annee+row_cod,0);
					}
					else{
						var date:String = getDateFromWeek(annee_toperiode + row_cod,6);
						var month:int = parseInt(date.substr(5,2));
						var day:int = parseInt(date.substr(8,2));
						var toDay:int = parseInt(SELECT.TOPERIODE.substr(8,2));	

						if (month <= parseInt(mois_toperiode) && day <= toDay) {
							return getDateFromWeek(annee_toperiode+row_cod,0);
						}
						else {
								return getDateFromWeek((parseInt(annee_toperiode)).toString()+row_cod,0);
						}
					}
				}
				
				if (SELECT.GROUPBY == 'JOURS' || SELECT.GROUPBY_2 == 'JOURS' || SELECT.GROUPBY_3 == 'JOURS' ) {
					
					if (SELECT.GROUPBY == 'JOURS') {
						
						return annee_periode+'-'+ROW.COD1;
					}
					else if (ROW.COD == ROW.COD2) {

						return annee_periode+'-'+ROW.COD2;

					} 
					else if(ROW.COD == ROW.COD3) {

						return annee_periode+'-'+ROW.COD3;
					}
				}
				if (SELECT.GROUPBY == 'JOUR' || SELECT.GROUPBY_2 == 'JOUR' || SELECT.GROUPBY_3 == 'JOUR') {
					
					if (SELECT.GROUPBY == 'JOUR') {
						return ROW.COD1;
					}
					else if (ROW.COD == ROW.COD2) {

						return ROW.COD2;

					}else if(ROW.COD == ROW.COD3) {

						return ROW.COD3;
					}
				}
				if (SELECT.GROUPBY == 'MOIS' || SELECT.GROUPBY_2 == 'MOIS' || SELECT.GROUPBY_3 == 'MOIS' ) {
					
					var mois:String = '';
					
					if (SELECT.GROUPBY == 'MOIS') {
						
						annee = ROW.COD1.substr(0,4);
						mois = ROW.COD1.substr(-2);
						
						if (annee == annee_periode && mois == mois_periode) {
							return SELECT.PERIODE;
						}
						else {
							return annee + mois;
						}
					}
					else if (SELECT.GROUPBY_2 == 'MOIS') {
						
						annee = ROW.COD2.substr(0,4);
						mois = ROW.COD2.substr(-2);
						
						if (ROW.COD == ROW.COD2) {
							
							if (annee == annee_periode && mois == mois_periode) {
								return SELECT.PERIODE;
							}
							else {
								return annee + mois;
							}
						}
						else {
							
							if (SELECT.GROUPBY == 'ANNEE' && ROW.COD1 != annee_periode) {
								return ROW.COD1 + '01';
							}
							else {
								return SELECT.PERIODE;
							}
						}
					} 
					else {
							annee = ROW.COD3.substr(0,4);
							mois = ROW.COD3.substr(-2);
						
						if (ROW.COD == ROW.COD3) {
							
							if (annee == annee_periode && mois == mois_periode) {
								return SELECT.PERIODE;
							}
							else {
								return annee + mois;
							}
						}
						else {
							
							if (SELECT.GROUPBY == 'ANNEE' && ROW.COD1 != annee_periode) {
								return ROW.COD1 + '01';
							}
							else {
								return SELECT.PERIODE;
							}
						}
					
					}
				}
				else if (SELECT.GROUPBY == 'NUMEROMOIS' || SELECT.GROUPBY_2 == 'NUMEROMOIS' || SELECT.GROUPBY_3 == 'NUMEROMOIS') {
					
					if (SELECT.GROUPBY == 'NUMEROMOIS') {
						
						if (parseInt(ROW.COD1) <= parseInt(mois_toperiode)) {
							return annee_toperiode + ROW.COD1;
						}
						else {
							return (parseInt(annee_toperiode) - 1).toString() + ROW.COD1;
						}
					}
					else if (SELECT.GROUPBY_2 == 'NUMEROMOIS') {
						
						mois_debut = 1 + 3 * (parseInt(ROW.COD1.substr(-1)) - 1);
						mois_debut_string = mois_debut < 10 ? '0' + mois_debut.toString() : mois_debut.toString();
						annee = ROW.COD1.substr(0,4);
						
						if (SELECT.GROUPBY == 'ANNEE') {
							
							if (ROW.COD == ROW.COD2) {
								return ROW.COD1 + ROW.COD2;
							}
							else {
								
								if (ROW.COD1 == annee_periode) {
									return SELECT.PERIODE;
								}
								else {
									return ROW.COD1 + '01';
								}
							}
						}
						else if (SELECT.GROUPBY == 'TRIM') {
						
							if (ROW.COD == ROW.COD2) {
								return annee + ROW.COD2;
							}
							else {
								if (annee == annee_periode && mois_debut <= parseInt(mois_periode)) {
									return SELECT.PERIODE;
								}
								else {
									return annee + mois_debut_string;
								}
							}
						}
						else if (SELECT.GROUPBY == 'NUMEROTRIM') {
							
							if (ROW.COD ==  ROW.COD2) {
								
								if (parseInt(ROW.COD2) <= parseInt(mois_toperiode)) {
									return annee_toperiode + ROW.COD2
								}
								else {
									return (parseInt(annee_toperiode) - 1).toString() + ROW.COD2;
								}
							}
							else {
								
								if (mois_debut <= parseInt(mois_toperiode)) {
									return annee_toperiode + mois_debut_string;
								}
								else {
									return (parseInt(annee_toperiode) - 1).toString() + mois_debut_string;
								}
							}
						}
						else {
							
							if (ROW.COD == ROW.COD2) {
								
								if (parseInt(ROW.COD2) <= parseInt(mois_toperiode)) {
									return annee_toperiode + ROW.COD2;
								}
								else {
									return (parseInt(annee_toperiode) - 1).toString() + ROW.COD2;
								}
							}
							else {
								return SELECT.PERIODE;
							}
						}
					} 
					else {

							mois_debut = 1 + 3 * (parseInt(ROW.COD2.substr(-1)) - 1);
							mois_debut_string = mois_debut < 10 ? '0' + mois_debut.toString() : mois_debut.toString();
							annee = ROW.COD2.substr(0,4);
						
						if (SELECT.GROUPBY == 'ANNEE') {
							
							if (ROW.COD == ROW.COD3) {
								return ROW.COD1 + ROW.COD2 + ROW.COD3;
							}
							else {
								
								if (ROW.COD1 == annee_periode) {
									return SELECT.PERIODE;
								}
								else {
									return ROW.COD1 + '01';
								}
							}
						}
						else if (SELECT.GROUPBY == 'TRIM') {
						
							if (ROW.COD == ROW.COD2) {
								return annee + ROW.COD2;
							}
							else {
								if (annee == annee_periode && mois_debut <= parseInt(mois_periode)) {
									return SELECT.PERIODE;
								}
								else {
									return annee + mois_debut_string;
								}
							}
						}
						else if (SELECT.GROUPBY == 'NUMEROTRIM') {
							
							if (ROW.COD ==  ROW.COD2) {
								
								if (parseInt(ROW.COD2) <= parseInt(mois_toperiode)) {
									return annee_toperiode + ROW.COD2
								}
								else {
									return (parseInt(annee_toperiode) - 1).toString() + ROW.COD2;
								}
							}
							else {
								
								if (mois_debut <= parseInt(mois_toperiode)) {
									return annee_toperiode + mois_debut_string;
								}
								else {
									return (parseInt(annee_toperiode) - 1).toString() + mois_debut_string;
								}
							}
						}
						else {
							
							if (ROW.COD == ROW.COD3) {
								
								if (parseInt(ROW.COD3) <= parseInt(mois_toperiode)) {
									return annee_toperiode + ROW.COD3;
								}
								else {
									return (parseInt(annee_toperiode) - 1).toString() + ROW.COD3;
								}
							}
							else {
								return SELECT.PERIODE;
							}
						}
					}
				}
				else if (SELECT.GROUPBY == 'TRIM' || SELECT.GROUPBY_2 == 'TRIM' || SELECT.GROUPBY_3 == 'TRIM') {
					
					if (SELECT.GROUPBY == 'TRIM') {
					
							annee = ROW.COD1.substr(0,4);
							mois_debut = 1 + 3 * (parseInt(ROW.COD1.substr(-1)) - 1);
							mois_debut_string = mois_debut < 10 ? '0' + mois_debut.toString() : mois_debut.toString();
						
						if (annee == annee_periode && mois_debut <= parseInt(mois_periode)) {
							return SELECT.PERIODE;
						}
						else {
							return annee + mois_debut_string;
						}
					}
					else if (SELECT.GROUPBY_2 == 'TRIM'){
					
							annee = ROW.COD2.substr(0,4);
							mois_debut = 1 + 3 * (parseInt(ROW.COD2.substr(-1)) - 1);
							mois_debut_string = mois_debut < 10 ? '0' + mois_debut.toString() : mois_debut.toString();
						
						if (ROW.COD == ROW.COD2) {
							
							if (annee == annee_periode && mois_debut <= parseInt(mois_periode)) {
								return SELECT.PERIODE;
							}
							else {
								return annee + mois_debut_string;
							}
						}
						else {
							
							if (SELECT.GROUPBY == 'ANNEE' && ROW.COD1 != annee_periode) {
								return ROW.COD1 + '01';
							}
							else {
								return SELECT.PERIODE;
							}
						}
					} else {
							annee = ROW.COD3.substr(0,4);
							mois_debut = 1 + 3 * (parseInt(ROW.COD3.substr(-1)) - 1);
							mois_debut_string = mois_debut < 10 ? '0' + mois_debut.toString() : mois_debut.toString();
						
						if (ROW.COD == ROW.COD3) {
							
							if (annee == annee_periode && mois_debut <= parseInt(mois_periode)) {
								return SELECT.PERIODE;
							}
							else {
								return annee + mois_debut_string;
							}
						}
						else {
							
							if (SELECT.GROUPBY == 'ANNEE' && ROW.COD1 != annee_periode) {
								return ROW.COD1 + '01';
							}
							else {
								return SELECT.PERIODE;
							}
						}
					
					} 
				}
				else if (SELECT.GROUPBY == 'NUMEROTRIM' || SELECT.GROUPBY_2 == 'NUMEROTRIM' || SELECT.GROUPBY_3 == 'NUMEROTRIM') {
					
						mois_debut = 1 + 3 * (parseInt(ROW.COD2.substr(-1)) - 1);
						mois_debut_string = mois_debut < 10 ? '0' + mois_debut.toString() : mois_debut.toString();
					
					if (SELECT.GROUPBY == 'NUMEROTRIM') {
					
						mois_debut = 1 + 3 * (parseInt(ROW.COD1.substr(-1)) - 1);
						mois_debut_string = mois_debut < 10 ? '0' + mois_debut.toString() : mois_debut.toString();
						
						if (mois_debut <= parseInt(mois_toperiode)) {
							return annee_toperiode + mois_debut_string;
						}
						else {
							return (parseInt(annee_toperiode) -1).toString() + mois_debut_string;
						}
					}
					else if (SELECT.GROUPBY == 'ANNEE') {

						if (ROW.COD == ROW.COD2) {
							
							if (ROW.COD1 == annee_periode && mois_debut <= parseInt(mois_periode)) {
								return SELECT.PERIODE;
							}
							else {
								return ROW.COD1 + mois_debut_string;
							}
						}
						else {
							
							if (ROW.COD1 == annee_periode) {
								return SELECT.PERIODE;
							}
							else {
								return ROW.COD1 + '01';
							}
						}
					}
					else  if(SELECT.GROUPBY_2 == 'NUMEROTRIM') {
						
						if (ROW.COD == ROW.COD2) {
							
							if (mois_debut <= parseInt(mois_toperiode)) {
								return annee_toperiode + mois_debut_string;
							}
							else {
								return (parseInt(annee_toperiode) - 1).toString() + mois_debut_string;
							}
						}
						else {
							return SELECT.PERIODE;
						}
					}	
					else {
								mois_debut = 1 + 3 * (parseInt(ROW.COD3.substr(-1)) - 1);
								mois_debut_string = mois_debut < 10 ? '0' + mois_debut.toString() : mois_debut.toString();
						if (ROW.COD == ROW.COD3) {
								
							if (mois_debut <= parseInt(mois_toperiode)) {
									return annee_toperiode + mois_debut_string;
							}
							else {
									return (parseInt(annee_toperiode) - 1).toString() + mois_debut_string;
								}
						}
						else {
								return SELECT.PERIODE;
						}
					
					}
				}
				else if (SELECT.GROUPBY == 'ANNEE'|| SELECT.GROUPBY_2 == 'ANNEE' || SELECT.GROUPBY_3 == 'ANNEE') {
				
					if(SELECT.GROUPBY == 'ANNEE'|| SELECT.GROUPBY_2 == 'ANNEE') {
					
						var row_cod:String = (SELECT.GROUPBY == 'ANNEE') ? ROW.COD1 : ROW.COD2;
					}else {
						var row_cod:String = ROW.COD3;
					}
	
					if (row_cod == annee_periode) {
						return SELECT.PERIODE;
					}
					else {
						return row_cod + '01';
					}
				}
			// FIN TRAITEMENT DATE Sortie
			// TRAITEMENT DATE D'ACTIVITE
				if (SELECT.GROUPBY == 'SEMAINEANNEA' || SELECT.GROUPBY_2 == 'SEMAINEANNEA' || SELECT.GROUPBY_3 == 'SEMAINEANNEA' ) {
					if(SELECT.GROUPBY == 'SEMAINEANNEA' || SELECT.GROUPBY_2 == 'SEMAINEANNEA'){
							row_cod = (SELECT.GROUPBY == 'SEMAINEANNEA') ? ROW.COD1 : ROW.COD2;
					} 
					else {
							row_cod = ROW.COD3;
					}
					if (SELECT.GROUPBY == 'ANNEEA' || SELECT.GROUPBY_2 == 'ANNEEA' ) {
						var annee:String =  (SELECT.GROUPBY == 'SEMAINEANNEA') ?  ROW.COD2.substr(0,4) : ROW.COD1.substr(0,4);
						return getDateFromWeek(annee+row_cod,0);
					}
					else{
						var date:String = getDateFromWeek(annee_toperiode + row_cod,6);
						var month:int = parseInt(date.substr(5,2));
						var day:int = parseInt(date.substr(8,2));
						var toDay:int = parseInt(SELECT.TOPERIODE.substr(8,2));	

						if (month <= parseInt(mois_toperiode) && day <= toDay) {
							return getDateFromWeek(annee_toperiode+row_cod,0);
						}
						else {
								return getDateFromWeek((parseInt(annee_toperiode)).toString()+row_cod,0);
						}
					}
				}
				
				if (SELECT.GROUPBY == 'JOURSA' || SELECT.GROUPBY_2 == 'JOURSA' || SELECT.GROUPBY_3 == 'JOURSA' ) {
					
					if (SELECT.GROUPBY == 'JOURSA') {
						
						return annee_periode+'-'+ROW.COD1;
					}
					else if (ROW.COD == ROW.COD2) {

						return annee_periode+'-'+ROW.COD2;

					} 
					else if(ROW.COD == ROW.COD3) {

						return annee_periode+'-'+ROW.COD3;
					}
				}
				if (SELECT.GROUPBY == 'JOURA' || SELECT.GROUPBY_2 == 'JOURA' || SELECT.GROUPBY_3 == 'JOURA') {
					
					if (SELECT.GROUPBY == 'JOURA') {
						return ROW.COD1;
					}
					else if (ROW.COD == ROW.COD2) {

						return ROW.COD2;

					}else if(ROW.COD == ROW.COD3) {

						return ROW.COD3;
					}
				}
				if (SELECT.GROUPBY == 'MOISA' || SELECT.GROUPBY_2 == 'MOISA' || SELECT.GROUPBY_3 == 'MOISA' ) {
					
					var mois:String = '';
					
					if (SELECT.GROUPBY == 'MOISA') {
						
						annee = ROW.COD1.substr(0,4);
						mois = ROW.COD1.substr(-2);
						
						if (annee == annee_periode && mois == mois_periode) {
							return SELECT.PERIODE;
						}
						else {
							return annee + mois;
						}
					}
					else if (SELECT.GROUPBY_2 == 'MOISA') {
						
						annee = ROW.COD2.substr(0,4);
						mois = ROW.COD2.substr(-2);
						
						if (ROW.COD == ROW.COD2) {
							
							if (annee == annee_periode && mois == mois_periode) {
								return SELECT.PERIODE;
							}
							else {
								return annee + mois;
							}
						}
						else {
							
							if (SELECT.GROUPBY == 'ANNEEA' && ROW.COD1 != annee_periode) {
								return ROW.COD1 + '01';
							}
							else {
								return SELECT.PERIODE;
							}
						}
					} 
					else {
							annee = ROW.COD3.substr(0,4);
							mois = ROW.COD3.substr(-2);
						
						if (ROW.COD == ROW.COD3) {
							
							if (annee == annee_periode && mois == mois_periode) {
								return SELECT.PERIODE;
							}
							else {
								return annee + mois;
							}
						}
						else {
							
							if (SELECT.GROUPBY == 'ANNEEA' && ROW.COD1 != annee_periode) {
								return ROW.COD1 + '01';
							}
							else {
								return SELECT.PERIODE;
							}
						}
					
					}
				}
				else if (SELECT.GROUPBY == 'NUMEROMOISA' || SELECT.GROUPBY_2 == 'NUMEROMOISA' || SELECT.GROUPBY_3 == 'NUMEROMOISA') {
					
					if (SELECT.GROUPBY == 'NUMEROMOISA') {
						
						if (parseInt(ROW.COD1) <= parseInt(mois_toperiode)) {
							return annee_toperiode + ROW.COD1;
						}
						else {
							return (parseInt(annee_toperiode) - 1).toString() + ROW.COD1;
						}
					}
					else if (SELECT.GROUPBY_2 == 'NUMEROMOISA') {
						
						mois_debut = 1 + 3 * (parseInt(ROW.COD1.substr(-1)) - 1);
						mois_debut_string = mois_debut < 10 ? '0' + mois_debut.toString() : mois_debut.toString();
						annee = ROW.COD1.substr(0,4);
						
						if (SELECT.GROUPBY == 'ANNEEA') {
							
							if (ROW.COD == ROW.COD2) {
								return ROW.COD1 + ROW.COD2;
							}
							else {
								
								if (ROW.COD1 == annee_periode) {
									return SELECT.PERIODE;
								}
								else {
									return ROW.COD1 + '01';
								}
							}
						}
						else if (SELECT.GROUPBY == 'TRIMA') {
						
							if (ROW.COD == ROW.COD2) {
								return annee + ROW.COD2;
							}
							else {
								if (annee == annee_periode && mois_debut <= parseInt(mois_periode)) {
									return SELECT.PERIODE;
								}
								else {
									return annee + mois_debut_string;
								}
							}
						}
						else if (SELECT.GROUPBY == 'NUMEROTRIMA') {
							
							if (ROW.COD ==  ROW.COD2) {
								
								if (parseInt(ROW.COD2) <= parseInt(mois_toperiode)) {
									return annee_toperiode + ROW.COD2
								}
								else {
									return (parseInt(annee_toperiode) - 1).toString() + ROW.COD2;
								}
							}
							else {
								
								if (mois_debut <= parseInt(mois_toperiode)) {
									return annee_toperiode + mois_debut_string;
								}
								else {
									return (parseInt(annee_toperiode) - 1).toString() + mois_debut_string;
								}
							}
						}
						else {
							
							if (ROW.COD == ROW.COD2) {
								
								if (parseInt(ROW.COD2) <= parseInt(mois_toperiode)) {
									return annee_toperiode + ROW.COD2;
								}
								else {
									return (parseInt(annee_toperiode) - 1).toString() + ROW.COD2;
								}
							}
							else {
								return SELECT.PERIODE;
							}
						}
					} 
					else {

							mois_debut = 1 + 3 * (parseInt(ROW.COD2.substr(-1)) - 1);
							mois_debut_string = mois_debut < 10 ? '0' + mois_debut.toString() : mois_debut.toString();
							annee = ROW.COD2.substr(0,4);
						
						if (SELECT.GROUPBY == 'ANNEEA') {
							
							if (ROW.COD == ROW.COD3) {
								return ROW.COD1 + ROW.COD2 + ROW.COD3;
							}
							else {
								
								if (ROW.COD1 == annee_periode) {
									return SELECT.PERIODE;
								}
								else {
									return ROW.COD1 + '01';
								}
							}
						}
						else if (SELECT.GROUPBY == 'TRIMA') {
						
							if (ROW.COD == ROW.COD2) {
								return annee + ROW.COD2;
							}
							else {
								if (annee == annee_periode && mois_debut <= parseInt(mois_periode)) {
									return SELECT.PERIODE;
								}
								else {
									return annee + mois_debut_string;
								}
							}
						}
						else if (SELECT.GROUPBY == 'NUMEROTRIMA') {
							
							if (ROW.COD ==  ROW.COD2) {
								
								if (parseInt(ROW.COD2) <= parseInt(mois_toperiode)) {
									return annee_toperiode + ROW.COD2
								}
								else {
									return (parseInt(annee_toperiode) - 1).toString() + ROW.COD2;
								}
							}
							else {
								
								if (mois_debut <= parseInt(mois_toperiode)) {
									return annee_toperiode + mois_debut_string;
								}
								else {
									return (parseInt(annee_toperiode) - 1).toString() + mois_debut_string;
								}
							}
						}
						else {
							
							if (ROW.COD == ROW.COD3) {
								
								if (parseInt(ROW.COD3) <= parseInt(mois_toperiode)) {
									return annee_toperiode + ROW.COD3;
								}
								else {
									return (parseInt(annee_toperiode) - 1).toString() + ROW.COD3;
								}
							}
							else {
								return SELECT.PERIODE;
							}
						}
					}
				}
				else if (SELECT.GROUPBY == 'TRIMA' || SELECT.GROUPBY_2 == 'TRIMA' || SELECT.GROUPBY_3 == 'TRIMA') {
					
					if (SELECT.GROUPBY == 'TRIMA') {
					
							annee = ROW.COD1.substr(0,4);
							mois_debut = 1 + 3 * (parseInt(ROW.COD1.substr(-1)) - 1);
							mois_debut_string = mois_debut < 10 ? '0' + mois_debut.toString() : mois_debut.toString();
						
						if (annee == annee_periode && mois_debut <= parseInt(mois_periode)) {
							return SELECT.PERIODE;
						}
						else {
							return annee + mois_debut_string;
						}
					}
					else if (SELECT.GROUPBY_2 == 'TRIMA'){
					
							annee = ROW.COD2.substr(0,4);
							mois_debut = 1 + 3 * (parseInt(ROW.COD2.substr(-1)) - 1);
							mois_debut_string = mois_debut < 10 ? '0' + mois_debut.toString() : mois_debut.toString();
						
						if (ROW.COD == ROW.COD2) {
							
							if (annee == annee_periode && mois_debut <= parseInt(mois_periode)) {
								return SELECT.PERIODE;
							}
							else {
								return annee + mois_debut_string;
							}
						}
						else {
							
							if (SELECT.GROUPBY == 'ANNEEA' && ROW.COD1 != annee_periode) {
								return ROW.COD1 + '01';
							}
							else {
								return SELECT.PERIODE;
							}
						}
					} else {
							annee = ROW.COD3.substr(0,4);
							mois_debut = 1 + 3 * (parseInt(ROW.COD3.substr(-1)) - 1);
							mois_debut_string = mois_debut < 10 ? '0' + mois_debut.toString() : mois_debut.toString();
						
						if (ROW.COD == ROW.COD3) {
							
							if (annee == annee_periode && mois_debut <= parseInt(mois_periode)) {
								return SELECT.PERIODE;
							}
							else {
								return annee + mois_debut_string;
							}
						}
						else {
							
							if (SELECT.GROUPBY == 'ANNEEA' && ROW.COD1 != annee_periode) {
								return ROW.COD1 + '01';
							}
							else {
								return SELECT.PERIODE;
							}
						}
					
					} 
				}
				else if (SELECT.GROUPBY == 'NUMEROTRIMA' || SELECT.GROUPBY_2 == 'NUMEROTRIMA' || SELECT.GROUPBY_3 == 'NUMEROTRIMA') {
					
						mois_debut = 1 + 3 * (parseInt(ROW.COD2.substr(-1)) - 1);
						mois_debut_string = mois_debut < 10 ? '0' + mois_debut.toString() : mois_debut.toString();
					
					if (SELECT.GROUPBY == 'NUMEROTRIMA') {
					
						mois_debut = 1 + 3 * (parseInt(ROW.COD1.substr(-1)) - 1);
						mois_debut_string = mois_debut < 10 ? '0' + mois_debut.toString() : mois_debut.toString();
						
						if (mois_debut <= parseInt(mois_toperiode)) {
							return annee_toperiode + mois_debut_string;
						}
						else {
							return (parseInt(annee_toperiode) -1).toString() + mois_debut_string;
						}
					}
					else if (SELECT.GROUPBY == 'ANNEEA') {

						if (ROW.COD == ROW.COD2) {
							
							if (ROW.COD1 == annee_periode && mois_debut <= parseInt(mois_periode)) {
								return SELECT.PERIODE;
							}
							else {
								return ROW.COD1 + mois_debut_string;
							}
						}
						else {
							
							if (ROW.COD1 == annee_periode) {
								return SELECT.PERIODE;
							}
							else {
								return ROW.COD1 + '01';
							}
						}
					}
					else  if(SELECT.GROUPBY_2 == 'NUMEROTRIMA') {
						
						if (ROW.COD == ROW.COD2) {
							
							if (mois_debut <= parseInt(mois_toperiode)) {
								return annee_toperiode + mois_debut_string;
							}
							else {
								return (parseInt(annee_toperiode) - 1).toString() + mois_debut_string;
							}
						}
						else {
							return SELECT.PERIODE;
						}
					}	
					else {
								mois_debut = 1 + 3 * (parseInt(ROW.COD3.substr(-1)) - 1);
								mois_debut_string = mois_debut < 10 ? '0' + mois_debut.toString() : mois_debut.toString();
						if (ROW.COD == ROW.COD3) {
								
							if (mois_debut <= parseInt(mois_toperiode)) {
									return annee_toperiode + mois_debut_string;
							}
							else {
									return (parseInt(annee_toperiode) - 1).toString() + mois_debut_string;
								}
						}
						else {
								return SELECT.PERIODE;
						}
					
					}
				}
				else if (SELECT.GROUPBY == 'ANNEEA'|| SELECT.GROUPBY_2 == 'ANNEEA' || SELECT.GROUPBY_3 == 'ANNEEA') {
				
					if(SELECT.GROUPBY == 'ANNEEA'|| SELECT.GROUPBY_2 == 'ANNEEA') {
					
						var row_cod:String = (SELECT.GROUPBY == 'ANNEEA') ? ROW.COD1 : ROW.COD2;
					}else {
						var row_cod:String = ROW.COD3;
					}
	
					if (row_cod == annee_periode) {
						return SELECT.PERIODE;
					}
					else {
						return row_cod + '01';
					}
				}
			// FIN TRAITEMENT DATE D'ACTIVITE
			// DATE DE VENTE
				if (SELECT.GROUPBY == 'SEMAINEANNEV' || SELECT.GROUPBY_2 == 'SEMAINEANNEV' || SELECT.GROUPBY_3 == 'SEMAINEANNEV' ) {

					if(SELECT.GROUPBY == 'SEMAINEANNEV' || SELECT.GROUPBY_2 == 'SEMAINEANNEV'){
										row_cod = (SELECT.GROUPBY == 'SEMAINEANNEV') ? ROW.COD1 : ROW.COD2;
						}
						else {
										row_cod = ROW.COD3;
						}
						if (SELECT.GROUPBY == 'ANNEEV' || SELECT.GROUPBY_2 == 'ANNEEV' ) {
								var annee:String =  (SELECT.GROUPBY == 'SEMAINEANNEV') ?  ROW.COD2.substr(0,4) : ROW.COD1.substr(0,4);
								return getDateFromWeek(annee+row_cod,0);
						}
						else{
							var date:String = getDateFromWeek(annee_toperiode + row_cod,6);
							var month:int = parseInt(date.substr(5,2));
							var day:int = parseInt(date.substr(8,2));
							var toDay:int = parseInt(SELECT.TOPERIODE.substr(8,2));					
							
							if (month <= parseInt(mois_toperiode) && day <= toDay) {
									
									return getDateFromWeek(annee_toperiode+row_cod,0);
							}
							else {
									return getDateFromWeek((parseInt(annee_toperiode) - 1).toString()+row_cod,0);
							}
						}
				}
				
				if (SELECT.GROUPBY == 'JOURSV' || SELECT.GROUPBY_2 == 'JOURSV' || SELECT.GROUPBY_3 == 'JOURSV' ) {
					
					if (SELECT.GROUPBY == 'JOURSV') {
						
						return annee_periode+'-'+ROW.COD1;
					}
					else if (ROW.COD == ROW.COD2) {
					
							return annee_periode+'-'+ROW.COD2;
							
					} 
					else if(ROW.COD == ROW.COD3) {
						
						return annee_periode+'-'+ROW.COD3;
							
					}
				}
				if (SELECT.GROUPBY == 'JOURV' || SELECT.GROUPBY_2 == 'JOURV' || SELECT.GROUPBY_3 == 'JOURV') {
					
					if (SELECT.GROUPBY == 'JOURV') {
						return ROW.COD1;
					}
					else if (ROW.COD == ROW.COD2) {
					
							return ROW.COD2;
							
						}
						else if(ROW.COD == ROW.COD3) {
						
							return ROW.COD3;
						}
				}
				if (SELECT.GROUPBY == 'MOISV' || SELECT.GROUPBY_2 == 'MOISV' || SELECT.GROUPBY_3 == 'MOISV' ) {
					
					var mois:String = '';
					
					if (SELECT.GROUPBY == 'MOISV') {
						
						annee = ROW.COD1.substr(0,4);
						mois = ROW.COD1.substr(-2);
						
						if (annee == annee_periode && mois == mois_periode) {
							return SELECT.PERIODE;
						}
						else {
							return annee + mois;
						}
					}
					else if (SELECT.GROUPBY_2 == 'MOISV') {
						
						annee = ROW.COD2.substr(0,4);
						mois = ROW.COD2.substr(-2);
						
						if (ROW.COD == ROW.COD2) {
							
							if (annee == annee_periode && mois == mois_periode) {
								return SELECT.PERIODE;
							}
							else {
								return annee + mois;
							}
						}
						else {
							
							if (SELECT.GROUPBY == 'ANNEEV' && ROW.COD1 != annee_periode) {
								return ROW.COD1 + '01';
							}
							else {
								return SELECT.PERIODE;
							}
						}
					} 
					else {
							annee = ROW.COD3.substr(0,4);
							mois = ROW.COD3.substr(-2);
						
						if (ROW.COD == ROW.COD3) {
							
							if (annee == annee_periode && mois == mois_periode) {
								return SELECT.PERIODE;
							}
							else {
								return annee + mois;
							}
						}
						else {
							
							if (SELECT.GROUPBY == 'ANNEEV' && ROW.COD1 != annee_periode) {
								return ROW.COD1 + '01';
							}
							else {
								return SELECT.PERIODE;
							}
						}
					
					}
				}
				else if (SELECT.GROUPBY == 'NUMEROMOISV' || SELECT.GROUPBY_2 == 'NUMEROMOISV' || SELECT.GROUPBY_3 == 'NUMEROMOISV') {
					
					if (SELECT.GROUPBY == 'NUMEROMOISV') {
						
						if (parseInt(ROW.COD1) <= parseInt(mois_toperiode)) {
							return annee_toperiode + ROW.COD1;
						}
						else {
							return (parseInt(annee_toperiode) - 1).toString() + ROW.COD1;
						}
					}
					else if (SELECT.GROUPBY_2 == 'NUMEROMOISV') {
						
						mois_debut = 1 + 3 * (parseInt(ROW.COD1.substr(-1)) - 1);
						mois_debut_string = mois_debut < 10 ? '0' + mois_debut.toString() : mois_debut.toString();
						annee = ROW.COD1.substr(0,4);
						
						if (SELECT.GROUPBY == 'ANNEEV') {
							
							if (ROW.COD == ROW.COD2) {
								return ROW.COD1 + ROW.COD2;
							}
							else {
								
								if (ROW.COD1 == annee_periode) {
									return SELECT.PERIODE;
								}
								else {
									return ROW.COD1 + '01';
								}
							}
						}
						else if (SELECT.GROUPBY == 'TRIMV') {
						
							if (ROW.COD == ROW.COD2) {
								return annee + ROW.COD2;
							}
							else {
								if (annee == annee_periode && mois_debut <= parseInt(mois_periode)) {
									return SELECT.PERIODE;
								}
								else {
									return annee + mois_debut_string;
								}
							}
						}
						else if (SELECT.GROUPBY == 'NUMEROTRIMV') {
							
							if (ROW.COD ==  ROW.COD2) {
								
								if (parseInt(ROW.COD2) <= parseInt(mois_toperiode)) {
									return annee_toperiode + ROW.COD2
								}
								else {
									return (parseInt(annee_toperiode) - 1).toString() + ROW.COD2;
								}
							}
							else {
								
								if (mois_debut <= parseInt(mois_toperiode)) {
									return annee_toperiode + mois_debut_string;
								}
								else {
									return (parseInt(annee_toperiode) - 1).toString() + mois_debut_string;
								}
							}
						}
						else {
							
							if (ROW.COD == ROW.COD2) {
								
								if (parseInt(ROW.COD2) <= parseInt(mois_toperiode)) {
									return annee_toperiode + ROW.COD2;
								}
								else {
									return (parseInt(annee_toperiode) - 1).toString() + ROW.COD2;
								}
							}
							else {
								return SELECT.PERIODE;
							}
						}
					} else {
						mois_debut = 1 + 3 * (parseInt(ROW.COD2.substr(-1)) - 1);
						mois_debut_string = mois_debut < 10 ? '0' + mois_debut.toString() : mois_debut.toString();
						annee = ROW.COD2.substr(0,4);
						
						if (SELECT.GROUPBY == 'ANNEEV') {
							
							if (ROW.COD == ROW.COD3) {
								return ROW.COD1 + ROW.COD2 + ROW.COD3;
							}
							else {
								
								if (ROW.COD1 == annee_periode) {
									return SELECT.PERIODE;
								}
								else {
									return ROW.COD1 + '01';
								}
							}
						}
						else if (SELECT.GROUPBY == 'TRIMV') {
						
							if (ROW.COD == ROW.COD2) {
								return annee + ROW.COD2;
							}
							else {
								if (annee == annee_periode && mois_debut <= parseInt(mois_periode)) {
									return SELECT.PERIODE;
								}
								else {
									return annee + mois_debut_string;
								}
							}
						}
						else if (SELECT.GROUPBY == 'NUMEROTRIMV') {
							
							if (ROW.COD ==  ROW.COD2) {
								
								if (parseInt(ROW.COD2) <= parseInt(mois_toperiode)) {
									return annee_toperiode + ROW.COD2
								}
								else {
									return (parseInt(annee_toperiode) - 1).toString() + ROW.COD2;
								}
							}
							else {
								
								if (mois_debut <= parseInt(mois_toperiode)) {
									return annee_toperiode + mois_debut_string;
								}
								else {
									return (parseInt(annee_toperiode) - 1).toString() + mois_debut_string;
								}
							}
						}
						else {
							
							if (ROW.COD == ROW.COD3) {
								
								if (parseInt(ROW.COD3) <= parseInt(mois_toperiode)) {
									return annee_toperiode + ROW.COD3;
								}
								else {
									return (parseInt(annee_toperiode) - 1).toString() + ROW.COD3;
								}
							}
							else {
								return SELECT.PERIODE;
							}
						}
					}
				}
				else if (SELECT.GROUPBY == 'TRIMV' || SELECT.GROUPBY_2 == 'TRIMV' || SELECT.GROUPBY_3 == 'TRIMV') {
					
					if (SELECT.GROUPBY == 'TRIMV') {
					
						annee = ROW.COD1.substr(0,4);
						mois_debut = 1 + 3 * (parseInt(ROW.COD1.substr(-1)) - 1);
						mois_debut_string = mois_debut < 10 ? '0' + mois_debut.toString() : mois_debut.toString();
						
						if (annee == annee_periode && mois_debut <= parseInt(mois_periode)) {
							return SELECT.PERIODE;
						}
						else {
							return annee + mois_debut_string;
						}
					}
					else if (SELECT.GROUPBY_2 == 'TRIMV'){
					
						annee = ROW.COD2.substr(0,4);
						mois_debut = 1 + 3 * (parseInt(ROW.COD2.substr(-1)) - 1);
						mois_debut_string = mois_debut < 10 ? '0' + mois_debut.toString() : mois_debut.toString();
						
						if (ROW.COD == ROW.COD2) {
							
							if (annee == annee_periode && mois_debut <= parseInt(mois_periode)) {
								return SELECT.PERIODE;
							}
							else {
								return annee + mois_debut_string;
							}
						}
						else {
							
							if (SELECT.GROUPBY == 'ANNEEV' && ROW.COD1 != annee_periode) {
								return ROW.COD1 + '01';
							}
							else {
								return SELECT.PERIODE;
							}
						}
					} else {
						annee = ROW.COD3.substr(0,4);
						mois_debut = 1 + 3 * (parseInt(ROW.COD3.substr(-1)) - 1);
						mois_debut_string = mois_debut < 10 ? '0' + mois_debut.toString() : mois_debut.toString();
						
						if (ROW.COD == ROW.COD3) {
							
							if (annee == annee_periode && mois_debut <= parseInt(mois_periode)) {
								return SELECT.PERIODE;
							}
							else {
								return annee + mois_debut_string;
							}
						}
						else {
							
							if (SELECT.GROUPBY == 'ANNEEV' && ROW.COD1 != annee_periode) {
								return ROW.COD1 + '01';
							}
							else {
								return SELECT.PERIODE;
							}
						}
					
					} 
				}
				else if (SELECT.GROUPBY == 'NUMEROTRIMV' || SELECT.GROUPBY_2 == 'NUMEROTRIMV' || SELECT.GROUPBY_3 == 'NUMEROTRIMV') {
					
					mois_debut = 1 + 3 * (parseInt(ROW.COD2.substr(-1)) - 1);
					mois_debut_string = mois_debut < 10 ? '0' + mois_debut.toString() : mois_debut.toString();
					
					if (SELECT.GROUPBY == 'NUMEROTRIMV') {
					
						mois_debut = 1 + 3 * (parseInt(ROW.COD1.substr(-1)) - 1);
						mois_debut_string = mois_debut < 10 ? '0' + mois_debut.toString() : mois_debut.toString();
						
						if (mois_debut <= parseInt(mois_toperiode)) {
							return annee_toperiode + mois_debut_string;
						}
						else {
							return (parseInt(annee_toperiode) -1).toString() + mois_debut_string;
						}
					}
					else if (SELECT.GROUPBY == 'ANNEEV') {

						if (ROW.COD == ROW.COD2) {
							
							if (ROW.COD1 == annee_periode && mois_debut <= parseInt(mois_periode)) {
								return SELECT.PERIODE;
							}
							else {
								return ROW.COD1 + mois_debut_string;
							}
						}
						else {
							
							if (ROW.COD1 == annee_periode) {
								return SELECT.PERIODE;
							}
							else {
								return ROW.COD1 + '01';
							}
						}
					}
					else  if(SELECT.GROUPBY_2 == 'NUMEROTRIMV') {
						
						if (ROW.COD == ROW.COD2) {
							
							if (mois_debut <= parseInt(mois_toperiode)) {
								return annee_toperiode + mois_debut_string;
							}
							else {
								return (parseInt(annee_toperiode) - 1).toString() + mois_debut_string;
							}
						}
						else {
							return SELECT.PERIODE;
						}
					} else {
							mois_debut = 1 + 3 * (parseInt(ROW.COD3.substr(-1)) - 1);
							mois_debut_string = mois_debut < 10 ? '0' + mois_debut.toString() : mois_debut.toString();
							if (ROW.COD == ROW.COD3) {
								
								if (mois_debut <= parseInt(mois_toperiode)) {
									return annee_toperiode + mois_debut_string;
								}
								else {
									return (parseInt(annee_toperiode) - 1).toString() + mois_debut_string;
								}
							}
							else {
								return SELECT.PERIODE;
							}
					
					}
				}
				else if (SELECT.GROUPBY == 'ANNEEV'|| SELECT.GROUPBY_2 == 'ANNEEV' || SELECT.GROUPBY_3 == 'ANNEEV') {
				
					if(SELECT.GROUPBY == 'ANNEEV'|| SELECT.GROUPBY_2 == 'ANNEEV') {
					
						var row_cod:String = (SELECT.GROUPBY == 'ANNEEV') ? ROW.COD1 : ROW.COD2;
					}else {
						var row_cod:String = ROW.COD3;
					}
	
					if (row_cod == annee_periode) {
						return SELECT.PERIODE;
					}
					else {
						return row_cod + '01';
					}
				}			
				// FIN DATE DE VENTE
				//DATE FACTURE 
				if (SELECT.GROUPBY == 'SEMAINEANNEF' || SELECT.GROUPBY_2 == 'SEMAINEANNEF' || SELECT.GROUPBY_3 == 'SEMAINEANNEF' ) {
						if(SELECT.GROUPBY == 'SEMAINEANNEF' || SELECT.GROUPBY_2 == 'SEMAINEANNEF'){
							row_cod = (SELECT.GROUPBY == 'SEMAINEANNEF') ? ROW.COD1 : ROW.COD2;
						}else {
							row_cod = ROW.COD3;
						}
					if (SELECT.GROUPBY == 'ANNEEF' || SELECT.GROUPBY_2 == 'ANNEEF' ) {
						var ANNEEF:String =  (SELECT.GROUPBY == 'SEMAINEANNEF') ?  ROW.COD2.substr(0,4) : ROW.COD1.substr(0,4);
						return getDateFromWeek(ANNEEF+row_cod,0);
					}
					else{
						var date:String = getDateFromWeek(annee_toperiode + row_cod,6);
						var month:int = parseInt(date.substr(5,2));
						var day:int = parseInt(date.substr(8,2));
						var toDay:int = parseInt(SELECT.TOPERIODE.substr(8,2));					
						if (month <= parseInt(mois_toperiode) && day <= toDay) {
							return getDateFromWeek(annee_toperiode+row_cod,0);
						}
						else {
								return getDateFromWeek((parseInt(annee_toperiode)).toString()+row_cod,0);
						}
					}
				}
				
				if (SELECT.GROUPBY == 'JOURSF' || SELECT.GROUPBY_2 == 'JOURSF' || SELECT.GROUPBY_3 == 'JOURSF' ) {
					
					if (SELECT.GROUPBY == 'JOURSF') {
						
						return annee_periode+'-'+ROW.COD1;
					}
					else if (ROW.COD == ROW.COD2) {
					
						return annee_periode+'-'+ROW.COD2;
						
						} else if(ROW.COD == ROW.COD3) {
								return annee_periode+'-'+ROW.COD3;
								}
				}
				if (SELECT.GROUPBY == 'JOURF' || SELECT.GROUPBY_2 == 'JOURF' || SELECT.GROUPBY_3 == 'JOURF') {
					
					if (SELECT.GROUPBY == 'JOURF') {
						return ROW.COD1;
					}
					else if (ROW.COD == ROW.COD2) {
						return ROW.COD2;
					}else if(ROW.COD == ROW.COD3) {
						return ROW.COD3;
					}
				}
				if (SELECT.GROUPBY == 'MOISF' || SELECT.GROUPBY_2 == 'MOISF' || SELECT.GROUPBY_3 == 'MOISF' ) {
					
					var MOISF:String = '';
					
					if (SELECT.GROUPBY == 'MOISF') {
						
						ANNEEF = ROW.COD1.substr(0,4);
						MOISF = ROW.COD1.substr(-2);
						
						if (ANNEEF == annee_periode && MOISF == mois_periode) {
							return SELECT.PERIODE;
						}
						else {
							return ANNEEF + MOISF;
						}
					}
					else if (SELECT.GROUPBY_2 == 'MOISF') {
						
						ANNEEF = ROW.COD2.substr(0,4);
						MOISF = ROW.COD2.substr(-2);
						
						if (ROW.COD == ROW.COD2) {
							
							if (ANNEEF == annee_periode && MOISF == mois_periode) {
								return SELECT.PERIODE;
							}
							else {
								return ANNEEF + MOISF;
							}
						}
						else {
							
							if (SELECT.GROUPBY == 'ANNEEF' && ROW.COD1 != annee_periode) {
								return ROW.COD1 + '01';
							}
							else {
								return SELECT.PERIODE;
							}
						}
					} else {
							ANNEEF = ROW.COD3.substr(0,4);
							MOISF = ROW.COD3.substr(-2);
						
						if (ROW.COD == ROW.COD3) {
							
							if (ANNEEF == annee_periode && MOISF == mois_periode) {
								return SELECT.PERIODE;
							}
							else {
								return ANNEEF + MOISF;
							}
						}
						else {
							
							if (SELECT.GROUPBY == 'ANNEEF' && ROW.COD1 != annee_periode) {
								return ROW.COD1 + '01';
							}
							else {
								return SELECT.PERIODE;
							}
						}
					
					}
				}
				else if (SELECT.GROUPBY == 'NUMEROMOISF' || SELECT.GROUPBY_2 == 'NUMEROMOISF' || SELECT.GROUPBY_3 == 'NUMEROMOISF') {
					
					if (SELECT.GROUPBY == 'NUMEROMOISF') {
						
						if (parseInt(ROW.COD1) <= parseInt(mois_toperiode)) {
							return annee_toperiode + ROW.COD1;
						}
						else {
							return (parseInt(annee_toperiode) - 1).toString() + ROW.COD1;
						}
					}
					else if (SELECT.GROUPBY_2 == 'NUMEROMOISF') {
						
						mois_debut = 1 + 3 * (parseInt(ROW.COD1.substr(-1)) - 1);
						mois_debut_string = mois_debut < 10 ? '0' + mois_debut.toString() : mois_debut.toString();
						ANNEEF = ROW.COD1.substr(0,4);
						
						if (SELECT.GROUPBY == 'ANNEEF') {
							
							if (ROW.COD == ROW.COD2) {
								return ROW.COD1 + ROW.COD2;
							}
							else {
								
								if (ROW.COD1 == annee_periode) {
									return SELECT.PERIODE;
								}
								else {
									return ROW.COD1 + '01';
								}
							}
						}
						else if (SELECT.GROUPBY == 'TRIMF') {
						
							if (ROW.COD == ROW.COD2) {
								return ANNEEF + ROW.COD2;
							}
							else {
								if (ANNEEF == annee_periode && mois_debut <= parseInt(mois_periode)) {
									return SELECT.PERIODE;
								}
								else {
									return ANNEEF + mois_debut_string;
								}
							}
						}
						else if (SELECT.GROUPBY == 'NUMEROTRIMF') {
							
							if (ROW.COD ==  ROW.COD2) {
								
								if (parseInt(ROW.COD2) <= parseInt(mois_toperiode)) {
									return annee_toperiode + ROW.COD2
								}
								else {
									return (parseInt(annee_toperiode) - 1).toString() + ROW.COD2;
								}
							}
							else {
								
								if (mois_debut <= parseInt(mois_toperiode)) {
									return annee_toperiode + mois_debut_string;
								}
								else {
									return (parseInt(annee_toperiode) - 1).toString() + mois_debut_string;
								}
							}
						}
						else {
							
							if (ROW.COD == ROW.COD2) {
								
								if (parseInt(ROW.COD2) <= parseInt(mois_toperiode)) {
									return annee_toperiode + ROW.COD2;
								}
								else {
									return (parseInt(annee_toperiode) - 1).toString() + ROW.COD2;
								}
							}
							else {
								return SELECT.PERIODE;
							}
						}
					} else {
						mois_debut = 1 + 3 * (parseInt(ROW.COD2.substr(-1)) - 1);
						mois_debut_string = mois_debut < 10 ? '0' + mois_debut.toString() : mois_debut.toString();
						ANNEEF = ROW.COD2.substr(0,4);
						
						if (SELECT.GROUPBY == 'ANNEEF') {
							
							if (ROW.COD == ROW.COD3) {
								return ROW.COD1 + ROW.COD2 + ROW.COD3;
							}
							else {
								
								if (ROW.COD1 == annee_periode) {
									return SELECT.PERIODE;
								}
								else {
									return ROW.COD1 + '01';
								}
							}
						}
						else if (SELECT.GROUPBY == 'TRIMF') {
						
							if (ROW.COD == ROW.COD2) {
								return ANNEEF + ROW.COD2;
							}
							else {
								if (ANNEEF == annee_periode && mois_debut <= parseInt(mois_periode)) {
									return SELECT.PERIODE;
								}
								else {
									return ANNEEF + mois_debut_string;
								}
							}
						}
						else if (SELECT.GROUPBY == 'NUMEROTRIMF') {
							
							if (ROW.COD ==  ROW.COD2) {
								
								if (parseInt(ROW.COD2) <= parseInt(mois_toperiode)) {
									return annee_toperiode + ROW.COD2
								}
								else {
									return (parseInt(annee_toperiode) - 1).toString() + ROW.COD2;
								}
							}
							else {
								
								if (mois_debut <= parseInt(mois_toperiode)) {
									return annee_toperiode + mois_debut_string;
								}
								else {
									return (parseInt(annee_toperiode) - 1).toString() + mois_debut_string;
								}
							}
						}
						else {
							
							if (ROW.COD == ROW.COD3) {
								
								if (parseInt(ROW.COD3) <= parseInt(mois_toperiode)) {
									return annee_toperiode + ROW.COD3;
								}
								else {
									return (parseInt(annee_toperiode) - 1).toString() + ROW.COD3;
								}
							}
							else {
								return SELECT.PERIODE;
							}
						}
					}
				}
				else if (SELECT.GROUPBY == 'TRIMF' || SELECT.GROUPBY_2 == 'TRIMF' || SELECT.GROUPBY_3 == 'TRIMF') {
					
					if (SELECT.GROUPBY == 'TRIMF') {
					
						ANNEEF = ROW.COD1.substr(0,4);
						mois_debut = 1 + 3 * (parseInt(ROW.COD1.substr(-1)) - 1);
						mois_debut_string = mois_debut < 10 ? '0' + mois_debut.toString() : mois_debut.toString();
						
						if (ANNEEF == annee_periode && mois_debut <= parseInt(mois_periode)) {
							return SELECT.PERIODE;
						}
						else {
							return ANNEEF + mois_debut_string;
						}
					}
					else if (SELECT.GROUPBY_2 == 'TRIMF'){
					
						ANNEEF = ROW.COD2.substr(0,4);
						mois_debut = 1 + 3 * (parseInt(ROW.COD2.substr(-1)) - 1);
						mois_debut_string = mois_debut < 10 ? '0' + mois_debut.toString() : mois_debut.toString();
						
						if (ROW.COD == ROW.COD2) {
							
							if (ANNEEF == annee_periode && mois_debut <= parseInt(mois_periode)) {
								return SELECT.PERIODE;
							}
							else {
								return ANNEEF + mois_debut_string;
							}
						}
						else {
							
							if (SELECT.GROUPBY == 'ANNEEF' && ROW.COD1 != annee_periode) {
								return ROW.COD1 + '01';
							}
							else {
								return SELECT.PERIODE;
							}
						}
					} else {
						ANNEEF = ROW.COD3.substr(0,4);
						mois_debut = 1 + 3 * (parseInt(ROW.COD3.substr(-1)) - 1);
						mois_debut_string = mois_debut < 10 ? '0' + mois_debut.toString() : mois_debut.toString();
						
						if (ROW.COD == ROW.COD3) {
							
							if (ANNEEF == annee_periode && mois_debut <= parseInt(mois_periode)) {
								return SELECT.PERIODE;
							}
							else {
								return ANNEEF + mois_debut_string;
							}
						}
						else {
							
							if (SELECT.GROUPBY == 'ANNEEF' && ROW.COD1 != annee_periode) {
								return ROW.COD1 + '01';
							}
							else {
								return SELECT.PERIODE;
							}
						}
					
					} 
				}
				else if (SELECT.GROUPBY == 'NUMEROTRIMF' || SELECT.GROUPBY_2 == 'NUMEROTRIMF' || SELECT.GROUPBY_3 == 'NUMEROTRIMF') {
					
					mois_debut = 1 + 3 * (parseInt(ROW.COD2.substr(-1)) - 1);
					mois_debut_string = mois_debut < 10 ? '0' + mois_debut.toString() : mois_debut.toString();
					
					if (SELECT.GROUPBY == 'NUMEROTRIMF') {
					
						mois_debut = 1 + 3 * (parseInt(ROW.COD1.substr(-1)) - 1);
						mois_debut_string = mois_debut < 10 ? '0' + mois_debut.toString() : mois_debut.toString();
						
						if (mois_debut <= parseInt(mois_toperiode)) {
							return annee_toperiode + mois_debut_string;
						}
						else {
							return (parseInt(annee_toperiode) -1).toString() + mois_debut_string;
						}
					}
					else if (SELECT.GROUPBY == 'ANNEEF') {

						if (ROW.COD == ROW.COD2) {
							
							if (ROW.COD1 == annee_periode && mois_debut <= parseInt(mois_periode)) {
								return SELECT.PERIODE;
							}
							else {
								return ROW.COD1 + mois_debut_string;
							}
						}
						else {
							
							if (ROW.COD1 == annee_periode) {
								return SELECT.PERIODE;
							}
							else {
								return ROW.COD1 + '01';
							}
						}
					}
					else  if(SELECT.GROUPBY_2 == 'NUMEROTRIMF') {
						
						if (ROW.COD == ROW.COD2) {
							
							if (mois_debut <= parseInt(mois_toperiode)) {
								return annee_toperiode + mois_debut_string;
							}
							else {
								return (parseInt(annee_toperiode) - 1).toString() + mois_debut_string;
							}
						}
						else {
							return SELECT.PERIODE;
						}
					} else {
							mois_debut = 1 + 3 * (parseInt(ROW.COD3.substr(-1)) - 1);
							mois_debut_string = mois_debut < 10 ? '0' + mois_debut.toString() : mois_debut.toString();
							if (ROW.COD == ROW.COD3) {
								
								if (mois_debut <= parseInt(mois_toperiode)) {
									return annee_toperiode + mois_debut_string;
								}
								else {
									return (parseInt(annee_toperiode) - 1).toString() + mois_debut_string;
								}
							}
							else {
								return SELECT.PERIODE;
							}
					
					}
				}
				else if (SELECT.GROUPBY == 'ANNEEF'|| SELECT.GROUPBY_2 == 'ANNEEF' || SELECT.GROUPBY_3 == 'ANNEEF') {
				
					if(SELECT.GROUPBY == 'ANNEEF'|| SELECT.GROUPBY_2 == 'ANNEEF') {
					
						var row_cod:String = (SELECT.GROUPBY == 'ANNEEF') ? ROW.COD1 : ROW.COD2;
					}else {
						var row_cod:String = ROW.COD3;
					}
	
					if (row_cod == annee_periode) {
						return SELECT.PERIODE;
					}
					else {
						return row_cod + '01';
					}
				}
				// FIN TRAITEMENT DATE FACTURE	
				// TRAITEMANT DATE D'EXPEDITION
					if (SELECT.GROUPBY == 'SEMAINEANNEEX' || SELECT.GROUPBY_2 == 'SEMAINEANNEEX' || SELECT.GROUPBY_3 == 'SEMAINEANNEEX' ) {
						if(SELECT.GROUPBY == 'SEMAINEANNEEX' || SELECT.GROUPBY_2 == 'SEMAINEANNEEX'){
							row_cod = (SELECT.GROUPBY == 'SEMAINEANNEEX') ? ROW.COD1 : ROW.COD2;
						}else {
							row_cod = ROW.COD3;
						}
					if (SELECT.GROUPBY == 'ANNEEEX' || SELECT.GROUPBY_2 == 'ANNEEEX' ) {
						var ANNEEEX:String =  (SELECT.GROUPBY == 'SEMAINEANNEEX') ?  ROW.COD2.substr(0,4) : ROW.COD1.substr(0,4);
						return getDateFromWeek(ANNEEEX+row_cod,0);
					}
					else{
						var date:String = getDateFromWeek(annee_toperiode + row_cod,6);
						var month:int = parseInt(date.substr(5,2));
						var day:int = parseInt(date.substr(8,2));
						var toDay:int = parseInt(SELECT.TOPERIODE.substr(8,2));					
						if (month <= parseInt(mois_toperiode) && day <= toDay) {
							return getDateFromWeek(annee_toperiode+row_cod,0);
						}
						else {
								return getDateFromWeek((parseInt(annee_toperiode)).toString()+row_cod,0);
						}
					}
				}
				
				if (SELECT.GROUPBY == 'JOURSEX' || SELECT.GROUPBY_2 == 'JOURSEX' || SELECT.GROUPBY_3 == 'JOURSEX' ) {
					
					if (SELECT.GROUPBY == 'JOURSEX') {
						
						return annee_periode+'-'+ROW.COD1;
					}
					else if (ROW.COD == ROW.COD2) {
						return annee_periode+'-'+ROW.COD2;
					} else if(ROW.COD == ROW.COD3) {
						return annee_periode+'-'+ROW.COD3;
					}
				}
				if (SELECT.GROUPBY == 'JOUREX' || SELECT.GROUPBY_2 == 'JOUREX' || SELECT.GROUPBY_3 == 'JOUREX') {
					
					if (SELECT.GROUPBY == 'JOUREX') {
						return ROW.COD1;
					}
					else if (ROW.COD == ROW.COD2) {
						return ROW.COD2;
					}else if(ROW.COD == ROW.COD3) {
						return ROW.COD3;
					}
				}
				if (SELECT.GROUPBY == 'MOISEX' || SELECT.GROUPBY_2 == 'MOISEX' || SELECT.GROUPBY_3 == 'MOISEX' ) {
					
					var MOISEX:String = '';
					
					if (SELECT.GROUPBY == 'MOISEX') {
						
							ANNEEEX = ROW.COD1.substr(0,4);
							MOISEX = ROW.COD1.substr(-2);
						
						if (ANNEEEX == annee_periode && MOISEX == mois_periode) {
							return SELECT.PERIODE;
						}
						else {
							return ANNEEEX + MOISEX;
						}
					}
					else if (SELECT.GROUPBY_2 == 'MOISEX') {
						
							ANNEEEX = ROW.COD2.substr(0,4);
							MOISEX = ROW.COD2.substr(-2);
						
						if (ROW.COD == ROW.COD2) {
							
							if (ANNEEEX == annee_periode && MOISEX == mois_periode) {
								return SELECT.PERIODE;
							}
							else {
								return ANNEEEX + MOISEX;
							}
						}
						else {
							
								if (SELECT.GROUPBY == 'ANNEEEX' && ROW.COD1 != annee_periode) {
									return ROW.COD1 + '01';
								}
								else {
									return SELECT.PERIODE;
								}
						}
					} else {
							ANNEEEX = ROW.COD3.substr(0,4);
							MOISEX = ROW.COD3.substr(-2);
						
						if (ROW.COD == ROW.COD3) {
							
							if (ANNEEEX == annee_periode && MOISEX == mois_periode) {
								return SELECT.PERIODE;
							}
							else {
								return ANNEEEX + MOISEX;
							}
						}
						else {
							
							if (SELECT.GROUPBY == 'ANNEEEX' && ROW.COD1 != annee_periode) {
								return ROW.COD1 + '01';
							}
							else {
								return SELECT.PERIODE;
							}
						}
					
					}
				}
				else if (SELECT.GROUPBY == 'NUMEROMOISEX' || SELECT.GROUPBY_2 == 'NUMEROMOISEX' || SELECT.GROUPBY_3 == 'NUMEROMOISEX') {
					
					if (SELECT.GROUPBY == 'NUMEROMOISEX') {
						
						if (parseInt(ROW.COD1) <= parseInt(mois_toperiode)) {
							return annee_toperiode + ROW.COD1;
						}
						else {
							return (parseInt(annee_toperiode) - 1).toString() + ROW.COD1;
						}
					}
					else if (SELECT.GROUPBY_2 == 'NUMEROMOISEX') {
						
						mois_debut = 1 + 3 * (parseInt(ROW.COD1.substr(-1)) - 1);
						mois_debut_string = mois_debut < 10 ? '0' + mois_debut.toString() : mois_debut.toString();
						ANNEEEX = ROW.COD1.substr(0,4);
						
						if (SELECT.GROUPBY == 'ANNEEEX') {
							
							if (ROW.COD == ROW.COD2) {
								return ROW.COD1 + ROW.COD2;
							}
							else {
								
								if (ROW.COD1 == annee_periode) {
								
									return SELECT.PERIODE;
								}
								else {
								
									return ROW.COD1 + '01';
									
								}
							}
						}
						else if (SELECT.GROUPBY == 'TRIMEX') {
						
							if (ROW.COD == ROW.COD2) {
							
								return ANNEEEX + ROW.COD2;
								
							}
							else {
								if (ANNEEEX == annee_periode && mois_debut <= parseInt(mois_periode)) {
									return SELECT.PERIODE;
								}
								else {
									return ANNEEEX + mois_debut_string;
								}
							}
						}
						else if (SELECT.GROUPBY == 'NUMEROTRIMEX') {
							
							if (ROW.COD ==  ROW.COD2) {
								
								if (parseInt(ROW.COD2) <= parseInt(mois_toperiode)) {
									return annee_toperiode + ROW.COD2
								}
								else {
									return (parseInt(annee_toperiode) - 1).toString() + ROW.COD2;
								}
							}
							else {
								
								if (mois_debut <= parseInt(mois_toperiode)) {
									return annee_toperiode + mois_debut_string;
								}
								else {
									return (parseInt(annee_toperiode) - 1).toString() + mois_debut_string;
								}
							}
						}
						else {
							
							if (ROW.COD == ROW.COD2) {
								
								if (parseInt(ROW.COD2) <= parseInt(mois_toperiode)) {
									return annee_toperiode + ROW.COD2;
								}
								else {
									return (parseInt(annee_toperiode) - 1).toString() + ROW.COD2;
								}
							}
							else {
								return SELECT.PERIODE;
							}
						}
					} else {
						mois_debut = 1 + 3 * (parseInt(ROW.COD2.substr(-1)) - 1);
						mois_debut_string = mois_debut < 10 ? '0' + mois_debut.toString() : mois_debut.toString();
						ANNEEEX = ROW.COD2.substr(0,4);
						
						if (SELECT.GROUPBY == 'ANNEEEX') {
							
							if (ROW.COD == ROW.COD3) {
								return ROW.COD1 + ROW.COD2 + ROW.COD3;
							}
							else {
								
								if (ROW.COD1 == annee_periode) {
									return SELECT.PERIODE;
								}
								else {
									return ROW.COD1 + '01';
								}
							}
						}
						else if (SELECT.GROUPBY == 'TRIMEX') {
						
							if (ROW.COD == ROW.COD2) {
								return ANNEEEX + ROW.COD2;
							}
							else {
								if (ANNEEEX == annee_periode && mois_debut <= parseInt(mois_periode)) {
									return SELECT.PERIODE;
								}
								else {
									return ANNEEEX + mois_debut_string;
								}
							}
						}
						else if (SELECT.GROUPBY == 'NUMEROTRIMEX') {
							
							if (ROW.COD ==  ROW.COD2) {
								
								if (parseInt(ROW.COD2) <= parseInt(mois_toperiode)) {
									return annee_toperiode + ROW.COD2
								}
								else {
									return (parseInt(annee_toperiode) - 1).toString() + ROW.COD2;
								}
							}
							else {
								
								if (mois_debut <= parseInt(mois_toperiode)) {
									return annee_toperiode + mois_debut_string;
								}
								else {
									return (parseInt(annee_toperiode) - 1).toString() + mois_debut_string;
								}
							}
						}
						else {
							
							if (ROW.COD == ROW.COD3) {
								
								if (parseInt(ROW.COD3) <= parseInt(mois_toperiode)) {
									return annee_toperiode + ROW.COD3;
								}
								else {
									return (parseInt(annee_toperiode) - 1).toString() + ROW.COD3;
								}
							}
							else {
								return SELECT.PERIODE;
							}
						}
					}
				}
				else if (SELECT.GROUPBY == 'TRIMEX' || SELECT.GROUPBY_2 == 'TRIMEX' || SELECT.GROUPBY_3 == 'TRIMEX') {
					
					if (SELECT.GROUPBY == 'TRIMEX') {
					
						ANNEEEX = ROW.COD1.substr(0,4);
						mois_debut = 1 + 3 * (parseInt(ROW.COD1.substr(-1)) - 1);
						mois_debut_string = mois_debut < 10 ? '0' + mois_debut.toString() : mois_debut.toString();
						
						if (ANNEEEX == annee_periode && mois_debut <= parseInt(mois_periode)) {
							return SELECT.PERIODE;
						}
						else {
							return ANNEEEX + mois_debut_string;
						}
					}
					else if (SELECT.GROUPBY_2 == 'TRIMEX'){
					
						ANNEEEX = ROW.COD2.substr(0,4);
						mois_debut = 1 + 3 * (parseInt(ROW.COD2.substr(-1)) - 1);
						mois_debut_string = mois_debut < 10 ? '0' + mois_debut.toString() : mois_debut.toString();
						
						if (ROW.COD == ROW.COD2) {
							
							if (ANNEEEX == annee_periode && mois_debut <= parseInt(mois_periode)) {
								return SELECT.PERIODE;
							}
							else {
								return ANNEEEX + mois_debut_string;
							}
						}
						else {
							
							if (SELECT.GROUPBY == 'ANNEEEX' && ROW.COD1 != annee_periode) {
								return ROW.COD1 + '01';
							}
							else {
								return SELECT.PERIODE;
							}
						}
					} else {
						ANNEEEX = ROW.COD3.substr(0,4);
						mois_debut = 1 + 3 * (parseInt(ROW.COD3.substr(-1)) - 1);
						mois_debut_string = mois_debut < 10 ? '0' + mois_debut.toString() : mois_debut.toString();
						
						if (ROW.COD == ROW.COD3) {
							
							if (ANNEEEX == annee_periode && mois_debut <= parseInt(mois_periode)) {
								return SELECT.PERIODE;
							}
							else {
								return ANNEEEX + mois_debut_string;
							}
						}
						else {
							
							if (SELECT.GROUPBY == 'ANNEEEX' && ROW.COD1 != annee_periode) {
								return ROW.COD1 + '01';
							}
							else {
								return SELECT.PERIODE;
							}
						}
					
					} 
				}
				else if (SELECT.GROUPBY == 'NUMEROTRIMEX' || SELECT.GROUPBY_2 == 'NUMEROTRIMEX' || SELECT.GROUPBY_3 == 'NUMEROTRIMEX') {
					
					mois_debut = 1 + 3 * (parseInt(ROW.COD2.substr(-1)) - 1);
					mois_debut_string = mois_debut < 10 ? '0' + mois_debut.toString() : mois_debut.toString();
					
					if (SELECT.GROUPBY == 'NUMEROTRIMEX') {
					
						mois_debut = 1 + 3 * (parseInt(ROW.COD1.substr(-1)) - 1);
						mois_debut_string = mois_debut < 10 ? '0' + mois_debut.toString() : mois_debut.toString();
						
						if (mois_debut <= parseInt(mois_toperiode)) {
							return annee_toperiode + mois_debut_string;
						}
						else {
							return (parseInt(annee_toperiode) -1).toString() + mois_debut_string;
						}
					}
					else if (SELECT.GROUPBY == 'ANNEEEX') {

						if (ROW.COD == ROW.COD2) {
							
							if (ROW.COD1 == annee_periode && mois_debut <= parseInt(mois_periode)) {
								return SELECT.PERIODE;
							}
							else {
								return ROW.COD1 + mois_debut_string;
							}
						}
						else {
							
							if (ROW.COD1 == annee_periode) {
								return SELECT.PERIODE;
							}
							else {
								return ROW.COD1 + '01';
							}
						}
					}
					else  if(SELECT.GROUPBY_2 == 'NUMEROTRIMEX') {
						
						if (ROW.COD == ROW.COD2) {
							
							if (mois_debut <= parseInt(mois_toperiode)) {
								return annee_toperiode + mois_debut_string;
							}
							else {
								return (parseInt(annee_toperiode) - 1).toString() + mois_debut_string;
							}
						}
						else {
							return SELECT.PERIODE;
						}
					} else {
							mois_debut = 1 + 3 * (parseInt(ROW.COD3.substr(-1)) - 1);
							mois_debut_string = mois_debut < 10 ? '0' + mois_debut.toString() : mois_debut.toString();
							if (ROW.COD == ROW.COD3) {
								
								if (mois_debut <= parseInt(mois_toperiode)) {
									return annee_toperiode + mois_debut_string;
								}
								else {
									return (parseInt(annee_toperiode) - 1).toString() + mois_debut_string;
								}
							}
							else {
								return SELECT.PERIODE;
							}
					
					}
				}
				else if (SELECT.GROUPBY == 'ANNEEEX'|| SELECT.GROUPBY_2 == 'ANNEEEX' || SELECT.GROUPBY_3 == 'ANNEEEX') {
				
					if(SELECT.GROUPBY == 'ANNEEEX'|| SELECT.GROUPBY_2 == 'ANNEEEX') {
					
						var row_cod:String = (SELECT.GROUPBY == 'ANNEEEX') ? ROW.COD1 : ROW.COD2;
					}else {
						var row_cod:String = ROW.COD3;
					}
	
					if (row_cod == annee_periode) {
						return SELECT.PERIODE;
					}
					else {
						return row_cod + '01';
					}
				// FIN TRAITEMETN DATE D'EXPEDITION
				}
				else {
                    var periode_comparatif:String = SELECT.PERIODE;
                    
                    if (COLUMN.NAME == 'D1_OLD') {periode_comparatif =  VIEW.PERIODE_D;}
                    if (COLUMN.NAME == 'D1_NOW') {periode_comparatif = SELECT.PERIODE;}
                    if (COLUMN.NAME == 'D2_OLD') {periode_comparatif = VIEW.PERIODE_D;}
                    if (COLUMN.NAME == 'D2_NOW') {periode_comparatif = SELECT.PERIODE;}
                    if (COLUMN.NAME == 'CA_MOY_OLD') {periode_comparatif = VIEW.PERIODE_D;}
                    if (COLUMN.NAME == 'CA_MOY_NOW') {periode_comparatif = SELECT.PERIODE;}
                    if (COLUMN.NAME == 'F1') {periode_comparatif = SELECT.PERIODE}
                    if (COLUMN.NAME == 'F2') {periode_comparatif = SELECT.PERIODE}
                    if (COLUMN.NAME == 'F3') {periode_comparatif = SELECT.PERIODE}
                    if (COLUMN.NAME == 'F4') {periode_comparatif = SELECT.PERIODE}
                    if (COLUMN.NAME == 'F5') {periode_comparatif = SELECT.PERIODE}
                    if (COLUMN.NAME == 'F6') {periode_comparatif = SELECT.PERIODE}
                    if (COLUMN.NAME == 'F7') {periode_comparatif = SELECT.PERIODE}
                    if (COLUMN.NAME == 'F8') {periode_comparatif = SELECT.PERIODE}
                    if (COLUMN.NAME == 'F9') {periode_comparatif = SELECT.PERIODE}
                    if (COLUMN.NAME == 'F10') {periode_comparatif = SELECT.PERIODE}
                    if (COLUMN.NAME == 'F11') {periode_comparatif = SELECT.PERIODE}
                    if (COLUMN.NAME == 'F12') {periode_comparatif = SELECT.PERIODE}
                    if (COLUMN.NAME == 'F13') {periode_comparatif = SELECT.PERIODE}
                    if (COLUMN.NAME == 'F14') {periode_comparatif = SELECT.PERIODE}
                    if (COLUMN.NAME == 'F15') {periode_comparatif = SELECT.PERIODE}
                    if (COLUMN.NAME == 'D1') {periode_comparatif = VIEW.PERIODE_D}
                    if (COLUMN.NAME == 'D2') {periode_comparatif = VIEW.PERIODE_D}
                    if (COLUMN.NAME == 'D3') {periode_comparatif = VIEW.PERIODE_D}
                    if (COLUMN.NAME == 'D4') {periode_comparatif = VIEW.PERIODE_D}
                    if (COLUMN.NAME == 'D5') {periode_comparatif = VIEW.PERIODE_D}
                    if (COLUMN.NAME == 'D6') {periode_comparatif = VIEW.PERIODE_D}
                    if (COLUMN.NAME == 'D7') {periode_comparatif = VIEW.PERIODE_D}
                    if (COLUMN.NAME == 'D8') {periode_comparatif = VIEW.PERIODE_D}
                    if (COLUMN.NAME == 'D9') {periode_comparatif = VIEW.PERIODE_D}
                    if (COLUMN.NAME == 'D10') {periode_comparatif = VIEW.PERIODE_D}
                    if (COLUMN.NAME == 'D11') {periode_comparatif = VIEW.PERIODE_D}
                    if (COLUMN.NAME == 'D12') {periode_comparatif = VIEW.PERIODE_D}
                    if (COLUMN.NAME == 'D13') {periode_comparatif = VIEW.PERIODE_D}
                    if (COLUMN.NAME == 'D14') {periode_comparatif = VIEW.PERIODE_D}
                    if (COLUMN.NAME == 'D15') {periode_comparatif = VIEW.PERIODE_D}
                    if (COLUMN.NAME == 'L1') {periode_comparatif = VIEW.PERIODE_D2}
                    if (COLUMN.NAME == 'L2') {periode_comparatif = VIEW.PERIODE_D2}
                    if (COLUMN.NAME == 'L3') {periode_comparatif = VIEW.PERIODE_D2}
                    if (COLUMN.NAME == 'L4') {periode_comparatif = VIEW.PERIODE_D2}
                    if (COLUMN.NAME == 'L5') {periode_comparatif = VIEW.PERIODE_D2}
                    if (COLUMN.NAME == 'L6') {periode_comparatif = VIEW.PERIODE_D2}
                    if (COLUMN.NAME == 'L7') {periode_comparatif = VIEW.PERIODE_D2}
                    if (COLUMN.NAME == 'L8') {periode_comparatif = VIEW.PERIODE_D2}
                    if (COLUMN.NAME == 'L9') {periode_comparatif = VIEW.PERIODE_D2}
                    if (COLUMN.NAME == 'L10') {periode_comparatif = VIEW.PERIODE_D2}
                    if (COLUMN.NAME == 'L11') {periode_comparatif = VIEW.PERIODE_D2}
                    if (COLUMN.NAME == 'L12') {periode_comparatif = VIEW.PERIODE_D2}
                    if (COLUMN.NAME == 'L13') {periode_comparatif = VIEW.PERIODE_D2}
                    if (COLUMN.NAME == 'L14') {periode_comparatif = VIEW.PERIODE_D2}
                    if (COLUMN.NAME == 'L15') {periode_comparatif = VIEW.PERIODE_D2}
					return periode_comparatif;
				}
				
				
			]]></value>
		</ARG>
		
		<ARG name="TOPERIODE">
			<value><![CDATA[
			
				var annee_periode:String = SELECT.PERIODE.substr(0,4);
				var mois_periode:String = SELECT.PERIODE.substr(5,2);
				var annee_toperiode:String = SELECT.TOPERIODE.substr(0,4);
				var mois_toperiode:String = SELECT.TOPERIODE.substr(5,2);
				
				var mois_debut:int = 0;
				var mois_fin:int = 0;
				var mois_fin_string:String = '';
				var annee:String = '';
				
				function getDateFromWeek(code:String,day:int) {
					var annee:String =  code.substr(0,4);
					var date:Date = new Date(int(annee),0,1);
					date.setTime(date.getTime() + 1000*60*60*24*(7*(int(code.substr(4,6))-1)-(date.getDay()+7)%6+day));
					var year = date.getFullYear();
					var month = date.getMonth()+1;
					var day = date.getDate();
					if(month < 10){
						month = 0 + month;
					}
					if(day < 10){
						day = 0 + day;
					}
					return year + '-' + month + '-' + day;
				}

				if(ROW.OID === '-9999999'){
					return SELECT.TOPERIODE;
				}
			// TRAITEMENT DATE D'EXPEDITION
				if (SELECT.GROUPBY == 'SEMAINEANNEEX' || SELECT.GROUPBY_2 == 'SEMAINEANNEEX' || SELECT.GROUPBY_3 == 'SEMAINEANNEEX' ) {
						if(SELECT.GROUPBY == 'SEMAINEANNEEX' || SELECT.GROUPBY_2 == 'SEMAINEANNEEX'){
							row_cod = (SELECT.GROUPBY == 'SEMAINEANNEEX') ? ROW.COD1 : ROW.COD2;
						}else {
							row_cod = ROW.COD3;
						}
					if (SELECT.GROUPBY == 'ANNEEEX' || SELECT.GROUPBY_2 == 'ANNEEEX') {
						var ANNEEEX:String =  (SELECT.GROUPBY == 'SEMAINEANNEEX') ?  ROW.COD2.substr(0,4) : ROW.COD1.substr(0,4);
						return getDateFromWeek(ANNEEEX+row_cod,6);
					}
					else{
						var date:String = getDateFromWeek(annee_toperiode + row_cod,6);
						var month:int = parseInt(date.substr(5,2));
						var day:int = parseInt(date.substr(8,2));
						var toDay:int = parseInt(SELECT.TOPERIODE.substr(8,2));					
						if (month <= parseInt(mois_toperiode) && day <= toDay) {
							return getDateFromWeek(annee_toperiode+row_cod,6);
						}
						else {
								return getDateFromWeek((parseInt(annee_toperiode)).toString()+row_cod,0);
						}
					}
				}
				if (SELECT.GROUPBY == 'JOURSEX' || SELECT.GROUPBY_2 == 'JOURSEX' || SELECT.GROUPBY_3 == 'JOURSEX') {
					
					if (SELECT.GROUPBY == 'JOURSEX') {
						return annee_periode+'-'+ROW.COD1;
					}
					else if (ROW.COD == ROW.COD2) {
						return annee_periode+'-'+ROW.COD2;
					}else if(ROW.COD == ROW.COD3) {
						return annee_periode+'-'+ROW.COD3;
					}
				}
				if (SELECT.GROUPBY == 'JOUREX' || SELECT.GROUPBY_2 == 'JOUREX' || SELECT.GROUPBY_3 == 'JOUREX') {
					
					if (SELECT.GROUPBY == 'JOUREX') {
						return ROW.COD1;
					}
					else if (ROW.COD == ROW.COD2) {
						return ROW.COD2;
					} else if(ROW.COD == ROW.COD3) {
						return ROW.COD3;
					}
				}
				if (SELECT.GROUPBY == 'MOISEX' || SELECT.GROUPBY_2 == 'MOISEX' || SELECT.GROUPBY_3 == 'MOISEX') {
					
					var mois:String = '';
					
					if (SELECT.GROUPBY == 'MOISEX') {
						
						 annee  = ROW.COD1.substr(0,4);
						 mois   = ROW.COD1.substr(-2);
						
						if (annee == annee_toperiode && mois == mois_toperiode) {
							return SELECT.TOPERIODE;
						}
						else {
							return annee + mois;
						}
					}
					else if (SELECT.GROUPBY_2 == 'MOISEX') {
						
						annee = ROW.COD2.substr(0,4);
						mois = ROW.COD2.substr(-2);
						
						if (ROW.COD == ROW.COD2) {
							
							if (annee == annee_toperiode && mois == mois_toperiode) {
								return SELECT.TOPERIODE;
							}
							else {
								return annee + mois;
							}
						}
						else {
							
							if (SELECT.GROUPBY == 'ANNEEEX' && ROW.COD1 != annee_toperiode) {
								return ROW.COD1 + '12';
							}
							else {
								return SELECT.TOPERIODE;
							}
						}
					} else if (SELECT.GROUPBY_3 == 'MOISEX'){
							annee = ROW.COD3.substr(0,4);
							mois = ROW.COD3.substr(-2);
						
						if (ROW.COD == ROW.COD3) {
							
							if (annee== annee_periode && mois == mois_periode) {
								 return annee + mois;
							}
						}
						else {
							
							if (SELECT.GROUPBY == 'ANNEEEX' && ROW.COD1 != annee_periode) {
								return ROW.COD1 + '01';
							}
							else {
								return SELECT.PERIODE;
							}
						}
					
					}
				}
				else if (SELECT.GROUPBY == 'NUMEROMOISEX' || SELECT.GROUPBY_2 == 'NUMEROMOISEX' || SELECT.GROUPBY_3 == 'NUMEROMOISEX') {
					
					if (SELECT.GROUPBY == 'NUMEROMOISEX') {
						
						if (parseInt(ROW.COD1) <= parseInt(mois_toperiode)) {
							return annee_toperiode + ROW.COD1;
						}
						else {
							return (parseInt(annee_toperiode) - 1).toString() + ROW.COD1;
						}
					}
					else if (SELECT.GROUPBY_2 == 'NUMEROMOISEX'){
					
						mois_debut = 1 + 3 * (parseInt(ROW.COD1.substr(-1)) - 1);
						mois_fin = 3 * parseInt(ROW.COD1.substr(-1));
						mois_fin_string = mois_fin < 10 ? '0' + mois_fin.toString() : mois_fin.toString();
						ANNEEEX = ROW.COD1.substr(0,4);
						
						if (SELECT.GROUPBY == 'ANNEEEX') {
							
							if (ROW.COD == ROW.COD2) {
								return ROW.COD1 + ROW.COD2;
							}
							else {
								
								if (ROW.COD1 == annee_toperiode) {
									return SELECT.TOPERIODE;
								}
								else {
									return ROW.COD1 + '12';
								}
							}
						}
						else if (SELECT.GROUPBY == 'TRIMEX') {
						
							if (ROW.COD == ROW.COD2) {
								return ANNEEEX + ROW.COD2;
							}
							else {
								
								if (ANNEEEX == annee_toperiode && mois_fin >= parseInt(mois_toperiode)) {
									return SELECT.TOPERIODE;
								}
								else {
									return ANNEEEX + mois_fin_string;
								}
							}
						}
						else if (SELECT.GROUPBY == 'NUMEROTRIMEX') {
							
							if (ROW.COD ==  ROW.COD2) {
								
								if (parseInt(ROW.COD2) <= parseInt(mois_toperiode)) {
									return annee_toperiode + ROW.COD2
								}
								else {
									return (parseInt(annee_toperiode) - 1).toString() + ROW.COD2;
								}
							}
							else {
								
								if (mois_fin <= parseInt(mois_toperiode)) {
									return annee_toperiode + mois_fin_string;
								}
								else {
									
									if (mois_debut <= parseInt(mois_toperiode)) {
										return SELECT.TOPERIODE;
									}
									else {
										return (parseInt(annee_toperiode) - 1).toString() + mois_fin_string;
									}
								}
							}
						}
						else {
							
							if (ROW.COD == ROW.COD2) {
								
								if (parseInt(ROW.COD2) <= parseInt(mois_toperiode)) {
									return annee_toperiode + ROW.COD2;
								}
								else {
									return (parseInt(annee_toperiode) - 1).toString() + ROW.COD2;
								}
							}
							else {
								return SELECT.TOPERIODE;
							}
						}
					} else {
							mois_debut = 1 + 3 * (parseInt(ROW.COD2.substr(-1)) - 1);
							mois_fin = 3 * parseInt(ROW.COD2.substr(-1));
							mois_fin_string = mois_fin < 10 ? '0' + mois_fin.toString() : mois_fin.toString();
							ANNEEEX = ROW.COD2.substr(0,4);
						
						if (SELECT.GROUPBY == 'ANNEEEX') {
							
							if (ROW.COD == ROW.COD2) {
								return ROW.COD1 + ROW.COD2;
							}
							else {
								
								if (ROW.COD1 == annee_toperiode) {
									return SELECT.TOPERIODE;
								}
								else {
									return ROW.COD1 + '12';
								}
							}
						}
						else if (SELECT.GROUPBY == 'TRIMEX') {
						
							if (ROW.COD == ROW.COD2) {
								return ANNEEEX + ROW.COD2;
							}
							else {
								
								if (ANNEEEX == annee_toperiode && mois_fin >= parseInt(mois_toperiode)) {
									return SELECT.TOPERIODE;
								}
								else {
									return ANNEEEX + mois_fin_string;
								}
							}
						}
						else if (SELECT.GROUPBY == 'NUMEROTRIMEX') {
							
							if (ROW.COD ==  ROW.COD2) {
								
								if (parseInt(ROW.COD2) <= parseInt(mois_toperiode)) {
									return annee_toperiode + ROW.COD2
								}
								else {
									return (parseInt(annee_toperiode) - 1).toString() + ROW.COD2;
								}
							}
							else {
								
								if (mois_fin <= parseInt(mois_toperiode)) {
									return annee_toperiode + mois_fin_string;
								}
								else {
									
									if (mois_debut <= parseInt(mois_toperiode)) {
										return SELECT.TOPERIODE;
									}
									else {
										return (parseInt(annee_toperiode) - 1).toString() + mois_fin_string;
									}
								}
							}
						}
						else {
							
							if (ROW.COD == ROW.COD3) {
								
								if (parseInt(ROW.COD3) <= parseInt(mois_toperiode)) {
									return annee_toperiode + ROW.COD3;
								}
								else {
									return (parseInt(annee_toperiode) - 1).toString() + ROW.COD3;
								}
							}
							else {
								return SELECT.TOPERIODE;
							}
						}
					}
				}
				else if (SELECT.GROUPBY == 'TRIMEX' || SELECT.GROUPBY_2 == 'TRIMEX' || SELECT.GROUPBY_3 == 'TRIMEX') {
					
					if (SELECT.GROUPBY == 'TRIMEX') {
					
						ANNEEEX = ROW.COD1.substr(0,4);
						mois_fin = 3 * parseInt(ROW.COD1.substr(-1));
						mois_fin_string = mois_fin < 10 ? '0' + mois_fin.toString() : mois_fin.toString();
						
						if (ANNEEEX == annee_periode && mois_fin >= parseInt(mois_toperiode)) {
							return SELECT.TOPERIODE;
						}
						else {
							return ANNEEEX + mois_fin_string;
						}
					}
					else if (SELECT.GROUPBY_2 == 'TRIMEX'){
					
						ANNEEEX = ROW.COD2.substr(0,4);
						mois_fin = 3 * parseInt(ROW.COD2.substr(-1));
						mois_fin_string = mois_fin < 10 ? '0' + mois_fin.toString() : mois_fin.toString();
						
						if (ROW.COD == ROW.COD2) {
							
							if (ANNEEEX == annee_toperiode && mois_fin >= parseInt(mois_toperiode)) {
								return SELECT.TOPERIODE;
							}
							else {
								return ANNEEEX + mois_fin_string;
							}
						}
						else {
							
							if (SELECT.GROUPBY == 'ANNEEEX' && ROW.COD1 != annee_toperiode) {
								return ROW.COD1 + '12';
							}
							else {
								return SELECT.TOPERIODE;
							}
						}
					} else {
						ANNEEEX = ROW.COD3.substr(0,4);
						mois_fin = 3 * parseInt(ROW.COD3.substr(-1));
						mois_fin_string = mois_fin < 10 ? '0' + mois_fin.toString() : mois_fin.toString();
						
						if (ROW.COD == ROW.COD3) {
							
							if (ANNEEEX == annee_toperiode && mois_fin >= parseInt(mois_toperiode)) {
								return SELECT.TOPERIODE;
							}
							else {
								return ANNEEEX + mois_fin_string;
							}
						}
						else {
							
							if (SELECT.GROUPBY == 'ANNEEEX' && ROW.COD1 != annee_toperiode) {
								return ROW.COD1 + '12';
							}
							else {
								return SELECT.TOPERIODE;
							}
						}
					}
				}
				else if (SELECT.GROUPBY == 'NUMEROTRIMEX' || SELECT.GROUPBY_2 == 'NUMEROTRIMEX' || SELECT.GROUPBY_3 == 'NUMEROTRIMEX' ) {
					
					mois_debut = 1 + 3 * (parseInt(ROW.COD2.substr(-1)) - 1);
					mois_fin = 3 * parseInt(ROW.COD2.substr(-1));
					mois_fin_string = mois_fin < 10 ? '0' + mois_fin.toString() : mois_fin.toString();
					
					if (SELECT.GROUPBY == 'NUMEROTRIMEX') {
					
						mois_debut = 1 + 3 * (parseInt(ROW.COD1.substr(-1)) - 1);
						mois_fin = 3 * parseInt(ROW.COD1.substr(-1));
						mois_fin_string = mois_fin < 10 ? '0' + mois_fin.toString() : mois_fin.toString();
						
						if (mois_fin <= parseInt(mois_toperiode)) {
							return annee_toperiode + mois_fin_string;
						}
						else {
							
							if (mois_debut <= parseInt(mois_toperiode)) {
								return SELECT.TOPERIODE;
							}
							else {
								return (parseInt(annee_toperiode) -1).toString() + mois_fin_string;
							}
						}
					}
					else if (SELECT.GROUPBY == 'ANNEEEX') {

						if (ROW.COD == ROW.COD2) {
							
							if (ROW.COD1 == annee_toperiode && mois_fin >= parseInt(mois_toperiode)) {
								return SELECT.TOPERIODE;
							}
							else {
								return ROW.COD1 + mois_fin_string;
							}
						}
						else {
							
							if (ROW.COD1 == annee_toperiode) {
								return SELECT.TOPERIODE;
							}
							else {
								return ROW.COD1 + '12';
							}
						}
					}
					else if (SELECT.GROUPBY_2 == 'NUMEROTRIMEX'){
						
						if (ROW.COD == ROW.COD2) {
							
							if (mois_fin <= parseInt(mois_toperiode)) {
								return annee_toperiode + mois_fin_string;
							}
							else {
								
								if (mois_debut <= mois_toperiode) {
									return SELECT.TOPERIODE;
								}
								else {
									return (parseInt(annee_toperiode) -1).toString() + mois_fin_string;
								}
							}
						}
						else {
							return SELECT.TOPERIODE;
						}
					} else {
							mois_debut = 1 + 3 * (parseInt(ROW.COD3.substr(-1)) - 1);
							mois_fin = 3 * parseInt(ROW.COD3.substr(-1));
							mois_fin_string = mois_fin < 10 ? '0' + mois_fin.toString() : mois_fin.toString();
						if (ROW.COD == ROW.COD3) {
							
							if (mois_fin <= parseInt(mois_toperiode)) {
								return annee_toperiode + mois_fin_string;
							}
							else {
								
								if (mois_debut <= mois_toperiode) {
									return SELECT.TOPERIODE;
								}
								else {
									return (parseInt(annee_toperiode) -1).toString() + mois_fin_string;
								}
							}
						}
						else {
							return SELECT.TOPERIODE;
						}
					}
				}
				else if (SELECT.GROUPBY == 'ANNEEEX'|| SELECT.GROUPBY_2 == 'ANNEEEX' || SELECT.GROUPBY_3 == 'ANNEEEX' ) {
					
					if(SELECT.GROUPBY == 'ANNEEEX'|| SELECT.GROUPBY_2 == 'ANNEEEX') {
					
						var row_cod:String = (SELECT.GROUPBY == 'ANNEEEX') ? ROW.COD1 : ROW.COD2;
					}else {
						var row_cod:String = ROW.COD3;
					}
					
					if (row_cod == annee_toperiode) {
						return SELECT.TOPERIODE;
					}
					else {
						return row_cod + '12';
					}
				}
			// FIN TRAITEMENT DATE D'EXPEDITION 
			// TRAITEMENT DATE D'ACTIVITE
				if (SELECT.GROUPBY == 'SEMAINEANNEA' || SELECT.GROUPBY_2 == 'SEMAINEANNEA' || SELECT.GROUPBY_3 == 'SEMAINEANNEA' ) {
						if(SELECT.GROUPBY == 'SEMAINEANNEA' || SELECT.GROUPBY_2 == 'SEMAINEANNEA'){
							row_cod = (SELECT.GROUPBY == 'SEMAINEANNEA') ? ROW.COD1 : ROW.COD2;
						}else {
							row_cod = ROW.COD3;
						}
					if (SELECT.GROUPBY == 'ANNEEA' || SELECT.GROUPBY_2 == 'ANNEEA') {
						var ANNEEEX:String =  (SELECT.GROUPBY == 'SEMAINEANNEA') ?  ROW.COD2.substr(0,4) : ROW.COD1.substr(0,4);
						return getDateFromWeek(ANNEEEX+row_cod,6);
					}
					else{
						var date:String = getDateFromWeek(annee_toperiode + row_cod,6);
						var month:int = parseInt(date.substr(5,2));
						var day:int = parseInt(date.substr(8,2));
						var toDay:int = parseInt(SELECT.TOPERIODE.substr(8,2));					
						if (month <= parseInt(mois_toperiode) && day <= toDay) {
							return getDateFromWeek(annee_toperiode+row_cod,6);
						}
						else {
								return getDateFromWeek((parseInt(annee_toperiode)).toString()+row_cod,0);
						}
					}
				}
				if (SELECT.GROUPBY == 'JOURSA' || SELECT.GROUPBY_2 == 'JOURSA' || SELECT.GROUPBY_3 == 'JOURSA') {
					
					if (SELECT.GROUPBY == 'JOURSA') {
						return annee_periode+'-'+ROW.COD1;
					}
					else if (ROW.COD == ROW.COD2) {
						return annee_periode+'-'+ROW.COD2;
					}else if(ROW.COD == ROW.COD3) {
						return annee_periode+'-'+ROW.COD3;
					}
				}
				if (SELECT.GROUPBY == 'JOURA' || SELECT.GROUPBY_2 == 'JOURA' || SELECT.GROUPBY_3 == 'JOURA') {
					
					if (SELECT.GROUPBY == 'JOURA') {
						return ROW.COD1;
					}
					else if (ROW.COD == ROW.COD2) {
						return ROW.COD2;
					} else if(ROW.COD == ROW.COD3) {
						return ROW.COD3;
					}
				}
				if (SELECT.GROUPBY == 'MOISA' || SELECT.GROUPBY_2 == 'MOISA' || SELECT.GROUPBY_3 == 'MOISA') {
					
					var mois:String = '';
					
					if (SELECT.GROUPBY == 'MOISA') {
						
						 annee  = ROW.COD1.substr(0,4);
						 mois   = ROW.COD1.substr(-2);
						
						if (annee == annee_toperiode && mois == mois_toperiode) {
							return SELECT.TOPERIODE;
						}
						else {
							return annee + mois;
						}
					}
					else if (SELECT.GROUPBY_2 == 'MOISA') {
						
						annee = ROW.COD2.substr(0,4);
						mois = ROW.COD2.substr(-2);
						
						if (ROW.COD == ROW.COD2) {
							
							if (annee == annee_toperiode && mois == mois_toperiode) {
								return SELECT.TOPERIODE;
							}
							else {
								return annee + mois;
							}
						}
						else {
							
							if (SELECT.GROUPBY == 'ANNEEA' && ROW.COD1 != annee_toperiode) {
								return ROW.COD1 + '12';
							}
							else {
								return SELECT.TOPERIODE;
							}
						}
					} else if (SELECT.GROUPBY_3 == 'MOISA'){
							annee = ROW.COD3.substr(0,4);
							mois = ROW.COD3.substr(-2);
						
						if (ROW.COD == ROW.COD3) {
							
							if (annee== annee_periode && mois == mois_periode) {
								 return annee + mois;
							}
						}
						else {
							
							if (SELECT.GROUPBY == 'ANNEEA' && ROW.COD1 != annee_periode) {
								return ROW.COD1 + '01';
							}
							else {
								return SELECT.PERIODE;
							}
						}
					
					}
				}
				else if (SELECT.GROUPBY == 'NUMEROMOISA' || SELECT.GROUPBY_2 == 'NUMEROMOISA' || SELECT.GROUPBY_3 == 'NUMEROMOISA') {
					
					if (SELECT.GROUPBY == 'NUMEROMOISA') {
						
						if (parseInt(ROW.COD1) <= parseInt(mois_toperiode)) {
							return annee_toperiode + ROW.COD1;
						}
						else {
							return (parseInt(annee_toperiode) - 1).toString() + ROW.COD1;
						}
					}
					else if (SELECT.GROUPBY_2 == 'NUMEROMOISA'){
					
						mois_debut = 1 + 3 * (parseInt(ROW.COD1.substr(-1)) - 1);
						mois_fin = 3 * parseInt(ROW.COD1.substr(-1));
						mois_fin_string = mois_fin < 10 ? '0' + mois_fin.toString() : mois_fin.toString();
						ANNEEEX = ROW.COD1.substr(0,4);
						
						if (SELECT.GROUPBY == 'ANNEEA') {
							
							if (ROW.COD == ROW.COD2) {
								return ROW.COD1 + ROW.COD2;
							}
							else {
								
								if (ROW.COD1 == annee_toperiode) {
									return SELECT.TOPERIODE;
								}
								else {
									return ROW.COD1 + '12';
								}
							}
						}
						else if (SELECT.GROUPBY == 'TRIMA') {
						
							if (ROW.COD == ROW.COD2) {
								return ANNEEEX + ROW.COD2;
							}
							else {
								
								if (ANNEEEX == annee_toperiode && mois_fin >= parseInt(mois_toperiode)) {
									return SELECT.TOPERIODE;
								}
								else {
									return ANNEEEX + mois_fin_string;
								}
							}
						}
						else if (SELECT.GROUPBY == 'NUMEROTRIMA') {
							
							if (ROW.COD ==  ROW.COD2) {
								
								if (parseInt(ROW.COD2) <= parseInt(mois_toperiode)) {
									return annee_toperiode + ROW.COD2
								}
								else {
									return (parseInt(annee_toperiode) - 1).toString() + ROW.COD2;
								}
							}
							else {
								
								if (mois_fin <= parseInt(mois_toperiode)) {
									return annee_toperiode + mois_fin_string;
								}
								else {
									
									if (mois_debut <= parseInt(mois_toperiode)) {
										return SELECT.TOPERIODE;
									}
									else {
										return (parseInt(annee_toperiode) - 1).toString() + mois_fin_string;
									}
								}
							}
						}
						else {
							
							if (ROW.COD == ROW.COD2) {
								
								if (parseInt(ROW.COD2) <= parseInt(mois_toperiode)) {
									return annee_toperiode + ROW.COD2;
								}
								else {
									return (parseInt(annee_toperiode) - 1).toString() + ROW.COD2;
								}
							}
							else {
								return SELECT.TOPERIODE;
							}
						}
					} else {
							mois_debut = 1 + 3 * (parseInt(ROW.COD2.substr(-1)) - 1);
							mois_fin = 3 * parseInt(ROW.COD2.substr(-1));
							mois_fin_string = mois_fin < 10 ? '0' + mois_fin.toString() : mois_fin.toString();
							ANNEEEX = ROW.COD2.substr(0,4);
						
						if (SELECT.GROUPBY == 'ANNEEA') {
							
							if (ROW.COD == ROW.COD2) {
								return ROW.COD1 + ROW.COD2;
							}
							else {
								
								if (ROW.COD1 == annee_toperiode) {
									return SELECT.TOPERIODE;
								}
								else {
									return ROW.COD1 + '12';
								}
							}
						}
						else if (SELECT.GROUPBY == 'TRIMA') {
						
							if (ROW.COD == ROW.COD2) {
								return ANNEEEX + ROW.COD2;
							}
							else {
								
								if (ANNEEEX == annee_toperiode && mois_fin >= parseInt(mois_toperiode)) {
									return SELECT.TOPERIODE;
								}
								else {
									return ANNEEEX + mois_fin_string;
								}
							}
						}
						else if (SELECT.GROUPBY == 'NUMEROTRIMA') {
							
							if (ROW.COD ==  ROW.COD2) {
								
								if (parseInt(ROW.COD2) <= parseInt(mois_toperiode)) {
									return annee_toperiode + ROW.COD2
								}
								else {
									return (parseInt(annee_toperiode) - 1).toString() + ROW.COD2;
								}
							}
							else {
								
								if (mois_fin <= parseInt(mois_toperiode)) {
									return annee_toperiode + mois_fin_string;
								}
								else {
									
									if (mois_debut <= parseInt(mois_toperiode)) {
										return SELECT.TOPERIODE;
									}
									else {
										return (parseInt(annee_toperiode) - 1).toString() + mois_fin_string;
									}
								}
							}
						}
						else {
							
							if (ROW.COD == ROW.COD3) {
								
								if (parseInt(ROW.COD3) <= parseInt(mois_toperiode)) {
									return annee_toperiode + ROW.COD3;
								}
								else {
									return (parseInt(annee_toperiode) - 1).toString() + ROW.COD3;
								}
							}
							else {
								return SELECT.TOPERIODE;
							}
						}
					}
				}
				else if (SELECT.GROUPBY == 'TRIMA' || SELECT.GROUPBY_2 == 'TRIMA' || SELECT.GROUPBY_3 == 'TRIMA') {
					
					if (SELECT.GROUPBY == 'TRIMA') {
					
						ANNEEEX = ROW.COD1.substr(0,4);
						mois_fin = 3 * parseInt(ROW.COD1.substr(-1));
						mois_fin_string = mois_fin < 10 ? '0' + mois_fin.toString() : mois_fin.toString();
						
						if (ANNEEEX == annee_periode && mois_fin >= parseInt(mois_toperiode)) {
							return SELECT.TOPERIODE;
						}
						else {
							return ANNEEEX + mois_fin_string;
						}
					}
					else if (SELECT.GROUPBY_2 == 'TRIMA'){
					
						ANNEEEX = ROW.COD2.substr(0,4);
						mois_fin = 3 * parseInt(ROW.COD2.substr(-1));
						mois_fin_string = mois_fin < 10 ? '0' + mois_fin.toString() : mois_fin.toString();
						
						if (ROW.COD == ROW.COD2) {
							
							if (ANNEEEX == annee_toperiode && mois_fin >= parseInt(mois_toperiode)) {
								return SELECT.TOPERIODE;
							}
							else {
								return ANNEEEX + mois_fin_string;
							}
						}
						else {
							
							if (SELECT.GROUPBY == 'ANNEEA' && ROW.COD1 != annee_toperiode) {
								return ROW.COD1 + '12';
							}
							else {
								return SELECT.TOPERIODE;
							}
						}
					} else {
						ANNEEEX = ROW.COD3.substr(0,4);
						mois_fin = 3 * parseInt(ROW.COD3.substr(-1));
						mois_fin_string = mois_fin < 10 ? '0' + mois_fin.toString() : mois_fin.toString();
						
						if (ROW.COD == ROW.COD3) {
							
							if (ANNEEEX == annee_toperiode && mois_fin >= parseInt(mois_toperiode)) {
								return SELECT.TOPERIODE;
							}
							else {
								return ANNEEEX + mois_fin_string;
							}
						}
						else {
							
							if (SELECT.GROUPBY == 'ANNEEA' && ROW.COD1 != annee_toperiode) {
								return ROW.COD1 + '12';
							}
							else {
								return SELECT.TOPERIODE;
							}
						}
					}
				}
				else if (SELECT.GROUPBY == 'NUMEROTRIMA' || SELECT.GROUPBY_2 == 'NUMEROTRIMA' || SELECT.GROUPBY_3 == 'NUMEROTRIMA' ) {
					
					mois_debut = 1 + 3 * (parseInt(ROW.COD2.substr(-1)) - 1);
					mois_fin = 3 * parseInt(ROW.COD2.substr(-1));
					mois_fin_string = mois_fin < 10 ? '0' + mois_fin.toString() : mois_fin.toString();
					
					if (SELECT.GROUPBY == 'NUMEROTRIMA') {
					
						mois_debut = 1 + 3 * (parseInt(ROW.COD1.substr(-1)) - 1);
						mois_fin = 3 * parseInt(ROW.COD1.substr(-1));
						mois_fin_string = mois_fin < 10 ? '0' + mois_fin.toString() : mois_fin.toString();
						
						if (mois_fin <= parseInt(mois_toperiode)) {
							return annee_toperiode + mois_fin_string;
						}
						else {
							
							if (mois_debut <= parseInt(mois_toperiode)) {
								return SELECT.TOPERIODE;
							}
							else {
								return (parseInt(annee_toperiode) -1).toString() + mois_fin_string;
							}
						}
					}
					else if (SELECT.GROUPBY == 'ANNEEA') {

						if (ROW.COD == ROW.COD2) {
							
							if (ROW.COD1 == annee_toperiode && mois_fin >= parseInt(mois_toperiode)) {
								return SELECT.TOPERIODE;
							}
							else {
								return ROW.COD1 + mois_fin_string;
							}
						}
						else {
							
							if (ROW.COD1 == annee_toperiode) {
								return SELECT.TOPERIODE;
							}
							else {
								return ROW.COD1 + '12';
							}
						}
					}
					else if (SELECT.GROUPBY_2 == 'NUMEROTRIMA'){
						
						if (ROW.COD == ROW.COD2) {
							
							if (mois_fin <= parseInt(mois_toperiode)) {
								return annee_toperiode + mois_fin_string;
							}
							else {
								
								if (mois_debut <= mois_toperiode) {
									return SELECT.TOPERIODE;
								}
								else {
									return (parseInt(annee_toperiode) -1).toString() + mois_fin_string;
								}
							}
						}
						else {
							return SELECT.TOPERIODE;
						}
					} else {
							mois_debut = 1 + 3 * (parseInt(ROW.COD3.substr(-1)) - 1);
							mois_fin = 3 * parseInt(ROW.COD3.substr(-1));
							mois_fin_string = mois_fin < 10 ? '0' + mois_fin.toString() : mois_fin.toString();
						if (ROW.COD == ROW.COD3) {
							
							if (mois_fin <= parseInt(mois_toperiode)) {
								return annee_toperiode + mois_fin_string;
							}
							else {
								
								if (mois_debut <= mois_toperiode) {
									return SELECT.TOPERIODE;
								}
								else {
									return (parseInt(annee_toperiode) -1).toString() + mois_fin_string;
								}
							}
						}
						else {
							return SELECT.TOPERIODE;
						}
					}
				}
				else if (SELECT.GROUPBY == 'ANNEEA'|| SELECT.GROUPBY_2 == 'ANNEEA' || SELECT.GROUPBY_3 == 'ANNEEA' ) {
					
					if(SELECT.GROUPBY == 'ANNEEA'|| SELECT.GROUPBY_2 == 'ANNEEA') {
					
						var row_cod:String = (SELECT.GROUPBY == 'ANNEEA') ? ROW.COD1 : ROW.COD2;
					}else {
						var row_cod:String = ROW.COD3;
					}
					
					if (row_cod == annee_toperiode) {
						return SELECT.TOPERIODE;
					}
					else {
						return row_cod + '12';
					}
				}
			// FIN TRAITEMENT DATE D'ACTIVITE
			// TRAITEMENT DATE SORTIE
			
				if (SELECT.GROUPBY == 'SEMAINEANNE' || SELECT.GROUPBY_2 == 'SEMAINEANNE' || SELECT.GROUPBY_3 == 'SEMAINEANNE' ) {
						if(SELECT.GROUPBY == 'SEMAINEANNE' || SELECT.GROUPBY_2 == 'SEMAINEANNE'){
							row_cod = (SELECT.GROUPBY == 'SEMAINEANNE') ? ROW.COD1 : ROW.COD2;
						}else {
							row_cod = ROW.COD3;
						}
				if (SELECT.GROUPBY == 'ANNEE' || SELECT.GROUPBY_2 == 'ANNEE') {
						var annee:String =  (SELECT.GROUPBY == 'SEMAINEANNE') ?  ROW.COD2.substr(0,4) : ROW.COD1.substr(0,4);
						return getDateFromWeek(annee+row_cod,6);
					}else{
						var date:String = getDateFromWeek(annee_toperiode + row_cod,6);
						var month:int = parseInt(date.substr(5,2));
						var day:int = parseInt(date.substr(8,2));
						var toDay:int = parseInt(SELECT.TOPERIODE.substr(8,2));					
						if (month <= parseInt(mois_toperiode) && day <= toDay) {
							return getDateFromWeek(annee_toperiode+row_cod,6);
						}
						else {
								return getDateFromWeek((parseInt(annee_toperiode)).toString()+row_cod,0);
						}
					}
				}
				if (SELECT.GROUPBY == 'JOURS' || SELECT.GROUPBY_2 == 'JOURS' || SELECT.GROUPBY_3 == 'JOURS') {
					
					if (SELECT.GROUPBY == 'JOURS') {
						return annee_periode+'-'+ROW.COD1;
					}
					else if (ROW.COD == ROW.COD2) {
						return annee_periode+'-'+ROW.COD2;
					}else if(ROW.COD == ROW.COD3) {
						return annee_periode+'-'+ROW.COD3;
					}
				}
				if (SELECT.GROUPBY == 'JOUR' || SELECT.GROUPBY_2 == 'JOUR' || SELECT.GROUPBY_3 == 'JOUR') {
					
					if (SELECT.GROUPBY == 'JOUR') {
						return ROW.COD1;
					}
					else if (ROW.COD == ROW.COD2) {
						return ROW.COD2;
					} else if(ROW.COD == ROW.COD3) {
						return ROW.COD3;
					}
				}
				if (SELECT.GROUPBY == 'MOIS' || SELECT.GROUPBY_2 == 'MOIS' || SELECT.GROUPBY_3 == 'MOIS') {
					
					var mois:String = '';
					
					if (SELECT.GROUPBY == 'MOIS') {
						
						annee = ROW.COD1.substr(0,4);
						mois = ROW.COD1.substr(-2);
						
						if (annee == annee_toperiode && mois == mois_toperiode) {
							return SELECT.TOPERIODE;
						}
						else {
							return annee + mois;
						}
					}
					else if (SELECT.GROUPBY_2 == 'MOIS') {
						
						annee = ROW.COD2.substr(0,4);
						mois = ROW.COD2.substr(-2);
						
						if (ROW.COD == ROW.COD2) {
							
							if (annee == annee_toperiode && mois == mois_toperiode) {
								return SELECT.TOPERIODE;
							}
							else {
								return annee + mois;
							}
						}
						else {
							
							if (SELECT.GROUPBY == 'ANNEE' && ROW.COD1 != annee_toperiode) {
								return ROW.COD1 + '12';
							}
							else {
								return SELECT.TOPERIODE;
							}
						}
					} else if (SELECT.GROUPBY_3 == 'MOIS'){
							annee = ROW.COD3.substr(0,4);
							mois = ROW.COD3.substr(-2);
						
						if (ROW.COD == ROW.COD3) {
							
							if (annee == annee_periode && mois == mois_periode) {
								 return annee + mois;
							}
						}
						else {
							
							if (SELECT.GROUPBY == 'ANNEE' && ROW.COD1 != annee_periode) {
								return ROW.COD1 + '01';
							}
							else {
								return SELECT.PERIODE;
							}
						}
					
					}
				}
				else if (SELECT.GROUPBY == 'NUMEROMOIS' || SELECT.GROUPBY_2 == 'NUMEROMOIS' || SELECT.GROUPBY_3 == 'NUMEROMOIS') {
					
					if (SELECT.GROUPBY == 'NUMEROMOIS') {
						
						if (parseInt(ROW.COD1) <= parseInt(mois_toperiode)) {
							return annee_toperiode + ROW.COD1;
						}
						else {
							return (parseInt(annee_toperiode) - 1).toString() + ROW.COD1;
						}
					}
					else if (SELECT.GROUPBY_2 == 'NUMEROMOIS'){
					
						mois_debut = 1 + 3 * (parseInt(ROW.COD1.substr(-1)) - 1);
						mois_fin = 3 * parseInt(ROW.COD1.substr(-1));
						mois_fin_string = mois_fin < 10 ? '0' + mois_fin.toString() : mois_fin.toString();
						annee = ROW.COD1.substr(0,4);
						
						if (SELECT.GROUPBY == 'ANNEE') {
							
							if (ROW.COD == ROW.COD2) {
								return ROW.COD1 + ROW.COD2;
							}
							else {
								
								if (ROW.COD1 == annee_toperiode) {
									return SELECT.TOPERIODE;
								}
								else {
									return ROW.COD1 + '12';
								}
							}
						}
						else if (SELECT.GROUPBY == 'TRIM') {
						
							if (ROW.COD == ROW.COD2) {
								return annee + ROW.COD2;
							}
							else {
								
								if (annee == annee_toperiode && mois_fin >= parseInt(mois_toperiode)) {
									return SELECT.TOPERIODE;
								}
								else {
									return annee + mois_fin_string;
								}
							}
						}
						else if (SELECT.GROUPBY == 'NUMEROTRIM') {
							
							if (ROW.COD ==  ROW.COD2) {
								
								if (parseInt(ROW.COD2) <= parseInt(mois_toperiode)) {
									return annee_toperiode + ROW.COD2
								}
								else {
									return (parseInt(annee_toperiode) - 1).toString() + ROW.COD2;
								}
							}
							else {
								
								if (mois_fin <= parseInt(mois_toperiode)) {
									return annee_toperiode + mois_fin_string;
								}
								else {
									
									if (mois_debut <= parseInt(mois_toperiode)) {
										return SELECT.TOPERIODE;
									}
									else {
										return (parseInt(annee_toperiode) - 1).toString() + mois_fin_string;
									}
								}
							}
						}
						else {
							
							if (ROW.COD == ROW.COD2) {
								
								if (parseInt(ROW.COD2) <= parseInt(mois_toperiode)) {
									return annee_toperiode + ROW.COD2;
								}
								else {
									return (parseInt(annee_toperiode) - 1).toString() + ROW.COD2;
								}
							}
							else {
								return SELECT.TOPERIODE;
							}
						}
					} else {
							mois_debut = 1 + 3 * (parseInt(ROW.COD2.substr(-1)) - 1);
							mois_fin = 3 * parseInt(ROW.COD2.substr(-1));
							mois_fin_string = mois_fin < 10 ? '0' + mois_fin.toString() : mois_fin.toString();
							annee = ROW.COD2.substr(0,4);
						
						if (SELECT.GROUPBY == 'ANNEE') {
							
							if (ROW.COD == ROW.COD2) {
								return ROW.COD1 + ROW.COD2;
							}
							else {
								
								if (ROW.COD1 == annee_toperiode) {
									return SELECT.TOPERIODE;
								}
								else {
									return ROW.COD1 + '12';
								}
							}
						}
						else if (SELECT.GROUPBY == 'TRIM') {
						
							if (ROW.COD == ROW.COD2) {
								return annee + ROW.COD2;
							}
							else {
								
								if (annee == annee_toperiode && mois_fin >= parseInt(mois_toperiode)) {
									return SELECT.TOPERIODE;
								}
								else {
									return annee + mois_fin_string;
								}
							}
						}
						else if (SELECT.GROUPBY == 'NUMEROTRIM') {
							
							if (ROW.COD ==  ROW.COD2) {
								
								if (parseInt(ROW.COD2) <= parseInt(mois_toperiode)) {
									return annee_toperiode + ROW.COD2
								}
								else {
									return (parseInt(annee_toperiode) - 1).toString() + ROW.COD2;
								}
							}
							else {
								
								if (mois_fin <= parseInt(mois_toperiode)) {
									return annee_toperiode + mois_fin_string;
								}
								else {
									
									if (mois_debut <= parseInt(mois_toperiode)) {
										return SELECT.TOPERIODE;
									}
									else {
										return (parseInt(annee_toperiode) - 1).toString() + mois_fin_string;
									}
								}
							}
						}
						else {
							
							if (ROW.COD == ROW.COD3) {
								
								if (parseInt(ROW.COD3) <= parseInt(mois_toperiode)) {
									return annee_toperiode + ROW.COD3;
								}
								else {
									return (parseInt(annee_toperiode) - 1).toString() + ROW.COD3;
								}
							}
							else {
								return SELECT.TOPERIODE;
							}
						}
					}
				}
				else if (SELECT.GROUPBY == 'TRIM' || SELECT.GROUPBY_2 == 'TRIM' || SELECT.GROUPBY_3 == 'TRIM') {
					
					if (SELECT.GROUPBY == 'TRIM') {
					
						annee = ROW.COD1.substr(0,4);
						mois_fin = 3 * parseInt(ROW.COD1.substr(-1));
						mois_fin_string = mois_fin < 10 ? '0' + mois_fin.toString() : mois_fin.toString();
						
						if (annee == annee_periode && mois_fin >= parseInt(mois_toperiode)) {
							return SELECT.TOPERIODE;
						}
						else {
							return annee + mois_fin_string;
						}
					}
					else if (SELECT.GROUPBY_2 == 'TRIM'){
					
						annee = ROW.COD2.substr(0,4);
						mois_fin = 3 * parseInt(ROW.COD2.substr(-1));
						mois_fin_string = mois_fin < 10 ? '0' + mois_fin.toString() : mois_fin.toString();
						
						if (ROW.COD == ROW.COD2) {
							
							if (annee == annee_toperiode && mois_fin >= parseInt(mois_toperiode)) {
								return SELECT.TOPERIODE;
							}
							else {
								return annee + mois_fin_string;
							}
						}
						else {
							
							if (SELECT.GROUPBY == 'ANNEE' && ROW.COD1 != annee_toperiode) {
								return ROW.COD1 + '12';
							}
							else {
								return SELECT.TOPERIODE;
							}
						}
					} else {
						annee = ROW.COD3.substr(0,4);
						mois_fin = 3 * parseInt(ROW.COD3.substr(-1));
						mois_fin_string = mois_fin < 10 ? '0' + mois_fin.toString() : mois_fin.toString();
						
						if (ROW.COD == ROW.COD3) {
							
							if (annee == annee_toperiode && mois_fin >= parseInt(mois_toperiode)) {
								return SELECT.TOPERIODE;
							}
							else {
								return annee + mois_fin_string;
							}
						}
						else {
							
							if (SELECT.GROUPBY == 'ANNEE' && ROW.COD1 != annee_toperiode) {
								return ROW.COD1 + '12';
							}
							else {
								return SELECT.TOPERIODE;
							}
						}
					}
				}
				else if (SELECT.GROUPBY == 'NUMEROTRIM' || SELECT.GROUPBY_2 == 'NUMEROTRIM' || SELECT.GROUPBY_3 == 'NUMEROTRIM' ) {
					
					mois_debut = 1 + 3 * (parseInt(ROW.COD2.substr(-1)) - 1);
					mois_fin = 3 * parseInt(ROW.COD2.substr(-1));
					mois_fin_string = mois_fin < 10 ? '0' + mois_fin.toString() : mois_fin.toString();
					
					if (SELECT.GROUPBY == 'NUMEROTRIM') {
					
						mois_debut = 1 + 3 * (parseInt(ROW.COD1.substr(-1)) - 1);
						mois_fin = 3 * parseInt(ROW.COD1.substr(-1));
						mois_fin_string = mois_fin < 10 ? '0' + mois_fin.toString() : mois_fin.toString();
						
						if (mois_fin <= parseInt(mois_toperiode)) {
							return annee_toperiode + mois_fin_string;
						}
						else {
							
							if (mois_debut <= parseInt(mois_toperiode)) {
								return SELECT.TOPERIODE;
							}
							else {
								return (parseInt(annee_toperiode) -1).toString() + mois_fin_string;
							}
						}
					}
					else if (SELECT.GROUPBY == 'ANNEE') {

						if (ROW.COD == ROW.COD2) {
							
							if (ROW.COD1 == annee_toperiode && mois_fin >= parseInt(mois_toperiode)) {
								return SELECT.TOPERIODE;
							}
							else {
								return ROW.COD1 + mois_fin_string;
							}
						}
						else {
							
							if (ROW.COD1 == annee_toperiode) {
								return SELECT.TOPERIODE;
							}
							else {
								return ROW.COD1 + '12';
							}
						}
					}
					else if (SELECT.GROUPBY_2 == 'NUMEROTRIM'){
						
						if (ROW.COD == ROW.COD2) {
							
							if (mois_fin <= parseInt(mois_toperiode)) {
								return annee_toperiode + mois_fin_string;
							}
							else {
								
								if (mois_debut <= mois_toperiode) {
									return SELECT.TOPERIODE;
								}
								else {
									return (parseInt(annee_toperiode) -1).toString() + mois_fin_string;
								}
							}
						}
						else {
							return SELECT.TOPERIODE;
						}
					} else {
							mois_debut = 1 + 3 * (parseInt(ROW.COD3.substr(-1)) - 1);
							mois_fin = 3 * parseInt(ROW.COD3.substr(-1));
							mois_fin_string = mois_fin < 10 ? '0' + mois_fin.toString() : mois_fin.toString();
						if (ROW.COD == ROW.COD3) {
							
							if (mois_fin <= parseInt(mois_toperiode)) {
								return annee_toperiode + mois_fin_string;
							}
							else {
								
								if (mois_debut <= mois_toperiode) {
									return SELECT.TOPERIODE;
								}
								else {
									return (parseInt(annee_toperiode) -1).toString() + mois_fin_string;
								}
							}
						}
						else {
							return SELECT.TOPERIODE;
						}
					}
				}
				else if (SELECT.GROUPBY == 'ANNEE'|| SELECT.GROUPBY_2 == 'ANNEE' || SELECT.GROUPBY_3 == 'ANNEE' ) {
					
					if(SELECT.GROUPBY == 'ANNEE'|| SELECT.GROUPBY_2 == 'ANNEE') {
					
						var row_cod:String = (SELECT.GROUPBY == 'ANNEE') ? ROW.COD1 : ROW.COD2;
					}else {
						var row_cod:String = ROW.COD3;
					}
					
					if (row_cod == annee_toperiode) {
						return SELECT.TOPERIODE;
					}
					else {
						return row_cod + '12';
					}
				}
				
				// FIN TRAITEMENT DATE SORTIE
				//DATE DE VENTE
				if (SELECT.GROUPBY == 'SEMAINEANNEV' || SELECT.GROUPBY_2 == 'SEMAINEANNEV' || SELECT.GROUPBY_3 == 'SEMAINEANNEV' ) {
					if(SELECT.GROUPBY == 'SEMAINEANNEV' || SELECT.GROUPBY_2 == 'SEMAINEANNEV'){
							row_cod = (SELECT.GROUPBY == 'SEMAINEANNEV') ? ROW.COD1 : ROW.COD2;
					}else {
							row_cod = ROW.COD3;
					}
					if (SELECT.GROUPBY == 'ANNEEV' || SELECT.GROUPBY_2 == 'ANNEEV') {
							var annee:String =  (SELECT.GROUPBY == 'SEMAINEANNEV') ?  ROW.COD2.substr(0,4) : ROW.COD1.substr(0,4);
							return getDateFromWeek(annee+row_cod,6);
					}
					else 
						{
							var date:String = getDateFromWeek(annee_toperiode + row_cod,6);
							var month:int = parseInt(date.substr(5,2));
							var day:int = parseInt(date.substr(8,2));
							var toDay:int = parseInt(SELECT.TOPERIODE.substr(8,2));		

							if (month <= parseInt(mois_toperiode) && day <= toDay) {
								return getDateFromWeek(annee_toperiode+row_cod,6);
							}
							else {
									return getDateFromWeek((parseInt(annee_toperiode) - 1).toString()+row_cod,6);
							}
						}
				}
				if (SELECT.GROUPBY == 'JOURSV' || SELECT.GROUPBY_2 == 'JOURSV' || SELECT.GROUPBY_3 == 'JOURSV') {
					
					if (SELECT.GROUPBY == 'JOURSV') {
						return annee_periode+'-'+ROW.COD1;
					}
					else if (ROW.COD == ROW.COD2) {
						return annee_periode+'-'+ROW.COD2;
					}else if(ROW.COD == ROW.COD3) {
						return annee_periode+'-'+ROW.COD3;
					}
				}
				if (SELECT.GROUPBY == 'JOURV' || SELECT.GROUPBY_2 == 'JOURV' || SELECT.GROUPBY_3 == 'JOURV') {
					
					if (SELECT.GROUPBY == 'JOURV') {
						return ROW.COD1;
					}
					else if (ROW.COD == ROW.COD2) {
						return ROW.COD2;
					} else if(ROW.COD == ROW.COD3) {
						return ROW.COD3;
					}
				}
				if (SELECT.GROUPBY == 'MOISV' || SELECT.GROUPBY_2 == 'MOISV' || SELECT.GROUPBY_3 == 'MOISV') {
					
					var mois:String = '';
					
					if (SELECT.GROUPBY == 'MOISV') {
						
						annee = ROW.COD1.substr(0,4);
						mois = ROW.COD1.substr(-2);
						
						if (annee == annee_toperiode && mois == mois_toperiode) {
							return SELECT.TOPERIODE;
						}
						else {
							return annee + mois;
						}
					}
					else if (SELECT.GROUPBY_2 == 'MOISV') {
						
						annee = ROW.COD2.substr(0,4);
						mois = ROW.COD2.substr(-2);
						
						if (ROW.COD == ROW.COD2) {
							
							if (annee == annee_toperiode && mois == mois_toperiode) {
								return SELECT.TOPERIODE;
							}
							else {
								return annee + mois;
							}
						}
						else {
							
							if (SELECT.GROUPBY == 'ANNEEV' && ROW.COD1 != annee_toperiode) {
								return ROW.COD1 + '12';
							}
							else {
								return SELECT.TOPERIODE;
							}
						}
					}
					 else if (SELECT.GROUPBY_3 == 'MOISV'){
							annee = ROW.COD3.substr(0,4);
							mois = ROW.COD3.substr(-2);
						
						if (ROW.COD == ROW.COD3) {
							
							if (annee == annee_periode && mois == mois_periode) {
								 return annee + mois;
							}
						}
						else {
							
							if (SELECT.GROUPBY == 'ANNEEV' && ROW.COD1 != annee_periode) {
								return ROW.COD1 + '01';
							}
							else {
								return SELECT.PERIODE;
							}
						}
					
					}
				}
				else if (SELECT.GROUPBY == 'NUMEROMOISV' || SELECT.GROUPBY_2 == 'NUMEROMOISV' || SELECT.GROUPBY_3 == 'NUMEROMOISV') {
					
					if (SELECT.GROUPBY == 'NUMEROMOISV') {
						
						if (parseInt(ROW.COD1) <= parseInt(mois_toperiode)) {
							return annee_toperiode + ROW.COD1;
						}
						else {
							return (parseInt(annee_toperiode) - 1).toString() + ROW.COD1;
						}
					}
					else if (SELECT.GROUPBY_2 == 'NUMEROMOISV'){
					
						mois_debut = 1 + 3 * (parseInt(ROW.COD1.substr(-1)) - 1);
						mois_fin = 3 * parseInt(ROW.COD1.substr(-1));
						mois_fin_string = mois_fin < 10 ? '0' + mois_fin.toString() : mois_fin.toString();
						annee = ROW.COD1.substr(0,4);
						
						if (SELECT.GROUPBY == 'ANNEEV') {
							
							if (ROW.COD == ROW.COD2) {
								return ROW.COD1 + ROW.COD2;
							}
							else {
								
								if (ROW.COD1 == annee_toperiode) {
									return SELECT.TOPERIODE;
								}
								else {
									return ROW.COD1 + '12';
								}
							}
						}
						else if (SELECT.GROUPBY == 'TRIMV') {
						
							if (ROW.COD == ROW.COD2) {
								return annee + ROW.COD2;
							}
							else {
								
								if (annee == annee_toperiode && mois_fin >= parseInt(mois_toperiode)) {
									return SELECT.TOPERIODE;
								}
								else {
									return annee + mois_fin_string;
								}
							}
						}
						else if (SELECT.GROUPBY == 'NUMEROTRIMV') {
							
							if (ROW.COD ==  ROW.COD2) {
								
								if (parseInt(ROW.COD2) <= parseInt(mois_toperiode)) {
									return annee_toperiode + ROW.COD2
								}
								else {
									return (parseInt(annee_toperiode) - 1).toString() + ROW.COD2;
								}
							}
							else {
								
								if (mois_fin <= parseInt(mois_toperiode)) {
									return annee_toperiode + mois_fin_string;
								}
								else {
									
									if (mois_debut <= parseInt(mois_toperiode)) {
										return SELECT.TOPERIODE;
									}
									else {
										return (parseInt(annee_toperiode) - 1).toString() + mois_fin_string;
									}
								}
							}
						}
						else {
							
							if (ROW.COD == ROW.COD2) {
								
								if (parseInt(ROW.COD2) <= parseInt(mois_toperiode)) {
									return annee_toperiode + ROW.COD2;
								}
								else {
									return (parseInt(annee_toperiode) - 1).toString() + ROW.COD2;
								}
							}
							else {
								return SELECT.TOPERIODE;
							}
						}
					} else {
							mois_debut = 1 + 3 * (parseInt(ROW.COD2.substr(-1)) - 1);
							mois_fin = 3 * parseInt(ROW.COD2.substr(-1));
							mois_fin_string = mois_fin < 10 ? '0' + mois_fin.toString() : mois_fin.toString();
							annee = ROW.COD2.substr(0,4);
						
						if (SELECT.GROUPBY == 'ANNEEV') {
							
							if (ROW.COD == ROW.COD2) {
								return ROW.COD1 + ROW.COD2;
							}
							else {
								
								if (ROW.COD1 == annee_toperiode) {
									return SELECT.TOPERIODE;
								}
								else {
									return ROW.COD1 + '12';
								}
							}
						}
						else if (SELECT.GROUPBY == 'TRIMV') {
						
							if (ROW.COD == ROW.COD2) {
								return annee + ROW.COD2;
							}
							else {
								
								if (annee == annee_toperiode && mois_fin >= parseInt(mois_toperiode)) {
									return SELECT.TOPERIODE;
								}
								else {
									return annee + mois_fin_string;
								}
							}
						}
						else if (SELECT.GROUPBY == 'NUMEROTRIMV') {
							
							if (ROW.COD ==  ROW.COD2) {
								
								if (parseInt(ROW.COD2) <= parseInt(mois_toperiode)) {
									return annee_toperiode + ROW.COD2
								}
								else {
									return (parseInt(annee_toperiode) - 1).toString() + ROW.COD2;
								}
							}
							else {
								
								if (mois_fin <= parseInt(mois_toperiode)) {
									return annee_toperiode + mois_fin_string;
								}
								else {
									
									if (mois_debut <= parseInt(mois_toperiode)) {
										return SELECT.TOPERIODE;
									}
									else {
										return (parseInt(annee_toperiode) - 1).toString() + mois_fin_string;
									}
								}
							}
						}
						else {
							
							if (ROW.COD == ROW.COD3) {
								
								if (parseInt(ROW.COD3) <= parseInt(mois_toperiode)) {
									return annee_toperiode + ROW.COD3;
								}
								else {
									return (parseInt(annee_toperiode) - 1).toString() + ROW.COD3;
								}
							}
							else {
								return SELECT.TOPERIODE;
							}
						}
					}
				}
				else if (SELECT.GROUPBY == 'TRIMV' || SELECT.GROUPBY_2 == 'TRIMV' || SELECT.GROUPBY_3 == 'TRIMV') {
					
					if (SELECT.GROUPBY == 'TRIMV') {
					
						annee = ROW.COD1.substr(0,4);
						mois_fin = 3 * parseInt(ROW.COD1.substr(-1));
						mois_fin_string = mois_fin < 10 ? '0' + mois_fin.toString() : mois_fin.toString();
						
						if (annee == annee_periode && mois_fin >= parseInt(mois_toperiode)) {
							return SELECT.TOPERIODE;
						}
						else {
							return annee + mois_fin_string;
						}
					}
					else if (SELECT.GROUPBY_2 == 'TRIMV'){
					
						annee = ROW.COD2.substr(0,4);
						mois_fin = 3 * parseInt(ROW.COD2.substr(-1));
						mois_fin_string = mois_fin < 10 ? '0' + mois_fin.toString() : mois_fin.toString();
						
						if (ROW.COD == ROW.COD2) {
							
							if (annee == annee_toperiode && mois_fin >= parseInt(mois_toperiode)) {
								return SELECT.TOPERIODE;
							}
							else {
								return annee + mois_fin_string;
							}
						}
						else {
							
							if (SELECT.GROUPBY == 'ANNEEV' && ROW.COD1 != annee_toperiode) {
								return ROW.COD1 + '12';
							}
							else {
								return SELECT.TOPERIODE;
							}
						}
					} else {
						annee = ROW.COD3.substr(0,4);
						mois_fin = 3 * parseInt(ROW.COD3.substr(-1));
						mois_fin_string = mois_fin < 10 ? '0' + mois_fin.toString() : mois_fin.toString();
						
						if (ROW.COD == ROW.COD3) {
							
							if (annee == annee_toperiode && mois_fin >= parseInt(mois_toperiode)) {
								return SELECT.TOPERIODE;
							}
							else {
								return annee + mois_fin_string;
							}
						}
						else {
							
							if (SELECT.GROUPBY == 'ANNEEV' && ROW.COD1 != annee_toperiode) {
								return ROW.COD1 + '12';
							}
							else {
								return SELECT.TOPERIODE;
							}
						}
					}
				}
				else if (SELECT.GROUPBY == 'NUMEROTRIMV' || SELECT.GROUPBY_2 == 'NUMEROTRIMV' || SELECT.GROUPBY_3 == 'NUMEROTRIMV' ) {
					
					mois_debut = 1 + 3 * (parseInt(ROW.COD2.substr(-1)) - 1);
					mois_fin = 3 * parseInt(ROW.COD2.substr(-1));
					mois_fin_string = mois_fin < 10 ? '0' + mois_fin.toString() : mois_fin.toString();
					
					if (SELECT.GROUPBY == 'NUMEROTRIMV') {
					
						mois_debut = 1 + 3 * (parseInt(ROW.COD1.substr(-1)) - 1);
						mois_fin = 3 * parseInt(ROW.COD1.substr(-1));
						mois_fin_string = mois_fin < 10 ? '0' + mois_fin.toString() : mois_fin.toString();
						
						if (mois_fin <= parseInt(mois_toperiode)) {
							return annee_toperiode + mois_fin_string;
						}
						else {
							
							if (mois_debut <= parseInt(mois_toperiode)) {
								return SELECT.TOPERIODE;
							}
							else {
								return (parseInt(annee_toperiode) -1).toString() + mois_fin_string;
							}
						}
					}
					else if (SELECT.GROUPBY == 'ANNEEV') {

						if (ROW.COD == ROW.COD2) {
							
							if (ROW.COD1 == annee_toperiode && mois_fin >= parseInt(mois_toperiode)) {
								return SELECT.TOPERIODE;
							}
							else {
								return ROW.COD1 + mois_fin_string;
							}
						}
						else {
							
							if (ROW.COD1 == annee_toperiode) {
								return SELECT.TOPERIODE;
							}
							else {
								return ROW.COD1 + '12';
							}
						}
					}
					else if (SELECT.GROUPBY_2 == 'NUMEROTRIMV'){
						
						if (ROW.COD == ROW.COD2) {
							
							if (mois_fin <= parseInt(mois_toperiode)) {
								return annee_toperiode + mois_fin_string;
							}
							else {
								
								if (mois_debut <= mois_toperiode) {
									return SELECT.TOPERIODE;
								}
								else {
									return (parseInt(annee_toperiode) -1).toString() + mois_fin_string;
								}
							}
						}
						else {
							return SELECT.TOPERIODE;
						}
					} else {
							mois_debut = 1 + 3 * (parseInt(ROW.COD3.substr(-1)) - 1);
							mois_fin = 3 * parseInt(ROW.COD3.substr(-1));
							mois_fin_string = mois_fin < 10 ? '0' + mois_fin.toString() : mois_fin.toString();
						if (ROW.COD == ROW.COD3) {
							
							if (mois_fin <= parseInt(mois_toperiode)) {
								return annee_toperiode + mois_fin_string;
							}
							else {
								
								if (mois_debut <= mois_toperiode) {
									return SELECT.TOPERIODE;
								}
								else {
									return (parseInt(annee_toperiode) -1).toString() + mois_fin_string;
								}
							}
						}
						else {
							return SELECT.TOPERIODE;
						}
					}
				}
				else if (SELECT.GROUPBY == 'ANNEEV'|| SELECT.GROUPBY_2 == 'ANNEEV' || SELECT.GROUPBY_3 == 'ANNEEV' ) {
					
					if(SELECT.GROUPBY == 'ANNEEV'|| SELECT.GROUPBY_2 == 'ANNEEV') {
					
						var row_cod:String = (SELECT.GROUPBY == 'ANNEEV') ? ROW.COD1 : ROW.COD2;
					}else {
						var row_cod:String = ROW.COD3;
					}
					
					if (row_cod == annee_toperiode) {
						return SELECT.TOPERIODE;
					}
					else {
						return row_cod + '12';
					}
				}
				
			// FIN DE VENTE
			// TRAITEMENT DATE FACTURE
					if (SELECT.GROUPBY == 'SEMAINEANNEF' || SELECT.GROUPBY_2 == 'SEMAINEANNEF' || SELECT.GROUPBY_3 == 'SEMAINEANNEF' ) {
						if(SELECT.GROUPBY == 'SEMAINEANNEF' || SELECT.GROUPBY_2 == 'SEMAINEANNEF'){
							row_cod = (SELECT.GROUPBY == 'SEMAINEANNEF') ? ROW.COD1 : ROW.COD2;
						}else {
							row_cod = ROW.COD3;
						}
					if (SELECT.GROUPBY == 'ANNEEF' || SELECT.GROUPBY_2 == 'ANNEEF') {
						var ANNEEF:String =  (SELECT.GROUPBY == 'SEMAINEANNEF') ?  ROW.COD2.substr(0,4) : ROW.COD1.substr(0,4);
						return getDateFromWeek(ANNEEF+row_cod,6);
					}
					else{
						var date:String = getDateFromWeek(annee_toperiode + row_cod,6);
						var month:int = parseInt(date.substr(5,2));
						var day:int = parseInt(date.substr(8,2));
						var toDay:int = parseInt(SELECT.TOPERIODE.substr(8,2));					
						if (month <= parseInt(mois_toperiode) && day <= toDay) {
							return getDateFromWeek(annee_toperiode+row_cod,6);
						}
						else {
								return getDateFromWeek((parseInt(annee_toperiode)).toString()+row_cod,0);
						}
					}
				}
				if (SELECT.GROUPBY == 'JOURSF' || SELECT.GROUPBY_2 == 'JOURSF' || SELECT.GROUPBY_3 == 'JOURSF') {
					
					if (SELECT.GROUPBY == 'JOURSF') {
						return annee_periode+'-'+ROW.COD1;
					}
					else if (ROW.COD == ROW.COD2) {
						return annee_periode+'-'+ROW.COD2;
					}else if(ROW.COD == ROW.COD3) {
						return annee_periode+'-'+ROW.COD3;
					}
				}
				if (SELECT.GROUPBY == 'JOURF' || SELECT.GROUPBY_2 == 'JOURF' || SELECT.GROUPBY_3 == 'JOURF') {
					
					if (SELECT.GROUPBY == 'JOURF') {
						return ROW.COD1;
					}
					else if (ROW.COD == ROW.COD2) {
						return ROW.COD2;
					} else if(ROW.COD == ROW.COD3) {
						return ROW.COD3;
					}
				}
				if (SELECT.GROUPBY == 'MOISF' || SELECT.GROUPBY_2 == 'MOISF' || SELECT.GROUPBY_3 == 'MOISF') {
					
					var mois:String = '';
					
					if (SELECT.GROUPBY == 'MOISF') {
						
						 annee  = ROW.COD1.substr(0,4);
						 mois   = ROW.COD1.substr(-2);
						
						if (annee == annee_toperiode && mois == mois_toperiode) {
							return SELECT.TOPERIODE;
						}
						else {
							return annee + mois;
						}
					}
					else if (SELECT.GROUPBY_2 == 'MOISF') {
						
						annee = ROW.COD2.substr(0,4);
						mois = ROW.COD2.substr(-2);
						
						if (ROW.COD == ROW.COD2) {
							
							if (annee == annee_toperiode && mois == mois_toperiode) {
								return SELECT.TOPERIODE;
							}
							else {
								return annee + mois;
							}
						}
						else {
							
							if (SELECT.GROUPBY == 'ANNEEF' && ROW.COD1 != annee_toperiode) {
								return ROW.COD1 + '12';
							}
							else {
								return SELECT.TOPERIODE;
							}
						}
					} else if (SELECT.GROUPBY_3 == 'MOISF'){
							annee = ROW.COD3.substr(0,4);
							mois = ROW.COD3.substr(-2);
						
						if (ROW.COD == ROW.COD3) {
							
							if (annee== annee_periode && mois == mois_periode) {
								 return annee + mois;
							}
						}
						else {
							
							if (SELECT.GROUPBY == 'ANNEEF' && ROW.COD1 != annee_periode) {
								return ROW.COD1 + '01';
							}
							else {
								return SELECT.PERIODE;
							}
						}
					
					}
				}
				else if (SELECT.GROUPBY == 'NUMEROMOISF' || SELECT.GROUPBY_2 == 'NUMEROMOISF' || SELECT.GROUPBY_3 == 'NUMEROMOISF') {
					
					if (SELECT.GROUPBY == 'NUMEROMOISF') {
						
						if (parseInt(ROW.COD1) <= parseInt(mois_toperiode)) {
							return annee_toperiode + ROW.COD1;
						}
						else {
							return (parseInt(annee_toperiode) - 1).toString() + ROW.COD1;
						}
					}
					else if (SELECT.GROUPBY_2 == 'NUMEROMOISF'){
					
						mois_debut = 1 + 3 * (parseInt(ROW.COD1.substr(-1)) - 1);
						mois_fin = 3 * parseInt(ROW.COD1.substr(-1));
						mois_fin_string = mois_fin < 10 ? '0' + mois_fin.toString() : mois_fin.toString();
						ANNEEF = ROW.COD1.substr(0,4);
						
						if (SELECT.GROUPBY == 'ANNEEF') {
							
							if (ROW.COD == ROW.COD2) {
								return ROW.COD1 + ROW.COD2;
							}
							else {
								
								if (ROW.COD1 == annee_toperiode) {
									return SELECT.TOPERIODE;
								}
								else {
									return ROW.COD1 + '12';
								}
							}
						}
						else if (SELECT.GROUPBY == 'TRIMF') {
						
							if (ROW.COD == ROW.COD2) {
								return ANNEEF + ROW.COD2;
							}
							else {
								
								if (ANNEEF == annee_toperiode && mois_fin >= parseInt(mois_toperiode)) {
									return SELECT.TOPERIODE;
								}
								else {
									return ANNEEF + mois_fin_string;
								}
							}
						}
						else if (SELECT.GROUPBY == 'NUMEROTRIMF') {
							
							if (ROW.COD ==  ROW.COD2) {
								
								if (parseInt(ROW.COD2) <= parseInt(mois_toperiode)) {
									return annee_toperiode + ROW.COD2
								}
								else {
									return (parseInt(annee_toperiode) - 1).toString() + ROW.COD2;
								}
							}
							else {
								
								if (mois_fin <= parseInt(mois_toperiode)) {
									return annee_toperiode + mois_fin_string;
								}
								else {
									
									if (mois_debut <= parseInt(mois_toperiode)) {
										return SELECT.TOPERIODE;
									}
									else {
										return (parseInt(annee_toperiode) - 1).toString() + mois_fin_string;
									}
								}
							}
						}
						else {
							
							if (ROW.COD == ROW.COD2) {
								
								if (parseInt(ROW.COD2) <= parseInt(mois_toperiode)) {
									return annee_toperiode + ROW.COD2;
								}
								else {
									return (parseInt(annee_toperiode) - 1).toString() + ROW.COD2;
								}
							}
							else {
								return SELECT.TOPERIODE;
							}
						}
					} else {
							mois_debut = 1 + 3 * (parseInt(ROW.COD2.substr(-1)) - 1);
							mois_fin = 3 * parseInt(ROW.COD2.substr(-1));
							mois_fin_string = mois_fin < 10 ? '0' + mois_fin.toString() : mois_fin.toString();
							ANNEEF = ROW.COD2.substr(0,4);
						
						if (SELECT.GROUPBY == 'ANNEEF') {
							
							if (ROW.COD == ROW.COD2) {
								return ROW.COD1 + ROW.COD2;
							}
							else {
								
								if (ROW.COD1 == annee_toperiode) {
									return SELECT.TOPERIODE;
								}
								else {
									return ROW.COD1 + '12';
								}
							}
						}
						else if (SELECT.GROUPBY == 'TRIMF') {
						
							if (ROW.COD == ROW.COD2) {
								return ANNEEF + ROW.COD2;
							}
							else {
								
								if (ANNEEF == annee_toperiode && mois_fin >= parseInt(mois_toperiode)) {
									return SELECT.TOPERIODE;
								}
								else {
									return ANNEEF + mois_fin_string;
								}
							}
						}
						else if (SELECT.GROUPBY == 'NUMEROTRIMF') {
							
							if (ROW.COD ==  ROW.COD2) {
								
								if (parseInt(ROW.COD2) <= parseInt(mois_toperiode)) {
									return annee_toperiode + ROW.COD2
								}
								else {
									return (parseInt(annee_toperiode) - 1).toString() + ROW.COD2;
								}
							}
							else {
								
								if (mois_fin <= parseInt(mois_toperiode)) {
									return annee_toperiode + mois_fin_string;
								}
								else {
									
									if (mois_debut <= parseInt(mois_toperiode)) {
										return SELECT.TOPERIODE;
									}
									else {
										return (parseInt(annee_toperiode) - 1).toString() + mois_fin_string;
									}
								}
							}
						}
						else {
							
							if (ROW.COD == ROW.COD3) {
								
								if (parseInt(ROW.COD3) <= parseInt(mois_toperiode)) {
									return annee_toperiode + ROW.COD3;
								}
								else {
									return (parseInt(annee_toperiode) - 1).toString() + ROW.COD3;
								}
							}
							else {
								return SELECT.TOPERIODE;
							}
						}
					}
				}
				else if (SELECT.GROUPBY == 'TRIMF' || SELECT.GROUPBY_2 == 'TRIMF' || SELECT.GROUPBY_3 == 'TRIMF') {
					
					if (SELECT.GROUPBY == 'TRIMF') {
					
						ANNEEF = ROW.COD1.substr(0,4);
						mois_fin = 3 * parseInt(ROW.COD1.substr(-1));
						mois_fin_string = mois_fin < 10 ? '0' + mois_fin.toString() : mois_fin.toString();
						
						if (ANNEEF == annee_periode && mois_fin >= parseInt(mois_toperiode)) {
							return SELECT.TOPERIODE;
						}
						else {
							return ANNEEF + mois_fin_string;
						}
					}
					else if (SELECT.GROUPBY_2 == 'TRIMF'){
					
						ANNEEF = ROW.COD2.substr(0,4);
						mois_fin = 3 * parseInt(ROW.COD2.substr(-1));
						mois_fin_string = mois_fin < 10 ? '0' + mois_fin.toString() : mois_fin.toString();
						
						if (ROW.COD == ROW.COD2) {
							
							if (ANNEEF == annee_toperiode && mois_fin >= parseInt(mois_toperiode)) {
								return SELECT.TOPERIODE;
							}
							else {
								return ANNEEF + mois_fin_string;
							}
						}
						else {
							
							if (SELECT.GROUPBY == 'ANNEEF' && ROW.COD1 != annee_toperiode) {
								return ROW.COD1 + '12';
							}
							else {
								return SELECT.TOPERIODE;
							}
						}
					} else {
						ANNEEF = ROW.COD3.substr(0,4);
						mois_fin = 3 * parseInt(ROW.COD3.substr(-1));
						mois_fin_string = mois_fin < 10 ? '0' + mois_fin.toString() : mois_fin.toString();
						
						if (ROW.COD == ROW.COD3) {
							
							if (ANNEEF == annee_toperiode && mois_fin >= parseInt(mois_toperiode)) {
								return SELECT.TOPERIODE;
							}
							else {
								return ANNEEF + mois_fin_string;
							}
						}
						else {
							
							if (SELECT.GROUPBY == 'ANNEEF' && ROW.COD1 != annee_toperiode) {
								return ROW.COD1 + '12';
							}
							else {
								return SELECT.TOPERIODE;
							}
						}
					}
				}
				else if (SELECT.GROUPBY == 'NUMEROTRIMF' || SELECT.GROUPBY_2 == 'NUMEROTRIMF' || SELECT.GROUPBY_3 == 'NUMEROTRIMF' ) {
					
					mois_debut = 1 + 3 * (parseInt(ROW.COD2.substr(-1)) - 1);
					mois_fin = 3 * parseInt(ROW.COD2.substr(-1));
					mois_fin_string = mois_fin < 10 ? '0' + mois_fin.toString() : mois_fin.toString();
					
					if (SELECT.GROUPBY == 'NUMEROTRIMF') {
					
						mois_debut = 1 + 3 * (parseInt(ROW.COD1.substr(-1)) - 1);
						mois_fin = 3 * parseInt(ROW.COD1.substr(-1));
						mois_fin_string = mois_fin < 10 ? '0' + mois_fin.toString() : mois_fin.toString();
						
						if (mois_fin <= parseInt(mois_toperiode)) {
							return annee_toperiode + mois_fin_string;
						}
						else {
							
							if (mois_debut <= parseInt(mois_toperiode)) {
								return SELECT.TOPERIODE;
							}
							else {
								return (parseInt(annee_toperiode) -1).toString() + mois_fin_string;
							}
						}
					}
					else if (SELECT.GROUPBY == 'ANNEEF') {

						if (ROW.COD == ROW.COD2) {
							
							if (ROW.COD1 == annee_toperiode && mois_fin >= parseInt(mois_toperiode)) {
								return SELECT.TOPERIODE;
							}
							else {
								return ROW.COD1 + mois_fin_string;
							}
						}
						else {
							
							if (ROW.COD1 == annee_toperiode) {
								return SELECT.TOPERIODE;
							}
							else {
								return ROW.COD1 + '12';
							}
						}
					}
					else if (SELECT.GROUPBY_2 == 'NUMEROTRIMF'){
						
						if (ROW.COD == ROW.COD2) {
							
							if (mois_fin <= parseInt(mois_toperiode)) {
								return annee_toperiode + mois_fin_string;
							}
							else {
								
								if (mois_debut <= mois_toperiode) {
									return SELECT.TOPERIODE;
								}
								else {
									return (parseInt(annee_toperiode) -1).toString() + mois_fin_string;
								}
							}
						}
						else {
							return SELECT.TOPERIODE;
						}
					} else {
							mois_debut = 1 + 3 * (parseInt(ROW.COD3.substr(-1)) - 1);
							mois_fin = 3 * parseInt(ROW.COD3.substr(-1));
							mois_fin_string = mois_fin < 10 ? '0' + mois_fin.toString() : mois_fin.toString();
						if (ROW.COD == ROW.COD3) {
							
							if (mois_fin <= parseInt(mois_toperiode)) {
								return annee_toperiode + mois_fin_string;
							}
							else {
								
								if (mois_debut <= mois_toperiode) {
									return SELECT.TOPERIODE;
								}
								else {
									return (parseInt(annee_toperiode) -1).toString() + mois_fin_string;
								}
							}
						}
						else {
							return SELECT.TOPERIODE;
						}
					}
				}
				else if (SELECT.GROUPBY == 'ANNEEF'|| SELECT.GROUPBY_2 == 'ANNEEF' || SELECT.GROUPBY_3 == 'ANNEEF' ) {
					
					if(SELECT.GROUPBY == 'ANNEEF'|| SELECT.GROUPBY_2 == 'ANNEEF') {
					
						var row_cod:String = (SELECT.GROUPBY == 'ANNEEF') ? ROW.COD1 : ROW.COD2;
					}else {
						var row_cod:String = ROW.COD3;
					}
					
					if (row_cod == annee_toperiode) {
						return SELECT.TOPERIODE;
					}
					else {
						return row_cod + '12';
					}
				}else {
                            var to_periode_comparatif:String = SELECT.TOPERIODE;
							if (COLUMN.NAME == 'D1_OLD') {to_periode_comparatif = VIEW.TOPERIODE_D;}
                            if (COLUMN.NAME == 'D1_NOW') {to_periode_comparatif =  SELECT.TOPERIODE;}
                            if (COLUMN.NAME == 'D2_OLD') {to_periode_comparatif =  VIEW.TOPERIODE_D;}
                            if (COLUMN.NAME == 'D2_NOW') {to_periode_comparatif =  SELECT.TOPERIODE;}
                            if (COLUMN.NAME == 'CA_MOY_OLD') {to_periode_comparatif =  VIEW.TOPERIODE_D;}
                            if (COLUMN.NAME == 'CA_MOY_NOW') {to_periode_comparatif =  SELECT.TOPERIODE;}
                            if (COLUMN.NAME == 'F1') {to_periode_comparatif =  SELECT.TOPERIODE}
                            if (COLUMN.NAME == 'F2') {to_periode_comparatif =  SELECT.TOPERIODE}
                            if (COLUMN.NAME == 'F3') {to_periode_comparatif =  SELECT.TOPERIODE}
                            if (COLUMN.NAME == 'F4') {to_periode_comparatif =  SELECT.TOPERIODE}
                            if (COLUMN.NAME == 'F5') {to_periode_comparatif =  SELECT.TOPERIODE}
                            if (COLUMN.NAME == 'F6') {to_periode_comparatif =  SELECT.TOPERIODE}
                            if (COLUMN.NAME == 'F7') {to_periode_comparatif =  SELECT.TOPERIODE}
                            if (COLUMN.NAME == 'F8') {to_periode_comparatif =  SELECT.TOPERIODE}
                            if (COLUMN.NAME == 'F9') {to_periode_comparatif =  SELECT.TOPERIODE}
                            if (COLUMN.NAME == 'F10') {to_periode_comparatif =  SELECT.TOPERIODE}
                            if (COLUMN.NAME == 'F11') {to_periode_comparatif =  SELECT.TOPERIODE}
                            if (COLUMN.NAME == 'F12') {to_periode_comparatif =  SELECT.TOPERIODE}
                            if (COLUMN.NAME == 'F13') {to_periode_comparatif =  SELECT.TOPERIODE}
                            if (COLUMN.NAME == 'F14') {to_periode_comparatif =  SELECT.TOPERIODE}
                            if (COLUMN.NAME == 'F15') {to_periode_comparatif =  SELECT.TOPERIODE}
                            if (COLUMN.NAME == 'D1') {to_periode_comparatif =  VIEW.TOPERIODE_D}
                            if (COLUMN.NAME == 'D2') {to_periode_comparatif =  VIEW.TOPERIODE_D}
                            if (COLUMN.NAME == 'D3') {to_periode_comparatif =  VIEW.TOPERIODE_D}
                            if (COLUMN.NAME == 'D4') {to_periode_comparatif =  VIEW.TOPERIODE_D}
                            if (COLUMN.NAME == 'D5') {to_periode_comparatif =  VIEW.TOPERIODE_D}
                            if (COLUMN.NAME == 'D6') {to_periode_comparatif =  VIEW.TOPERIODE_D}
                            if (COLUMN.NAME == 'D7') {to_periode_comparatif =  VIEW.TOPERIODE_D}
                            if (COLUMN.NAME == 'D8') {to_periode_comparatif =  VIEW.TOPERIODE_D}
                            if (COLUMN.NAME == 'D9') {to_periode_comparatif =  VIEW.TOPERIODE_D}
                            if (COLUMN.NAME == 'D10') {to_periode_comparatif =  VIEW.TOPERIODE_D}
                            if (COLUMN.NAME == 'D11') {to_periode_comparatif =  VIEW.TOPERIODE_D}
                            if (COLUMN.NAME == 'D12') {to_periode_comparatif =  VIEW.TOPERIODE_D}
                            if (COLUMN.NAME == 'D13') {to_periode_comparatif =  VIEW.TOPERIODE_D}
                            if (COLUMN.NAME == 'D14') {to_periode_comparatif =  VIEW.TOPERIODE_D}
                            if (COLUMN.NAME == 'D15') {to_periode_comparatif =  VIEW.TOPERIODE_D}
                            if (COLUMN.NAME == 'L1') {to_periode_comparatif =  VIEW.TOPERIODE_D2}
                            if (COLUMN.NAME == 'L2') {to_periode_comparatif =  VIEW.TOPERIODE_D2}
                            if (COLUMN.NAME == 'L3') {to_periode_comparatif =  VIEW.TOPERIODE_D2}
                            if (COLUMN.NAME == 'L4') {to_periode_comparatif =  VIEW.TOPERIODE_D2}
                            if (COLUMN.NAME == 'L5') {to_periode_comparatif =  VIEW.TOPERIODE_D2}
                            if (COLUMN.NAME == 'L6') {to_periode_comparatif =  VIEW.TOPERIODE_D2}
                            if (COLUMN.NAME == 'L7') {to_periode_comparatif =  VIEW.TOPERIODE_D2}
                            if (COLUMN.NAME == 'L8') {to_periode_comparatif =  VIEW.TOPERIODE_D2}
                            if (COLUMN.NAME == 'L9') {to_periode_comparatif =  VIEW.TOPERIODE_D2}
                            if (COLUMN.NAME == 'L10') {to_periode_comparatif =  VIEW.TOPERIODE_D2}
                            if (COLUMN.NAME == 'L11') {to_periode_comparatif =  VIEW.TOPERIODE_D2}
                            if (COLUMN.NAME == 'L12') {to_periode_comparatif =  VIEW.TOPERIODE_D2}
                            if (COLUMN.NAME == 'L13') {to_periode_comparatif =  VIEW.TOPERIODE_D2}
                            if (COLUMN.NAME == 'L14') {to_periode_comparatif =  VIEW.TOPERIODE_D2}
                            if (COLUMN.NAME == 'L15') {to_periode_comparatif =  VIEW.TOPERIODE_D2}
                            return to_periode_comparatif;
				}
			//FIN TRAITEMENT DATE FACTURE 
				
			]]></value>
		</ARG>
		<ARG name= "ALIAS_PERIODE">
					<value>
						<![CDATA[
							if (SELECT.GROUPBY == 'MOIS') {return '-1';}							
							if (SELECT.GROUPBY_2 == 'MOIS' ) {return '-1';} 
							if (SELECT.GROUPBY_3 == 'MOIS' ) {return '-1';} 
							
							if (SELECT.GROUPBY == 'TRIM') {return '-1';}							
							if (SELECT.GROUPBY_2 == 'TRIM' ) {return '-1';} 
							if (SELECT.GROUPBY_3 == 'TRIM' ) {return '-1';} 
							
							if (SELECT.GROUPBY == 'ANNEE') {return '-1';}							
							if (SELECT.GROUPBY_2 == 'ANNEE' ) {return '-1';} 
							if (SELECT.GROUPBY_3 == 'ANNEE' ) {return '-1';} 
							
							if (SELECT.GROUPBY == 'NUMEROTRIM') {return '-1';}							
							if (SELECT.GROUPBY_2 == 'NUMEROTRIM' ) {return '-1';} 
							if (SELECT.GROUPBY_3 == 'NUMEROTRIM' ) {return '-1';} 
							
							if (SELECT.GROUPBY == 'NUMEROMOIS') {return '-1';}							
							if (SELECT.GROUPBY_2 == 'NUMEROMOIS' ) {return '-1';} 
							if (SELECT.GROUPBY_3 == 'NUMEROMOIS' ) {return '-1';} 
							
							if (SELECT.GROUPBY == 'NUMEROJOUR') {return '-1';}							
							if (SELECT.GROUPBY_2 == 'NUMEROJOUR' ) {return '-1';} 
							if (SELECT.GROUPBY_3 == 'NUMEROJOUR' ) {return '-1';} 
							
							if (SELECT.GROUPBY == 'JOUR') {return '-1';}							
							if (SELECT.GROUPBY_2 == 'JOUR' ) {return '-1';} 
							if (SELECT.GROUPBY_3 == 'JOUR' ) {return '-1';} 
							
							if (SELECT.GROUPBY == 'JOURS') {return '-1';}							
							if (SELECT.GROUPBY_2 == 'JOURS' ) {return '-1';} 
							if (SELECT.GROUPBY_3 == 'JOURS' ) {return '-1';} 
							
							if (SELECT.GROUPBY == 'SEMAINEANNE') {return '-1';}							
							if (SELECT.GROUPBY_2 == 'SEMAINEANNE' ) {return '-1';} 
							if (SELECT.GROUPBY_3 == 'SEMAINEANNE' ) {return '-1';} 
							
							if (SELECT.GROUPBY == 'MOISF') {return '-1';}							
							if (SELECT.GROUPBY_2 == 'MOISF' ) {return '-1';} 
							if (SELECT.GROUPBY_3 == 'MOISF' ) {return '-1';} 
							
							if (SELECT.GROUPBY == 'TRIMF') {return '-1';}							
							if (SELECT.GROUPBY_2 == 'TRIMF' ) {return '-1';} 
							if (SELECT.GROUPBY_3 == 'TRIMF' ) {return '-1';} 
							
							if (SELECT.GROUPBY == 'ANNEEF') {return '-1';}							
							if (SELECT.GROUPBY_2 == 'ANNEEF' ) {return '-1';} 
							if (SELECT.GROUPBY_3 == 'ANNEEF' ) {return '-1';} 
							
							if (SELECT.GROUPBY == 'NUMEROTRIMF') {return '-1';}							
							if (SELECT.GROUPBY_2 == 'NUMEROTRIMF' ) {return '-1';} 
							if (SELECT.GROUPBY_3 == 'NUMEROTRIMF' ) {return '-1';} 
							
							if (SELECT.GROUPBY == 'NUMEROMOISF') {return '-1';}							
							if (SELECT.GROUPBY_2 == 'NUMEROMOISF' ) {return '-1';} 
							if (SELECT.GROUPBY_3 == 'NUMEROMOISF' ) {return '-1';} 
							
							if (SELECT.GROUPBY == 'NUMEROJOURF') {return '-1';}							
							if (SELECT.GROUPBY_2 == 'NUMEROJOURF' ) {return '-1';} 
							if (SELECT.GROUPBY_3 == 'NUMEROJOURF' ) {return '-1';} 
							
							if (SELECT.GROUPBY == 'JOURF') {return '-1';}							
							if (SELECT.GROUPBY_2 == 'JOURF' ) {return '-1';} 
							if (SELECT.GROUPBY_3 == 'JOURF' ) {return '-1';} 
							
							if (SELECT.GROUPBY == 'JOURSF') {return '-1';}							
							if (SELECT.GROUPBY_2 == 'JOURSF' ) {return '-1';} 
							if (SELECT.GROUPBY_3 == 'JOURSF' ) {return '-1';} 
							
							if (SELECT.GROUPBY == 'SEMAINEANNEF') {return '-1';}							
							if (SELECT.GROUPBY_2 == 'SEMAINEANNEF' ) {return '-1';} 
							if (SELECT.GROUPBY_3 == 'SEMAINEANNEF' ) {return '-1';} 
							
							if (SELECT.GROUPBY == 'MOISEX') {return '-1';}							
							if (SELECT.GROUPBY_2 == 'MOISEX' ) {return '-1';} 
							if (SELECT.GROUPBY_3 == 'MOISEX' ) {return '-1';} 
							
							if (SELECT.GROUPBY == 'TRIMEX') {return '-1';}							
							if (SELECT.GROUPBY_2 == 'TRIMEX' ) {return '-1';} 
							if (SELECT.GROUPBY_3 == 'TRIMEX' ) {return '-1';} 
							
							if (SELECT.GROUPBY == 'ANNEEEX') {return '-1';}							
							if (SELECT.GROUPBY_2 == 'ANNEEEX' ) {return '-1';} 
							if (SELECT.GROUPBY_3 == 'ANNEEEX' ) {return '-1';} 
							
							if (SELECT.GROUPBY == 'NUMEROTRIMEX') {return '-1';}							
							if (SELECT.GROUPBY_2 == 'NUMEROTRIMEX' ) {return '-1';} 
							if (SELECT.GROUPBY_3 == 'NUMEROTRIMEX' ) {return '-1';} 
							
							if (SELECT.GROUPBY == 'NUMEROMOISEX') {return '-1';}							
							if (SELECT.GROUPBY_2 == 'NUMEROMOISEX' ) {return '-1';} 
							if (SELECT.GROUPBY_3 == 'NUMEROMOISEX' ) {return '-1';} 
							
							if (SELECT.GROUPBY == 'NUMEROJOUREX') {return '-1';}							
							if (SELECT.GROUPBY_2 == 'NUMEROJOUREX' ) {return '-1';} 
							if (SELECT.GROUPBY_3 == 'NUMEROJOUREX' ) {return '-1';} 
							
							if (SELECT.GROUPBY == 'JOUREX') {return '-1';}							
							if (SELECT.GROUPBY_2 == 'JOUREX' ) {return '-1';} 
							if (SELECT.GROUPBY_3 == 'JOUREX' ) {return '-1';} 
							
							if (SELECT.GROUPBY == 'JOURSEX') {return '-1';}							
							if (SELECT.GROUPBY_2 == 'JOURSEX' ) {return '-1';} 
							if (SELECT.GROUPBY_3 == 'JOURSEX' ) {return '-1';} 
							
							if (SELECT.GROUPBY == 'SEMAINEANNEEX') {return '-1';}							
							if (SELECT.GROUPBY_2 == 'SEMAINEANNEEX' ) {return '-1';} 
							if (SELECT.GROUPBY_3 == 'SEMAINEANNEEX' ) {return '-1';} 
						]]>
					</value>
		</ARG>
		<ARG name="QUELLEDATE">
			<value>
				<![CDATA[
						if(SELECT.QUELLEDATE != '') {return SELECT.QUELLEDATE;}
						if('[GROUPBY]' == 'ANNEEF' || '[GROUPBY]' == 'TRIMF' || '[GROUPBY]' == 'JOURF' || '[GROUPBY]' == 'NUMEROTRIMF' || '[GROUPBY]' == 'NUMEROMOISF' || '[GROUPBY]' == 'NUMEROJOURF' || '[GROUPBY]' == 'SEMAINEANNEF' || '[GROUPBY]' == 'JOURSF' || '[GROUPBY]' == 'SEMAINEWEF' ) {return '2';}
						if('[GROUPBY]' == 'ANNEEEX' || '[GROUPBY]' == 'TRIMEX' || '[GROUPBY]' == 'JOUREX' || '[GROUPBY]' == 'NUMEROTRIMEX' || '[GROUPBY]' == 'NUMEROMOISEX' || '[GROUPBY]' == 'NUMEROJOUREX' || '[GROUPBY]' == 'SEMAINEANNEEX' || '[GROUPBY]' == 'JOURSEX' || '[GROUPBY]' == 'SEMAINEWEEX' ) {return '3';}
						return '1';
				]]>
			</value>
		</ARG>		
		<ARG name="SERVICE_SEJOUR">
			<value>
				<![CDATA[
					if (SELECT.GROUPBY_3.substr(0,6) == 'SORCLS' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID3} 
					if (SELECT.GROUPBY_3 == 'SOR' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'SF' + ROW.OID3} 
					if (SELECT.GROUPBY_2.substr(0,6) == 'SORCLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2} 
					if (SELECT.GROUPBY_2 == 'SOR' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'SF' + ROW.OID2} 
					if (SELECT.GROUPBY.substr(0,6) == 'SORCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1} 
					if (SELECT.GROUPBY == 'SOR') {return 'SF' + ROW.OID1} 
				]]>
			</value>
		</ARG>			
		<ARG name="ETAGE_SEJOUR">
			<value>
				<![CDATA[
					if (SELECT.GROUPBY_3.substr(0,6) == 'ESOCLS' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'LS' + SELECT.GROUPBY_3.substr(6,2) + ROW.OID3} 
					if (SELECT.GROUPBY_3 == 'ESO' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'ET' + ROW.OID3} 
					if (SELECT.GROUPBY_2.substr(0,6) == 'ESOCLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2} 
					if (SELECT.GROUPBY_2 == 'ESO' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'ET' + ROW.OID2} 
					if (SELECT.GROUPBY.substr(0,6) == 'ESOCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1} 
					if (SELECT.GROUPBY == 'ESO') {return 'ET' + ROW.OID1} 
				]]>
			</value>
		</ARG>
		
		<ARG name="MEDECIN_SEJOUR">
			<value>
				<![CDATA[
					if (SELECT.GROUPBY_2.substr(0,6) == 'MDACLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2} 
					if (SELECT.GROUPBY_2 == 'MDA' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'MA' + ROW.OID2} 
					if (SELECT.GROUPBY_2 == 'MED' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'MD' + ROW.OID2} 
					if (SELECT.GROUPBY_2 == 'SPM' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'SP' + ROW.OID2} 
					if (SELECT.GROUPBY_3 == 'MDA' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'MA' + ROW.OID3} 
					if (SELECT.GROUPBY_3 == 'MED' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'MD' + ROW.OID3} 
					if (SELECT.GROUPBY_3 == 'SPM' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'SP' + ROW.OID3}
					if (SELECT.GROUPBY.substr(0,6) == 'MDACLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1} 
					if (SELECT.GROUPBY == 'MDA' && ROW.OID1 != '-9999999') {return 'MA' + ROW.OID1} 
					if (SELECT.GROUPBY == 'MED' && ROW.OID1 != '-9999999') {return 'MD' + ROW.OID1} 
					if (SELECT.GROUPBY == 'SPM' && ROW.OID1 != '-9999999') {return 'SP' + ROW.OID1} 
					;
				]]>
			</value>
		</ARG>
		
		<ARG name="ACTIVITE_SEJOUR">
			<value>
				<![CDATA[
					if (SELECT.GROUPBY_3.substr(0,6) == 'ACTCLS' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'LS' + SELECT.GROUPBY_3.substr(6,2) + ROW.OID3} 
					if (SELECT.GROUPBY_3 == 'ACT' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'AC' + ROW.OID3}
					if (SELECT.GROUPBY_2.substr(0,6) == 'ACTCLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2} 
					if (SELECT.GROUPBY_2 == 'ACT' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'AC' + ROW.OID2} 
					if (SELECT.GROUPBY.substr(0,6) == 'ACTCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1} 
					if (SELECT.GROUPBY == 'ACT') {return 'AC' + ROW.OID1} 
				]]>
			</value>
		</ARG>
		
	<!-- 	<ARG name="UM_SEJOUR">
			<value>
				<![CDATA[
					if (SELECT.GROUPBY_2.substr(0,6) == 'UMDCLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2} 
					if (SELECT.GROUPBY_2 == 'UM' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'UM' + ROW.OID2} 
					if (SELECT.GROUPBY.substr(0,6) == 'UMDCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1} 
					if (SELECT.GROUPBY == 'UM') {return 'UM' + ROW.OID1} 
				]]>
			</value>
		</ARG> -->
		
<!-- 		<ARG name="UF_SEJOUR">
			<value>
				<![CDATA[
					if (SELECT.GROUPBY_3.substr(0,6) == 'UFSCLS' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'LS' + SELECT.GROUPBY_3.substr(6,2) + ROW.OID3} 
					if (SELECT.GROUPBY_3 == 'UFS' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'UF' + ROW.OID3} 
					if (SELECT.GROUPBY_2.substr(0,6) == 'UFSCLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2} 
					if (SELECT.GROUPBY_2 == 'UFS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'UF' + ROW.OID2} 
					if (SELECT.GROUPBY.substr(0,6) == 'UFSCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1} 
					if (SELECT.GROUPBY == 'UFS') {return 'UF' + ROW.OID1} 
				]]>
			</value>
		</ARG> -->
		
		<ARG name="TIERS" value="	if (ROW.OID1 != null &amp; SELECT.GROUPBY == 'TPY') {return 'TP' + ROW.OID1}
									if (ROW.OID1 != null &amp; SELECT.GROUPBY == 'TTP') {return 'TT' + ROW.OID1}
									if (ROW.OID1 != null &amp; SELECT.GROUPBY == 'TRG') {return 'RG' + ROW.OID1}
									if (ROW.OID2 != null &amp; SELECT.GROUPBY_2 == 'TPY') {return 'TP' + ROW.OID2}
									if (ROW.OID2 != null &amp; SELECT.GROUPBY_2 == 'TTP') {return 'TT' + ROW.OID2}
									if (ROW.OID2 != null &amp; SELECT.GROUPBY_2 == 'TRG') {return 'RG' + ROW.OID2}
									if (ROW.OID3 != null &amp; SELECT.GROUPBY_3 == 'TPY') {return 'TP' + ROW.OID3}
									if (ROW.OID3 != null &amp; SELECT.GROUPBY_3 == 'TTP') {return 'TT' + ROW.OID3}
									if (ROW.OID3 != null &amp; SELECT.GROUPBY_3 == 'TRG') {return 'RG' + ROW.OID3}
									if (COLUMN.NAME == 'NNSOL0') {return 'TT0'}
									if (COLUMN.NAME == 'MNSOL0') {return 'TT0'}
									if (COLUMN.NAME == 'DSOL0') {return 'TT0'}
									if (COLUMN.NAME == 'NNSOL1') {return 'TT1'}
									if (COLUMN.NAME == 'MNSOL1') {return 'TT1'}
									if (COLUMN.NAME == 'DSOL1') {return 'TT1'}
									if (COLUMN.NAME == 'NNSOL2') {return 'TT2'}
									if (COLUMN.NAME == 'MNSOL2') {return 'TT2'}
									if (COLUMN.NAME == 'DSOL2') {return 'TT2'}
									return '-1' "/>
		<ARG name="QGROUPE" value="if (COLUMN.NAME == 'NNGRP') {return '1'}
									if (COLUMN.NAME == 'NNFACB') {return '3'}
									if (COLUMN.NAME == 'DGRP') {return '2'}
									return '-1'"/>
		<ARG name="QFACTURE" value="
									if (COLUMN.NAME == 'NNFAC') {return '1'}
                                    if (COLUMN.NAME == 'NNFACBG') {return '1BG'}
									if (COLUMN.NAME == 'NNFACHBG') {return '1HBG'}
									if (COLUMN.NAME == 'NNFACB') {return '1'}
									if (COLUMN.NAME == 'DFAC') {return '2'}
									if (COLUMN.NAME == 'NFACF') {return '2'}
									return '-1'"/>
		<ARG name="QEXPEDIE" value="
									if (COLUMN.NAME == 'NNEXP') {return '1'}
									if (COLUMN.NAME == 'MNEXP') {return '1'}
									if (COLUMN.NAME == 'DEXP') {return '2'}
									if (COLUMN.NAME == 'MEXP') {return '2'}
									if (COLUMN.NAME == 'NFCTEXP') {return '2'}
									return '-1'"/>
		<ARG name="QSOLDE" value="	if (COLUMN.NAME == 'NNSOL') {return '1'}
									if (COLUMN.NAME == 'MNSOL') {return '1'}
									if (COLUMN.NAME == 'DSOL') {return '2'}
									if (COLUMN.NAME == 'NNSOL0') {return '1'}
									if (COLUMN.NAME == 'MNSOL0') {return '1'}
									if (COLUMN.NAME == 'DSOL0') {return '2'}
									if (COLUMN.NAME == 'NNSOL1') {return '1'}
									if (COLUMN.NAME == 'MNSOL1') {return '1'}
									if (COLUMN.NAME == 'DSOL1') {return '2'}
									if (COLUMN.NAME == 'NNSOL2') {return '1'}
									if (COLUMN.NAME == 'MNSOL2') {return '1'}
									if (COLUMN.NAME == 'DSOL2') {return '2'}
									if (COLUMN.NAME == 'NBSOL') {return '2'}
									if (COLUMN.NAME == 'MTSOL') {return '2'}
									return '-1'"/>
				<ARG name="QCLOTURE" value="
										if (COLUMN.NAME == 'NNCLO') {return '1'}
										return '-1'"/>
	</COMPONENT>
	
	<COMPONENT name="PRESTATIONS_BASE_VIEWLINK"  >
        <ARG name="POLE_MOUVEMENT">
			<value>
				<![CDATA[
					if (SELECT.GROUPBY_2.substr(0,6) == 'POLCLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2} 
					if (SELECT.GROUPBY_2 == 'POL' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'DT' + ROW.OID2} 
					if (SELECT.GROUPBY.substr(0,6) == 'POLCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1} 
					if (SELECT.GROUPBY == 'POL') {return 'DT' + ROW.OID1} 
				]]>
			</value>
		</ARG>
		
		
		<ARG name="SERVICE_MOUVEMENT">
			<value>
				<![CDATA[
					if (SELECT.COLUMNBY.substr(0,6) == 'SERCLS' && COLUMN.DATA != '') {return 'LS' + SELECT.GROUPBY.substr(6,2) + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'SER' && COLUMN.DATA != '') {return 'SF' + COLUMN.DATA;} 
					if (SELECT.GROUPBY_2.substr(0,6) == 'SERCLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'SER' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'SF' + ROW.OID2;} 
					if (SELECT.GROUPBY.substr(0,6) == 'SERCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1;} 
					if (SELECT.GROUPBY == 'SER') {return 'SF' + ROW.OID1;} 
				]]>
			</value>
		</ARG>
		
		
		<ARG name="ETAGE_MOUVEMENT">
			<value>
				<![CDATA[
					if (SELECT.COLUMNBY.substr(0,6) == 'ETACLS' && COLUMN.DATA != '') {return 'LS' + SELECT.GROUPBY.substr(6,2) + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'ETA' && COLUMN.DATA != '') {return 'ET' + COLUMN.DATA;} 
					if (SELECT.GROUPBY_2.substr(0,6) == 'ETACLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'ETA' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'ET' + ROW.OID2;} 
					if (SELECT.GROUPBY.substr(0,6) == 'ETACLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1;} 
					if (SELECT.GROUPBY == 'ETA') {return 'ET' + ROW.OID1;} 
				]]>
			</value>
		</ARG>
		
		<ARG name="MEDECIN_MOUVEMENT">
			<value>
				<![CDATA[
					if (SELECT.COLUMNBY.substr(0,6) == 'MDACLS' && COLUMN.DATA != '') {return 'LS' + SELECT.COLUMNBY.substr(6,2) + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'MDA' && COLUMN.DATA != '') {return 'MA' + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'MED' && COLUMN.DATA != '') {return 'MD' + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'SPM' && COLUMN.DATA != '') {return 'SP' + COLUMN.DATA;} 
					if (SELECT.GROUPBY_2.substr(0,6) == 'MDACLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'MDA' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'MA' + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'MED' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'MD' + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'SPM' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'SP' + ROW.OID2;} 
					if (SELECT.GROUPBY.substr(0,6) == 'MDACLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1;} 
					if (SELECT.GROUPBY == 'MDA') {return 'MA' + ROW.OID1;} 
					if (SELECT.GROUPBY == 'MED') {return 'MD' + ROW.OID1;} 
					if (SELECT.GROUPBY == 'SPM') {return 'SP' + ROW.OID1;} 
				]]>
			</value>
		</ARG>
		
		<ARG name="ACTIVITE_MOUVEMENT">
			<value>
				<![CDATA[
					if (SELECT.COLUMNBY.substr(0,6) == 'ACTCLS' && COLUMN.DATA != '') {return 'LS' + SELECT.GROUPBY.substr(6,2) + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'ACT' && COLUMN.DATA != '') {return 'AC' + COLUMN.DATA;} 
					if (SELECT.GROUPBY_2.substr(0,6) == 'ACTCLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'ACT' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'AC' + ROW.OID2;} 
					if (SELECT.GROUPBY.substr(0,6) == 'ACTCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1;} 
					if (SELECT.GROUPBY == 'ACT') {return 'AC' + ROW.OID1;} 
				]]>
			</value>
		</ARG>
		
		<ARG name="UM_MOUVEMENT">
			<value>
				<![CDATA[
					if (SELECT.COLUMNBY.substr(0,6) == 'UMDCLS' && COLUMN.DATA != '') {return 'LS' + SELECT.COLUMNBY.substr(6,2) + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'UM' && COLUMN.DATA != '') {return 'UM' + COLUMN.DATA;} 
					if (SELECT.GROUPBY_2.substr(0,6) == 'UMDCLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'UM' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'UM' + ROW.OID2;} 
					if (SELECT.GROUPBY.substr(0,6) == 'UMDCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1;} 
					if (SELECT.GROUPBY == 'UM') {return 'UM' + ROW.OID1;} 
				]]>
			</value>
		</ARG>
		
		<ARG name="UF_MOUVEMENT">
			<value>
				<![CDATA[
					if (SELECT.COLUMNBY.substr(0,6) == 'UFTCLS' && COLUMN.DATA != '') {return 'LS' + SELECT.COLUMNBY.substr(6,2) + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'UF' && COLUMN.DATA != '') {return 'UF' + COLUMN.DATA;} 
					if (SELECT.GROUPBY_2.substr(0,6) == 'UFTCLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'UF' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'UF' + ROW.OID2;} 
					if (SELECT.GROUPBY.substr(0,6) == 'UFTCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1;} 
					if (SELECT.GROUPBY == 'UF') {return 'UF' + ROW.OID1;} 
				]]>
			</value>
		</ARG>
		
		<ARG name="LIT_MOUVEMENT">
			<value>
				<![CDATA[
					if (SELECT.COLUMNBY.substr(0,6) == 'LITCLS' && COLUMN.DATA != '') {return 'LS' + SELECT.COLUMNBY.substr(6,2) + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'LIT' && COLUMN.DATA != '') {return 'LT' + COLUMN.DATA;} 
					if (SELECT.GROUPBY_2.substr(0,6) == 'LITCLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'LIT' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LT' + ROW.OID2;} 
					if (SELECT.GROUPBY.substr(0,6) == 'LITCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1;} 
					if (SELECT.GROUPBY == 'LIT') {return 'LT' + ROW.OID1} 
				]]>
			</value>
		</ARG>
		
		<ARG name="PRESTATION">
			<value>
				<![CDATA[
					if (SELECT.COLUMNBY.substr(0,6) == 'PRFCLS' && COLUMN.DATA != '') {return 'LS' + SELECT.GROUPBY.substr(6,2) + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'PRF' && COLUMN.DATA != '') {return 'PR' + COLUMN.DATA;}
					if (SELECT.GROUPBY_2.substr(0,6) == 'PRFCLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'PRF' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'PR' + ROW.OID2;} 
					if (SELECT.GROUPBY.substr(0,6) == 'PRFCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1;} 
					if (SELECT.GROUPBY == 'PRF') {return 'PR' + ROW.OID1;} 
				]]>
			</value>
		</ARG>	
		
		<ARG name="UCD">
			<value>
				<![CDATA[
					if (SELECT.COLUMNBY.substr(0,6) == 'UCDCLS' && COLUMN.DATA != '') {return 'LS' + SELECT.GROUPBY.substr(6,2) + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'UCD' && COLUMN.DATA != '') {return 'DT' + COLUMN.DATA;}
					if (SELECT.COLUMNBY == 'UC1' && COLUMN.DATA != '') {return 'D1' + COLUMN.DATA;}
					if (SELECT.COLUMNBY == 'UC2' && COLUMN.DATA != '') {return 'D2' + COLUMN.DATA;}
					if (SELECT.COLUMNBY == 'UC3' && COLUMN.DATA != '') {return 'D3' + COLUMN.DATA;}
					if (SELECT.COLUMNBY == 'UC4' && COLUMN.DATA != '') {return 'D4' + COLUMN.DATA;}
					if (SELECT.COLUMNBY == 'UC5' && COLUMN.DATA != '') {return 'D5' + COLUMN.DATA;}
					if (SELECT.GROUPBY_2.substr(0,6) == 'UCDCLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'UCD' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'DT' + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'UC1' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'D1' + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'UC2' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'D2' + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'UC3' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'D3' + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'UC4' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'D4' + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'UC5' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'D5' + ROW.OID2;} 
					if (SELECT.GROUPBY.substr(0,6) == 'UCDCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1;} 
					if (SELECT.GROUPBY == 'UCD') {return 'DT' + ROW.OID1;} 
					if (SELECT.GROUPBY == 'UC1') {return 'D1' + ROW.OID1;} 
					if (SELECT.GROUPBY == 'UC2') {return 'D2' + ROW.OID1;} 
					if (SELECT.GROUPBY == 'UC3') {return 'D3' + ROW.OID1;} 
					if (SELECT.GROUPBY == 'UC4') {return 'D4' + ROW.OID1;} 
					if (SELECT.GROUPBY == 'UC5') {return 'D5' + ROW.OID1;} 
				]]>
			</value>
		</ARG>	
		
		<ARG name="LPP">
			<value>
				<![CDATA[
					if (SELECT.COLUMNBY.substr(0,6) == 'LPPCLS' && COLUMN.DATA != '') {return 'LS' + SELECT.GROUPBY.substr(6,2) + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'LPP' && COLUMN.DATA != '') {return 'DT' + COLUMN.DATA;}
					if (SELECT.COLUMNBY == 'LP1' && COLUMN.DATA != '') {return 'D1' + COLUMN.DATA;}
					if (SELECT.COLUMNBY == 'LP2' && COLUMN.DATA != '') {return 'D2' + COLUMN.DATA;}
					if (SELECT.COLUMNBY == 'LP3' && COLUMN.DATA != '') {return 'D3' + COLUMN.DATA;}
					if (SELECT.COLUMNBY == 'LP4' && COLUMN.DATA != '') {return 'D4' + COLUMN.DATA;}
					if (SELECT.COLUMNBY == 'LP5' && COLUMN.DATA != '') {return 'D5' + COLUMN.DATA;}
					if (SELECT.GROUPBY_2.substr(0,6) == 'LPPCLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'LPP' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'DT' + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'LP1' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'D1' + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'LP2' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'D2' + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'LP3' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'D3' + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'LP4' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'D4' + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'LP5' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'D5' + ROW.OID2;} 
					if (SELECT.GROUPBY.substr(0,6) == 'LPPCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1;} 
					if (SELECT.GROUPBY == 'LPP') {return 'DT' + ROW.OID1;} 
					if (SELECT.GROUPBY == 'LP1') {return 'D1' + ROW.OID1;} 
					if (SELECT.GROUPBY == 'LP2') {return 'D2' + ROW.OID1;} 
					if (SELECT.GROUPBY == 'LP3') {return 'D3' + ROW.OID1;} 
					if (SELECT.GROUPBY == 'LP4') {return 'D4' + ROW.OID1;} 
					if (SELECT.GROUPBY == 'LP5') {return 'D5' + ROW.OID1;} 
				]]>
			</value>
		</ARG>
		
		<ARG name="RUBRIQUE">
			<value>
				<![CDATA[
					if (SELECT.COLUMNBY.substr(0,6) == 'RUFCLS' && COLUMN.DATA != '') {return 'LS' + SELECT.GROUPBY.substr(6,2) + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'RUF' && COLUMN.DATA != '') {return 'RU' + COLUMN.DATA;}
					if (SELECT.GROUPBY_3.substr(0,6) == 'RUFCLS' && ROW.OID3 != '0' && ROW.OID3 != '-9999999' && ROW.OID3 != '-9999999') {return 'LS' + SELECT.GROUPBY_3.substr(6,1) + ROW.OID3;} 
					if (SELECT.GROUPBY_3 == 'RUF' && ROW.OID3!= '0' && ROW.OID3 != '-9999999') {return 'RU' + ROW.OID3;} 
					if (SELECT.GROUPBY_2.substr(0,6) == 'RUFCLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'RUF' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'RU' + ROW.OID2;} 
					if (SELECT.GROUPBY.substr(0,6) == 'RUFCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1;} 
					if (SELECT.GROUPBY == 'RUF') {return 'RU' + ROW.OID1;} 
				]]>
			</value>
		</ARG>	
		
		<ARG name="COMPTE">
			<value>
				<![CDATA[
					if (SELECT.COLUMNBY.substr(0,6) == 'CPTCLS' && COLUMN.DATA != '') {return 'LS' + SELECT.GROUPBY.substr(6,2) + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'CPT' && COLUMN.DATA != '') {return 'DT' + COLUMN.DATA;}
					if (SELECT.GROUPBY_2.substr(0,6) == 'CPTCLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'CPT' && ROW.OID2 != '-9999999') {return 'DT' + ROW.OID2;} 
					if (SELECT.GROUPBY.substr(0,6) == 'CPTCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1;} 
					if (SELECT.GROUPBY == 'CPT') {return 'DT' + ROW.OID1;} 
				]]>
			</value>
		</ARG>
		<ARG name="GME">
			<value>
				<![CDATA[
					if (SELECT.GROUPBY_3.substr(0,6) == 'GMECLS' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'LS' + SELECT.GROUPBY_3.substr(6,2) + ROW.OID3} 
					if (SELECT.GROUPBY_3 == 'GME' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'GM' + ROW.OID3} 
					if (SELECT.GROUPBY_3 == 'CM' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'CM' + ROW.OID3} 
					if (SELECT.GROUPBY_3 == 'GN' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'GN' + ROW.OID3} 
					if (SELECT.GROUPBY_3 == 'RGME' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'RG' + ROW.OID3} 
					if (SELECT.GROUPBY_2.substr(0,6) == 'GMECLS' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2} 
					if (SELECT.GROUPBY_2 == 'GME' && ROW.OID2 != '-9999999') {return 'GM' + ROW.OID2} 
					if (SELECT.GROUPBY_2 == 'CM' && ROW.OID2 != '-9999999') {return 'CM' + ROW.OID2} 
					if (SELECT.GROUPBY_2 == 'GN' && ROW.OID2 != '-9999999') {return 'GN' + ROW.OID2} 
					if (SELECT.GROUPBY_2 == 'RGME' && ROW.OID2 != '-9999999') {return 'RG' + ROW.OID2} 
					if (SELECT.GROUPBY.substr(0,6) == 'GMECLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1} 
					if (SELECT.GROUPBY == 'GME') {return 'GM' + ROW.OID1} 
					if (SELECT.GROUPBY == 'CM') {return 'CM' + ROW.OID1} 					
					if (SELECT.GROUPBY == 'GN') {return 'GN' + ROW.OID1} 
					if (SELECT.GROUPBY == 'RGME') {return 'RG' + ROW.OID1} 
				]]>
			</value>
		</ARG>
		
		<ARG name="MEDECIN_SEJOUR">
			<value>
				<![CDATA[
					if (SELECT.COLUMNBY.substr(0,6) == 'MDACLS' && COLUMN.DATA != '') {return 'LS' + SELECT.COLUMNBY.substr(6,2) + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'MDA' && COLUMN.DATA != '') {return 'MA' + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'MED' && COLUMN.DATA != '') {return 'MD' + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'SPM' && COLUMN.DATA != '') {return 'SP' + COLUMN.DATA;} 
					if (SELECT.GROUPBY_2.substr(0,6) == 'MDACLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'MDA' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'MA' + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'MED' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'MD' + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'SPM' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'SP' + ROW.OID2;} 
					if (SELECT.GROUPBY.substr(0,6) == 'MDACLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1;} 
					if (SELECT.GROUPBY == 'MDA' && ROW.OID1 !== '-9999999') {return 'MA' + ROW.OID1;} 
					if (SELECT.GROUPBY == 'MED' && ROW.OID1 !== '-9999999') {return 'MD' + ROW.OID1;} 
					if (SELECT.GROUPBY == 'SPM' && ROW.OID1 !== '-9999999') {return 'SP' + ROW.OID1;} 
				]]>
			</value>
		</ARG>
		<ARGS name="QUELMONTANT">
			<value><![CDATA[
				// Indicateurs Facturation et valorisation 	
				var valo_array:Array = new Array('MTENC','NBRUBENC','NBPREENC','NBSEJENC',
												'MTENC1','NBRUBENC1','NBPREENC1','NBSEJENC1',
												'MTENC2','NBRUBENC2','NBPREENC2','NBSEJENC2',
												'MTENC3','NBRUBENC3','NBPREENC3','NBSEJENC3'
												);
				// Indicateurs C.A comptabilisé						
				var compta_array:Array = new Array('MTCPT','MTCPTHBG','MTCPT0','MTCPT1','MTCPT1BG','MTCPT2');
				
				var fact_valo_array:Array = new Array('MTFACENC','NBRUBFACENC','NBPREFACENC','NBSEJFACENC',
													  'FAVNBS','FAVEMC','FAVNBSHC','FAVNBEMCHC','FAVNBSHJ','FAVNBSHA',
													  'FAVNBJ','MMFPVEMC','FAVMTTHC','FAVCAMHC','FAVDMS'
													);
				// Indicateurs Facturation 											
				var fact_array:Array = new Array('MTFAC','MMFACEMC','MMTFAC','FACMTTHC','MFACMTTHC',
												'MMTFACHC','FACMTTHJ','MMTFACHJ','FACMTTHA','MMTFACAU',
												'NBSEJ','NBSEJHC','NBSEJHJ','NBSEJAU','NBFAC','NBRUB','NBPRE','FACNBJ'
												);
								
                if(SELECT.DATA1 != '0' && (COLUMN.NAME == 'D1' || COLUMN.NAME == 'F1' || COLUMN.NAME == 'L1')){
						if (valo_array.indexOf(SELECT.DATA1) >= 0 ) {
							LINKVARIABLES['QUELMONTANT'] = 'VAL';
						}
						else if (compta_array.indexOf(SELECT.DATA1) >= 0) {
							LINKVARIABLES['QUELMONTANT'] = 'CPT';
						}
						else if (fact_valo_array.indexOf(SELECT.DATA1) >= 0) {
							LINKVARIABLES['QUELMONTANT'] =  'FAV';
						}
						else if (fact_array.indexOf(SELECT.DATA1) >= 0) {
							LINKVARIABLES['QUELMONTANT'] =  'FAC';
						}else {
							LINKVARIABLES['QUELMONTANT'] =  'FAV';
						}	
				}else if(SELECT.DATA2 != '0' && (COLUMN.NAME == 'D2' || COLUMN.NAME == 'F2' || COLUMN.NAME == 'L2')){
						if (valo_array.indexOf(SELECT.DATA2) >= 0 ) {
							LINKVARIABLES['QUELMONTANT'] =  'VAL';
						}
						else if (compta_array.indexOf(SELECT.DATA2) >= 0 ) {
							LINKVARIABLES['QUELMONTANT'] =  'CPT';
						}
						else if (fact_valo_array.indexOf(SELECT.DATA2) >= 0) {
							LINKVARIABLES['QUELMONTANT'] =  'FAV';
						}
						else if (fact_array.indexOf(SELECT.DATA2) >= 0) {
							LINKVARIABLES['QUELMONTANT'] = 'FAC';
						}else {
							LINKVARIABLES['QUELMONTANT'] = 'FAV';
						}	
				}else if(SELECT.DATA3 != '0' && (COLUMN.NAME == 'D3' || COLUMN.NAME == 'F3' || COLUMN.NAME == 'L3')){
						if (valo_array.indexOf(SELECT.DATA3) >= 0) {
							LINKVARIABLES['QUELMONTANT'] =  'VAL';
						}
						else if (compta_array.indexOf(SELECT.DATA3) >= 0) {
							LINKVARIABLES['QUELMONTANT'] =  'CPT';
						}
						else if (fact_valo_array.indexOf(SELECT.DATA3) >= 0) {
							LINKVARIABLES['QUELMONTANT'] =  'FAV';
						}
						else if (fact_array.indexOf(SELECT.DATA3) >= 0 ) {
							LINKVARIABLES['QUELMONTANT'] =  'FAC';
						}else {
							LINKVARIABLES['QUELMONTANT'] =  'FAV';
						}	
				}else if(SELECT.DATA4 != '0' && (COLUMN.NAME == 'D4' || COLUMN.NAME == 'F4' || COLUMN.NAME == 'L4')){
						if (valo_array.indexOf(SELECT.DATA4) >= 0) {
							LINKVARIABLES['QUELMONTANT'] = 'VAL';
						}
						else if (compta_array.indexOf(SELECT.DATA4) >= 0) {
							LINKVARIABLES['QUELMONTANT'] =  'CPT';
						}
						else if (fact_valo_array.indexOf(SELECT.DATA4) >= 0 ) {
							LINKVARIABLES['QUELMONTANT'] =  'FAV';
						}
						else if (fact_array.indexOf(SELECT.DATA4) >= 0) {
							LINKVARIABLES['QUELMONTANT'] =  'FAC';
						}else {
							LINKVARIABLES['QUELMONTANT'] =  'FAV';
						}	
				}else if(SELECT.DATA5 != '0' && (COLUMN.NAME == 'D5' || COLUMN.NAME == 'F5' || COLUMN.NAME == 'L5')){
						if (valo_array.indexOf(SELECT.DATA5) >= 0 ) {
							LINKVARIABLES['QUELMONTANT'] =  'VAL';
						}
						else if (compta_array.indexOf(SELECT.DATA5) >= 0 ) {
							LINKVARIABLES['QUELMONTANT'] =  'CPT';
						}
						else if (fact_valo_array.indexOf(SELECT.DATA5) >= 0) {
							LINKVARIABLES['QUELMONTANT'] =  'FAV';
						}
						else if (fact_array.indexOf(SELECT.DATA5) >= 0) {
							LINKVARIABLES['QUELMONTANT'] =  'FAC';
						}else {
							LINKVARIABLES['QUELMONTANT'] =  'FAV';
						}	
				}else if(SELECT.DATA6 != '0' && (COLUMN.NAME == 'D6' || COLUMN.NAME == 'F6' || COLUMN.NAME == 'L6')){
						if (valo_array.indexOf(SELECT.DATA6) >= 0 ) {
							LINKVARIABLES['QUELMONTANT'] =  'VAL';
						}
						else if (compta_array.indexOf(SELECT.DATA6) >= 0) {
							LINKVARIABLES['QUELMONTANT'] =  'CPT';
						}
						else if (fact_valo_array.indexOf(SELECT.DATA6) >= 0 ) {
							LINKVARIABLES['QUELMONTANT'] =  'FAV';
						}
						else if (fact_array.indexOf(SELECT.DATA6) >= 0) {
							LINKVARIABLES['QUELMONTANT'] =  'FAC';
						}else {
							LINKVARIABLES['QUELMONTANT'] =  'FAV';
						}	
				}else if(SELECT.DATA7 != '0' && (COLUMN.NAME == 'D7' || COLUMN.NAME == 'F7' || COLUMN.NAME == 'L7')){
						if (valo_array.indexOf(SELECT.DATA7) >= 0 ) {
							LINKVARIABLES['QUELMONTANT'] =  'VAL';
						}
						else if (compta_array.indexOf(SELECT.DATA7) >= 0) {
							LINKVARIABLES['QUELMONTANT'] =  'CPT';
						}
						else if (fact_valo_array.indexOf(SELECT.DATA7) >= 0 ) {
							LINKVARIABLES['QUELMONTANT'] =  'FAV';
						}
						else if (fact_array.indexOf(SELECT.DATA7) >= 0 ) {
							LINKVARIABLES['QUELMONTANT'] =  'FAC';
						}else {
							LINKVARIABLES['QUELMONTANT'] =  'FAC';
						}	
				}else if(SELECT.DATA8 != '0' && (COLUMN.NAME == 'D8' || COLUMN.NAME == 'F8' || COLUMN.NAME == 'L8')){
						if (valo_array.indexOf(SELECT.DATA8) >= 0 ) {
							LINKVARIABLES['QUELMONTANT'] =  'VAL';
						}
						else if (compta_array.indexOf(SELECT.DATA8) >= 0 ) {
							LINKVARIABLES['QUELMONTANT'] =  'CPT';
						}
						else if (fact_valo_array.indexOf(SELECT.DATA8) >= 0) {
							LINKVARIABLES['QUELMONTANT'] =  'FAV';
						}
						else if (fact_array.indexOf(SELECT.DATA8) >= 0) {
							LINKVARIABLES['QUELMONTANT'] =  'FAC';
						}else {
							LINKVARIABLES['QUELMONTANT'] =  'FAV';
						}	
				}else if(SELECT.DATA9 != '0' && (COLUMN.NAME == 'D9' || COLUMN.NAME == 'F9' || COLUMN.NAME == 'L9')){
						if (valo_array.indexOf(SELECT.DATA9) >= 0 ) {
							LINKVARIABLES['QUELMONTANT'] =  'VAL';
						}
						else if (compta_array.indexOf(SELECT.DATA9) >= 0) {
							LINKVARIABLES['QUELMONTANT'] =  'CPT';
						}
						else if (fact_valo_array.indexOf(SELECT.DATA9) >= 0) {
							LINKVARIABLES['QUELMONTANT'] =  'FAV';
						}
						else if (fact_array.indexOf(SELECT.DATA9) >= 0 ) {
							LINKVARIABLES['QUELMONTANT'] =  'FAC';
						}else {
							LINKVARIABLES['QUELMONTANT'] =  'FAV';
						}	
				}else if(SELECT.DATA10 != '0'  && (COLUMN.NAME == 'D10' || COLUMN.NAME == 'F10' || COLUMN.NAME == 'L10')){
						if (valo_array.indexOf(SELECT.DATA10) >= 0) {
							LINKVARIABLES['QUELMONTANT'] =  'VAL';
						}
						else if (compta_array.indexOf(SELECT.DATA10) >= 0) {
							LINKVARIABLES['QUELMONTANT'] =  'CPT';
						}
						else if (fact_valo_array.indexOf(SELECT.DATA10) >= 0) {
							LINKVARIABLES['QUELMONTANT'] =  'FAV';
						}
						else if (fact_array.indexOf(SELECT.DATA10) >= 0) {
							LINKVARIABLES['QUELMONTANT'] =  'FAC';
						}else {
							LINKVARIABLES['QUELMONTANT'] =  'FAV';
						}	
				}else if(SELECT.DATA011 != '0'  && (COLUMN.NAME == 'D11' || COLUMN.NAME == 'F11' || COLUMN.NAME == 'L11')){
						if (valo_array.indexOf(SELECT.DATA011) >= 0) {
							LINKVARIABLES['QUELMONTANT'] =  'VAL';
						}
						else if (compta_array.indexOf(SELECT.DATA011) >= 0) {
							LINKVARIABLES['QUELMONTANT'] =  'CPT';
						}
						else if (fact_valo_array.indexOf(SELECT.DATA011) >= 0) {
							LINKVARIABLES['QUELMONTANT'] =  'FAV';
						}
						else if (fact_array.indexOf(SELECT.DATA011) >= 0) {
							LINKVARIABLES['QUELMONTANT'] =  'FAC';
						}else {
							LINKVARIABLES['QUELMONTANT'] =  'FAV';
						}	
				}else if(SELECT.DATA012 != '0'  && (COLUMN.NAME == 'D12' || COLUMN.NAME == 'F12' || COLUMN.NAME == 'L12')){
						if (valo_array.indexOf(SELECT.DATA012) >= 0) {
							LINKVARIABLES['QUELMONTANT'] =  'VAL';
						}
						else if (compta_array.indexOf(SELECT.DATA012) >= 0) {
							LINKVARIABLES['QUELMONTANT'] =  'CPT';
						}
						else if (fact_valo_array.indexOf(SELECT.DATA012) >= 0) {
							LINKVARIABLES['QUELMONTANT'] =  'FAV';
						}
						else if (fact_array.indexOf(SELECT.DATA012) >= 0) {
							LINKVARIABLES['QUELMONTANT'] =  'FAC';
						}else {
							LINKVARIABLES['QUELMONTANT'] =  'FAV';
						}	
				}else if(SELECT.DATA013 != '0' && (COLUMN.NAME == 'D13' || COLUMN.NAME == 'F13' || COLUMN.NAME == 'L13')){
						if (valo_array.indexOf(SELECT.DATA013) >= 0 ) {
							LINKVARIABLES['QUELMONTANT'] =  'VAL';
						}
						else if (compta_array.indexOf(SELECT.DATA013) >= 0) {
							LINKVARIABLES['QUELMONTANT'] =  'CPT';
						}
						else if (fact_valo_array.indexOf(SELECT.DATA013) >= 0) {
							LINKVARIABLES['QUELMONTANT'] =  'FAV';
						}
						else if (fact_array.indexOf(SELECT.DATA013) >= 0) {
							LINKVARIABLES['QUELMONTANT'] =  'FAC';
						}else {
							LINKVARIABLES['QUELMONTANT'] =  'FAV';
						}	
				}else if(SELECT.DATA014 != '0'  && (COLUMN.NAME == 'D14' || COLUMN.NAME == 'F14' || COLUMN.NAME == 'L14')){
						if (valo_array.indexOf(SELECT.DATA014) >= 0) {
							LINKVARIABLES['QUELMONTANT'] =  'VAL';
						}
						else if (compta_array.indexOf(SELECT.DATA014) >= 0) {
							LINKVARIABLES['QUELMONTANT'] =  'CPT';
						}
						else if (fact_valo_array.indexOf(SELECT.DATA014) >= 0) {
							LINKVARIABLES['QUELMONTANT'] =  'FAV';
						}
						else if (fact_array.indexOf(SELECT.DATA014) >= 0) {
							LINKVARIABLES['QUELMONTANT'] =  'FAC';
						}else {
							LINKVARIABLES['QUELMONTANT'] =  'FAV';
						}	
				}else if(SELECT.DATA015 != '0' && (COLUMN.NAME == 'D15' || COLUMN.NAME == 'F15' || COLUMN.NAME == 'L15')){
						if (valo_array.indexOf(SELECT.DATA015) >= 0 ) {
							LINKVARIABLES['QUELMONTANT'] =  'VAL';
						}
						else if (compta_array.indexOf(SELECT.DATA015) >= 0) {
							LINKVARIABLES['QUELMONTANT'] =  'CPT';
						}
						else if (fact_valo_array.indexOf(SELECT.DATA015) >= 0) {
							LINKVARIABLES['QUELMONTANT'] =  'FAV';
						}
						else if (fact_array.indexOf(SELECT.DATA015) >= 0) {
							LINKVARIABLES['QUELMONTANT'] =  'FAC';
						}else {
							LINKVARIABLES['QUELMONTANT'] =  'FAV';
						}	
				}else if(SELECT.LS_DATA != '-1'){
                        
						var liste_indicateurs:String = SELECT.LS_DATA;
                        var my_array1:Array = liste_indicateurs.split("=");
                        var my_array:Array = my_array1[1].split(",");
                        var i:int;
                        for(i=0;i<=14;i++){
                            if(my_array[i] != '0' && COLUMN.NAME == 'F'+(i+1)){
                                if (valo_array.indexOf(my_array[i]) >= 0) {
                                    LINKVARIABLES['QUELMONTANT'] = 'VAL';
                                }
                                else if (compta_array.indexOf(my_array[i]) >= 0) {
                                    LINKVARIABLES['QUELMONTANT'] = 'CPT';
                                }
                                else if (fact_valo_array.indexOf(my_array[i] ) >= 0) {
                                    LINKVARIABLES['QUELMONTANT'] = 'FAV';
                                }
                                else if (fact_array.indexOf(my_array[i]) >= 0) {
                                    LINKVARIABLES['QUELMONTANT'] = 'FAC';
                                }else {
                                    LINKVARIABLES['QUELMONTANT'] = 'CPT';
                                }
                            }
                        }
				}   
			]]></value>
		</ARGS>
		
	</COMPONENT>	
	
    
    <COMPONENT name="PRESTATIONS_DATA_VIEWLINK"  >
		<ARGS name="DATA1">
			<value><![CDATA[
			if(SELECT.LS_DATA != '-1'){
				var liste_indicateurs:String = SELECT.LS_DATA;
                var my_array1:Array = liste_indicateurs.split("=");
                var my_array:Array = my_array1[1].split(",");
				var my_array:Array = my_str.split(","); 
			
				LINKVARIABLES['DATA1'] = my_array[0];
				LINKVARIABLES['DATA2'] = my_array[1];
				LINKVARIABLES['DATA3'] = my_array[2];						
				LINKVARIABLES['DATA4'] = my_array[3];
				LINKVARIABLES['DATA5'] = my_array[4];
				LINKVARIABLES['DATA6'] = my_array[5];						
				LINKVARIABLES['DATA7'] = my_array[6];
				LINKVARIABLES['DATA8'] = my_array[7];
				LINKVARIABLES['DATA9'] = my_array[8];						
				LINKVARIABLES['DATA10'] = my_array[9];
				LINKVARIABLES['DATA011'] = my_array[10];
				LINKVARIABLES['DATA012'] = my_array[11];						
				LINKVARIABLES['DATA013'] = my_array[12];
				LINKVARIABLES['DATA014'] = my_array[13];
				LINKVARIABLES['DATA015'] = my_array[14];						
			} else {
					if(SELECT.DATA1 != '0'){
						if(SELECT.QUELLEDATE == '1' || SELECT.QUELLEDATE == '2') { LINKVARIABLES['DATA1'] = 'FAVEMC';
							} else { LINKVARIABLES['DATA1'] = 'FAVNBS';
						}
					}
					if(SELECT.DATA2 != '0'){
					 LINKVARIABLES['DATA2'] ='MTFACENC';
					}
					
					if(SELECT.DATA3 != '0'){ 
						if(SELECT.QUELLEDATE == '1' || SELECT.QUELLEDATE == '2') { LINKVARIABLES['DATA3'] = 'MMFPVEMC';
						} else { LINKVARIABLES['DATA3'] = 'MMTFACENC';
						  }
					}						
					if(SELECT.DATA4 != '0'){ 
						if(SELECT.QUELLEDATE == '1' || SELECT.QUELLEDATE == '2') { LINKVARIABLES['DATA4'] = 'FAVNBEMCHC';
						} else { LINKVARIABLES['DATA3'] = 'FAVNBSHC';
						  }
					}							
					if(SELECT.DATA5 != '0'){ 
						 LINKVARIABLES['DATA5'] = 'FAVMTTHC';
					}						
					if(SELECT.DATA6 != '0'){ 
						LINKVARIABLES['DATA6'] = SELECT.DATA6;	
					}						
					if(SELECT.DATA7 != '0'){ 
						LINKVARIABLES['DATA7'] = SELECT.DATA7;	
					}						
					if(SELECT.DATA8 != '0'){ 

						LINKVARIABLES['DATA8'] = SELECT.DATA8;	
					}						
					if(SELECT.DATA9 != '0'){ 
						LINKVARIABLES['DATA9'] = SELECT.DATA9;	
					}						
					if(SELECT.DATA10 != '0'){ 
						LINKVARIABLES['DATA10'] = SELECT.DATA10;	
					}						
					if(SELECT.DATA011 != '0'){ 
						LINKVARIABLES['DATA011'] = SELECT.DATA011;	
					}						
					if(SELECT.DATA012 != '0'){ 
						LINKVARIABLES['DATA012'] = SELECT.DATA012;	
					}						
					if(SELECT.DATA013 != '0'){ 
						LINKVARIABLES['DATA013'] = SELECT.DATA013;	
					}						
					if(SELECT.DATA014 != '0'){ 
						LINKVARIABLES['DATA014'] = SELECT.DATA014;	
					}						
					if(SELECT.DATA015 != '0'){ 
						LINKVARIABLES['DATA015'] = SELECT.DATA015;	
					}						

			}
			]]></value>
		</ARGS>	
	</COMPONENT>	
	
    <COMPONENT name="PRESTATIONS_ANALYSE_CROISEE_MULTIVIEWLINK" >
		<ARG name="ALIAS_PERIODE" value="return '-1'"/>
		<ARG name="QUELLEDATE" value="return SELECT.QUELLEDATE;"/> 
		<ARG name="DATA" value="'MTFACENC';"/>
		<ARG name="COLUMNBY">
			<value>
				<![CDATA[			
					if(SELECT.QUELLEDATE == '1') {s = 'NUMEROMOISA';}
					if(SELECT.QUELLEDATE == '2') {s = 'NUMEROMOIS';}
					if(SELECT.QUELLEDATE == '3') {s = 'NUMEROMOISF';}
					if(SELECT.QUELLEDATE == '4') {s = 'NUMEROMOISV';}
				return s;
				]]>
			</value>
		</ARG>
		<ARG name="LGROUPBY" value="return SELECT.GROUPBY;"/>
		<ARG name="LGROUPBY_2" value="return SELECT.GROUPBY_2;"/>
		<ARG name="LGROUPBY_3" value="return SELECT.GROUPBY_3;"/>
		<ARG name="GROUPBY">
			<value>
				<![CDATA[			
					if(SELECT.QUELLEDATE == '1') {s = 'ANNEEA';}
					if(SELECT.QUELLEDATE == '2') {s = 'ANNEE';}
					if(SELECT.QUELLEDATE == '3') {s = 'ANNEEF';}
					if(SELECT.QUELLEDATE == '4') {s = 'ANNEEV';}
				return s;
				]]>
			</value>
		</ARG>
		<ARG name="GROUPBY_2" value="if(SELECT.GROUPBY == 'ANNEEA' || SELECT.GROUPBY == 'ANNEE' || SELECT.GROUPBY == 'ANNEEF' || SELECT.GROUPBY == 'ANNEEV' ){return SELECT.GROUPBY_2;} else {return SELECT.GROUPBY;}" />
		<ARG name="GROUPBY_3" value="return '-1';" />
		<ARG name="GROUPBY_TAB" value="'TAB'" />
		<ARG name="COLUMNBYCOUNT" value="'12'" />
	</COMPONENT>
	<COMPONENT name="PRESTATIONS_DER_CUMUL_M_A_MULTIVIEWLINK" >
		<ARG name="ALIAS_PERIODE" value="return '-1';" />
		<ARG name="GROUPBY">
			<value>
				<![CDATA[
					
				var s:String = '';
				switch (SELECT.GROUPBY) {
					case 'ANNEE' :			s = 'NUMEROMOIS'; 		break;
					case 'TRIM' :			s = 'NUMEROMOIS';		break;
					case 'MOIS' :			s = 'NUMEROMOIS';		break;
					case 'NUMEROMOIS' :		s = 'NUMEROMOIS';		break;
					case 'NUMEROTRIM' :		s = 'NUMEROMOIS';		break;
					case 'SEMAINEWE' :		s = 'NUMEROMOIS';		break;
					case 'SEMAINEANNE' :	s = 'NUMEROMOIS';		break;
					case 'NUMEROJOUR' :		s = 'NUMEROMOIS';		break;
					case 'JOURS' :			s = 'NUMEROMOIS';		break;
					case 'JOUR' :			s = 'NUMEROMOIS';		break;
					
					case 'ANNEEF' :			s = 'NUMEROMOISF'; 		break;
					case 'TRIMF' :			s = 'NUMEROMOISF';		break;
					case 'MOISF' :			s = 'NUMEROMOISF';		break;
					case 'NUMEROMOISF' :	s = 'NUMEROMOISF';		break;
					case 'NUMEROTRIMF' :	s = 'NUMEROMOISF';		break;
					case 'SEMAINEWEF' :		s = 'NUMEROMOISF';		break;
					case 'SEMAINEANNEF' :	s = 'NUMEROMOISF';		break;
					case 'NUMEROJOURF' :	s = 'NUMEROMOISF';		break;
					case 'JOURSF' :			s = 'NUMEROMOISF';		break;
					case 'JOURF' :			s = 'NUMEROMOISF';		break;
					
					case 'ANNEEA' :			s = 'NUMEROMOISA'; 		break;
					case 'TRIMA' :			s = 'NUMEROMOISA';		break;
					case 'MOISA' :			s = 'NUMEROMOISA';		break;
					case 'NUMEROMOISA' :	s = 'NUMEROMOISA';		break;
					case 'NUMEROTRIMA' :	s = 'NUMEROMOISA';		break;
					case 'SEMAINEWEA' :		s = 'NUMEROMOISA';		break;
					case 'SEMAINEANNEA' :	s = 'NUMEROMOISA';		break;
					case 'NUMEROJOURA' :	s = 'NUMEROMOISA';		break;
					case 'JOURSA' :			s = 'NUMEROMOISA';		break;
					case 'JOURA' :			s = 'NUMEROMOISA';		break;
					
					case 'ANNEEV' :			s = 'NUMEROMOISV'; 		break;
					case 'TRIMV' :			s = 'NUMEROMOISV';		break;
					case 'MOISV' :			s = 'NUMEROMOISV';		break;
					case 'NUMEROMOISV' :	s = 'NUMEROMOISV';		break;
					case 'NUMEROTRIMV' :	s = 'NUMEROMOISV';		break;
					case 'SEMAINEWEV' :		s = 'NUMEROMOISV';		break;
					case 'SEMAINEANNEV' :	s = 'NUMEROMOISV';		break;
					case 'NUMEROJOURV' :	s = 'NUMEROMOISV';		break;
					case 'JOURSV' :			s = 'NUMEROMOISV';		break;
					case 'JOURV' :			s = 'NUMEROMOISV';		break;
		
					default :
							if(SELECT.QUELLEDATE == 1) {s = 'NUMEROMOISA';			break;}
							if(SELECT.QUELLEDATE == 2) {s = 'NUMEROMOIS';			break;}
							if(SELECT.QUELLEDATE == 3) {s = 'NUMEROMOISF';			break;}
							if(SELECT.QUELLEDATE == 4) {s = 'NUMEROMOISV';			break;}
					
				}
				return s;
				]]>
			</value>
		</ARG>
		<ARG name="GROUPBY_2" value="return '-1';" />
		<ARG name="GROUPBY_3" value="return '-1';" />
		<ARG name="LGROUPBY" value="return SELECT.GROUPBY;" />
		<ARG name="LGROUPBY_2" value="return SELECT.GROUPBY_2;" />
		<ARG name="LGROUPBY_3" value="return SELECT.GROUPBY_3;" />
		<ARG name="DATA1" value="'NBSEJ'" />
		<ARG name="DATA2" value="'MTFACENC'" />
		<ARG name="DATA2" value="'MTFACENC'" />
		<ARG name="DATA3" value="'MTENC'" />
		<ARG name="TYPE_COMPARAISON" value="'2'" />	
	</COMPONENT>
	
	<COMPONENT name="PRESTATIONS_H_BASE_VIEWLINK"  >
	
		<ARG name="PERIODE">
			<value>
				<![CDATA[
					if (SELECT.GROUPBY_3 == 'MOI' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return ROW.OID3;}
					if (SELECT.GROUPBY_2 == 'MOI' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return ROW.OID2;}
					if (SELECT.GROUPBY == 'MOI') {return ROW.OID1;} 
					return SELECT.PERIODE;
				]]>
			</value>
		</ARG>
		
		<ARG name="TOPERIODE">
			<value>
				<![CDATA[
                    if (SELECT.GROUPBY_3 == 'MOI' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return ROW.OID3;}
					if (SELECT.GROUPBY_2 == 'MOI' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return ROW.OID2;} 
					if (SELECT.GROUPBY == 'MOI') {return ROW.OID1;} 
					return SELECT.TOPERIODE;
				]]>
			</value>
		</ARG>
        <ARG name="POLE_MOUVEMENT">
			<value>
				<![CDATA[
					if (SELECT.GROUPBY_3.substr(0,6) == 'POLCLS' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'LS' + SELECT.GROUPBY_3.substr(6,2) + ROW.OID3} 
                    if (SELECT.GROUPBY_3 == 'POL' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'DT' + ROW.OID3;}
					if (SELECT.GROUPBY_2.substr(0,6) == 'POLCLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2} 
					if (SELECT.GROUPBY_2 == 'POL' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'DT' + ROW.OID2} 
					if (SELECT.GROUPBY.substr(0,6) == 'POLCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1} 
					if (SELECT.GROUPBY == 'POL') {return 'DT' + ROW.OID1} 
				]]>
			</value>
		</ARG>
				
		<ARG name="SERVICE_MOUVEMENT">
			<value>
				<![CDATA[
					if (SELECT.COLUMNBY.substr(0,6) == 'SERCLS' && COLUMN.DATA != '') {return 'LS' + SELECT.GROUPBY.substr(6,2) + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'SER' && COLUMN.DATA != '') {return 'SF' + COLUMN.DATA;} 
					if (SELECT.GROUPBY_3.substr(0,6) == 'SERCLS' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'LS' + SELECT.GROUPBY_3.substr(6,2) + ROW.OID3;} 
					if (SELECT.GROUPBY_3 == 'SER' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'SF' + ROW.OID3;}
                    if (SELECT.GROUPBY_2.substr(0,6) == 'SERCLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'SER' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'SF' + ROW.OID2;} 
					if (SELECT.GROUPBY.substr(0,6) == 'SERCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1;} 
					if (SELECT.GROUPBY == 'SER') {return 'SF' + ROW.OID1;} 
				]]>
			</value>
		</ARG>
		
		<ARG name="ETAGE_MOUVEMENT">
			<value>
				<![CDATA[
					if (SELECT.COLUMNBY.substr(0,6) == 'ETACLS' && COLUMN.DATA != '') {return 'LS' + SELECT.GROUPBY.substr(6,2) + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'ETA' && COLUMN.DATA != '') {return 'ET' + COLUMN.DATA;} 
					if (SELECT.GROUPBY_3.substr(0,6) == 'ETACLS' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'LS' + SELECT.GROUPBY_3.substr(6,2) + ROW.OID3;} 
					if (SELECT.GROUPBY_3 == 'ETA' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'ET' + ROW.OID3;}
                    if (SELECT.GROUPBY_2.substr(0,6) == 'ETACLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'ETA' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'ET' + ROW.OID2;} 
					if (SELECT.GROUPBY.substr(0,6) == 'ETACLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1;} 
					if (SELECT.GROUPBY == 'ETA') {return 'ET' + ROW.OID1;} 
				]]>
			</value>
		</ARG>
		
		<ARG name="MEDECIN_MOUVEMENT">
			<value>
				<![CDATA[
					if (SELECT.COLUMNBY.substr(0,6) == 'MDACLS' && COLUMN.DATA != '') {return 'LS' + SELECT.COLUMNBY.substr(6,2) + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'MDA' && COLUMN.DATA != '') {return 'MA' + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'MED' && COLUMN.DATA != '') {return 'MD' + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'SPM' && COLUMN.DATA != '') {return 'SP' + COLUMN.DATA;} 
					if (SELECT.GROUPBY_3.substr(0,6) == 'MDACLS' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'LS' + SELECT.GROUPBY_3.substr(6,2) + ROW.OID3;} 
					if (SELECT.GROUPBY_3 == 'MDA' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'MA' + ROW.OID3;} 
					if (SELECT.GROUPBY_3 == 'MED' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'MD' + ROW.OID3;} 
					if (SELECT.GROUPBY_3 == 'SPM' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'SP' + ROW.OID3;}
                    if (SELECT.GROUPBY_2.substr(0,6) == 'MDACLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'MDA' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'MA' + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'MED' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'MD' + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'SPM' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'SP' + ROW.OID2;} 
					if (SELECT.GROUPBY.substr(0,6) == 'MDACLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1;} 
					if (SELECT.GROUPBY == 'MDA') {return 'MA' + ROW.OID1;} 
					if (SELECT.GROUPBY == 'MED') {return 'MD' + ROW.OID1;} 
					if (SELECT.GROUPBY == 'SPM') {return 'SP' + ROW.OID1;} 
				]]>
			</value>
		</ARG>
		
		<ARG name="ACTIVITE_MOUVEMENT">
			<value>
				<![CDATA[
					if (SELECT.COLUMNBY.substr(0,6) == 'ACTCLS' && COLUMN.DATA != '') {return 'LS' + SELECT.GROUPBY.substr(6,2) + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'ACT' && COLUMN.DATA != '') {return 'AC' + COLUMN.DATA;} 
					if (SELECT.GROUPBY_3.substr(0,6) == 'ACTCLS' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'LS' + SELECT.GROUPBY_3.substr(6,2) + ROW.OID3;} 
					if (SELECT.GROUPBY_3 == 'ACT' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'AC' + ROW.OID3;}
                    if (SELECT.GROUPBY_2.substr(0,6) == 'ACTCLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'ACT' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'AC' + ROW.OID2;} 
					if (SELECT.GROUPBY.substr(0,6) == 'ACTCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1;} 
					if (SELECT.GROUPBY == 'ACT') {return 'AC' + ROW.OID1;} 
				]]>
			</value>
		</ARG>
		
		<ARG name="UM_MOUVEMENT">
			<value>
				<![CDATA[
					if (SELECT.COLUMNBY.substr(0,6) == 'UMDCLS' && COLUMN.DATA != '') {return 'LS' + SELECT.COLUMNBY.substr(6,2) + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'UM' && COLUMN.DATA != '') {return 'UM' + COLUMN.DATA;} 
					if (SELECT.GROUPBY_3.substr(0,6) == 'UMDCLS' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'LS' + SELECT.GROUPBY_3.substr(6,2) + ROW.OID3;} 
					if (SELECT.GROUPBY_3 == 'UM' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'UM' + ROW.OID3;}
                    if (SELECT.GROUPBY_2.substr(0,6) == 'UMDCLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'UM' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'UM' + ROW.OID2;} 
					if (SELECT.GROUPBY.substr(0,6) == 'UMDCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1;} 
					if (SELECT.GROUPBY == 'UM') {return 'UM' + ROW.OID1;} 
				]]>
			</value>
		</ARG>
		
		<ARG name="UF_MOUVEMENT">
			<value>
				<![CDATA[
					if (SELECT.COLUMNBY.substr(0,6) == 'UFTCLS' && COLUMN.DATA != '') {return 'LS' + SELECT.COLUMNBY.substr(6,2) + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'UF' && COLUMN.DATA != '') {return 'UF' + COLUMN.DATA;} 
					if (SELECT.GROUPBY_3.substr(0,6) == 'UFTCLS' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'LS' + SELECT.GROUPBY_3.substr(6,2) + ROW.OID3;} 
					if (SELECT.GROUPBY_3== 'UF' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'UF' + ROW.OID3;}
                    if (SELECT.GROUPBY_2.substr(0,6) == 'UFTCLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'UF' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'UF' + ROW.OID2;} 
					if (SELECT.GROUPBY.substr(0,6) == 'UFTCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1;} 
					if (SELECT.GROUPBY == 'UF') {return 'UF' + ROW.OID1;} 
				]]>
			</value>
		</ARG>
		
		<ARG name="LIT_MOUVEMENT">
			<value>
				<![CDATA[
					if (SELECT.COLUMNBY.substr(0,6) == 'LITCLS' && COLUMN.DATA != '') {return 'LS' + SELECT.COLUMNBY.substr(6,2) + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'LIT' && COLUMN.DATA != '') {return 'LT' + COLUMN.DATA;} 
					if (SELECT.GROUPBY_3.substr(0,6) == 'LITCLS' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID3;} 
					if (SELECT.GROUPBY_3 == 'LIT' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'LT' + ROW.OID3;}
                    if (SELECT.GROUPBY_2.substr(0,6) == 'LITCLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'LIT' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LT' + ROW.OID2;} 
					if (SELECT.GROUPBY.substr(0,6) == 'LITCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1;} 
					if (SELECT.GROUPBY == 'LIT') {return 'LT' + ROW.OID1;} 
				]]>
			</value>
		</ARG>
		
		<ARG name="PRESTATION">
			<value>
				<![CDATA[
					if (SELECT.COLUMNBY.substr(0,6) == 'PRFCLS' && COLUMN.DATA != '') {return 'LS' + SELECT.GROUPBY.substr(6,2) + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'PRF' && COLUMN.DATA != '') {return 'PR' + COLUMN.DATA; }
					if (SELECT.GROUPBY_3.substr(0,6) == 'PRFCLS' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'LS' + SELECT.GROUPBY_3.substr(6,2) + ROW.OID3;} 
					if (SELECT.GROUPBY_3 == 'PRF' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'PR' + ROW.OID3;}
                    if (SELECT.GROUPBY_2.substr(0,6) == 'PRFCLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'PRF' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'PR' + ROW.OID2;} 
					if (SELECT.GROUPBY.substr(0,6) == 'PRFCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1;} 
					if (SELECT.GROUPBY == 'PRF') {return 'PR' + ROW.OID1;} 
				]]>
			</value>
		</ARG>	
		
		<ARG name="RUBRIQUE">
			<value>
				<![CDATA[
					if (SELECT.COLUMNBY.substr(0,6) == 'RUFCLS' && COLUMN.DATA != '') {return 'LS' + SELECT.GROUPBY.substr(6,2) + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'RUF' && COLUMN.DATA != '') {return 'RU' + COLUMN.DATA; }
					if (SELECT.GROUPBY_3.substr(0,6) == 'RUFCLS' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'LS' + SELECT.GROUPBY_3.substr(6,2) + ROW.OID3;} 
					if (SELECT.GROUPBY_3 == 'RUF' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'RU' + ROW.OID3;}
                    if (SELECT.GROUPBY_2.substr(0,6) == 'RUFCLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'RUF' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'RU' + ROW.OID2;} 
					if (SELECT.GROUPBY.substr(0,6) == 'RUFCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1;} 
					if (SELECT.GROUPBY == 'RUF') {return 'RU' + ROW.OID1;} 
				]]>
			</value>
		</ARG>
		
		<ARG name="ACTE">
			<value>
				<![CDATA[
					if (SELECT.COLUMNBY.substr(0,6) == 'ACXCLS' && COLUMN.DATA != '') {return 'LS' + SELECT.GROUPBY.substr(6,2) + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'ACTE' && COLUMN.DATA != '') {return 'AC' + COLUMN.DATA; }
					if (SELECT.GROUPBY_3.substr(0,6) == 'ACXCLS' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'LS' + SELECT.GROUPBY_3.substr(6,2) + ROW.OID3;} 
					if (SELECT.GROUPBY_3 == 'ACTE' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'AC' + ROW.OID3;}
                    if (SELECT.GROUPBY_2.substr(0,6) == 'ACXCLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'ACTE' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'AC' + ROW.OID2;} 
					if (SELECT.GROUPBY.substr(0,6) == 'ACXCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1;} 
					if (SELECT.GROUPBY == 'ACTE') {return 'AC' + ROW.OID1;} 
				]]>
			</value>
		</ARG>
		
		<ARG name="PROTOCOLE">
			<value>
				<![CDATA[
					if (SELECT.COLUMNBY.substr(0,6) == 'PROCLS' && COLUMN.DATA != '') {return 'LS' + SELECT.GROUPBY.substr(6,2) + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'PROT' && COLUMN.DATA != '') {return 'DT' + COLUMN.DATA; }
					if (SELECT.GROUPBY_3.substr(0,6) == 'PROCLS' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'LS' + SELECT.GROUPBY_3.substr(6,2) + ROW.OID3;} 
					if (SELECT.GROUPBY_3 == 'PROT' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'DT' + ROW.OID3;} 
					if (SELECT.GROUPBY_2.substr(0,6) == 'PROCLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'PROT' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'DT' + ROW.OID2;} 
					if (SELECT.GROUPBY.substr(0,6) == 'PROCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1;} 
					if (SELECT.GROUPBY == 'PROT') {return 'DT' + ROW.OID1;} 
				]]>
			</value>
		</ARG>
		
		<ARG name="MEDECINEXECUTANT">
			<value>
				<![CDATA[
					if (SELECT.COLUMNBY.substr(0,6) == 'EXACLS' && COLUMN.DATA != '') {return 'LS' + SELECT.COLUMNBY.substr(6,2) + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'EXAF' && COLUMN.DATA != '') {return 'MA' + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'EXEF' && COLUMN.DATA != '') {return 'MD' + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'EXAC' && COLUMN.DATA != '') {return 'MA' + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'EXEC' && COLUMN.DATA != '') {return 'MD' + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'SPMF' && COLUMN.DATA != '') {return 'SP' + COLUMN.DATA;}

					if (SELECT.GROUPBY_3.substr(0,6) == 'EXACLS' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'LS' + SELECT.GROUPBY_3.substr(6,2) + ROW.OID3;} 
					if (SELECT.GROUPBY_3 == 'EXAF' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'MA' + ROW.OID3;} 
					if (SELECT.GROUPBY_3 == 'EXEF' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'MD' + ROW.OID3;} 
					if (SELECT.GROUPBY_3 == 'EXAC' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'MA' + ROW.OID3;} 
					if (SELECT.GROUPBY_3 == 'EXEC' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'MD' + ROW.OID3;} 
					if (SELECT.GROUPBY_3 == 'SPMF' && ROW.OID3 != '0' && ROW.OID3 != '-9999999') {return 'SP' + ROW.OID3;} 
                    
                    if (SELECT.GROUPBY_2.substr(0,6) == 'EXACLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'EXAF' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'MA' + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'EXEF' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'MD' + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'EXAC' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'MA' + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'EXEC' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'MD' + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'SPMF' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'SP' + ROW.OID2;} 
                    
					if (SELECT.GROUPBY.substr(0,6) == 'EXACLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1;} 
					if (SELECT.GROUPBY == 'EXAF') {return 'MA' + ROW.OID1;} 
					if (SELECT.GROUPBY == 'EXEF') {return 'MD' + ROW.OID1;} 
					if (SELECT.GROUPBY == 'EXAC') {return 'MA' + ROW.OID1;} 
					if (SELECT.GROUPBY == 'EXEC') {return 'MD' + ROW.OID1;} 
					if (SELECT.GROUPBY == 'SPMF') {return 'SP' + ROW.OID1;} 
				]]>
			</value>
		</ARG>
		
	</COMPONENT>
	
	<COMPONENT name="COMPTE_CLIENT_BASE_VIEWLINK"  >
	
		<ARG name="PERIODE">
			<value>
				<![CDATA[
					if (SELECT.GROUPBY_2 == 'MOI' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return ROW.OID2;} 
					if (SELECT.GROUPBY == 'MOI') {return ROW.OID1;} 
					return SELECT.PERIODE;
				]]>
			</value>
		</ARG>
		
		<ARG name="TOPERIODE">
			<value>
				<![CDATA[
					if (SELECT.GROUPBY_2 == 'MOI' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return ROW.OID2;} 
					if (SELECT.GROUPBY == 'MOI') {return ROW.OID1;} 
					return SELECT.TOPERIODE;
				]]>
			</value>
		</ARG>
		
		
		<ARG name="SERVICE_SEJOUR">
			<value>
				<![CDATA[
					if (SELECT.COLUMNBY.substr(0,6) == 'SERCLS' && COLUMN.DATA != '') {return 'LS' + SELECT.GROUPBY.substr(6,2) + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'SER' && COLUMN.DATA != '') {return 'SF' + COLUMN.DATA;} 
					if (SELECT.GROUPBY_2.substr(0,6) == 'SERCLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'SER' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'SF' + ROW.OID2;} 
					if (SELECT.GROUPBY.substr(0,6) == 'SERCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1;} 
					if (SELECT.GROUPBY == 'SER') {return 'SF' + ROW.OID1;} 
				]]>
			</value>
		</ARG>
				
		<ARG name="ETAGE_SEJOUR">
			<value>
				<![CDATA[
					if (SELECT.COLUMNBY.substr(0,6) == 'ESOCLS' && COLUMN.DATA != '') {return 'LS' + SELECT.GROUPBY.substr(6,2) + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'ETA' && COLUMN.DATA != '') {return 'ET' + COLUMN.DATA;} 
					if (SELECT.GROUPBY_2.substr(0,6) == 'ESOCLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'ETA' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'ET' + ROW.OID2;} 
					if (SELECT.GROUPBY.substr(0,6) == 'ESOCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1;} 
					if (SELECT.GROUPBY == 'ETA') {return 'ET' + ROW.OID1;} 
				]]>
			</value>
		</ARG>
		
		<ARG name="MEDECIN_SEJOUR">
			<value>
				<![CDATA[
					if (SELECT.COLUMNBY.substr(0,6) == 'MDACLS' && COLUMN.DATA != '') {return 'LS' + SELECT.COLUMNBY.substr(6,2) + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'MDA' && COLUMN.DATA != '') {return 'MA' + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'MED' && COLUMN.DATA != '') {return 'MD' + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'SPM' && COLUMN.DATA != '') {return 'SP' + COLUMN.DATA;} 
					if (SELECT.GROUPBY_2.substr(0,6) == 'MDACLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'MDA' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'MA' + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'MED' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'MD' + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'SPM' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'SP' + ROW.OID2;} 
					if (SELECT.GROUPBY.substr(0,6) == 'MDACLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1;} 
					if (SELECT.GROUPBY == 'MDA' && ROW.OID1 != '-9999999') {return 'MA' + ROW.OID1;} 
					if (SELECT.GROUPBY == 'MED' && ROW.OID1 != '-9999999') {return 'MD' + ROW.OID1;} 
					if (SELECT.GROUPBY == 'SPM' && ROW.OID1 != '-9999999') {return 'SP' + ROW.OID1;} 
					return "-1";
				]]>
			</value>
		</ARG>
		
		<ARG name="ACTIVITE_SEJOUR">
			<value>
				<![CDATA[
					if (SELECT.COLUMNBY.substr(0,6) == 'ACTCLS' && COLUMN.DATA != '') {return 'LS' + SELECT.GROUPBY.substr(6,2) + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'ACT' && COLUMN.DATA != '') {return 'AC' + COLUMN.DATA;} 
					if (SELECT.GROUPBY_2.substr(0,6) == 'ACTCLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'ACT' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'AC' + ROW.OID2;} 
					if (SELECT.GROUPBY.substr(0,6) == 'ACTCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1;} 
					if (SELECT.GROUPBY == 'ACT') {return 'AC' + ROW.OID1;} 
				]]>
			</value>
		</ARG>
		
		<ARG name="UM_SEJOUR">
			<value>
				<![CDATA[
					if (SELECT.COLUMNBY.substr(0,6) == 'UMDCLS' && COLUMN.DATA != '') {return 'LS' + SELECT.COLUMNBY.substr(6,2) + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'UM' && COLUMN.DATA != '') {return 'UM' + COLUMN.DATA;} 
					if (SELECT.GROUPBY_2.substr(0,6) == 'UMDCLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'UM' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'UM' + ROW.OID2;} 
					if (SELECT.GROUPBY.substr(0,6) == 'UMDCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1;} 
					if (SELECT.GROUPBY == 'UM') {return 'UM' + ROW.OID1;} 
				]]>
			</value>
		</ARG>
		
		<ARG name="UF_SEJOUR">
			<value>
				<![CDATA[
					if (SELECT.COLUMNBY.substr(0,6) == 'UFTCLS' && COLUMN.DATA != '') {return 'LS' + SELECT.COLUMNBY.substr(6,2) + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'UF' && COLUMN.DATA != '') {return 'UF' + COLUMN.DATA;} 
					if (SELECT.GROUPBY_2.substr(0,6) == 'UFTCLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'UF' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'UF' + ROW.OID2;} 
					if (SELECT.GROUPBY.substr(0,6) == 'UFTCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1;} 
					if (SELECT.GROUPBY == 'UF') {return 'UF' + ROW.OID1;} 
				]]>
			</value>
		</ARG>
		
		<ARG name="LIT_SEJOUR">
			<value>
				<![CDATA[
					if (SELECT.COLUMNBY.substr(0,6) == 'LITCLS' && COLUMN.DATA != '') {return 'LS' + SELECT.COLUMNBY.substr(6,2) + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'LIT' && COLUMN.DATA != '') {return 'LT' + COLUMN.DATA;} 
					if (SELECT.GROUPBY_2.substr(0,6) == 'LITCLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'LIT' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LT' + ROW.OID2;} 
					if (SELECT.GROUPBY.substr(0,6) == 'LITCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1;} 
					if (SELECT.GROUPBY == 'LIT') {return 'LT' + ROW.OID1;} 
				]]>
			</value>
		</ARG>
		
		<ARG name="PRESTATION">
			<value>
				<![CDATA[
					if (SELECT.COLUMNBY.substr(0,6) == 'PRFCLS' && COLUMN.DATA != '') {return 'LS' + SELECT.GROUPBY.substr(6,2) + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'PRF' && COLUMN.DATA != '') {return 'PR' + COLUMN.DATA; }
					if (SELECT.GROUPBY_2.substr(0,6) == 'PRFCLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'PRF' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'PR' + ROW.OID2;} 
					if (SELECT.GROUPBY.substr(0,6) == 'PRFCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1;} 
					if (SELECT.GROUPBY == 'PRF') {return 'PR' + ROW.OID1;} 
				]]>
			</value>
		</ARG>	
		
		<ARG name="RUBRIQUE">
			<value>
				<![CDATA[
					if (SELECT.COLUMNBY.substr(0,6) == 'RUCCLS' && COLUMN.DATA != '') {return 'LS' + SELECT.GROUPBY.substr(6,2) + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'RUC' && COLUMN.DATA != '') {return 'RU' + COLUMN.DATA; }
					if (SELECT.GROUPBY_2.substr(0,6) == 'RUCCLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'RUC' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'RU' + ROW.OID2;} 
					if (SELECT.GROUPBY.substr(0,6) == 'RUCCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1;} 
					if (SELECT.GROUPBY == 'RUC') {return 'RU' + ROW.OID1;} 
				]]>
			</value>
		</ARG>
		
		<ARG name="TIERS">
			<value>
				<![CDATA[
					if (SELECT.COLUMNBY.substr(0,6) == 'TPYCLS' && COLUMN.DATA != '') {return 'LS' + SELECT.GROUPBY.substr(6,2) + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'TPY' && COLUMN.DATA != '') {return 'TP' + COLUMN.DATA; }
					if (SELECT.COLUMNBY == 'TTP' && COLUMN.DATA != '') {return 'TT' + COLUMN.DATA; }
					if (SELECT.GROUPBY_2.substr(0,6) == 'TPYCLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'TPY' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'TP' + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'TTP' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'TT' + ROW.OID2;} 
					if (SELECT.GROUPBY.substr(0,6) == 'TPYCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1;} 
					if (SELECT.GROUPBY == 'TPY') {return 'TP' + ROW.OID1;} 
					if (SELECT.GROUPBY == 'TTP') {return 'TT' + ROW.OID1;} 
				]]>
			</value>
		</ARG>
		
		<ARG name="QFAC">
			<value>
				<![CDATA[
					return '1';
				]]>
			</value>
		</ARG>
		
		<ARG name="QTP">
			<value>
				<![CDATA[
					return '1';
				]]>
			</value>
		</ARG>
		
		<ARG name="QSD">
			<value>
				<![CDATA[
					return '1';
				]]>
			</value>
		</ARG>
		
		<ARG name="QMC">
			<value>
				<![CDATA[
					return '1';
				]]>
			</value>
		</ARG>
		
		<ARG name="QMR">
			<value>
				<![CDATA[
					return '1';
				]]>
			</value>
		</ARG>
		
		<ARG name="QSF">
			<value>
				<![CDATA[
					return '1';
				]]>
			</value>
		</ARG>
		
	
	</COMPONENT>
	
	<COMPONENT name="COMPTE_CLIENT_H_BASE_VIEWLINK"  >
	
		<ARG name="PERIODE">
			<value>
				<![CDATA[
					if (SELECT.GROUPBY_2 == 'MOI' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return ROW.OID2;} 
					if (SELECT.GROUPBY == 'MOI') {return ROW.OID1;} 
					return SELECT.PERIODE;
				]]>
			</value>
		</ARG>
		
		<ARG name="TOPERIODE">
			<value>
				<![CDATA[
					if (SELECT.GROUPBY_2 == 'MOI' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return ROW.OID2;} 
					if (SELECT.GROUPBY == 'MOI') {return ROW.OID1;} 
					return SELECT.TOPERIODE;
				]]>
			</value>
		</ARG>
		
		<ARG name="SERVICE_SEJOUR">
			<value>
				<![CDATA[
					if (SELECT.COLUMNBY.substr(0,6) == 'SERCLS' && COLUMN.DATA != '') {return 'LS' + SELECT.GROUPBY.substr(6,2) + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'SER' && COLUMN.DATA != '') {return 'SF' + COLUMN.DATA;} 
					if (SELECT.GROUPBY_2.substr(0,6) == 'SERCLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'SER' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'SF' + ROW.OID2;} 
					if (SELECT.GROUPBY.substr(0,6) == 'SERCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1;} 
					if (SELECT.GROUPBY == 'SER') {return 'SF' + ROW.OID1;} 
				]]>
			</value>
		</ARG>
		
		<ARG name="ETAGE_SEJOUR">
			<value>
				<![CDATA[
					if (SELECT.COLUMNBY.substr(0,6) == 'ESOCLS' && COLUMN.DATA != '') {return 'LS' + SELECT.GROUPBY.substr(6,2) + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'ETA' && COLUMN.DATA != '') {return 'ET' + COLUMN.DATA;} 
					if (SELECT.GROUPBY_2.substr(0,6) == 'ESOCLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'ETA' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'ET' + ROW.OID2;} 
					if (SELECT.GROUPBY.substr(0,6) == 'ESOCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1;} 
					if (SELECT.GROUPBY == 'ETA') {return 'ET' + ROW.OID1;} 
				]]>
			</value>
		</ARG>
		
		<ARG name="MEDECIN_SEJOUR">
			<value>
				<![CDATA[
					if (SELECT.COLUMNBY.substr(0,6) == 'MDACLS' && COLUMN.DATA != '') {return 'LS' + SELECT.COLUMNBY.substr(6,2) + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'MDA' && COLUMN.DATA != '') {return 'MA' + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'MED' && COLUMN.DATA != '') {return 'MD' + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'SPM' && COLUMN.DATA != '') {return 'SP' + COLUMN.DATA;} 
					if (SELECT.GROUPBY_2.substr(0,6) == 'MDACLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'MDA' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'MA' + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'MED' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'MD' + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'SPM' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'SP' + ROW.OID2;} 
					if (SELECT.GROUPBY.substr(0,6) == 'MDACLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1;} 
					if (SELECT.GROUPBY == 'MDA' && ROW.OID1 != '-9999999') {return 'MA' + ROW.OID1;} 
					if (SELECT.GROUPBY == 'MED' && ROW.OID1 != '-9999999') {return 'MD' + ROW.OID1;} 
					if (SELECT.GROUPBY == 'SPM' && ROW.OID1 != '-9999999') {return 'SP' + ROW.OID1;} 
					return "-1";
				]]>
			</value>
		</ARG>
		
		<ARG name="ACTIVITE_SEJOUR">
			<value>
				<![CDATA[
					if (SELECT.COLUMNBY.substr(0,6) == 'ACTCLS' && COLUMN.DATA != '') {return 'LS' + SELECT.GROUPBY.substr(6,2) + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'ACT' && COLUMN.DATA != '') {return 'AC' + COLUMN.DATA;} 
					if (SELECT.GROUPBY_2.substr(0,6) == 'ACTCLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'ACT' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'AC' + ROW.OID2;} 
					if (SELECT.GROUPBY.substr(0,6) == 'ACTCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1;} 
					if (SELECT.GROUPBY == 'ACT') {return 'AC' + ROW.OID1;} 
				]]>
			</value>
		</ARG>
		
		<ARG name="UM_SEJOUR">
			<value>
				<![CDATA[
					if (SELECT.COLUMNBY.substr(0,6) == 'UMDCLS' && COLUMN.DATA != '') {return 'LS' + SELECT.COLUMNBY.substr(6,2) + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'UM' && COLUMN.DATA != '') {return 'UM' + COLUMN.DATA;} 
					if (SELECT.GROUPBY_2.substr(0,6) == 'UMDCLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'UM' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'UM' + ROW.OID2;} 
					if (SELECT.GROUPBY.substr(0,6) == 'UMDCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1;} 
					if (SELECT.GROUPBY == 'UM') {return 'UM' + ROW.OID1;} 
				]]>
			</value>
		</ARG>
		
		<ARG name="UF_SEJOUR">
			<value>
				<![CDATA[
					if (SELECT.COLUMNBY.substr(0,6) == 'UFTCLS' && COLUMN.DATA != '') {return 'LS' + SELECT.COLUMNBY.substr(6,2) + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'UF' && COLUMN.DATA != '') {return 'UF' + COLUMN.DATA;} 
					if (SELECT.GROUPBY_2.substr(0,6) == 'UFTCLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'UF' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'UF' + ROW.OID2;} 
					if (SELECT.GROUPBY.substr(0,6) == 'UFTCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1;} 
					if (SELECT.GROUPBY == 'UF') {return 'UF' + ROW.OID1;} 
				]]>
			</value>
		</ARG>
		
		<ARG name="LIT_SEJOUR">
			<value>
				<![CDATA[
					if (SELECT.COLUMNBY.substr(0,6) == 'LITCLS' && COLUMN.DATA != '') {return 'LS' + SELECT.COLUMNBY.substr(6,2) + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'LIT' && COLUMN.DATA != '') {return 'LT' + COLUMN.DATA;} 
					if (SELECT.GROUPBY_2.substr(0,6) == 'LITCLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'LIT' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LT' + ROW.OID2;} 
					if (SELECT.GROUPBY.substr(0,6) == 'LITCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1;} 
					if (SELECT.GROUPBY == 'LIT') {return 'LT' + ROW.OID1;} 
				]]>
			</value>
		</ARG>
		
		<ARG name="TIERS">
			<value>
				<![CDATA[
					if (SELECT.COLUMNBY.substr(0,6) == 'TPYCLS' && COLUMN.DATA != '') {return 'LS' + SELECT.GROUPBY.substr(6,2) + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'TPY' && COLUMN.DATA != '') {return 'TP' + COLUMN.DATA; }
					if (SELECT.COLUMNBY == 'TTP' && COLUMN.DATA != '') {return 'TT' + COLUMN.DATA; }
					if (SELECT.GROUPBY_2.substr(0,6) == 'TPYCLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'TPY' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'TP' + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'TTP' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'TT' + ROW.OID2;} 
					if (SELECT.GROUPBY.substr(0,6) == 'TPYCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1;} 
					if (SELECT.GROUPBY == 'TPY') {return 'TP' + ROW.OID1;} 
					if (SELECT.GROUPBY == 'TTP') {return 'TT' + ROW.OID1;} 
				]]>
			</value>
		</ARG>	
		
		<ARG name="MEDECINCOMPTABILISE">
			<value>
				<![CDATA[
					if (SELECT.COLUMNBY.substr(0,6) == 'EXACLS' && COLUMN.DATA != '') {return 'LS' + SELECT.COLUMNBY.substr(6,2) + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'EXAF' && COLUMN.DATA != '') {return 'MA' + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'EXEF' && COLUMN.DATA != '') {return 'MD' + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'EXAC' && COLUMN.DATA != '') {return 'MA' + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'EXEC' && COLUMN.DATA != '') {return 'MD' + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'SPMF' && COLUMN.DATA != '') {return 'SP' + COLUMN.DATA;} 
					if (SELECT.GROUPBY_2.substr(0,6) == 'EXACLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'EXAF' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'MA' + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'EXEF' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'MD' + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'EXAC' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'MA' + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'EXEC' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'MD' + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'SPMF' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'SP' + ROW.OID2;} 
					if (SELECT.GROUPBY.substr(0,6) == 'EXACLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1;} 
					if (SELECT.GROUPBY == 'EXAF') {return 'MA' + ROW.OID1;} 
					if (SELECT.GROUPBY == 'EXEF') {return 'MD' + ROW.OID1;} 
					if (SELECT.GROUPBY == 'EXAC') {return 'MA' + ROW.OID1;} 
					if (SELECT.GROUPBY == 'EXEC') {return 'MD' + ROW.OID1;} 
					if (SELECT.GROUPBY == 'SPMF') {return 'SP' + ROW.OID1;} 
				]]>
			</value>
		</ARG>
		
		<ARG name="QFAC">
			<value>
				<![CDATA[
					return '1';
				]]>
			</value>
		</ARG>
		
		<ARG name="QTP">
			<value>
				<![CDATA[
					return '1';
				]]>
			</value>
		</ARG>
		
		<ARG name="QEXE">
			<value>
				<![CDATA[
					return '1';
				]]>
			</value>
		</ARG>
		
	
	</COMPONENT>
	
	<COMPONENT name="REJETS_BASE_VIEWLINK"  >
	
		<ARG name="PERIODE">
			<value>
				<![CDATA[
					if (SELECT.GROUPBY_2 == 'MOI' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return ROW.OID2;} 
					if (SELECT.GROUPBY == 'MOI') {return ROW.OID1;} 
					return SELECT.PERIODE;
				]]>
			</value>
		</ARG>
		
		<ARG name="TOPERIODE">
			<value>
				<![CDATA[
					if (SELECT.GROUPBY_2 == 'MOI' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return ROW.OID2;} 
					if (SELECT.GROUPBY == 'MOI') {return ROW.OID1;} 
					return SELECT.TOPERIODE;
				]]>
			</value>
		</ARG>
					
		<ARG name="SERVICE_SEJOUR">
			<value>
				<![CDATA[
					if (SELECT.COLUMNBY.substr(0,6) == 'SERCLS' && COLUMN.DATA != '') {return 'LS' + SELECT.GROUPBY.substr(6,2) + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'SER' && COLUMN.DATA != '') {return 'SF' + COLUMN.DATA;} 
					if (SELECT.GROUPBY_2.substr(0,6) == 'SERCLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'SER' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'SF' + ROW.OID2;} 
					if (SELECT.GROUPBY.substr(0,6) == 'SERCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1;} 
					if (SELECT.GROUPBY == 'SER') {return 'SF' + ROW.OID1;} 
				]]>
			</value>
		</ARG>

		<ARG name="ETAGE_SEJOUR">
			<value>
				<![CDATA[
					if (SELECT.COLUMNBY.substr(0,6) == 'ESOCLS' && COLUMN.DATA != '') {return 'LS' + SELECT.GROUPBY.substr(6,2) + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'ETA' && COLUMN.DATA != '') {return 'ET' + COLUMN.DATA;} 
					if (SELECT.GROUPBY_2.substr(0,6) == 'ESOCLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'ETA' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'ET' + ROW.OID2;} 
					if (SELECT.GROUPBY.substr(0,6) == 'ESOCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1;} 
					if (SELECT.GROUPBY == 'ETA') {return 'ET' + ROW.OID1;} 
				]]>
			</value>
		</ARG>
		
		<ARG name="MEDECIN_SEJOUR">
			<value>
				<![CDATA[
					if (SELECT.COLUMNBY.substr(0,6) == 'MDACLS' && COLUMN.DATA != '') {return 'LS' + SELECT.COLUMNBY.substr(6,2) + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'MDA' && COLUMN.DATA != '') {return 'MA' + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'MED' && COLUMN.DATA != '') {return 'MD' + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'SPM' && COLUMN.DATA != '') {return 'SP' + COLUMN.DATA;} 
					if (SELECT.GROUPBY_2.substr(0,6) == 'MDACLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'MDA' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'MA' + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'MED' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'MD' + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'SPM' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'SP' + ROW.OID2;} 
					if (SELECT.GROUPBY.substr(0,6) == 'MDACLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1;} 
					if (SELECT.GROUPBY == 'MDA' && ROW.OID1 != '-9999999') {return 'MA' + ROW.OID1;} 
					if (SELECT.GROUPBY == 'MED' && ROW.OID1 != '-9999999') {return 'MD' + ROW.OID1;} 
					if (SELECT.GROUPBY == 'SPM' && ROW.OID1 != '-9999999') {return 'SP' + ROW.OID1;} 
					return "-1";
				]]>
			</value>
		</ARG>
		
		<ARG name="ACTIVITE_SEJOUR">
			<value>
				<![CDATA[
					if (SELECT.COLUMNBY.substr(0,6) == 'ACTCLS' && COLUMN.DATA != '') {return 'LS' + SELECT.GROUPBY.substr(6,2) + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'ACT' && COLUMN.DATA != '') {return 'AC' + COLUMN.DATA;} 
					if (SELECT.GROUPBY_2.substr(0,6) == 'ACTCLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'ACT' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'AC' + ROW.OID2;} 
					if (SELECT.GROUPBY.substr(0,6) == 'ACTCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1;} 
					if (SELECT.GROUPBY == 'ACT') {return 'AC' + ROW.OID1;} 
				]]>
			</value>
		</ARG>
		
		<ARG name="UM_SEJOUR">
			<value>
				<![CDATA[
					if (SELECT.COLUMNBY.substr(0,6) == 'UMDCLS' && COLUMN.DATA != '') {return 'LS' + SELECT.COLUMNBY.substr(6,2) + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'UM' && COLUMN.DATA != '') {return 'UM' + COLUMN.DATA;} 
					if (SELECT.GROUPBY_2.substr(0,6) == 'UMDCLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'UM' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'UM' + ROW.OID2;} 
					if (SELECT.GROUPBY.substr(0,6) == 'UMDCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1;} 
					if (SELECT.GROUPBY == 'UM') {return 'UM' + ROW.OID1;} 
				]]>
			</value>
		</ARG>
		
		<ARG name="UF_SEJOUR">
			<value>
				<![CDATA[
					if (SELECT.COLUMNBY.substr(0,6) == 'UFTCLS' && COLUMN.DATA != '') {return 'LS' + SELECT.COLUMNBY.substr(6,2) + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'UF' && COLUMN.DATA != '') {return 'UF' + COLUMN.DATA;} 
					if (SELECT.GROUPBY_2.substr(0,6) == 'UFTCLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'UF' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'UF' + ROW.OID2;} 
					if (SELECT.GROUPBY.substr(0,6) == 'UFTCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1;} 
					if (SELECT.GROUPBY == 'UF') {return 'UF' + ROW.OID1;} 
				]]>
			</value>
		</ARG>
		
		<ARG name="LIT_SEJOUR">
			<value>
				<![CDATA[
					if (SELECT.COLUMNBY.substr(0,6) == 'LITCLS' && COLUMN.DATA != '') {return 'LS' + SELECT.COLUMNBY.substr(6,2) + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'LIT' && COLUMN.DATA != '') {return 'LT' + COLUMN.DATA;} 
					if (SELECT.GROUPBY_2.substr(0,6) == 'LITCLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'LIT' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LT' + ROW.OID2;} 
					if (SELECT.GROUPBY.substr(0,6) == 'LITCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1;} 
					if (SELECT.GROUPBY == 'LIT') {return 'LT' + ROW.OID1;} 
				]]>
			</value>
		</ARG>
		
		<ARG name="REJET">
			<value>
				<![CDATA[
					if (SELECT.COLUMNBY.substr(0,6) == 'REJCLS' && COLUMN.DATA != '') {return 'LS' + SELECT.GROUPBY.substr(6,2) + COLUMN.DATA;} 
					if (SELECT.COLUMNBY == 'REJ' && COLUMN.DATA != '') {return 'RJ' + COLUMN.DATA; }
					if (SELECT.GROUPBY_2.substr(0,6) == 'REJCLS' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'LS' + SELECT.GROUPBY_2.substr(6,2) + ROW.OID2;} 
					if (SELECT.GROUPBY_2 == 'REJ' && ROW.OID2 != '0' && ROW.OID2 != '-9999999') {return 'RJ' + ROW.OID2;} 
					if (SELECT.GROUPBY.substr(0,6) == 'REJCLS') {return 'LS' + SELECT.GROUPBY.substr(6,2) + ROW.OID1;} 
					if (SELECT.GROUPBY == 'REJ') {return 'RJ' + ROW.OID1;} 
				]]>
			</value>
		</ARG>	
		
	
	</COMPONENT>
	
	<COMPONENT name="STANDARD_FUNCTIONS" label="Fonctions standards" >

			<value><![CDATA[
						
				// <?

                // Retourne le champ date SQL correspondant à la sélection utilisateur.
                // A destination de la clause WHERE.
                // Remplace l'usage du champ de selection QUELLEDATE2 (= data2 de QUELLEDATE) pour que JIS fonctionne.
                function ACTI_get_quelledate2($_quelledate) {
                    $toRet = "";
					switch ($_quelledate) {
                        case "1" :
                            $toRet = "date_fin";
                            break;
                        case "2" :
                            $toRet = "date_fin_facture";
                            break;
                        case "3" :
                            $toRet = "date_facture";
                            break;
                        case "4" :
                            $toRet = "date_vente";
                            break;
                        default :
                            $toRet = "date_fin";
                            break;
                    }
                    return $toRet;
				}
				
				// idem que la function d'avant mais que pour le justificatif d'etat des dossiers
				function ACTI_get_quelledate2_etat_dossier($_quelledate) {
                    $toRet = "";
					switch ($_quelledate) {
                        case "1" :
                            $toRet = "v_factures_reference_1.date_fin_facture";
                            break;
                        case "2" :
                            $toRet = "v_factures_reference_1.date_facture";
                            break;
                        case "3" :
                            $toRet = "v_factures_reference_1.date_expedition";
                            break;
                        case "5" :
                            $toRet = "v_factures_reference_1.date_groupage";
                            break;
                        default :
                            $toRet = "date_fin";
                            break;
                    }
                    return $toRet;
				}

				function ACTI_get_section_id($param, $start = 2, $length = 2, $field = 'section_id') {
					return $field . '[' . intval(substr($param, $start, $length)) . ']';
				}
				
				function ACTI_get_classe_oid($param, $start = 4) {
					return substr($param, $start);
				}
						
				function ACTI_standard_field_select($field_prefixe, $table_name, $selected_value, $selected_code="", $field2_prefixe="") {
					$select = "";
                    
                    $module_name = "activite";
                    if ($field_prefixe == "v_sejours_finess_1.finess") {
                        $module_name = "base";
                    }
				
					if (substr($selected_value,0,1) == "[") {
						return "";
					}
					
					
					if ($selected_value != "-1" && $field_prefixe == "sexe") {
						if ($table_name != '') {
							$field = $table_name . '.code_sexe';
						}
						else {
							$field = 'code_sexe';
						}
						$select = $select. " AND $field = '$selected_value' ";
						return $select;
					}
					
					// Spécifique MCO
					if ($field_prefixe == "mco") {
						if ($selected_value != "MCOS*") {
							//$select = " AND '$selected_value' LIKE '%' || mco_code || '%' ";
							$select = " AND mco_code IN ('" . 
												substr($selected_value,0,1) . "', '" .
												substr($selected_value,1,1) . "', '" .
												substr($selected_value,2,1) . "', '" .
												substr($selected_value,3,1) . "', '" .
												substr($selected_value,4,1) . "') ";
						}
						return $select;
					}
					
					// Spécifique CAS
					if ($field_prefixe == "cas") {
						if ($selected_value != "CKXNOS*") {
							//$select = " AND '$selected_value' LIKE '%' || cas_code || '%' ";
							$select = " AND cas_code IN ('" . 
												substr($selected_value,0,1) . "', '" .
												substr($selected_value,1,1) . "', '" .
												substr($selected_value,2,1) . "', '" .
												substr($selected_value,3,1) . "', '" .
												substr($selected_value,4,1) . "', '" .
												substr($selected_value,5,1) . "', '" .
												substr($selected_value,6,1) . "') ";
						}
						return $select;
					}
					
					// Spécifique durée séjour
					if ($field_prefixe == "duree_sejour") {
						
						$selected_value_array = explode("|", $selected_value);
						
						// Tranches fixes
						$tranche_fixe = "";
						if ($selected_value_array[0] == '0') {
							$tranche_fixe = "duree = 0";
						}
						if ($selected_value_array[0] == '1') {
							$tranche_fixe = "duree = 1";
						}
						if ($selected_value_array[0] == '2') {
							$tranche_fixe = "duree = 2";
						}
						if ($selected_value_array[0] == '1EX') {
							$tranche_fixe = "duree >= 1";
						}
						if ($selected_value_array[0] == '01') {
							$tranche_fixe = "duree IN (0,1) ";
						}
						if ($selected_value_array[0] == '012') {
							$tranche_fixe = "duree IN (0,1,2) ";
						}
						if ($selected_value_array[0] == '1X') {
							$tranche_fixe = "duree > 1";
						}
						if ($selected_value_array[0] == 'X') {
							$tranche_fixe = "duree > 2";
						}
						
						if ($tranche_fixe == "") {
							// Intervalle de durées
							if ($selected_value_array[0] == 'I') {
								$select= "";
								if ($selected_value_array[1] != '' ) {
									$select .= ' AND  duree >= ' . intval($selected_value_array[1]);
								}
								if ($selected_value_array[2] != '' ) {
									$select .= ' AND  duree <= ' . intval($selected_value_array[2]);
								}
								return $select;
							}
							// Durée explicite
							else if (substr($selected_value, 0, 2) == "DU") {
								$select .= ' AND duree = ' . intval(substr($selected_value, 2));
								return $select;
							}
							// Autres (classes, ...)
							else {
								$selected_value = $selected_value_array[0];
							}
						}
						else {
							$select .= ' AND ' . $tranche_fixe;
							return $select;
						}
					}
                    // Spécifique durée d'occupation
					if ($field_prefixe == "duree_occupation") {
						
						$selected_value_array = explode("|", $selected_value);
						
						// Tranches fixes
						$tranche_fixe = "";
						if ($selected_value_array[0] === '0') {
							$tranche_fixe = "duree_occ_eta = 0";
						}
						if ($selected_value_array[0] === '1') {
							$tranche_fixe = "duree_occ_eta = 1";
						}
						if ($selected_value_array[0] === '2') {
							$tranche_fixe = "duree_occ_eta = 2";
						}
						if ($selected_value_array[0] == '1EX') {
							$tranche_fixe = "duree_occ_eta >= 1";
						}
						if ($selected_value_array[0] === '01') {
							$tranche_fixe = "duree_occ_eta IN (0,1) ";
						}
						if ($selected_value_array[0] === '012') {
							$tranche_fixe = "duree_occ_eta IN (0,1,2) ";
						}
						if ($selected_value_array[0] === '1X') {
							$tranche_fixe = "duree_occ_eta > 1";
						}
						if ($selected_value_array[0] === 'X') {
							$tranche_fixe = "duree_occ_eta > 2";
						}
						
						if ($tranche_fixe == "") {
							// Intervalle de durées
							if ($selected_value_array[0] == 'I') {
								$select= "";
								if ($selected_value_array[1] != '' ) {
									$select .= ' AND  duree_occ_eta >= ' . intval($selected_value_array[1]);
								}
								if ($selected_value_array[2] != '' ) {
									$select .= ' AND  duree_occ_eta <= ' . intval($selected_value_array[2]);
								}
								return $select;
							}
							// Durée explicite
							else if (substr($selected_value, 0, 2) == "DU") {
								$select .= ' AND duree_occ_eta = ' . intval(substr($selected_value, 2));
								return $select;
							}
							// Autres (classes, ...)
							else {
								$selected_value = $selected_value_array[0];
							}
						}
						else {
							$select .= ' AND ' . $tranche_fixe;
							return $select;
						}
					}
					
					// Spécifique age
					if ($field_prefixe == "age") {
						
						$selected_value_array = explode("|", $selected_value);
					
						$mode = substr($selected_value_array[0],0,2);
						$oid = substr($selected_value_array[0],2);
						if ($mode == 'LS') {
                            $section_id = ACTI_get_section_id($selected_value_array[0], 2, 2, 'age_section_id');
                            $oid = ACTI_get_classe_oid($selected_value_array[0]);
						}
						$subselect_select = '';
						
						if ($mode == 'LI') {$subselect_select = " age_id = ANY (array(SELECT to_id FROM activite.t_listes_contenu WHERE liste_id = $oid)::bigint[])";}
						if ($mode == 'SL') {$subselect_select = " age_id != ALL (array(SELECT to_id FROM activite.t_listes_contenu WHERE liste_id = $oid)::bigint[])";}
						if ($mode == 'LS') {$subselect_select = " age_id = ANY (array(SELECT age_id FROM activite.v_ages_1 WHERE $section_id = $oid)::bigint[])";}
						if ($mode == 'AG') {$subselect_select = " age_id = $oid ";}
						
						
						if ($subselect_select != '') {
							$select = $select. " AND $subselect_select ";
						}
						else {
						
							// Anciennes codifications
							if ($selected_value_array[0] == '0') {
								$select = $select. ' AND age = 0';
							}
							if ($selected_value_array[0] == '1') {
								$select = $select. ' AND age >= 1 AND age <= 5' ;
							}
							if ($selected_value_array[0] == '6') {
								$select = $select. ' AND age >= 6 AND age <= 12' ;}
							if ($selected_value_array[0] == '13') {
								$select = $select. ' AND age >= 13 AND age <= 20' ;
							}
							if ($selected_value_array[0] == '21') {
								$select = $select. ' AND age >= 21 AND age <= 30' ;
							}
							if ($selected_value_array[0] == '31') {
								$select = $select. ' AND age >= 31 AND age <= 40' ;
							}
							if ($selected_value_array[0] == '41') {
								$select = $select. ' AND age >= 41 AND age <= 50' ;
							}
							if ($selected_value_array[0] == '51') {
								$select = $select. ' AND age >= 51 AND age <= 60' ;
							}
							if ($selected_value_array[0] == '61') {
								$select = $select. ' AND age >= 61 AND age <= 70' ;
							}
							if ($selected_value_array[0] == '71') {
								$select = $select. ' AND age >= 71 AND age <= 80' ;
							}
							if ($selected_value_array[0] == '81') {
								$select = $select. ' AND age >= 81' ;
							}
							if ($selected_value_array[0] == 'I' && $selected_value_array[1] != '' && $selected_value_array[2] != '' ) {
								$select = $select. ' AND age >= ' . intval($selected_value_array[1]) . ' AND age <= ' . intval($selected_value_array[2]);
							}
							else if ($selected_value_array[0] == 'I' && $selected_value_array[1] != '' ) {
								$select = $select. ' AND age >= ' . intval($selected_value_array[1]);
							}
							else if ($selected_value_array[0] == 'I' && $selected_value_array[2] != '' ) {
								$select = $select. ' AND age <= ' . intval($selected_value_array[2]);
							}
						
						}
						return $select;
					}
					
					// Spécifique heure entrée
					
					if ($field_prefixe == "heure_entree") {
					
						$selected_value_array = explode("|", $selected_value);
					
						if($selected_value_array[0] != '-1') {
							$field1 = intval($selected_value_array[2]) * 10000;
							$field2 = intval($selected_value_array[3]) * 10000;
							switch ($selected_value_array[1]) {
							case 1 :
								$select = " AND v_sejours_1.heure_entree < $field1";
								break;
							case 2 :
								$select = " AND v_sejours_1.heure_entree >= $field1";
								break;
							case 3 :
								$select = " AND v_sejours_1.heure_entree BETWEEN $field1 AND $field2";
								break;
							}
						}
						
						return $select;
							
					}
					
					// Spécifique heure sortie
					
					if ($field_prefixe == "heure_sortie") {
					
						$selected_value_array = explode("|", $selected_value);
					
						if($selected_value_array[0] != '-1') {
							$field1 = intval($selected_value_array[2]) * 10000;
							$field2 = intval($selected_value_array[3]) * 10000;
							switch ($selected_value_array[1]) {
							case 1 :
								$select = " AND v_sejours_1.heure_sortie < $field1";
								break;
							case 2 :
								$select = " AND v_sejours_1.heure_sortie >= $field1";
								break;
							case 3 :
								$select = " AND v_sejours_1.heure_sortie BETWEEN $field1 AND $field2";
								break;
							}
						}
						
						return $select;
							
					}
					
					// Filtre avec prestation dans séjour

					if ($selected_value != '-1' && ($field_prefixe == "prestation_avec" or $field_prefixe == "rubrique_facturation_avec" or $field_prefixe == "compte_produit_avec")) {
						$mode = substr($selected_value,0,2);
						$oid = $selected_value;
						$field_code = '';
						$view_join = '';
							
						if ($selected_value == 'SAISIECODE') {
							$mode = "CC";
							$mode_cc = True;
						}	
						
						if ($mode == 'LS') {
							$section = substr($selected_value,2,2);
							$oid = substr($selected_value,4);
						}
						
						if ($mode != 'LI' && $mode != 'SL' && $mode != 'LS' && $mode != 'CC' ) {
							if ($mode != 'D2') {
								$mode = 'DP';
							}
							$oid = substr($selected_value,2);
						}
						if($field_prefixe == "prestation_avec"){$field_id ="prestation_id"; $view_join = 'v_factures_lignes_prestation_1';}
						if($field_prefixe == "rubrique_facturation_avec"){ $field_id ="rubrique_facturation_id"; $view_join = 'v_factures_lignes_rubrique_facturation_1';}
						if($field_prefixe == "compte_produit_avec"){$field_id ="compte_produit_id"; $view_join = 'v_factures_lignes_compte_produit_1';}
						
						if($field_prefixe == "prestation_avec" && $mode_cc ){$field_code ="prestation_code";}
						if($field_prefixe == "rubrique_facturation_avec" && $mode_cc ){ $field_code ="rubrique_facturation_code";}
						if($field_prefixe == "compte_produit_avec" && $mode_cc ){$field_code ="compte_produit_code";}

						if ($mode == 'LI' || $mode == 'SL') {$oid = substr($selected_value,2);}
						
						$subselect_select = '';
						$field_section_id = str_replace("_avec","",$field_prefixe). "_section_id[" . $section . "]";
						
						if ($mode == 'LI') {$subselect_select = "$field_id = ANY (array(SELECT to_id FROM activite.t_listes_contenu WHERE liste_id = $oid)::bigint[])";}
						if ($mode == 'SL') {$subselect_select = "$field_id != ALL (array(SELECT to_id FROM activite.t_listes_contenu WHERE liste_id = $oid)::bigint[])";}
						if ($mode == 'LS') {$subselect_select = "$field_section_id = $oid";}
						if ($mode == 'DP') {$subselect_select = "$field_id = $oid";}
						if ($mode == 'CC') {$subselect_select = "$field_code = '$selected_code' ";}
						
						
						// Spécifique avec prestation
						if ($selected_value != '-1') {
							$select = "AND v_sejours_1.no_sejour = ANY(
							SELECT v_factures_lignes_c_5.no_sejour 
							FROM activite.v_factures_lignes_c_5
								JOIN activite.$view_join ON $view_join.oid = v_factures_lignes_c_5.$field_id
							WHERE $subselect_select
							GROUP BY 1 
							)";
						}
						
						return $select;
						
					}
					
					// Filtre passage 

					if ($selected_value != '-1' && ($field_prefixe == "lieu_service_passage" or $field_prefixe == "lieu_unite_fonctionnelle_passage" or $field_prefixe == "lieu_unite_medicale_passage" or $field_prefixe == "lieu_etage_passage" )) {
						$mode = substr($selected_value,0,2);
							$oid = $selected_value;
							
						if ($selected_value == 'SAISIECODE') {
							$mode = "CC";
							$mode_cc = True;
						}	
						
						if ($mode == 'LS') {
							$section = substr($selected_value,2,2);
							$oid = substr($selected_value,4);
						}
						
						if ($mode != 'LI' && $mode != 'SL' && $mode != 'LS' && $mode != 'CC' ) {
							if ($mode != 'D2') {
								$mode = 'DP';
							}
							$oid = substr($selected_value,2);
						}
						if($field_prefixe == "lieu_service_passage"){$field_id ="lieu_service_id";}
						if($field_prefixe == "lieu_unite_fonctionnelle_passage"){ $field_id ="lieu_unite_fonctionnelle_id";}
						if($field_prefixe == "lieu_unite_medicale_passage"){$field_id ="lieu_unite_medicale_id";}
						if($field_prefixe == "lieu_etage_passage"){$field_id ="lieu_etage_id";}
						
						if($field_prefixe == "lieu_service_passage" && $mode_cc ){$field_id ="lieu_service_code";}
						if($field_prefixe == "lieu_unite_fonctionnelle_passage" && $mode_cc ){ $field_id ="lieu_unite_fonctionnelle_code";}
						if($field_prefixe == "lieu_unite_medicale_passage" && $mode_cc ){$field_id ="lieu_unite_medicale_code";}
						if($field_prefixe == "lieu_etage_passage" && $mode_cc ){$field_id ="lieu_etage_code";}
						
						if ($mode == 'LI' || $mode == 'SL') {$oid = substr($selected_value,2);}
						
						$subselect_select = '';
						$field_section_id = str_replace("_passage","",$field_prefixe). "_section_id[" . $section . "]";
						
						if ($mode == 'LI') {$subselect_select = "$field_id = ANY (SELECT to_id FROM activite.t_listes_contenu WHERE liste_id = $oid)";}
						if ($mode == 'SL') {$subselect_select = "$field_id != ALL (array(SELECT to_id FROM activite.t_listes_contenu WHERE liste_id = $oid)::bigint[])";}
						if ($mode == 'LS') {$subselect_select = "$field_section_id = $oid";}
						if ($mode == 'DP') {$subselect_select = "$field_id = $oid";}
						if ($mode == 'CC') {$subselect_select = "$field_id = '$selected_code' ";}
						
						
						// Spécifique lieu de passage service/UF/UM/etage 

						$lieux_passages = array(
							"lieu_service_passage", 
							"lieu_unite_fonctionnelle_passage", 
							"lieu_unite_medicale_passage", 
							"lieu_etage_passage"
						);

						if(in_array($field_prefixe, $lieux_passages) && $selected_value != '-1') 
						{
							$select = "AND EXISTS (
								SELECT v_sejours_1.sejour_id
									FROM activite.v_mouvements_sejour_2
								WHERE activite.v_mouvements_sejour_2.$subselect_select 
									AND v_sejours_1.no_sejour = v_mouvements_sejour_2.no_sejour 
								GROUP BY 1
							)";
						}
											
						return $select;
						
					}

					// GME
					if ($selected_value != '-1' && $field_prefixe == 'v_sejours_gme_1.gme') {
						
						$oid = substr($selected_value,2);
						$mode = substr($selected_value,0,2);
						switch ($mode) {
							case 'LI' :
								$select .= " AND gme_id IN (SELECT to_id FROM acivite.t_listes_contenu WHERE liste_id = $oid)";
								break;
							case 'SL' :
								$select .= " AND gme_id NOT IN (SELECT to_id FROM acivite.t_listes_contenu WHERE liste_id = $oid)";
								break;
							case 'LS' :
								$select .= " AND gme_id IN (SELECT oid FROM acivite.t_gme_c WHERE $section_id = $oid)";
								break;
							case 'CM' :
								$select .= " AND v_sejours_gme_1.cm_id = $oid ";
								break;
							case 'GN' :
								$select .= " AND v_sejours_gme_1.gn_id = $oid ";
								break;
							case 'RG' :
								$oid = substr($selected_value,4);
								$select .= " AND v_sejours_gme_1.rgme_id = $oid ";
								break;
							case 'GM' :
								$oid = substr($selected_value,3);
								$select .= " AND v_sejours_gme_1.gme_id = $oid ";
								break;
						}
						return $select;
					}


					// standard
					
					if ($selected_value != '-1') {
						$mode = substr($selected_value,0,2);
						$oid = $selected_value;
						if ($selected_value == 'SAISIECODE') {
							$mode = "C*";
							$selected_value = "C*$selected_code";
						}
						if ($mode == 'LS') {
                            $section = ACTI_get_section_id($selected_value);
                            $oid = ACTI_get_classe_oid($selected_value);
						}
						
						// Pour champ GHM, il y a plusieurs cas selon le préfixe
						if ($field_prefixe == "ghm") {
							if ($mode == "CM") {
								$field_prefixe = "cmd";
							}
							if ($mode == "G5") {
								$field_prefixe = "ghm5";
							}
							if ($mode == "SV") {
								$field_prefixe = "severite_ghm";
							}
						}

						// Pour champ GHM, il y a plusieurs cas selon le préfixe
						if ($field_prefixe == "v_sejours_ghmgme_1.ghmgme") {
							if ($mode == "CM") {
								$field_prefixe = "cmdcm";
							}
							if ($mode == "G5") {
								$field_prefixe = "ghm5rgme";
							}
						}

						// Pour champ GME, il y a plusieurs cas selon le préfixe
						if ($field_prefixe == "gme") {
							if ($mode == "CM") {
								$field_prefixe = "cm";
							}
							if ($mode == "GN") {
								$field_prefixe = "gn";
							}
							if ($mode == "RG") {
								$field_prefixe = "rgme";
							}
						}


						// Pour champ code_postal, il y a plusieurs cas selon le préfixe
						if ($field_prefixe == "code_postal") {
							if ($mode == 'CP' || $mode == 'LI' || $mode == 'LS') {
								$field_prefixe = $table_name . ".code_postal";
							}
							if ($mode == 'DP' || $mode == 'DG') {
								$field_prefixe = $table_name . ".departement";
							}
							if ($mode == 'GP') {
								$field_prefixe = $table_name . ".code_geographique_pmsi";
							}
							if ($mode == 'TS') {
								$field_prefixe = $table_name . ".territoire_sante";
							}
						}
						
						// Pour champ ACTE, il y a plusieurs cas selon le préfixe
						if ($field_prefixe == "acte") {
							if ($selected_value == "ACTEREGR") {
								$field_prefixe = "ccam_regroupement";
							}
							if ($selected_value == "ACTECNOM") {
								$field_prefixe = "acte_nomenclature";
							}
						}
						
						// Pour champ LPP, pour les classifications
						if ($field_prefixe == "lpp") {
							if ($mode == "D1") {
								$field_prefixe = "lpp_classification_atc_1";
								$mode = "DT";
							}
							if ($mode == "D2") {
								$field_prefixe = "lpp_classification_atc_2";
								$mode = "DT";
							}
							if ($mode == "D3") {
								$field_prefixe = "lpp_classification_atc_3";
								$mode = "DT";
							}
							if ($mode == "D4") {
								$field_prefixe = "lpp_classification_atc_4";
								$mode = "DT";
							}
						}
						
						// Pour champ UCD, pour les classifications
						if ($field_prefixe == "ucd") {
							if ($mode == "D1") {
								$field_prefixe = "ucd_classification_atc_1";
								$mode = "DT";
							}
							if ($mode == "D2") {
								$field_prefixe = "ucd_classification_atc_2";
								$mode = "DT";
							}
							if ($mode == "D3") {
								$field_prefixe = "ucd_classification_atc_3";
								$mode = "DT";
							}
							if ($mode == "D4") {
								$field_prefixe = "ucd_classification_atc_4";
								$mode = "DT";
							}
						}
						
						// Pour champ TIERS, il y a plusieurs cas selon le préfixe
						if ($field_prefixe == "tiers_payant") {
							if ($mode == "TT") {
								$field_prefixe = "type_tiers_payant";
							}
							if ($mode == "RG") {
								$field_prefixe = "tiers_payant_grand_regime";
							}
						}
						if ($field_prefixe == "v_factures_reference_1.tiers_payant") {
							if ($mode == "TT") {
								$field_prefixe = "v_factures_reference_1.type_tiers_payant";
							}
							if ($mode == "RG") {
								$field_prefixe = "v_factures_reference_1.tiers_payant_grand_regime";
							}
						}
						
                        // Medecin traitant 
                        if ($field_prefixe == "medecin_traitant") {
								$field_prefixe = "medecin_traitant";
						}
						
						// Pour champ Medecin, il y a plusieurs cas selon le préfixe
						if ($field_prefixe == "medecin_adm_sejour") {
							if ($mode == "MD") {
								$field_prefixe = "medecin_sejour";
							}
							if ($mode == "SP") {
								$field_prefixe = "medecin_sejour_specialite";
							}
						}
						if ($field_prefixe == "medecin_adm_mouvement") {
							if ($mode == "MD") {
								$field_prefixe = "medecin_mouvement";
							}
							if ($mode == "SP") {
								$field_prefixe = "medecin_mouvement_specialite";
							}
						}
						if ($field_prefixe == "medecin_adm_facture") {
							if ($mode == "MD") {
								$field_prefixe = "medecin_facture";
							}
							if ($mode == "SP") {
								$field_prefixe = "medecin_facture_specialite";
							}
						}
						if ($field_prefixe == "medecin_adm_comptabilise") {
							if ($mode == "MD") {
								$field_prefixe = "medecin_comptabilise";
							}
							if ($mode == "SP") {
								$field_prefixe = "medecin_comptabilise_specialite";
							}
						}

						
						if ($mode != 'LI' && $mode != 'SL' && $mode != 'LS' && $mode != 'C*' ) {
							if ($mode != 'D2') {
								$mode = 'DT';
							}
							$oid = substr($selected_value,2);
						}
						
						
						if ($mode == 'LI' || $mode == 'SL') {$oid = substr($selected_value,2);}
						
						// recherche dans des codes
						if ($mode == 'C*') {
							switch ($table_name) {
							case 't_ghs_c':
								$source_field_id = "ghs_id";
								$where_codes = sql_codes_list_n(substr($selected_value,2), "to_number(ghs_code,'0000')");
								break;
							case 't_ghm_c':
								$source_field_id = "ghm_id";
								$where_codes = sql_codes_list_a(substr($selected_value,2), 'ghm_code');
								break;
							case 't_ghmgme_c':
								$source_field_id = "ghmgme_id";
								$where_codes = sql_codes_list_a(substr($selected_value,2), 'ghmgme_code');
								break;
							default:
								$source_field_id = "oid";
								$where_codes = sql_codes_list_a(substr($selected_value,2), 'code');
							}
						}
						
						$subselect_select = '';					

						
						$field_id = $field_prefixe . "_id";
						$field2_id = $field2_prefixe . "_id";
						
						// ME/MS/PR/DE
						if (in_array($field_prefixe, array('mode_entree', 'mode_sortie', 'destination', 'provenance'))) {
							$field_id = $field_prefixe;
							$oid = "'" . substr($selected_value,2) . "'";
						}
						if ($field_prefixe == 'etablissement_provenance' || $field_prefixe == 'etablissement_destination') $oid = $selected_value;
						
						if ($field_prefixe == 'traitement_epmsi') $oid = $selected_value;
						
						// actes CCAM ou NGAP
						if ($field_prefixe == 'acte' and substr($selected_value,0,2) == 'NO') {
							$field_id = 'acte_nomenclature';
							$oid="'$oid'";  // sale mais evite de changer v_actes_3 (ne sait pas quelle conséquences)
						}

                        
						// sections nouvelle mode
                        $field_section_id = $field_prefixe . "_" . $section;
						
						if ($mode == 'LI') {$subselect_select = " $field_id = ANY (array(SELECT to_id FROM $module_name.t_listes_contenu WHERE liste_id = $oid)::bigint[])";}
						if ($mode == 'SL') {$subselect_select = " $field_id != ALL (array(SELECT to_id FROM $module_name.t_listes_contenu WHERE liste_id = $oid)::bigint[])";}
						if ($mode == 'LS') {$subselect_select = " $field_section_id = $oid";}
						if ($mode == 'DT') {$subselect_select = " $field_id = $oid";}
						// Spécifique type de séjour (s'adapte pour tout oid concatenant différents type de sejour ex 12 ou 125)
						if ($field_prefixe == "type_sejour") {
							if ($mode == 'DT') {
								if (strlen($oid)==1) {
									$subselect_select = " $field_id = $oid";
								}
								else {
									$subselect_select = " $field_id IN (" . implode(',', str_split($oid)) . ")";
								}
							}
						}
						
						if (in_array($field_prefixe, array('mode_entree', 'mode_sortie', 'destination', 'provenance'))){
							if ($mode == 'DT') {
								if (substr($selected_value,1,1) == 'X'){
									$subselect_select = " $field_id <> $oid";
								}
								else {
									$subselect_select = " $field_id = $oid";
								}
							}
						}
						if ($mode == 'D2') {$subselect_select = " $field2_id = $oid";}
						if ($mode == 'C*') {$subselect_select = " $field_id = ANY (array(SELECT $source_field_id FROM activite.$table_name WHERE $where_codes)::bigint[])";}
						
                        if ($field_prefixe == "severite_cti") {
                            $oid = $selected_value;
                            $subselect_select = " $field_id = $oid ";
                        }
                        
						if ($subselect_select != '') {$select = " AND $subselect_select ";}
					}
					return $select;
				}
			
				function ACTI_STANDARD_prefixe($GROUPBY, $DEFAULT="", $CONTEXTE="") {
					if (substr($GROUPBY,3,3) == 'CLS') {
						$GROUPBY = substr($GROUPBY,0,6);
					}
					$field = '';
					$field_id = '';
					$field_code = '';
					$field_texte = '';
					switch ($GROUPBY) {
					case '*TAB':
						$field = "*TAB";
						break;
					case '-1':
						$field = "";
						break;
					case 'TSE':
						$field = "type_sejour";
						break;
					case 'TSECLS':
						$field = "type_sejour_section";
						break;
					case 'EDS':
						$field = "v_sejours_1.etat_sejour";
						break;
                    case 'EDSCLS':
						$field = "etat_sejour_section";
						break;
                    case 'FOA':
						$field = "forme_activite";
						break;
					case 'FOACLS':
						$field = "forme_activite_section";
						break;
					case 'FSP':
						$field = "filiere_soin_principale";
						break;
					case 'FSPCLS':
						$field = "filiere_soin_principale_section";
						break;
                    case 'POL':
						$field = "pole";
						break;
					case 'POLCLS':
						$field = "pole_section";
						break;
					case 'MTR':
						$field = "mode_traitement";
						break;
                    case 'ETAT_PMSI':
						$field = "traitement_epmsi";
						break;
					case 'MCO':
						$field = "mcos";
						break;
					case 'CAS':
						$field = "cas";
						break;
					case 'CMD':
						$field = "cmd";
						break;
					case 'GHS':
						$field = "v_sejours_ghs_1.ghs";
						break;
					case 'GHM':
						$field = "ghm";
						break;
					case 'GHMCLS':
						$field = "ghm_section";
						break;
					case 'GHM5':
						$field = "ghm5";
						break;
					case 'GHMSEV':
						$field = "severite_ghm";
						break;
                    case 'SEVCTI':
						$field = "severite_cti";
						break;
					case 'GME':
						$field = "v_sejours_gme_1.gme";
						break;
					case 'GMECLS':
						$field = "gme_section";
						break;
					case 'GN':
						$field = "v_sejours_gme_1.gn";
						break;
					case 'GNCLS':
						$field = "gn_section";
						break;
					case 'CM':
						$field = "v_sejours_gme_1.cm";
						break;
					case 'CMCLS':
						$field = "cm_section";
						break;
					case 'RGME':
						$field = "v_sejours_gme_1.rgme";
						break;
					case 'RGMECLS':
						$field = "rgme_section";
						break;
					case 'HME':
						$field = "v_sejours_ghmgme_1.ghmgme";
						break;
					case 'HMECLS':
						$field = "ghmgme_section";
						break;
					case 'CCM':
						$field = "v_sejours_ghmgme_1.cmdcm";
						break;
					case '5ME':
						$field = "v_sejours_ghmgme_1.ghm5rgme";
						break;
                    case 'ETAB_PROV':
						$field = "etablissement_provenance";
						break;
                    case 'ETAB_DEST':
						$field = "etablissement_destination";
						break;

					case 'CPT':
                        if ($CONTEXTE != "OCCUPATION") {
                            $field = "compte_produit";
                        }
						break;
					case 'CPTCLS':
                        if ($CONTEXTE != "OCCUPATION") {
                            $field = "compte_produit_section";
                        }
						break;
						
					case 'CPA':
                        if ($CONTEXTE != "OCCUPATION") {
                            $field = "compte_produit_analytique";
                        }
						break;
					case 'CPACLS':
                        if ($CONTEXTE != "OCCUPATION") {
                            $field = "compte_produit_analytique_section";
                        }
						break;
						
					case 'BUC':
						$field = "budget_cle";
						break;
					case 'BUCCLS':
						$field = "budget_cle_section";
						break;
					
					case 'PS1':
						$field = "v_sejours_parametres_personnalises_1.parametre_personnalise_1";
						break;
					case 'PS1CLS':
						$field = "v_sejours_parametres_personnalises_1.parametre_personnalise_1_section";
						break;
					case 'PS2':
						$field = "v_sejours_parametres_personnalises_1.parametre_personnalise_2";
						break;
					case 'PS2CLS':
						$field = "v_sejours_parametres_personnalises_1.parametre_personnalise_2_section";
						break;
					case 'FIN':
						$field = "finess";
						break;
					case 'FINCLS':
						$field = "finess_section";
						break;
					case 'DUREE_SEJOUR':
						$field = "duree_sejour";
						break;
                    case 'DUREE_OCCUP':
						$field = "duree_occupation";
						break;
					case 'MODE_ENTREE':
						$field = "mode_entree";
						break;
					case 'MODE_SORTIE':
						$field = "mode_sortie";
						break;
					case 'PROVENANCE':
						$field = "provenance";
						break;
					case 'DESTINATION':
						$field = "destination";
						break;
					case 'ETABLISSEMENT_PROVENANCE':
						$field = "etablissement_provenance";
						break;
					case 'ETABLISSEMENT_DESTINATION':
						$field = "etablissement_destination";
						break;
					case 'DSJCLS':
						$field = "duree_sejour_section";
						break;
						
					// Si contexte "séjour", pour service sortie
					case 'SER':
						if ($CONTEXTE != "OCCUPATION" && $CONTEXTE != "PRESTATION" && $CONTEXTE != "PRESTATION_H") {
							$field = "lieu_sortie_service";
						}
						break;
					case 'SERCLS':
						if ($CONTEXTE != "OCCUPATION" && $CONTEXTE != "PRESTATION" && $CONTEXTE != "PRESTATION_H") {
							$field = "lieu_sortie_service_section";
						}
						break;
					// Service de sortie pour l'occupation
					case 'SOR':
						$field = "lieu_sortie_service";
						break;
					case 'SORCLS':
						$field = "lieu_sortie_service_section";
						break;
					case 'ACT':
						if ($CONTEXTE != "OCCUPATION" && $CONTEXTE != "PRESTATION" && $CONTEXTE != "PRESTATION_H") {
							$field = "lieu_sortie_activite";
						}
						break;
					case 'ETA':
						if ($CONTEXTE != "OCCUPATION" && $CONTEXTE != "PRESTATION" && $CONTEXTE != "PRESTATION_H") {
							$field = "lieu_sortie_etage";
						}
						break;
					case 'ETACLS':
						if ($CONTEXTE != "OCCUPATION" && $CONTEXTE != "PRESTATION" && $CONTEXTE != "PRESTATION_H") {
							$field = "lieu_sortie_etage_section";
						}
						break;
					case 'ESO':
							$field = "lieu_sortie_etage";
						break;
					case 'ESOCLS':
							$field = "lieu_sortie_etage_section";
						break;
					case 'LIT':
						if ($CONTEXTE != "OCCUPATION" && $CONTEXTE != "PRESTATION" && $CONTEXTE != "PRESTATION_H") {
							$field = "lieu_sortie_lit";
						}
						break;
					case 'LITCLS':
						if ($CONTEXTE != "OCCUPATION" && $CONTEXTE != "PRESTATION" && $CONTEXTE != "PRESTATION_H") {
							$field = "lieu_sortie_lit_section";
						}
						break;
                    case 'GIR':
						if ($CONTEXTE != "OCCUPATION" && $CONTEXTE != "PRESTATION" && $CONTEXTE != "PRESTATION_H") {
							$field = "lieu_sortie_gir";
						}
                        else {
                            $field = "lieu_gir";
                        }
						break;
					case 'GIRCLS':
						if ($CONTEXTE != "OCCUPATION" && $CONTEXTE != "PRESTATION" && $CONTEXTE != "PRESTATION_H") {
							$field = "lieu_sortie_gir_section";
						}
                        else {
                            $field = "lieu_gir_section";
                        }
						break;
                    case 'GRS':
						$field = "lieu_sortie_gir";
						break;
					case 'GRSCLS':
						$field = "lieu_sortie_gir_section";
						break;
					case 'UM':
						if ($CONTEXTE != "OCCUPATION" && $CONTEXTE != "PRESTATION" && $CONTEXTE != "PRESTATION_H") {
							$field = "lieu_sortie_unite_medicale";
						}
						break;
					case 'UMDCLS':
						if ($CONTEXTE != "OCCUPATION" && $CONTEXTE != "PRESTATION" && $CONTEXTE != "PRESTATION_H") {
							$field = "lieu_sortie_unite_medicale_section";
						}
						break;
					case 'UMS':
							$field = "lieu_sortie_unite_medicale";
						break;
					case 'UMSCLS':
							$field = "lieu_sortie_unite_medicale_section";
						break;
					case 'UF':
						if ($CONTEXTE != "OCCUPATION" && $CONTEXTE != "PRESTATION" && $CONTEXTE != "PRESTATION_H") {
							$field = "lieu_sortie_unite_fonctionnelle";
						}
						break;
					case 'UFTCLS':
						if ($CONTEXTE != "OCCUPATION" && $CONTEXTE != "PRESTATION" && $CONTEXTE != "PRESTATION_H") {
							$field = "lieu_sortie_unite_fonctionnelle_section";
						}
						break;
					case 'UFS':
							$field = "lieu_sortie_unite_fonctionnelle";
						break;
					case 'UFSCLS':
							$field = "lieu_sortie_unite_fonctionnelle_section";
						break;
					case 'SEXE':
						$field = "v_sejours_1.code_sexe";
						break;
					case 'AGE':
						$field = "age";
						break;
					case 'AGECLS':
						$field = "age_section";
						break;
					case 'CODEPOST':
						$field = "v_codes_postaux_2.code_postal";
						break;
					case 'DEPARTEMENT':
						$field = "v_codes_postaux_2.departement";
						break;
					case 'CDPCLS':
						$field = "v_codes_postaux_2.code_postal_section";
						break;
					case 'TERSANTE':
						$field = "v_codes_postaux_2.territoire_sante";
						break;
					case 'CODEGEOPMSI':
						$field = "v_codes_postaux_2.code_geographique_pmsi";
						break;
					case 'EXC' :
						$field = "expert_controle";
						break;
					case 'EXC_ANMO_SIGNAL' :
						$field = "date_signalement_mois";
						break;
					case 'EXC_ANSE_SIGNAL' : 
						$field = "date_signalement_semaine";
						break;
					case 'EXC_DATE_SIGNAL' : 
						$field = "date_signalement";
						break;
					case 'EXC_ANMO_CORREC' : 
						$field = "date_correction_mois";
						break;
					case 'EXC_ANSE_CORREC' : 
						$field = "date_correction_semaine";
						break;
					case 'EXC_DATE_CORREC' : 
						$field = "date_correction";
						break;
					case 'EXCCLS' :
						$field = "expert_controle_section";
						break;
					case 'SEJOUR' :
						$field = "v_sejours_1.sejour";
						break;
					case 'RIS' :
						$field = "v_risque_1.risque";
						break;
                        
                    // Occupation bloc
                    case 'BLODAT':
						$field = "date";
						break;
                    case 'BLOMOI':
						$field = "mois";
						break;
                    case 'BLS':
						$field = "salle";
						break;
					case 'BLSCLS':
						$field = "salle_section";
						break;
                    case 'BLB':
						$field = "bloc";
						break;
					case 'BLBCLS':
						$field = "bloc_section";
						break;
                    case 'BLC':
						$field = "medecin_chirurgien_intervention";
						break;
					case 'BLCCLS':
						$field = "medecin_chirurgien_adm_intervention";
						break;
                    case 'BLCSPE':
						$field = "medecin_chirurgien_intervention_specialite";
						break;   
                    case 'BLM':
						$field = "motif_intervention";
						break;
					case 'BLMCLS':
						$field = "motif_intervention";
						break;  
					case 'LPP':
						if ($CONTEXTE == "PRESTATION") {
							$field = "lpp";
						}
						break;
					case 'LP1':
						if ($CONTEXTE == "PRESTATION") {
							$field = "lpp_classification_atc_1";
						}
						break;
					case 'LP2':
						if ($CONTEXTE == "PRESTATION") {
							$field = "lpp_classification_atc_2";
						}
						break;
					case 'LP3':
						if ($CONTEXTE == "PRESTATION") {
							$field = "lpp_classification_atc_3";
						}
						break;
					case 'LP4':
						if ($CONTEXTE == "PRESTATION") {
							$field = "lpp_classification_atc_4";
						}
						break;
					case 'LP5':
						if ($CONTEXTE == "PRESTATION") {
							$field = "lpp_classification_atc";
						}
						break;
					case 'LPPCLS':
						if ($CONTEXTE == "PRESTATION") {
							$field = "lpp_section";
						}
						break;
					case 'UCD':
						if ($CONTEXTE == "PRESTATION") {
							$field = "ucd";
						}
						break;
					case 'UC1':
						if ($CONTEXTE == "PRESTATION") {
							$field = "ucd_classification_atc_1";
						}
						break;
					case 'UC2':
						if ($CONTEXTE == "PRESTATION") {
							$field = "ucd_classification_atc_2";
						}
						break;
					case 'UC3':
						if ($CONTEXTE == "PRESTATION") {
							$field = "ucd_classification_atc_3";
						}
						break;
					case 'UC4':
						if ($CONTEXTE == "PRESTATION") {
							$field = "ucd_classification_atc_4";
						}
						break;
					case 'UC5':
						if ($CONTEXTE == "PRESTATION") {
							$field = "ucd_classification_atc";
						}
						break;
					case 'UCDCLS':
						if ($CONTEXTE == "PRESTATION") {
							$field = "ucd_section";
						}
						break;
					default:
						$field = $DEFAULT;
					}
					return $field;
				}
			
				
				
				function ACTI_MOUVEMENT_prefixe($GROUPBY, $DEFAULT="") {
					if (substr($GROUPBY,3,3) == 'CLS') {
						$GROUPBY = substr($GROUPBY,0,6);
					}
					$field = '';
					$field_id = '';
					$field_code = '';
					$field_texte = '';
					switch ($GROUPBY) {
					case '*TAB':
						$field = "*TAB";
						break;
					case '-1':
						$field = "";
						break;
					case 'SER':
						$field = "lieu_service";
						break;
					case 'SERCLS':
						$field = "lieu_service_section";
						break;
					case 'ACT':
						$field = "lieu_activite";
						break;
					case 'ACTCLS':
						$field = "lieu_activite_section";
						break;
					case 'ETA':
						$field = "lieu_etage";
						break;
					case 'ETACLS':
						$field = "lieu_etage_section";
						break;
					case 'LIT':
						$field = "lieu_lit";
						break;
					case 'LITCLS':
						$field = "lieu_lit_section";
						break;
                    case 'GIR':
						$field = "lieu_gir";
						break;
					case 'GIRCLS':
						$field = "lieu_gir_section";
						break;
					case 'UM':
						$field = "lieu_unite_medicale";
						break;
					case 'UMDCLS':
						$field = "lieu_unite_medicale_section";
						break;
					case 'UF':
						$field = "lieu_unite_fonctionnelle";
						break;
					case 'UFTCLS':
						$field = "lieu_unite_fonctionnelle_section";
						break;
					case 'SPM':
						$field = "medecin_mouvement_specialite";
						break;
					case 'MED':
						$field = "medecin_mouvement";
						break;
					case 'MDA':
						$field = "medecin_adm_mouvement";
						break;
					case 'MDACLS':
						$field = "medecin_adm_mouvement_section";
						break;
					case 'ANNEE':case 'ANNEEA':
						$field = "CALC_ANNEE";
						break;
					case 'MOIS':case 'MOISA':
						$field = "CALC_MOIS";
						break;
					case 'TRIM':case 'TRIMA':
						$field = "CALC_TRIM";
						break;
					case 'JOUR':case 'JOURA':
						$field = "CALC_JOUR";
						break;
					case 'JOURS':case 'JOURSA':
						$field = "CALC_JOURS";
						break;
					case 'NUMEROSEMAINE':case 'NUMEROSEMAINEA':
						$field = "CALC_NUMEROSEMAINE";
						break;
					case 'NUMEROTRIM':case 'NUMEROTRIMA':
						$field = "CALC_NUMEROTRIM";
						break;
					case 'NUMEROJOUR':case 'NUMEROJOURA':
						$field = "CALC_NUMEROJOUR";
						break;
					case 'SEMAINEWE':
						$field = "CALC_SEMAINEWE";
						break;
					case 'NUMEROMOIS':case 'NUMEROMOISA':
						$field = "CALC_NUMEROMOIS";
						break;
					
					default:
						$field = $DEFAULT;
					}
					return $field;
					
					$prefixe = '';
					$groupby = '[GROUPBY]';
					if ($groupby == '-1') {$groupby = '[GROUPBY_2]';}

					$cls6 = substr($groupby, 0 , 6);
					$cls7 = substr($groupby, 6 , 1);

					
				}
				
				function ACTI_MOUVEMENT_field_id($GROUPBY, $DEFAULT="") {
					
					$field = "";
					$prefixe = ACTI_STANDARD_prefixe($GROUPBY, "", "OCCUPATION");
					if ($prefixe == "") {
						$prefixe = ACTI_MOUVEMENT_prefixe($GROUPBY, $DEFAULT);
					}
                    
					// Classes nouvelle sauce (avec les tableaux d'oid, de codes et de textes)
					if (substr($GROUPBY, 3, 3) == 'CLS' && $prefixe != $DEFAULT) {
						$section = substr($GROUPBY,6);
						$group = substr($GROUPBY,0,6);
						$field = "$prefixe" . "_id[" . $section . "]";
					}
					if ($field == '') {
						switch ($prefixe) {
							case "":
								$field = "0";
								break;
							case "*TAB":
								$field = "-9999999";
								break;
							case "v_sejours_1.duree" :
								$field = $prefixe;
								break;
							case "v_sejours_1.code_sexe" :
								$field = $prefixe;
								break;
							case "provenance" :
								$field = "mode_entree_id + provenance_id";
								break;
							case "destination" :
								$field = "mode_sortie_id + destination_id";
								break;
							case "CALC_ANNEE":
								$field = "EXTRACT(YEAR FROM date)";
								break;
							case "CALC_MOIS":
								$field = "v_mouvements_sejour_2.mois";
								break;
							case "CALC_TRIM":
								$field = "(EXTRACT(YEAR FROM date) * 10) + EXTRACT(QUARTER FROM date)";
								break;
							case "CALC_JOUR":
								$field = "EXTRACT(YEAR FROM date) * 10000 + EXTRACT(MONTH FROM date) * 100 + EXTRACT(DAY FROM date)";
								break;
							case "CALC_JOURS":
								$field = "EXTRACT(MONTH FROM date) * 100 + EXTRACT(DAY FROM date)";
								break;
							case "CALC_NUMEROSEMAINE":
								$field = "EXTRACT(WEEK FROM date)";
								break;
							case "CALC_NUMEROTRIM":
								$field = "EXTRACT(QUARTER FROM date)";
								break;
							case "CALC_NUMEROJOUR":
								$field = "jour_semaine";
								break;
							case "CALC_SEMAINEWE":
								$field = "is_weekend";
								break;
							case "CALC_NUMEROMOIS":
								$field = "EXTRACT(MONTH FROM date)";
								break;
							default:
								$field = "$prefixe" . "_id";
						}
					}
					return $field;
				}
				
				function ACTI_MOUVEMENT_field_code($GROUPBY, $DEFAULT="") {
					
					$field = '';
					$prefixe = ACTI_STANDARD_prefixe($GROUPBY, "", "OCCUPATION");
					if ($prefixe == "") {
						$prefixe = ACTI_MOUVEMENT_prefixe($GROUPBY, $DEFAULT="");
					}
					
					// Classes d'age nouvelle sauce (avec les tableaux d'oid, de codes et de textes)
					if (substr($GROUPBY, 3, 3) == 'CLS' && $prefixe != $DEFAULT) {
						$section = substr($GROUPBY,6);
						$group = substr($GROUPBY,0,6);
							$field = "$prefixe" . "_code[" . $section . "]";
					}
					if ($field == '') {
						switch ($prefixe) {
						case "":
							$field = "''";
							break;
						case "*TAB":
							$field = "' Résumé'";
							break;
						case "v_sejours_1.duree" :
							$field = "lpad($prefixe, 4, '0')";
							break;
						case "v_sejours_1.code_sexe" :
							$field = "v_sejours_1.sexe_texte_court";
							break;
						case "provenance" :
							$field = "mode_entree_code::text || provenance_code::text";
							break;
						case "destination" :
							$field = "mode_sortie_code::text || destination_code::text";
							break;
						case "CALC_ANNEE":
							$field = "EXTRACT(YEAR FROM date)";
							break;
						case "CALC_MOIS":
							$field = "v_mouvements_sejour_2.mois";
							break;
						case "CALC_TRIM":
							$field = "EXTRACT(YEAR FROM date)::text || ' T' || EXTRACT(QUARTER FROM date)::text";
							break;
						case "CALC_JOUR":
							$field = "v_mouvements_sejour_2.date::text";
							break;
						case "CALC_JOURS":
							$field = "to_char(v_mouvements_sejour_2.date, 'MM') ||'-'|| to_char(v_mouvements_sejour_2.date, 'DD')";
							break;
						case "CALC_NUMEROTRIM":
							$field = "'T' || EXTRACT(QUARTER FROM date)::text";
							break;
						case "CALC_NUMEROJOUR":
							$field = "jour_semaine";
							break;
						case "CALC_SEMAINEWE":
							$field = "(CASE WHEN is_weekend = 1 THEN 'WE' ELSE 'SEM' END)";
							break;
						case "CALC_NUMEROSEMAINE":
							$field = "'S' || lpad(EXTRACT(WEEK FROM date)::text, 2, '0')";
							break;
						case "CALC_NUMEROMOIS":
							$field = "base.cti_extract('MONTH_CODE', date)";
							break;
						case "v_sejours_1.sejour" :
							$field = "v_sejours_1.no_sejour";
							break;
						default:
							$field = "$prefixe" . "_code";
						}
					}
					return $field;
				}
				
				function ACTI_MOUVEMENT_field_texte($GROUPBY, $DEFAULT="") {
					
					$field = '';
					$prefixe = ACTI_STANDARD_prefixe($GROUPBY, "", "OCCUPATION");
					if ($prefixe == "") {
						$prefixe = ACTI_MOUVEMENT_prefixe($GROUPBY, $DEFAULT="");
					}
					
					// Classes d'age nouvelle sauce (avec les tableaux d'oid, de codes et de textes)
					if (substr($GROUPBY, 3, 3) == 'CLS' && $prefixe != $DEFAULT) {
						$section = substr($GROUPBY,6);
						$group = substr($GROUPBY,0,6);
							$field = "$prefixe" . "_texte[" . $section . "]";
					}
					if ($field == '') {
						switch ($prefixe) {
						case "":
							$field = "''";
							break;
						case "*TAB":
							$field = "'Résumé'";
							break;
						case "v_sejours_1.duree" :
							$field = $prefixe . " || CASE WHEN $prefixe < 2 THEN ' jour' ELSE ' jours' END";
							break;
						case "provenance" :
							$field = "mode_entree_texte || ' - ' || provenance_texte";
							break;
						case "destination" :
							$field = "mode_sortie_texte || ' - ' || destination_texte";
							break;
						case "v_sejours_1.code_sexe" :
							$field = " CASE WHEN v_sejours_1.code_sexe = '1' THEN 'Masculin' WHEN v_sejours_1.code_sexe = '2' THEN 'Feminin' ELSE 'Autres' END ";
							break;
						case "medecin_mouvement":
							$field = "$prefixe" . "_nom_prenom";
							break;
						case "medecin_adm_mouvement":
							$field = "$prefixe" . "_nom_prenom";
							break;
						case "CALC_ANNEE":
							$field = "EXTRACT(YEAR FROM date)";
							break;
						case "CALC_MOIS":
							$field = "CASE substr(v_mouvements_sejour_2.mois , 5 , 2)	
									WHEN '01' THEN 'Janvier'  
									WHEN '02' THEN 'Fevrier' 
									WHEN '03' THEN 'Mars' 
									WHEN '04' THEN 'Avril' 
									WHEN '05' THEN 'Mai' 
									WHEN '06' THEN 'Juin' 
									WHEN '07' THEN 'Juillet'  
									WHEN '08' THEN 'Aout' 
									WHEN '09' THEN 'Septembre' 
									WHEN '10' THEN 'Octobre' 
									WHEN '11' THEN 'Novembre' 
									WHEN '12' THEN 'Decembre' 
									ELSE '?'
									END
									|| ' ' || substr(v_mouvements_sejour_2.mois , 1 , 4)";
							break;
						case "CALC_TRIM":
							$field = "EXTRACT(YEAR FROM date)::text || ' Trimestre ' || EXTRACT(QUARTER FROM date)::text";
							break;
						case "CALC_JOUR":
							$field = "base.cti_to_char(v_mouvements_sejour_2.date, 'FF')";
							break;
						case "CALC_JOURS":
							$field = "to_char(v_mouvements_sejour_2.date, 'DD') ||' '||
								CASE date_part('month',v_mouvements_sejour_2.date)
										WHEN 01 THEN 'Janvier'  
										WHEN 02 THEN 'Fevrier' 
										WHEN 03 THEN 'Mars' 
										WHEN 04 THEN 'Avril' 
										WHEN 05 THEN 'Mai' 
										WHEN 06 THEN 'Juin' 
										WHEN 07 THEN 'Juillet'  
										WHEN 08 THEN 'Aout' 
										WHEN 09 THEN 'Septembre' 
										WHEN 10 THEN 'Octobre' 
										WHEN 11 THEN 'Novembre' 
										WHEN 12 THEN 'Decembre' 
										ELSE '?'
										END
										";
							break;
						case "CALC_NUMEROTRIM":
							$field = "'Trimestre ' || EXTRACT(QUARTER FROM date)::text";
							break;
						case "CALC_NUMEROSEMAINE":
							$field = "'Semaine ' || lpad(EXTRACT(WEEK FROM date)::text, 2, '0')";
							break;
						case "CALC_NUMEROJOUR":
							$field = "CASE
										WHEN jour_semaine = 1 THEN 'Lundi'  
										WHEN jour_semaine = 2 THEN 'Mardi' 
										WHEN jour_semaine = 3 THEN 'Mercredi' 
										WHEN jour_semaine = 4 THEN 'Jeudi' 
										WHEN jour_semaine = 5 THEN 'Vendredi' 
										WHEN jour_semaine = 6 THEN 'Samedi' 
										WHEN jour_semaine = 7 THEN 'Dimanche' 
										ELSE '?'
										END";
							break;
						case "CALC_SEMAINEWE":
							$field = "(CASE WHEN is_weekend = 1 THEN 'Week-end' ELSE 'Semaine' END)";
							break;
						case "CALC_NUMEROMOIS":
							$field = "base.cti_extract('MONTH_TEXT', date)";
							break;
						case "v_sejours_1.sejour" :
							$field = "v_sejours_1.no_sejour";
							break;
						default:
							$field = "$prefixe" . "_texte";
						}
					}
					return $field;
				}
				
                function ACTI_MOUVEMENT_param_data($LS_DATA, $LS_DATA_COL, $DATA, $DEFAULT="", $CASE="", $PERIODE,$TOPERIODE) {
					
					$wdata = $DATA;
					if ($LS_DATA != "-1") {
						$wdata_array_1 = explode("=",$LS_DATA);
						$wdata_array_2 = $wdata_array_1[1];
						$wdata_array = explode(",",$wdata_array_2);

						$wdata = $wdata_array[$LS_DATA_COL-1];
					}
					if($wdata != ""){
					return ACTI_MOUVEMENT_data($wdata, $DEFAULT="", $CASE="", $PERIODE,$TOPERIODE);
					}
				}

				function ACTI_MOUVEMENT_data($DATA, $DEFAULT="", $CASE="", $PERIODE, $TOPERIODE) {
					$case_when = "";
					$case_else = "";
					if ($CASE != "") {
						$case_when = "CASE WHEN $CASE THEN";
						$case_else = "ELSE null END";
					}
					switch ($DATA) {
					case 'NED':
						return "SUM($case_when nb_entrees_directes $case_else)";
						break;
					case 'NEM':
						return "SUM($case_when nb_entrees_directes + nb_entrees_mutation_[VIEW.MUTATION_FIELD] $case_else)";
						break;
					case 'NSD':
						return "SUM($case_when nb_sorties_directes $case_else)";
						break;
					case 'NSM':
						return "SUM($case_when nb_sorties_directes + nb_sorties_mutation_[VIEW.MUTATION_FIELD] $case_else)";
						break;
					case 'NJN':
						return "SUM($case_when [VIEW.JOURNEES_FIELD] $case_else)";
						break;
					case 'NJNS':
						return "SUM($case_when nb_jour_sejour_sorti $case_else)";
						break;
					case 'NEX':
						return "SUM($case_when nb_externes $case_else)";
						break;
					case 'NPX':
						return "SUM($case_when nb_passage_externe $case_else)";
						break;
					case 'NAM':
						return "SUM($case_when nb_ambulatoires $case_else)";
						break;
					case 'NEDA':
						return "SUM($case_when nb_entrees_directes + nb_ambulatoires $case_else)";
						break;
					case 'NSDA':
						return "SUM($case_when nb_sorties_directes + nb_ambulatoires $case_else)";
						break;
					case 'NEDXA':
						return "SUM($case_when nb_entrees_directes + nb_externes + nb_ambulatoires $case_else)";
						break;
					case 'NSDAM':
						return "SUM($case_when nb_sorties_directes +  nb_sorties_mutation_[VIEW.MUTATION_FIELD] + nb_ambulatoires $case_else)";
						break;
					case 'NSDXA':
						return "SUM($case_when nb_sorties_directes + nb_externes + nb_ambulatoires $case_else)";
						break;
					case 'NSDXBB':
						return "SUM($case_when nb_sorties_directes + nb_bebes + nb_ambulatoires $case_else)";
						break;
					case 'NJNXA':
						return "SUM($case_when [VIEW.JOURNEES_FIELD] + nb_externes + nb_ambulatoires $case_else)";
						break;
					case 'NEDXAS':
						return "SUM($case_when nb_entrees_directes + nb_externes + nb_ambulatoires + nb_seances $case_else)";
						break;
					case 'NSDXAS':
						return "SUM($case_when nb_sorties_directes + nb_externes + nb_ambulatoires + nb_seances_dans_taux $case_else)";
						break;
					case 'NSDXASSH':
						return "SUM($case_when nb_sorties_directes + nb_externes + nb_ambulatoires + CASE WHEN type_sejour = '5' THEN nb_seances ELSE 0 END $case_else)";
						break;
					case 'NJNXAS':
						return "SUM($case_when [VIEW.JOURNEES_FIELD] + nb_externes + nb_ambulatoires + nb_seances_dans_taux $case_else)";
						break;
					case 'NSE':
						return "SUM($case_when nb_seances $case_else)";
						break;
					case 'NSEDIA':
						return "SUM($case_when nb_seances_dialyse $case_else)";
						break;
					case 'NSECHM':
						return "SUM($case_when nb_seances_chimio $case_else)";
						break;
					case 'NSEDIV':
						return "SUM($case_when nb_seances_autre $case_else)";
						break;
					case 'NBB':
						return "SUM($case_when nb_bebes $case_else)";
						break;
                    case 'NBP':
						return "COUNT(DISTINCT $case_when no_patient $case_else)";
						break;
					case 'NCP':
						return "SUM($case_when [VIEW.CP_FIELD] $case_else)";
						break;
					case 'NJO':
						return "COUNT(*)";
						break;
					case 'NJNM':
						return "SUM($case_when [VIEW.JOURNEES_FIELD] $case_else)";
						break;
					case 'NEXM':
						return "SUM($case_when nb_externes $case_else)";
						break;
					case 'NAMM':
						return "SUM($case_when nb_ambulatoires $case_else)";
						break;
					case 'NSEM':
						return "base.cti_division(SUM(nb_seances), MAX(date(date)) - MIN(date(date)) + 1)";
						break;
					case 'NSEMDIA':
						return "base.cti_division(SUM(nb_seances_dialyse), MAX(date(date)) - MIN(date(date)) + 1)";
						break;
					case 'NSEMCHI':
						return "base.cti_division(SUM(nb_seances_chimio), MAX(date(date)) - MIN(date(date)) + 1)";
						break;
					case 'NSEMAUT':
						return "base.cti_division(SUM(nb_seances_autre), MAX(date(date)) - MIN(date(date)) + 1)";
						break;
					case 'NJNXAM':
						return "SUM($case_when [VIEW.JOURNEES_FIELD] + nb_externes + nb_ambulatoires $case_else)";
						break;
					case 'TAU':
						return "SUM($case_when [VIEW.JOURNEES_FIELD] + nb_ambulatoires + nb_seances_dans_taux $case_else)";
						break;
					case 'TAUHOSPI':
						return "SUM($case_when [VIEW.JOURNEES_FIELD] $case_else)";
						break;
					case 'TAUAMBU':
						return "SUM($case_when  nb_ambulatoires  $case_else)";
						break;
					case 'NJNAS':
						return "SUM($case_when [VIEW.JOURNEES_FIELD] + nb_ambulatoires + nb_seances_dans_taux $case_else)";
						break;
					case 'NAD':
						return "COUNT(DISTINCT $case_when CASE WHEN v_sejours_1.date_entree BETWEEN '$PERIODE'::date AND '$TOPERIODE'::date THEN v_sejours_1.no_sejour ELSE null END $case_else)";
						break;
					case 'NADPRE':
						return "COUNT(DISTINCT $case_when CASE WHEN v_sejours_1.date_entree &lt; '$PERIODE'::date THEN v_sejours_1.no_sejour ELSE null END $case_else)";
						break;
					case 'NSEJ':
						return "COUNT(DISTINCT $case_when v_sejours_1.no_sejour $case_else)";
						break;
					case 'NNONSOR':
						return "COUNT(DISTINCT $case_when CASE WHEN code_sorti = 0 THEN v_sejours_1.no_sejour ELSE null END $case_else)";
						break;
					case 'NSHP':
						return "COUNT(DISTINCT $case_when CASE WHEN v_sejours_1.date_sortie &gt; '$TOPERIODE'::date AND v_sejours_1.code_sorti = 1 THEN v_sejours_1.no_sejour ELSE null END $case_else)";
						break;
					case 'NFULL':
						return "COUNT(DISTINCT $case_when CASE WHEN v_sejours_1.date_entree BETWEEN '$PERIODE'::date AND '$TOPERIODE'::date AND v_sejours_1.date_sortie BETWEEN '$PERIODE'::date AND '$TOPERIODE'::date THEN v_sejours_1.no_sejour ELSE null END $case_else)";
						break;
					case 'NSFAC':
						return "COUNT(DISTINCT CASE WHEN date_sortie <= '$TOPERIODE'::date AND code_sorti = '1' AND v_mouvements_sejour_2.est_facture = '1' THEN v_sejours_1.no_sejour ELSE NULL END)";
						break;
					case 'NSNFAC':
						return "COUNT(DISTINCT CASE WHEN date_sortie <= '$TOPERIODE'::date AND code_sorti = '1' AND v_mouvements_sejour_2.est_facture = '0' THEN v_sejours_1.no_sejour ELSE NULL END)";
						break;
					case 'JRNSORFAC':
						return "SUM($case_when CASE WHEN date_sortie &lt;= '$TOPERIODE'::date AND v_mouvements_sejour_2.est_facture = '1' THEN [VIEW.JOURNEES_FIELD] ELSE null END $case_else)";
						break;
					case 'JRNSORHONFAC':
						return "SUM($case_when CASE WHEN date_sortie &lt;= '$TOPERIODE'::date AND v_mouvements_sejour_2.est_facture = '1' THEN [VIEW.JOURNEES_FIELD] + nb_ambulatoires + nb_seances_dans_taux ELSE null END $case_else)";
						break;
					case 'DMSHES':
						return "base.cti_division(SUM($case_when CASE WHEN type_sejour = '1' AND nb_sorties_directes = 1 THEN duree ELSE 0 END $case_else), SUM($case_when nb_sorties_directes $case_else))";
						break;
					case 'DMSHON':
						return "base.cti_division(SUM($case_when CASE WHEN type_sejour = '1' AND nb_sorties_directes = 1 THEN duree WHEN type_sejour = '2' THEN nb_ambulatoires WHEN type_sejour = '5' THEN nb_seances ELSE 0 END $case_else), SUM($case_when CASE WHEN v_sejours_1.date_sortie BETWEEN '$PERIODE'::date AND '$TOPERIODE'::date AND nb_sorties_directes + nb_ambulatoires + nb_seances_dans_taux &gt; 0 THEN 1 ELSE 0 END $case_else))";
						break;
					case 'URG':
						return "SUM($case_when nb_urgences $case_else)";
						break;
					case 'EMC':
						return "SUM($case_when equivalent_malade_complet $case_else)";
						break;
					case 'PCP':
						return "SUM($case_when [VIEW.CP_FIELD] $case_else)";
						break;
                    case 'GMP':
                        return "base.cti_division(
                            SUM($case_when gir_gmp_base*gir_gmp_coefficient $case_else),
                            SUM($case_when gir_gmp_base $case_else)
                            )";
                        break;

					default:
						return "0";
					}

				}
				
				
				
				function ACTI_PLACES_prefixe($GROUPBY, $DEFAULT="") {
					if (substr($GROUPBY,3,3) == 'CLS') {
						$GROUPBY = substr($GROUPBY,0,6);
					}
					$field = '';
					$field_id = '';
					$field_code = '';
					$field_texte = '';

					switch ($GROUPBY) {
					case '*TAB':
						$field = "*TAB";
						break;
					case '-1':
						$field = "";
						break;
					case 'TSE':
						$field = "type_sejour";
						break;
					case 'TSECLS':
						$field = "type_sejour_section";
						break;
					case 'ETA':
						$field = "etage";
						break;
					case 'ETACLS':
						$field = "etage_section";
						break;
                    case 'POL':
						$field = "pole";
						break;
					case 'POLCLS':
						$field = "pole_section";
						break;
					case 'SER':
						$field = "service";
						break;
					case 'SERCLS':
						$field = "service_section";
						break;
					case 'UF':
						$field = "uf";
						break;
					case 'UFTCLS':
						$field = "uf_section";
						break;
					case 'UM':
						$field = "um";
						break;
					case 'UMDCLS':
						$field = "um_section";
						break;
					case 'MTR':	
						$field = "mode_traitement";
						break;
					case 'FIN':
						$field = "finess";
						break;
					case 'FINCLS':
						$field = "finess_section";
						break;
					case 'ANNEE':
						$field = "CALC_ANNEE";
						break;
					case 'MOIS':
						$field = "CALC_MOIS";
						break;
					case 'TRIM':
						$field = "CALC_TRIM";
						break;
					case 'JOUR':
						$field = "CALC_JOUR";
						break;
					case 'NUMEROTRIM':
						$field = "CALC_NUMEROTRIM";
						break;
					case 'NUMEROSEMAINE':
						$field = "CALC_NUMEROSEMAINE";
						break;
					case 'NUMEROJOUR':
						$field = "CALC_NUMEROJOUR";
						break;
					case 'SEMAINEWE':
						$field = "CALC_SEMAINEWE";
						break;
					case 'NUMEROMOIS':
						$field = "CALC_NUMEROMOIS";
						break;
					default:
						$field = $DEFAULT;
					}
					return $field;

				}
				
				function ACTI_PLACES_field_id($GROUPBY, $DEFAULT="") {
				
					$prefixe = ACTI_PLACES_prefixe($GROUPBY, $DEFAULT);
					
					if (substr($GROUPBY, 3, 3) == 'CLS' && $prefixe != $DEFAULT) {
						$section = substr($GROUPBY, 6);
						$field = "$prefixe" . "_id[" . $section . "]";
					}
					else {
						switch ($prefixe) {
							case "":
								$field = "0";
								break;
							case "*TAB":
								$field = "-9999999";
								break;
							case '-111':
								$field = "-111";
								break;
							case "CALC_ANNEE":
								$field = "EXTRACT(YEAR FROM date)";
								break;
							case "CALC_MOIS":
								$field = "EXTRACT(YEAR FROM date) * 100 + EXTRACT(MONTH FROM date)";
								break;
							case "CALC_TRIM":
								$field = "(EXTRACT(YEAR FROM date) * 10) + EXTRACT(QUARTER FROM date)";
								break;
							case "CALC_JOUR":
								$field = "EXTRACT(YEAR FROM date) * 10000 + EXTRACT(MONTH FROM date) * 100 + EXTRACT(DAY FROM date)";
								break;
							case "CALC_NUMEROTRIM":
								$field = "EXTRACT(QUARTER FROM date)";
								break;
							case "CALC_NUMEROSEMAINE":
								$field = "EXTRACT(WEEK FROM date)";
								break;
							case "CALC_NUMEROJOUR":
								$field = "jour_semaine";
								break;
							case "CALC_SEMAINEWE":
								$field = "is_weekend";
								break;
							case "CALC_NUMEROMOIS":
								$field = "EXTRACT(MONTH FROM date)";
								break;
							default:
								$field = "$prefixe" . "_id";
						}
					}
					return $field;
				}
				
				function ACTI_PLACES_field_code($GROUPBY, $DEFAULT="") {
					
					$prefixe = ACTI_PLACES_prefixe($GROUPBY, $DEFAULT);
					
					if (substr($GROUPBY, 3, 3) == 'CLS' && $prefixe != $DEFAULT) {
						$section = substr($GROUPBY, 6);
						$field = "$prefixe" . "_code[" . $section . "]";
					}
					else {
						switch ($prefixe) {
							case "":
								$field = "''";
								break;
							case "*TAB":
								$field = "' Résumé'";
								break;
							case '-111':
								$field = "-111";
								break;
							case "CALC_ANNEE":
								$field = "EXTRACT(YEAR FROM date)";
								break;
							case "CALC_MOIS":
								$field = "EXTRACT(YEAR FROM date) * 100 + EXTRACT(MONTH FROM date)";
								break;
							case "CALC_TRIM":
								$field = "EXTRACT(YEAR FROM date)::text || ' T' || EXTRACT(QUARTER FROM date)::text";
								break;
							case "CALC_JOUR":
								$field = "date::text";
								break;
							case "CALC_NUMEROTRIM":
								$field = "'T' || EXTRACT(QUARTER FROM date)::text";
								break;
							case "CALC_NUMEROSEMAINE":
								$field = "'S' || lpad(EXTRACT(WEEK FROM date)::text, 2, '0')";
								break;
							case "CALC_NUMEROJOUR":
								$field = "jour_semaine";
								break;
							case "CALC_SEMAINEWE":
								$field = "(CASE WHEN is_weekend = 1 THEN 'WE' ELSE 'SEM' END)";
								break;
							case "CALC_NUMEROMOIS":
								$field = "base.cti_extract('MONTH_CODE', date)";
								break;
							default:
								$field = "$prefixe" . "_code";
						}
					}
					return $field;
				}
				
				function ACTI_PLACES_field_texte($GROUPBY, $DEFAULT="") {
				
					$prefixe = ACTI_PLACES_prefixe($GROUPBY, $DEFAULT);
					
					if (substr($GROUPBY, 3, 3) == 'CLS' && $prefixe != $DEFAULT) {
						$section = substr($GROUPBY, 6);
						$field = "$prefixe" . "_texte[" . $section . "]";
					}
					else {
					
						switch ($prefixe) {
							case "":
								$field = "''";
								break;
							case "*TAB":
								$field = "'Résumé'";
								break;
							case '-111':
								$field = "-111";
								break;
							case "CALC_ANNEE":
								$field = "EXTRACT(YEAR FROM date)";
								break;
							case "CALC_MOIS":
								$field = "base.cti_extract('MONTH_TEXT', date)::text
										|| ' ' || EXTRACT(YEAR FROM date)::text";
								break;
							case "CALC_TRIM":
								$field = "EXTRACT(YEAR FROM date)::text || ' Trimestre ' || EXTRACT(QUARTER FROM date)::text";
								break;
							case "CALC_JOUR":
								$field = "base.cti_to_char(date, 'FF')";
								break;
							case "CALC_NUMEROTRIM":
								$field = "'Trimestre ' || EXTRACT(QUARTER FROM date)::text";
								break;
							case "CALC_NUMEROSEMAINE":
								$field = "'Semaine ' || lpad(EXTRACT(WEEK FROM date)::text, 2, '0')";
								break;
							case "CALC_NUMEROJOUR":
								$field = "CASE
											WHEN jour_semaine = 1 THEN 'Lundi'  
											WHEN jour_semaine = 2 THEN 'Mardi' 
											WHEN jour_semaine = 3 THEN 'Mercredi' 
											WHEN jour_semaine = 4 THEN 'Jeudi' 
											WHEN jour_semaine = 5 THEN 'Vendredi' 
											WHEN jour_semaine = 6 THEN 'Samedi' 
											WHEN jour_semaine = 7 THEN 'Dimanche' 
											ELSE '?'
											END";
								break;
							case "CALC_SEMAINEWE":
								$field = "(CASE WHEN is_weekend = 1 THEN 'Week-end' ELSE 'Semaine' END)";
								break;
							case "CALC_NUMEROMOIS":
								$field = "base.cti_extract('MONTH_TEXT', date)";
								break;
							default:
								$field = "$prefixe" . "_texte";
						}
					}
					return $field;
				}
                
                function ACTI_OCCUPATION_BLOC_field_id($GROUPBY, $DEFAULT="") {
					
					$field = "";
					$prefixe = ACTI_STANDARD_prefixe($GROUPBY, "", "OCCUPATION");
					if ($prefixe == "") {
						$prefixe = ACTI_MOUVEMENT_prefixe($GROUPBY, $DEFAULT);
					}
                    
					// Classes nouvelle sauce (avec les tableaux d'oid, de codes et de textes)
					if (substr($GROUPBY, 3, 3) == 'CLS' && $prefixe != $DEFAULT) {
						$section = substr($GROUPBY,6);
						$group = substr($GROUPBY,0,6);
						$field = "$prefixe" . "_id[" . $section . "]";
					}
					if ($field == '') {
						switch ($prefixe) {
							case "":
								$field = "0";
								break;
							case "*TAB":
								$field = "-9999999";
								break;
							
							default:
								$field = "$prefixe" . "_id";
						}
					}
					return $field;
				}
				
				function ACTI_OCCUPATION_BLOC_field_code($GROUPBY, $DEFAULT="") {
					
					$field = '';
					$prefixe = ACTI_STANDARD_prefixe($GROUPBY, "", "OCCUPATION");
					if ($prefixe == "") {
						$prefixe = ACTI_MOUVEMENT_prefixe($GROUPBY, $DEFAULT="");
					}
					
					// Classes d'age nouvelle sauce (avec les tableaux d'oid, de codes et de textes)
					if (substr($GROUPBY, 3, 3) == 'CLS' && $prefixe != $DEFAULT) {
						$section = substr($GROUPBY,6);
						$group = substr($GROUPBY,0,6);
							$field = "$prefixe" . "_code[" . $section . "]";
					}
					if ($field == '') {
						switch ($prefixe) {
						case "":
							$field = "''";
							break;
						case "*TAB":
							$field = "' Résumé'";
							break;
						
						default:
							$field = "$prefixe" . "_code";
						}
					}
					return $field;
				}
				
				function ACTI_OCCUPATION_BLOC_field_texte($GROUPBY, $DEFAULT="") {
					
					$field = '';
					$prefixe = ACTI_STANDARD_prefixe($GROUPBY, "", "OCCUPATION");
					if ($prefixe == "") {
						$prefixe = ACTI_MOUVEMENT_prefixe($GROUPBY, $DEFAULT="");
					}
					
					// Classes d'age nouvelle sauce (avec les tableaux d'oid, de codes et de textes)
					if (substr($GROUPBY, 3, 3) == 'CLS' && $prefixe != $DEFAULT) {
						$section = substr($GROUPBY,6);
						$group = substr($GROUPBY,0,6);
							$field = "$prefixe" . "_texte[" . $section . "]";
					}
					if ($field == '') {
						switch ($prefixe) {
						case "":
							$field = "''";
							break;
						case "*TAB":
							$field = "'Résumé'";
							break;
						
						default:
							$field = "$prefixe" . "_texte";
						}
					}
					return $field;
				}

				function ACTI_OCCUPATION_BLOC_data($DATA, $DEFAULT="", $CASE="", $PERIODE="", $TOPERIODE="") {
					$case_when = "";
					$case_else = "";
					if ($CASE != "") {
						$case_when = "CASE WHEN $CASE THEN";
						$case_else = "ELSE null END";
					}
					switch ($DATA) {
					case 'NBINT':
						return "SUM($case_when nb_intervention $case_else)";
						break;
					case 'DUSAL':
						return "SUM($case_when duree_salle $case_else)";
						break;
					case 'DURET':
						return "SUM($case_when duree_remise_en_etat $case_else)";
						break;
					case 'DUTOT':
						return "SUM($case_when duree_total $case_else)";
						break;
					case 'DUDBT':
						return "SUM($case_when duree_debordement $case_else)";
						break;
					case 'DUDIS':
						return "SUM($case_when duree_disponible $case_else)";
						break;
                    case 'TXOCC':
                        return "base.cti_division(
                            SUM($case_when duree_occupation*100 $case_else),
                            SUM($case_when duree_disponible $case_else)
                            )";
                        break;

					default:
						return $DEFAULT;
					}

				}
				
				
				
				function ACTI_PRESTATION_prefixe($GROUPBY, $DEFAULT="") {
					if (substr($GROUPBY,3,3) == 'CLS') {
						$GROUPBY = substr($GROUPBY,0,6);
					}
					$field = '';
					$field_id = '';
					$field_code = '';
					$field_texte = '';
					switch ($GROUPBY) {
					case '*TAB':
						$field = "*TAB";
						break;
					case '-1':
						$field = "";
						break;
			
					case 'PRF':
						$field = "prestation";
						break;
					case 'PRFCLS':
						$field = "prestation_section";
						break;
					case 'RUF':
						$field = "rubrique_facturation";
						break;
					case 'RUFCLS':
						$field = "rubrique_facturation_section";
						break;
					case 'RUC':
						$field = "rubrique_comptabilisation";
						break;
					case 'RUCCLS':
						$field = "rubrique_comptabilisation_section";
						break;
					case 'SER':
						$field = "lieu_ligne_service";
						break;
					case 'SERCLS':
						$field = "lieu_ligne_service_section";
						break;
					case 'ACT':
						$field = "lieu_ligne_activite";
						break;
					case 'ETA':
						$field = "lieu_ligne_etage";
						break;
					case 'ETACLS':
						$field = "lieu_ligne_etage_section";
						break;
					case 'LIT':
						$field = "lieu_ligne_lit";
						break;
					case 'LITCLS':
						$field = "lieu_ligne_lit_section";
						break;
					case 'UM':
						$field = "lieu_ligne_unite_medicale";
						break;
					case 'UMDCLS':
						$field = "lieu_ligne_unite_medicale_section";
						break;
					case 'UF':
						$field = "lieu_ligne_unite_fonctionnelle";
						break;
					case 'UFTCLS':
						$field = "lieu_ligne_unite_fonctionnelle_section";
						break;
					case 'SPM':
						$field = "medecin_sejour_specialite";
						break;
					case 'MED':
						$field = "medecin_sejour";
						break;
					case 'MDA':
						$field = "medecin_adm_sejour";
						break;
					case 'MDACLS':
						$field = "medecin_adm_sejour_section";
						break;
                    case 'MTA':
						$field = "medecin_traitant";
						break;                    
                    case 'MTACLS':
						$field = "medecin_traitant_section";
						break;
					case 'MOIA':
						$field = "CALC_MOIA";
						break;
					case 'MOIS':
						$field = "CALC_MOIS";
						break;
					case 'ANNEE':
						$field = "CALC_ANNEE";
						break;
					case 'NUMEROMOIS':
						$field = "CALC_NUMEROMOIS";
						break;
					case 'TRIM':
						$field = "CALC_TRIM";
						break;
					case 'JOUR':
						$field = "CALC_JOUR";
						break;
					case 'JOURS':
						$field = "CALC_JOURS";
						break;
					case 'NUMEROTRIM':
						$field = "CALC_NUMEROTRIM";
						break;
					case 'NUMEROJOUR':
						$field = "CALC_NUMEROJOUR";
						break;
					case 'SEMAINEWE':
						$field = "CALC_SEMAINEWE";
						break;
					case 'SEMAINEANNE':
						$field = "CALC_SEMAINEANNE";
						break;
						
					case 'MOISF':
						$field = "CALC_MOISF";
						break;
					case 'ANNEEF':
						$field = "CALC_ANNEEF";
						break;
					case 'NUMEROMOISF':
						$field = "CALC_NUMEROMOISF";
						break;
					case 'TRIMF':
						$field = "CALC_TRIMF";
						break;
					case 'JOURF':
						$field = "CALC_JOURF";
						break;
					case 'JOURSF':
						$field = "CALC_JOURSF";
						break;
					case 'NUMEROTRIMF':
						$field = "CALC_NUMEROTRIMF";
						break;
					case 'NUMEROJOURF':
						$field = "CALC_NUMEROJOURF";
						break;
					case 'SEMAINEWEF':
						$field = "CALC_SEMAINEWEF";
						break;
					case 'SEMAINEANNEF':
						$field = "CALC_SEMAINEANNEF";
						break;
					case 'MOISA':
						$field = "CALC_MOISA";
						break;
					case 'ANNEEA':
						$field = "CALC_ANNEEA";
						break;
					case 'NUMEROMOISA':
						$field = "CALC_NUMEROMOISA";
						break;
					case 'TRIMA':
						$field = "CALC_TRIMA";
						break;
					case 'JOURA':
						$field = "CALC_JOURA";
						break;
					case 'JOURSA':
						$field = "CALC_JOURSA";
						break;
					case 'NUMEROTRIMA':
						$field = "CALC_NUMEROTRIMA";
						break;
					case 'NUMEROJOURA':
						$field = "CALC_NUMEROJOURA";
						break;
					case 'SEMAINEWEA':
						$field = "CALC_SEMAINEWEA";
						break;
					case 'SEMAINEANNEA':
						$field = "CALC_SEMAINEANNEA";
						break;
						
					case 'MOISV':
						$field = "CALC_MOISV";
						break;
					case 'ANNEEV':
						$field = "CALC_ANNEEV";
						break;
					case 'NUMEROMOISV':
						$field = "CALC_NUMEROMOISV";
						break;
					case 'TRIMV':
						$field = "CALC_TRIMV";
						break;
					case 'JOURV':
						$field = "CALC_JOURV";
						break;
					case 'JOURSV':
						$field = "CALC_JOURSV";
						break;
					case 'NUMEROTRIMV':
						$field = "CALC_NUMEROTRIMV";
						break;
					case 'NUMEROJOURV':
						$field = "CALC_NUMEROJOURV";
						break;
					case 'SEMAINEWEV':
						$field = "CALC_SEMAINEWEV";
						break;
					case 'SEMAINEANNEV':
						$field = "CALC_SEMAINEANNEV";
						break;
					
					default:
						$field = $DEFAULT;
					}
					return $field;
					
					$prefixe = '';
					$groupby = '[GROUPBY]';
					if ($groupby == '-1') {$groupby = '[GROUPBY_2]';}

					$cls6 = substr($groupby, 0 , 6);
					$cls7 = substr($groupby, 6 , 1);

					
				}
				
				function ACTI_PRESTATION_field_id($GROUPBY, $DEFAULT="") {
				
					$prefixe = ACTI_STANDARD_prefixe($GROUPBY, $DEFAULT, "PRESTATION");
					if ($prefixe == "") {
						$prefixe = ACTI_PRESTATION_prefixe($GROUPBY, $DEFAULT="");
					}
					
					if (substr($GROUPBY, 3, 3) == 'CLS' && $prefixe != $DEFAULT) {
						$section = substr($GROUPBY, 6);
						$field = "$prefixe" . "_id[" . $section . "]";
					}
					else {
						switch ($prefixe) {
							case "":
								$field = "0";
								break;
							case "*TAB":
								$field = "-9999999";
								break;
							case "CALC_MOIA":
								$field = "v_factures_lignes_c_4.mois_fin";
								break;
							case 'CALC_ANNEE':
								$field = "to_char(v_factures_lignes_c_4.date_fin_facture, 'YYYY')";
								break;
							case 'CALC_NUMEROMOIS':
								$field = "to_char(v_factures_lignes_c_4.date_fin_facture, 'MM')";
								break;
							case 'CALC_TRIM':
								$field = "to_char(v_factures_lignes_c_4.date_fin_facture, 'YYYYQ')";
								break;
							case 'CALC_NUMEROTRIM':
								$field = "to_char(v_factures_lignes_c_4.date_fin_facture, 'Q')";
								break;
							case 'CALC_NUMEROJOUR':
								$field = "CASE extract(DOW FROM v_factures_lignes_c_4.date_fin_facture) WHEN 0 THEN 7 ELSE extract(DOW FROM v_factures_lignes_c_4.date_fin_facture) END";
								break;
							case 'CALC_JOUR':
								$field = "to_char(v_factures_lignes_c_4.date_fin_facture, 'YYYYMMDD')";
								break;
							case 'CALC_JOURS':
								$field = "to_char(v_factures_lignes_c_4.date_fin_facture, 'MMDD')";
								break;
							case "CALC_MOIS":
								$field = "to_char(v_factures_lignes_c_4.date_fin_facture, 'YYYYMM')";
								break;
							case 'CALC_SEMAINEWE':
								$field = "to_char(v_factures_lignes_c_4.date_fin_facture, 'W')";
								break;
							case 'CALC_SEMAINEANNE':
								$field = "to_char(v_factures_lignes_c_4.date_fin_facture, 'WW')";
								break;
								
							case 'CALC_ANNEEF':
								$field = "to_char(v_factures_lignes_c_4.date_facture, 'YYYY')";
								break;
							case 'CALC_NUMEROMOISF':
								$field = "to_char(v_factures_lignes_c_4.date_facture, 'MM')";
								break;
							case 'CALC_TRIMF':
								$field = "to_char(v_factures_lignes_c_4.date_facture, 'YYYYQ')";
								break;
							case 'CALC_NUMEROTRIMF':
								$field = "to_char(v_factures_lignes_c_4.date_facture, 'Q')";
								break;
							case 'CALC_NUMEROJOURF':
								$field = "CASE extract(DOW FROM v_factures_lignes_c_4.date_facture) WHEN 0 THEN 7 ELSE extract(DOW FROM v_factures_lignes_c_4.date_facture) END";
								break;
							case 'CALC_JOURF':
								$field = "to_char(v_factures_lignes_c_4.date_facture, 'YYYYMMDD')";
								break;
							case 'CALC_JOURSF':
								$field = "to_char(v_factures_lignes_c_4.date_facture, 'MMDD')";
								break;
							case 'CALC_SEMAINEWEF':
								$field = "to_char(v_factures_lignes_c_4.date_facture, 'W')";
								break;
							case 'CALC_SEMAINEANNEF':
								$field = "to_char(v_factures_lignes_c_4.date_facture, 'WW')";
								break;
							case "CALC_MOISF":
								$field = "to_char(v_factures_lignes_c_4.date_facture, 'YYYYMM')";
								break;							
							
							case 'CALC_ANNEEA':
								$field = "to_char(v_factures_lignes_c_4.date_fin, 'YYYY')";
								break;
							case 'CALC_NUMEROMOISA':
								$field = "to_char(v_factures_lignes_c_4.date_fin, 'MM')";
								break;
							case 'CALC_TRIMA':
								$field = "to_char(v_factures_lignes_c_4.date_fin, 'YYYYQ')";
								break;
							case 'CALC_NUMEROTRIMA':
								$field = "to_char(v_factures_lignes_c_4.date_fin, 'Q')";
								break;
							case 'CALC_NUMEROJOURA':
								$field = "CASE extract(DOW FROM v_factures_lignes_c_4.date_fin) WHEN 0 THEN 7 ELSE extract(DOW FROM v_factures_lignes_c_4.date_fin) END";
								break;
							case 'CALC_JOURA':
								$field = "to_char(v_factures_lignes_c_4.date_fin, 'YYYYMMDD')";
								break;
							case 'CALC_JOURSA':
								$field = "to_char(v_factures_lignes_c_4.date_fin, 'MMDD')";
								break;
							case 'CALC_SEMAINEWEA':
								$field = "to_char(v_factures_lignes_c_4.date_fin, 'W')";
								break;
							case 'CALC_SEMAINEANNEA':
								$field = "to_char(v_factures_lignes_c_4.date_fin, 'WW')";
								break;
							case "CALC_MOISA":
								$field = "to_char(v_factures_lignes_c_4.date_fin, 'YYYYMM')";
								break;							
							
							case 'CALC_ANNEEV':
								$field = "to_char(v_factures_lignes_c_4.date_vente, 'YYYY')";
								break;
							case 'CALC_NUMEROMOISV':
								$field = "to_char(v_factures_lignes_c_4.date_vente, 'MM')";
								break;
							case 'CALC_TRIMV':
								$field = "to_char(v_factures_lignes_c_4.date_vente, 'YYYYQ')";
								break;
							case 'CALC_NUMEROTRIMV':
								$field = "to_char(v_factures_lignes_c_4.date_vente, 'Q')";
								break;
							case 'CALC_NUMEROJOURV':
								$field = "CASE extract(DOW FROM v_factures_lignes_c_4.date_vente) WHEN 0 THEN 7 ELSE extract(DOW FROM v_factures_lignes_c_4.date_vente) END";
								break;
							case 'CALC_JOURV':
								$field = "to_char(v_factures_lignes_c_4.date_vente, 'YYYYMMDD')";
								break;
							case 'CALC_JOURSV':
								$field = "to_char(v_factures_lignes_c_4.date_vente, 'MMDD')";
								break;
							case 'CALC_SEMAINEWEV':
								$field = "to_char(v_factures_lignes_c_4.date_vente, 'W')";
								break;
							case 'CALC_SEMAINEANNEV':
								$field = "to_char(v_factures_lignes_c_4.date_vente, 'WW')";
								break;
							case "CALC_MOISV":
								$field = "to_char(v_factures_lignes_c_4.date_vente, 'YYYYMM')";
								break;
							default:
								$field = "$prefixe" . "_id";
						}
					}
					return $field;
				}
				
				function ACTI_PRESTATION_field_code($GROUPBY, $DEFAULT="") {
				
					$prefixe = ACTI_STANDARD_prefixe($GROUPBY, $DEFAULT, "PRESTATION");
					if ($prefixe == "") {
						$prefixe = ACTI_PRESTATION_prefixe($GROUPBY, $DEFAULT="");
					}
					
					if (substr($GROUPBY, 3, 3) == 'CLS' && $prefixe != $DEFAULT) {
						$section = substr($GROUPBY, 6);
						$field = "$prefixe" . "_code[" . $section . "]";
					}
					else {
						switch ($prefixe) {
							case "":
								$field = "''";
								break;
							case "*TAB":
								$field = "' Résumé'";
								break;
							case "CALC_MOIA":
								$field = "v_factures_lignes_c_4.mois_fin";
								break;
							case 'CALC_ANNEE':
								$field = "to_char(v_factures_lignes_c_4.date_fin_facture, 'YYYY')";
								break;
							case 'CALC_NUMEROMOIS':
								$field = "to_char(v_factures_lignes_c_4.date_fin_facture, 'MM')";
								break;
							case 'CALC_TRIM':
								$field = "to_char(v_factures_lignes_c_4.date_fin_facture, 'YYYY') ||' T'|| to_char(v_factures_lignes_c_4.date_fin_facture, 'Q')  ";
								break;
							case 'CALC_NUMEROTRIM':
								$field = "to_char(v_factures_lignes_c_4.date_fin_facture, 'Q')";
								break;
							case 'CALC_NUMEROJOUR':
								$field = "CASE extract(DOW FROM v_factures_lignes_c_4.date_fin_facture) WHEN 0 THEN 7 ELSE extract(DOW FROM v_factures_lignes_c_4.date_fin_facture) END";
								break;
							case 'CALC_SEMAINEWE':
								$field = "to_char(v_factures_lignes_c_4.date_fin_facture, 'W')";
								break;
							case 'CALC_SEMAINEANNE':
								$field = "to_char(v_factures_lignes_c_4.date_fin_facture, 'WW')";
								break;
							case 'CALC_JOUR':
								$field = "to_char(v_factures_lignes_c_4.date_fin_facture, 'YYYY') ||'-'|| to_char(v_factures_lignes_c_4.date_fin_facture, 'MM') ||'-'||to_char(v_factures_lignes_c_4.date_fin_facture, 'DD')";
								break;
							case 'CALC_JOURS':
								$field = " to_char(v_factures_lignes_c_4.date_fin_facture, 'MM') ||'-'|| to_char(v_factures_lignes_c_4.date_fin_facture, 'DD') ";
								break;
							case "CALC_MOIS":
								$field = "to_char(v_factures_lignes_c_4.date_fin_facture, 'YYYYMM')";
								break;
							case 'CALC_ANNEEF':
								$field = "to_char(v_factures_lignes_c_4.date_facture, 'YYYY')";
								break;
							case 'CALC_NUMEROMOISF':
								$field = "to_char(v_factures_lignes_c_4.date_facture, 'MM')";
								break;
							case 'CALC_TRIMF':
								$field = "to_char(v_factures_lignes_c_4.date_facture, 'YYYY') ||' T'|| to_char(v_factures_lignes_c_4.date_facture, 'Q')  ";
								break;
							case 'CALC_NUMEROTRIMF':
								$field = "to_char(v_factures_lignes_c_4.date_facture, 'Q')";
								break;
							case 'CALC_NUMEROJOURF':
								$field = "CASE extract(DOW FROM v_factures_lignes_c_4.date_facture) WHEN 0 THEN 7 ELSE extract(DOW FROM v_factures_lignes_c_4.date_facture) END";
								break;
							case 'CALC_SEMAINEWEF':
								$field = "to_char(v_factures_lignes_c_4.date_facture, 'W')";
								break;
							case 'CALC_SEMAINEANNEF':
								$field = "to_char(v_factures_lignes_c_4.date_facture, 'WW')";
								break;
							case 'CALC_JOURF':
								$field = "to_char(v_factures_lignes_c_4.date_facture, 'YYYY') ||'-'|| to_char(v_factures_lignes_c_4.date_facture, 'MM') ||'-'||to_char(v_factures_lignes_c_4.date_facture, 'DD')";
								break;
							case 'CALC_JOURSF':
								$field = " to_char(v_factures_lignes_c_4.date_facture, 'MM') ||'-'|| to_char(v_factures_lignes_c_4.date_facture, 'DD') ";
								break;
							case "CALC_MOISF":
								$field = "to_char(v_factures_lignes_c_4.date_facture, 'YYYYMM')";
								break;							
							
							case 'CALC_ANNEEA':
								$field = "to_char(v_factures_lignes_c_4.date_fin, 'YYYY')";
								break;
							case 'CALC_NUMEROMOISA':
								$field = "to_char(v_factures_lignes_c_4.date_fin, 'MM')";
								break;
							case 'CALC_TRIMA':
								$field = "to_char(v_factures_lignes_c_4.date_fin, 'YYYY') ||' T'|| to_char(v_factures_lignes_c_4.date_fin, 'Q')  ";
								break;
							case 'CALC_NUMEROTRIMA':
								$field = "to_char(v_factures_lignes_c_4.date_fin, 'Q')";
								break;
							case 'CALC_NUMEROJOURA':
								$field = "CASE extract(DOW FROM v_factures_lignes_c_4.date_fin) WHEN 0 THEN 7 ELSE extract(DOW FROM v_factures_lignes_c_4.date_fin) END";
								break;
							case 'CALC_SEMAINEWEA':
								$field = "to_char(v_factures_lignes_c_4.date_fin, 'W')";
								break;
							case 'CALC_SEMAINEANNEA':
								$field = "to_char(v_factures_lignes_c_4.date_fin, 'WW')";
								break;
							case 'CALC_JOURA':
								$field = "to_char(v_factures_lignes_c_4.date_fin, 'YYYY') ||'-'|| to_char(v_factures_lignes_c_4.date_fin, 'MM') ||'-'||to_char(v_factures_lignes_c_4.date_fin, 'DD')";
								break;
							case 'CALC_JOURSA':
								$field = " to_char(v_factures_lignes_c_4.date_fin, 'MM') ||'-'|| to_char(v_factures_lignes_c_4.date_fin, 'DD') ";
								break;
							case "CALC_MOISA":
								$field = "to_char(v_factures_lignes_c_4.date_fin, 'YYYYMM')";
								break;							
							
							case 'CALC_ANNEEV':
								$field = "to_char(v_factures_lignes_c_4.date_vente, 'YYYY')";
								break;
							case 'CALC_NUMEROMOISV':
								$field = "to_char(v_factures_lignes_c_4.date_vente, 'MM')";
								break;
							case 'CALC_TRIMV':
								$field = "to_char(v_factures_lignes_c_4.date_vente, 'YYYY') ||' T'|| to_char(v_factures_lignes_c_4.date_vente, 'Q')  ";
								break;
							case 'CALC_NUMEROTRIMV':
								$field = "to_char(v_factures_lignes_c_4.date_vente, 'Q')";
								break;
							case 'CALC_NUMEROJOURV':
								$field = "CASE extract(DOW FROM v_factures_lignes_c_4.date_vente) WHEN 0 THEN 7 ELSE extract(DOW FROM v_factures_lignes_c_4.date_vente) END";
								break;
							case 'CALC_SEMAINEWEV':
								$field = "to_char(v_factures_lignes_c_4.date_vente, 'W')";
								break;
							case 'CALC_SEMAINEANNEV':
								$field = "to_char(v_factures_lignes_c_4.date_vente, 'WW')";
								break;
							case 'CALC_JOURV':
								$field = "to_char(v_factures_lignes_c_4.date_vente, 'YYYY') ||'-'|| to_char(v_factures_lignes_c_4.date_vente, 'MM') ||'-'||to_char(v_factures_lignes_c_4.date_vente, 'DD')";
								break;
							case 'CALC_JOURSV':
								$field = " to_char(v_factures_lignes_c_4.date_vente, 'MM') ||'-'|| to_char(v_factures_lignes_c_4.date_vente, 'DD') ";
								break;
							case "CALC_MOISV":
								$field = "to_char(v_factures_lignes_c_4.date_vente, 'YYYYMM')";
								break;
							default:
								$field = "$prefixe" . "_code";
						}
					}
					return $field;
				}
				
				function ACTI_PRESTATION_field_texte($GROUPBY, $DEFAULT="") {
					$prefixe = ACTI_STANDARD_prefixe($GROUPBY, $DEFAULT, "PRESTATION");
					if ($prefixe == "") {
						$prefixe = ACTI_PRESTATION_prefixe($GROUPBY, $DEFAULT="");
					}
					
					if (substr($GROUPBY, 3, 3) == 'CLS' && $prefixe != $DEFAULT) {
						$section = substr($GROUPBY, 6);
						$field = "$prefixe" . "_texte[" . $section . "]";
					}
					else {
						switch ($prefixe) {
							case "":
								$field = "''";
								break;
							case "*TAB":
								$field = "'Résumé'";
								break;
							case "medecin_adm_sejour":
								$field = "$prefixe" . "_nom_prenom";
								break;
							case "medecin_sejour":
								$field = "$prefixe" . "_nom_prenom";
								break;							
                            case "medecin_traitant":
								$field = "$prefixe" . "_nom_prenom";
                                break;
							case "CALC_ANNEE":
								$field = "to_char(v_factures_lignes_c_4.date_fin_facture, 'YYYY')";
								break;
							case 'CALC_NUMEROMOIS':
								$field = "CASE date_part('month',v_factures_lignes_c_4.date_fin_facture)
										WHEN 01 THEN 'Janvier'  
										WHEN 02 THEN 'Fevrier' 
										WHEN 03 THEN 'Mars' 
										WHEN 04 THEN 'Avril' 
										WHEN 05 THEN 'Mai' 
										WHEN 06 THEN 'Juin' 
										WHEN 07 THEN 'Juillet'  
										WHEN 08 THEN 'Aout' 
										WHEN 09 THEN 'Septembre' 
										WHEN 10 THEN 'Octobre' 
										WHEN 11 THEN 'Novembre' 
										WHEN 12 THEN 'Decembre' 
										ELSE '?'
										END";
								break;
							case 'CALC_TRIM':
								$field = "date_part('year',v_factures_lignes_c_4.date_fin_facture) ||'-'|| 
								CASE to_char(v_factures_lignes_c_4.date_fin_facture, 'Q')
										WHEN 1 THEN 'Trimestre 1'  
										WHEN 2 THEN 'Trimestre 2' 
										WHEN 3 THEN 'Trimestre 3' 
										WHEN 4 THEN 'Trimestre 4'
										ELSE '?'
										END";
								break;
							case 'CALC_NUMEROTRIM':
								$field = "CASE to_char(v_factures_lignes_c_4.date_fin_facture, 'Q')
										WHEN 1 THEN 'Trimestre 1'  
										WHEN 2 THEN 'Trimestre 2' 
										WHEN 3 THEN 'Trimestre 3' 
										WHEN 4 THEN 'Trimestre 4'
										ELSE '?'
										END";
								break;
							case 'CALC_NUMEROJOUR':
								$field = "CASE CASE extract(DOW FROM v_factures_lignes_c_4.date_fin_facture) WHEN 0 THEN 7 ELSE extract(DOW FROM v_factures_lignes_c_4.date_fin_facture) END
										WHEN 1 THEN 'Lundi'  
										WHEN 2 THEN 'Mardi' 
										WHEN 3 THEN 'Mercredi' 
										WHEN 4 THEN 'Jeudi'
										WHEN 5 THEN 'Vendredi'
										WHEN 6 THEN 'Samedi'
										WHEN 7 THEN 'Dimanche'
										ELSE '?'
										END";
								break;
							case 'CALC_JOUR':
								$field = "base.cti_to_char(v_factures_lignes_c_4.date_fin_facture, 'FF')";
								break;
							case 'CALC_JOURS':
								$field = "base.cti_to_char(v_factures_lignes_c_4.date_fin_facture, 'DD') ||' '||
								CASE date_part('month',v_factures_lignes_c_4.date_fin_facture)
										WHEN 01 THEN 'Janvier'  
										WHEN 02 THEN 'Fevrier' 
										WHEN 03 THEN 'Mars' 
										WHEN 04 THEN 'Avril' 
										WHEN 05 THEN 'Mai' 
										WHEN 06 THEN 'Juin' 
										WHEN 07 THEN 'Juillet'  
										WHEN 08 THEN 'Aout' 
										WHEN 09 THEN 'Septembre' 
										WHEN 10 THEN 'Octobre' 
										WHEN 11 THEN 'Novembre' 
										WHEN 12 THEN 'Decembre' 
										ELSE '?'
										END
								
								";
								break;

							case 'CALC_SEMAINEANNE':
								$field = " 'Semaine '||' '|| to_char(v_factures_lignes_c_4.date_fin_facture, 'WW')

										";
								break;
							case 'CALC_SEMAINEWE':
								$field = "CASE to_char(v_factures_lignes_c_4.date_fin_facture, 'W')
										WHEN 1 THEN 'Semaine 1'  
										WHEN 2 THEN 'Semaine 2' 
										WHEN 3 THEN 'Semaine 3' 
										WHEN 4 THEN 'Semaine 4'
										WHEN 5 THEN 'Semaine 5'
										ELSE '?'
										END";
								break;
							case "CALC_MOIS":
								$field = "CASE date_part('month',v_factures_lignes_c_4.date_fin_facture)
										WHEN 01 THEN 'Janvier'  
										WHEN 02 THEN 'Fevrier' 
										WHEN 03 THEN 'Mars' 
										WHEN 04 THEN 'Avril' 
										WHEN 05 THEN 'Mai' 
										WHEN 06 THEN 'Juin' 
										WHEN 07 THEN 'Juillet'  
										WHEN 08 THEN 'Aout' 
										WHEN 09 THEN 'Septembre' 
										WHEN 10 THEN 'Octobre' 
										WHEN 11 THEN 'Novembre' 
										WHEN 12 THEN 'Decembre' 
										ELSE '?'
										END
										|| ' ' || date_part('year',v_factures_lignes_c_4.date_fin_facture)";
								break;
							case "CALC_ANNEEF":
								$field = "to_char(v_factures_lignes_c_4.date_facture, 'YYYY')";
								break;
							case 'CALC_NUMEROMOISF':
								$field = "CASE date_part('month',v_factures_lignes_c_4.date_facture)
										WHEN 01 THEN 'Janvier'  
										WHEN 02 THEN 'Fevrier' 
										WHEN 03 THEN 'Mars' 
										WHEN 04 THEN 'Avril' 
										WHEN 05 THEN 'Mai' 
										WHEN 06 THEN 'Juin' 
										WHEN 07 THEN 'Juillet'  
										WHEN 08 THEN 'Aout' 
										WHEN 09 THEN 'Septembre' 
										WHEN 10 THEN 'Octobre' 
										WHEN 11 THEN 'Novembre' 
										WHEN 12 THEN 'Decembre' 
										ELSE '?'
										END";
								break;
							case 'CALC_TRIMF':
								$field = "date_part('year',v_factures_lignes_c_4.date_facture) ||'-'|| 
								CASE to_char(v_factures_lignes_c_4.date_facture, 'Q')
										WHEN 1 THEN 'Trimestre 1'  
										WHEN 2 THEN 'Trimestre 2' 
										WHEN 3 THEN 'Trimestre 3' 
										WHEN 4 THEN 'Trimestre 4'
										ELSE '?'
										END";
								break;
							case 'CALC_NUMEROTRIMF':
								$field = "CASE to_char(v_factures_lignes_c_4.date_facture, 'Q')
										WHEN 1 THEN 'Trimestre 1'  
										WHEN 2 THEN 'Trimestre 2' 
										WHEN 3 THEN 'Trimestre 3' 
										WHEN 4 THEN 'Trimestre 4'
										ELSE '?'
										END";
								break;
							case 'CALC_NUMEROJOURF':
								$field = "CASE CASE extract(DOW FROM v_factures_lignes_c_4.date_facture) WHEN 0 THEN 7 ELSE extract(DOW FROM v_factures_lignes_c_4.date_facture) END
										WHEN 1 THEN 'Lundi'  
										WHEN 2 THEN 'Mardi' 
										WHEN 3 THEN 'Mercredi' 
										WHEN 4 THEN 'Jeudi'
										WHEN 5 THEN 'Vendredi'
										WHEN 6 THEN 'Samedi'
										WHEN 7 THEN 'Dimanche'
										ELSE '?'
										END";
								break;
							case 'CALC_JOURF':
								$field = "base.cti_to_char(v_factures_lignes_c_4.date_facture, 'FF')";
								break;
							case 'CALC_JOURSF':
								$field = "base.cti_to_char(v_factures_lignes_c_4.date_facture, 'DD') ||' '||
								CASE date_part('month',v_factures_lignes_c_4.date_facture)
										WHEN 01 THEN 'Janvier'  
										WHEN 02 THEN 'Fevrier' 
										WHEN 03 THEN 'Mars' 
										WHEN 04 THEN 'Avril' 
										WHEN 05 THEN 'Mai' 
										WHEN 06 THEN 'Juin' 
										WHEN 07 THEN 'Juillet'  
										WHEN 08 THEN 'Aout' 
										WHEN 09 THEN 'Septembre' 
										WHEN 10 THEN 'Octobre' 
										WHEN 11 THEN 'Novembre' 
										WHEN 12 THEN 'Decembre' 
										ELSE '?'
										END
								
								";
								break;

							case 'CALC_SEMAINEANNEF':
								$field = " 'Semaine '||' '|| to_char(v_factures_lignes_c_4.date_facture, 'WW')

										";
								break;
							case 'CALC_SEMAINEWEF':
								$field = "CASE to_char(v_factures_lignes_c_4.date_facture, 'W')
										WHEN 1 THEN 'Semaine 1'  
										WHEN 2 THEN 'Semaine 2' 
										WHEN 3 THEN 'Semaine 3' 
										WHEN 4 THEN 'Semaine 4'
										WHEN 5 THEN 'Semaine 5'
										ELSE '?'
										END";
								break;
							case "CALC_MOISF":
								$field = "CASE date_part('month',v_factures_lignes_c_4.date_facture)
										WHEN 01 THEN 'Janvier'  
										WHEN 02 THEN 'Fevrier' 
										WHEN 03 THEN 'Mars' 
										WHEN 04 THEN 'Avril' 
										WHEN 05 THEN 'Mai' 
										WHEN 06 THEN 'Juin' 
										WHEN 07 THEN 'Juillet'  
										WHEN 08 THEN 'Aout' 
										WHEN 09 THEN 'Septembre' 
										WHEN 10 THEN 'Octobre' 
										WHEN 11 THEN 'Novembre' 
										WHEN 12 THEN 'Decembre' 
										ELSE '?'
										END
										|| ' ' || date_part('year',v_factures_lignes_c_4.date_facture)";
								break;							
							
							case "CALC_ANNEEA":
								$field = "to_char(v_factures_lignes_c_4.date_fin, 'YYYY')";
								break;
							case 'CALC_NUMEROMOISA':
								$field = "CASE date_part('month',v_factures_lignes_c_4.date_fin)
										WHEN 01 THEN 'Janvier'  
										WHEN 02 THEN 'Fevrier' 
										WHEN 03 THEN 'Mars' 
										WHEN 04 THEN 'Avril' 
										WHEN 05 THEN 'Mai' 
										WHEN 06 THEN 'Juin' 
										WHEN 07 THEN 'Juillet'  
										WHEN 08 THEN 'Aout' 
										WHEN 09 THEN 'Septembre' 
										WHEN 10 THEN 'Octobre' 
										WHEN 11 THEN 'Novembre' 
										WHEN 12 THEN 'Decembre' 
										ELSE '?'
										END";
								break;
							case 'CALC_TRIMA':
								$field = "date_part('year',v_factures_lignes_c_4.date_fin) ||'-'|| 
								CASE to_char(v_factures_lignes_c_4.date_fin, 'Q')
										WHEN 1 THEN 'Trimestre 1'  
										WHEN 2 THEN 'Trimestre 2' 
										WHEN 3 THEN 'Trimestre 3' 
										WHEN 4 THEN 'Trimestre 4'
										ELSE '?'
										END";
								break;
							case 'CALC_NUMEROTRIMA':
								$field = "CASE to_char(v_factures_lignes_c_4.date_fin, 'Q')
										WHEN 1 THEN 'Trimestre 1'  
										WHEN 2 THEN 'Trimestre 2' 
										WHEN 3 THEN 'Trimestre 3' 
										WHEN 4 THEN 'Trimestre 4'
										ELSE '?'
										END";
								break;
							case 'CALC_NUMEROJOURA':
								$field = "CASE CASE extract(DOW FROM v_factures_lignes_c_4.date_fin) WHEN 0 THEN 7 ELSE extract(DOW FROM v_factures_lignes_c_4.date_fin) END
										WHEN 1 THEN 'Lundi'  
										WHEN 2 THEN 'Mardi' 
										WHEN 3 THEN 'Mercredi' 
										WHEN 4 THEN 'Jeudi'
										WHEN 5 THEN 'Vendredi'
										WHEN 6 THEN 'Samedi'
										WHEN 7 THEN 'Dimanche'
										ELSE '?'
										END";
								break;
							case 'CALC_JOURA':
								$field = "base.cti_to_char(v_factures_lignes_c_4.date_fin, 'FF')";
								break;
							case 'CALC_JOURSA':
								$field = "base.cti_to_char(v_factures_lignes_c_4.date_fin, 'DD') ||' '||
								CASE date_part('month',v_factures_lignes_c_4.date_fin)
										WHEN 01 THEN 'Janvier'  
										WHEN 02 THEN 'Fevrier' 
										WHEN 03 THEN 'Mars' 
										WHEN 04 THEN 'Avril' 
										WHEN 05 THEN 'Mai' 
										WHEN 06 THEN 'Juin' 
										WHEN 07 THEN 'Juillet'  
										WHEN 08 THEN 'Aout' 
										WHEN 09 THEN 'Septembre' 
										WHEN 10 THEN 'Octobre' 
										WHEN 11 THEN 'Novembre' 
										WHEN 12 THEN 'Decembre' 
										ELSE '?'
										END
								
								";
								break;

							case 'CALC_SEMAINEANNEA':
								$field = " 'Semaine '||' '|| to_char(v_factures_lignes_c_4.date_fin, 'WW')

										";
								break;
							case 'CALC_SEMAINEWEA':
								$field = "CASE to_char(v_factures_lignes_c_4.date_fin, 'W')
										WHEN 1 THEN 'Semaine 1'  
										WHEN 2 THEN 'Semaine 2' 
										WHEN 3 THEN 'Semaine 3' 
										WHEN 4 THEN 'Semaine 4'
										WHEN 5 THEN 'Semaine 5'
										ELSE '?'
										END";
								break;
							case "CALC_MOISA":
								$field = "CASE date_part('month',v_factures_lignes_c_4.date_fin)
										WHEN 01 THEN 'Janvier'  
										WHEN 02 THEN 'Fevrier' 
										WHEN 03 THEN 'Mars' 
										WHEN 04 THEN 'Avril' 
										WHEN 05 THEN 'Mai' 
										WHEN 06 THEN 'Juin' 
										WHEN 07 THEN 'Juillet'  
										WHEN 08 THEN 'Aout' 
										WHEN 09 THEN 'Septembre' 
										WHEN 10 THEN 'Octobre' 
										WHEN 11 THEN 'Novembre' 
										WHEN 12 THEN 'Decembre' 
										ELSE '?'
										END
										|| ' ' || date_part('year',v_factures_lignes_c_4.date_fin)";
								break;
							case "CALC_MOIA":
								$field = "CASE substr(v_factures_lignes_c_4.date_fin, 5 , 2)	
										WHEN '01' THEN 'Janvier'  
										WHEN '02' THEN 'Fevrier' 
										WHEN '03' THEN 'Mars' 
										WHEN '04' THEN 'Avril' 
										WHEN '05' THEN 'Mai' 
										WHEN '06' THEN 'Juin' 
										WHEN '07' THEN 'Juillet'  
										WHEN '08' THEN 'Aout' 
										WHEN '09' THEN 'Septembre' 
										WHEN '10' THEN 'Octobre' 
										WHEN '11' THEN 'Novembre' 
										WHEN '12' THEN 'Decembre' 
										ELSE '?'
										END
										|| ' ' || substr(v_factures_lignes_c_4.date_fin, 1 , 4)";
								break;							
							
							case "CALC_ANNEEV":
								$field = "to_char(v_factures_lignes_c_4.date_vente, 'YYYY')";
								break;
							case 'CALC_NUMEROMOISV':
								$field = "CASE date_part('month',v_factures_lignes_c_4.date_vente)
										WHEN 01 THEN 'Janvier'  
										WHEN 02 THEN 'Fevrier' 
										WHEN 03 THEN 'Mars' 
										WHEN 04 THEN 'Avril' 
										WHEN 05 THEN 'Mai' 
										WHEN 06 THEN 'Juin' 
										WHEN 07 THEN 'Juillet'  
										WHEN 08 THEN 'Aout' 
										WHEN 09 THEN 'Septembre' 
										WHEN 10 THEN 'Octobre' 
										WHEN 11 THEN 'Novembre' 
										WHEN 12 THEN 'Decembre' 
										ELSE '?'
										END";
								break;
							case 'CALC_TRIMV':
								$field = "date_part('year',v_factures_lignes_c_4.date_vente) ||'-'|| 
								CASE to_char(v_factures_lignes_c_4.date_vente, 'Q')
										WHEN 1 THEN 'Trimestre 1'  
										WHEN 2 THEN 'Trimestre 2' 
										WHEN 3 THEN 'Trimestre 3' 
										WHEN 4 THEN 'Trimestre 4'
										ELSE '?'
										END";
								break;
							case 'CALC_NUMEROTRIMV':
								$field = "CASE to_char(v_factures_lignes_c_4.date_vente, 'Q')
										WHEN 1 THEN 'Trimestre 1'  
										WHEN 2 THEN 'Trimestre 2' 
										WHEN 3 THEN 'Trimestre 3' 
										WHEN 4 THEN 'Trimestre 4'
										ELSE '?'
										END";
								break;
							case 'CALC_NUMEROJOURV':
								$field = "CASE CASE extract(DOW FROM v_factures_lignes_c_4.date_vente) WHEN 0 THEN 7 ELSE extract(DOW FROM v_factures_lignes_c_4.date_vente) END
										WHEN 1 THEN 'Lundi'  
										WHEN 2 THEN 'Mardi' 
										WHEN 3 THEN 'Mercredi' 
										WHEN 4 THEN 'Jeudi'
										WHEN 5 THEN 'Vendredi'
										WHEN 6 THEN 'Samedi'
										WHEN 7 THEN 'Dimanche'
										ELSE '?'
										END";
								break;
							case 'CALC_JOURV':
								$field = "base.cti_to_char(v_factures_lignes_c_4.date_vente, 'FF')";
								break;
							case 'CALC_JOURSV':
								$field = "base.cti_to_char(v_factures_lignes_c_4.date_vente, 'DD') ||' '||
								CASE date_part('month',v_factures_lignes_c_4.date_vente)
										WHEN 01 THEN 'Janvier'  
										WHEN 02 THEN 'Fevrier' 
										WHEN 03 THEN 'Mars' 
										WHEN 04 THEN 'Avril' 
										WHEN 05 THEN 'Mai' 
										WHEN 06 THEN 'Juin' 
										WHEN 07 THEN 'Juillet'  
										WHEN 08 THEN 'Aout' 
										WHEN 09 THEN 'Septembre' 
										WHEN 10 THEN 'Octobre' 
										WHEN 11 THEN 'Novembre' 
										WHEN 12 THEN 'Decembre' 
										ELSE '?'
										END
								
								";
								break;

							case 'CALC_SEMAINEANNEV':
								$field = " 'Semaine '||' '|| to_char(v_factures_lignes_c_4.date_vente, 'WW')

										";
								break;
							case 'CALC_SEMAINEWEV':
								$field = "CASE to_char(v_factures_lignes_c_4.date_vente, 'W')
										WHEN 1 THEN 'Semaine 1'  
										WHEN 2 THEN 'Semaine 2' 
										WHEN 3 THEN 'Semaine 3' 
										WHEN 4 THEN 'Semaine 4'
										WHEN 5 THEN 'Semaine 5'
										ELSE '?'
										END";
								break;
							case "CALC_MOISV":
								$field = "CASE date_part('month',v_factures_lignes_c_4.date_vente)
										WHEN 01 THEN 'Janvier'  
										WHEN 02 THEN 'Fevrier' 
										WHEN 03 THEN 'Mars' 
										WHEN 04 THEN 'Avril' 
										WHEN 05 THEN 'Mai' 
										WHEN 06 THEN 'Juin' 
										WHEN 07 THEN 'Juillet'  
										WHEN 08 THEN 'Aout' 
										WHEN 09 THEN 'Septembre' 
										WHEN 10 THEN 'Octobre' 
										WHEN 11 THEN 'Novembre' 
										WHEN 12 THEN 'Decembre' 
										ELSE '?'
										END
										|| ' ' || date_part('year',v_factures_lignes_c_4.date_vente)";
								break;
							case "CALC_MOIV":
								$field = "CASE substr(v_factures_lignes_c_4.date_vente, 5 , 2)	
										WHEN '01' THEN 'Janvier'  
										WHEN '02' THEN 'Fevrier' 
										WHEN '03' THEN 'Mars' 
										WHEN '04' THEN 'Avril' 
										WHEN '05' THEN 'Mai' 
										WHEN '06' THEN 'Juin' 
										WHEN '07' THEN 'Juillet'  
										WHEN '08' THEN 'Aout' 
										WHEN '09' THEN 'Septembre' 
										WHEN '10' THEN 'Octobre' 
										WHEN '11' THEN 'Novembre' 
										WHEN '12' THEN 'Decembre' 
										ELSE '?'
										END
										|| ' ' || substr(v_factures_lignes_c_4.date_vente, 1 , 4)";
								break;
							
							default:
								$field = "$prefixe" . "_texte";
						}
					}
					return $field;
				}
				
				function ACTI_PRESTATION_2_prefixe($GROUPBY, $DEFAULT="") {
					if (substr($GROUPBY,3,3) == 'CLS') {
						$GROUPBY = substr($GROUPBY,0,6);
					}
					$field = '';
					$field_id = '';
					$field_code = '';
					$field_texte = '';
					switch ($GROUPBY) {
					case '*TAB':
						$field = "*TAB";
						break;
					case '-1':
						$field = "";
						break;
					case 'RUF':
						$field = "CALC_ANNEE";
						break;					
					case 'ANNEE':case 'ANNEEA':
						$field = "CALC_ANNEE";
						break;
					case 'MOIS':case 'MOISA':
						$field = "CALC_MOIS";
						break;
					case 'TRIM':case 'TRIMA':
						$field = "CALC_TRIM";
						break;
					case 'JOUR':case 'JOURA':
						$field = "CALC_JOUR";
						break;
					case 'JOURS':case 'JOURSA':
						$field = "CALC_JOURS";
						break;
					case 'NUMEROSEMAINE':case 'NUMEROSEMAINEA':
						$field = "CALC_NUMEROSEMAINE";
						break;
					case 'NUMEROTRIM':case 'NUMEROTRIMA':
						$field = "CALC_NUMEROTRIM";
						break;
					case 'NUMEROJOUR':case 'NUMEROJOURA':
						$field = "CALC_NUMEROJOUR";
						break;
					case 'SEMAINEWE':
						$field = "CALC_SEMAINEWE";
						break;
					case 'NUMEROMOIS':case 'NUMEROMOISA':
						$field = "CALC_NUMEROMOIS";
						break;
					
					default:
						$field = $DEFAULT;
					}
					return $field;
					
					$prefixe = '';
					$groupby = '[GROUPBY]';
					if ($groupby == '-1') {$groupby = '[GROUPBY_2]';}

					$cls6 = substr($groupby, 0 , 6);
					$cls7 = substr($groupby, 6 , 1);

					
				}
				
				function ACTI_PRESTATION_2_field_id($GROUPBY, $DEFAULT="") {
				
					$prefixe ='';
					if ($prefixe == "") {
						$prefixe = ACTI_PRESTATION_2_prefixe($GROUPBY, $DEFAULT="");
					}
					
					if (substr($GROUPBY, 3, 3) == 'CLS' && $prefixe != $DEFAULT) {
						$section = substr($GROUPBY, 6);
						$field = "$prefixe" . "_id[" . $section . "]";
					}
					else {
						switch ($prefixe) {
							case "":
								$field = "0";
								break;
							case "*TAB":
								$field = "-9999999";
								break;
							case "CALC_ANNEE":
								$field = "EXTRACT(YEAR FROM date)";
								break;
							case "CALC_MOIS":
								$field = "v_mouvements_sejour_2.mois";
								break;
							case "CALC_TRIM":
								$field = "(EXTRACT(YEAR FROM date) * 10) + EXTRACT(QUARTER FROM date)";
								break;
							case "CALC_JOUR":
								$field = "EXTRACT(YEAR FROM date) * 10000 + EXTRACT(MONTH FROM date) * 100 + EXTRACT(DAY FROM date)";
								break;
							case "CALC_JOURS":
								$field = "EXTRACT(MONTH FROM date) * 100 + EXTRACT(DAY FROM date)";
								break;
							case "CALC_NUMEROSEMAINE":
								$field = "EXTRACT(WEEK FROM date)";
								break;
							case "CALC_NUMEROTRIM":
								$field = "EXTRACT(QUARTER FROM date)";
								break;
							case "CALC_NUMEROJOUR":
								$field = "jour_semaine";
								break;
							case "CALC_SEMAINEWE":
								$field = "is_weekend";
								break;
							case "CALC_NUMEROMOIS":
								$field = "EXTRACT(MONTH FROM date)";
								break;

							default:
								$field = "$prefixe" . "_id";
						}
					}
					return $field;
				}
				
				function ACTI_PRESTATION_2_field_code($GROUPBY, $DEFAULT="") {
				
					$prefixe = '';
					if ($prefixe == "") {
						$prefixe = ACTI_PRESTATION_2_prefixe($GROUPBY, $DEFAULT="");
					}
					
					if (substr($GROUPBY, 3, 3) == 'CLS' && $prefixe != $DEFAULT) {
						$section = substr($GROUPBY, 6);
						$field = "$prefixe" . "_code[" . $section . "]";
					}
					else {
						switch ($prefixe) {
							case "":
								$field = "''";
								break;
							case "*TAB":
								$field = "' Résumé'";
								break;
						case "CALC_ANNEE":
							$field = "EXTRACT(YEAR FROM date)";
							break;
						case "CALC_MOIS":
							$field = "v_mouvements_sejour_2.mois";
							break;
						case "CALC_TRIM":
							$field = "EXTRACT(YEAR FROM date)::text || ' T' || EXTRACT(QUARTER FROM date)::text";
							break;
						case "CALC_JOUR":
							$field = "v_mouvements_sejour_2.date::text";
							break;
						case "CALC_JOURS":
							$field = "to_char(v_mouvements_sejour_2.date, 'MM') ||'-'|| to_char(v_mouvements_sejour_2.date, 'DD')";
							break;
						case "CALC_NUMEROTRIM":
							$field = "'T' || EXTRACT(QUARTER FROM date)::text";
							break;
						case "CALC_NUMEROJOUR":
							$field = "jour_semaine";
							break;
						case "CALC_SEMAINEWE":
							$field = "(CASE WHEN is_weekend = 1 THEN 'WE' ELSE 'SEM' END)";
							break;
						case "CALC_NUMEROSEMAINE":
							$field = "'S' || lpad(EXTRACT(WEEK FROM date)::text, 2, '0')";
							break;
						case "CALC_NUMEROMOIS":
							$field = "base.cti_extract('MONTH_CODE', date)";
							break;
							default:
								$field = "$prefixe" . "_code";
						}
					}
					return $field;
				}
				
				function ACTI_PRESTATION_2_field_texte($GROUPBY, $DEFAULT="") {
					$prefixe = '';
					if ($prefixe == "") {
						$prefixe = ACTI_PRESTATION_2_prefixe($GROUPBY, $DEFAULT="");
					}
					
					if (substr($GROUPBY, 3, 3) == 'CLS' && $prefixe != $DEFAULT) {
						$section = substr($GROUPBY, 6);
						$field = "$prefixe" . "_texte[" . $section . "]";
					}
					else {
						switch ($prefixe) {
							case "":
								$field = "''";
								break;
							case "*TAB":
								$field = "'Résumé'";
								break;
						case "CALC_ANNEE":
							$field = "EXTRACT(YEAR FROM date)";
							break;
						case "CALC_MOIS":
							$field = "CASE substr(v_mouvements_sejour_2.mois , 5 , 2)	
									WHEN '01' THEN 'Janvier'  
									WHEN '02' THEN 'Fevrier' 
									WHEN '03' THEN 'Mars' 
									WHEN '04' THEN 'Avril' 
									WHEN '05' THEN 'Mai' 
									WHEN '06' THEN 'Juin' 
									WHEN '07' THEN 'Juillet'  
									WHEN '08' THEN 'Aout' 
									WHEN '09' THEN 'Septembre' 
									WHEN '10' THEN 'Octobre' 
									WHEN '11' THEN 'Novembre' 
									WHEN '12' THEN 'Decembre' 
									ELSE '?'
									END
									|| ' ' || substr(v_mouvements_sejour_2.mois , 1 , 4)";
							break;
						case "CALC_TRIM":
							$field = "EXTRACT(YEAR FROM date)::text || ' Trimestre ' || EXTRACT(QUARTER FROM date)::text";
							break;
						case "CALC_JOUR":
							$field = "base.cti_to_char(v_mouvements_sejour_2.date, 'FF')";
							break;
						case "CALC_JOURS":
							$field = "to_char(v_mouvements_sejour_2.date, 'DD') ||' '||
								CASE date_part('month',v_mouvements_sejour_2.date)
										WHEN 01 THEN 'Janvier'  
										WHEN 02 THEN 'Fevrier' 
										WHEN 03 THEN 'Mars' 
										WHEN 04 THEN 'Avril' 
										WHEN 05 THEN 'Mai' 
										WHEN 06 THEN 'Juin' 
										WHEN 07 THEN 'Juillet'  
										WHEN 08 THEN 'Aout' 
										WHEN 09 THEN 'Septembre' 
										WHEN 10 THEN 'Octobre' 
										WHEN 11 THEN 'Novembre' 
										WHEN 12 THEN 'Decembre' 
										ELSE '?'
										END
										";
							break;
						case "CALC_NUMEROTRIM":
							$field = "'Trimestre ' || EXTRACT(QUARTER FROM date)::text";
							break;
						case "CALC_NUMEROSEMAINE":
							$field = "'Semaine ' || lpad(EXTRACT(WEEK FROM date)::text, 2, '0')";
							break;
						case "CALC_NUMEROJOUR":
							$field = "CASE
										WHEN jour_semaine = 1 THEN 'Lundi'  
										WHEN jour_semaine = 2 THEN 'Mardi' 
										WHEN jour_semaine = 3 THEN 'Mercredi' 
										WHEN jour_semaine = 4 THEN 'Jeudi' 
										WHEN jour_semaine = 5 THEN 'Vendredi' 
										WHEN jour_semaine = 6 THEN 'Samedi' 
										WHEN jour_semaine = 7 THEN 'Dimanche' 
										ELSE '?'
										END";
							break;
						case "CALC_SEMAINEWE":
							$field = "(CASE WHEN is_weekend = 1 THEN 'Week-end' ELSE 'Semaine' END)";
							break;
						case "CALC_NUMEROMOIS":
							$field = "base.cti_extract('MONTH_TEXT', date)";
							break;

							
							default:
								$field = "$prefixe" . "_texte";
						}
					}
					return $field;
				}				
				
				function ACTI_PRESTATION_H_prefixe($GROUPBY, $DEFAULT="") {
					if (substr($GROUPBY,3,3) == 'CLS') {
						$GROUPBY = substr($GROUPBY,0,6);
					}
					$field = '';
					$field_id = '';
					$field_code = '';
					$field_texte = '';
					switch ($GROUPBY) {
					case '*TAB':
						$field = "*TAB";
						break;
					case '-1':
						$field = "";
						break;
			
					case 'ACTE':
						$field = "v_factures_lignes_h_3.acte";
						break;
					case 'ACXCLS':
						$field = "v_factures_lignes_h_3.acte_section";
						break;
					case 'ACTEREGR':
						$field = "v_factures_lignes_h_3.ccam_regroupement";
						break;
					case 'ACTECNOM':
						$field = "v_factures_lignes_h_3.acte_nomenclature";
						break;
					case 'PROT':
						$field = "protocole";
						break;
					case 'SPMF':
						$field = "medecin_facture_specialite";
						break;
					case 'EXEC':
						$field = "medecin_comptabilise";
						break;
					case 'EXAC':
						$field = "medecin_adm_comptabilise";
						break;
					case 'EXEF':
						$field = "medecin_facture";
						break;
					case 'EXAF':
						$field = "medecin_adm_facture";
						break;
					case 'EXACLS':
						$field = "medecin_adm_facture_section";
						break;
					case 'PRF':
						$field = "v_factures_lignes_h_3.prestation";
						break;
					case 'PRFCLS':
						$field = "v_factures_lignes_h_3.prestation_section";
						break;
					case 'RUF':
						$field = "v_factures_lignes_h_3.rubrique_facturation";
						break;
					case 'RUFCLS':
						$field = "v_factures_lignes_h_3.rubrique_facturation_section";
						break;
					case 'RUC':
						$field = "v_factures_lignes_h_3.rubrique_comptabilisation";
						break;
					case 'RUCCLS':
						$field = "v_factures_lignes_h_3.rubrique_comptabilisation_section";
						break;
					case 'SER':
						$field = "lieu_ligne_service";
						break;
					case 'SERCLS':
						$field = "lieu_ligne_service_section";
						break;
					case 'ACT':
						$field = "lieu_ligne_activite";
						break;
					case 'ETA':
						$field = "lieu_ligne_etage";
						break;
					case 'ETACLS':
						$field = "lieu_ligne_etage_section";
						break;
					case 'LIT':
						$field = "lieu_ligne_lit";
						break;
					case 'LITCLS':
						$field = "lieu_ligne_lit_section";
						break;
					case 'UM':
						$field = "lieu_ligne_unite_medicale";
						break;
					case 'UMDCLS':
						$field = "lieu_ligne_unite_medicale_section";
						break;
					case 'UF':
						$field = "lieu_ligne_unite_fonctionnelle";
						break;
					case 'UFTCLS':
						$field = "lieu_ligne_unite_fonctionnelle_section";
						break;
					case 'SPM':
						$field = "medecin_sejour_specialite";
						break;
					case 'MED':
						$field = "medecin_sejour";
						break;
					case 'MDA':
						$field = "medecin_adm_sejour";
						break;
					case 'MDACLS':
						$field = "medecin_adm_sejour_section";
						break;
					case 'MOIA':
						$field = "CALC_MOIA";
						break;
					case 'MOIS':
						$field = "CALC_MOIS";
						break;
					case 'ANNEE':
						$field = "CALC_ANNEE";
						break;
					case 'NUMEROMOIS':
						$field = "CALC_NUMEROMOIS";
						break;
					case 'TRIM':
						$field = "CALC_TRIM";
						break;
					case 'JOUR':
						$field = "CALC_JOUR";
						break;
					case 'JOURS':
						$field = "CALC_JOURS";
						break;
					case 'NUMEROTRIM':
						$field = "CALC_NUMEROTRIM";
						break;
					case 'NUMEROJOUR':
						$field = "CALC_NUMEROJOUR";
						break;
					case 'SEMAINEWE':
						$field = "CALC_SEMAINEWE";
						break;
					case 'SEMAINEANNE':
						$field = "CALC_SEMAINEANNE";
						break;
						
					case 'MOISF':
						$field = "CALC_MOISF";
						break;
					case 'ANNEEF':
						$field = "CALC_ANNEEF";
						break;
					case 'NUMEROMOISF':
						$field = "CALC_NUMEROMOISF";
						break;
					case 'TRIMF':
						$field = "CALC_TRIMF";
						break;
					case 'JOURF':
						$field = "CALC_JOURF";
						break;
					case 'JOURSF':
						$field = "CALC_JOURSF";
						break;
					case 'NUMEROTRIMF':
						$field = "CALC_NUMEROTRIMF";
						break;
					case 'NUMEROJOURF':
						$field = "CALC_NUMEROJOURF";
						break;
					case 'SEMAINEWEF':
						$field = "CALC_SEMAINEWEF";
						break;
					case 'SEMAINEANNEF':
						$field = "CALC_SEMAINEANNEF";
						break;					
					
					case 'MOISA':
						$field = "CALC_MOISA";
						break;
					case 'ANNEEA':
						$field = "CALC_ANNEEA";
						break;
					case 'NUMEROMOISA':
						$field = "CALC_NUMEROMOISA";
						break;
					case 'TRIMA':
						$field = "CALC_TRIMA";
						break;
					case 'JOURA':
						$field = "CALC_JOURA";
						break;
					case 'JOURSA':
						$field = "CALC_JOURSA";
						break;
					case 'NUMEROTRIMA':
						$field = "CALC_NUMEROTRIMA";
						break;
					case 'NUMEROJOURA':
						$field = "CALC_NUMEROJOURA";
						break;
					case 'SEMAINEWEA':
						$field = "CALC_SEMAINEWEA";
						break;
					case 'SEMAINEANNEA':
						$field = "CALC_SEMAINEANNEA";
						break;
						
					case 'MOISV':
						$field = "CALC_MOISV";
						break;
					case 'ANNEEV':
						$field = "CALC_ANNEEV";
						break;
					case 'NUMEROMOISV':
						$field = "CALC_NUMEROMOISV";
						break;
					case 'TRIMV':
						$field = "CALC_TRIMV";
						break;
					case 'JOURV':
						$field = "CALC_JOURV";
						break;
					case 'JOURSV':
						$field = "CALC_JOURSV";
						break;
					case 'NUMEROTRIMV':
						$field = "CALC_NUMEROTRIMV";
						break;
					case 'NUMEROJOURV':
						$field = "CALC_NUMEROJOURV";
						break;
					case 'SEMAINEWEV':
						$field = "CALC_SEMAINEWEV";
						break;
					case 'SEMAINEANNEV':
						$field = "CALC_SEMAINEANNEV";
						break;
					
					default:
						$field = $DEFAULT;
					}
					return $field;
					
					$prefixe = '';
					$groupby = '[GROUPBY]';
					if ($groupby == '-1') {$groupby = '[GROUPBY_2]';}

					$cls6 = substr($groupby, 0 , 6);
					$cls7 = substr($groupby, 6 , 1);

					
				}
				
				function ACTI_PRESTATION_H_field_id($GROUPBY, $DEFAULT="") {
				
					$prefixe = ACTI_STANDARD_prefixe($GROUPBY, $DEFAULT, "PRESTATION_H");
					if ($prefixe == "") {
						$prefixe = ACTI_PRESTATION_H_prefixe($GROUPBY, $DEFAULT="");
					}
					
					if (substr($GROUPBY, 3, 3) == 'CLS' && $prefixe != $DEFAULT) {
						$section = substr($GROUPBY, 6);
						$field = "$prefixe" . "_id[" . $section . "]";
					}
					else {
						switch ($prefixe) {
							case "":
								$field = "0";
								break;
							case "*TAB":
								$field = "-9999999";
								break;
							case "CALC_MOIA":
								$field = "v_factures_lignes_h_3.mois_fin";
								break;
							case 'CALC_ANNEE':
								$field = "to_char(v_factures_lignes_h_3.date_fin_facture, 'YYYY')";
								break;
							case 'CALC_NUMEROMOIS':
								$field = "to_char(v_factures_lignes_h_3.date_fin_facture, 'MM')";
								break;
							case 'CALC_TRIM':
								$field = "to_char(v_factures_lignes_h_3.date_fin_facture, 'YYYYQ')";
								break;
							case 'CALC_NUMEROTRIM':
								$field = "to_char(v_factures_lignes_h_3.date_fin_facture, 'Q')";
								break;
							case 'CALC_NUMEROJOUR':
								$field = "CASE extract(DOW FROM v_factures_lignes_h_3.date_fin_facture) WHEN 0 THEN 7 ELSE extract(DOW FROM v_factures_lignes_h_3.date_fin_facture) END";
								break;
							case 'CALC_JOUR':
								$field = "to_char(v_factures_lignes_h_3.date_fin_facture, 'YYYYMMDD')";
								break;
							case 'CALC_JOURS':
								$field = "to_char(v_factures_lignes_h_3.date_fin_facture, 'MMDD')";
								break;
							case "CALC_MOIS":
								$field = "to_char(v_factures_lignes_h_3.date_fin_facture, 'YYYYMM')";
								break;
							case 'CALC_SEMAINEWE':
								$field = "to_char(v_factures_lignes_h_3.date_fin_facture, 'W')";
								break;
							case 'CALC_SEMAINEANNE':
								$field = "to_char(v_factures_lignes_h_3.date_fin_facture, 'WW')";
								break;
								
							case 'CALC_ANNEEF':
								$field = "to_char(v_factures_lignes_h_3.date_facture, 'YYYY')";
								break;
							case 'CALC_NUMEROMOISF':
								$field = "to_char(v_factures_lignes_h_3.date_facture, 'MM')";
								break;
							case 'CALC_TRIMF':
								$field = "to_char(v_factures_lignes_h_3.date_facture, 'YYYYQ')";
								break;
							case 'CALC_NUMEROTRIMF':
								$field = "to_char(v_factures_lignes_h_3.date_facture, 'Q')";
								break;
							case 'CALC_NUMEROJOURF':
								$field = "CASE extract(DOW FROM v_factures_lignes_h_3.date_facture) WHEN 0 THEN 7 ELSE extract(DOW FROM v_factures_lignes_h_3.date_facture) END";
								break;
							case 'CALC_JOURF':
								$field = "to_char(v_factures_lignes_h_3.date_facture, 'YYYYMMDD')";
								break;
							case 'CALC_JOURSF':
								$field = "to_char(v_factures_lignes_h_3.date_facture, 'MMDD')";
								break;
							case 'CALC_SEMAINEWEF':
								$field = "to_char(v_factures_lignes_h_3.date_facture, 'W')";
								break;
							case 'CALC_SEMAINEANNEF':
								$field = "to_char(v_factures_lignes_h_3.date_facture, 'WW')";
								break;
							case "CALC_MOISF":
								$field = "to_char(v_factures_lignes_h_3.date_facture, 'YYYYMM')";
								break;							
							
							case 'CALC_ANNEEA':
								$field = "to_char(v_factures_lignes_h_3.date_fin, 'YYYY')";
								break;
							case 'CALC_NUMEROMOISA':
								$field = "to_char(v_factures_lignes_h_3.date_fin, 'MM')";
								break;
							case 'CALC_TRIMA':
								$field = "to_char(v_factures_lignes_h_3.date_fin, 'YYYYQ')";
								break;                              
							case 'CALC_NUMEROTRIMA':                
								$field = "to_char(v_factures_lignes_h_3.date_fin, 'Q')";
								break;                              
							case 'CALC_NUMEROJOURA':                
								$field = "CASE extract(DOW FROM v_factures_lignes_h_3.date_fin) WHEN 0 THEN 7 ELSE extract(DOW FROM v_factures_lignes_h_3.date_fin) END";
								break;
							case 'CALC_JOURA':
								$field = "to_char(v_factures_lignes_h_3.date_fin, 'YYYYMMDD')";
								break;
							case 'CALC_JOURSA':
								$field = "to_char(v_factures_lignes_h_3.date_fin, 'MMDD')";
								break;
							case 'CALC_SEMAINEWEA':
								$field = "to_char(v_factures_lignes_h_3.date_fin, 'W')";
								break;
							case 'CALC_SEMAINEANNEA':
								$field = "to_char(v_factures_lignes_h_3.date_fin, 'WW')";
								break;
							case "CALC_MOISA":
								$field = "to_char(v_factures_lignes_h_3.date_fin, 'YYYYMM')";
								break;							
							
							case 'CALC_ANNEEV':
								$field = "to_char(v_factures_lignes_h_3.date_vente, 'YYYY')";
								break;
							case 'CALC_NUMEROMOISV':
								$field = "to_char(v_factures_lignes_h_3.date_vente, 'MM')";
								break;
							case 'CALC_TRIMV':
								$field = "to_char(v_factures_lignes_h_3.date_vente, 'YYYYQ')";
								break;
							case 'CALC_NUMEROTRIMV':
								$field = "to_char(v_factures_lignes_h_3.date_vente, 'Q')";
								break;
							case 'CALC_NUMEROJOURV':
								$field = "CASE extract(DOW FROM v_factures_lignes_h_3.date_vente) WHEN 0 THEN 7 ELSE extract(DOW FROM v_factures_lignes_h_3.date_vente) END";
								break;
							case 'CALC_JOURV':
								$field = "to_char(v_factures_lignes_h_3.date_vente, 'YYYYMMDD')";
								break;
							case 'CALC_JOURSV':
								$field = "to_char(v_factures_lignes_h_3.date_vente, 'MMDD')";
								break;
							case 'CALC_SEMAINEWEV':
								$field = "to_char(v_factures_lignes_h_3.date_vente, 'W')";
								break;
							case 'CALC_SEMAINEANNEV':
								$field = "to_char(v_factures_lignes_h_3.date_vente, 'WW')";
								break;
							case "CALC_MOISV":
								$field = "to_char(v_factures_lignes_h_3.date_vente, 'YYYYMM')";
								break;
							default:
								$field = "$prefixe" . "_id";
						}
					}
					return $field;
				}
				
				function ACTI_PRESTATION_H_field_code($GROUPBY, $DEFAULT="") {
				
					$prefixe = ACTI_STANDARD_prefixe($GROUPBY, $DEFAULT, "PRESTATION_H");
					if ($prefixe == "") {
						$prefixe = ACTI_PRESTATION_H_prefixe($GROUPBY, $DEFAULT="");
					}
					
					if (substr($GROUPBY, 3, 3) == 'CLS' && $prefixe != $DEFAULT) {
						$section = substr($GROUPBY, 6);
						$field = "$prefixe" . "_code[" . $section . "]";
					}
					else {
						switch ($prefixe) {
							case "":
								$field = "''";
								break;
							case "*TAB":
								$field = "' Résumé'";
								break;
							case "CALC_MOIA":
								$field = "v_factures_lignes_h_3.mois_fin";
								break;
							case 'CALC_ANNEE':
								$field = "to_char(v_factures_lignes_h_3.date_fin_facture, 'YYYY')";
								break;
							case 'CALC_NUMEROMOIS':
								$field = "to_char(v_factures_lignes_h_3.date_fin_facture, 'MM')";
								break;
							case 'CALC_TRIM':
								$field = "to_char(v_factures_lignes_h_3.date_fin_facture, 'YYYY') ||' T'|| to_char(v_factures_lignes_h_3.date_fin_facture, 'Q')  ";
								break;
							case 'CALC_NUMEROTRIM':
								$field = "to_char(v_factures_lignes_h_3.date_fin_facture, 'Q')";
								break;
							case 'CALC_NUMEROJOUR':
								$field = "CASE extract(DOW FROM v_factures_lignes_h_3.date_fin_facture) WHEN 0 THEN 7 ELSE extract(DOW FROM v_factures_lignes_h_3.date_fin_facture) END";
								break;
							case 'CALC_SEMAINEWE':
								$field = "to_char(v_factures_lignes_h_3.date_fin_facture, 'W')";
								break;
							case 'CALC_SEMAINEANNE':
								$field = "to_char(v_factures_lignes_h_3.date_fin_facture, 'WW')";
								break;
							case 'CALC_JOUR':
								$field = "to_char(v_factures_lignes_h_3.date_fin_facture, 'YYYY') ||'-'|| to_char(v_factures_lignes_h_3.date_fin_facture, 'MM') ||'-'||to_char(v_factures_lignes_h_3.date_fin_facture, 'DD')";
								break;
							case 'CALC_JOURS':
								$field = " to_char(v_factures_lignes_h_3.date_fin_facture, 'MM') ||'-'|| to_char(v_factures_lignes_h_3.date_fin_facture, 'DD') ";
								break;
							case "CALC_MOIS":
								$field = "to_char(v_factures_lignes_h_3.date_fin_facture, 'YYYYMM')";
								break;
							case 'CALC_ANNEEF':
								$field = "to_char(v_factures_lignes_h_3.date_facture, 'YYYY')";
								break;
							case 'CALC_NUMEROMOISF':
								$field = "to_char(v_factures_lignes_h_3.date_facture, 'MM')";
								break;
							case 'CALC_TRIMF':
								$field = "to_char(v_factures_lignes_h_3.date_facture, 'YYYY') ||' T'|| to_char(v_factures_lignes_h_3.date_facture, 'Q')  ";
								break;
							case 'CALC_NUMEROTRIMF':
								$field = "to_char(v_factures_lignes_h_3.date_facture, 'Q')";
								break;
							case 'CALC_NUMEROJOURF':
								$field = "CASE extract(DOW FROM v_factures_lignes_h_3.date_facture) WHEN 0 THEN 7 ELSE extract(DOW FROM v_factures_lignes_h_3.date_facture) END";
								break;
							case 'CALC_SEMAINEWEF':
								$field = "to_char(v_factures_lignes_h_3.date_facture, 'W')";
								break;
							case 'CALC_SEMAINEANNEF':
								$field = "to_char(v_factures_lignes_h_3.date_facture, 'WW')";
								break;
							case 'CALC_JOURF':
								$field = "to_char(v_factures_lignes_h_3.date_facture, 'YYYY') ||'-'|| to_char(v_factures_lignes_h_3.date_facture, 'MM') ||'-'||to_char(v_factures_lignes_h_3.date_facture, 'DD')";
								break;
							case 'CALC_JOURSF':
								$field = " to_char(v_factures_lignes_h_3.date_facture, 'MM') ||'-'|| to_char(v_factures_lignes_h_3.date_facture, 'DD') ";
								break;
							case "CALC_MOISF":
								$field = "to_char(v_factures_lignes_h_3.date_facture, 'YYYYMM')";
								break;							
							
							case 'CALC_ANNEEA':
								$field = "to_char(v_factures_lignes_h_3.date_fin, 'YYYY')";
								break;
							case 'CALC_NUMEROMOISA':
								$field = "to_char(v_factures_lignes_h_3.date_fin, 'MM')";
								break;
							case 'CALC_TRIMA':
								$field = "to_char(v_factures_lignes_h_3.date_fin, 'YYYY') ||' T'|| to_char(v_factures_lignes_h_3.date_fin, 'Q')  ";
								break;
							case 'CALC_NUMEROTRIMA':
								$field = "to_char(v_factures_lignes_h_3.date_fin, 'Q')";
								break;
							case 'CALC_NUMEROJOURA':
								$field = "CASE extract(DOW FROM v_factures_lignes_h_3.date_fin) WHEN 0 THEN 7 ELSE extract(DOW FROM v_factures_lignes_h_3.date_fin) END";
								break;
							case 'CALC_SEMAINEWEA':
								$field = "to_char(v_factures_lignes_h_3.date_fin, 'W')";
								break;
							case 'CALC_SEMAINEANNEA':
								$field = "to_char(v_factures_lignes_h_3.date_fin, 'WW')";
								break;
							case 'CALC_JOURA':
								$field = "to_char(v_factures_lignes_h_3.date_fin, 'YYYY') ||'-'|| to_char(v_factures_lignes_h_3.date_fin, 'MM') ||'-'||to_char(v_factures_lignes_h_3.date_fin, 'DD')";
								break;
							case 'CALC_JOURSA':
								$field = " to_char(v_factures_lignes_h_3.date_fin, 'MM') ||'-'|| to_char(v_factures_lignes_h_3.date_fin, 'DD') ";
								break;
							case "CALC_MOISA":
								$field = "to_char(v_factures_lignes_h_3.date_fin, 'YYYYMM')";
								break;							
							
							case 'CALC_ANNEEV':
								$field = "to_char(v_factures_lignes_h_3.date_vente, 'YYYY')";
								break;
							case 'CALC_NUMEROMOISV':
								$field = "to_char(v_factures_lignes_h_3.date_vente, 'MM')";
								break;
							case 'CALC_TRIMV':
								$field = "to_char(v_factures_lignes_h_3.date_vente, 'YYYY') ||' T'|| to_char(v_factures_lignes_h_3.date_vente, 'Q')  ";
								break;
							case 'CALC_NUMEROTRIMV':
								$field = "to_char(v_factures_lignes_h_3.date_vente, 'Q')";
								break;
							case 'CALC_NUMEROJOURV':
								$field = "CASE extract(DOW FROM v_factures_lignes_h_3.date_vente) WHEN 0 THEN 7 ELSE extract(DOW FROM v_factures_lignes_h_3.date_vente) END";
								break;
							case 'CALC_SEMAINEWEV':
								$field = "to_char(v_factures_lignes_h_3.date_vente, 'W')";
								break;
							case 'CALC_SEMAINEANNEV':
								$field = "to_char(v_factures_lignes_h_3.date_vente, 'WW')";
								break;
							case 'CALC_JOURV':
								$field = "to_char(v_factures_lignes_h_3.date_vente, 'YYYY') ||'-'|| to_char(v_factures_lignes_h_3.date_vente, 'MM') ||'-'||to_char(v_factures_lignes_h_3.date_vente, 'DD')";
								break;
							case 'CALC_JOURSV':
								$field = " to_char(v_factures_lignes_h_3.date_vente, 'MM') ||'-'|| to_char(v_factures_lignes_h_3.date_vente, 'DD') ";
								break;
							case "CALC_MOISV":
								$field = "to_char(v_factures_lignes_h_3.date_vente, 'YYYYMM')";
								break;
							default:
								$field = "$prefixe" . "_code";
						}
					}
					return $field;
				}
				
				function ACTI_PRESTATION_H_field_texte($GROUPBY, $DEFAULT="") {
				
					$prefixe = ACTI_STANDARD_prefixe($GROUPBY, $DEFAULT, "PRESTATION_H");
					if ($prefixe == "") {
						$prefixe = ACTI_PRESTATION_H_prefixe($GROUPBY, $DEFAULT="");
					}
					
					if (substr($GROUPBY, 3, 3) == 'CLS' && $prefixe != $DEFAULT) {
						$section = substr($GROUPBY, 6);
						$field = "$prefixe" . "_texte[" . $section . "]";
					}
					else {
						switch ($prefixe) {
							case "":
								$field = "''";
								break;
							case "*TAB":
								$field = "'Résumé'";
								break;
							case "medecin_adm_sejour":
								$field = "$prefixe" . "_nom_prenom";
								break;
							case "medecin_sejour":
								$field = "$prefixe" . "_nom_prenom";
								break;
							case "medecin_adm_comptabilise":
								$field = "$prefixe" . "_nom_prenom";
								break;
							case "medecin_comptabilise":
								$field = "$prefixe" . "_nom_prenom";
								break;
							case "medecin_adm_facture":
								$field = "$prefixe" . "_nom_prenom";
								break;
							case "medecin_facture":
								$field = "$prefixe" . "_nom_prenom";
								break;
							case "CALC_ANNEE":
								$field = "to_char(v_factures_lignes_h_3.date_fin_facture, 'YYYY')";
								break;
							case 'CALC_NUMEROMOIS':
								$field = "CASE date_part('month',v_factures_lignes_h_3.date_fin_facture)
										WHEN 01 THEN 'Janvier'  
										WHEN 02 THEN 'Fevrier' 
										WHEN 03 THEN 'Mars' 
										WHEN 04 THEN 'Avril' 
										WHEN 05 THEN 'Mai' 
										WHEN 06 THEN 'Juin' 
										WHEN 07 THEN 'Juillet'  
										WHEN 08 THEN 'Aout' 
										WHEN 09 THEN 'Septembre' 
										WHEN 10 THEN 'Octobre' 
										WHEN 11 THEN 'Novembre' 
										WHEN 12 THEN 'Decembre' 
										ELSE '?'
										END";
								break;
							case 'CALC_TRIM':
								$field = "date_part('year',v_factures_lignes_h_3.date_fin_facture) ||'-'|| 
								CASE to_char(v_factures_lignes_h_3.date_fin_facture, 'Q')
										WHEN 1 THEN 'Trimestre 1'  
										WHEN 2 THEN 'Trimestre 2' 
										WHEN 3 THEN 'Trimestre 3' 
										WHEN 4 THEN 'Trimestre 4'
										ELSE '?'
										END";
								break;
							case 'CALC_NUMEROTRIM':
								$field = "CASE to_char(v_factures_lignes_h_3.date_fin_facture, 'Q')
										WHEN 1 THEN 'Trimestre 1'  
										WHEN 2 THEN 'Trimestre 2' 
										WHEN 3 THEN 'Trimestre 3' 
										WHEN 4 THEN 'Trimestre 4'
										ELSE '?'
										END";
								break;
							case 'CALC_NUMEROJOUR':
								$field = "CASE CASE extract(DOW FROM v_factures_lignes_h_3.date_fin_facture) WHEN 0 THEN 7 ELSE extract(DOW FROM v_factures_lignes_h_3.date_fin_facture) END
										WHEN 1 THEN 'Lundi'  
										WHEN 2 THEN 'Mardi' 
										WHEN 3 THEN 'Mercredi' 
										WHEN 4 THEN 'Jeudi'
										WHEN 5 THEN 'Vendredi'
										WHEN 6 THEN 'Samedi'
										WHEN 7 THEN 'Dimanche'
										ELSE '?'
										END";
								break;
							case 'CALC_JOUR':
								$field = "base.cti_to_char(v_factures_lignes_h_3.date_fin_facture, 'FF')";
								break;
							case 'CALC_JOURS':
								$field = "base.cti_to_char(v_factures_lignes_h_3.date_fin_facture, 'DD') ||' '||
								CASE date_part('month',v_factures_lignes_h_3.date_fin_facture)
										WHEN 01 THEN 'Janvier'  
										WHEN 02 THEN 'Fevrier' 
										WHEN 03 THEN 'Mars' 
										WHEN 04 THEN 'Avril' 
										WHEN 05 THEN 'Mai' 
										WHEN 06 THEN 'Juin' 
										WHEN 07 THEN 'Juillet'  
										WHEN 08 THEN 'Aout' 
										WHEN 09 THEN 'Septembre' 
										WHEN 10 THEN 'Octobre' 
										WHEN 11 THEN 'Novembre' 
										WHEN 12 THEN 'Decembre' 
										ELSE '?'
										END
								
								";
								break;

							case 'CALC_SEMAINEANNE':
								$field = " 'Semaine '||' '|| to_char(v_factures_lignes_h_3.date_fin_facture, 'WW')

										";
								break;
							case 'CALC_SEMAINEWE':
								$field = "CASE to_char(v_factures_lignes_h_3.date_fin_facture, 'W')
										WHEN 1 THEN 'Semaine 1'  
										WHEN 2 THEN 'Semaine 2' 
										WHEN 3 THEN 'Semaine 3' 
										WHEN 4 THEN 'Semaine 4'
										WHEN 5 THEN 'Semaine 5'
										ELSE '?'
										END";
								break;
							case "CALC_MOIS":
								$field = "CASE date_part('month',v_factures_lignes_h_3.date_fin_facture)
										WHEN 01 THEN 'Janvier'  
										WHEN 02 THEN 'Fevrier' 
										WHEN 03 THEN 'Mars' 
										WHEN 04 THEN 'Avril' 
										WHEN 05 THEN 'Mai' 
										WHEN 06 THEN 'Juin' 
										WHEN 07 THEN 'Juillet'  
										WHEN 08 THEN 'Aout' 
										WHEN 09 THEN 'Septembre' 
										WHEN 10 THEN 'Octobre' 
										WHEN 11 THEN 'Novembre' 
										WHEN 12 THEN 'Decembre' 
										ELSE '?'
										END
										|| ' ' || date_part('year',v_factures_lignes_h_3.date_fin_facture)";
								break;
							case "CALC_ANNEEF":
								$field = "to_char(v_factures_lignes_h_3.date_facture, 'YYYY')";
								break;
							case 'CALC_NUMEROMOISF':
								$field = "CASE date_part('month',v_factures_lignes_h_3.date_facture)
										WHEN 01 THEN 'Janvier'  
										WHEN 02 THEN 'Fevrier' 
										WHEN 03 THEN 'Mars' 
										WHEN 04 THEN 'Avril' 
										WHEN 05 THEN 'Mai' 
										WHEN 06 THEN 'Juin' 
										WHEN 07 THEN 'Juillet'  
										WHEN 08 THEN 'Aout' 
										WHEN 09 THEN 'Septembre' 
										WHEN 10 THEN 'Octobre' 
										WHEN 11 THEN 'Novembre' 
										WHEN 12 THEN 'Decembre' 
										ELSE '?'
										END";
								break;
							case 'CALC_TRIMF':
								$field = "date_part('year',v_factures_lignes_h_3.date_facture) ||'-'|| 
								CASE to_char(v_factures_lignes_h_3.date_facture, 'Q')
										WHEN 1 THEN 'Trimestre 1'  
										WHEN 2 THEN 'Trimestre 2' 
										WHEN 3 THEN 'Trimestre 3' 
										WHEN 4 THEN 'Trimestre 4'
										ELSE '?'
										END";
								break;
							case 'CALC_NUMEROTRIMF':
								$field = "CASE to_char(v_factures_lignes_h_3.date_facture, 'Q')
										WHEN 1 THEN 'Trimestre 1'  
										WHEN 2 THEN 'Trimestre 2' 
										WHEN 3 THEN 'Trimestre 3' 
										WHEN 4 THEN 'Trimestre 4'
										ELSE '?'
										END";
								break;
							case 'CALC_NUMEROJOURF':
								$field = "CASE CASE extract(DOW FROM v_factures_lignes_h_3.date_facture) WHEN 0 THEN 7 ELSE extract(DOW FROM v_factures_lignes_h_3.date_facture) END
										WHEN 1 THEN 'Lundi'  
										WHEN 2 THEN 'Mardi' 
										WHEN 3 THEN 'Mercredi' 
										WHEN 4 THEN 'Jeudi'
										WHEN 5 THEN 'Vendredi'
										WHEN 6 THEN 'Samedi'
										WHEN 7 THEN 'Dimanche'
										ELSE '?'
										END";
								break;
							case 'CALC_JOURF':
								$field = "base.cti_to_char(v_factures_lignes_h_3.date_facture, 'FF')";
								break;
							case 'CALC_JOURSF':
								$field = "base.cti_to_char(v_factures_lignes_h_3.date_facture, 'DD') ||' '||
								CASE date_part('month',v_factures_lignes_h_3.date_facture)
										WHEN 01 THEN 'Janvier'  
										WHEN 02 THEN 'Fevrier' 
										WHEN 03 THEN 'Mars' 
										WHEN 04 THEN 'Avril' 
										WHEN 05 THEN 'Mai' 
										WHEN 06 THEN 'Juin' 
										WHEN 07 THEN 'Juillet'  
										WHEN 08 THEN 'Aout' 
										WHEN 09 THEN 'Septembre' 
										WHEN 10 THEN 'Octobre' 
										WHEN 11 THEN 'Novembre' 
										WHEN 12 THEN 'Decembre' 
										ELSE '?'
										END
								
								";
								break;

							case 'CALC_SEMAINEANNEF':
								$field = " 'Semaine '||' '|| to_char(v_factures_lignes_h_3.date_facture, 'WW')

										";
								break;
							case 'CALC_SEMAINEWEF':
								$field = "CASE to_char(v_factures_lignes_h_3.date_facture, 'W')
										WHEN 1 THEN 'Semaine 1'  
										WHEN 2 THEN 'Semaine 2' 
										WHEN 3 THEN 'Semaine 3' 
										WHEN 4 THEN 'Semaine 4'
										WHEN 5 THEN 'Semaine 5'
										ELSE '?'
										END";
								break;
							case "CALC_MOISF":
								$field = "CASE date_part('month',v_factures_lignes_h_3.date_facture)
										WHEN 01 THEN 'Janvier'  
										WHEN 02 THEN 'Fevrier' 
										WHEN 03 THEN 'Mars' 
										WHEN 04 THEN 'Avril' 
										WHEN 05 THEN 'Mai' 
										WHEN 06 THEN 'Juin' 
										WHEN 07 THEN 'Juillet'  
										WHEN 08 THEN 'Aout' 
										WHEN 09 THEN 'Septembre' 
										WHEN 10 THEN 'Octobre' 
										WHEN 11 THEN 'Novembre' 
										WHEN 12 THEN 'Decembre' 
										ELSE '?'
										END
										|| ' ' || date_part('year',v_factures_lignes_h_3.date_facture)";
								break;							
							
							case "CALC_ANNEEA":
								$field = "to_char(v_factures_lignes_h_3.date_fin, 'YYYY')";
								break;
							case 'CALC_NUMEROMOISA':
								$field = "CASE date_part('month',v_factures_lignes_h_3.date_fin)
										WHEN 01 THEN 'Janvier'  
										WHEN 02 THEN 'Fevrier' 
										WHEN 03 THEN 'Mars' 
										WHEN 04 THEN 'Avril' 
										WHEN 05 THEN 'Mai' 
										WHEN 06 THEN 'Juin' 
										WHEN 07 THEN 'Juillet'  
										WHEN 08 THEN 'Aout' 
										WHEN 09 THEN 'Septembre' 
										WHEN 10 THEN 'Octobre' 
										WHEN 11 THEN 'Novembre' 
										WHEN 12 THEN 'Decembre' 
										ELSE '?'
										END";
								break;
							case 'CALC_TRIMA':
								$field = "date_part('year',v_factures_lignes_h_3.date_fin) ||'-'|| 
								CASE to_char(v_factures_lignes_h_3.date_fin, 'Q')
										WHEN 1 THEN 'Trimestre 1'  
										WHEN 2 THEN 'Trimestre 2' 
										WHEN 3 THEN 'Trimestre 3' 
										WHEN 4 THEN 'Trimestre 4'
										ELSE '?'
										END";
								break;
							case 'CALC_NUMEROTRIMA':
								$field = "CASE to_char(v_factures_lignes_h_3.date_fin, 'Q')
										WHEN 1 THEN 'Trimestre 1'  
										WHEN 2 THEN 'Trimestre 2' 
										WHEN 3 THEN 'Trimestre 3' 
										WHEN 4 THEN 'Trimestre 4'
										ELSE '?'
										END";
								break;
							case 'CALC_NUMEROJOURA':
								$field = "CASE CASE extract(DOW FROM v_factures_lignes_h_3.date_fin) WHEN 0 THEN 7 ELSE extract(DOW FROM v_factures_lignes_h_3.date_fin) END
										WHEN 1 THEN 'Lundi'  
										WHEN 2 THEN 'Mardi' 
										WHEN 3 THEN 'Mercredi' 
										WHEN 4 THEN 'Jeudi'
										WHEN 5 THEN 'Vendredi'
										WHEN 6 THEN 'Samedi'
										WHEN 7 THEN 'Dimanche'
										ELSE '?'
										END";
								break;
							case 'CALC_JOURA':
								$field = "base.cti_to_char(v_factures_lignes_h_3.date_fin, 'FF')";
								break;
							case 'CALC_JOURSA':
								$field = "base.cti_to_char(v_factures_lignes_h_3.date_fin, 'DD') ||' '||
								CASE date_part('month',v_factures_lignes_h_3.date_fin)
										WHEN 01 THEN 'Janvier'  
										WHEN 02 THEN 'Fevrier' 
										WHEN 03 THEN 'Mars' 
										WHEN 04 THEN 'Avril' 
										WHEN 05 THEN 'Mai' 
										WHEN 06 THEN 'Juin' 
										WHEN 07 THEN 'Juillet'  
										WHEN 08 THEN 'Aout' 
										WHEN 09 THEN 'Septembre' 
										WHEN 10 THEN 'Octobre' 
										WHEN 11 THEN 'Novembre' 
										WHEN 12 THEN 'Decembre' 
										ELSE '?'
										END
								
								";
								break;

							case 'CALC_SEMAINEANNEA':
								$field = " 'Semaine '||' '|| to_char(v_factures_lignes_h_3.date_fin, 'WW')

										";
								break;
							case 'CALC_SEMAINEWEA':
								$field = "CASE to_char(v_factures_lignes_h_3.date_fin, 'W')
										WHEN 1 THEN 'Semaine 1'  
										WHEN 2 THEN 'Semaine 2' 
										WHEN 3 THEN 'Semaine 3' 
										WHEN 4 THEN 'Semaine 4'
										WHEN 5 THEN 'Semaine 5'
										ELSE '?'
										END";
								break;
							case "CALC_MOISA":
								$field = "CASE date_part('month',v_factures_lignes_h_3.date_fin)
										WHEN 01 THEN 'Janvier'  
										WHEN 02 THEN 'Fevrier' 
										WHEN 03 THEN 'Mars' 
										WHEN 04 THEN 'Avril' 
										WHEN 05 THEN 'Mai' 
										WHEN 06 THEN 'Juin' 
										WHEN 07 THEN 'Juillet'  
										WHEN 08 THEN 'Aout' 
										WHEN 09 THEN 'Septembre' 
										WHEN 10 THEN 'Octobre' 
										WHEN 11 THEN 'Novembre' 
										WHEN 12 THEN 'Decembre' 
										ELSE '?'
										END
										|| ' ' || date_part('year',v_factures_lignes_h_3.date_fin)";
								break;
							case "CALC_MOIA":
								$field = "CASE substr(v_factures_lignes_h_3.date_fin, 5 , 2)	
										WHEN '01' THEN 'Janvier'  
										WHEN '02' THEN 'Fevrier' 
										WHEN '03' THEN 'Mars' 
										WHEN '04' THEN 'Avril' 
										WHEN '05' THEN 'Mai' 
										WHEN '06' THEN 'Juin' 
										WHEN '07' THEN 'Juillet'  
										WHEN '08' THEN 'Aout' 
										WHEN '09' THEN 'Septembre' 
										WHEN '10' THEN 'Octobre' 
										WHEN '11' THEN 'Novembre' 
										WHEN '12' THEN 'Decembre' 
										ELSE '?'
										END
										|| ' ' || substr(v_factures_lignes_h_3.date_fin, 1 , 4)";
								break;							
							
							case "CALC_ANNEEV":
								$field = "to_char(v_factures_lignes_h_3.date_vente, 'YYYY')";
								break;
							case 'CALC_NUMEROMOISV':
								$field = "CASE date_part('month',v_factures_lignes_h_3.date_vente)
										WHEN 01 THEN 'Janvier'  
										WHEN 02 THEN 'Fevrier' 
										WHEN 03 THEN 'Mars' 
										WHEN 04 THEN 'Avril' 
										WHEN 05 THEN 'Mai' 
										WHEN 06 THEN 'Juin' 
										WHEN 07 THEN 'Juillet'  
										WHEN 08 THEN 'Aout' 
										WHEN 09 THEN 'Septembre' 
										WHEN 10 THEN 'Octobre' 
										WHEN 11 THEN 'Novembre' 
										WHEN 12 THEN 'Decembre' 
										ELSE '?'
										END";
								break;
							case 'CALC_TRIMV':
								$field = "date_part('year',v_factures_lignes_h_3.date_vente) ||'-'|| 
								CASE to_char(v_factures_lignes_h_3.date_vente, 'Q')
										WHEN 1 THEN 'Trimestre 1'  
										WHEN 2 THEN 'Trimestre 2' 
										WHEN 3 THEN 'Trimestre 3' 
										WHEN 4 THEN 'Trimestre 4'
										ELSE '?'
										END";
								break;
							case 'CALC_NUMEROTRIMV':
								$field = "CASE to_char(v_factures_lignes_h_3.date_vente, 'Q')
										WHEN 1 THEN 'Trimestre 1'  
										WHEN 2 THEN 'Trimestre 2' 
										WHEN 3 THEN 'Trimestre 3' 
										WHEN 4 THEN 'Trimestre 4'
										ELSE '?'
										END";
								break;
							case 'CALC_NUMEROJOURV':
								$field = "CASE CASE extract(DOW FROM v_factures_lignes_h_3.date_vente) WHEN 0 THEN 7 ELSE extract(DOW FROM v_factures_lignes_h_3.date_vente) END
										WHEN 1 THEN 'Lundi'  
										WHEN 2 THEN 'Mardi' 
										WHEN 3 THEN 'Mercredi' 
										WHEN 4 THEN 'Jeudi'
										WHEN 5 THEN 'Vendredi'
										WHEN 6 THEN 'Samedi'
										WHEN 7 THEN 'Dimanche'
										ELSE '?'
										END";
								break;
							case 'CALC_JOURV':
								$field = "base.cti_to_char(v_factures_lignes_h_3.date_vente, 'FF')";
								break;
							case 'CALC_JOURSV':
								$field = "base.cti_to_char(v_factures_lignes_h_3.date_vente, 'DD') ||' '||
								CASE date_part('month',v_factures_lignes_h_3.date_vente)
										WHEN 01 THEN 'Janvier'  
										WHEN 02 THEN 'Fevrier' 
										WHEN 03 THEN 'Mars' 
										WHEN 04 THEN 'Avril' 
										WHEN 05 THEN 'Mai' 
										WHEN 06 THEN 'Juin' 
										WHEN 07 THEN 'Juillet'  
										WHEN 08 THEN 'Aout' 
										WHEN 09 THEN 'Septembre' 
										WHEN 10 THEN 'Octobre' 
										WHEN 11 THEN 'Novembre' 
										WHEN 12 THEN 'Decembre' 
										ELSE '?'
										END
								
								";
								break;

							case 'CALC_SEMAINEANNEV':
								$field = " 'Semaine '||' '|| to_char(v_factures_lignes_h_3.date_vente, 'WW')

										";
								break;
							case 'CALC_SEMAINEWEV':
								$field = "CASE to_char(v_factures_lignes_h_3.date_vente, 'W')
										WHEN 1 THEN 'Semaine 1'  
										WHEN 2 THEN 'Semaine 2' 
										WHEN 3 THEN 'Semaine 3' 
										WHEN 4 THEN 'Semaine 4'
										WHEN 5 THEN 'Semaine 5'
										ELSE '?'
										END";
								break;
							case "CALC_MOISV":
								$field = "CASE date_part('month',v_factures_lignes_h_3.date_vente)
										WHEN 01 THEN 'Janvier'  
										WHEN 02 THEN 'Fevrier' 
										WHEN 03 THEN 'Mars' 
										WHEN 04 THEN 'Avril' 
										WHEN 05 THEN 'Mai' 
										WHEN 06 THEN 'Juin' 
										WHEN 07 THEN 'Juillet'  
										WHEN 08 THEN 'Aout' 
										WHEN 09 THEN 'Septembre' 
										WHEN 10 THEN 'Octobre' 
										WHEN 11 THEN 'Novembre' 
										WHEN 12 THEN 'Decembre' 
										ELSE '?'
										END
										|| ' ' || date_part('year',v_factures_lignes_h_3.date_vente)";
								break;
							case "CALC_MOIV":
								$field = "CASE substr(v_factures_lignes_h_3.date_vente, 5 , 2)	
										WHEN '01' THEN 'Janvier'  
										WHEN '02' THEN 'Fevrier' 
										WHEN '03' THEN 'Mars' 
										WHEN '04' THEN 'Avril' 
										WHEN '05' THEN 'Mai' 
										WHEN '06' THEN 'Juin' 
										WHEN '07' THEN 'Juillet'  
										WHEN '08' THEN 'Aout' 
										WHEN '09' THEN 'Septembre' 
										WHEN '10' THEN 'Octobre' 
										WHEN '11' THEN 'Novembre' 
										WHEN '12' THEN 'Decembre' 
										ELSE '?'
										END
										|| ' ' || substr(v_factures_lignes_h_3.date_vente, 1 , 4)";
								break;
							
							default:
								$field = "$prefixe" . "_texte";
						}
					}
					return $field;
				}
				
				
				function ACTI_ETATDOSSIER_prefixe($GROUPBY, $DEFAULT="") {
					if (substr($GROUPBY,3,3) == 'CLS') {
						$GROUPBY = substr($GROUPBY,0,6);
					}
					$field = '';
					$field_id = '';
					$field_code = '';
					$field_texte = '';
					switch ($GROUPBY) {
					case '*TAB':
						$field = "*TAB";
						break;
					case '-1':
						$field = "";
						break;
			
					case 'TPY':
						$field = "v_factures_reference_1.tiers_payant";
						break;
					case 'TRG':
						$field = "v_factures_reference_1.tiers_payant_grand_regime";
						break;
					case 'TPYCLS':
						$field = "v_factures_reference_1.tiers_payant_section";
						break;
					case 'TTP':
						$field = "type_tiers_payant";
						break;
					case 'SPM':
						$field = "medecin_sejour_specialite";
						break;
					case 'MED':
						$field = "medecin_sejour";
						break;
					case 'MDA':
						$field = "medecin_adm_sejour";
						break;
					case 'MDACLS':
						$field = "medecin_adm_sejour_section";
						break;
                    case 'MTA':
						$field = "medecin_traitant";
						break;                    
                    case 'MTACLS':
						$field = "medecin_traitant_section";
						break;
					case 'MOIV':
						$field = "CALC_MOIV";
						break;
					case 'MOIS':
						$field = "CALC_MOIS";
						break;
					case 'ANNEE':
						$field = "CALC_ANNEE";
						break;
					case 'NUMEROMOIS':
						$field = "CALC_NUMEROMOIS";
						break;
					case 'TRIM':
						$field = "CALC_TRIM";
						break;
					case 'JOUR':
						$field = "CALC_JOUR";
						break;
					case 'JOURS':
						$field = "CALC_JOURS";
						break;
					case 'NUMEROTRIM':
						$field = "CALC_NUMEROTRIM";
						break;
					case 'NUMEROJOUR':
						$field = "CALC_NUMEROJOUR";
						break;
					case 'SEMAINEWE':
						$field = "CALC_SEMAINEWE";
						break;
					case 'SEMAINEANNE':
						$field = "CALC_SEMAINEANNE";
						break;
					case 'MOISF':
						$field = "CALC_MOISF";
						break;
					case 'ANNEEF':
						$field = "CALC_ANNEEF";
						break;
					case 'NUMEROMOISF':
						$field = "CALC_NUMEROMOISF";
						break;
					case 'TRIMF':
						$field = "CALC_TRIMF";
						break;
					case 'JOURF':
						$field = "CALC_JOURF";
						break;
					case 'JOURSF':
						$field = "CALC_JOURSF";
						break;
					case 'NUMEROTRIMF':
						$field = "CALC_NUMEROTRIMF";
						break;
					case 'NUMEROJOURF':
						$field = "CALC_NUMEROJOURF";
						break;
					case 'SEMAINEWEF':
						$field = "CALC_SEMAINEWEF";
						break;
					case 'SEMAINEANNEF':
						$field = "CALC_SEMAINEANNEF";
						break;
					case 'MOISEX':
						$field = "CALC_MOISEX";
						break;
					case 'ANNEEEX':
						$field = "CALC_ANNEEEX";
						break;
					case 'NUMEROMOISEX':
						$field = "CALC_NUMEROMOISEX";
						break;
					case 'TRIMEX':
						$field = "CALC_TRIMEX";
						break;
					case 'JOUREX':
						$field = "CALC_JOUREX";
						break;
					case 'JOURSEX':
						$field = "CALC_JOURSEX";
						break;
					case 'NUMEROTRIMEX':
						$field = "CALC_NUMEROTRIMEX";
						break;
					case 'NUMEROJOUREX':
						$field = "CALC_NUMEROJOUREX";
						break;
					case 'SEMAINEWEEX':
						$field = "CALC_SEMAINEWEEX";
						break;
					case 'SEMAINEANNEEX':
						$field = "CALC_SEMAINEANNEEX";
						break;
					case 'SEXE':
						$field = "v_sejours_1.code_sexe";
						break;		
						
					
					default:
						$field = $DEFAULT;
					}
					return $field;
					
					$prefixe = '';
					$groupby = '[GROUPBY]';
					if ($groupby == '-1') {$groupby = '[GROUPBY_2]';}

					$cls6 = substr($groupby, 0 , 6);
					$cls7 = substr($groupby, 6 , 1);

					
				}
				
				function ACTI_ETATDOSSIER_field_id($GROUPBY, $DEFAULT="") {
				
					$prefixe = ACTI_STANDARD_prefixe($GROUPBY, $DEFAULT, "ETATDOSSIER");
					if ($prefixe == "") {
						$prefixe = ACTI_ETATDOSSIER_prefixe($GROUPBY, $DEFAULT="");
					}
					
					if (substr($GROUPBY, 3, 3) == 'CLS' && $prefixe != $DEFAULT) {
						$section = substr($GROUPBY, 6);
						$field = "$prefixe" . "_id[" . $section . "]";
					}
					else {
						switch ($prefixe) {
							case "":
								$field = "0";
								break;
							case "*TAB":
								$field = "-9999999";
								break;
							case 'CALC_ANNEE':
								$field = "to_char(v_factures_reference_1.date_fin_facture, 'YYYY')";
								break;
							case 'CALC_NUMEROMOIS':
								$field = "to_char(v_factures_reference_1.date_fin_facture, 'MM')";
								break;
							case 'CALC_TRIM':
								$field = "to_char(v_factures_reference_1.date_fin_facture, 'YYYYQ')";
								break;
							case 'CALC_NUMEROTRIM':
								$field = "to_char(v_factures_reference_1.date_fin_facture, 'Q')";
								break;
							case 'CALC_NUMEROJOUR':
								$field = "CASE extract(DOW FROM v_factures_reference_1.date_fin_facture) WHEN 0 THEN 7 ELSE extract(DOW FROM v_factures_reference_1.date_fin_facture) END";
								break;
							case 'CALC_JOUR':
								$field = "to_char(v_factures_reference_1.date_fin_facture, 'YYYYMMDD')";
								break;
							case 'CALC_JOURS':
								$field = "to_char(v_factures_reference_1.date_fin_facture, 'MMDD')";
								break;
							case "CALC_MOIS":
								$field = "to_char(v_factures_reference_1.date_fin_facture, 'YYYYMM')";
								break;
							case 'CALC_SEMAINEWE':
								$field = "to_char(v_factures_reference_1.date_fin_facture, 'W')";
								break;
							case 'CALC_SEMAINEANNE':
								$field = "to_char(v_factures_reference_1.date_fin_facture, 'WW')";
								break;
							case 'CALC_ANNEEF':
								$field = "to_char(v_factures_reference_1.date_fin_facture, 'YYYY')";
								break;
							case 'CALC_NUMEROMOISF':
								$field = "to_char(v_factures_reference_1.date_fin_facture, 'MM')";
								break;
							case 'CALC_TRIMF':
								$field = "to_char(v_factures_reference_1.date_fin_facture, 'YYYYQ')";
								break;
							case 'CALC_NUMEROTRIMF':
								$field = "to_char(v_factures_reference_1.date_fin_facture, 'Q')";
								break;
							case 'CALC_NUMEROJOURF':
								$field = "CASE extract(DOW FROM v_factures_reference_1.date_fin_facture) WHEN 0 THEN 7 ELSE extract(DOW FROM v_factures_reference_1.date_fin_facture) END";
								break;
							case 'CALC_JOURF':
								$field = "to_char(v_factures_reference_1.date_fin_facture, 'YYYYMMDD')";
								break;
							case 'CALC_JOURSF':
								$field = "to_char(v_factures_reference_1.date_fin_facture, 'MMDD')";
								break;
							case 'CALC_SEMAINEWEF':
								$field = "to_char(v_factures_reference_1.date_fin_facture, 'W')";
								break;
							case 'CALC_SEMAINEANNEF':
								$field = "to_char(v_factures_reference_1.date_fin_facture, 'WW')";
								break;
							case "CALC_MOISF":
								$field = "to_char(v_factures_reference_1.date_fin_facture, 'YYYYMM')";
								break;
							case "CALC_MOIC":
								$field = "to_char(v_factures_reference_1.date_comptable, 'YYYYMM')";
								break;
							case 'CALC_ANNEEEX':
								$field = "to_char(v_factures_reference_1.date_expedition, 'YYYY')";
								break;
							case 'CALC_NUMEROMOISEX':
								$field = "to_char(v_factures_reference_1.date_expedition, 'MM')";
								break;
							case 'CALC_TRIMEX':
								$field = "to_char(v_factures_reference_1.date_expedition, 'YYYYQ')";
								break;
							case 'CALC_NUMEROTRIMEX':
								$field = "to_char(v_factures_reference_1.date_expedition, 'Q')";
								break;
							case 'CALC_NUMEROJOUREX':
								$field = "CASE extract(DOW FROM v_factures_reference_1.date_expedition) WHEN 0 THEN 7 ELSE extract(DOW FROM v_factures_reference_1.date_expedition) END";
								break;
							case 'CALC_JOUREX':
								$field = "to_char(v_factures_reference_1.date_expedition, 'YYYYMMDD')";
								break;
							case 'CALC_JOURSEX':
								$field = "to_char(v_factures_reference_1.date_expedition, 'MMDD')";
								break;
							case 'CALC_SEMAINEWEEX':
								$field = "to_char(v_factures_reference_1.date_expedition, 'W')";
								break;
							case 'CALC_SEMAINEANNEEX':
								$field = "to_char(v_factures_reference_1.date_expedition, 'WW')";
								break;
							case "CALC_MOISEX":
								$field = "to_char(v_factures_reference_1.date_expedition, 'YYYYMM')";
								break;
							case "CALC_MOIV":
								$field = "to_char(v_factures_reference_1.date_vente, 'YYYYMM')";
								break;
							case 'v_sejours_1.code_sexe':
								$field = "v_sejours_1.code_sexe";
								break;								
							default:
								$field = "$prefixe" . "_id";
						}
					}
					return $field;
				}
				
				function ACTI_ETATDOSSIER_field_code($GROUPBY, $DEFAULT="") {
					$prefixe = ACTI_STANDARD_prefixe($GROUPBY, $DEFAULT, "ETATDOSSIER");
					if ($prefixe == "") {
						$prefixe = ACTI_ETATDOSSIER_prefixe($GROUPBY, $DEFAULT="");
					}
					
					if (substr($GROUPBY, 3, 3) == 'CLS' && $prefixe != $DEFAULT) {
						$section = substr($GROUPBY, 6);
						$field = "$prefixe" . "_code[" . $section . "]";
					}
					else {
						switch ($prefixe) {
							case "":
								$field = "''";
								break;
							case "*TAB":
								$field = "' Résumé'";
								break;
							case 'CALC_ANNEE':
								$field = "to_char(v_factures_reference_1.date_fin_facture, 'YYYY')";
								break;
							case 'CALC_NUMEROMOIS':
								$field = "to_char(v_factures_reference_1.date_fin_facture, 'MM')";
								break;
							case 'CALC_TRIM':
								$field = "to_char(v_factures_reference_1.date_fin_facture, 'YYYY') ||' T'|| to_char(v_factures_reference_1.date_fin_facture, 'Q')  ";
								break;
							case 'CALC_NUMEROTRIM':
								$field = "to_char(v_factures_reference_1.date_fin_facture, 'Q')";
								break;
							case 'CALC_NUMEROJOUR':
								$field = "CASE extract(DOW FROM v_factures_reference_1.date_fin_facture) WHEN 0 THEN 7 ELSE extract(DOW FROM v_factures_reference_1.date_fin_facture) END";
								break;
							case 'CALC_SEMAINEWE':
								$field = "to_char(v_factures_reference_1.date_fin_facture, 'W')";
								break;
							case 'CALC_SEMAINEANNE':
								$field = "to_char(v_factures_reference_1.date_fin_facture, 'WW')";
								break;
							case 'CALC_JOUR':
								$field = "to_char(v_factures_reference_1.date_fin_facture, 'YYYY') ||'-'|| to_char(v_factures_reference_1.date_fin_facture, 'MM') ||'-'||to_char(v_factures_reference_1.date_fin_facture, 'DD')";
								break;
							case 'CALC_JOURS':
								$field = " to_char(v_factures_reference_1.date_fin_facture, 'MM') ||'-'|| to_char(v_factures_reference_1.date_fin_facture, 'DD') ";
								break;
							case "CALC_MOIS":
								$field = "to_char(v_factures_reference_1.date_fin_facture, 'YYYYMM')";
								break;
							case 'CALC_ANNEEF':
								$field = "to_char(v_factures_reference_1.date_fin_facture, 'YYYY')";
								break;
							case 'CALC_NUMEROMOISF':
								$field = "to_char(v_factures_reference_1.date_fin_facture, 'MM')";
								break;
							case 'CALC_TRIMF':
								$field = "to_char(v_factures_reference_1.date_fin_facture, 'YYYY') ||' T'|| to_char(v_factures_reference_1.date_fin_facture, 'Q')  ";
								break;
							case 'CALC_NUMEROTRIMF':
								$field = "to_char(v_factures_reference_1.date_fin_facture, 'Q')";
								break;
							case 'CALC_NUMEROJOURF':
								$field = "CASE extract(DOW FROM v_factures_reference_1.date_fin_facture) WHEN 0 THEN 7 ELSE extract(DOW FROM v_factures_reference_1.date_fin_facture) END";
								break;
							case 'CALC_SEMAINEWEF':
								$field = "to_char(v_factures_reference_1.date_fin_facture, 'W')";
								break;
							case 'CALC_SEMAINEANNEF':
								$field = "to_char(v_factures_reference_1.date_fin_facture, 'WW')";
								break;
							case 'CALC_JOURF':
								$field = "to_char(v_factures_reference_1.date_fin_facture, 'YYYY') ||'-'|| to_char(v_factures_reference_1.date_fin_facture, 'MM') ||'-'||to_char(v_factures_reference_1.date_fin_facture, 'DD')";
								break;
							case 'CALC_JOURSF':
								$field = " to_char(v_factures_reference_1.date_fin_facture, 'MM') ||'-'|| to_char(v_factures_reference_1.date_fin_facture, 'DD') ";
								break;
							case "CALC_MOISF":
								$field = "to_char(v_factures_reference_1.date_fin_facture, 'YYYYMM')";
								break;
							case 'CALC_ANNEEEX':
								$field = "to_char(v_factures_reference_1.date_expedition, 'YYYY')";
								break;
							case 'CALC_NUMEROMOISEX':
								$field = "to_char(v_factures_reference_1.date_expedition, 'MM')";
								break;
							case 'CALC_TRIMEX':
								$field = "to_char(v_factures_reference_1.date_expedition, 'YYYY') ||' T'|| to_char(v_factures_reference_1.date_expedition, 'Q')  ";
								break;
							case 'CALC_NUMEROTRIMEX':
								$field = "to_char(v_factures_reference_1.date_expedition, 'Q')";
								break;
							case 'CALC_NUMEROJOUREX':
								$field = "CASE extract(DOW FROM v_factures_reference_1.date_expedition) WHEN 0 THEN 7 ELSE extract(DOW FROM v_factures_reference_1.date_expedition) END";
								break;
							case 'CALC_SEMAINEWEEX':
								$field = "to_char(v_factures_reference_1.date_expedition, 'W')";
								break;
							case 'CALC_SEMAINEANNEEX':
								$field = "to_char(v_factures_reference_1.date_expedition, 'WW')";
								break;
							case 'CALC_JOUREX':
								$field = "to_char(v_factures_reference_1.date_expedition, 'YYYY') ||'-'|| to_char(v_factures_reference_1.date_expedition, 'MM') ||'-'||to_char(v_factures_reference_1.date_expedition, 'DD')";
								break;
							case 'CALC_JOURSEX':
								$field = " to_char(v_factures_reference_1.date_expedition, 'MM') ||'-'|| to_char(v_factures_reference_1.date_expedition, 'DD') ";
								break;
							case "CALC_MOISEX":
								$field = "to_char(v_factures_reference_1.date_expedition, 'YYYYMM')";
								break;
							case "CALC_MOIC":
								$field = "to_char(v_factures_reference_1.date_comptable, 'YYYYMM')";
								break;
							case "CALC_MOIV":
								$field = "to_char(v_factures_reference_1.date_vente, 'YYYYMM')";
								break;
							case 'v_sejours_1.code_sexe':
								$field = "v_sejours_1.code_sexe";
								break;	
							default:
								$field = "$prefixe" . "_code";
						}
					}
					return $field;
				}
				
				function ACTI_ETATDOSSIER_field_texte($GROUPBY, $DEFAULT="") {
					$prefixe = ACTI_STANDARD_prefixe($GROUPBY, $DEFAULT, "ETATDOSSIER");
					if ($prefixe == "") {
						$prefixe = ACTI_ETATDOSSIER_prefixe($GROUPBY, $DEFAULT="");
					}
					
					if (substr($GROUPBY, 3, 3) == 'CLS' && $prefixe != $DEFAULT) {
						$section = substr($GROUPBY, 6);
						$field = "$prefixe" . "_texte[" . $section . "]";
					}
					else {
						switch ($prefixe) {
							case "":
								$field = "''";
								break;
							case "*TAB":
								$field = "'Résumé'";
								break;
							case "medecin_adm_sejour":
								$field = "$prefixe" . "_nom_prenom";
								break;
							case "medecin_sejour":
								$field = "$prefixe" . "_nom_prenom";
								break;                            
                            case "medecin_traitant":
								$field = "$prefixe" . "_nom_prenom";
                                break;
							case "CALC_ANNEE":
								$field = "to_char(v_factures_reference_1.date_fin_facture, 'YYYY')";
								break;
							case 'CALC_NUMEROMOIS':
								$field = "CASE date_part('month',v_factures_reference_1.date_fin_facture)
										WHEN 01 THEN 'Janvier'  
										WHEN 02 THEN 'Fevrier' 
										WHEN 03 THEN 'Mars' 
										WHEN 04 THEN 'Avril' 
										WHEN 05 THEN 'Mai' 
										WHEN 06 THEN 'Juin' 
										WHEN 07 THEN 'Juillet'  
										WHEN 08 THEN 'Aout' 
										WHEN 09 THEN 'Septembre' 
										WHEN 10 THEN 'Octobre' 
										WHEN 11 THEN 'Novembre' 
										WHEN 12 THEN 'Decembre' 
										ELSE '?'
										END";
								break;
							case 'CALC_TRIM':
								$field = "date_part('year',v_factures_reference_1.date_fin_facture) ||'-'|| 
								CASE to_char(v_factures_reference_1.date_fin_facture, 'Q')
										WHEN 1 THEN 'Trimestre 1'  
										WHEN 2 THEN 'Trimestre 2' 
										WHEN 3 THEN 'Trimestre 3' 
										WHEN 4 THEN 'Trimestre 4'
										ELSE '?'
										END";
								break;
							case 'CALC_NUMEROTRIM':
								$field = "CASE to_char(v_factures_reference_1.date_fin_facture, 'Q')
										WHEN 1 THEN 'Trimestre 1'  
										WHEN 2 THEN 'Trimestre 2' 
										WHEN 3 THEN 'Trimestre 3' 
										WHEN 4 THEN 'Trimestre 4'
										ELSE '?'
										END";
								break;
							case 'CALC_NUMEROJOUR':
								$field = "CASE CASE extract(DOW FROM v_factures_reference_1.date_fin_facture) WHEN 0 THEN 7 ELSE extract(DOW FROM v_factures_reference_1.date_fin_facture) END
										WHEN 1 THEN 'Lundi'  
										WHEN 2 THEN 'Mardi' 
										WHEN 3 THEN 'Mercredi' 
										WHEN 4 THEN 'Jeudi'
										WHEN 5 THEN 'Vendredi'
										WHEN 6 THEN 'Samedi'
										WHEN 7 THEN 'Dimanche'
										ELSE '?'
										END";
								break;
							case 'CALC_JOUR':
								$field = "base.cti_to_char(v_factures_reference_1.date_fin_facture, 'FF')";
								break;
							case 'CALC_JOURS':
								$field = "base.cti_to_char(v_factures_reference_1.date_fin_facture, 'DD') ||' '||
								CASE date_part('month',v_factures_reference_1.date_fin_facture)
										WHEN 01 THEN 'Janvier'  
										WHEN 02 THEN 'Fevrier' 
										WHEN 03 THEN 'Mars' 
										WHEN 04 THEN 'Avril' 
										WHEN 05 THEN 'Mai' 
										WHEN 06 THEN 'Juin' 
										WHEN 07 THEN 'Juillet'  
										WHEN 08 THEN 'Aout' 
										WHEN 09 THEN 'Septembre' 
										WHEN 10 THEN 'Octobre' 
										WHEN 11 THEN 'Novembre' 
										WHEN 12 THEN 'Decembre' 
										ELSE '?'
										END
								
								";
								break;

							case 'CALC_SEMAINEANNE':
								$field = " 'Semaine '||' '|| to_char(v_factures_reference_1.date_fin_facture, 'WW')

										";
								break;
							case 'CALC_SEMAINEWE':
								$field = "CASE to_char(v_factures_reference_1.date_fin_facture, 'W')
										WHEN 1 THEN 'Semaine 1'  
										WHEN 2 THEN 'Semaine 2' 
										WHEN 3 THEN 'Semaine 3' 
										WHEN 4 THEN 'Semaine 4'
										WHEN 5 THEN 'Semaine 5'
										ELSE '?'
										END";
								break;
							case "CALC_MOIS":
								$field = "CASE date_part('month',v_factures_reference_1.date_fin_facture)
										WHEN 01 THEN 'Janvier'  
										WHEN 02 THEN 'Fevrier' 
										WHEN 03 THEN 'Mars' 
										WHEN 04 THEN 'Avril' 
										WHEN 05 THEN 'Mai' 
										WHEN 06 THEN 'Juin' 
										WHEN 07 THEN 'Juillet'  
										WHEN 08 THEN 'Aout' 
										WHEN 09 THEN 'Septembre' 
										WHEN 10 THEN 'Octobre' 
										WHEN 11 THEN 'Novembre' 
										WHEN 12 THEN 'Decembre' 
										ELSE '?'
										END
										|| ' ' || date_part('year',v_factures_reference_1.date_fin_facture)";
								break;
							case "CALC_ANNEEF":
								$field = "to_char(v_factures_reference_1.date_fin_facture, 'YYYY')";
								break;
							case 'CALC_NUMEROMOISF':
								$field = "CASE date_part('month',v_factures_reference_1.date_fin_facture)
										WHEN 01 THEN 'Janvier'  
										WHEN 02 THEN 'Fevrier' 
										WHEN 03 THEN 'Mars' 
										WHEN 04 THEN 'Avril' 
										WHEN 05 THEN 'Mai' 
										WHEN 06 THEN 'Juin' 
										WHEN 07 THEN 'Juillet'  
										WHEN 08 THEN 'Aout' 
										WHEN 09 THEN 'Septembre' 
										WHEN 10 THEN 'Octobre' 
										WHEN 11 THEN 'Novembre' 
										WHEN 12 THEN 'Decembre' 
										ELSE '?'
										END";
								break;
							case 'CALC_TRIMF':
								$field = "date_part('year',v_factures_reference_1.date_fin_facture) ||'-'|| 
								CASE to_char(v_factures_reference_1.date_fin_facture, 'Q')
										WHEN 1 THEN 'Trimestre 1'  
										WHEN 2 THEN 'Trimestre 2' 
										WHEN 3 THEN 'Trimestre 3' 
										WHEN 4 THEN 'Trimestre 4'
										ELSE '?'
										END";
								break;
							case 'CALC_NUMEROTRIMF':
								$field = "CASE to_char(v_factures_reference_1.date_fin_facture, 'Q')
										WHEN 1 THEN 'Trimestre 1'  
										WHEN 2 THEN 'Trimestre 2' 
										WHEN 3 THEN 'Trimestre 3' 
										WHEN 4 THEN 'Trimestre 4'
										ELSE '?'
										END";
								break;
							case 'CALC_NUMEROJOURF':
								$field = "CASE CASE extract(DOW FROM v_factures_reference_1.date_fin_facture) WHEN 0 THEN 7 ELSE extract(DOW FROM v_factures_reference_1.date_fin_facture) END
										WHEN 1 THEN 'Lundi'  
										WHEN 2 THEN 'Mardi' 
										WHEN 3 THEN 'Mercredi' 
										WHEN 4 THEN 'Jeudi'
										WHEN 5 THEN 'Vendredi'
										WHEN 6 THEN 'Samedi'
										WHEN 7 THEN 'Dimanche'
										ELSE '?'
										END";
								break;
							case 'CALC_JOURF':
								$field = "base.cti_to_char(v_factures_reference_1.date_fin_facture, 'FF')";
								break;
							case 'CALC_JOURSF':
								$field = "base.cti_to_char(v_factures_reference_1.date_fin_facture, 'DD') ||' '||
								CASE date_part('month',v_factures_reference_1.date_fin_facture)
										WHEN 01 THEN 'Janvier'  
										WHEN 02 THEN 'Fevrier' 
										WHEN 03 THEN 'Mars' 
										WHEN 04 THEN 'Avril' 
										WHEN 05 THEN 'Mai' 
										WHEN 06 THEN 'Juin' 
										WHEN 07 THEN 'Juillet'  
										WHEN 08 THEN 'Aout' 
										WHEN 09 THEN 'Septembre' 
										WHEN 10 THEN 'Octobre' 
										WHEN 11 THEN 'Novembre' 
										WHEN 12 THEN 'Decembre' 
										ELSE '?'
										END
								
								";
								break;

							case 'CALC_SEMAINEANNEF':
								$field = " 'Semaine '||' '|| to_char(v_factures_reference_1.date_fin_facture, 'WW')

										";
								break;
							case 'CALC_SEMAINEWEF':
								$field = "CASE to_char(v_factures_reference_1.date_fin_facture, 'W')
										WHEN 1 THEN 'Semaine 1'  
										WHEN 2 THEN 'Semaine 2' 
										WHEN 3 THEN 'Semaine 3' 
										WHEN 4 THEN 'Semaine 4'
										WHEN 5 THEN 'Semaine 5'
										ELSE '?'
										END";
								break;
							case "CALC_MOISF":
								$field = "CASE date_part('month',v_factures_reference_1.date_fin_facture)
										WHEN 01 THEN 'Janvier'  
										WHEN 02 THEN 'Fevrier' 
										WHEN 03 THEN 'Mars' 
										WHEN 04 THEN 'Avril' 
										WHEN 05 THEN 'Mai' 
										WHEN 06 THEN 'Juin' 
										WHEN 07 THEN 'Juillet'  
										WHEN 08 THEN 'Aout' 
										WHEN 09 THEN 'Septembre' 
										WHEN 10 THEN 'Octobre' 
										WHEN 11 THEN 'Novembre' 
										WHEN 12 THEN 'Decembre' 
										ELSE '?'
										END
										|| ' ' || date_part('year',v_factures_reference_1.date_fin_facture)";
								break;
							case "CALC_ANNEEEX":
								$field = "to_char(v_factures_reference_1.date_expedition, 'YYYY')";
								break;
							case 'CALC_NUMEROMOISEX':
								$field = "CASE date_part('month',v_factures_reference_1.date_expedition)
										WHEN 01 THEN 'Janvier'  
										WHEN 02 THEN 'Fevrier' 
										WHEN 03 THEN 'Mars' 
										WHEN 04 THEN 'Avril' 
										WHEN 05 THEN 'Mai' 
										WHEN 06 THEN 'Juin' 
										WHEN 07 THEN 'Juillet'  
										WHEN 08 THEN 'Aout' 
										WHEN 09 THEN 'Septembre' 
										WHEN 10 THEN 'Octobre' 
										WHEN 11 THEN 'Novembre' 
										WHEN 12 THEN 'Decembre' 
										ELSE '?'
										END";
								break;
							case 'CALC_TRIMEX':
								$field = "date_part('year',v_factures_reference_1.date_expedition) ||'-'|| 
								CASE to_char(v_factures_reference_1.date_expedition, 'Q')
										WHEN 1 THEN 'Trimestre 1'  
										WHEN 2 THEN 'Trimestre 2' 
										WHEN 3 THEN 'Trimestre 3' 
										WHEN 4 THEN 'Trimestre 4'
										ELSE '?'
										END";
								break;
							case 'CALC_NUMEROTRIMEX':
								$field = "CASE to_char(v_factures_reference_1.date_expedition, 'Q')
										WHEN 1 THEN 'Trimestre 1'  
										WHEN 2 THEN 'Trimestre 2' 
										WHEN 3 THEN 'Trimestre 3' 
										WHEN 4 THEN 'Trimestre 4'
										ELSE '?'
										END";
								break;
							case 'CALC_NUMEROJOUREX':
								$field = "CASE CASE extract(DOW FROM v_factures_reference_1.date_expedition) WHEN 0 THEN 7 ELSE extract(DOW FROM v_factures_reference_1.date_expedition) END
										WHEN 1 THEN 'Lundi'  
										WHEN 2 THEN 'Mardi' 
										WHEN 3 THEN 'Mercredi' 
										WHEN 4 THEN 'Jeudi'
										WHEN 5 THEN 'Vendredi'
										WHEN 6 THEN 'Samedi'
										WHEN 7 THEN 'Dimanche'
										ELSE '?'
										END";
								break;
							case 'CALC_JOUREX':
								$field = "base.cti_to_char(v_factures_reference_1.date_expedition, 'FF')";
								break;
							case 'CALC_JOURSEX':
								$field = "base.cti_to_char(v_factures_reference_1.date_expedition, 'DD') ||' '||
								CASE date_part('month',v_factures_reference_1.date_expedition)
										WHEN 01 THEN 'Janvier'  
										WHEN 02 THEN 'Fevrier' 
										WHEN 03 THEN 'Mars' 
										WHEN 04 THEN 'Avril' 
										WHEN 05 THEN 'Mai' 
										WHEN 06 THEN 'Juin' 
										WHEN 07 THEN 'Juillet'  
										WHEN 08 THEN 'Aout' 
										WHEN 09 THEN 'Septembre' 
										WHEN 10 THEN 'Octobre' 
										WHEN 11 THEN 'Novembre' 
										WHEN 12 THEN 'Decembre' 
										ELSE '?'
										END
								
								";
								break;

							case 'CALC_SEMAINEANNEEX':
								$field = " 'Semaine '||' '|| to_char(v_factures_reference_1.date_expedition, 'WW')

										";
								break;
							case 'CALC_SEMAINEWEEX':
								$field = "CASE to_char(v_factures_reference_1.date_expedition, 'W')
										WHEN 1 THEN 'Semaine 1'  
										WHEN 2 THEN 'Semaine 2' 
										WHEN 3 THEN 'Semaine 3' 
										WHEN 4 THEN 'Semaine 4'
										WHEN 5 THEN 'Semaine 5'
										ELSE '?'
										END";
								break;
							case "CALC_MOISEX":
								$field = "CASE date_part('month',v_factures_reference_1.date_expedition)
										WHEN 01 THEN 'Janvier'  
										WHEN 02 THEN 'Fevrier' 
										WHEN 03 THEN 'Mars' 
										WHEN 04 THEN 'Avril' 
										WHEN 05 THEN 'Mai' 
										WHEN 06 THEN 'Juin' 
										WHEN 07 THEN 'Juillet'  
										WHEN 08 THEN 'Aout' 
										WHEN 09 THEN 'Septembre' 
										WHEN 10 THEN 'Octobre' 
										WHEN 11 THEN 'Novembre' 
										WHEN 12 THEN 'Decembre' 
										ELSE '?'
										END
										|| ' ' || date_part('year',v_factures_reference_1.date_expedition)";
								break;
							case "CALC_MOIC":
								$field = "CASE date_part('month',v_factures_reference_1.date_comptable)
										WHEN 01 THEN 'Janvier'  
										WHEN 02 THEN 'Fevrier' 
										WHEN 03 THEN 'Mars' 
										WHEN 04 THEN 'Avril' 
										WHEN 05 THEN 'Mai' 
										WHEN 06 THEN 'Juin' 
										WHEN 07 THEN 'Juillet'  
										WHEN 08 THEN 'Aout' 
										WHEN 09 THEN 'Septembre' 
										WHEN 10 THEN 'Octobre' 
										WHEN 11 THEN 'Novembre' 
										WHEN 12 THEN 'Decembre' 
										ELSE '?'
										END
										|| ' ' || date_part('year',v_factures_reference_1.date_comptable)";
								break;
							case "CALC_MOIV":
								$field = "CASE date_part('month',v_factures_reference_1.date_vente)
										WHEN 01 THEN 'Janvier'  
										WHEN 02 THEN 'Fevrier' 
										WHEN 03 THEN 'Mars' 
										WHEN 04 THEN 'Avril' 
										WHEN 05 THEN 'Mai' 
										WHEN 06 THEN 'Juin' 
										WHEN 07 THEN 'Juillet'  
										WHEN 08 THEN 'Aout' 
										WHEN 09 THEN 'Septembre' 
										WHEN 10 THEN 'Octobre' 
										WHEN 11 THEN 'Novembre' 
										WHEN 12 THEN 'Decembre' 
										ELSE '?'
										END
										|| ' ' || date_part('year',v_factures_reference_1.date_vente)::text";
								break;
							case 'v_sejours_1.code_sexe':
								$field = "v_sejours_1.code_sexe";
								break;								
							default:
								$field = "$prefixe" . "_texte";
						}
					}
					return $field;
				}
				
				
				
				function ACTI_CLIENT_prefixe($GROUPBY, $DEFAULT="") {
					if (substr($GROUPBY,3,3) == 'CLS') {
						$GROUPBY = substr($GROUPBY,0,6);
					}
					$field = '';
					$field_id = '';
					$field_code = '';
					$field_texte = '';
					switch ($GROUPBY) {
					case '*TAB':
						$field = "*TAB";
						break;
					case '-1':
						$field = "";
						break;
			
					case 'PRF':
						$field = "prestation";
						break;
					case 'PRFCLS':
						$field = "prestation_section";
						break;
					case 'RUC':
						$field = "rubrique_comptabilisation";
						break;
					case 'RUCCLS':
						$field = "rubrique_comptabilisation_section";
						break;
					case 'TPY':
						$field = "tiers_payant";
						break;
					case 'TRG':
						$field = "tiers_payant_grand_regime";
						break;
					case 'TPYCLS':
						$field = "tiers_payant_section";
						break;
					case 'TTP':
						$field = "type_tiers_payant";
						break;
					case 'MOIC':
						$field = "CALC_MOIC";
						break;
					case 'MOIS':
						$field = "CALC_MOIS";
						break;
					case 'MOIV':
						$field = "CALC_MOIV";
						break;
					case 'SPM':
						$field = "medecin_sejour_specialite";
						break;
					case 'MED':
						$field = "medecin_sejour";
						break;
					case 'MDA':
						$field = "medecin_adm_sejour";
						break;
					case 'MDACLS':
						$field = "medecin_adm_sejour_section";
						break;
					default:
						$field = $DEFAULT;
					}
					return $field;
					
					$prefixe = '';
					$groupby = '[GROUPBY]';
					if ($groupby == '-1') {$groupby = '[GROUPBY_2]';}

					$cls6 = substr($groupby, 0 , 6);
					$cls7 = substr($groupby, 6 , 1);

					
				}
				
				function ACTI_CLIENT_field_id($GROUPBY, $DEFAULT="") {
				
					$prefixe = ACTI_STANDARD_prefixe($GROUPBY, $DEFAULT, "CLIENT");
					if ($prefixe == "") {
						$prefixe = ACTI_CLIENT_prefixe($GROUPBY, $DEFAULT="");
					}
					
					if (substr($GROUPBY, 3, 3) == 'CLS' && $prefixe != $DEFAULT) {
						$section = substr($GROUPBY, 6);
						$field = "$prefixe" . "_id[" . $section . "]";
					}
					else {
						switch ($prefixe) {
							case "":
								$field = "0";
								break;
							case "*TAB":
								$field = "-9999999";
								break;
							case "CALC_MOIC":
								$field = "to_char(date_comptable, 'YYYYMM')";
								break;
							case "CALC_MOIS":
								$field = "to_char(date_fin_facture, 'YYYYMM')";
								break;
							case "CALC_MOIV":
								$field = "to_char(date_vente, 'YYYYMM')";
								break;
							
							default:
								$field = "$prefixe" . "_id";
						}
					}
					return $field;
				}
				
				function ACTI_CLIENT_field_code($GROUPBY, $DEFAULT="") {
					
					$prefixe = ACTI_STANDARD_prefixe($GROUPBY, $DEFAULT, "CLIENT");
					if ($prefixe == "") {
						$prefixe = ACTI_CLIENT_prefixe($GROUPBY, $DEFAULT="");
					}
					
					if (substr($GROUPBY, 3, 3) == 'CLS' && $prefixe != $DEFAULT) {
						$section = substr($GROUPBY, 6);
						$field = "$prefixe" . "_code[" . $section . "]";
					}
					else {
						switch ($prefixe) {
							case "":
								$field = "''";
								break;
							case "*TAB":
								$field = "' Résumé'";
								break;
							case "CALC_MOIC":
								$field = "to_char(date_comptable, 'YYYYMM')";
								break;
							case "CALC_MOIS":
								$field = "to_char(date_fin_facture, 'YYYYMM')";
								break;
							case "CALC_MOIV":
								$field = "to_char(date_vente, 'YYYYMM')";
								break;
							default:
								$field = "$prefixe" . "_code";
						}
					}
					return $field;
				}
				
				function ACTI_CLIENT_field_texte($GROUPBY, $DEFAULT="") {
					
					$prefixe = ACTI_STANDARD_prefixe($GROUPBY, $DEFAULT, "CLIENT");
					if ($prefixe == "") {
						$prefixe = ACTI_CLIENT_prefixe($GROUPBY, $DEFAULT);
					}
					
					if (substr($GROUPBY, 3, 3) == 'CLS' && $prefixe != $DEFAULT) {
						$section = substr($GROUPBY, 6);
						$field = "$prefixe" . "_texte[" . $section . "]";
					}
					else {
						switch ($prefixe) {
							case "":
								$field = "''";
								break;
							case "*TAB":
								$field = "'Résumé'";
								break;
							case "medecin_adm_sejour":
								$field = "$prefixe" . "_nom_prenom";
								break;
							case "medecin_sejour":
								$field = "$prefixe" . "_nom_prenom";
								break;
							case "CALC_MOIC":
								$field = "CASE date_part('month',date_comptable)
										WHEN 01 THEN 'Janvier'  
										WHEN 02 THEN 'Fevrier' 
										WHEN 03 THEN 'Mars' 
										WHEN 04 THEN 'Avril' 
										WHEN 05 THEN 'Mai' 
										WHEN 06 THEN 'Juin' 
										WHEN 07 THEN 'Juillet'  
										WHEN 08 THEN 'Aout' 
										WHEN 09 THEN 'Septembre' 
										WHEN 10 THEN 'Octobre' 
										WHEN 11 THEN 'Novembre' 
										WHEN 12 THEN 'Decembre' 
										ELSE '?'
										END
										|| ' ' || date_part('year',date_comptable)::text";
								break;
							case "CALC_MOIS":
								$field = "CASE date_part('month',date_fin_facture)
										WHEN 01 THEN 'Janvier'  
										WHEN 02 THEN 'Fevrier' 
										WHEN 03 THEN 'Mars' 
										WHEN 04 THEN 'Avril' 
										WHEN 05 THEN 'Mai' 
										WHEN 06 THEN 'Juin' 
										WHEN 07 THEN 'Juillet'  
										WHEN 08 THEN 'Aout' 
										WHEN 09 THEN 'Septembre' 
										WHEN 10 THEN 'Octobre' 
										WHEN 11 THEN 'Novembre' 
										WHEN 12 THEN 'Decembre' 
										ELSE '?'
										END
										|| ' ' || date_part('year',date_fin_facture)::text";
								break;
							case "CALC_MOIV":
								$field = "CASE date_part('month',date_vente)
										WHEN 01 THEN 'Janvier'  
										WHEN 02 THEN 'Fevrier' 
										WHEN 03 THEN 'Mars' 
										WHEN 04 THEN 'Avril' 
										WHEN 05 THEN 'Mai' 
										WHEN 06 THEN 'Juin' 
										WHEN 07 THEN 'Juillet'  
										WHEN 08 THEN 'Aout' 
										WHEN 09 THEN 'Septembre' 
										WHEN 10 THEN 'Octobre' 
										WHEN 11 THEN 'Novembre' 
										WHEN 12 THEN 'Decembre' 
										ELSE '?'
										END
										|| ' ' || date_part('year',date_vente)::text";
								break;
							
							default:
								$field = "$prefixe" . "_texte";
						}
					}
					return $field;
				}
				
				
				
				function ACTI_CLIENT_H_prefixe($GROUPBY, $DEFAULT="") {
					if (substr($GROUPBY,3,3) == 'CLS') {
						$GROUPBY = substr($GROUPBY,0,6);
					}
					$field = '';
					$field_id = '';
					$field_code = '';
					$field_texte = '';
					switch ($GROUPBY) {
					case '*TAB':
						$field = "*TAB";
						break;
					case '-1':
						$field = "";
						break;
			
					case 'SPMC':
						$field = "medecin_facture_specialite";
						break;
					case 'EXEC':
						$field = "medecin_comptabilise";
						break;
					case 'EXAC':
						$field = "medecin_adm_comptabilise";
						break;
					case 'EXACLS':
						$field = "medecin_adm_facture_section";
						break;
					case 'TPY':
						$field = "v_factures_soldes_h_3.tiers_payant";
						break;
					case 'TRG':
						$field = "v_factures_soldes_h_3.tiers_payant_grand_regime";
						break;
					case 'TPYCLS':
						$field = "v_factures_soldes_h_3.tiers_payant_section";
						break;
					case 'TTP':
						$field = "type_tiers_payant";
						break;
					case 'MOIC':
						$field = "CALC_MOIC";
						break;
					case 'MOIS':
						$field = "CALC_MOIS";
						break;
					case 'MOIV':
						$field = "CALC_MOIV";
						break;
					case 'SPM':
						$field = "medecin_sejour_specialite";
						break;
					case 'MED':
						$field = "medecin_sejour";
						break;
					case 'MDA':
						$field = "medecin_adm_sejour";
						break;
					case 'MDACLS':
						$field = "medecin_adm_sejour_section";
						break;
					default:
						$field = $DEFAULT;
					}
					return $field;
					
					$prefixe = '';
					$groupby = '[GROUPBY]';
					if ($groupby == '-1') {$groupby = '[GROUPBY_2]';}

					$cls6 = substr($groupby, 0 , 6);
					$cls7 = substr($groupby, 6 , 1);

					
				}
				
				function ACTI_CLIENT_H_field_id($GROUPBY, $DEFAULT="") {
				
					$prefixe = ACTI_STANDARD_prefixe($GROUPBY, $DEFAULT, "CLIENT_H");
					if ($prefixe == "") {
						$prefixe = ACTI_CLIENT_H_prefixe($GROUPBY, $DEFAULT="");
					}
					
					if (substr($GROUPBY, 3, 3) == 'CLS' && $prefixe != $DEFAULT) {
						$section = substr($GROUPBY, 6);
						$field = "$prefixe" . "_id[" . $section . "]";
					}
					else {
						switch ($prefixe) {
							case "":
								$field = "0";
								break;
							case "*TAB":
								$field = "-9999999";
								break;
							case "CALC_MOIC":
								$field = "to_char(v_factures_soldes_h_3.date_comptable, 'YYYYMM')";
								break;
							case "CALC_MOIS":
								$field = "to_char(v_factures_soldes_h_3.date_fin_facture, 'YYYYMM')";
								break;
							case "CALC_MOIV":
								$field = "to_char(v_factures_soldes_h_3.date_vente, 'YYYYMM')";
								break;
							
							default:
								$field = "$prefixe" . "_id";
						}
					}
					return $field;
				}
				
				function ACTI_CLIENT_H_field_code($GROUPBY, $DEFAULT="") {
					$prefixe = ACTI_STANDARD_prefixe($GROUPBY, $DEFAULT, "CLIENT_H");
					if ($prefixe == "") {
						$prefixe = ACTI_CLIENT_H_prefixe($GROUPBY, $DEFAULT="");
					}
					
					if (substr($GROUPBY, 3, 3) == 'CLS' && $prefixe != $DEFAULT) {
						$section = substr($GROUPBY, 6);
						$field = "$prefixe" . "_code[" . $section . "]";
					}
					else {
						switch ($prefixe) {
							case "":
								$field = "''";
								break;
							case "*TAB":
								$field = "' Résumé'";
								break;
							case "CALC_MOIC":
								$field = "to_char(v_factures_soldes_h_3.date_comptable, 'YYYYMM')";
								break;
							case "CALC_MOIS":
								$field = "to_char(v_factures_soldes_h_3.date_fin_facture, 'YYYYMM')";
								break;
							case "CALC_MOIV":
								$field = "to_char(v_factures_soldes_h_3.date_vente, 'YYYYMM')";
								break;
							default:
								$field = "$prefixe" . "_code";
						}
					}
					return $field;
				}
				
				function ACTI_CLIENT_H_field_texte($GROUPBY, $DEFAULT="") {
					$prefixe = ACTI_STANDARD_prefixe($GROUPBY, $DEFAULT, "CLIENT_H");
					if ($prefixe == "") {
						$prefixe = ACTI_CLIENT_H_prefixe($GROUPBY, $DEFAULT="");
					}
					
					if (substr($GROUPBY, 3, 3) == 'CLS' && $prefixe != $DEFAULT) {
						$section = substr($GROUPBY, 6);
						$field = "$prefixe" . "_texte[" . $section . "]";
					}
					else {
						switch ($prefixe) {
							case "":
								$field = "''";
								break;
							case "*TAB":
								$field = "'Résumé'";
								break;
							case "medecin_adm_sejour":
								$field = "$prefixe" . "_nom_prenom";
								break;
							case "medecin_sejour":
								$field = "$prefixe" . "_nom_prenom";
								break;
							case "medecin_adm_comptabilise":
								$field = "$prefixe" . "_nom_prenom";
								break;
							case "medecin_comptabilise":
								$field = "$prefixe" . "_nom_prenom";
								break;
							case "CALC_MOIC":
								$field = "CASE date_part('month',v_factures_soldes_h_3.date_comptable)
										WHEN 01 THEN 'Janvier'  
										WHEN 02 THEN 'Fevrier' 
										WHEN 03 THEN 'Mars' 
										WHEN 04 THEN 'Avril' 
										WHEN 05 THEN 'Mai' 
										WHEN 06 THEN 'Juin' 
										WHEN 07 THEN 'Juillet'  
										WHEN 08 THEN 'Aout' 
										WHEN 09 THEN 'Septembre' 
										WHEN 10 THEN 'Octobre' 
										WHEN 11 THEN 'Novembre' 
										WHEN 12 THEN 'Decembre' 
										ELSE '?'
										END
										|| ' ' || date_part('year',v_factures_soldes_h_3.date_comptable)::text";
								break;
							case "CALC_MOIS":
								$field = "CASE date_part('month',v_factures_soldes_h_3.date_fin_facture)
										WHEN 01 THEN 'Janvier'  
										WHEN 02 THEN 'Fevrier' 
										WHEN 03 THEN 'Mars' 
										WHEN 04 THEN 'Avril' 
										WHEN 05 THEN 'Mai' 
										WHEN 06 THEN 'Juin' 
										WHEN 07 THEN 'Juillet'  
										WHEN 08 THEN 'Aout' 
										WHEN 09 THEN 'Septembre' 
										WHEN 10 THEN 'Octobre' 
										WHEN 11 THEN 'Novembre' 
										WHEN 12 THEN 'Decembre' 
										ELSE '?'
										END
										|| ' ' || date_part('year',v_factures_soldes_h_3.date_fin_facture)::text";
								break;
							case "CALC_MOIV":
								$field = "CASE date_part('month',v_factures_soldes_h_3.date_vente)
										WHEN 01 THEN 'Janvier'  
										WHEN 02 THEN 'Fevrier' 
										WHEN 03 THEN 'Mars' 
										WHEN 04 THEN 'Avril' 
										WHEN 05 THEN 'Mai' 
										WHEN 06 THEN 'Juin' 
										WHEN 07 THEN 'Juillet'  
										WHEN 08 THEN 'Aout' 
										WHEN 09 THEN 'Septembre' 
										WHEN 10 THEN 'Octobre' 
										WHEN 11 THEN 'Novembre' 
										WHEN 12 THEN 'Decembre' 
										ELSE '?'
										END
										|| ' ' || date_part('year',v_factures_soldes_h_3.date_vente)::text";
								break;
							
							default:
								$field = "$prefixe" . "_texte";
						}
					}
					return $field;
				}
				
				
				
				function ACTI_REJET_prefixe($GROUPBY, $DEFAULT="") {
					if (substr($GROUPBY,3,3) == 'CLS') {
						$GROUPBY = substr($GROUPBY,0,6);
					}
					$field = '';
					$field_id = '';
					$field_code = '';
					$field_texte = '';
					switch ($GROUPBY) {
					case '*TAB':
						$field = "*TAB";
						break;
					case '-1':
						$field = "";
						break;
			
					case 'REJ':
						$field = "rejet";
						break;
					case 'REJCLS':
						$field = "rejet_section";
						break;
					case 'MOIA':
						$field = "CALC_MOIA";
						break;
					case 'MOIS':
						$field = "CALC_MOIS";
						break;
					case 'MOIV':
						$field = "CALC_MOIV";
						break;
					
					default:
						$field = $DEFAULT;
					}
					return $field;
					
					$prefixe = '';
					$groupby = '[GROUPBY]';
					if ($groupby == '-1') {$groupby = '[GROUPBY_2]';}

					$cls6 = substr($groupby, 0 , 6);
					$cls7 = substr($groupby, 6 , 1);

					
				}
				
				function ACTI_REJET_field_id($GROUPBY, $DEFAULT="") {
					
					$prefixe = ACTI_STANDARD_prefixe($GROUPBY, $DEFAULT, "REJET");
					if ($prefixe == "") {
						$prefixe = ACTI_REJET_prefixe($GROUPBY, $DEFAULT="");
					}
					
					if (substr($GROUPBY, 3, 3) == 'CLS' && $prefixe != $DEFAULT) {
						$section = substr($GROUPBY, 6);
						$field = "$prefixe" . "_id[" . $section . "]";
					}
					else {
						switch ($prefixe) {
							case "":
								$field = "0";
								break;
							case "*TAB":
								$field = "-9999999";
								break;
							case "CALC_MOIS":
								$field = "v_sejours_1.mois_sortie";
								break;
							
							default:
								$field = "$prefixe" . "_id";
						}
					}
					return $field;
				}
				
				function ACTI_REJET_field_code($GROUPBY, $DEFAULT="") {
					
					$prefixe = ACTI_STANDARD_prefixe($GROUPBY, $DEFAULT, "REJET");
					if ($prefixe == "") {
						$prefixe = ACTI_REJET_prefixe($GROUPBY, $DEFAULT="");
					}
					
					if (substr($GROUPBY, 3, 3) == 'CLS' && $prefixe != $DEFAULT) {
						$section = substr($GROUPBY, 6);
						$field = "$prefixe" . "_code[" . $section . "]";
					}
					else {
						switch ($prefixe) {
							case "":
								$field = "''";
								break;
							case "*TAB":
								$field = "' Résumé'";
								break;
							case "CALC_MOIS":
								$field = "v_sejours_1.mois_sortie";
								break;
							default:
								$field = "$prefixe" . "_code";
						}
					}
					return $field;
				}
				
				function ACTI_REJET_field_texte($GROUPBY, $DEFAULT="") {
					
					$prefixe = ACTI_STANDARD_prefixe($GROUPBY, $DEFAULT, "REJET");
					if ($prefixe == "") {
						$prefixe = ACTI_REJET_prefixe($GROUPBY, $DEFAULT="");
					}
					
					if (substr($GROUPBY, 3, 3) == 'CLS' && $prefixe != $DEFAULT) {
						$section = substr($GROUPBY, 6);
						$field = "$prefixe" . "_texte[" . $section . "]";
					}
					else {
						switch ($prefixe) {
							case "":
								$field = "''";
								break;
							case "*TAB":
								$field = "'Résumé'";
								break;
							case "CALC_MOIS":
								$field = "CASE substr(v_sejours_1.mois_sortie , 5 , 2)	
										WHEN '01' THEN 'Janvier'  
										WHEN '02' THEN 'Fevrier' 
										WHEN '03' THEN 'Mars' 
										WHEN '04' THEN 'Avril' 
										WHEN '05' THEN 'Mai' 
										WHEN '06' THEN 'Juin' 
										WHEN '07' THEN 'Juillet'  
										WHEN '08' THEN 'Aout' 
										WHEN '09' THEN 'Septembre' 
										WHEN '10' THEN 'Octobre' 
										WHEN '11' THEN 'Novembre' 
										WHEN '12' THEN 'Decembre' 
										ELSE '?'
										END
										|| ' ' || substr(v_sejours_1.mois_sortie , 1 , 4)";
								break;
							
							default:
								$field = "$prefixe" . "_texte";
						}
					}
					return $field;
				}
				
				
				
				
				function ACTI_ETATDOSSIER_data($DATA, $DEFAULT="", $CASE="", $PERIODE_DUREE="") {
					$case_when = "";
					$case_else = "";
					if ($CASE != "") {
						$case_when = "CASE WHEN $CASE THEN";
						$case_else = "ELSE null END";
					}
					switch ($DATA) {
					case 'NBFAC':
						return "base.cti_sum_distinct_on(DISTINCT $case_when $colsec array[v_factures_reference_1.no_sejour, v_factures_reference_1.nb_factures::text] $colsecend $case_else)";
						break;
					case 'NBREG':
						return "base.cti_sum_distinct_on(DISTINCT $case_when $colsec array[v_factures_reference_1.no_sejour, v_factures_reference_1.nb_factures_regularisation::text] $colsecend $case_else)";
						break;
					case 'PRREG':
						return "base.cti_division(
								base.cti_sum_distinct_on(DISTINCT $case_when $colsec array[v_factures_reference_1.no_sejour, v_factures_reference_1.nb_factures::text] $colsecend $case_else),
								base.cti_sum_distinct_on(DISTINCT $case_when $colsec array[v_factures_reference_1.no_sejour, v_factures_reference_1.nb_factures_regularisation::text] $colsecend $case_else)
								) * 100 ";
						break;
					case 'NBREJ':
						return "base.cti_sum_distinct_on(DISTINCT $case_when $colsec array[v_factures_reference_1.no_sejour, v_factures_reference_1.nb_rejets::text] $colsecend $case_else)";
						break;
					case 'NBNGRP':
						return "base.cti_sum_distinct_on(DISTINCT $case_when $colsec array[v_factures_reference_1.no_sejour, v_factures_reference_1.nb_non_groupe::text] $colsecend $case_else)";
						break;
					case 'DELGRP':
						return "AVG($case_when v_factures_reference_1.delai_groupage $case_else)";
						break;
					case 'NBNFAC':
						return "base.cti_sum_distinct_on(DISTINCT $case_when $colsec array[v_factures_reference_1.no_sejour, v_factures_reference_1.nb_non_calcules::text] $colsecend $case_else)";
						break;
					case 'DELFAC':
						return "AVG($case_when v_factures_reference_1.delai_facture $case_else)";
						break;
					case 'NBNEXP':
						return "base.cti_sum_distinct_on(DISTINCT $case_when $colsec array[v_factures_reference_1.no_sejour, v_factures_reference_1.nb_non_expedie[VIEW.CLIHON]::text] $colsecend $case_else)";
						break;
					case 'MTNEXP':
						return "base.cti_sum_distinct_on(DISTINCT $case_when $colsec array[v_factures_reference_1.no_sejour, v_factures_reference_1.montant_non_expedie[VIEW.CLIHON]::text] $colsecend $case_else)";
						break;
					case 'MTNEXPHC':
						return "base.cti_sum_distinct_on(DISTINCT $case_when $colsec array[v_factures_reference_1.no_sejour, (CASE WHEN type_sejour = '1'  THEN v_factures_reference_1.montant_non_expedie[VIEW.CLIHON] ELSE NULL END)::text] $colsecend $case_else)";
						break;
					case 'MTNEXPHJ':
						return "base.cti_sum_distinct_on(DISTINCT $case_when $colsec array[v_factures_reference_1.no_sejour, (CASE WHEN (type_sejour = '2' OR type_sejour = '5') THEN v_factures_reference_1.montant_non_expedie[VIEW.CLIHON] ELSE NULL END)::text] $colsecend $case_else)";
						break;
					case 'MTNEXPA':
						return "base.cti_sum_distinct_on(DISTINCT $case_when $colsec array[v_factures_reference_1.no_sejour, (CASE WHEN type_sejour = '3' THEN v_factures_reference_1.montant_non_expedie[VIEW.CLIHON] ELSE NULL END)::text] $colsecend $case_else)";
						break;
					case 'MTEXP':
						return "base.cti_sum_distinct_on(DISTINCT $case_when $colsec array[v_factures_reference_1.no_sejour, (CASE WHEN  v_factures_reference_1.nb_non_expedie[VIEW.CLIHON] <> 1  THEN v_factures_reference_1.montant_facture[VIEW.CLIHON] ELSE NULL END)::text] $colsecend $case_else)";
						break;
					case 'MTEXPHC':
						return "base.cti_sum_distinct_on(DISTINCT $case_when $colsec array[v_factures_reference_1.no_sejour, (CASE WHEN type_sejour = '1' AND  v_factures_reference_1.nb_non_expedie[VIEW.CLIHON] <> 1  THEN v_factures_reference_1.montant_facture[VIEW.CLIHON] ELSE NULL END)::text] $colsecend $case_else)";
						break;
					case 'MTEXPHJ':
						return "base.cti_sum_distinct_on(DISTINCT $case_when $colsec array[v_factures_reference_1.no_sejour, (CASE WHEN (type_sejour = '2' OR type_sejour = '5') AND v_factures_reference_1.nb_non_expedie[VIEW.CLIHON] <> 1  THEN v_factures_reference_1.montant_facture[VIEW.CLIHON] ELSE NULL END)::text] $colsecend $case_else)";
						break;
					case 'MTEXPA':
						return "base.cti_sum_distinct_on(DISTINCT $case_when $colsec array[v_factures_reference_1.no_sejour, (CASE WHEN type_sejour = '3'  AND v_factures_reference_1.nb_non_expedie[VIEW.CLIHON] <> 1  THEN v_factures_reference_1.montant_facture[VIEW.CLIHON] ELSE NULL END)::text] $colsecend $case_else)";
						break;
					case 'DELEXP':
						return "AVG($case_when v_factures_reference_1.delai_expedition $case_else)";
						break;
					case 'NBNSOL':
						return "base.cti_sum_distinct_on(DISTINCT $case_when $colsec array[v_factures_reference_1.no_sejour, (v_factures_reference_1.nb_non_solde[VIEW.CLIHON])::text] $colsecend $case_else)";
						break;
					case 'MTSOL':
						return "base.cti_sum_distinct_on(DISTINCT $case_when $colsec array[v_factures_reference_1.no_sejour, (v_factures_reference_1.montant_facture[VIEW.CLIHON])::text] $colsecend $case_else) - (base.cti_sum_distinct_on(DISTINCT $case_when $colsec array[v_factures_reference_1.no_sejour, (CASE WHEN   v_factures_reference_1.nb_non_solde_0[VIEW.CLIHON] <> 0 then v_factures_reference_1.montant_solde_0[VIEW.CLIHON] ELSE 0 END)::text] $colsecend $case_else) + base.cti_sum_distinct_on(DISTINCT $case_when $colsec array[v_factures_reference_1.no_sejour, (CASE WHEN   v_factures_reference_1.nb_non_solde_1[VIEW.CLIHON] <> 0 then v_factures_reference_1.montant_solde_1[VIEW.CLIHON] ELSE 0 END)::text] $colsecend $case_else) + base.cti_sum_distinct_on(DISTINCT $case_when $colsec array[v_factures_reference_1.no_sejour, (CASE WHEN   v_factures_reference_1.nb_non_solde_2[VIEW.CLIHON] <> 0 then v_factures_reference_1.montant_solde_2[VIEW.CLIHON] ELSE 0 END)::text] $colsecend $case_else))";
						break;
					case 'MTSOLHC':
						return "base.cti_sum_distinct_on(DISTINCT $case_when $colsec array[v_factures_reference_1.no_sejour, (CASE WHEN type_sejour = '1' AND  v_factures_reference_1.nb_non_solde[VIEW.CLIHON] <> 1  THEN v_factures_reference_1.montant_facture[VIEW.CLIHON] ELSE NULL END)::text] $colsecend $case_else)";
						break;
					case 'MTSOLHJ':
						return "base.cti_sum_distinct_on(DISTINCT $case_when $colsec array[v_factures_reference_1.no_sejour, (CASE WHEN (type_sejour = '2' OR type_sejour = '5') AND  v_factures_reference_1.nb_non_solde[VIEW.CLIHON] <> 1  THEN v_factures_reference_1.montant_facture[VIEW.CLIHON] ELSE NULL END)::text] $colsecend $case_else)";
						break;
					case 'MTSOLA':
						return "base.cti_sum_distinct_on(DISTINCT $case_when $colsec array[v_factures_reference_1.no_sejour, (CASE WHEN type_sejour = '3' AND  v_factures_reference_1.nb_non_solde[VIEW.CLIHON] <> 1  THEN v_factures_reference_1.montant_facture[VIEW.CLIHON] ELSE NULL END)::text] $colsecend $case_else)";
						break;
					case 'MTNSOL':
						return "base.cti_sum_distinct_on(DISTINCT $case_when $colsec array[v_factures_reference_1.no_sejour, (CASE WHEN v_factures_reference_1.nb_non_solde_0[VIEW.CLIHON] <> 0 then v_factures_reference_1.montant_solde_0[VIEW.CLIHON] ELSE 0 END)::text] $colsecend $case_else) + base.cti_sum_distinct_on(DISTINCT $case_when $colsec array[v_factures_reference_1.no_sejour, (CASE WHEN v_factures_reference_1.nb_non_solde_1[VIEW.CLIHON] <> 0 then v_factures_reference_1.montant_solde_1[VIEW.CLIHON] ELSE 0 END)::text] $colsecend $case_else) + base.cti_sum_distinct_on(DISTINCT $case_when $colsec array[v_factures_reference_1.no_sejour, (CASE WHEN v_factures_reference_1.nb_non_solde_2[VIEW.CLIHON] <> 0 then v_factures_reference_1.montant_solde_2[VIEW.CLIHON] ELSE 0 END)::text] $colsecend $case_else)";
						break;					
					case 'MTNSOLHC':
							return "base.cti_sum_distinct_on(DISTINCT $case_when $colsec array[v_factures_reference_1.no_sejour, (CASE WHEN type_sejour = '1' AND v_factures_reference_1.nb_non_solde[VIEW.CLIHON] = 1 THEN v_factures_reference_1.montant_solde[VIEW.CLIHON] ELSE NULL END)::text] $colsecend $case_else)";
							break;					
					case 'MTNSOLHJ':
							return "base.cti_sum_distinct_on(DISTINCT $case_when $colsec array[v_factures_reference_1.no_sejour, (CASE WHEN (type_sejour = '2' OR type_sejour = '5') AND  v_factures_reference_1.nb_non_solde[VIEW.CLIHON] = 1 THEN v_factures_reference_1.montant_solde[VIEW.CLIHON] ELSE NULL END)::text] $colsecend $case_else)";
							break;
					case 'MTNSOLA':
							return "base.cti_sum_distinct_on(DISTINCT $case_when $colsec array[v_factures_reference_1.no_sejour, (CASE WHEN type_sejour = '3' AND v_factures_reference_1.nb_non_solde[VIEW.CLIHON] = 1 THEN v_factures_reference_1.montant_solde[VIEW.CLIHON] ELSE NULL END)::text] $colsecend $case_else)";
							break;
					case 'DELSOL':
						return "AVG($case_when v_factures_reference_1.delai_solde[VIEW.CLIHON] $case_else)";
						break;
					case 'NBNCLO':
						return "base.cti_sum_distinct_on(DISTINCT $case_when $colsec array[v_factures_reference_1.no_sejour, (v_factures_reference_1.nb_non_cloture[VIEW.CLIHON])::text] $colsecend $case_else)";
						break;
					case 'NSEJ':
						return "COUNT(DISTINCT $case_when  v_factures_reference_1.no_sejour  $case_else)";
						break;					
					case 'NSEJHC':
						return "COUNT(DISTINCT $case_when CASE WHEN type_sejour = '1' THEN v_factures_reference_1.no_sejour ELSE NULL END $case_else)";
						break;					
					case 'NSEJHJ':
						return "COUNT(DISTINCT $case_when  CASE WHEN (type_sejour = '2' OR type_sejour = '5')  THEN v_factures_reference_1.no_sejour ELSE NULL END $case_else)";
						break;					
					case 'NSEJAUT':
						return "COUNT(DISTINCT $case_when CASE WHEN type_sejour = '3'  THEN v_factures_reference_1.no_sejour  ELSE NULL END $case_else)";
						break;
					case 'MFAC':
						return "base.cti_sum_distinct_on(DISTINCT $case_when $colsec array[v_factures_reference_1.no_sejour, (v_factures_reference_1.montant_facture[VIEW.CLIHON])::text] $colsecend $case_else)";
						break;
					case 'CAMFAC':
						return "base.cti_division(
								base.cti_sum_distinct_on(DISTINCT $case_when $colsec array[v_factures_reference_1.no_sejour, (v_factures_reference_1.montant_facture[VIEW.CLIHON])::text] $colsecend $case_else),
								COUNT(DISTINCT $case_when  v_factures_reference_1.no_sejour  $case_else)
								) ";
						break;						
					case 'CAMFHC':
						return "base.cti_division(
								base.cti_sum_distinct_on(DISTINCT $case_when $colsec array[v_factures_reference_1.no_sejour, (CASE WHEN type_sejour = '1' THEN v_factures_reference_1.montant_facture[VIEW.CLIHON] ELSE NULL END)::text] $colsecend $case_else),
								COUNT(DISTINCT $case_when CASE WHEN type_sejour = '1' THEN  v_factures_reference_1.no_sejour  ELSE NULL END $case_else)
								) ";
						break;	
					case 'CAMFHJ':
						return "base.cti_division(
								base.cti_sum_distinct_on(DISTINCT $case_when $colsec array[v_factures_reference_1.no_sejour, (CASE WHEN type_sejour = '2' OR type_sejour = '5'  THEN v_factures_reference_1.montant_facture[VIEW.CLIHON] ELSE NULL END)::text] $colsecend $case_else),
								COUNT(DISTINCT $case_when CASE WHEN type_sejour = '2' OR type_sejour = '5'  THEN  v_factures_reference_1.no_sejour  ELSE NULL END $case_else)
								) ";
						break;
					case 'CAMFA':
						return "base.cti_division(
								base.cti_sum_distinct_on(DISTINCT $case_when $colsec array[v_factures_reference_1.no_sejour, (CASE WHEN type_sejour = '3' THEN v_factures_reference_1.montant_facture[VIEW.CLIHON] ELSE NULL END)::text] $colsecend $case_else),
								COUNT($case_when CASE WHEN type_sejour = '3' THEN  v_factures_reference_1.no_sejour  ELSE NULL END $case_else)
								) ";
						break;
					case 'CAMFV':
						return "base.cti_division(
								base.cti_sum_distinct_on(DISTINCT $case_when $colsec array[v_factures_reference_1.no_sejour, (v_factures_reference_1.montant_facture[VIEW.CLIHON] + v_factures_reference_1.montant_encours[VIEW.CLIHON])::text] $colsecend $case_else),
								COUNT(DISTINCT $case_when v_factures_reference_1.no_sejour  $case_else)
								) ";
						break;						
					case 'CAMFVHC':
						return "base.cti_division(
								base.cti_sum_distinct_on(DISTINCT $case_when $colsec array[v_factures_reference_1.no_sejour, (CASE WHEN type_sejour = '1' THEN  v_factures_reference_1.montant_facture[VIEW.CLIHON] + v_factures_reference_1.montant_encours[VIEW.CLIHON] ELSE NULL END)::text] $colsecend $case_else),
								COUNT(DISTINCT $case_when CASE WHEN type_sejour = '1' THEN  v_factures_reference_1.no_sejour  ELSE NULL END $case_else)
								) ";
						break;	
					case 'CAMFVHJ':
						return "base.cti_division(
								base.cti_sum_distinct_on(DISTINCT $case_when $colsec array[v_factures_reference_1.no_sejour, (CASE WHEN type_sejour = '2' OR type_sejour = '5' THEN  v_factures_reference_1.montant_facture[VIEW.CLIHON] + v_factures_reference_1.montant_encours[VIEW.CLIHON] ELSE NULL END)::text] $colsecend $case_else),
								COUNT(DISTINCT $case_when CASE WHEN type_sejour = '2' OR type_sejour = '5'  THEN  v_factures_reference_1.no_sejour  ELSE NULL END $case_else)
								) ";
						break;
					case 'CAMFACA':
						return "base.cti_division(
								base.cti_sum_distinct_on(DISTINCT $case_when $colsec array[v_factures_reference_1.no_sejour, (CASE WHEN type_sejour = '3'  THEN  v_factures_reference_1.montant_facture[VIEW.CLIHON]  ELSE NULL END)::text] $colsecend $case_else),
								COUNT(DISTINCT $case_when CASE WHEN type_sejour = '3' THEN  v_factures_reference_1.no_sejour  ELSE NULL END $case_else)
								) ";
						break;
					case 'CAMFVA':
						return "base.cti_division(
								base.cti_sum_distinct_on(DISTINCT $case_when $colsec array[v_factures_reference_1.no_sejour, (CASE WHEN type_sejour = '3'  THEN  v_factures_reference_1.montant_facture[VIEW.CLIHON] + v_factures_reference_1.montant_encours[VIEW.CLIHON] ELSE NULL END)::text] $colsecend $case_else),
								COUNT(DISTINCT $case_when CASE WHEN type_sejour = '3' THEN  v_factures_reference_1.no_sejour  ELSE NULL END $case_else)
								) ";
						break;
					case 'MFACHC':
						return "base.cti_sum_distinct_on(DISTINCT $case_when $colsec array[v_factures_reference_1.no_sejour, (CASE WHEN type_sejour = '1' THEN  v_factures_reference_1.montant_facture[VIEW.CLIHON] ELSE NULL END)::text] $colsecend $case_else)";
						break;					
					case 'MFACHJ':
						return "base.cti_sum_distinct_on(DISTINCT $case_when $colsec array[v_factures_reference_1.no_sejour, (CASE WHEN type_sejour = '2' OR type_sejour = '5' THEN  v_factures_reference_1.montant_facture[VIEW.CLIHON] ELSE NULL END)::text] $colsecend $case_else)";
						break;
					case 'MFACA':
						return "base.cti_sum_distinct_on(DISTINCT $case_when $colsec array[v_factures_reference_1.no_sejour, (CASE WHEN type_sejour = '3' THEN  v_factures_reference_1.montant_facture[VIEW.CLIHON] ELSE NULL END)::text] $colsecend $case_else)";
						break;
					case 'MNFAC':
						break;
					case 'MNFHC':
						return "base.cti_sum_distinct_on(DISTINCT $case_when $colsec array[v_factures_reference_1.no_sejour, (CASE WHEN type_sejour = '1' THEN  v_factures_reference_1.montant_encours[VIEW.CLIHON] ELSE NULL END)::text] $colsecend $case_else)";
						break;
					case 'MNFHJ':
						return "base.cti_sum_distinct_on(DISTINCT $case_when $colsec array[v_factures_reference_1.no_sejour, (CASE WHEN type_sejour = '2' OR type_sejour = '5' THEN  v_factures_reference_1.montant_encours[VIEW.CLIHON] ELSE NULL END)::text] $colsecend $case_else)";
						break;
					case 'MNFACA':
						return "base.cti_sum_distinct_on(DISTINCT $case_when $colsec array[v_factures_reference_1.no_sejour, (CASE WHEN type_sejour = '3'  THEN  v_factures_reference_1.montant_encours[VIEW.CLIHON] ELSE NULL END)::text] $colsecend $case_else)";
						break;
					case 'MVFAC':
						return "base.cti_sum_distinct_on(DISTINCT $case_when $colsec array[v_factures_reference_1.no_sejour, (v_factures_reference_1.montant_facture[VIEW.CLIHON] ELSE NULL END)::text] $colsecend $case_else) + base.cti_sum_distinct_on(DISTINCT $case_when $colsec array[v_factures_reference_1.no_sejour, (v_factures_reference_1.montant_encours[VIEW.CLIHON])::text] $colsecend $case_else)";
						break;					
					case 'MVFHC':
						return "base.cti_sum_distinct_on(DISTINCT $case_when $colsec array[v_factures_reference_1.no_sejour, (CASE WHEN type_sejour = '1' THEN  v_factures_reference_1.montant_facture[VIEW.CLIHON] ELSE NULL END)::text] $colsecend $case_else) + base.cti_sum_distinct_on(DISTINCT $case_when $colsec array[v_factures_reference_1.no_sejour, (CASE WHEN type_sejour = '1' THEN  v_factures_reference_1.montant_encours[VIEW.CLIHON] ELSE NULL END )::text] $colsecend $case_else)";
						break;
					case 'MVFHJ':
						return "base.cti_sum_distinct_on(DISTINCT $case_when $colsec array[v_factures_reference_1.no_sejour, (CASE WHEN type_sejour = '2' OR type_sejour = '5' THEN  v_factures_reference_1.montant_facture[VIEW.CLIHON] ELSE NULL END)::text] $colsecend $case_else) + base.cti_sum_distinct_on(DISTINCT $case_when $colsec array[v_factures_reference_1.no_sejour, (CASE WHEN type_sejour = '2' OR type_sejour = '5' THEN  v_factures_reference_1.montant_encours[VIEW.CLIHON] ELSE NULL END )::text] $colsecend $case_else)";
						break;
					case 'MVFACA':
						return "base.cti_sum_distinct_on(DISTINCT $case_when $colsec array[v_factures_reference_1.no_sejour, (CASE WHEN type_sejour = '3' THEN  v_factures_reference_1.montant_facture[VIEW.CLIHON] ELSE NULL END)::text] $colsecend $case_else) + base.cti_sum_distinct_on(DISTINCT $case_when $colsec array[v_factures_reference_1.no_sejour, (CASE WHEN type_sejour = '3' THEN  v_factures_reference_1.montant_encours[VIEW.CLIHON] ELSE NULL END )::text] $colsecend $case_else)";
						break;
					case 'MCPT':
							return "base.cti_sum_distinct_on(DISTINCT $case_when $colsec array[v_factures_reference_1.no_sejour, (v_factures_reference_1.montant_comptabilise[VIEW.CLIHON])::text] $colsecend $case_else)";
							break;
					case 'MCPTHC':
						return "base.cti_sum_distinct_on(DISTINCT $case_when $colsec array[v_factures_reference_1.no_sejour, (CASE WHEN type_sejour = '1' THEN  v_factures_reference_1.montant_comptabilise[VIEW.CLIHON] ELSE NULL END)::text] $colsecend $case_else)";
						break;
					case 'MCPTHJ':
						return "base.cti_sum_distinct_on(DISTINCT $case_when $colsec array[v_factures_reference_1.no_sejour, (CASE WHEN type_sejour = '2' OR type_sejour = '5' THEN  v_factures_reference_1.montant_comptabilise[VIEW.CLIHON] ELSE NULL END)::text] $colsecend $case_else)";
						break;
					case 'MCPTA':
						return "base.cti_sum_distinct_on(DISTINCT $case_when $colsec array[v_factures_reference_1.no_sejour, (CASE WHEN type_sejour = '3'  THEN  v_factures_reference_1.montant_comptabilise[VIEW.CLIHON] ELSE NULL END)::text] $colsecend $case_else)";
						break;

					default:
                        return $DEFAULT;
                        break;
					}

				}
				
				function ACTI_facturation_clinique_param_data($LS_DATA, $LS_DATA_COL, $DATA, $DEFAULT="", $CASE="", $PERIODE_DUREE="", $COL='0') {
					
					$wdata = $DATA;
					if ($LS_DATA != "-1") {
						$wdata_array_1 = explode("=",$LS_DATA);
						$wdata_array_2 = $wdata_array_1[1];
						$wdata_array = explode(",",$wdata_array_2);
						$wdata = $wdata_array[$LS_DATA_COL-1];
					}
					if($wdata != ""){
					    return ACTI_facturation_clinique_data($wdata, $DEFAULT, $CASE, $PERIODE_DUREE, $COL);
					}
				}
				
				function ACTI_facturation_clinique_data($DATA, $DEFAULT="", $CASE="", $PERIODE_DUREE="",$COL='0') {
					$case_when = "";
					$case_else = "";
					if($COL == '1'){
						$colsec="CASE WHEN COLUMNCHECKSEQUENCE THEN";
						$colsecend = "ELSE null END";
						
					}else {
						$colsec=" ";
						$colsecend = " ";
					
					}
					if ($CASE != "") {
						$case_when = "CASE WHEN $CASE THEN";
						$case_else = "ELSE null END";
					}
					if ($DATA == "NBPROTO" || $DATA == "NBPROTO2" ) {
						if ($colsecend == "ELSE null END") {
							$colsecend = "ELSE Array['','0'] END";
						}
						if ($case_else == "ELSE null END") {
							$case_else = "ELSE Array['','0'] END";
						}
					}
					switch ($DATA) {
								case 'NBSEJ':
									return "COUNT(DISTINCT $case_when $colsec CASE WHEN est_ligne_facturee = '1' AND v_sejours_1.type_sejour <> '9' THEN v_factures_lignes_c_4.no_sejour  $colsecend ELSE NULL END  $case_else)";
									break;
								case 'NBFAC':
									return "COUNT(DISTINCT $case_when  $colsec CASE WHEN est_ligne_facturee = '1' THEN v_factures_lignes_c_4.no_facture  $colsecend ELSE NULL END $case_else)";
									break;
								case 'NBSEJHC':
									return "COUNT(DISTINCT $case_when $colsec CASE WHEN est_ligne_facturee = '1' AND type_sejour = '1' THEN v_factures_lignes_c_4.no_sejour $colsecend ELSE NULL END $case_else)";
									break;								
								case 'NBSEJHJ':
									return "COUNT(DISTINCT $case_when $colsec CASE WHEN est_ligne_facturee = '1' AND type_sejour IN ('2','5') THEN v_factures_lignes_c_4.no_sejour $colsecend ELSE NULL END $case_else)";
									break;								
								case 'NBSEJAU':
									return "COUNT(DISTINCT $case_when $colsec CASE WHEN est_ligne_facturee = '1' AND type_sejour NOT IN ('1','2','5') THEN v_factures_lignes_c_4.no_sejour $colsecend ELSE NULL END $case_else)";
									break;
								case 'FACNS1':
									return "COUNT(DISTINCT $case_when $colsec CASE WHEN montant_facture_1 <> 0 THEN v_sejours_1.no_sejour $colsecend ELSE null END $case_else)";
									break;
								case 'FACNS2':
									return "COUNT(DISTINCT $case_when $colsec CASE WHEN montant_facture_2 + montant_facture_22 <> 0 THEN v_sejours_1.no_sejour $colsecend ELSE null END $case_else )";
									break;
								case 'FACNS0':
									return "COUNT(DISTINCT $case_when $colsec CASE WHEN montant_facture_0 <> 0 THEN v_sejours_1.no_sejour $colsecend ELSE null END $case_else )";
									break;	
								case 'FAVNBS':
									return "COUNT(DISTINCT $case_when $colsec CASE WHEN (est_ligne_facturee = '1' OR est_ligne_encours = '1') AND v_sejours_1.type_sejour <> '9' THEN v_sejours_1.no_sejour $colsecend ELSE NULL END $case_else)";
									break;
								case 'NBRUB':
									return "SUM($case_when $colsec CASE WHEN est_ligne_facturee = '1' THEN nb_rubrique * coefficient $colsecend ELSE NULL END $case_else)";
									break;
								case 'NBPRE':
									return "SUM( $case_when $colsec CASE WHEN est_ligne_facturee = '1' THEN nb_prestation * coefficient $colsecend ELSE NULL END $case_else)";
									break;
                                case 'NBPROTO':
                                    return "base.cti_sum_distinct_on(DISTINCT $case_when $colsec array[v_factures_lignes_h_3.no_facture::text || '|' || protocole_id::text,CASE WHEN nb_prestation >= 0 THEN '1' ELSE '-1' END]  $colsecend   $case_else)";
                                    break;
								case 'NBPROTO2':
                                    return "base.cti_sum_distinct_on(DISTINCT $case_when $colsec array[v_factures_lignes_h_3.no_facture::text || '|' || protocole_id::text,CASE WHEN protocole_id = 0 THEN '0' WHEN nb_prestation >= 0 THEN '1' ELSE '-1' END]  $colsecend   $case_else)";
                                    break;
								case 'MTFAC':
									return "SUM($case_when $colsec CASE WHEN  est_ligne_facturee = '1' THEN montant_facture $colsecend ELSE NULL END $case_else)";
									break;								
								case 'MMTFAC':
									return "base.cti_division(SUM($case_when $colsec CASE WHEN  est_ligne_facturee = '1' THEN montant_facture $colsecend ELSE NULL END $case_else),COUNT(DISTINCT $case_when $colsec CASE WHEN est_ligne_facturee = '1' THEN v_factures_lignes_c_4.no_sejour $colsecend ELSE NULL END $case_else))";
									break;
								case 'FAVNBSHC':
									return "COUNT(DISTINCT $case_when $colsec CASE WHEN (est_ligne_facturee = '1' OR est_ligne_encours = '1') AND type_sejour = '1' THEN v_sejours_1.no_sejour $colsecend ELSE NULL END $case_else)";
									break;	
								case 'FAVNBSHJ':
									return "COUNT(DISTINCT $case_when $colsec CASE WHEN (est_ligne_facturee = '1' OR est_ligne_encours = '1') AND type_sejour IN ('2','5') THEN v_sejours_1.no_sejour $colsecend ELSE NULL END $case_else)";
									break;
								case 'FAVNBSHA':
									return "COUNT(DISTINCT $case_when $colsec CASE WHEN (est_ligne_facturee = '1' OR est_ligne_encours = '1') AND type_sejour NOT IN ('1','2','5') THEN v_sejours_1.no_sejour $colsecend ELSE NULL END $case_else)";
									break;	
								case 'FAVMTTHC':
									return "SUM($case_when $colsec CASE WHEN type_sejour = '1' THEN montant_facture + montant_encours $colsecend ELSE 0 END $case_else)";
									break;	
								case 'FAVMTTHJ':
									return "SUM($case_when $colsec CASE WHEN type_sejour IN ('2','5') THEN montant_facture + montant_encours $colsecend ELSE 0 END $case_else)";
									break;
								case 'FAVMTTHA':
									return "SUM($case_when $colsec CASE WHEN type_sejour NOT IN ('1','2','5') THEN montant_facture + montant_encours $colsecend ELSE 0 END $case_else)";
									break;											
									
								case 'FACMTTHC':
									return "SUM($case_when $colsec CASE WHEN est_ligne_facturee = '1' AND type_sejour = '1' THEN montant_facture $colsecend ELSE 0 END $case_else)";
									break;
								case 'MMTFACHC':
									return "base.cti_division(SUM($case_when $colsec CASE WHEN est_ligne_facturee = '1' AND type_sejour = '1' THEN montant_facture $colsecend ELSE 0 END $case_else),COUNT(DISTINCT $case_when $colsec CASE WHEN est_ligne_facturee = '1' AND type_sejour = '1' THEN v_factures_lignes_c_4.no_sejour $colsecend ELSE NULL END $case_else))";
									break;									
								case 'FACMTTHJ':
									return "SUM($case_when  $colsec CASE WHEN est_ligne_facturee = '1' AND type_sejour IN ('2','5') THEN montant_facture $colsecend ELSE 0 END $case_else)";
									break;
								case 'MMTFACHJ':
									return "base.cti_division(SUM($case_when $colsec CASE WHEN est_ligne_facturee = '1' AND type_sejour IN ('2','5') THEN montant_facture $colsecend ELSE 0 END $case_else),COUNT(DISTINCT $case_when $colsec CASE WHEN est_ligne_facturee = '1' AND type_sejour IN ('2','5') THEN v_factures_lignes_c_4.no_sejour $colsecend ELSE NULL END $case_else))";
									break;								
								case 'FACMTTHA':
									return "SUM($case_when  $colsec CASE WHEN est_ligne_facturee = '1' AND type_sejour NOT IN ('1','2','5') THEN montant_facture $colsecend ELSE 0 END $case_else)";
									break;
								case 'MMTFACAU':
									return "base.cti_division(SUM($case_when $colsec CASE WHEN est_ligne_facturee = '1' AND type_sejour NOT IN ('1','2','5')  THEN montant_facture $colsecend ELSE 0 END $case_else),COUNT(DISTINCT $case_when $colsec CASE WHEN est_ligne_facturee = '1' AND type_sejour NOT IN ('1','2','5')  THEN v_factures_lignes_c_4.no_sejour $colsecend ELSE NULL END $case_else))";
									break;									
								case 'VALMTHCGR':
									return "SUM($case_when $colsec CASE WHEN type_sejour = '1' AND nb_non_groupe = 0 AND est_ligne_encours = '1' THEN montant_encours $colsecend ELSE 0 END $case_else)";
									break;								
								case 'VALMTHCNG':
									return "SUM($case_when $colsec CASE WHEN type_sejour = '1' AND (code_sorti <> '1' OR nb_non_groupe <> 0) AND est_ligne_encours = '1' THEN montant_encours $colsecend ELSE 0 END $case_else)";
									break;
								case 'VALMTHJGR':
									return "SUM($case_when $colsec CASE WHEN type_sejour IN ('2','5') AND nb_non_groupe = 0 AND est_ligne_encours = '1' THEN montant_encours $colsecend ELSE 0 END $case_else)";
									break;
                                case 'VALMTHCT':
									return "SUM($case_when $colsec CASE WHEN type_sejour = '1' AND est_ligne_encours = '1' THEN montant_encours $colsecend ELSE 0 END $case_else)";
									break;                                    
								case 'VALMTHJNG':
									return "SUM($case_when $colsec CASE WHEN type_sejour IN ('2','5') AND (code_sorti <> '1' OR nb_non_groupe <> 0) AND est_ligne_encours = '1' THEN montant_encours $colsecend ELSE 0 END $case_else)";
									break;								
                                case 'VALMTHJT':
									return "SUM($case_when $colsec CASE WHEN type_sejour IN ('2','5') AND est_ligne_encours = '1' THEN montant_encours $colsecend ELSE 0 END $case_else)";
									break;
								case 'VALMTHA':
									return "SUM($case_when $colsec CASE WHEN type_sejour NOT IN ('1', '2','5') AND est_ligne_encours = '1' THEN montant_encours $colsecend ELSE 0 END $case_else)";
									break;
									
								case 'MTFACC':
									return "SUM($case_when $colsec CASE WHEN COALESCE(origine_facturation_id,0) <= 1 THEN montant_facture $colsecend ELSE NULL END $case_else)";
									break;
								case 'MTFACH':
									return "SUM($case_when $colsec CASE WHEN COALESCE(origine_facturation_id,0) = 2 THEN montant_facture $colsecend ELSE NULL END $case_else)";
									break;
								case 'MTFACHI':
									return "SUM($case_when $colsec CASE WHEN COALESCE(origine_facturation_id,0) = 3 THEN montant_facture_actes_inclus_dans_sejour $colsecend ELSE NULL END $case_else)";
									break;
								case 'MTFAC0':
									return "SUM($case_when $colsec montant_facture_0 $colsecend $case_else)";
									break;
								case 'MTFAC1':
									return "SUM($case_when $colsec montant_facture_1 $colsecend  $case_else)";
									break;
								case 'MTFAC2':
									return "SUM($case_when $colsec montant_facture_2 + montant_facture_22 $colsecend  $case_else)";
									break;
								case 'MTCPT':
									return "SUM($case_when $colsec montant_comptabilise + COALESCE(montant_comptabilise_budget_global_1,0) $colsecend $case_else)";
									break;
								case 'MTCPTHBG':
									return "SUM($case_when $colsec montant_comptabilise $colsecend $case_else)";
									break;
								case 'MTCPT0':
									return "SUM($case_when $colsec montant_comptabilise_0 $colsecend $case_else)";
									break;
								case 'MTCPT1':
									return "SUM($case_when $colsec montant_comptabilise_1 + COALESCE(montant_comptabilise_budget_global_1,0) $colsecend $case_else)";
									break;
								case 'MTCPT1BG':
									return "SUM($case_when $colsec COALESCE(montant_comptabilise_budget_global_1,0) $colsecend $case_else)";
									break;
								case 'MTCPT1HBG':
									return "SUM($case_when $colsec montant_comptabilise_1 $colsecend $case_else)";
									break;
								case 'MTCPT2':
									return "SUM($case_when $colsec montant_comptabilise_2 + montant_comptabilise_22 $colsecend $case_else)";
									break;
								case 'NBSEJENC':
									return "COUNT(DISTINCT $case_when $colsec CASE WHEN est_ligne_encours = '1' THEN v_factures_lignes_c_4.no_sejour $colsecend ELSE NULL END $case_else )";
									break;
								case 'NBRUBENC':
									return "SUM($case_when $colsec CASE WHEN est_ligne_encours = '1' THEN nb_rubrique * coefficient $colsecend ELSE NULL END $case_else)";
									break;
								case 'NBPREENC':
									return "SUM( $case_when $colsec CASE WHEN est_ligne_encours = '1' THEN nb_prestation * coefficient $colsecend ELSE NULL END $case_else)";
									break;								
								case 'MTENC':
									return "SUM($case_when $colsec CASE WHEN est_ligne_encours = '1' THEN montant_encours ELSE NULL END $colsecend $case_else)";
									break;
								case 'NBSEJENC1':
									return "COUNT(DISTINCT $case_when $colsec CASE WHEN code_sorti = '1' AND est_ligne_encours = '1' AND nb_non_groupe = 0 THEN v_factures_lignes_c_4.no_sejour $colsecend ELSE NULL END $case_else)";
									break;
								case 'NBRUBENC1':
									return "SUM($case_when $colsec CASE WHEN code_sorti = '1' AND est_ligne_encours = '1' AND nb_non_groupe = 0 THEN nb_rubrique * coefficient $colsecend ELSE NULL END $case_else)";
									break;
								case 'NBPREENC1':
									return "SUM($case_when $colsec CASE WHEN code_sorti = '1' AND est_ligne_encours = '1' AND nb_non_groupe = 0 THEN nb_prestation * coefficient $colsecend ELSE NULL END $case_else)";
									break;	
								case 'MTENC1':
									return "SUM($case_when $colsec CASE WHEN code_sorti = '1' AND est_ligne_encours = '1' AND nb_non_groupe = 0 THEN montant_encours $colsecend ELSE NULL END $case_else)";
									break;
								case 'NBSEJENC2':
									return "COUNT(DISTINCT $case_when $colsec CASE WHEN code_sorti = '1' AND est_ligne_encours = '1' AND nb_non_groupe <> 0 THEN v_factures_lignes_c_4.no_sejour $colsecend ELSE NULL END $case_else)";
									break;
								case 'NBRUBENC2':
									return "SUM($case_when $colsec CASE WHEN code_sorti = '1' AND est_ligne_encours = '1' AND nb_non_groupe <> 0 THEN nb_rubrique * coefficient $colsecend ELSE NULL END $case_else)";
									break;
								case 'NBPREENC2':
									return "SUM($case_when $colsec CASE WHEN code_sorti = '1' AND est_ligne_encours = '1' AND nb_non_groupe <> 0 THEN nb_prestation * coefficient $colsecend ELSE NULL END $case_else)";
									break;		
								case 'MTENC2':
									return "SUM($case_when $colsec CASE WHEN code_sorti = '1' AND est_ligne_encours = '1' AND nb_non_groupe <> 0 THEN montant_encours $colsecend ELSE NULL END $case_else)";
									break;
								case 'NBSEJENC3':
									return "COUNT(DISTINCT $case_when $colsec CASE WHEN code_sorti <> '1' AND est_ligne_encours = '1' THEN v_factures_lignes_c_4.no_sejour $colsecend ELSE NULL END $case_else)";
									break;
								case 'NBRUBENC3':
									return "SUM($case_when $colsec CASE WHEN code_sorti <> '1' AND est_ligne_encours = '1' THEN nb_rubrique * coefficient $colsecend ELSE NULL END $case_else)";
									break;
								case 'NBPREENC3':
									return "SUM($case_when $colsec CASE WHEN code_sorti <> '1' AND est_ligne_encours = '1' THEN nb_prestation * coefficient $colsecend ELSE NULL END $case_else)";
									break;		
								case 'MTENC3':
									return "SUM($case_when $colsec CASE WHEN code_sorti <> '1' AND est_ligne_encours = '1' THEN montant_encours $colsecend ELSE NULL END $case_else)";
									break;
								case 'NBSEJFACENC':
									return "COUNT(DISTINCT $case_when $colsec CASE WHEN est_ligne_encours = '1' OR est_ligne_facturee = '1' THEN v_factures_lignes_c_4.no_sejour $colsecend ELSE NULL END $case_else)";
									break;
								case 'NBRUBFACENC':
									return "SUM($case_when $colsec CASE WHEN est_ligne_encours = '1' OR est_ligne_facturee = '1' THEN nb_rubrique * coefficient $colsecend ELSE NULL END $case_else)";
									break;
								case 'NBPREFACENC':
									return "SUM($case_when $colsec CASE WHEN est_ligne_encours = '1' OR est_ligne_facturee = '1' THEN nb_prestation * coefficient $colsecend ELSE NULL END $case_else)";
									break;			
								case 'MTFACENC':
									return "SUM($case_when $colsec CASE WHEN est_ligne_encours = '1' OR est_ligne_facturee = '1' THEN montant_encours ELSE NULL END + montant_facture $colsecend $case_else)";
									break;								
								case 'MMTFACENC':
									return "base.cti_division(SUM($case_when $colsec CASE WHEN est_ligne_encours = '1' OR est_ligne_facturee = '1' THEN montant_encours  ELSE NULL END + montant_facture $colsecend $case_else),COUNT(DISTINCT $case_when $colsec CASE WHEN est_ligne_encours = '1' OR est_ligne_facturee = '1' THEN v_factures_lignes_c_4.no_sejour $colsecend ELSE NULL END $case_else))";
									break;								
								case 'FAVCAMHC':
									return "base.cti_division(SUM($case_when $colsec CASE WHEN type_sejour = '1' THEN montant_facture + montant_encours $colsecend ELSE 0 END $case_else),COUNT(DISTINCT $case_when $colsec CASE WHEN (est_ligne_facturee = '1' OR est_ligne_encours = '1') AND type_sejour = '1' THEN v_sejours_1.no_sejour $colsecend ELSE NULL END $case_else))";
									break;								
								case 'FAVCAMHJ':
									return "base.cti_division(SUM($case_when $colsec CASE WHEN type_sejour IN ('2','5') THEN montant_facture + montant_encours $colsecend ELSE 0 END $case_else),COUNT(DISTINCT $case_when $colsec CASE WHEN (est_ligne_facturee = '1' OR est_ligne_encours = '1') AND type_sejour IN ('2','5') THEN v_sejours_1.no_sejour $colsecend ELSE NULL END $case_else))";
									break;									
								case 'FAVCAMAU':
									return "base.cti_division(SUM($case_when $colsec CASE WHEN type_sejour NOT IN ('1','2','5') THEN montant_facture + montant_encours $colsecend ELSE 0 END $case_else),COUNT(DISTINCT $case_when $colsec CASE WHEN (est_ligne_facturee = '1' OR est_ligne_encours = '1') AND type_sejour NOT IN ('1','2','5') THEN v_sejours_1.no_sejour $colsecend ELSE NULL END $case_else))";
									break;									
								case 'MFACEMC':
									return "SUM($case_when $colsec CASE WHEN v_factures_lignes_c_4.code_facture = '1' THEN v_factures_lignes_c_4.montant_facture $colsecend ELSE 0 END $case_else)";
									break;									
								case 'MVALEMC':
									return "SUM($case_when $colsec CASE WHEN v_factures_lignes_c_4.code_facture = '0' AND est_ligne_encours = '1' THEN v_factures_lignes_c_4.montant_encours $colsecend ELSE 0 END $case_else)";
									break;								
								case 'MFPVEMC':
									return "SUM($case_when $colsec CASE WHEN v_factures_lignes_c_4.code_facture IN ('0','1')   THEN v_factures_lignes_c_4.montant_encours + v_factures_lignes_c_4.montant_facture $colsecend ELSE 0 END $case_else)";
									break;								
								case 'MMFPVEMC':
									return "SUM($case_when $colsec CASE WHEN v_factures_lignes_c_4.code_facture IN ('0','1')   THEN v_factures_lignes_c_4.montant_encours + v_factures_lignes_c_4.montant_facture $colsecend ELSE 0 END $case_else)";
									break;									
								case 'MFPVEMCHC':
									return "SUM($case_when $colsec CASE WHEN v_factures_lignes_c_4.code_facture IN ('0','1') AND type_sejour = '1'  THEN v_factures_lignes_c_4.montant_encours + v_factures_lignes_c_4.montant_facture $colsecend ELSE 0 END $case_else)";
									break;									
								case 'MFAVCAMHC':
									return "SUM($case_when $colsec CASE WHEN v_factures_lignes_c_4.code_facture IN ('0','1') AND type_sejour = '1'  THEN v_factures_lignes_c_4.montant_encours + v_factures_lignes_c_4.montant_facture $colsecend ELSE 0 END $case_else)";
									break;									
								case 'MFACMTTHC':
									return "SUM($case_when $colsec CASE WHEN v_factures_lignes_c_4.code_facture IN ('0','1') AND type_sejour = '1'  THEN  v_factures_lignes_c_4.montant_facture $colsecend ELSE 0 END $case_else)";
									break;									
								case 'MMFACEMC':
									return "SUM($case_when $colsec CASE WHEN v_factures_lignes_c_4.code_facture = '1'  THEN  v_factures_lignes_c_4.montant_facture $colsecend ELSE 0 END $case_else)";
									break;								
								case 'MMVALEMC':
									return "SUM($case_when $colsec CASE WHEN v_factures_lignes_c_4.code_facture = '0' AND est_ligne_encours = '1' THEN v_factures_lignes_c_4.montant_encours $colsecend ELSE 0 END $case_else)";
									break;	
								case 'MFACEMCHC':
									return "SUM($case_when $colsec CASE WHEN v_factures_lignes_c_4.code_facture = '1' and type_sejour='1' THEN v_factures_lignes_c_4.montant_facture $colsecend ELSE 0 END $case_else)";
									break;									
								case '0':case 'EMC':case 'VALEMC':case 'FAVEMC':case 'FACNBJ':case 'VALNBJ':case 'FAVNBJ':case 'FAVDMS':case 'FAVNBEMCHC':case 'MFAVCAMHC':case 'MMFPVEMC':case 'MMFACEMC':case 'MMVALEMC':
									return "0";
									break;											
                                default:
                                    return $DEFAULT;
                                    break;
					}

				}
				
				function ACTI_facturation_clinique_data_col($DATA, $DEFAULT="", $CASE="", $PERIODE_DUREE="",$COL,$TOPERIODE) {
					$case_when = "";
					$case_else = "";
					if($COL == '1'){
						$colsec="CASE WHEN COLUMNCHECKSEQUENCE THEN";
						$colsecend = "ELSE null END";
						
					}else {
						$colsec=" ";
						$colsecend = " ";
					
					}
					if ($CASE != "") {
						$case_when = "CASE WHEN $CASE THEN";
						$case_else = "ELSE null END";
					}
					switch ($DATA) {
								case 'EMC':
									return "SUM($colsec CASE WHEN  p_factures_reference.code_facture = '1' THEN equivalent_malade_complet $colsecend ELSE 0 END)";
									break;								
								case 'MMFACEMC':
									return "SUM($colsec CASE WHEN  p_factures_reference.code_facture = '1' THEN equivalent_malade_complet $colsecend ELSE 0 END)";
									break;								
								case 'MMVALEMC':
									return "SUM($colsec CASE WHEN  p_factures_reference.code_facture = '0' THEN equivalent_malade_complet $colsecend ELSE 0 END)";
									break;								
								case 'VALEMC':
									return "SUM($colsec CASE WHEN  p_factures_reference.code_facture = '0' THEN equivalent_malade_complet $colsecend ELSE 0 END)";
									break;								
								case 'FAVEMC':
									return "SUM($colsec equivalent_malade_complet $colsecend)";
									break;									
								case 'MMFPVEMC':
									return "SUM($colsec equivalent_malade_complet $colsecend)";
									break;								
								case 'FACNBJ':
									return "SUM($colsec CASE WHEN  p_factures_reference.code_facture = '1' THEN nb_jours_f + nb_ambulatoires + CASE WHEN type_sejour = '5' THEN nb_seances  ELSE 0 END $colsecend ELSE 0 END)";
									break;								
								case 'VALNBJ':
									return "SUM($colsec CASE WHEN  p_factures_reference.code_facture = '0' THEN nb_jours_f + nb_ambulatoires + CASE WHEN type_sejour = '5' THEN nb_seances  ELSE 0 END $colsecend ELSE 0 END)";
									break;								
								case 'FAVNBJ':
									return "SUM($colsec nb_jours_f + nb_ambulatoires + CASE WHEN type_sejour = '5' THEN nb_seances  ELSE 0 END $colsecend)";
									break;								
								case 'FAVNBEMCHC':
									return "SUM($colsec CASE WHEN type_sejour = '1' then equivalent_malade_complet ELSE 0 END $colsecend)";
									break;								
								case 'MFAVCAMHC':
									return "SUM($colsec CASE WHEN type_sejour = '1' then equivalent_malade_complet ELSE 0 END $colsecend)";
									break;								
								case 'MFACMTTHC':
									return "SUM($colsec CASE WHEN type_sejour = '1' then equivalent_malade_complet ELSE 0 END $colsecend)";
									break;	
								case 'FAVDMS':
									return "base.cti_division(SUM($colsec CASE WHEN  (v_sejours_1.date_sortie <='$TOPERIODE'::date ) AND v_sejours_1.code_sorti = 1 then [VIEW.JOURNEES_FIELD] $colsecend ELSE null END),SUM($colsec nb_sorties_directes $colsecend))";
									break;
                                default:
                                    return $DEFAULT;
                                    break;
					}

				}
				function ACTI_facturation_honoraires_data($DATA, $DEFAULT="", $CASE="", $PERIODE_DUREE="",$COL) {
					$case_when = "";
					$case_else = "";
					if($COL == '1'){
						$colsec="CASE WHEN COLUMNCHECKSEQUENCE THEN";
						$colsecend = "ELSE null END";
						
					}else {
						$colsec=" ";
						$colsecend = " ";
					}
					if ($CASE != "") {
						$case_when = "CASE WHEN $CASE THEN";
						$case_else = "ELSE null END";
					}
					if ($DATA == "NBPROTO" || $DATA == "NBPROTO2") {
						if ($colsecend == "ELSE null END") {
							$colsecend = "ELSE Array['','0'] END";
						}
						if ($case_else == "ELSE null END") {
							$case_else = "ELSE Array['','0'] END";
						}
					}
					switch ($DATA) {
								case 'NBSEJ':
									return "COUNT(DISTINCT $case_when $colsec v_factures_lignes_h_3.no_sejour $colsecend $case_else)";
									break;
								case 'SEJPAT':
									return "COUNT(DISTINCT $case_when $colsec CASE WHEN (montant_facture <> 0 OR montant_depassement <> 0 OR montant_non_facture <> 0) and (tiers_payant_0_id <> 0 and montant_facture_0 != 0) then  v_factures_lignes_h_3.sejour_id $colsecend else NULL end $case_else)";
									break;
								case 'SEJAMO':
									return "COUNT(DISTINCT $case_when $colsec CASE WHEN (montant_facture <> 0 OR montant_depassement <> 0 OR montant_non_facture <> 0) and (tiers_payant_1_id <> 0 and montant_facture_1 != 0)  then  v_factures_lignes_h_3.sejour_id $colsecend else null end $case_else)";
									break;
								case 'SEJAMC':
									return "COUNT(DISTINCT $case_when $colsec CASE WHEN (montant_facture <> 0 OR montant_depassement <> 0 OR montant_non_facture <> 0) and (tiers_payant_2_id <> 0 and montant_facture_2 != 0)  then  v_factures_lignes_h_3.sejour_id $colsecend else null end $case_else)";
									break;
								case 'NBDEP':
									return "COUNT(DISTINCT $case_when $colsec CASE WHEN montant_depassement <> 0 THEN v_factures_lignes_h_3.sejour_id   $colsecend ELSE NULL END  $case_else)";
									break;
								case 'NBRUB':
									return "SUM($case_when $colsec nb_rubrique * coefficient $colsecend  $case_else)";
									break;
								case 'NBPRE':
									return "SUM($case_when $colsec case when montant_facture <> 0 OR montant_depassement <> 0 OR montant_non_facture <> 0 then nb_prestation $colsecend ELSE NULL END $case_else)";
									break;
                                case 'NBPROTO':
                                    return "base.cti_sum_distinct_on(DISTINCT $case_when $colsec array[v_factures_lignes_h_3.no_facture::text || '|' || protocole_id::text,CASE WHEN nb_prestation >= 0 THEN '1' ELSE '-1' END]  $colsecend   $case_else)";
                                    break;
								case 'NBPROTO2':
                                    return "base.cti_sum_distinct_on(DISTINCT $case_when $colsec array[v_factures_lignes_h_3.no_facture::text || '|' || protocole_id::text,CASE WHEN protocole_id = 0 THEN '0' WHEN nb_prestation >= 0 THEN '1' ELSE '-1' END]  $colsecend   $case_else)";
                                    break;
								case 'NBCOEPRE':
									return "SUM($case_when $colsec nb_prestation * coefficient $colsecend $case_else)";
									break;
								case 'MTFAC':
									return "SUM($case_when $colsec case when montant_facture <> 0 OR montant_depassement <> 0 OR montant_non_facture <> 0 then montant_facture  $colsecend ELSE NULL END $case_else)";
									break;
								case 'MTFACI':
									return "SUM($case_when $colsec case when (montant_facture <> 0 OR montant_depassement <> 0 OR montant_non_facture <> 0 OR montant_facture_actes_inclus_dans_sejour <> 0) then montant_facture + COALESCE(montant_facture_actes_inclus_dans_sejour,0) $colsecend ELSE NULL END $case_else)";
									break;
								case 'MTI':
									return "SUM($case_when $colsec case when montant_facture_actes_inclus_dans_sejour <> 0 then COALESCE(montant_facture_actes_inclus_dans_sejour,0) $colsecend  ELSE NULL END $case_else)";
									break;
								case 'MTFAC0':
									return "SUM($case_when $colsec case when montant_facture <> 0 OR montant_depassement <> 0 OR montant_non_facture <> 0 then montant_facture_0  $colsecend ELSE NULL END $case_else)";
									break;
								case 'MTFAC1':
									return "SUM($case_when $colsec case when montant_facture <> 0 OR montant_depassement <> 0 OR montant_non_facture <> 0 then montant_facture_1  $colsecend ELSE NULL END $case_else)";
									break;
								case 'MTFAC2':
									return "SUM($case_when $colsec case when montant_facture <> 0 OR montant_depassement <> 0 OR montant_non_facture <> 0 then montant_facture_2  $colsecend ELSE NULL END $case_else)";
									break;
								case 'MTDEP':
									return "SUM($case_when $colsec montant_depassement $colsecend  $case_else)";
									break;
								case 'MTCPT':
									return "SUM($case_when $colsec case when montant_facture <> 0 OR montant_depassement <> 0 OR montant_non_facture <> 0 then montant_comptabilise $colsecend ELSE NULL END $case_else)";
									break;
								case 'MTCPT0':
									return "SUM($case_when $colsec case when montant_facture <> 0 OR montant_depassement <> 0 OR montant_non_facture <> 0 then montant_comptabilise_0 $colsecend ELSE NULL END $case_else)";
									break;
								case 'MTCPT1':
									return "SUM($case_when $colsec case when montant_facture <> 0 OR montant_depassement <> 0 OR montant_non_facture <> 0 then montant_comptabilise_1 $colsecend ELSE NULL END $case_else)";
									break;
								case 'MTCPT2':
									return "SUM($case_when $colsec case when montant_facture <> 0 OR montant_depassement <> 0 OR montant_non_facture <> 0 then montant_comptabilise_2 $colsecend ELSE NULL END $case_else)";
									break;
								case 'MTCONV':
									return "SUM($case_when $colsec montant_facture $colsecend  $case_else) - SUM($case_when $colsec montant_depassement $colsecend  $case_else)";
									break;
								case 'MMTFAC':
									return "base.cti_division(SUM($case_when $colsec montant_facture $colsecend  $case_else),COUNT(DISTINCT $case_when $colsec v_factures_lignes_h_3.sejour_id  $colsecend   $case_else))";
									break;
								case 'MMTFAC0':
									return "base.cti_division(SUM($case_when $colsec montant_facture_0 $colsecend  $case_else),COUNT(DISTINCT $case_when $colsec CASE WHEN tiers_payant_0_id <> 0 then  v_factures_lignes_h_3.sejour_id $colsecend else 0 end $case_else))";
									break;
								case 'MMTFAC1':
									return "base.cti_division(SUM($case_when $colsec montant_facture_1 $colsecend  $case_else),COUNT(DISTINCT $case_when $colsec CASE WHEN tiers_payant_1_id <> 0 then  v_factures_lignes_h_3.sejour_id $colsecend else 0 end $case_else))";
									break;
								case 'MMTFAC2':
									return "base.cti_division(SUM($case_when $colsec montant_facture_2 $colsecend  $case_else),COUNT(DISTINCT $case_when $colsec CASE WHEN tiers_payant_2_id <> 0 then  v_factures_lignes_h_3.sejour_id $colsecend else 0 end $case_else))";
									break;
                                case 'MTNNFACT':
									return "SUM($case_when $colsec case when montant_non_facture <> 0 then montant_non_facture  $colsecend ELSE NULL END $case_else)";
									break;                                    
                                case 'MTFACVAL':
									return "SUM($case_when $colsec case when montant_facture <> 0 OR montant_depassement <> 0 OR montant_non_facture <> 0 OR montant_facture_actes_inclus_dans_sejour <> 0 then coalesce(montant_facture, 0) + coalesce(montant_non_facture, 0) + coalesce(montant_facture_actes_inclus_dans_sejour, 0) $colsecend ELSE NULL END $case_else)";
									break;
                                default:
                                    return $DEFAULT;
                                    break;
					}

				}
				
				function ACTI_RAPPORT_prefixe($GROUPBY, $DEFAULT="") {
					if (substr($GROUPBY,3,3) == 'CLS') {
						$GROUPBY = substr($GROUPBY,0,6);
					}
					$field = '';
					$field_id = '';
					$field_code = '';
					$field_texte = '';
					switch ($GROUPBY) {
					case '*TAB':
						$field = "*TAB";
						break;
					case '-1':
						$field = "";
						break;
					case 'TSE':
						$field = "type_sejour";
						break;
					case 'TSECLS':
						$field = "type_sejour_section";
						break;
                    case 'FOA':
						$field = "forme_activite";
						break;
					case 'FOACLS':
						$field = "forme_activite_section";
						break;
					case 'FSP':
						$field = "filiere_soin_principale";
						break;
					case 'FSPCLS':
						$field = "filiere_soin_principale_section";
						break;
					case 'MTR':
						$field = "mode_traitement";
						break;
					case 'SER':
						$field = "lieu_reference_service";
						break;
					case 'SERCLS':
						$field = "lieu_reference_service_section";
						break;
					case 'ACT':
						$field = "lieu_reference_activite";
						break;
					case 'ETA':
						$field = "lieu_reference_etage";
						break;
					case 'ETACLS':
						$field = "lieu_reference_etage_section";
						break;
					case 'LIT':
						$field = "lieu_reference_lit";
						break;
					case 'LITCLS':
						$field = "lieu_reference_lit_section";
						break;
					case 'UM':
						$field = "lieu_reference_unite_medicale";
						break;
					case 'UMDCLS':
						$field = "lieu_reference_unite_medicale_section";
						break;
					case 'UF':
						$field = "lieu_reference_unite_fonctionnelle";
						break;
					case 'UFTCLS':
						$field = "lieu_reference_unite_fonctionnelle_section";
						break;
					case 'SPM':
						$field = "medecin_reference_specialite";
						break;
					case 'MED':
						$field = "medecin_reference";
						break;
					case 'MDA':
						$field = "medecin_adm_reference";
						break;
					case 'MDACLS':
						$field = "medecin_adm_reference_section";
						break;
					case 'MCO':
						$field = "mcos";
						break;
					case 'CAS':
						$field = "cas";
						break;
					case 'CMD':
						$field = "cmd";
						break;
					case 'GHS':
						$field = "ghs";
						break;
					case 'GHM':
						$field = "ghm";
						break;
					case 'GHMCLS':
						$field = "ghm_section";
						break;
					case 'GHM5':
						$field = "ghm5";
						break;
					case 'GHMSEV':
						$field = "severite_ghm";
						break;					
                    case 'SEVCTI':
						$field = "severite_cti";
						break;
					case 'PS1':
						$field = "v_sejours_parametres_personnalises_1.parametre_personnalise_1";
						break;
					case 'PS1CLS':
						$field = "v_sejours_parametres_personnalises_1.parametre_personnalise_1_section";
						break;
					case 'PS2':
						$field = "v_sejours_parametres_personnalises_1.parametre_personnalise_2";
						break;
					case 'PS2CLS':
						$field = "v_sejours_parametres_personnalises_1.parametre_personnalise_2_section";
						break;
					
					case 'BUC':
						$field = "budget_cle";
						break;
					case 'BUCCLS':
						$field = "budget_cle_section";
						break;
						
					case 'MCO':
						$field = "mcos";
						break;
					case 'FIN':
						$field = "finess";
						break;
					case 'FINCLS':
						$field = "finess_section";
						break;
					case 'ANNEE':
						$field = "CALC_ANNEE";
						break;
					case 'MOIS':
						$field = "CALC_MOIS";
						break;
					case 'NUMEROJOUR':
						$field = "CALC_NUMEROJOUR";
						break;
					case 'NUMEROMOIS':
						$field = "CALC_NUMEROMOIS";
						break;
					
					default:
						$field = $DEFAULT;
					}
					return $field;
					
					$prefixe = '';
					$groupby = '[GROUPBY]';
					if ($groupby == '-1') {$groupby = '[GROUPBY_2]';}

					$cls6 = substr($groupby, 0 , 6);
					$cls7 = substr($groupby, 6 , 1);

					
				}
				
				function ACTI_RAPPORT_field_id($GROUPBY, $DEFAULT="") {
				
					$prefixe = ACTI_RAPPORT_prefixe($GROUPBY, $DEFAULT="");
					
					if (substr($GROUPBY, 3, 3) == 'CLS' && $prefixe != $DEFAULT) {
						$section = substr($GROUPBY, 6);
						$field = "$prefixe" . "_id[" . $section . "]";
					}
					else {
						switch ($prefixe) {
							case "":
								$field = "0";
								break;
							case "*TAB":
								$field = "-9999999";
								break;
							case "CALC_ANNEE":
								$field = "EXTRACT(YEAR FROM date_reference)";
								break;
							case "CALC_MOIS":
								$field = "EXTRACT(YEAR FROM date_reference) * 100 + EXTRACT(MONTH FROM date_reference)";
								break;
							case "CALC_NUMEROJOUR":
								$field = "EXTRACT(DOW FROM date_reference)";
								break;
							case "CALC_NUMEROMOIS":
								$field = "EXTRACT(MONTH FROM date_reference)";
								break;
							default:
								$field = "$prefixe" . "_id";
						}
					}
					return $field;
				}
				
				function ACTI_RAPPORT_field_code($GROUPBY, $DEFAULT="") {
					
					$prefixe = ACTI_RAPPORT_prefixe($GROUPBY, $DEFAULT="");
					
					if (substr($GROUPBY, 3, 3) == 'CLS' && $prefixe != $DEFAULT) {
						$section = substr($GROUPBY, 6);
						$field = "$prefixe" . "_code[" . $section . "]";
					}
					else {
						switch ($prefixe) {
							case "":
								$field = "''";
								break;
							case "*TAB":
								$field = "' Résumé'";
								break;
							case "CALC_ANNEE":
								$field = "EXTRACT(YEAR FROM date_reference)";
								break;
							case "CALC_MOIS":
								$field = "EXTRACT(YEAR FROM date_reference) * 100 + EXTRACT(MONTH FROM date_reference)";
								break;
							case "CALC_NUMEROJOUR":
								$field = "CASE WHEN EXTRACT(DOW FROM date_reference) > 0 THEN EXTRACT(DOW FROM date_reference) ELSE 7 END";
								break;
							case "CALC_NUMEROMOIS":
								$field = "CASE 	
										WHEN EXTRACT(MONTH FROM date_reference) = 1 THEN '01'  
										WHEN EXTRACT(MONTH FROM date_reference) = 2 THEN '02' 
										WHEN EXTRACT(MONTH FROM date_reference) = 3 THEN '03' 
										WHEN EXTRACT(MONTH FROM date_reference) = 4 THEN '04' 
										WHEN EXTRACT(MONTH FROM date_reference) = 5 THEN '05' 
										WHEN EXTRACT(MONTH FROM date_reference) = 6 THEN '06' 
										WHEN EXTRACT(MONTH FROM date_reference) = 7 THEN '07'  
										WHEN EXTRACT(MONTH FROM date_reference) = 8 THEN '08' 
										WHEN EXTRACT(MONTH FROM date_reference) = 9 THEN '09' 
										WHEN EXTRACT(MONTH FROM date_reference) = 10 THEN '10' 
										WHEN EXTRACT(MONTH FROM date_reference) = 11 THEN '11' 
										WHEN EXTRACT(MONTH FROM date_reference) = 12 THEN '12' 
										ELSE '?'
										END";
								break;
							default:
								$field = "$prefixe" . "_code";
						}
					}
					return $field;
				}
				
				function ACTI_RAPPORT_field_texte($GROUPBY, $DEFAULT="") {
					
					$prefixe = ACTI_RAPPORT_prefixe($GROUPBY, $DEFAULT="");
					
					if (substr($GROUPBY, 3, 3) == 'CLS' && $prefixe != $DEFAULT) {
						$section = substr($GROUPBY, 6);
						$field = "$prefixe" . "_texte[" . $section . "]";
					}
					else {
						switch ($prefixe) {
						case "":
							$field = "''";
							break;
						case "*TAB":
							$field = "'Résumé'";
							break;
						case "medecin_reference":
							$field = "$prefixe" . "_nom_prenom";
							break;
						case "medecin_adm_reference":
							$field = "$prefixe" . "_nom_prenom";
							break;
						case "CALC_ANNEE":
							$field = "EXTRACT(YEAR FROM date_reference)";
							break;
						case "CALC_MOIS":
							$field = "CASE EXTRACT(MONTH FROM date_reference)
									WHEN 01 THEN 'Janvier'  
									WHEN 02 THEN 'Fevrier' 
									WHEN 03 THEN 'Mars' 
									WHEN 04 THEN 'Avril' 
									WHEN 05 THEN 'Mai' 
									WHEN 06 THEN 'Juin' 
									WHEN 07 THEN 'Juillet'  
									WHEN 08 THEN 'Aout' 
									WHEN 09 THEN 'Septembre' 
									WHEN 10 THEN 'Octobre' 
									WHEN 11 THEN 'Novembre' 
									WHEN 12 THEN 'Decembre' 
									ELSE '?'
									END
									|| ' ' || EXTRACT(YEAR FROM date_reference)::text";
							break;
						case "CALC_NUMEROJOUR":
							$field = "CASE 	WHEN EXTRACT(DOW FROM date_reference) = 0 THEN 'Dimanche' 
									WHEN EXTRACT(DOW FROM date_reference) = 1 THEN 'Lundi'  
									WHEN EXTRACT(DOW FROM date_reference) = 2 THEN 'Mardi' 
									WHEN EXTRACT(DOW FROM date_reference) = 3 THEN 'Mercredi' 
									WHEN EXTRACT(DOW FROM date_reference) = 4 THEN 'Jeudi' 
									WHEN EXTRACT(DOW FROM date_reference) = 5 THEN 'Vendredi' 
									WHEN EXTRACT(DOW FROM date_reference) = 6 THEN 'Samedi' 
									ELSE '?'
									END";
							break;
						case "CALC_NUMEROMOIS":
							$field = "CASE 	
									WHEN EXTRACT(MONTH FROM date_reference) = 1 THEN 'Janv'  
									WHEN EXTRACT(MONTH FROM date_reference) = 2 THEN 'Fev' 
									WHEN EXTRACT(MONTH FROM date_reference) = 3 THEN 'Mars' 
									WHEN EXTRACT(MONTH FROM date_reference) = 4 THEN 'Avr' 
									WHEN EXTRACT(MONTH FROM date_reference) = 5 THEN 'Mai' 
									WHEN EXTRACT(MONTH FROM date_reference) = 6 THEN 'Juin' 
									WHEN EXTRACT(MONTH FROM date_reference) = 7 THEN 'Juil'  
									WHEN EXTRACT(MONTH FROM date_reference) = 8 THEN 'Aout' 
									WHEN EXTRACT(MONTH FROM date_reference) = 9 THEN 'Sept' 
									WHEN EXTRACT(MONTH FROM date_reference) = 10 THEN 'Oct' 
									WHEN EXTRACT(MONTH FROM date_reference) = 11 THEN 'Nov' 
									WHEN EXTRACT(MONTH FROM date_reference) = 12 THEN 'Dec' 
									ELSE '?'
									END";
									break;
						default:
							$field = "$prefixe" . "_texte";
						}
					}
					return $field;
				}
				
				function ACTI_RAPPORT_PLACES_prefixe($GROUPBY, $DEFAULT="") {
					if (substr($GROUPBY,3,3) == 'CLS') {
						$GROUPBY = substr($GROUPBY,0,6);
					}
					$field = '';
					$field_id = '';
					$field_code = '';
					$field_texte = '';

					switch ($GROUPBY) {
					case '*TAB':
						$field = "*TAB";
						break;
					case '-1':
						$field = "";
						break;
					case 'TSE':
						$field = "type_sejour";
						break;
					case 'TSECLS':
						$field = "type_sejour_section";
						break;
					case 'ETA':
						$field = "etage";
						break;
					case 'ETACLS':
						$field = "etage_section";
						break;
					case 'SER':
						$field = "service";
						break;
					case 'SERCLS':
						$field = "service_section";
						break;
					case 'UF':
						$field = "uf";
						break;
					case 'UFTCLS':
						$field = "uf_section";
						break;
					case 'UM':
						$field = "um";
						break;
					case 'UMDCLS':
						$field = "um_section";
						break;
					case 'FIN':
						$field = "finess";
						break;
					case 'FINCLS':
						$field = "finess_section";
						break;
					case 'ANNEE':
						$field = "CALC_ANNEE";
						break;
					case 'MOIS':
						$field = "CALC_MOIS";
						break;
					case 'NUMEROMOIS':
						$field = "CALC_NUMEROMOIS";
						break;
					case 'TRIM':
						$field = "CALC_TRIM";
						break;
					case 'JOUR':
						$field = "CALC_JOUR";
						break;
					case 'JOURS':
						$field = "CALC_JOURS";
						break;
					case 'NUMEROTRIM':
						$field = "CALC_NUMEROTRIM";
						break;
					case 'NUMEROJOUR':
						$field = "CALC_NUMEROJOUR";
						break;
					case 'SEMAINEWE':
						$field = "CALC_SEMAINEWE";
						break;
					case 'SEMAINEANNE':
						$field = "CALC_SEMAINEANNE";
						break;
					
					default:
						$field = $DEFAULT;
					}
					return $field;
					
					$prefixe = '';
					$groupby = '[GROUPBY]';
					if ($groupby == '-1') {$groupby = '[GROUPBY_2]';}

					$cls6 = substr($groupby, 0 , 6);
					$cls7 = substr($groupby, 6 , 1);

					
				}
				
				function ACTI_RAPPORT_PLACES_field_id($GROUPBY, $DEFAULT="") {
				
					$prefixe = ACTI_RAPPORT_PLACES_prefixe($GROUPBY, $DEFAULT);
					
					if (substr($GROUPBY, 3, 3) == 'CLS' && $prefixe != $DEFAULT) {
						$section = substr($GROUPBY, 6);
						$field = "$prefixe" . "_id[" . $section . "]";
					}
					else {
						switch ($prefixe) {
							case "":
								$field = "0";
								break;
							case "*TAB":
								$field = "-9999999";
								break;
							case '-111':
								$field = "-111";
								break;
							case "CALC_ANNEE":
								$field = "EXTRACT(YEAR FROM date_reference)";
								break;
							case "CALC_MOIS":
								$field = "EXTRACT(YEAR FROM date_reference) * 100 + EXTRACT(MONTH FROM date_reference)";
								break;
							case 'CALC_NUMEROMOIS':
								$field = "to_char(date_reference, 'MM')";
								break;
							case 'CALC_TRIM':
								$field = "to_char(date_reference, 'YYYYQ')";
								break;
							case 'CALC_NUMEROTRIM':
								$field = "to_char(date_reference, 'Q')";
								break;
							case 'CALC_NUMEROJOUR':
								$field = "date_reference.jour_semaine";
								break;
							case 'CALC_JOUR':
								$field = "to_char(date_reference, 'YYYYMMDD')";
								break;
							case 'CALC_JOURS':
								$field = "to_char(date_reference, 'MMDD')";
								break;
							case 'CALC_SEMAINEWE':
								$field = "to_char(date_reference, 'W')";
								break;
							case 'CALC_SEMAINEANNE':
								$field = "to_char(date_reference, 'WW')";
								break;
							default:
								$field = "$prefixe" . "_id";
						}
					}
					return $field;
				}
				
				function ACTI_RAPPORT_PLACES_field_code($GROUPBY, $DEFAULT="") {
					
					$prefixe = ACTI_RAPPORT_PLACES_prefixe($GROUPBY, $DEFAULT);
					
					if (substr($GROUPBY, 3, 3) == 'CLS' && $prefixe != $DEFAULT) {
						$section = substr($GROUPBY, 6);
						$field = "$prefixe" . "_code[" . $section . "]";
					}
					else {
						switch ($prefixe) {
							case "":
								$field = "''";
								break;
							case "*TAB":
								$field = "' Résumé'";
								break;
							case '-111':
								$field = "-111";
								break;
							case "CALC_ANNEE":
								$field = "EXTRACT(YEAR FROM date_reference)";
								break;
							case "CALC_MOIS":
								$field = "EXTRACT(YEAR FROM date_reference) * 100 + EXTRACT(MONTH FROM date_reference)";
								break;
							case 'CALC_NUMEROMOIS':
								$field = "to_char(date_reference, 'MM')";
								break;
							case 'CALC_TRIM':
								$field = "to_char(date_reference, 'YYYY') ||' T'|| to_char(date_reference, 'Q')  ";
								break;
							case 'CALC_NUMEROTRIM':
								$field = "to_char(date_reference, 'Q')";
								break;
							case 'CALC_NUMEROJOUR':
								$field = "date_reference.jour_semaine::text";
								break;
							case 'CALC_SEMAINEWE':
								$field = "to_char(date_reference, 'W')";
								break;
							case 'CALC_SEMAINEANNE':
								$field = "to_char(date_reference, 'WW')";
								break;
							case 'CALC_JOUR':
								$field = "to_char(date_reference, 'YYYY') ||'-'|| to_char(date_reference, 'MM') ||'-'||to_char(date_reference, 'DD')";
								break;
							case 'CALC_JOURS':
								$field = " to_char(date_reference, 'MM') ||'-'|| to_char(date_reference, 'DD') ";
								break;
							default:
								$field = "$prefixe" . "_code";
						}
					}
					return $field;
				}
				
				function ACTI_RAPPORT_PLACES_field_texte($GROUPBY, $DEFAULT="") {
					
					$prefixe = ACTI_RAPPORT_PLACES_prefixe($GROUPBY, $DEFAULT);
					
					if (substr($GROUPBY, 3, 3) == 'CLS' && $prefixe != $DEFAULT) {
						$section = substr($GROUPBY, 6);
						$field = "$prefixe" . "_texte[" . $section . "]";
					}
					else {
						switch ($prefixe) {
							case "":
								$field = "''";
								break;
							case "*TAB":
								$field = "'Résumé'";
								break;
							case '-111':
								$field = "-111";
								break;
							case "CALC_ANNEE":
								$field = "EXTRACT(YEAR FROM date_reference)";
								break;
							case "CALC_MOIS":
								$field = "CASE EXTRACT(MONTH FROM date_reference)	
										WHEN 01 THEN 'Janvier'  
										WHEN 02 THEN 'Fevrier' 
										WHEN 03 THEN 'Mars' 
										WHEN 04 THEN 'Avril' 
										WHEN 05 THEN 'Mai' 
										WHEN 06 THEN 'Juin' 
										WHEN 07 THEN 'Juillet'  
										WHEN 08 THEN 'Aout' 
										WHEN 09 THEN 'Septembre' 
										WHEN 10 THEN 'Octobre' 
										WHEN 11 THEN 'Novembre' 
										WHEN 12 THEN 'Decembre' 
										ELSE '?'
										END
										|| ' ' || EXTRACT('YEAR' FROM date_reference)::text";
								break;
							case 'CALC_NUMEROMOIS':
								$field = "CASE date_part('month',date_reference)
										WHEN 01 THEN 'Janvier'  
										WHEN 02 THEN 'Fevrier' 
										WHEN 03 THEN 'Mars' 
										WHEN 04 THEN 'Avril' 
										WHEN 05 THEN 'Mai' 
										WHEN 06 THEN 'Juin' 
										WHEN 07 THEN 'Juillet'  
										WHEN 08 THEN 'Aout' 
										WHEN 09 THEN 'Septembre' 
										WHEN 10 THEN 'Octobre' 
										WHEN 11 THEN 'Novembre' 
										WHEN 12 THEN 'Decembre' 
										ELSE '?'
										END";
								break;
							case 'CALC_TRIM':
								$field = "date_part('year',date_reference) ||'-'|| 
								CASE to_char(date_reference, 'Q')
										WHEN 1 THEN 'Trimestre 1'  
										WHEN 2 THEN 'Trimestre 2' 
										WHEN 3 THEN 'Trimestre 3' 
										WHEN 4 THEN 'Trimestre 4'
										ELSE '?'
										END";
								break;
							case 'CALC_NUMEROTRIM':
								$field = "CASE to_char(date_reference, 'Q')
										WHEN 1 THEN 'Trimestre 1'  
										WHEN 2 THEN 'Trimestre 2' 
										WHEN 3 THEN 'Trimestre 3' 
										WHEN 4 THEN 'Trimestre 4'
										ELSE '?'
										END";
								break;
							case 'CALC_NUMEROJOUR':
								$field = "CASE p_calendrier.jour_semaine
										WHEN 1 THEN 'Lundi'  
										WHEN 2 THEN 'Mardi' 
										WHEN 3 THEN 'Mercredi' 
										WHEN 4 THEN 'Jeudi'
										WHEN 5 THEN 'Vendredi'
										WHEN 6 THEN 'Samedi'
										WHEN 7 THEN 'Dimanche'
										ELSE '?'
										END";
								break;
							case 'CALC_JOUR':
								$field = "base.cti_to_char(date_reference, 'FF')";
								break;
							case 'CALC_JOURS':
								$field = "base.cti_to_char(date_reference, 'DD') ||' '||
								CASE date_part('month',date_reference)
										WHEN 01 THEN 'Janvier'  
										WHEN 02 THEN 'Fevrier' 
										WHEN 03 THEN 'Mars' 
										WHEN 04 THEN 'Avril' 
										WHEN 05 THEN 'Mai' 
										WHEN 06 THEN 'Juin' 
										WHEN 07 THEN 'Juillet'  
										WHEN 08 THEN 'Aout' 
										WHEN 09 THEN 'Septembre' 
										WHEN 10 THEN 'Octobre' 
										WHEN 11 THEN 'Novembre' 
										WHEN 12 THEN 'Decembre' 
										ELSE '?'
										END
								
								";
								break;

							case 'CALC_SEMAINEANNE':
								$field = " 'Semaine '||' '|| to_char(date_reference, 'WW')

										";
								break;
							case 'CALC_SEMAINEWE':
								$field = "CASE to_char(date_reference, 'W')
										WHEN 1 THEN 'Semaine 1'  
										WHEN 2 THEN 'Semaine 2' 
										WHEN 3 THEN 'Semaine 3' 
										WHEN 4 THEN 'Semaine 4'
										WHEN 5 THEN 'Semaine 5'
										ELSE '?'
										END";
								break;
							default:
								$field = "$prefixe" . "_texte";
						}
					}
					return $field;
				}
				
				
				
				
			
				function ACTI_RAPPORT_BUDGET_prefixe($GROUPBY, $DEFAULT="") {
					if (substr($GROUPBY,3,3) == 'CLS') {
						$GROUPBY = substr($GROUPBY,0,6);
					}
					$field = '';
					$field_id = '';
					$field_code = '';
					$field_texte = '';

					switch ($GROUPBY) {
					case '*TAB':
						$field = "*TAB";
						break;
					case '-1':
						$field = "";
						break;
						
					case 'BUC':
						$field = "budget_cle";
						break;
					case 'BUCCLS':
						$field = "budget_cle_section";
						break;
					
					case 'ANNEE':
						$field = "CALC_ANNEE";
						break;
					case 'MOIS':
						$field = "CALC_MOIS";
						break;
					
					default:
						$field = $DEFAULT;
					}
					return $field;
					
					$prefixe = '';
					$groupby = '[GROUPBY]';
					if ($groupby == '-1') {$groupby = '[GROUPBY_2]';}

					$cls6 = substr($groupby, 0 , 6);
					$cls7 = substr($groupby, 6 , 1);

					
				}
				
				function ACTI_RAPPORT_BUDGET_field_id($GROUPBY, $DEFAULT="") {
				
					$prefixe = ACTI_RAPPORT_BUDGET_prefixe($GROUPBY, $DEFAULT);
					
					if (substr($GROUPBY, 3, 3) == 'CLS' && $prefixe != $DEFAULT) {
						$section = substr($GROUPBY, 6);
						$field = "$prefixe" . "_id[" . $section . "]";
					}
					else {
						switch ($prefixe) {
							case "":
								$field = "0";
								break;
							case "*TAB":
								$field = "-9999999";
								break;
							case '-111':
								$field = "-111";
								break;
							case "CALC_ANNEE":
								$field = "EXTRACT(YEAR FROM date_reference)";
								break;
							case "CALC_MOIS":
								$field = "EXTRACT(YEAR FROM date_reference) * 100 + EXTRACT(MONTH FROM date_reference)";
								break;
							default:
								$field = "$prefixe" . "_id";
						}
					}
					return $field;
				}
				
				function ACTI_RAPPORT_BUDGET_field_code($GROUPBY, $DEFAULT="") {
					
					$prefixe = ACTI_RAPPORT_BUDGET_prefixe($GROUPBY, $DEFAULT);
					
					if (substr($GROUPBY, 3, 3) == 'CLS' && $prefixe != $DEFAULT) {
						$section = substr($GROUPBY, 6);
						$field = "$prefixe" . "_code[" . $section . "]";
					}
					else {
						switch ($prefixe) {
							case "":
								$field = "''";
								break;
							case "*TAB":
								$field = "' Résumé'";
								break;
							case '-111':
								$field = "-111";
								break;
							case "CALC_ANNEE":
								$field = "EXTRACT(YEAR FROM date_reference)";
								break;
							case "CALC_MOIS":
								$field = "EXTRACT(YEAR FROM date_reference) * 100 + EXTRACT(MONTH FROM date_reference)";
								break;
							default:
								$field = "$prefixe" . "_code";
						}
					}
					return $field;
				}
				
				function ACTI_RAPPORT_BUDGET_field_texte($GROUPBY, $DEFAULT="") {
					
					$prefixe = ACTI_RAPPORT_BUDGET_prefixe($GROUPBY, $DEFAULT);
					
					if (substr($GROUPBY, 3, 3) == 'CLS' && $prefixe != $DEFAULT) {
						$section = substr($GROUPBY, 6);
						$field = "$prefixe" . "_texte[" . $section . "]";
					}
					else {
						switch ($prefixe) {
							case "":
								$field = "''";
								break;
							case "*TAB":
								$field = "'Résumé'";
								break;
							case '-111':
								$field = "-111";
								break;
							case "CALC_ANNEE":
								$field = "EXTRACT(YEAR FROM date_reference)";
								break;
							case "CALC_MOIS":
								$field = "CASE EXTRACT(MONTH FROM date_reference)	
										WHEN 01 THEN 'Janvier'  
										WHEN 02 THEN 'Fevrier' 
										WHEN 03 THEN 'Mars' 
										WHEN 04 THEN 'Avril' 
										WHEN 05 THEN 'Mai' 
										WHEN 06 THEN 'Juin' 
										WHEN 07 THEN 'Juillet'  
										WHEN 08 THEN 'Aout' 
										WHEN 09 THEN 'Septembre' 
										WHEN 10 THEN 'Octobre' 
										WHEN 11 THEN 'Novembre' 
										WHEN 12 THEN 'Decembre' 
										ELSE '?'
										END
										|| ' ' || EXTRACT('YEAR' FROM date_reference)::text";
								break;
							default:
								$field = "$prefixe" . "_texte";
						}
					}
					return $field;
				}
				
				function ACTI_ANALYSE_TT_field_prefixe($GROUPBY, $DEFAULT=""){
					if (substr($GROUPBY,3,3) == 'CLS') {
						$GROUPBY = substr($GROUPBY,0,6);
					}
					$field = '';
					$field_id = '';
					$field_code = '';
					$field_texte = '';
					switch ($GROUPBY) {
					case '*TAB':
						$field = "*TAB";
						break;
					case '-1':
						$field = "";
						break;
					case 'ANNEE':
						$field = "CALC_ANNEE";
						break;
					case 'NUMEROMOIS':
						$field = "CALC_NUMEROMOIS";
						break;
					case 'CALC_MOIS':
						$field = "CALC_MOIS";
						break;
					case 'TRIM':
						$field = "CALC_TRIM";
						break;
					case 'JOUR':
						$field = "CALC_JOUR";
						break;
					case 'JOURS':
						$field = "CALC_JOURS";
						break;
					case 'NUMEROTRIM':
						$field = "CALC_NUMEROTRIM";
						break;
					case 'NUMEROJOUR':
						$field = "CALC_NUMEROJOUR";
						break;
					case 'SEMAINEWE':
						$field = "CALC_SEMAINEWE";
						break;
					case 'SEMAINEANNE':
						$field = "CALC_SEMAINEANNE";
						break;
						
					default:
						$field = $DEFAULT;
					}
					return $field;
					
					$prefixe = '';
					$groupby = '[GROUPBY]';
					if ($groupby == '-1') {$groupby = '[GROUPBY_2]';}

					$cls6 = substr($groupby, 0 , 6);
					$cls7 = substr($groupby, 6 , 1);
				
				}
				
				function ACTI_ANALYSE_TT_field_id($GROUPBY, $DEFAULT=""){
				$prefixe = ACTI_STANDARD_prefixe($GROUPBY, $DEFAULT, "ANALYSE_TT");
					if ($prefixe == "") {
						$prefixe = ACTI_ETATDOSSIER_prefixe($GROUPBY, $DEFAULT="");
					}
					
					if (substr($GROUPBY, 3, 3) == 'CLS' && $prefixe != $DEFAULT) {
						$section = substr($GROUPBY, 6);
						$field = "$prefixe" . "_id[" . $section . "]";
					}
					else {
						switch ($prefixe) {
							case "":
								$field = "0";
								break;
							case "*TAB":
								$field = "-9999999";
								break;
							case 'CALC_ANNEE':
								$field = "to_char(p_calendrier.date, 'YYYY')";
								break;
							case 'CALC_NUMEROMOIS':
								$field = "to_char(p_calendrier.date, 'MM')";
								break;							
							case 'CALC_MOIS':
								$field = "to_char(p_calendrier.date, 'YYYYMM')";
								break;
							case 'CALC_TRIM':
								$field = "to_char(p_calendrier.date, 'YYYYQ')";
								break;
							case 'CALC_NUMEROTRIM':
								$field = "to_char(p_calendrier.date, 'Q')";
								break;
							case 'CALC_NUMEROJOUR':
								$field = "p_calendrier.jour_semaine";
								break;
							case 'CALC_JOUR':
								$field = "to_char(p_calendrier.date, 'YYYYMMDD')";
								break;
							case 'CALC_JOURS':
								$field = "to_char(p_calendrier.date, 'MMDD')";
								break;
							case 'CALC_SEMAINEWE':
								$field = "to_char(p_calendrier.date, 'W')";
								break;
							case 'CALC_SEMAINEANNE':
								$field = "to_char(p_calendrier.date, 'WW')";
								break;
							
							default:
								$field = "$prefixe" . "_id";
						}
					}
					return $field;
				
				}
				function ACTI_ANALYSE_TT_field_code($GROUPBY, $DEFAULT=""){
				$prefixe = ACTI_STANDARD_prefixe($GROUPBY, $DEFAULT, "ANALYSE_TT");
					if ($prefixe == "") {
						$prefixe = ACTI_ETATDOSSIER_prefixe($GROUPBY, $DEFAULT="");
					}
					
					if (substr($GROUPBY, 3, 3) == 'CLS' && $prefixe != $DEFAULT) {
						$section = substr($GROUPBY, 6);
						$field = "$prefixe" . "_code[" . $section . "]";
					}
					else {
						switch ($prefixe) {
							case "":
								$field = "''";
								break;
							case "*TAB":
								$field = "' Résumé'";
								break;
							case 'CALC_ANNEE':
								$field = "to_char(p_calendrier.date, 'YYYY')";
								break;
							case 'CALC_NUMEROMOIS':
								$field = "to_char(p_calendrier.date, 'MM')";
								break;
							case 'CALC_TRIM':
								$field = "to_char(p_calendrier.date, 'YYYY') ||' T'|| to_char(p_calendrier.date, 'Q')  ";
								break;
							case 'CALC_NUMEROTRIM':
								$field = "to_char(p_calendrier.date, 'Q')";
								break;
							case 'CALC_NUMEROJOUR':
								$field = "p_calendrier.jour_semaine::text";
								break;
							case 'CALC_SEMAINEWE':
								$field = "to_char(p_calendrier.date, 'W')";
								break;
							case 'CALC_SEMAINEANNE':
								$field = "to_char(p_calendrier.date, 'WW')";
								break;
							case 'CALC_JOUR':
								$field = "to_char(p_calendrier.date, 'YYYY') ||'-'|| to_char(p_calendrier.date, 'MM') ||'-'||to_char(p_calendrier.date, 'DD')";
								break;
							case 'CALC_JOURS':
								$field = " to_char(p_calendrier.date, 'MM') ||'-'|| to_char(p_calendrier.date, 'DD') ";
								break;
							case "CALC_MOIS":
								$field = "to_char(p_calendrier.date, 'YYYYMM')";
								break;
							case 'v_sejours_1.code_sexe':
								$field = "v_sejours_1.code_sexe";
								break;	
							default:
								$field = "$prefixe" . "_code";
						}
					}
					return $field;
				
				}
				function ACTI_ANALYSE_TT_field_texte($GROUPBY, $DEFAULT=""){
				$prefixe = ACTI_STANDARD_prefixe($GROUPBY, $DEFAULT, "ANALYSE_TT");
					if ($prefixe == "") {
						$prefixe = ACTI_ETATDOSSIER_prefixe($GROUPBY, $DEFAULT="");
					}
					
					if (substr($GROUPBY, 3, 3) == 'CLS' && $prefixe != $DEFAULT) {
						$section = substr($GROUPBY, 6);
						$field = "$prefixe" . "_texte[" . $section . "]";
					}
					else {
						switch ($prefixe) {
							case "":
								$field = "''";
								break;
							case "*TAB":
								$field = "'Résumé'";
								break;
							case "medecin_adm_sejour":
								$field = "$prefixe" . "_nom_prenom";
								break;
							case "medecin_sejour":
								$field = "$prefixe" . "_nom_prenom";
								break;
							case "CALC_ANNEE":
								$field = "to_char(p_calendrier.date, 'YYYY')";
								break;
							case 'CALC_NUMEROMOIS':
								$field = "CASE date_part('month',p_calendrier.date)
										WHEN 01 THEN 'Janvier'  
										WHEN 02 THEN 'Fevrier' 
										WHEN 03 THEN 'Mars' 
										WHEN 04 THEN 'Avril' 
										WHEN 05 THEN 'Mai' 
										WHEN 06 THEN 'Juin' 
										WHEN 07 THEN 'Juillet'  
										WHEN 08 THEN 'Aout' 
										WHEN 09 THEN 'Septembre' 
										WHEN 10 THEN 'Octobre' 
										WHEN 11 THEN 'Novembre' 
										WHEN 12 THEN 'Decembre' 
										ELSE '?'
										END";
								break;
							case 'CALC_TRIM':
								$field = "date_part('year',p_calendrier.date) ||'-'|| 
								CASE to_char(p_calendrier.date, 'Q')
										WHEN 1 THEN 'Trimestre 1'  
										WHEN 2 THEN 'Trimestre 2' 
										WHEN 3 THEN 'Trimestre 3' 
										WHEN 4 THEN 'Trimestre 4'
										ELSE '?'
										END";
								break;
							case 'CALC_NUMEROTRIM':
								$field = "CASE to_char(p_calendrier.date, 'Q')
										WHEN 1 THEN 'Trimestre 1'  
										WHEN 2 THEN 'Trimestre 2' 
										WHEN 3 THEN 'Trimestre 3' 
										WHEN 4 THEN 'Trimestre 4'
										ELSE '?'
										END";
								break;
							case 'CALC_NUMEROJOUR':
								$field = "CASE p_calendrier.jour_semaine
										WHEN 1 THEN 'Lundi'  
										WHEN 2 THEN 'Mardi' 
										WHEN 3 THEN 'Mercredi' 
										WHEN 4 THEN 'Jeudi'
										WHEN 5 THEN 'Vendredi'
										WHEN 6 THEN 'Samedi'
										WHEN 7 THEN 'Dimanche'
										ELSE '?'
										END";
								break;
							case 'CALC_JOUR':
								$field = "base.cti_to_char(p_calendrier.date, 'FF')";
								break;
							case 'CALC_JOURS':
								$field = "base.cti_to_char(p_calendrier.date, 'DD') ||' '||
								CASE date_part('month',p_calendrier.date)
										WHEN 01 THEN 'Janvier'  
										WHEN 02 THEN 'Fevrier' 
										WHEN 03 THEN 'Mars' 
										WHEN 04 THEN 'Avril' 
										WHEN 05 THEN 'Mai' 
										WHEN 06 THEN 'Juin' 
										WHEN 07 THEN 'Juillet'  
										WHEN 08 THEN 'Aout' 
										WHEN 09 THEN 'Septembre' 
										WHEN 10 THEN 'Octobre' 
										WHEN 11 THEN 'Novembre' 
										WHEN 12 THEN 'Decembre' 
										ELSE '?'
										END
								
								";
								break;

							case 'CALC_SEMAINEANNE':
								$field = " 'Semaine '||' '|| to_char(p_calendrier.date, 'WW')

										";
								break;
							case 'CALC_SEMAINEWE':
								$field = "CASE to_char(p_calendrier.date, 'W')
										WHEN 1 THEN 'Semaine 1'  
										WHEN 2 THEN 'Semaine 2' 
										WHEN 3 THEN 'Semaine 3' 
										WHEN 4 THEN 'Semaine 4'
										WHEN 5 THEN 'Semaine 5'
										ELSE '?'
										END";
								break;
							case "CALC_MOIS":
								$field = "CASE date_part('month',p_calendrier.date)
										WHEN 01 THEN 'Janvier'  
										WHEN 02 THEN 'Fevrier' 
										WHEN 03 THEN 'Mars' 
										WHEN 04 THEN 'Avril' 
										WHEN 05 THEN 'Mai' 
										WHEN 06 THEN 'Juin' 
										WHEN 07 THEN 'Juillet'  
										WHEN 08 THEN 'Aout' 
										WHEN 09 THEN 'Septembre' 
										WHEN 10 THEN 'Octobre' 
										WHEN 11 THEN 'Novembre' 
										WHEN 12 THEN 'Decembre' 
										ELSE '?'
										END
										|| ' ' || date_part('year',p_calendrier.date)";
								break;
							case 'v_sejours_1.code_sexe':
								$field = "v_sejours_1.code_sexe";
								break;
							default:
								$field = "$prefixe" . "_texte";
						}
					}
					return $field;
				
				}
			
			]]>
			</value>

	</COMPONENT>

	<!-- COMPOSANTS DE REQUÊTES SQL POUR LA DATA DES VUES -->

	<!-- REQUÊTE SQL POUR VUE modules\activite\settings\views\occupation\ACTIOCCPREADM.XML -->
	
	<COMPONENT name="QUERIES_PREADM_ANZ" label="Query pour analyse pré-admissions">
		<QUERIES>
			<QUERY>
				<SQL optimizer="V_SEJOURS_X" optimizer2="V_MOUVEMENTS_SEJOUR_X">
					<select><![CDATA[ 
							
						CTISELECT_TREE 
							WORKTABLE{actioccpreadm_data} 
							GROUPBY1{[VIEW.GROUPBY_OID_FIELD],, [VIEW.GROUPBY_COD_FIELD],, [VIEW.GROUPBY_TXT_FIELD]} 
							GROUPBY1MODE{[GROUPBY_TAB]} 
							GROUPBY2{[VIEW.GROUPBY_2_OID_FIELD],, [VIEW.GROUPBY_2_COD_FIELD],, [VIEW.GROUPBY_2_TXT_FIELD]} 
							GROUPBY3{[VIEW.GROUPBY_3_OID_FIELD],, [VIEW.GROUPBY_3_COD_FIELD],, [VIEW.GROUPBY_3_TXT_FIELD]} 
							SIGNIFDATA{[VIEW.ACTIVITE_SIGNIFICATIVE_DATA],, [ACTIVITE_SIGNIFICATIVE_MODE],, [ACTIVITE_SIGNIFICATIVE_NUMBER]} 
						INDICATORS{ 
							COUNT(DISTINCT v_mouvements_sejour_2.no_sejour),,
							SUM(nb_preadmission_validee),,
							SUM(nb_preadmission_validee_j1),,
							SUM(nb_preadmission_validee_j2),,
						}
					FROM #V_SEJOURS_X#
						JOIN #V_MOUVEMENTS_SEJOUR_X# ON v_mouvements_sejour_2.no_sejour = v_sejours_1.no_sejour 
					WHERE
						v_mouvements_sejour_2.date BETWEEN '[VIEW.PERIODE]' AND '[VIEW.TOPERIODE]'
						[VIEW.SEJOURS_SELECT] [VIEW.PASSAGES_SELECT]
						[VIEW.MOUVEMENTS_SELECT] [VIEW.JOURS_SELECT] [VIEW.PATIENTS_SELECT]	 

					]]></select>
					<FIELDS>
						<INSERT name="CTISELECT_TREE_FIELDS" />
						<FIELD name="NBSEJ" /><!-- 					1	Nombre de séjours -->
						<FIELD name="NBPREADM" /><!-- 				2	Nombre de séjours avec préadmission validée au global -->
						<FIELD name="NBPREADMJ1" /><!-- 			3	Nombre de séjours avec préadmission validée à J-1 -->
						<FIELD name="NBPREADMJ2" /><!-- 			4	Nombre de séjours avec préadmission validée à J-2 -->
					</FIELDS>
				</SQL>
			</QUERY>
		</QUERIES>
	</COMPONENT>
	
	<COMPONENT name="QUERIES_PREADM_JSF" label="Query pour justificatif pré-admissions">
		<QUERIES>
			<QUERY label="">
				<SQL optimizer="V_SEJOURS_X" optimizer2="V_MOUVEMENTS_SEJOUR_X">
					<select><![CDATA[
						(
						SELECT 
							v_mouvements_sejour_2.no_sejour, 
							p_patients.no_patient, 
							p_patients.nom || ' ' || p_patients.prenom, 
							v_sejours_1.sexe_texte_court as code_sexe,
							p_patients.date_naissance,
							v_sejours_1.age as age,
							(medecin_mouvement_nom || '  ' ||medecin_mouvement_prenom) as medecin_mouvement ,
							v_sejours_1.date_entree, 
							CASE WHEN v_sejours_1.date_sortie <> '2099-12-31' THEN to_char(v_sejours_1.date_sortie,'YYYY-MM-DD') ELSE '' END::text as date_sortie,
							p_sejours_preadmission.date_validation_preadmission,
							v_mouvements_sejour_2.nb_preadmission_validee_j1,
							v_mouvements_sejour_2.nb_preadmission_validee_j2,
							(p_sejours_preadmission.date_entree - date_validation_preadmission)
						FROM #V_SEJOURS_X#
						JOIN #V_MOUVEMENTS_SEJOUR_X# ON v_mouvements_sejour_2.no_sejour = v_sejours_1.no_sejour 
						JOIN activite.p_sejours_preadmission ON p_sejours_preadmission.no_sejour = v_sejours_1.no_sejour
						JOIN activite.p_patients ON v_sejours_1.no_patient = p_patients.no_patient
						WHERE 
							v_mouvements_sejour_2.date BETWEEN '[VIEW.PERIODE]' AND '[VIEW.TOPERIODE]'
							[VIEW.SEJOURS_SELECT] [VIEW.PASSAGES_SELECT]
							[VIEW.MOUVEMENTS_SELECT] [VIEW.JOURS_SELECT] [VIEW.PATIENTS_SELECT]							
						GROUP BY 
						1,2,3,4,5,6,7,8,9,10,11,12,13
						ORDER BY
							1	
						)					
						UNION ALL
						(
						SELECT 
							'-9999999', 
							COUNT(DISTINCT v_mouvements_sejour_2.no_sejour)::text || ' séjours, ' || COUNT(DISTINCT v_sejours_1.no_patient)::text || ' patients',
							'',
							'',
							null,
							null,
							'',
							null,
							null,
							null,
							SUM(nb_preadmission_validee_j1),
							SUM(nb_preadmission_validee_j2),
							null
						FROM #V_SEJOURS_X#
						JOIN #V_MOUVEMENTS_SEJOUR_X# ON v_mouvements_sejour_2.no_sejour = v_sejours_1.no_sejour 
						JOIN activite.p_sejours_preadmission ON p_sejours_preadmission.no_sejour = v_sejours_1.no_sejour
						JOIN activite.p_patients ON v_sejours_1.no_patient = p_patients.no_patient
						WHERE 
							v_mouvements_sejour_2.date BETWEEN '[VIEW.PERIODE]' AND '[VIEW.TOPERIODE]'
							[VIEW.SEJOURS_SELECT] [VIEW.PASSAGES_SELECT]
							[VIEW.MOUVEMENTS_SELECT] [VIEW.JOURS_SELECT] [VIEW.PATIENTS_SELECT]	
						GROUP BY 1
						)										
					]]></select>
					<FIELDS>
						<FIELD name="SEJ" />
						<FIELD name="NPAT"  />
						<FIELD name="NOM" ifHideNames="Non autorisé" />
						<FIELD name="SEXE" />
						<FIELD name="DNAT" />
						<FIELD name="AGE" />
						<FIELD name="MED" />
						<FIELD name="DENT" />
						<FIELD name="DSOR" />
						<FIELD name="DPREADM" />
						<FIELD name="PREADMJ1" />
						<FIELD name="PREADMJ2" />
						<FIELD name="ECARTPREADM" />
					</FIELDS>
				</SQL>
			</QUERY>
		</QUERIES>		
	</COMPONENT>

	<!-- REQUÊTE SQL POUR VUE modules\activite\settings\views\occupation\annulation\ACTIANNULA.XML -->
	
	<COMPONENT name="QUERIES_ANNULATIONS_ANZ" label="Query pour analyse annulations">
		<QUERIES>
			<QUERY>
				<SQL optimizer="V_SEJOURS_ANNULES_X" optimizer2="V_MOUVEMENTS_SEJOUR_X">
					<select><![CDATA[ 
							
						CTISELECT_TREE 
							WORKTABLE{actioccannul_data} 
							GROUPBY1{[VIEW.GROUPBY_OID_FIELD],, [VIEW.GROUPBY_COD_FIELD],, [VIEW.GROUPBY_TXT_FIELD]} 
							GROUPBY1MODE{[GROUPBY_TAB]} 
							GROUPBY2{[VIEW.GROUPBY_2_OID_FIELD],, [VIEW.GROUPBY_2_COD_FIELD],, [VIEW.GROUPBY_2_TXT_FIELD]} 
							GROUPBY3{[VIEW.GROUPBY_3_OID_FIELD],, [VIEW.GROUPBY_3_COD_FIELD],, [VIEW.GROUPBY_3_TXT_FIELD]} 
							SIGNIFDATA{[VIEW.ACTIVITE_SIGNIFICATIVE_DATA],, [ACTIVITE_SIGNIFICATIVE_MODE],, [ACTIVITE_SIGNIFICATIVE_NUMBER]} 
						INDICATORS{ 
							COUNT(DISTINCT v_sejours_1.no_sejour),,
							SUM(is_annulation_j0),,
							COUNT(DISTINCT CASE WHEN v_sejours_1.etat_sejour_code = 'A' AND is_annulation_j0 = 1 THEN v_sejours_1.no_sejour ELSE NULL END),,
							COUNT(DISTINCT CASE WHEN v_sejours_1.etat_sejour_code = 'R' AND is_annulation_j0 = 1 THEN v_sejours_1.no_sejour ELSE NULL END),,
							COUNT(DISTINCT CASE WHEN v_sejours_1.etat_sejour_code = 'C' AND is_annulation_j0 = 1 THEN v_sejours_1.no_sejour ELSE NULL END),,
						}
					FROM #V_SEJOURS_ANNULES_X#
						JOIN #V_MOUVEMENTS_SEJOUR_X# ON v_mouvements_sejour_2.no_sejour = v_sejours_1.no_sejour 
					WHERE 
						v_sejours_1.date_entree BETWEEN '[VIEW.PERIODE]' AND '[VIEW.TOPERIODE]'
						[VIEW.SEJOURS_SELECT] [VIEW.PASSAGES_SELECT]
						[VIEW.MOUVEMENTS_SELECT] [VIEW.JOURS_SELECT] [VIEW.PATIENTS_SELECT]	 

					]]></select>
					<FIELDS>
						<INSERT name="CTISELECT_TREE_FIELDS" />
						<FIELD name="NBSEJ" /><!-- 					1	Nombre de séjours annulés au global-->
						<FIELD name="NBANNULJ0" /><!-- 				2	Nombre de séjours annulés à J0 -->
						<FIELD name="NBANNUL" /><!-- 				3	Nombre de séjours avec état annulé -->
						<FIELD name="NBRECUSE" /><!-- 				4	Nombre de séjours avec état récusé -->
						<FIELD name="NBSUSPENDU" /><!-- 			5	Nombre de séjours avec état suspensdu -->
					</FIELDS>
				</SQL>
			</QUERY>
		</QUERIES>
	</COMPONENT>
	<COMPONENT name="QUERIES_ANNULATIONS_JSF" label="Query pour justificatif annulations">
		<QUERIES>
			<QUERY label="">
				<SQL optimizer="V_SEJOURS_ANNULES_X" optimizer2="V_MOUVEMENTS_SEJOUR_X">
					<select><![CDATA[
						(
						SELECT 
							v_mouvements_sejour_2.no_sejour, 
							p_patients.no_patient, 
							p_patients.nom || ' ' || p_patients.prenom, 
							v_sejours_1.sexe_texte_court as code_sexe,
							p_patients.date_naissance,
							v_sejours_1.age as age,
							(medecin_mouvement_nom || '  ' ||medecin_mouvement_prenom) as medecin_mouvement ,
							v_sejours_1.date_entree, 
							v_sejours_1.etat_sejour_texte,
							v_sejours_1.is_annulation_j0,
							v_sejours_1.date_etat,
							(v_sejours_1.date_entree - date(v_sejours_1.date_etat))
						FROM #V_SEJOURS_ANNULES_X#
						JOIN #V_MOUVEMENTS_SEJOUR_X# ON v_mouvements_sejour_2.no_sejour = v_sejours_1.no_sejour 
						JOIN activite.p_patients ON v_sejours_1.no_patient = p_patients.no_patient
						WHERE 
							v_sejours_1.date_entree BETWEEN '[VIEW.PERIODE]' AND '[VIEW.TOPERIODE]'
							[VIEW.SEJOURS_SELECT] [VIEW.PASSAGES_SELECT]
							[VIEW.MOUVEMENTS_SELECT] [VIEW.JOURS_SELECT] [VIEW.PATIENTS_SELECT]							
						GROUP BY 
						1,2,3,4,5,6,7,8,9,10,11,12
						ORDER BY
							1	
						)					
						UNION ALL
						(
						SELECT 
							'-9999999', 
							COUNT(DISTINCT v_mouvements_sejour_2.no_sejour)::text || ' séjours, ' || COUNT(DISTINCT v_sejours_1.no_patient)::text || ' patients',
							'',
							'',
							null,
							null,
							'',
							null,
							null,
							SUM(is_annulation_j0),
							null,
							null
						FROM #V_SEJOURS_ANNULES_X#
						JOIN #V_MOUVEMENTS_SEJOUR_X# ON v_mouvements_sejour_2.no_sejour = v_sejours_1.no_sejour 
						JOIN activite.p_patients ON v_sejours_1.no_patient = p_patients.no_patient
						WHERE 
							v_sejours_1.date_entree BETWEEN '[VIEW.PERIODE]' AND '[VIEW.TOPERIODE]'
							[VIEW.SEJOURS_SELECT] [VIEW.PASSAGES_SELECT]
							[VIEW.MOUVEMENTS_SELECT] [VIEW.JOURS_SELECT] [VIEW.PATIENTS_SELECT]	
						GROUP BY 1
						)										
					]]></select>
					<FIELDS>
						<FIELD name="SEJ" />
						<FIELD name="NPAT"  />
						<FIELD name="NOM" ifHideNames="Non autorisé" />
						<FIELD name="SEXE" />
						<FIELD name="DNAT" />
						<FIELD name="AGE" />
						<FIELD name="MED" />
						<FIELD name="DENT" />
						<FIELD name="ETATSEJ" />
						<FIELD name="ANNULJ0" />
						<FIELD name="DATETAT" />
						<FIELD name="ECARTETAT" />
					</FIELDS>
				</SQL>
			</QUERY>
		</QUERIES>		
	</COMPONENT>
	<!-- COMPOSANTS DE PRESENTATION DES VUES  -->

	<!-- PRESENTATION ANALYSE PREADMISSIONS  -->
	<COMPONENT name="PRESENTATION_PREADM_ANZ" label="Présentation pour analyse pré-admissions">
		<PRESENTATION>
			<VIEWLINKS>
				<VIEWLINK label="Liste des séjours" shortLabel="Séjours" view="ACTIADMJSF.XML" componentName="OCC_BASE_VIEWLINK" component3Name="STANDARD_BASE_VIEWLINK">
					<ARG name="DATA">
						<value><![CDATA[ 
							
							var s:String = '';
							switch (COLUMN.NAME) {
								case 'ENT' :	s = 'ENT'; 		break;
								case 'ENTM' :	s = 'ENTMUT';	break;
								case 'SOR' :	s = 'SOR';		break;
								case 'SORM' :	s = 'SORMUT';	break;
								case 'JRN' :	s = 'JRN';		break;
								case 'JRNM' :	s = 'JRN';		break;
								case 'NCP' :	s = 'CP';		break;
								case 'EXT' :	s = 'EXT';		break;
								case 'EXTM' :	s = 'EXT';		break;
								case 'AMB' :	s = 'AMB';		break;
								case 'AMBM' :	s = 'AMB';		break;
								case 'URG' :	s = 'URG';		break;
								case 'URGM' :	s = 'URG';		break;
								case 'BB' :		s = 'BB';		break;
								case 'BBM' :	s = 'BB';		break;
								case 'SEA' :	s = 'SEA';		break;
								case 'SEAM' :	s = 'SEA';		break;
								case 'JRNHON' :	s = 'JRNHON';	break;
								default :		s = '-1';		break;
							}
							return s;
							
						]]></value>
					</ARG>
				</VIEWLINK>
			</VIEWLINKS>
			<ONGLET excelLabel="Préadmissions" label="Préadmissions" multiTab="true" multiTabBreakField="TABD" multiTabBreakLabelField="TABDL" multiTabBreakLonglabelField="TABDLL">
				<CHART 
					title="Décomposition des préadmissions par nombre d'entrées décroissantes" 
					type="columnChart" 
					maxItems="6" 
					maxItemsSortOn="NBSEJ" 
					maxItemsSortSeq="D" 
					sortField="NBSEJ" 
					sortSeq="D" 
					visible="true">
					<CATEGORY field="TXT" type="Char"/>
					<SERIE field="TX_PREADM_J2" displayName="Taux de préadmissions validées J-2"/>
					<SERIE field="TX_PREADM_J1" displayName="Taux de préadmissions validées J-1"/>
					<SERIE field="TX_PREADM_TOT" displayName="Taux de préadmissions validées"/>
				</CHART>
				<DATAGRID title="" total="true" showOthers="true" headerHeight="48" selectRowInRows="= ROW.OID == '-9999997'" otherRowInRows="= ROW.OID == '-9999998'" totalRowInRows="= ROW.OID == '-9999999'" 
						sortable="= SELECT.GROUPBY_3 == '-1' &amp;&amp; (SELECT.GROUPBY_2 == '-1' || SELECT.GROUPBY_TAB == 'TAB')">
					<INSERT name="DATAGRID_MULTITAB_STYLES" />
					<COLUMN dataField="OID" width="80" type="Char" visible="false" headerText="Oid" />
					<COLUMN dataField="COD" width="90" type="Char" visible="true" headerText="Code" textAlign="left" otherFunction="text" totalFunction="text">
						<INSERT name="COLUMN_COD_MULTITAB_STYLES" />
					</COLUMN>
					<COLUMN dataField="TXT" minWidth="200" type="Char" headerText="SELECT.GROUPBY_LABEL" headerTextCalc="true" textAlign="left" totalFunction="text" totalComplement="TOTAL" otherFunction="text" otherComplement="Autres" />
					<COLUMN dataField="NBSEJ" width="100" type="Number" outputFormat="#" headerText="Total séjours&#xD;période" textAlign="right" totalFunction="sum" otherFunction="sum"
					description="Nombre de séjours entrés sur la période d'analyse" />
					<COLUMN dataField="NBPREADM" width="100" type="Number" outputFormat="#" headerText="Total&#xD;préadmissions&#xD;période" textAlign="right" totalFunction="sum" otherFunction="sum"
					description="Nombre de séjours avec une préadmission validée" />
					<COLUMN dataField="TX_PREADM_TOT" type="Number" width="100" outputFormat="#,0%" headerText="Taux&#xD;préadmission&#xD;total" textAlign="right" totalComplement="" calc="true"
						description="Taux de séjours avec préadmission validée par rapport au nombre de séjours total sur la période analysée">
						<CALC formula="ROW.NBPREADM / ROW.NBSEJ * 100" />
					</COLUMN>
					<COLUMN dataField="NBPREADMJ1" width="100" type="Number" outputFormat="#" headerText="Préadmissions&#xD;J-1 à 14h" textAlign="right" totalFunction="sum" otherFunction="sum"
					description="Nombre de séjours avec une préadmission validée à J-1 avant 14h00" />
					<COLUMN dataField="TX_PREADM_J1" type="Number" width="100" outputFormat="#,0%" headerText="Taux&#xD;préadmission&#xD;J-1 à 14h" textAlign="right" totalComplement="" calc="true"
						description="Taux de séjours avec préadmission validée à J-1 avant 14h00 par rapport au nombre de séjours total sur la période analysée">
						<CALC formula="ROW.NBPREADMJ1 / ROW.NBSEJ * 100" />
					</COLUMN>
					<COLUMN dataField="NBPREADMJ2" width="100" type="Number" outputFormat="#" headerText="Préadmissions&#xD;J-2 à 18h" textAlign="right" totalFunction="sum" otherFunction="sum"
					description="Nombre de séjours avec une préadmission validée à J-2 avant 18h00" />
					<COLUMN dataField="TX_PREADM_J2" type="Number" width="100" outputFormat="#,0%" headerText="Taux&#xD;préadmission&#xD;J-2 à 18h" textAlign="right" totalComplement="" calc="true"
						description="Taux de séjours avec préadmission validée à J-2 avant 18h00 par rapport au nombre de séjours total sur la période analysée">
						<CALC formula="ROW.NBPREADMJ2 / ROW.NBSEJ * 100" />
					</COLUMN>
				</DATAGRID>
			</ONGLET>
		</PRESENTATION>
	</COMPONENT>
	<!-- COMPOSANT DE PRESENTATION POUR LA VUE JUSTIFICATIVE DES PREADMISSIONS -->

	<COMPONENT name="PRESENTATION_PREADM_JSF" label="Présentation pour justificatif pré-admissions">
		<PRESENTATION>
			<VIEWLINKS>
				<VIEWLINK label="Détail séjour" shortLabel="Détail séjour" view="ACTI000020.XML">
					<ARG name="SEJOUR" value="ROW.SEJ" />
				</VIEWLINK>
			</VIEWLINKS>
			<ONGLET excelLabel="Liste séjours" label="Liste séjours">
				<DATAGRID title="" total="true" key="SEJ" headerHeight="48" totalRowInRows="= ROW.SEJ == '-9999999'">
					<COLUMN dataField="SEJ" frozen="left" width="100" type="Char" headerText="No séjour" textAlign="left" otherFunction="text" totalFunction="text" totalComplement="TOTAL" />
					<COLUMN dataField="NPAT" frozen="left" type="Char" width="100" headerText="N° Patient" textAlign="left" totalFunction="text" totalComplement="*ROW" />				
					<COLUMN dataField="NOM" frozen="left" type="Char" minWidth="150" headerText="Nom" textAlign="left" totalFunction="text" totalComplement="*ROW" />
					<COLUMN dataField="SEXE" width="40" type="Char" headerText="Sexe" textAlign="right" totalFunction="text">
						<CELLSTYLE name="cellIndicator" value="femme, 12,right middle , 0xEB76B1" condition="ROW.SEXE == 'F'" /> 
						<CELLSTYLE name="cellIndicator" value="homme, 12,right middle , 0x75a0eb " condition="ROW.SEXE == 'M'" />
						<CELLSTYLE name="cellIndicator" value="rectangle, 10, left middle, 0x666666" condition="ROW.SEXE != 'M' &amp;&amp; ROW.SEXE != 'F'" /> 
					</COLUMN>
					<COLUMN dataField="DNAT" width="60" type="Date" inputFormat="AAAA-MM-JJ" outputFormat="DD/MM/YY" headerText="Date naissance" textAlign="right" totalFunction="text" />
					<COLUMN dataField="AGE" width="35" type="Number" outputFormat="= if (ROW.SEJ == '-9999999') { return '#,0';} else { return '#';}" headerText="Age" textAlign="right" totalFunction="text" />
					<COLUMN dataField="MED" type="Char" minWidth="80" maxWidth="150" fixed="false" headerText="Médecin" textAlign="left" totalFunction="text" />
					<COLUMN dataField="DENT" width="70" type="Date" inputFormat="AAAA-MM-JJ" outputFormat="DD/MM/YY" headerText="Date entrée ETS" textAlign="right" totalFunction="text" />
					<COLUMN dataField="DSOR" width="70" type="Date" inputFormat="AAAA-MM-JJ" outputFormat="DD/MM/YY" headerText="Date sortie  ETS" textAlign="right" totalFunction="text" />
					<COLUMN dataField="DPREADM" width="70" type="Date" inputFormat="AAAA-MM-JJ" outputFormat="DD/MM/YY" headerText="Date validation préadmission" textAlign="right" totalFunction="text" />
					<COLUMN dataField="PREADMJ1" width="70" type="Number"  headerText="Validation&#xD;J-1 à 14h" textAlign="right" totalFunction="text" 
						description="Si la valeur est égale à 1, la préadmission pour ce séjour était validée à J-1 avant 14h00" />
					<COLUMN dataField="PREADMJ2" width="70" type="Number" headerText="Validation&#xD;J-2 à 18h" textAlign="right" totalFunction="text"
						description="Si la valeur est égale à 1, la préadmission pour ce séjour était validée à J-2 avant 18h00" />
					<COLUMN dataField="ECARTPREADM" width="80" type="Date" headerText="Ecart&#xD;entrée&#xD;préadmission" textAlign="right" totalFunction="text" outputFormat="#"
						description="Ecart en nombre de jours et d'heures entre la date d'entrée du séjour et la date de validation de la préadmission" />
				</DATAGRID>
			</ONGLET>
		</PRESENTATION>
	</COMPONENT>

	<!-- PRESENTATION ANALYSE ANNULATIONS  -->
	<COMPONENT name="PRESENTATION_ANNULATIONS_ANZ" label="Présentation pour analyse annulations">
		<PRESENTATION>
			<VIEWLINKS>
				<VIEWLINK label="Liste des séjours" shortLabel="Séjours" view="ACTIANNJSF.XML" componentName="OCC_BASE_VIEWLINK" component3Name="STANDARD_BASE_VIEWLINK">
					<ARG name="DATA">
						<value><![CDATA[ 
							
							var s:String = '';
							switch (COLUMN.NAME) {
								case 'ENT' :	s = 'ENT'; 		break;
								case 'ENTM' :	s = 'ENTMUT';	break;
								case 'SOR' :	s = 'SOR';		break;
								case 'SORM' :	s = 'SORMUT';	break;
								case 'JRN' :	s = 'JRN';		break;
								case 'JRNM' :	s = 'JRN';		break;
								case 'NCP' :	s = 'CP';		break;
								case 'EXT' :	s = 'EXT';		break;
								case 'EXTM' :	s = 'EXT';		break;
								case 'AMB' :	s = 'AMB';		break;
								case 'AMBM' :	s = 'AMB';		break;
								case 'URG' :	s = 'URG';		break;
								case 'URGM' :	s = 'URG';		break;
								case 'BB' :		s = 'BB';		break;
								case 'BBM' :	s = 'BB';		break;
								case 'SEA' :	s = 'SEA';		break;
								case 'SEAM' :	s = 'SEA';		break;
								case 'JRNHON' :	s = 'JRNHON';	break;
								default :		s = '-1';		break;
							}
							return s;
							
						]]></value>
					</ARG>
				</VIEWLINK>
			</VIEWLINKS>
			<ONGLET excelLabel="Annulations" label="Annulations" multiTab="true" multiTabBreakField="TABD" multiTabBreakLabelField="TABDL" multiTabBreakLonglabelField="TABDLL">
				<CHART 
					title="Décomposition du nombre d'annulations" 
					type="columnChart" 
					maxItems="6" 
					maxItemsSortOn="NBSEJ" 
					maxItemsSortSeq="D" 
					sortField="NBSEJ" 
					sortSeq="D" 
					visible="true">
					<CATEGORY field="TXT" type="Char"/>
					<SERIE field="NBSEJ" displayName="Nombre d'annulations"/>
					<SERIE field="NBANNULJ0" displayName="Nombre d'annulations à J-0"/>
				</CHART>
				<DATAGRID title="" total="true" showOthers="true" headerHeight="48" selectRowInRows="= ROW.OID == '-9999997'" otherRowInRows="= ROW.OID == '-9999998'" totalRowInRows="= ROW.OID == '-9999999'" 
						sortable="= SELECT.GROUPBY_3 == '-1' &amp;&amp; (SELECT.GROUPBY_2 == '-1' || SELECT.GROUPBY_TAB == 'TAB')">
					<INSERT name="DATAGRID_MULTITAB_STYLES" />
					<COLUMN dataField="OID" width="80" type="Char" visible="false" headerText="Oid" />
					<COLUMN dataField="COD" width="90" type="Char" visible="true" headerText="Code" textAlign="left" otherFunction="text" totalFunction="text">
						<INSERT name="COLUMN_COD_MULTITAB_STYLES" />
					</COLUMN>
					<COLUMN dataField="TXT" minWidth="200" type="Char" headerText="SELECT.GROUPBY_LABEL" headerTextCalc="true" textAlign="left" totalFunction="text" totalComplement="TOTAL" otherFunction="text" otherComplement="Autres" />
					<COLUMN dataField="NBSEJ" width="100" type="Number" outputFormat="#" headerText="Total&#xD;annulations&#xD;période" textAlign="right" totalFunction="sum" otherFunction="sum"
					description="Nombre de séjours annulés sur la période d'analyse" />
					<COLUMN dataField="NBANNULJ0" width="100" type="Number" outputFormat="#" headerText="Total&#xD;annulations&#xD;à J-0" textAlign="right" totalFunction="sum" otherFunction="sum"
					description="Nombre de séjours annulés à J-0" />
					<COLUMN dataField="TX_NBANNULJ0" type="Number" width="100" outputFormat="#,0%" headerText="Taux&#xD;annulations&#xD;à J-0" textAlign="right" totalComplement="" calc="true"
						description="Taux de séjours avec annulation à J-0 par rapport au nombre de séjours annulés au global sur la période analysée">
						<CALC formula="ROW.NBANNULJ0 / ROW.NBSEJ * 100" />
					</COLUMN>
					<COLUMN dataField="NBANNUL" width="100" type="Number" outputFormat="#" headerText="Total&#xD;séjours&#xD;annulés J-0" textAlign="right" totalFunction="sum" otherFunction="sum"
					description="Nombre de séjours avec l'éat annulé" />
					<COLUMN dataField="TX_NBANNUL" type="Number" width="100" outputFormat="#,0%" headerText="Taux&#xD;annulations J-0" textAlign="right" totalComplement="" calc="true"
						description="Taux de séjours avec l'état annulé par rapport au nombre de séjours annulés à J-0 sur la période analysée">
						<CALC formula="ROW.NBANNUL / ROW.NBANNULJ0 * 100" />
					</COLUMN>
					<COLUMN dataField="NBRECUSE" width="100" type="Number" outputFormat="#" headerText="Total&#xD;séjours&#xD;récusés J-0" textAlign="right" totalFunction="sum" otherFunction="sum"
					description="Nombre de séjours avec l'éat récusé" />
					<COLUMN dataField="TX_NBRECUSE" type="Number" width="100" outputFormat="#,0%" headerText="Taux&#xD;séjours&#xD;récusés J-0" textAlign="right" totalComplement="" calc="true"
						description="Taux de séjours avec l'état récusé par rapport au nombre de séjours annulés à J-0 sur la période analysée">
						<CALC formula="ROW.NBRECUSE / ROW.NBANNULJ0 * 100" />
					</COLUMN>
					<COLUMN dataField="NBSUSPENDU" width="100" type="Number" outputFormat="#" headerText="Total&#xD;séjours&#xD;suspendus J-0" textAlign="right" totalFunction="sum" otherFunction="sum"
					description="Nombre de séjours avec l'état suspendu" />
					<COLUMN dataField="TX_NBSUSPENDU" type="Number" width="100" outputFormat="#,0%" headerText="Taux&#xD;séjours&#xD;suspendus J-0" textAlign="right" totalComplement="" calc="true"
						description="Taux de séjours avec l'état suspendu par rapport au nombre de séjours annulés à J-0 sur la période analysée">
						<CALC formula="ROW.NBSUSPENDU / ROW.NBANNULJ0 * 100" />
					</COLUMN>
				</DATAGRID>
			</ONGLET>
		</PRESENTATION>
	</COMPONENT>
	<!-- COMPOSANT DE PRESENTATION POUR LA VUE JUSTIFICATIVE DES PREADMISSIONS -->

	<COMPONENT name="PRESENTATION_ANNULATIONS_JSF" label="Présentation pour justificatif annulations">
		<PRESENTATION>
			<ONGLET excelLabel="Liste séjours" label="Liste séjours">
				<DATAGRID title="" total="true" key="SEJ" headerHeight="48" totalRowInRows="= ROW.SEJ == '-9999999'">
					<COLUMN dataField="SEJ" frozen="left" width="100" type="Char" headerText="No séjour" textAlign="left" otherFunction="text" totalFunction="text" totalComplement="TOTAL" />
					<COLUMN dataField="NPAT" frozen="left" type="Char" width="100" headerText="N° Patient" textAlign="left" totalFunction="text" totalComplement="*ROW" />				
					<COLUMN dataField="NOM" frozen="left" type="Char" minWidth="150" headerText="Nom" textAlign="left" totalFunction="text" totalComplement="*ROW" />
					<COLUMN dataField="SEXE" width="40" type="Char" headerText="Sexe" textAlign="right" totalFunction="text">
						<CELLSTYLE name="cellIndicator" value="femme, 12,right middle , 0xEB76B1" condition="ROW.SEXE == 'F'" /> 
						<CELLSTYLE name="cellIndicator" value="homme, 12,right middle , 0x75a0eb " condition="ROW.SEXE == 'M'" />
						<CELLSTYLE name="cellIndicator" value="rectangle, 10, left middle, 0x666666" condition="ROW.SEXE != 'M' &amp;&amp; ROW.SEXE != 'F'" /> 
					</COLUMN>
					<COLUMN dataField="DNAT" width="60" type="Date" inputFormat="AAAA-MM-JJ" outputFormat="DD/MM/YY" headerText="Date naissance" textAlign="right" totalFunction="text" />
					<COLUMN dataField="AGE" width="35" type="Number" outputFormat="= if (ROW.SEJ == '-9999999') { return '#,0';} else { return '#';}" headerText="Age" textAlign="right" totalFunction="text" />
					<COLUMN dataField="MED" type="Char" minWidth="80" maxWidth="150" fixed="false" headerText="Médecin" textAlign="left" totalFunction="text" />
					<COLUMN dataField="DENT" width="70" type="Date" inputFormat="AAAA-MM-JJ" outputFormat="DD/MM/YY" headerText="Date entrée ETS" textAlign="right" totalFunction="text" />
					<COLUMN dataField="ETATSEJ" type="Char" width="90" fixed="false" headerText="Etat séjour" textAlign="left" totalFunction="text" />
					<COLUMN dataField="ANNULJ0" width="70" type="Number"  headerText="Annulation&#xD;J-0" textAlign="right" totalFunction="text" 
						description="Si la valeur est égale à 1, l'annulation pour ce séjour a été faite à J-0" />
					<COLUMN dataField="DATETAT" width="70" type="Date" inputFormat="AAAA-MM-JJ" outputFormat="DD/MM/YY" headerText="Date annulation" textAlign="right" totalFunction="text" />
					<COLUMN dataField="ECARTETAT" width="70" type="Number" headerText="Ecart&#xD;entrée&#xD;annulation" textAlign="right" totalFunction="text" outputFormat="#"
						description="Ecart en nombre de jours entre la date d'entrée du séjour et la date de changement d'état du séjour" />
				</DATAGRID>
			</ONGLET>
		</PRESENTATION>
	</COMPONENT>

	<!-- COMPOSANT DE DEFINITIONS DES PROPRIETES DE DATES DE BASE  -->
	<COMPONENT name="ACTI_OCC_BASE_DATE_PROPERTIES" label="Initialisation des propriétés de dates">
		<VIEWPROPERTIES	>
			<PROPERTY dataLink="DATEVIEWPROPERTIES" nameField="name" valueField="value" />
		</VIEWPROPERTIES>
		<QUERIES>
			<QUERY type="propertiesLink" name="DATEVIEWPROPERTIES" forSelections="false">
				<SQL>
					<select><![CDATA[ 
						
							SELECT 
								'TOPERIODE', 
								to_char(COALESCE(MAX(date),'[TOPERIODE]'::date), 'YYYY-MM-DD')
							FROM 
								activite.p_mouvements_sejour 
							WHERE 
								date BETWEEN '[PERIODE]' AND '[TOPERIODE]' 
						UNION 
							SELECT 
								'PERIODE', 
								to_char(COALESCE(MIN(date),'[PERIODE]'::date), 'YYYY-MM-DD')
							FROM 
								activite.p_mouvements_sejour 
							WHERE 
								date BETWEEN '[PERIODE]' AND '[TOPERIODE]' 
						UNION ALL
							SELECT 'ANA_CROI_PERIODE', to_char(greatest(	date_trunc('year', '[TOPERIODE]'::date) - INTERVAL  '3 year', 
															(SELECT date_trunc('year', min(date_comptable)) FROM activite.p_chiffrier_comptable)
														)::date, 'YYYY-MM-DD')
						UNION ALL
							SELECT 'ANA_CROI_TOPERIODE', 	to_char(
										least(	date_trunc('year', '[TOPERIODE]'::date) - interval '1 day' + interval '1 year',
													'[TOPERIODE]'::date)
										, 'YYYY-MM-DD')
						UNION ALL
							SELECT 'COMP_PERIODE', to_char(
										greatest(	date_trunc('year', '[TOPERIODE]'::date),
													date_trunc('month', '[PERIODE]'::date))
										, 'YYYY-MM-DD')
						UNION ALL
							SELECT 'COMP_PERIODE_D', to_char(
										greatest(	date_trunc('year', '[TOPERIODE]'::date) - interval '1 year',
													date_trunc('month', '[PERIODE]'::date) - interval '1 year')
										, 'YYYY-MM-DD')
						UNION ALL
							SELECT 'COMP_TOPERIODE_D', 	to_char(
										least(	date_trunc('year', '[TOPERIODE]'::date) - interval '1 day',
													'[TOPERIODE]'::date - interval '1 year')
										, 'YYYY-MM-DD')
										
					]]></select>
					<FIELDS>
						<FIELD name="name" />
						<FIELD name="value" />
					</FIELDS>
				</SQL>
			</QUERY>	
		</QUERIES>		
	</COMPONENT>
</COMPONENTS>
