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.

273 lines
11 KiB

8 months ago
--ӯ<EFBFBD><EFBFBD>
if exists(select * from sysobjects where name='p_rz_prepare_yk' and xtype='p')
drop procedure p_rz_prepare_yk
go
create procedure p_rz_prepare_yk
(
@psorgcode varchar(10),
@psbillno varchar(20),
@psparams varchar(200),
@psmsg varchar(2000) out
)
as
begin
declare @volidplu varchar(100)
declare @volidpluname varchar(100)
declare @bookcount numeric(19,4)
declare @realcount numeric(19,4)
declare @ykcount numeric(19,4)
declare @errmsg varchar(2000)
declare @sorgcode varchar(10)
select @sorgcode=orgcode from t_differ_head where billno=@psbillno
declare cur_differprepare cursor for select ltrim(plucode)+'-'+pluname as plucode from t_differ_body d
where billno=@psbillno and (not exists(select plucode from t_plu where plucode=d.plucode)
or not exists(select plucode from t_plu_org where plucode=d.plucode and orgcode=@sorgcode and isright='1'))
open cur_differprepare
fetch next from cur_differprepare into @volidplu
while @@fetch_status=0
begin
if isnull(@errmsg,'')=''
set @errmsg=@volidplu
else
set @errmsg=@errmsg+char(13)+@volidplu
fetch next from cur_differprepare into @volidplu
end
close cur_differprepare
deallocate cur_differprepare
if isnull(@errmsg,'')<>''
begin
set @psmsg='<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD>Ѳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڻ<EFBFBD><EFBFBD>ڻ<EFBFBD><EFBFBD><EFBFBD>['+@sorgcode+']<5D><><EFBFBD><EFBFBD><EFBFBD>޾<EFBFBD>ӪȨ<D3AA>ޣ<EFBFBD><DEA3>޷<EFBFBD><DEB7><EFBFBD><EFBFBD><EFBFBD>'+char(13)+@errmsg
return(-1)
end
set @errmsg=''
declare cur_checkbilldata cursor for select plucode,pluname,realcount,bookcount,ykcount from t_differ_body where realcount-bookcount<>ykcount and billno=@psbillno
open cur_checkbilldata
fetch next from cur_checkbilldata into @volidplu,@volidpluname,@realcount,@bookcount,@ykcount
while @@fetch_status=0
begin
if @errmsg=''
set @errmsg='<EFBFBD><EFBFBD><EFBFBD>'+@volidplu+' <20><><EFBFBD>ƣ<EFBFBD>'+@volidpluname+' <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'+convert(varchar(30),@bookcount)+' ʵ<><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'+convert(varchar(30),@realcount)+' ӯ<><D3AF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'+convert(varchar(30),@ykcount)
else
set @errmsg=@errmsg+char(13)+'<EFBFBD><EFBFBD><EFBFBD>'+@volidplu+' <20><><EFBFBD>ƣ<EFBFBD>'+@volidpluname+' <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'+convert(varchar(30),@bookcount)+' ʵ<><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'+convert(varchar(30),@realcount)+' ӯ<><D3AF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'+convert(varchar(30),@ykcount)
fetch next from cur_checkbilldata into @volidplu,@volidpluname,@realcount,@bookcount,@ykcount
end
close cur_checkbilldata
deallocate cur_checkbilldata
if @errmsg<>''
begin
set @psmsg='<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD>̵<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'+char(13)+@errmsg
return(-1)
end
set @psmsg=''
return(1)
end
go
if exists(select * from sysobjects where name='p_rz_yk' and xtype='p')
drop procedure p_rz_yk
go
create procedure p_rz_yk
(
@psorgcode varchar(10),
@psbillno varchar(20),
@psparams varchar(200),
@psmsg varchar(2000) out
)
as
begin
declare @sorgcode varchar(10)
declare @scurdate varchar(10)
declare @scurtime varchar(8)
declare @splace varchar(1)
declare @bill_cost 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_serialno int
declare @detail_plucode varchar(20)
declare @detail_depcode varchar(10)
declare @detail_jtaxrate numeric(19,4)
declare @detail_pluname varchar(40)
declare @detail_jprice numeric(19,4)
declare @detail_netjprice numeric(19,4)
declare @detail_price numeric(19,4)
declare @goods_price numeric(19,4)
declare @goods_plutype varchar(1)
declare @stock_jprice numeric(19,4)
declare @stock_netjprice numeric(19,4)
declare @stock_gcount numeric(19,4)
declare @stock_ccount numeric(19,4)
declare @stock_count 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 @stock_jycost 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 @sbranchno varchar(10)
declare @bpricechgflag varchar(1)
set @bpricechgflag='0'
select @sorgcode=orgcode,@splace=place from t_differ_head where billno=@psbillno
select @scurdate=convert(varchar(100),getdate(),23),@scurtime=convert(varchar(100),getdate(),108)
select @sbranchno=itemvalue from t_syscfg where section='SYSTEM' and itemname='BranchNo'
update t_differ_head set rzdate=@scurdate,rztime=@scurtime where billno=@psbillno
update d set d.jprice=case when g.plutype='2' then 0 else o.jprice end,
d.netjprice=case when g.plutype='2' then 0 else o.netjprice end,d.price=o.price,
d.bookcost=round((case when g.plutype='2' then 0 else o.jprice end)*d.bookcount,2),d.realcost=round((case when g.plutype='2' then 0 else o.jprice end)*d.realcount,2),
d.ykcost=round((case when g.plutype='2' then 0 else o.jprice end)*d.realcount,2)-round((case when g.plutype='2' then 0 else o.jprice end)*d.bookcount,2),
d.booknetcost=round((case when g.plutype='2' then 0 else o.netjprice end)*d.bookcount,2),d.realnetcost=round((case when g.plutype='2' then 0 else o.netjprice end)*d.realcount,2),
d.yknetcost=round((case when g.plutype='2' then 0 else o.netjprice end)*d.realcount,2)-round((case when g.plutype='2' then 0 else o.netjprice end)*d.bookcount,2),
d.booktotal=case when g.plutype='2' then 0 else round(o.price*d.bookcount,2) end,
d.realtotal=case when g.plutype='2' then 0 else round(o.price*d.realcount,2) end,
d.yktotal=case when g.plutype='2' then 0 else round(o.price*d.realcount,2)-round(o.price*d.bookcount,2) end
from t_differ_body d,t_differ_head h,t_plu_org o,t_plu g
where h.billno=d.billno and h.billno=@psbillno and d.plucode=g.plucode and d.plucode=o.plucode and o.orgcode=h.orgcode and o.isright='1' and (h.billtype='0' or (h.billtype='1' and d.ykcount<0))
if @@error>0
begin
set @psmsg='<EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϸ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>'
return(-1)
end
update h set h.ykcost=d.ykcost,h.yknetcost=d.yknetcost,h.yktotal=d.yktotal
from t_differ_head h,(select billno,sum(ykcost) as ykcost,sum(yknetcost) as yknetcost,sum(yktotal) as yktotal from t_differ_body where billno=@psbillno group by billno) d
where h.billno=d.billno and h.billno=@psbillno
if @@error >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>'
return(-1)
end
declare cur_ykaccount cursor for select serialno,plucode,pluname,depcode,jtaxrate,ykcount,ykcost,yknetcost,yktotal,jprice,netjprice,price from t_differ_body where billno=@psbillno
open cur_ykaccount
fetch next from cur_ykaccount into @detail_serialno,@detail_plucode,@detail_pluname,@detail_depcode,@detail_jtaxrate,@detail_counts,@detail_cost,@detail_netcost,@detail_total,@detail_jprice,@detail_netjprice,@detail_price
while @@fetch_status=0
begin
select @stock_jprice=case when g.plutype='2' then 0 else o.jprice end,
@stock_netjprice=case when g.plutype='2' then 0 else o.netjprice end,
@goods_price=o.price,
@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=case when g.plutype='2' then 0 else o.tzamount end,
@goods_plutype=g.plutype
from t_plu_org o,t_plu g
where o.plucode=@detail_plucode and orgcode=@sorgcode and o.plucode=g.plucode and o.isright='1'
if @@error>0
begin
set @psmsg='<EFBFBD><EFBFBD>ѯ<EFBFBD><EFBFBD>Ʒ<EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>'
close cur_ykaccount
deallocate cur_ykaccount
return(-1)
end
if @splace='0'
set @stock_gcount=@stock_gcount+@detail_counts
else
set @stock_ccount=@stock_ccount+@detail_counts
set @stock_count=@stock_gcount+@stock_ccount
if ((@stock_count=0) and (@detail_counts<0))
begin
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_differ_body set ykcost=@detail_cost,yknetcost=@detail_netcost,yktotal=@detail_total,remark='β<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>' where billno=@psbillno and serialno=@detail_serialno and plucode=@detail_plucode
if @@error>0
begin
set @psmsg='<EFBFBD>޸ĵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ['+@detail_plucode+']<5D>Ľ<EFBFBD><C4BD><EFBFBD><EFBFBD><EFBFBD>Ϣʧ<CFA2><CAA7>'
close cur_ykaccount
deallocate cur_ykaccount
return(-1)
end
set @bpricechgflag='1'
end
else
begin
set @stock_cost=@stock_cost+@detail_cost
set @stock_netcost=@stock_netcost+@detail_netcost
if @goods_plutype='2'
set @stock_total=0.00
else
set @stock_total=round(@goods_price*@stock_count,2)
set @stock_jycost=@stock_cost
set @stock_tzamount=@stock_tzamount +@stock_jycost-@stock_cost
end
update t_plu_org set
gcount=@stock_gcount,ccount=@stock_ccount,
cost=@stock_cost,netcost=@stock_netcost,total=@stock_total,tzamount=@stock_tzamount
where plucode=@detail_plucode and orgcode=@sorgcode and isright='1'
if @@error>0
begin
set @psmsg='<EFBFBD>޸<EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>'
close cur_ykaccount
deallocate cur_ykaccount
return(-1)
end
if @detail_counts>0
begin
update t_plu_org set yjdate=@scurdate where plucode=@detail_plucode and (yjdate is null or yjdate='') and orgcode=@sorgcode and isright='1'
if @@error >0
begin
set @psmsg='<EFBFBD><EFBFBD>ѯ<EFBFBD><EFBFBD>Ʒ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>'
close cur_ykaccount
deallocate cur_ykaccount
return(-1)
end
end
if @detail_counts<>0
begin
set @fscost=@detail_cost
set @fsnetcost=@detail_netcost
set @fstotal=@detail_total
set @jccount=@stock_count
set @jccost=@stock_cost+@stock_tzamount
set @jcnetcost=@stock_netcost+round(@stock_tzamount/(1.00+@detail_jtaxrate/100.00),2)
set @jctotal=@stock_total
exec p_create_gbk_data @scurdate,@scurtime,@detail_plucode,@detail_depcode,@psbillno,'2',@detail_jprice,@detail_netjprice,@detail_price,
@detail_counts,@fscost,@fsnetcost,@fstotal,@jccount,@jccost,@jcnetcost,@jctotal,@sorgcode,'','',@psmsg
if @@error>0
begin
set @psmsg='<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ̨<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>'
close cur_ykaccount
deallocate cur_ykaccount
return(-1)
end
end
fetch next from cur_ykaccount into @detail_serialno,@detail_plucode,@detail_pluname,@detail_depcode,@detail_jtaxrate,@detail_counts,@detail_cost,@detail_netcost,@detail_total,@detail_jprice,@detail_netjprice,@detail_price
end
close cur_ykaccount
deallocate cur_ykaccount
if @bpricechgflag='1'
begin
update h set h.ykcost=d.ykcost,h.yknetcost=d.yknetcost,h.yktotal=d.yktotal
from t_differ_head h,(select billno,sum(ykcost) as ykcost,sum(yknetcost) as yknetcost,sum(yktotal) as yktotal from t_differ_body where billno=@psbillno group by billno) d
where h.billno=d.billno and h.billno=@psbillno
if @@error >0
begin
set @psmsg='<EFBFBD>޸ĵ<EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD>еĽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>'
return(-1)
end
end
--exec p_sup_stock_in @psbillno,'YK',@psmsg
--exec p_sup_stock_out @psbillno,'YK',@psmsg
set @psmsg=''
return(1)
end
go