|
楼主 |
发表于 2024-12-11 18:25:19
|
显示全部楼层
----1111 期初库存
SELECT max(i.ownerid) 保管账ID, a.compid 关联 , '默认货主' 保管账,
a.wareid AS 货品ID,
max(w.warename) AS 通用名,
max(w.warename) AS 商品名,
max(w.warespec) AS 规格,
max(w.wareunit) AS 基本单位,
max(f.factoryname) AS 生产厂商,
max(t_area.areafullname) AS 产地,
max(w.fileno) 批准文号,
max(wb.regno) as 注册证号,
max(i.buyer) AS 采购员ID,f_get_username(max(i.buyer)) as 采购员,
sum(a.wareqty) as 库存数量,
sum(round(a.wareqty * nvl(ad.purpriceo,i.purprice),2)) as 批次金额,
sum(round(a.wareqty * (nvl(ad.purpriceo,i.purprice)/(1+i.PURTAX/100)),2)) 批次无税金额
FROM (SELECT compid AS compid,
busno AS busno,
wareid AS wareid,
stallno AS stallno,
batid AS batid,
SUM(wareqty) AS wareqty
FROM (SELECT compid, busno, wareid, stallno, batid, wareqty
FROM t_store_d
WHERE compid = 2
UNION ALL
SELECT l.compid,
l.busno,
l.wareid,
l.stallno,
l.batid,
SUM(-l.inqty) AS wareqty
FROM t_store_inout_list l
WHERE l.execdate > to_date( '202309012359','yyyy-mm-dd hh24:mi' ) and l.compid = 2
GROUP BY l.compid, l.busno, l.wareid, l.batid, l.stallno)
GROUP BY compid, busno, wareid, stallno, batid) a
JOIN t_store_i i
ON a.wareid = i.wareid
AND a.batid = i.batid
JOIN t_ware w
ON a.compid = w.compid
AND a.wareid = w.wareid
JOIN t_ware_ext wb
ON wb.wareid = a.wareid
LEFT JOIN t_factory f
ON f.factoryid = w.factoryid
LEFT JOIN t_area
ON t_area.areacode = i.areacode
left join (select h1.compid,d1.wareid,d1.batid,d1.purpriceo,h1.execdate
from t_adjust_purprice_d d1,
t_adjust_purprice_h h1
where d1.adjustno = h1.adjustno
and h1.compid = 2
and h1.status = 1
and (d1.adjustype = 2 or d1.adjustype = 3)
and h1.execdate > to_date( '202309012359','yyyy-mm-dd hh24:mi' )
and not exists(
select 1 from t_adjust_purprice_d d2,t_adjust_purprice_h h2
where d2.adjustno = h2.adjustno and h2.compid = 2
and h2.status = 1
and (d2.adjustype = 2 or d2.adjustype = 3)
and h2.execdate > to_date( '202312312359','yyyy-mm-dd hh24:mi' )
and h2.compid = h1.compid and d2.wareid = d1.wareid
and d2.batid = d1.batid and h2.execdate < h1.execdate)
order by execdate asc
) ad
on
ad.compid = a.compid
and ad.wareid = a.wareid
and ad.batid = a.batid
WHERE i.createtime <= to_date( '202309012359','yyyy-mm-dd hh24:mi' ) and i.compid = 2 AND w.compid=2 and nvl(w.insuranceno,'1')<>'1'
and a.busno ='266'
group by a.compid,a.busno,a.wareid ;
-----2222期末库存
--2222期末库存
SELECT max(i.ownerid) 保管账ID, a.compid 关联 , '默认货主' 保管账,
a.wareid AS 货品ID,
max(w.warename) AS 通用名,
max(w.warename) AS 商品名,
max(w.warespec) AS 规格,
max(w.wareunit) AS 基本单位,
max(f.factoryname) AS 生产厂商,
max(t_area.areafullname) AS 产地,
max(w.fileno) 批准文号,
max(wb.regno) as 注册证号,
max(i.buyer) AS 采购员ID,f_get_username(max(i.buyer)) as 采购员,
sum(a.wareqty) as 库存数量,
sum(round(a.wareqty * nvl(ad.purpriceo,i.purprice),2)) as 批次金额,
sum(round(a.wareqty * (nvl(ad.purpriceo,i.purprice)/(1+i.PURTAX/100)),2)) 批次无税金额
FROM (SELECT compid AS compid,
busno AS busno,
wareid AS wareid,
stallno AS stallno,
batid AS batid,
SUM(wareqty) AS wareqty
FROM (SELECT compid, busno, wareid, stallno, batid, wareqty
FROM t_store_d
WHERE compid = 2
UNION ALL
SELECT l.compid,
l.busno,
l.wareid,
l.stallno,
l.batid,
SUM(-l.inqty) AS wareqty
FROM t_store_inout_list l
WHERE l.execdate > to_date( '202411302359','yyyy-mm-dd hh24:mi' ) and l.compid = 2
GROUP BY l.compid, l.busno, l.wareid, l.batid, l.stallno)
GROUP BY compid, busno, wareid, stallno, batid) a
JOIN t_store_i i
ON a.wareid = i.wareid
AND a.batid = i.batid
JOIN t_ware w
ON a.compid = w.compid
AND a.wareid = w.wareid
JOIN t_ware_ext wb
ON wb.wareid = a.wareid
LEFT JOIN t_factory f
ON f.factoryid = w.factoryid
LEFT JOIN t_area
ON t_area.areacode = i.areacode
left join (select h1.compid,d1.wareid,d1.batid,d1.purpriceo,h1.execdate
from t_adjust_purprice_d d1,
t_adjust_purprice_h h1
where d1.adjustno = h1.adjustno
and h1.compid = 2
and h1.status = 1
and (d1.adjustype = 2 or d1.adjustype = 3)
and h1.execdate > to_date( '202411302359','yyyy-mm-dd hh24:mi' )
and not exists(
select 1 from t_adjust_purprice_d d2,t_adjust_purprice_h h2
where d2.adjustno = h2.adjustno and h2.compid = 2
and h2.status = 1
and (d2.adjustype = 2 or d2.adjustype = 3)
and h2.execdate > to_date( '202411302359','yyyy-mm-dd hh24:mi' )
and h2.compid = h1.compid and d2.wareid = d1.wareid
and d2.batid = d1.batid and h2.execdate < h1.execdate)
order by execdate asc
) ad
on
ad.compid = a.compid
and ad.wareid = a.wareid
and ad.batid = a.batid
WHERE i.createtime <= to_date( '202411302359','yyyy-mm-dd hh24:mi' ) and i.compid = 2 AND w.compid=2 and nvl(w.insuranceno,'1')<>'1'
and a.busno ='266'
group by a.compid,a.busno,a.wareid ;
|
|