|
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。如果您注册时有任何问题请联系客服QQ: 83569622 。
您需要 登录 才可以下载或查看,没有帐号?注册
x
create or replace view FAST_UNIT_PRICE_BY_TSnT as
select a.inventory_item_id , decode(b.UNIT_SELLING_PRICE , null , a.price , b.UNIT_SELLING_PRICE) UNIT_SELLING_PRICE
--列出物料最新价格,如果没有销售价格,就取SO_PRICE_LIST_LINES中价格返回
--BY HZHA 20050824
from
(select msib.inventory_item_id inventory_item_id,
max(case when pl.currency_code='USD' then spll.LIST_PRICE*
( --求美元最新汇率子查询
FAST_PKG_BY_HZHA.FAST_GET_USD_CNY_RATE_BY_TSnT
/*
select avg(exchange_rate) from RA_CUSTOMER_TRX_ALL
where last_update_date =
( --求最后一个汇率发生的时间
select max(last_update_date) from RA_CUSTOMER_TRX_ALL where (cust_trx_type_id =1025 or cust_trx_type_id =1026)
)
and (cust_trx_type_id =1025 or cust_trx_type_id =1026)
*/
)
else spll.LIST_PRICE end ) price
from SO_PRICE_LIST_LINES spll,
mtl_system_items_b msib,
qp_secu_list_headers_v pl
where pl.list_header_id=spll.PRICE_LIST_ID
and spll.INVENTORY_ITEM_ID=msib.inventory_item_id
and msib.organization_id=84
and pl.end_date_active is null
group by msib.inventory_item_id
) a
left join
( --有销售价格的物料价格
select RA_LINES.INVENTORY_ITEM_ID,
avg(RA_LINES.UNIT_SELLING_PRICE) UNIT_SELLING_PRICE
from RA_CUSTOMER_TRX_LINES_ALL RA_LINES,
(
select INVENTORY_ITEM_ID,
max(LAST_UPDATE_DATE) LAST_UPDATE_DATE
from RA_CUSTOMER_TRX_LINES_ALL
where INVENTORY_ITEM_ID is not null
group by INVENTORY_ITEM_ID
) REFER
where RA_LINES.inventory_item_id=REFER.INVENTORY_ITEM_ID
and RA_LINES.LAST_UPDATE_DATE=REFER.LAST_UPDATE_DATE
and RA_LINES.INVENTORY_ITEM_ID is not null
group by RA_LINES.INVENTORY_ITEM_ID
) b
on a.INVENTORY_ITEM_ID=b.INVENTORY_ITEM_ID
order by a.INVENTORY_ITEM_ID |
|