USE [AIS20161026095136]
GO
/****** Object: StoredProcedure [dbo].[x_xlh] Script Date: 2017/1/23 13:16:02 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[x_xlh]
@fbillno varchar(50),@fbiller int
AS
BEGIN
declare @FInterid2 int
declare @FInterid int
declare @fcustid int
DECLARE @fdcstockid int
declare @fbase2 varchar(50)
declare @fbaseproperty varchar(50)
declare @fbaseproperty2 varchar(50)
declare @finteger int
declare @fentryid int
declare @fitemid int
declare @fid int
declare @ffmanagerid int
declare @fsmanagerid int
declare @FDeptid int
declare @Fbillno1 varchar(50)
declare @FbillnoBM varchar(50)
declare @fbillnolen int
declare @FUnitIDICItem int
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
select 1
select @FDeptid=fitemid from t_item where ffullnumber ='AU.01' and fitemclassid =2 --领料部门
select @ffmanagerid=fitemid from t_Emp --发料
select @fsmanagerid=fitemid from t_Emp --领料
-- 单据编号
select @FbillnoBM =FProjectVal from t_BillCodeRule where FBilltypeID='29' and FProjectID=1
select @fbillnolen=Flength,@Fbillno1=FProjectVal from t_BillCodeRule where FBilltypeID='29' and FProjectID=3
select @Fbillno1 = @FbillnoBM + Right('000000'+ @Fbillno1, @FbillnoLen)
select top 1 @fcustid=a1.fbase5 from t_bos200000001entry2 a1 inner join t_bos200000001 b1 on a1.fid=b1.fid where b1.fbillno=@fbillno
select @fbiller
--select @fdcstockid=535
exec GetICMaxNum 'ICStockbill',@FInterid2 output ,29,16394
select @fentryid=1
DECLARE #point_cursor3 CURSOR
FOR
SELECT a1.fbase2 ,a1.finteger,a1.fid,a1.FBase
FROM t_bos200000001entry2 a1 inner join t_bos200000001 b1 on a1.fid=b1.fid where b1.fbillno=@fbillno
OPEN #point_cursor3
FETCH NEXT FROM #point_cursor3 INTO @fbase2,@finteger,@fid,@fdcstockid
while @@fetch_status = 0
BEGIN
select @fitemid=fitemid from t_icitem where FItemID=@fbase2
select @FUnitIDICItem=funitid from t_ICItem where FItemID=@fitemid
--发货仓001
select @fdcstockid=fbase from t_BOS200000001Entry2 a1 inner join t_BOS200000001 b1 on a1.fid=b1.fid
where b1.FBillNo=@fbillno and a1.fbase5=@fitemid
insert into ICStockBillEntry (FBrNo,FInterID,FEntryID,FItemID,FQtyMust,FQty,FPrice,
FBatchNo,FAmount,FNote,FAuxPrice,FAuxQty,FAuxQtyMust,
FSourceEntryID,FSourceTranType,FSourceInterId,FSourceBillNo,
FICMOInterID,FPPBomEntryID,FOrderInterID,FOrderEntryID,
FOrderBillNo,FDCStockID,FPlanMode,FFatherProductID,FICMOBillNo,FUnitID)
values ('0',@FInterid2,@fentryid,@fitemid,@finteger,@finteger ,0,
0,0,'',0,@finteger ,@finteger,
0,'1007105',@fid,@fbillno,
@fid,@fentryid,@FInterid2,@fentryid,
@fbillno,@fdcstockid,'14036',@fitemid,@fbillno,@FUnitIDICItem )
select @fentryid=@fentryid+1
update ICInventory set fqty=fqty+@finteger where fitemid=@fitemid and FStockID=@fdcstockid
FETCH NEXT FROM #point_cursor3 INTO @fbase2,@finteger,@fid,@fdcstockid
END
CLOSE #point_cursor3
DEALLOCATE #point_cursor3
insert into ICStockBill (FBrNo,FInterID,FTranType,FDate,FBillNo,FNote,
FSupplyID,FFManagerID,FSManagerID,FBillerID,
FROB,FUpStockWhenSave,FOperDate,FMarketingStyle,
FSelTranType,FsourceType,
FPurposeID,FCussentAcctID,FPayCondition
,FSettleDate,FDCStockID,fcheckerid,fstatus,fcheckdate )
values ('0',@FInterid2,'29',convert(varchar(10),getdate(),120),@Fbillno1,'',
@fcustid,@ffmanagerid,@fsmanagerid,@fbiller,
'1','1',null,'12530',
'','37521'
,14190,1104,1000
,convert(varchar(10),getdate(),120),@fdcstockid,16393,1,convert(varchar(10),getdate(),120) )
update t_BillCodeRule set FProjectVal=(select Fprojectval from t_BillCodeRule Where FBillTypeID = '29' and FProjectID=3)+1 Where FBillTypeID = '29' and FProjectID=3
END
SELECT * FROM t_BOS200000001Entry2
SELECT * FROM t_Stock