IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[order_269_check]') AND type = 'P')
DROP PROCEDURE [dbo].[order_269_check]
GO

-- 生成时间:2018-11-29 16:53:13 by ebs-core  
CREATE  procedure order_269_check(
     @cmpid int,
     @branchid int,
     @userdpid int,
     @useruid int,
     @userotid int,
     @jbid bigint,
     @ordid bigint,
     @operation varchar(50) output,
     @errorinfo nvarchar(4000) output
  ) 
as  
begin  
set nocount on  
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
declare @ord2group2 nvarchar(50) 
set @ord2group2 = '' 
declare @sys_recid bigint 
set @sys_recid = 0 
 declare @nonedate datetime 
set @nonedate = CONVERT(datetime,'1910-1-1')
 set @operation = 'continue'
 set @errorinfo = '' 
 --- 以下是预处理事件中的临时表
 
exec drop_temp_table '#master' 
select * into #master from order_269 with(nolock) where ord_id=@ordid  

 ---- 以下是开发人员写的 check order 事件 --------------
 /*验证明细中是否存在已提交的数据(若存在则不允许提交)*/
declare @workid nvarchar(50)
declare @type1 nvarchar(50) = ''
select @type1 = ord_hplx from #master
select @workid = jb_wrkid from mps_job where jb_crmid = 269  and jb_id =@jbid
if(@workid = 3244)
begin
    if(@type1 = '维修机')
        begin
            if exists (select count(10) from order_269_2 where ord2_ordid = @ordid)
                begin   
                    if exists (select ord_id ,ord_dqzt 
                    from order_260 
                    where ord_id in (select ord2_fordid from order_269_2 a,order_260 b where a.ord2_ordid = @ordid) and ord_dqzt = '总部返货到门店')
                        begin
                            set @operation = 'abort'
                            set @errorinfo = '列表中有不需要被装箱的数据，其状态不是维修后总部收货！'
                        end
                end
            else
                    begin
                        set @operation = 'abort'
                        set @errorinfo = '非法操作！！列表中没有需要装箱信息！'
                    end
        end
        
    else if(@type1 = '旧件')
    begin
        if exists (select count(10) from order_269_2 where ord2_ordid = @ordid)
            begin
                if exists (select ord_id ,ord_status 
            from order_265 
            where ord_id in (select ord2_fordid from order_269_2 a,order_269 b where a.ord2_ordid = @ordid) and ord_status = '总部返货到门店')
            begin
            set @operation = 'abort'
                    set @errorinfo = '列表中有不需要被装箱的数据，其状态不是维修后总部收货！'
            end
            end
        else
            begin
                set @operation = 'abort'
                set @errorinfo = '非法操作！！列表中没有需要装箱信息！'
            end
    end
end
   

 ---- 以上是开发人员写的 check order 事件 --------------
 
 if (@operation='continue') 
 begin
 set @sys_recid=@sys_recid  -- here useless 
 
end 
--- 清除临时表 

exec drop_temp_table '#master' 

set nocount off 
end