<?xml version="1.0" encoding="ISO-8859-1"?>
<ROOT>
	<NODE name="COPIE" label="REPLICATIONS">
		<NODE label="Réplication du schéma eco">
			<sqlcmd><![CDATA[
			
			-- eco_ori correspond en temps normal au schéma eco.
			-- le schéma eco_prestataire a été renommé eco.
			SELECT base.cti_synchronize_schema('eco_ori', 'eco');

			]]></sqlcmd>
		</NODE>
		<NODE label="Réplication du paramétrage">
			<sqlcmd><![CDATA[

            -- Réplication du paramétrage t_divers.
            TRUNCATE eco.t_divers
            ;

            INSERT INTO eco.t_divers(code, texte, valeur, description, valeur_date)
                SELECT code, texte, valeur, description, valeur_date
                FROM eco_ori.t_divers
            ;
		
            -- Réplication de t_listes_tables.
            TRUNCATE eco.t_listes_tables
            ;

            INSERT INTO eco.t_listes_tables(oid, name, texte, select_cmd, code)
                SELECT oid, name, texte, select_cmd, code
                FROM eco_ori.t_listes_tables
            ;

			]]></sqlcmd>
		</NODE>
	</NODE>
	<NODE name="INIT" label="INITIALISATIONS">
		<NODE label="Tables de paramètres.">
			<sqlcmd><![CDATA[

			-- eco correspond au schéma habituel eco.
			-- eco_src correspond au schéma du prestataire.

			-- Maj lettres budgétaires
			SELECT synctable('t_lettre_budgetaire')
			;

			-- Maj des comptes
			SELECT syncTable('t_compte')
			;
            
			-- Maj des familles
			SELECT synctable('t_familles_articles')
			;

			-- Maj des sous familles
			SELECT synctable('t_sous_familles_articles')
			;

			-- Maj des classification atc
			SELECT mergeTable('t_classification_atc')
			;

			-- Maj des unités
			SELECT synctable('t_unites')
			;

			-- Maj des types articles
			--SELECT synctable('t_types_articles')
			--;
			
			UPDATE eco.t_types_articles cible SET
				code_original = '[TPX]' || src.code_original,
				code = '[TPX]' || src.code,
				texte = src.texte,
				texte_court = src.texte_court
			FROM eco_src.t_types_articles src
			WHERE src.oid + [IPX] = cible.oid
			;
			
			INSERT INTO eco.t_types_articles (
				oid,
				code,
				code_original,
				texte,
				texte_court)
			SELECT 
				src.oid + [IPX],
				'[TPX]' || src.code,  
				'[TPX]' || src.code_original,
				src.texte,
				src.texte_court
			FROM eco_src.t_types_articles src
				LEFT JOIN eco.t_types_articles cible ON src.oid + [IPX] = cible.oid
			WHERE cible.code_original IS NULL AND src.oid != 0
			ORDER BY 1
			;
			
			-- Maj des catégories
			SELECT synctable('t_categories_articles')
			;
			
			-- Maj des sous catégories
			SELECT synctable('t_sous_categories_articles')
			;
			
			-- Maj des lieux
			SELECT synctable('t_lieux')
			;
					
			-- Maj des sites
			SELECT synctable('t_sites')
			;
			
			-- Maj des fournisseurs
			SELECT synctable('t_types_fournisseurs')
			;
			--SELECT synctable('t_fournisseurs')
			--;
			
			INSERT INTO eco.t_fournisseurs (
				oid,
				code,
				code_original,
				texte,
				texte_court)
			SELECT 
				src.oid + [IPX],
				'[TPX]' || src.code,  
				'[TPX]' || src.code_original,
				src.texte,
				src.texte_court
			FROM eco_src.t_fournisseurs src
				LEFT JOIN eco.t_fournisseurs cible ON src.oid + [IPX] = cible.oid
			WHERE cible.code_original IS NULL AND src.oid != 0
			ORDER BY 1;
			
			
			
			UPDATE eco.t_fournisseurs SET
				code = '[TPX]' || src.code,
				texte = src.texte,
				texte_court = src.texte_court,
				type_id = CASE WHEN src.type_id <> 0 THEN src.type_id + [IPX] ELSE 0 END,
				fournisseur_distributeur_id = CASE WHEN src.fournisseur_distributeur_id <> 0 THEN src.fournisseur_distributeur_id + [IPX] ELSE 0 END,
				code_cahpp = src.code_cahpp,
				adresse = src.adresse,
				code_postal_id = src.code_postal_id,
				ville = src.ville,
				telephone = src.telephone,
				fax = src.fax,
				email = src.email,
				code_edi = src.code_edi,
				siret = src.siret,
				iban = src.iban,
				cedex = src.cedex,
				code_comptable = src.code_comptable,
				bic = src.bic
			FROM eco_src.t_fournisseurs src
			WHERE src.oid + [IPX] = t_fournisseurs.oid AND
				(
					t_fournisseurs.code IS DISTINCT FROM ('[TPX]' || src.code) OR
					t_fournisseurs.texte IS DISTINCT FROM src.texte OR
					t_fournisseurs.texte_court IS DISTINCT FROM src.texte_court OR
					t_fournisseurs.type_id IS DISTINCT FROM CASE WHEN src.type_id <> 0 THEN src.type_id + [IPX] ELSE 0 END OR
					t_fournisseurs.fournisseur_distributeur_id IS DISTINCT FROM CASE WHEN src.fournisseur_distributeur_id <> 0 THEN src.fournisseur_distributeur_id + [IPX] ELSE 0 END OR
					t_fournisseurs.code_cahpp IS DISTINCT FROM src.code_cahpp OR
					t_fournisseurs.adresse IS DISTINCT FROM src.adresse OR
					t_fournisseurs.code_postal_id IS DISTINCT FROM src.code_postal_id OR
					t_fournisseurs.ville IS DISTINCT FROM src.ville OR
					t_fournisseurs.telephone IS DISTINCT FROM src.telephone OR
					t_fournisseurs.fax IS DISTINCT FROM src.fax OR
					t_fournisseurs.email IS DISTINCT FROM src.email OR
					t_fournisseurs.code_edi IS DISTINCT FROM src.code_edi OR
					t_fournisseurs.siret IS DISTINCT FROM src.siret OR
					t_fournisseurs.iban IS DISTINCT FROM src.iban OR
					t_fournisseurs.cedex IS DISTINCT FROM src.cedex OR
					t_fournisseurs.code_comptable IS DISTINCT FROM src.code_comptable OR
					t_fournisseurs.bic IS DISTINCT FROM src.bic
				)
			;
			
			
			UPDATE eco.t_fournisseurs SET
				type_code = t_types_fournisseurs.code,
				type_texte = t_types_fournisseurs.texte_court,
				type_section_id = t_types_fournisseurs.section_id,
				type_section_code = t_types_fournisseurs.section_code,
				type_section_texte = t_types_fournisseurs.section_texte
			FROM eco.t_types_fournisseurs
			WHERE type_id = t_types_fournisseurs.oid
				AND (
					type_code IS DISTINCT FROM t_types_fournisseurs.code OR
					type_texte IS DISTINCT FROM t_types_fournisseurs.texte_court OR
					type_section_id IS DISTINCT FROM t_types_fournisseurs.section_id OR
					type_section_code IS DISTINCT FROM t_types_fournisseurs.section_code OR
					type_section_texte IS DISTINCT FROM t_types_fournisseurs.section_texte
				);
			
			-- Maj des gestionnaires
			SELECT synctable('t_gestionnaires')
			;
			
			-- Maj des uf
			SELECT synctable('t_unites_fonctionnelles')
			;
			
			-- Maj des types mouvements
			SELECT synctable('t_types_mouvements')
			;

			-- Maj des articles
			--SELECT synctable('t_articles') impossible car références lieés
			;

			INSERT INTO eco.t_articles (
					oid,
					code,
					code_original,
					texte,
					texte_court)
				SELECT 
					src.oid + [IPX],
					left('[TPX]' || src.code,30),  
					'[TPX]' || src.code_original,
					src.texte,
					src.texte_court
				FROM eco_src.t_articles src
					LEFT JOIN eco.t_articles cible ON src.oid + [IPX] = cible.oid
				WHERE cible.code_original IS NULL AND src.oid != 0
				ORDER by 1;
				
			UPDATE eco.t_articles SET
				code = left('[TPX]'::text || src.code,30),
				code_original = '[TPX]'::text || src.code_original,
				texte = src.texte,
				texte_court = src.texte_court,
				ucd_id = src.ucd_id,
				lpp_id = src.lpp_id,
				code_ucd13 = src.code_ucd13,
				taux_tva_en_cours = src.taux_tva_en_cours,
				gere_en_stock = src.gere_en_stock,
				stock_en_depot = src.stock_en_depot,
				type_id = CASE WHEN src.type_id <> 0 THEN src.type_id + [IPX] ELSE 0 END,
				famille_id = CASE WHEN src.famille_id <> 0 THEN src.famille_id + [IPX] ELSE 0 END,
				sous_famille_id = CASE WHEN src.sous_famille_id <> 0 THEN src.sous_famille_id + [IPX] ELSE 0 END,
				categorie_id = CASE WHEN src.categorie_id <> 0 THEN src.categorie_id + [IPX] ELSE 0 END,
				sous_categorie_id = CASE WHEN src.sous_categorie_id <> 0 THEN src.sous_categorie_id + [IPX] ELSE 0 END,
				unite_stockage_id = CASE WHEN src.unite_stockage_id <> 0 THEN src.unite_stockage_id + [IPX] ELSE 0 END,
				unite_distribution_id = CASE WHEN src.unite_distribution_id <> 0 THEN src.unite_distribution_id + [IPX] ELSE 0 END
			FROM eco_src.t_articles src
			WHERE src.oid + [IPX] = t_articles.oid AND
				(
					t_articles.code IS DISTINCT FROM left('[TPX]'::text || src.code,30) OR
					t_articles.code_original IS DISTINCT FROM '[TPX]' || src.code_original OR
					t_articles.texte IS DISTINCT FROM src.texte OR
					t_articles.texte_court IS DISTINCT FROM src.texte_court OR
					t_articles.ucd_id IS DISTINCT FROM src.ucd_id OR
					t_articles.lpp_id IS DISTINCT FROM src.lpp_id OR
					t_articles.code_ucd13 IS DISTINCT FROM src.code_ucd13 OR
					t_articles.taux_tva_en_cours IS DISTINCT FROM src.taux_tva_en_cours OR
					t_articles.stock_en_depot IS DISTINCT FROM src.stock_en_depot OR
					t_articles.gere_en_stock IS DISTINCT FROM src.gere_en_stock OR
					t_articles.type_id IS DISTINCT FROM CASE WHEN src.type_id <> 0 THEN src.type_id + [IPX] ELSE 0 END OR
					t_articles.famille_id IS DISTINCT FROM CASE WHEN src.famille_id <> 0 THEN src.famille_id + [IPX] ELSE 0 END OR
					t_articles.sous_famille_id IS DISTINCT FROM CASE WHEN src.sous_famille_id <> 0 THEN src.sous_famille_id + [IPX] ELSE 0 END OR
					t_articles.categorie_id IS DISTINCT FROM CASE WHEN src.categorie_id <> 0 THEN src.categorie_id + [IPX] ELSE 0 END OR
					t_articles.sous_categorie_id IS DISTINCT FROM CASE WHEN src.sous_categorie_id <> 0 THEN src.sous_categorie_id + [IPX] ELSE 0 END OR
					t_articles.unite_stockage_id IS DISTINCT FROM CASE WHEN src.unite_stockage_id <> 0 THEN src.unite_stockage_id + [IPX] ELSE 0 END OR
					t_articles.unite_distribution_id IS DISTINCT FROM CASE WHEN src.unite_distribution_id <> 0 THEN src.unite_distribution_id + [IPX] ELSE 0 END
				)
			;

			UPDATE eco.t_articles SET
				compte_id = CASE WHEN src.compte_id <> 0 THEN src.compte_id + [IPX] ELSE 0 END
			FROM eco_src.t_articles src
			WHERE src.oid + [IPX] = t_articles.oid AND
				(SELECT valeur FROM eco.t_divers WHERE code = 'MERGE_CPT') <> '1' AND
				(
					t_articles.compte_id IS DISTINCT FROM CASE WHEN src.compte_id <> 0 THEN src.compte_id + [IPX] ELSE 0 END
				)
			;

			UPDATE eco.t_articles SET
				compte_id = COALESCE(subview.compte_id,0)
			FROM eco_src.t_articles src
			JOIN eco_src.t_compte src_compte ON src.compte_id = src_compte.oid
			LEFT JOIN (SELECT code, MIN(oid) AS compte_id FROM eco.t_compte GROUP BY 1) subview ON src_compte.code = subview.code
			WHERE src.oid + [IPX] = t_articles.oid AND
				(SELECT valeur FROM eco.t_divers WHERE code = 'MERGE_CPT') = '1' AND
				(
					t_articles.compte_id IS DISTINCT FROM COALESCE(subview.compte_id,0)
				)
			;


			UPDATE eco.t_articles SET
				classification_atc_id = COALESCE(subview.classification_atc_id,0)
			FROM eco_src.t_articles src
			JOIN eco_src.t_classification_atc src_classification_atc ON src.classification_atc_id = src_classification_atc.oid
			LEFT JOIN (SELECT code, MIN(oid) AS classification_atc_id FROM eco.t_classification_atc GROUP BY 1) subview ON src_classification_atc.code = subview.code
			WHERE src.oid + [IPX] = t_articles.oid AND
				(
					t_articles.classification_atc_id IS DISTINCT FROM COALESCE(subview.classification_atc_id,0)
				)
			;

			UPDATE eco.t_articles SET
				type_code = t_types_articles.code,
				type_texte = t_types_articles.texte_court,
				type_section_id = t_types_articles.section_id,
				type_section_code = t_types_articles.section_code,
				type_section_texte = t_types_articles.section_texte,
				
				famille_code = t_familles_articles.code,
				famille_texte = t_familles_articles.texte_court,
				famille_section_id = t_familles_articles.section_id,
				famille_section_code = t_familles_articles.section_code,
				famille_section_texte = t_familles_articles.section_texte,

				sous_famille_code = t_sous_familles_articles.code,
				sous_famille_texte = t_sous_familles_articles.texte_court,
				sous_famille_section_id = t_sous_familles_articles.section_id,
				sous_famille_section_code = t_sous_familles_articles.section_code,
				sous_famille_section_texte = t_sous_familles_articles.section_texte,

				categorie_code = t_categories_articles.code,
				categorie_texte = t_categories_articles.texte_court,
				categorie_section_id = t_categories_articles.section_id,
				categorie_section_code = t_categories_articles.section_code,
				categorie_section_texte = t_categories_articles.section_texte,

				sous_categorie_code = t_sous_categories_articles.code,
				sous_categorie_texte = t_sous_categories_articles.texte_court,
				sous_categorie_section_id = t_sous_categories_articles.section_id,
				sous_categorie_section_code = t_sous_categories_articles.section_code,
				sous_categorie_section_texte = t_sous_categories_articles.section_texte,

				classification_atc_code = t_classification_atc.code,
				classification_atc_texte = t_classification_atc.texte_court,
				classification_atc_section_id = t_classification_atc.section_id,
				classification_atc_section_code = t_classification_atc.section_code,
				classification_atc_section_texte = t_classification_atc.section_texte,
				classification_atc_1_id = t_classification_atc.classification_atc_1_id,
				classification_atc_1_code = t_classification_atc.classification_atc_1_code,
				classification_atc_1_texte = t_classification_atc.classification_atc_1_texte,
				classification_atc_2_id = t_classification_atc.classification_atc_2_id,
				classification_atc_2_code = t_classification_atc.classification_atc_2_code,
				classification_atc_2_texte = t_classification_atc.classification_atc_2_texte,
				classification_atc_3_id = t_classification_atc.classification_atc_3_id,
				classification_atc_3_code = t_classification_atc.classification_atc_3_code,
				classification_atc_3_texte = t_classification_atc.classification_atc_3_texte,
				classification_atc_4_id = t_classification_atc.classification_atc_4_id,
				classification_atc_4_code = t_classification_atc.classification_atc_4_code,
				classification_atc_4_texte = t_classification_atc.classification_atc_4_texte,

				unite_stockage_code = t_unites_stockage.code,
				unite_stockage_texte = t_unites_stockage.texte_court,
				unite_stockage_section_id = t_unites_stockage.section_id,
				unite_stockage_section_code = t_unites_stockage.section_code,
				unite_stockage_section_texte = t_unites_stockage.section_texte,

				unite_distribution_code = t_unites_distribution.code,
				unite_distribution_texte = t_unites_distribution.texte_court,
				unite_distribution_section_id = t_unites_distribution.section_id,
				unite_distribution_section_code = t_unites_distribution.section_code,
				unite_distribution_section_texte = t_unites_distribution.section_texte,
				
				compte_code = t_compte.code,
				compte_texte = t_compte.texte_court,
				compte_section_id = t_compte.section_id,
				compte_section_code = t_compte.section_code,
				compte_section_texte = t_compte.section_texte

			FROM eco.t_types_articles ,
				eco.t_familles_articles,
				eco.t_sous_familles_articles,
				eco.t_categories_articles,
				eco.t_sous_categories_articles,
				eco.t_classification_atc,
				eco.t_unites t_unites_stockage,
				eco.t_unites t_unites_distribution,
				eco.t_compte
				
			WHERE type_id = t_types_articles.oid
				AND famille_id = t_familles_articles.oid
				AND sous_famille_id = t_sous_familles_articles.oid
				AND categorie_id = t_categories_articles.oid
				AND sous_categorie_id = t_sous_categories_articles.oid
				AND classification_atc_id = t_classification_atc.oid
				AND unite_stockage_id = t_unites_stockage.oid
				AND unite_distribution_id = t_unites_distribution.oid
				AND compte_id = t_compte.oid
				AND (
					type_code IS DISTINCT FROM t_types_articles.code OR
					type_texte IS DISTINCT FROM t_types_articles.texte_court OR
					type_section_id IS DISTINCT FROM t_types_articles.section_id OR
					type_section_code IS DISTINCT FROM t_types_articles.section_code OR
					type_section_texte IS DISTINCT FROM t_types_articles.section_texte OR
					
					famille_code IS DISTINCT FROM t_familles_articles.code OR
					famille_texte IS DISTINCT FROM t_familles_articles.texte_court OR
					famille_section_id IS DISTINCT FROM t_familles_articles.section_id OR
					famille_section_code IS DISTINCT FROM t_familles_articles.section_code OR
					famille_section_texte IS DISTINCT FROM t_familles_articles.section_texte OR
					
					sous_famille_code IS DISTINCT FROM t_sous_familles_articles.code OR
					sous_famille_texte IS DISTINCT FROM t_sous_familles_articles.texte_court OR
					sous_famille_section_id IS DISTINCT FROM t_sous_familles_articles.section_id OR
					sous_famille_section_code IS DISTINCT FROM t_sous_familles_articles.section_code OR
					sous_famille_section_texte IS DISTINCT FROM t_sous_familles_articles.section_texte OR
					
					categorie_code IS DISTINCT FROM t_categories_articles.code OR
					categorie_texte IS DISTINCT FROM t_categories_articles.texte_court OR
					categorie_section_id IS DISTINCT FROM t_categories_articles.section_id OR
					categorie_section_code IS DISTINCT FROM t_categories_articles.section_code OR
					categorie_section_texte IS DISTINCT FROM t_categories_articles.section_texte OR
					
					sous_categorie_code IS DISTINCT FROM t_sous_categories_articles.code OR
					sous_categorie_texte IS DISTINCT FROM t_sous_categories_articles.texte_court OR
					sous_categorie_section_id IS DISTINCT FROM t_sous_categories_articles.section_id OR
					sous_categorie_section_code IS DISTINCT FROM t_sous_categories_articles.section_code OR
					sous_categorie_section_texte IS DISTINCT FROM t_sous_categories_articles.section_texte OR
					
					t_articles.classification_atc_code IS DISTINCT FROM t_classification_atc.code OR
					t_articles.classification_atc_texte IS DISTINCT FROM t_classification_atc.texte_court OR
					t_articles.classification_atc_section_id IS DISTINCT FROM t_classification_atc.section_id OR
					t_articles.classification_atc_section_code IS DISTINCT FROM t_classification_atc.section_code OR
					t_articles.classification_atc_section_texte IS DISTINCT FROM t_classification_atc.section_texte OR
					t_articles.classification_atc_1_id IS DISTINCT FROM t_classification_atc.classification_atc_1_id OR
					t_articles.classification_atc_1_code IS DISTINCT FROM t_classification_atc.classification_atc_1_code OR
					t_articles.classification_atc_1_texte IS DISTINCT FROM t_classification_atc.classification_atc_1_texte OR
					t_articles.classification_atc_2_id IS DISTINCT FROM t_classification_atc.classification_atc_2_id OR
					t_articles.classification_atc_2_code IS DISTINCT FROM t_classification_atc.classification_atc_2_code OR
					t_articles.classification_atc_2_texte IS DISTINCT FROM t_classification_atc.classification_atc_2_texte OR
					t_articles.classification_atc_3_id IS DISTINCT FROM t_classification_atc.classification_atc_3_id OR
					t_articles.classification_atc_3_code IS DISTINCT FROM t_classification_atc.classification_atc_3_code OR
					t_articles.classification_atc_3_texte IS DISTINCT FROM t_classification_atc.classification_atc_3_texte OR
					t_articles.classification_atc_4_id IS DISTINCT FROM t_classification_atc.classification_atc_4_id OR
					t_articles.classification_atc_4_code IS DISTINCT FROM t_classification_atc.classification_atc_4_code OR
					t_articles.classification_atc_4_texte IS DISTINCT FROM t_classification_atc.classification_atc_4_texte OR

					t_articles.unite_stockage_code IS DISTINCT FROM t_unites_stockage.code OR
					t_articles.unite_stockage_texte IS DISTINCT FROM t_unites_stockage.texte_court OR
					t_articles.unite_stockage_section_id IS DISTINCT FROM t_unites_stockage.section_id OR
					t_articles.unite_stockage_section_code IS DISTINCT FROM t_unites_stockage.section_code OR
					t_articles.unite_stockage_section_texte IS DISTINCT FROM t_unites_stockage.section_texte OR
					
					t_articles.unite_distribution_code IS DISTINCT FROM t_unites_distribution.code OR
					t_articles.unite_distribution_texte IS DISTINCT FROM t_unites_distribution.texte_court OR
					t_articles.unite_distribution_section_id IS DISTINCT FROM t_unites_distribution.section_id OR
					t_articles.unite_distribution_section_code IS DISTINCT FROM t_unites_distribution.section_code OR
					t_articles.unite_distribution_section_texte IS DISTINCT FROM t_unites_distribution.section_texte OR

					t_articles.compte_code IS DISTINCT FROM t_compte.code OR
					t_articles.compte_texte IS DISTINCT FROM t_compte.texte_court OR
					t_articles.compte_section_id IS DISTINCT FROM t_compte.section_id OR
					t_articles.compte_section_code IS DISTINCT FROM t_compte.section_code OR
					t_articles.compte_section_texte IS DISTINCT FROM t_compte.section_texte
				);
				
			
			    UPDATE eco.t_articles
                SET 
                    ref_fournisseur_id = src.ref_fournisseur_id,
                    ref_fournisseur_texte = src.ref_fournisseur_texte
                FROM (
                    SELECT 
                        oid,
                        array_agg(fou_id + [IPX]) AS ref_fournisseur_id,
                        array_agg(fou_txt) AS ref_fournisseur_texte
                    FROM (
                        SELECT 
                            oid,
                            unnest(ref_fournisseur_id) as fou_id,
                            unnest(ref_fournisseur_texte) AS fou_txt
                        FROM 
                            eco_src.t_articles src
                    ) sub
                    GROUP BY 1
                ) src
                WHERE src.oid + [IPX] = t_articles.oid
                    AND (
                        t_articles.ref_fournisseur_id  != src.ref_fournisseur_id OR
                        t_articles.ref_fournisseur_texte  != src.ref_fournisseur_texte
                        )
                        ;
						
				DELETE
				FROM eco.t_article_fournisseur
				WHERE oid NOT IN (SELECT oid FROM eco_src.t_article_fournisseur) AND
					oid BETWEEN [IPX] AND ([IPX]+10000000)
				;

						
				INSERT INTO eco.t_article_fournisseur (
					oid,
					code_original,
					article_id,
					fournisseur_id,
					code_reference_fournisseur,
					texte_reference_fournisseur,
					code_cip,
					code_cahpp,
					unite_approvisionnement_id,
					nombre_conditionnement_approvisionnement,
					prix_unitaire_en_cours,
					est_fournisseur_principal,
					fournisseur_distributeur_id,
					ucd_id,
					lpp_id,
					code_ucd13
					)
				SELECT 
					src.oid + [IPX],
					'[TPX]' || src.code_original,
					CASE WHEN src.article_id > 0 THEN src.article_id + [IPX] ELSE 0 END,
					CASE WHEN src.fournisseur_id > 0 THEN src.fournisseur_id + [IPX] ELSE 0 END,
					src.code_reference_fournisseur,
					src.texte_reference_fournisseur,
					src.code_cip,
					src.code_cahpp,
					CASE WHEN src.unite_approvisionnement_id > 0 THEN src.unite_approvisionnement_id + [IPX] ELSE 0 END,
					src.nombre_conditionnement_approvisionnement,
					src.prix_unitaire_en_cours,
					src.est_fournisseur_principal,
					CASE WHEN src.fournisseur_distributeur_id > 0 THEN src.fournisseur_distributeur_id + [IPX] ELSE 0 END,
					src.ucd_id,
					src.lpp_id,
					src.code_ucd13
				FROM eco_src.t_article_fournisseur src
					LEFT JOIN eco.t_article_fournisseur cible ON src.oid + [IPX] = cible.oid
				WHERE cible.oid IS NULL AND src.oid != 0
				ORDER BY 1
				;
				
				UPDATE eco.t_article_fournisseur cible SET
					code_original = '[TPX]'::text || src.code_original,
					article_id = CASE WHEN src.article_id > 0 THEN src.article_id + [IPX] ELSE 0 END,
					fournisseur_id = CASE WHEN src.fournisseur_id > 0 THEN src.fournisseur_id + [IPX] ELSE 0 END,
					code_reference_fournisseur = src.code_reference_fournisseur,
					texte_reference_fournisseur = src.texte_reference_fournisseur,
					code_cip = src.code_cip,
					code_cahpp = src.code_cahpp,
					unite_approvisionnement_id = CASE WHEN src.unite_approvisionnement_id > 0 THEN src.unite_approvisionnement_id + [IPX] ELSE 0 END,
					nombre_conditionnement_approvisionnement = src.nombre_conditionnement_approvisionnement,
					prix_unitaire_en_cours = src.prix_unitaire_en_cours,
					est_fournisseur_principal = src.est_fournisseur_principal,
					fournisseur_distributeur_id = CASE WHEN src.fournisseur_distributeur_id > 0 THEN src.fournisseur_distributeur_id + [IPX] ELSE 0 END,
					ucd_id = src.ucd_id,
					lpp_id = src.lpp_id,
					code_ucd13 = src.code_ucd13
				FROM eco_src.t_article_fournisseur src
				WHERE src.oid + [IPX] = cible.oid AND
					(
					cible.code_original = '[TPX]'::text || src.code_original AND
					cible.article_id IS DISTINCT FROM CASE WHEN src.article_id > 0 THEN src.article_id + [IPX] ELSE 0 END OR
					cible.fournisseur_id IS DISTINCT FROM CASE WHEN src.fournisseur_id > 0 THEN src.fournisseur_id + [IPX] ELSE 0 END OR
					cible.code_reference_fournisseur IS DISTINCT FROM src.code_reference_fournisseur OR
					cible.texte_reference_fournisseur IS DISTINCT FROM src.texte_reference_fournisseur OR
					cible.code_cip IS DISTINCT FROM src.code_cip OR
					cible.code_cahpp IS DISTINCT FROM src.code_cahpp OR
					cible.unite_approvisionnement_id IS DISTINCT FROM CASE WHEN src.unite_approvisionnement_id > 0 THEN src.unite_approvisionnement_id + [IPX] ELSE 0 END OR
					cible.nombre_conditionnement_approvisionnement IS DISTINCT FROM src.nombre_conditionnement_approvisionnement OR
					cible.prix_unitaire_en_cours IS DISTINCT FROM src.prix_unitaire_en_cours OR
					cible.est_fournisseur_principal IS DISTINCT FROM src.est_fournisseur_principal OR
					cible.fournisseur_distributeur_id IS DISTINCT FROM CASE WHEN src.fournisseur_distributeur_id > 0 THEN src.fournisseur_distributeur_id + [IPX] ELSE 0 END OR
					cible.ucd_id IS DISTINCT FROM src.ucd_id OR
					cible.lpp_id IS DISTINCT FROM src.lpp_id OR
					cible.code_ucd13 IS DISTINCT FROM src.code_ucd13
					)
				;
				
				

			]]></sqlcmd>
		</NODE>
	</NODE>
	<NODE name="FUSION" label="FUSION">
		<NODE label="Commandes">
			<sqlcmd><![CDATA[
				SELECT pushtable('p_commandes');
				SELECT pushtable('p_lignes_commandes');

			]]></sqlcmd>
		</NODE>
		<NODE label="Stocks">
			<sqlcmd><![CDATA[
				SELECT pushtable('p_mouvements_articles');
				SELECT pushtable('p_stock');
			]]></sqlcmd>
		</NODE>
		<NODE label="Factures">
			<sqlcmd><![CDATA[
				SELECT pushtable('p_facture');
			]]></sqlcmd>
		</NODE>
		<NODE label="Gestion de la bascule">
			<condition>
			<![CDATA[
				"[StartDate]" != "1900-01-01" || "[EndDate]" != "2099-12-31"
			]]>
			</condition>
			<sqlcmd><![CDATA[
				DELETE FROM eco.p_facture WHERE commande_id IN (SELECT oid from eco.p_commandes WHERE provider_id = fp('provider') AND date_commande NOT BETWEEN fp('str')::date and fp('end')::date - interval '1 day');
				DELETE FROM eco.p_lignes_commandes WHERE commande_id IN (SELECT oid from eco.p_commandes WHERE provider_id = fp('provider') AND date_commande NOT BETWEEN fp('str')::date and fp('end')::date - interval '1 day');
				DELETE FROM eco.p_commandes WHERE provider_id = fp('provider') AND date_commande NOT BETWEEN fp('str')::date and fp('end')::date - interval '1 day';
				DELETE FROM eco.p_mouvements_articles WHERE provider_id = fp('provider') AND date NOT BETWEEN fp('str')::date and fp('end')::date - interval '1 day';
				DELETE FROM eco.p_stock WHERE provider_id = fp('provider') AND date_fin NOT BETWEEN fp('str')::date and fp('end')::date - interval '1 day';
				UPDATE eco.p_mouvements_articles SET date_fin = fp('end')::date WHERE provider_id = fp('provider') AND date_fin > fp('end')::date - interval '1 day';
				DELETE FROM eco.p_chiffrier_production WHERE provider_id = fp('provider') AND substr(mois,1,4)||'-'||substr(mois,5,2)||'-01' NOT BETWEEN fp('str')::date and fp('end')::date - interval '1 day';
			]]></sqlcmd>
		</NODE>
		<NODE label="Fusion des différentes thématiques">
			<sqlcmd><![CDATA[
				SELECT base.cti_execute('UPDATE eco.p_lignes_commandes SET compte_id = cible_id
				FROM (
					SELECT src.oid AS source_id, t_compte.oid AS cible_id
						FROM eco_src.t_compte src
						JOIN eco.t_compte ON src.code = t_compte.code) sub
				WHERE compte_id = source_id + [IPX]
				.,
				UPDATE eco.t_articles SET compte_id = cible_id
				FROM (
					SELECT src.oid AS source_id, t_compte.oid AS cible_id
						FROM eco_src.t_compte src
						JOIN eco.t_compte ON src.code = t_compte.code) sub
				WHERE compte_id = source_id + [IPX]
				.,
				UPDATE eco.p_mouvements_articles SET compte_id = cible_id
				FROM (
						SELECT src.oid AS source_id, t_compte.oid AS cible_id
						FROM eco_src.t_compte src
						JOIN eco.t_compte ON src.code = t_compte.code) sub
				WHERE compte_id = source_id + [IPX]
				.,
				UPDATE eco.t_compte
				SET code = 	SUBSTR(code,STRPOS(code,''_'')+1) 
				WHERE oid BETWEEN [IPX] AND [IPX] + 9999999999',1)
				WHERE (SELECT valeur FROM eco.t_divers WHERE code = 'MERGE_CPT') = 1;
				
				
				SELECT base.cti_execute('UPDATE eco.p_stock SET compte_id = cible_id
				FROM (
					SELECT src.oid AS source_id, t_compte.oid AS cible_id
						FROM eco_src.t_compte src
						JOIN eco.t_compte ON src.code = t_compte.code) sub
				WHERE compte_id = source_id + [IPX]
				.,
				UPDATE eco.p_lignes_commandes SET article_id = cible_id
				FROM (
					SELECT src.oid AS source_id, MIN(t_articles.oid) AS cible_id
						FROM eco.t_articles src
						JOIN eco.t_articles ON src.code like ''[TPX]%'' AND src.texte = t_articles.texte 
							AND t_articles.oid != src.oid
							AND t_articles.oid = ANY(SELECT article_id FROM eco.p_lignes_commandes)
						GROUP BY 1) sub
				WHERE article_id = source_id
				.,
				UPDATE eco.p_mouvements_articles SET article_id = cible_id
				FROM (
					SELECT src.oid AS source_id, MIN(t_articles.oid) AS cible_id
						FROM eco.t_articles src
						JOIN eco.t_articles ON src.code like ''[TPX]%'' AND src.texte = t_articles.texte 
							AND t_articles.oid != src.oid
							AND t_articles.oid = ANY(SELECT article_id FROM eco.p_mouvements_articles)
					GROUP BY 1) sub
				WHERE article_id = source_id
				.,
				UPDATE eco.p_stock SET article_id = cible_id
				FROM (
					SELECT src.oid AS source_id, MIN(t_articles.oid) AS cible_id
						FROM eco.t_articles src
						JOIN eco.t_articles ON src.code like ''[TPX]%'' AND src.texte = t_articles.texte 
							AND t_articles.oid != src.oid
							AND t_articles.oid = ANY(SELECT article_id FROM eco.p_stock)
					GROUP BY 1) sub
				WHERE article_id = source_id
				.,
				UPDATE eco.t_articles
				SET code = 	SUBSTR(code,STRPOS(code,''_'')+1) 
				WHERE oid BETWEEN [IPX] AND [IPX] + 9999999999',1)
				WHERE (SELECT valeur FROM eco.t_divers WHERE code = 'MERGE_ART') = 1;
				
					
				SELECT base.cti_execute('
				UPDATE eco.p_lignes_commandes SET article_id = cible_id
				FROM (
					SELECT src.oid AS source_id, t_articles.oid AS cible_id
						FROM eco.t_articles src
						JOIN eco.t_articles ON src.code like ''[TPX]%'' AND right(src.code,-3) = t_articles.code
							AND t_articles.oid != src.oid) sub
				WHERE article_id = source_id
				.,
				UPDATE eco.p_mouvements_articles SET article_id = cible_id
				FROM (
					SELECT src.oid AS source_id, t_articles.oid AS cible_id
						FROM eco.t_articles src
						JOIN eco.t_articles ON src.code like ''[TPX]%'' AND right(src.code,-3) = t_articles.code
							AND t_articles.oid != src.oid) sub
				WHERE article_id = source_id
				.,
				UPDATE eco.p_stock SET article_id = cible_id
				FROM (
					SELECT src.oid AS source_id, t_articles.oid AS cible_id
						FROM eco.t_articles src
						JOIN eco.t_articles ON src.code like ''[TPX]%'' AND right(src.code,-3) = t_articles.code
							AND t_articles.oid != src.oid) sub
				WHERE article_id = source_id
				.,
				UPDATE eco.t_articles
				SET code = 	SUBSTR(code,STRPOS(code,''_'')+1) 
				WHERE oid BETWEEN [IPX] AND [IPX] + 9999999999',1)
				WHERE (SELECT valeur FROM eco.t_divers WHERE code = 'MERGE_ART_CODE') = 1;
				
				
                SELECT base.cti_execute('UPDATE eco.p_mouvements_articles SET unite_fonctionnelle_id = cible_id
				FROM (
					SELECT src.oid AS source_id, t_unites_fonctionnelles.oid AS cible_id
						FROM eco.t_unites_fonctionnelles src
						JOIN eco.t_unites_fonctionnelles ON
							src.code like ''[TPX]%'' AND (right(src.code,-3) = t_unites_fonctionnelles.code
							OR src.code = t_unites_fonctionnelles.code
							OR left(right(src.code,2),1) || ''I'' || right(right(src.code,2),1) = t_unites_fonctionnelles.code
							OR (right(src.code,2) = t_unites_fonctionnelles.code and t_unites_fonctionnelles.code = ''SC'')
							AND t_unites_fonctionnelles.oid != src.oid)) sub
				WHERE unite_fonctionnelle_id = source_id
				.,
				UPDATE eco.p_lignes_commandes SET unite_fonctionnelle_id = cible_id
				FROM (
					SELECT src.oid AS source_id, t_unites_fonctionnelles.oid AS cible_id
						FROM eco.t_unites_fonctionnelles src
						JOIN eco.t_unites_fonctionnelles ON
							src.code like ''[TPX]%'' AND (right(src.code,-3) = t_unites_fonctionnelles.code
							OR src.code = t_unites_fonctionnelles.code
							OR left(right(src.code,2),1) || ''I'' || right(right(src.code,2),1) = t_unites_fonctionnelles.code
							OR (right(src.code,2) = t_unites_fonctionnelles.code and t_unites_fonctionnelles.code = ''SC'')
							AND t_unites_fonctionnelles.oid != src.oid)) sub
				WHERE unite_fonctionnelle_id = source_id
				.,
				UPDATE eco.t_unites_fonctionnelles
				SET code = 	SUBSTR(code,STRPOS(code,''_'')+1) 
				WHERE oid BETWEEN [IPX] AND [IPX] + 9999999999
				',1
				)
				WHERE (SELECT valeur FROM eco.t_divers WHERE code = 'MERGE_UF') = 1;

				SELECT base.cti_execute('UPDATE eco.p_mouvements_articles SET type_mouvement_id = cible_id
				FROM (
					SELECT src.oid AS source_id, t_types_mouvements.oid AS cible_id
						FROM eco_src.t_types_mouvements src
						JOIN eco.t_types_mouvements ON src.code = t_types_mouvements.code) sub
				WHERE type_mouvement_id = source_id + [IPX]',1)
				WHERE (SELECT valeur FROM eco.t_divers WHERE code = 'MERGE_MVT') = 1
				;
				
				SELECT base.cti_execute('UPDATE eco.t_articles SET unite_distribution_id = cible_id
				FROM (
					SELECT src.oid AS source_id, t_unites.oid AS cible_id
						FROM eco_src.t_unites src
						JOIN eco.t_unites ON src.code = t_unites.code) sub
				WHERE unite_distribution_id = source_id + [IPX]
				.,
				UPDATE eco.t_articles SET unite_stockage_id = cible_id
				FROM (
					SELECT src.oid AS source_id, t_unites.oid AS cible_id
						FROM eco_src.t_unites src
						JOIN eco.t_unites ON src.code = t_unites.code) sub
				WHERE unite_stockage_id = source_id + [IPX]
				.,
				UPDATE eco.t_unites
				SET code = 	SUBSTR(code,STRPOS(code,''_'')+1) 
				WHERE oid BETWEEN [IPX] AND [IPX] + 9999999999',1)
				WHERE (SELECT valeur FROM eco.t_divers WHERE code = 'MERGE_UNI') = 1
				;
				
				SELECT base.cti_execute('UPDATE eco.t_articles SET categorie_id = cible_id
				FROM (
					SELECT src.oid AS source_id, t_categories_articles.oid AS cible_id
						FROM eco_src.t_categories_articles src
						JOIN eco.t_categories_articles ON src.code = t_categories_articles.code) sub
				WHERE categorie_id = source_id + [IPX]
				.,
				UPDATE eco.t_articles SET sous_categorie_id = cible_id
				FROM (
					SELECT src.oid AS source_id, t_sous_categories_articles.oid AS cible_id
						FROM eco_src.t_sous_categories_articles src
						JOIN eco.t_sous_categories_articles ON src.code = t_sous_categories_articles.code) sub
				WHERE sous_categorie_id = source_id + [IPX]
				.,
				UPDATE eco.t_categories_articles
				SET code = 	SUBSTR(code,STRPOS(code,''_'')+1) 
				WHERE oid BETWEEN [IPX] AND [IPX] + 9999999999
				.,
				UPDATE eco.t_sous_categories_articles
				SET code = 	SUBSTR(code,STRPOS(code,''_'')+1) 
				WHERE oid BETWEEN [IPX] AND [IPX] + 9999999999
				',1)
				WHERE (SELECT valeur FROM eco.t_divers WHERE code = 'MERGE_CAT') = 1
				;
				
				SELECT base.cti_execute('UPDATE eco.t_articles SET famille_id = cible_id
				FROM (
					SELECT src.oid AS source_id, t_familles_articles.oid AS cible_id
						FROM eco_src.t_familles_articles src
						JOIN eco.t_familles_articles ON src.code = t_familles_articles.code) sub
				WHERE famille_id = source_id + [IPX]
				.,
				UPDATE eco.t_articles SET sous_famille_id = cible_id
				FROM (
					SELECT src.oid AS source_id, t_sous_familles_articles.oid AS cible_id
						FROM eco_src.t_sous_familles_articles src
						JOIN eco.t_sous_familles_articles ON src.code = t_sous_familles_articles.code) sub
				WHERE sous_famille_id = source_id + [IPX]
				.,
				UPDATE eco.t_familles_articles
				SET code = 	SUBSTR(code,STRPOS(code,''_'')+1) 
				WHERE oid BETWEEN [IPX] AND [IPX] + 9999999999
				.,
				UPDATE eco.t_sous_familles_articles
				SET code = 	SUBSTR(code,STRPOS(code,''_'')+1) 
				WHERE oid BETWEEN [IPX] AND [IPX] + 9999999999
				',1)
				WHERE (SELECT valeur FROM eco.t_divers WHERE code = 'MERGE_FAM') = 1
				;
				
				SELECT base.cti_execute('UPDATE eco.t_articles SET type_id = cible_id
				FROM (
					SELECT src.oid AS source_id, t_types_articles.oid AS cible_id
						FROM eco_src.t_types_articles src
						JOIN eco.t_types_articles ON src.code = t_types_articles.code) sub
				WHERE type_id = source_id + [IPX]
				.,
				UPDATE eco.t_types_articles
				SET code = 	SUBSTR(code,STRPOS(code,''_'')+1) 
				WHERE oid BETWEEN [IPX] AND [IPX] + 9999999999
				',1)
				WHERE (SELECT valeur FROM eco.t_divers WHERE code = 'MERGE_TYP') = 1
				;
				
				SELECT base.cti_execute('UPDATE eco.p_mouvements_articles SET lieu_id = cible_id
				FROM (
					SELECT src.oid AS source_id, t_lieux.oid AS cible_id
						FROM eco_src.t_lieux src
						JOIN eco.t_lieux ON t_lieux.code_original NOT LIKE ''[TPX]%'' AND (src.code = t_lieux.code OR src.texte = t_lieux.texte)) sub
				WHERE lieu_id = source_id + [IPX]
				.,
				UPDATE eco.p_commandes SET lieu_commande_id = cible_id
				FROM (
					SELECT src.oid AS source_id, t_lieux.oid AS cible_id
						FROM eco_src.t_lieux src
						JOIN eco.t_lieux ON t_lieux.code_original NOT LIKE ''[TPX]%'' AND (src.code = t_lieux.code OR src.texte = t_lieux.texte)) sub
				WHERE lieu_commande_id = source_id + [IPX]
				.,
				UPDATE eco.p_commandes SET lieu_livraison_id = cible_id
				FROM (
					SELECT src.oid AS source_id, t_lieux.oid AS cible_id
						FROM eco_src.t_lieux src
						JOIN eco.t_lieux ON t_lieux.code_original NOT LIKE ''[TPX]%'' AND (src.code = t_lieux.code OR src.texte = t_lieux.texte)) sub
				WHERE lieu_livraison_id = source_id + [IPX]
				.,
				UPDATE eco.p_commandes SET lieu_facturation_id = cible_id
				FROM (
					SELECT src.oid AS source_id, t_lieux.oid AS cible_id
						FROM eco_src.t_lieux src
						JOIN eco.t_lieux ON t_lieux.code_original NOT LIKE ''[TPX]%'' AND (src.code = t_lieux.code OR src.texte = t_lieux.texte)) sub
				WHERE lieu_facturation_id = source_id + [IPX]
				.,
				UPDATE eco.p_stock SET lieu_id = cible_id
				FROM (
					SELECT src.oid AS source_id, t_lieux.oid AS cible_id
						FROM eco_src.t_lieux src
						JOIN eco.t_lieux ON t_lieux.code_original NOT LIKE ''[TPX]%'' AND (src.code = t_lieux.code OR src.texte = t_lieux.texte)) sub
				WHERE lieu_id = source_id + [IPX]
				.,
				--UPDATE eco.t_lieux
				--SET code = 	SUBSTR(code,STRPOS(code,''_'')+1) 
				--WHERE oid BETWEEN [IPX] AND [IPX] + 9999999999
				',1)
				WHERE (SELECT valeur FROM eco.t_divers WHERE code = 'MERGE_LIE') = 1
				;
				
				SELECT base.cti_execute('UPDATE eco.p_mouvements_articles SET site_id = cible_id
				FROM (
					SELECT src.oid AS source_id, t_sites.oid AS cible_id
						FROM eco_src.t_sites src
						JOIN eco.t_sites ON src.code = t_sites.code) sub
				WHERE site_id = source_id + [IPX]
				.,
				UPDATE eco.p_commandes SET site_id = cible_id
				FROM (
					SELECT src.oid AS source_id, t_sites.oid AS cible_id
						FROM eco_src.t_sites src
						JOIN eco.t_sites ON src.code = t_sites.code) sub
				WHERE site_id = source_id + [IPX]
				.,
				UPDATE eco.p_stock SET site_id = cible_id
				FROM (
					SELECT src.oid AS source_id, t_sites.oid AS cible_id
						FROM eco_src.t_sites src
						JOIN eco.t_sites ON src.code = t_sites.code) sub
				WHERE site_id = source_id + [IPX]
				.,
				UPDATE eco.t_sites
				SET code = 	SUBSTR(code,STRPOS(code,''_'')+1) 
				WHERE oid BETWEEN [IPX] AND [IPX] + 9999999999',1)
				WHERE (SELECT valeur FROM eco.t_divers WHERE code = 'MERGE_SIT') = 1
				;
			
				SELECT base.cti_execute('UPDATE eco.p_mouvements_articles SET gestionnaire_id = cible_id
				FROM (
					SELECT src.oid AS source_id, t_gestionnaires.oid AS cible_id
						FROM eco_src.t_gestionnaires src
						JOIN eco.t_gestionnaires ON UPPER(src.code) = UPPER(t_gestionnaires.code)) sub
				WHERE gestionnaire_id = source_id + [IPX]
				.,
				UPDATE eco.p_commandes SET gestionnaire_id = cible_id
				FROM (
					SELECT src.oid AS source_id, t_gestionnaires.oid AS cible_id
						FROM eco_src.t_gestionnaires src
						JOIN eco.t_gestionnaires ON UPPER(src.code) = UPPER(t_gestionnaires.code)) sub
				WHERE gestionnaire_id = source_id + [IPX]
				.,
				UPDATE eco.t_gestionnaires
				SET code = 	SUBSTR(code,STRPOS(code,''_'')+1) 
				WHERE oid BETWEEN [IPX] AND [IPX] + 9999999999',1)
				WHERE (SELECT valeur FROM eco.t_divers WHERE code = 'MERGE_GES') = 1
				;
				
				SELECT base.cti_execute('UPDATE eco.p_commandes SET fournisseur_id = cible_id
				FROM (
					SELECT src.oid AS source_id, t_fournisseurs.oid AS cible_id
						FROM eco_src.t_fournisseurs src
						JOIN eco.t_fournisseurs ON src.code = t_fournisseurs.code) sub
				WHERE fournisseur_id = source_id + [IPX]
				.,
				UPDATE eco.p_lignes_commandes SET fournisseur_distributeur_id = cible_id
				FROM (
					SELECT src.oid AS source_id, t_fournisseurs.oid AS cible_id
						FROM eco_src.t_fournisseurs src
						JOIN eco.t_fournisseurs ON src.code = t_fournisseurs.code) sub
				WHERE fournisseur_distributeur_id = source_id + [IPX]
				.,
				UPDATE eco.t_articles SET fournisseur_principal_id = cible_id
				FROM (
					SELECT src.oid AS source_id, t_fournisseurs.oid AS cible_id
						FROM eco_src.t_fournisseurs src
						JOIN eco.t_fournisseurs ON src.code = t_fournisseurs.code) sub
				WHERE fournisseur_principal_id = source_id + [IPX]
				.,
				UPDATE eco.p_mouvements_articles SET fournisseur_id = cible_id
				FROM (
						SELECT src.oid AS source_id, t_fournisseurs.oid AS cible_id
						FROM eco_src.t_fournisseurs src
						JOIN eco.t_fournisseurs ON src.code = t_fournisseurs.code) sub
				WHERE fournisseur_id = source_id + [IPX]
				.,
				',1)
				WHERE (SELECT valeur FROM eco.t_divers WHERE code = 'MERGE_FOU') = 1;
				
				
			
			]]></sqlcmd>
		</NODE>
		<!-- spécifique Europe pour fusion 1 ancien prestataire avec 3 nouveaux prestataire -->
		<NODE label="Forcage Lieux">
			<condition><![CDATA[
				
				SELECT count(*) > 0 
				FROM base.t_finess
				WHERE 1=1
					AND code = '440002020'
            ;
			]]></condition>	
			<sqlcmd><![CDATA[
				UPDATE eco.p_mouvements_articles SET lieu_id = (SELECT oid from eco.t_lieux WHERE CODE = '2' AND oid < 1000000)
				WHERE provider_id = 1;
				UPDATE eco.p_stock SET lieu_id = (SELECT oid from eco.t_lieux WHERE CODE = '2' AND oid < 1000000)
				WHERE provider_id = 1;
				UPDATE eco.p_commandes SET lieu_commande_id = (SELECT oid from eco.t_lieux WHERE CODE = '2' AND oid < 1000000)
				WHERE provider_id = 1;
				UPDATE eco.p_commandes SET lieu_facturation_id = (SELECT oid from eco.t_lieux WHERE CODE = '2' AND oid < 1000000)
				WHERE provider_id = 1;
				UPDATE eco.p_commandes SET lieu_livraison_id = (SELECT oid from eco.t_lieux WHERE CODE = '2' AND oid < 1000000)
				WHERE provider_id = 1;
			]]></sqlcmd>
		</NODE>
	</NODE>
	<NODE name="VACUUM" label="REORGANISATION BASE DE DONNEES">
		<NODE name="VACUUM" type="common" />
	</NODE>
	<NODE name="RAZ" label="RAZ BASE">
		<NODE name="RAZ" type="common" />
	</NODE>
	<NODE name="RAZ_ALL" label="RAZ ALL">
		<NODE name="RAZ_ALL" type="common" />
	</NODE>
</ROOT>
