0 AND IDUNITE::text NOT IN (SELECT code_original FROM eco.t_unites WHERE code_original IS NOT NULL); -- LPP -- UCD INSERT INTO base.t_ucd (code, texte, texte_court, laboratoire_texte, conditionnement_texte) SELECT CODE_UCD_7, CODE_UCD_7, CODE_UCD_7, '', '' FROM prod_evolucare_hygie.ARTICLES WHERE CODE_UCD_7 <> '' AND CODE_UCD_7 NOT IN (SELECT code FROM base.t_ucd WHERE code IS NOT NULL) GROUP BY 1; -- ATC INSERT INTO eco.t_classification_atc(code_original, code, texte, texte_court ) SELECT UPPER(CODE_ATC), UPPER(CODE_ATC), MAX(LIBELLE_ATC), MAX(LIBELLE_ATC) FROM prod_evolucare_hygie.ATC LEFT JOIN eco.t_classification_atc ON code_original = UPPER(CODE_ATC) WHERE code_original IS NULL GROUP BY 1 ORDER BY 1; -- Standard ATC SELECT eco.cti_reorganize_classification_atc(); -- Comptes INSERT INTO eco.t_compte(code_original, code, texte, texte_court) SELECT CPTE_ACHAT_FAMI_COMPTA code_original, CPTE_ACHAT_FAMI_COMPTA AS code, MAX(LIB_FAMI_COMPTA) AS texte, MAX(LIB_FAMI_COMPTA) AS texte_court FROM prod_evolucare_hygie.FAMILLES_COMPTA WHERE length(CPTE_ACHAT_FAMI_COMPTA) > 5 AND CPTE_ACHAT_FAMI_COMPTA NOT IN (SELECT code_original FROM eco.t_compte WHERE code_original IS NOT NULL) AND CODE_FAMI_COMPTA IN (SELECT CODE_FAMI_COMPTA FROM prod_evolucare_hygie.ARTICLES) GROUP BY 1 ORDER BY 1; -- Types d'articles INSERT INTO eco.t_types_articles(code_original, code, texte, texte_court) SELECT NOMENCLATURE, NOMENCLATURE,NOMENCLATURE, NOMENCLATURE FROM prod_evolucare_hygie.ARTICLES WHERE NOMENCLATURE NOT IN (SELECT code_original FROM eco.t_types_articles WHERE code_original IS NOT NULL) GROUP BY 1,2,3,4 ORDER BY 1; -- Familles d'articles INSERT INTO eco.t_familles_articles(code_original, code, texte, texte_court) SELECT COD_FAMILLE_ART, COD_FAMILLE_ART, MAX(CASE WHEN LIB_FAMILLE_ART <> '' THEN LIB_FAMILLE_ART ELSE COD_FAMILLE_ART END), MAX(CASE WHEN LIB_FAMILLE_ART <> '' THEN LIB_FAMILLE_ART ELSE COD_FAMILLE_ART END) FROM prod_evolucare_hygie.FAMILLE_ARTICLES WHERE COD_FAMILLE_ART <> 0 AND COD_FAMILLE_ART NOT IN (SELECT code_original FROM eco.t_familles_articles WHERE code_original IS NOT NULL) GROUP BY 1,2 ORDER BY 1; UPDATE eco.t_familles_articles SET texte = CASE WHEN LIB_FAMILLE_ART <> '' THEN LIB_FAMILLE_ART ELSE COD_FAMILLE_ART END, texte_court = CASE WHEN LIB_FAMILLE_ART <> '' THEN LIB_FAMILLE_ART ELSE COD_FAMILLE_ART END FROM prod_evolucare_hygie.FAMILLE_ARTICLES WHERE COD_FAMILLE_ART = code_original AND (texte IS DISTINCT FROM CASE WHEN LIB_FAMILLE_ART <> '' THEN LIB_FAMILLE_ART ELSE COD_FAMILLE_ART END OR texte_court IS DISTINCT FROM CASE WHEN LIB_FAMILLE_ART <> '' THEN LIB_FAMILLE_ART ELSE COD_FAMILLE_ART END); -- Sous familles INSERT INTO eco.t_sous_familles_articles(code_original, code, texte, texte_court) SELECT COD_FAMILLE_ART, COD_FAMILLE_ART, MAX(CASE WHEN LIB_FAMILLE_ART <> '' THEN LIB_FAMILLE_ART ELSE COD_FAMILLE_ART END), MAX(CASE WHEN LIB_FAMILLE_ART <> '' THEN LIB_FAMILLE_ART ELSE COD_FAMILLE_ART END) FROM prod_evolucare_hygie.FAMILLE_ARTICLES WHERE COD_FAMILLE_ART <> 0 AND LIB_FAMILLE_ART <> '' AND COD_FAMILLE_ART NOT IN (SELECT code_original FROM eco.t_sous_familles_articles WHERE code_original IS NOT NULL) GROUP BY 1,2 ORDER BY 1; UPDATE eco.t_sous_familles_articles SET texte = CASE WHEN LIB_FAMILLE_ART <> '' THEN LIB_FAMILLE_ART ELSE COD_FAMILLE_ART END, texte_court = CASE WHEN LIB_FAMILLE_ART <> '' THEN LIB_FAMILLE_ART ELSE COD_FAMILLE_ART END FROM prod_evolucare_hygie.FAMILLE_ARTICLES WHERE COD_FAMILLE_ART = code_original AND (texte IS DISTINCT FROM CASE WHEN LIB_FAMILLE_ART <> '' THEN LIB_FAMILLE_ART ELSE COD_FAMILLE_ART END OR texte_court IS DISTINCT FROM CASE WHEN LIB_FAMILLE_ART <> '' THEN LIB_FAMILLE_ART ELSE COD_FAMILLE_ART END); -- Catégories INSERT INTO eco.t_categories_articles(code_original, code, texte, texte_court) SELECT IDTYPE_PRODUIT, CODE_TYPE_PROD,LIBELLLE_TYPE_PROD, LEFT(LIBELLLE_TYPE_PROD,50) FROM prod_evolucare_hygie.TYPE_PRODUIT WHERE IDTYPE_PRODUIT NOT IN (SELECT code_original FROM eco.t_categories_articles WHERE code_original IS NOT NULL) GROUP BY 1,2,3,4 ORDER BY 1; -- Sous catégories -- Articles INSERT INTO eco.t_articles(code_original, code, texte, texte_court) SELECT REF_ART_INT, REF_ART_INT, DESIGN_USUELLE, substr(DESIGN_USUELLE,1,50) FROM prod_evolucare_hygie.ARTICLES LEFT JOIN eco.t_articles ON (code_original = REF_ART_INT) WHERE code_original IS NULL; UPDATE eco.t_articles SET texte = DESIGN_USUELLE, texte_court = substr(DESIGN_USUELLE,1,50) FROM prod_evolucare_hygie.ARTICLES WHERE code_original = REF_ART_INT AND ( texte IS DISTINCT FROM DESIGN_USUELLE OR texte_court IS DISTINCT FROM substr(DESIGN_USUELLE,1,50)) ; UPDATE eco.t_articles SET type_id = COALESCE(t_types_articles.oid,0), famille_id = COALESCE(t_familles_articles.oid,0), sous_famille_id = COALESCE(t_sous_familles_articles.oid,0), categorie_id = COALESCE(t_categories_articles.oid,0), sous_categorie_id = COALESCE(t_sous_categories_articles.oid,0), classification_atc_id = COALESCE(t_classification_atc.oid,0), unite_stockage_id = COALESCE(t_unites_stockage.oid,0), unite_distribution_id = COALESCE(t_unites_distribution.oid,0), lpp_id = COALESCE(t_lpp.oid,0), ucd_id = COALESCE(t_ucd.oid,0) FROM prod_evolucare_hygie.ARTICLES LEFT JOIN prod_evolucare_hygie.FAMILLE_ARTICLES ON ARTICLES.COD_FAMILLE_ART::text = FAMILLE_ARTICLES.COD_FAMILLE_ART LEFT JOIN eco.t_familles_articles ON CASE WHEN ARTICLES.SOUS_FAMILLE <> '' THEN ARTICLES.SOUS_FAMILLE ELSE FAMILLE_ARTICLES.COD_FAMILLE_ART::text END = t_familles_articles.code_original LEFT JOIN eco.t_sous_familles_articles ON FAMILLE_ARTICLES.COD_FAMILLE_ART = t_sous_familles_articles.code_original LEFT JOIN eco.t_types_articles ON NOMENCLATURE = upper(t_types_articles.code_original) LEFT JOIN eco.t_classification_atc ON CODE_ATC = upper(t_classification_atc.code_original) LEFT JOIN eco.t_categories_articles ON TYPE_DE_PRODUIT = t_categories_articles.code_original LEFT JOIN eco.t_sous_categories_articles ON t_sous_categories_articles.oid = 0 LEFT JOIN eco.t_unites t_unites_stockage ON t_unites_stockage.oid = 0 LEFT JOIN eco.t_unites t_unites_distribution ON t_unites_distribution.oid = 0 LEFT JOIN base.t_lpp ON t_lpp.oid = 0 LEFT JOIN base.t_ucd ON CODE_UCD_7 = t_ucd.code WHERE t_articles.code_original = REF_ART_INT AND (t_articles.type_id IS DISTINCT FROM COALESCE(t_types_articles.oid,0) OR t_articles.famille_id IS DISTINCT FROM COALESCE(t_familles_articles.oid,0) OR t_articles.sous_famille_id IS DISTINCT FROM COALESCE(t_sous_familles_articles.oid,0) OR t_articles.categorie_id IS DISTINCT FROM COALESCE(t_categories_articles.oid,0) OR t_articles.sous_categorie_id IS DISTINCT FROM COALESCE(t_sous_categories_articles.oid,0) OR t_articles.classification_atc_id IS DISTINCT FROM COALESCE(t_classification_atc.oid,0) OR t_articles.unite_stockage_id IS DISTINCT FROM COALESCE(t_unites_stockage.oid,0) OR t_articles.unite_distribution_id IS DISTINCT FROM COALESCE(t_unites_distribution.oid,0) OR lpp_id IS DISTINCT FROM COALESCE(t_lpp.oid,0) OR ucd_id IS DISTINCT FROM COALESCE(t_ucd.oid,0) ); UPDATE eco.t_articles SET compte_id = COALESCE(t_compte.oid,0) FROM prod_evolucare_hygie.ARTICLES LEFT JOIN prod_evolucare_hygie.FAMILLES_COMPTA ON ARTICLES.CODE_FAMI_COMPTA = FAMILLES_COMPTA.CODE_FAMI_COMPTA LEFT JOIN eco.t_compte ON CPTE_ACHAT_FAMI_COMPTA = t_compte.code_original WHERE t_articles.code_original = REF_ART_INT AND ( t_articles.compte_id IS DISTINCT FROM COALESCE(t_compte.oid,0) ); UPDATE eco.t_articles SET compte_id = 0 WHERE compte_id IS NULL; UPDATE eco.t_articles SET gere_en_stock = '1' FROM prod_evolucare_hygie.ARTICLES WHERE REF_ART_INT = code_original AND gere_en_stock != '1' ; 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 ); ]]> '' THEN REF_ART_FOURN ELSE REF_ART_INT END AS ref_fournisseur_texte FROM eco.t_articles JOIN prod_evolucare_hygie.ARTICLES ON REF_ART_INT = t_articles.code_original JOIN eco.t_fournisseurs ON CODE_FOURN = t_fournisseurs.code GROUP BY 1,2,3 ORDER BY 1,2,3 ) subview GROUP BY 1 ) subview WHERE t_articles.oid = subview.article_id AND ( t_articles.ref_fournisseur_id IS DISTINCT FROM subview.ref_fournisseur_id OR t_articles.ref_fournisseur_texte IS DISTINCT FROM subview.ref_fournisseur_texte ) ; ]]> = '[ENV_ECO_ANNEEDEBUT]-01-01' ORDER BY 1; SELECT base.cti_enable_index('eco', 'i_commandes_1'); SELECT base.cti_enable_index('eco', 'i_commandes_2'); SELECT base.cti_enable_index('eco', 'i_commandes_3'); SELECT base.cti_enable_index('eco', 'i_commandes_4'); SELECT base.cti_enable_index('eco', 'i_commandes_5'); SELECT base.cti_enable_index('eco', 'i_commandes_6'); SELECT base.cti_enable_index('eco', 'i_commandes_7'); SELECT base.cti_enable_index('eco', 'i_commandes_8'); SELECT base.cti_disable_index('eco', 'i_ligne_commandes_1'); SELECT base.cti_disable_index('eco', 'i_ligne_commandes_2'); SELECT base.cti_disable_index('eco', 'i_ligne_commandes_3'); DROP TABLE IF EXISTS w_LIGNECDE_FOURN; CREATE TEMP TABLE w_LIGNECDE_FOURN AS SELECT *, 0::numeric AS QTE_LIGNELIV_FOURN FROM prod_evolucare_hygie.LIGNECDE_FOURN ; UPDATE w_LIGNECDE_FOURN LIGNECDE_FOURN SET QTE_LIGNELIV_FOURN = subview.QTE_LIGNELIV_FOURN FROM ( SELECT LIGNELIV_FOURN.IDLIGNECDE_FOURN_INCHANGEABLE, SUM(QTE_LIGNELIV_FOURN) AS QTE_LIGNELIV_FOURN FROM prod_evolucare_hygie.LIV_FOURN JOIN prod_evolucare_hygie.LIGNELIV_FOURN ON LIV_FOURN.NUM_LIV_FOURN = LIGNELIV_FOURN.NUM_LIV_FOURN JOIN prod_evolucare_hygie.LIGNECDE_FOURN ON LIGNELIV_FOURN.IDLIGNECDE_FOURN_INCHANGEABLE = LIGNECDE_FOURN.IDLIGNECDE_FOURN_INCHANGEABLE GROUP BY 1 ) subview WHERE subview.IDLIGNECDE_FOURN_INCHANGEABLE = LIGNECDE_FOURN.IDLIGNECDE_FOURN_INCHANGEABLE ; UPDATE w_LIGNECDE_FOURN LIGNECDE_FOURN SET QTE_LIGNELIV_FOURN = QTE_LIGNECDE_FOURN WHERE QTE_LIGNELIV_FOURN <> QTE_LIGNECDE_FOURN AND QTE_LIGNELIV_FOURN = QTE_LIGNECDE_FOURN * COND1_LIGNECDE_FOURN ; TRUNCATE eco.p_lignes_commandes; INSERT INTO eco.p_lignes_commandes( code_original, commande_id, ligne_commande, texte, article_id, unite_approvisionnement_id, compte_id, ucd_id, lpp_id, quantite_approvisionnement, prix_unitaire_approvisionnement, multiplicateur_stockage, quantite_stockage, prix_unitaire_stockage, montant_commande_ht, montant_commande_remise, montant_commande_tva, montant_commande_port, montant_commande_ttc, quantite_livraison_approvisionnement, quantite_livraison_stockage, montant_livraison_ht, montant_livraison_ttc, etat_livraison, montant_liquidation_ht, montant_liquidation_remise, montant_liquidation_tva, montant_liquidation_port, montant_liquidation_ttc, etat_liquidation, taux_prorata_tva) SELECT IDLIGNECDE_FOURN_INCHANGEABLE AS code_original, p_commandes.oid AS commande_id, NUMLI_LIGNECDE_FOURN::numeric AS ligne_commande, LIB_LIGNECDE_FOURN AS texte, COALESCE(t_articles.oid, 0) AS article_id, 0::bigint AS unite_approvisionnement_id, t_articles.compte_id, COALESCE(t_ucd.oid, t_articles.ucd_id, 0) AS ucd_id, COALESCE(t_lpp.oid, t_articles.lpp_id, 0) AS lpp_id, QTE_LIGNECDE_FOURN AS quantite_approvisionnement, PA_LIGNECDE_FOURN AS prix_unitaire_approvisionnement, 0::numeric AS multiplicateur_stockage, 0::numeric AS quantite_stockage, 0::numeric AS prix_unitaire_stockage, round(QTE_LIGNECDE_FOURN::numeric * PA_LIGNECDE_FOURN::numeric,2) AS montant_commande_ht, 0::numeric AS montant_commande_remise, round(QTE_LIGNECDE_FOURN::numeric * PA_LIGNECDE_FOURN::numeric * VAL_TVA_LIGNECDE_FOURN / 100,2) AS montant_commande_tva, 0::numeric AS montant_commande_port, round(QTE_LIGNECDE_FOURN::numeric * PA_LIGNECDE_FOURN::numeric,2) + round(QTE_LIGNECDE_FOURN::numeric * PA_LIGNECDE_FOURN::numeric * VAL_TVA_LIGNECDE_FOURN / 100,2) AS montant_commande_ttc, QTE_LIGNELIV_FOURN AS quantite_livraison_approvisionnement, QTE_LIGNELIV_FOURN AS quantite_livraison_stockage, round(QTE_LIGNELIV_FOURN::numeric * PA_LIGNECDE_FOURN::numeric,2) AS montant_livraison_ht, round(QTE_LIGNELIV_FOURN::numeric * PA_LIGNECDE_FOURN::numeric,2) + round(QTE_LIGNELIV_FOURN::numeric * PA_LIGNECDE_FOURN::numeric * VAL_TVA_LIGNECDE_FOURN / 100,2) AS montant_livraison_ttc, CASE WHEN QTE_LIGNELIV_FOURN = QTE_LIGNECDE_FOURN THEN 'T' WHEN QTE_LIGNELIV_FOURN > QTE_LIGNECDE_FOURN THEN 'S' WHEN QTE_LIGNELIV_FOURN = 0 THEN 'N' ELSE 'P' END AS etat_livraison, 0::numeric AS montant_liquidation_ht, 0::numeric AS montant_liquidation_remise, 0::numeric AS montant_liquidation_tva, 0::numeric AS montant_liquidation_port, 0::numeric AS montant_liquidation_ttc, 'T', 0::numeric FROM w_LIGNECDE_FOURN LIGNECDE_FOURN JOIN eco.p_commandes ON LIGNECDE_FOURN.NUM_CDE_FOURN = p_commandes.code_original LEFT JOIN eco.t_articles ON REF_ART_INT = t_articles.code_original AND t_articles.oid != 0 LEFT JOIN base.t_ucd ON ucd_id = t_ucd.oid AND t_ucd.oid != 0 LEFT JOIN base.t_lpp ON lpp_id = t_lpp.oid AND t_lpp.oid != 0 LEFT JOIN eco.t_prorata_tva ON p_commandes.date_engagement BETWEEN t_prorata_tva.date_debut AND t_prorata_tva.date_fin ; UPDATE eco.p_commandes SET montant_commande_ht = subview.montant_commande_ht, montant_commande_tva = subview.montant_commande_tva, montant_commande_total = subview.montant_commande_ttc, etat_reception = subview.etat_livraison FROM ( SELECT commande_id, SUM(p_lignes_commandes.montant_commande_ht) AS montant_commande_ht, SUM(p_lignes_commandes.montant_commande_tva) AS montant_commande_tva, SUM(p_lignes_commandes.montant_commande_ttc) AS montant_commande_ttc, MIN(CASE WHEN etat_livraison NOT IN ('S','T') THEN 'N' ELSE 'T' END) AS etat_livraison FROM eco.p_lignes_commandes GROUP BY 1 ) subview WHERE commande_id = p_commandes.oid ; SELECT base.cti_enable_index('eco', 'i_ligne_commandes_1'); SELECT base.cti_enable_index('eco', 'i_ligne_commandes_2'); SELECT base.cti_enable_index('eco', 'i_ligne_commandes_3'); ]]> = date('[ENV_ECO_ANNEEDEBUT]-01-01') ORDER BY LIV_FOURN.DATE_LIV_FOURN ; INSERT INTO eco.p_mouvements_articles( date, sens_mouvement, type_mouvement_id, texte, gestionnaire_id, lieu_id, unite_fonctionnelle_id, article_id, compte_id, fournisseur_id, commande_id, ligne_commande, lpp_id, ucd_id, prix_unitaire, entree_quantite, entree_montant, entree_montant_ht, sortie_quantite, sortie_montant, sortie_montant_ht) SELECT DATE(LIV_FOURN.DATE_LIV_FOURN) AS date, 'E' AS sens_mouvement, COALESCE(t_types_mouvements.oid,0) AS type_mouvement_id, t_types_mouvements.texte || ' ' || NUM_RETOUR_FOURN || '-' || t_articles.code AS texte, COALESCE(t_gestionnaires.oid,0) AS gestionnaire_id, COALESCE(t_lieux.oid,0) AS lieu_id, COALESCE(t_unites_fonctionnelles.oid,0) AS unite_fonctionnelle_id, COALESCE(t_articles.oid,0) AS article_id, COALESCE(t_articles.compte_id,0) AS compte_id, COALESCE(t_fournisseurs.oid,t_articles.fournisseur_principal_id,0) AS fournisseur_id, COALESCE(p_commandes.oid,0) AS commande_id, COALESCE(p_lignes_commandes.ligne_commande,0) AS ligne_commande, COALESCE(t_articles.lpp_id,0) AS lppid, COALESCE(t_articles.ucd_id,0) AS ucd_id, PMP AS prix_unitaire, QTE_LIGNELIV_FOURN AS entree_quantite, (QTE_LIGNELIV_FOURN * PA_LIGNELIV_FOURN) + (QTE_LIGNELIV_FOURN * PA_LIGNELIV_FOURN * VAL_TVA_LIGNELIV_FOURN / 100) AS entree_montant, QTE_LIGNELIV_FOURN * PA_LIGNELIV_FOURN AS entree_montant_ht, 0::numeric AS sortie_quantite, 0::numeric AS sortie_montant, 0::numeric AS sortie_montant_ht FROM prod_evolucare_hygie.LIGNELIV_RETOUR_FOURN JOIN prod_evolucare_hygie.LIV_FOURN ON LIGNELIV_RETOUR_FOURN.NUM_LIV_FOURN = LIV_FOURN.NUM_LIV_FOURN LEFT JOIN eco.p_lignes_commandes ON 'XXX' = p_lignes_commandes.code_original LEFT JOIN eco.p_commandes ON 'XXX' = p_commandes.code_original LEFT JOIN eco.t_types_mouvements ON 'RET' = t_types_mouvements.code_original LEFT JOIN eco.t_fournisseurs ON LIGNELIV_RETOUR_FOURN.CODE_FOURN = t_fournisseurs.code_original LEFT JOIN eco.t_gestionnaires ON 'XXX' = t_gestionnaires.code_original LEFT JOIN eco.t_lieux ON 'XXX' = t_lieux.code_original LEFT JOIN eco.t_unites_fonctionnelles ON 'XXXX' = t_unites_fonctionnelles.code_original LEFT JOIN eco.t_articles ON LIGNELIV_RETOUR_FOURN.REF_ART_INT = t_articles.code_original AND t_articles.oid != 0 WHERE DATE(LIV_FOURN.DATE_LIV_FOURN) >= date('[ENV_ECO_ANNEEDEBUT]-01-01') ORDER BY LIV_FOURN.DATE_LIV_FOURN ; INSERT INTO eco.p_mouvements_articles( date, sens_mouvement, type_mouvement_id, texte, gestionnaire_id, lieu_id, unite_fonctionnelle_id, article_id, compte_id, fournisseur_id, commande_id, ligne_commande, lpp_id, ucd_id, prix_unitaire, entree_quantite, entree_montant, entree_montant_ht, sortie_quantite, sortie_montant, sortie_montant_ht) SELECT DATE(DATE_LIV_CLIENT) AS date, 'S' AS sens_mouvement, COALESCE(t_types_mouvements.oid,0) AS type_mouvement_id, TITRE_LIV_CLIENT || ' ' || LIGNELIV_CLI.NUM_LIV_CLIENT || '-' || NUMLI_LIGNELIV_CLIENT AS texte, COALESCE(t_gestionnaires.oid,0) AS gestionnaire_id, COALESCE(t_lieux.oid,0) AS lieu_id, COALESCE(t_unites_fonctionnelles.oid,0) AS unite_fonctionnelle_id, COALESCE(t_articles.oid,0) AS article_id, COALESCE(t_articles.compte_id,0) AS compte_id, COALESCE(t_articles.fournisseur_principal_id,0) AS fournisseur_id, COALESCE(p_commandes.oid,0) AS commande_id, 0 AS ligne_commande, COALESCE(t_articles.lpp_id,0) AS lppid, COALESCE(t_articles.ucd_id,0) AS ucd_id, PMP AS prix_unitaire, 0::numeric AS entree_quantite, 0::numeric AS entree_montant, 0::numeric AS entree_montant_ht, QTE_LIGNELIV_CLIENT AS sortie_quantite, (QTE_LIGNELIV_CLIENT * PMP) + (QTE_LIGNELIV_CLIENT * PMP * VAL_TVA_LIGNELIV_CLIENT / 100) AS sortie_montant, QTE_LIGNELIV_CLIENT * PMP AS sortie_montant_ht FROM prod_evolucare_hygie.LIGNELIV_CLI JOIN prod_evolucare_hygie.LIV_CLIENT ON LIGNELIV_CLI.NUM_LIV_CLIENT = LIV_CLIENT.NUM_LIV_CLIENT LEFT JOIN eco.p_commandes ON 'XXX' = p_commandes.code_original LEFT JOIN eco.t_types_mouvements ON 'LIV' = t_types_mouvements.code_original LEFT JOIN eco.t_gestionnaires ON 'XXX' = t_gestionnaires.code_original LEFT JOIN eco.t_lieux ON 'XXX' = t_lieux.code_original LEFT JOIN eco.t_unites_fonctionnelles ON CODE_CLIENT = t_unites_fonctionnelles.code_original LEFT JOIN eco.t_articles ON LIGNELIV_CLI.REF_ART_INT = t_articles.code_original AND t_articles.oid != 0 WHERE DATE(DATE_LIV_CLIENT) >= date('[ENV_ECO_ANNEEDEBUT]-01-01') ORDER BY DATE_LIV_CLIENT; INSERT INTO eco.p_mouvements_articles( date, sens_mouvement, type_mouvement_id, texte, gestionnaire_id, lieu_id, unite_fonctionnelle_id, article_id, compte_id, fournisseur_id, commande_id, ligne_commande, lpp_id, ucd_id, prix_unitaire, entree_quantite, entree_montant, entree_montant_ht, sortie_quantite, sortie_montant, sortie_montant_ht) SELECT DATE(LIGNELIV_CLI_SUPPR.DATE_LIV_CLIENT) AS date, 'S' AS sens_mouvement, COALESCE(t_types_mouvements.oid,0) AS type_mouvement_id, TITRE_LIV_CLIENT || ' ' || LIGNELIV_CLI_SUPPR.NUM_LIV_CLIENT || '-' || NUMLI_LIGNELIV_CLIENT AS texte, COALESCE(t_gestionnaires.oid,0) AS gestionnaire_id, COALESCE(t_lieux.oid,0) AS lieu_id, COALESCE(t_unites_fonctionnelles.oid,0) AS unite_fonctionnelle_id, COALESCE(t_articles.oid,0) AS article_id, COALESCE(t_articles.compte_id,0) AS compte_id, COALESCE(t_articles.fournisseur_principal_id,0) AS fournisseur_id, COALESCE(p_commandes.oid,0) AS commande_id, 0 AS ligne_commande, COALESCE(t_articles.lpp_id,0) AS lppid, COALESCE(t_articles.ucd_id,0) AS ucd_id, PA_LIGNELIV_CLIENT AS prix_unitaire, 0::numeric AS entree_quantite, 0::numeric AS entree_montant, 0::numeric AS entree_montant_ht, QTE_LIGNELIV_CLIENT AS sortie_quantite, (QTE_LIGNELIV_CLIENT * PA_LIGNELIV_CLIENT) + (QTE_LIGNELIV_CLIENT * PA_LIGNELIV_CLIENT * VAL_TVA_LIGNELIV_CLIENT / 100) AS sortie_montant, QTE_LIGNELIV_CLIENT * PA_LIGNELIV_CLIENT AS sortie_montant_ht FROM prod_evolucare_hygie.LIGNELIV_CLI_SUPPR JOIN prod_evolucare_hygie.LIV_CLIENT ON LIGNELIV_CLI_SUPPR.NUM_LIV_CLIENT = LIV_CLIENT.NUM_LIV_CLIENT LEFT JOIN eco.p_commandes ON 'XXX' = p_commandes.code_original LEFT JOIN eco.t_types_mouvements ON 'LIV' = t_types_mouvements.code_original LEFT JOIN eco.t_gestionnaires ON 'XXX' = t_gestionnaires.code_original LEFT JOIN eco.t_lieux ON 'XXX' = t_lieux.code_original LEFT JOIN eco.t_unites_fonctionnelles ON LIGNELIV_CLI_SUPPR.CODE_CLIENT = t_unites_fonctionnelles.code_original LEFT JOIN eco.t_articles ON LIGNELIV_CLI_SUPPR.REF_ART_INT = t_articles.code_original AND t_articles.oid != 0 WHERE DATE(LIGNELIV_CLI_SUPPR.DATE_LIV_CLIENT) >= date('[ENV_ECO_ANNEEDEBUT]-01-01') ORDER BY LIGNELIV_CLI_SUPPR.DATE_LIV_CLIENT; INSERT INTO eco.p_mouvements_articles( date, sens_mouvement, type_mouvement_id, texte, gestionnaire_id, lieu_id, unite_fonctionnelle_id, article_id, compte_id, fournisseur_id, commande_id, ligne_commande, lpp_id, ucd_id, prix_unitaire, entree_quantite, entree_montant, entree_montant_ht, sortie_quantite, sortie_montant, sortie_montant_ht) SELECT DATE(DATEHEUREREGUL) AS date, 'S' AS sens_mouvement, COALESCE(t_types_mouvements.oid,0) AS type_mouvement_id, t_types_mouvements.texte || ' ' || t_articles.code AS texte, COALESCE(t_gestionnaires.oid,0) AS gestionnaire_id, COALESCE(t_lieux.oid,0) AS lieu_id, COALESCE(t_unites_fonctionnelles.oid,0) AS unite_fonctionnelle_id, COALESCE(t_articles.oid,0) AS article_id, COALESCE(t_articles.compte_id,0) AS compte_id, COALESCE(t_articles.fournisseur_principal_id,0) AS fournisseur_id, COALESCE(p_commandes.oid,0) AS commande_id, 0 AS ligne_commande, COALESCE(t_articles.lpp_id,0) AS lppid, COALESCE(t_articles.ucd_id,0) AS ucd_id, PMP AS prix_unitaire, 0::numeric AS entree_quantite, 0::numeric AS entree_montant, 0::numeric AS entree_montant_ht, -DIFFERENCESTOCK AS sortie_quantite, (DIFFERENCESTOCK * PMP) + (DIFFERENCESTOCK * PMP * (1+TAUX_TVA) / 100) AS sortie_montant, DIFFERENCESTOCK * PMP AS sortie_montant_ht FROM prod_evolucare_hygie.REGULINVENTAIRE LEFT JOIN prod_evolucare_hygie.TVA ON REGULINVENTAIRE.CODETVA = TVA.CODE_TVA LEFT JOIN eco.p_commandes ON 'XXX' = p_commandes.code_original LEFT JOIN eco.t_types_mouvements ON 'INV' = t_types_mouvements.code_original LEFT JOIN eco.t_gestionnaires ON 'XXX' = t_gestionnaires.code_original LEFT JOIN eco.t_lieux ON 'XXX' = t_lieux.code_original LEFT JOIN eco.t_unites_fonctionnelles ON CODE_CLIENT = t_unites_fonctionnelles.code_original LEFT JOIN eco.t_articles ON REF_ART_INT = t_articles.code_original AND t_articles.oid != 0 WHERE DATE(DATEHEUREREGUL) >= date('[ENV_ECO_ANNEEDEBUT]-01-01') ORDER BY DATEHEUREREGUL; SELECT base.cti_enable_index('eco', 'i_mouvements_articles_1'); SELECT base.cti_enable_index('eco', 'i_mouvements_articles_2'); SELECT base.cti_enable_index('eco', 'i_mouvements_articles_3'); SELECT base.cti_enable_index('eco', 'i_mouvements_articles_4'); SELECT base.cti_enable_index('eco', 'i_mouvements_articles_5'); SELECT base.cti_enable_index('eco', 'i_mouvements_articles_6'); SELECT base.cti_enable_index('eco', 'i_mouvements_articles_7'); SELECT base.cti_enable_index('eco', 'i_mouvements_articles_8'); SELECT base.cti_enable_index('eco', 'i_mouvements_articles_9'); SELECT base.cti_enable_index('eco', 'i_mouvements_articles_10'); UPDATE eco.p_mouvements_articles SET entree_quantite = 0 - entree_quantite, sortie_quantite = 0 - sortie_quantite, entree_montant = 0 - entree_montant, sortie_montant = 0 - sortie_montant, entree_montant_ht = 0 - entree_montant_ht, sortie_montant_ht = 0 - sortie_montant_ht, sortie_montant_original_ttc = 0 - sortie_montant_original_ttc, sortie_montant_original_ht = 0 - sortie_montant_original_ht FROM eco.t_types_mouvements WHERE type_mouvement_id = t_types_mouvements.oid AND t_types_mouvements.particularite_inverser_signe = '1'; UPDATE eco.p_commandes SET date_reception = date FROM ( SELECT commande_id, MAX(date) AS date FROM eco.p_mouvements_articles GROUP BY 1) sub WHERE oid = commande_id ; ]]> 0 ; SELECT base.cti_execute(' INSERT INTO w_stock SELECT w_stock.article_code_original, w_stock.article_id, w_stock.compte_id, w_stock.ucd_id, w_stock.lpp_id, w_stock.fournisseur_id, w_stock.site_id, w_stock.lieu_id, date(date_trunc(''month'',w_stock.date_debut) + interval ''1 month'') AS date_debut, date(date_trunc(''month'',w_stock.date_debut) + interval ''2 month'' - interval ''1 day'') AS date_fin, w_stock.mois_code + 1, 0 AS entree_quantite, 0 AS entree_montant, 0 AS sortie_quantite, 0 AS sortie_montant, 0::numeric AS pump, ''0''::text AS ok_pump, 0::numeric AS stock_quantite_debut, w_stock.stock_quantite_fin, 0::numeric AS stock_valeur_debut, 0::numeric AS stock_valeur_fin FROM w_stock LEFT JOIN w_stock w_stock_next ON w_stock.site_id = w_stock_next.site_id AND w_stock.lieu_id = w_stock_next.lieu_id AND w_stock.article_id = w_stock_next.article_id AND w_stock.mois_code = w_stock_next.mois_code - 1 WHERE w_stock.stock_quantite_fin <> 0 AND w_stock_next.mois_code IS NULL AND w_stock.date_debut <= date(now()) ',200) ; UPDATE w_stock SET ok_pump = '1', pump = PMP, stock_valeur_fin = stock_quantite_fin * PMP FROM ( SELECT REF_ART_INT, date_trunc('month',DATE_LIV_CLIENT) as month, (MAX(ARRAY[DATE_LIV_CLIENT::text,PMP::text]))[2]::numeric AS PMP FROM prod_evolucare_hygie.LIGNELIV_CLI JOIN prod_evolucare_hygie.LIV_CLIENT ON LIGNELIV_CLI.NUM_LIV_CLIENT = LIV_CLIENT.NUM_LIV_CLIENT GROUP BY 1,2 ) sub WHERE article_code_original = REF_ART_INT AND date_trunc('month',date_fin) = month AND ok_pump = 0 ; UPDATE w_stock SET ok_pump = '1', pump = PMP, stock_valeur_fin = stock_quantite_fin * PMP FROM ( SELECT REF_ART_INT, date_trunc('month',LIGNELIV_FOURN.DATE_LIV_FOURN) as month, (MAX(ARRAY[LIGNELIV_FOURN.DATE_LIV_FOURN::text,PMP::text]))[2]::numeric AS PMP FROM prod_evolucare_hygie.LIGNELIV_FOURN JOIN prod_evolucare_hygie.LIV_FOURN ON LIGNELIV_FOURN.NUM_LIV_FOURN = LIV_FOURN.NUM_LIV_FOURN GROUP BY 1,2 ) sub WHERE article_code_original = REF_ART_INT AND date_trunc('month',date_fin) = month AND ok_pump = 0 ; UPDATE w_stock SET ok_pump = '1', pump = last_pump, stock_valeur_fin = stock_quantite_fin * last_pump FROM ( SELECT article_id, date_fin AS date_pump, COALESCE(LEAD(pump) OVER (PARTITION BY article_id ORDER BY date_fin), 0) AS last_pump, COALESCE(LAG(date_fin) OVER (PARTITION BY article_id ORDER BY date_fin), '1900-01-01') AS last_date, COALESCE(LEAD(date_fin) OVER (PARTITION BY article_id ORDER BY date_fin), '2099-12-31') AS next_date FROM w_stock WHERE ok_pump != '0' ) sub WHERE sub.article_id = w_stock.article_id AND date_fin BETWEEN CASE WHEN last_date = '1900-01-01' THEN last_date ELSE date_pump END AND next_date AND ok_pump = 0 ; UPDATE w_stock SET stock_quantite_debut = w_stock_prec.stock_quantite_fin, stock_valeur_debut = w_stock_prec.stock_valeur_fin FROM w_stock w_stock_prec WHERE w_stock.site_id = w_stock_prec.site_id AND w_stock.lieu_id = w_stock_prec.lieu_id AND w_stock.article_id = w_stock_prec.article_id AND w_stock.mois_code = w_stock_prec.mois_code + 1 ; TRUNCATE eco.p_stock ; INSERT INTO eco.p_stock ( article_id, fournisseur_id, compte_id, ucd_id, lpp_id, site_id, lieu_id, date_debut, date_fin, entree_quantite, entree_montant, sortie_quantite, sortie_montant, pump, stock_quantite_debut, stock_quantite_fin, stock_valeur_debut, stock_valeur_fin ) SELECT article_id, fournisseur_id, compte_id, ucd_id, lpp_id, site_id, lieu_id, date_debut, date_fin, entree_quantite, entree_montant, sortie_quantite, sortie_montant, pump, stock_quantite_debut, stock_quantite_fin, stock_valeur_debut, stock_valeur_fin FROM w_stock ; SELECT base.cti_enable_index('eco', 'i_stock_1'); SELECT base.cti_enable_index('eco', 'i_stock_2'); SELECT base.cti_enable_index('eco', 'i_stock_3'); SELECT base.cti_enable_index('eco', 'i_stock_4'); SELECT base.cti_enable_index('eco', 'i_stock_5'); ]]> = '[ENV_ECO_ANNEEDEBUT]-01-01' GROUP BY 1,2,3,4,5,6,7 ORDER BY 1; SELECT base.cti_enable_index('eco', 'i_facture_1'); SELECT base.cti_enable_index('eco', 'i_facture_2'); SELECT base.cti_enable_index('eco', 'i_facture_3'); SELECT base.cti_enable_index('eco', 'i_facture_4'); SELECT base.cti_enable_index('eco', 'i_facture_5'); SELECT base.cti_disable_index('eco', 'i_lignes_facture_1'); SELECT base.cti_disable_index('eco', 'i_lignes_facture_2'); SELECT base.cti_disable_index('eco', 'i_lignes_facture_3'); SELECT base.cti_disable_index('eco', 'i_lignes_facture_4'); TRUNCATE eco.p_lignes_facture; INSERT INTO eco.p_lignes_facture( article_id, code_original, compte_id, facture_id, ligne_commande, ligne_commande_id, montant_facture_article_ht, montant_facture_article_ttc, montant_facture_article_tva, montant_facture_port_ht, montant_facture_port_ttc, montant_facture_port_tva, montant_facture_ht, montant_facture_ttc, montant_facture_tva ) SELECT t_articles.oid, PINVOICED.NUM_0 || '-' || PINVOICED.PIDLIN_0 AS code_original, 0 as compte_id, p_facture.oid, ligne_commande, p_lignes_commandes.oid, AMTNOTLIN_0 AS montant_facture_article_ht, AMTATILIN_0 AS montant_facture_article_ttc, AMTTAXLIN1_0 AS montant_facture_article_tva, 0::numeric, 0::numeric, 0::numeric, AMTNOTLIN_0 AS montant_facture_ht, AMTATILIN_0 AS montant_facture_ttc, AMTTAXLIN1_0 AS montant_facture_tva FROM prod_sagex3.PINVOICED JOIN eco.t_articles ON ITMREF_0 = t_articles.code_original JOIN eco.p_facture ON NUM_0 = p_facture.code_original JOIN eco.p_lignes_commandes ON POHNUM_0 || '-' || POPLIN_0 = p_lignes_commandes.code_original LEFT JOIN prod_sagex3.GACCENTRY ON GACCENTRY.NUM_0 = PINVOICED.NUM_0 WHERE PINVOICED.ACCDAT_0 >= '[ENV_ECO_ANNEEDEBUT]-01-01' ORDER BY 2; SELECT base.cti_enable_index('eco', 'i_lignes_facture_1'); SELECT base.cti_enable_index('eco', 'i_lignes_facture_2'); SELECT base.cti_enable_index('eco', 'i_lignes_facture_3'); SELECT base.cti_enable_index('eco', 'i_lignes_facture_4'); ]]>