You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

863 lines
30 KiB

--<EFBFBD>ŵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
1 year ago
if exists(select * from sysobjects where name='p_circle_proc_by_trans' and xtype='p')
drop procedure p_circle_proc_by_trans
go
create procedure p_circle_proc_by_trans
(
@pstrmode varchar(1),
@psbillno varchar(20),
@psorgcode varchar(10),
@psmsg varchar(2000) out
)
as
begin
declare @curdate varchar(10)
declare @curtime varchar(8)
declare @pisout varchar(1)
declare @poutorgcode varchar(10)
declare @pinorgcode varchar(10)
declare @splace varchar(1)
declare @pbilltype varchar(1)
declare @pplucode varchar(20)
8 months ago
declare @detail_serialno int
1 year ago
declare @detail_jprice numeric(19,4)
declare @detail_netjprice numeric(19,4)
declare @detail_price numeric(19,4)
declare @detail_cost numeric(19,4)
declare @detail_netcost numeric(19,4)
declare @detail_total numeric(19,4)
declare @detail_counts numeric(19,4)
declare @detail_plancounts numeric(19,4)
declare @detail_depcode varchar(10)
declare @goods_price numeric(19,4)
declare @goods_netjprice numeric(19,4)
declare @goods_jprice numeric(19,4)
declare @goods_plutype varchar(1)
declare @goods_mngstock varchar(1)
declare @goods_jtaxrate numeric(19,4)
declare @goods_iszfcode varchar(1)
declare @stock_gcount numeric(19,4)
declare @stock_ccount numeric(19,4)
declare @stock_cost numeric(19,4)
declare @stock_netcost numeric(19,4)
declare @stock_total numeric(19,4)
declare @stock_tzamount numeric(19,4)
declare @jynetcost numeric(19,4)
declare @differnetcost numeric(19,4)
declare @sisneedadjnetcost varchar(1)
declare @kccount numeric(19,4)
declare @sumtotal numeric(19,4)
declare @oldj numeric(19,4)
declare @oldn numeric(19,4)
declare @oldc numeric(19,4)
declare @oldt numeric(19,4)
declare @fxj numeric(19,4)
declare @fxn numeric(19,4)
declare @fxc numeric(19,4)
declare @newj numeric(19,4)
declare @newn numeric(19,4)
declare @newc numeric(19,4)
declare @newt numeric(19,4)
declare @newjprice numeric(19,4)
declare @newnetjprice numeric(19,4)
declare @newstock_tzamount numeric(19,4)
declare @pgbkformtype varchar(2)
declare @pgbkjccost numeric(19,4)
declare @pgbkjcnetcost numeric(19,4)
declare @jycost numeric(19,4)
8 months ago
declare @bpricechgflag varchar(1)
1 year ago
declare @irtncode int
declare @pdiffertype varchar(1)
declare @scybillno varchar(20)
8 months ago
set @bpricechgflag='0'
1 year ago
set @newjprice=0
set @newnetjprice=0
set @sumtotal=0
set @sisneedadjnetcost='0'
select @curdate=convert(varchar(10),getdate(),126)
select @curtime=convert(varchar(10),getdate(),8)
select @pisout=isout,@poutorgcode=outorgcode,@pinorgcode=inorgcode,@splace=place,@pbilltype=billtype
from t_outtrans_head where billno=@psbillno
update t_outtrans_head set rzdate=@curdate,rztime=@curtime where billno=@psbillno and orgcode=@psorgcode
if @@error<>0
begin
set @psmsg='<EFBFBD>޸ĵ<EFBFBD><EFBFBD>ݼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>'
1 year ago
return(-1)
end
if @pisout='0'
begin
set @pdiffertype=''
if @pbilltype='0'
set @pdiffertype='2'
else if @pbilltype='1'
set @pdiffertype='1'
if exists(select 1 from t_outtrans_body where billno=@psbillno and counts <> PlanCounts)
8 months ago
begin
set @scybillno = ''
exec f_get_billno 'cy',@pinorgcode,'1',@scybillno output
if @scybillno <> ''
begin
insert into t_distdiffer_body(billno,supcode,plucode,pluname,jprice,netjprice,counts,differcount,differcost,differnetcost,remark,differmode,depcode,depname)
select @scybillno,(select supcode from t_plu where plucode = t_outtrans_body.plucode) as supcode,plucode,pluname,JPrice,NetJPrice,PlanCounts,counts-PlanCounts,
round((counts-PlanCounts)*JPrice,2),round((counts-PlanCounts)*netjprice,2),'<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>','0',depcode,depname
from t_outtrans_body where billno=@psbillno and counts <> PlanCounts
insert into t_distdiffer_head
(billno,ywbillNo ,orgcode,bizdate,differtype,contrno,differcount,differcost,differnetcost,lrdate,lrtime,rzdate,rztime,
accdate,usercode,username,zdrcode,zdrname,shrcode,shrname,chkstatus,depcode,depname,remark
)
select
@scybillno -- billno - varchar(20)
, @psbillno -- ywbillNo - varchar(20)
, @pinorgcode -- orgcode - varchar(10)
, @curdate -- bizdate - varchar(10)
, @pdiffertype -- differtype - varchar(1)
, '' -- contrno - varchar(40)
, 0 -- differcount - numeric(19, 4)
, 0 -- differcost - numeric(19, 4)
, 0 -- differnetcost - numeric(19, 4)
, @curdate -- lrdate - varchar(10)
, @curtime -- lrtime - varchar(8)
, '' -- rzdate - varchar(10)
, '' -- rztime - varchar(8)
, '' -- accdate - varchar(10)
, usercode -- usercode - varchar(6)
, username -- username - varchar(10)
, zdrcode -- zdrcode - varchar(6)
, zdrname -- zdrname - varchar(10)
, '' -- shrcode - varchar(6)
, '' -- shrname - varchar(10)
, '0' -- chkstatus - varchar(1)
, depcode -- depcode - varchar(10)
, depname -- depname - varchar(16)
, '' -- remark - varchar(200)
from t_outtrans_head where billno = @psbillno
--
update a
set differcount=b.differcount,
differcost=b.differcost,
differnetcost=b.differnetcost
from t_distdiffer_head a,(select sum(differcount) differcount, sum(differcost) differcost,sum(differnetcost) differnetcost
from t_distdiffer_body where billno = @scybillno )b
where a.billno = @scybillno
end
1 year ago
end
8 months ago
update b set counts=PlanCounts,punit='',pcount=0,itemcnt=0,sglcount=PlanCounts,b.cost=round(PlanCounts*b.jprice,2),b.netcost=round(PlanCounts*b.netjprice,2),
b.total=case when plutype='2' then 0 else round(PlanCounts*b.price,2) end
from t_outtrans_body b,t_plu c
where b.plucode=c.plucode and b.billno=@psbillno and b.counts<>b.PlanCounts
if @@ROWCOUNT<>0
begin
update a set total=b.total
from t_outtrans_head a,(select sum(cost) as cost,sum(netcost) as netcost,sum(total) as total from t_outtrans_body where billno=@psbillno) b
where a.billno=@psbillno
end
1 year ago
end
8 months ago
declare cur_usp_circleprocedurebytrans cursor for select serialno,plucode,depcode,jprice,netjprice,price,cost,netcost,total,counts,plancounts from t_outtrans_body where billno=@psbillno
1 year ago
open cur_usp_circleprocedurebytrans
8 months ago
fetch next from cur_usp_circleprocedurebytrans into @detail_serialno,@pplucode,@detail_depcode,@detail_jprice,@detail_netjprice,@detail_price,@detail_cost,@detail_netcost,@detail_total,@detail_counts,@detail_plancounts
1 year ago
while @@fetch_status=0
begin
select @goods_price=o.price,@goods_netjprice=case when g.plutype='2' then 0 else o.netjprice end,
@goods_jprice=case when g.plutype='2' then 0 else o.jprice end,
@goods_plutype=g.plutype,@goods_mngstock=o.mngstock,@goods_jtaxrate=g.jtaxrate,
@stock_gcount=o.gcount,@stock_ccount=o.ccount,
@stock_cost=case when g.plutype='2' then 0 else o.cost end,
@stock_netcost=case when g.plutype='2' then 0 else o.netcost end,
@stock_total=case when g.plutype='2' then 0 else o.total end,
@stock_tzamount=o.tzamount,
@goods_iszfcode=isnull(g.iszfcode,'0')
from t_plu_org o,t_plu g
where o.plucode=g.plucode and o.plucode=@pplucode and o.orgcode=case when @pisout='1' then @poutorgcode else @pinorgcode end and o.isright='1'
if @@rowcount=0
begin
if @pisout='1'
set @psmsg='<EFBFBD><EFBFBD><EFBFBD><EFBFBD>['+@poutorgcode+'<><C3BB><EFBFBD><EFBFBD>Ʒ['+@pplucode+ ']<5D>ľ<EFBFBD>ӪȨ<D3AA><C8A8>'
1 year ago
else
set @psmsg='<EFBFBD><EFBFBD><EFBFBD><EFBFBD>['+@pinorgcode+'<><C3BB><EFBFBD><EFBFBD>Ʒ['+@pplucode+ ']<5D>ľ<EFBFBD>ӪȨ<D3AA><C8A8>'
1 year ago
close cur_usp_circleprocedurebytrans
deallocate cur_usp_circleprocedurebytrans
return(-1)
end
set @kccount=@stock_gcount+@stock_ccount
set @sumtotal=@sumtotal+@detail_total
if @pstrmode='0'
begin
if @kccount>0
begin
set @sisneedadjnetcost='0'
if @splace='0'
set @stock_gcount=@stock_gcount+@detail_plancounts
else
set @stock_ccount=@stock_ccount+@detail_plancounts
set @kccount=@stock_gcount+@stock_ccount
if @stock_tzamount<>0
begin
if (@stock_tzamount<0) and (@stock_tzamount+@detail_cost<0)
begin
set @newstock_tzamount=@stock_tzamount+@detail_cost
set @stock_cost=@stock_cost
set @stock_netcost=@stock_netcost
end
else
begin
set @newstock_tzamount=0
set @stock_cost=@stock_cost+@detail_cost+@stock_tzamount
set @stock_netcost=@stock_netcost+@detail_netcost+round((@stock_tzamount/(1+@goods_jtaxrate/100.00)),2)
end
set @stock_tzamount=@newstock_tzamount
end
else
begin
set @stock_cost=@stock_cost+@detail_cost
set @stock_netcost=@stock_netcost+@detail_netcost
end
if @goods_plutype='2'
set @stock_total=0.00
else
set @stock_total=round((@goods_price*@kccount),2)
set @newjprice=@stock_cost/@kccount
set @newnetjprice=@stock_netcost/@kccount
end
else
begin
set @sisneedadjnetcost='1'
if @splace='0'
set @stock_gcount=@stock_gcount+@detail_plancounts
else
set @stock_ccount=@stock_ccount+@detail_plancounts
set @kccount=@stock_gcount+@stock_ccount
set @newjprice=@detail_jprice
set @newnetjprice=@detail_netjprice
set @jycost=@stock_cost+@detail_cost
set @jynetcost=@stock_netcost+@detail_netcost+round((@stock_tzamount/(1+@goods_jtaxrate/100.00)),2)
set @stock_cost=round((@newjprice*@kccount),2)
set @stock_netcost=round((@newnetjprice*@kccount),2)
if @goods_plutype='2'
set @stock_total=0.00
else
set @stock_total=round((@goods_price*@kccount),2)
set @stock_tzamount=@stock_tzamount+@jycost-@stock_cost
end
end
else
begin
set @sisneedadjnetcost='1'
set @oldj=@goods_jprice
set @oldn=@stock_gcount+@stock_ccount
set @oldc=@stock_cost
set @oldt=@stock_tzamount
set @fxj=@detail_jprice
set @fxn=@detail_counts
set @fxc=@detail_cost
if @splace='0'
set @stock_gcount=@stock_gcount-@detail_counts
else
set @stock_ccount=@stock_ccount-@detail_counts
set @jynetcost=@stock_netcost-@detail_netcost+round((@stock_tzamount/(1+@goods_jtaxrate/100.00)),2)
set @kccount=@stock_gcount+@stock_ccount
8 months ago
if (@kccount=0)
1 year ago
begin
8 months ago
set @sisneedadjnetcost='0'
set @newjprice=@goods_jprice
1 year ago
set @newnetjprice=@goods_netjprice
8 months ago
set @detail_cost=@stock_cost
set @detail_netcost=@stock_netcost
set @detail_total=@stock_total
set @stock_cost=0.00
set @stock_netcost=0.00
set @stock_total=0.00
-- set @stock_tzamount=@stock_tzamount
update t_outtrans_body set cost=@detail_cost,netcost=@detail_netcost,total=@detail_total where billno=@psbillno and serialno=@detail_serialno and plucode=@pplucode
if @@error<>0
begin
set @psmsg='<EFBFBD>޸ĵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ['+@pplucode+']<5D>Ľ<EFBFBD><C4BD><EFBFBD><EFBFBD><EFBFBD>Ϣʧ<CFA2><CAA7>'
close cur_usp_circleprocedurebytrans
deallocate cur_usp_circleprocedurebytrans
return(-1)
end
set @bpricechgflag='1'
1 year ago
end
else
begin
8 months ago
if ((@fxn>=@oldn) and (@fxc<=@oldc)) or ((@fxn<=@oldn) and (@fxc>=@oldc))
begin
set @newj=@oldj
set @newn=@oldn-@fxn
set @newc=round((@newj*@newn),2)
set @newt=@oldt+@oldc-@fxc-@newc
set @newjprice=@newj
set @newnetjprice=@goods_netjprice
set @stock_cost=@newc
set @stock_netcost=round((@newnetjprice*@newn),2)
if @goods_plutype='2'
set @stock_total=0.00
else
set @stock_total=round((@goods_price*@newn),2)
set @stock_tzamount=@newt
end
else
1 year ago
begin
8 months ago
if @stock_tzamount<>0
1 year ago
begin
8 months ago
if (@stock_tzamount>0) and (@stock_tzamount-@detail_cost>0)
begin
set @newstock_tzamount=@stock_tzamount-@detail_cost
set @stock_cost=@stock_cost
set @stock_netcost=@stock_netcost
end
else
begin
set @newstock_tzamount=0
set @stock_cost=@stock_cost-@detail_cost+@stock_tzamount
set @stock_netcost=@stock_netcost-@detail_netcost+round((@stock_tzamount/(1+@goods_jtaxrate/100.00)),2)
end
set @stock_tzamount=@newstock_tzamount
1 year ago
end
else
begin
8 months ago
set @stock_cost=@stock_cost-@detail_cost
set @stock_netcost=@stock_netcost-@detail_netcost
1 year ago
end
8 months ago
if @goods_plutype='2'
set @stock_total=0.00
else
set @stock_total=round((@goods_price*@kccount),2)
set @newjprice=@stock_cost/@kccount
set @newnetjprice=@stock_netcost/@kccount
1 year ago
end
end
end
if @goods_price<>@detail_price
begin
update b set b.price=@goods_price,b.total=case when g.plutype='2' then 0 else @goods_price*@detail_plancounts end
from t_outtrans_body b left join t_plu g on b.plucode=g.plucode
where 1=1 and (b.billno=@psbillno) and b.plucode=@pplucode
if @@error<>0
begin
set @psmsg='<EFBFBD>޸ĵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ['+@pplucode+']<5D><><EFBFBD>ۼ<EFBFBD><DBBC><EFBFBD>Ϣʧ<CFA2><CAA7>'
1 year ago
close cur_usp_circleprocedurebytrans
deallocate cur_usp_circleprocedurebytrans
return(-1)
end
8 months ago
set @bpricechgflag='1'
1 year ago
end
if (@sisneedadjnetcost='1') and ((@jynetcost-@stock_netcost-round(@stock_tzamount/(1+@goods_jtaxrate/100.00),2))<>0)
begin
set @stock_netcost=@jynetcost-round(@stock_tzamount/(1+@goods_jtaxrate/100.00),2)
end
update t_plu_org set jprice=@newjprice,netjprice=@newnetjprice,
gcount=@stock_gcount,ccount=@stock_ccount,
tzamount=@stock_tzamount,
cost=@stock_cost,netcost=@stock_netcost,total=@stock_total,
yjdate=@curdate
where plucode=@pplucode and orgcode=case when @pisout='1' then @poutorgcode else @pinorgcode end and isright='1'
if @@error<>0
begin
set @psmsg='<EFBFBD>޸<EFBFBD><EFBFBD><EFBFBD>Ʒ['+@pplucode+']<5D>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD><EFBFBD>Ϣʧ<CFA2><CAA7>'
1 year ago
close cur_usp_circleprocedurebytrans
deallocate cur_usp_circleprocedurebytrans
return(-1)
end
if @goods_iszfcode='2'
begin
update t_plu_org set jprice=@newjprice,netjprice=@newnetjprice
where plucode in (select plucode from t_plu where innercode=@pplucode and isnull(iszfcode,'0')='2')
and orgcode=case when @pisout='1' then @poutorgcode else @pinorgcode end
end
set @pgbkformtype=case when @pbilltype='0' then 'G' else 'F' end
set @pgbkjccost=@stock_cost+@stock_tzamount
set @pgbkjcnetcost=@stock_netcost+round(@stock_tzamount/(1+@goods_jtaxrate/100.00),2)
if @pisout='1'
exec @irtncode=p_create_gbk_data @curdate,@curtime,@pplucode,@detail_depcode,@psbillno,@pgbkformtype,@detail_jprice,@detail_netjprice,@detail_price,
@detail_counts,@detail_cost,@detail_netcost,@detail_total,@kccount,@pgbkjccost,@pgbkjcnetcost,@stock_total,@poutorgcode,'','',@psmsg out
else
begin
set @detail_plancounts=-@detail_plancounts
set @detail_cost=-@detail_cost
set @detail_netcost=-@detail_netcost
set @detail_total=-@detail_total
exec @irtncode=p_create_gbk_data @curdate,@curtime,@pplucode,@detail_depcode,@psbillno,@pgbkformtype,@detail_jprice,@detail_netjprice,@detail_price,
@detail_plancounts,@detail_cost,@detail_netcost,@detail_total,@kccount,@pgbkjccost,@pgbkjcnetcost,@stock_total,@pinorgcode,'','',@psmsg out
end
if @@error<>0
begin
set @psmsg='<EFBFBD><EFBFBD>¼<EFBFBD><EFBFBD>Ʒ['+@pplucode+']<5D><>̨<EFBFBD><CCA8><EFBFBD><EFBFBD>Ϣʧ<CFA2><CAA7>'
1 year ago
close cur_usp_circleprocedurebytrans
deallocate cur_usp_circleprocedurebytrans
return(-1)
end
if @irtncode=-1
begin
set @psmsg='<EFBFBD><EFBFBD>¼<EFBFBD><EFBFBD>Ʒ['+@pplucode+']<5D><>̨<EFBFBD><CCA8><EFBFBD><EFBFBD>Ϣʧ<CFA2>ܣ<EFBFBD>'+isnull(@psmsg,'')
1 year ago
close cur_usp_circleprocedurebytrans
deallocate cur_usp_circleprocedurebytrans
return(-1)
end
8 months ago
fetch next from cur_usp_circleprocedurebytrans into @detail_serialno,@pplucode,@detail_depcode,@detail_jprice,@detail_netjprice,@detail_price,@detail_cost,@detail_netcost,@detail_total,@detail_counts,@detail_plancounts
1 year ago
end
close cur_usp_circleprocedurebytrans
deallocate cur_usp_circleprocedurebytrans
8 months ago
if @bpricechgflag='1'
1 year ago
begin
8 months ago
update a set cost=b.cost,netcost=b.netcost,total=b.total
1 year ago
from t_outtrans_head a,(select sum(cost) as cost,sum(netcost) as netcost,sum(total) as total from t_outtrans_body where billno=@psbillno) b
where a.billno=@psbillno
if @@error<>0
begin
8 months ago
set @psmsg='<EFBFBD>޸ĵ<EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD>еĽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>'
1 year ago
return(-1)
end
end
set @psmsg=''
return(1)
end
go
if exists(select * from sysobjects where name='p_out_trans_create_in_bill' and xtype='p')
drop procedure p_out_trans_create_in_bill
go
create procedure p_out_trans_create_in_bill
(
@psbillno varchar(20),
@psoutorgcode varchar(10),
@psusercode varchar(6),
@psusername varchar(10),
@psnewbillno varchar(20) out,
@pserrmsg varchar(2000) out
)
as
begin
declare @pinorgcode varchar(10)
declare @poutorgcode varchar(10)
declare @pinplace varchar(1)
declare @pbilltype varchar(4)
declare @pintransno varchar(20)
declare @pinorgtype varchar(1)
declare @pmakertype varchar(1)
declare @curver varchar(1)
declare @curorgcode varchar(10)
select @curorgcode=itemvalue from t_syscfg where itemname='branchno'
select @curver=itemvalue from t_syscfg where itemname='ver'
select @pmakertype=makertype,@pintransno=intransno,@pinorgcode=inorgcode,@poutorgcode=outorgcode,@pinplace=place,@pbilltype=case when billtype='0' then 'yd' else 'dd' end
from t_outtrans_head where billno=@psbillno and orgcode=@psoutorgcode
if @@error<>0
begin
set @pserrmsg='<EFBFBD><EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>'
1 year ago
return(-1)
end
if @pbilltype is null
begin
set @pserrmsg='û<EFBFBD>в<EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ'
1 year ago
return(-1)
end
select @pinplace=case when orgtype='2' then '1' when orgtype<>'2' and isdbdeploy='1' then '0' end from t_shop where orgcode=@pinorgcode
if @pinplace is null
begin
set @pserrmsg='û<EFBFBD>в<EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ'
1 year ago
return(-1)
end
if @pmakertype='0'
8 months ago
exec f_get_billno @pbilltype,@pinorgcode,'1',@psnewbillno output
1 year ago
else
begin
if @curver='0'
set @psnewbillno=@pintransno
else
8 months ago
exec f_get_billno @pbilltype,@pinorgcode,'1',@psnewbillno output
1 year ago
end
if @psnewbillno is null
begin
set @pserrmsg='<EFBFBD><EFBFBD><EFBFBD>ɵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݺ<EFBFBD>ʧ<EFBFBD><EFBFBD>'
1 year ago
return(-1)
end
insert into t_outtrans_head(billno,intransno,bizdate,outorgcode,outorgname,depcode,depname,inorgcode,inorgname,place,
counts,cost,netcost,total,prntimes,accdate,rzdate,rztime,chkstatus,billtype,zdrcode,zdrname,usercode,
username,shrcode,shrname,isout,orgcode,makertype,qrdate,lrdate,lrtime)
select @psnewbillno,@psbillno,bizdate,outorgcode,outorgname,depcode,depname,inorgcode,inorgname,@pinplace,
counts,cost,netcost,total,0,accdate,'','','0',billtype,@psusercode,@psusername,@psusercode,
@psusername,'','','0',inorgcode,makertype,'',convert(varchar(10),getdate(),126),convert(varchar(8),getdate(),8)
from t_outtrans_head
where (billno=@psbillno) and orgcode=@psoutorgcode
if @@error<>0
begin
set @pserrmsg='<EFBFBD><EFBFBD><EFBFBD>ɵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><EFBFBD>Ϣʧ<EFBFBD><EFBFBD>'
1 year ago
return(-1)
end
insert into t_outtrans_body(billno,serialno,plucode,depcode,depname,barcode,pluname,cargono,spec,unit,punit,itemcnt,pcount,
sglcount,jprice,netjprice,price,cost,netcost,total,counts,plancounts,jtaxrate,remark)
select @psnewbillno,a.serialno,a.plucode,case when g.plucode is null then a.depcode else g.depcode end,case when g.plucode is null then a.depname else d.depname end,
case when g.plucode is null then a.barcode else g.barcode end,a.pluname,case when g.plucode is null then a.cargono else g.cargono end,
case when g.plucode is null then a.spec else g.spec end,a.unit,a.punit,a.itemcnt,a.pcount,
a.sglcount,a.jprice,a.netjprice,case when g.plucode is null then a.price else o.price end,a.cost,a.netcost,
case when g.plucode is null and g.plutype='2' then 0.00
when g.plucode is null and g.plutype<>'2' then a.total
when not g.plucode is null and g.plutype='2' then 0.00
when not g.plucode is null and g.plutype<>'2' then o.price*a.counts
end,a.counts,a.plancounts,a.jtaxrate,a.remark
from t_outtrans_body a left join t_plu g on a.plucode=g.plucode
left join t_dept d on g.depcode=d.depcode
left join t_plu_org o on a.plucode=o.plucode and o.orgcode=@pinorgcode
where a.billno=@psbillno
if @@error<>0
begin
set @pserrmsg='<EFBFBD><EFBFBD><EFBFBD>ɵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣʧ<EFBFBD><EFBFBD>'
1 year ago
return(-1)
end
update a set total=b.total
from t_outtrans_head a,(select sum(cost) as cost,sum(netcost) as netcost,sum(total) as total from t_outtrans_body
where billno=@psnewbillno) b
where a.billno=@psnewbillno
if @@error<>0
begin
set @pserrmsg='<EFBFBD>޸ĵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><EFBFBD>Ϣʧ<EFBFBD><EFBFBD>'
1 year ago
return(-1)
end
set @pserrmsg=''
return(1)
end
go
if exists(select * from sysobjects where name='p_rz_prepare_dd' and xtype='p')
drop procedure p_rz_prepare_dd
go
create procedure p_rz_prepare_dd
(
@psorgcode varchar(10),
@psbillno varchar(20),
@psparams varchar(200),
@psmsg varchar(2000) out
)
as
begin
declare @splace varchar(1)
declare @serrmsg varchar(2000)
declare @irtncode int
declare @pisout varchar(1)
declare @poutorgcode varchar(10)
declare @pinorgcode varchar(10)
declare @pplucode varchar(20)
declare @ppluname varchar(40)
set @psmsg=''
select @pisout=isout,@poutorgcode=outorgcode,@pinorgcode=inorgcode from t_outtrans_head where billno=@psbillno
declare cur_rzprocprepare_dd cursor for
select g.plucode,g.pluname from t_plu g left join t_plu_org o on g.plucode=o.plucode and o.orgcode=case when @pisout='1' then @poutorgcode else @pinorgcode end
where g.plucode in (select plucode from t_outtrans_body where billno=@psbillno) and isnull(o.isright,'0')='0'
open cur_rzprocprepare_dd
fetch next from cur_rzprocprepare_dd into @pplucode,@ppluname
while @@fetch_status=0
begin
if @psmsg=''
set @psmsg=@ppluname
else
set @psmsg=@psmsg+char(13)+@ppluname
fetch next from cur_rzprocprepare_dd into @pplucode,@ppluname
end
close cur_rzprocprepare_dd
deallocate cur_rzprocprepare_dd
if @psmsg<>''
begin
set @psmsg='<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD>ڻ<EFBFBD><EFBFBD><EFBFBD>['+case when @pisout='1' then @poutorgcode else @pinorgcode end+']<5D><>û<EFBFBD>о<EFBFBD>ӪȨ<D3AA>ޣ<EFBFBD>'+char(13)+@psmsg
1 year ago
return(-1)
end
if @pisout='1'
begin
select @splace=place from t_outtrans_head where billno=@psbillno
exec @irtncode=p_check_plu_stock_rz @poutorgcode,@psbillno,@splace,'t_outtrans_head','t_outtrans_body',@psparams,@serrmsg output
if @@error<>0
begin
set @psmsg='<EFBFBD>ж<EFBFBD><EFBFBD>Ƿ񸺿<EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>δ֪<EFBFBD><EFBFBD><EFBFBD><EFBFBD>'
1 year ago
return(-1)
end
else if @irtncode=-1
begin
set @psmsg='<EFBFBD>ж<EFBFBD><EFBFBD>Ƿ񸺿<EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>'+isnull(@serrmsg,'')
1 year ago
return(-1)
end
else if isnull(@serrmsg,'')<>''
begin
set @psmsg='<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'+@serrmsg
1 year ago
return(-1)
end
end
set @psmsg=''
return(1)
end
go
if exists(select * from sysobjects where name='p_rz_prepare_yd' and xtype='p')
drop procedure p_rz_prepare_yd
go
create procedure p_rz_prepare_yd
(
@psorgcode varchar(10),
@psbillno varchar(20),
@psparams varchar(200),
@psmsg varchar(2000) out
)
as
begin
declare @irtncode int
exec @irtncode=p_rz_prepare_dd @psorgcode,@psbillno,@psparams,@psmsg out
if @@error <>0
begin
set @psmsg='<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD>ж<EFBFBD>ִ<EFBFBD>г<EFBFBD><EFBFBD><EFBFBD>'
1 year ago
return(-1)
end
if @irtncode=-1
begin
set @psmsg='<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD>ж<EFBFBD>ִ<EFBFBD>г<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'+isnull(@psmsg,'')
1 year ago
return(-1)
end
set @psmsg=''
return(1)
end
go
if exists(select * from sysobjects where name='p_rz_dd' and xtype='p')
drop procedure p_rz_dd
go
create procedure p_rz_dd
(
@psorgcode varchar(10),
@psbillno varchar(20),
@psparams varchar(200),
@psmsg varchar(2000) out
)
as
begin
declare @pcurorgtype varchar(1)
declare @pcurorgcode varchar(10)
declare @pisout varchar(1)
declare @pmakertype varchar(1)
declare @poutorgcode varchar(10)
declare @pinorgcode varchar(10)
declare @pbilltype varchar(1)
declare @splace varchar(1)
declare @poutorgtype varchar(1)
declare @pinorgtype varchar(1)
declare @curdate varchar(10)
declare @curtime varchar(8)
declare @pplucode varchar(20)
declare @kccount numeric(19,4)
declare @sumtotal numeric(19,4)
declare @pintranbillno varchar(20)
declare @irtncode int
declare @pdiffertype varchar(1)
declare @pusercode varchar(6)
declare @pusername varchar(10)
set @pusercode=''
set @pusername=''
set @pusercode=@psparams
select @pusername=username from t_user where usercode=@pusercode
select @curdate=convert(varchar(10),getdate(),126)
select @curtime=convert(varchar(10),getdate(),8)
select @pcurorgtype=itemvalue from t_syscfg where itemname='ver'
select @pcurorgcode=itemvalue from t_syscfg where itemname='branchno'
select @pisout=isout,@pmakertype=makertype,@poutorgcode=outorgcode,@pinorgcode=inorgcode,@pbilltype=billtype,@splace=place from t_outtrans_head where billno=@psbillno
select @poutorgtype=isdbdeploy from t_shop where orgcode=@poutorgcode
select @pinorgtype=isdbdeploy from t_shop where orgcode=@pinorgcode
set @sumtotal=0
set @kccount=0
if @pcurorgtype='1'
begin
if @pbilltype='1'
begin
if @pisout='1'
begin
if @poutorgtype='0'
begin
set @psmsg='<EFBFBD>õ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƕ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ŵ<EFBFBD><EFBFBD>ĵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'
1 year ago
return(-1)
end
else if @poutorgtype='1'
begin
exec @irtncode=p_circle_proc_by_trans '1',@psbillno,@poutorgcode,@psmsg out
if @irtncode=-1
begin
set @psmsg='ѭ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>'+isnull(@psmsg,'')
1 year ago
return(-1)
end
update t_outtrans_head set qrdate=@curdate
where billno=@psbillno and orgcode=@poutorgcode
if @@error <>0
begin
set @psmsg='<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>'
1 year ago
return(-1)
end
if @pinorgtype='1'
begin
exec @irtncode=p_out_trans_create_in_bill @psbillno,@poutorgcode,@pusercode,@pusername,@pintranbillno out,@psmsg out
if @@error <>0
begin
set @psmsg='<EFBFBD><EFBFBD><EFBFBD>ɵ<EFBFBD><EFBFBD>뵥ʧ<EFBFBD><EFBFBD>'
1 year ago
return(-1)
end
if @irtncode=-1
begin
set @psmsg='<EFBFBD><EFBFBD><EFBFBD>ɵ<EFBFBD><EFBFBD>뵥ʧ<EFBFBD>ܣ<EFBFBD>'+isnull(@psmsg,'')
1 year ago
return(-1)
end
8 months ago
if not exists(select * from t_shop where orgcode=@pinorgcode and isdbconfirm='1')
begin
exec @irtncode=p_rz_sum 'dd',@pinorgcode,@pintranbillno,'',@psmsg out
if @irtncode=-1
begin
set @psmsg='<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɵĵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>'+@pintranbillno+'<EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>'+isnull(@psmsg,'')
return(-1)
end
end
1 year ago
end
end
end
else if @pisout='0'
begin
if @pinorgtype='0'
begin
set @psmsg='<EFBFBD>õ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƕ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ŵ<EFBFBD><EFBFBD>ĵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'
1 year ago
return(-1)
end
else if @pinorgtype='1'
begin
exec @irtncode=p_circle_proc_by_trans '0',@psbillno,@pinorgcode,@psmsg out
if @irtncode=-1
begin
set @psmsg='ѭ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>'+isnull(@psmsg,'')
1 year ago
return(-1)
end
if not exists(select*from t_shop where orgcode=@pinorgcode and isdbconfirm='1')
begin
update t_outtrans_head set qrdate=@curdate where billno=@psbillno and orgcode=@pinorgcode
if @@error<>0
begin
set @psmsg='<EFBFBD>޸ĵ<EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>'
1 year ago
return(-1)
end
end
end
end
end
else if @pbilltype='0'
begin
if @pisout='1'
begin
exec @irtncode=p_circle_proc_by_trans '1',@psbillno,@poutorgcode,@psmsg out
if @irtncode=-1
begin
set @psmsg='ѭ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>'+isnull(@psmsg,'')
1 year ago
return(-1)
end
update t_outtrans_head set qrdate=@curdate where billno=@psbillno and orgcode=@poutorgcode
if @@error<>0
begin
set @psmsg='<EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>'
1 year ago
return(-1)
end
8 months ago
exec @irtncode=p_out_trans_create_in_bill @psbillno,@poutorgcode,@pusercode,@pusername,@pintranbillno out,@psmsg out
if @irtncode=-1
begin
set @psmsg='<EFBFBD><EFBFBD><EFBFBD>ɵ<EFBFBD><EFBFBD>뵥ʧ<EFBFBD>ܣ<EFBFBD>'+isnull(@psmsg,'')
return(-1)
end
1 year ago
8 months ago
--<EFBFBD>ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٵ<EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD>Ч
--if not exists(select * from t_shop where orgcode=@pinorgcode and isdbconfirm='1')
begin
exec @irtncode=p_rz_sum 'yd',@pinorgcode,@pintranbillno,'',@psmsg out
if @irtncode=-1
begin
set @psmsg='<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɵĵ<EFBFBD><EFBFBD>뵥['+@pintranbillno+'<>ܣ<EFBFBD>'+isnull(@psmsg,'')
return(-1)
end
end
1 year ago
end
else if @pisout='0'
begin
exec @irtncode=p_circle_proc_by_trans '0',@psbillno,@pinorgcode,@psmsg out
if @irtncode=-1
begin
set @psmsg='ѭ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>'+isnull(@psmsg,'')
1 year ago
return(-1)
end
if not exists(select * from t_shop where orgcode=@pinorgcode and isdbconfirm='1')
begin
update t_outtrans_head set qrdate=@curdate where billno=@psbillno and orgcode=@pinorgcode
if @@error<>0
begin
set @psmsg='<EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>'
1 year ago
return(-1)
end
end
end
end
end
set @psmsg=''
return(1)
end
go
if exists(select*from sysobjects where name='p_rz_yd' and xtype='p')
drop procedure p_rz_yd
go
create procedure p_rz_yd
(
@psorgcode varchar(10),
@psbillno varchar(20),
@psparams varchar(200),
@psmsg varchar(2000) out
)
as
begin
declare @irtncode int
exec @irtncode=p_rz_dd @psorgcode,@psbillno,@psparams,@psmsg out
if @@error<>0
begin
set @psmsg='ִ<EFBFBD>м<EFBFBD><EFBFBD>˹<EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>'
1 year ago
return(-1)
end
if @irtncode=-1
begin
set @psmsg='ִ<EFBFBD>м<EFBFBD><EFBFBD>˹<EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>'+isnull(@psmsg,'')
1 year ago
return(-1)
end
set @psmsg=''
return(1)
end
go