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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
| select /*+ parallel(aven 8) */
tbo.org_id id_societe,
tc.id id_contrat,
NVL(tc.X_AV_RAISON_SOC1, tbo.NAME) RS,
aven.x_av_id id_mouvement,
aven.X_AV_STATUS statut_mouvement,
tc.X_AV_BU BU,
aven.X_AV_FAMILLE famille,
aven.x_av_ligne ligne,
aven.x_av_offre offre,
aven.X_AV_TYPE_PRINC type_mouv,
replace(replace(aven.X_AV_LIBELLE,chr(10),' '),chr(13),' ') libelle_mouv,
replace(replace(aven.X_AV_COMMENT,chr(10),' '),chr(13),' ') commentaire_mouv,
aven.X_AV_PROVENANCE_CONTRAT origine_contr,
aven.X_AV_DUREE_CDE duree_cmd,
aven.X_AV_NET_TOT PO,
aven.X_AV_PDC_REM pdv_rem,
to_char(aven.X_AV_DATE, 'YYYY-MM-DD') date_creation_mouv,
to_char(aven.X_AV_DATE, 'IYYY')||'-'||
to_char(aven.X_AV_DATE, 'IW') semaine_creation_mouv,
to_char(aven.X_AV_DATE, 'IYYY')||'-'||
to_char(aven.X_AV_DATE, 'MONTH') mois_creation_mouv,
(select ts.SITE_ID from table_site ts where ts.objid=aven.x_av_avt2site_dac) code_pdv,
(select ts.NAME from table_site ts where ts.objid=aven.x_av_avt2site_dac) libelle_pdv,
NVL((select decode((select 1
from table_user tu
where tu.login_name=dist.X_AV_LIBELLE),
1 , dist.X_AV_LIBELLE,
(select dist_resp.X_AV_LIBELLE
from table_x_av_dist_struct_commer dist_resp
where dist_resp.objid=dist.X_AV_STRCOM2CRVE))
from table_x_av_dist_struct_commer dist,
table_site ts
where dist.objid=ts.x_av_dist_site2sect_vente
and ts.objid=aven.x_av_avt2site_dac), 'IC Fictif') IcSFR,
(select /*+ index(te IND_EMPLOYEE2USER) index(tu USER_LOGIN_INDEXO) */
te.x_av_division
from table_employee te,
table_user tu
where 1=1
and te.employee2user=tu.objid
and tu.login_name in
(select decode((select '1' from table_user tu
where tu.login_name=dist.X_AV_LIBELLE),
'1' , dist.X_AV_LIBELLE,
(select dist_resp.X_AV_LIBELLE
from table_x_av_dist_struct_commer dist_resp
where dist_resp.objid=dist.X_AV_STRCOM2CRVE))
from table_x_av_dist_struct_commer dist,
table_site ts
where dist.objid=ts.x_av_dist_site2sect_vente
and ts.objid=aven.x_av_avt2site_dac)) Region,
Case
When substr(X_AV_ID_COMMANDE_GLOBALE,1,3) = 'ECU' OR aven.X_AV_LIBELLE = 'eCommande' Then 'eCommande'
When aven.X_AV_LIBELLE Like '%Extranet%' Then 'extranet'
Else 'Autre'
End flag_ecommande,
(select decode(to_char(count(tbo2.objid)), '1', 'MONO', 'MULTI') from table_bus_org tbo2 where tbo2.x_av_siren=tbo.X_AV_SIREN) TYPE_SIREN,
(select count(tcs.objid)
from table_contr_schedule tcs
where 1=1
and tcs.SCHEDULE2CONTRACT=tc.objid
and exists (select 1
from table_contr_itm tci
where 1=1
and tci.CONTR_ITM2CONTR_SCHEDULE=tcs.objid
and tci.CHILD2CONTR_ITM is null
and tci.X_AV_CONTR_ITM2AVENANT=aven.objid)) nb_sites_associes,
(select count(tcs.objid)
from table_contr_schedule tcs
where 1=1
and tcs.SCHEDULE2CONTRACT=tc.objid
and tcs.X_AV_STATUS='Résilié'
and exists (select 1
from table_contr_itm tci
where 1=1
and tci.CONTR_ITM2CONTR_SCHEDULE=tcs.objid
and tci.CHILD2CONTR_ITM is null
and tci.X_AV_CONTR_ITM2AVENANT=aven.objid)) nb_sites_associes_resil
from table_x_av_avenant aven,
table_contract tc,
table_bus_org tbo
where 1=1
and aven.X_AV_DATE>=to_date('01/'||to_char(sysdate+TO_YMINTERVAL('-1-0'),'MM/YYYY'),'DD/MM/YYYY')
and (aven.X_AV_TYPE_PRINC in ('Commande initiale','Commande parallélisée') or
(aven.X_AV_TYPE_PRINC='Souscription initiale fixe' and X_AV_LIBELLE='SFIX') or
(aven.X_AV_TYPE_PRINC='Ajout d''offre' and X_AV_LIBELLE='AOFF') or
(aven.X_AV_TYPE_PRINC='Ajout de ligne' and X_AV_LIBELLE='ALIG'))
and tc.objid=aven.X_AV_AVENANT2CONTRACT
and tbo.objid=tc.SELL_TO2BUS_ORG
order by aven.X_AV_DATE desc |
Partager