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.

306 lines
13 KiB

1 year ago
if exists(select * from sysobjects where name ='p_nosameacc_th' and xtype='p')
drop procedure p_nosameacc_th
go
create procedure p_nosameacc_th
(
@psbillno varchar(20),
@psmsg varchar(2000) out
)
as
declare @swarecode varchar(10)
declare @swarename varchar(100)
declare @sshopcode varchar(10)
declare @sfinacode varchar(10)
declare @thno varchar(20)
declare @psno varchar(20)
declare @psthno varchar(20)
declare @scurdate varchar(10)
declare @scurtime varchar(8)
declare @susercode varchar(10)
declare @susername varchar(10)
begin
select @swarecode = 'C009'
select @swarename=orgname from t_shop where orgcode = @swarecode
select @scurdate=convert(varchar(100),getdate(),23),@scurtime=convert(varchar(100),getdate(),108)
select @sshopcode=orgcode,@susercode=usercode,@susername = username from t_return_head where billno = @psbillno
select @sfinacode = finacode from t_shop where orgcode = @sshopcode
--1<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> C009<EFBFBD>޲ɹ<EFBFBD><EFBFBD>˻<EFBFBD>
while 1=1
begin
exec f_get_billno 'TH', @swarecode, '1', @thno output
if exists(select 1 from t_return_head where billno = @thno)
continue
else
break
end
if @@ERROR <> 0
begin
set @psMsg = '<EFBFBD><EFBFBD>ȡ<EFBFBD>˻<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݺ<EFBFBD>ʧ<EFBFBD><EFBFBD>'
return(-1)
end
insert into t_return_body(billno,serialno,plucode,pluname,barcode,cargono,spec,unit,punit,itemcnt,pcount,sglcount,price,jprice,netjprice,
counts,orncounts,cost,netcost,total,jxprice,jtaxrate,kindcd,remark)
select @thno,serialno,plucode,pluname,barcode,cargono,spec,unit,punit,itemcnt,pcount,sglcount,price,jprice,netjprice,
counts,orncounts,cost,netcost,total,jxprice,jtaxrate,kindcd,remark
from t_return_body where billno = @psbillno
insert into t_return_head(billno,orgcode,bizdate,lrdate,lrtime,contrno,supcode,supname,place,chkstatus,billtype,
counts,cost,netcost,total,usercode,username,zdrcode,zdrname,remark)
select @thno,@swarecode,@scurdate,@scurdate,@scurtime,contrno,supcode,supname,'1'as place,chkstatus,'0',
counts,cost,netcost,total,usercode,username,zdrcode,zdrname,'<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD><EFBFBD><EFBFBD>˻<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'
from t_return_head where billno = @psbillno
update t_return_head
set rzdate = @scurdate,
rztime = @scurtime
where billno = @thno
--2<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ŵC009<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˻<EFBFBD><EFBFBD><EFBFBD>
-- while 1=1
-- begin
--exec f_get_billno 'PS', @swarecode, '1', @psno output
--if exists(select 1 from t_dist_head where billno = @psno)
-- continue
--else
-- break
-- end
-- if @@ERROR <> 0
-- begin
-- set @psMsg = '<27><>ȡ<EFBFBD><C8A1><EFBFBD>͵<EFBFBD><CDB5><EFBFBD><EFBFBD>ݺ<EFBFBD>ʧ<EFBFBD><CAA7>'
-- return(-1)
-- end
set @psno = @psbillno
insert into t_dist_body(billno,serialno,plucode,pluname,barcode,supcode,cargono,spec,unit,punit,itemcnt,pcount,sglcount,price,jprice,netjprice,
cost,netcost,zpamount,zpnetamount,
ispsprice,zpprice,zpcount,total,jtaxrate,staxrate,depcode,depname,remark)
select @psno,serialno,a.plucode,a.pluname,a.barcode,b.supcode,a.cargono,a.spec,a.unit,punit,a.itemcnt,-1*pcount,-1*sglcount,a.price,a.jprice,a.netjprice,
-1*cost,-1*netcost,-1*cost as zpamount,-1*round(cost/(1+b.staxrate/100.00),2) as zpnetamount,
'0' as ispsprice,a.jprice as zpprice,-1*counts,-1*total,a.jtaxrate,b.staxrate,a.depcode,a.depname,a.remark
from t_return_body a,t_plu b
where billno = @psbillno and a.plucode = b.plucode
insert into t_dist_head(billno,askno,orgcode,shopcode,depcode,depname,lrdate,lrtime,sqauremode,paydate,chkstatus,
zpcount,zpamount,zpnetamount,cost,netcost,total,usercode,username,zdrcode,zdrname,remark)
select @psno,'',@swarecode,@sshopcode,'' as depcode,'' depname,@scurdate,@scurtime,'1' as sqauremode,@scurdate,'1' as chkstatus,
sum(d.zpcount),sum(d.zpamount),sum(d.zpnetamount),sum(d.cost),sum(d.netcost),sum(d.total),@susercode,@susername,@susercode,@susername,'<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD><EFBFBD><EFBFBD>˻<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'
from t_dist_body d
where d.billno = @psno
update t_dist_head
set rzdate = @scurdate,
rztime = @scurtime
where billno = @psno
insert into t_pay_bill(orgcode,billtype,billno,bizdate,supcode,sqauremode,cost,paydate,jscost,zrcost,isfinished,total,contrno,finacode)
select shopcode,'7',billno,lrdate,'C2000',sqauremode,zpamount,paydate,0,0,case when zpamount=0 then '1' else '0' end,total,'',@sfinacode
from t_dist_head where billno=@psno
--3<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ŵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ŵ<EFBFBD><EFBFBD>˲ֵ<EFBFBD>
while 1=1
begin
exec f_get_billno 'PTH', @swarecode, '1', @psthno output
if exists(select 1 from t_return_head where billno = @psthno)
continue
else
break
end
if @@ERROR <> 0
begin
set @psMsg = '<EFBFBD><EFBFBD>ȡ<EFBFBD>ŵ<EFBFBD><EFBFBD>˲ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݺ<EFBFBD>ʧ<EFBFBD><EFBFBD>'
return(-1)
end
insert into t_return_head(billno,orgcode,bizdate,lrdate,lrtime,contrno,supcode,supname,place,oldbillno,chkstatus,billtype,
counts,cost,netcost,total,usercode,username,zdrcode,zdrname,remark)
select @psthno,@sshopcode,@scurdate,@scurdate,@scurtime,contrno,@swarecode,@swarename,place,@psbillno,chkstatus,'3',
counts,cost,netcost,total,usercode,username,zdrcode,zdrname,'<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD><EFBFBD><EFBFBD>˻<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'
from t_return_head where billno = @psbillno
if @@error<>0
begin
set @psmsg='<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ŵ<EFBFBD><EFBFBD>˲ֵ<EFBFBD><EFBFBD><EFBFBD>ͷʧ<EFBFBD><EFBFBD>'
return(-1)
end
insert into t_return_body(billno,serialno,plucode,pluname,barcode,cargono,spec,unit,punit,itemcnt,pcount,sglcount,price,jprice,netjprice,
counts,orncounts,cost,netcost,total,jxprice,jtaxrate,kindcd,remark)
select @psthno,serialno,plucode,pluname,barcode,cargono,spec,unit,punit,itemcnt,pcount,sglcount,price,jprice,netjprice,
counts,orncounts,cost,netcost,total,jxprice,jtaxrate,kindcd,remark
from t_return_body where 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
update t_return_head
set rzdate = @scurdate,
rztime = @scurtime
where billno = @psthno
set @psmsg = ''
return (1)
end
go
if exists(select * from sysobjects where name ='p_nosameacc_jh' and xtype='p')
drop procedure p_nosameacc_jh
go
create procedure p_nosameacc_jh
(
@psbillno varchar(20),
@psmsg varchar(2000) out
)
as
declare @swarecode varchar(10)
declare @swarename varchar(100)
declare @sshopcode varchar(10)
declare @sfinacode varchar(10)
declare @jhno varchar(20)
declare @psno varchar(20)
declare @psjhno varchar(20)
declare @scurdate varchar(10)
declare @scurtime varchar(8)
declare @susercode varchar(10)
declare @susername varchar(10)
begin
select @swarecode = 'C009'
select @swarename = orgname from t_shop where orgcode = @swarecode
select @scurdate=convert(varchar(100),getdate(),23),@scurtime=convert(varchar(100),getdate(),108)
select @sshopcode=orgcode,@susercode=usercode,@susername = username from t_accept_head where billno = @psbillno
select @sfinacode = finacode from t_shop where orgcode = @sshopcode
--select
--1<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> C009<EFBFBD>޲ɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
while 1=1
begin
exec f_get_billno 'JH', @swarecode, '1', @jhno output
if exists(select 1 from t_accept_head where billno = @jhno)
continue
else
break
end
if @@ERROR <> 0
begin
set @psMsg = '<EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݺ<EFBFBD>ʧ<EFBFBD><EFBFBD>'
return(-1)
end
insert into t_accept_body(billno,plucode,serialno,barcode,pluname,cargono,spec,unit,punit,itemcnt,pcount,sglcount,
jprice,netjprice,ornjprice,ornnetjprice,price,counts,cost,netcost,total,jtaxrate,jxprice,cgcount,depcode,depname,remark)
select @jhno,plucode,serialno,barcode,pluname,cargono,spec,unit,punit,itemcnt,pcount,sglcount,jprice,netjprice,ornjprice,ornnetjprice,price,counts,
cost,netcost,total,jtaxrate,jxprice,cgcount,depcode,depname,remark
from t_accept_body where billno = @psbillno
insert into t_accept_head(billno,orgcode,billtype,bizdate,lrdate,lrtime,depcode,depname,supcode,supname,
counts,givecount,cost,netcost,total,
place,sqauremode,paydate,orderno,chkstatus,shrcode,shrname,usercode,username,zdrcode,zdrname,remark,askno)
select @jhno,@swarecode,'1',@scurdate,@scurdate,@scurtime,depcode,depname,supcode,supname,
counts,givecount,cost,netcost,total,
'1',sqauremode,paydate,orderno,chkstatus,shrcode,shrname,usercode,
username,zdrcode,zdrname,'<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',''
from t_accept_head where billno = @psbillno
update t_accept_head
set rzdate = @scurdate,
rztime = @scurtime
where billno = @jhno
--2<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>C009<EFBFBD><EFBFBD><EFBFBD>ŵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD>
while 1=1
begin
exec f_get_billno 'PS', @swarecode, '1', @psno output
if exists(select 1 from t_dist_head where billno = @psno)
continue
else
break
end
if @@ERROR <> 0
begin
set @psMsg = '<EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݺ<EFBFBD>ʧ<EFBFBD><EFBFBD>'
return(-1)
end
insert into t_dist_body(billno,serialno,plucode,pluname,barcode,supcode,cargono,spec,unit,punit,itemcnt,pcount,sglcount,price,jprice,netjprice,
cost,netcost,zpamount,zpnetamount,
ispsprice,zpprice,zpcount,total,jtaxrate,staxrate,depcode,depname,remark)
select @psno,serialno,a.plucode,a.pluname,a.barcode,a.supcode,a.cargono,a.spec,a.unit,punit,a.itemcnt,pcount,sglcount,a.price,a.jprice,a.netjprice,
cost,netcost,cost as zpamount,round(cost/(1+b.staxrate/100.00),2) as zpnetamount,
'0' as ispsprice,a.jprice as zpprice,counts,total,a.jtaxrate,b.staxrate,a.depcode,a.depname,a.remark
from t_accept_body a,t_plu b
where billno = @psbillno and a.plucode = b.plucode
insert into t_dist_head(billno,askno,orgcode,shopcode,depcode,depname,lrdate,lrtime,sqauremode,paydate,chkstatus,
zpcount,zpamount,zpnetamount,cost,netcost,total,usercode,username,zdrcode,zdrname,remark)
select @psno,'',@swarecode,@sshopcode,'' as depcode,'' depname,@scurdate,@scurtime,'1' as sqauremode,@scurdate,'1' as chkstatus,
sum(d.zpcount),sum(d.zpamount),sum(d.zpnetamount),sum(d.cost),sum(d.netcost),sum(d.total),@susercode,@susername,@susercode,@susername,@psbillno
from t_dist_body d
where d.billno = @psno
update t_dist_head
set rzdate = @scurdate,
rztime = @scurtime
where billno = @psno
insert into t_pay_bill(orgcode,billtype,billno,bizdate,supcode,sqauremode,cost,paydate,jscost,zrcost,isfinished,total,contrno,finacode)
select shopcode,'6',billno,lrdate,'C2000',sqauremode,zpamount,paydate,0,0,case when zpamount=0 then '1' else '0' end,total,'',@sfinacode
from t_dist_head where billno=@psno
--3<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 'PJH', @swarecode, '1', @psjhno output
if exists(select 1 from t_accept_head where billno = @psjhno)
continue
else
break
end
if @@ERROR <> 0
begin
set @psMsg = '<EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݺ<EFBFBD>ʧ<EFBFBD><EFBFBD>'
return(-1)
end
insert into t_accept_head(billno,orgcode,billtype,bizdate,lrdate,lrtime,depcode,depname,supcode,supname,
place,sqauremode,paydate,orderno,chkstatus,shrcode,shrname,usercode,username,zdrcode,zdrname,remark,askno)
select @psjhno,shopcode,'3',@scurdate,@scurdate,@scurtime,depcode,depname,orgcode,(select supname from t_supplier where supcode=orgcode) as supname,
'0',sqauremode,paydate,billno,chkstatus,shrcode,shrname,@susercode,@susername,@susercode,@susername,remark,askno
from t_dist_head where billno=@psno
if @@error<>0
begin
set @psmsg='<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><EFBFBD><EFBFBD>ͷʧ<EFBFBD><EFBFBD>'
return(-1)
end
insert into t_accept_body(billno,plucode,serialno,barcode,pluname,cargono,spec,unit,punit,itemcnt,pcount,sglcount,
jprice,netjprice,ornjprice,ornnetjprice,price,counts,cost,netcost,total,jtaxrate,jxprice,cgcount,depcode,depname,remark)
select @psjhno,a.plucode,a.serialno,a.barcode,a.pluname,a.cargono,a.spec,a.unit,a.punit,a.itemcnt,a.pcount,a.sglcount,
a.zpprice,round(a.zpprice/(1+a.staxrate/100.0),4),
a.zpprice,round(a.zpprice/(1+a.staxrate/100.0),4),c.price,
a.zpcount,a.zpamount,a.zpnetamount,
case when b.plutype='2' then 0 else round(c.price*a.zpcount,2) end,
a.staxrate,
case when b.plutype='2' then 0 else (round(c.price*a.zpcount,2)-round(a.zpprice*a.zpcount,2)) end,a.zpcount,a.depcode,a.depname,a.remark
from t_dist_body a,t_plu b,t_plu_org c where billno=@psno
and a.plucode=b.plucode and a.plucode=c.plucode and c.orgcode=@sshopcode
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
update a set counts=b.counts,cost=b.cost,netcost=b.netcost,total=b.total
from t_accept_head a,(select billno,sum(counts) as counts,sum(cost) as cost,sum(netcost) as netcost,sum(total) as total from t_accept_body
where billno=@psjhno group by billno) b
where a.billno=b.billno
if @@error<>0
begin
set @psmsg='<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><EFBFBD><EFBFBD>ͷʧ<EFBFBD><EFBFBD>'
return(-1)
end
update t_accept_head
set rzdate = @scurdate,
rztime = @scurtime
where billno = @psjhno
set @psmsg = ''
return (1)
end
go