|
|
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_commande AS date_item,
|
|
|
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,
|
|
|
p_commandes.gestionnaire_id,
|
|
|
p_commandes.lieu_commande_id,
|
|
|
p_commandes.lieu_facturation_id,
|
|
|
p_commandes.lieu_livraison_id AS lieu_id,
|
|
|
p_lignes_commandes.unite_fonctionnelle_id,
|
|
|
p_lignes_commandes.article_id,
|
|
|
p_lignes_commandes.article_texte_specifique,
|
|
|
p_lignes_commandes.ucd_id,
|
|
|
p_lignes_commandes.lpp_id,
|
|
|
p_lignes_commandes.compte_id AS compte_article_id,
|
|
|
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,
|
|
|
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_unites ON p_lignes_commandes.unite_approvisionnement_id = t_unites.oid;
|