<?xml version="1.0" encoding="ISO-8859-1"?>
<ROOT>
	
	
	<NODE name="INIT" label="INITIALISATIONS">
	
		
		
	</NODE>

	<NODE name="ECRITURES" label="RECUPERATION ECRITURES">
			
		<NODE label="Ecritures">
			<sqlcmd><![CDATA[
			
				SELECT base.cti_copy_table('dbname=[DBNAME] port=[DBPORT] host=[DBHOST] user=[DBUSER] password=[DBPASSWORD]', '
					SELECT p_historique_ecritures.*
					FROM compta.p_historique_ecritures
					JOIN compta.t_sites ON site_id = t_sites.oid
					WHERE t_sites.code = ANY (string_to_array(''[ETAB]'','' ''))
					', 'temp e_historique_ecritures'
				);
				
				SELECT base.cti_disable_index('compta', 'i_historique_ecritures_1');
				SELECT base.cti_disable_index('compta', 'i_historique_ecritures_2');
				SELECT base.cti_disable_index('compta', 'i_historique_ecritures_3');
				SELECT base.cti_disable_index('compta', 'i_historique_ecritures_4');
				SELECT base.cti_disable_index('compta', 'i_historique_ecritures_5');
				SELECT base.cti_disable_index('compta', 'i_historique_ecritures_6');
				SELECT base.cti_disable_index('compta', 'i_historique_ecritures_7');
				SELECT base.cti_disable_index('compta', 'i_historique_ecritures_8');
				SELECT base.cti_disable_index('compta', 'i_historique_ecritures_9');
				SELECT base.cti_disable_index('compta', 'i_historique_ecritures_10');
				SELECT base.cti_disable_index('compta', 'i_historique_ecritures_11');
				SELECT base.cti_disable_index('compta', 'i_historique_ecritures_12');
				SELECT base.cti_disable_index('compta', 'i_historique_ecritures_13');


				TRUNCATE compta.p_historique_ecritures;
				TRUNCATE compta.p_historique_ecritures_total;
				
				INSERT INTO compta.p_historique_ecritures(
					compte_id,
					date_ecriture,
					mois_comptable,
					montant_credit,
					montant_debit,
					journal_id,
					section_analytique_id,
					clinique_honoraire,
					exercice_comptable,
					type_compta_id,
					compte_extra_id,
					comptabilisee,
					fin_exercice,
					ajustement,
					cle_originale,
					compte_contrepartie_id,
					texte,
					date_facture_fournisseur,
					piece,
					dossier,
					date_echeance,
					journal_paiement_id,
					mode_paiement_id,
					numero_cheque,
					site_id,
					partenaire_id,
					inter_site,
					identifiant_operation,
					ecriture_consolidee,
					section_analytique_2_id,
					section_analytique_3_id,
					section_analytique_4_id,
					section_analytique_5_id,
					section_analytique_6_id,
					is_budget,
					compte_budget_id,
					section_analytique_7_id,
					section_analytique_8_id,
					section_analytique_9_id
				    )
				SELECT 
					compte_id,
					date_ecriture,
					mois_comptable,
					montant_credit,
					montant_debit,
					journal_id,
					section_analytique_id,
					clinique_honoraire,
					exercice_comptable,
					type_compta_id,
					compte_extra_id,
					comptabilisee,
					fin_exercice,
					ajustement,
					cle_originale,
					compte_contrepartie_id,
					texte,
					date_facture_fournisseur,
					piece,
					dossier,
					date_echeance,
					journal_paiement_id,
					mode_paiement_id,
					numero_cheque,
					site_id,
					partenaire_id,
					inter_site,
					identifiant_operation,
					ecriture_consolidee,
					section_analytique_2_id,
					section_analytique_3_id,
					section_analytique_4_id,
					section_analytique_5_id,
					section_analytique_6_id,
					is_budget,
					compte_budget_id,
					section_analytique_7_id,
					section_analytique_8_id,
					section_analytique_9_id
				FROM e_historique_ecritures
				;
				
				SELECT base.cti_enable_index('compta', 'i_historique_ecritures_1');				
				SELECT base.cti_enable_index('compta', 'i_historique_ecritures_2');
				SELECT base.cti_enable_index('compta', 'i_historique_ecritures_3');
				SELECT base.cti_enable_index('compta', 'i_historique_ecritures_4');
				SELECT base.cti_enable_index('compta', 'i_historique_ecritures_5');
				SELECT base.cti_enable_index('compta', 'i_historique_ecritures_6');
				SELECT base.cti_enable_index('compta', 'i_historique_ecritures_7');
				SELECT base.cti_enable_index('compta', 'i_historique_ecritures_8');
				SELECT base.cti_enable_index('compta', 'i_historique_ecritures_9');
				SELECT base.cti_enable_index('compta', 'i_historique_ecritures_10');
				SELECT base.cti_enable_index('compta', 'i_historique_ecritures_11');
				SELECT base.cti_enable_index('compta', 'i_historique_ecritures_12');
				SELECT base.cti_enable_index('compta', 'i_historique_ecritures_13');
				


				SELECT base.cti_verify_sequences('compta');


				
				
				
				
			]]></sqlcmd>
		</NODE>
		
	</NODE>
	
	<NODE name="POST" label="TRAITEMENTS COMPLEMENTAIRES">
		<NODE label="Séquences">
			<sqlcmd><![CDATA[

				SELECT base.cti_verify_sequences('compta');
		
			]]></sqlcmd>
		</NODE>	
	</NODE>	

	<NODE name="CHIFFRIER" label="CREATION DU CHIFFRIER">
		<NODE label="Chiffrier">
			<sqlcmd><![CDATA[
				

				SELECT base.cti_copy_table('dbname=[DBNAME] port=[DBPORT] host=[DBHOST] user=[DBUSER] password=[DBPASSWORD]', '
					SELECT p_chiffrier_comptable.*
					FROM compta.p_chiffrier_comptable
					JOIN compta.t_sites ON site_id = t_sites.oid
					WHERE t_sites.code = ANY (string_to_array(''[ETAB]'','' ''))
					', 'temp e_chiffrier_comptable'
				);

				TRUNCATE compta.p_chiffrier_comptable;
				
				INSERT INTO compta.p_chiffrier_comptable(
					mois_comptable, 
					site_id, 
					clinique_honoraire, 
					montant_debit, 
					montant_credit, 
					provider_id
					)
				SELECT 
					mois_comptable, 
					site_id, 
					clinique_honoraire, 
					montant_debit, 
					montant_credit, 
					provider_id
				FROM e_chiffrier_comptable
				;

			]]></sqlcmd>
		</NODE>
		
	</NODE>
	
	<NODE name="PARAM" label="RECUPERATION DES PARAMETRES">
		<NODE label="Sites">
			<sqlcmd><![CDATA[
			
				SELECT base.cti_copy_table('dbname=[DBNAME] port=[DBPORT] host=[DBHOST] user=[DBUSER] password=[DBPASSWORD]', '
					SELECT *
					FROM compta.t_sites
					WHERE code = ANY (string_to_array(''[ETAB]'','' '')) OR oid = 0
					', 'temp e_sites'
				);

				INSERT INTO compta.t_sites(
					 oid,
					 code,
					 texte,
					 clinique_honoraire,
					 code_original
					 )
				SELECT 
					oid,
					 code,
					 texte,
					 clinique_honoraire,
					 code_original
				FROM e_sites
				WHERE oid NOT IN (SELECT oid FROM compta.t_sites)
				;
			]]></sqlcmd>
		</NODE>
		
		<NODE label="Types de compta">
			<sqlcmd><![CDATA[
			
				SELECT base.cti_copy_table('dbname=[DBNAME] port=[DBPORT] host=[DBHOST] user=[DBUSER] password=[DBPASSWORD]', '
					SELECT *
					FROM compta.t_types_compta
					', 'temp e_types_compta'
				);

				INSERT INTO compta.t_types_compta(
					 oid,
					 code,
					 texte,
					 specialite,
					 code_original
					 )
				SELECT 
					oid,
					 code,
					 texte,
					 specialite,
					 code_original
				FROM e_types_compta
				WHERE oid NOT IN (SELECT oid FROM compta.t_types_compta)
				;
				]]></sqlcmd>
		</NODE>
		
		<NODE label="Journaux">
			<sqlcmd><![CDATA[
			
				SELECT base.cti_copy_table('dbname=[DBNAME] port=[DBPORT] host=[DBHOST] user=[DBUSER] password=[DBPASSWORD]', '
					SELECT *
					FROM compta.t_journaux
					', 'temp e_journaux'
				);


				INSERT INTO compta.t_journaux(
					 oid,
					 code,
					 texte,
					 clinique_honoraire,
					 a_nouveaux,
					 code_original
					 )
				SELECT 
					oid,
					 code,
					 texte,
					 clinique_honoraire,
					 a_nouveaux,
					 code_original
				FROM e_journaux
				WHERE oid NOT IN (SELECT oid FROM compta.t_journaux)
				;
			]]></sqlcmd>
		</NODE>
		
		<NODE label="Modes de paiement">
			<sqlcmd><![CDATA[
			
				SELECT base.cti_copy_table('dbname=[DBNAME] port=[DBPORT] host=[DBHOST] user=[DBUSER] password=[DBPASSWORD]', '
					SELECT *
					FROM compta.t_mode_paiement
					', 'temp e_mode_paiement'
				);

				INSERT INTO compta.t_mode_paiement(
					 oid,
					 code,
					 texte,
					 code_original
					 )
				SELECT 
					oid,
					 code,
					 texte,
					 code_original
				FROM e_mode_paiement
				WHERE oid NOT IN (SELECT oid FROM compta.t_mode_paiement)
				;
			]]></sqlcmd>
		</NODE>
		
		<NODE label="Partenaires">
			<sqlcmd><![CDATA[
			
				SELECT base.cti_copy_table('dbname=[DBNAME] port=[DBPORT] host=[DBHOST] user=[DBUSER] password=[DBPASSWORD]', '
					SELECT *
					FROM compta.t_partenaires
					', 'temp e_partenaires'
				);

				INSERT INTO compta.t_partenaires(
					 oid,
					 code,
					 texte,
					 intra_groupe,
					 code_original
					 )
				SELECT 
					oid,
					 code,
					 texte,
					 intra_groupe,
					 code_original
				FROM e_partenaires
				WHERE oid NOT IN (SELECT oid FROM compta.t_partenaires)
				;
			]]></sqlcmd>
		</NODE>
		
		<NODE label="Sections analytiques">
			<sqlcmd><![CDATA[
			
				SELECT base.cti_copy_table('dbname=[DBNAME] port=[DBPORT] host=[DBHOST] user=[DBUSER] password=[DBPASSWORD]', '
					SELECT *
					FROM compta.t_sections_analytiques
					', 'temp e_sections_analytiques'
				);

				INSERT INTO compta.t_sections_analytiques(
					 oid,
					 code,
					 texte,
					 code_original
					 )
				SELECT 
					oid,
					 code,
					 texte,
					 code_original
				FROM e_sections_analytiques
				WHERE oid NOT IN (SELECT oid FROM compta.t_sections_analytiques)
				;
			]]></sqlcmd>
		</NODE>
		
		<NODE label="Comptes">
			<sqlcmd><![CDATA[
			
				SELECT base.cti_copy_table('dbname=[DBNAME] port=[DBPORT] host=[DBHOST] user=[DBUSER] password=[DBPASSWORD]', '
					SELECT *
					FROM compta.t_classes_comptes
					', 'temp e_classes_comptes'
				);

				INSERT INTO compta.t_classes_comptes(
					 oid,
					 code,
					 texte,
					 clinique,
					 honoraire
					 )
				SELECT 
					oid,
					 code,
					 texte,
					 clinique,
					 honoraire
				FROM e_classes_comptes
				WHERE oid NOT IN (SELECT oid FROM compta.t_classes_comptes)
				;
				
				SELECT base.cti_copy_table('dbname=[DBNAME] port=[DBPORT] host=[DBHOST] user=[DBUSER] password=[DBPASSWORD]', '
					SELECT *
					FROM compta.t_comptes
					', 'temp e_comptes'
				);

				TRUNCATE compta.t_comptes;
				
				INSERT INTO compta.t_comptes(
					type_compta_id,
					numero,
					texte,
					oid,
					compte_general_id,
					clinique_honoraire,
					banque,
					etat,
					classe_1_id,
					classe_2_id,
					classe_3_id,
					classe_4_id,
					classe_5_id,
					classe_6_id,
					solde_initial,
					collectif,
					type_compta_extra_id,
					numero_extra,
					texte_extra,
					partenaire_id,
					inter_site,
					sens,
					compte_nonsigne_id,
					compte_nonsigne_numero
				 )
				SELECT 
					type_compta_id,
					numero,
					texte,
					oid,
					compte_general_id,
					clinique_honoraire,
					banque,
					etat,
					classe_1_id,
					classe_2_id,
					classe_3_id,
					classe_4_id,
					classe_5_id,
					classe_6_id,
					solde_initial,
					collectif,
					type_compta_extra_id,
					numero_extra,
					texte_extra,
					partenaire_id,
					inter_site,
					sens,
					compte_nonsigne_id,
					compte_nonsigne_numero
				FROM e_comptes
				;

			
			
			]]></sqlcmd>
		</NODE>
		
		<NODE label="Poles">
			<sqlcmd><![CDATA[ 
			
				SELECT base.cti_copy_table('dbname=[DBNAME] port=[DBPORT] host=[DBHOST] user=[DBUSER] password=[DBPASSWORD]', ' 
					SELECT * 
					FROM base.t_pole 
					', 'temp e_pole' 
				); 
				
				SELECT base.cti_copy_table('dbname=[DBNAME] port=[DBPORT] host=[DBHOST] user=[DBUSER] password=[DBPASSWORD]', ' 
					SELECT * 
					FROM compta.t_pole_rule
					', 'temp e_pole_rule' 
				); 
				
				TRUNCATE base.t_pole; 
				
				INSERT INTO base.t_pole(
					oid, 
					code, 
					texte, 
					texte_court, 
					section_id, 
					section_code, 
					section_texte
				) 
				SELECT 
					oid, 
					code, 
					texte, 
					texte_court, 
					section_id, 
					section_code, 
					section_texte 
				FROM e_pole 
				; 
				
				TRUNCATE compta.t_pole; 
				
				INSERT INTO compta.t_pole(
					oid, 
					code, 
					texte, 
					texte_court, 
					section_id, 
					section_code, 
					section_texte
				) 
				SELECT 
					oid, 
					code, 
					texte, 
					texte_court, 
					section_id, 
					section_code, 
					section_texte 
				FROM e_pole 
				; 
				
				TRUNCATE compta.t_pole_rule; 
				
				INSERT INTO compta.t_pole_rule(
					oid, 
					code, 
					texte, 
					pole_id, 
					priorite, 
					liste_compte, 
					liste_sauf_compte, 
					liste_journal, 
					liste_sauf_journal, 
					liste_section_analytique, 
					liste_sauf_section_analytique, 
					liste_finess, 
					liste_site, 
					from_rule_id, 
					liste_exercice, 
					liste_mois_comptable, 
					special_calc, 
					special_calc_from
				) 
				SELECT 
					oid, 
					code, 
					texte, 
					pole_id, 
					priorite, 
					liste_compte, 
					liste_sauf_compte, 
					liste_journal, 
					liste_sauf_journal, 
					liste_section_analytique, 
					liste_sauf_section_analytique, 
					liste_finess, 
					liste_site, 
					from_rule_id, 
					liste_exercice, 
					liste_mois_comptable, 
					special_calc, 
					special_calc_from 
				FROM e_pole_rule 
				; 
			
			
			]]></sqlcmd> 
		</NODE>
	</NODE>
	
</ROOT>













