if exists(select * from sysobjects where name='p_rz_cnt' and xtype='p') drop procedure p_rz_cnt go create procedure p_rz_cnt ( @psorgcode varchar(10), @psbillno varchar(20), @psparams varchar(200), @psmsg varchar(2000) out ) as begin declare @sisgenoq varchar(1) declare @sorgcode varchar(10) declare @ssupcode varchar(15) declare @sjymode varchar(1) declare @sjscode varchar(1) declare @sdkrate varchar(500) declare @soqbillno varchar(20) declare @scurdate varchar(10) declare @scurtime varchar(8) set @sisgenoq=isnull(@psparams,'1') set @soqbillno='' select @sorgcode=orgcode,@ssupcode=supcode,@sjymode=jymode,@sjscode=jscode,@sdkrate=ext3 from t_contract where contrno=@psbillno select @scurdate=convert(varchar(100),getdate(),23),@scurtime=convert(varchar(100),getdate(),108) if @sjscode not in ('0','1') begin begin set @psmsg='合同结算方式不正确,必须为经销、代销结算' return(-1) end end if @sisgenoq = '1' begin --根据合同商品自动生成初始化合同报价单 exec f_get_billno 'oq',@psorgcode,'1',@soqbillno output --合同报价单头 insert into t_orderquote_head(billno,contrno,orgcode,supcode,supname,quotetype,lrdate,lrtime,rzdate,rztime,usercode,username,zdrcode,zdrname,shrcode,shrname,chkstatus,remark) select @soqbillno,contrno,@psorgcode,supcode,isnull((select supname from t_supplier where supcode=cnt.supcode),'') as supname,'0',@scurdate,@scurtime,@scurdate,@scurtime, usercode,username,usercode,username,'','','0','合同执行初始化生成' from t_contract cnt where contrno=@psbillno --合同报价单商品明细 insert into t_orderquote_body(billno,serialno,plucode,barcode,pluname,cargono,spec,unit,jtaxrate,depcode,depname,remark) select @soqbillno,row_number() over(order by p.plucode) as serialno,p.plucode,p.barcode,p.pluname,p.cargono,p.spec,p.unit,p.jtaxrate, u.depcode,(select depname from t_dept where depcode=u.depcode) as depname,'' from t_contr_plu p,t_plu u where p.plucode=u.plucode and p.contrno=@psbillno --合同报价单机构明细 insert into t_orderquote_org(BillNo,SerialNo,PluCode,OrgCode,JPrice,NetJPrice,Remark) select @soqbillno,oqb.SerialNo,p.plucode,o.orgcode,p.jprice,p.netjprice,'' from t_contr_org o,t_contr_plu p,t_orderquote_body oqb where o.contrno=p.contrno and p.plucode=oqb.plucode and o.contrno=@psbillno and oqb.BillNo=@soqbillno --调用记账过程 exec p_rz_oq @psorgcode,@soqbillno,'',@psmsg output if @@error <> 0 begin set @psmsg = '生成的合同报价单记账失败:' + @psmsg return(-1) end end if @sjscode='2' begin --联销合同更新组织商品的倒扣率 update p set p.dkrate = convert(numeric(19,4),@sdkrate) from t_plu_org p where supcode=@ssupcode and exists(select orgcode from t_contr_org c where c.orgcode=p.orgcode and c.contrno=@psbillno) end update t_contract set contrstatus='0',statusdate=@scurdate where contrno=@psbillno set @psmsg='' return(1) end go