if exists(select * from sysobjects where name='p_rz_prepare_dz' and xtype='p') drop procedure p_rz_prepare_dz go create procedure p_rz_prepare_dz ( @psorgcode varchar(10), @psbillno varchar(20), @psparams varchar(200), @psmsg varchar(2000) out ) as begin declare @optoverstatus varchar(10) declare @ssupcode varchar(15) declare @ssupstatus varchar(1) declare @ssupvalidstatus varchar(1) select @ssupcode=supcode from t_paysoa_head where billno=@psbillno select @optoverstatus=itemvalue from t_syscfg where section='SYSTEM' and itemname='OVER' if @optoverstatus<>'STOP' begin set @psmsg='正在进行营业日结,请稍后记账' return(-1) end if not exists(select * from t_supplier where supcode=@ssupcode) begin set @psmsg='供应商不存在,不能记账' return(-1) end select @ssupstatus=supstatus, @ssupvalidstatus=case when (isnull(validdate,'')='' or validdate>=convert(varchar(100),getdate(),23)) then '1' else '0' end from t_supplier where supcode=@ssupcode if @ssupstatus<>'0' begin set @psmsg='供应商状态非正常,不能记账' return(-1) end if @ssupvalidstatus='0' begin set @psmsg='供应商已过有效期,不能记账' return(-1) end --CheckBillBatch select @psmsg=isnull(@psmsg+char(13),'')+billname+':' + ywbillno + ' 实际未对账:' + convert(varchar(20),convert(numeric(19,2),wftotal)) + ' 对账金额:'+convert(varchar(20),convert(numeric(19,2),bcjstotal)) from (select a.cost-a.jscost-a.zrcost as wftotal,b.bcjstotal,b.ywbillno, case b.billtype when '0' then '采购验收单' when '1' then '采购退货单' when '2' then '进价调整单' when '3' then '直送验收单' when '4' then '直送退货单' when '5' then '直送进价调整单' when '6' then '配送单' when '7' then '配送退货单' when '8' then '配送进价调整单' else '未知类型单据' end as billname from t_pay_bill a,t_paysoa_body b where a.billno=b.ywbillno and a.billtype=b.billtype and a.orgcode=b.orgcode and b.billno=@psbillno and ((a.jscost<>b.jstotal) or (a.zrcost<>b.zrtotal))) a if isnull(@psmsg,'')<>'' begin set @psmsg='以下单据的对账金额超过了实际的未对账或者单据已更改,请重新录入后再记账'+char(13)+@psmsg return(-1) end --UCheckHisPayBill set @psmsg='' return(1) end go if exists(select * from sysobjects where name='p_rz_dz' and xtype='p') drop procedure p_rz_dz go create procedure p_rz_dz ( @psorgcode varchar(10), @psbillno varchar(20), @psparams varchar(200), @psmsg varchar(2000) out ) as begin declare @scurdate varchar(10) declare @scurtime varchar(8) declare @ssupcode varchar(15) declare @sup_payable numeric(19,4) declare @sup_prepaytotal numeric(19,4) declare @dztotal numeric(19,4) declare @bczrtotal numeric(19,4) declare @feetotal numeric(19,4) declare @bcjstotal numeric(19,4) declare @xscost numeric(19,4) declare @ssql varchar(2000) declare @svbktablename varchar(20) declare @bodycount int select @scurdate=convert(varchar(100),getdate(),23),@scurtime=convert(varchar(100),getdate(),108) select @bodycount=count(billno) from t_paysoa_body where billno=@psbillno if @bodycount=0 begin --用于不选择单据,直接自动生成符合条件的所有单据明细,壳牌暂时用不到 --todo CheckPayForm --todo UAutoCreateJsPayBillDetail set @psmsg='对账单没有录入任何业务单据!' return(-1) end --CircleProcedure update b set b.jscost=b.jscost+a.bcjstotal,b.zrcost=b.zrcost+a.bczrtotal, b.isaccounted=case when a.total-a.jstotal-a.zrtotal-a.bcjstotal-a.bczrtotal=0 then '1' else '0' end from t_pay_bill b,t_paysoa_body a where a.billno=@psbillno and b.billtype=a.billtype and b.orgcode=a.orgcode and b.billno=a.ywbillno --AlterVendor select @ssupcode=supcode,@dztotal=dztotal,@bczrtotal=bczrtotal,@feetotal=feetotal,@bcjstotal=bcjstotal,@xscost=xscost from t_paysoa_head where billno=@psbillno update t_supplier set dztotal=dztotal+@dztotal,dzrtotal=dzrtotal+@bczrtotal,feetotal=feetotal+@feetotal, dywtotal=dywtotal+@bcjstotal,xscost=xscost+@xscost where supcode=@ssupcode --WriteVendorBook set @svbktablename='t_vbk_'+substring(convert(varchar(100),getdate(),112),1,6) exec p_create_vbk @svbktablename,@psmsg out if isnull(@psmsg,'')<>'' begin return(-1) end select @sup_payable=jhtotal-thtotal+tjtotal,@sup_prepaytotal=prepay from t_supplier where supcode=@ssupcode if (@feetotal<>0) begin set @ssql='insert into t_vbk_'+ substring(convert(varchar(100),getdate(),112),1,6)+'(orgcode,bookdate,booktime,supcode ,billno,billtype,fsamount,yfjytotal,prejytotal)' +' values('''+@psorgcode+''','''+@scurdate+''','''+@scurtime+''','''+@ssupcode+''','''+@psbillno+''',''8'','+convert(varchar(20),-@feetotal)+','+convert(varchar(20),@sup_payable-@feetotal)+','+convert(varchar(20),@sup_prepaytotal)+')' exec(@ssql) end if (@bczrtotal<>0) begin set @ssql='insert into t_vbk_'+ substring(convert(varchar(100),getdate(),112),1,6)+'(orgcode,bookdate,booktime,supcode ,billno,billtype,fsamount,yfjytotal,prejytotal)' +' values('''+@psorgcode+''','''+@scurdate+''','''+@scurtime+''','''+@ssupcode+''','''+@psbillno+''',''9'','+convert(varchar(20),-@bczrtotal)+','+convert(varchar(20),@sup_payable-@feetotal-@bczrtotal)+','+convert(varchar(20),@sup_prepaytotal)+')' exec(@ssql) END --更新条款上次处理日期 update b set b.cldate=convert(varchar(19),getdate(),120) from t_contr_clause b, t_paysoa_clause a where a.billno=@psbillno and b.contrno=a.contrno and b.supcode=a.supcode and b.orgcode=a.orgcode and b.itemcode=a.itemcode and b.itemno=a.itemno --终止采购单 update c set c.state='9',statedate=convert(varchar(10),getdate(),21),statetime=convert(varchar(8),getdate(),108) from t_order_head c,t_paysoa_body a,t_accept_head b where a.ywbillno=b.billno and b.orderno=c.billno and a.billtype in ('0','3') and a.billno=@psbillno set @psmsg='' return(1) end go