|
|
|
|
|
|
|
|
update OP_WMS set WMSBASEID=WMSID where exists(select 1 from OP_WMS_CHANGE where wmsid=op_wms.WMSID and CHANGETYPE='入库')
|
|
|
--基础数据
|
|
|
insert into OP_WMS_BASE select WMSID,BSNO,BILLTYPE,REMARK,CORPID,CreateID,Creator,CreateDate,CUSTOMERNAME,MATERIALNO,GOODSCODE,GOODSNAME,GOODSHSCODE
|
|
|
,MBLNO,CNTRNO,KGS,CBM,PKGS,KINDPKGS,STORAGEUNIT,STORAGEUNITCOUNT,RULEUNIT,RULEUNITCOUNT,FEEENDDATE,FEESTARTDATE,INDATE,STORAGEUNITCOUNT_SINGLE
|
|
|
,RULEUNITCOUNT_SINGLE,OP,NETWEIGHT,CUSTOMNO,ACCBOOKNO,GOODSOWNER,FEERATESTARTDATE,WMSINDATE,ARCLIENTWMSOUT,COUNTRY
|
|
|
from op_wms where exists(select 1 from OP_WMS_CHANGE where wmsid=op_wms.WMSID and CHANGETYPE='入库')
|
|
|
|
|
|
select * from OP_WMS_CHANGE where CHANGETYPE like '%移库%'
|
|
|
|
|
|
select * from OP_WMS where exists(select 1 from OP_WMS_CHANGE where CHANGETYPE like '货转入库' and wmsid=OP_WMS.wmsid)
|
|
|
|
|
|
select WMSBASEID,* from OP_WMS where wmsid in(
|
|
|
select WMSID from OP_WMS_TRANSFERGOODS_DETAIL where WMSID_NEW in(
|
|
|
select wmsid from OP_WMS where exists(select 1 from OP_WMS_CHANGE where CHANGETYPE like '货转入库' and wmsid=OP_WMS.wmsid)
|
|
|
))
|
|
|
|
|
|
|
|
|
update OP_WMS set WMSBASEID=(
|
|
|
select WMSBASEID from OP_WMS w2 where wmsid in(
|
|
|
select WMSID from OP_WMS_TRANSFERGOODS_DETAIL where WMSID_NEW in(
|
|
|
select wmsid from OP_WMS w where exists(select 1 from OP_WMS_CHANGE where CHANGETYPE like '货转入库' and wmsid=OP_WMS.wmsid)
|
|
|
and w.wmsid = OP_WMS.WMSID
|
|
|
))
|
|
|
) where exists(select 1 from OP_WMS_CHANGE where CHANGETYPE like '货转入库' and wmsid=OP_WMS.wmsid)
|
|
|
|
|
|
--delete from OP_WMS_FEEPAYINFO
|
|
|
|
|
|
--select * from OP_WMS_FEEPAYINFO order by wmsid,feestartdate
|
|
|
|
|
|
insert into OP_WMS_FEEPAYINFO
|
|
|
select newid() GID,WMSID,WMSID WMSBASEID,FEESTARTDATE,null,WMSID,WMSID,ARCLIENTWMSOUT,'',ARCLIENTWMSOUT,'',ARCLIENTWMSOUT,'',STORAGEUNITCOUNT from OP_WMS where exists(select 1 from OP_WMS_CHANGE where wmsid=op_wms.WMSID and CHANGETYPE='入库') and not exists(
|
|
|
select 1 from OP_WMS_FEEPAYINFO where wmsid=OP_WMS.WMSID
|
|
|
)
|
|
|
--drop table temp_TRANSFERGOODS_DETAIL
|
|
|
select * into temp_TRANSFERGOODS_DETAIL from OP_WMS_TRANSFERGOODS_DETAIL where exists (select 1 from OP_WMS_FEEPAYINFO where WMSID=OP_WMS_TRANSFERGOODS_DETAIL.WMSID)
|
|
|
and not exists(select 1 from OP_WMS_FEEPAYINFO where WMSID=OP_WMS_TRANSFERGOODS_DETAIL.WMSID_NEW) and OP_WMS_TRANSFERGOODS_DETAIL.WMSID_NEW in(select wmsid from op_wms)
|
|
|
and OP_WMS_TRANSFERGOODS_DETAIL.WMSID_NEW is not null
|
|
|
|
|
|
--select * from OP_WMS_TRANSFERGOODS_DETAIL where exists (select 1 from OP_WMS_FEEPAYINFO where WMSID=OP_WMS_TRANSFERGOODS_DETAIL.WMSID)
|
|
|
--and not exists(select 1 from OP_WMS_FEEPAYINFO where WMSID=OP_WMS_TRANSFERGOODS_DETAIL.WMSID_NEW) and OP_WMS_TRANSFERGOODS_DETAIL.WMSID_NEW in(select wmsid from op_wms)
|
|
|
--and OP_WMS_TRANSFERGOODS_DETAIL.WMSID_NEW is not null
|
|
|
--select * from temp_TRANSFERGOODS_DETAIL
|
|
|
--对这些库存进行如下操作:
|
|
|
--1 将父库存的feeenddate改为货转执行日期 将子节点的feestartdate改为货转日期的第二天
|
|
|
|
|
|
update OP_WMS set FEEENDDATE=(select TRANSFERDATE from OP_WMS_TRANSFERGOODS where WMSTRANSFERGOODSID=(select top 1 WMSTRANSFERGOODSID from temp_TRANSFERGOODS_DETAIL where WMSID=OP_WMS.WMSID)) where exists(select 1 from temp_TRANSFERGOODS_DETAIL where WMSID=OP_WMS.wmsid)
|
|
|
|
|
|
--select FEEENDDATE, * from OP_wms where exists(select 1 from temp_TRANSFERGOODS_DETAIL where WMSID=OP_WMS.wmsid)
|
|
|
|
|
|
update OP_WMS set FEESTARTDATE=DATEADD(DAY,1,(select TRANSFERDATE from OP_WMS_TRANSFERGOODS where WMSTRANSFERGOODSID=(select top 1 WMSTRANSFERGOODSID from temp_TRANSFERGOODS_DETAIL where WMSID_NEW=OP_WMS.WMSID))) where exists(select 1 from temp_TRANSFERGOODS_DETAIL where WMSID_NEW=OP_WMS.wmsid)
|
|
|
|
|
|
--select FEESTARTDATE, * from OP_wms where exists(select 1 from temp_TRANSFERGOODS_DETAIL where WMSID_NEW=OP_WMS.wmsid)
|
|
|
|
|
|
--select * from OP_WMS_TRANSFERGOODS_DETAIL where WMSID in (select WMSID from OP_WMS_TRANSFERGOODS_DETAIL group by WMSID having count(WMSID) > 1)order by WMSID
|
|
|
|
|
|
--2 复制所有父库存的 【FEESTARTDATE小于子节点的feestartdate】 的费用变动表 日期改为子库存的FEESTARTDATE
|
|
|
|
|
|
insert into OP_WMS_FEEPAYINFO
|
|
|
select newid(),WMSID_NEW,WMSBASEID,feedate FEESTARTDATE,ARCLIENTWMSOUT,APCLIENTWMSOUT,ARCLIENTWMSIN,APCLIENTWMSIN,ARCLIENTWMS_OUTDO,APCLIENTWMS_OUTDO from (
|
|
|
select (select FEESTARTDATE from OP_WMS where wmsid=(select wmsid_new from temp_TRANSFERGOODS_DETAIL where wmsid=OP_WMS_FEEPAYINFO.wmsid)) feedate
|
|
|
,(select WMSID_NEW from temp_TRANSFERGOODS_DETAIL where wmsid =OP_WMS_FEEPAYINFO.wmsid) WMSID_NEW
|
|
|
, * from OP_WMS_FEEPAYINFO where wmsid in(select wmsid from temp_TRANSFERGOODS_DETAIL) )t1 where feedate is not null
|
|
|
|
|
|
--3 子库存增加一条记录 FEESTARTDATE为货转的费用截止日期第二天,应收对象为货转业务的 ARCLIENTWMSOUT
|
|
|
insert into OP_WMS_FEEPAYINFO
|
|
|
select newid(),WMSID_NEW,w.WMSBASEID,w.FEESTARTDATE,t.ARCLIENTWMSOUT,'',t.ARCLIENTWMSOUT,'',t.ARCLIENTWMSOUT,'' from temp_TRANSFERGOODS_DETAIL D
|
|
|
left join op_wms w on w.wmsid=d.WMSID_NEW
|
|
|
left join OP_WMS_TRANSFERGOODS t on t.WMSTRANSFERGOODSID=d.WMSTRANSFERGOODSID where w.FEESTARTDATE is not null
|
|
|
--where (select count(1) from OP_WMS_FEEPAYINFO where wmsid=D.WMSID_NEW)=1
|
|
|
|
|
|
|
|
|
select * from OP_WMS_FEEPAYINFO where WMSID in (select WMSID from OP_WMS_FEEPAYINFO group by WMSID having count(WMSID) > 1) order by wmsid,FEESTARTDATE
|
|
|
|
|
|
|
|
|
|
|
|
select * from op_wms where wmsid='61FEF391-3968-48D1-9A54-00263BFF24FC'
|
|
|
|
|
|
delete from OP_WMS_FEEPAYINFO where gid in(
|
|
|
select
|
|
|
--fp.ARCLIENTWMSOUT,t2.ARCLIENTWMSOUT,
|
|
|
fp.gid from OP_WMS_FEEPAYINFO fp left join(
|
|
|
|
|
|
select t.ARCLIENTWMSOUT,w.wmsid from OP_WMS_TRANSFERGOODS t
|
|
|
left join OP_WMS_TRANSFERGOODS_DETAIL d on d.WMSTRANSFERGOODSID=t.WMSTRANSFERGOODSID
|
|
|
left join op_wms w on w.WMSID=d.WMSID_NEW
|
|
|
where t.WMSTRANSFERGOODSID in(select WMSTRANSFERGOODSID from OP_WMS_TRANSFERGOODS_DETAIL where WMSID_NEW in(select wmsid from OP_WMS_FEEPAYINFO where WMSID in (select WMSID from OP_WMS_FEEPAYINFO group by WMSID having count(WMSID) > 1)
|
|
|
)) )t2 on t2.WMSID=fp.wmsid where fp.ARCLIENTWMSOUT<>t2.ARCLIENTWMSOUT)
|
|
|
|
|
|
select * from OP_WMS_FEEPAYINFO where ARCLIENTWMSOUT is null
|
|
|
|
|
|
select * from OP_WMS_TRANSFERGOODS where ARCLIENTWMSOUT is null
|
|
|
|