SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[cpinstock]
(@FBillNO varchar(255),@FName varchar(255),@FQty decimal(28, 10),@FEntryID int, @insert int out)
as
begin
--存在生产任务单重复,请手工结案重复的生产任务单
if exists(
select 1 from icmo a
inner join t_icitem b on a.FItemID = b.FitemID
where substring(FBillNo,0,charindex('*',FBillNo)) = @FBillNO
and b.FName = @FName
and a.FSourceEntryID = @FEntryID
and a.FStatus = 1
group by b.FName,a.FSourceEntryID
having count(*)>1)
begin
--返回错误提示
set @insert = 2
end
---判断条件:生产任务单必须是下达状态,未完全入库
if exists(
select 1 from icmo a
inner join t_icitem b on a.FItemID = b.FitemID
where substring(FBillNo,0,charindex('*',FBillNo)) = @FBillNO
and b.FName = @FName
and a.FSourceEntryID = @FEntryID
and a.FStatus = 1
and (FQty-FCommitQty) < @FQty
)
begin
--返回错误提示
-- RAISERROR('错误:已入库!',16,1)
--不允许插入,更新变量为0,返回变量
set @insert = 0
end
else
begin
declare @FInterID_1 int
exec GetICMaxNum 'icstockbill',@FInterID_1 output,1
-- select @FInterID_1