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
| select RegionOperationnelle,
' toto ' As Departement,
mvt.d01ste as Societe,
d01rs1 as NomSociete,
c04man as Mandat,
SoldeAvantDateValidation,
Encaissement,
case
when Encaissement > 0 then
case
when SoldeAvantDateValidation >= 0 then
0
else
case
when Encaissement + SoldeAvantDateValidation <= 0 then
Encaissement
else
SoldeAvantDateValidation * -1
end end else 0 end as EncaissementPourCompenserDebit,
SoldeADateTraitement,
AppelDeFonds,
case
when Encaissement = 0 then
0
else
case
when AppelDeFonds = 0 then
1
else
case
when abs((1230.456789 + Encaissement - 1230.456789) / AppelDeFonds) > 1 then
abs((1230.456789 + Encaissement - 1230.456789) / AppelDeFonds)
else
abs((1230.456789 + Encaissement - 1230.456789) / AppelDeFonds)
end end end as TauxEncaissementInstantane,
case
when SoldeAvantDateValidation + AppelDeFonds = 0 then
1
else
case
when abs((1230.456789 + Encaissement - 1230.456789) /
(SoldeAvantDateValidation + AppelDeFonds)) > 1 then
abs((1230.456789 + Encaissement - 1230.456789) /
(SoldeAvantDateValidation + AppelDeFonds))
end end as TauxEncaissementCumule,
substring(DateComptabilisation, 7, 2) || '/' ||
substring(DateComptabilisation, 5, 2) || '/' ||
substring(DateComptabilisation, 1, 4) as DateComptabilisation,
substring(cast(current date as char(10)), 9, 2) || '/' ||
substring(cast(current date as char(10)), 6, 2) || '/' ||
substring(cast(current date as char(10)), 1, 4) as DateTraitement
from (select mvt.d01ste,
c04man,
hsv.DateValidation,
hsv.DateComptabilisation,
sum(case
when mvt.DateComptabilisation < hsv.DateValidation then
c04mon
else
0
end) * -1 as SoldeAvantDateValidation,
sum(case
when mvt.DateComptabilisation >= hsv.DateValidation then
Encaissement
else
0
end) as Encaissement,
sum(case
when mvt.DateComptabilisation <=
year(current date) * 10000 + month(current date) * 100 +
day(current date) then
c04mon
else
0
end) * -1 as SoldeADateTraitement,
sum(case
when mvt.DateComptabilisation = hsv.DateComptabilisation then
AppelDeFonds
else
0
end) as AppelDeFonds
from (select d01ste,
c04man,
c01cpt,
c04scp,
c04blc,
c04ade * 10000 + C04mde * 100 + c04jde as DateComptabilisation,
sum(case
when c04mon < 0 then
c04mon
else
0
end) * -1 as Encaissement,
sum(case
when c04mon > 0 then
c04mon
else
0
end) * -1 as AppelDeFonds,
sum(c04mon) as c04mon
from agircptoto.c04mvt0 mvt
where c01cpt = 450100
group by d01ste,
c04man,
c01cpt,
c04scp,
c04blc,
c04ade * 10000 + C04mde * 100 + c04jde) mvt
inner join (select d01ste,
s10man,
S90cpt,
min(s91adv * 10000 + s91mdv * 100 + s91jdv) as DateValidation,
s90acp * 10000 + s90mcp * 100 + s90jcp as DateComptabilisation,
sum(s91mre) as s91mre
from agircptoto.s91hsv0 hsv
where s90cpt = 450100
and s90acp * 10000 + s90mcp * 100 + s90jcp = 20110701
group by d01ste, s10man, s90cpt, s90jcp, s90mcp, s90acp) hsv on mvt.d01ste =
hsv.d01ste
and mvt.c04man =
hsv.s10man
and mvt.c01cpt =
hsv.s90cpt
and mvt.DateComptabilisation <=
(case when
year(current date) *
10000 +
month(current date) * 100 +
day(current date) <
20110701 then
99999999 else
year(current date) *
10000 +
month(current date) * 100 +
day(current date) end)
group by mvt.d01ste,
c04man,
hsv.DateComptabilisation,
hsv.DateValidation) mvt
left outer join (select d01ste, regionoperationnelle
from agircptoto.d01ste0
inner join simco.bx_ro on upper(activite) = 'COP'
and upper(departement) = ' toto '
and d01ste = societe
union all
select d01ste, regionoperationnelle
from agircptoto.d01ste0
inner join simco.bx_ro on upper(activite) = 'COP'
and upper(departement) = ' toto '
where d01ste not in
(select d01ste
from agircptoto.d01ste0
inner join simco.bx_ro on upper(departement) =
' toto '
and d01ste = societe)
and societe = '') ro on mvt.d01ste = ro.d01ste
left outer join(agircptoto.d01ste0 ste on mvt.d01ste = ste.d01ste)
order by RegionOperationnelle, departement, mvt.d01ste |
Partager