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

-- 生成时间:2018-05-31 10:51:34 by ebs-core  
CREATE  procedure order_141_modify(
@cmpid int,
@branchid int,
@userdpid int,
@useruid int,
@userotid int,
@jbid bigint,
@ordid bigint,@sourcefield varchar(50)=default, 
@ord_createcuid int =default ,@ord_createdpid int =default ,@ord_cuid int =default ,@ord_dpid int =default ,@ord_fbizid int =default ,@ord_ford2tag int =default ,@ord_ygrs int =default ,@ord_noi int =default ,@ord_rbizid int =default ,@ord_rord2tag int =default ,@ord_security int =default ,@ord_style int =default ,@ord_templateid int =default ,@ord_enddate datetime =default ,@ord_gdrq datetime =default ,@ord_kyrq datetime =default ,@ord_sxwcsj datetime =default ,@ord_cbid bigint =default ,@ord_fjbid bigint =default ,@ord_ford2id bigint =default ,@ord_fordid bigint =default ,@ord_rord2id bigint =default ,@ord_rordid bigint =default ,@ord_ftype varchar(10) =default ,@ord_key varchar(30) =default ,@ord_no varchar(50) =default ,@ord_rtype varchar(10) =default ,@ord_branch nvarchar(50) =default ,@ord_bz nvarchar(100) =default ,@ord_createbizids nvarchar(200) =default ,@ord_createdepart nvarchar(50) =default ,@ord_creator nvarchar(50) =default ,@ord_cwcl nvarchar(100) =default ,@ord_jmsxm nvarchar(100) =default ,@ord_sxspqq nvarchar(100) =default ,@ord_dz nvarchar(100) =default ,@ord_lxfs nvarchar(100) =default ,@ord_jsdx nvarchar(1000) =default ,@ord_bznr nvarchar(100) =default ,@ord_pqdd nvarchar(100) =default ,@ord_pqzj nvarchar(100) =default ,@ord_qyjl nvarchar(100) =default ,@ord_szpq nvarchar(100) =default ,@ord_dplx nvarchar(100) =default ,@ord_fz nvarchar(100) =default ,@ord_wpcl nvarchar(100) =default ,@ord_wxsj nvarchar(100) =default ,@ord_xzzl nvarchar(100) =default ,@ord_yckcl nvarchar(100) =default ,@ord_ygcl nvarchar(100) =default ,@ord_zysx nvarchar(100) =default ,@ord_status nvarchar(30) =default ,@ord_sxblr nvarchar(100) =default ,@ord_syxp nvarchar(100) =default ,@ord_template nvarchar(50) =default ,@ord_title nvarchar(100) =default ,@ord_type nvarchar(50) =default ,@ord_jmht nvarchar(100) =default ,@ord_jmsj nvarchar(100) =default ,@ord_lxdh nvarchar(100) =default ,@ord_pxsc nvarchar(100) =default ,@ord_sfzhm nvarchar(100) =default ,@ord_sjxt nvarchar(100) =default ,@ord_depart nvarchar(50) =default ,@ord_dpbh nvarchar(100) =default ,@ord_dpdz nvarchar(100) =default ,@ord_dpfzr nvarchar(100) =default ,@ord_dpmc nvarchar(100) =default ,@ord_empname nvarchar(50) =default  ) 
as  
begin  
set nocount on  
declare @nonedate datetime 
set @nonedate = CONVERT(datetime,'1910-1-1')
 declare @operation varchar(50)
declare @errorinfo nvarchar(4000) 
 set @operation = 'continue' 
set @errorinfo = '' 
 --- 以下是预处理事件中的临时表
 update order_141 set 
ord_branch=case when @ord_branch is null or @ord_branch = '_none_'  then ord_branch else @ord_branch end,ord_bz=case when @ord_bz is null or @ord_bz = '_none_'  then ord_bz else @ord_bz end,ord_cbid=case when @ord_cbid is null or @ord_cbid = -999999999  then ord_cbid else @ord_cbid end,ord_createbizids=case when @ord_createbizids is null or @ord_createbizids = '_none_'  then ord_createbizids else @ord_createbizids end,ord_createcuid=case when @ord_createcuid is null or @ord_createcuid = -999999999  then ord_createcuid else @ord_createcuid end,ord_createdepart=case when @ord_createdepart is null or @ord_createdepart = '_none_'  then ord_createdepart else @ord_createdepart end,ord_createdpid=case when @ord_createdpid is null or @ord_createdpid = -999999999  then ord_createdpid else @ord_createdpid end,ord_creator=case when @ord_creator is null or @ord_creator = '_none_'  then ord_creator else @ord_creator end,ord_cuid=case when @ord_cuid is null or @ord_cuid = -999999999  then ord_cuid else @ord_cuid end,ord_cwcl=case when @ord_cwcl is null or @ord_cwcl = '_none_'  then ord_cwcl else @ord_cwcl end,ord_depart=case when @ord_depart is null or @ord_depart = '_none_'  then ord_depart else @ord_depart end,ord_dpbh=case when @ord_dpbh is null or @ord_dpbh = '_none_'  then ord_dpbh else @ord_dpbh end,ord_dpdz=case when @ord_dpdz is null or @ord_dpdz = '_none_'  then ord_dpdz else @ord_dpdz end,ord_dpfzr=case when @ord_dpfzr is null or @ord_dpfzr = '_none_'  then ord_dpfzr else @ord_dpfzr end,ord_dpid=case when @ord_dpid is null or @ord_dpid = -999999999  then ord_dpid else @ord_dpid end,ord_dpmc=case when @ord_dpmc is null or @ord_dpmc = '_none_'  then ord_dpmc else @ord_dpmc end,ord_empname=case when @ord_empname is null or @ord_empname = '_none_'  then ord_empname else @ord_empname end,ord_enddate=case when @ord_enddate is null or @ord_enddate = @nonedate then ord_enddate else @ord_enddate end,ord_fbizid=case when @ord_fbizid is null or @ord_fbizid = -999999999  then ord_fbizid else @ord_fbizid end,ord_fjbid=case when @ord_fjbid is null or @ord_fjbid = -999999999  then ord_fjbid else @ord_fjbid end,ord_ford2id=case when @ord_ford2id is null or @ord_ford2id = -999999999  then ord_ford2id else @ord_ford2id end,ord_ford2tag=case when @ord_ford2tag is null or @ord_ford2tag = -999999999  then ord_ford2tag else @ord_ford2tag end,ord_fordid=case when @ord_fordid is null or @ord_fordid = -999999999  then ord_fordid else @ord_fordid end,ord_ftype=case when @ord_ftype is null or @ord_ftype = '_none_'  then ord_ftype else @ord_ftype end,ord_gdrq=case when @ord_gdrq is null or @ord_gdrq = @nonedate then ord_gdrq else @ord_gdrq end,ord_jmht=case when @ord_jmht is null or @ord_jmht = '_none_'  then ord_jmht else @ord_jmht end,ord_jmsj=case when @ord_jmsj is null or @ord_jmsj = '_none_'  then ord_jmsj else @ord_jmsj end,ord_key=case when @ord_key is null or @ord_key = '_none_'  then ord_key else @ord_key end,ord_kyrq=case when @ord_kyrq is null or @ord_kyrq = @nonedate then ord_kyrq else @ord_kyrq end,ord_lxdh=case when @ord_lxdh is null or @ord_lxdh = '_none_'  then ord_lxdh else @ord_lxdh end,ord_no=case when @ord_no is null or @ord_no = '_none_'  then ord_no else @ord_no end,ord_noi=case when @ord_noi is null or @ord_noi = -999999999  then ord_noi else @ord_noi end,ord_pxsc=case when @ord_pxsc is null or @ord_pxsc = '_none_'  then ord_pxsc else @ord_pxsc end,ord_rbizid=case when @ord_rbizid is null or @ord_rbizid = -999999999  then ord_rbizid else @ord_rbizid end,ord_rord2id=case when @ord_rord2id is null or @ord_rord2id = -999999999  then ord_rord2id else @ord_rord2id end,ord_rord2tag=case when @ord_rord2tag is null or @ord_rord2tag = -999999999  then ord_rord2tag else @ord_rord2tag end,ord_rordid=case when @ord_rordid is null or @ord_rordid = -999999999  then ord_rordid else @ord_rordid end,ord_rtype=case when @ord_rtype is null or @ord_rtype = '_none_'  then ord_rtype else @ord_rtype end,ord_security=case when @ord_security is null or @ord_security = -999999999  then ord_security else @ord_security end,ord_sfzhm=case when @ord_sfzhm is null or @ord_sfzhm = '_none_'  then ord_sfzhm else @ord_sfzhm end,ord_sjxt=case when @ord_sjxt is null or @ord_sjxt = '_none_'  then ord_sjxt else @ord_sjxt end,ord_status=case when @ord_status is null or @ord_status = '_none_'  then ord_status else @ord_status end,ord_style=case when @ord_style is null or @ord_style = -999999999  then ord_style else @ord_style end,ord_sxblr=case when @ord_sxblr is null or @ord_sxblr = '_none_'  then ord_sxblr else @ord_sxblr end,ord_syxp=case when @ord_syxp is null or @ord_syxp = '_none_'  then ord_syxp else @ord_syxp end,ord_template=case when @ord_template is null or @ord_template = '_none_'  then ord_template else @ord_template end,ord_templateid=case when @ord_templateid is null or @ord_templateid = -999999999  then ord_templateid else @ord_templateid end,ord_title=case when @ord_title is null or @ord_title = '_none_'  then ord_title else @ord_title end,ord_type=case when @ord_type is null or @ord_type = '_none_'  then ord_type else @ord_type end,ord_wpcl=case when @ord_wpcl is null or @ord_wpcl = '_none_'  then ord_wpcl else @ord_wpcl end,ord_wxsj=case when @ord_wxsj is null or @ord_wxsj = '_none_'  then ord_wxsj else @ord_wxsj end,ord_xzzl=case when @ord_xzzl is null or @ord_xzzl = '_none_'  then ord_xzzl else @ord_xzzl end,ord_yckcl=case when @ord_yckcl is null or @ord_yckcl = '_none_'  then ord_yckcl else @ord_yckcl end,ord_ygcl=case when @ord_ygcl is null or @ord_ygcl = '_none_'  then ord_ygcl else @ord_ygcl end,ord_ygrs=case when @ord_ygrs is null or @ord_ygrs = -999999999  then ord_ygrs else @ord_ygrs end,ord_zysx=case when @ord_zysx is null or @ord_zysx = '_none_'  then ord_zysx else @ord_zysx end,ord_pqdd=case when @ord_pqdd is null or @ord_pqdd = '_none_'  then ord_pqdd else @ord_pqdd end,ord_pqzj=case when @ord_pqzj is null or @ord_pqzj = '_none_'  then ord_pqzj else @ord_pqzj end,ord_qyjl=case when @ord_qyjl is null or @ord_qyjl = '_none_'  then ord_qyjl else @ord_qyjl end,ord_szpq=case when @ord_szpq is null or @ord_szpq = '_none_'  then ord_szpq else @ord_szpq end,ord_dplx=case when @ord_dplx is null or @ord_dplx = '_none_'  then ord_dplx else @ord_dplx end,ord_fz=case when @ord_fz is null or @ord_fz = '_none_'  then ord_fz else @ord_fz end,ord_jmsxm=case when @ord_jmsxm is null or @ord_jmsxm = '_none_'  then ord_jmsxm else @ord_jmsxm end,ord_sxspqq=case when @ord_sxspqq is null or @ord_sxspqq = '_none_'  then ord_sxspqq else @ord_sxspqq end,ord_dz=case when @ord_dz is null or @ord_dz = '_none_'  then ord_dz else @ord_dz end,ord_lxfs=case when @ord_lxfs is null or @ord_lxfs = '_none_'  then ord_lxfs else @ord_lxfs end,ord_jsdx=case when @ord_jsdx is null or @ord_jsdx = '_none_'  then ord_jsdx else @ord_jsdx end,ord_sxwcsj=case when @ord_sxwcsj is null or @ord_sxwcsj = @nonedate then ord_sxwcsj else @ord_sxwcsj end,ord_bznr=case when @ord_bznr is null or @ord_bznr = '_none_'  then ord_bznr else @ord_bznr end,
ord_finished=case when ord_finished=0 then 1 else ord_finished end ,
ord_updated=getdate() 
where ord_id=@ordid 
 if (@operation='continue') 
 begin
 set @nonedate = @nonedate 
 
 if (@ord_fordid>0) -- 说明有可能在修改上级关系
begin
if (dbo.checkprocedure('order_141_calc_relation')=0)
begin
exec order_141_calc_relation @cmpid , @ordid 
end
end 
 select 'ok' operation, '' errorinfo 
end  else 
begin
select @operation operation, @errorinfo errorinfo  
end


-- 对项目进行处理
declare @style int 
declare @finished int 
select @style=ord_style , @finished=ord_finished from order_141 where ord_id=@ordid 
if (@style=0)
begin
if (@finished>=10 or @finished<=0) 
begin
delete mps_order where ord_bizid=141 and ord_id=@ordid 
end  else 
begin
if (exists (select 1 from mps_order where ord_bizid=141 and ord_id=@ordid)) 
begin
update a set 
a.ord_bcid=b.ord_bcid ,
a.ord_branch=b.ord_branch,
a.ord_createdpid=b.ord_createdpid,
a.ord_createdepart=b.ord_createdepart,
a.ord_dpid=b.ord_dpid,
a.ord_depart=b.ord_depart,
a.ord_createcuid=b.ord_createcuid,
a.ord_creator=b.ord_creator,
a.ord_cuid=b.ord_cuid,
a.ord_empname=b.ord_empname,
a.ord_date=b.ord_date,
a.ord_enddate=b.ord_enddate,
a.ord_finished=b.ord_finished,
a.ord_no=b.ord_no,
a.ord_title=b.ord_title,
a.ord_status=b.ord_status,
a.ord_type =b.ord_type
from mps_order a , order_141 b
where a.ord_bizid=141 and a.ord_id=b.ord_id and b.ord_id=@ordid 
end else
begin
insert into mps_order(
ord_bizid,
ord_id,
ord_cmpid,
ord_bcid,
ord_branch,
ord_createdpid,
ord_createdepart,
ord_dpid,
ord_depart,
ord_createcuid,
ord_creator,
ord_cuid,
ord_empname,
ord_date,
ord_enddate,
ord_finished,
ord_no,
ord_title,
ord_status,
ord_type )
select 
ord_bizid,
ord_id,
ord_cmpid,
ord_bcid,
ord_branch,
ord_createdpid,
ord_createdepart,
ord_dpid,
ord_depart,
ord_createcuid,
ord_creator,
ord_cuid,
ord_empname,
ord_date,
ord_enddate,
ord_finished,
ord_no,
ord_title,
ord_status,
ord_type
from order_141 where ord_id=@ordid 
end 
end 
end 
set nocount off 
end