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

-- 生成时间:2018-06-13 15:14:19 by ebs-core  
CREATE  procedure order_242_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  
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_242 where ord_id=@ordid  

exec drop_temp_table '#rodetail2' 
select * into #rodetail2 from order_242_2 where ord2_ordid=@ordid  

 ---- 以下是开发人员写的 check order 事件 --------------
 declare @log int
declare @log1 int

select  @log=sum(ord2_je)  from   order_242_2 where  ord2_ordid in  (select  ord_id from   order_242   where  ord_createdpid = @userdpid and ord_jidu =(select  (   select  DateName(year,GetDate()) )  +''+(select  DATENAME(QUARTER,getdate()))) and (ord_status='已完成' or ord_status='审核中') )  and  ord2_cplx !='固定物资' 
select  @log1=sum(ord2_je)  from   #rodetail2 where  ord2_ordid in  (select  ord_id from   #master   where  ord_createdpid = @userdpid  )  and  ord2_cplx !='固定物资'

if((isnull(@log,0)+isnull(@log1,0))>600)

begin
set @operation='abort'
set @errorinfo = '彩妆护肤该季度超过600了'
end
 



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

exec drop_temp_table '#master' 

set nocount off 
end