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_facture.date_reglement,
      p_facture.date_reglement - p_facture.date_facture AS delai_paiement,
      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_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_commandes.oid = p_facture.commande_id
       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;