金蝶K3供应链初始化存储过程 下载本文

内容发布更新时间 : 2024/12/24 20:25:58星期一 下面是文章的全部内容请认真阅读。

FReceiveDiff,Sum(t1.FSendDiff) As FSendDiff,

Sum(t1.FYtdReceiveDiff) As FYtdReceiveDiff,Sum(t1.FYtdSendDiff) As FYtdSendDiff, FAuxPropID,Sum(FAuxUnitBegQty) As FSecBegQty, t1.FBillInterID As FInterID, Sum(FYtdAuxUnitSend) As FSecYtdSend,Sum(FYtdAuxUnitReceive) As FSecYtdReceive,FStockInDate,

t1.FKFDate,t1.FKFPeriod,Sum(t1.FAuxUnitBegQty) As FAuxUnitBegQty, Sum(t1.FYtdAuxUnitSend) As FYtdAuxUnitSend,Sum(t1.FYtdAuxUnitReceive) As FYtdAuxUnitReceive,t1.FSupplyID FROM ICInvInitial t1 INNER JOIN t_icitem t3 ON t1.FItemID=t3.FItemID INNER JOIN t_Stock t4 ON t1.FStockID=t4.FItemID

WHERE t1.FPeriod=@Period And t3.FTrack= 79 AND t4.FTypeID = 504 GROUP BY t1.FStockID,t1.FItemID,t1.FBatchNo,t1.FMtoNo,FAuxPropID,FStockInDate,t1.FBillInterID,t1.FSPID,t1.FKFDate,t1.FKFPeriod,t1.FSupplyID) a ORDER BY a.FStockID,a.FItemID,a.FStockInDate DESC ,a.FBatchNo,a.FMtoNo,a.FAuxPropID,a.FInterID,a.FSPID,a.FKFDate,a.FKFPeriod,a.FSupplyID --VMI临时表结算库存余额结转进入ICVMIInvBal INSERT INTO ICVMIInvBal(FBrNo, FYear, FPeriod, FStockID, FStockPlaceID, FItemID, FBatchNo,FMtoNo,

FBegQty, FReceive, FSend, FYtdReceive, FYtdSend, FEndQty, FBegBal, FDebit, FCredit, FYtdDebit, FYtdCredit, FEndBal, FBegDiff, FReceiveDiff, FSendDiff, FYtdReceiveDiff, FYtdSendDiff,

FKFDate, FKFPeriod, FAuxPropID, FSecBegQty, FSecYtdSend, FSecYtdReceive,

FStockInDate,FBillInterID,FSupplyID) SELECT '0', @CurYear, @Period, FStockID, FSPID, FItemID, FBatchNo, FMtoNo,

FBegQty, FReceive, FSend, FYtdReceive, FYtdSend, FEndQty, FBegBal, FDebit, FCredit, FYtdDebit, FYtdCredit, FEndBal, FBegDiff,FReceiveDiff, FSendDiff, FYtdReceiveDiff, FYtdSendDiff,

FKFDate, FKFPeriod, FAuxPropID, FAuxUnitBegQty, FYtdAuxUnitSend, FYtdAuxUnitReceive,

FStockInDate,FBillInterID,FSupplyID FROM #ICVMIInvBalTemp UPDATE t1 SET FBillInterID=0 FROM ICVMIInvBal t1 inner join t_icitem t2 on t1.FItemID=t2.FItemID where t2.FTrack not in (78,79,20308) --即时库存来自库存初始化表ICInvInitial TRUNCATE TABLE ICInventory

INSERT INTO ICInventory (FBrNo, FItemID, FBatchNo,FMtoNo, FStockID, FQty, FBal, FStockPlaceID, FKFDate, FKFPeriod,

FAuxPropID,FSecQty,FSupplyID)

SELECT '0', FItemID, FBatchNo,FMtoNo, FStockID, SUM(FBegQty), SUM(FBegBal), FSPID, FKFDate, FKFPeriod,

FAuxPropID, SUM(FAuxUnitBegQty) ,FSupplyID FROM ICInvInitial

WHERE FPeriod = @Period

GROUP BY FStockID, FItemID, FBatchNo,FMtoNo, FSPID, FKFDate, FKFPeriod, FAuxPropID,FSupplyID --处理初始化余额表

UPDATE ICInvInitial SET FPeriod = 0 UPDATE t1 SET t1.FBillInterID=t2.FBillInterID from ICInvInitial t1

INNER join #ICInvBalTemp t2 on t1.FStockID=t2.FStockID and t1.FSPID=t2.FSPID and t1.FItemID=t2.FItemID and t1.FBatchNo=t2.FBatchNo and t1.FMtoNo=t2.FMtoNo and t1.FKFDate=t2.FKFDate AND t1.FKFPeriod =t2.FKFPeriod AND t2.FItemID=t1.FItemID AND

t1.FAuxPropID=t2.FAuxPropID AND t1.FStockInDate=t2.FStockInDate AND t1.FBillInterID=t2.FOldBillInterID AND t1.FSupplyID = t2.FSupplyID --从ICInvInitial备份普通仓结算余额数据到ICInvInitialAdj用于做期初余额调整 --VMI仓的余额不会变化

DELETE t1 FROM ICInvInitialAdj t1 INNER JOIN t_Stock t2 ON t1.FStockID = t2.FItemID WHERE t2.FTypeID <> 504

UPDATE ICInvInitialAdj SET FPeriod = 0 INSERT INTO ICInvInitialAdj(FBrNo,FPeriod,FStockID,FItemID,FBatchNo,FBegQty,FReceive,FSend,FYtdReceive, FYtdSend,FEndQty,FBegBal,FDebit,FCredit,FYtdDebit,FYtdCredit,FEndBal,FBegDiff,FReceiveDiff,FSendDiff, FBillInterID,FUnitID,FAuxBegQty,FYtdBegQty,FYtdAuxBegQty,FYtdAuxReceive,FYtdAuxSend,FYtdBegBal,

FYtdBegDiff,FYtdReceiveDiff,FYtdSendDiff,FKFDate,FKFPeriod,FSPID,FSecBegQty,FSecReceive,FSecSend, FSecYtdReceive,FSecYtdSend,FSecEndQty,FSecUnitID,FStockInDate,FAuxPropID,FSecCoefficient, FAuxUnitBegQty,FYtdAuxUnitBegQty,FYtdAuxUnitSend,FYtdAuxUnitReceive,FSNListID,FMTONo,FSupplyID) SELECT

'',0,t1.FStockID,t1.FItemID,t1.FBatchNo,t1.FBegQty,t1.FReceive,t1.FSend,t1.FYtdReceive,t1.FYtdSend, t1.FEndQty,t1.FBegBal,t1.FDebit,t1.FCredit,t1.FYtdDebit,t1.FYtdCredit,t1.FEndBal,t1.FBegDiff, t1.FReceiveDiff,t1.FSendDiff,t1.FBillInterID,t1.FUnitID,t1.FAuxBegQty,t1.FYtdBegQty,t1.FYtdAuxBegQty, t1.FYtdAuxReceive,t1.FYtdAuxSend,t1.FYtdBegBal,t1.FYtdBegDiff,t1.FYtdReceiveDiff,t1.FYtdSendDiff, t1.FKFDate,t1.FKFPeriod,t1.FSPID,t1.FSecBegQty,t1.FSecReceive,t1.FSecSend,t1.FSecYtdReceive, t1.FSecYtdSend,t1.FSecEndQty,t1.FSecUnitID,t1.FStockInDate,t1.FAuxPropID,t1.FSecCoefficient, t1.FAuxUnitBegQty,t1.FYtdAuxUnitBegQty,t1.FYtdAuxUnitSend,t1.FYtdAuxUnitReceive,t1.FSNListID, t1.FMTONo,t1.FSupplyID

FROM ICInvInitial t1 INNER JOIN t_Stock t2 ON t1.FStockID = t2.FItemID WHERE t2.FTypeID <> 504

UPDATE t1 SET FBillInterID=0 FROM ICInvInitialAdj t1 inner join t_icitem t2 on t1.FItemID=t2.FItemID where t2.FTrack not in (78,79,20308) UPDATE t1 SET FBillInterID=0 FROM ICInvInitial t1 inner join t_icitem t2 on t1.FItemID=t2.FItemID where t2.FTrack not in (78,79,20308)

DROP TABLE #ICInvBalTemp DROP TABLE #ICVMIInvBalTemp

UPDATE t_SystemProFile SET FValue = '0' WHERE FCategory = 'IC' AND FKey = 'InvDataPeriod'

UPDATE t_SystemProFile SET FValue = '1' WHERE FCategory = 'IC' AND FKey =

'ICClosed'

--处理启用前的单据

--初始化前的委外加工入库单默认为全部核销BT244631 MYQ V11.0 2007-11-08 UPDATE u1

SET u1.FCheckStatus = 2 FROM ICStockBill v1 INNER JOIN ICStockBillEntry u1 ON u1.FInterID=v1.FInterID WHERE v1.FDate < @CurStartDate AND v1.FTranType=5 UPDATE ICStockBill SET FVchInterID = -1

WHERE FDate < @CurStartDate AND FCancellation = 0

DELETE t1

FROM t_MakeVouchTemp t1

JOIN ICStockBill t2 ON t1.FSCBillInterID = t2.FInterID

WHERE t1.FTranType IN (4000, 5) AND t1.FPreVchInterID = 0 AND t1.FGroup = 0 AND t2.FDate < @CurStartDate AND t2.FTranType IN (1, 5) AND t2.FCancellation = 0

INSERT INTO t_MakeVouchTemp (FGroupID,FVchInterID,FPeriod,FYear,FVchNumber,FTranType,FSCBillInterID,FGroup,FPreVchInterID)

SELECT 0, -1, @Period, @CurYear, -1, CASE FTranType WHEN 1 THEN 4000 ELSE FTranType END, FInterID, 0, 0 FROM ICStockBill

WHERE FDate < @CurStartDate AND FTranType IN (1, 5) And FCancellation = 0

DELETE t1

FROM ICSaleVoucher t1

JOIN ICStockBill t2 ON t1.FInterID = t2.FInterID

WHERE t2.FDate < @CurStartDate AND t2.FTranType = 21 AND t2.FSaleStyle IN (102, 103) AND t2.FCancellation = 0

INSERT INTO ICSaleVoucher (FInterID,FVoucherID,FTypeID) SELECT FInterID, -1, 0 FROM ICStockBill

WHERE FDate < @CurStartDate AND FTranType = 21 AND FSaleStyle IN (102, 103) AND FCancellation = 0

RETURN 1