You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

177 lines
11 KiB

src: |
SELECT p_facture.provider_id AS facture_provider_id,
p_lignes_facture.oid AS ligne_facture_id,
p_lignes_facture.facture_id,
p_facture.no_facture AS facture_code,
p_facture.texte AS facture_texte,
p_facture.date_facture,
p_facture.commande_id AS facture_commande_id,
p_lignes_facture.compte_id AS facture_compte_article_id,
p_lignes_facture.article_id AS facture_acticle_id,
p_facture.fournisseur_id AS facture_fournisseur_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_facture.date_reglement,
p_facture.date_reglement - p_facture.date_facture AS delai_paiement,
p_commandes.reference AS commande_reference,
p_lignes_facture.oid AS ligne_commande_id,
(p_commandes.numero::text || '-'::text) || btrim(to_char(p_lignes_facture.ligne_commande, '0000'::text)) AS ligne_commande_code,
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_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,
t_articles.code AS article_code,
t_articles.texte AS article_texte,
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_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,
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_facture.montant_facture_ht,
p_lignes_facture.montant_facture_tva,
p_lignes_facture.montant_facture_ttc,
p_lignes_facture.montant_facture_ht + round(p_lignes_facture.montant_facture_tva * p_lignes_facture.taux_prorata_tva / 100::numeric, 2) AS montant_facture_ht_prorata,
p_lignes_facture.montant_facture_tva - round(p_lignes_facture.montant_facture_tva * p_lignes_facture.taux_prorata_tva / 100::numeric, 2) AS montant_facture_tva_prorata,
p_lignes_facture.montant_facture_port_ttc,
p_lignes_facture.montant_facture_article_ht,
p_lignes_facture.montant_facture_article_tva,
p_lignes_facture.montant_facture_article_ttc,
p_lignes_facture.montant_facture_article_ht + round(p_lignes_facture.montant_facture_article_tva * p_lignes_facture.taux_prorata_tva / 100::numeric, 2) AS montant_facture_article_ht_prorata,
p_lignes_facture.montant_facture_article_tva - round(p_lignes_facture.montant_facture_article_tva * p_lignes_facture.taux_prorata_tva / 100::numeric, 2) AS montant_facture_article_tva_prorata
FROM eco.p_lignes_facture
JOIN eco.p_facture ON p_lignes_facture.facture_id = p_facture.oid
JOIN eco.p_commandes ON p_facture.commande_id = p_commandes.oid
JOIN eco.t_gestionnaires ON p_commandes.gestionnaire_id = t_gestionnaires.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_facture.article_id = t_articles.oid
JOIN eco.t_compte ON p_lignes_facture.compte_id = t_compte.oid
JOIN eco.t_fournisseurs ON p_facture.fournisseur_id = t_fournisseurs.oid
JOIN eco.t_unites_fonctionnelles ON p_commandes.unite_fonctionnelle_id = t_unites_fonctionnelles.oid;