|
|
/*·ÇÓÍÏúÊÛ±¨±í*/
|
|
|
if exists(select * from sysobjects where name='p_rpt_salerpt' and xtype='p')
|
|
|
drop procedure p_rpt_salerpt
|
|
|
go
|
|
|
|
|
|
create procedure p_rpt_salerpt
|
|
|
(
|
|
|
@pfinacode varchar(1000),
|
|
|
@porgcode varchar(1000),
|
|
|
@pbgndate varchar(10),
|
|
|
@penddate varchar(10),
|
|
|
@pclscode varchar(1000),
|
|
|
@pplucode varchar(2000),
|
|
|
@psupcode varchar(10),
|
|
|
@ps_SysUserCode varchar(20)
|
|
|
)
|
|
|
as
|
|
|
declare @ssql varchar(8000)
|
|
|
declare @stmpdate varchar(10)
|
|
|
declare @sfinacode varchar(1000)
|
|
|
declare @sorgcode varchar(1000)
|
|
|
declare @sclscode varchar(1000)
|
|
|
declare @splucode varchar(1000)
|
|
|
declare @ssupcode varchar(10)
|
|
|
declare @sbgndate varchar(10)
|
|
|
declare @senddate varchar(10)
|
|
|
begin
|
|
|
set @sfinacode=replace(@pfinacode,',',''',''')
|
|
|
set @sorgcode=replace(@porgcode,',',''',''')
|
|
|
set @sclscode=replace(@pclscode,',',''',''')
|
|
|
set @splucode=replace(@pplucode,',',''',''')
|
|
|
set @ssupcode=@psupcode
|
|
|
set @sbgndate=@pbgndate
|
|
|
set @senddate=@penddate
|
|
|
if isnull(@sbgndate,'')=''
|
|
|
set @sbgndate='2023-08-01'
|
|
|
if isnull(@senddate,'')=''
|
|
|
set @senddate='2099-12-31'
|
|
|
|
|
|
if exists(select name from tempdb..sysobjects where name='##tmpgclass' and xtype='u')
|
|
|
drop table ##tmpgclass
|
|
|
create table ##tmpgclass (
|
|
|
clscode varchar(10),clsname varchar(20),uppercode1 varchar(10),uppername1 varchar(20),uppercode2 varchar(10),uppername2 varchar(20))
|
|
|
|
|
|
if exists(select name from tempdb..sysobjects where name='##tmpplusale' and xtype='u')
|
|
|
drop table ##tmpplusale
|
|
|
create table ##tmpplusale (
|
|
|
accdate varchar(10),orgcode varchar(10),orgname varchar(30),plucode varchar(20),pluname varchar(40),
|
|
|
supcode varchar(15),supname varchar(100),jymode varchar(1),counts numeric(19,4),cost numeric(19,4),netcost numeric(19,4),total numeric(19,4),
|
|
|
amount numeric(19,4),netamount numeric(19,4),normaldsc numeric(19,4),vipdsc numeric(19,4),pricedsc numeric(19,4),
|
|
|
grossprofit numeric(19,4),netprofit numeric(19,4),adjustprofit numeric(19,4),netadjustprofit numeric(19,4),
|
|
|
jtaxrate int,staxrate int,prctr varchar(10),finacode varchar(10),kccount numeric(19,4),price numeric(19,4),
|
|
|
clscode varchar(10),clsname varchar(20),uppercode1 varchar(10),uppername1 varchar(20),uppercode2 varchar(10),uppername2 varchar(20))
|
|
|
|
|
|
insert into ##tmpgclass (clscode,clsname,uppercode1,uppercode2)
|
|
|
select clscode,clsname,uppercode1,uppercode2 from t_gclass where clslevel=3
|
|
|
update a set uppername1=b.clsname
|
|
|
from ##tmpgclass a,t_gclass b where a.uppercode1=b.clscode
|
|
|
update a set uppername2=b.clsname
|
|
|
from ##tmpgclass a,t_gclass b where a.uppercode2=b.clscode
|
|
|
|
|
|
set @stmpdate=@sbgndate
|
|
|
while substring(@stmpdate,1,7)<=substring(@senddate,1,7)
|
|
|
begin
|
|
|
if exists(select name from sysobjects where name='t_plusale_'+substring(@stmpdate,1,4)+substring(@stmpdate,6,2) and xtype='u')
|
|
|
begin
|
|
|
set @ssql='insert into ##tmpplusale(accdate,orgcode,orgname,plucode,pluname,supcode,supname,jymode,counts,cost,netcost,total,amount,netamount,normaldsc,vipdsc,pricedsc,grossprofit,netprofit,
|
|
|
adjustprofit,netadjustprofit,jtaxrate,staxrate,finacode,kccount,price,clscode,clsname,uppercode1,uppername1,uppercode2,uppername2,prctr)
|
|
|
select a.accdate,a.orgcode,b.orgname,a.plucode,d.pluname,a.supcode,c.supname,c.jymode,a.counts,a.cost,a.netcost,a.total,a.amount,a.netamount,a.normaldsc,a.vipdsc,a.pricedsc,a.grossprofit,a.netprofit,
|
|
|
a.adjustprofit,a.netadjustprofit,a.jtaxrate,a.staxrate,b.finacode,e.gcount+e.ccount,e.price,d.clscode,f.clsname,f.uppercode1,f.uppername1,f.uppercode2,f.uppername2,
|
|
|
''P''+b.finacode+''1''+case when b.orgtype=''2'' then b.param1 else b.orgcode end
|
|
|
from t_plusale_'+substring(@stmpdate,1,4)+substring(@stmpdate,6,2)+' a
|
|
|
left join t_shop b on a.orgcode=b.orgcode
|
|
|
left join t_supplier c on a.supcode=c.supcode
|
|
|
left join t_plu d on a.plucode=d.plucode
|
|
|
left join t_plu_org e on a.plucode=e.plucode and a.orgcode=e.orgcode
|
|
|
left join ##tmpgclass f on d.clscode=f.clscode
|
|
|
where accdate between '''+@sbgndate+''' and '''+@senddate+'''
|
|
|
and exists(select * from t_user_org where orgcode=a.orgcode and usercode='''+@ps_SysUserCode+''')'
|
|
|
if @sfinacode<>''
|
|
|
set @ssql=@ssql+' and exists(select * from t_shop where orgcode=a.orgcode and finacode in ('''+@sfinacode+'''))'
|
|
|
if @sorgcode<>''
|
|
|
set @ssql=@ssql+' and a.orgcode in ('''+@sorgcode+''')'
|
|
|
if @sclscode<>''
|
|
|
set @ssql=@ssql+' and exists(select * from t_gclass where clscode=d.clscode and uppercode1 in ('''+@sclscode+'''))'
|
|
|
if @splucode<>''
|
|
|
set @ssql=@ssql+' and a.plucode in ('''+@splucode+''')'
|
|
|
if @ssupcode<>''
|
|
|
set @ssql=@ssql+' and a.supcode in ('''+@ssupcode+''')'
|
|
|
exec(@ssql)
|
|
|
end
|
|
|
set @stmpdate=convert(varchar(10),dateadd(month,1,@stmpdate),120)
|
|
|
end
|
|
|
|
|
|
set @ssql='select finacode,orgcode,orgname,accdate,plucode,pluname,
|
|
|
sum(counts) counts,sum(total) total,sum(amount) as amount,
|
|
|
sum(normaldsc+vipdsc+pricedsc) as dsc,sum(netamount) as netamount,staxrate,
|
|
|
sum(amount-netamount) as taxamount,sum(normaldsc+vipdsc+pricedsc)/(1+staxrate/100.00) as netdsc,
|
|
|
sum(normaldsc+vipdsc+pricedsc)-sum(normaldsc+vipdsc+pricedsc)/(1+staxrate/100.00) as taxdsc,
|
|
|
sum(cost+adjustprofit) as cost,sum(netcost+netadjustprofit) as netcost,sum(grossprofit-adjustprofit) as grossprofit,
|
|
|
case when sum(amount)=0 then 0 else sum(grossprofit-adjustprofit)/sum(amount)*100 end as profitrate,
|
|
|
case when isnull(jymode,''0'') = ''0'' then 0 else sum(total-cost-(total-cost)/(1+staxrate/100.00)) end as taxdktotal,
|
|
|
''FP'' as fptype,uppercode2,uppername2,uppercode1,uppername1,clscode,clsname,supcode,supname,prctr,kccount,price
|
|
|
from ##tmpplusale where 0=0
|
|
|
group by finacode,orgcode,orgname,accdate,plucode,pluname,jtaxrate,staxrate,uppercode2,uppername2,
|
|
|
uppercode1,uppername1,clscode,clsname,supcode,supname,jymode,prctr,kccount,price
|
|
|
order by finacode,orgcode,accdate,plucode'
|
|
|
exec(@ssql)
|
|
|
|
|
|
if exists(select name from tempdb..sysobjects where name='##tmpgclass' and xtype='u')
|
|
|
drop table ##tmpgclass
|
|
|
if exists(select name from tempdb..sysobjects where name='##tmpplusale' and xtype='u')
|
|
|
drop table ##tmpplusale
|
|
|
end
|
|
|
go
|
|
|
|
|
|
/*·ÇÓÍÖ§¸¶±¨±í*/
|
|
|
if exists(select * from sysobjects where name='p_rpt_tendrpt' and xtype='p')
|
|
|
drop procedure p_rpt_tendrpt
|
|
|
go
|
|
|
|
|
|
create procedure p_rpt_tendrpt
|
|
|
(
|
|
|
@porgcode varchar(1000),
|
|
|
@pbgndate varchar(10),
|
|
|
@penddate varchar(10),
|
|
|
@pclscode varchar(1000),
|
|
|
@pqryall varchar(1),
|
|
|
@ps_SysUserCode varchar(20)
|
|
|
)
|
|
|
as
|
|
|
declare @ssql varchar(8000)
|
|
|
declare @stmpdate varchar(10)
|
|
|
declare @sorgcode varchar(1000)
|
|
|
declare @sclscode varchar(1000)
|
|
|
declare @sadd varchar(4000)
|
|
|
declare @tendcode varchar(4)
|
|
|
declare @sbgndate varchar(10)
|
|
|
declare @senddate varchar(10)
|
|
|
begin
|
|
|
set @sorgcode=replace(@porgcode,',',''',''')
|
|
|
set @sclscode=replace(@pclscode,',',''',''')
|
|
|
set @sbgndate=@pbgndate
|
|
|
set @senddate=@penddate
|
|
|
if isnull(@sbgndate,'')=''
|
|
|
set @sbgndate='2023-08-01'
|
|
|
if isnull(@senddate,'')=''
|
|
|
set @senddate='2099-12-31'
|
|
|
|
|
|
if exists(select name from tempdb..sysobjects where name='##tmppaydeilysum' and xtype='u')
|
|
|
drop table ##tmppaydeilysum
|
|
|
create table ##tmppaydeilysum (
|
|
|
orgcode varchar(10),accdate varchar(10),clscode varchar(10),tendcode varchar(4),amount numeric(19,4))
|
|
|
if exists(select name from tempdb..sysobjects where name='##tmppaydeily' and xtype='u')
|
|
|
drop table ##tmppaydeily
|
|
|
create table ##tmppaydeily (
|
|
|
finacode varchar(10),finaname varchar(40),orgcode varchar(10),orgname varchar(30),accdate varchar(10),clscode varchar(10),clsname varchar(20),
|
|
|
amount numeric(19,4))
|
|
|
|
|
|
set @stmpdate=@sbgndate
|
|
|
while substring(@stmpdate,1,7)<=substring(@senddate,1,7)
|
|
|
begin
|
|
|
if exists(select name from sysobjects where name='t_int_flow_pay_deily_'+substring(@stmpdate,1,4)+substring(@stmpdate,6,2) and xtype='u')
|
|
|
begin
|
|
|
set @ssql='update a set amount=b.amount
|
|
|
from ##tmppaydeilysum a,(select business_date,werks,clscode,mop_id,sum(amount) as amount
|
|
|
from t_int_flow_pay_deily_'+substring(@stmpdate,1,4)+substring(@stmpdate,6,2)+' t
|
|
|
where business_date between '''+@sbgndate+''' and '''+@senddate+'''
|
|
|
and clscode not in (''1001'',''1002'') and left(werks,2)<>''2D''
|
|
|
group by business_date,werks,clscode,mop_id) b where a.accdate=b.business_date and a.orgcode=b.werks and a.clscode=b.clscode and a.tendcode=b.mop_id'
|
|
|
exec(@ssql)
|
|
|
|
|
|
set @ssql='insert into ##tmppaydeilysum(orgcode,accdate,clscode,tendcode,amount)
|
|
|
select werks,business_date,clscode,mop_id,sum(amount)
|
|
|
from t_int_flow_pay_deily_'+substring(@stmpdate,1,4)+substring(@stmpdate,6,2)+' t
|
|
|
where business_date between '''+@sbgndate+''' and '''+@senddate+'''
|
|
|
and clscode not in (''1001'',''1002'') and left(werks,2)<>''2D''
|
|
|
and not exists(select * from ##tmppaydeilysum where accdate=t.business_date and orgcode=t.werks and clscode=t.clscode and tendcode=t.mop_id)
|
|
|
and exists(select * from t_user_org where orgcode=t.werks and usercode='''+@ps_SysUserCode+''')'
|
|
|
if @sorgcode<>''
|
|
|
set @ssql=@ssql+' and werks in ('''+@sorgcode+''')'
|
|
|
if @sclscode<>''
|
|
|
set @ssql=@ssql+' and clscode in ('''+@sclscode+''')'
|
|
|
if isnull(@pqryall,'')='0'
|
|
|
set @ssql=@ssql+' and exists(select * from t_shop where orgcode=t.werks and overdate>=t.business_date)'
|
|
|
set @ssql=@ssql+' group by werks,business_date,clscode,mop_id'
|
|
|
exec(@ssql)
|
|
|
|
|
|
set @ssql='update a set amount=b.amount
|
|
|
from ##tmppaydeily a,(select business_date,werks,clscode,sum(amount) as amount
|
|
|
from t_int_flow_pay_deily_'+substring(@stmpdate,1,4)+substring(@stmpdate,6,2)+' t
|
|
|
where business_date between '''+@sbgndate+''' and '''+@senddate+'''
|
|
|
and clscode not in (''1001'',''1002'') and left(werks,2)<>''2D''
|
|
|
group by business_date,werks,clscode) b where a.accdate=b.business_date and a.orgcode=b.werks and a.clscode=b.clscode'
|
|
|
exec(@ssql)
|
|
|
|
|
|
set @ssql='insert into ##tmppaydeily(finacode,finaname,orgcode,orgname,accdate,clscode,clsname,amount)
|
|
|
select b.finacode,c.finaname,a.werks,b.orgname,a.business_date,a.clscode,d.clsname,sum(a.amount)
|
|
|
from t_int_flow_pay_deily_'+substring(@stmpdate,1,4)+substring(@stmpdate,6,2)+' a
|
|
|
left join t_shop b on a.werks=b.orgcode
|
|
|
left join t_financial_body c on b.finacode=c.finacode
|
|
|
left join t_gclass d on a.clscode=d.clscode
|
|
|
where a.business_date between '''+@sbgndate+''' and '''+@senddate+'''
|
|
|
and a.clscode not in (''1001'',''1002'') and left(werks,2)<>''2D''
|
|
|
and not exists(select * from ##tmppaydeily where orgcode=a.werks and accdate=a.business_date and clscode=a.clscode)
|
|
|
and exists(select * from t_user_org where orgcode=a.werks and usercode='''+@ps_SysUserCode+''')'
|
|
|
if @sorgcode<>''
|
|
|
set @ssql=@ssql+' and b.orgcode in ('''+@sorgcode+''')'
|
|
|
if @sclscode<>''
|
|
|
set @ssql=@ssql+' and a.clscode in ('''+@sclscode+''')'
|
|
|
if isnull(@pqryall,'')='0'
|
|
|
set @ssql=@ssql+' and exists(select * from t_shop where orgcode=a.werks and overdate>=a.business_date)'
|
|
|
set @ssql=@ssql+' group by b.finacode,c.finaname,a.werks,b.orgname,a.business_date,a.clscode,d.clsname'
|
|
|
exec(@ssql)
|
|
|
end
|
|
|
set @stmpdate=convert(varchar(10),dateadd(month,1,@stmpdate),120)
|
|
|
end
|
|
|
|
|
|
set @sadd=''
|
|
|
set @ssql=''
|
|
|
declare cur cursor for select tendcode from t_tend order by tendcode
|
|
|
open cur
|
|
|
fetch next from cur into @tendcode
|
|
|
while @@fetch_status=0
|
|
|
begin
|
|
|
set @sadd=@sadd+'alter table ##tmppaydeily add tend'+@tendcode+' numeric(19,4)'+char(10)
|
|
|
set @ssql=@ssql+'update a set tend'+@tendcode+'=b.amount from ##tmppaydeily a,##tmppaydeilysum b where a.orgcode=b.orgcode and a.accdate=b.accdate and a.clscode=b.clscode and b.tendcode='+@tendcode+char(10)
|
|
|
fetch next from cur into @tendcode
|
|
|
end
|
|
|
close cur
|
|
|
deallocate cur
|
|
|
exec(@sadd)
|
|
|
exec(@ssql)
|
|
|
|
|
|
select * from ##tmppaydeily order by finacode,orgcode,accdate,clscode
|
|
|
|
|
|
if exists(select name from tempdb..sysobjects where name='##tmppaydeilysum' and xtype='u')
|
|
|
drop table ##tmppaydeilysum
|
|
|
if exists(select name from tempdb..sysobjects where name='##tmppaydeily' and xtype='u')
|
|
|
drop table ##tmppaydeily
|
|
|
end
|
|
|
go
|
|
|
|
|
|
/*ÓÍÕ¾ÏúÊÛÈÕ±¨*/
|
|
|
if exists(select * from sysobjects where name='p_rpt_dayrpt' and xtype='p')
|
|
|
drop procedure p_rpt_dayrpt
|
|
|
go
|
|
|
|
|
|
create procedure p_rpt_dayrpt
|
|
|
(
|
|
|
@pfinacode varchar(1000),
|
|
|
@porgcode varchar(1000),
|
|
|
@pbgndate varchar(10),
|
|
|
@penddate varchar(10),
|
|
|
@pisdiff varchar(1),
|
|
|
@pqryall varchar(1),
|
|
|
@ps_SysUserCode varchar(20)
|
|
|
)
|
|
|
as
|
|
|
declare @ssql varchar(8000)
|
|
|
declare @stmpdate varchar(10)
|
|
|
declare @sfinacode varchar(1000)
|
|
|
declare @sorgcode varchar(1000)
|
|
|
declare @sbgndate varchar(10)
|
|
|
declare @senddate varchar(10)
|
|
|
begin
|
|
|
set @sfinacode=replace(@pfinacode,',',''',''')
|
|
|
set @sorgcode=replace(@porgcode,',',''',''')
|
|
|
set @sbgndate=@pbgndate
|
|
|
set @senddate=@penddate
|
|
|
if isnull(@sbgndate,'')=''
|
|
|
set @sbgndate='2023-08-01'
|
|
|
if isnull(@senddate,'')=''
|
|
|
set @senddate='2099-12-31'
|
|
|
|
|
|
if exists(select name from tempdb..sysobjects where name='##tmpdayrpt' and xtype='u')
|
|
|
drop table ##tmpdayrpt
|
|
|
create table ##tmpdayrpt (
|
|
|
accdate varchar(10),orgcode varchar(10),orgname varchar(30),finacode varchar(10),finaname varchar(40),
|
|
|
amount numeric(19,4),tendamount numeric(19,4))
|
|
|
|
|
|
set @stmpdate=@sbgndate
|
|
|
while substring(@stmpdate,1,7)<=substring(@senddate,1,7)
|
|
|
begin
|
|
|
if exists(select name from sysobjects where name='t_flow_total_'+substring(@stmpdate,1,4)+substring(@stmpdate,6,2) and xtype='u')
|
|
|
begin
|
|
|
set @ssql='update a set amount=amount+b.plutotal
|
|
|
from ##tmpdayrpt a,(select accdate,orgcode,sum(plutotal) as plutotal
|
|
|
from t_flow_item_'+substring(@stmpdate,1,4)+substring(@stmpdate,6,2)+'
|
|
|
where accdate between '''+@sbgndate+''' and '''+@senddate+'''
|
|
|
and clscode not in (''1001'',''1002'') and left(orgcode,2)<>''2D''
|
|
|
group by accdate,orgcode) b where a.accdate=b.accdate and a.orgcode=b.orgcode'
|
|
|
exec(@ssql)
|
|
|
|
|
|
set @ssql='insert into ##tmpdayrpt(accdate,orgcode,amount)
|
|
|
select accdate,orgcode,sum(plutotal)
|
|
|
from t_flow_item_'+substring(@stmpdate,1,4)+substring(@stmpdate,6,2)+' a
|
|
|
where accdate between '''+@sbgndate+''' and '''+@senddate+'''
|
|
|
and clscode not in (''1001'',''1002'') and left(orgcode,2)<>''2D''
|
|
|
and not exists(select * from ##tmpdayrpt where accdate=a.accdate and orgcode=a.orgcode)
|
|
|
and exists(select * from t_user_org where orgcode=a.orgcode and usercode='''+@ps_SysUserCode+''')'
|
|
|
if @sorgcode<>''
|
|
|
set @ssql=@ssql+' and a.orgcode in ('''+@sorgcode+''')'
|
|
|
if isnull(@pqryall,'')='0'
|
|
|
set @ssql=@ssql+' and exists(select * from t_shop where orgcode=a.orgcode and overdate>=a.accdate)'
|
|
|
set @ssql=@ssql+' group by accdate,orgcode'
|
|
|
exec(@ssql)
|
|
|
end
|
|
|
if exists(select name from sysobjects where name='t_int_flow_pay_deily_'+substring(@stmpdate,1,4)+substring(@stmpdate,6,2) and xtype='u')
|
|
|
begin
|
|
|
set @ssql='update a set tendamount=b.amount
|
|
|
from ##tmpdayrpt a,(select business_date,werks,sum(amount) as amount
|
|
|
from t_int_flow_pay_deily_'+substring(@stmpdate,1,4)+substring(@stmpdate,6,2)+' t
|
|
|
where business_date between '''+@sbgndate+''' and '''+@senddate+'''
|
|
|
and clscode not in (''1001'',''1002'') and left(werks,2)<>''2D''
|
|
|
group by business_date,werks) b where a.accdate=b.business_date and a.orgcode=b.werks'
|
|
|
exec(@ssql)
|
|
|
|
|
|
set @ssql='insert into ##tmpdayrpt(accdate,orgcode,amount,tendamount)
|
|
|
select business_date,werks,0,sum(amount)
|
|
|
from t_int_flow_pay_deily_'+substring(@stmpdate,1,4)+substring(@stmpdate,6,2)+' t
|
|
|
where business_date between '''+@sbgndate+''' and '''+@senddate+'''
|
|
|
and clscode not in (''1001'',''1002'') and left(werks,2)<>''2D''
|
|
|
and not exists(select * from ##tmpdayrpt where accdate=t.business_date and orgcode=t.werks)
|
|
|
and exists(select * from t_user_org where orgcode=t.werks and usercode='''+@ps_SysUserCode+''')'
|
|
|
if @sorgcode<>''
|
|
|
set @ssql=@ssql+' and werks in ('''+@sorgcode+''')'
|
|
|
if isnull(@pqryall,'')='0'
|
|
|
set @ssql=@ssql+' and exists(select * from t_shop where orgcode=t.werks and overdate>=t.business_date)'
|
|
|
set @ssql=@ssql+' group by business_date,werks'
|
|
|
exec(@ssql)
|
|
|
end
|
|
|
set @stmpdate=convert(varchar(10),dateadd(month,1,@stmpdate),120)
|
|
|
end
|
|
|
|
|
|
if @pqryall='1'
|
|
|
begin
|
|
|
set @ssql='update a set amount=amount+b.plutotal
|
|
|
from ##tmpdayrpt a,(select accdate,orgcode,sum(plutotal) as plutotal
|
|
|
from t_flow_item
|
|
|
where accdate between '''+@sbgndate+''' and '''+@senddate+'''
|
|
|
and clscode not in (''1001'',''1002'') and left(orgcode,2)<>''2D''
|
|
|
group by accdate,orgcode) b where a.accdate=b.accdate and a.orgcode=b.orgcode'
|
|
|
exec(@ssql)
|
|
|
|
|
|
set @ssql='insert into ##tmpdayrpt(accdate,orgcode,amount)
|
|
|
select accdate,orgcode,sum(plutotal)
|
|
|
from t_flow_item a
|
|
|
where accdate between '''+@sbgndate+''' and '''+@senddate+'''
|
|
|
and clscode not in (''1001'',''1002'') and left(orgcode,2)<>''2D''
|
|
|
and not exists(select * from ##tmpdayrpt where accdate=a.accdate and orgcode=a.orgcode)
|
|
|
and exists(select * from t_user_org where orgcode=a.orgcode and usercode='''+@ps_SysUserCode+''')'
|
|
|
if @sorgcode<>''
|
|
|
set @ssql=@ssql+' and a.orgcode in ('''+@sorgcode+''')'
|
|
|
set @ssql=@ssql+' group by accdate,orgcode'
|
|
|
exec(@ssql)
|
|
|
end
|
|
|
|
|
|
update a set finacode=b.finacode,orgname=b.orgname
|
|
|
from ##tmpdayrpt a,t_shop b where a.orgcode=b.orgcode
|
|
|
update a set finaname=b.finaname
|
|
|
from ##tmpdayrpt a,t_financial_body b where a.finacode=b.finacode
|
|
|
update ##tmpdayrpt set tendamount=isnull(tendamount,0)
|
|
|
|
|
|
set @ssql='select accdate,orgcode,orgname,amount,tendamount,amount-tendamount as diffamount,finacode,finaname
|
|
|
from ##tmpdayrpt where 0=0'
|
|
|
if @sfinacode<>''
|
|
|
set @ssql=@ssql+' and finacode in ('''+@sfinacode+''')'
|
|
|
if isnull(@pisdiff,'')='1'
|
|
|
set @ssql=@ssql+' and amount-tendamount<>0'
|
|
|
|
|
|
set @ssql=@ssql+' order by accdate,orgcode'
|
|
|
exec(@ssql)
|
|
|
|
|
|
if exists(select name from tempdb..sysobjects where name='##tmpdayrpt' and xtype='u')
|
|
|
drop table ##tmpdayrpt
|
|
|
end
|
|
|
go
|
|
|
|
|
|
/*È«ÍøÂçËùÓÐSKUÒƶ¯Ã÷ϸ*/
|
|
|
if exists(select * from sysobjects where name='p_rpt_plubook' and xtype='p')
|
|
|
drop procedure p_rpt_plubook
|
|
|
go
|
|
|
|
|
|
create procedure p_rpt_plubook
|
|
|
(
|
|
|
@porgcode varchar(1000),
|
|
|
@pbgndate varchar(10),
|
|
|
@penddate varchar(10),
|
|
|
@pplucode varchar(2000),
|
|
|
@pbilltype varchar(2),
|
|
|
@ps_SysUserCode varchar(20)
|
|
|
)
|
|
|
as
|
|
|
declare @ssql varchar(8000)
|
|
|
declare @stmpdate varchar(10)
|
|
|
declare @sorgcode varchar(1000)
|
|
|
declare @splucode varchar(1000)
|
|
|
declare @sbgndate varchar(10)
|
|
|
declare @senddate varchar(10)
|
|
|
begin
|
|
|
set @sorgcode=replace(@porgcode,',',''',''')
|
|
|
set @splucode=replace(@pplucode,',',''',''')
|
|
|
set @sbgndate=@pbgndate
|
|
|
set @senddate=@penddate
|
|
|
if isnull(@sbgndate,'')=''
|
|
|
set @sbgndate='2023-08-01'
|
|
|
if isnull(@senddate,'')=''
|
|
|
set @senddate='2099-12-31'
|
|
|
|
|
|
if exists(select name from tempdb..sysobjects where name='##tmpplubook' and xtype='u')
|
|
|
drop table ##tmpplubook
|
|
|
create table ##tmpplubook (
|
|
|
accdate varchar(10),orgcode varchar(10),plucode varchar(20),billno varchar(20),billtype varchar(1),unitcode varchar(10),
|
|
|
ywbilltype varchar(1),inbilltype varchar(2),r_billtype varchar(20),tblname varchar(6),serialno int,fscount numeric(19,4),fsnetcost numeric(19,4))
|
|
|
|
|
|
set @stmpdate=@sbgndate
|
|
|
while substring(@stmpdate,1,7)<=substring(@senddate,1,7)
|
|
|
begin
|
|
|
if exists(select name from sysobjects where name='t_gbk_'+substring(@stmpdate,1,4)+substring(@stmpdate,6,2) and xtype='u')
|
|
|
begin
|
|
|
set @ssql='insert into ##tmpplubook(accdate,plucode,orgcode,billno,billtype,ywbilltype,tblname,serialno,fscount,fsnetcost)
|
|
|
select distinct accdate,plucode,orgcode,billno,billtype,'''','''+substring(@stmpdate,1,4)+substring(@stmpdate,6,2)+''',serialno,
|
|
|
case when billtype in (''3'',''5'',''6'',''7'',''A'',''E'',''F'',''G'',''S'') then -fscount else fscount end,
|
|
|
case when billtype in (''3'',''5'',''6'',''7'',''A'',''E'',''F'',''G'',''S'') and serialno <> 21151 then -fsnetcost else fsnetcost end
|
|
|
from t_gbk_'+substring(@stmpdate,1,4)+substring(@stmpdate,6,2)+' a
|
|
|
where accdate between '''+@sbgndate+''' and '''+@senddate+''' and (billtype=''E'' and fscount<>0 or billtype<>''E'')
|
|
|
and billtype not in (''4'',''8'',''Z'')
|
|
|
and exists(select * from t_user_org where orgcode=a.orgcode and usercode='''+@ps_SysUserCode+''')'
|
|
|
if @sorgcode='C009'
|
|
|
set @ssql=@ssql+' and orgcode in (select orgcode from t_shop where finacode<>''2000'')'
|
|
|
else if @sorgcode<>''
|
|
|
set @ssql=@ssql+' and orgcode in ('''+@sorgcode+''')'
|
|
|
if @splucode<>''
|
|
|
set @ssql=@ssql+' and plucode in ('''+@splucode+''')'
|
|
|
exec(@ssql)
|
|
|
end
|
|
|
set @stmpdate=convert(varchar(10),dateadd(month,1,@stmpdate),120)
|
|
|
end
|
|
|
|
|
|
-----2023-11-07£¬ÊµÊ±Ì¨Õ˱íÖеÄACCDate Ϊ¿Õ£¬Õâ¸öдÊý¾ÝÒ²ÐèÒªÕ¹ÏÖ£¬¹Êµ÷Õû²éѯÌõ¼þΪ£º
|
|
|
set @ssql='insert into ##tmpplubook(accdate,plucode,orgcode,billno,billtype,ywbilltype,tblname,serialno,fscount,fsnetcost)
|
|
|
select distinct accdate,plucode,orgcode,billno,billtype,'''',''yyyymm'',serialno,
|
|
|
case when billtype in (''3'',''5'',''6'',''7'',''A'',''E'',''F'',''G'',''S'') then -fscount else fscount end,
|
|
|
case when billtype in (''3'',''5'',''6'',''7'',''A'',''E'',''F'',''G'',''S'') then -fsnetcost else fsnetcost end
|
|
|
from t_gbk_yyyymm a
|
|
|
where bookdate between '''+@sbgndate+''' and '''+@senddate+''' and (billtype=''E'' and fscount<>0 or billtype<>''E'')
|
|
|
and billtype not in (''4'',''8'',''Z'')
|
|
|
and exists(select * from t_user_org where orgcode=a.orgcode and usercode='''+@ps_SysUserCode+''')'
|
|
|
if @sorgcode='C009'
|
|
|
set @ssql=@ssql+' and orgcode in (select orgcode from t_shop where finacode<>''2000'')'
|
|
|
else if @sorgcode<>''
|
|
|
set @ssql=@ssql+' and orgcode in ('''+@sorgcode+''')'
|
|
|
if @splucode<>''
|
|
|
set @ssql=@ssql+' and plucode in ('''+@splucode+''')'
|
|
|
exec(@ssql)
|
|
|
|
|
|
set @ssql='update a set ywbilltype=case when c.finacode<>''2000'' and b.billtype = ''2'' then ''9'' when c.finacode<>''2000'' and b.billtype <> ''2'' then ''8'' else b.billtype end
|
|
|
from ##tmpplubook a,t_accept_head b,t_shop c
|
|
|
where a.billno=b.billno and b.orgcode=c.orgcode and a.billtype=''0'''
|
|
|
exec(@ssql)
|
|
|
|
|
|
set @ssql='update a set ywbilltype=case when c.finacode<>''2000'' and b.billtype = ''2'' then ''9'' when c.finacode<>''2000'' and b.billtype <> ''2'' then ''8'' else b.billtype end
|
|
|
from ##tmpplubook a,t_return_head b,t_shop c
|
|
|
where a.billno=b.billno and b.orgcode=c.orgcode and a.billtype=''5'''
|
|
|
exec(@ssql)
|
|
|
|
|
|
--¿ç²ÆÎñÖ÷ÌåµÄÖ±ËÍÑéÊÕ²»²úÉúÐéÄâÅäË͵¥Ì¨ÕË£¬¶¯Ì¬Éú³Ę́ÕË£¬ÌåÏÖÔÚÄÚ²¿ÏúÊÛ
|
|
|
set @ssql='insert into ##tmpplubook(accdate,plucode,orgcode,billno,billtype,ywbilltype,tblname,serialno,fscount,fsnetcost)
|
|
|
select a.accdate,a.plucode,b.orgcode,b.billno,''E'',a.ywbilltype,a.tblname,a.serialno,a.fscount,a.fsnetcost
|
|
|
from ##tmpplubook a,t_dist_head b
|
|
|
where a.billno=b.remark and a.billtype=''0'' and a.ywbilltype=''9'' and a.orgcode=b.shopcode
|
|
|
and not exists(select * from ##tmpplubook where accdate=a.accdate and plucode=a.plucode and orgcode=b.orgcode and billno=b.billno and billtype=''E'')'
|
|
|
exec(@ssql)
|
|
|
--¿ç²ÆÎñÖ÷ÌåµÄÖ±ËÍÍË»õ²»²úÉúÐéÄâÅäÍ˵¥Ì¨ÕË£¬¶¯Ì¬Éú³Ę́ÕË£¬ÌåÏÖÔÚÄÚ²¿ÏúÊÛ
|
|
|
set @ssql='insert into ##tmpplubook(accdate,plucode,orgcode,billno,billtype,ywbilltype,tblname,serialno,fscount,fsnetcost)
|
|
|
select a.accdate,a.plucode,b.orgcode,b.billno,''E'',a.ywbilltype,a.tblname,a.serialno,a.fscount,a.fsnetcost
|
|
|
from ##tmpplubook a,t_dist_head b
|
|
|
where a.billno=b.billno and a.billtype=''5'' and a.ywbilltype=''9'' and a.orgcode=b.shopcode
|
|
|
and not exists(select * from ##tmpplubook where accdate=a.accdate and plucode=a.plucode and orgcode=b.orgcode and billno=b.billno and billtype=''E'')'
|
|
|
exec(@ssql)
|
|
|
--¿ç²ÆÎñÖ÷ÌåµÄÅäË͵¥£¬ÌåÏÖÔÚÄÚ²¿ÏúÊÛ
|
|
|
set @ssql='update a set ywbilltype=''9''
|
|
|
from ##tmpplubook a,t_dist_head b,t_shop c
|
|
|
where a.billno=b.billno and b.shopcode=c.orgcode and a.billtype=''E'' and c.finacode<>''2000'''
|
|
|
exec(@ssql)
|
|
|
|
|
|
/* *
|
|
|
* ²É¹ºÑéÊÕ£ºÖÐÑë²Ö²É¹º£¨C001£©¡¢ÓÍÕ¾Ö±²É¡¢×Ó¹«Ë¾ÓÍÕ¾ÏòÖÐÑë²Ö²É¹º£¨ÅäËÍÑéÊÕ ywbilltype='8'£©¡¢×Ó¹«Ë¾ÓÍÕ¾Ö±²É£¨ywbilltype='9'£©¡¢ÖÐÑë²ÖÏò¹©Ó¦É̵ÄÐéÄâ²É¹º£¨ywbilltype='9'£©
|
|
|
* ²É¹ºÍË»õ£ºÖÐÑë²Ö²É¹ºÍË»õ£¨C002)¡¢ÓÍÕ¾Ö±²ÉÍË»õ¡¢×Ó¹«Ë¾ÓÍÕ¾ÏòÖÐÑë²ÖÍË»õ£¨ÅäËÍÍË»õ ywbilltype='8'£©¡¢×Ó¹«Ë¾ÓÍÕ¾Ö±ÍË£¨ywbilltype='9'£©¡¢ÖÐÑë²ÖÏò¹©Ó¦É̵ÄÐéÄâÍË»õ£¨ywbilltype='9'£©
|
|
|
* ÅäËÍÈë¿â£ºÖÐÑë²ÖÊÕµ½ÓÍÕ¾ÍËÅä(C002)¡¢ÓÍÕ¾ÊÕµ½ÖÐÑë²ÖÅäËÍ£¨¼¯ÍÅÄÚÏúÊÛÉú³ÉµÄÅäË͵¥²»ÔÚ´Ë´¦£©
|
|
|
* ÅäËͳö¿â£ºÖÐÑë²ÖÏòÓÍÕ¾ÅäËÍ(C001/C002)¡¢ÓÍÕ¾ÏòÖÐÑë²ÖÍËÅ䣨¼¯ÍÅÄÚÏúÊÛÉú³ÉµÄÅäË͵¥²»ÔÚ´Ë´¦£©
|
|
|
* µ÷²¦£ºµ÷ÈëÕ¾£¨ÕýÊý£©¡¢µ÷³öÕ¾£¨¸ºÊý£©
|
|
|
* ÏúÊÛ£ºÓÍÕ¾ÏúÊÛ£¨ÏúÊÛ-¸ºÊý/ÏúÊÛÍË»õ-ÕýÊý£©¡¢ÏúÊÛ²¹Â¼£¨ÕýÏòÊý¾Ý-¸ºÊý/·´ÏòÊý¾Ý-ÕýÊý£©¡¢ÖÐÑë²ÖÅú·¢ÏúÊÛ£¨¸ºÊý£©¡¢ÖÐÑë²ÖÅú·¢ÏúÊÛÍË»õ£¨ÕýÊý£©
|
|
|
* ÄÚ²¿ÏúÊÛ£º¿ç²ÆÎñÖ÷ÌåµÄÅäË͵¥£¨ywbilltype='9'£©
|
|
|
* Å̵㣺ÁÙʱÅ̵㡢Ô¶ÈÅ̵㣨ÅÌÓ¯-ÕýÊý/ÅÌ¿÷-¸ºÊý£©
|
|
|
* ±¨Ë𣺱¨Ë𣨸ºÊý£©
|
|
|
* ÁìÓãºÁìÓ㨸ºÊý£©
|
|
|
* ¼Ó¹¤ÓÃÁÏ£ºÔÁϳɱ¾£¨¸ºÊý£©
|
|
|
* ¼Ó¹¤²ú³ö£º²ú³ÉÆ·³É±¾£¨ÕýÊý£©
|
|
|
* Òƿ⣺ÖÐÑë²ÖÈë¿â·½£¨ÕýÊý£©¡¢ÖÐÑë²Ö³ö¿â·½£¨¸ºÊý£©
|
|
|
* */
|
|
|
set @ssql='update ##tmpplubook set
|
|
|
inbilltype=case when billtype=''0'' and ywbilltype in (''0'',''1'',''2'') then ''01''
|
|
|
when billtype=''0'' and ywbilltype =''8'' then ''01''
|
|
|
when billtype=''0'' and ywbilltype=''9'' then ''15''
|
|
|
when billtype=''5'' and ywbilltype in (''0'',''2'') then ''02''
|
|
|
when billtype=''5'' and ywbilltype =''8'' then ''02''
|
|
|
when billtype=''5'' and ywbilltype=''9'' then ''16''
|
|
|
when billtype=''E'' and fscount>0 and ywbilltype<>''9'' or billtype=''0'' and ywbilltype=''3'' then ''03''
|
|
|
when billtype=''E'' and fscount<0 and ywbilltype<>''9'' or billtype=''5'' and ywbilltype=''3'' then ''04''
|
|
|
when billtype=''F'' then ''05'' when billtype in (''6'',''A'',''B'') then ''06''
|
|
|
when billtype=''E'' and ywbilltype=''9'' then ''07'' when billtype=''2'' then ''08''
|
|
|
when billtype=''S'' then ''09'' when billtype=''7'' then ''10''
|
|
|
when billtype=''C'' then ''11'' when billtype=''D'' then ''12''
|
|
|
when billtype=''G'' then ''13'' when billtype=''4'' then ''14''
|
|
|
else ''99'' end,
|
|
|
r_billtype=case when billtype=''0'' and ywbilltype in (''0'',''1'',''2'',''8'') then ''²É¹ºÑéÊÕ''
|
|
|
when billtype=''0'' and ywbilltype=''9'' then ''Ö±ËͲɹºÑéÊÕ''
|
|
|
when billtype=''5'' and ywbilltype in (''0'',''2'',''8'') then ''²É¹ºÍË»õ''
|
|
|
when billtype=''5'' and ywbilltype=''9'' then ''Ö±ËͲɹºÍË»õ''
|
|
|
when billtype=''E'' and fscount>0 and ywbilltype<>''9'' or billtype=''0'' and ywbilltype=''3'' then ''ÅäËÍÈë¿â''
|
|
|
when billtype=''E'' and fscount<0 and ywbilltype<>''9'' or billtype=''5'' and ywbilltype=''3'' then ''ÅäËͳö¿â''
|
|
|
when billtype=''F'' then ''µ÷²¦'' when billtype in (''6'',''A'',''B'') then ''ÏúÊÛ''
|
|
|
when billtype=''E'' and ywbilltype=''9'' then ''ÄÚ²¿ÏúÊÛ'' when billtype=''2'' then ''Å̵ã''
|
|
|
when billtype=''S'' then ''±¨Ëð'' when billtype=''7'' then ''ÁìÓÃ''
|
|
|
when billtype=''C'' then ''¼Ó¹¤ÓÃÁÏ'' when billtype=''D'' then ''¼Ó¹¤²ú³ö''
|
|
|
when billtype=''G'' then ''ÒÆ¿â'' when billtype=''4'' then ''µ÷ÏÖ´æ''
|
|
|
else ''ÆäËû'' end'
|
|
|
exec(@ssql)
|
|
|
|
|
|
set @ssql='update a set unitcode=(select top 1 unitcode from t_unit where unitname=b.unit)
|
|
|
from ##tmpplubook a,t_plu b
|
|
|
where a.plucode=b.plucode'
|
|
|
exec(@ssql)
|
|
|
|
|
|
set @ssql='select a.plucode,b.pluname,a.orgcode,c.orgname,e.clscode,a.inbilltype,a.r_billtype,a.billno,a.accdate,a.fscount,a.unitcode,a.fsnetcost
|
|
|
from ##tmpplubook a
|
|
|
left join t_plu b on a.plucode=b.plucode
|
|
|
left join t_shop c on a.orgcode=c.orgcode
|
|
|
left join t_gclass d on b.clscode=d.clscode
|
|
|
left join t_gclass e on d.uppercode1=e.clscode
|
|
|
where 1=1'
|
|
|
if @sorgcode<>''
|
|
|
set @ssql=@ssql+' and a.orgcode in ('''+@sorgcode+''')'
|
|
|
if @pbilltype<>''
|
|
|
set @ssql=@ssql+' and a.inbilltype='''+@pbilltype+''''
|
|
|
set @ssql=@ssql+' order by a.tblname,a.serialno,a.plucode,a.orgcode'
|
|
|
exec(@ssql)
|
|
|
|
|
|
if exists(select name from tempdb..sysobjects where name='##tmpplubook' and xtype='u')
|
|
|
drop table ##tmpplubook
|
|
|
end
|
|
|
go
|
|
|
|
|
|
/*È«ÍøÂçËùÓÐSKUµÄÆÚÄ©¿â´æ*/
|
|
|
if exists(select * from sysobjects where name='p_rpt_plustock' and xtype='p')
|
|
|
drop procedure p_rpt_plustock
|
|
|
go
|
|
|
|
|
|
create procedure p_rpt_plustock
|
|
|
(
|
|
|
@porgcode varchar(1000),
|
|
|
@pbgndate varchar(10),
|
|
|
@penddate varchar(10),
|
|
|
@pplucode varchar(2000),
|
|
|
@ps_SysUserCode varchar(20)
|
|
|
)
|
|
|
as
|
|
|
declare @ssql varchar(8000)
|
|
|
declare @stmpdate varchar(10)
|
|
|
declare @sorgcode varchar(1000)
|
|
|
declare @splucode varchar(1000)
|
|
|
declare @sbgndate varchar(10)
|
|
|
declare @senddate varchar(10)
|
|
|
begin
|
|
|
set @sorgcode=replace(@porgcode,',',''',''')
|
|
|
set @splucode=replace(@pplucode,',',''',''')
|
|
|
set @sbgndate=@pbgndate
|
|
|
set @senddate=@penddate
|
|
|
if isnull(@sbgndate,'')=''
|
|
|
set @sbgndate='2023-08-01'
|
|
|
if isnull(@senddate,'')=''
|
|
|
set @senddate='2099-12-31'
|
|
|
|
|
|
if exists(select name from tempdb..sysobjects where name='##tmpplustock' and xtype='u')
|
|
|
drop table ##tmpplustock
|
|
|
create table ##tmpplustock (
|
|
|
plucode varchar(20),orgcode varchar(10),qccount numeric(19,4),incount numeric(19,4),outcount numeric(19,4),jccount numeric(19,4),
|
|
|
qcnetcost numeric(19,4),innetcost numeric(19,4),outnetcost numeric(19,4),jcnetcost numeric(19,4))
|
|
|
|
|
|
set @ssql='insert into ##tmpplustock(plucode,orgcode,qccount,incount,outcount,jccount,qcnetcost,innetcost,outnetcost,jcnetcost)
|
|
|
select plucode,orgcode,0,0,0,0,0,0,0,0 from t_plu_org t
|
|
|
where mngstock=''1'' and exists(select * from t_shop where orgcode=t.orgcode and status=''1'')
|
|
|
and exists(select * from t_user_org where orgcode=t.orgcode and usercode='''+@ps_SysUserCode+''')'
|
|
|
if @sorgcode<>''
|
|
|
set @ssql=@ssql+' and orgcode in ('''+@sorgcode+''')'
|
|
|
if @splucode<>''
|
|
|
set @ssql=@ssql+' and plucode in ('''+@splucode+''')'
|
|
|
exec(@ssql)
|
|
|
|
|
|
if exists(select name from sysobjects where name='t_gbk_'+substring(@sbgndate,1,4)+substring(@sbgndate,6,2) and xtype='u')
|
|
|
begin
|
|
|
set @ssql='update a set qccount=b.jccount,qcnetcost=b.jcnetcost
|
|
|
from ##tmpplustock a,t_gbk_'+substring(@sbgndate,1,4)+substring(@sbgndate,6,2)+' b
|
|
|
where a.plucode=b.plucode and a.orgcode=b.orgcode and b.billtype=''Z''
|
|
|
and exists(select * from t_user_org where orgcode=a.orgcode and usercode='''+@ps_SysUserCode+''')'
|
|
|
exec(@ssql)
|
|
|
end
|
|
|
|
|
|
if exists(select name from sysobjects where name='t_gbk_'+substring(@senddate,1,4)+substring(@senddate,6,2) and xtype='u')
|
|
|
begin
|
|
|
set @ssql='update a set jccount=b.jccount,jcnetcost=b.jcnetcost
|
|
|
from ##tmpplustock a,t_gbk_'+substring(@senddate,1,4)+substring(@senddate,6,2)+' b
|
|
|
where a.plucode=b.plucode and a.orgcode=b.orgcode and b.billtype=''Z''
|
|
|
and exists(select * from t_user_org where orgcode=a.orgcode and usercode='''+@ps_SysUserCode+''')'
|
|
|
exec(@ssql)
|
|
|
end
|
|
|
|
|
|
set @stmpdate=@sbgndate
|
|
|
while substring(@stmpdate,1,7)<=substring(@senddate,1,7)
|
|
|
begin
|
|
|
if exists(select name from sysobjects where name='t_gbk_'+substring(@stmpdate,1,4)+substring(@stmpdate,6,2) and xtype='u')
|
|
|
begin
|
|
|
if substring(@stmpdate,1,7)=substring(@sbgndate,1,7)
|
|
|
begin
|
|
|
set @ssql='update a set qccount=a.qccount+b.fscount,qcnetcost=a.qcnetcost+b.fsnetcost
|
|
|
from ##tmpplustock a,(select plucode,orgcode,
|
|
|
sum(case when billtype in (''3'',''5'',''6'',''7'',''A'',''E'',''F'',''G'',''S'') then -fscount else fscount end) as fscount,
|
|
|
sum(case when billtype in (''3'',''5'',''6'',''7'',''A'',''E'',''F'',''G'',''S'') then -fsnetcost else fsnetcost end) as fsnetcost
|
|
|
from t_gbk_'+substring(@stmpdate,1,4)+substring(@stmpdate,6,2)+' t
|
|
|
where accdate<'''+@sbgndate+''' and billtype not in (''4'',''8'',''Z'')
|
|
|
and exists(select * from t_user_org where orgcode=t.orgcode and usercode='''+@ps_SysUserCode+''')'
|
|
|
if @sorgcode<>''
|
|
|
set @ssql=@ssql+' and orgcode in ('''+@sorgcode+''')'
|
|
|
if @splucode<>''
|
|
|
set @ssql=@ssql+' and plucode in ('''+@splucode+''')'
|
|
|
set @ssql=@ssql+' group by plucode,orgcode) b where a.plucode=b.plucode and a.orgcode=b.orgcode'
|
|
|
exec(@ssql)
|
|
|
end
|
|
|
|
|
|
if substring(@stmpdate,1,7)=substring(@senddate,1,7)
|
|
|
begin
|
|
|
set @ssql='update a set jccount=a.jccount+b.fscount,jcnetcost=a.jcnetcost+b.fsnetcost
|
|
|
from ##tmpplustock a,(select plucode,orgcode,
|
|
|
sum(case when billtype in (''3'',''5'',''6'',''7'',''A'',''E'',''F'',''G'',''S'') then -fscount else fscount end) as fscount,
|
|
|
sum(case when billtype in (''3'',''5'',''6'',''7'',''A'',''E'',''F'',''G'',''S'') then -fsnetcost else fsnetcost end) as fsnetcost
|
|
|
from t_gbk_'+substring(@stmpdate,1,4)+substring(@stmpdate,6,2)+' t
|
|
|
where accdate<='''+@senddate+''' and billtype not in (''4'',''8'',''Z'')
|
|
|
and exists(select * from t_user_org where orgcode=t.orgcode and usercode='''+@ps_SysUserCode+''')'
|
|
|
if @sorgcode<>''
|
|
|
set @ssql=@ssql+' and orgcode in ('''+@sorgcode+''')'
|
|
|
if @splucode<>''
|
|
|
set @ssql=@ssql+' and plucode in ('''+@splucode+''')'
|
|
|
set @ssql=@ssql+' group by plucode,orgcode) b where a.plucode=b.plucode and a.orgcode=b.orgcode'
|
|
|
exec(@ssql)
|
|
|
end
|
|
|
|
|
|
set @ssql='update a set incount=a.incount+b.incount,outcount=a.outcount+b.outcount,
|
|
|
innetcost=a.innetcost+b.innetcost,outnetcost=a.outnetcost+b.outnetcost
|
|
|
from ##tmpplustock a,(select plucode,orgcode,
|
|
|
sum(case when billtype in (''0'',''B'',''D'') then fscount when billtype=''2'' and fscount>0 then fscount when billtype in (''E'',''F'',''G'') and fscount<0 then -fscount else 0 end) as incount,
|
|
|
sum(case when billtype in (''3'',''5'',''6'',''7'',''A'',''S'') then -fscount when billtype=''2'' and fscount<0 then fscount when billtype=''C'' then fscount when billtype in (''E'',''F'',''G'') and fscount>0 then -fscount else 0 end) as outcount,
|
|
|
sum(case when billtype in (''0'',''B'',''D'') then fsnetcost when billtype=''2'' and fsnetcost>0 then fsnetcost when billtype in (''E'',''F'',''G'') and fsnetcost<0 then -fsnetcost else 0 end) as innetcost,
|
|
|
sum(case when billtype in (''3'',''5'',''6'',''7'',''A'',''S'') then -fsnetcost when billtype=''2'' and fsnetcost<0 then fsnetcost when billtype=''C'' then fsnetcost when billtype in (''E'',''F'',''G'') and fsnetcost>0 then -fsnetcost else 0 end) as outnetcost
|
|
|
from t_gbk_'+substring(@stmpdate,1,4)+substring(@stmpdate,6,2)+' t
|
|
|
where accdate between '''+@sbgndate+''' and '''+@senddate+''' and billtype not in (''4'',''8'',''Z'')
|
|
|
and exists(select * from t_user_org where orgcode=t.orgcode and usercode='''+@ps_SysUserCode+''')'
|
|
|
if @sorgcode<>''
|
|
|
set @ssql=@ssql+' and orgcode in ('''+@sorgcode+''')'
|
|
|
if @splucode<>''
|
|
|
set @ssql=@ssql+' and plucode in ('''+@splucode+''')'
|
|
|
set @ssql=@ssql+' group by plucode,orgcode) b where a.plucode=b.plucode and a.orgcode=b.orgcode'
|
|
|
exec(@ssql)
|
|
|
end
|
|
|
set @stmpdate=convert(varchar(10),dateadd(month,1,@stmpdate),120)
|
|
|
end
|
|
|
|
|
|
set @ssql='select distinct a.orgcode,a.plucode,'''+@pbgndate+''' as bgndate,'''+@penddate+''' as enddate,
|
|
|
a.qccount,a.incount,a.outcount,a.jccount,
|
|
|
(select top 1 unitcode from t_unit where unitname=b.unit order by unitcode) as unitcode,
|
|
|
a.qcnetcost,a.innetcost,a.outnetcost,a.jcnetcost,''CNY'' as currunit
|
|
|
from ##tmpplustock a
|
|
|
left join t_plu b on a.plucode=b.plucode
|
|
|
where 0=0 order by orgcode,plucode'
|
|
|
exec(@ssql)
|
|
|
|
|
|
if exists(select name from tempdb..sysobjects where name='##tmpplustock' and xtype='u')
|
|
|
drop table ##tmpplustock
|
|
|
end
|
|
|
go
|
|
|
|
|
|
/*ÉÌÆ·½øÏú´æ±¨±í*/
|
|
|
if exists(select * from sysobjects where name='p_rpt_plujxc' and xtype='p')
|
|
|
drop procedure p_rpt_plujxc
|
|
|
go
|
|
|
|
|
|
create procedure p_rpt_plujxc
|
|
|
(
|
|
|
@pfinacode varchar(1000),
|
|
|
@pregncode varchar(1000),
|
|
|
@pareacode varchar(1000),
|
|
|
@porgcode varchar(1000),
|
|
|
@pbgndate varchar(10),
|
|
|
@penddate varchar(10),
|
|
|
@pclscode varchar(1000),
|
|
|
@pplucode varchar(2000),
|
|
|
@ps_SysUserCode varchar(20)
|
|
|
)
|
|
|
as
|
|
|
declare @ssql varchar(8000)
|
|
|
declare @stmpdate varchar(10)
|
|
|
declare @sfinacode varchar(1000)
|
|
|
declare @sregncode varchar(1000)
|
|
|
declare @sareacode varchar(1000)
|
|
|
declare @sorgcode varchar(1000)
|
|
|
declare @sclscode varchar(1000)
|
|
|
declare @splucode varchar(1000)
|
|
|
declare @sfilt varchar(8000)
|
|
|
declare @sbgndate varchar(10)
|
|
|
declare @senddate varchar(10)
|
|
|
begin
|
|
|
-- if isnull(@porgcode,'')=''
|
|
|
-- begin
|
|
|
-- raiserror('±ØÐëÑ¡ÔñÓÍÕ¾',16,1)
|
|
|
-- return(1)
|
|
|
-- end
|
|
|
set @sfinacode=replace(@pfinacode,',',''',''')
|
|
|
set @sregncode=replace(@sregncode,',',''',''')
|
|
|
set @sareacode=replace(@sareacode,',',''',''')
|
|
|
set @sorgcode=replace(@porgcode,',',''',''')
|
|
|
set @sclscode=replace(@pclscode,',',''',''')
|
|
|
set @splucode=replace(@pplucode,',',''',''')
|
|
|
set @sbgndate=@pbgndate
|
|
|
set @senddate=@penddate
|
|
|
if isnull(@sbgndate,'')=''
|
|
|
set @sbgndate='2023-08-01'
|
|
|
if isnull(@senddate,'')=''
|
|
|
set @senddate='2099-12-31'
|
|
|
|
|
|
set @sfilt=' and exists(select * from t_user_org where orgcode=t.orgcode and usercode='''+@ps_SysUserCode+''')'
|
|
|
if @sfinacode<>''
|
|
|
set @sfilt=@sfilt+' and exists(select * from t_shop where orgcode=t.orgcode and finacode in ('''+@sfinacode+'''))'
|
|
|
if @sregncode<>''
|
|
|
set @sfilt=@sfilt+' and exists(select * from t_shop m,t_area n where m.areacode=n.areacode and m.orgcode=t.orgcode and n.uppercode1 in ('''+@sregncode+'''))'
|
|
|
if @sareacode<>''
|
|
|
set @sfilt=@sfilt+' and exists(select * from t_shop where orgcode=t.orgcode and areacode in ('''+@sareacode+'''))'
|
|
|
if @sorgcode<>''
|
|
|
set @sfilt=@sfilt+' and orgcode in ('''+@sorgcode+''')'
|
|
|
if @sclscode<>''
|
|
|
set @sfilt=@sfilt+' and exists(select * from t_plu m,t_gclass n where m.clscode=n.clscode and m.plucode=t.plucode and n.uppercode1 in ('''+@sclscode+'''))'
|
|
|
if @splucode<>''
|
|
|
set @sfilt=@sfilt+' and plucode in ('''+@splucode+''')'
|
|
|
|
|
|
if exists(select name from tempdb..sysobjects where name='##tmpplujxc' and xtype='u')
|
|
|
drop table ##tmpplujxc
|
|
|
create table ##tmpplujxc (
|
|
|
plucode varchar(20),orgcode varchar(10),qccount numeric(19,4),qcnetcost numeric(19,4),
|
|
|
jhcount numeric(19,4),jhnetcost numeric(19,4),thcount numeric(19,4),thnetcost numeric(19,4),
|
|
|
xscount numeric(19,4),xsnetcost numeric(19,4),drcount numeric(19,4),drnetcost numeric(19,4),
|
|
|
dccount numeric(19,4),dcnetcost numeric(19,4),pjhcount numeric(19,4),pjhnetcost numeric(19,4),
|
|
|
pscount numeric(19,4),psnetcost numeric(19,4),tccount numeric(19,4),tcnetcost numeric(19,4),
|
|
|
pthcount numeric(19,4),pthnetcost numeric(19,4),pycount numeric(19,4),pynetcost numeric(19,4),
|
|
|
pkcount numeric(19,4),pknetcost numeric(19,4),bscount numeric(19,4),bsnetcost numeric(19,4),
|
|
|
lycount numeric(19,4),lynetcost numeric(19,4),jgcount numeric(19,4),jgnetcost numeric(19,4),
|
|
|
cjgcount numeric(19,4),cjgnetcost numeric(19,4),hccount numeric(19,4),hcnetcost numeric(19,4),
|
|
|
zpscount numeric(19,4),zpsnetcost numeric(19,4),zthcount numeric(19,4),zthnetcost numeric(19,4),
|
|
|
jccount numeric(19,4),jcnetcost numeric(19,4))
|
|
|
|
|
|
set @ssql='insert into ##tmpplujxc(plucode,orgcode,qccount,qcnetcost,jhcount,jhnetcost,thcount,thnetcost,
|
|
|
xscount,xsnetcost,drcount,drnetcost,dccount,dcnetcost,pjhcount,pjhnetcost,pscount,psnetcost,
|
|
|
tccount,tcnetcost,pthcount,pthnetcost,pycount,pynetcost,pkcount,pknetcost,bscount,bsnetcost,
|
|
|
lycount,lynetcost,jgcount,jgnetcost,cjgcount,cjgnetcost,hccount,hcnetcost,zpscount,zpsnetcost,
|
|
|
zthcount,zthnetcost,jccount,jcnetcost)
|
|
|
select plucode,orgcode,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
|
|
|
from t_plu_org t where mngstock=''1'' and exists(select * from t_shop where orgcode=t.orgcode and status=''1'')'
|
|
|
set @ssql=@ssql+@sfilt
|
|
|
exec(@ssql)
|
|
|
|
|
|
if exists(select name from sysobjects where name='t_gbk_'+substring(@sbgndate,1,4)+substring(@sbgndate,6,2) and xtype='u')
|
|
|
begin
|
|
|
set @ssql='update a set qccount=b.jccount,qcnetcost=b.jcnetcost
|
|
|
from ##tmpplujxc a,t_gbk_'+substring(@sbgndate,1,4)+substring(@sbgndate,6,2)+' b
|
|
|
where a.plucode=b.plucode and a.orgcode=b.orgcode and b.billtype=''Z''
|
|
|
and exists(select * from t_user_org where orgcode=a.orgcode and usercode='''+@ps_SysUserCode+''')'
|
|
|
exec(@ssql)
|
|
|
end
|
|
|
|
|
|
if exists(select name from sysobjects where name='t_gbk_'+substring(@senddate,1,4)+substring(@senddate,6,2) and xtype='u')
|
|
|
begin
|
|
|
set @ssql='update a set jccount=b.jccount,jcnetcost=b.jcnetcost
|
|
|
from ##tmpplujxc a,t_gbk_'+substring(@senddate,1,4)+substring(@senddate,6,2)+' b
|
|
|
where a.plucode=b.plucode and a.orgcode=b.orgcode and b.billtype=''Z''
|
|
|
and exists(select * from t_user_org where orgcode=a.orgcode and usercode='''+@ps_SysUserCode+''')'
|
|
|
exec(@ssql)
|
|
|
end
|
|
|
|
|
|
set @stmpdate=@sbgndate
|
|
|
while substring(@stmpdate,1,7)<=substring(@senddate,1,7)
|
|
|
begin
|
|
|
if exists(select name from sysobjects where name='t_gbk_'+substring(@stmpdate,1,4)+substring(@stmpdate,6,2) and xtype='u')
|
|
|
begin
|
|
|
if substring(@stmpdate,1,7)=substring(@sbgndate,1,7)
|
|
|
begin
|
|
|
set @ssql='update a set qccount=a.qccount+b.fscount,qcnetcost=a.qcnetcost+b.fsnetcost
|
|
|
from ##tmpplujxc a,(select plucode,orgcode,
|
|
|
sum(case when billtype in (''3'',''5'',''6'',''7'',''A'',''E'',''F'',''G'',''S'') then -fscount else fscount end) as fscount,
|
|
|
sum(case when billtype in (''3'',''5'',''6'',''7'',''A'',''E'',''F'',''G'',''S'') then -fsnetcost else fsnetcost end) as fsnetcost
|
|
|
from t_gbk_'+substring(@stmpdate,1,4)+substring(@stmpdate,6,2)+' t
|
|
|
where accdate<'''+@sbgndate+''' and billtype not in (''4'',''8'',''Z'')'
|
|
|
set @ssql=@ssql+@sfilt
|
|
|
set @ssql=@ssql+' group by plucode,orgcode) b where a.plucode=b.plucode and a.orgcode=b.orgcode'
|
|
|
exec(@ssql)
|
|
|
end
|
|
|
|
|
|
if substring(@stmpdate,1,7)=substring(@senddate,1,7)
|
|
|
begin
|
|
|
set @ssql='update a set jccount=a.jccount+b.fscount,jcnetcost=a.jcnetcost+b.fsnetcost
|
|
|
from ##tmpplujxc a,(select plucode,orgcode,
|
|
|
sum(case when billtype in (''3'',''5'',''6'',''7'',''A'',''E'',''F'',''G'',''S'') then -fscount else fscount end) as fscount,
|
|
|
sum(case when billtype in (''3'',''5'',''6'',''7'',''A'',''E'',''F'',''G'',''S'') then -fsnetcost else fsnetcost end) as fsnetcost
|
|
|
from t_gbk_'+substring(@stmpdate,1,4)+substring(@stmpdate,6,2)+' t
|
|
|
where accdate<='''+@senddate+''' and billtype not in (''4'',''8'',''Z'')'
|
|
|
set @ssql=@ssql+@sfilt
|
|
|
set @ssql=@ssql+' group by plucode,orgcode) b where a.plucode=b.plucode and a.orgcode=b.orgcode'
|
|
|
exec(@ssql)
|
|
|
end
|
|
|
|
|
|
set @ssql='update a set jhcount=a.jhcount+b.fscount,jhnetcost=a.jhnetcost+b.fsnetcost
|
|
|
from ##tmpplujxc a,(select plucode,orgcode,sum(fscount) as fscount,sum(fsnetcost) as fsnetcost
|
|
|
from t_gbk_'+substring(@stmpdate,1,4)+substring(@stmpdate,6,2)+' t
|
|
|
where accdate between '''+@sbgndate+''' and '''+@senddate+''' and billtype=''0''
|
|
|
and exists(select * from t_accept_head where billno=t.billno and billtype in (''0'',''1'',''2''))'
|
|
|
set @ssql=@ssql+@sfilt
|
|
|
set @ssql=@ssql+' group by plucode,orgcode) b where a.plucode=b.plucode and a.orgcode=b.orgcode'
|
|
|
exec(@ssql)
|
|
|
|
|
|
set @ssql='update a set thcount=a.thcount+b.fscount,thnetcost=a.thnetcost+b.fsnetcost
|
|
|
from ##tmpplujxc a,(select plucode,orgcode,sum(fscount) as fscount,sum(fsnetcost) as fsnetcost
|
|
|
from t_gbk_'+substring(@stmpdate,1,4)+substring(@stmpdate,6,2)+' t
|
|
|
where accdate between '''+@sbgndate+''' and '''+@senddate+''' and billtype=''5''
|
|
|
and exists(select * from t_return_head where billno=t.billno and billtype in (''0'',''2''))'
|
|
|
set @ssql=@ssql+@sfilt
|
|
|
set @ssql=@ssql+' group by plucode,orgcode) b where a.plucode=b.plucode and a.orgcode=b.orgcode'
|
|
|
exec(@ssql)
|
|
|
|
|
|
set @ssql='update a set xscount=a.xscount+b.fscount,xsnetcost=a.xsnetcost+b.fsnetcost
|
|
|
from ##tmpplujxc a,(select plucode,orgcode,
|
|
|
sum(case when billtype=''B'' then -fscount else fscount end) as fscount,
|
|
|
sum(case when billtype=''B'' then -fsnetcost else fsnetcost end) as fsnetcost
|
|
|
from t_gbk_'+substring(@stmpdate,1,4)+substring(@stmpdate,6,2)+' t
|
|
|
where accdate between '''+@sbgndate+''' and '''+@senddate+''' and billtype in (''6'',''A'',''B'')'
|
|
|
set @ssql=@ssql+@sfilt
|
|
|
set @ssql=@ssql+' group by plucode,orgcode) b where a.plucode=b.plucode and a.orgcode=b.orgcode'
|
|
|
exec(@ssql)
|
|
|
|
|
|
set @ssql='update a set drcount=a.drcount+b.fscount,drnetcost=a.drnetcost+b.fsnetcost
|
|
|
from ##tmpplujxc a,(select plucode,orgcode,-sum(fscount) as fscount,-sum(fsnetcost) as fsnetcost
|
|
|
from t_gbk_'+substring(@stmpdate,1,4)+substring(@stmpdate,6,2)+' t
|
|
|
where accdate between '''+@sbgndate+''' and '''+@senddate+''' and billtype=''F'' and fscount<0'
|
|
|
set @ssql=@ssql+@sfilt
|
|
|
set @ssql=@ssql+' group by plucode,orgcode) b where a.plucode=b.plucode and a.orgcode=b.orgcode'
|
|
|
exec(@ssql)
|
|
|
|
|
|
set @ssql='update a set drcount=a.drcount+b.fscount,drnetcost=a.drnetcost+b.fsnetcost
|
|
|
from ##tmpplujxc a,(select plucode,orgcode,sum(fscount) as fscount,sum(fsnetcost) as fsnetcost
|
|
|
from t_gbk_'+substring(@stmpdate,1,4)+substring(@stmpdate,6,2)+' t
|
|
|
where accdate between '''+@sbgndate+''' and '''+@senddate+''' and billtype=''F'' and fscount>0'
|
|
|
set @ssql=@ssql+@sfilt
|
|
|
set @ssql=@ssql+' group by plucode,orgcode) b where a.plucode=b.plucode and a.orgcode=b.orgcode'
|
|
|
exec(@ssql)
|
|
|
|
|
|
set @ssql='update a set pjhcount=a.pjhcount+b.fscount,pjhnetcost=a.pjhnetcost+b.fsnetcost
|
|
|
from ##tmpplujxc a,(select plucode,orgcode,sum(fscount) as fscount,sum(fsnetcost) as fsnetcost
|
|
|
from t_gbk_'+substring(@stmpdate,1,4)+substring(@stmpdate,6,2)+' t
|
|
|
where accdate between '''+@sbgndate+''' and '''+@senddate+''' and billtype=''0''
|
|
|
and exists(select * from t_accept_head p,t_shop q where p.orgcode=q.orgcode and billno=t.billno and p.billtype=''3'' and q.finacode=''2000'')'
|
|
|
set @ssql=@ssql+@sfilt
|
|
|
set @ssql=@ssql+' group by plucode,orgcode) b where a.plucode=b.plucode and a.orgcode=b.orgcode'
|
|
|
exec(@ssql)
|
|
|
|
|
|
set @ssql='update a set pscount=a.pscount+b.fscount,psnetcost=a.psnetcost+b.fsnetcost
|
|
|
from ##tmpplujxc a,(select plucode,orgcode,sum(fscount) as fscount,sum(fsnetcost) as fsnetcost
|
|
|
from t_gbk_'+substring(@stmpdate,1,4)+substring(@stmpdate,6,2)+' t
|
|
|
where accdate between '''+@sbgndate+''' and '''+@senddate+''' and billtype=''E''
|
|
|
and (exists(select * from t_dist_head p,t_shop q where p.shopcode=q.orgcode and billno=t.billno and p.zpcount>0 and q.finacode=''2000'')
|
|
|
or exists(select * from t_dist_head where billno=t.billno and zpcount=0 and zpamount>0))'
|
|
|
set @ssql=@ssql+@sfilt
|
|
|
set @ssql=@ssql+' group by plucode,orgcode) b where a.plucode=b.plucode and a.orgcode=b.orgcode'
|
|
|
exec(@ssql)
|
|
|
|
|
|
set @ssql='update a set tccount=a.tccount+b.fscount,tcnetcost=a.tcnetcost+b.fsnetcost
|
|
|
from ##tmpplujxc a,(select plucode,orgcode,sum(fscount) as fscount,sum(fsnetcost) as fsnetcost
|
|
|
from t_gbk_'+substring(@stmpdate,1,4)+substring(@stmpdate,6,2)+' t
|
|
|
where accdate between '''+@sbgndate+''' and '''+@senddate+''' and billtype=''5''
|
|
|
and exists(select * from t_return_head p,t_shop q where p.orgcode=q.orgcode and billno=t.billno and p.billtype=''3'' and q.finacode=''2000'')'
|
|
|
set @ssql=@ssql+@sfilt
|
|
|
set @ssql=@ssql+' group by plucode,orgcode) b where a.plucode=b.plucode and a.orgcode=b.orgcode'
|
|
|
exec(@ssql)
|
|
|
|
|
|
set @ssql='update a set pthcount=a.pthcount+b.fscount,pthnetcost=a.pthnetcost+b.fsnetcost
|
|
|
from ##tmpplujxc a,(select plucode,orgcode,sum(fscount) as fscount,sum(fsnetcost) as fsnetcost
|
|
|
from t_gbk_'+substring(@stmpdate,1,4)+substring(@stmpdate,6,2)+' t
|
|
|
where accdate between '''+@sbgndate+''' and '''+@senddate+''' and billtype=''E''
|
|
|
and (exists(select * from t_dist_head p,t_shop q where p.shopcode=q.orgcode and billno=t.billno and p.zpcount<0 and p.orgcode=''C002'' and q.finacode=''2000'')
|
|
|
or exists(select * from t_dist_head where billno=t.billno and zpcount=0 and zpamount<0))'
|
|
|
set @ssql=@ssql+@sfilt
|
|
|
set @ssql=@ssql+' group by plucode,orgcode) b where a.plucode=b.plucode and a.orgcode=b.orgcode'
|
|
|
exec(@ssql)
|
|
|
|
|
|
set @ssql='update a set pycount=a.pycount+b.fscount,pynetcost=a.pynetcost+b.fsnetcost
|
|
|
from ##tmpplujxc a,(select plucode,orgcode,sum(fscount) as fscount,sum(fsnetcost) as fsnetcost
|
|
|
from t_gbk_'+substring(@stmpdate,1,4)+substring(@stmpdate,6,2)+' t
|
|
|
where accdate between '''+@sbgndate+''' and '''+@senddate+''' and billtype=''2'' and fscount>0'
|
|
|
set @ssql=@ssql+@sfilt
|
|
|
set @ssql=@ssql+' group by plucode,orgcode) b where a.plucode=b.plucode and a.orgcode=b.orgcode'
|
|
|
exec(@ssql)
|
|
|
|
|
|
set @ssql='update a set pkcount=a.pkcount+b.fscount,pknetcost=a.pknetcost+b.fsnetcost
|
|
|
from ##tmpplujxc a,(select plucode,orgcode,sum(fscount) as fscount,sum(fsnetcost) as fsnetcost
|
|
|
from t_gbk_'+substring(@stmpdate,1,4)+substring(@stmpdate,6,2)+' t
|
|
|
where accdate between '''+@sbgndate+''' and '''+@senddate+''' and billtype=''2'' and fscount<0'
|
|
|
set @ssql=@ssql+@sfilt
|
|
|
set @ssql=@ssql+' group by plucode,orgcode) b where a.plucode=b.plucode and a.orgcode=b.orgcode'
|
|
|
exec(@ssql)
|
|
|
|
|
|
set @ssql='update a set bscount=a.bscount+b.fscount,bsnetcost=a.bsnetcost+b.fsnetcost
|
|
|
from ##tmpplujxc a,(select plucode,orgcode,sum(fscount) as fscount,sum(fsnetcost) as fsnetcost
|
|
|
from t_gbk_'+substring(@stmpdate,1,4)+substring(@stmpdate,6,2)+' t
|
|
|
where accdate between '''+@sbgndate+''' and '''+@senddate+''' and billtype=''S'''
|
|
|
set @ssql=@ssql+@sfilt
|
|
|
set @ssql=@ssql+' group by plucode,orgcode) b where a.plucode=b.plucode and a.orgcode=b.orgcode'
|
|
|
exec(@ssql)
|
|
|
|
|
|
set @ssql='update a set lycount=a.lycount+b.fscount,lynetcost=a.lynetcost+b.fsnetcost
|
|
|
from ##tmpplujxc a,(select plucode,orgcode,sum(fscount) as fscount,sum(fsnetcost) as fsnetcost
|
|
|
from t_gbk_'+substring(@stmpdate,1,4)+substring(@stmpdate,6,2)+' t
|
|
|
where accdate between '''+@sbgndate+''' and '''+@senddate+''' and billtype=''7'''
|
|
|
set @ssql=@ssql+@sfilt
|
|
|
set @ssql=@ssql+' group by plucode,orgcode) b where a.plucode=b.plucode and a.orgcode=b.orgcode'
|
|
|
exec(@ssql)
|
|
|
|
|
|
set @ssql='update a set jgcount=a.jgcount+b.fscount,jgnetcost=a.jgnetcost+b.fsnetcost
|
|
|
from ##tmpplujxc a,(select plucode,orgcode,sum(fscount) as fscount,sum(fsnetcost) as fsnetcost
|
|
|
from t_gbk_'+substring(@stmpdate,1,4)+substring(@stmpdate,6,2)+' t
|
|
|
where accdate between '''+@sbgndate+''' and '''+@senddate+''' and billtype=''C'''
|
|
|
set @ssql=@ssql+@sfilt
|
|
|
set @ssql=@ssql+' group by plucode,orgcode) b where a.plucode=b.plucode and a.orgcode=b.orgcode'
|
|
|
exec(@ssql)
|
|
|
|
|
|
set @ssql='update a set cjgcount=a.cjgcount+b.fscount,cjgnetcost=a.cjgnetcost+b.fsnetcost
|
|
|
from ##tmpplujxc a,(select plucode,orgcode,sum(fscount) as fscount,sum(fsnetcost) as fsnetcost
|
|
|
from t_gbk_'+substring(@stmpdate,1,4)+substring(@stmpdate,6,2)+' t
|
|
|
where accdate between '''+@sbgndate+''' and '''+@senddate+''' and billtype=''D'''
|
|
|
set @ssql=@ssql+@sfilt
|
|
|
set @ssql=@ssql+' group by plucode,orgcode) b where a.plucode=b.plucode and a.orgcode=b.orgcode'
|
|
|
exec(@ssql)
|
|
|
|
|
|
set @ssql='update a set hccount=a.hccount+b.fscount,hcnetcost=a.hcnetcost+b.fsnetcost
|
|
|
from ##tmpplujxc a,(select plucode,orgcode,sum(fscount) as fscount,sum(fsnetcost) as fsnetcost
|
|
|
from t_gbk_'+substring(@stmpdate,1,4)+substring(@stmpdate,6,2)+' t
|
|
|
where accdate between '''+@sbgndate+''' and '''+@senddate+''' and billtype=''E''
|
|
|
and exists(select * from t_dist_head p,t_shop q where p.shopcode=q.orgcode and billno=t.billno and p.zpcount<0 and p.orgcode=''C001'' and q.finacode=''2000'')'
|
|
|
set @ssql=@ssql+@sfilt
|
|
|
set @ssql=@ssql+' group by plucode,orgcode) b where a.plucode=b.plucode and a.orgcode=b.orgcode'
|
|
|
exec(@ssql)
|
|
|
|
|
|
set @ssql='update a set zpscount=a.zpscount+b.fscount,zpsnetcost=a.zpsnetcost+b.fsnetcost
|
|
|
from ##tmpplujxc a,(select plucode,orgcode,sum(fscount) as fscount,sum(fsnetcost) as fsnetcost
|
|
|
from t_gbk_'+substring(@stmpdate,1,4)+substring(@stmpdate,6,2)+' t
|
|
|
where accdate between '''+@sbgndate+''' and '''+@senddate+''' and billtype=''E''
|
|
|
and exists(select * from t_dist_head p,t_shop q where p.shopcode=q.orgcode and billno=t.billno and p.zpcount>0 and q.finacode<>''2000'')'
|
|
|
set @ssql=@ssql+@sfilt
|
|
|
set @ssql=@ssql+' group by plucode,orgcode) b where a.plucode=b.plucode and a.orgcode=b.orgcode'
|
|
|
exec(@ssql)
|
|
|
|
|
|
set @ssql='update a set zthcount=a.zthcount+b.fscount,zthnetcost=a.zthnetcost+b.fsnetcost
|
|
|
from ##tmpplujxc a,(select plucode,orgcode,sum(fscount) as fscount,sum(fsnetcost) as fsnetcost
|
|
|
from t_gbk_'+substring(@stmpdate,1,4)+substring(@stmpdate,6,2)+' t
|
|
|
where accdate between '''+@sbgndate+''' and '''+@senddate+''' and billtype=''E''
|
|
|
and exists(select * from t_dist_head p,t_shop q where p.shopcode=q.orgcode and billno=t.billno and p.zpcount<0 and q.finacode<>''2000'')'
|
|
|
set @ssql=@ssql+@sfilt
|
|
|
set @ssql=@ssql+' group by plucode,orgcode) b where a.plucode=b.plucode and a.orgcode=b.orgcode'
|
|
|
exec(@ssql)
|
|
|
end
|
|
|
set @stmpdate=convert(varchar(10),dateadd(month,1,@stmpdate),120)
|
|
|
end
|
|
|
|
|
|
delete from ##tmpplujxc
|
|
|
where (abs(qccount)+abs(qcnetcost)+abs(jhcount)+abs(jhnetcost)+abs(thcount)+abs(thnetcost)+abs(xscount)+abs(xsnetcost)+
|
|
|
abs(drcount)+abs(drnetcost)+abs(dccount)+abs(dcnetcost)+abs(pjhcount)+abs(pjhnetcost)+abs(pscount)+abs(psnetcost)+
|
|
|
abs(tccount)+abs(tcnetcost)+abs(pthcount)+abs(pthnetcost)+abs(pycount)+abs(pynetcost)+abs(pkcount)+abs(pknetcost)+
|
|
|
abs(bscount)+abs(bsnetcost)+abs(lycount)+abs(lynetcost)+abs(jgcount)+abs(jgnetcost)+abs(cjgcount)+abs(cjgnetcost)+
|
|
|
abs(hccount)+abs(hcnetcost)+abs(zpscount)+abs(zpsnetcost)+abs(zthcount)+abs(zthnetcost)+abs(jccount)+abs(jcnetcost)) = 0
|
|
|
|
|
|
set @ssql='select distinct b.finacode,d.areaname as regnname,c.areaname,a.orgcode,b.orgname,
|
|
|
h.clscode as dclscode,h.clsname as dclsname,g.clscode,g.clsname,a.plucode,e.pluname,
|
|
|
(select top 1 unitcode from t_unit where unitname=e.unit order by unitcode) as unitcode,
|
|
|
a.qccount,a.qcnetcost,a.jhcount,a.jhnetcost,a.thcount,a.thnetcost,a.xscount,a.xsnetcost,
|
|
|
a.drcount,a.drnetcost,a.dccount,a.dcnetcost,a.pjhcount,a.pjhnetcost,a.pscount,a.psnetcost,
|
|
|
a.tccount,a.tcnetcost,a.pthcount,a.pthnetcost,a.pycount,a.pynetcost,a.pkcount,a.pknetcost,
|
|
|
a.bscount,a.bsnetcost,a.lycount,a.lynetcost,a.jgcount,a.jgnetcost,a.cjgcount,a.cjgnetcost,
|
|
|
a.hccount,a.hcnetcost,a.zpscount,zpsnetcost,zthcount,zthnetcost,a.jccount,a.jcnetcost
|
|
|
from ##tmpplujxc a
|
|
|
left join t_shop b on a.orgcode=b.orgcode
|
|
|
left join t_area c on b.areacode=c.areacode
|
|
|
left join t_area d on c.uppercode1=d.areacode
|
|
|
left join t_plu e on a.plucode=e.plucode
|
|
|
left join t_gclass f on e.clscode=f.clscode
|
|
|
left join t_gclass g on f.uppercode1=g.clscode
|
|
|
left join t_gclass h on g.uppercode1=h.clscode
|
|
|
where 0=0 order by b.finacode,a.orgcode,a.plucode'
|
|
|
exec(@ssql)
|
|
|
|
|
|
if exists(select name from tempdb..sysobjects where name='##tmpplujxc' and xtype='u')
|
|
|
drop table ##tmpplujxc
|
|
|
end
|
|
|
go
|
|
|
|
|
|
/*²É¹º¶©µ¥²éѯ*/
|
|
|
if exists(select * from sysobjects where name='p_rpt_orderrpt' and xtype='p')
|
|
|
drop procedure p_rpt_orderrpt
|
|
|
go
|
|
|
|
|
|
create procedure p_rpt_orderrpt
|
|
|
(
|
|
|
@pregncode varchar(1000),
|
|
|
@pareacode varchar(1000),
|
|
|
@porgcode varchar(1000),
|
|
|
@psupcode varchar(1000),
|
|
|
@pbgndate varchar(10),
|
|
|
@penddate varchar(10),
|
|
|
@pbillno varchar(1000),
|
|
|
@pbilltype varchar(2),
|
|
|
@pbillstate varchar(1),
|
|
|
@pplucode varchar(2000),
|
|
|
@pchkstatus varchar(1),
|
|
|
@ps_SysUserCode varchar(20)
|
|
|
)
|
|
|
as
|
|
|
declare @ssql varchar(8000)
|
|
|
declare @stmpdate varchar(10)
|
|
|
declare @sregncode varchar(1000)
|
|
|
declare @sareacode varchar(1000)
|
|
|
declare @sorgcode varchar(1000)
|
|
|
declare @ssupcode varchar(1000)
|
|
|
declare @sbillno varchar(1000)
|
|
|
declare @splucode varchar(1000)
|
|
|
declare @sbgndate varchar(10)
|
|
|
declare @senddate varchar(10)
|
|
|
begin
|
|
|
set @sregncode=replace(@sregncode,',',''',''')
|
|
|
set @sareacode=replace(@sareacode,',',''',''')
|
|
|
set @sorgcode=replace(@porgcode,',',''',''')
|
|
|
set @ssupcode=replace(@psupcode,',',''',''')
|
|
|
set @sbillno=replace(@pbillno,',',''',''')
|
|
|
set @splucode=replace(@pplucode,',',''',''')
|
|
|
set @sbgndate=@pbgndate
|
|
|
set @senddate=@penddate
|
|
|
if isnull(@sbgndate,'')=''
|
|
|
set @sbgndate='2023-08-01'
|
|
|
if isnull(@senddate,'')=''
|
|
|
set @senddate='2099-12-31'
|
|
|
|
|
|
if exists(select name from tempdb..sysobjects where name='##tmporderrpt' and xtype='u')
|
|
|
drop table ##tmporderrpt
|
|
|
create table ##tmporderrpt (
|
|
|
orgcode varchar(10),rzdate varchar(10),jhrzdate varchar(10),billno varchar(20),billtype varchar(2),
|
|
|
state varchar(1),supcode varchar(15),zdrname varchar(10),chkstatus varchar(1),plucode varchar(20),
|
|
|
barcode varchar(20),pluname varchar(40),unit varchar(10),pcount numeric(19,4),jprice numeric(19,4),
|
|
|
counts numeric(19,4),givecount numeric(19,4),cost numeric(19,4),netcost numeric(19,4),jhcounts numeric(19,4),jhgivecount numeric(19,4),
|
|
|
jhcost numeric(19,4),jhnetcost numeric(19,4),jtaxrate numeric(19,4),ywbillno varchar(20),refbillno varchar(20))
|
|
|
|
|
|
set @ssql='insert into ##tmporderrpt(orgcode,rzdate,jhrzdate,billno,billtype,state,supcode,zdrname,chkstatus,plucode,
|
|
|
barcode,pluname,unit,pcount,jprice,counts,givecount,cost,netcost,jhcounts,jhgivecount,jhcost,jhnetcost,jtaxrate,refbillno)
|
|
|
select a.orgcode,a.rzdate,'''',a.billno,case when d.finatype=''1'' then ''05'' when a.iszs=''1'' then ''03'' else ''01'' end,
|
|
|
a.state,a.supcode,a.zdrname,a.chkstatus,b.plucode,b.barcode,b.pluname,b.unit,b.itemcnt,b.jprice,b.counts,b.givecount,b.cost,b.netcost,0,0,0,0,b.jtaxrate,
|
|
|
(select max(billno) from t_accept_head h where a.billno=h.orderno and a.orgcode<>h.orgcode and a.supcode=h.supcode and h.billtype=''1'')
|
|
|
from t_order_head a,t_order_body b,t_shop c,t_financial_body d
|
|
|
where a.billno=b.billno and a.orgcode=c.orgcode and c.finacode=d.finacode
|
|
|
and exists(select * from t_user_org where orgcode=a.orgcode and usercode='''+@ps_SysUserCode+''')'
|
|
|
if @sregncode<>''
|
|
|
set @ssql=@ssql+' and exists(select * from t_shop m,t_area n where m.areacode=n.areacode and m.orgcode=a.orgcode and n.uppercode1 in ('''+@sregncode+'''))'
|
|
|
if @sareacode<>''
|
|
|
set @ssql=@ssql+' and exists(select * from t_shop where orgcode=a.orgcode and areacode in ('''+@sareacode+'''))'
|
|
|
if @sorgcode<>''
|
|
|
set @ssql=@ssql+' and a.orgcode in ('''+@sorgcode+''')'
|
|
|
if @ssupcode<>''
|
|
|
set @ssql=@ssql+' and a.supcode in ('''+@ssupcode+''')'
|
|
|
if @sbillno<>''
|
|
|
set @ssql=@ssql+' and a.billno in ('''+@sbillno+''')'
|
|
|
if @splucode<>''
|
|
|
set @ssql=@ssql+' and b.plucode in ('''+@splucode+''')'
|
|
|
if isnull(@pbilltype,'')='01'
|
|
|
set @ssql=@ssql+' and a.iszs=''0'' and d.finatype=''0'''
|
|
|
else if isnull(@pbilltype,'')='03'
|
|
|
set @ssql=@ssql+' and a.iszs=''1'' and d.finatype=''0'''
|
|
|
else if isnull(@pbilltype,'')='05'
|
|
|
set @ssql=@ssql+' and d.finatype=''1'''
|
|
|
else if isnull(@pbilltype,'')<>''
|
|
|
set @ssql=@ssql+' and 0=1'
|
|
|
if isnull(@pbillstate,'')<>''
|
|
|
set @ssql=@ssql+' and a.state='''+@pbillstate+''''
|
|
|
if isnull(@pchkstatus,'')='0'
|
|
|
set @ssql=@ssql+' and a.rzdate between '''+@sbgndate+''' and '''+@senddate+''''
|
|
|
else if isnull(@pchkstatus,'')='1'
|
|
|
set @ssql=@ssql+' and isnull(a.rzdate,'''')='''' and a.chkstatus in (''0'',''9'') and a.lrdate between '''+@sbgndate+''' and '''+@senddate+''''
|
|
|
else
|
|
|
set @ssql=@ssql+' and a.chkstatus in (''1'',''9'') and a.lrdate between '''+@sbgndate+''' and '''+@senddate+''''
|
|
|
exec(@ssql)
|
|
|
|
|
|
set @ssql='update t set ywbillno=s.billno,jhrzdate=s.rzdate,jhcounts=s.counts,jhgivecount=s.givecount,jhcost=s.cost,jhnetcost=s.netcost
|
|
|
from ##tmporderrpt t,
|
|
|
(select a.orderno,a.orgcode,b.plucode,max(a.billno) as billno,max(a.rzdate) as rzdate,sum(b.counts) as counts,sum(b.givecount) as givecount,sum(b.cost) as cost,sum(b.netcost) as netcost
|
|
|
from t_accept_head a,t_accept_body b
|
|
|
where a.billno=b.billno and a.rzdate >= '''+@sbgndate+''''
|
|
|
if @sregncode<>''
|
|
|
set @ssql=@ssql+' and exists(select * from t_shop m,t_area n where m.areacode=n.areacode and m.orgcode=a.orgcode and n.uppercode1 in ('''+@sregncode+'''))'
|
|
|
if @sareacode<>''
|
|
|
set @ssql=@ssql+' and exists(select * from t_shop where orgcode=a.orgcode and areacode in ('''+@sareacode+'''))'
|
|
|
if @sorgcode<>''
|
|
|
set @ssql=@ssql+' and a.orgcode in ('''+@sorgcode+''')'
|
|
|
if @ssupcode<>''
|
|
|
set @ssql=@ssql+' and a.supcode in ('''+@ssupcode+''')'
|
|
|
if @sbillno<>''
|
|
|
set @ssql=@ssql+' and a.orderno in ('''+@sbillno+''')'
|
|
|
if @splucode<>''
|
|
|
set @ssql=@ssql+' and b.plucode in ('''+@splucode+''')'
|
|
|
set @ssql=@ssql+' group by a.orderno,a.orgcode,b.plucode) s
|
|
|
where t.billno=s.orderno and t.orgcode=s.orgcode and t.plucode=s.plucode'
|
|
|
exec(@ssql)
|
|
|
|
|
|
set @ssql='insert into ##tmporderrpt(orgcode,rzdate,jhrzdate,billno,billtype,state,supcode,zdrname,chkstatus,plucode,
|
|
|
barcode,pluname,unit,pcount,jprice,counts,givecount,cost,netcost,jhcounts,jhgivecount,jhcost,jhnetcost,jtaxrate,ywbillno,refbillno)
|
|
|
select a.orgcode,a.rzdate,a.rzdate,a.billno,case when d.finatype=''1'' then ''06'' when a.billtype=''2'' then ''04'' else ''02'' end,case when isnull(a.rzdate,'''')='''' then ''1'' else ''2'' end,a.supcode,a.zdrname,a.chkstatus,
|
|
|
b.plucode,b.barcode,b.pluname,b.unit,b.itemcnt,b.jprice,(-1)*b.counts,0,(-1)*b.cost,(-1)*b.netcost,(-1)*b.counts,0,(-1)*b.cost,(-1)*b.netcost,b.jtaxrate,a.billno,
|
|
|
(select max(billno) from t_return_head h where a.billno=h.oldbillno and a.orgcode<>h.orgcode and a.supcode=h.supcode and h.billtype=''0'')
|
|
|
from t_return_head a,t_return_body b,t_shop c,t_financial_body d
|
|
|
where a.billno=b.billno and a.orgcode=c.orgcode and c.finacode=d.finacode and a.billtype in (''0'',''2'')
|
|
|
and exists(select * from t_user_org where orgcode=a.orgcode and usercode='''+@ps_SysUserCode+''')'
|
|
|
if @sregncode<>''
|
|
|
set @ssql=@ssql+' and exists(select * from t_shop m,t_area n where m.areacode=n.areacode and m.orgcode=a.orgcode and n.uppercode1 in ('''+@sregncode+'''))'
|
|
|
if @sareacode<>''
|
|
|
set @ssql=@ssql+' and exists(select * from t_shop where orgcode=a.orgcode and areacode in ('''+@sareacode+'''))'
|
|
|
if @sorgcode<>''
|
|
|
set @ssql=@ssql+' and a.orgcode in ('''+@sorgcode+''')'
|
|
|
if @ssupcode<>''
|
|
|
set @ssql=@ssql+' and a.supcode in ('''+@ssupcode+''')'
|
|
|
if @sbillno<>''
|
|
|
set @ssql=@ssql+' and a.billno in ('''+@sbillno+''')'
|
|
|
if @splucode<>''
|
|
|
set @ssql=@ssql+' and b.plucode in ('''+@splucode+''')'
|
|
|
if isnull(@pbilltype,'')='02'
|
|
|
set @ssql=@ssql+' and a.billtype=''0'' and d.finatype=''0'''
|
|
|
else if isnull(@pbilltype,'')='04'
|
|
|
set @ssql=@ssql+' and a.billtype=''2'' and d.finatype=''0'''
|
|
|
else if isnull(@pbilltype,'')='06'
|
|
|
set @ssql=@ssql+' and d.finatype=''1'''
|
|
|
else if isnull(@pbilltype,'')<>''
|
|
|
set @ssql=@ssql+' and 0=1'
|
|
|
if isnull(@pbillstate,'')<>''
|
|
|
set @ssql=@ssql+' and 0=1'
|
|
|
if isnull(@pchkstatus,'')='0'
|
|
|
set @ssql=@ssql+' and a.rzdate between '''+@sbgndate+''' and '''+@senddate+''''
|
|
|
else if isnull(@pchkstatus,'')='1'
|
|
|
set @ssql=@ssql+' and isnull(a.rzdate,'''')='''' and a.chkstatus in (''0'',''9'') and a.lrdate between '''+@sbgndate+''' and '''+@senddate+''''
|
|
|
else
|
|
|
set @ssql=@ssql+' and a.chkstatus in (''1'',''9'') and a.lrdate between '''+@sbgndate+''' and '''+@senddate+''''
|
|
|
exec(@ssql)
|
|
|
|
|
|
set @ssql='select a.orgcode,b.orgname,a.rzdate,a.jhrzdate,a.billtype,
|
|
|
case a.billtype when ''01'' then ''ÖÐÑë²Ö²É¹º¶©µ¥'' when ''02'' then ''ÖÐÑë²Ö²É¹ºÍË»õµ¥'' when ''03'' then ''±ãÀûµêÖ±ËͲɹº¶©µ¥''
|
|
|
when ''04'' then ''±ãÀûµêÖ±ËÍÍË»õ¶©µ¥'' when ''05'' then ''ĸ×Ó¹«Ë¾²É¹º¶©µ¥'' when ''06'' then ''ĸ×Ó¹«Ë¾²É¹ºÍË»õµ¥''
|
|
|
else '''' end as c_billtype,
|
|
|
case a.state when ''0'' then ''δִÐÐ'' when ''1'' then ''Ö´ÐÐÖÐ'' when ''2'' then ''Ö´ÐÐÍê³É'' when ''3'' then ''ÊÖ¹¤¹Ø±Õ'' when ''4'' then ''¹ýÆڹرÕ'' when ''5'' then ''È˹¤×÷·Ï'' when ''9'' then ''Íê³É½áËã'' else '''' end as billstate,
|
|
|
a.billno,a.supcode,e.supname,a.zdrname,case when a.chkstatus in (''1'',''2'') then ''¡Ì'' else '''' end as chkflag,
|
|
|
a.plucode,a.barcode,a.pluname,a.counts,a.givecount,(select top 1 unitcode from t_unit where unitname=f.unit) as unitcode,a.unit,
|
|
|
a.jprice,a.cost,a.netcost,a.cost-a.netcost as taxamt,a.jhcost,a.jhnetcost,a.jhcounts,a.jhgivecount,h.clscode,h.clsname,
|
|
|
case when a.billtype in (''02'',''04'',''06'') then ''¡Á'' else '''' end as rtnflag,a.pcount,a.unit as punit,b.areacode,c.areaname,d.areacode as regncode,d.areaname as regnname,a.jtaxrate,
|
|
|
case when p.isaccounted = ''1'' then ''¡Ì'' else '''' end as accountflag,refbillno
|
|
|
from ##tmporderrpt a
|
|
|
left join t_shop b on a.orgcode=b.orgcode
|
|
|
left join t_area c on b.areacode=c.areacode
|
|
|
left join t_area d on c.uppercode1=d.areacode
|
|
|
left join t_supplier e on a.supcode=e.supcode
|
|
|
left join t_plu f on a.plucode=f.plucode
|
|
|
left join t_gclass g on f.clscode=g.clscode
|
|
|
left join t_gclass h on g.uppercode1=h.clscode
|
|
|
left join t_pay_bill p on a.ywbillno=p.billno and a.supcode=p.supcode
|
|
|
order by a.orgcode,a.rzdate,a.jhrzdate,a.billno,a.plucode'
|
|
|
exec(@ssql)
|
|
|
|
|
|
if exists(select name from tempdb..sysobjects where name='##tmporderrpt' and xtype='u')
|
|
|
drop table ##tmporderrpt
|
|
|
end
|
|
|
go
|
|
|
|
|
|
/*ÖÐÑë²ÖÅäËͱ¨±í*/
|
|
|
if exists(select * from sysobjects where name='p_rpt_distrpt' and xtype='p')
|
|
|
drop procedure p_rpt_distrpt
|
|
|
go
|
|
|
|
|
|
create procedure p_rpt_distrpt
|
|
|
(
|
|
|
@pregncode varchar(1000),
|
|
|
@pareacode varchar(1000),
|
|
|
@porgcode varchar(1000),
|
|
|
@pshopcode varchar(1000),
|
|
|
@pbgndate varchar(10),
|
|
|
@penddate varchar(10),
|
|
|
@pjhbgndate varchar(10),
|
|
|
@pjhenddate varchar(10),
|
|
|
@pbillno varchar(1000),
|
|
|
@pplucode varchar(2000),
|
|
|
@pdifftype varchar(1),
|
|
|
@pjhstate varchar(1),
|
|
|
@ps_SysUserCode varchar(20)
|
|
|
)
|
|
|
as
|
|
|
declare @ssql varchar(8000)
|
|
|
declare @stmpdate varchar(10)
|
|
|
declare @sregncode varchar(1000)
|
|
|
declare @sareacode varchar(1000)
|
|
|
declare @sorgcode varchar(1000)
|
|
|
declare @sshopcode varchar(1000)
|
|
|
declare @sbillno varchar(1000)
|
|
|
declare @splucode varchar(1000)
|
|
|
declare @sbgndate varchar(10)
|
|
|
declare @senddate varchar(10)
|
|
|
declare @sjhbgndate varchar(10)
|
|
|
declare @sjhenddate varchar(10)
|
|
|
begin
|
|
|
set @sregncode=replace(@pregncode,',',''',''')
|
|
|
set @sareacode=replace(@pareacode,',',''',''')
|
|
|
set @sorgcode=replace(@porgcode,',',''',''')
|
|
|
set @sshopcode=replace(@pshopcode,',',''',''')
|
|
|
set @sbillno=replace(@pbillno,',',''',''')
|
|
|
set @splucode=replace(@pplucode,',',''',''')
|
|
|
set @sbgndate=@pbgndate
|
|
|
set @senddate=@penddate
|
|
|
set @sjhbgndate=@pjhbgndate
|
|
|
set @sjhenddate=@pjhenddate
|
|
|
if isnull(@sbgndate,'')=''
|
|
|
set @sbgndate='2023-08-01'
|
|
|
if isnull(@senddate,'')=''
|
|
|
set @senddate='2099-12-31'
|
|
|
if isnull(@sjhbgndate,'')=''
|
|
|
set @sjhbgndate='2023-08-01'
|
|
|
if isnull(@sjhenddate,'')=''
|
|
|
set @sjhenddate='2099-12-31'
|
|
|
|
|
|
if exists(select name from tempdb..sysobjects where name='##tmpdistrpt' and xtype='u')
|
|
|
drop table ##tmpdistrpt
|
|
|
create table ##tmpdistrpt (
|
|
|
orgcode varchar(10),orgname varchar(30),shopcode varchar(10),rzdate varchar(10),jhrzdate varchar(10),billno varchar(20),
|
|
|
jhbillno varchar(20),plucode varchar(20),barcode varchar(20),pluname varchar(40),unit varchar(10),pcount numeric(19,4),
|
|
|
zpcount numeric(19,4),counts numeric(19,4),thbillno varchar(20),thcount numeric(19,4),thrzdate varchar(10))
|
|
|
|
|
|
set @ssql='insert into ##tmpdistrpt(orgcode,orgname,shopcode,rzdate,jhrzdate,billno,jhbillno,plucode,barcode,pluname,unit,pcount,zpcount,counts,thbillno,thcount,thrzdate)
|
|
|
select a.supcode,a.supname,a.orgcode,a.bizdate,a.rzdate,a.orderno,a.billno,b.plucode,b.barcode,b.pluname,b.unit,b.itemcnt,b.cgcount,
|
|
|
case when isnull(a.rzdate,'''')='''' then 0 else b.cgcount end,'''',0,''''
|
|
|
from t_accept_head a,t_accept_body b
|
|
|
where a.billno=b.billno and a.billtype=''3''
|
|
|
and a.bizdate between '''+@sbgndate+''' and '''+@senddate+'''
|
|
|
and (a.rzdate between '''+@sjhbgndate+''' and '''+@sjhenddate+''' or isnull(a.rzdate,'''')='''')
|
|
|
and exists(select * from t_user_org where orgcode=a.orgcode and usercode='''+@ps_SysUserCode+''')'
|
|
|
if @sregncode<>''
|
|
|
set @ssql=@ssql+' and exists(select * from t_shop m,t_area n where m.areacode=n.areacode and m.orgcode=a.orgcode and n.uppercode1 in ('''+@sregncode+'''))'
|
|
|
if @sareacode<>''
|
|
|
set @ssql=@ssql+' and exists(select * from t_shop where orgcode=a.orgcode and areacode in ('''+@sareacode+'''))'
|
|
|
if @sorgcode<>''
|
|
|
set @ssql=@ssql+' and a.supcode in ('''+@sorgcode+''')'
|
|
|
if @sshopcode<>''
|
|
|
set @ssql=@ssql+' and a.orgcode in ('''+@sshopcode+''')'
|
|
|
if @sbillno<>''
|
|
|
set @ssql=@ssql+' and a.orderno in ('''+@sbillno+''')'
|
|
|
if @splucode<>''
|
|
|
set @ssql=@ssql+' and b.plucode in ('''+@splucode+''')'
|
|
|
if isnull(@pdifftype,'')='1'
|
|
|
set @ssql=@ssql+' and b.cgcount<>b.counts'
|
|
|
if isnull(@pjhstate,'')='1'
|
|
|
set @ssql=@ssql+' and isnull(a.rzdate,'''')='''''
|
|
|
else if isnull(@pjhstate,'')='2'
|
|
|
set @ssql=@ssql+' and isnull(a.rzdate,'''')<>'''''
|
|
|
exec(@ssql)
|
|
|
|
|
|
set @ssql='update t set thbillno=b.genbillno
|
|
|
from ##tmpdistrpt t,t_distdiffer_head a,t_distdiffer_body b
|
|
|
where t.jhbillno=a.ywbillno and a.billno=b.billno and t.plucode=b.plucode and a.differtype=''0'''
|
|
|
exec(@ssql)
|
|
|
|
|
|
set @ssql='update t set thcount=b.counts,thrzdate=a.rzdate
|
|
|
from ##tmpdistrpt t,t_return_head a,t_return_body b
|
|
|
where t.thbillno=a.billno and a.billno=b.billno and t.plucode=b.plucode and a.billtype=''3'''
|
|
|
exec(@ssql)
|
|
|
|
|
|
set @ssql='select a.orgcode,a.orgname,a.billno,a.rzdate,a.plucode,a.pluname,a.barcode,a.unit,a.pcount,
|
|
|
a.zpcount,a.counts,a.jhrzdate,a.zpcount-a.counts as diffcount,a.thbillno,a.thcount,a.thrzdate,
|
|
|
b.areacode,c.areaname,d.areacode as regncode,d.areaname as regnname,a.shopcode,b.orgname as shopname,
|
|
|
case when isnull(a.jhrzdate,'''')='''' then ''δÊÕ»õ'' else ''ÒÑÊÕ»õ'' end as r_jhstate
|
|
|
from ##tmpdistrpt a
|
|
|
left join t_shop b on a.shopcode=b.orgcode
|
|
|
left join t_area c on b.areacode=c.areacode
|
|
|
left join t_area d on c.uppercode1=d.areacode
|
|
|
order by a.orgcode,a.rzdate,a.billno,a.plucode'
|
|
|
exec(@ssql)
|
|
|
|
|
|
if exists(select name from tempdb..sysobjects where name='##tmpdistrpt' and xtype='u')
|
|
|
drop table ##tmpdistrpt
|
|
|
end
|
|
|
go
|
|
|
|
|
|
/*ÖÐÑë²ÖÅäËÍÍË»õ±¨±í*/
|
|
|
if exists(select * from sysobjects where name='p_rpt_distrtnrpt' and xtype='p')
|
|
|
drop procedure p_rpt_distrtnrpt
|
|
|
go
|
|
|
|
|
|
create procedure p_rpt_distrtnrpt
|
|
|
(
|
|
|
@pregncode varchar(1000),
|
|
|
@pareacode varchar(1000),
|
|
|
@porgcode varchar(1000),
|
|
|
@pshopcode varchar(1000),
|
|
|
@pbgndate varchar(10),
|
|
|
@penddate varchar(10),
|
|
|
@pjhbgndate varchar(10),
|
|
|
@pjhenddate varchar(10),
|
|
|
@pbillno varchar(1000),
|
|
|
@pplucode varchar(2000),
|
|
|
@pdifftype varchar(1),
|
|
|
@pjhstate varchar(1),
|
|
|
@ps_SysUserCode varchar(20)
|
|
|
)
|
|
|
as
|
|
|
declare @ssql varchar(8000)
|
|
|
declare @stmpdate varchar(10)
|
|
|
declare @sregncode varchar(1000)
|
|
|
declare @sareacode varchar(1000)
|
|
|
declare @sorgcode varchar(1000)
|
|
|
declare @sshopcode varchar(1000)
|
|
|
declare @sbillno varchar(1000)
|
|
|
declare @splucode varchar(1000)
|
|
|
declare @sbgndate varchar(10)
|
|
|
declare @senddate varchar(10)
|
|
|
declare @sjhbgndate varchar(10)
|
|
|
declare @sjhenddate varchar(10)
|
|
|
begin
|
|
|
set @sregncode=replace(@sregncode,',',''',''')
|
|
|
set @sareacode=replace(@sareacode,',',''',''')
|
|
|
set @sorgcode=replace(@porgcode,',',''',''')
|
|
|
set @sshopcode=replace(@pshopcode,',',''',''')
|
|
|
set @sbillno=replace(@pbillno,',',''',''')
|
|
|
set @splucode=replace(@pplucode,',',''',''')
|
|
|
set @sbgndate=@pbgndate
|
|
|
set @senddate=@penddate
|
|
|
set @sjhbgndate=@pjhbgndate
|
|
|
set @sjhenddate=@pjhenddate
|
|
|
if isnull(@sbgndate,'')=''
|
|
|
set @sbgndate='2023-08-01'
|
|
|
if isnull(@senddate,'')=''
|
|
|
set @senddate='2099-12-31'
|
|
|
if isnull(@sjhbgndate,'')=''
|
|
|
set @sjhbgndate='2023-08-01'
|
|
|
if isnull(@sjhenddate,'')=''
|
|
|
set @sjhenddate='2099-12-31'
|
|
|
|
|
|
if exists(select name from tempdb..sysobjects where name='##tmpdistrtnrpt' and xtype='u')
|
|
|
drop table ##tmpdistrtnrpt
|
|
|
create table ##tmpdistrtnrpt (
|
|
|
orgcode varchar(10),orgname varchar(30),shopcode varchar(10),rzdate varchar(10),jhrzdate varchar(10),billno varchar(20),
|
|
|
jhbillno varchar(20),plucode varchar(20),barcode varchar(20),pluname varchar(40),unit varchar(10),pcount numeric(19,4),
|
|
|
zpcount numeric(19,4),counts numeric(19,4),thbillno varchar(20),thcount numeric(19,4),thrzdate varchar(10))
|
|
|
|
|
|
set @ssql='insert into ##tmpdistrtnrpt(orgcode,orgname,shopcode,rzdate,jhrzdate,billno,jhbillno,plucode,barcode,pluname,unit,pcount,zpcount,counts,thbillno,thcount,thrzdate)
|
|
|
select a.supcode,a.supname,a.orgcode,a.bizdate,a.rzdate,'''',a.billno,b.plucode,b.barcode,b.pluname,b.unit,b.itemcnt,b.orncounts,
|
|
|
case when isnull(a.rzdate,'''')='''' then 0 else b.counts end,a.billno,0,''''
|
|
|
from t_return_head a,t_return_body b
|
|
|
where a.billno=b.billno and a.billtype=''3''
|
|
|
and a.bizdate between '''+@sbgndate+''' and '''+@senddate+'''
|
|
|
and (a.rzdate between '''+@sjhbgndate+''' and '''+@sjhenddate+''' or isnull(a.rzdate,'''')='''')
|
|
|
and exists(select * from t_user_org where orgcode=a.orgcode and usercode='''+@ps_SysUserCode+''')'
|
|
|
if @sregncode<>''
|
|
|
set @ssql=@ssql+' and exists(select * from t_shop m,t_area n where m.areacode=n.areacode and m.orgcode=a.shopcode and n.uppercode1 in ('''+@sregncode+'''))'
|
|
|
if @sareacode<>''
|
|
|
set @ssql=@ssql+' and exists(select * from t_shop where orgcode=a.shopcode and areacode in ('''+@sareacode+'''))'
|
|
|
if @sorgcode<>''
|
|
|
set @ssql=@ssql+' and a.supcode in ('''+@sorgcode+''')'
|
|
|
if @sshopcode<>''
|
|
|
set @ssql=@ssql+' and a.orgcode in ('''+@sshopcode+''')'
|
|
|
if @sbillno<>''
|
|
|
set @ssql=@ssql+' and a.orderno in ('''+@sbillno+''')'
|
|
|
if @splucode<>''
|
|
|
set @ssql=@ssql+' and b.plucode in ('''+@splucode+''')'
|
|
|
if isnull(@pdifftype,'')='1'
|
|
|
set @ssql=@ssql+' and b.orncounts<>b.counts'
|
|
|
if isnull(@pjhstate,'')='1'
|
|
|
set @ssql=@ssql+' and isnull(a.rzdate,'''')='''''
|
|
|
else if isnull(@pjhstate,'')='2'
|
|
|
set @ssql=@ssql+' and isnull(a.rzdate,'''')<>'''''
|
|
|
exec(@ssql)
|
|
|
|
|
|
set @ssql='update t set billno=a.billno,thcount=b.zpcount,thrzdate=a.rzdate
|
|
|
from ##tmpdistrtnrpt t,t_dist_head a,t_dist_body b
|
|
|
where t.thbillno=a.billno and a.billno=b.billno and t.plucode=b.plucode and a.zpcount<0'
|
|
|
exec(@ssql)
|
|
|
|
|
|
set @ssql='select a.orgcode,a.orgname,a.billno,a.rzdate,a.plucode,a.pluname,a.barcode,a.unit,a.pcount,
|
|
|
a.zpcount,a.counts,a.jhrzdate,a.zpcount-a.counts as diffcount,a.thbillno,a.thcount,a.thrzdate,
|
|
|
b.areacode,c.areaname,d.areacode as regncode,d.areaname as regnname,a.shopcode,b.orgname as shopname,
|
|
|
case when isnull(a.jhrzdate,'''')='''' then ''δÊÕ»õ'' else ''ÒÑÊÕ»õ'' end as r_jhstate
|
|
|
from ##tmpdistrtnrpt a
|
|
|
left join t_shop b on a.shopcode=b.orgcode
|
|
|
left join t_area c on b.areacode=c.areacode
|
|
|
left join t_area d on c.uppercode1=d.areacode
|
|
|
order by a.orgcode,a.rzdate,a.billno,a.plucode'
|
|
|
exec(@ssql)
|
|
|
|
|
|
if exists(select name from tempdb..sysobjects where name='##tmpdistrtnrpt' and xtype='u')
|
|
|
drop table ##tmpdistrtnrpt
|
|
|
end
|
|
|
go
|
|
|
|
|
|
/*ĸ×Ó¹«Ë¾¹ºÏúÃ÷ϸ»ã×Ü*/
|
|
|
if exists(select * from sysobjects where name='p_rpt_subsettle' and xtype='p')
|
|
|
drop procedure p_rpt_subsettle
|
|
|
go
|
|
|
|
|
|
create procedure p_rpt_subsettle
|
|
|
(
|
|
|
@pfinacode varchar(1000),
|
|
|
@pshopcode varchar(1000),
|
|
|
@porgcode varchar(1000),
|
|
|
@pbgndate varchar(10),
|
|
|
@penddate varchar(10),
|
|
|
@pbilltype varchar(1),
|
|
|
@pplucode varchar(2000),
|
|
|
@ps_SysUserCode varchar(20)
|
|
|
)
|
|
|
as
|
|
|
declare @ssql varchar(8000)
|
|
|
declare @sfinacode varchar(1000)
|
|
|
declare @sshopcode varchar(1000)
|
|
|
declare @sorgcode varchar(1000)
|
|
|
declare @splucode varchar(1000)
|
|
|
declare @sbgndate varchar(10)
|
|
|
declare @senddate varchar(10)
|
|
|
begin
|
|
|
set @sfinacode=replace(@pfinacode,',',''',''')
|
|
|
set @sorgcode=replace(@porgcode,',',''',''')
|
|
|
set @sshopcode=replace(@pshopcode,',',''',''')
|
|
|
set @splucode=replace(@pplucode,',',''',''')
|
|
|
set @sbgndate=@pbgndate
|
|
|
set @senddate=@penddate
|
|
|
if isnull(@sbgndate,'')=''
|
|
|
set @sbgndate='2023-08-01'
|
|
|
if isnull(@senddate,'')=''
|
|
|
set @senddate='2099-12-31'
|
|
|
|
|
|
if exists(select name from tempdb..sysobjects where name='##tmpsubsettle' and xtype='u')
|
|
|
drop table ##tmpsubsettle
|
|
|
create table ##tmpsubsettle (
|
|
|
billno varchar(20),orgcode varchar(10),shopcode varchar(10),billtype varchar(1),staxrate numeric(19,0), rzdate varchar(10),
|
|
|
plucode varchar(20),pluname varchar(40),jprice numeric(19,4),netjprice numeric(19,4),zpcount numeric(19,4),
|
|
|
cost numeric(19,4),netcost numeric(19,4),jhrzdate varchar(10),jhjprice numeric(19,4),jhnetjprice numeric(19,4),
|
|
|
jhcount numeric(19,4),jhcost numeric(19,4),jhnetcost numeric(19,4))
|
|
|
|
|
|
set @ssql='insert into ##tmpsubsettle(billno,orgcode,shopcode,billtype,rzdate,plucode,pluname,jprice,netjprice,staxrate,
|
|
|
zpcount,cost,netcost,jhrzdate,jhjprice,jhnetjprice,jhcount,jhcost,jhnetcost)
|
|
|
select a.billno,a.orgcode,a.shopcode,case when t.billtype=''7'' then ''1'' else ''0'' end,a.rzdate,
|
|
|
b.plucode,b.pluname,b.jprice,b.netjprice,b.jtaxrate,b.zpcount,b.cost,b.netcost,'''',0,0,0,0,0
|
|
|
from t_pay_bill t,t_dist_head a,t_dist_body b
|
|
|
where t.billno=a.billno and a.billno=b.billno and t.billtype in (''6'',''7'')
|
|
|
and a.rzdate between '''+@sbgndate+''' and '''+@senddate+'''
|
|
|
and exists(select * from t_shop where orgcode=a.orgcode and finacode<>t.finacode)
|
|
|
and exists(select * from t_user_org where orgcode=a.orgcode and usercode='''+@ps_SysUserCode+''')
|
|
|
and exists(select * from t_user_org where orgcode=a.shopcode and usercode='''+@ps_SysUserCode+''')'
|
|
|
if @sfinacode<>''
|
|
|
set @ssql=@ssql+' and exists(select * from t_shop where orgcode=a.shopcode and finacode in ('''+@sfinacode+'''))'
|
|
|
if @sshopcode<>''
|
|
|
set @ssql=@ssql+' and a.shopcode in ('''+@sshopcode+''')'
|
|
|
if @sorgcode<>''
|
|
|
set @ssql=@ssql+' and t.orgcode in ('''+@sorgcode+''')'
|
|
|
if @splucode<>''
|
|
|
set @ssql=@ssql+' and b.plucode in ('''+@splucode+''')'
|
|
|
if isnull(@pbilltype,'')='0'
|
|
|
set @ssql=@ssql+' and t.billtype=''6'''
|
|
|
if isnull(@pbilltype,'')='1'
|
|
|
set @ssql=@ssql+' and t.billtype=''7'''
|
|
|
else if isnull(@pbilltype,'')='2'
|
|
|
set @ssql=@ssql+' and 0=1'
|
|
|
exec(@ssql)
|
|
|
|
|
|
set @ssql='update t set jhrzdate=a.rzdate,jhjprice=b.jprice,jhnetjprice=b.netjprice,staxrate=b.jtaxrate,jhcount=b.counts,jhcost=b.cost,jhnetcost=b.netcost
|
|
|
from ##tmpsubsettle t,t_accept_head a,t_accept_body b
|
|
|
where t.billno=a.orderno and a.billno=b.billno and t.plucode=b.plucode
|
|
|
and isnull(a.rzdate,'''')<>'''' and t.billtype=''0'' and a.billtype=''3'''
|
|
|
exec(@ssql)
|
|
|
|
|
|
set @ssql='update t set jhrzdate=a.rzdate,jhjprice=b.jprice,jhnetjprice=b.netjprice,staxrate=b.jtaxrate,jhcount=-b.counts,jhcost=-b.cost,jhnetcost=-b.netcost
|
|
|
from ##tmpsubsettle t,t_return_head a,t_return_body b
|
|
|
where t.billno=a.billno and a.billno=b.billno and t.plucode=b.plucode
|
|
|
and isnull(a.rzdate,'''')<>'''' and t.billtype=''1''
|
|
|
and not exists(select 1
|
|
|
from t_distdiffer_head tdh,t_distdiffer_body tdb
|
|
|
where tdh.billno=tdb.billno and isnull(tdh.rzdate,'''')<>'''' and tdb.genbillno=t.billno)'
|
|
|
exec(@ssql)
|
|
|
|
|
|
set @ssql='insert into ##tmpsubsettle(billno,orgcode,shopcode,billtype,rzdate,plucode,pluname,jprice,netjprice,staxrate,
|
|
|
zpcount,cost,netcost,jhjprice,jhnetjprice,jhcount,jhcost,jhnetcost)
|
|
|
select a.billno,''C009'',t.orgcode,''2'',a.rzdate,b.plucode,b.pluname,
|
|
|
b.newjprice-b.jprice,b.newnetjprice-b.netjprice,b.jtaxrate,b.tzcount,b.cjcost,b.netcjcost,0,0,0,0,0
|
|
|
from t_pay_bill t,t_adjbuyprice_head a,t_adjbuyprice_body b
|
|
|
where t.billno=a.billno and a.billno=b.billno and t.billtype in (''8'')
|
|
|
and a.rzdate between '''+@sbgndate+''' and '''+@senddate+'''
|
|
|
and exists(select * from t_shop where orgcode=''C009'' and finacode<>t.finacode)
|
|
|
and exists(select * from t_user_org where orgcode=a.orgcode and usercode='''+@ps_SysUserCode+''')'
|
|
|
if @sfinacode<>''
|
|
|
set @ssql=@ssql+' and exists(select * from t_shop where orgcode=a.OrgCode and finacode in ('''+@sfinacode+'''))'
|
|
|
if @sshopcode<>''
|
|
|
set @ssql=@ssql+' and a.orgcode in ('''+@sshopcode+''')'
|
|
|
if @sorgcode<>''
|
|
|
set @ssql=@ssql+' and t.orgcode in ('''+@sorgcode+''')'
|
|
|
if @splucode<>''
|
|
|
set @ssql=@ssql+' and b.plucode in ('''+@splucode+''')'
|
|
|
if isnull(@pbilltype,'')='0'
|
|
|
set @ssql=@ssql+' and 0=1'
|
|
|
if isnull(@pbilltype,'')='1'
|
|
|
set @ssql=@ssql+' and 0=1'
|
|
|
else if isnull(@pbilltype,'')='2'
|
|
|
set @ssql=@ssql+' and t.billtype=''8'''
|
|
|
exec(@ssql)
|
|
|
|
|
|
-----11-23ÈÕ£¬Ôö¼ÓSkuµÄµ¥Î»ÐÅÏ¢
|
|
|
set @ssql='select b.finacode,c.finaname,a.shopcode,b.orgname as shopname,
|
|
|
case a.billtype when ''1'' then ''ÅäËÍÍË»õµ¥'' when ''2'' then ''ÅäËͽø¼Ûµ÷Õûµ¥'' else ''ÅäË͵¥'' end as c_billtype,a.billno,
|
|
|
a.plucode,a.pluname,f.clscode,f.clsname,a.staxrate,a.rzdate,a.zpcount,a.jprice,a.netjprice,a.cost,a.netcost,a.cost-a.netcost as taxamt,
|
|
|
a.jhrzdate,a.jhcount,a.jhjprice,a.jhnetjprice,a.jhcost,a.jhnetcost,a.jhcost-a.jhnetcost as jhtaxamt,a.orgcode,g.orgname,d.unit
|
|
|
from ##tmpsubsettle a
|
|
|
left join t_shop b on a.shopcode=b.orgcode
|
|
|
left join t_financial_body c on b.finacode=c.finacode
|
|
|
left join t_plu d on a.plucode=d.plucode
|
|
|
left join t_gclass e on d.clscode=e.clscode
|
|
|
left join t_gclass f on e.uppercode1=f.clscode
|
|
|
left join t_shop g on a.orgcode=g.orgcode
|
|
|
order by b.finacode,a.shopcode,a.billtype,a.plucode'
|
|
|
exec(@ssql)
|
|
|
|
|
|
if exists(select name from tempdb..sysobjects where name='##tmpsubsettle' and xtype='u')
|
|
|
drop table ##tmpsubsettle
|
|
|
end
|
|
|
go
|
|
|
|
|
|
/*×ܲ¿Å̵ã½á¹û±¨±í*/
|
|
|
if exists(select * from sysobjects where name='p_rpt_cykrpt' and xtype='p')
|
|
|
drop procedure p_rpt_cykrpt
|
|
|
go
|
|
|
|
|
|
create procedure p_rpt_cykrpt
|
|
|
(
|
|
|
@pregncode varchar(1000),
|
|
|
@pareacode varchar(1000),
|
|
|
@porgcode varchar(1000),
|
|
|
@pbgndate varchar(10),
|
|
|
@penddate varchar(10),
|
|
|
@pykreason varchar(2),
|
|
|
@pplucode varchar(2000),
|
|
|
@ps_SysUserCode varchar(20)
|
|
|
)
|
|
|
as
|
|
|
declare @ssql varchar(8000)
|
|
|
declare @sregncode varchar(1000)
|
|
|
declare @sareacode varchar(1000)
|
|
|
declare @sorgcode varchar(1000)
|
|
|
declare @splucode varchar(1000)
|
|
|
declare @sbgndate varchar(10)
|
|
|
declare @senddate varchar(10)
|
|
|
begin
|
|
|
set @sregncode=replace(@sregncode,',',''',''')
|
|
|
set @sareacode=replace(@sareacode,',',''',''')
|
|
|
set @sorgcode=replace(@porgcode,',',''',''')
|
|
|
set @splucode=replace(@pplucode,',',''',''')
|
|
|
set @sbgndate=@pbgndate
|
|
|
set @senddate=@penddate
|
|
|
if isnull(@sbgndate,'')=''
|
|
|
set @sbgndate='2023-08-01'
|
|
|
if isnull(@senddate,'')=''
|
|
|
set @senddate='2099-12-31'
|
|
|
|
|
|
set @ssql='select e.areaname as regnname,d.areaname,a.orgcode,c.orgname,a.billno,a.accdate as rzdate,
|
|
|
b.plucode,f.pluname,h.clscode,h.clsname,b.jtaxrate,b.bookcount,b.realcount,b.ykcount,
|
|
|
b.netjprice,b.yknetcost,b.price,b.yktotal,case when len(b.remark)=2 then b.remark+''-''+i.name else b.remark end as ykreason,b.describe
|
|
|
from t_differ_head a join t_differ_body b on a.billno=b.billno
|
|
|
left join t_shop c on a.orgcode=c.orgcode
|
|
|
left join t_area d on c.areacode=d.areacode
|
|
|
left join t_area e on d.uppercode1=e.areacode
|
|
|
left join t_plu f on b.plucode=f.plucode
|
|
|
left join t_gclass g on f.clscode=g.clscode
|
|
|
left join t_gclass h on g.uppercode1=h.clscode
|
|
|
left join (select q.item_value,q.name from dict_data p,dict_data_item q where p.id=q.p_id and p.code=''PD0006'') i on b.remark=i.item_value
|
|
|
where a.accdate between '''+@sbgndate+''' and '''+@senddate+''' and a.billtype in (''0'',''1'',''3'')
|
|
|
and exists(select * from t_user_org where orgcode=a.orgcode and usercode='''+@ps_SysUserCode+''')'
|
|
|
if @sregncode<>''
|
|
|
set @ssql=@ssql+' and exists(select * from t_shop m,t_area n where m.areacode=n.areacode and m.orgcode=a.orgcode and n.uppercode1 in ('''+@sregncode+'''))'
|
|
|
if @sareacode<>''
|
|
|
set @ssql=@ssql+' and exists(select * from t_shop where orgcode=a.orgcode and areacode in ('''+@sareacode+'''))'
|
|
|
if @sorgcode<>''
|
|
|
set @ssql=@ssql+' and a.orgcode in ('''+@sorgcode+''')'
|
|
|
if @splucode<>''
|
|
|
set @ssql=@ssql+' and b.plucode in ('''+@splucode+''')'
|
|
|
if isnull(@pykreason,'')<>''
|
|
|
set @ssql=@ssql+' and b.remark=''' + @pykreason + ''''
|
|
|
set @ssql=@ssql+' order by e.areacode,d.areacode,a.orgcode,b.plucode'
|
|
|
exec(@ssql)
|
|
|
end
|
|
|
go
|
|
|
|
|
|
/*ÓÍÕ¾Å̵ã½á¹û±¨±í*/
|
|
|
if exists(select * from sysobjects where name='p_rpt_sykrpt' and xtype='p')
|
|
|
drop procedure p_rpt_sykrpt
|
|
|
go
|
|
|
|
|
|
create procedure p_rpt_sykrpt
|
|
|
(
|
|
|
@pregncode varchar(1000),
|
|
|
@pareacode varchar(1000),
|
|
|
@porgcode varchar(1000),
|
|
|
@pbgndate varchar(10),
|
|
|
@penddate varchar(10),
|
|
|
@pykreason varchar(2),
|
|
|
@pplucode varchar(2000),
|
|
|
@ps_SysUserCode varchar(20)
|
|
|
)
|
|
|
as
|
|
|
declare @ssql varchar(8000)
|
|
|
declare @sregncode varchar(1000)
|
|
|
declare @sareacode varchar(1000)
|
|
|
declare @sorgcode varchar(1000)
|
|
|
declare @splucode varchar(1000)
|
|
|
declare @sbgndate varchar(10)
|
|
|
declare @senddate varchar(10)
|
|
|
begin
|
|
|
set @sregncode=replace(@sregncode,',',''',''')
|
|
|
set @sareacode=replace(@sareacode,',',''',''')
|
|
|
set @sorgcode=replace(@porgcode,',',''',''')
|
|
|
set @splucode=replace(@pplucode,',',''',''')
|
|
|
set @sbgndate=@pbgndate
|
|
|
set @senddate=@penddate
|
|
|
if isnull(@sbgndate,'')=''
|
|
|
set @sbgndate='2023-08-01'
|
|
|
if isnull(@senddate,'')=''
|
|
|
set @senddate='2099-12-31'
|
|
|
|
|
|
set @ssql='select e.areaname as regnname,d.areaname,a.orgcode,c.orgname,a.billno,a.rzdate,
|
|
|
b.plucode,f.pluname,h.clscode,h.clsname,b.jtaxrate,b.bookcount,b.realcount,b.ykcount,
|
|
|
b.price,b.yktotal,case when len(b.remark)=2 then b.remark+''-''+i.name else b.remark end as ykreason,b.describe
|
|
|
from t_differ_head a join t_differ_body b on a.billno=b.billno
|
|
|
left join t_shop c on a.orgcode=c.orgcode
|
|
|
left join t_area d on c.areacode=d.areacode
|
|
|
left join t_area e on d.uppercode1=e.areacode
|
|
|
left join t_plu f on b.plucode=f.plucode
|
|
|
left join t_gclass g on f.clscode=g.clscode
|
|
|
left join t_gclass h on g.uppercode1=h.clscode
|
|
|
left join (select q.item_value,q.name from dict_data p,dict_data_item q where p.id=q.p_id and p.code=''PD0006'') i on b.remark=i.item_value
|
|
|
where a.rzdate between '''+@sbgndate+''' and '''+@senddate+''' and a.billtype in (''0'',''1'')
|
|
|
and exists(select * from t_user_org where orgcode=a.orgcode and usercode='''+@ps_SysUserCode+''')'
|
|
|
if @sregncode<>''
|
|
|
set @ssql=@ssql+' and exists(select * from t_shop m,t_area n where m.areacode=n.areacode and m.orgcode=a.orgcode and n.uppercode1 in ('''+@sregncode+'''))'
|
|
|
if @sareacode<>''
|
|
|
set @ssql=@ssql+' and exists(select * from t_shop where orgcode=a.orgcode and areacode in ('''+@sareacode+'''))'
|
|
|
if @sorgcode<>''
|
|
|
set @ssql=@ssql+' and a.orgcode in ('''+@sorgcode+''')'
|
|
|
if @splucode<>''
|
|
|
set @ssql=@ssql+' and b.plucode in ('''+@splucode+''')'
|
|
|
if isnull(@pykreason,'')<>''
|
|
|
set @ssql=@ssql+' and b.remark=''' + @pykreason + ''''
|
|
|
set @ssql=@ssql+' order by e.areacode,d.areacode,a.orgcode,b.plucode'
|
|
|
exec(@ssql)
|
|
|
end
|
|
|
go
|
|
|
|
|
|
/*ÈÕ½áÇ°Êý¾Ý¼ì²é*/
|
|
|
---½¨Á¢ÁËÒ»¸ö´æ´¢¹ý³Ì£¬Ã¿ÌìÁ賿5µã×óÓÒ·þÎñÆ÷ÔËÐС£
|
|
|
if exists(select * from sysobjects where name='p_rpt_rj_overqry' and xtype='p')
|
|
|
drop procedure p_rpt_rj_overqry
|
|
|
go
|
|
|
|
|
|
create procedure p_rpt_rj_overqry
|
|
|
----=====================
|
|
|
------ÿÌìÈÕ½áÉú³É
|
|
|
------¹ý³ÌÏÈɾ³ýËùÓÐÊý¾Ý£¬ºóÔÙ²åÈëδÈÕ½áÓÍÕ¾µÄÊý¾Ý¡£
|
|
|
----=====================
|
|
|
as
|
|
|
declare @ssql varchar(8000)
|
|
|
declare @sfilt varchar(8000)
|
|
|
declare @stmpdate varchar(10)
|
|
|
declare @thismonth varchar(6)
|
|
|
declare @lastmonth varchar(6)
|
|
|
begin
|
|
|
set @stmpdate=convert(varchar(10),getdate()-1,120)
|
|
|
set @thismonth=substring(@stmpdate,1,4)+substring(@stmpdate,6,2)
|
|
|
set @stmpdate=convert(varchar(10),dateadd(month,-1,getdate()),120)
|
|
|
set @lastmonth=substring(@stmpdate,1,4)+substring(@stmpdate,6,2)
|
|
|
|
|
|
set @sfilt=' and exists(select * from t_shop where orgcode=a.orgcode and status=''1'')'
|
|
|
|
|
|
if not exists(select name from sysobjects where name='t_tmpoverqry' and xtype='u')
|
|
|
create table t_tmpoverqry (
|
|
|
orgcode varchar(10),errtype varchar(2),plucode varchar(20),xscount numeric(19,4),kccount numeric(19,4))
|
|
|
|
|
|
------ÏÈɾ³ý±íµÄÊý¾Ý
|
|
|
truncate table t_tmpoverqry
|
|
|
----ÀàÐÍ0-±¾ÈÕ²»´æÔÚÏúÊÛÁ÷Ë®£¬ÐèÒªÕ¾¼¶ÔËά½øÐÐÅŲéÓëÉÏ´«
|
|
|
set @ssql='insert into t_tmpoverqry(orgcode,errtype,plucode,xscount,kccount)
|
|
|
select a.orgcode,''0'','''',0,0
|
|
|
from t_shop a
|
|
|
where orgtype<>''2'' and overdate<convert(varchar(10),getdate()-1,120)
|
|
|
and not exists(select * from t_int_flow_total where orgcode=a.orgcode and accdate>a.overdate)'
|
|
|
set @ssql=@ssql+@sfilt
|
|
|
exec(@ssql)
|
|
|
|
|
|
----ÀàÐÍ1-±¾ÈÕ²»´æÔÚÖ§¸¶ÈÕ±¨£¬ÐèÒªÕ¾¼¶ÔËά½øÐÐÅŲéÓëÉÏ´«
|
|
|
set @ssql='insert into t_tmpoverqry(orgcode,errtype,plucode,xscount,kccount)
|
|
|
select a.orgcode,''1'','''',0,0
|
|
|
from t_shop a
|
|
|
where orgtype<>''2'' and overdate<convert(varchar(10),getdate()-1,120)'
|
|
|
if exists(select name from sysobjects where name='t_int_flow_pay_deily_'+@thismonth and xtype='u') or exists(select name from sysobjects where name='t_int_flow_pay_deily_'+@lastmonth and xtype='u')
|
|
|
begin
|
|
|
set @ssql=@ssql+' and not exists(select * from ('
|
|
|
if exists(select name from sysobjects where name='t_int_flow_pay_deily_'+@thismonth and xtype='u')
|
|
|
set @ssql=@ssql+' select * from t_int_flow_pay_deily_'+@thismonth+' where werks=a.orgcode and business_date>a.overdate'
|
|
|
if exists(select name from sysobjects where name='t_int_flow_pay_deily_'+@lastmonth and xtype='u')
|
|
|
set @ssql=@ssql+' union select * from t_int_flow_pay_deily_'+@lastmonth+' where werks=a.orgcode and business_date>a.overdate'
|
|
|
set @ssql=@ssql+') b)'
|
|
|
end
|
|
|
set @ssql=@ssql+@sfilt
|
|
|
exec(@ssql)
|
|
|
|
|
|
|
|
|
----2-Á÷Ë®ÖÐÓÐÉÌÆ·²»´æÔÚ¡£
|
|
|
set @ssql='insert into t_tmpoverqry(orgcode,errtype,plucode,xscount,kccount)
|
|
|
select a.orgcode,''2'',a.plucode,sum(a.pluqty),0
|
|
|
from t_int_flow_item a
|
|
|
where not exists(select * from t_plu where plucode=a.plucode)
|
|
|
and (plucode not like ''298%'' or plucode in (''298213'',''298214'',''298215'')) and plucode not like ''299%'' and plucode not in (''300809'',''99999999000'') and plucode <> ''0''
|
|
|
and exists(select * from t_shop where orgcode=a.orgcode and overdate<a.accdate)'
|
|
|
set @ssql=@ssql+@sfilt
|
|
|
set @ssql=@ssql+' group by a.orgcode,a.plucode,a.pluname'
|
|
|
exec(@ssql)
|
|
|
|
|
|
----3-Á÷Ë®ÖÐÉÌÆ·µÄÖ÷¹©Ó¦ÉÌ»òÃŵ깩ӦÉÌÐÅϢΪ¿Õ¡£
|
|
|
set @ssql='insert into t_tmpoverqry(orgcode,errtype,plucode,xscount,kccount)
|
|
|
select a.orgcode,''3'',a.plucode,0,0
|
|
|
from t_int_flow_item a,t_plu b,t_plu_org c
|
|
|
where a.plucode=b.plucode and a.plucode=c.plucode and a.orgcode=c.orgcode
|
|
|
and (a.plucode not like ''298%'' or a.plucode in (''298213'',''298214'',''298215'')) and a.plucode not like ''299%'' and a.plucode not in (''300809'',''99999999000'') and a.plucode <> ''0''
|
|
|
and (isnull(c.supcode,'''')<>'''' and not exists(select * from t_supplier where supcode=c.supcode)
|
|
|
or isnull(b.supcode,'''')<>'''' and not exists(select * from t_supplier where supcode=b.supcode))
|
|
|
and exists(select * from t_shop where orgcode=a.orgcode and overdate<a.accdate)'
|
|
|
set @ssql=@ssql+@sfilt
|
|
|
exec(@ssql)
|
|
|
|
|
|
|
|
|
----3-Á÷Ë®ÖÐÉÌÆ·µÄÖ÷¹©Ó¦É̺ÍÃŵ깩ӦÉÌÐÅÏ¢¶¼Îª¿Õ¡£
|
|
|
set @ssql='insert into t_tmpoverqry(orgcode,errtype,plucode,xscount,kccount)
|
|
|
select a.orgcode,''3'',a.plucode,0,0
|
|
|
from t_int_flow_item a,t_plu b,t_plu_org c
|
|
|
where a.plucode=b.plucode and a.plucode=c.plucode and a.orgcode=c.orgcode
|
|
|
and (a.plucode not like ''298%'' or a.plucode in (''298213'',''298214'',''298215'')) and a.plucode not like ''299%'' and a.plucode not in (''300809'',''99999999000'') and a.plucode <> ''0''
|
|
|
and (isnull(c.supcode,'''')='''' and isnull(b.supcode,'''')='''' )
|
|
|
and exists(select * from t_shop where orgcode=a.orgcode and overdate<a.accdate)
|
|
|
and SUBSTRING( b.clscode,1,2)= ''20'' '
|
|
|
set @ssql=@ssql+@sfilt
|
|
|
exec(@ssql)
|
|
|
|
|
|
----4-´æÔÚ¸º¿â´æÊý¾Ý¡£
|
|
|
set @ssql='insert into t_tmpoverqry(orgcode,errtype,plucode,xscount,kccount)
|
|
|
select a.orgcode,''4'',a.plucode,isnull(c.packpluqty,0)+isnull(d.pluqty,0),a.gcount+a.ccount
|
|
|
from t_plu_org a
|
|
|
left join t_plu b on a.plucode=b.plucode
|
|
|
left join (select i.orgcode,p.plucode,sum(i.pluqty*p.counts) packpluqty from t_plupack p,t_int_flow_item i
|
|
|
where p.packcode=i.plucode and exists(select * from t_shop where orgcode=i.orgcode and overdate<i.accdate) group by p.plucode,i.orgcode) c
|
|
|
on a.plucode=c.plucode and a.orgcode=c.orgcode
|
|
|
left join (select orgcode,plucode,sum(pluqty) as pluqty from t_int_flow_item j where exists(select * from t_shop where orgcode=j.orgcode and overdate<j.accdate)
|
|
|
group by plucode,orgcode) d on a.plucode=d.plucode and a.orgcode=d.orgcode
|
|
|
where b.plutype<>''3'' and b.plutype<>''4'' and a.mngstock=''1''
|
|
|
and a.gcount+a.ccount-isnull(c.packpluqty,0)-isnull(d.pluqty,0)<0
|
|
|
and isnull(c.packpluqty,0)+isnull(d.pluqty,0)<>0
|
|
|
and not exists(select * from t_mix_product where plucode=a.plucode)'
|
|
|
set @ssql=@ssql+@sfilt
|
|
|
exec(@ssql)
|
|
|
|
|
|
------2024-01-31,´æÔÚSCLµÄ¿ÇÅÆÖйúµÄʵʱÁ÷Ë®¶ªÊ§µÄÎÊÌ⣬µ¼ÖÂÈÕ½á´æÔÚ¸º¿â´æÎÞ·¨Èսᡣ
|
|
|
set @ssql=' Insert Into t_tmpoverqry(orgcode,errtype,plucode,xscount,kccount)
|
|
|
Select OrgCode,''4'',plucode,xscount ,kccount from t_over_error_detail Ed
|
|
|
Where Not Exists (Select * From t_tmpoverqry T where T.orgcode=Ed.orgcode And T.plucode=Ed.plucode) '
|
|
|
exec(@ssql)
|
|
|
------2024-01-31,´æÔÚSCLµÄ¿ÇÅÆÖйúµÄʵʱÁ÷Ë®¶ªÊ§µÄÎÊÌ⣬µ¼ÖÂÈÕ½á´æÔÚ¸º¿â´æÎÞ·¨Èսᡣ
|
|
|
|
|
|
|
|
|
----5-BOM´æÔÚ¸º¿â´æÊý¾Ý¡£
|
|
|
---´æÔÚ°´µ¥¸ö³ÉÆ·¿´£¬ÔÁÏ¿â´æ¹»£¬¼ÓÆðÀ´¾Í²»¹»ÁË¡£2024-01-01¸ù¾ÝÈÕ½áµÄ¿ØÖÆÂß¼½øÐбàд±¨±íÖС£
|
|
|
set @ssql=' insert into t_tmpoverqry(orgcode,errtype,plucode,xscount,kccount)
|
|
|
select a.orgcode,''5'',a.plucode,a.xscount,g.gcount+g.ccount as kccount
|
|
|
from (
|
|
|
select d.orgcode,e.plucode,sum(d.mixcnt*e.counts) as xscount
|
|
|
from (
|
|
|
select orgcode,mixcode,mixcnt
|
|
|
from (
|
|
|
select f.orgcode,b.mixcode,f.plucode,ceiling(sum(f.pluqty)/b.counts) as mixcnt,
|
|
|
row_number() over(partition by f.orgcode,b.mixcode,f.plucode order by ceiling(sum(f.pluqty)/b.counts) desc) as rowid
|
|
|
from t_int_flow_item f,t_mix_product b
|
|
|
where f.plucode=b.plucode
|
|
|
---and a.accdate=:accdate and a.orgcode=:orgcode
|
|
|
And exists(select * from t_shop where orgcode=f.orgcode and overdate<f.accdate)
|
|
|
group by f.orgcode,b.mixcode,f.plucode,b.counts
|
|
|
) c
|
|
|
where rowid=1
|
|
|
) d, t_mix_stuff e
|
|
|
where d.mixcode=e.mixcode
|
|
|
group by d.orgcode,e.plucode
|
|
|
) a,t_plu_org g
|
|
|
where a.plucode=g.plucode
|
|
|
and a.orgcode=g.orgcode
|
|
|
and a.xscount>g.gcount+g.ccount'
|
|
|
set @ssql=@ssql+@sfilt
|
|
|
exec(@ssql)
|
|
|
|
|
|
----6-ÈÕÁ÷Ë®½ð¶îÓëÖ§¸¶ÈÕ±¨½ð¶î²»Ò»Ö¡£Ôö¼ÓÏúÊÛÈÕ±¨²»µÈÓÚÖ§¸¶ÈÕ±¨µÄ´íÎóÈÕÖ¾ ,´íÎóÀàÐÍΪ6
|
|
|
set @ssql='insert into t_tmpoverqry(orgcode,errtype,plucode,xscount,kccount)
|
|
|
Select orgcode,''6'',overdate,0,0
|
|
|
from t_over_error a
|
|
|
where Exists (Select * from t_shop p
|
|
|
where a.orgcode=p.orgcode
|
|
|
and a.overdate>p.overdate
|
|
|
and a.errreason like ''%½ð¶î²»Ò»ÖÂ%'') '
|
|
|
set @ssql=@ssql+@sfilt
|
|
|
exec(@ssql)
|
|
|
|
|
|
----7-ÆäÖ÷¹©Ó¦ÉÌ»òÃŵ깩ӦÉÌÐÅϢΪ¿Õ£¬ÐèÒªÁªÏµ×ܲ¿ÒµÎñÕýȷά»¤£¡ ,´íÎóÀàÐÍΪ7
|
|
|
set @ssql='insert into t_tmpoverqry(orgcode,errtype,plucode,xscount,kccount)
|
|
|
Select orgcode,''7'',plucode,0,0
|
|
|
from t_flow_item a
|
|
|
Where a.plucode not in (Select plucode from t_plu where supcode<>'''' )
|
|
|
And not exists (Select * From t_plu_org tp where tp.orgcode=a.orgcode and tp.supcode<>'''')'
|
|
|
set @ssql=@ssql+@sfilt
|
|
|
exec(@ssql)
|
|
|
|
|
|
----8-ÉÌƷûÓоӪȨÏÞ
|
|
|
set @ssql='insert into t_tmpoverqry(orgcode,errtype,plucode,xscount,kccount)
|
|
|
select orgcode,''8'',plucode,sum(pluqty) as xscount,0 as kccount
|
|
|
from t_int_flow_item a
|
|
|
where exists(select plucode from t_plu_org where orgcode = a.orgcode and plucode = a.plucode and isright=''0'')
|
|
|
and exists(select * from t_shop where orgcode=a.orgcode and overdate<a.accdate)'
|
|
|
set @ssql=@ssql+@sfilt
|
|
|
set @ssql=@ssql+' group by a.orgcode,a.plucode'
|
|
|
exec(@ssql)
|
|
|
|
|
|
end
|
|
|
go
|
|
|
|
|
|
if exists(select * from sysobjects where name='p_rpt_overqry' and xtype='p')
|
|
|
drop procedure p_rpt_overqry
|
|
|
go
|
|
|
|
|
|
create procedure p_rpt_overqry
|
|
|
(
|
|
|
@pregncode varchar(1000),
|
|
|
@pareacode varchar(1000),
|
|
|
@porgcode varchar(1000),
|
|
|
@ps_SysUserCode varchar(20)
|
|
|
)
|
|
|
as
|
|
|
declare @ssql varchar(8000)
|
|
|
declare @sregncode varchar(1000)
|
|
|
declare @sareacode varchar(1000)
|
|
|
declare @sorgcode varchar(1000)
|
|
|
declare @sfilt varchar(8000)
|
|
|
declare @stmpdate varchar(10)
|
|
|
declare @thismonth varchar(6)
|
|
|
declare @lastmonth varchar(6)
|
|
|
begin
|
|
|
--set @sregncode=isnull(@pregncode,'')
|
|
|
--set @sareacode=isnull(@pareacode,'')
|
|
|
--set @sorgcode=isnull(@porgcode,'')
|
|
|
set @sregncode=replace(@pregncode,',',''',''')
|
|
|
set @sareacode=replace(@pareacode,',',''',''')
|
|
|
set @sorgcode=replace(@porgcode,',',''',''')
|
|
|
--set @stmpdate=convert(varchar(10),getdate()-1,120)
|
|
|
--set @thismonth=substring(@stmpdate,1,4)+substring(@stmpdate,6,2)
|
|
|
---set @stmpdate=convert(varchar(10),dateadd(month,-1,getdate()),120)
|
|
|
--set @lastmonth=substring(@stmpdate,1,4)+substring(@stmpdate,6,2)
|
|
|
|
|
|
/*
|
|
|
---2024-01-24 ÒѾͨ¹ý´æ´¢¹ý³ÌÉú³ÉÎïÀí±íÁË£¬¹Ê²»ÐèÒªÔÙ´ÎÉú³É
|
|
|
|
|
|
if (isnull(@sregncode,'')='' and isnull(@sareacode,'')='' and isnull(@sorgcode,'')='')
|
|
|
begin
|
|
|
raiserror('²éѯ²ÎÊý²»ÔÊÐíÈ«²¿Îª¿Õ',16,1)
|
|
|
return(1)
|
|
|
End
|
|
|
*/
|
|
|
Set @sfilt=' where 1=1 '
|
|
|
set @sfilt=@sfilt+' and exists(select * from t_user_org where orgcode=a.orgcode and usercode='''+@ps_SysUserCode+''')'
|
|
|
|
|
|
if isNull(@sregncode,'')<>''
|
|
|
set @sfilt=@sfilt+' and exists(select * from t_shop m,t_area n where m.areacode=n.areacode and m.orgcode=a.orgcode and n.uppercode1 in ('''+@sregncode+'''))'
|
|
|
if isnull(@sareacode,'')<>''
|
|
|
set @sfilt=@sfilt+' and exists(select * from t_shop where orgcode=a.orgcode and areacode in ('''+@sareacode+'''))'
|
|
|
if isnull(@sorgcode,'')<>''
|
|
|
set @sfilt=@sfilt+' and a.orgcode in ('''+@sorgcode+''')'
|
|
|
|
|
|
----2024-04-24 ´æÔÚBOMÉÌÆ·¸º¿â´æ£¬Í¬Ê±¿ÉÄÜÀàÐÍ=¡°errtype=4¡±µÄ¸º¿â´æÊý¾Ý£¬È¡×î´óµÄÀàÐÍΪ5µÄÊý¾Ý£ºmax(errtype)
|
|
|
set @ssql='select (select Areaname From t_area B,t_shop p where B.areacode=substring(p.areacode,1,2) and p.orgcode =a.orgcode ) as regnname,
|
|
|
(select Areaname From t_area B,t_shop p where B.areacode=p.areacode and p.orgcode =a.orgcode ) as Areaname,
|
|
|
a.orgcode,(Select OrgName From t_Shop P where A.Orgcode=p.orgcode) as OrgName,
|
|
|
(Select overdate From t_shop p where p.orgcode=a.orgcode) as overdate,
|
|
|
case errtype when ''0'' then ''±¾Õ¾²»´æÔÚ·ÇÓÍÈÕ½áÊý¾Ý£¬ÇëÓʼþÁªÏµÈ«Õ¾ÔËάÖØÐÂÉÏ´«ÈÕ½áÊý¾Ý£¡''
|
|
|
when ''1'' then ''±¾Õ¾²»´æÔÚ·ÇÓÍÈÕ½áÊý¾Ý£¬ÇëÓʼþÁªÏµÈ«Õ¾ÔËάÖØÐÂÉÏ´«ÈÕ½áÊý¾Ý£¡''
|
|
|
when ''2'' then ''Á÷Ë®ÖÐÓÐÉÌÆ·²»´æÔÚ£¬ÁªÏµ×ܲ¿ÒµÎñÕýȷά»¤£¡''
|
|
|
when ''3'' then ''Á÷Ë®ÖÐÉÌÆ·Ö÷¹©Ó¦ÉÌ»òÃŵ깩ӦÉÌÐÅÏ¢²»´æÔÚ£¬ÁªÏµ×ܲ¿ÒµÎñÕýȷά»¤£¡''
|
|
|
when ''4'' then ''´æÔÚ¸º¿â´æÊý¾Ý£¨¿â´æ²»¹»¿Û¼õ£©£¬¼ì²éµ½»õÊÇ·ñÑéÊÕ£¿»òÕßÁÙÅ̵÷Õû£¡''
|
|
|
when ''5'' then ''BOM´æÔÚ¸º¿â´æÊý¾Ý£¬¼ì²éµ½»õÊÇ·ñÑéÊÕ»òÁÙÅ̵÷Õû£¡''
|
|
|
when ''6'' then a.plucode+''ÈÕÁ÷Ë®½ð¶îÓëÖ§¸¶ÈÕ±¨½ð¶î²»Ò»Ö£¡''
|
|
|
When ''7'' then a.plucode+''ÆäÖ÷¹©Ó¦ÉÌ»òÃŵ깩ӦÉÌÐÅϢΪ¿Õ£¬ÁªÏµ×ܲ¿ÒµÎñÕýȷά»¤£¡''
|
|
|
when ''8'' then ''Á÷Ë®ÖÐÓÐÉÌƷûÓоӪȨÏÞ£¬ÁªÏµ×ܲ¿ÒµÎñÕýȷά»¤£¡''
|
|
|
Else ''ÆäËû''
|
|
|
End as r_errtype,
|
|
|
case errtype when ''6'' then '''' else a.plucode end as plucode ,
|
|
|
(Select pluName From t_plu p Where plucode =a.plucode ) as pluname,a.xscount,a.kccount,a.xscount-a.kccount as diffcount
|
|
|
from (Select orgcode ,max(errtype) as errtype ,plucode,xscount ,kccount
|
|
|
from t_tmpoverqry group by orgcode ,plucode,xscount ,kccount ) a
|
|
|
'
|
|
|
Set @ssql= @ssql+@sfilt +' order by a.orgcode,a.plucode '
|
|
|
---order by d.areacode,c.areacode,a.orgcode,a.plucode
|
|
|
--print @ssql
|
|
|
---print ('Insert into t_tmp_Rptqry(QrySQL) Value(''' +@ssql+'''')
|
|
|
|
|
|
exec(@ssql)
|
|
|
|
|
|
end
|
|
|
go
|
|
|
|
|
|
|
|
|
/*BOSͨѶÈÕÖ¾*/
|
|
|
if exists(select * from sysobjects where name='p_rpt_int_log_bos' and xtype='p')
|
|
|
drop procedure p_rpt_int_log_bos
|
|
|
go
|
|
|
|
|
|
create procedure p_rpt_int_log_bos
|
|
|
(
|
|
|
@porgcode varchar(1000),
|
|
|
@pbgndate varchar(10),
|
|
|
@penddate varchar(10),
|
|
|
@plogtype varchar(1)
|
|
|
)
|
|
|
as
|
|
|
declare @ssql varchar(8000)
|
|
|
declare @sorgcode varchar(1000)
|
|
|
declare @sbgndate varchar(10)
|
|
|
declare @senddate varchar(10)
|
|
|
begin
|
|
|
set @sorgcode=replace(@porgcode,',',''',''')
|
|
|
set @sbgndate=@pbgndate
|
|
|
set @senddate=@penddate
|
|
|
if isnull(@sbgndate,'')=''
|
|
|
set @sbgndate='2023-08-01'
|
|
|
if isnull(@senddate,'')=''
|
|
|
set @senddate='2099-12-31'
|
|
|
|
|
|
set @ssql='select b.itemcode,b.itemname,c.orgcode,c.orgname,a.logdate,a.logtime,case a.logtype when ''S'' then ''³É¹¦'' else ''ʧ°Ü'' end as logtype,a.logmsg,a.sessioncode
|
|
|
from t_int_log a, t_int_item b, t_shop c
|
|
|
where a.typecode = b.typecode and a.itemcode = b.itemcode and a.orgcode = c.orgcode
|
|
|
and a.typecode = ''002''
|
|
|
and a.logdate between ''' + @sbgndate + ''' and ''' + @senddate + ''''
|
|
|
|
|
|
if @sorgcode<>''
|
|
|
set @ssql=@ssql+' and a.orgcode in ('''+@sorgcode+''')'
|
|
|
|
|
|
if @plogtype<>''
|
|
|
set @ssql=@ssql+' and a.logtype = ''' + @plogtype + ''''
|
|
|
|
|
|
set @ssql=@ssql+' order by a.logdate,a.orgcode,a.itemcode'
|
|
|
exec(@ssql)
|
|
|
end
|
|
|
go
|
|
|
|
|
|
/*ʵʱÏúÁ¿Ã«ÀûÔ¤¹À*/
|
|
|
if exists(select * from sysobjects where name='p_rpt_int_flow_profit' and xtype='p')
|
|
|
drop procedure p_rpt_int_flow_profit
|
|
|
go
|
|
|
|
|
|
create procedure p_rpt_int_flow_profit
|
|
|
(
|
|
|
@porgcode varchar(1000),
|
|
|
@pbgndate varchar(10),
|
|
|
@penddate varchar(10),
|
|
|
@pclscode varchar(1000),
|
|
|
@pplucode varchar(2000)
|
|
|
)
|
|
|
as
|
|
|
declare @ssql varchar(8000)
|
|
|
declare @sorgcode varchar(1000)
|
|
|
declare @sclscode varchar(1000)
|
|
|
declare @splucode varchar(1000)
|
|
|
declare @sbgndate varchar(10)
|
|
|
declare @senddate varchar(10)
|
|
|
begin
|
|
|
set @sorgcode=replace(@porgcode,',',''',''')
|
|
|
set @sclscode=replace(@pclscode,',',''',''')
|
|
|
set @splucode=replace(@pplucode,',',''',''')
|
|
|
set @sbgndate=@pbgndate
|
|
|
set @senddate=@penddate
|
|
|
if isnull(@sbgndate,'')=''
|
|
|
set @sbgndate='2023-08-01'
|
|
|
if isnull(@senddate,'')=''
|
|
|
set @senddate='2099-12-31'
|
|
|
|
|
|
set @ssql='select a.orgcode,s.orgname,a.sdate,a.plucode,b.pluname,b.barcode,a.clscode,c.clsname,
|
|
|
d.clscode as midclscode,d.clsname as midclsname,a.pluqty,a.plutotal,
|
|
|
round(a.plutotal/(1+b.staxrate/100.00),2) as netamount,round(o.netjprice*a.pluqty,2) as netcost
|
|
|
from t_int_flow_item a,t_plu b,t_gclass c,t_gclass d,t_plu_org o,t_shop s
|
|
|
where a.plucode=b.plucode and a.clscode=c.clscode
|
|
|
and a.plucode=o.plucode and a.orgcode=o.orgcode
|
|
|
and c.uppercode1=d.clscode and a.orgcode=s.orgcode
|
|
|
and c.uppercode2=''20''
|
|
|
and a.sdate between ''' + @sbgndate + ''' and ''' + @senddate + ''''
|
|
|
|
|
|
if @sorgcode<>''
|
|
|
set @ssql=@ssql+' and a.orgcode in ('''+@sorgcode+''')'
|
|
|
|
|
|
if @sclscode<>''
|
|
|
set @ssql=@ssql+' and d.clscode in ('''+@sclscode+'''))'
|
|
|
|
|
|
if @splucode<>''
|
|
|
set @ssql=@ssql+' and a.plucode in ('''+@splucode+''')'
|
|
|
|
|
|
set @ssql='select a.orgcode,a.orgname,a.sdate,a.plucode,a.pluname,a.barcode,a.clscode,a.clsname,a.midclscode,a.midclsname,
|
|
|
sum(a.pluqty) as pluqty,sum(a.plutotal) as plutotal,sum(netamount) as netamount,sum(netcost) as netcost,
|
|
|
sum(netamount)-sum(netcost) as netprofit
|
|
|
from (' +@ssql+') a
|
|
|
group by a.orgcode,a.orgname,a.sdate,a.plucode,a.pluname,a.barcode,a.clscode,a.clsname,a.midclscode,a.midclsname
|
|
|
order by a.orgcode,a.sdate,a.plucode'
|
|
|
|
|
|
exec(@ssql)
|
|
|
end
|
|
|
go |