rendered paste bodycreate or replace view AccRegistrOtklAmortCore as
select
amrt.nminref amort, -- аморт группа
amrtcd.codinref amortcode, -- код аморт
dr.nminref dr, -- дох/расх
drcd.codinref drcd, -- код дох/расх
st.nminref stat, -- статья дох/расх
t.codinref2201 oscode, -- код статьи дох/расх
decode(t.acc1, 2, 'Спис. аморт. при выб. (Д02-К01)',
1, 'Нач. аморт. (Д..- К02)', '!Error!') acc, -- начисление/амортизация
t.acc1 acccode, -- код счета
sum( -- до периода - остатки
/**decode(t.acc1, 1, /**/
- decode(
ith_misc_func.dateinrange(
to_date(p.DateFr, 'dd.mm.yyyy'),
to_date(p.DateTo, 'dd.mm.yyyy'),
t.datetr),
0,
decode( t.flagcredit, 0, t.summaincur, 0 ) -
decode( t.flagcredit, 1, t.summaincur, 0 ),
0
)/**,
- decode(
ith_misc_func.dateinrange(
to_date(p.DateFr, 'dd.mm.yyyy'),
to_date(p.DateTo, 'dd.mm.yyyy'),
t.datetr),
0,
decode( t.flagcredit, 0, t.summaincur, 0 ) -
decode( t.flagcredit, 1, t.summaincur, 0 ),
0
)
) /**/
) sumost,
sum( -- в периоде - обороты
decode(t.acc1, 1,
decode(
ith_misc_func.dateinrange(
to_date(p.DateFr, 'dd.mm.yyyy'),
to_date(p.DateTo, 'dd.mm.yyyy'),
t.datetr),
1,
decode( t.flagcredit, 0, t.summaincur, 0 ) -
decode( t.flagcredit, 1, t.summaincur, 0 ),
0
),
- decode(
ith_misc_func.dateinrange(
to_date(p.DateFr, 'dd.mm.yyyy'),
to_date(p.DateTo, 'dd.mm.yyyy'),
t.datetr),
1,
decode( t.flagcredit, 0, t.summaincur, 0 ) -
decode( t.flagcredit, 1, t.summaincur, 0 ),
0
)
)
) summain,
t.codplant codplant,
t.acc1 acc1,
i.perc / 100 perc
from acctransreportview t,
refgroupextent amrt,
refitemref amrtcd,
refgroupextent dr,
refitemref drcd,
refuser st,
ithcde_oso_sngprm p,
acc acc,
(
select i1.codinref, i1.value datebeg, i2.value dateend, i3.value perc
from refitemattr i1, refitemattr i2, refitemattr i3
where i1.codref = 32201
and i1.codattr = 64401
and i2.codref = i1.codref
and i2.codattr = 64501
and i3.codref = i1.codref
and i3.codattr = 64601
and i2.codinref = i1.codinref
and i3.codinref = i1.codinref
) i
where t.datetr <= to_date(p.DateTo, 'dd.mm.yyyy')
and ith_misc_func.dateinrange(
to_date(i.datebeg, 'dd/mm/yyyy'),
to_date(i.dateend, 'dd/mm/yyyy'),
t.datetr) = 1
and t.codbr = p.CodBr--201
and
(
-- Бухгалтерский Учет
(
t.codplan = 501
and t.codplant = 201
and
(
(t.acc1 = 02 and t.acc2 <> 02)
or
(t.acc1 = 01)
)
)
or
-- Налоговый Учет
(
t.codplan = 2201
and t.codplant = 2301
and
(
(t.acc1 = 02 and t.acc2 <> 02)
or
(t.acc1 = 01)
)
)
)
and t.flagofficial = 1
and t.summaincur <> 0
and st.codinref = t.codinref2201
and st.codref = 2201
and amrtcd.codinrk (+) = t.codinref2201
and amrtcd.codrk (+) = 2201
and amrtcd.codref (+) = 18301
and amrt.codinref (+) = amrtcd.codinref
and amrt.codref (+) = 18301
and drcd.codinrk (+) = t.codinref2201
and drcd.codrk (+) = 2201
and drcd.codref (+) = 18401
and dr.codinref (+) = drcd.codinref
and dr.codref (+) = 18401
and acc.acc (+) = t.acc1
and acc.codplant (+) = 201
and acc.subacc (+) = 0
group by amrt.nminref, amrtcd.codinref, dr.nminref, drcd.codinref, t.codinref2201,
decode(t.acc1, 2, 'Спис. аморт. при выб. (Д02-К01)',
1, 'Нач. аморт. (Д..- К02)', '!Error!'),
t.acc1, st.nminref, t.codplant, t.acc1, i.perc / 100
order by amort, dr, stat, acc, sumost, summain
---------------------
create or replace view AccRegistrOtklAmort as
select
s.amort amort,
s.amortcode amortcode,
s.dr accgr,
s.drcd drcd,
s.stat stat,
s.oscode oscode,
s.acc acc,
s.acccode acccode,
-- остатки
sum(s.sumost_bu) sumost_bu,
sum(s.sumost_nu) sumost_nu,
sum(s.sumost_otkl) sumost_otkl,
sum(s.sumost_ona) sumost_ona,
sum(s.sumost_ono) sumost_ono,
-- обороты
sum(s.summain_bu) summain_bu,
sum(s.summain_nu) summain_nu,
sum(s.summain_otkl) summain_otkl,
sum(s.summain_ona) summain_ona,
sum(s.summain_ono) summain_ono,
-- сальдо
sum(s.sumsald_bu) sumsald_bu,
sum(s.sumsald_nu) sumsald_nu,
sum(s.sumsald_otkl) sumsald_otkl,
sum(s.sumsald_ona) sumsald_ona,
sum(s.sumsald_ono) sumsald_ono
/**--------------- Групповые суммы по списанию
-- остатки
sum(decode(s.acc1, 1, s.sumost_bu, 0)) sumost_bu_s,
sum(decode(s.acc1, 1, s.sumost_nu, 0)) sumost_nu_s,
sum(decode(s.acc1, 1, s.sumost_otkl, 0)) sumost_otkl_s,
sum(decode(s.acc1, 1, s.sumost_ona, 0)) sumost_ona_s,
sum(decode(s.acc1, 1, s.sumost_ono, 0)) sumost_ono_s,
-- обороты
sum(decode(s.acc1, 1, s.summain_bu, 0)) summain_bu_s,
sum(decode(s.acc1, 1, s.summain_nu, 0)) summain_nu_s,
sum(decode(s.acc1, 1, s.summain_otkl, 0)) summain_otkl_s,
sum(decode(s.acc1, 1, s.summain_ona, 0)) summain_ona_s,
sum(decode(s.acc1, 1, s.summain_ono, 0)) summain_ono_s,
-- сальдо
sum(decode(s.acc1, 1, s.sumsald_bu, 0)) sumsald_bu_s,
sum(decode(s.acc1, 1, s.sumsald_nu, 0)) sumsald_nu_s,
sum(decode(s.acc1, 1, s.sumsald_otkl, 0)) sumsald_otkl_s,
sum(decode(s.acc1, 1, s.sumsald_ona, 0)) sumsald_ona_s,
sum(decode(s.acc1, 1, s.sumsald_ono, 0)) sumsald_ono_s /**/
from (
select
v.amort amort,
v.amortcode amortcode,
v.dr dr,
v.drcd drcd,
v.stat stat,
v.oscode oscode ,
v.acc acc,
v.acccode acccode,
-- остатки
sum(v.sumost_bu) sumost_bu,
sum(v.sumost_nu) sumost_nu,
sum(v.sumost_otkl) sumost_otkl,
sum(
decode(
decode(
decode(sumost_bu * sumost_nu, 0, 0, 1), -- если БУ и НУ не равны нулю - 1, иначе - 0
1,
ith_misc_func.numbinrange(0, 0, sumost_otkl), -- если отклонение больше нуля то 2, иначе 0
1), -- если 2 - ОНА, 0 - ОНО, 1 - решаем дальше
2,
v.sumost_otkl * v.perc, -- сумма
0,
0, -- сумма
decode(
ith_misc_func.numbinrange(
0, 0, sumost_bu * sumost_bu), -- если выше нуля - 2, равно - 1, ниже нуля - 0
1, -- если БУ = 0 то ОНА
v.sumost_otkl * v.perc, -- сумма
0)
)) sumost_ona,
sum(
decode(
decode(
decode(sumost_bu * sumost_nu, 0, 0, 1), -- если БУ и НУ не равны нулю - 1, иначе - 0
1,
ith_misc_func.numbinrange(0, 0, sumost_otkl), -- если отклонение больше нуля то 2, иначе 0
1), -- если 2 - ОНА, 0 - ОНО, 1 - решаем дальше
0,
v.sumost_otkl * v.perc, -- сумма
2,
0, -- сумма
decode(
ith_misc_func.numbinrange(
0, 0, sumost_nu * sumost_nu), -- если выше нуля - 2, равно - 1, ниже нуля - 0
1, -- если НУ = 0 то ОНА
v.sumost_otkl * v.perc, -- сумма
0)
)) sumost_ono,
-- обороты
sum(v.summain_bu) summain_bu,
sum(v.summain_nu) summain_nu,
sum(v.summain_otkl) summain_otkl,
sum(
decode(
ith_misc_func.numbinrange(0, 0, abs(v.summain_bu) - abs(v.summain_nu)),
decode(v.acccode, 1, 0, 2), -- 0 - меньше нуля, 2 - больше нуля, 1 = нулю
-- на ос надо на оно если бу > ну на аморт надо на она
decode(v.summain_bu * v.summain_nu, 0, -1, 1) -- знак она/оно
* v.summain_otkl * v.perc,
0)
) summain_ona,
sum(
decode(
ith_misc_func.numbinrange(0, 0, abs(v.summain_bu) - abs(v.summain_nu)),
decode(v.acccode, 1, 2, 0), -- 0 - меньше нуля, 2 - больше нуля, 1 = нулю
-- на ос надо на оно если бу > ну на аморт надо на она
decode(v.summain_bu * v.summain_nu, 0, -1, 1) -- знак она/оно
* v.summain_otkl * v.perc,
0)
) summain_ono,
-- сальдо
sum(v.sumsald_bu) sumsald_bu,
sum(v.sumsald_nu) sumsald_nu,
sum(v.sumsald_otkl) sumsald_otkl,
sum(
decode(
ith_misc_func.numbinrange(0, 0, abs(v.sumsald_bu) - abs(v.sumsald_nu)),
decode(v.acccode, 1, 0, 2), -- 0 - меньше нуля, 2 - больше нуля, 1 = нулю
-- на ос надо на оно если бу > ну на аморт надо на она
decode(v.sumsald_bu * v.sumsald_nu, 0, -1, 1) -- знак она/оно
* v.sumsald_otkl * v.perc,
0)
) sumsald_ona,
sum(
decode(
ith_misc_func.numbinrange(0, 0, abs(v.sumsald_bu) - abs(v.sumsald_nu)),
decode(v.acccode, 1, 2, 0), -- 0 - меньше нуля, 2 - больше нуля, 1 = нулю
-- на ос надо на оно если бу > ну на аморт надо на она
decode(v.sumsald_bu * v.sumsald_nu, 0, -1, 1) -- знак она/оно
* v.sumsald_otkl * v.perc,
0)
) sumsald_ono,
v.codplant codplant,
v.acc1 acc1
from (
select
a.amort amort,
a.amortcode amortcode,
a.dr dr,
a.drcd drcd,
a.stat stat,
a.oscode oscode ,
a.acc acc,
a.acccode acccode,
sum(a.sumost_bu) sumost_bu,
sum(a.sumost_nu) sumost_nu,
sum(abs(a.sumost_bu) - abs(a.sumost_nu)) sumost_otkl,
sum(a.summain_bu) summain_bu,
sum(a.summain_nu) summain_nu,
sum(abs(a.summain_bu) - abs(a.summain_nu)) summain_otkl,
sum(a.sumost_bu + a.summain_bu) sumsald_bu,
sum(a.sumost_nu + a.summain_nu) sumsald_nu,
sum(abs(a.sumost_bu) + abs(a.summain_bu) - (abs(a.sumost_nu) + abs(a.summain_nu))) sumsald_otkl,
a.codplant codplant,
a.acc1 acc1,
a.perc perc
from (
select
t.amort amort,
t.amortcode amortcode,
t.dr dr,
t.drcd drcd,
t.stat stat,
t.oscode oscode ,
t.acc acc,
t.acccode acccode,
decode(t.codplant, 201, t.sumost, 0) sumost_bu,
decode(t.codplant, 2301, t.sumost, 0) sumost_nu,
decode(t.codplant, 201, t.summain, 0) summain_bu,
decode(t.codplant, 2301, t.summain, 0) summain_nu,
t.codplant codplant,
t.acc1 acc1,
t.perc perc
from accregistrotklamortcore t) a
group by a.amort, a.amortcode, a.dr, a.drcd, a.stat, a.oscode, a.acc, a.acccode, a.codplant, a.acc1, a.perc) v
group by v.amort, v.amortcode, v.dr, v.drcd, v.stat, v.oscode, v.acc, v.acccode, v.codplant, v.acc1) s
group by s.amort, s.amortcode, s.dr, s.drcd, s.stat, s.oscode, s.acc, s.acccode
order by amort, accgr, stat, acc