1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
| SELECT ptd_new_vue_fact.COD_TRS as cod_trs
, ptd_new_vue_fact.COD_ETP as COD_ETP
, ptd_new_vue_fact.NUM_LIG as NUM_LIG
, ( Decode( :as_flg_dou
, 'O', sum( NVL(PTD_new_VUE_FACT.MNT_DOU, 0) / PTD_new_VUE_FACT.taux)
, 'N', sum( ( NVL(PTD_new_VUE_FACT.MNT_FACT, 0) - NVL(PTD_new_VUE_FACT.MNT_DOU, 0)) / PTD_new_VUE_FACT.taux)
, sum( NVL(PTD_new_VUE_FACT.MNT_FACT, 0 ) / PTD_new_VUE_FACT.taux)
) * Decode ( ptd_new_vue_fact.TYP_FAC , 'A' , -1 , 1 )) as ventes_reel
, 0.00 as achat_reel
, 0.00 as ventes_restant
, 0.00 as achats_restant
FROM ptd_new_vue_fact
WHERE ptd_new_vue_fact.NUM_REF_FAC = :al_num_ref_fac
AND ptd_new_vue_fact.TYP_UAT = 'P'
AND ( ptd_new_vue_fact.NUM_FAC <> '*****************'
or ptd_new_vue_fact.NUM_FAC_CAL <> '*****************'
)
group by cod_trs
,cod_etp
,num_lig
,ptd_new_vue_fact.TYP_FAC
UNION
SELECT ptd_new_vue_fact.COD_TRS as cod_trs
, ptd_new_vue_fact.COD_ETP as COD_ETP
, ptd_new_vue_fact.NUM_LIG as NUM_LIG
, 0.00 as ventes_reel
, ( Decode( :as_flg_dou
, 'O' , sum( NVL(PTD_new_VUE_FACT.MNT_DOU, 0) / NVL( SAT_AMHT.TAU_DEV, PTD_new_VUE_FACT.TAUX ) )
, 'N' , sum( ( NVL(PTD_new_VUE_FACT.MNT_FACT, 0) - NVL(PTD_new_VUE_FACT.MNT_DOU, 0) ) / NVL( SAT_AMHT.TAU_DEV, PTD_new_VUE_FACT.TAUX ) )
, sum( PTD_new_VUE_FACT.MNT_FACT / NVL( SAT_AMHT.TAU_DEV, PTD_new_VUE_FACT.TAUX ) )
) ) as achats_reel
, 0.00 as ventes_restant
, 0.00 as achats_restant
FROM ptd_new_vue_fact, sat_amht
WHERE sat_amht.num_int_fac = ptd_new_vue_fact.num_int_fac
AND ptd_new_vue_fact.NUM_REF_FAC = :al_num_ref_fac
AND ptd_new_vue_fact.TYP_UAT <> 'P'
AND ptd_new_vue_fact.COD_BAP in ( '1' , '2' )
group by cod_trs
,cod_etp
,num_lig
UNION
SELECT ptd_new_vue_fact.COD_TRS as cod_trs
, ptd_new_vue_fact.COD_ETP as COD_ETP
, ptd_new_vue_fact.NUM_LIG as NUM_LIG
, 0.00 as vente_reel
, 0.00 as achats_reel
, ( Decode( :as_flg_dou
, 'O' , sum( NVL(PTD_new_VUE_FACT.MNT_DOU, 0) / NVL(PTD_new_VUE_FACT.taux,1))
, 'N' , sum( ( NVL(PTD_new_VUE_FACT.MNT_FACT, 0) - NVL(PTD_new_VUE_FACT.MNT_DOU, 0) ) / NVL(PTD_new_VUE_FACT.taux,1))
, sum( NVL(PTD_new_VUE_FACT.MNT_FACT,0) / NVL(PTD_new_VUE_FACT.taux,1))
) * Decode ( ptd_new_vue_fact.TYP_FAC , 'A' , -1 , 1 )) as ventes_restant
, 0.00 as achats_restant
FROM ptd_new_vue_fact
WHERE ptd_new_vue_fact.NUM_REF_FAC = :al_num_ref_fac
AND ptd_new_vue_fact.TYP_UAT = 'P'
AND ptd_new_vue_fact.NUM_FAC = '*****************'
AND ptd_new_vue_fact.NUM_FAC_CAL = '*****************'
group by cod_trs
,cod_etp
,num_lig
,ptd_new_vue_fact.TYP_FAC
UNION
SELECT ptd_new_vue_fact.COD_TRS as cod_trs
, ptd_new_vue_fact.COD_ETP as COD_ETP
, ptd_new_vue_fact.NUM_LIG as NUM_LIG
, 0.00 as ventes_reel
, 0.00 as achats_reel
, 0.00 as ventes_restant
, ( Decode( :as_flg_dou
, 'O' , sum( NVL(PTD_new_VUE_FACT.MNT_DOU, 0) / NVL(PTD_new_VUE_FACT.taux,1) )
, 'N' , sum( ( NVL(PTD_new_VUE_FACT.MNT_FACT, 0) - NVL(PTD_new_VUE_FACT.MNT_DOU, 0) ) / NVL(PTD_new_VUE_FACT.taux,1))
, sum( NVL(PTD_new_VUE_FACT.MNT_FACT, 0) / NVL(PTD_new_VUE_FACT.taux, 1) )
) ) as achats_restant
FROM ptd_new_vue_fact
WHERE ptd_new_vue_fact.NUM_REF_FAC = :al_num_ref_fac
AND ptd_new_vue_fact.TYP_UAT <> 'P'
AND ptd_new_vue_fact.NUM_FAC_CAL = '*****************'
AND ptd_new_vue_fact.COD_BAP in ( '*' , '0' )
group by cod_trs
,cod_etp
,num_lig |
Partager