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.
394 lines
20 KiB
394 lines
20 KiB
if exists(select * from sysobjects where name='p_rz_prepare_pt' and xtype='p')
|
|
drop procedure p_rz_prepare_pt
|
|
go
|
|
create procedure p_rz_prepare_pt
|
|
(
|
|
@psorgcode varchar(10),
|
|
@psbillno varchar(20),
|
|
@psparams varchar(200),
|
|
@psmsg varchar(2000) out
|
|
)
|
|
as
|
|
begin
|
|
declare @sorgcode varchar(10)
|
|
declare @scustcode varchar(15)
|
|
declare @ssqauremode varchar(1)
|
|
declare @syqflag varchar(1)
|
|
declare @sstr varchar(1000)
|
|
|
|
select @sorgcode=orgcode,@scustcode=custcode,@ssqauremode=sqauremode from t_whreturn_head where billno=@psbillno
|
|
|
|
select @syqflag=yqflag from t_customer where custcode=@scustcode
|
|
if @@rowcount=0
|
|
begin
|
|
set @psmsg='批发客户已经不存在'
|
|
return(-1)
|
|
end
|
|
|
|
if (@ssqauremode='1') and (@syqflag='0')
|
|
begin
|
|
set @psmsg='批发客户不允许延期收款'
|
|
return(-1)
|
|
end
|
|
|
|
select @sstr=coalesce(@sstr+char(13),'')+rtrim(d.plucode)+'-'+rtrim(d.pluname) from t_whreturn_body d
|
|
where d.billno=@psbillno and not exists(select plucode from t_plu where plucode=d.plucode and depcode=d.depcode)
|
|
if isnull(@sstr,'')<>''
|
|
begin
|
|
set @psmsg='已经不存在或部门发生了变化'+char(13)+@sstr
|
|
return(-1)
|
|
end
|
|
|
|
set @psmsg=''
|
|
return(1)
|
|
end
|
|
go
|
|
|
|
if exists(select * from sysobjects where name='p_rz_pt' and xtype='p')
|
|
drop procedure p_rz_pt
|
|
go
|
|
create procedure p_rz_pt
|
|
(
|
|
@psorgcode varchar(10),
|
|
@psbillno varchar(20),
|
|
@psparams varchar(200),
|
|
@psmsg varchar(2000) out
|
|
)
|
|
as
|
|
begin
|
|
declare @sorgcode varchar(10)
|
|
declare @scustcode varchar(15)
|
|
declare @szdrcode varchar(6)
|
|
declare @ssqauremode varchar(1)
|
|
declare @splace varchar(1)
|
|
declare @srzdate varchar(10)
|
|
declare @org_orgtype varchar(1)
|
|
declare @org_isdbdeploy varchar(1)
|
|
declare @scurver varchar(1)
|
|
declare @scurdate varchar(10)
|
|
declare @scurtime varchar(8)
|
|
declare @custbook_name varchar(20)
|
|
declare @sedition varchar(20)
|
|
declare @ssql varchar(8000)
|
|
declare @sinfo varchar(8000)
|
|
declare @irtn int
|
|
declare @detail_jtaxrate int
|
|
declare @detail_cost numeric(19,4)
|
|
declare @detail_netcost numeric(19,4)
|
|
declare @detail_total numeric(19,4)
|
|
declare @detail_plucode varchar(20)
|
|
declare @detail_depcode varchar(10)
|
|
declare @detail_pfprice numeric(19,4)
|
|
declare @detail_zrtotal numeric(19,4)
|
|
declare @detail_pftotal numeric(19,4)
|
|
declare @detail_counts numeric(19,4)
|
|
declare @detail_zpcounts numeric(19,4)
|
|
declare @detail_serialno numeric(19,0)
|
|
declare @detail_plutype varchar(1)
|
|
declare @detail_mngstock varchar(1)
|
|
declare @detail_jymode varchar(1)
|
|
declare @goods_netjprice numeric(19,4)
|
|
declare @goods_jprice numeric(19,4)
|
|
declare @goods_price numeric(19,4)
|
|
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 @new_cost numeric(19,4)
|
|
declare @new_netcost numeric(19,4)
|
|
declare @new_total numeric(19,4)
|
|
declare @stock_csgcount numeric(19,4)
|
|
declare @stock_csccount numeric(19,4)
|
|
declare @csdetail_ccounts numeric(19,4)
|
|
declare @csdetail_plucode varchar(20)
|
|
declare @csdetail_colorcode varchar(10)
|
|
declare @csdetail_sizecode varchar(10)
|
|
declare @csdetail_zpcounts numeric(19,4)
|
|
declare @fscscount numeric(19,4)
|
|
declare @packplu_plucode varchar(20)
|
|
declare @packplu_pluname varchar(40)
|
|
declare @packplu_barcode varchar(20)
|
|
declare @packplu_depcode varchar(10)
|
|
declare @packplu_depname varchar(20)
|
|
declare @packplu_cargono varchar(20)
|
|
declare @packplu_spec varchar(40)
|
|
declare @packplu_prodarea varchar(30)
|
|
declare @packplu_unit varchar(4)
|
|
declare @packplu_jtaxrate int
|
|
declare @packplu_price numeric(19,4)
|
|
declare @packplu_jprice numeric(19,4)
|
|
declare @packplu_netjprice numeric(19,4)
|
|
declare @packplu_counts numeric(19,4)
|
|
declare @packplu_zpcounts numeric(19,4)
|
|
declare @packplu_plutotal numeric(19,4)
|
|
declare @packplu_pftotal numeric(19,4)
|
|
declare @packplu_zrtotal numeric(19,4)
|
|
declare @packplu_pfprice numeric(19,4)
|
|
declare @packplu_pfcounts numeric(19,4)
|
|
declare @packplucount int
|
|
declare @packplutotalsum numeric(19,4)
|
|
declare @i int
|
|
declare @sumpftotal numeric(19,4)
|
|
declare @sumzrtotal numeric(19,4)
|
|
declare @fscount numeric(19,4)
|
|
declare @fscost numeric(19,4)
|
|
declare @fsnetcost numeric(19,4)
|
|
declare @fstotal numeric(19,4)
|
|
declare @jccost numeric(19,4)
|
|
declare @jcnetcost numeric(19,4)
|
|
declare @jctotal numeric(19,4)
|
|
declare @jccount numeric(19,4)
|
|
declare @jffstotal numeric(19,4)
|
|
declare @billystotal numeric(19,4)
|
|
declare @goods_iszfcode varchar(1)
|
|
declare @packplu_iszfcode varchar(1)
|
|
declare @packplu_zmcode varchar(20)
|
|
|
|
select @sedition=itemvalue from t_syscfg where section='SYSTEM' and itemname='Edition'
|
|
select @sorgcode=orgcode,@scustcode=custcode,@splace=place,@szdrcode=zdrcode,@ssqauremode=sqauremode,@srzdate=isnull(rzdate,'')
|
|
from t_whreturn_head where billno=@psbillno
|
|
|
|
select @org_orgtype=orgtype,@org_isdbdeploy=isdbdeploy from t_shop where orgcode=@sorgcode
|
|
select @scurver=itemvalue from t_syscfg where section='SYSTEM' and itemname='VER'
|
|
select @scurdate=convert(varchar(100),getdate(),120),@scurtime=convert(varchar(100),getdate(),108)
|
|
|
|
set @custbook_name='t_whcbk_yyyymm'
|
|
|
|
declare cur cursor for select d.plucode,d.serialno,g.plutype,d.counts,d.zpcount,d.pftotal,d.zrtotal,isnull(g.iszfcode,'0')
|
|
from t_whreturn_body d,t_plu g where billno=@psbillno and d.plucode=g.plucode order by d.plucode,d.serialno
|
|
open cur
|
|
fetch next from cur into @detail_plucode,@detail_serialno,@detail_plutype,@detail_counts,@detail_zpcounts,@detail_pftotal,@detail_zrtotal,@goods_iszfcode
|
|
while @@fetch_status=0
|
|
begin
|
|
if (@detail_plutype<>'3') and (@goods_iszfcode<>'2')
|
|
begin
|
|
insert into t_whreturn_body2(billno,serialno,plucode,packcode,barcode,pluname,cargono,spec,
|
|
prodarea,punit,pcount,unit,price,jprice,netjprice,pfprice,counts,zpcount,
|
|
pftotal,zrtotal,cost,netcost,total,jtaxrate,tag,depname,depcode,remark,itemcnt,sglcount)
|
|
select billno,serialno,plucode,'' packcode,barcode,pluname,cargono,spec,
|
|
prodarea,punit,pcount,unit,price,jprice,netjprice,pfprice,counts,zpcount,
|
|
pftotal,zrtotal,cost,netcost,total,jtaxrate,tag,depname,depcode,remark,itemcnt,sglcount
|
|
from t_whreturn_body d
|
|
where billno=@psbillno and plucode=@detail_plucode and serialno=@detail_serialno
|
|
end
|
|
else if (@detail_plutype<>'3') and (@goods_iszfcode='2')
|
|
begin
|
|
insert into t_whreturn_body2(billno,serialno,plucode,packcode,barcode,pluname,cargono,spec,
|
|
prodarea,punit,pcount,unit,price,jprice,netjprice,pfprice,counts,zpcount,
|
|
pftotal,zrtotal,cost,netcost,total,jtaxrate,tag,depname,depcode,remark,itemcnt,sglcount)
|
|
select billno,serialno,p.innercode,'' packcode,barcode,pluname,cargono,spec,
|
|
prodarea,punit,pcount,unit,price,jprice,netjprice,pfprice,d.counts,zpcount,
|
|
pftotal,zrtotal,cost,netcost,total,jtaxrate,tag,depname,depcode,remark,itemcnt,sglcount
|
|
from t_whreturn_body d,(select plucode,innercode from t_plu where iszfcode='2') p
|
|
where billno=@psbillno and d.plucode=@detail_plucode and serialno=@detail_serialno and p.plucode=d.plucode
|
|
end
|
|
|
|
else if @detail_plutype='3'
|
|
begin
|
|
set @i=1
|
|
set @sumpftotal=0
|
|
set @sumzrtotal=0
|
|
|
|
select @packplucount=count(*),@packplutotalsum=sum(pluprice*counts) from t_plupack where packcode=@detail_plucode and packtype='0'
|
|
|
|
declare curpackplu cursor static for select g.plucode,g.pluname,g.barcode,g.depcode,d.depname,g.cargono,g.spec,g.prodarea,g.unit,g.jtaxrate,o.price,
|
|
case when isnull(iszfcode,'0')='2' then g.jprice else o.jprice end as jprice,
|
|
case when isnull(iszfcode,'0')='2' then g.netjprice else o.netjprice end as netjprice,
|
|
p.counts,(p.counts * p.pluprice),isnull(iszfcode,'0')
|
|
from t_plupack p,t_plu_org o,t_plu g left join t_dept d on g.depcode=d.depcode
|
|
where o.orgcode=@sorgcode and p.packcode=@detail_plucode and p.plucode=g.plucode and p.plucode=o.plucode and packtype='0'
|
|
open curpackplu
|
|
|
|
fetch next from curpackplu into @packplu_plucode,@packplu_pluname,@packplu_barcode,@packplu_depcode,@packplu_depname,
|
|
@packplu_cargono,@packplu_spec,@packplu_prodarea,@packplu_unit,@packplu_jtaxrate,
|
|
@packplu_price,@packplu_jprice,@packplu_netjprice,@packplu_counts,@packplu_plutotal,@packplu_iszfcode
|
|
while @@fetch_status=0
|
|
begin
|
|
if @i<@packplucount
|
|
begin
|
|
set @packplu_pftotal=round(@detail_pftotal*@packplu_plutotal/@packplutotalsum,2)
|
|
set @packplu_zrtotal=round(@detail_zrtotal*@packplu_plutotal/@packplutotalsum,2)
|
|
set @sumpftotal=@sumpftotal+@packplu_pftotal
|
|
set @sumzrtotal=@sumzrtotal+@packplu_zrtotal
|
|
end
|
|
else
|
|
begin
|
|
set @packplu_pftotal=round(@detail_pftotal-@sumpftotal,2)
|
|
set @packplu_zrtotal=round(@detail_zrtotal-@sumzrtotal,2)
|
|
end
|
|
set @packplu_pfcounts=@packplu_counts*@detail_counts
|
|
set @packplu_zpcounts=@packplu_counts*@detail_zpcounts
|
|
if @packplu_pfcounts<>0
|
|
set @packplu_pfprice=round(@packplu_pftotal/@packplu_pfcounts ,4)
|
|
else
|
|
set @packplu_pfprice=0
|
|
|
|
if @packplu_iszfcode='2'
|
|
begin
|
|
select @packplu_zmcode=innercode from t_plu where plucode=@packplu_plucode
|
|
if exists (select plucode from t_whreturn_body2 where billno=@psbillno and serialno=@detail_serialno and plucode=@packplu_zmcode)
|
|
begin
|
|
update t_whreturn_body2 set counts=counts+@packplu_pfcounts,zpcount=zpcount+@packplu_zpcounts,pftotal=pftotal+@packplu_pftotal,
|
|
zrtotal=zrtotal+@packplu_zrtotal,cost=cost+round(@packplu_jprice*@packplu_pfcounts,2),netcost=netcost+round(@packplu_netjprice*@packplu_pfcounts,2),
|
|
total=total+round(@packplu_price*@packplu_pfcounts,2),sglcount=sglcount+@packplu_pfcounts
|
|
where billno=@psbillno and serialno=@detail_serialno and plucode=@packplu_zmcode
|
|
set @i=@i+1
|
|
end
|
|
else
|
|
begin
|
|
insert into t_whreturn_body2(billno,serialno,plucode,packcode,barcode,pluname,cargono,spec,
|
|
prodarea,punit,pcount,unit,price,jprice,netjprice,pfprice,counts,zpcount,
|
|
pftotal,zrtotal,cost,netcost,total,jtaxrate,tag,depname,depcode,remark,itemcnt,sglcount)
|
|
values(@psbillno,@detail_serialno,@packplu_zmcode,@detail_plucode,@packplu_barcode,@packplu_pluname,@packplu_cargono,@packplu_spec,
|
|
@packplu_prodarea,'',0,@packplu_unit,@packplu_price,@packplu_jprice,@packplu_netjprice,@packplu_pfprice,
|
|
@packplu_pfcounts,@packplu_zpcounts,@packplu_pftotal,@packplu_zrtotal,
|
|
round(@packplu_jprice*@packplu_pfcounts,2),round(round(@packplu_jprice*@packplu_pfcounts,2)/(1+@packplu_jtaxrate/100.00),2),round(@packplu_price*@packplu_pfcounts,2),
|
|
@packplu_jtaxrate,'',@packplu_depname ,@packplu_depcode ,'',0,@packplu_pfcounts)
|
|
set @i=@i+1
|
|
end
|
|
end
|
|
else
|
|
begin
|
|
insert into t_whreturn_body2(billno,serialno,plucode,packcode,barcode,pluname,cargono,spec,
|
|
prodarea,punit,pcount,unit,price,jprice,netjprice,pfprice,counts,zpcount,
|
|
pftotal,zrtotal,cost,netcost,total,jtaxrate,tag,depname,depcode,remark,itemcnt,sglcount)
|
|
values(@psbillno,@detail_serialno,@packplu_plucode,@detail_plucode,@packplu_barcode,@packplu_pluname,@packplu_cargono,@packplu_spec,
|
|
@packplu_prodarea,'',0,@packplu_unit,@packplu_price,@packplu_jprice,@packplu_netjprice,@packplu_pfprice,
|
|
@packplu_pfcounts,@packplu_zpcounts,@packplu_pftotal,@packplu_zrtotal,
|
|
round(@packplu_jprice*@packplu_pfcounts,2),round(round(@packplu_jprice*@packplu_pfcounts,2)/(1+@packplu_jtaxrate/100.00),2),round(@packplu_price*@packplu_pfcounts,2),
|
|
@packplu_jtaxrate,'',@packplu_depname ,@packplu_depcode,'',0,@packplu_pfcounts)
|
|
set @i=@i+1
|
|
end
|
|
fetch next from curpackplu into @packplu_plucode,@packplu_pluname,@packplu_barcode,@packplu_depcode,@packplu_depname,
|
|
@packplu_cargono,@packplu_spec,@packplu_prodarea,@packplu_unit,@packplu_jtaxrate,
|
|
@packplu_price,@packplu_jprice,@packplu_netjprice,@packplu_counts,@packplu_plutotal,@packplu_iszfcode
|
|
end
|
|
close curpackplu
|
|
deallocate curpackplu
|
|
|
|
update a set cost=b.cost,jprice=round(b.cost/(a.counts+zpcount),4),
|
|
netcost=b.netcost,netjprice=round(b.netcost/(a.counts+zpcount),4),
|
|
total=b.total,price=round(b.total/(a.counts+zpcount),2)
|
|
from t_whreturn_body a,(select billno,serialno,packcode,sum(cost) cost,sum(netcost) netcost,sum(total) total
|
|
from t_whreturn_body2 where billno=@psbillno and isnull(packcode,'')<>'' group by billno,serialno,packcode) b
|
|
where a.billno=@psbillno and a.billno=b.billno and a.plucode=b.packcode and a.serialno=b.serialno
|
|
end
|
|
|
|
fetch next from cur into @detail_plucode,@detail_serialno,@detail_plutype,@detail_counts,@detail_zpcounts,@detail_pftotal,@detail_zrtotal,@goods_iszfcode
|
|
end
|
|
close cur
|
|
deallocate cur
|
|
|
|
declare cur cursor for select d.plucode,d.serialno,d.counts,d.zpcount,d.pfprice,d.pftotal,d.depcode,d.jtaxrate,o.mngstock,isnull(v2.jymode,v1.jymode) as jymode
|
|
from t_whreturn_body2 d join t_plu_org o on d.plucode = o.plucode and o.orgcode = @sorgcode
|
|
join t_plu p on d.plucode = p.plucode
|
|
left join t_supplier v1 on p.supcode = v1.supcode
|
|
left join dbo.t_supplier v2 on o.supcode = v2.supcode
|
|
where billno=@psbillno
|
|
order by d.plucode,d.serialno
|
|
open cur
|
|
fetch next from cur into @detail_plucode,@detail_serialno,@detail_counts,@detail_zpcounts,@detail_pfprice,@detail_pftotal,@detail_depcode,@detail_jtaxrate,@detail_mngstock,@detail_jymode
|
|
while @@fetch_status=0
|
|
begin
|
|
set @fscount=@detail_counts+@detail_zpcounts
|
|
|
|
select @goods_netjprice=netjprice,@goods_jprice=jprice,@goods_price=price,
|
|
@stock_gcount=gcount,@stock_ccount=ccount,@stock_cost=cost,@stock_netcost=netcost,
|
|
@stock_total=total,@stock_tzamount=tzamount
|
|
from t_plu_org where plucode=@detail_plucode and orgcode=@sorgcode
|
|
|
|
if @scurver='0'
|
|
begin
|
|
if @splace='0'
|
|
set @stock_gcount=@stock_gcount+@fscount
|
|
else
|
|
set @stock_ccount=@stock_ccount+@fscount
|
|
end
|
|
else
|
|
begin
|
|
if @org_orgtype='2'
|
|
set @stock_ccount=@stock_ccount+@fscount
|
|
else if (@org_orgtype<>'2' and @org_isdbdeploy='1')
|
|
set @stock_gcount=@stock_gcount+@fscount
|
|
end
|
|
|
|
set @jccount=@stock_gcount+@stock_ccount
|
|
set @new_cost=round(@goods_jprice*@jccount,2)
|
|
set @new_netcost=round(@new_cost/(1+@detail_jtaxrate/100.00),2)
|
|
set @new_total=round(@goods_price*@jccount,2)
|
|
set @detail_cost=@new_cost-@stock_cost
|
|
set @detail_netcost=round(@detail_cost/(1+@detail_jtaxrate/100.00),2);
|
|
set @detail_total=@new_total-@stock_total
|
|
set @jccost=@new_cost+@stock_tzamount
|
|
set @jcnetcost=@new_netcost+@stock_tzamount/(1+@detail_jtaxrate/100.00 )
|
|
set @jctotal=@new_total
|
|
|
|
update t_plu_org set ccount=@stock_ccount,gcount=@stock_gcount,
|
|
cost=@new_cost,netcost=@new_netcost,total=@new_total
|
|
where plucode=@detail_plucode and orgcode=@sorgcode and @detail_mngstock = '1'
|
|
|
|
update t_whreturn_body2 set jprice=@goods_jprice,netjprice=@goods_netjprice,price=@goods_price,
|
|
cost=@detail_cost,netcost=@detail_netcost,total=@detail_total
|
|
where billno=@psbillno and serialno=@detail_serialno and plucode=@detail_plucode
|
|
|
|
update a set cost=b.cost,jprice=round(b.cost/(a.counts+zpcount),4),
|
|
netcost=b.netcost,netjprice=round(b.netcost/(a.counts+zpcount),4),
|
|
total=b.total,price=round(b.total/(a.counts+zpcount),2)
|
|
from t_whreturn_body a,(select billno,serialno,packcode,sum(cost) cost,sum(netcost) netcost,sum(total) total
|
|
from t_whreturn_body2 where billno=@psbillno and isnull(packcode,'')<>'' group by billno,serialno,packcode) b
|
|
where a.billno=@psbillno and a.billno=b.billno and a.plucode=b.packcode and a.serialno=b.serialno
|
|
if @detail_jymode = '2'
|
|
begin
|
|
select @goods_jprice = 0,@goods_netjprice=0,@detail_cost=0,@detail_netcost=0,@detail_total=0,@jccost=0,@jcnetcost=0,@jctotal=0
|
|
if @detail_mngstock = '0'
|
|
begin
|
|
select @fscount=0,@jccount =0
|
|
end
|
|
end
|
|
exec p_create_gbk_data @scurdate,@scurtime,@detail_plucode,@detail_depcode,@psbillno,'B',
|
|
@goods_jprice,@goods_netjprice,@goods_price,@fscount ,@detail_cost,@detail_netcost,@detail_total,
|
|
@jccount,@jccost,@jcnetcost,@jctotal,@sorgcode,'','',@sinfo out
|
|
|
|
fetch next from cur into @detail_plucode,@detail_serialno,@detail_counts,@detail_zpcounts,@detail_pfprice,@detail_pftotal,@detail_depcode,@detail_jtaxrate,@detail_mngstock,@detail_jymode
|
|
end
|
|
close cur
|
|
deallocate cur
|
|
|
|
if @sedition='4'
|
|
begin
|
|
insert into t_plu_org_cs(plucode,orgcode,colorcode,sizecode,csbarcode,gcount,ccount,remark)
|
|
select distinct a.plucode as plucode,@sorgcode as orgcode,a.colorcode as colorcode,a.sizecode as sizecode,g.csbarcode as csbarcode,0 as gcount,0 as ccount,'' as remark
|
|
from t_whreturn_cs_body a,t_plu_cs g where a.plucode=g.plucode and a.colorcode=g.colorcode and a.sizecode=g.sizecode and a.billno=@psbillno
|
|
and not exists(select plucode from t_plu_org_cs o where o.plucode=a.plucode and o.colorcode=a.colorcode and o.sizecode=a.sizecode and o.orgcode=@sorgcode)
|
|
|
|
update a set a.gcount=case when @splace='0' then a.gcount+b.ccounts+b.zpcounts else a.gcount end,
|
|
a.ccount=case when @splace='0' then a.ccount else a.ccount+b.ccounts+b.zpcounts end
|
|
from t_plu_org_cs a,(select plucode,colorcode,sizecode,sum(ccounts) as ccounts,sum(zpcounts) as zpcounts from t_whreturn_cs_body where billno=@psbillno group by plucode,colorcode,sizecode) b
|
|
where a.plucode=b.plucode and a.orgcode=@sorgcode and a.colorcode=b.colorcode and a.sizecode=b.sizecode
|
|
end
|
|
|
|
update a set cost=b.cost,netcost=b.netcost,total=b.total
|
|
from t_whreturn_head a,(select sum(cost) cost,sum(netcost) netcost,sum(total) total from t_whreturn_body2 where billno=@psbillno) b
|
|
where billno=@psbillno
|
|
|
|
update a set a.thtotal=a.thtotal+(b.pftotal-b.zrtotal)
|
|
from t_customer a,t_whreturn_head b
|
|
where a.custcode=b.custcode and a.custcode=@scustcode and b.billno=@psbillno
|
|
|
|
set @ssql='insert into '+@custbook_name+'(bookdate,booktime,bizdate,custcode,billtype,billno,username,ywname,ctotal,ysjytotal,prepayjytotal,orgcode,tag,accdate)'
|
|
+' select '''+@scurdate+''','''+@scurtime+''',f.bizdate,f.custcode,''1'',f.billno,f.username,f.zdrname,(-1)*(f.pftotal-f.zrtotal) as ctotal,
|
|
c.pftotal-c.thtotal-c.fktotal as ysjytotal,prepay as prepayjytotal,'''+@sorgcode+''' as orgcode,''0'' as tag,'''' as accdate
|
|
from t_customer c,t_whreturn_head f
|
|
where c.custcode=f.custcode and c.custcode='''+@scustcode+''' and f.billno='''+@psbillno+''''
|
|
exec(@ssql)
|
|
|
|
update t_whreturn_head set rzdate=@scurdate,rztime=@scurtime where billno=@psbillno
|
|
update t_whreturn_head set isfinished='1' where billno=@psbillno and pftotal-zrtotal=0
|
|
-- exec p_sup_stock_in @psbillno,'PT',@psmsg
|
|
set @psmsg=''
|
|
return(1)
|
|
end
|
|
go
|