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

-- 生成时间:2018-06-19 15:34:08 by ebs-core  
CREATE  procedure order_240_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_240 where ord_id=@ordid  

 ---- 以下是开发人员写的 check order 事件 --------------
 declare @log varchar(1000)
declare @log1 varchar(1000)
declare @log2 varchar(1000)
declare @dp int

select  @log=ord_photos,@log1=ord_photos1,@log2=ord_photos2,@dp=ord_createdpid  from  #master n    

/*if  not exists(
select ord_updated from order_223 where ord_updated  between  (Select CONVERT(varchar(100), GETDATE(), 23) + ' 6:00:00.000')  and
(Select CONVERT(varchar(100), GETDATE(), 23) + ' 12:00:00.000'))
begin
    set @operation = 'abort'
    set @errorinfo = '必须在6：00到12：00之间！'
end*/

if (isnull(@log,'')='')
begin
set @operation='abort'
set @errorinfo = '请上传彩妆柜照片'
end

if (isnull(@log1,'')='')
begin
set @operation='abort'
set @errorinfo = '请上传护肤柜照片'
end
if (isnull(@log2,'')='')
begin
set @operation='abort'
set @errorinfo = '请上传饰品柜照片'
end


declare @log3 int
select @log3=COUNT(*)  from  order_240 where ord_createdpid=@dp and (ord_status ='已完成'  )  and  
ord_updated  between  (select CONVERT(varchar(7), getdate() , 120) + '-11'  )  and
(select CONVERT(varchar(7), getdate() , 120) + '-21'  ) and (select GETDATE())  between  (select CONVERT(varchar(7), getdate() , 120) + '-11'  )  and
(select CONVERT(varchar(7), getdate() , 120) + '-21'  )   
    

if (isnull(@log3,0)>0)
begin
set @operation='abort'
set @errorinfo = '11号到20号只能传一张'
end

if exists(select 1 from #master where  ord_ffggs =0 or ord_czggs =0 or ord_spggs =0   )
begin
set @operation ='abort'
    set @errorinfo ='请填写对应的货柜个数！'
end


declare @log4 int
select @log4=COUNT(*)  from  order_240 where ord_createdpid=@dp and (ord_status ='已完成' )  and  
ord_updated  between  (select CONVERT(varchar(7), getdate() , 120) + '-1'  )  and
(select CONVERT(varchar(7), getdate() , 120) + '-11'  ) and (select GETDATE())  between  (select CONVERT(varchar(7), getdate() , 120) + '-1'  )  and
(select CONVERT(varchar(7), getdate() , 120) + '-11'  )

if (isnull(@log4,0)>0)
begin
set @operation='abort'
set @errorinfo = '1号到10号只能传一张'
end

if not exists(
selecT 1 from #master where  (len(ord_photos)-len(replace(ord_photos, '|', '')))+1=(select ord_czggs  from #master ) )

begin
set @operation ='abort'
    set @errorinfo ='彩妆柜添加的照片数请与填写的彩妆柜个数保持一致！'
end

if not exists(
selecT 1 from #master where  (len(ord_photos2)-len(replace(ord_photos2, '|', '')))+1=(select ord_spggs  from #master ) )

begin
set @operation ='abort'
    set @errorinfo ='饰品柜添加的照片数请与填写的饰品柜个数保持一致！'
end


if not exists(
selecT 1 from #master where  (len(ord_photos1)-len(replace(ord_photos1, '|', '')))+1=(select ord_ffggs  from #master ) )

begin
set @operation ='abort'
    set @errorinfo ='护肤柜添加的照片数请与填写的护肤柜个数保持一致！'
end



if not exists(select 1  from #master  where ord_updated<(select CONVERT(varchar(7), getdate() , 120) + '-21'  ))

begin
set @operation ='abort'
    set @errorinfo ='只能1-20号上传'
end




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

exec drop_temp_table '#master' 

set nocount off 
end