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.
 
 

172 lines
10 KiB

src: |
SELECT p_factures_soldes_c.finess,
p_factures_soldes_c.no_facture,
p_factures.sejour_id,
p_factures.oid AS facture_id,
p_factures.no_sejour,
p_factures.date_facture,
p_factures.date_vente,
p_factures.mois_vente,
p_factures.date_debut AS date_debut_facture,
p_factures.date_fin AS date_fin_facture,
p_factures_soldes_c.date_comptable,
t_tiers_payant.type_tiers_payant_id,
t_tiers_payant.type_tiers_payant AS type_tiers_payant_code,
t_tiers_payant.type_tiers_payant_texte,
p_factures.tiers_payant_0_id AS tiers_payant_id,
t_tiers_payant.code AS tiers_payant_code,
t_tiers_payant.texte_court AS tiers_payant_texte,
t_tiers_payant.grand_regime_id AS tiers_payant_grand_regime_id,
t_tiers_payant.grand_regime_code AS tiers_payant_grand_regime_code,
t_tiers_payant.grand_regime_texte AS tiers_payant_grand_regime_texte,
t_tiers_payant.section_id AS tiers_payant_section_id,
t_tiers_payant.section_code AS tiers_payant_section_code,
t_tiers_payant.section_texte AS tiers_payant_section_texte,
p_factures_soldes_c.rubrique_comptabilisee_id,
t_rubriques_facturation.code AS rubrique_comptabilisee_code,
t_rubriques_facturation.texte_court AS rubrique_comptabilisee_texte,
t_rubriques_facturation.section_id AS rubrique_comptabilisee_section_id,
t_rubriques_facturation.section_code AS rubrique_comptabilisee_section_code,
t_rubriques_facturation.section_texte AS rubrique_comptabilisee_section_texte,
p_factures_soldes_c.prestation_id,
t_prestations.code AS prestation_code,
t_prestations.texte_court AS prestation_texte,
t_prestations.section_id AS prestation_section_id,
t_prestations.section_code AS prestation_section_code,
t_prestations.section_texte AS prestation_section_texte,
p_factures_soldes_c.montant_comptabilise_0 AS montant_comptabilise,
p_factures_soldes_c.montant_regle_0 AS montant_regle
FROM activite.p_factures_soldes_c
JOIN activite.p_factures ON p_factures_soldes_c.no_facture = p_factures.no_facture
JOIN activite.t_tiers_payant ON p_factures.tiers_payant_0_id = t_tiers_payant.oid AND p_factures.tiers_payant_0_id > 0 AND (p_factures_soldes_c.montant_comptabilise_0 <> 0::numeric OR p_factures_soldes_c.montant_regle_0 <> 0::numeric)
JOIN activite.t_rubriques_facturation ON p_factures_soldes_c.rubrique_comptabilisee_id = t_rubriques_facturation.oid
JOIN activite.t_prestations ON p_factures_soldes_c.prestation_id = t_prestations.oid
UNION ALL
SELECT p_factures_soldes_c.finess,
p_factures_soldes_c.no_facture,
p_factures.sejour_id,
p_factures.oid AS facture_id,
p_factures.no_sejour,
p_factures.date_facture,
p_factures.date_vente,
p_factures.mois_vente,
p_factures.date_debut AS date_debut_facture,
p_factures.date_fin AS date_fin_facture,
p_factures_soldes_c.date_comptable,
t_tiers_payant.type_tiers_payant_id,
t_tiers_payant.type_tiers_payant AS type_tiers_payant_code,
t_tiers_payant.type_tiers_payant_texte,
p_factures.tiers_payant_1_id AS tiers_payant_id,
t_tiers_payant.code AS tiers_payant_code,
t_tiers_payant.texte_court AS tiers_payant_texte,
t_tiers_payant.grand_regime_id AS tiers_payant_grand_regime_id,
t_tiers_payant.grand_regime_code AS tiers_payant_grand_regime_code,
t_tiers_payant.grand_regime_texte AS tiers_payant_grand_regime_texte,
t_tiers_payant.section_id AS tiers_payant_section_id,
t_tiers_payant.section_code AS tiers_payant_section_code,
t_tiers_payant.section_texte AS tiers_payant_section_texte,
p_factures_soldes_c.rubrique_comptabilisee_id,
t_rubriques_facturation.code AS rubrique_comptabilisee_code,
t_rubriques_facturation.texte_court AS rubrique_comptabilisee_texte,
t_rubriques_facturation.section_id AS rubrique_comptabilisee_section_id,
t_rubriques_facturation.section_code AS rubrique_comptabilisee_section_code,
t_rubriques_facturation.section_texte AS rubrique_comptabilisee_section_texte,
p_factures_soldes_c.prestation_id,
t_prestations.code AS prestation_code,
t_prestations.texte_court AS prestation_texte,
t_prestations.section_id AS prestation_section_id,
t_prestations.section_code AS prestation_section_code,
t_prestations.section_texte AS prestation_section_texte,
p_factures_soldes_c.montant_comptabilise_1 AS montant_comptabilise,
p_factures_soldes_c.montant_regle_1 AS montant_regle
FROM activite.p_factures_soldes_c
JOIN activite.p_factures ON p_factures_soldes_c.no_facture = p_factures.no_facture
JOIN activite.t_tiers_payant ON p_factures.tiers_payant_1_id = t_tiers_payant.oid AND (p_factures.tiers_payant_1_id > 0 OR p_factures.montant_facture_1_c <> 0::numeric OR p_factures.montant_facture_1_h <> 0::numeric) AND (p_factures_soldes_c.montant_comptabilise_1 <> 0::numeric OR p_factures_soldes_c.montant_regle_1 <> 0::numeric)
JOIN activite.t_rubriques_facturation ON p_factures_soldes_c.rubrique_comptabilisee_id = t_rubriques_facturation.oid
JOIN activite.t_prestations ON p_factures_soldes_c.prestation_id = t_prestations.oid
UNION ALL
SELECT p_factures_soldes_c.finess,
p_factures_soldes_c.no_facture,
p_factures.sejour_id,
p_factures.oid AS facture_id,
p_factures.no_sejour,
p_factures.date_facture,
p_factures.date_vente,
p_factures.mois_vente,
p_factures.date_debut AS date_debut_facture,
p_factures.date_fin AS date_fin_facture,
p_factures_soldes_c.date_comptable,
t_tiers_payant.type_tiers_payant_id,
t_tiers_payant.type_tiers_payant AS type_tiers_payant_code,
t_tiers_payant.type_tiers_payant_texte,
p_factures.tiers_payant_2_id AS tiers_payant_id,
t_tiers_payant.code AS tiers_payant_code,
t_tiers_payant.texte_court AS tiers_payant_texte,
t_tiers_payant.grand_regime_id AS tiers_payant_grand_regime_id,
t_tiers_payant.grand_regime_code AS tiers_payant_grand_regime_code,
t_tiers_payant.grand_regime_texte AS tiers_payant_grand_regime_texte,
t_tiers_payant.section_id AS tiers_payant_section_id,
t_tiers_payant.section_code AS tiers_payant_section_code,
t_tiers_payant.section_texte AS tiers_payant_section_texte,
p_factures_soldes_c.rubrique_comptabilisee_id,
t_rubriques_facturation.code AS rubrique_comptabilisee_code,
t_rubriques_facturation.texte_court AS rubrique_comptabilisee_texte,
t_rubriques_facturation.section_id AS rubrique_comptabilisee_section_id,
t_rubriques_facturation.section_code AS rubrique_comptabilisee_section_code,
t_rubriques_facturation.section_texte AS rubrique_comptabilisee_section_texte,
p_factures_soldes_c.prestation_id,
t_prestations.code AS prestation_code,
t_prestations.texte_court AS prestation_texte,
t_prestations.section_id AS prestation_section_id,
t_prestations.section_code AS prestation_section_code,
t_prestations.section_texte AS prestation_section_texte,
p_factures_soldes_c.montant_comptabilise_2 AS montant_comptabilise,
p_factures_soldes_c.montant_regle_2 AS montant_regle
FROM activite.p_factures_soldes_c
JOIN activite.p_factures ON p_factures_soldes_c.no_facture = p_factures.no_facture
JOIN activite.t_tiers_payant ON p_factures.tiers_payant_2_id = t_tiers_payant.oid AND (p_factures.tiers_payant_2_id > 0 OR p_factures.montant_facture_2_c <> 0::numeric OR p_factures.montant_facture_2_h <> 0::numeric) AND (p_factures_soldes_c.montant_comptabilise_2 <> 0::numeric OR p_factures_soldes_c.montant_regle_2 <> 0::numeric)
JOIN activite.t_rubriques_facturation ON p_factures_soldes_c.rubrique_comptabilisee_id = t_rubriques_facturation.oid
JOIN activite.t_prestations ON p_factures_soldes_c.prestation_id = t_prestations.oid
UNION ALL
SELECT p_factures_soldes_c.finess,
p_factures_soldes_c.no_facture,
p_factures.sejour_id,
p_factures.oid AS facture_id,
p_factures.no_sejour,
p_factures.date_facture,
p_factures.date_vente,
p_factures.mois_vente,
p_factures.date_debut AS date_debut_facture,
p_factures.date_fin AS date_fin_facture,
p_factures_soldes_c.date_comptable,
t_tiers_payant.type_tiers_payant_id,
t_tiers_payant.type_tiers_payant AS type_tiers_payant_code,
t_tiers_payant.type_tiers_payant_texte,
p_factures.tiers_payant_22_id AS tiers_payant_id,
t_tiers_payant.code AS tiers_payant_code,
t_tiers_payant.texte_court AS tiers_payant_texte,
t_tiers_payant.grand_regime_id AS tiers_payant_grand_regime_id,
t_tiers_payant.grand_regime_code AS tiers_payant_grand_regime_code,
t_tiers_payant.grand_regime_texte AS tiers_payant_grand_regime_texte,
t_tiers_payant.section_id AS tiers_payant_section_id,
t_tiers_payant.section_code AS tiers_payant_section_code,
t_tiers_payant.section_texte AS tiers_payant_section_texte,
p_factures_soldes_c.rubrique_comptabilisee_id,
t_rubriques_facturation.code AS rubrique_comptabilisee_code,
t_rubriques_facturation.texte_court AS rubrique_comptabilisee_texte,
t_rubriques_facturation.section_id AS rubrique_comptabilisee_section_id,
t_rubriques_facturation.section_code AS rubrique_comptabilisee_section_code,
t_rubriques_facturation.section_texte AS rubrique_comptabilisee_section_texte,
p_factures_soldes_c.prestation_id,
t_prestations.code AS prestation_code,
t_prestations.texte_court AS prestation_texte,
t_prestations.section_id AS prestation_section_id,
t_prestations.section_code AS prestation_section_code,
t_prestations.section_texte AS prestation_section_texte,
p_factures_soldes_c.montant_comptabilise_22 AS montant_comptabilise,
p_factures_soldes_c.montant_regle_22 AS montant_regle
FROM activite.p_factures_soldes_c
JOIN activite.p_factures ON p_factures_soldes_c.no_facture = p_factures.no_facture
JOIN activite.t_tiers_payant ON p_factures.tiers_payant_22_id = t_tiers_payant.oid AND (p_factures.tiers_payant_22_id > 0 OR p_factures.montant_facture_22_c <> 0::numeric OR p_factures.montant_facture_22_h <> 0::numeric) AND (p_factures_soldes_c.montant_comptabilise_22 <> 0::numeric OR p_factures_soldes_c.montant_regle_22 <> 0::numeric)
JOIN activite.t_rubriques_facturation ON p_factures_soldes_c.rubrique_comptabilisee_id = t_rubriques_facturation.oid
JOIN activite.t_prestations ON p_factures_soldes_c.prestation_id = t_prestations.oid;