|
|
|
|
--ʵ<EFBFBD><EFBFBD>
|
|
|
|
|
if exists(select * from sysobjects where name='p_rz_prepare_pd' and xtype='p')
|
|
|
|
|
drop procedure p_rz_prepare_pd
|
|
|
|
|
go
|
|
|
|
|
create procedure p_rz_prepare_pd
|
|
|
|
|
(
|
|
|
|
|
@psorgcode varchar(10),
|
|
|
|
|
@psbillno varchar(20),
|
|
|
|
|
@psparams varchar(200),
|
|
|
|
|
@psmsg varchar(2000) out
|
|
|
|
|
)
|
|
|
|
|
as
|
|
|
|
|
begin
|
|
|
|
|
declare @spdtaskno varchar(20)
|
|
|
|
|
declare @sbilltype varchar(1)
|
|
|
|
|
declare @sbillno varchar(20)
|
|
|
|
|
declare @splucode varchar(20)
|
|
|
|
|
|
|
|
|
|
select @spdtaskno=pdno,@sbilltype=billtype from t_check_head where billno=@psbillno
|
|
|
|
|
|
|
|
|
|
if not exists(select pdno from t_check_task where pdno=@spdtaskno and pdstatus='0')
|
|
|
|
|
begin
|
|
|
|
|
set @psmsg='<EFBFBD>̵<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>['+@spdtaskno+']<5D>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD>'
|
|
|
|
|
return(-1)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
declare cur_pdprepare cursor for select distinct d.billno billno,fp.plucode plucode from t_check_head f,t_check_body d,t_check_body fp
|
|
|
|
|
where pdno=@spdtaskno and billtype='1' and rzdate<>'' and rzdate is not null and f.billno=d.billno and d.plucode=fp.plucode and d.billno<>@psbillno and fp.billno=@psbillno
|
|
|
|
|
open cur_pdprepare
|
|
|
|
|
fetch next from cur_pdprepare into @sbillno,@splucode
|
|
|
|
|
while @@fetch_status=0
|
|
|
|
|
begin
|
|
|
|
|
if isnull(@psmsg,'')=''
|
|
|
|
|
set @psmsg='['+@sbillno++'-'+@splucode+']'
|
|
|
|
|
else
|
|
|
|
|
set @psmsg=@psmsg+char(13)+'['+@sbillno++'-'+@splucode+']'
|
|
|
|
|
fetch next from cur_pdprepare into @sbillno,@splucode
|
|
|
|
|
end
|
|
|
|
|
close cur_pdprepare
|
|
|
|
|
deallocate cur_pdprepare
|
|
|
|
|
if isnull(@psmsg,'')<>''
|
|
|
|
|
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>'+char(13)+@psmsg+char(13)+'<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>'
|
|
|
|
|
return(-1)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if @sbilltype='1'
|
|
|
|
|
begin
|
|
|
|
|
if exists(select billno from t_check_head where pdno=@spdtaskno and billtype='0' and (rzdate='' or rzdate is null))
|
|
|
|
|
begin
|
|
|
|
|
set @psmsg='<EFBFBD>̵<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>['+@spdtaskno+']<5D><><EFBFBD><EFBFBD>δ<EFBFBD><CEB4><EFBFBD>˵<EFBFBD>ʵ<EFBFBD>̵<EFBFBD>'
|
|
|
|
|
return(-1)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
set @psmsg=''
|
|
|
|
|
return(1)
|
|
|
|
|
end
|
|
|
|
|
go
|
|
|
|
|
|
|
|
|
|
if exists(select * from sysobjects where name='p_rz_pd' and xtype='p')
|
|
|
|
|
drop procedure p_rz_pd
|
|
|
|
|
go
|
|
|
|
|
create procedure p_rz_pd
|
|
|
|
|
(
|
|
|
|
|
@psorgcode varchar(10),
|
|
|
|
|
@psbillno varchar(20),
|
|
|
|
|
@psparams varchar(200),
|
|
|
|
|
@psmsg varchar(2000) out
|
|
|
|
|
)
|
|
|
|
|
as
|
|
|
|
|
begin
|
|
|
|
|
declare @spdtaskno varchar(20)
|
|
|
|
|
declare @sbilltype varchar(1)
|
|
|
|
|
declare @scurdate varchar(10)
|
|
|
|
|
declare @scurtime varchar(8)
|
|
|
|
|
declare @psnewbillno varchar(20)
|
|
|
|
|
declare @psmsg1 varchar(2000)
|
|
|
|
|
declare @iRtn integer
|
|
|
|
|
|
|
|
|
|
select @scurdate=convert(varchar(100),getdate(),120),@scurtime=convert(varchar(100),getdate(),108)
|
|
|
|
|
|
|
|
|
|
select @spdtaskno=pdno,@sbilltype=billtype from t_check_head where billno=@psbillno
|
|
|
|
|
|
|
|
|
|
update a set pcount=case when @sbilltype='0' then pcount+b.counts when @sbilltype='1' then b.counts end,upddate=b.upddate
|
|
|
|
|
from t_check_snap a,(select pdno,plucode,sum(d.counts) as counts,max(d.upddate) as upddate from t_check_head f,t_check_body d
|
|
|
|
|
where f.billno=d.billno and f.billno=@psbillno and pdno=@spdtaskno group by pdno,plucode) b
|
|
|
|
|
where a.pdno=b.pdno and a.plucode=b.plucode
|
|
|
|
|
|
|
|
|
|
update a set upddate=b.upddate from t_check_snap a,(select pdno,plucode,max(d.upddate) as upddate from t_check_head f,t_check_body d
|
|
|
|
|
where f.billno=d.billno and f.billno=@psbillno and pdno=@spdtaskno and rzdate<>'' and rzdate is not null group by pdno,plucode) b
|
|
|
|
|
where a.pdno=b.pdno and a.plucode=b.plucode
|
|
|
|
|
|
|
|
|
|
--<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><EFBFBD>ԴΪ<EFBFBD>¶<EFBFBD><EFBFBD>̵<EFBFBD>
|
|
|
|
|
|
|
|
|
|
while 1=1
|
|
|
|
|
begin
|
|
|
|
|
exec f_get_billno 'yk',@psorgcode,'1',@psnewbillno output
|
|
|
|
|
if exists(select 1 from t_differ_head where billno=@psnewbillno)
|
|
|
|
|
continue
|
|
|
|
|
else
|
|
|
|
|
break
|
|
|
|
|
end
|
|
|
|
|
if @@error<>0 goto lblfail
|
|
|
|
|
|
|
|
|
|
insert into t_differ_body(billno,serialno,plucode,pluname,barcode,cargono,spec,unit,price,
|
|
|
|
|
jprice,netjprice,bookcount,realcount,bookcost,realcost,booknetcost,realnetcost,booktotal,realtotal,
|
|
|
|
|
ykcount,ykcost,yknetcost,yktotal,jtaxrate,remark)
|
|
|
|
|
select @psnewbillno,a.serialno,a.plucode,g.pluname,a.barcode,g.cargono,g.spec,g.unit,a.price,
|
|
|
|
|
a.jprice,a.jprice/(1+isnull(g.jtaxrate,0)/100.00) as netjprice,ocount as bookcount,counts as realcount,
|
|
|
|
|
round(ocount*a.jprice,2) as bookcost,round(counts*a.jprice,2) as realcost,
|
|
|
|
|
round(ocount*(a.jprice/(1+isnull(g.jtaxrate,0)/100.00)),2) as booknetcost,
|
|
|
|
|
round(counts*(a.jprice/(1+isnull(g.jtaxrate,0)/100.00)),2) as realnetcost,
|
|
|
|
|
ocount*o.price as booktotal,counts*o.price as realtotal,
|
|
|
|
|
(counts - ocount) as ykcount,round((counts - ocount)*a.jprice,2) as ykcost,
|
|
|
|
|
round((counts - ocount)*(a.jprice/(1+isnull(g.jtaxrate,0)/100.00)),2) as yknetcost,
|
|
|
|
|
(counts - ocount)*o.price as yktotal,g.jtaxrate, a.remark
|
|
|
|
|
from t_check_body a join t_plu g on a.plucode=g.plucode
|
|
|
|
|
join t_plu_org o on a.plucode=o.plucode and o.orgcode=@psorgcode and o.isright='1'
|
|
|
|
|
where a.billno=@psbillno
|
|
|
|
|
if @@error<>0
|
|
|
|
|
begin
|
|
|
|
|
set @psmsg='<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>'
|
|
|
|
|
return (-1)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
insert into t_differ_head(billno,orgcode,bizdate,billtype,lrdate,lrtime,place,
|
|
|
|
|
zdrcode,zdrname,usercode,username,
|
|
|
|
|
chkstatus,remark,supcode)
|
|
|
|
|
select @psnewbillno,upper(@psorgcode),@scurdate,'3',@scurdate,@scurtime,place,
|
|
|
|
|
zdrcode,zdrname,usercode,username,'1' as chkstatus,'<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ:<3A>¶<EFBFBD><C2B6>̵<EFBFBD>',''
|
|
|
|
|
from t_check_head d where d.billno=@psbillno
|
|
|
|
|
|
|
|
|
|
update h set h.ykcost=d.ykcost,h.yknetcost=d.yknetcost,h.yktotal=d.yktotal,h.ykcount = d.ykcount
|
|
|
|
|
from t_differ_head h,(select billno,sum(ykcount) as ykcount, sum(ykcost) as ykcost,sum(yknetcost) as yknetcost,sum(yktotal) as yktotal from t_differ_body where billno=@psnewbillno group by billno) d
|
|
|
|
|
where h.billno=d.billno and h.billno=@psnewbillno
|
|
|
|
|
|
|
|
|
|
if @@error<>0
|
|
|
|
|
begin
|
|
|
|
|
set @psmsg='<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷʧ<EFBFBD><EFBFBD>'
|
|
|
|
|
return (-1)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
exec @iRtn=p_rz_prepare_yk @psorgcode,@psnewbillno,'',@psmsg1 out
|
|
|
|
|
if @iRtn<>1
|
|
|
|
|
begin
|
|
|
|
|
set @psmsg='ӯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>:'+@psmsg1
|
|
|
|
|
return (-1)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
exec @iRtn=p_rz_yk @psorgcode,@psnewbillno,'',@psmsg1 out
|
|
|
|
|
if @iRtn<>1
|
|
|
|
|
begin
|
|
|
|
|
set @psmsg='ӯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>:'+@psmsg1
|
|
|
|
|
return (-1)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
update t_check_head set rzdate=@scurdate,rztime=@scurtime where billno=@psbillno
|
|
|
|
|
|
|
|
|
|
update t_check_task set pdstatus = '1' where pdno = @spdtaskno
|
|
|
|
|
|
|
|
|
|
set @psmsg=''
|
|
|
|
|
return(1)
|
|
|
|
|
lblfail:
|
|
|
|
|
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
|
|
|
|
|
end
|
|
|
|
|
go
|