金蝶K3销售订单无法完成表

统计出要求出货日期前无法完成的销售订单

 

CREATE proc stkd_销售_订单无法完成表
@begdate datetime,
@enddate datetime
as

set nocount on
select @begdate='1900-1-1' where @begdate=''
select @enddate='2999-12-31' where @enddate=''

create table #aa(
finterid 
int,
fbillno 
varchar(20),
fdate 
datetime,
fcust 
varchar(80),
fnumber 
varchar(80),
fname 
varchar(80),
fmodel 
varchar(50),
fqty 
decimal(18,2default(0),
faskdate 
datetime,
femp 
varchar(20),
fentryid 
int,
ficqty 
decimal(18,2default(0),
fstockqty 
decimal(18,2default(0),
fseqty 
decimal(18,2default(0)
)


insert into #aa(finterid,fbillno,fdate,fcust,fnumber,fname,fmodel,fqty,faskdate,femp,fentryid)
select se.finterid,se.fbillno,se.fdate,tog.fname,ti.fnumber,ti.fname,ti.fmodel,see.fqty,see.fdate,te.fname,see.fentryid
--im.fqty,ice.fqty,seoe.fqty
from seorder se inner join seorderentry see on se.finterid=see.finterid
inner join t_organization tog on se.fcustid=tog.fitemid
inner join t_icitem ti on see.fitemid=ti.fitemid
inner join t_emp te on se.fempid=te.fitemid

left join SEOutStockentry seoe on seoe.fsourceinterid=se.finterid and seoe.fentryid=see.fentryid
where se.fdate>=@begdate and se.fdate<=@enddate and se.fstatus<>3

update t1
set t1.fstockqty=t2.fqty
from #aa t1,(
select im.forderinterid,im.fsourceentryid,sum(ice.fqty) as fqty
from icmo im
left join icstockbillentry ice on ice.finterid in (select finterid from icstockbill where ftrantype=2)
and ice.ficmointerid=im.finterid
group by im.forderinterid,im.fsourceentryid
) t2
where t1.finterid=t2.forderinterid and t1.fentryid=t2.fsourceentryid

update t1
set t1.fseqty=t2.fqty
from #aa t1,(
select seoe.fsourceinterid,seoe.fsourceentryid,sum(seoe.fqty) as fqty
from SEOutStockentry seoe
group by seoe.fsourceinterid,seoe.fsourceentryid
) t2
where t1.finterid=t2.fsourceinterid and t1.fentryid=t2.fsourceentryid

delete from #aa where fstockqty>=fqty
delete from #aa where fseqty>=fqty
--select * from seorder where month(fdate)=4finterid in (select finterid from icstockbill where ftrantype=2) and ficmointerid<>0

select fbillno as 订单号,fdate as 下单日期,fcust as 客户,fnumber as 物料编码,fname as 物料名称,fmodel as 规格,
fqty 
as 下单数量,faskdate as 要求到货日期,femp as 业务员,fstockqty as 入库数量,fseqty as 通知单数量 
from #aa

GO
posted @ 2008-08-07 02:19  arrowolf  阅读(760)  评论(0)    收藏  举报