|
|
/***************************************************************************
|
|
|
¼ÇÕË´æ´¢¹ý³Ì½Å±¾
|
|
|
****************************************************************************/
|
|
|
|
|
|
if exists(select * from sysobjects where name='p_rz_prepare' and xtype='p')
|
|
|
drop procedure p_rz_prepare
|
|
|
go
|
|
|
create procedure p_rz_prepare
|
|
|
(
|
|
|
@psbilltype varchar(20),
|
|
|
@psorgcode varchar(10),
|
|
|
@psbillno varchar(20),
|
|
|
@psparams varchar(200),
|
|
|
@psmsg varchar(2000) out
|
|
|
)
|
|
|
as
|
|
|
begin
|
|
|
declare @ssql nvarchar(2000)
|
|
|
declare @smessage_tmp varchar(2000)
|
|
|
declare @irnt int
|
|
|
set @ssql ='exec @rnt=p_rz_prepare_'+@psbilltype+' '''+@psorgcode+''','''+@psbillno+''', '''+@psparams+''',@smessage out'
|
|
|
exec sp_executesql @ssql,N'@smessage varchar(2000) output,@rnt int output',@smessage_tmp out,@irnt out
|
|
|
set @psmsg=@smessage_tmp
|
|
|
return(@irnt)
|
|
|
end
|
|
|
go
|
|
|
|
|
|
if exists(select * from sysobjects where name='p_rz_sum' and xtype='p')
|
|
|
drop procedure p_rz_sum
|
|
|
go
|
|
|
create procedure p_rz_sum
|
|
|
(
|
|
|
@psbilltype varchar(20),
|
|
|
@psorgcode varchar(10),
|
|
|
@psbillno varchar(20),
|
|
|
@psparams varchar(200),
|
|
|
@psmsg varchar(2000) out
|
|
|
)
|
|
|
as
|
|
|
begin
|
|
|
declare @ssql nvarchar(2000)
|
|
|
declare @smessage_tmp varchar(2000)
|
|
|
declare @irnt int
|
|
|
set @ssql ='exec @rnt=p_rz'+isnull('_'+@psbilltype,'')+' '''+isnull(@psorgcode,'')+''','''+isnull(@psbillno,'')+''','''+isnull(@psparams,'')+''', @smessage out'
|
|
|
exec sp_executesql @ssql,N'@smessage varchar(2000) output,@rnt int output',@smessage_tmp out,@irnt out
|
|
|
set @psmsg=@smessage_tmp
|
|
|
return(@irnt)
|
|
|
end
|
|
|
go
|
|
|
|
|
|
if exists(select * from sysobjects where name='p_build_customer_book' and xtype='p')
|
|
|
drop procedure p_build_customer_book
|
|
|
go
|
|
|
create procedure p_build_customer_book
|
|
|
(
|
|
|
@pstablename varchar(20),
|
|
|
@psmsg varchar(2000) out
|
|
|
)
|
|
|
as
|
|
|
begin
|
|
|
declare @str varchar(8000)
|
|
|
declare @producttype varchar(2)
|
|
|
declare @triggername varchar(20)
|
|
|
set @str = 'if not exists (select name from dbo.sysobjects where name=''' + @pstablename + ''' and xtype=''u'')
|
|
|
create table ' + @pstablename + '
|
|
|
(bookdate varchar(10) not null,
|
|
|
booktime varchar(8) not null,
|
|
|
bizdate varchar(10) not null,
|
|
|
orgcode varchar(10) not null,
|
|
|
serialno int identity(1,1),
|
|
|
custcode varchar(15) not null,
|
|
|
billtype varchar(1) not null,
|
|
|
billno varchar(20) not null,
|
|
|
username varchar(10),
|
|
|
ywname varchar(10),
|
|
|
ctotal numeric(19,4) null,
|
|
|
ysjytotal numeric(19,4) not null default(0),
|
|
|
prepayjytotal numeric(19,4) not null default(0),
|
|
|
tag varchar(1) null,
|
|
|
remark varchar(100) null,
|
|
|
accdate varchar(10) null,
|
|
|
constraint pk_' + @pstablename + ' primary key
|
|
|
(bizdate,custcode,billtype,billno,serialno,orgcode)
|
|
|
)'
|
|
|
exec(@str)
|
|
|
if @@error <> 0
|
|
|
begin
|
|
|
set @psmsg='´´½¨±í' + @pstablename + 'ʧ°Ü'
|
|
|
return(-1)
|
|
|
end
|
|
|
set @psmsg=''
|
|
|
return(1)
|
|
|
end
|
|
|
go
|
|
|
|
|
|
if exists(select * from sysobjects where name='p_create_gbk_data' and xtype='p')
|
|
|
drop procedure p_create_gbk_data
|
|
|
go
|
|
|
create procedure p_create_gbk_data
|
|
|
(
|
|
|
@psdate varchar(10),
|
|
|
@pstime varchar(8),
|
|
|
@psplucode varchar(20),
|
|
|
@psdepcode varchar(10),
|
|
|
@psbillno varchar(20),
|
|
|
@psbilltype varchar(2),
|
|
|
@psjprice numeric(19,4),
|
|
|
@psnetjprice numeric(19,4),
|
|
|
@psprice numeric(19,4),
|
|
|
@psfscount numeric(19,4),
|
|
|
@psfscost numeric(19,4),
|
|
|
@psfsnetcost numeric(19,4),
|
|
|
@psfstotal numeric(19,4),
|
|
|
@psjccount numeric(19,4),
|
|
|
@psjccost numeric(19,4),
|
|
|
@psjcnetcost numeric(19,4),
|
|
|
@psjctotal numeric(19,4),
|
|
|
@psorgcode varchar(10),
|
|
|
@psaccdate varchar(10),
|
|
|
@pstag varchar(1),
|
|
|
@psmsg varchar(2000) out
|
|
|
)
|
|
|
as
|
|
|
begin
|
|
|
if not exists(select * from t_gbk_yyyymm where bookdate=@psdate and booktime=@pstime and plucode=@psplucode
|
|
|
and billno=@psbillno and billtype=@psbilltype and orgcode=@psorgcode)
|
|
|
insert into t_gbk_yyyymm(bookdate,booktime,plucode,depcode,billno,billtype,
|
|
|
jprice,netjprice,price,fscount,fscost,fsnetcost,fstotal,
|
|
|
jccount,jccost,jcnetcost,jctotal,tag,orgcode,accdate)
|
|
|
values(@psdate,@pstime,@psplucode,@psdepcode,@psbillno,@psbilltype,
|
|
|
@psjprice,@psnetjprice,@psprice,@psfscount,@psfscost,@psfsnetcost,@psfstotal,
|
|
|
@psjccount,@psjccost,@psjcnetcost,@psjctotal,@pstag,@psorgcode,@psaccdate)
|
|
|
else
|
|
|
update t_gbk_yyyymm set jprice=round((fscost+@psfscost)/(fscount+@psfscount),4),
|
|
|
netjprice=round((fsnetcost+@psfsnetcost)/(fscount+@psfscount),4),
|
|
|
price=@psprice,fscount=fscount+@psfscount,
|
|
|
fscost=fscost+@psfscost,fsnetcost=fsnetcost+@psfsnetcost,fstotal=fstotal+@psfstotal,
|
|
|
jccount=@psjccount,jccost=@psjccost,jcnetcost=@psjcnetcost,
|
|
|
jctotal=@psjctotal,tag=@pstag,accdate=@psaccdate
|
|
|
where bookdate=@psdate and booktime=@pstime and plucode=@psplucode
|
|
|
and billno=@psbillno and billtype=@psbilltype and orgcode=@psorgcode
|
|
|
if @@error<>0
|
|
|
begin
|
|
|
set @psmsg = 'Éú³ÉÉÌƷ̨ÕËʧ°Ü'
|
|
|
return(-1)
|
|
|
end
|
|
|
end
|
|
|
go
|
|
|
|
|
|
if exists(select * from sysobjects where name ='p_create_vbk' and xtype='p')
|
|
|
drop procedure p_create_vbk
|
|
|
go
|
|
|
create procedure p_create_vbk
|
|
|
(
|
|
|
@pstablename varchar(20),
|
|
|
@psmsg varchar(2000) out
|
|
|
)
|
|
|
as
|
|
|
begin
|
|
|
declare @ssql varchar(2000)
|
|
|
if not exists(select * from sysobjects where name=@pstablename)
|
|
|
begin
|
|
|
set @ssql = 'create table '+@pstablename
|
|
|
+'(orgcode varchar(10) not null,'
|
|
|
+'bookdate varchar(10) not null,'
|
|
|
+'booktime varchar(8) not null,'
|
|
|
+'supcode varchar(15) not null,'
|
|
|
+'billno varchar(20) not null,'
|
|
|
+'billtype varchar(1) not null,'
|
|
|
+'fsamount numeric(19,4) null,'
|
|
|
+'yfjytotal numeric(19,4) null,'
|
|
|
+'prejytotal numeric(19,4) null,'
|
|
|
+'tag varchar(1) null,'
|
|
|
+'serialno int identity (1,1) not null,'
|
|
|
+'constraint pk_'+@pstablename+' primary key'
|
|
|
+'(bookdate,booktime,supcode ,billno,billtype)'
|
|
|
+')'
|
|
|
exec(@ssql)
|
|
|
if @@error <>0
|
|
|
begin
|
|
|
set @psmsg = 'Éú³É¹©Ó¦ÉĮ̀Õ˱íʧ°Ü'
|
|
|
return(-1)
|
|
|
end
|
|
|
end
|
|
|
set @psmsg = ''
|
|
|
return (1)
|
|
|
end
|
|
|
go
|
|
|
|
|
|
if exists (select name from sysobjects where name='p_sys_day_over_plugin' and xtype='p')
|
|
|
drop procedure p_sys_day_over_plugin
|
|
|
go
|
|
|
create procedure p_sys_day_over_plugin
|
|
|
(
|
|
|
@orgcode varchar(10),
|
|
|
@accdate varchar(10),
|
|
|
@acctimes int,
|
|
|
@usercode varchar(10),
|
|
|
@vipdbname varchar(20),
|
|
|
@message varchar(200) out
|
|
|
)
|
|
|
as
|
|
|
declare @psmsg varchar(200)
|
|
|
begin
|
|
|
declare @curedition varchar(1)
|
|
|
declare @finaltype varchar(1)
|
|
|
declare @irtnresult int
|
|
|
declare @srtnmsg varchar(200)
|
|
|
declare @sautopdaccount varchar(1)
|
|
|
declare @ssql varchar(2000)
|
|
|
set @sautopdaccount = isnull(@sautopdaccount,'0')
|
|
|
set @finaltype = null
|
|
|
|
|
|
--sapÏúÊÛÃ÷ϸ»ã×Ü
|
|
|
exec @irtnresult = p_int_gen_flow_item @orgcode, @accdate, @srtnmsg out
|
|
|
if @irtnresult <> 1
|
|
|
begin
|
|
|
insert into t_over_error (orgcode, overdate, overtime, errreason)
|
|
|
values (@orgcode, @accdate, convert(varchar(10), getdate(), 24), @srtnmsg)
|
|
|
end
|
|
|
--sapÏúÊ۳ɱ¾»ã×Ü
|
|
|
exec @irtnresult = p_int_gen_flow_chg @orgcode, @accdate, @srtnmsg out
|
|
|
if @irtnresult <> 1
|
|
|
begin
|
|
|
insert into t_over_error (orgcode, overdate, overtime, errreason)
|
|
|
values (@orgcode, @accdate, convert(varchar(10), getdate(), 24), @srtnmsg)
|
|
|
end
|
|
|
--sapÖ§¸¶·½Ê½»ã×Ü
|
|
|
exec @irtnresult = p_int_gen_flow_pay @orgcode, @accdate, @srtnmsg out
|
|
|
if @irtnresult <> 1
|
|
|
begin
|
|
|
insert into t_over_error (orgcode, overdate, overtime, errreason)
|
|
|
values (@orgcode, @accdate, convert(varchar(10), getdate(), 24), @srtnmsg)
|
|
|
end
|
|
|
--sapÏÖ½ð½É´æ»ã×Ü
|
|
|
exec @irtnresult = p_int_gen_flow_pay_cash @orgcode, @accdate, @srtnmsg out
|
|
|
if @irtnresult <> 1
|
|
|
begin
|
|
|
insert into t_over_error (orgcode, overdate, overtime, errreason)
|
|
|
values (@orgcode, @accdate, convert(varchar(10), getdate(), 24), @srtnmsg)
|
|
|
end
|
|
|
|
|
|
set @message = ''
|
|
|
return (1)
|
|
|
end
|
|
|
go
|
|
|
|
|
|
if exists(select * from sysobjects where name='p_return_create_dist_form' and xtype='p')
|
|
|
drop procedure p_return_create_dist_form
|
|
|
go
|
|
|
create procedure p_return_create_dist_form
|
|
|
(
|
|
|
@psbillno varchar(20),
|
|
|
@psmsg varchar(2000) out
|
|
|
)
|
|
|
as
|
|
|
begin
|
|
|
declare @ssql varchar(2000)
|
|
|
declare @scurver varchar(1)
|
|
|
declare @sorgcode varchar(10)
|
|
|
declare @org_orgtype varchar(1)
|
|
|
declare @org_isdbdeploy varchar(1)
|
|
|
declare @scalctype varchar(1)
|
|
|
declare @fsjrate numeric(19,4)
|
|
|
declare @sedition varchar(20)
|
|
|
declare @svendorcode varchar(20)
|
|
|
declare @svendortype varchar(2)
|
|
|
declare @svendorjymode varchar(1)
|
|
|
declare @v_org_type varchar(1)
|
|
|
declare @scurdate varchar(10)
|
|
|
declare @scurtime varchar(8)
|
|
|
declare @ssameaccorg varchar(1)
|
|
|
|
|
|
select @sedition=itemvalue from t_syscfg where section='SYSTEM' and itemname='Edition'
|
|
|
select @scurver=itemvalue from t_syscfg where section='SYSTEM' and itemname = 'VER'
|
|
|
select @sorgcode=orgcode,@svendorcode=supcode from t_return_head where billno=@psbillno
|
|
|
select @scurdate=convert(varchar(100),getdate(),23),@scurtime=convert(varchar(100),getdate(),108)
|
|
|
select @org_orgtype=orgtype,@org_isdbdeploy=isdbdeploy,@scalctype=calctype,@fsjrate=sjrate from t_shop where orgcode=@sorgcode
|
|
|
select @ssameaccorg=case when isnull(a.finacode,'')<>isnull(b.finacode,'') then '0' else '1' end from t_shop a,t_shop b where a.orgcode=@sorgcode and b.orgcode=@svendorcode
|
|
|
select @svendorjymode=jymode,@svendortype=suptype
|
|
|
from t_supplier where supcode=@svendorcode
|
|
|
if @@rowcount= 0
|
|
|
begin
|
|
|
set @psmsg = '¹©Ó¦ÉÌ['+@svendorcode+']²»´æÔÚ'
|
|
|
return(-1)
|
|
|
end
|
|
|
if (@scurver <> '0') and (@org_orgtype <> '2') and (@org_isdbdeploy = '1') and (@svendortype = '9')
|
|
|
begin
|
|
|
delete from t_dist_body where billno = @psbillno
|
|
|
if @sedition = '4'
|
|
|
begin
|
|
|
delete from t_dist_cs_body where billno = @psbillno
|
|
|
end
|
|
|
delete from t_dist_head where billno = @psbillno
|
|
|
set @scalctype = '0'
|
|
|
insert into t_dist_body(billno,plucode,serialno,pluname,barcode,cargono,spec,unit,jprice,netjprice,price,zpprice,
|
|
|
sglcount,zpcount,cost,netcost,total,zpamount,zpnetamount,jtaxrate,staxrate,remark,depcode,depname)
|
|
|
select billno,d.plucode,serialno,d.pluname,d.barcode,d.cargono,d.spec,d.unit,
|
|
|
case when o.plutype='2' then 0 else
|
|
|
case when @scalctype = '1' then round(d.jprice/(1+@fsjrate/100.00),4)
|
|
|
else isnull(d.jprice,0) end end as jprice,
|
|
|
case when o.plutype='2' then 0 else
|
|
|
case when @scalctype = '1' then round(d.jprice/(1+@fsjrate/100.00)/(1+d.jtaxrate/100.00),4)
|
|
|
else isnull(d.netjprice,0) end end as netjprice,
|
|
|
isnull(g.price,d.price),case when o.plutype='2' then 0 else d.jprice end as zpprice,
|
|
|
counts*(-1),counts*(-1),
|
|
|
case when o.plutype='2' then 0 else
|
|
|
case when @scalctype = '1' then round(round(d.jprice/(1+@fsjrate/100.00),4)*counts*(-1),2)
|
|
|
else d.cost*(-1) end end as cost,
|
|
|
case when o.plutype='2' then 0 else
|
|
|
case when @scalctype = '1' then round(round(d.jprice/(1+@fsjrate/100.00)/(1+o.jtaxrate/100.00),4)*counts*(-1),2)
|
|
|
else round(case when @ssameaccorg='1' then d.cost*(-1)/(1+o.jtaxrate/100.00) else d.cost*(-1)/(1+o.staxrate/100.00) end,2) end end as netcost,
|
|
|
case when o.plutype='2' then 0 else round(isnull(g.price,0)*counts*(-1),2) end total,
|
|
|
case when o.plutype='2' then 0 else d.cost*(-1) end zpamount,
|
|
|
case when o.plutype='2' then 0
|
|
|
else round(case when @ssameaccorg='1' then d.cost*(-1)/(1+o.jtaxrate/100.00) else d.cost*(-1)/(1+o.staxrate/100.00) end,2) end zpnetamount,
|
|
|
d.jtaxrate,o.staxrate,d.remark,d.depcode,d.depname
|
|
|
|
|
|
from t_return_body d left join t_plu_org g on d.plucode=g.plucode
|
|
|
left join t_plu o on d.plucode=o.plucode
|
|
|
where d.billno = @psbillno and g.orgcode=@svendorcode and g.isright = '1'
|
|
|
if @@error <> 0
|
|
|
begin
|
|
|
set @psmsg = 'Éú³ÉÅäËÍÍË»õµ¥±íÌåʧ°Ü'
|
|
|
return(-1)
|
|
|
end
|
|
|
|
|
|
if @sedition = '4'
|
|
|
begin
|
|
|
insert into t_dist_cs_body(billno,serialno,plucode,csbarcode,colorcode,sizecode,ccounts,remark)
|
|
|
select billno,serialno,d.plucode,d.csbarcode,colorcode,sizecode,d.ccounts*(-1),d.remark
|
|
|
from t_return_cs_body d left join t_plu_org g on d.plucode=g.plucode and g.orgcode=@svendorcode and g.isright = '1'
|
|
|
where d.billno=@psbillno
|
|
|
if @@error <> 0
|
|
|
begin
|
|
|
set @psmsg = 'Éú³ÉÅäËÍÍË»õµ¥É«Âëʧ°Ü'
|
|
|
return(-1)
|
|
|
end
|
|
|
end
|
|
|
|
|
|
insert into t_dist_head(billno,orgcode,lrdate,lrtime,shopcode,depcode,depname,zdrcode,zdrname,usercode,username,chkstatus,shrcode,shrname,remark,tag)
|
|
|
select @psbillno,supcode,@scurdate,@scurtime,orgcode,depcode,depname,zdrcode,zdrname,usercode,username,'1',shrcode,shrname,remark,tag
|
|
|
from t_return_head where billno=@psbillno
|
|
|
if @@error <> 0
|
|
|
begin
|
|
|
set @psmsg = 'Éú³ÉÅäËÍÍË»õ±íͷʧ°Ü'
|
|
|
return(-1)
|
|
|
end
|
|
|
|
|
|
update h set zpcount=b.zpcount,cost=b.cost,netcost=b.netcost,total=b.total,zpamount=b.zpamount,zpnetamount=b.zpnetamount,chkstatus='1'
|
|
|
from t_dist_head h,(select billno,sum(zpcount) as zpcount,sum(cost) as cost,sum(netcost) as netcost,
|
|
|
sum(total) as total,sum(zpamount) as zpamount,sum(zpnetamount) as zpnetamount from t_dist_body where billno=@psbillno group by billno) b
|
|
|
where h.billno=b.billno
|
|
|
if @@error <> 0
|
|
|
begin
|
|
|
set @psmsg = '¸üÐÂÅäËÍÍË»õ±íͷʧ°Ü'
|
|
|
return(-1)
|
|
|
end
|
|
|
end
|
|
|
set @psmsg = ''
|
|
|
return (1)
|
|
|
end
|
|
|
go
|
|
|
|
|
|
|
|
|
|
|
|
if exists(select * from sysobjects where name ='p_get_finacode' and xtype='p')
|
|
|
drop procedure p_get_finacode
|
|
|
go
|
|
|
create procedure p_get_finacode
|
|
|
(
|
|
|
@pswarecode varchar(10),
|
|
|
@psshopcode varchar(10),
|
|
|
@psfinacode varchar(10) out,
|
|
|
@psissameacc varchar(1) out,
|
|
|
@psmsg varchar(2000) out
|
|
|
)
|
|
|
as
|
|
|
declare @swarefinacode varchar(10)
|
|
|
declare @sshopfinacode varchar(10)
|
|
|
begin
|
|
|
|
|
|
select @swarefinacode = finacode from t_shop where orgcode = @pswarecode
|
|
|
if (@swarefinacode = '') or (@swarefinacode is null)
|
|
|
begin
|
|
|
set @psmsg = '»ñÈ¡ÖÐÑë²Ö²ÆÎñÖ÷Ìåʧ°Ü'
|
|
|
return(-1)
|
|
|
end
|
|
|
|
|
|
select @sshopfinacode = finacode from t_shop where orgcode = @psshopcode
|
|
|
if (@sshopfinacode = '') or (@sshopfinacode is null)
|
|
|
begin
|
|
|
set @psmsg = '»ñÈ¡ÓÍÕ¾²ÆÎñÖ÷Ìåʧ°Ü'
|
|
|
return(-1)
|
|
|
end
|
|
|
|
|
|
if (@swarefinacode = @sshopfinacode)
|
|
|
begin
|
|
|
set @psfinacode = @sshopfinacode
|
|
|
set @psissameacc = '1'
|
|
|
end else
|
|
|
begin
|
|
|
set @psfinacode = @swarefinacode
|
|
|
set @psissameacc = '0'
|
|
|
end
|
|
|
|
|
|
set @psmsg = ''
|
|
|
return (1)
|
|
|
end
|
|
|
go
|
|
|
|
|
|
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¡¢Éú³É C009Î޲ɹºÍË»õ
|
|
|
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 = '»ñÈ¡ÍË»õµ¥µ¥¾ÝºÅʧ°Ü'
|
|
|
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,oldbillno,chkstatus,billtype,
|
|
|
counts,cost,netcost,total,usercode,username,zdrcode,zdrname,remark)
|
|
|
select @thno,@swarecode,@scurdate,@scurdate,@scurtime,contrno,supcode,supname,'1'as place,@psbillno,chkstatus,'0',
|
|
|
counts,cost,netcost,total,usercode,username,zdrcode,zdrname,'¿ç²ÆÎñÖ÷ÌåÖ±ËÍÍË»õÉú³É'
|
|
|
from t_return_head where billno = @psbillno
|
|
|
|
|
|
update t_return_head
|
|
|
set rzdate = @scurdate,
|
|
|
rztime = @scurtime
|
|
|
where billno = @thno
|
|
|
|
|
|
--2¡¢Éú³ÉÃŵ굽C009µÄÅäËÍÍË»õµ¥
|
|
|
-- 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 = '»ñÈ¡ÅäË͵¥µ¥¾ÝºÅʧ°Ü'
|
|
|
-- 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,'¿ç²ÆÎñÖ÷ÌåÖ±ËÍÍË»õÉú³É'
|
|
|
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¡¢Éú³ÉÃŵêµÄÃŵêÍ˲ֵ¥
|
|
|
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 = '»ñÈ¡ÃŵêÍ˲ֵ¥µ¥¾ÝºÅʧ°Ü'
|
|
|
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,'¿ç²ÆÎñÖ÷ÌåÖ±ËÍÍË»õÉú³É'
|
|
|
from t_return_head where billno = @psbillno
|
|
|
if @@error<>0
|
|
|
begin
|
|
|
set @psmsg='Éú³ÉÃŵêÍ˲ֵ¥±íͷʧ°Ü'
|
|
|
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='Éú³ÉÃŵêÍ˲ֵ¥±íÌåʧ°Ü'
|
|
|
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¡¢Éú³É C009Î޲ɹºÑéÊÕ
|
|
|
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 = '»ñÈ¡ÑéÊÕµ¥µ¥¾ÝºÅʧ°Ü'
|
|
|
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,'¿ç²ÆÎñÖ÷ÌåÖ±ËÍÑéÊÕÉú³É',''
|
|
|
from t_accept_head where billno = @psbillno
|
|
|
|
|
|
update t_accept_head
|
|
|
set rzdate = @scurdate,
|
|
|
rztime = @scurtime
|
|
|
where billno = @jhno
|
|
|
|
|
|
--2¡¢Éú³ÉC009µ½ÃŵêµÄÅäË͵¥
|
|
|
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 = '»ñÈ¡ÅäË͵¥µ¥¾ÝºÅʧ°Ü'
|
|
|
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¡¢Éú³ÉÃŵêµÄÅäËÍÑéÊÕµ¥
|
|
|
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 = '»ñÈ¡ÅäËÍÑéÊÕµ¥µ¥¾ÝºÅʧ°Ü'
|
|
|
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='Éú³ÉÅäËÍÑéÊÕµ¥±íͷʧ°Ü'
|
|
|
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='Éú³ÉÅäËÍÑéÊÕµ¥±íÌåʧ°Ü'
|
|
|
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='¸üÐÂÅäËÍÑéÊÕµ¥±íͷʧ°Ü'
|
|
|
return(-1)
|
|
|
end
|
|
|
|
|
|
update t_accept_head
|
|
|
set rzdate = @scurdate,
|
|
|
rztime = @scurtime
|
|
|
where billno = @psjhno
|
|
|
|
|
|
set @psmsg = ''
|
|
|
return (1)
|
|
|
end
|
|
|
go |