set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON go
ALTER PROCEDURE [dbo].[StockINIDataOn] AS
SET NOCOUNT ON
DECLARE @pPeriodTmp VARCHAR (255)
DECLARE @Period INT --当前会计期间 DECLARE @Ptype VARCHAR (255)
DECLARE @CurYear INT --当前年份 DECLARE @CalType INT --核算方式 DECLARE @CurStartDate DATETIME DECLARE @CurEndDate DATETIME
DECLARE @BillNo VARCHAR (255) --单据号码
DECLARE @AuditChoice INT ---核算方式,--数量核算,--数量、金额核算
--电子行业:序列号检查
--检查SystemINISNDataOn存储过程的存在,存在则执行
IF EXISTS(SELECT 1 FROM sysobjects WHERE name = 'SystemINISNDataOn') EXEC SystemINISNDataOn
--电子行业:序列号检查 SET @AuditChoice = 0
SELECT @CurYear = CONVERT(INT, FValue) FROM t_SystemProfile WHERE FCategory = 'IC' AND FKey = 'CurrentYear'
IF @CurYear = NULL BEGIN
RAISERROR('~$~系统参数: 《IC--CurrentYear》数据被破坏^|^!',16,1) RETURN 0 END
EXEC GetSysPrm 'IC', 'CurrentPeriod', @pPeriodTmp OUTPUT, @pType OUTPUT
SELECT @Period = CONVERT(INT, @pPeriodTmp)
SELECT @CalType = CONVERT(INT, Fvalue) FROM t_SystemProfile WHERE FCategory = 'IC' AND FKey = 'CalculateType'
If @CalType = Null BEGIN
RAISERROR('~$~系统参数: 《IC--CalculateType 数据被破坏^|^!',16,1) RETURN 0
END
IF @CalType = 2 BEGIN
IF EXISTS (SELECT 1
FROM t_Stock
WHERE FTypeID IN (500, 20291, 20293) AND FStockGroupID = 0 ) BEGIN
RAISERROR('~$~系统检测到在分组核算模式下,还有实仓未分组^|^', 16, 1) RETURN 0 END
UPDATE t_Stock SET FGroupID = FStockGroupID WHERE FTypeID IN (500, 20291, 20293) END
IF @CalType = 1 BEGIN
UPDATE t_Stock SET FGroupID = FItemID WHERE FTypeID IN (500, 20291, 20293) END
IF @CalType = 0 BEGIN
UPDATE t_Stock SET FGroupID = 0 WHERE FTypeID IN (500, 20291, 20293) END
--当前会计期间的起止日期
EXEC GetPeriodStartEnd 0, @Period, @CurStartDate OUTPUT, @CurEndDate OUTPUT
IF (SELECT COUNT(*) FROM (SELECT DISTINCT FPeriod FROM ICInvInitial) AS t1) = 1
BEGIN
UPDATE ICInvInitial SET FPeriod = @Period UPDATE ICInvInitialAdj SET FPeriod = @Period END
ELSE IF (SELECT COUNT(*) FROM (SELECT DISTINCT FPeriod FROM ICInvInitial) AS t1) > 1 BEGIN
RAISERROR('~$~系统提示: 系统初始化表《ICInvInitial》含有多期数据,不符合启用条件^|^!', 16, 1) RETURN 0 END
SELECT @BillNo = FBillNo FROM ICStockBill
WHERE (FCheckerID IS NULL OR FCheckerID = 0) AND FTranType = 28 AND FDate < @CurStartDate
IF @@ROWCOUNT > 0 BEGIN
SET @BillNo = '~$~系统提示: 委外加工出库单--^|^' + @BillNo + '^|^~$~未审核,不符合启用条件^|^!'
RAISERROR(@BillNo, 16, 1) RETURN 0 END
SELECT @BillNo = FBillNo FROM ICStockBill
WHERE (FCheckerID IS NULL OR FCheckerID = 0) AND FTranType = 5 AND FDate < @CurStartDate
IF @@ROWCOUNT > 0 BEGIN
SET @BillNo = '~$~系统提示: 委外加工入库单--^|^' + @BillNo + '^|^~$~未审核,不符合启用条件^|^!'
RAISERROR(@BillNo, 16, 1) RETURN 0 END
--数量核算账套不检查金额
SELECT @AuditChoice = FValue FROM t_SystemProfile WHERE FKey = 'AuditChoice' AND FCategory = 'IC'
IF @AuditChoice = 1 BEGIN
SELECT @BillNo = B.FBillNo FROM ICStockBill B
INNER JOIN ICStockBillEntry E ON B.FInterID = E.FInterID AND B.FTranType = 28 AND E.FAmount = 0
WHERE B.FDate < @CurStartDate
IF @@ROWCOUNT > 0 BEGIN
SET @BillNo = '~$~系统提示: 委外加工出库单--^|^' + @BillNo + '^|^~$~中存在金额为的分录,不符合启用条件^|^!' RAISERROR(@BillNo, 16, 1) RETURN 0 END
SELECT @BillNo = B.FBillNo FROM ICStockBill B
INNER JOIN ICStockBillEntry E ON B.FInterID = E.FInterID AND B.FTranType = 5
AND (E.FMaterialCost = 0 OR E.FMaterialCostPrice = 0)
WHERE B.FDate < @CurStartDate
IF @@ROWCOUNT > 0 BEGIN
SET @BillNo = '~$~系统提示: 委外加工入库单--^|^' + @BillNo + '^|^~$~中存在金额为的分录,不符合启用条件^|^!' RAISERROR(@BillNo, 16, 1) RETURN 0 END END
--系统不允许负库存的时候,不允许出现负数 IF EXISTS (SELECT top 1 1 FROM ICInvInitial ti
INNER JOIN t_Stock ts ON ti.FStockID = ts.FItemID WHERE FBegQty < 0 AND ts.FUnderStock=0) BEGIN
RAISERROR('~$~系统不允许负库存,但是期初结存已经录入负数,不符合启用条件^|^!',16,1)
RETURN 0 END
TRUNCATE TABLE ICInvBal TRUNCATE TABLE ICBal TRUNCATE TABLE ICVMIInvBal
CREATE TABLE #ICInvBalTemp (
FStockID INT NOT NULL DEFAULT (0), FSPID INT NOT NULL DEFAULT (0), FItemID INT NOT NULL,
FBatchNo VARCHAR (200) NOT NULL DEFAULT (''), FMtoNo NVARCHAR (50) NOT NULL DEFAULT (''), FBegQty DECIMAL (28, 10) DEFAULT (0), FReceive DECIMAL (28, 10) DEFAULT (0), FSend DECIMAL (28, 10) DEFAULT (0), FYtdReceive DECIMAL (28, 10) DEFAULT (0), FYtdSend DECIMAL (28, 10) DEFAULT (0), FEndQty DECIMAL (28, 10) DEFAULT (0),
FBegBal DECIMAL (20, 2) NOT NULL DEFAULT (0),
FDebit DECIMAL (20, 2) NOT NULL DEFAULT (0), FCredit DECIMAL (20, 2) NOT NULL DEFAULT (0), FYtdDebit DECIMAL (20, 2) NOT NULL DEFAULT (0), FYtdCredit DECIMAL (20, 2) NOT NULL DEFAULT (0), FEndBal DECIMAL (20, 2) NOT NULL DEFAULT (0), FBegDiff DECIMAL (20, 2) NOT NULL DEFAULT (0), FReceiveDiff DECIMAL (20, 2) NOT NULL DEFAULT (0), FSendDiff DECIMAL (20, 2) NOT NULL DEFAULT (0), FEndDiff DECIMAL (20, 2) NOT NULL DEFAULT (0), FBillInterID INT IDENTITY(1,1),
FOldBillInterID INT NOT NULL DEFAULT (0), FEntryID INT NOT NULL DEFAULT (0),
FYtdReceiveDiff DECIMAL (20, 2) NOT NULL DEFAULT (0),
FYtdSendDiff DECIMAL (20, 2) NOT NULL DEFAULT (0), FSecBegQty DECIMAL (28, 10) NOT NULL DEFAULT (0), FSecReceive DECIMAL (28, 10) NOT NULL DEFAULT (0), FSecSend DECIMAL (28, 10) NOT NULL DEFAULT (0), FSecYtdReceive DECIMAL (28, 10) NOT NULL DEFAULT (0), FSecYtdSend DECIMAL (28, 10) NOT NULL DEFAULT (0), FSecEndQty DECIMAL (28, 10) NOT NULL DEFAULT (0), FStockInDate VARCHAR (20) NOT NULL DEFAULT (''), FAuxPropID INT NOT NULL DEFAULT (0),
FKFDate VARCHAR (20) NOT NULL DEFAULT (''), FKFPeriod INT NOT NULL DEFAULT (0),
FAuxUnitBegQty DECIMAL (28, 10) NOT NULL DEFAULT(0), FYtdAuxUnitSend DECIMAL (28, 10) NOT NULL DEFAULT(0), FYtdAuxUnitReceive DECIMAL (28, 10) NOT NULL DEFAULT(0), FSupplyID INT NOT NULL DEFAULT (0) ) CREATE TABLE #ICVMIInvBalTemp (
FStockID INT NOT NULL DEFAULT (0), FSPID INT NOT NULL DEFAULT (0), FItemID INT NOT NULL,
FBatchNo VARCHAR (200) NOT NULL DEFAULT (''), FMtoNo NVARCHAR (50) NOT NULL DEFAULT (''), FBegQty DECIMAL (28, 10) DEFAULT (0), FReceive DECIMAL (28, 10) DEFAULT (0), FSend DECIMAL (28, 10) DEFAULT (0), FYtdReceive DECIMAL (28, 10) DEFAULT (0), FYtdSend DECIMAL (28, 10) DEFAULT (0), FEndQty DECIMAL (28, 10) DEFAULT (0),
FBegBal DECIMAL (20, 2) NOT NULL DEFAULT (0),