src: | SELECT p_commandes.provider_id, p_lignes_commandes.commande_id, p_commandes.numero AS commande_code, btrim(p_commandes.objet::text) AS commande_texte, p_commandes.objet AS commande_objet, p_commandes.date_commande, p_commandes.date_engagement, p_commandes.reference AS commande_reference, p_lignes_commandes.oid AS ligne_commande_id, (p_commandes.numero::text || '-'::text) || btrim(to_char(p_lignes_commandes.ligne_commande, '0000'::text)) AS ligne_commande_code, p_lignes_commandes.texte AS ligne_commande_texte, p_commandes.site_id, t_sites.code AS site_code, t_sites.texte_court AS site_texte, t_sites.section_id AS site_section_id, t_sites.section_code AS site_section_code, t_sites.section_texte AS site_section_texte, p_commandes.gestionnaire_id, t_gestionnaires.code AS gestionnaire_code, t_gestionnaires.texte_court AS gestionnaire_texte, t_gestionnaires.section_id AS gestionnaire_section_id, t_gestionnaires.section_code AS gestionnaire_section_code, t_gestionnaires.section_texte AS gestionnaire_section_texte, p_commandes.lieu_commande_id, t_lieux_commande.code AS lieu_commande_code, t_lieux_commande.texte_court AS lieu_commande_texte, t_lieux_commande.section_id AS lieu_commande_section_id, t_lieux_commande.section_code AS lieu_commande_section_code, t_lieux_commande.section_texte AS lieu_commande_section_texte, p_commandes.lieu_facturation_id, t_lieux_facturation.code AS lieu_facturation_code, t_lieux_facturation.texte_court AS lieu_facturation_texte, t_lieux_facturation.section_id AS lieu_facturation_section_id, t_lieux_facturation.section_code AS lieu_facturation_section_code, t_lieux_facturation.section_texte AS lieu_facturation_section_texte, p_commandes.lieu_livraison_id AS lieu_id, t_lieux_livraison.code AS lieu_code, t_lieux_livraison.texte_court AS lieu_texte, t_lieux_livraison.section_id AS lieu_section_id, t_lieux_livraison.section_code AS lieu_section_code, t_lieux_livraison.section_texte AS lieu_section_texte, p_lignes_commandes.unite_fonctionnelle_id, t_unites_fonctionnelles.code AS unite_fonctionnelle_code, t_unites_fonctionnelles.texte_court AS unite_fonctionnelle_texte, t_unites_fonctionnelles.section_id AS unite_fonctionnelle_section_id, t_unites_fonctionnelles.section_code AS unite_fonctionnelle_section_code, t_unites_fonctionnelles.section_texte AS unite_fonctionnelle_section_texte, p_lignes_commandes.article_id, t_articles.code AS article_code, t_articles.texte AS article_texte, p_lignes_commandes.article_texte_specifique, CASE p_commandes.fournisseur_id WHEN 0 THEN t_articles.texte WHEN t_articles.ref_fournisseur_id[1] THEN t_articles.ref_fournisseur_texte[1]::character varying WHEN t_articles.ref_fournisseur_id[2] THEN t_articles.ref_fournisseur_texte[2]::character varying WHEN t_articles.ref_fournisseur_id[3] THEN t_articles.ref_fournisseur_texte[3]::character varying WHEN t_articles.ref_fournisseur_id[4] THEN t_articles.ref_fournisseur_texte[4]::character varying WHEN t_articles.ref_fournisseur_id[5] THEN t_articles.ref_fournisseur_texte[5]::character varying WHEN t_articles.ref_fournisseur_id[6] THEN t_articles.ref_fournisseur_texte[6]::character varying WHEN t_articles.ref_fournisseur_id[7] THEN t_articles.ref_fournisseur_texte[7]::character varying WHEN t_articles.ref_fournisseur_id[8] THEN t_articles.ref_fournisseur_texte[8]::character varying WHEN t_articles.ref_fournisseur_id[9] THEN t_articles.ref_fournisseur_texte[9]::character varying WHEN t_articles.ref_fournisseur_id[10] THEN t_articles.ref_fournisseur_texte[10]::character varying WHEN t_articles.ref_fournisseur_id[11] THEN t_articles.ref_fournisseur_texte[11]::character varying WHEN t_articles.ref_fournisseur_id[12] THEN t_articles.ref_fournisseur_texte[12]::character varying WHEN t_articles.ref_fournisseur_id[13] THEN t_articles.ref_fournisseur_texte[13]::character varying WHEN t_articles.ref_fournisseur_id[14] THEN t_articles.ref_fournisseur_texte[14]::character varying WHEN t_articles.ref_fournisseur_id[15] THEN t_articles.ref_fournisseur_texte[15]::character varying WHEN t_articles.ref_fournisseur_id[16] THEN t_articles.ref_fournisseur_texte[16]::character varying WHEN t_articles.ref_fournisseur_id[17] THEN t_articles.ref_fournisseur_texte[17]::character varying WHEN t_articles.ref_fournisseur_id[18] THEN t_articles.ref_fournisseur_texte[18]::character varying WHEN t_articles.ref_fournisseur_id[19] THEN t_articles.ref_fournisseur_texte[19]::character varying WHEN t_articles.ref_fournisseur_id[20] THEN t_articles.ref_fournisseur_texte[20]::character varying ELSE t_articles.texte END AS article_texte_fournisseur, t_articles.section_id AS article_section_id, t_articles.section_code AS article_section_code, t_articles.section_texte AS article_section_texte, t_articles.type_id AS type_article_id, t_articles.type_code AS type_article_code, t_articles.type_texte AS type_article_texte, t_articles.type_section_id AS type_article_section_id, t_articles.type_section_code AS type_article_section_code, t_articles.type_section_texte AS type_article_section_texte, t_articles.article_reference_cacic_id, t_articles.article_reference_cacic_code, t_articles.article_reference_cacic_texte, t_articles.article_reference_cacic_section_id, t_articles.article_reference_cacic_section_code, t_articles.article_reference_cacic_section_texte, t_articles.article_reference_cti_id, t_articles.article_reference_cti_code, t_articles.article_reference_cti_texte, t_articles.article_reference_cti_section_id, t_articles.article_reference_cti_section_code, t_articles.article_reference_cti_section_texte, t_articles.fournisseur_principal_id, p_lignes_commandes.ucd_id, t_ucd_c.code AS ucd_code, t_ucd_c.texte AS ucd_texte, t_ucd_c.section_id AS ucd_section_id, t_ucd_c.section_code AS ucd_section_code, t_ucd_c.section_texte AS ucd_section_texte, p_lignes_commandes.lpp_id, t_lpp_c.code AS lpp_code, t_lpp_c.texte AS lpp_texte, t_lpp_c.section_id AS lpp_section_id, t_lpp_c.section_code AS lpp_section_code, t_lpp_c.section_texte AS lpp_section_texte, p_lignes_commandes.compte_id AS compte_article_id, t_compte.code AS compte_article_code, t_compte.texte AS compte_article_texte, t_compte.section_id AS compte_article_section_id, t_compte.section_code AS compte_article_section_code, t_compte.section_texte AS compte_article_section_texte, t_articles.classification_atc_id, t_articles.classification_atc_code, t_articles.classification_atc_texte, t_articles.classification_atc_1_id, t_articles.classification_atc_1_code, t_articles.classification_atc_1_texte, t_articles.classification_atc_2_id, t_articles.classification_atc_2_code, t_articles.classification_atc_2_texte, t_articles.classification_atc_3_id, t_articles.classification_atc_3_code, t_articles.classification_atc_3_texte, t_articles.classification_atc_4_id, t_articles.classification_atc_4_code, t_articles.classification_atc_4_texte, t_articles.classification_atc_section_id, t_articles.classification_atc_section_code, t_articles.classification_atc_section_texte, t_articles.famille_id AS famille_article_id, t_articles.famille_code AS famille_article_code, t_articles.famille_texte AS famille_article_texte, t_articles.famille_section_id AS famille_article_section_id, t_articles.famille_section_code AS famille_article_section_code, t_articles.famille_section_texte AS famille_article_section_texte, t_articles.sous_famille_id AS sous_famille_article_id, t_articles.sous_famille_code AS sous_famille_article_code, t_articles.sous_famille_texte AS sous_famille_article_texte, t_articles.sous_famille_section_id AS sous_famille_article_section_id, t_articles.sous_famille_section_code AS sous_famille_article_section_code, t_articles.sous_famille_section_texte AS sous_famille_article_section_texte, t_articles.categorie_id AS categorie_article_id, t_articles.categorie_code AS categorie_article_code, t_articles.categorie_texte AS categorie_article_texte, t_articles.categorie_section_id AS categorie_article_section_id, t_articles.categorie_section_code AS categorie_article_section_code, t_articles.categorie_section_texte AS categorie_article_section_texte, t_articles.sous_categorie_id AS sous_categorie_article_id, t_articles.sous_categorie_code AS sous_categorie_article_code, t_articles.sous_categorie_texte AS sous_categorie_article_texte, t_articles.sous_categorie_section_id AS sous_categorie_article_section_id, t_articles.sous_categorie_section_code AS sous_categorie_article_section_code, t_articles.sous_categorie_section_texte AS sous_categorie_article_section_texte, t_articles.unite_stockage_id AS unite_stockage_article_id, t_articles.unite_stockage_code AS unite_stockage_article_code, t_articles.unite_stockage_texte AS unite_stockage_article_texte, t_articles.unite_stockage_section_id AS unite_stockage_article_section_id, t_articles.unite_stockage_section_code AS unite_stockage_article_section_code, t_articles.unite_stockage_section_texte AS unite_stockage_article_section_texte, t_articles.unite_distribution_id AS unite_distribution_article_id, t_articles.unite_distribution_code AS unite_distribution_article_code, t_articles.unite_distribution_texte AS unite_distribution_article_texte, t_articles.unite_distribution_section_id AS unite_distribution_article_section_id, t_articles.unite_distribution_section_code AS unite_distribution_article_section_code, t_articles.unite_distribution_section_texte AS unite_distribution_article_section_texte, p_lignes_commandes.unite_approvisionnement_id AS unite_approvisionnement_article_id, t_unites.code AS unite_approvisionnement_article_code, t_unites.texte AS unite_approvisionnement_article_texte, t_unites.section_id AS unite_approvisionnement_article_section_id, t_unites.section_code AS unite_approvisionnement_article_section_code, t_unites.section_texte AS unite_approvisionnement_article_section_texte, p_commandes.fournisseur_id, t_fournisseurs.code AS fournisseur_code, t_fournisseurs.texte_court AS fournisseur_texte, t_fournisseurs.section_id AS fournisseur_section_id, t_fournisseurs.section_code AS fournisseur_section_code, t_fournisseurs.section_texte AS fournisseur_section_texte, t_fournisseurs.type_id AS type_fournisseur_id, t_fournisseurs.type_code AS type_fournisseur_code, t_fournisseurs.type_texte AS type_fournisseur_texte, t_fournisseurs.type_section_id AS type_fournisseur_section_id, t_fournisseurs.type_section_code AS type_fournisseur_section_code, t_fournisseurs.type_section_texte AS type_fournisseur_section_texte, t_fournisseurs.fournisseur_reference_cacic_id, t_fournisseurs.fournisseur_reference_cacic_code, t_fournisseurs.fournisseur_reference_cacic_texte, t_fournisseurs.fournisseur_reference_cacic_section_id, t_fournisseurs.fournisseur_reference_cacic_section_code, t_fournisseurs.fournisseur_reference_cacic_section_texte, t_fournisseurs.fournisseur_reference_cti_id, t_fournisseurs.fournisseur_reference_cti_code, t_fournisseurs.fournisseur_reference_cti_texte, t_fournisseurs.fournisseur_reference_cti_section_id, t_fournisseurs.fournisseur_reference_cti_section_code, t_fournisseurs.fournisseur_reference_cti_section_texte, p_lignes_commandes.quantite_approvisionnement, p_lignes_commandes.prix_unitaire_approvisionnement, p_lignes_commandes.multiplicateur_stockage, p_lignes_commandes.quantite_stockage, p_lignes_commandes.prix_unitaire_stockage, p_lignes_commandes.montant_commande_ht, p_lignes_commandes.montant_commande_remise, p_lignes_commandes.montant_commande_tva, p_lignes_commandes.montant_commande_port, p_lignes_commandes.montant_commande_ttc, p_lignes_commandes.montant_commande_ht + round(p_lignes_commandes.montant_commande_tva * p_lignes_commandes.taux_prorata_tva / 100::numeric, 2) AS montant_commande_ht_prorata, p_lignes_commandes.montant_commande_tva - round(p_lignes_commandes.montant_commande_tva * p_lignes_commandes.taux_prorata_tva / 100::numeric, 2) AS montant_commande_tva_prorata, p_lignes_commandes.quantite_livraison_approvisionnement, p_lignes_commandes.quantite_livraison_stockage, p_lignes_commandes.montant_livraison_ht, p_lignes_commandes.montant_livraison_tva, p_lignes_commandes.montant_livraison_ttc, p_lignes_commandes.etat_livraison AS ligne_commande_etat_livraison, CASE WHEN p_lignes_commandes.etat_livraison = ANY (ARRAY['N'::bpchar, 'P'::bpchar]) THEN p_lignes_commandes.quantite_approvisionnement - p_lignes_commandes.quantite_livraison_approvisionnement ELSE 0::numeric END AS quantite_non_livraison_approvisionnement, CASE WHEN p_lignes_commandes.etat_livraison = ANY (ARRAY['N'::bpchar, 'P'::bpchar]) THEN p_lignes_commandes.montant_commande_ht - p_lignes_commandes.montant_livraison_ht ELSE 0::numeric END AS montant_non_livraison_ht, CASE WHEN p_lignes_commandes.etat_livraison = ANY (ARRAY['N'::bpchar, 'P'::bpchar]) THEN p_lignes_commandes.montant_commande_ttc - p_lignes_commandes.montant_livraison_ttc ELSE 0::numeric END AS montant_non_livraison_ttc, p_lignes_commandes.montant_liquidation_ht, p_lignes_commandes.montant_liquidation_remise, p_lignes_commandes.montant_liquidation_tva, p_lignes_commandes.montant_liquidation_port, p_lignes_commandes.montant_liquidation_ttc, p_lignes_commandes.etat_liquidation, p_commandes.date_livraison_prevue, p_lignes_commandes.date_reception FROM eco.p_lignes_commandes JOIN eco.p_commandes ON p_lignes_commandes.commande_id = p_commandes.oid JOIN eco.t_gestionnaires ON p_commandes.gestionnaire_id = t_gestionnaires.oid JOIN eco.t_sites ON p_commandes.site_id = t_sites.oid JOIN eco.t_lieux t_lieux_commande ON p_commandes.lieu_commande_id = t_lieux_commande.oid JOIN eco.t_lieux t_lieux_facturation ON p_commandes.lieu_facturation_id = t_lieux_facturation.oid JOIN eco.t_lieux t_lieux_livraison ON p_commandes.lieu_livraison_id = t_lieux_livraison.oid JOIN eco.t_articles ON p_lignes_commandes.article_id = t_articles.oid JOIN eco.t_compte ON p_lignes_commandes.compte_id = t_compte.oid JOIN eco.t_ucd_c ON p_lignes_commandes.ucd_id = t_ucd_c.oid JOIN eco.t_lpp_c ON p_lignes_commandes.lpp_id = t_lpp_c.oid JOIN eco.t_fournisseurs ON p_commandes.fournisseur_id = t_fournisseurs.oid JOIN eco.t_unites_fonctionnelles ON p_commandes.unite_fonctionnelle_id = t_unites_fonctionnelles.oid JOIN eco.t_unites ON p_lignes_commandes.unite_approvisionnement_id = t_unites.oid;