金蝶自动生成拆卸单

ALTER PROCEDURE [dbo].[xp_icstockBill_chaixie]
@Fid_z varchar(255)
AS
BEGIN
set IDENTITY_INSERT icchangeentry on
declare @FDeptid int --领料部门
declare @FEmpID int --业务员
declare @ffmanagerid int --发料:
declare @fsmanagerid int --领料:
declare @FSupplyID int --供应商
declare @FbillnoBM varchar(100)
declare @FbillnoQZ varchar(100)
declare @fbillnolen int
declare @Fbillno varchar(100)
declare @FItemID int
declare @icmo_FInterid int
declare @FCostObjID int
declare @FInterid int
DECLARE @parent int
DECLARE @FCUSTID int
declare @fcheck int
declare @fidz int
if exists ( select 1 from X_chaixiedan where 标记 =@Fid_z )
begin

select @ffmanagerid=fitemid from t_Emp where fnumber ='06' --发料
select @fsmanagerid=fitemid from t_Emp where fnumber ='08' --领料
DECLARE #point_cursor CURSOR
FOR
select distinct parent_code,fid_z from X_chaixiedan where 标记=@Fid_z
OPEN #point_cursor

FETCH NEXT FROM #point_cursor INTO @parent,@fidz
while @@fetch_status = 0

BEGIN

exec GetICMaxNum 'icchangeentry',@FInterid output

select @FbillnoBM =FProjectVal from t_BillCodeRule where FBilltypeID='1007000' and FProjectID=1
select @fbillnolen=Flength,@Fbillno=FProjectVal from t_BillCodeRule where FBilltypeID='1007000' and FProjectID=3
select @Fbillno = @FbillnoBM + Right('000000'+ @Fbillno, @FbillnoLen)

insert into icchangeentry( fid,fEntryid,fmtrltype,

Fitemid, Fqty,fdcstockid,funitid)

select @FInterid,rank () OVER (ORDER BY a.fid_z) rank,a.组装拆卸类型

,b.fitemid,a.数量 ,c.fitemid,d.fitemid

from X_chaixiedan a
inner join t_stock c on a.仓库=c.fname
inner join t_icitem b on a.物料代码=b.fnumber
inner join t_MeasureUnit d on a.单位=d.fname
where 标记=@Fid_z and parent_code=@parent
--inner join t_icitem b on a.物料名称=b.fname
--inner join t_stock b on a.仓库=b.fname

select @fcheck=fitemid from t_emp k1 inner join X_chaixiedan a on a.审核人=k1.fname where a.标记=@Fid_z and a.fid_z=@fidz --审核人

insert into icchange ( fid,ftrantype,fdate,

fbillno,FCheckerID,fcheckdate,

fbillerid,FDeptid,FEmpID)

select @FInterid,'1007451',convert(varchar(10),getdate(),120),

@Fbillno,@fcheck,convert(varchar(10),getdate(),120)

,'16394', @FDeptid,@FEmpID

from X_chaixiedan a where 标记=@Fid_z and parent_code=@parent

update t_BillCodeRule set FProjectVal=(select Fprojectval from t_BillCodeRule Where FBillTypeID = '1007000' and FProjectID=3)+1 Where FBillTypeID = '1007000' and FProjectID=3


FETCH NEXT FROM #point_cursor INTO @parent,@fidz
end
CLOSE #point_cursor
DEALLOCATE #point_cursor
end
end

原文地址:https://www.cnblogs.com/xujiating/p/6370200.html