- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 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
select
0 as IS_WRK,
case when DD.DELIVERY_DET_ID is null then 1 else 0 end NW,
0 as NH,
round(WO.AMOUNT * AD.PRICE_BASE*100.0/(100.0+AD.NDS), 2)*AMM.CURS*CDS.CURRENCY_KOEF/CDV.CURRENCY_KOEF as SUMM_NO_NDS,
round(WO.AMOUNT * AD.PRICE_BASE, 2)*AMM.CURS*CDS.CURRENCY_KOEF/CDV.CURRENCY_KOEF as SUMM_VV,
case
when DD.DELIVERY_DET_ID is null
then
( isnull(round(WO.AMOUNT * A.PRICE_IN *
(select CURRENCY_KOEF from CURRENCY_DAILY (nolock) where CURRENCY_GROUP_ID =
(select CURRENCY_GROUP_ID from CURRENCY_GROUP (nolock) where CURRENCY_DATE =
(select max(CURRENCY_DATE) from CURRENCY_GROUP (nolock) where CURRENCY_DATE <= AD.DATE_ACTION)) and CURRENCY_ID = @Currency)
/
(select CURRENCY_KOEF from CURRENCY_DAILY (nolock) where CURRENCY_GROUP_ID =
(select CURRENCY_GROUP_ID from CURRENCY_GROUP (nolock) where CURRENCY_DATE =
(select max(CURRENCY_DATE) from CURRENCY_GROUP (nolock) where CURRENCY_DATE <= AD.DATE_ACTION)) and CURRENCY_ID = A.CURRENCY_ID), 2),0)
)
else
( /* 08.04.2015 - 4700 BEGIN */
ISNULL ( round(WO.AMOUNT *case @Currency
when DM.CURRENCY_ID then DD.PRICE_NO_NDS
when @CurrencyBase then DD.PRICE_BASE*(100.0/(100.0+DD.NDS))
else DD.PRICE_BASE*(100.0/(100.0+DD.NDS))*CDS.CURRENCY_KOEF
end, 2), 0)
/* 08.04.2015 - 4700 END */
)
end
as IN_NO_NDS,
case
when DD.DELIVERY_DET_ID is null
then
( isnull(round(WO.AMOUNT * A.PRICE_IN *
(select CURRENCY_KOEF from CURRENCY_DAILY (nolock) where CURRENCY_GROUP_ID =
(select CURRENCY_GROUP_ID from CURRENCY_GROUP (nolock) where CURRENCY_DATE =
(select max(CURRENCY_DATE) from CURRENCY_GROUP (nolock) where CURRENCY_DATE <= AD.DATE_ACTION)) and CURRENCY_ID = @Currency)
/
(select CURRENCY_KOEF from CURRENCY_DAILY (nolock) where CURRENCY_GROUP_ID =
(select CURRENCY_GROUP_ID from CURRENCY_GROUP (nolock) where CURRENCY_DATE =
(select max(CURRENCY_DATE) from CURRENCY_GROUP (nolock) where CURRENCY_DATE <= AD.DATE_ACTION)) and CURRENCY_ID = A.CURRENCY_ID), 2),0)
)
else
( /* 08.04.2015 - 4700 BEGIN */
ISNULL(round(WO.AMOUNT *case @Currency
when DM.CURRENCY_ID then DD.PRICE
when @CurrencyBase then DD.PRICE_BASE
else DD.PRICE_BASE*(100.0/(100.0+DD.NDS))*CDS.CURRENCY_KOEF
end, 2), 0)
/* 08.04.2015 - 4700 END */
)
end
as IN_VV,
AD.USER_WRITER as WRITER,
AD.ACCOUNT_ID
from ACCOUNT_DETAIL as AD (nolock)
inner join @AM as AM on AM.ACCOUNT_ID = AD.ACCOUNT_ID
inner join ARTICLE as A (nolock) on A.ARTICLE_ID = AD.ARTICLE_ID
left join #_WRITEOUT_TEMP_REST_ as WO on WO.ACCOUNT_DET_ID = AD.ACCOUNT_DET_ID
left join DELIVERY_DETAIL as DD (nolock) on WO.ROOT_ID = DD.DELIVERY_DET_ID
left join DELIVERY_MASTER as DM (nolock) on DM.DELIVERY_MST_ID = DD.DELIVERY_MST_ID
inner join ACCOUNT_MASTER AMM (nolock) on AMM.ACCOUNT_ID=AM.ACCOUNT_ID
inner join CURRENCY_DAILY CDV (nolock) on ((CDV.CURRENCY_GROUP_ID = AMM.CURRENCY_GROUP_ID)and(CDV.CURRENCY_ID = AMM.CURRENCY_ID))
inner join CURRENCY_DAILY CDS (nolock) on ((CDS.CURRENCY_GROUP_ID = AMM.CURRENCY_GROUP_ID)and(CDS.CURRENCY_ID = @Currency))
where
AD.IS_WRITEOUT = 0 and AD.OUT = 1
and (@Articles = '' and @ArticleGroups = '' or charindex(',' + convert(varchar, A.ARTICLE_ID) + ',', @Articles) > 0
or charindex(',' + convert(varchar, A.GROUP_ID) + ',', @ArticleGroups) > 0)
bahamot 01.02.2017 18:37 # 0