|
|
@ -337,7 +337,7 @@ go
|
|
|
|
if exists(select * from sysobjects where name='p_create_orderdata' and xtype='p')
|
|
|
|
if exists(select * from sysobjects where name='p_create_orderdata' and xtype='p')
|
|
|
|
drop procedure p_create_orderdata
|
|
|
|
drop procedure p_create_orderdata
|
|
|
|
go
|
|
|
|
go
|
|
|
|
create procedure p_create_orderdata
|
|
|
|
CREATE procedure p_create_orderdata
|
|
|
|
(
|
|
|
|
(
|
|
|
|
@psusercode varchar(10),
|
|
|
|
@psusercode varchar(10),
|
|
|
|
@pstblname varchar(100),
|
|
|
|
@pstblname varchar(100),
|
|
|
@ -369,6 +369,7 @@ begin
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
select @susername=username from t_user where usercode = @psusercode
|
|
|
|
select @susername=username from t_user where usercode = @psusercode
|
|
|
|
|
|
|
|
----中央仓,缺货缺省采购订单有效天数
|
|
|
|
select @icgvaliddays=convert(int,itemvalue) from t_syscfg where section='system' and itemname='cgvaliddays'
|
|
|
|
select @icgvaliddays=convert(int,itemvalue) from t_syscfg where section='system' and itemname='cgvaliddays'
|
|
|
|
set @svaliddate=convert(varchar(10),dateadd(day,@icgvaliddays,getdate()),120)
|
|
|
|
set @svaliddate=convert(varchar(10),dateadd(day,@icgvaliddays,getdate()),120)
|
|
|
|
set @sarrivedate = convert(varchar(10),dateadd(day,4,getdate()),120)
|
|
|
|
set @sarrivedate = convert(varchar(10),dateadd(day,4,getdate()),120)
|
|
|
@ -389,9 +390,11 @@ begin
|
|
|
|
plucode,billno,orgcode
|
|
|
|
plucode,billno,orgcode
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
------20231108,调整根据判断数量进行调整Cgmode的方式,当要货数据大于等于判断数量(非0)为Cgmode=2,否则为Cgmode=1
|
|
|
|
set @ssql = 'insert into tmporderdata_param(plucode,billno,orgcode,cgmode,clmode,supcode,ordercnt,askcounts) '+
|
|
|
|
set @ssql = 'insert into tmporderdata_param(plucode,billno,orgcode,cgmode,clmode,supcode,ordercnt,askcounts) '+
|
|
|
|
'select a.plucode,a.billno,h.orgcode,b.cgmode,b.clmode,case when isnull(o.supcode,'''') <>'''' then o.supcode else p.supcode end as supcode,'+
|
|
|
|
'select a.plucode,a.billno,h.orgcode,
|
|
|
|
|
|
|
|
Case when (b.counts>=o.judgecnt And o.judgecnt >0) then ''2'' Else ''1'' end As cgmode,
|
|
|
|
|
|
|
|
b.clmode,case when isnull(o.supcode,'''') <>'''' then o.supcode else p.supcode end as supcode,'+
|
|
|
|
'p.ordercnt,b.counts '+
|
|
|
|
'p.ordercnt,b.counts '+
|
|
|
|
'from '+@pstblname+' a '+
|
|
|
|
'from '+@pstblname+' a '+
|
|
|
|
'join dbo.t_ask_body b on a.plucode = b.plucode and a.billno = b.billno '+
|
|
|
|
'join dbo.t_ask_body b on a.plucode = b.plucode and a.billno = b.billno '+
|
|
|
@ -437,6 +440,7 @@ begin
|
|
|
|
where cgmode = '1' and clmode = '0' and isnull(supcode,'') <> ''
|
|
|
|
where cgmode = '1' and clmode = '0' and isnull(supcode,'') <> ''
|
|
|
|
group by plucode,supcode,ordercnt
|
|
|
|
group by plucode,supcode,ordercnt
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* 2023-11-08 以下内容不用这么复杂的控制
|
|
|
|
if exists(select * from sysobjects where name = 'tmporderdata_onway' and xtype = 'U')
|
|
|
|
if exists(select * from sysobjects where name = 'tmporderdata_onway' and xtype = 'U')
|
|
|
|
drop table tmporderdata_onway
|
|
|
|
drop table tmporderdata_onway
|
|
|
|
create table tmporderdata_onway(
|
|
|
|
create table tmporderdata_onway(
|
|
|
@ -454,10 +458,13 @@ begin
|
|
|
|
from
|
|
|
|
from
|
|
|
|
(select plucode,sum(askcounts) as askcounts,sum(onwaycount) as onwaycount
|
|
|
|
(select plucode,sum(askcounts) as askcounts,sum(onwaycount) as onwaycount
|
|
|
|
from (
|
|
|
|
from (
|
|
|
|
|
|
|
|
/* 2023-11-08,物流已处理的状态订货数据,已经生成了采购订单了
|
|
|
|
select plucode,sum(b.counts) as askcounts, 0 as onwaycount from t_ask_body b,t_ask_head h
|
|
|
|
select plucode,sum(b.counts) as askcounts, 0 as onwaycount from t_ask_body b,t_ask_head h
|
|
|
|
where b.billno = h.billno and isnull(h.rzdate,'') <> '' and b.clstate = '1' and b.clmode = '0' and b.cgmode = '1'
|
|
|
|
where b.billno = h.billno and isnull(h.rzdate,'') <> '' and b.clstate = '1' and b.clmode = '0' and b.cgmode = '1'
|
|
|
|
group by b.plucode
|
|
|
|
group by b.plucode
|
|
|
|
union all
|
|
|
|
union all
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
-----只统计中央仓的采购订单执行状态的在途库存数据
|
|
|
|
select plucode,0 as askcounts, sum(b.counts-b.dhcount)as onwaycount from t_order_body b,t_order_head h,dbo.t_shop s
|
|
|
|
select plucode,0 as askcounts, sum(b.counts-b.dhcount)as onwaycount from t_order_body b,t_order_head h,dbo.t_shop s
|
|
|
|
where b.billno = h.billno and h.orgcode = s.orgcode and s.orgtype = '2'
|
|
|
|
where b.billno = h.billno and h.orgcode = s.orgcode and s.orgtype = '2'
|
|
|
|
and h.state = '1'
|
|
|
|
and h.state = '1'
|
|
|
@ -467,11 +474,40 @@ begin
|
|
|
|
)a,tmporderdata_cg b where a.plucode = b.plucode
|
|
|
|
)a,tmporderdata_cg b where a.plucode = b.plucode
|
|
|
|
|
|
|
|
|
|
|
|
--中央仓采购订单
|
|
|
|
--中央仓采购订单
|
|
|
|
|
|
|
|
-----处理冲减中央仓已有的库存数据和执行中的采购订单未到货库存数量
|
|
|
|
|
|
|
|
|
|
|
|
update a
|
|
|
|
update a
|
|
|
|
set a.counts = a.counts + b.askcount - b.onwaycount - isnull(o.gcount,0) - isnull(o.ccount,0)
|
|
|
|
set a.counts = a.counts + b.askcount - b.onwaycount - isnull(o.gcount,0) - isnull(o.ccount,0)
|
|
|
|
from tmporderdata_cg a join tmporderdata_onway b on a.plucode = b.plucode
|
|
|
|
from tmporderdata_cg a join tmporderdata_onway b on a.plucode = b.plucode
|
|
|
|
join t_plu_org o on a.plucode = o.plucode and o.orgcode = @sbranchno
|
|
|
|
join t_plu_org o on a.plucode = o.plucode and o.orgcode = @sbranchno
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*2023-11-08 以上内容不用这么复杂的控制
|
|
|
|
|
|
|
|
* ----按中央仓库存+中央仓采购订单执行状态且未收完货的数据
|
|
|
|
|
|
|
|
Select pluCode ,sum(onwaycount) as onwaycount From
|
|
|
|
|
|
|
|
(Select pluCode,(isnull(gcount,0)+isnull(ccount,0)) as onwaycount from t_plu_org where orgcode='c001'
|
|
|
|
|
|
|
|
union all
|
|
|
|
|
|
|
|
select plucode, sum(b.counts-b.dhcount) as onwaycount from t_order_body b,t_order_head h,dbo.t_shop s
|
|
|
|
|
|
|
|
where b.billno = h.billno and h.orgcode = s.orgcode and s.orgcode='c001'
|
|
|
|
|
|
|
|
and h.state = '1'
|
|
|
|
|
|
|
|
group by b.plucode ) TT group by plucode
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
---------20231108按中央仓库存+中央仓采购订单执行状态且未收完货的数据 ---20231109 在途库存需要减去物流已处理 中央仓未处理的配送要货单数量
|
|
|
|
|
|
|
|
update a
|
|
|
|
|
|
|
|
set a.counts = a.counts -o.onwaycount
|
|
|
|
|
|
|
|
from tmporderdata_cg a
|
|
|
|
|
|
|
|
join ( Select pluCode ,sum(onwaycount) as onwaycount From
|
|
|
|
|
|
|
|
(Select pluCode,(isnull(gcount,0)+isnull(ccount,0)) as onwaycount from t_plu_org where orgcode= @sbranchno
|
|
|
|
|
|
|
|
union all
|
|
|
|
|
|
|
|
select plucode, sum(b.counts-b.dhcount) as onwaycount from t_order_body b,t_order_head h,dbo.t_shop s
|
|
|
|
|
|
|
|
where b.billno = h.billno and h.orgcode = s.orgcode and s.orgcode= @sbranchno
|
|
|
|
|
|
|
|
and h.state = '1'
|
|
|
|
|
|
|
|
group by b.plucode
|
|
|
|
|
|
|
|
union all
|
|
|
|
|
|
|
|
select pluCode ,-sum(c.counts) as onwaycount from t_ask_body c , t_ask_head tah where c.cgmode='1' and clstate = '1' and c.billno = tah.billno and tah.state ='0'
|
|
|
|
|
|
|
|
group by c.plucode
|
|
|
|
|
|
|
|
) TT group by plucode ) o on a.plucode = o.plucode
|
|
|
|
|
|
|
|
|
|
|
|
update a
|
|
|
|
update a
|
|
|
|
set
|
|
|
|
set
|
|
|
|
counts = case ordercnt when 0 then counts else round(counts/ordercnt,0)*ordercnt end,
|
|
|
|
counts = case ordercnt when 0 then counts else round(counts/ordercnt,0)*ordercnt end,
|
|
|
@ -482,7 +518,6 @@ begin
|
|
|
|
order by signdate,c.contrno)
|
|
|
|
order by signdate,c.contrno)
|
|
|
|
,'')
|
|
|
|
,'')
|
|
|
|
from tmporderdata_cg a
|
|
|
|
from tmporderdata_cg a
|
|
|
|
|
|
|
|
|
|
|
|
where counts > 0
|
|
|
|
where counts > 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -531,7 +566,7 @@ begin
|
|
|
|
else
|
|
|
|
else
|
|
|
|
break
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
--print (@sorderno)
|
|
|
|
print (@sorderno)
|
|
|
|
insert into t_order_body(billno,serialno,plucode,pluname,barcode,cargono,spec,unit,price,counts,
|
|
|
|
insert into t_order_body(billno,serialno,plucode,pluname,barcode,cargono,spec,unit,price,counts,
|
|
|
|
jprice,netjprice,ornjprice,ornnetjprice,cost,netcost,jtaxrate,depcode,depname,remark,pcount,punit,itemcnt,sglcount,tag)
|
|
|
|
jprice,netjprice,ornjprice,ornnetjprice,cost,netcost,jtaxrate,depcode,depname,remark,pcount,punit,itemcnt,sglcount,tag)
|
|
|
|
select @sorderno,0 as serialno,a.plucode,g.pluname,g.barcode,g.cargono,g.spec,g.unit,o.price,a.counts,
|
|
|
|
select @sorderno,0 as serialno,a.plucode,g.pluname,g.barcode,g.cargono,g.spec,g.unit,o.price,a.counts,
|
|
|
@ -640,7 +675,7 @@ begin
|
|
|
|
|
|
|
|
|
|
|
|
declare curZ cursor for select distinct supcode,orgcode,contrno from tmporderdata_cg where counts > 0 and contrno <> '' order by orgcode,supcode
|
|
|
|
declare curZ cursor for select distinct supcode,orgcode,contrno from tmporderdata_cg where counts > 0 and contrno <> '' order by orgcode,supcode
|
|
|
|
open curZ
|
|
|
|
open curZ
|
|
|
|
fetch next from curZ into @ssupcode,@sorgcode,@scontrno
|
|
|
|
fetch next from curZ into @ssupcode,@sorgcode,@scontrno
|
|
|
|
while @@fetch_status = 0
|
|
|
|
while @@fetch_status = 0
|
|
|
|
begin
|
|
|
|
begin
|
|
|
|
select @sdate=convert(varchar(10),getdate(),20),@stime = substring(convert(varchar(20),getdate(),20),12,8)
|
|
|
|
select @sdate=convert(varchar(10),getdate(),20),@stime = substring(convert(varchar(20),getdate(),20),12,8)
|
|
|
|