|
|
/***************************************************************************
|
|
|
业务存储过程脚本
|
|
|
****************************************************************************/
|
|
|
|
|
|
--获取批次号
|
|
|
if exists(select * from sysobjects where name = 'f_getstockpcno' and xtype = 'fn')
|
|
|
drop function f_getstockpcno
|
|
|
go
|
|
|
create function f_getstockpcno
|
|
|
(
|
|
|
@ps_billno varchar(max),
|
|
|
@ps_ywtype varchar(max),
|
|
|
@pi_serialno numeric(19,0)
|
|
|
)
|
|
|
returns varchar(max)
|
|
|
as
|
|
|
begin
|
|
|
declare
|
|
|
@vs_serialno varchar(40),
|
|
|
@return_value_argument varchar(max)
|
|
|
set @vs_serialno = '00000' + isnull(cast(round(@pi_serialno, 0) as varchar(max)), '')
|
|
|
set @vs_serialno = substring(@vs_serialno, len(@vs_serialno)-5+1, 5)
|
|
|
set @return_value_argument = (isnull(@ps_billno, '') + isnull(@ps_ywtype, '') + isnull(@vs_serialno, ''))
|
|
|
return @return_value_argument
|
|
|
end
|
|
|
go
|
|
|
|
|
|
--获取批次库存数量
|
|
|
if exists(select * from sysobjects where name = 'f_getbatchstk' and xtype = 'fn')
|
|
|
drop function f_getbatchstk
|
|
|
go
|
|
|
create function f_getbatchstk
|
|
|
(
|
|
|
@ps_orgcode varchar(max),
|
|
|
@ps_depcode varchar(max),
|
|
|
@ps_place varchar(max),
|
|
|
@ps_plucode varchar(max),
|
|
|
@ps_plutype varchar(max),
|
|
|
@ps_supcode varchar(max),
|
|
|
@ps_pcno varchar(max)
|
|
|
)
|
|
|
returns numeric(19,4)
|
|
|
as
|
|
|
begin
|
|
|
declare
|
|
|
@vf_kccount numeric(19, 4),
|
|
|
@vf_kcpccount numeric(19, 4),
|
|
|
@vs_pcno varchar(40),
|
|
|
@vf_kycount numeric(19, 4)
|
|
|
|
|
|
set @vs_pcno = isnull(@ps_pcno, '*')
|
|
|
|
|
|
if @ps_pcno = ''
|
|
|
set @vs_pcno = '*'
|
|
|
|
|
|
select @vf_kccount = isnull(sum(stkcount), 0)
|
|
|
from t_plu_batch with (nolock)
|
|
|
where orgcode = @ps_orgcode and
|
|
|
((isnull(@ps_depcode,'') = '') or ((isnull(@ps_depcode,'') <> '') and (depcode = @ps_depcode))) and
|
|
|
((isnull(@ps_supcode,'') = '') or ((isnull(@ps_supcode,'') <> '') and (supcode = @ps_supcode))) and
|
|
|
((isnull(@ps_place,'') = '') or ((isnull(@ps_place,'') <> '') and (place = @ps_place))) and plucode = @ps_plucode and
|
|
|
((isnull(@ps_plutype,'') = '') or ((@ps_plutype <> '') and (plutype = @ps_plutype))) and
|
|
|
((@vs_pcno = '*') or ((@vs_pcno <> '*') and (batchno = @vs_pcno))) and stkcount > 0
|
|
|
|
|
|
set @vf_kycount = @vf_kccount
|
|
|
return isnull(@vf_kycount, 0)
|
|
|
end
|
|
|
go
|
|
|
|
|
|
if exists(select * from sysobjects where name ='f_get_pack_jprice' and xtype='fn')
|
|
|
drop function f_get_pack_jprice
|
|
|
go
|
|
|
create function f_get_pack_jprice
|
|
|
(
|
|
|
@jpricetype varchar(1),
|
|
|
@packcode varchar(20),
|
|
|
@orgcode varchar(10)
|
|
|
)
|
|
|
returns numeric(19,4)
|
|
|
as
|
|
|
begin
|
|
|
declare @rnt numeric(19,4)
|
|
|
set @rnt = 0.0000
|
|
|
if @jpricetype = '0'
|
|
|
select @rnt = sum(b.counts * a.jprice) from t_plupack b,t_plu_org a
|
|
|
where a.plucode=b.plucode and a.orgcode = @orgcode and b.packcode = @packcode
|
|
|
group by b.packcode
|
|
|
else if @jpricetype = '1'
|
|
|
select @rnt = sum(b.counts * a.netjprice) from t_plupack b,t_plu_org a
|
|
|
where a.plucode=b.plucode and a.orgcode = @orgcode and b.packcode = @packcode
|
|
|
group by b.packcode
|
|
|
return(@rnt)
|
|
|
end
|
|
|
go
|
|
|
|
|
|
if exists(select * from sysobjects where name = 'f_substring' and xtype = 'fn')
|
|
|
drop function f_substring
|
|
|
go
|
|
|
create function f_substring(@sourcestr varchar(8000),@len int) returns varchar(8000)
|
|
|
as
|
|
|
begin
|
|
|
return(cast(substring(cast(@sourcestr as varbinary(8000)),1,@len) as varchar(100)))
|
|
|
end
|
|
|
go
|
|
|
|
|
|
if exists(select * from sysobjects where name = 'f_get_mncode' and xtype = 'fn')
|
|
|
drop function f_get_mncode
|
|
|
go
|
|
|
create function f_get_mncode
|
|
|
(
|
|
|
@str nvarchar(4000)
|
|
|
)
|
|
|
returns nvarchar(4000)
|
|
|
as
|
|
|
begin
|
|
|
declare @intlen int
|
|
|
declare @strret nvarchar(4000)
|
|
|
declare @temp nvarchar(100)
|
|
|
|
|
|
set @intlen = len(@str)
|
|
|
set @strret = ''
|
|
|
|
|
|
while @intlen > 0
|
|
|
begin
|
|
|
set @temp = ''
|
|
|
|
|
|
select @temp = case
|
|
|
when substring(@str,@intlen,1) >= '帀' then 'z'
|
|
|
when substring(@str,@intlen,1) >= '丫' then 'y'
|
|
|
when substring(@str,@intlen,1) >= '夕' then 'x'
|
|
|
when substring(@str,@intlen,1) >= '屲' then 'w'
|
|
|
when substring(@str,@intlen,1) >= '他' then 't'
|
|
|
when substring(@str,@intlen,1) >= '仨' then 's'
|
|
|
when substring(@str,@intlen,1) >= '呥' then 'r'
|
|
|
when substring(@str,@intlen,1) >= '七' then 'q'
|
|
|
when substring(@str,@intlen,1) >= '妑' then 'p'
|
|
|
when substring(@str,@intlen,1) >= '噢' then 'o'
|
|
|
when substring(@str,@intlen,1) >= '拏' then 'n'
|
|
|
when substring(@str,@intlen,1) >= '嘸' then 'm'
|
|
|
when substring(@str,@intlen,1) >= '垃' then 'l'
|
|
|
when substring(@str,@intlen,1) >= '咔' then 'k'
|
|
|
when substring(@str,@intlen,1) >= '丌' then 'j'
|
|
|
when substring(@str,@intlen,1) >= '铪' then 'h'
|
|
|
when substring(@str,@intlen,1) >= '旮' then 'g'
|
|
|
when substring(@str,@intlen,1) >= '发' then 'f'
|
|
|
when substring(@str,@intlen,1) >= '妸' then 'e'
|
|
|
when substring(@str,@intlen,1) >= '咑' then 'd'
|
|
|
when substring(@str,@intlen,1) >= '嚓' then 'c'
|
|
|
when substring(@str,@intlen,1) >= '八' then 'b'
|
|
|
when substring(@str,@intlen,1) >= '吖' then 'a'
|
|
|
else rtrim(ltrim(substring(@str,@intlen,1)))
|
|
|
end
|
|
|
|
|
|
--['0'..'9', 'a'..'z', 'a'..'z', '-']
|
|
|
--对于汉字特殊字符,不生成拼音码
|
|
|
if not ((ascii(@temp) between ascii('0') and ascii('9'))
|
|
|
or (ascii(@temp) between ascii('a') and ascii('z'))
|
|
|
or (ascii(@temp) between ascii('a') and ascii('z'))
|
|
|
or (ascii(@temp) = ascii('-')))
|
|
|
set @temp = ''
|
|
|
|
|
|
--对于英文中小括号,不生成拼音码
|
|
|
--if @temp = '(' or @temp = ')' set @temp = ''
|
|
|
|
|
|
select @strret = @temp + @strret
|
|
|
|
|
|
set @intlen = @intlen - 1
|
|
|
end
|
|
|
|
|
|
return lower(@strret)
|
|
|
end
|
|
|
go
|
|
|
|
|
|
if exists(select * from sysobjects where name = 'f_compare_image' and xtype = 'fn')
|
|
|
drop function f_compare_image
|
|
|
go
|
|
|
create function f_compare_image
|
|
|
(
|
|
|
@a1 image,
|
|
|
@a2 image)
|
|
|
returns int
|
|
|
as
|
|
|
begin
|
|
|
declare @n int, @i int, @j int
|
|
|
declare @b1 varbinary(8000), @b2 varbinary(8000)
|
|
|
set @n = 1
|
|
|
if datalength(@a1) <> datalength(@a2) -- different length
|
|
|
set @n = 0
|
|
|
else
|
|
|
begin
|
|
|
set @i = 0
|
|
|
set @j = (datalength(@a1) - 1) / 8000 + 1
|
|
|
while @i <= @j
|
|
|
begin
|
|
|
set @b1 = substring(@a1, @i * 8000 + 1, case @i when @j then datalength(@a1) % 8000 else 8000 end)
|
|
|
set @b2 = substring(@a2, @i * 8000 + 1, case @i when @j then datalength(@a2) % 8000 else 8000 end)
|
|
|
if @b1 <> @b2
|
|
|
begin
|
|
|
set @n = 0
|
|
|
break
|
|
|
end
|
|
|
set @i = @i + 1
|
|
|
end
|
|
|
end
|
|
|
return(@n)
|
|
|
end
|
|
|
go
|
|
|
|
|
|
if exists (select * from dbo.sysobjects where id = object_id(N'p_update_prn_format') and objectproperty(id, N'isprocedure') = 1)
|
|
|
drop procedure p_update_prn_format
|
|
|
go
|
|
|
create procedure p_update_prn_format
|
|
|
@prntype varchar(1),
|
|
|
@prncode varchar(10),
|
|
|
@ver varchar(1),
|
|
|
@prnname varchar(40),
|
|
|
@remark varchar(40),
|
|
|
@newformat image
|
|
|
as
|
|
|
begin
|
|
|
declare @iisfind int
|
|
|
declare @imgformat varbinary(8000)
|
|
|
declare @prnformat varbinary(8000)
|
|
|
declare cur_loop cursor for
|
|
|
select prnformat from t_prn_format where prntype=@prntype and prncode=@prncode order by serialno
|
|
|
|
|
|
set @iisfind=0
|
|
|
set @imgformat=@newformat
|
|
|
open cur_loop
|
|
|
fetch next from cur_loop into @prnformat
|
|
|
while @@fetch_status=0
|
|
|
begin
|
|
|
if dbo.f_compare_image(@imgformat,@prnformat)=1
|
|
|
begin
|
|
|
set @iisfind=1
|
|
|
break
|
|
|
end
|
|
|
fetch next from cur_loop into @prnformat
|
|
|
end
|
|
|
close cur_loop
|
|
|
deallocate cur_loop
|
|
|
|
|
|
if @iisfind=0
|
|
|
insert into t_prn_format (prntype,prncode,ver,serialno,isdefault,prnname,remark,prnformat)
|
|
|
select @prntype,@prncode,@ver,(select isnull(max(serialno),0)+1 serialno from t_prn_format where prntype=@prntype and prncode=@prncode),'0',@prnname,@remark,@newformat
|
|
|
end
|
|
|
go
|
|
|
|
|
|
if exists (select * from dbo.sysobjects where id = object_id(N'p_calc_staff_pct') and objectproperty(id, N'isprocedure') = 1)
|
|
|
drop procedure p_calc_staff_pct
|
|
|
go
|
|
|
create procedure p_calc_staff_pct
|
|
|
@prjcode varchar(6),
|
|
|
@stafftype varchar(1),
|
|
|
@orgcode varchar(10),
|
|
|
@staffcode varchar(10),
|
|
|
@bgndate varchar(10),
|
|
|
@enddate varchar(10),
|
|
|
@message varchar(100) output
|
|
|
as
|
|
|
declare @s_sql varchar(8000)
|
|
|
declare @s_nexesql nvarchar(4000)
|
|
|
declare @s_exesql varchar(8000)
|
|
|
declare @s_tmpstr varchar(8000)
|
|
|
declare @s_tmpdate varchar(10)
|
|
|
declare @s_calcrtn varchar(1)
|
|
|
declare @i_rowcount int
|
|
|
declare @s_tcgrptype varchar(1)
|
|
|
begin
|
|
|
if exists(select name from tempdb..sysobjects where name='##tmptccalchz' and xtype='u')
|
|
|
exec ('drop table ##tmptccalchz')
|
|
|
create table ##tmptccalchz(
|
|
|
usercode varchar (6) not null,
|
|
|
username varchar (10) null,
|
|
|
counts numeric (19,4) not null default (0),
|
|
|
total numeric (19,4) not null default (0),
|
|
|
tctotal numeric (19,4) not null default (0))
|
|
|
if exists(select name from tempdb..sysobjects where name='##tmptccalcdtl' and xtype='u')
|
|
|
exec ('drop table ##tmptccalcdtl')
|
|
|
create table ##tmptccalcdtl
|
|
|
(usercode varchar(6) not null,username varchar(10) null,
|
|
|
plucode varchar(20) null, barcode varchar(20) null,pluname varchar(40) null,spec varchar(40) null,unit varchar(10) null,cargono varchar(20) null,
|
|
|
depcode varchar(10) null,depname varchar(16) null,clscode varchar(10) null,clsname varchar(20) null,
|
|
|
brandcode varchar(10) null,brandname varchar(20) null,supcode varchar(15) null,supname varchar(100) null,
|
|
|
counts numeric(19,4) not null default(0),total numeric(19,4) not null default(0),
|
|
|
israte varchar(1) not null default('1'),sgltctotal numeric(19,4) not null default(0),tctotal numeric(19,4) not null default(0),tcrate numeric (19,4) not null default(0),isfinished varchar(1))
|
|
|
exec ('delete from ##tmptccalcdtl')
|
|
|
|
|
|
set @s_tcgrptype = null
|
|
|
select top 1 @s_tcgrptype = grptype from t_pct_project_detail where prjcode=@prjcode and usertype=@stafftype and grptype <> 'p'
|
|
|
|
|
|
if @stafftype ='0'
|
|
|
select @s_calcrtn=itemvalue from t_syscfg where section='stafftc' and itemname='tc_clerkrtn'
|
|
|
else
|
|
|
select @s_calcrtn=itemvalue from t_syscfg where section='stafftc' and itemname='tc_pfrtn'
|
|
|
if @s_calcrtn='' or @s_calcrtn is null
|
|
|
select @s_calcrtn='0'
|
|
|
|
|
|
if @stafftype ='0'
|
|
|
begin
|
|
|
if @s_tcgrptype <> 't'
|
|
|
begin
|
|
|
select @s_tmpdate=@bgndate
|
|
|
while (left(@s_tmpdate,7)<=left(@enddate,7))
|
|
|
begin
|
|
|
select @s_tmpstr='t_flow_item_'+substring(@s_tmpdate,1,4)+substring(@s_tmpdate,6,2)
|
|
|
if exists(select * from sysobjects where name=@s_tmpstr and xtype='u')
|
|
|
begin
|
|
|
select @s_sql='select clkcode,plucode,sum(pluqty) as counts,sum(plutotal) as total from ' + @s_tmpstr +'
|
|
|
where clkcode is not null and clkcode<>''''
|
|
|
and accdate between '''+@bgndate+''' and '''+@enddate+''''
|
|
|
if @orgcode<>'<全部>'
|
|
|
select @s_sql=@s_sql+' and orgcode='''+@orgcode+''''
|
|
|
if @staffcode<>''
|
|
|
select @s_sql=@s_sql+' and clkcode='''+@staffcode+''''
|
|
|
if @s_calcrtn='0'
|
|
|
select @s_sql=@s_sql+' and trantype in (''b'',''f'')'
|
|
|
else
|
|
|
select @s_sql=@s_sql+' and trantype in (''b'',''f'',''d'',''h'')'
|
|
|
select @s_sql=@s_sql+' group by clkcode,plucode'
|
|
|
set @s_exesql = ''
|
|
|
set @s_exesql = 'update a set a.total = a.total + b.total,a.counts = a.counts + b.counts
|
|
|
from ##tmptccalcdtl a, ('+@s_sql+') b where a.usercode = b.clkcode and a.plucode = b.plucode'
|
|
|
exec(@s_exesql)
|
|
|
set @s_exesql = ''
|
|
|
set @s_exesql = 'insert into ##tmptccalcdtl (usercode,plucode,total,counts)
|
|
|
select clkcode,plucode,total,counts
|
|
|
from ('+@s_sql+') b
|
|
|
where not exists(select * from ##tmptccalcdtl where usercode = b.clkcode and plucode = b.plucode)'
|
|
|
exec(@s_exesql)
|
|
|
end
|
|
|
select @s_tmpdate = convert(varchar(10),dateadd(mm,1,@s_tmpdate),120)
|
|
|
end
|
|
|
end
|
|
|
else
|
|
|
begin
|
|
|
select @s_tmpdate=@bgndate
|
|
|
while (left(@s_tmpdate,7)<=left(@enddate,7))
|
|
|
begin
|
|
|
select @s_tmpstr='t_flow_item_'+substring(@s_tmpdate,1,4)+substring(@s_tmpdate,6,2)
|
|
|
if exists(select * from sysobjects where name=@s_tmpstr and xtype='u')
|
|
|
begin
|
|
|
select @s_sql='select distinct posno,orgcode,sdate,stime,serialno,trantype from ' + @s_tmpstr +'
|
|
|
where clkcode is not null and clkcode<>''''
|
|
|
and accdate between '''+@bgndate+''' and '''+@enddate+''''
|
|
|
if @orgcode<>'<全部>'
|
|
|
select @s_sql=@s_sql+' and orgcode='''+@orgcode+''''
|
|
|
if @staffcode<>''
|
|
|
select @s_sql=@s_sql+' and clkcode='''+@staffcode+''''
|
|
|
if @s_calcrtn='0'
|
|
|
select @s_sql=@s_sql+' and trantype in (''b'',''f'')'
|
|
|
else
|
|
|
select @s_sql=@s_sql+' and trantype in (''b'',''f'',''d'',''h'')'
|
|
|
set @s_sql = 'select c.clkcode,b.payflag,b.amount,a.total,c.plutotal,round((c.plutotal/a.total)*b.amount,2) as tctotal
|
|
|
from t_flow_total_'+substring(@s_tmpdate,1,4)+substring(@s_tmpdate,6,2)+' a,t_flow_pay_'+substring(@s_tmpdate,1,4)+substring(@s_tmpdate,6,2)+' b,'+@s_tmpstr+' c,
|
|
|
('+@s_sql+') d
|
|
|
where a.posno = b.posno and a.orgcode = b.orgcode and a.sdate = b.sdate and a.stime = b.stime and a.serialno = b.serialno and a.trantype=b.trantype and
|
|
|
a.posno = c.posno and a.orgcode = c.orgcode and a.sdate = c.sdate and a.stime = c.stime and a.serialno = c.serialno and a.trantype=c.trantype and
|
|
|
a.posno = d.posno and a.orgcode = d.orgcode and a.sdate = d.sdate and a.stime = d.stime and a.serialno = d.serialno and a.trantype=d.trantype'
|
|
|
set @s_sql = 'select clkcode,payflag,sum(tctotal) as tctotal
|
|
|
from ('+@s_sql+') t where t.clkcode is not null and t.clkcode <> '''' group by clkcode,payflag'
|
|
|
set @s_exesql = ''
|
|
|
set @s_exesql = 'update a set a.total = a.total + b.tctotal
|
|
|
from ##tmptccalcdtl a, ('+@s_sql+') b where a.usercode = b.clkcode and a.plucode = b.payflag'
|
|
|
exec(@s_exesql)
|
|
|
set @s_exesql = ''
|
|
|
set @s_exesql = 'insert into ##tmptccalcdtl (usercode,plucode,total)
|
|
|
select clkcode,payflag,tctotal as total
|
|
|
from ('+@s_sql+') b
|
|
|
where not exists(select * from ##tmptccalcdtl where usercode = b.clkcode and plucode = b.payflag)'
|
|
|
exec(@s_exesql)
|
|
|
end
|
|
|
select @s_tmpdate = convert(varchar(10),dateadd(mm,1,@s_tmpdate),120)
|
|
|
end
|
|
|
end
|
|
|
end
|
|
|
else if @stafftype ='2'
|
|
|
begin
|
|
|
if @s_tcgrptype <> 't'
|
|
|
begin
|
|
|
select @s_tmpdate=@bgndate
|
|
|
while (left(@s_tmpdate,7)<=left(@enddate,7))
|
|
|
begin
|
|
|
select @s_tmpstr='t_flow_item_'+substring(@s_tmpdate,1,4)+substring(@s_tmpdate,6,2)
|
|
|
if exists(select * from sysobjects where name=@s_tmpstr and xtype='u')
|
|
|
begin
|
|
|
select @s_sql='select cshcode,plucode,sum(pluqty) as counts,sum(plutotal) as total from ' + @s_tmpstr +'
|
|
|
where cshcode is not null and cshcode<>''''
|
|
|
and accdate between '''+@bgndate+''' and '''+@enddate+''''
|
|
|
if @orgcode<>'<全部>'
|
|
|
select @s_sql=@s_sql+' and orgcode='''+@orgcode+''''
|
|
|
if @staffcode<>''
|
|
|
select @s_sql=@s_sql+' and cshcode='''+@staffcode+''''
|
|
|
if @s_calcrtn='0'
|
|
|
select @s_sql=@s_sql+' and trantype in (''b'',''f'')'
|
|
|
else
|
|
|
select @s_sql=@s_sql+' and trantype in (''b'',''f'',''d'',''h'')'
|
|
|
select @s_sql=@s_sql+' group by cshcode,plucode'
|
|
|
set @s_exesql = ''
|
|
|
set @s_exesql = 'update a set a.total = a.total + b.total,a.counts = a.counts + b.counts
|
|
|
from ##tmptccalcdtl a, ('+@s_sql+') b where a.usercode = b.cshcode and a.plucode = b.plucode'
|
|
|
exec(@s_exesql)
|
|
|
set @s_exesql = ''
|
|
|
set @s_exesql = 'insert into ##tmptccalcdtl (usercode,plucode,total,counts)
|
|
|
select cshcode,plucode,total,counts
|
|
|
from ('+@s_sql+') b
|
|
|
where not exists(select * from ##tmptccalcdtl where usercode = b.cshcode and plucode = b.plucode)'
|
|
|
exec(@s_exesql)
|
|
|
end
|
|
|
select @s_tmpdate = convert(varchar(10),dateadd(mm,1,@s_tmpdate),120)
|
|
|
end
|
|
|
end
|
|
|
else
|
|
|
begin
|
|
|
select @s_tmpdate=@bgndate
|
|
|
while (left(@s_tmpdate,7)<=left(@enddate,7))
|
|
|
begin
|
|
|
select @s_tmpstr='t_flow_item_'+substring(@s_tmpdate,1,4)+substring(@s_tmpdate,6,2)
|
|
|
if exists(select * from sysobjects where name=@s_tmpstr and xtype='u')
|
|
|
begin
|
|
|
select @s_sql='select distinct posno,orgcode,sdate,stime,serialno,trantype from ' + @s_tmpstr +'
|
|
|
where cshcode is not null and cshcode<>''''
|
|
|
and accdate between '''+@bgndate+''' and '''+@enddate+''''
|
|
|
if @orgcode<>'<全部>'
|
|
|
select @s_sql=@s_sql+' and orgcode='''+@orgcode+''''
|
|
|
if @staffcode<>''
|
|
|
select @s_sql=@s_sql+' and cshcode='''+@staffcode+''''
|
|
|
if @s_calcrtn='0'
|
|
|
select @s_sql=@s_sql+' and trantype in (''b'',''f'')'
|
|
|
else
|
|
|
select @s_sql=@s_sql+' and trantype in (''b'',''f'',''d'',''h'')'
|
|
|
set @s_sql = 'select c.cshcode,b.payflag,b.amount,a.total,c.plutotal,round((c.plutotal/a.total)*b.amount,2) as tctotal
|
|
|
from t_flow_total_'+substring(@s_tmpdate,1,4)+substring(@s_tmpdate,6,2)+' a,t_flow_pay_'+substring(@s_tmpdate,1,4)+substring(@s_tmpdate,6,2)+' b,'+@s_tmpstr+' c,
|
|
|
('+@s_sql+') d
|
|
|
where a.posno = b.posno and a.orgcode = b.orgcode and a.sdate = b.sdate and a.stime = b.stime and a.serialno = b.serialno and a.trantype=b.trantype and
|
|
|
a.posno = c.posno and a.orgcode = c.orgcode and a.sdate = c.sdate and a.stime = c.stime and a.serialno = c.serialno and a.trantype=c.trantype and
|
|
|
a.posno = d.posno and a.orgcode = d.orgcode and a.sdate = d.sdate and a.stime = d.stime and a.serialno = d.serialno and a.trantype=d.trantype'
|
|
|
set @s_sql = 'select cshcode,payflag,sum(tctotal) as tctotal
|
|
|
from ('+@s_sql+') t where t.cshcode is not null and t.cshcode <> '''' group by cshcode,payflag'
|
|
|
set @s_exesql = ''
|
|
|
set @s_exesql = 'update a set a.total = a.total + b.tctotal
|
|
|
from ##tmptccalcdtl a, ('+@s_sql+') b where a.usercode = b.cshcode and a.plucode = b.payflag'
|
|
|
exec(@s_exesql)
|
|
|
set @s_exesql = ''
|
|
|
set @s_exesql = 'insert into ##tmptccalcdtl (usercode,plucode,total)
|
|
|
select cshcode,payflag,tctotal as total
|
|
|
from ('+@s_sql+') b
|
|
|
where not exists(select * from ##tmptccalcdtl where usercode = b.cshcode and plucode = b.payflag)'
|
|
|
exec(@s_exesql)
|
|
|
end
|
|
|
select @s_tmpdate = convert(varchar(10),dateadd(mm,1,@s_tmpdate),120)
|
|
|
end
|
|
|
end
|
|
|
end
|
|
|
else if @stafftype ='1'
|
|
|
begin
|
|
|
select @s_sql='insert into ##tmptccalcdtl (usercode,plucode,total,counts)
|
|
|
select f.zdrcode,d.plucode,sum(d.pftotal) as total,sum(d.counts) as counts from t_whsale_head f,t_whsale_body d
|
|
|
where f.billno=d.billno and f.rzdate is not null and f.rzdate<>''''
|
|
|
and f.rzdate between '''+@bgndate+''' and '''+@enddate+''''
|
|
|
if @orgcode<>'<全部>'
|
|
|
select @s_sql=@s_sql+' and f.orgcode='''+@orgcode+''''
|
|
|
if @staffcode<>''
|
|
|
select @s_sql=@s_sql+' and f.zdrcode='''+@staffcode+''''
|
|
|
select @s_sql=@s_sql+' group by f.zdrcode,d.plucode'
|
|
|
exec(@s_sql)
|
|
|
if @s_calcrtn='1'
|
|
|
begin
|
|
|
select @s_sql='select f.zdrcode,d.plucode,(-1)*sum(d.pftotal) as total,(-1)*sum(d.counts) as counts from t_whreturn_head f,t_whreturn_body d
|
|
|
where f.billno=d.billno and f.rzdate is not null and f.rzdate<>''''
|
|
|
and f.rzdate between '''+@bgndate+''' and '''+@enddate+''''
|
|
|
if @orgcode<>'<全部>'
|
|
|
select @s_sql=@s_sql+' and f.orgcode='''+@orgcode+''''
|
|
|
if @staffcode<>''
|
|
|
select @s_sql=@s_sql+' and f.zdrcode='''+@staffcode+''''
|
|
|
select @s_sql=@s_sql+' group by f.zdrcode,d.plucode'
|
|
|
set @s_exesql = ''
|
|
|
set @s_exesql = 'update a set a.total = a.total + b.total,a.counts = a.counts + b.counts
|
|
|
from ##tmptccalcdtl a, ('+@s_sql+') b where a.usercode = b.zdrcode and a.plucode = b.plucode'
|
|
|
exec(@s_exesql)
|
|
|
set @s_exesql = ''
|
|
|
set @s_exesql = 'insert into ##tmptccalcdtl (usercode,plucode,total,counts)
|
|
|
select zdrcode,plucode,total,counts
|
|
|
from ('+@s_sql+') b
|
|
|
where not exists(select * from ##tmptccalcdtl where usercode = b.zdrcode and plucode = b.plucode)'
|
|
|
exec(@s_exesql)
|
|
|
end
|
|
|
end
|
|
|
|
|
|
if @s_tcgrptype <> 't'
|
|
|
begin
|
|
|
select @s_sql='update t set depcode=g.depcode,clscode=g.clscode,brandcode=g.brandcode ,supcode =g.supcode
|
|
|
from ##tmptccalcdtl t,t_plu g
|
|
|
where t.plucode=g.plucode '
|
|
|
exec(@s_sql)
|
|
|
end
|
|
|
|
|
|
if @s_tcgrptype <> 't'
|
|
|
begin
|
|
|
select @s_sql='update t set israte = p.israte,isfinished = ''1'',
|
|
|
tcrate=p.tcrate,
|
|
|
sgltctotal=p.tctotal,
|
|
|
tctotal=isnull(isnull(t.counts,0)*p.tctotal,0)
|
|
|
from ##tmptccalcdtl t,t_pct_project_detail p
|
|
|
where t.plucode=p.grpcode and p.prjcode='''+@prjcode+''' and p.usertype='''+@stafftype+''' and p.grptype=''p'' and p.tcmintotal = -1 and p.tcmaxtotal = -1'
|
|
|
exec(@s_sql)
|
|
|
select @s_sql='update t set israte = p.israte,isfinished = ''1'',
|
|
|
tcrate=p.tcrate,
|
|
|
sgltctotal = p.tctotal,
|
|
|
tctotal=isnull(isnull(t.counts,0)*p.tctotal,0)
|
|
|
from ##tmptccalcdtl t,t_pct_project_detail p
|
|
|
where t.plucode=p.grpcode and p.prjcode='''+@prjcode+''' and p.usertype='''+@stafftype+''' and p.grptype=''p'' and p.tcmintotal <> -1 and p.tcmaxtotal <> -1 and t.total >= p.tcmintotal and t.total < p.tcmaxtotal'
|
|
|
exec(@s_sql)
|
|
|
end
|
|
|
|
|
|
select @s_sql='update t set israte = p.israte,isfinished = ''9'',
|
|
|
tcrate=p.tcrate,
|
|
|
sgltctotal = p.tctotal,
|
|
|
tctotal=isnull(isnull(t.counts,0)*p.tctotal,0)
|
|
|
from ##tmptccalcdtl t,(select p1.grpcode,p1.israte,p1.tcrate,p1.tctotal,t1.total,p1.grptype,t1.usercode from '
|
|
|
if @s_tcgrptype = 'a'
|
|
|
set @s_sql = @s_sql + ' (select usercode,sum(total) as total from ##tmptccalcdtl where isnull(isfinished,'''')<>''1'' group by usercode) t1'
|
|
|
else if @s_tcgrptype = 'd'
|
|
|
set @s_sql = @s_sql + ' (select depcode,usercode,sum(total) as total from ##tmptccalcdtl where isnull(isfinished,'''')<>''1'' group by depcode,usercode) t1'
|
|
|
else if @s_tcgrptype = 'c'
|
|
|
set @s_sql = @s_sql + ' (select clscode,usercode,sum(total) as total from ##tmptccalcdtl where isnull(isfinished,'''')<>''1'' group by clscode,usercode) t1'
|
|
|
else if @s_tcgrptype = 'b'
|
|
|
set @s_sql = @s_sql + ' (select brandcode,usercode,sum(total) as total from ##tmptccalcdtl where isnull(isfinished,'''')<>''1'' group by brandcode,usercode) t1'
|
|
|
else if @s_tcgrptype = 't'
|
|
|
set @s_sql = @s_sql + ' (select plucode,usercode,sum(total) as total from ##tmptccalcdtl where isnull(isfinished,'''')<>''1'' group by plucode,usercode) t1'
|
|
|
else if @s_tcgrptype = 'v'
|
|
|
set @s_sql = @s_sql + ' (select supcode ,usercode,sum(total) as total from ##tmptccalcdtl where isnull(isfinished,'''')<>''1'' group by supcode ,usercode) t1'
|
|
|
set @s_sql = @s_sql +',t_pct_project_detail p1
|
|
|
where p1.prjcode='''+@prjcode+''' and p1.usertype='''+@stafftype+''' and p1.grptype<>''p'' and p1.tcmintotal <> -1 and p1.tcmaxtotal <> -1 and t1.total >= p1.tcmintotal and t1.total < p1.tcmaxtotal'
|
|
|
if @s_tcgrptype = 'a'
|
|
|
set @s_sql = @s_sql + ' and p1.grptype = ''a'') p'
|
|
|
else if @s_tcgrptype = 'd'
|
|
|
set @s_sql = @s_sql + ' and p1.grpcode = t1.depcode) p'
|
|
|
else if @s_tcgrptype = 'c'
|
|
|
set @s_sql = @s_sql + ' and p1.grpcode = t1.clscode) p'
|
|
|
else if @s_tcgrptype = 'b'
|
|
|
set @s_sql = @s_sql + ' and p1.grpcode = t1.brandcode) p'
|
|
|
else if @s_tcgrptype = 't'
|
|
|
set @s_sql = @s_sql + ' and p1.grpcode = t1.plucode) p'
|
|
|
else if @s_tcgrptype = 'v'
|
|
|
set @s_sql = @s_sql + ' and p1.grpcode = t1.supcode ) p'
|
|
|
if @s_tcgrptype = 'a'
|
|
|
set @s_sql = @s_sql + ' where p.grptype = ''a'' and p.usercode = t.usercode and isnull(t.isfinished,'''')<>''1'''
|
|
|
else if @s_tcgrptype = 'd'
|
|
|
set @s_sql = @s_sql + ' where p.grpcode = t.depcode and p.usercode = t.usercode and isnull(t.isfinished,'''')<>''1'''
|
|
|
else if @s_tcgrptype = 'c'
|
|
|
set @s_sql = @s_sql + ' where p.grpcode = t.clscode and p.usercode = t.usercode and isnull(t.isfinished,'''')<>''1'''
|
|
|
else if @s_tcgrptype = 'b'
|
|
|
set @s_sql = @s_sql + ' where p.grpcode = t.brandcode and p.usercode = t.usercode and isnull(t.isfinished,'''')<>''1'''
|
|
|
else if @s_tcgrptype = 't'
|
|
|
set @s_sql = @s_sql + ' where p.grpcode = t.plucode and p.usercode = t.usercode and isnull(t.isfinished,'''')<>''1'''
|
|
|
else if @s_tcgrptype = 'v'
|
|
|
set @s_sql = @s_sql + ' where p.grpcode = t.supcode and p.usercode = t.usercode and isnull(t.isfinished,'''')<>''1'''
|
|
|
exec(@s_sql)
|
|
|
|
|
|
exec('update ##tmptccalcdtl set isfinished = ''1''
|
|
|
where isnull(isfinished,'''') = ''9''')
|
|
|
|
|
|
select @s_sql='update t set israte = p.israte,isfinished = ''9'',
|
|
|
tcrate=p.tcrate,
|
|
|
sgltctotal=p.tctotal,
|
|
|
tctotal=isnull(isnull(t.counts,0)*p.tctotal,0)
|
|
|
from ##tmptccalcdtl t,(select p1.grpcode,p1.israte,p1.tcrate,p1.tctotal,t1.total,p1.grptype,t1.usercode from '
|
|
|
if @s_tcgrptype = 'a'
|
|
|
set @s_sql = @s_sql + ' (select usercode,sum(total) as total from ##tmptccalcdtl where isnull(isfinished,'''')<>''1'' group by usercode) t1'
|
|
|
else if @s_tcgrptype = 'd'
|
|
|
set @s_sql = @s_sql + ' (select depcode,usercode,sum(total) as total from ##tmptccalcdtl where isnull(isfinished,'''')<>''1'' group by depcode,usercode) t1'
|
|
|
else if @s_tcgrptype = 'c'
|
|
|
set @s_sql = @s_sql + ' (select clscode,usercode,sum(total) as total from ##tmptccalcdtl where isnull(isfinished,'''')<>''1'' group by clscode,usercode) t1'
|
|
|
else if @s_tcgrptype = 'b'
|
|
|
set @s_sql = @s_sql + ' (select brandcode,usercode,sum(total) as total from ##tmptccalcdtl where isnull(isfinished,'''')<>''1'' group by brandcode,usercode) t1'
|
|
|
else if @s_tcgrptype = 't'
|
|
|
set @s_sql = @s_sql + ' (select plucode,usercode,sum(total) as total from ##tmptccalcdtl where isnull(isfinished,'''')<>''1'' group by plucode,usercode) t1'
|
|
|
else if @s_tcgrptype = 'v'
|
|
|
set @s_sql = @s_sql + ' (select supcode ,usercode,sum(total) as total from ##tmptccalcdtl where isnull(isfinished,'''')<>''1'' group by supcode ,usercode) t1'
|
|
|
set @s_sql = @s_sql +',t_pct_project_detail p1
|
|
|
where p1.prjcode='''+@prjcode+''' and p1.usertype='''+@stafftype+''' and p1.grptype<>''p'' and p1.tcmintotal = -1 and p1.tcmaxtotal = -1'
|
|
|
if @s_tcgrptype = 'a'
|
|
|
set @s_sql = @s_sql + ' and p1.grptype = ''a'') p'
|
|
|
else if @s_tcgrptype = 'd'
|
|
|
set @s_sql = @s_sql + ' and p1.grpcode = t1.depcode) p'
|
|
|
else if @s_tcgrptype = 'c'
|
|
|
set @s_sql = @s_sql + ' and p1.grpcode = t1.clscode) p'
|
|
|
else if @s_tcgrptype = 'b'
|
|
|
set @s_sql = @s_sql + ' and p1.grpcode = t1.brandcode) p'
|
|
|
else if @s_tcgrptype = 't'
|
|
|
set @s_sql = @s_sql + ' and p1.grpcode = t1.plucode) p'
|
|
|
else if @s_tcgrptype = 'v'
|
|
|
set @s_sql = @s_sql + ' and p1.grpcode = t1.supcode ) p'
|
|
|
if @s_tcgrptype = 'a'
|
|
|
set @s_sql = @s_sql + ' where p.grptype = ''a'' and p.usercode = t.usercode and isnull(t.isfinished,'''')<>''1'''
|
|
|
else if @s_tcgrptype = 'd'
|
|
|
set @s_sql = @s_sql + ' where p.grpcode = t.depcode and p.usercode = t.usercode and isnull(t.isfinished,'''')<>''1'''
|
|
|
else if @s_tcgrptype = 'c'
|
|
|
set @s_sql = @s_sql + ' where p.grpcode = t.clscode and p.usercode = t.usercode and isnull(t.isfinished,'''')<>''1'''
|
|
|
else if @s_tcgrptype = 'b'
|
|
|
set @s_sql = @s_sql + ' where p.grpcode = t.brandcode and p.usercode = t.usercode and isnull(t.isfinished,'''')<>''1'''
|
|
|
else if @s_tcgrptype = 't'
|
|
|
set @s_sql = @s_sql + ' where p.grpcode = t.plucode and p.usercode = t.usercode and isnull(t.isfinished,'''')<>''1'''
|
|
|
else if @s_tcgrptype = 'v'
|
|
|
set @s_sql = @s_sql + ' where p.grpcode = t.supcode and p.usercode = t.usercode and isnull(t.isfinished,'''')<>''1'''
|
|
|
exec(@s_sql)
|
|
|
|
|
|
exec('update ##tmptccalcdtl set isfinished = ''1''
|
|
|
where isnull(isfinished,'''') = ''9''')
|
|
|
|
|
|
set @s_sql='update ##tmptccalcdtl set tctotal = case when israte = ''1'' then round(total*tcrate/100.00,2) else tctotal end'
|
|
|
exec(@s_sql)
|
|
|
select @s_sql='truncate table ##tmptccalchz'
|
|
|
exec(@s_sql)
|
|
|
|
|
|
select @s_sql='insert into ##tmptccalchz (usercode,username,counts,total,tctotal)
|
|
|
select usercode,(select username from t_user where usercode=t.usercode) as username,
|
|
|
isnull(round(sum(counts),2),0) as counts,
|
|
|
isnull(round(sum(total),2),0) as total,
|
|
|
isnull(round(sum(tctotal),2),0) as tctotal
|
|
|
from ##tmptccalcdtl t group by usercode '
|
|
|
exec(@s_sql)
|
|
|
if @s_tcgrptype <> 't'
|
|
|
exec('update t set username = s.username,barcode = g.barcode,pluname = g.pluname,spec=g.spec,unit = g.unit,
|
|
|
cargono = g.cargono,depname=d.depname,clsname=c.clsname,brandname=b.brandname,supname=v.supname
|
|
|
from ##tmptccalcdtl t left join t_dept d on t.depcode=d.depcode
|
|
|
left join t_gclass c on t.clscode=c.clscode
|
|
|
left join t_brand b on t.brandcode=b.brandcode
|
|
|
left join t_supplier v on t.supcode =v.supcode
|
|
|
left join t_plu g on t.plucode=g.plucode
|
|
|
left join t_user s on t.usercode=s.usercode ')
|
|
|
else
|
|
|
begin
|
|
|
exec('update t set username = s.username,pluname = g.tendname
|
|
|
from ##tmptccalcdtl t left join t_tend g on t.plucode=g.tendcode
|
|
|
left join t_user s on t.usercode=s.usercode ')
|
|
|
end
|
|
|
|
|
|
exec('select usercode,username,counts,total,tctotal,tctotal as tztotal,convert(varchar(50),'''') as remark
|
|
|
from ##tmptccalchz order by tctotal desc,usercode')
|
|
|
|
|
|
exec('select usercode,username,plucode,barcode,pluname,spec,unit,cargono,
|
|
|
depcode,depname,clscode,clsname,brandcode,brandname,supcode ,supname,
|
|
|
israte,tcrate,isnull(round(sum(counts),2),0) as counts,isnull(round(sum(total),2),0) as total,sgltctotal,isnull(round(sum(tctotal),2),0) as tctotal
|
|
|
from ##tmptccalcdtl
|
|
|
group by usercode,username,plucode,depcode,clscode,brandcode,supcode ,
|
|
|
israte,barcode,pluname,spec,unit,cargono,depname,clsname,brandname,supname,tcrate,sgltctotal
|
|
|
order by tctotal desc,usercode')
|
|
|
|
|
|
set @s_sql='if exists(select name from sysobjects where name=''##tmptccalcdtl'' and xtype=''u'')
|
|
|
drop table ##tmptccalcdtl'
|
|
|
exec(@s_sql)
|
|
|
set @s_sql='if exists(select name from sysobjects where name=''##tmptccalchz'' and xtype=''u'')
|
|
|
drop table ##tmptccalchz'
|
|
|
exec(@s_sql)
|
|
|
|
|
|
return (1)
|
|
|
end
|
|
|
go
|
|
|
|
|
|
if exists (select * from dbo.sysobjects where id = object_id(N'p_show_vip_yjph') and objectproperty(id, N'isprocedure') = 1)
|
|
|
drop procedure p_show_vip_yjph
|
|
|
go
|
|
|
create procedure p_show_vip_yjph
|
|
|
@pvipdbname varchar(20),
|
|
|
@pbgndate varchar(10),
|
|
|
@penddate varchar(10),
|
|
|
@pispre varchar(1),
|
|
|
@pnum int,
|
|
|
@ptotal numeric(19,4),
|
|
|
@pqrysql varchar(8000),
|
|
|
@porgcode varchar(10)
|
|
|
as
|
|
|
declare @ssql varchar(8000)
|
|
|
declare @stmpdate varchar(10)
|
|
|
declare @srpttable varchar(20)
|
|
|
declare @scangoon varchar(1)
|
|
|
declare @sver varchar(1)
|
|
|
begin
|
|
|
select @sver = itemvalue from t_syscfg where section = 'system' and itemname = 'ver'
|
|
|
if exists(select name from tempdb..sysobjects where name='##tmpvipyjdata' and xtype='u')
|
|
|
drop table ##tmpvipyjdata
|
|
|
create table ##tmpvipyjdata
|
|
|
(vipcode varchar(20) not null,vipname varchar(20) null,mobile1 varchar(20) null,mobile2 varchar(20) null,storetotal numeric(19,4),picktotal numeric(19,4),tendtotal numeric(19,4),
|
|
|
paytotal numeric(19,4),flxftotal numeric(19,4), xfjftotal numeric(19,4),fljftotal numeric(19,4), fltotal numeric(19,4))
|
|
|
|
|
|
set @stmpdate=@pbgndate
|
|
|
while (substring(@stmpdate,1,4)+substring(@stmpdate,6,2))<=(substring(@penddate,1,4)+substring(@penddate,6,2))
|
|
|
begin
|
|
|
set @srpttable = 't_viprpt_'+substring(@stmpdate,1,4)+substring(@stmpdate,6,2)
|
|
|
set @ssql='if exists(select name from '+@pvipdbname+'..sysobjects where name='''+@srpttable+''' and xtype=''u'')
|
|
|
|
|
|
insert into ##tmpvipyjdata(vipcode,vipname,mobile1,mobile2,storetotal,picktotal,tendtotal,paytotal,
|
|
|
flxftotal,xfjftotal,fljftotal,fltotal)
|
|
|
select a.vipcode,a.vipname,isnull(mobile1,''''),isnull(mobile2,''''),sum(b.storetotal) as storetotal,sum(b.picktotal) as picktotal,
|
|
|
sum(b.tendtotal) as tendtotal,sum(b.paytotal) as paytotal,
|
|
|
sum(b.flxftotal) as flxftotal,sum(b.xfjftotal) as xfjftotal,
|
|
|
sum(b.fljftotal) as fljftotal,sum(b.fltotal) as fltotal
|
|
|
from '+@pvipdbname+'..t_vip a,'+@pvipdbname+'..'+@srpttable+' b
|
|
|
where a.vipcode=b.vipcode and b.accdate between '''+@pbgndate+''' and '''+ @penddate+''''
|
|
|
if @porgcode <> '<全部>'
|
|
|
begin
|
|
|
if @sver = '1'
|
|
|
set @ssql = @ssql + ' and b.orgcode='''+@porgcode+''''
|
|
|
else
|
|
|
set @ssql = @ssql + ' and b.orgcode=''*'''
|
|
|
end
|
|
|
else
|
|
|
set @ssql = @ssql + ' and b.orgcode=''*'''
|
|
|
set @ssql = @ssql+
|
|
|
'group by a.vipcode,a.vipname,isnull(mobile1,''''),isnull(mobile2,'''')'
|
|
|
exec (@ssql)
|
|
|
set @stmpdate=convert(char(10),dateadd(month,1,@stmpdate),120)
|
|
|
end
|
|
|
|
|
|
set @ssql='select '
|
|
|
if @pnum <> 0
|
|
|
set @ssql = @ssql+'top '+convert(varchar(10),@pnum)
|
|
|
set @ssql = @ssql + ' * from (
|
|
|
select t1.vipcode as 会员编码,t1.vipname as 会员姓名,isnull(t1.mobile1,'''') 手机号1,isnull(t1.mobile2,'''') 手机号2,
|
|
|
sum(t1.storetotal) as 充值金额,sum(t1.picktotal) as 取款金额,sum(t1.tendtotal) as 消费金额,
|
|
|
sum(t1.paytotal) as 支付金额,sum(t1.flxftotal) as 返利消费金额,sum(t1.fltotal) as 返利金额,
|
|
|
sum(t1.xfjftotal) as 消费积分额度,sum(t1.fljftotal) as 返利积分额度,t2.orgcode as 发售机构编码,t2.sxdate as 发售日期
|
|
|
from ##tmpvipyjdata t1 left join '+@pvipdbname+'..t_vip t2 on t1.vipcode = t2.vipcode group by t1.vipcode,t1.vipname,isnull(t1.mobile1,''''),isnull(t1.mobile2,''''),t2.orgcode,t2.sxdate )a where 1=1 '
|
|
|
if @ptotal <> 0
|
|
|
if @pispre = '1'
|
|
|
set @ssql = @ssql+ 'and 消费金额 >= '+convert(varchar(10),@ptotal)
|
|
|
else
|
|
|
set @ssql = @ssql+ 'and 消费金额 <= '+convert(varchar(10),@ptotal)
|
|
|
if @pqrysql <> ''
|
|
|
set @ssql = @ssql + 'and '+@pqrysql
|
|
|
set @ssql = @ssql +
|
|
|
' order by 消费金额 desc,会员编码 asc '
|
|
|
exec (@ssql)
|
|
|
end
|
|
|
go
|
|
|
|
|
|
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[p_show_vip_xfmx]') and objectproperty(id, N'isprocedure') = 1)
|
|
|
drop procedure [dbo].[p_show_vip_xfmx]
|
|
|
go
|
|
|
create procedure p_show_vip_xfmx
|
|
|
@pvipdbname varchar(20),
|
|
|
@pbgndate varchar(10),
|
|
|
@penddate varchar(10),
|
|
|
@ptimesop varchar(2),
|
|
|
@ptimes int,
|
|
|
@ptotalop varchar(2),
|
|
|
@ptotal numeric(19,4),
|
|
|
@pqrysql varchar(8000),
|
|
|
@porgcode varchar(10),
|
|
|
@pclscode varchar(10),
|
|
|
@pdepcode varchar(10),
|
|
|
@pvipcode varchar(20),
|
|
|
@pishz varchar(1)
|
|
|
as
|
|
|
declare @ssql varchar(8000)
|
|
|
declare @stmpdate varchar(10)
|
|
|
declare @stmpenddate varchar(10)
|
|
|
declare @stotaltable varchar(20)
|
|
|
declare @sitemtable varchar(20)
|
|
|
begin
|
|
|
if exists(select name from tempdb..sysobjects where name='##tmpvipxfdata' and xtype='u')
|
|
|
drop table ##tmpvipxfdata
|
|
|
create table ##tmpvipxfdata
|
|
|
(posno varchar(6) not null,sdate varchar(10) not null,stime varchar(8) not null,serialno varchar(50) not null,trantype varchar(1) not null,orgcode varchar(10) not null,
|
|
|
orgname varchar(30) null,vipcode varchar(20) not null,vipname varchar(20) null,mobile1 varchar(20) null,mobile2 varchar(20) null,
|
|
|
plucode varchar(20) not null,pluname varchar(40) null,spec varchar(40) null,clscode varchar(10) null,clsname varchar(20) null,
|
|
|
depcode varchar(10) not null, depname varchar(20) null,brandcode varchar(10) null,brandname varchar(20) null,pluprice numeric(19,4) ,
|
|
|
pluqty numeric(19,4),plutotal numeric(19,4),pludsc numeric(19,4), sxorgcode varchar(10),sxdate varchar(10),jftotal numeric(19,4),
|
|
|
regclkcode varchar(6),regclkname varchar(10),regorgcode varchar(10),regorgname varchar(30))
|
|
|
|
|
|
set @stmpdate = convert(varchar(10), dateadd(month,-1,@pbgndate), 120)
|
|
|
set @stmpenddate = convert(varchar(10), dateadd(month,1,@penddate), 120)
|
|
|
while (substring(@stmpdate,1,4)+substring(@stmpdate,6,2))<=(substring(@stmpenddate,1,4)+substring(@stmpenddate,6,2))
|
|
|
begin
|
|
|
set @stotaltable = 't_flow_total_'+substring(@stmpdate,1,4)+substring(@stmpdate,6,2)
|
|
|
set @sitemtable = 't_flow_item_' +substring(@stmpdate,1,4)+substring(@stmpdate,6,2)
|
|
|
set @ssql='if exists(select name from sysobjects where name='''+@stotaltable+''' and xtype=''u'')
|
|
|
|
|
|
insert into ##tmpvipxfdata(posno,sdate,stime,serialno,trantype,orgcode,orgname,vipcode,vipname,mobile1,mobile2,plucode,pluname,spec,clscode,clsname,depcode,depname,
|
|
|
brandcode,brandname,pluprice,pluqty,plutotal,pludsc,sxorgcode,sxdate,jftotal,regclkcode,regclkname,regorgcode,regorgname)
|
|
|
select t.posno,t.sdate,t.stime,t.serialno,t.trantype,t.orgcode,sub.orgname,t.custcode,v.vipname,isnull(mobile1,'''') mobile1,isnull(mobile2,'''') mobile2,
|
|
|
s.plucode,g.pluname,g.spec,s.clscode,c.clsname,s.depcode,d.depname,g.brandcode ,b.brandname,s.pluprice,s.pluqty,
|
|
|
s.plutotal,s.pludsc,v.orgcode as sxorgcode,v.sxdate,isnull(jf.jftotal,0) as jftotal,v.regclkcode,v.regclkname,v.regorgcode,v.regorgname
|
|
|
from '+@stotaltable+' t join '+@sitemtable+' s
|
|
|
on t.serialno=s.serialno and t.posno=s.posno and t.orgcode=s.orgcode and t.sdate=s.sdate and t.stime = s.stime and t.trantype=s.trantype
|
|
|
and t.custflag=''2'' and isnull(t.custcode,'''') <> '''' and t.sdate between '''+@pbgndate+''' and '''+ @penddate+'''
|
|
|
join '+@pvipdbname+'..t_vip v on t.custcode=v.vipcode
|
|
|
join t_plu g on s.plucode=g.plucode
|
|
|
left join t_gclass c on s.clscode=c.clscode
|
|
|
left join t_dept d on s.depcode=d.depcode
|
|
|
left join t_brand b on g.brandcode =b.brandcode
|
|
|
left join t_shop sub on s.orgcode=sub.orgcode
|
|
|
left join '+@pvipdbname+'..t_vippt_item_flow jf
|
|
|
on s.serialno=jf.serialno and s.posno=jf.posno and s.orgcode=jf.orgcode and s.sdate=jf.sdate and s.stime = jf.stime and s.trantype=jf.trantype and t.custcode=jf.vipcode
|
|
|
and s.plucode = jf.plucode and cast(s.pageno as int) = cast(jf.pageno as int) and cast(s.itemno as int) = cast(jf.itemno as int)
|
|
|
where 1=1 and t.trantype in (''b'',''d'',''f'',''h'') '
|
|
|
if @porgcode <> '<全部>'
|
|
|
set @ssql = @ssql + ' and t.orgcode='''+@porgcode+''''
|
|
|
if @pclscode <> '000000'
|
|
|
set @ssql = @ssql + ' and c.clscode in (select clscode from t_gclass where clscode='+@pclscode+' or uppercode1='+@pclscode+' or uppercode2='+@pclscode+' or uppercode3='+@pclscode+' or uppercode4='+@pclscode+' or uppercode5='+@pclscode+') '
|
|
|
if @pdepcode <> '000000'
|
|
|
set @ssql = @ssql + ' and d.depcode in (select depcode from t_dept where depcode ='+@pdepcode+' or uppercode1='+@pdepcode+' or uppercode2='+@pdepcode+' or uppercode3='+@pdepcode+' or uppercode4='+@pdepcode+') '
|
|
|
if @pvipcode <> ''
|
|
|
set @ssql = @ssql + ' and t.custcode='''+@pvipcode+''''
|
|
|
exec (@ssql)
|
|
|
set @stmpdate=convert(varchar(10),dateadd(month,1,@stmpdate),120)
|
|
|
end
|
|
|
|
|
|
if @pishz <> '1'
|
|
|
begin
|
|
|
set @ssql=' select * from (
|
|
|
select orgcode,orgname,vipcode ,vipname ,sdate ,mobile1 , mobile2 ,
|
|
|
plucode ,pluname ,spec ,clscode,clsname,depcode ,depname ,
|
|
|
brandcode ,brandname ,pluprice ,pluqty,plutotal,pludsc ,jftotal,regclkcode,regclkname,regorgcode,regorgname
|
|
|
from ##tmpvipxfdata where 1=1 '
|
|
|
|
|
|
if @ptimes <> 0
|
|
|
begin
|
|
|
set @ssql = @ssql +
|
|
|
' and vipcode in
|
|
|
(select vipcode from
|
|
|
(select vipcode from ##tmpvipxfdata
|
|
|
where trantype=''b''
|
|
|
group by posno,sdate,stime,serialno,trantype,orgcode,vipcode) a
|
|
|
group by vipcode
|
|
|
having count(1) '+@ptimesop+convert(varchar(10),@ptimes)+')'
|
|
|
end
|
|
|
|
|
|
if @ptotal <> 0
|
|
|
begin
|
|
|
set @ssql = @ssql +
|
|
|
' and vipcode in
|
|
|
(select vipcode from ##tmpvipxfdata
|
|
|
group by vipcode
|
|
|
having sum(isnull(plutotal,0)) '+@ptotalop+convert(varchar(10),@ptotal)+')'
|
|
|
end
|
|
|
set @ssql = @ssql + ') a where 1=1 '
|
|
|
if @pqrysql <> ''
|
|
|
set @ssql = @ssql + 'and '+@pqrysql
|
|
|
set @ssql = @ssql +
|
|
|
' order by vipcode,orgcode'
|
|
|
exec (@ssql)
|
|
|
end
|
|
|
else
|
|
|
begin
|
|
|
set @ssql='select * from (
|
|
|
select times.vipcode,vipname,mobile1,mobile2,times,total,jftotal,sxorgcode,sxdate,regclkcode,regclkname,regorgcode,regorgname
|
|
|
from
|
|
|
(select vipcode,vipname,mobile1,mobile2,count(1) times,sxorgcode,sxdate,regclkcode,regclkname,regorgcode,regorgname from
|
|
|
(select vipcode,vipname,mobile1,mobile2,sxorgcode,sxdate,regclkcode,regclkname,regorgcode,regorgname from ##tmpvipxfdata
|
|
|
where trantype=''b''
|
|
|
group by posno,sdate,stime,serialno,trantype,orgcode,vipcode,vipname,mobile1,mobile2,sxorgcode,sxdate,regclkcode,regclkname,regorgcode,regorgname) a
|
|
|
group by vipcode,vipname,mobile1,mobile2,sxorgcode,sxdate,regclkcode,regclkname,regorgcode,regorgname '
|
|
|
if @ptimes <> 0
|
|
|
begin
|
|
|
set @ssql=@ssql+' having count(1) '+@ptimesop+convert(varchar(10),@ptimes)+') times'
|
|
|
end
|
|
|
else
|
|
|
begin
|
|
|
set @ssql=@ssql+' ) times'
|
|
|
end
|
|
|
set @ssql=@ssql+' join
|
|
|
(select vipcode,sum(isnull(plutotal,0)) total,sum(isnull(jftotal,0)) as jftotal from ##tmpvipxfdata
|
|
|
group by vipcode'
|
|
|
if @ptotal <> 0
|
|
|
begin
|
|
|
set @ssql=@ssql+' having sum(isnull(plutotal,0)) '+@ptotalop+convert(varchar(10),@ptotal)+') total'
|
|
|
end
|
|
|
else
|
|
|
begin
|
|
|
set @ssql=@ssql+') total'
|
|
|
end
|
|
|
set @ssql=@ssql+' on times.vipcode=total.vipcode ) a where 1=1 '
|
|
|
if @pqrysql <> ''
|
|
|
set @ssql = @ssql + 'and '+@pqrysql
|
|
|
set @ssql = @ssql +
|
|
|
' order by vipcode '
|
|
|
exec (@ssql)
|
|
|
end
|
|
|
end
|
|
|
go
|
|
|
|
|
|
if exists (select * from sysobjects where name='p_bulid_item_tend' and xtype='p')
|
|
|
drop procedure p_bulid_item_tend
|
|
|
go
|
|
|
create procedure p_bulid_item_tend
|
|
|
@stablename varchar(20),
|
|
|
@soutmessage varchar(100) out
|
|
|
as
|
|
|
declare @sdate varchar(10)
|
|
|
declare @ssql varchar(8000)
|
|
|
begin
|
|
|
select @sdate=convert(varchar(10),getdate(),20)
|
|
|
if not exists(select * from sysobjects where name=@stablename and xtype='u')
|
|
|
begin
|
|
|
set @ssql='
|
|
|
create table '+@stablename+'
|
|
|
(orgcode varchar(10) not null,
|
|
|
posno varchar(6) not null,
|
|
|
sdate varchar(10) not null,
|
|
|
stime varchar(8) not null,
|
|
|
serialno varchar(50) not null,
|
|
|
trantype varchar(1) not null,
|
|
|
pageno varchar(2) not null,
|
|
|
itemno varchar(5) not null,
|
|
|
accdate varchar(10) not null,
|
|
|
plucode varchar(20) not null,
|
|
|
barcode varchar(20) null,
|
|
|
pluname varchar(40) null,
|
|
|
depcode varchar(10) null,
|
|
|
depname varchar(16) null,
|
|
|
clscode varchar(10) null,
|
|
|
clsname varchar(20) null,
|
|
|
supcode varchar(15) null,
|
|
|
supname varchar(100) null,
|
|
|
brandcode varchar(10) null,
|
|
|
brandname varchar(20) null,
|
|
|
pludsctype varchar(1) null,
|
|
|
pluqty numeric(19,4) null default 0,
|
|
|
plutotal numeric(19,4) null default 0,
|
|
|
zf0 numeric(19,4) null default 0,
|
|
|
zf1 numeric(19,4) null default 0,
|
|
|
zf2 numeric(19,4) null default 0,
|
|
|
zf3 numeric(19,4) null default 0,
|
|
|
zf4 numeric(19,4) null default 0,
|
|
|
zf5 numeric(19,4) null default 0,
|
|
|
zf6 numeric(19,4) null default 0,
|
|
|
zf7 numeric(19,4) null default 0,
|
|
|
zf8 numeric(19,4) null default 0,
|
|
|
zf9 numeric(19,4) null default 0,
|
|
|
zf10 numeric(19,4) null default 0,
|
|
|
zf11 numeric(19,4) null default 0,
|
|
|
zf12 numeric(19,4) null default 0,
|
|
|
zf13 numeric(19,4) null default 0,
|
|
|
zfd numeric(19,4) null default 0,
|
|
|
zfe numeric(19,4) null default 0,
|
|
|
zff numeric(19,4) null default 0,
|
|
|
zfj numeric(19,4) null default 0,
|
|
|
zfm numeric(19,4) null default 0,
|
|
|
zfq numeric(19,4) null default 0,
|
|
|
zft numeric(19,4) null default 0,
|
|
|
zfu numeric(19,4) null default 0,
|
|
|
zfv numeric(19,4) null default 0,
|
|
|
zfw numeric(19,4) null default 0,
|
|
|
zfx numeric(19,4) null default 0,
|
|
|
zfy numeric(19,4) null default 0,
|
|
|
zfz numeric(19,4) null default 0,
|
|
|
remark varchar(200) null,
|
|
|
constraint [pk_'+@stablename+'] primary key nonclustered
|
|
|
(orgcode,posno,sdate,stime,serialno,trantype,pageno,itemno,accdate))'
|
|
|
exec(@ssql)
|
|
|
if @@error <> 0
|
|
|
begin
|
|
|
set @soutmessage = '创建表 ' + @stablename + ' 失败'
|
|
|
return 0
|
|
|
end
|
|
|
else
|
|
|
return 1
|
|
|
end
|
|
|
end
|
|
|
go
|
|
|
|
|
|
if exists (select * from sysobjects where name='p_tend_rpt' and xtype='p')
|
|
|
drop procedure p_tend_rpt
|
|
|
go
|
|
|
create procedure p_tend_rpt
|
|
|
@saccdate varchar(10)
|
|
|
as
|
|
|
declare @sdate varchar(10)
|
|
|
declare @stablename varchar(20)
|
|
|
declare @ssql varchar(8000)
|
|
|
declare @createtendrpt varchar(1)
|
|
|
declare @soutmsg varchar(100)
|
|
|
begin
|
|
|
select @createtendrpt = isnull(itemvalue,'') from t_syscfg where section = 'system' and itemname = 'createtendrpt'
|
|
|
if @createtendrpt <> '1'
|
|
|
begin
|
|
|
return (1)
|
|
|
end
|
|
|
|
|
|
select @sdate=@saccdate
|
|
|
set @stablename='t_itemtend_'+substring(@sdate,1,4)+substring(@sdate,6,2)
|
|
|
exec p_bulid_item_tend @stablename ,@soutmsg out
|
|
|
if @@error <> 0 goto lbl_fail
|
|
|
|
|
|
if exists(select name from sysobjects where name='tmplspay' and xtype='u')
|
|
|
drop table tmplspay
|
|
|
create table tmplspay
|
|
|
(posno varchar(6) not null,
|
|
|
orgcode varchar(10) not null,
|
|
|
sdate varchar(10) not null,
|
|
|
stime varchar(8) not null,
|
|
|
serialno varchar(50) not null,
|
|
|
accdate varchar(10) not null,
|
|
|
trantype varchar(1) not null,
|
|
|
paytotal numeric (19,4) null default 0,
|
|
|
zf0 numeric(19,4) null default 0,
|
|
|
zf1 numeric(19,4) null default 0,
|
|
|
zf2 numeric(19,4) null default 0,
|
|
|
zf3 numeric(19,4) null default 0,
|
|
|
zf4 numeric(19,4) null default 0,
|
|
|
zf5 numeric(19,4) null default 0,
|
|
|
zf6 numeric(19,4) null default 0,
|
|
|
zf7 numeric(19,4) null default 0,
|
|
|
zf8 numeric(19,4) null default 0,
|
|
|
zf9 numeric(19,4) null default 0,
|
|
|
zfy numeric(19,4) null default 0,
|
|
|
zfx numeric(19,4) null default 0,
|
|
|
zfz numeric(19,4) null default 0,
|
|
|
zfw numeric(19,4) null default 0,
|
|
|
zfd numeric(19,4) null default 0,
|
|
|
zfq numeric(19,4) null default 0,
|
|
|
zfv numeric(19,4) null default 0,
|
|
|
zfu numeric(19,4) null default 0,
|
|
|
zfe numeric(19,4) null default 0,
|
|
|
zfj numeric(19,4) null default 0,
|
|
|
zft numeric(19,4) null default 0,
|
|
|
zff numeric(19,4) null default 0,
|
|
|
zfm numeric(19,4) null default 0,
|
|
|
zf10 numeric(19,4) null default 0,
|
|
|
zf11 numeric(19,4) null default 0,
|
|
|
zf12 numeric(19,4) null default 0,
|
|
|
zf13 numeric(19,4) null default 0,
|
|
|
constraint [pk_tmplspay] primary key nonclustered
|
|
|
(posno,orgcode,sdate,stime,serialno,trantype,accdate))
|
|
|
if @@error <> 0 goto lbl_fail
|
|
|
|
|
|
insert into tmplspay (posno,orgcode,sdate,stime,serialno,accdate,trantype,zf0,zf1,zf2,zf3,zf4,zf5,zf6,zf7,zf8,zf9,zfy,zfx,zfw,zfd,zfq,zfz,zfv,zfu,zfe,zfj,zft,zff,zfm,zf10,zf11,zf12,zf13)
|
|
|
select posno,orgcode,sdate,stime,serialno,accdate,trantype,sum(zf0),sum(zf1),sum(zf2),sum(zf3),sum(zf4),sum(zf5),sum(zf6),sum(zf7),sum(zf8),sum(zf9),sum(zfy),
|
|
|
sum(zfx),sum(zfw),sum(zfd),sum(zfq),sum(zfz),sum(zfv),sum(zfu),sum(zfe),sum(zfj),sum(zft),sum(zff),sum(zfm),sum(zf10),sum(zf11),sum(zf12),sum(zf13) from
|
|
|
(select posno,orgcode,sdate,stime,serialno,accdate,trantype,
|
|
|
case p.payflag when '0' then p.amount else 0 end as zf0,
|
|
|
case p.payflag when '1' then p.amount else 0 end as zf1,
|
|
|
case p.payflag when '2' then p.amount else 0 end as zf2,
|
|
|
case p.payflag when '3' then p.amount else 0 end as zf3,
|
|
|
case p.payflag when '4' then p.amount else 0 end as zf4,
|
|
|
case p.payflag when '5' then p.amount else 0 end as zf5,
|
|
|
case p.payflag when '6' then p.amount else 0 end as zf6,
|
|
|
case p.payflag when '7' then p.amount else 0 end as zf7,
|
|
|
case p.payflag when '8' then p.amount else 0 end as zf8,
|
|
|
case p.payflag when '9' then p.amount else 0 end as zf9,
|
|
|
case p.payflag when 'y' then p.amount else 0 end as zfy,
|
|
|
case p.payflag when 'x' then p.amount else 0 end as zfx,
|
|
|
case p.payflag when 'w' then p.amount else 0 end as zfw,
|
|
|
case p.payflag when ':' then p.amount else 0 end as zfd,
|
|
|
case p.payflag when '=' then p.amount else 0 end as zfq,
|
|
|
case p.payflag when 'z' then p.amount else 0 end as zfz,
|
|
|
case p.payflag when 'v' then p.amount else 0 end as zfv,
|
|
|
case p.payflag when 'u' then p.amount else 0 end as zfu,
|
|
|
case p.payflag when '<' then p.amount else 0 end as zfe,
|
|
|
case p.payflag when '?' then p.amount else 0 end as zfj,
|
|
|
case p.payflag when 't' then p.amount else 0 end as zft,
|
|
|
case p.payflag when 'f' then p.amount else 0 end as zff,
|
|
|
case p.payflag when 'm' then p.amount else 0 end as zfm,
|
|
|
case p.payflag when 'a' then p.amount else 0 end as zf10,
|
|
|
case p.payflag when 'b' then p.amount else 0 end as zf11,
|
|
|
case p.payflag when 'c' then p.amount else 0 end as zf12,
|
|
|
case p.payflag when 'd' then p.amount else 0 end as zf13
|
|
|
from t_flow_endpay p where p.tag = '1' and trantype <> ':' and trantype <> '=' ) a
|
|
|
group by posno,orgcode,sdate,stime,serialno,accdate,trantype
|
|
|
if @@error <> 0 goto lbl_fail
|
|
|
|
|
|
update tmplspay set paytotal = zf0 + zf1 + zf2 + zf3 + zf4 + zf5 + zf6 + zf7 + zf8 + zf9 + zfy + zfx + zfz + zfw + zfd + zfq + zfv + zfu + zfe + zfj + zft + zff + zfm +zf10 + zf11 + zf12 + zf13
|
|
|
if @@error <> 0 goto lbl_fail
|
|
|
|
|
|
if exists(select name from sysobjects where name='tmplsitem' and xtype='u')
|
|
|
drop table tmplsitem
|
|
|
create table tmplsitem
|
|
|
(posno varchar(6) not null,
|
|
|
orgcode varchar(10) not null,
|
|
|
sdate varchar(10) not null,
|
|
|
stime varchar(8) not null,
|
|
|
serialno varchar(50) not null,
|
|
|
pageno varchar(2) not null,
|
|
|
itemno varchar(5) not null,
|
|
|
accdate varchar(10) not null,
|
|
|
trantype varchar(1) not null,
|
|
|
plucode varchar(20) not null,
|
|
|
pluname varchar(40) null,
|
|
|
barcode varchar(20) null,
|
|
|
pludsctype varchar(1) null,
|
|
|
pluqty numeric(19,4) null default 0,
|
|
|
plutotal numeric(19,4) null default 0,
|
|
|
zf0 numeric(19,4) null default 0,
|
|
|
zf1 numeric(19,4) null default 0,
|
|
|
zf2 numeric(19,4) null default 0,
|
|
|
zf3 numeric(19,4) null default 0,
|
|
|
zf4 numeric(19,4) null default 0,
|
|
|
zf5 numeric(19,4) null default 0,
|
|
|
zf6 numeric(19,4) null default 0,
|
|
|
zf7 numeric(19,4) null default 0,
|
|
|
zf8 numeric(19,4) null default 0,
|
|
|
zf9 numeric(19,4) null default 0,
|
|
|
zfy numeric(19,4) null default 0,
|
|
|
zfx numeric(19,4) null default 0,
|
|
|
zfz numeric(19,4) null default 0,
|
|
|
zfw numeric(19,4) null default 0,
|
|
|
zfd numeric(19,4) null default 0,
|
|
|
zfq numeric(19,4) null default 0,
|
|
|
zfv numeric(19,4) null default 0,
|
|
|
zfu numeric(19,4) null default 0,
|
|
|
zfe numeric(19,4) null default 0,
|
|
|
zfj numeric(19,4) null default 0,
|
|
|
zft numeric(19,4) null default 0,
|
|
|
zff numeric(19,4) null default 0,
|
|
|
zfm numeric(19,4) null default 0,
|
|
|
zf10 numeric(19,4) null default 0,
|
|
|
zf11 numeric(19,4) null default 0,
|
|
|
zf12 numeric(19,4) null default 0,
|
|
|
zf13 numeric(19,4) null default 0,
|
|
|
orderno int identity(1,1) not null,
|
|
|
constraint [pk_tmplsitem] primary key nonclustered
|
|
|
(posno,orgcode,sdate,stime,serialno,pageno,itemno,trantype,accdate))
|
|
|
if @@error <> 0 goto lbl_fail
|
|
|
|
|
|
insert into tmplsitem (posno,orgcode,sdate,stime,serialno,pageno,itemno,accdate,trantype,plucode,barcode,pluname,pludsctype,pluqty,plutotal)
|
|
|
select posno,orgcode,sdate,stime,serialno,pageno,itemno,accdate,trantype,plucode,barcode,pluname,pludsctype,pluqty,plutotal
|
|
|
from t_flow_enditem i where i.tag = '1' and trantype <> '=' and trantype <> ':' order by posno,orgcode,sdate,stime,serialno,trantype,accdate,plutotal desc
|
|
|
if @@error <> 0 goto lbl_fail
|
|
|
|
|
|
update i set
|
|
|
zf0 = round(p.zf0 * (i.plutotal / p.paytotal), 2),
|
|
|
zf1 = round(p.zf1 * (i.plutotal / p.paytotal), 2),
|
|
|
zf2 = round(p.zf2 * (i.plutotal / p.paytotal), 2),
|
|
|
zf3 = round(p.zf3 * (i.plutotal / p.paytotal), 2),
|
|
|
zf4 = round(p.zf4 * (i.plutotal / p.paytotal), 2),
|
|
|
zf5 = round(p.zf5 * (i.plutotal / p.paytotal), 2),
|
|
|
zf6 = round(p.zf6 * (i.plutotal / p.paytotal), 2),
|
|
|
zf7 = round(p.zf7 * (i.plutotal / p.paytotal), 2),
|
|
|
zf8 = round(p.zf8 * (i.plutotal / p.paytotal), 2),
|
|
|
zf9 = round(p.zf9 * (i.plutotal / p.paytotal), 2),
|
|
|
zfy = round(p.zfy * (i.plutotal / p.paytotal), 2),
|
|
|
zfx = round(p.zfx * (i.plutotal / p.paytotal), 2),
|
|
|
zfw = round(p.zfw * (i.plutotal / p.paytotal), 2),
|
|
|
zfz = round(p.zfz * (i.plutotal / p.paytotal), 2),
|
|
|
zfd = round(p.zfd * (i.plutotal / p.paytotal), 2),
|
|
|
zfq = round(p.zfq * (i.plutotal / p.paytotal), 2),
|
|
|
zfv = round(p.zfv * (i.plutotal / p.paytotal), 2),
|
|
|
zfu = round(p.zfu * (i.plutotal / p.paytotal), 2),
|
|
|
zfe = round(p.zfe * (i.plutotal / p.paytotal), 2),
|
|
|
zfj = round(p.zfj * (i.plutotal / p.paytotal), 2),
|
|
|
zft = round(p.zft * (i.plutotal / p.paytotal), 2),
|
|
|
zff = round(p.zff * (i.plutotal / p.paytotal), 2),
|
|
|
zfm = round(p.zfm * (i.plutotal / p.paytotal), 2),
|
|
|
zf10 = round(p.zf10 * (i.plutotal / p.paytotal), 2),
|
|
|
zf11 = round(p.zf11 * (i.plutotal / p.paytotal), 2),
|
|
|
zf12 = round(p.zf12 * (i.plutotal / p.paytotal), 2),
|
|
|
zf13 = round(p.zf13 * (i.plutotal / p.paytotal), 2)
|
|
|
from tmplsitem i,tmplspay p
|
|
|
where i.posno = p.posno and i.orgcode = p.orgcode and i.sdate = p.sdate and i.stime = p.stime
|
|
|
and i.serialno = p.serialno and i.accdate = p.accdate and i.trantype = p.trantype
|
|
|
and p.paytotal <> 0
|
|
|
if @@error <> 0 goto lbl_fail
|
|
|
|
|
|
if exists(select name from sysobjects where name='maxplu' and xtype='u')
|
|
|
drop table maxplu
|
|
|
create table maxplu
|
|
|
(posno varchar(6) not null,
|
|
|
orgcode varchar(10) not null,
|
|
|
sdate varchar(10) not null,
|
|
|
stime varchar(8) not null,
|
|
|
serialno varchar(50) not null,
|
|
|
accdate varchar(10) not null,
|
|
|
trantype varchar(1) not null,
|
|
|
orderno varchar(8) not null,
|
|
|
constraint [pk_maxplu] primary key nonclustered
|
|
|
(posno,orgcode,sdate,stime,serialno,trantype,accdate))
|
|
|
if @@error <> 0 goto lbl_fail
|
|
|
|
|
|
insert maxplu(posno,orgcode,sdate,stime,serialno,accdate,trantype,orderno) select posno,orgcode,sdate,stime,serialno,accdate,trantype,min(orderno) orderno
|
|
|
from tmplsitem group by posno,orgcode,sdate,stime,serialno,accdate,trantype
|
|
|
|
|
|
if exists(select name from sysobjects where name='tmplsitemmaxplu' and xtype='u')
|
|
|
drop table tmplsitemmaxplu
|
|
|
create table tmplsitemmaxplu
|
|
|
(posno varchar(6) not null,
|
|
|
orgcode varchar(10) not null,
|
|
|
sdate varchar(10) not null,
|
|
|
stime varchar(8) not null,
|
|
|
serialno varchar(50) not null,
|
|
|
pageno varchar(2) not null,
|
|
|
itemno varchar(5) not null,
|
|
|
accdate varchar(10) not null,
|
|
|
trantype varchar(1) not null,
|
|
|
plucode varchar(20) not null,
|
|
|
pluname varchar(40) null,
|
|
|
barcode varchar(20) null,
|
|
|
pludsctype varchar(1) null,
|
|
|
pluqty numeric(19,4) null default 0,
|
|
|
plutotal numeric(19,4) null default 0,
|
|
|
zf0 numeric(19,4) null default 0,
|
|
|
zf1 numeric(19,4) null default 0,
|
|
|
zf2 numeric(19,4) null default 0,
|
|
|
zf3 numeric(19,4) null default 0,
|
|
|
zf4 numeric(19,4) null default 0,
|
|
|
zf5 numeric(19,4) null default 0,
|
|
|
zf6 numeric(19,4) null default 0,
|
|
|
zf7 numeric(19,4) null default 0,
|
|
|
zf8 numeric(19,4) null default 0,
|
|
|
zf9 numeric(19,4) null default 0,
|
|
|
zfy numeric(19,4) null default 0,
|
|
|
zfx numeric(19,4) null default 0,
|
|
|
zfz numeric(19,4) null default 0,
|
|
|
zfw numeric(19,4) null default 0,
|
|
|
zfd numeric(19,4) null default 0,
|
|
|
zfq numeric(19,4) null default 0,
|
|
|
zfv numeric(19,4) null default 0,
|
|
|
zfu numeric(19,4) null default 0,
|
|
|
zfe numeric(19,4) null default 0,
|
|
|
zfj numeric(19,4) null default 0,
|
|
|
zft numeric(19,4) null default 0,
|
|
|
zff numeric(19,4) null default 0,
|
|
|
zfm numeric(19,4) null default 0,
|
|
|
zf10 numeric(19,4) null default 0,
|
|
|
zf11 numeric(19,4) null default 0,
|
|
|
zf12 numeric(19,4) null default 0,
|
|
|
zf13 numeric(19,4) null default 0,
|
|
|
orderno varchar(8) not null,
|
|
|
constraint [pk_tmplsitemmaxplu] primary key nonclustered
|
|
|
(posno,orgcode,sdate,stime,serialno,pageno,itemno,trantype,accdate))
|
|
|
if @@error <> 0 goto lbl_fail
|
|
|
|
|
|
insert tmplsitemmaxplu(posno,orgcode,sdate,stime,serialno,pageno,itemno, accdate,trantype,plucode,pluname,barcode,pludsctype,pluqty,plutotal,zf0,zf1,zf2,zf3,zf4,zf5,zf6,zf7,zf8,zf9,zfy,zfx,zfz,zfw,zfd,zfq ,zfv,zfu,zfe,zfj,zft,zff,zfm,zf10,zf11,zf12,zf13,orderno)
|
|
|
select t_flow_item.posno,t_flow_item.orgcode,t_flow_item.sdate,t_flow_item.stime,t_flow_item.serialno,pageno,itemno,t_flow_item. accdate,t_flow_item.trantype,plucode,pluname,barcode,pludsctype,pluqty,plutotal,zf0,zf1,zf2,zf3,zf4,zf5,zf6,zf7,zf8,zf9,zfy,zfx,zfz,zfw,zfd,zfq ,zfv,zfu,zfe,zfj,zft,zff,zfm,zf10,zf11,zf12,zf13,t_flow_item.orderno from tmplsitem t_flow_item, maxplu
|
|
|
where t_flow_item.posno = maxplu.posno and t_flow_item.orgcode = maxplu.orgcode and t_flow_item.sdate = maxplu.sdate and t_flow_item.stime = maxplu.stime and t_flow_item.serialno = maxplu.serialno and t_flow_item.accdate = maxplu.accdate and t_flow_item.trantype = maxplu.trantype and t_flow_item.orderno = maxplu.orderno
|
|
|
|
|
|
update tmplsitemmaxplu set
|
|
|
zf0 = zf0 + diff.diff0,zf1 = zf1 + diff.diff1, zf2 = zf2 + diff.diff2,
|
|
|
zf3 = zf3 + diff.diff3,zf4 = zf4 + diff.diff4, zf5 = zf5 + diff.diff5,
|
|
|
zf6 = zf6 + diff.diff6,zf7 = zf7 + diff.diff7, zf8 = zf8 + diff.diff8,
|
|
|
zf9 = zf9 + diff.diff9,zfy = zfy + diff.diffy, zfx = zfx + diff.diffx,
|
|
|
zfz = zfz + diff.diffz,zfw = zfw + diff.diffw, zfd = zfd + diff.diffd,
|
|
|
zfq = zfq + diff.diffq,zfv = zfv + diff.diffv, zfu = zfu + diff.diffu,
|
|
|
zfe = zfe + diff.diffe,zfj = zfj + diff.diffj, zft = zft + diff.difft, zff = zff + diff.difff,zfm = zfm + diff.diffm,
|
|
|
zf10 = zf10 + diff.diff10, zf11 = zf11 + diff.diff11, zf12 = zf12 + diff.diff12, zf13 = zf13 + diff.diff13
|
|
|
from
|
|
|
(select p.posno,p.orgcode,p.sdate,p.stime,p.serialno,p.accdate,p.trantype,
|
|
|
p.zf0 - i.zf0 as diff0, p.zf1 - i.zf1 as diff1, p.zf2 - i.zf2 as diff2,
|
|
|
p.zf3 - i.zf3 as diff3, p.zf4 - i.zf4 as diff4, p.zf5 - i.zf5 as diff5,
|
|
|
p.zf6 - i.zf6 as diff6, p.zf7 - i.zf7 as diff7, p.zf8 - i.zf8 as diff8,
|
|
|
p.zf9 - i.zf9 as diff9, p.zfy - i.zfy as diffy, p.zfx - i.zfx as diffx,
|
|
|
p.zfz - i.zfz as diffz, p.zfw - i.zfw as diffw, p.zfd - i.zfd as diffd,
|
|
|
p.zfq - i.zfq as diffq, p.zfv - i.zfv as diffv, p.zfu - i.zfu as diffu,
|
|
|
p.zfe - i.zfe as diffe, p.zfj - i.zfj as diffj, p.zft - i.zft as difft, p.zff - i.zff as difff,p.zfm - i.zfm as diffm,
|
|
|
p.zf10 - i.zf10 as diff10, p.zf11 - i.zf11 as diff11, p.zf12 - i.zf12 as diff12,p.zf13 - i.zf13 as diff13
|
|
|
from
|
|
|
(select posno,orgcode,sdate,stime,serialno,accdate,trantype,
|
|
|
sum(zf0) zf0,sum(zf1) zf1,sum(zf2) zf2,sum(zf3) zf3,sum(zf4) zf4,sum(zf5) zf5,sum(zf6) zf6,
|
|
|
sum(zf7) zf7,sum(zf8) zf8,sum(zf9) zf9,sum(zfy) zfy,sum(zfx) zfx,sum(zfz) zfz ,sum(zfw) zfw,
|
|
|
sum(zfd) zfd,sum(zfq) zfq,sum(zfv) zfv,sum(zfu) zfu,sum(zfe) zfe,sum(zfj) zfj,sum(zft) zft, sum(zff) zff,sum(zfm) zfm,
|
|
|
sum(zf10) zf10,sum(zf11) zf11,sum(zf12) zf12,sum(zf13) zf13
|
|
|
from tmplsitem group by posno,orgcode,sdate,stime,serialno,accdate,trantype) i,
|
|
|
tmplspay p where i.posno = p.posno and i.orgcode = p.orgcode and i.sdate = p.sdate and i.stime = p.stime
|
|
|
and i.serialno = p.serialno and i.accdate = p.accdate and i.trantype =p.trantype) diff,
|
|
|
tmplsitemmaxplu
|
|
|
where tmplsitemmaxplu.posno = diff.posno
|
|
|
and tmplsitemmaxplu.orgcode = diff.orgcode
|
|
|
and tmplsitemmaxplu.sdate = diff.sdate
|
|
|
and tmplsitemmaxplu.stime = diff.stime
|
|
|
and tmplsitemmaxplu.serialno = diff.serialno
|
|
|
and tmplsitemmaxplu.accdate = diff.accdate
|
|
|
and tmplsitemmaxplu.trantype = diff.trantype
|
|
|
|
|
|
if @@error <> 0 goto lbl_fail
|
|
|
|
|
|
set @ssql='
|
|
|
insert into '+@stablename+'(posno,orgcode,sdate,stime,serialno,pageno,itemno,plucode,accdate,trantype,pluname,barcode,clscode,clsname,depcode,depname,brandcode,
|
|
|
brandname,supcode ,supname,pludsctype,pluqty,plutotal,
|
|
|
zf0,zf1,zf2,zf3,zf4,zf5,zf6,zf7,zf8,zf9,zfy,zfx,zfz,zfw,zfd,zfq,zfv,zfu,zfe,zfj,zft,zff,zfm,zf10,zf11,zf12,zf13)
|
|
|
select distinct i.posno,i.orgcode,i.sdate,i.stime,i.serialno,i.pageno,i.itemno,i.plucode,i.accdate,i.trantype,i.pluname,i.barcode,
|
|
|
gds.clscode,gds.clsname,gds.depcode,gds.depname,gds.brandcode,
|
|
|
gds.brandname,gds.supcode ,gds.supname,i.pludsctype,i.pluqty,i.plutotal,
|
|
|
i.zf0,i.zf1,i.zf2,i.zf3,i.zf4,i.zf5,i.zf6,i.zf7,i.zf8,i.zf9,i.zfy,i.zfx,i.zfz,i.zfw,i.zfd,i.zfq,i.zfv,i.zfu,i.zfe,i.zfj,i.zft,i.zff,i.zfm,i.zf10,i.zf11,i.zf12,i.zf13
|
|
|
from tmplsitem i
|
|
|
left join
|
|
|
(select g.plucode,g.pluname,g.depcode,d.depname,g.clscode,c.clsname,g.brandcode,b.brandname,g.supcode,v.supname
|
|
|
from t_plu g
|
|
|
left join t_dept d on g.depcode=d.depcode
|
|
|
left join t_gclass c on g.clscode=c.clscode
|
|
|
left join t_brand b on g.brandcode=b.brandcode
|
|
|
left join t_supplier v on g.supcode=v.supcode) gds on i.plucode=gds.plucode
|
|
|
where not exists(select posno from '+@stablename+'
|
|
|
where posno=i.posno and orgcode=i.orgcode and sdate=i.sdate and stime=i.stime and serialno=i.serialno
|
|
|
and pageno=i.pageno and itemno=i.itemno and trantype=i.trantype and accdate=i.accdate)'
|
|
|
exec(@ssql)
|
|
|
if @@error <> 0 goto lbl_fail
|
|
|
|
|
|
if exists(select name from sysobjects where name='tmplspay' and xtype='u')
|
|
|
drop table tmplspay
|
|
|
if exists(select name from sysobjects where name='tmplsitem' and xtype='u')
|
|
|
drop table tmplsitem
|
|
|
if exists(select name from sysobjects where name='tmplsitemmaxplu' and xtype='u')
|
|
|
drop table tmplsitemmaxplu
|
|
|
if exists(select name from sysobjects where name='maxplu' and xtype='u')
|
|
|
drop table maxplu
|
|
|
|
|
|
return 1
|
|
|
|
|
|
lbl_fail:
|
|
|
return 0
|
|
|
end
|
|
|
go
|
|
|
|
|
|
if exists (select * from dbo.sysobjects where id = object_id(N'p_vip_qry_by4') and objectproperty(id, N'isprocedure') = 1)
|
|
|
drop procedure p_vip_qry_by4
|
|
|
go
|
|
|
|
|
|
create procedure p_vip_qry_by4
|
|
|
@vs_bgndate varchar(10),
|
|
|
@vs_enddate varchar(10),
|
|
|
@vipdbname varchar(20),
|
|
|
@viptype varchar(2000),
|
|
|
@vf_contotal numeric(19,2),
|
|
|
@vi_contimes numeric(19,0),
|
|
|
@vs_qry varchar(200),
|
|
|
@vs_orderby varchar(100),
|
|
|
@vs_edition varchar(10)
|
|
|
as
|
|
|
declare
|
|
|
@vs_nowdate varchar(10),
|
|
|
@stmpdate varchar(10),
|
|
|
@vs_where varchar(2000),
|
|
|
@vs_qrysql varchar(8000),
|
|
|
@i integer,
|
|
|
@vs_vipcode varchar(20),
|
|
|
@vs_clsid varchar(20),
|
|
|
@vs_clsname varchar(40)
|
|
|
begin
|
|
|
set @vs_nowdate = convert(char(10),getdate(),120)
|
|
|
set @vs_where=' 1=1 '
|
|
|
|
|
|
if @vs_bgndate > @vs_enddate
|
|
|
begin
|
|
|
raiserror('开始日期应该小于等于结束日期,请查看',16,1)
|
|
|
end;
|
|
|
if @vs_bgndate<>''
|
|
|
set @vs_where = @vs_where + ' and e.sdate>=''' + @vs_bgndate + ''''
|
|
|
|
|
|
if @vs_enddate<>''
|
|
|
set @vs_where = @vs_where + ' and e.sdate<=''' + @vs_enddate + ''''
|
|
|
|
|
|
create table #trptcon_tmp
|
|
|
(vipcode varchar(20) null,
|
|
|
contotal numeric(19,2) default(0),
|
|
|
trantimes numeric(19,0) default(0))
|
|
|
|
|
|
create table #trptconplu_tmp
|
|
|
(vipcode varchar(20) null,
|
|
|
plucode varchar(20) null)
|
|
|
|
|
|
set @stmpdate=@vs_bgndate
|
|
|
while left(@stmpdate,7)<=left(@vs_enddate,7)
|
|
|
begin
|
|
|
if exists(select name from sysobjects where name='t_flow_total_'+left(@stmpdate,4)+substring(@stmpdate,6,2) and xtype='u')
|
|
|
begin
|
|
|
set @vs_qrysql='insert into #trptcon_tmp(vipcode,contotal,trantimes)
|
|
|
select custcode,isnull(sum(total),0),isnull(count(orgcode),0)
|
|
|
from t_flow_total_' + substring(@stmpdate,1,4)+substring(@stmpdate,6,2)+ ' e
|
|
|
where ' + @vs_where +' and (custcode<>'''' and custcode is not null) group by custcode'
|
|
|
exec(@vs_qrysql)
|
|
|
end
|
|
|
|
|
|
if exists(select name from sysobjects where name='t_flow_item_'+left(@stmpdate,4)+substring(@stmpdate,6,2) and xtype='u')
|
|
|
begin
|
|
|
set @vs_qrysql='insert into #trptconplu_tmp(vipcode,plucode)
|
|
|
select e.custcode,i.plucode
|
|
|
from t_flow_item_' + substring(@stmpdate,1,4)+substring(@stmpdate,6,2)+ ' i,t_flow_total_'
|
|
|
+ substring(@stmpdate,1,4)+substring(@stmpdate,6,2)+ ' e
|
|
|
where ' + @vs_where +
|
|
|
' and i.orgcode=e.orgcode and i.posno=e.posno and i.sdate=e.sdate and i.stime=e.stime and i.trantype=e.trantype '+
|
|
|
' and i.serialno=e.serialno and i.accdate=e.accdate'+
|
|
|
' and (e.custcode<>'''' and e.custcode is not null) group by e.custcode,i.plucode'
|
|
|
exec(@vs_qrysql)
|
|
|
end
|
|
|
|
|
|
set @stmpdate=convert(varchar(10),dateadd(month,1,@stmpdate),120)
|
|
|
end
|
|
|
|
|
|
create table #tvipconby4
|
|
|
(vipcode varchar(20) null,
|
|
|
vipname varchar(40) null,
|
|
|
tel varchar(20) null,
|
|
|
mobile1 varchar(20) null,
|
|
|
mobile2 varchar(20) null,
|
|
|
vipsex varchar(10) null,
|
|
|
contotal numeric(19,2) default (0),
|
|
|
trantimes numeric(19,0) default (0),
|
|
|
avgvipprice numeric(19,2) default (0),
|
|
|
viptype1 int default (0),
|
|
|
viptype2 int default (0),
|
|
|
viptype3 int default (0),
|
|
|
viptype4 int default (0),
|
|
|
firstclass varchar(40) null,
|
|
|
secondclass varchar(40) null
|
|
|
)
|
|
|
insert into #tvipconby4(vipcode,vipname,contotal,trantimes,avgvipprice,viptype1)
|
|
|
select vipcode,vipcode,sum(contotal),sum(trantimes),
|
|
|
case when sum(trantimes)=0 then 0 else sum(contotal)/sum(trantimes) end,1--'知己'
|
|
|
from #trptcon_tmp
|
|
|
group by vipcode having sum(contotal)>=@vf_contotal and sum(trantimes)>=@vi_contimes
|
|
|
|
|
|
insert into #tvipconby4(vipcode,vipname,contotal,trantimes,avgvipprice,viptype2)
|
|
|
select vipcode,vipcode,sum(contotal),sum(trantimes),
|
|
|
case when sum(trantimes)=0 then 0 else sum(contotal)/sum(trantimes) end,1--'藤壶'
|
|
|
from #trptcon_tmp
|
|
|
group by vipcode having sum(contotal)<@vf_contotal and sum(trantimes)>=@vi_contimes
|
|
|
|
|
|
insert into #tvipconby4(vipcode,vipname,contotal,trantimes,avgvipprice,viptype3)
|
|
|
select vipcode,vipcode,sum(contotal),sum(trantimes),
|
|
|
case when sum(trantimes)=0 then 0 else sum(contotal)/sum(trantimes) end,1--'蝴蝶'
|
|
|
from #trptcon_tmp
|
|
|
group by vipcode having sum(contotal)>=@vf_contotal and sum(trantimes)<@vi_contimes
|
|
|
|
|
|
insert into #tvipconby4(vipcode,vipname,contotal,trantimes,avgvipprice,viptype4)
|
|
|
select vipcode,vipcode,sum(contotal),sum(trantimes),
|
|
|
case when sum(trantimes)=0 then 0 else sum(contotal)/sum(trantimes) end,1--'过客'
|
|
|
from #trptcon_tmp
|
|
|
group by vipcode having sum(contotal)<@vf_contotal and sum(trantimes)<@vi_contimes
|
|
|
|
|
|
set @vs_qrysql='update a set a.vipname=b.vipname,a.vipsex=b.vipsex,a.tel=b.tel,a.mobile1=b.mobile1,a.mobile2=b.mobile2
|
|
|
from #tvipconby4 a,'+@vipdbname+'.dbo.t_vip b with(nolock)
|
|
|
where a.vipcode=b.vipcode and (a.vipcode<>'''' and a.vipcode is not null)'
|
|
|
exec(@vs_qrysql)
|
|
|
|
|
|
if exists (select * from tempdb..sysobjects where name like '#vipclass%')
|
|
|
drop table #vipclass
|
|
|
|
|
|
create table #vipclass
|
|
|
(vipcode varchar(20),
|
|
|
clscode varchar(10),
|
|
|
clsname varchar(20),
|
|
|
clsidcount integer)
|
|
|
|
|
|
if @vs_edition = '3'
|
|
|
begin
|
|
|
insert into #vipclass(vipcode,clscode,clsname,clsidcount)
|
|
|
select vipcode,c.depcode as clscode,max(depname) as clsname,count(a.plucode) as clsidcount
|
|
|
from #trptconplu_tmp a,t_plu b,t_dept c
|
|
|
where a.plucode=b.plucode and b.depcode=c.depcode
|
|
|
group by vipcode,c.depcode,c.depname
|
|
|
end
|
|
|
else
|
|
|
begin
|
|
|
insert into #vipclass(vipcode,clscode,clsname,clsidcount)
|
|
|
select vipcode,c.brandcode as clscode,max(brandname) as clsname,count(a.plucode) as clsidcount
|
|
|
from #trptconplu_tmp a,t_plu b,t_brand c
|
|
|
where a.plucode=b.plucode and b.brandcode =c.brandcode
|
|
|
group by vipcode,c.brandcode,c.brandname
|
|
|
end
|
|
|
|
|
|
declare chcurtmp cursor for select vipcode from #tvipconby4
|
|
|
open chcurtmp
|
|
|
fetch chcurtmp into @vs_vipcode
|
|
|
while @@fetch_status>=0
|
|
|
begin
|
|
|
select top 1 @vs_clsid=case when isnull(clscode,'')='' then 'none' else clscode end,
|
|
|
@vs_clsname=case when isnull(clsname,'')='' then '不明品牌' else clsname end
|
|
|
from #vipclass where vipcode=@vs_vipcode order by clsidcount desc
|
|
|
|
|
|
update #tvipconby4 set firstclass= rtrim(@vs_clsid)+'-'+rtrim(@vs_clsname) where vipcode=@vs_vipcode
|
|
|
|
|
|
select top 1 @vs_clsid=case when isnull(clscode,'')='' then 'none' else clscode end,
|
|
|
@vs_clsname=case when isnull(clsname,'')='' then '不明品牌' else clsname end
|
|
|
from #vipclass where vipcode=@vs_vipcode and clscode<> @vs_clsid order by clsidcount desc
|
|
|
|
|
|
update #tvipconby4 set secondclass= rtrim(@vs_clsid)+'-'+rtrim(@vs_clsname) where vipcode=@vs_vipcode
|
|
|
|
|
|
fetch chcurtmp into @vs_vipcode
|
|
|
end
|
|
|
deallocate chcurtmp
|
|
|
|
|
|
set @vs_qrysql='select vipcode,vipname,tel,mobile1,mobile2,
|
|
|
vipsex=(case vipsex when ''0'' then ''男'' when ''1'' then ''女'' when ''2'' then ''未知'' else vipsex end),
|
|
|
contotal,trantimes,avgvipprice,viptype1,viptype2,viptype3,viptype4,firstclass,secondclass from #tvipconby4 where 1=1'
|
|
|
if @viptype <>''
|
|
|
set @vs_qrysql=@vs_qrysql+' and (1<>1 '+@viptype + ')'
|
|
|
if @vs_qry<>''
|
|
|
set @vs_qrysql=@vs_qrysql+' and '+@vs_qry
|
|
|
if @vs_orderby<>'' and @vs_orderby is not null
|
|
|
begin
|
|
|
set @vs_qrysql=@vs_qrysql+' order by '+@vs_orderby
|
|
|
end
|
|
|
else
|
|
|
begin
|
|
|
set @vs_qrysql=@vs_qrysql+' order by viptype4,viptype3,viptype2,viptype1'
|
|
|
end
|
|
|
exec(@vs_qrysql)
|
|
|
end
|
|
|
go
|
|
|
|
|
|
if exists (select * from dbo.sysobjects where id = object_id(N'p_vip_rfm_qry') and objectproperty(id, N'isprocedure') = 1)
|
|
|
drop procedure p_vip_rfm_qry
|
|
|
go
|
|
|
create procedure p_vip_rfm_qry
|
|
|
@vs_vipdbname varchar(20),
|
|
|
@vs_cardtypecode varchar(4),
|
|
|
@vs_topnum varchar(10),
|
|
|
@vs_vipcode varchar(20),
|
|
|
@vs_qry varchar(200),
|
|
|
@vs_orderby varchar(100)
|
|
|
as
|
|
|
declare
|
|
|
@vs_sql varchar(8000),
|
|
|
@vs_where varchar(2000),
|
|
|
@vs_where1 varchar(2000),
|
|
|
@vs_nowdate varchar(10),
|
|
|
@vs_yearago varchar(10),
|
|
|
@vs_accbgndate varchar(10),
|
|
|
@vs_accenddate varchar(10),
|
|
|
@stmpdate varchar(10),
|
|
|
@vs_accyearandmonth varchar(6)
|
|
|
begin
|
|
|
set @vs_nowdate = convert(varchar(10),getdate(),120)
|
|
|
set @vs_yearago = convert(varchar(10),getdate()-365,120)
|
|
|
set @vs_sql = ''
|
|
|
set @vs_where = ' a.sdate>= ''' + @vs_yearago + ''' and a.sdate<=''' + @vs_nowdate + ''''
|
|
|
set @vs_where1=' 1=1 '
|
|
|
|
|
|
if @vs_vipcode<>'' and @vs_vipcode<>'%' and @vs_vipcode is not null
|
|
|
set @vs_where = @vs_where + ' and a.custcode=''' + @vs_vipcode+''''
|
|
|
|
|
|
create table #trptcon
|
|
|
(vipcode varchar(20) null,
|
|
|
vipname varchar(50) null,
|
|
|
tel varchar(20) null,
|
|
|
mobile1 varchar(20) null,
|
|
|
mobile2 varchar(20) null,
|
|
|
cardtypecode varchar(20) null,
|
|
|
cardtypename varchar(20) null,
|
|
|
trantimes numeric(19,0) not null default (0),
|
|
|
contotal numeric(19,2) not null default (0),
|
|
|
signdate datetime null,
|
|
|
lstcondate datetime null)
|
|
|
|
|
|
set @stmpdate=@vs_yearago
|
|
|
while left(@stmpdate,7)<=left(@vs_nowdate,7)
|
|
|
begin
|
|
|
if exists(select name from sysobjects where name='t_flow_total_'+left(@stmpdate,4)+substring(@stmpdate,6,2) and xtype='u')
|
|
|
begin
|
|
|
set @vs_sql='insert into #trptcon(vipcode,contotal,trantimes,lstcondate)
|
|
|
select custcode,isnull(sum(total),0),isnull(count(orgcode),0),max(sdate)
|
|
|
from t_flow_total_' + substring(@stmpdate,1,4)+substring(@stmpdate,6,2)+ ' a
|
|
|
where ' + @vs_where +' and (custcode<>'''' and custcode is not null)'
|
|
|
|
|
|
if @vs_cardtypecode<>'' and @vs_cardtypecode<>'%' and @vs_cardtypecode is not null
|
|
|
set @vs_sql=@vs_sql+ ' and custcode in (select b.vipcode from '+@vs_vipdbname+'..t_vip b where b.viptype='''+@vs_cardtypecode+''')'
|
|
|
|
|
|
set @vs_sql=@vs_sql+ ' group by custcode'
|
|
|
exec(@vs_sql)
|
|
|
end
|
|
|
|
|
|
set @stmpdate=convert(varchar(10),dateadd(month,1,@stmpdate),120)
|
|
|
end
|
|
|
|
|
|
create table #trptcon2
|
|
|
(vipcode varchar(20) null,
|
|
|
vipname varchar(50) null,
|
|
|
tel varchar(20) null,
|
|
|
mobile1 varchar(20) null,
|
|
|
mobile2 varchar(20) null,
|
|
|
cardtypecode varchar(20) null,
|
|
|
cardtypename varchar(20) null,
|
|
|
trantimes numeric(19, 0) not null default(0),
|
|
|
contotal numeric(19, 2) not null default(0),
|
|
|
signdate datetime null,
|
|
|
lstcondate datetime null)
|
|
|
|
|
|
insert into #trptcon2(vipcode, contotal, trantimes, lstcondate)
|
|
|
select vipcode, sum(contotal), sum(trantimes), max(lstcondate)
|
|
|
from #trptcon group by vipcode
|
|
|
|
|
|
set @vs_sql='update a set a.cardtypecode=b.viptype,a.vipname=b.vipname,a.signdate=b.signdate,
|
|
|
a.tel=b.tel,a.mobile1=b.mobile1,a.mobile2=b.mobile2
|
|
|
from #trptcon2 a,'+@vs_vipdbname+'..t_vip b with(nolock)
|
|
|
where a.vipcode=b.vipcode '
|
|
|
exec(@vs_sql)
|
|
|
|
|
|
set @vs_sql='update a set a.cardtypename=b.lxname
|
|
|
from #trptcon2 a,'+@vs_vipdbname+'..t_viptype b with(nolock)
|
|
|
where a.cardtypecode=b.lxcode '
|
|
|
exec(@vs_sql)
|
|
|
|
|
|
if @vs_topnum<>'' and @vs_topnum is not null
|
|
|
begin
|
|
|
set @vs_sql= 'select top ' + @vs_topnum
|
|
|
end
|
|
|
else
|
|
|
begin
|
|
|
set @vs_sql= 'select '
|
|
|
end
|
|
|
|
|
|
set @vs_sql=@vs_sql+' cc.vipcode,cc.vipname,cc.cardtypename,cc.tel,cc.mobile1,cc.mobile2,
|
|
|
round(case when sum(cc.trantimes)=0 then 0 else sum(cc.contotal)/sum(cc.trantimes) end,2) as conavg,
|
|
|
sum(cc.trantimes) as trantimes,sum(cc.contotal) as contotal,
|
|
|
cast(round(case when sum(cc.trantimes)=0 then 0
|
|
|
when datediff(day,max(cc.signdate),getdate())+1<365 then (datediff(day,max(cc.signdate),getdate())+1)/sum(cc.trantimes)
|
|
|
else 365/sum(cc.trantimes) end,0) as numeric(10,0)) as concyc,cc.lstcondate,
|
|
|
(case when cc.lstcondate is null then 365 else datediff(day,cc.lstcondate,getdate()) end) as stopdays,
|
|
|
cast(round(case when sum(cc.trantimes)=0 then 0
|
|
|
when datediff(day,max(cc.signdate),getdate())+1<365 then (datediff(day,max(cc.signdate),getdate())+1)/sum(cc.trantimes)
|
|
|
else 365/sum(cc.trantimes) end,0) as numeric(10,0))-(case when cc.lstcondate is null then 365 else datediff(day,cc.lstcondate,getdate()) end) as danger
|
|
|
from #trptcon2 cc
|
|
|
d where ' +@vs_where1
|
|
|
if @vs_qry<>''
|
|
|
set @vs_sql=@vs_sql+' and '+@vs_qry
|
|
|
set @vs_sql=@vs_sql+' group by cc.vipcode,cc.vipname,cc.cardtypename,cc.lstcondate,cc.tel,cc.mobile1,cc.mobile2'
|
|
|
|
|
|
if @vs_orderby<>'' and @vs_orderby is not null
|
|
|
begin
|
|
|
set @vs_sql=@vs_sql+' order by '+@vs_orderby
|
|
|
end
|
|
|
else
|
|
|
begin
|
|
|
set @vs_sql=@vs_sql+' order by stopdays desc,trantimes desc,contotal desc'
|
|
|
end
|
|
|
exec(@vs_sql)
|
|
|
end
|
|
|
go
|
|
|
|
|
|
if exists(select * from sysobjects where name = 'p_get_aplu_kystock' and xtype = 'p')
|
|
|
drop procedure p_get_aplu_kystock
|
|
|
go
|
|
|
create procedure p_get_aplu_kystock @psorgcode varchar(10),@psplucode varchar(20),@psplace varchar(1),@pskycount numeric(19,4) output,@pserrmsg varchar(1000) output,@pscolorcode varchar(10),@pssizecode varchar(10)
|
|
|
as
|
|
|
declare @splucode varchar(20)
|
|
|
declare @sorgcode varchar(10)
|
|
|
declare @scolorcode varchar(10)
|
|
|
declare @ssizecode varchar(10)
|
|
|
declare @smngstock varchar(1)
|
|
|
begin
|
|
|
set @splucode = @psplucode
|
|
|
set @sorgcode = @psorgcode
|
|
|
set @scolorcode = @pscolorcode
|
|
|
set @ssizecode = @pssizecode
|
|
|
|
|
|
select @smngstock = isnull(mngstock,'') from t_plu_org where plucode = @splucode and orgcode = @psorgcode
|
|
|
if @smngstock = '0'
|
|
|
begin
|
|
|
set @pskycount = 9999999999
|
|
|
set @pserrmsg = ''
|
|
|
return(1)
|
|
|
end
|
|
|
if @psplace = ''
|
|
|
begin
|
|
|
if (@scolorcode <>'') and (@ssizecode<>'')
|
|
|
begin
|
|
|
select @pskycount = isnull((oc.ccount+oc.gcount),0) - isnull(i.pluqty,0) -- -isnull(p.pfcount,0)
|
|
|
from t_plu_org o,t_plu_org_cs oc left join t_plu g on g.plucode =oc.plucode
|
|
|
left join (select orgcode,plucode,colorcode,sizecode,sum(pluqty) as pluqty from t_flow_item group by plucode,orgcode,colorcode,sizecode) i on oc.plucode = i.plucode and i.orgcode = oc.orgcode and i.colorcode=oc.colorcode and i.sizecode=oc.sizecode
|
|
|
where o.orgcode = @sorgcode and o.isright = '1' and plutype<>'3' and o.mngstock= '1' and o.plucode = @splucode and oc.plucode=o.plucode and oc.orgcode=o.orgcode and oc.colorcode = @scolorcode and oc.sizecode = @ssizecode
|
|
|
end
|
|
|
else
|
|
|
begin
|
|
|
select @pskycount = (o.ccount+o.gcount) - isnull(l.packpluqty,0) - isnull(i.pluqty,0) -- -isnull(p.pfcount,0)
|
|
|
from t_plu_org o left join t_plu g on g.plucode =o.plucode
|
|
|
left join (select i.orgcode,p.plucode,sum(i.pluqty*p.counts) packpluqty from t_plupack p,t_flow_item i where p.packcode = i.plucode group by p.plucode,i.orgcode ) l on o.plucode = l.plucode and l.orgcode = o.orgcode
|
|
|
left join (select i.orgcode,p.innercode,sum(i.pluqty*p.itemcnt) as mppluqty from t_flow_item i ,(select plucode ,innercode ,itemcnt from t_plu where plutype = '4' or iszfcode = '2') p where p.plucode = i.plucode group by p.innercode,i.orgcode ) mp
|
|
|
on o.plucode = mp.innercode and mp.orgcode = o.orgcode
|
|
|
left join (select orgcode,plucode,sum(pluqty) as pluqty from t_flow_item group by plucode,orgcode) i on o.plucode = i.plucode and i.orgcode = o.orgcode
|
|
|
where o.orgcode = @sorgcode and o.isright = '1' and plutype<>'3' and o.mngstock= '1' and o.plucode = @splucode
|
|
|
end
|
|
|
end
|
|
|
else if @psplace = '0'
|
|
|
begin
|
|
|
if (@scolorcode <>'') and (@ssizecode<>'')
|
|
|
begin
|
|
|
select @pskycount = isnull(oc.gcount,0) - isnull(i.pluqty,0) -- -isnull(p.pfcount,0)
|
|
|
from t_plu_org o,t_plu_org_cs oc left join t_plu g on g.plucode =oc.plucode
|
|
|
left join (select orgcode,plucode,colorcode,sizecode,sum(pluqty) as pluqty from t_flow_item group by plucode,orgcode,colorcode,sizecode) i on oc.plucode = i.plucode and i.orgcode = oc.orgcode and i.colorcode=oc.colorcode and i.sizecode=oc.sizecode
|
|
|
where o.orgcode = @sorgcode and o.isright = '1' and plutype<>'3' and o.mngstock= '1' and o.plucode = @splucode and oc.plucode=o.plucode and oc.orgcode=o.orgcode and oc.colorcode = @scolorcode and oc.sizecode = @ssizecode
|
|
|
end
|
|
|
else
|
|
|
begin
|
|
|
select @pskycount = o.gcount - isnull(l.packpluqty,0) - isnull(mp.mppluqty,0) - isnull(i.pluqty,0) -- -isnull(p.pfcount,0)
|
|
|
from t_plu_org o left join t_plu g on g.plucode =o.plucode
|
|
|
left join (select i.orgcode,p.plucode,sum(i.pluqty*p.counts) packpluqty from t_plupack p,t_flow_item i where p.packcode = i.plucode group by p.plucode,i.orgcode ) l on o.plucode = l.plucode and l.orgcode = o.orgcode
|
|
|
left join (select i.orgcode,p.innercode,sum(i.pluqty*p.itemcnt) as mppluqty from t_flow_item i ,(select plucode ,innercode ,itemcnt from t_plu where plutype = '4' or iszfcode = '2') p where p.plucode = i.plucode group by p.innercode,i.orgcode ) mp
|
|
|
on o.plucode = mp.innercode and mp.orgcode = o.orgcode
|
|
|
left join (select orgcode,plucode,sum(pluqty) as pluqty from t_flow_item group by plucode,orgcode) i on o.plucode = i.plucode and i.orgcode = o.orgcode
|
|
|
where o.orgcode = @sorgcode and o.isright = '1' and plutype<>'3' and o.mngstock= '1' and o.plucode = @splucode
|
|
|
end
|
|
|
end
|
|
|
else if @psplace = '1'
|
|
|
begin
|
|
|
if (@scolorcode <>'') and (@ssizecode<>'')
|
|
|
begin
|
|
|
select @pskycount = isnull(oc.ccount,0) - isnull(i.pluqty,0) -- -isnull(p.pfcount,0)
|
|
|
from t_plu_org o,t_plu_org_cs oc left join t_plu g on g.plucode =oc.plucode
|
|
|
left join (select orgcode,plucode,colorcode,sizecode,sum(pluqty) as pluqty from t_flow_item group by plucode,orgcode,colorcode,sizecode) i on oc.plucode = i.plucode and i.orgcode = oc.orgcode and i.colorcode=oc.colorcode and i.sizecode=oc.sizecode
|
|
|
where o.orgcode = @sorgcode and o.isright = '1' and plutype<>'3' and o.mngstock= '1' and o.plucode = @splucode and oc.plucode=o.plucode and oc.orgcode=o.orgcode and oc.colorcode = @scolorcode and oc.sizecode = @ssizecode
|
|
|
end
|
|
|
else
|
|
|
begin
|
|
|
select @pskycount = o.ccount-isnull(i.pluqty,0)-isnull(l.packpluqty,0) - isnull(mp.mppluqty,0)
|
|
|
from t_plu_org o left join t_plu g on g.plucode =o.plucode
|
|
|
left join (select orgcode,plucode,sum(pluqty) as pluqty from t_flow_item group by plucode,orgcode) i on o.plucode = i.plucode and i.orgcode = o.orgcode
|
|
|
left join (select i.orgcode,p.plucode,sum(i.pluqty*p.counts) packpluqty from t_plupack p,t_flow_item i where p.packcode = i.plucode group by p.plucode,i.orgcode ) l on o.plucode = l.plucode and l.orgcode = o.orgcode
|
|
|
left join (select i.orgcode,p.innercode,sum(i.pluqty*p.itemcnt) as mppluqty from t_flow_item i ,(select plucode ,innercode ,itemcnt from t_plu where plutype = '4' or iszfcode = '2') p where p.plucode = i.plucode group by p.innercode,i.orgcode ) mp
|
|
|
on o.plucode = mp.innercode and mp.orgcode = o.orgcode
|
|
|
where o.orgcode = @sorgcode and o.isright = '1' and plutype<>'3' and o.mngstock= '1' and o.plucode = @splucode
|
|
|
end
|
|
|
end
|
|
|
if @@error <> 0
|
|
|
begin
|
|
|
set @pserrmsg = '查询商品可用库存失败'
|
|
|
return(-1)
|
|
|
end
|
|
|
|
|
|
return(1)
|
|
|
end
|
|
|
go
|
|
|
|
|
|
if exists(select * from sysobjects where name ='p_check_plu_stock_rz' and xtype='p')
|
|
|
drop procedure p_check_plu_stock_rz
|
|
|
go
|
|
|
create procedure p_check_plu_stock_rz
|
|
|
(
|
|
|
@psorgcode varchar(10),
|
|
|
@psbillno varchar(20),
|
|
|
@psplace varchar(1),
|
|
|
@psbillform varchar(100),
|
|
|
@psbilldetail varchar(100),
|
|
|
@psstaffcode varchar(10),
|
|
|
@psmsg varchar(2000) out
|
|
|
)
|
|
|
as
|
|
|
begin
|
|
|
declare @tmptblname varchar(100)
|
|
|
declare @ssql varchar(8000)
|
|
|
declare @nssql nvarchar(4000)
|
|
|
declare @spackcode varchar(20)
|
|
|
declare @splucode varchar(20)
|
|
|
declare @fcounts numeric(19,4)
|
|
|
declare @splutype varchar(1)
|
|
|
declare @fkycount numeric(19,4)
|
|
|
declare @finfcount numeric(19,4)
|
|
|
declare @fbillcounts numeric(19,4)
|
|
|
declare @serrmsg varchar(200)
|
|
|
set @tmptblname = @psbillform+@psbillno
|
|
|
set @psmsg = ''
|
|
|
|
|
|
if not exists(select * from sysobjects where name = @tmptblname and xtype = 'u')
|
|
|
begin
|
|
|
set @ssql = 'create table '+@tmptblname+
|
|
|
' (packcode varchar(20),plucode varchar(20),billcounts numeric(19,4),itemcnt numeric(19,4),counts numeric(19,4),plutype varchar(1))'
|
|
|
exec(@ssql)
|
|
|
if @@error <> 0
|
|
|
begin
|
|
|
set @psmsg = '创建临时表失败'
|
|
|
return(-1)
|
|
|
end
|
|
|
end
|
|
|
set @ssql = 'delete from '+@tmptblname
|
|
|
exec(@ssql)
|
|
|
if @@error <> 0
|
|
|
begin
|
|
|
set @psmsg = '删除临时表数据失败'
|
|
|
return(-1)
|
|
|
end
|
|
|
if @psbillform = 't_whsale_head'
|
|
|
set @ssql =
|
|
|
'insert into '+@tmptblname+
|
|
|
' select isnull(p.packcode,d.plucode) as packcode,isnull(p.plucode,d.plucode) as plucode,'+
|
|
|
' (d.counts+d.zpcount) as billcounts,isnull(p.counts,1) as itemcnt,'+
|
|
|
' (d.counts + d.zpcount) * isnull(p.counts,1) as counts,'+
|
|
|
' case when isnull(v1.jymode,'''') = ''2'' then ''2'' when (isnull(v1.jymode,'''') = '''') and (isnull(v.jymode,'''') = ''2'') then ''2'' else g.plutype end as plutype'+
|
|
|
' from t_whsale_body d left join t_plupack p on d.plucode = p.packcode'+
|
|
|
' left join t_plu g on d.plucode = g.plucode '+
|
|
|
' left join t_plu_org o on d.plucode = o.plucode and o.orgcode = '''+@psorgcode+''' '+
|
|
|
' left join t_supplier v on g.supcode =v.supcode '+
|
|
|
' left join t_supplier v1 on o.supcode =v1.supcode '+
|
|
|
' ,t_whsale_head h '+
|
|
|
' where h.billno = '''+@psbillno+''' and h.billno=d.billno and h.orgcode = '''+@psorgcode+''' and ((o.mngstock = ''1'') or (g.plutype=''3''))'
|
|
|
else if @psbillform = 't_return_head'
|
|
|
set @ssql =
|
|
|
'insert into '+@tmptblname+
|
|
|
' select isnull(p.packcode,d.plucode) as packcode,isnull(p.plucode,d.plucode) as plucode,'+
|
|
|
' d.counts as billcounts,isnull(p.counts,1) as itemcnt,'+
|
|
|
' d.counts * isnull(p.counts,1) as counts,'+
|
|
|
' case when isnull(v1.jymode,'''') = ''2'' then ''2'' when (isnull(v1.jymode,'''') = '''') and (isnull(v.jymode,'''') = ''2'') then ''2'' else g.plutype end as plutype '+
|
|
|
' from '+@psbilldetail+' d left join t_plupack p on d.plucode = p.packcode'+
|
|
|
' left join t_plu g on d.plucode = g.plucode '+
|
|
|
' left join t_plu_org o on d.plucode = o.plucode and o.orgcode = '''+@psorgcode+''' '+
|
|
|
' left join t_supplier v on g.supcode =v.supcode '+
|
|
|
' left join t_supplier v1 on o.supcode =v1.supcode '+
|
|
|
' ,'+@psbillform+' h '+
|
|
|
' where h.billno = '''+@psbillno+''' and h.billno=d.billno and h.orgcode = '''+@psorgcode+''' and ((o.mngstock = ''1'') or (g.plutype=''3''))'
|
|
|
else if @psbillform = 't_outtrans_head'
|
|
|
set @ssql =
|
|
|
'insert into '+@tmptblname+
|
|
|
' select isnull(p.packcode,d.plucode) as packcode,isnull(p.plucode,d.plucode) as plucode,'+
|
|
|
' d.counts as billcounts,isnull(p.counts,1) as itemcnt,'+
|
|
|
' d.counts * isnull(p.counts,1) as counts,'+
|
|
|
' case when isnull(v1.jymode,'''') = ''2'' then ''2'' when (isnull(v1.jymode,'''') = '''') and (isnull(v.jymode,'''') = ''2'') then ''2'' else g.plutype end as plutype '+
|
|
|
' from '+@psbilldetail+' d left join t_plupack p on d.plucode = p.packcode'+
|
|
|
' left join t_plu g on d.plucode = g.plucode '+
|
|
|
' left join t_plu_org o on d.plucode = o.plucode and o.orgcode = '''+@psorgcode+''' '+
|
|
|
' left join t_supplier v on g.supcode =v.supcode '+
|
|
|
' left join t_supplier v1 on o.supcode =v1.supcode '+
|
|
|
' ,'+@psbillform+' h '+
|
|
|
' where h.billno = '''+@psbillno+''' and h.billno=d.billno and h.outorgcode = '''+@psorgcode+''' and ((o.mngstock = ''1'') or (g.plutype=''3''))'
|
|
|
else if @psbillform = 't_cut_head'
|
|
|
set @ssql =
|
|
|
'insert into '+@tmptblname+
|
|
|
' select isnull(p.packcode,d.plucode) as packcode,isnull(p.plucode,d.plucode) as plucode,'+
|
|
|
' d.counts as billcounts,isnull(p.counts,1) as itemcnt,'+
|
|
|
' d.counts * isnull(p.counts,1) as counts,'+
|
|
|
' case when isnull(v1.jymode,'''') = ''2'' then ''2'' when (isnull(v1.jymode,'''') = '''') and (isnull(v.jymode,'''') = ''2'') then ''2'' else g.plutype end as plutype '+
|
|
|
' from '+@psbilldetail+' d left join t_plupack p on d.plucode = p.packcode'+
|
|
|
' left join t_plu g on d.plucode = g.plucode '+
|
|
|
' left join t_plu_org o on d.plucode = o.plucode and o.orgcode = '''+@psorgcode+''' '+
|
|
|
' left join t_supplier v on g.supcode =v.supcode '+
|
|
|
' left join t_supplier v1 on o.supcode =v1.supcode '+
|
|
|
' ,'+@psbillform+' h '+
|
|
|
' where h.billno = '''+@psbillno+''' and h.billno=d.billno and h.orgcode = '''+@psorgcode+''' and ((o.mngstock = ''1'') or (g.plutype=''3''))'
|
|
|
else if @psbillform = 't_draw_head'
|
|
|
set @ssql =
|
|
|
'insert into '+@tmptblname+
|
|
|
' select isnull(p.packcode,d.plucode) as packcode,isnull(p.plucode,d.plucode) as plucode,'+
|
|
|
' d.counts as billcounts,isnull(p.counts,1) as itemcnt,'+
|
|
|
' d.counts * isnull(p.counts,1) as counts,'+
|
|
|
' case when isnull(v1.jymode,'''') = ''2'' then ''2'' when (isnull(v1.jymode,'''') = '''') and (isnull(v.jymode,'''') = ''2'') then ''2'' else g.plutype end as plutype '+
|
|
|
' from '+@psbilldetail+' d left join t_plupack p on d.plucode = p.packcode'+
|
|
|
' left join t_plu g on d.plucode = g.plucode '+
|
|
|
' left join t_plu_org o on d.plucode = o.plucode and o.orgcode = '''+@psorgcode+''' '+
|
|
|
' left join t_supplier v on g.supcode =v.supcode '+
|
|
|
' left join t_supplier v1 on o.supcode =v1.supcode '+
|
|
|
' ,'+@psbillform+' h '+
|
|
|
' where h.billno = '''+@psbillno+''' and h.billno=d.billno and h.orgcode = '''+@psorgcode+''' and ((o.mngstock = ''1'') or (g.plutype=''3''))'
|
|
|
else if @psbillform = 't_dist_head'
|
|
|
set @ssql =
|
|
|
'insert into '+@tmptblname+
|
|
|
' select isnull(p.packcode,d.plucode) as packcode,isnull(p.plucode,d.plucode) as plucode,'+
|
|
|
' d.counts as billcounts,isnull(p.counts,1) as itemcnt,'+
|
|
|
' d.counts * isnull(p.counts,1) as counts,'+
|
|
|
' case when isnull(v1.jymode,'''') = ''2'' then ''2'' when (isnull(v1.jymode,'''') = '''') and (isnull(v.jymode,'''') = ''2'') then ''2'' else g.plutype end as plutype '+
|
|
|
' from '+@psbilldetail+' d left join t_plupack p on d.plucode = p.packcode'+
|
|
|
' left join t_plu g on d.plucode = g.plucode '+
|
|
|
' left join t_plu_org o on d.plucode = o.plucode and o.orgcode = '''+@psorgcode+''' '+
|
|
|
' left join t_supplier v on g.supcode =v.supcode '+
|
|
|
' left join t_supplier v1 on o.supcode =v1.supcode '+
|
|
|
' ,'+@psbillform+' h '+
|
|
|
' where h.billno = '''+@psbillno+''' and h.billno=d.billno and h.orgcode = '''+@psorgcode+''' and ((o.mngstock = ''1'') or (g.plutype=''3''))'
|
|
|
else if @psbillform = 't_produce_head'
|
|
|
set @ssql =
|
|
|
'insert into '+@tmptblname+
|
|
|
' select isnull(p.packcode,d.plucode) as packcode,isnull(p.plucode,d.plucode) as plucode,'+
|
|
|
' d.counts as billcounts,isnull(p.counts,1) as itemcnt,'+
|
|
|
' d.counts * isnull(p.counts,1) as counts,'+
|
|
|
' case when isnull(v1.jymode,'''') = ''2'' then ''2'' when (isnull(v1.jymode,'''') = '''') and (isnull(v.jymode,'''') = ''2'') then ''2'' else g.plutype end as plutype '+
|
|
|
' from '+@psbilldetail+' d left join t_plupack p on d.plucode = p.packcode'+
|
|
|
' left join t_plu g on d.plucode = g.plucode '+
|
|
|
' left join t_plu_org o on d.plucode = o.plucode and o.orgcode = '''+@psorgcode+''' '+
|
|
|
' left join t_supplier v on g.supcode =v.supcode '+
|
|
|
' left join t_supplier v1 on o.supcode =v1.supcode '+
|
|
|
' ,'+@psbillform+' h '+
|
|
|
' where h.billno = '''+@psbillno+''' and h.billno=d.billno and h.orgcode = '''+@psorgcode+''' and ((o.mngstock = ''1'') or (g.plutype=''3''))'
|
|
|
else if @psbillform = 't_scrap_head'
|
|
|
set @ssql =
|
|
|
'insert into '+@tmptblname+
|
|
|
' select isnull(p.packcode,d.plucode) as packcode,isnull(p.plucode,d.plucode) as plucode,'+
|
|
|
' d.counts as billcounts,isnull(p.counts,1) as itemcnt,'+
|
|
|
' d.counts * isnull(p.counts,1) as counts,'+
|
|
|
' case when isnull(v1.jymode,'''') = ''2'' then ''2'' when (isnull(v1.jymode,'''') = '''') and (isnull(v.jymode,'''') = ''2'') then ''2'' else g.plutype end as plutype '+
|
|
|
' from '+@psbilldetail+' d left join t_plupack p on d.plucode = p.packcode'+
|
|
|
' left join t_plu g on d.plucode = g.plucode '+
|
|
|
' left join t_plu_org o on d.plucode = o.plucode and o.orgcode = '''+@psorgcode+''' '+
|
|
|
' left join t_supplier v on g.supcode =v.supcode '+
|
|
|
' left join t_supplier v1 on o.supcode =v1.supcode '+
|
|
|
' ,'+@psbillform+' h '+
|
|
|
' where h.billno = '''+@psbillno+''' and h.billno=d.billno and h.orgcode = '''+@psorgcode+''' and ((o.mngstock = ''1'') or (g.plutype=''3''))'
|
|
|
exec(@ssql)
|
|
|
if @@error <> 0
|
|
|
begin
|
|
|
set @psmsg = '向临时表插入数据失败'
|
|
|
return(-1)
|
|
|
end
|
|
|
set @ssql = 'declare cur cursor for select packcode,plucode,counts,plutype from '+@tmptblname
|
|
|
exec(@ssql)
|
|
|
open cur
|
|
|
fetch next from cur into @spackcode,@splucode,@fcounts,@splutype
|
|
|
while @@fetch_status = 0
|
|
|
begin
|
|
|
set @nssql = N'select @tmpfbillcounts = sum(counts) from '+@tmptblname+' where plucode = '''+@splucode+''' group by plucode'
|
|
|
exec sp_executesql @nssql,
|
|
|
N'@tmpfbillcounts numeric(19,4) output',
|
|
|
@fbillcounts output
|
|
|
exec p_get_aplu_kystock @psorgcode,@splucode,@psplace,@fkycount output,@serrmsg output,'',''
|
|
|
|
|
|
set @finfcount = @fkycount
|
|
|
set @fkycount = @fkycount - @fbillcounts
|
|
|
if @@error <> 0
|
|
|
begin
|
|
|
set @psmsg = '查询商品可用数量失败'
|
|
|
return(-1)
|
|
|
end
|
|
|
if @fkycount < 0
|
|
|
begin
|
|
|
if exists(select * from t_sys_right_func r,t_sys_user_sub u where r.ugrpcode=u.ugrpcode and u.usercode=@psstaffcode and r.funcode='op07')
|
|
|
begin
|
|
|
if @splutype = '3'
|
|
|
begin
|
|
|
if @psmsg = ''
|
|
|
set @psmsg = '商品包【'+@spackcode+'】中:'+@splucode + ' 实际可用数量:' + convert(varchar(100),@finfcount)
|
|
|
else
|
|
|
set @psmsg = @psmsg + char(13) + char(10) + '商品包【'+@spackcode+'】中:'+@splucode + ' 实际可用数量:' + convert(varchar(100),@finfcount)
|
|
|
end
|
|
|
else
|
|
|
begin
|
|
|
if @psmsg = ''
|
|
|
set @psmsg = '商品:'+@splucode + ' 实际可用数量:' + convert(varchar(100),@finfcount)
|
|
|
else
|
|
|
set @psmsg = @psmsg + char(13) + char(10) + '商品:'+@splucode + ' 实际可用数量:' + convert(varchar(100),@finfcount)
|
|
|
end
|
|
|
end
|
|
|
else
|
|
|
begin
|
|
|
if @splutype = '3'
|
|
|
begin
|
|
|
if @psmsg = ''
|
|
|
set @psmsg = '商品包【'+@spackcode+'】中:'+@splucode
|
|
|
else
|
|
|
set @psmsg = @psmsg + char(13) + char(10) + '商品包【'+@spackcode+'】中:'+@splucode
|
|
|
end
|
|
|
else
|
|
|
begin
|
|
|
if @psmsg = ''
|
|
|
set @psmsg = '商品:'+@splucode
|
|
|
else
|
|
|
set @psmsg = @psmsg + char(13) + char(10) + '商品:'+@splucode
|
|
|
end
|
|
|
end
|
|
|
end
|
|
|
fetch next from cur into @spackcode,@splucode,@fcounts,@splutype
|
|
|
end
|
|
|
close cur
|
|
|
deallocate cur
|
|
|
set @ssql = 'drop table '+@tmptblname
|
|
|
exec(@ssql)
|
|
|
return(1)
|
|
|
end
|
|
|
go
|
|
|
|
|
|
if exists(select * from sysobjects where name ='p_search_plu_info' and xtype='p')
|
|
|
drop procedure p_search_plu_info
|
|
|
go
|
|
|
create procedure p_search_plu_info
|
|
|
(
|
|
|
@psorgcode varchar(10),
|
|
|
@psplucode varchar(20),
|
|
|
@pspluname varchar(40),
|
|
|
@psbarcode varchar(20),
|
|
|
@psspec varchar(40),
|
|
|
@psunit varchar(10),
|
|
|
@psmultbar varchar(1),
|
|
|
@psusercode varchar(6)
|
|
|
)
|
|
|
as
|
|
|
begin
|
|
|
declare @sdepcode varchar(10)
|
|
|
|
|
|
select g.plucode,g.mncode,g.depcode,d.depname,g.remark,o.orgcode,
|
|
|
case when @pspluname<>'' then @pspluname else g.pluname end as pluname,
|
|
|
case when @pspluname<>'' then @psbarcode else g.barcode end as barcode,
|
|
|
case when @pspluname<>'' then @psspec else g.spec end as spec,
|
|
|
case when @pspluname<>'' then @psunit else convert(varchar,'') end as unitname,
|
|
|
isnull(pb.bincode,'') as bincode,isnull(wb.binbarcode,'') as binbarcode,
|
|
|
g.askcnt,o.lowstock,o.topstock,g.prodarea,o.cost,o.netcost,o.total,g.psprice as gpsprice,o.psprice,
|
|
|
o.mngstock,g.mngcs,
|
|
|
d.uppercode1,d.uppercode2,d.uppercode3,d.uppercode4,
|
|
|
g.cargono,g.unit,
|
|
|
case when isnull(o.supcode ,'')='' then g.supcode
|
|
|
when s.orgtype='2' and v1.suptype='9' then g.supcode
|
|
|
else o.supcode end as supcode,
|
|
|
case when isnull(o.supcode ,'')='' then v.supname
|
|
|
when s.orgtype='2' and v1.suptype='9' then v.supname
|
|
|
else v1.supname end as supname,
|
|
|
g.jtaxrate,g.staxrate,o.ojprice,o.price,
|
|
|
case when isnull(v1.jymode,'') = '2' then '2' when (isnull(v1.jymode,'') = '' and isnull(v.jymode,'') = '2') then '2' else g.plutype end as plutype,
|
|
|
g.keepdays,rtrim(ltrim(g.plustatus)) as plustatus,
|
|
|
g.price as gprice,g.jprice as gjprice,g.netjprice as gnetjprice,
|
|
|
g.vipprice as gvipprice,o.vipprice as vipprice,g.pfprice as gpfprice,o.pfprice as pfprice,
|
|
|
g.clscode,c.clsname,g.brandcode as brandcode,b.brandname,
|
|
|
o.iscg,o.isxs,o.isth,o.iscgth,o.ispsth,o.isask as isyh,o.cgmode,o.jprice,o.netjprice,g.packprice,
|
|
|
o.ccount,o.gcount,o.dms,o.dms1,o.dms2,o.dms3,o.jhcycle,isweight,o.isright,@psmultbar as multbar,g.erpmaterialno,o.hjprice,o.ljprice,g.dkrate,
|
|
|
g.grossweight,g.netweight,g.minaskcount,g.ordercnt
|
|
|
from t_plu g left join t_plu_org o on g.plucode = o.plucode and o.orgcode = @psorgcode
|
|
|
left join t_shop s on s.orgcode = o.orgcode
|
|
|
left join t_dept d on g.depcode = d.depcode
|
|
|
left join t_gclass c on g.clscode=c.clscode
|
|
|
left join t_supplier v on g.supcode =v.supcode
|
|
|
left join t_supplier v1 on o.supcode =v1.supcode
|
|
|
left join t_brand b on g.brandcode =b.brandcode
|
|
|
left join t_plu_bin pb on g.PluCode = pb.plucode and pb.orgcode = @psorgcode
|
|
|
left join t_ware_bin wb on pb.bincode = wb.bincode and pb.orgcode = wb.orgcode
|
|
|
where g.plustatus<>'2' and (g.plucode=@psplucode and g.plucode<>'')
|
|
|
order by g.plucode
|
|
|
|
|
|
select @sdepcode=depcode from t_plu where plucode=@psplucode
|
|
|
|
|
|
select d.depcode from t_dept d
|
|
|
where d.depcode = @sdepcode and exists(select depcode from t_sys_right_dept r
|
|
|
where r.usercode = @psusercode and (d.depcode=r.depcode or d.uppercode1=r.depcode or d.uppercode2=r.depcode
|
|
|
or d.uppercode3=r.depcode or d.uppercode4=r.depcode ))
|
|
|
|
|
|
select unit as punit,itemcnt from t_plu
|
|
|
where innercode = @psplucode and plutype = '4'
|
|
|
order by itemcnt desc
|
|
|
end
|
|
|
go
|
|
|
|
|
|
if exists(select * from sysobjects where name ='p_search_plu_info_with_whl_sale' and xtype='p')
|
|
|
drop procedure p_search_plu_info_with_whl_sale
|
|
|
go
|
|
|
create procedure p_search_plu_info_with_whl_sale
|
|
|
(
|
|
|
@psorgcode varchar(10),
|
|
|
@psplucode varchar(20),
|
|
|
@pspfsalebillno varchar(20),
|
|
|
@psneedsale varchar(1),
|
|
|
@psselectbarmultplu varchar(1),
|
|
|
@pspluname varchar(40),
|
|
|
@psbarcode varchar(20),
|
|
|
@psspec varchar(40),
|
|
|
@psunit varchar(10),
|
|
|
@psmultbar varchar(1),
|
|
|
@psusercode varchar(6)
|
|
|
)
|
|
|
as
|
|
|
begin
|
|
|
declare @sdepcode varchar(10)
|
|
|
|
|
|
if @psneedsale='1'
|
|
|
begin
|
|
|
if @psselectbarmultplu='1'
|
|
|
select t_whsale_body.plucode,t_whsale_body.barcode,t_whsale_body.pluname,t_whsale_body.pfprice,t_plu.mncode ,t_plu.depcode,t_whsale_body.depname,t_plu.clscode,t_gclass.clsname,
|
|
|
t_dept.uppercode1,t_dept.uppercode2,t_dept.uppercode3,t_dept.uppercode4,t_plu.cargono,t_whsale_body.spec,t_plu.depcode,t_plu.prodarea,t_plu.unit,
|
|
|
t_plu_org.price,t_plu_org.jprice,t_plu_org.netjprice,
|
|
|
case when isnull(v1.jymode,'') = '2' then '2' when (isnull(v1.jymode,'') = '' and isnull(t_supplier.jymode,'') = '2') then '2' else t_plu.plutype end as plutype,
|
|
|
rtrim(ltrim(t_plu.plustatus)) as plustatus,t_plu_org.ccount,t_plu_org.gcount,t_plu.supcode ,t_supplier.supname,
|
|
|
t_plu_org.cost,t_plu_org.netcost,t_plu_org.total,t_plu_org.mngstock,t_plu.mngcs,convert(varchar,'') as unitname,
|
|
|
t_whsale_body.counts,t_whsale_body.zpcount,t_whsale_body.pftotal,t_whsale_body.zrtotal,t_whsale_body.punit,t_whsale_body.pcount,
|
|
|
t_plu.jtaxrate,t_whsale_body.itemcnt,sglcount,t_whsale_body.remark,t_plu_org.isright,@psmultbar as multbar
|
|
|
from t_whsale_body ,
|
|
|
t_plu left join t_plu_org on t_plu.plucode = t_plu_org.plucode and t_plu_org.orgcode = @psorgcode
|
|
|
left join t_dept on t_plu.depcode = t_dept.depcode
|
|
|
left join t_supplier on t_plu.supcode =t_supplier.supcode
|
|
|
left join t_supplier v1 on t_plu_org.supcode =v1.supcode
|
|
|
left join t_gclass on t_plu.clscode=t_gclass.clscode
|
|
|
where t_whsale_body.plucode=t_plu.plucode
|
|
|
and (t_plu.plustatus<>'2') and t_whsale_body.billno=@pspfsalebillno
|
|
|
and ((t_plu.plucode=@psplucode and t_plu.plucode<>''))
|
|
|
order by t_plu.plucode
|
|
|
else
|
|
|
select t_whsale_body.plucode,t_whsale_body.barcode,t_whsale_body.pluname,t_whsale_body.pfprice,t_plu.mncode ,t_plu.depcode,t_whsale_body.depname,t_plu.clscode,t_gclass.clsname,
|
|
|
t_dept.uppercode1,t_dept.uppercode2,t_dept.uppercode3,t_dept.uppercode4,t_plu.cargono,t_whsale_body.spec,t_plu.depcode,t_plu.prodarea,t_plu.unit,
|
|
|
t_plu_org.price,t_plu_org.jprice,t_plu_org.netjprice,
|
|
|
case when isnull(v1.jymode,'') = '2' then '2' when (isnull(v1.jymode,'') = '' and isnull(t_supplier.jymode,'') = '2') then '2' else t_plu.plutype end as plutype,
|
|
|
rtrim(ltrim(t_plu.plustatus)) as plustatus,t_plu_org.ccount,t_plu_org.gcount,t_plu.supcode ,t_supplier.supname,
|
|
|
t_plu_org.cost,t_plu_org.netcost,t_plu_org.total,t_plu_org.mngstock,t_plu.mngcs,convert(varchar,'') as unitname,
|
|
|
t_whsale_body.counts,t_whsale_body.zpcount,t_whsale_body.pftotal,t_whsale_body.zrtotal,t_whsale_body.punit,t_whsale_body.pcount,
|
|
|
t_plu.jtaxrate,t_whsale_body.itemcnt,sglcount,t_whsale_body.remark,t_plu_org.isright,@psmultbar as multbar
|
|
|
from t_whsale_body ,
|
|
|
t_plu left join t_plu_org on t_plu.plucode = t_plu_org.plucode and t_plu_org.orgcode = @psorgcode
|
|
|
left join t_dept on t_plu.depcode = t_dept.depcode
|
|
|
left join t_supplier on t_plu.supcode =t_supplier.supcode
|
|
|
left join t_supplier v1 on t_plu_org.supcode =v1.supcode
|
|
|
left join t_gclass on t_plu.clscode=t_gclass.clscode
|
|
|
where t_whsale_body.plucode=t_plu.plucode
|
|
|
and (t_plu.plustatus<>'2') and t_whsale_body.billno=@pspfsalebillno
|
|
|
and ((t_plu.plucode=@psplucode and t_plu.plucode<>''))
|
|
|
order by t_plu.plucode
|
|
|
end
|
|
|
else
|
|
|
begin
|
|
|
if @psselectbarmultplu='1'
|
|
|
select t_plu.plucode,t_plu.mncode ,
|
|
|
case when @pspluname<>'' then @pspluname else t_plu.pluname end as pluname,
|
|
|
case when @pspluname<>'' then @psbarcode else t_plu.barcode end as barcode,
|
|
|
case when @pspluname<>'' then @psspec else t_plu.spec end as spec,
|
|
|
case when @pspluname<>'' then @psunit else convert(varchar,'') end as unitname,
|
|
|
t_plu_org.pfprice,t_plu.depcode,t_dept.depname,t_plu.clscode,t_gclass.clsname,
|
|
|
t_dept.uppercode1,t_dept.uppercode2,t_dept.uppercode3,t_dept.uppercode4,t_plu.cargono,t_plu.depcode,t_plu.prodarea,t_plu.unit,
|
|
|
t_plu_org.price,t_plu_org.jprice,t_plu_org.netjprice,
|
|
|
case when isnull(v1.jymode,'') = '2' then '2' when (isnull(v1.jymode,'') = '' and isnull(t_supplier.jymode,'') = '2') then '2' else t_plu.plutype end as plutype,
|
|
|
rtrim(ltrim(t_plu.plustatus)) as plustatus,t_plu.supcode ,t_supplier.supname,t_plu_org.gcount,t_plu_org.ccount,
|
|
|
0.00 as counts,0.00 as zpcount,0.00 as pftotal,0.00 as zrtotal,' ' as punit,0.00 as pcount,
|
|
|
t_plu.jtaxrate,0 as itemcnt,0.00 as sglcount,' ' as remark,t_plu_org.mngstock,t_plu.mngcs,t_plu_org.isright,@psmultbar as multbar,t_plu.erpmaterialno
|
|
|
from t_plu left join t_plu_org on t_plu.plucode = t_plu_org.plucode and t_plu_org.orgcode = @psorgcode
|
|
|
left join t_dept on t_plu.depcode = t_dept.depcode
|
|
|
left join t_supplier on t_plu.supcode =t_supplier.supcode
|
|
|
left join t_supplier v1 on t_plu_org.supcode =v1.supcode
|
|
|
left join t_gclass on t_plu.clscode=t_gclass.clscode
|
|
|
where (t_plu.plustatus<>'2') and ((t_plu.plucode=@psplucode and t_plu.plucode<>''))
|
|
|
order by t_plu.plucode
|
|
|
else
|
|
|
select t_plu.plucode,t_plu.mncode ,
|
|
|
case when @pspluname<>'' then @pspluname else t_plu.pluname end as pluname,
|
|
|
case when @pspluname<>'' then @psbarcode else t_plu.barcode end as barcode,
|
|
|
case when @pspluname<>'' then @psspec else t_plu.spec end as spec,
|
|
|
case when @pspluname<>'' then @psunit else convert(varchar,'') end as unitname,
|
|
|
t_plu_org.pfprice,t_plu.depcode,t_dept.depname,t_plu.clscode,t_gclass.clsname,
|
|
|
t_dept.uppercode1,t_dept.uppercode2,t_dept.uppercode3,t_dept.uppercode4,t_plu.cargono,t_plu.depcode,t_plu.prodarea,t_plu.unit,
|
|
|
t_plu_org.price,t_plu_org.jprice,t_plu_org.netjprice,
|
|
|
case when isnull(v1.jymode,'') = '2' then '2' when (isnull(v1.jymode,'') = '' and isnull(t_supplier.jymode,'') = '2') then '2' else t_plu.plutype end as plutype,
|
|
|
rtrim(ltrim(t_plu.plustatus)) as plustatus,t_plu.supcode ,t_supplier.supname,t_plu_org.gcount,t_plu_org.ccount,
|
|
|
0.00 as counts,0.00 as zpcount,0.00 as pftotal,0.00 as zrtotal,' ' as punit,0.00 as pcount,
|
|
|
t_plu.jtaxrate,0 as itemcnt,0.00 as sglcount,' ' as remark,t_plu_org.mngstock,t_plu.mngcs,t_plu_org.isright,@psmultbar as multbar,t_plu.erpmaterialno
|
|
|
from t_plu left join t_plu_org on t_plu.plucode = t_plu_org.plucode and t_plu_org.orgcode = @psorgcode
|
|
|
left join t_dept on t_plu.depcode = t_dept.depcode
|
|
|
left join t_supplier on t_plu.supcode =t_supplier.supcode
|
|
|
left join t_supplier v1 on t_plu_org.supcode =v1.supcode
|
|
|
left join t_gclass on t_plu.clscode=t_gclass.clscode
|
|
|
where (t_plu.plustatus<>'2') and ((t_plu.plucode=@psplucode and t_plu.plucode<>''))
|
|
|
order by t_plu.plucode
|
|
|
end
|
|
|
|
|
|
select @sdepcode=depcode from t_plu where plucode=@psplucode
|
|
|
|
|
|
select d.depcode from t_dept d
|
|
|
where d.depcode = @sdepcode and exists(select depcode from t_sys_right_dept r
|
|
|
where r.usercode = @psusercode and (d.depcode=r.depcode or d.uppercode1=r.depcode or d.uppercode2=r.depcode
|
|
|
or d.uppercode3=r.depcode or d.uppercode4=r.depcode ))
|
|
|
|
|
|
select unit as punit,itemcnt from t_plu
|
|
|
where plucode = @psplucode and plutype = '4'
|
|
|
end
|
|
|
go
|
|
|
|
|
|
if exists(select * from sysobjects where name ='p_search_plu_info_with_other' and xtype='p')
|
|
|
drop procedure p_search_plu_info_with_other
|
|
|
go
|
|
|
create procedure p_search_plu_info_with_other
|
|
|
(
|
|
|
@psorgcode varchar(10),
|
|
|
@psplucode varchar(20),
|
|
|
@psusercode varchar(6)
|
|
|
)
|
|
|
as
|
|
|
begin
|
|
|
declare @sdepcode varchar(10)
|
|
|
|
|
|
select g.plucode,g.depcode,g.pluname,o.price,o.isright,rtrim(ltrim(g.plustatus)) as plustatus
|
|
|
from t_plu g left join t_plu_org o on g.plucode = o.plucode and o.orgcode = @psorgcode
|
|
|
where g.plustatus<>'2' and (g.plucode=@psplucode and g.plucode<>'')
|
|
|
order by g.plucode
|
|
|
|
|
|
select @sdepcode=depcode from t_plu where plucode=@psplucode
|
|
|
|
|
|
select d.depcode from t_dept d
|
|
|
where d.depcode = @sdepcode and exists(select depcode from t_sys_right_dept r
|
|
|
where r.usercode = @psusercode and (d.depcode=r.depcode or d.uppercode1=r.depcode or d.uppercode2=r.depcode
|
|
|
or d.uppercode3=r.depcode or d.uppercode4=r.depcode ))
|
|
|
|
|
|
select unit as punit,itemcnt from t_plu
|
|
|
where plucode = @psplucode and plutype = '4'
|
|
|
end
|
|
|
go
|
|
|
|
|
|
if exists(select * from sysobjects where name = 'p_before_dsc_account' and xtype = 'p')
|
|
|
drop procedure p_before_dsc_account
|
|
|
go
|
|
|
create procedure p_before_dsc_account
|
|
|
(
|
|
|
@sdsccode varchar(20),
|
|
|
@srtnmsg varchar(8000) output
|
|
|
)
|
|
|
as
|
|
|
begin
|
|
|
declare @splucode varchar(20)
|
|
|
declare @syhtype varchar(1)
|
|
|
set @srtnmsg = ''
|
|
|
|
|
|
if not exists(select * from sysobjects where name = 'dscpludetail_foraccount' and xtype = 'u')
|
|
|
begin
|
|
|
create table dscpludetail_foraccount
|
|
|
(accdsccode varchar(20),
|
|
|
billno varchar(20),
|
|
|
grptype varchar(1),
|
|
|
grptypename varchar(10),
|
|
|
grpcode varchar(20),
|
|
|
plucode varchar(20),
|
|
|
isrepeat varchar(1) default('1'))
|
|
|
end
|
|
|
|
|
|
if not exists(select * from sysobjects where name = 'dscpludetail_foraccount_other' and xtype = 'u')
|
|
|
begin
|
|
|
create table dscpludetail_foraccount_other
|
|
|
(accdsccode varchar(20),
|
|
|
billno varchar(20),
|
|
|
grptype varchar(1),
|
|
|
grptypename varchar(10),
|
|
|
grpcode varchar(20),
|
|
|
plucode varchar(20))
|
|
|
end
|
|
|
|
|
|
select @syhtype = yhtype from t_prom_head where billno = @sdsccode
|
|
|
|
|
|
delete from dscpludetail_foraccount where accdsccode = @sdsccode
|
|
|
|
|
|
insert into dscpludetail_foraccount(accdsccode,billno,grptype,grpcode,plucode,grptypename)
|
|
|
select @sdsccode,billno,grptype,d.grpcode,case when d.grptype = 'g' then g.plucode
|
|
|
when d.grptype = 'x' then g2.plucode
|
|
|
when d.grptype = 'w' then g3.plucode
|
|
|
when d.grptype = 'y' then g1.plucode
|
|
|
when d.grptype = 'p' then d.grpcode
|
|
|
end as plucode,
|
|
|
case when d.grptype = 'g' then '集合'
|
|
|
when d.grptype = 'x' then '部门'
|
|
|
when d.grptype = 'w' then '品牌'
|
|
|
when d.grptype = 'y' then '品类'
|
|
|
when d.grptype = 'p' then '单品'
|
|
|
end as grptypename
|
|
|
from t_prom_body d left join t_prom_gather_detail g on d.grpcode = g.gathercode and d.grptype = 'g'
|
|
|
left join t_plu g1 on d.grpcode = g1.clscode and d.grptype = 'y'
|
|
|
left join t_plu g2 on d.grpcode = g2.depcode and d.grptype = 'x'
|
|
|
left join t_plu g3 on d.grpcode = g3.brandcode and d.grptype = 'w'
|
|
|
where billno = @sdsccode
|
|
|
|
|
|
update dscpludetail_foraccount set isrepeat = '0'
|
|
|
where accdsccode = @sdsccode and plucode in (
|
|
|
select plucode from dscpludetail_foraccount
|
|
|
group by plucode
|
|
|
having count(*) =1)
|
|
|
|
|
|
set @srtnmsg = ''
|
|
|
set @splucode = ''
|
|
|
select @srtnmsg=case when (isnull(@splucode,'') = plucode) and (grptypename <> '单品') then
|
|
|
@srtnmsg + char(13) + '--在本单据中的'+grptypename+'['+grpcode+']中存在'
|
|
|
when (isnull(@splucode,'') = plucode) and (grptypename = '单品') then
|
|
|
@srtnmsg + char(13) + '--在本单据中存在该单品'
|
|
|
when (isnull(@splucode,'') <> plucode) and (@srtnmsg = '') and (grptypename <> '单品') then
|
|
|
'商品['+plucode+']重复'+char(13) + '--在本单据中的'+grptypename+'['+grpcode+']中存在'
|
|
|
when (isnull(@splucode,'') <> plucode) and (@srtnmsg = '') and (grptypename = '单品') then
|
|
|
'商品['+plucode+']重复'+char(13) + '--在本单据中存在该单品'
|
|
|
when (isnull(@splucode,'') <> plucode) and (@srtnmsg <> '') and (grptypename <> '单品') then
|
|
|
@srtnmsg+char(13)+'商品['+plucode+']重复'+char(13) + '--在本单据中的'+grptypename+'['+grpcode+']中存在'
|
|
|
when (isnull(@splucode,'') <> plucode) and (@srtnmsg <> '') and (grptypename = '单品') then
|
|
|
@srtnmsg+char(13)+'商品['+plucode+']重复'+char(13) + '--在本单据中存在该单品'
|
|
|
end,@splucode = plucode
|
|
|
from dscpludetail_foraccount
|
|
|
where accdsccode = @sdsccode and isrepeat = '1' and @syhtype <> '9'
|
|
|
order by plucode
|
|
|
if @srtnmsg <> ''
|
|
|
begin
|
|
|
set @srtnmsg = '如下商品在本单据中出现重复'+char(13)+@srtnmsg
|
|
|
delete from dscpludetail_foraccount where accdsccode = @sdsccode
|
|
|
return(-1)
|
|
|
end
|
|
|
|
|
|
delete from dscpludetail_foraccount_other where accdsccode = @sdsccode
|
|
|
insert into dscpludetail_foraccount_other(accdsccode,billno,grptype,grpcode,plucode,grptypename)
|
|
|
select @sdsccode,billno,grptype,d.grpcode,case when d.grptype = 'g' then g.plucode
|
|
|
when d.grptype = 'x' then g2.plucode
|
|
|
when d.grptype = 'w' then g3.plucode
|
|
|
when d.grptype = 'y' then g1.plucode
|
|
|
when d.grptype = 'p' then d.grpcode
|
|
|
end as plucode,
|
|
|
case when d.grptype = 'g' then '集合'
|
|
|
when d.grptype = 'x' then '部门'
|
|
|
when d.grptype = 'w' then '品牌'
|
|
|
when d.grptype = 'y' then '品类'
|
|
|
when d.grptype = 'p' then '单品'
|
|
|
end as grptypename
|
|
|
from t_prom_body d left join t_prom_gather_detail g on d.grpcode = g.gathercode and d.grptype = 'g'
|
|
|
left join t_plu g1 on d.grpcode = g1.clscode and d.grptype = 'y'
|
|
|
left join t_plu g2 on d.grpcode = g2.depcode and d.grptype = 'x'
|
|
|
left join t_plu g3 on d.grpcode = g3.brandcode and d.grptype = 'w'
|
|
|
where d.billno in
|
|
|
(select distinct h.billno
|
|
|
from t_prom_head h,t_prom_time t,t_prom_org o,
|
|
|
(select orgcode from t_prom_org where billno = @sdsccode) o1,
|
|
|
(select bgndate,enddate,bgntime,endtime,weekdays from t_prom_time where billno = @sdsccode) t1
|
|
|
where h.billno = t.billno and h.billno = o.billno and isnull(h.rzdate,'') <> '' and h.yhtype in ('1','2','6','7','9') and h.billno <> @sdsccode and
|
|
|
(@syhtype = '9' or h.yhtype <> @syhtype) and o.orgcode = o1.orgcode and
|
|
|
((t.bgndate between t1.bgndate and t1.enddate or t.enddate between t1.bgndate and t1.enddate) and (substring(t.weekdays,1,1) = substring(t1.weekdays,1,1) or
|
|
|
substring(t.weekdays,2,1) = substring(t1.weekdays,2,1) or
|
|
|
substring(t.weekdays,3,1) = substring(t1.weekdays,3,1) or
|
|
|
substring(t.weekdays,4,1) = substring(t1.weekdays,4,1) or
|
|
|
substring(t.weekdays,5,1) = substring(t1.weekdays,5,1) or
|
|
|
substring(t.weekdays,6,1) = substring(t1.weekdays,6,1) or
|
|
|
substring(t.weekdays,7,1) = substring(t1.weekdays,7,1)))
|
|
|
)
|
|
|
|
|
|
delete from dscpludetail_foraccount_other
|
|
|
where not exists(select * from dscpludetail_foraccount where accdsccode = dscpludetail_foraccount_other.accdsccode and
|
|
|
billno <> dscpludetail_foraccount_other.billno and plucode = dscpludetail_foraccount_other.plucode)
|
|
|
delete from dscpludetail_foraccount where accdsccode = @sdsccode
|
|
|
|
|
|
set @srtnmsg = ''
|
|
|
set @splucode = ''
|
|
|
select @srtnmsg=case when (isnull(@splucode,'') = plucode) and (grptypename <> '单品') then
|
|
|
@srtnmsg + char(13) + '--在单据['+billno+']中的'+grptypename+'['+grpcode+']中存在'
|
|
|
when (isnull(@splucode,'') = plucode) and (grptypename = '单品') then
|
|
|
@srtnmsg + char(13) + '--在单据['+billno+']中存在该单品'
|
|
|
when (isnull(@splucode,'') <> plucode) and (@srtnmsg = '') and (grptypename <> '单品') then
|
|
|
'商品['+plucode+']重复'+char(13) + '--在单据['+billno+']中的'+grptypename+'['+grpcode+']中存在该单品'
|
|
|
when (isnull(@splucode,'') <> plucode) and (@srtnmsg = '') and (grptypename = '单品') then
|
|
|
'商品['+plucode+']重复'+char(13) + '--在单据['+billno+']中存在该单品'
|
|
|
when (isnull(@splucode,'') <> plucode) and (@srtnmsg <> '') and (grptypename <> '单品') then
|
|
|
@srtnmsg+char(13)+'商品['+plucode+']重复'+char(13) + '--在单据['+billno+']中的'+grptypename+'['+grpcode+']中存在'
|
|
|
when (isnull(@splucode,'') <> plucode) and (@srtnmsg <> '') and (grptypename = '单品') then
|
|
|
@srtnmsg+char(13)+'商品['+plucode+']重复'+char(13) + '--在单据['+billno+']中存在该单品'
|
|
|
end,@splucode = plucode
|
|
|
from dscpludetail_foraccount_other
|
|
|
where accdsccode = @sdsccode
|
|
|
order by plucode
|
|
|
if @srtnmsg <> ''
|
|
|
begin
|
|
|
set @srtnmsg = '如下商品在其他单据中出现重复'+char(13)+@srtnmsg
|
|
|
delete from dscpludetail_foraccount_other where accdsccode = @sdsccode
|
|
|
return(-1)
|
|
|
end
|
|
|
return(1)
|
|
|
end
|
|
|
go
|
|
|
|
|
|
if exists(select * from sysobjects where name = 'f_format_str' and xtype = 'fn')
|
|
|
drop function f_format_str
|
|
|
go
|
|
|
create function f_format_str
|
|
|
(
|
|
|
@sfillstr varchar(100),
|
|
|
@ssourcestr varchar(100),
|
|
|
@ifilllen int
|
|
|
)
|
|
|
returns varchar(100)
|
|
|
as
|
|
|
begin
|
|
|
declare @rtnstr varchar(100)
|
|
|
set @rtnstr =@sfillstr + @ssourcestr
|
|
|
set @rtnstr = substring(@rtnstr,len(@rtnstr)-@ifilllen + 1,@ifilllen)
|
|
|
return @rtnstr
|
|
|
end
|
|
|
go
|
|
|
|
|
|
if exists (select * from sysobjects where name ='f_get_billno' and xtype = 'p')
|
|
|
drop procedure f_get_billno
|
|
|
go
|
|
|
create procedure f_get_billno
|
|
|
(
|
|
|
@sbilltype varchar(20),
|
|
|
@sorgcode varchar(10),
|
|
|
@shandasautoreturn varchar(1),
|
|
|
@snewbillno varchar(20) output
|
|
|
)
|
|
|
as
|
|
|
begin
|
|
|
declare @sreturnvalue varchar(20)
|
|
|
declare @sbillno_prefixpart varchar(20)
|
|
|
declare @sbillno_orgcodepart varchar(20)
|
|
|
declare @sbillno_datepart varchar(20)
|
|
|
declare @sbillno_serialnopart varchar(20)
|
|
|
declare @sbillno_serialnomax varchar(20)
|
|
|
declare @sbilltype_isrule varchar(1)
|
|
|
declare @ibilltype_nolength int
|
|
|
declare @sbilltype_prefix varchar(20)
|
|
|
declare @sbilltype_datefmt varchar(20)
|
|
|
declare @ibilltype_serialno int
|
|
|
declare @scurdate varchar(10)
|
|
|
declare @sbilltype_date varchar(10)
|
|
|
declare @serror_msg varchar(1000);
|
|
|
declare @irealsn_length int;
|
|
|
|
|
|
set @scurdate = convert(varchar(10),getdate(),21)
|
|
|
|
|
|
select @sbilltype_isrule = isrule,
|
|
|
@ibilltype_nolength = case when isrule='1' then nolength else 20 end,
|
|
|
@sbilltype_prefix = case when isrule='1' then prefix else billcode end,
|
|
|
@sbilltype_datefmt = case when isrule='1' then datefmt else 'yyyymmdd' end,
|
|
|
@ibilltype_serialno = serialno,
|
|
|
@sbilltype_date = sdate
|
|
|
from t_bill_type with(updlock)
|
|
|
where billcode = @sbilltype
|
|
|
|
|
|
if @sbilltype_isrule = '0' and @shandasautoreturn = '0'
|
|
|
begin
|
|
|
set @sreturnvalue = ''
|
|
|
end
|
|
|
else
|
|
|
begin
|
|
|
set @sbilltype_datefmt = isnull(@sbilltype_datefmt,'')
|
|
|
set @sbillno_prefixpart = isnull(@sbilltype_prefix,'')
|
|
|
set @sbillno_orgcodepart = @sorgcode
|
|
|
set @sbillno_serialnopart = ''
|
|
|
set @sbillno_datepart = ''
|
|
|
|
|
|
if @sbilltype_datefmt = 'yyyymmdd'
|
|
|
set @sbillno_datepart = substring(@scurdate,1,4)+substring(@scurdate,6,2)+substring(@scurdate,9,2)
|
|
|
else if @sbilltype_datefmt = 'yyyymm'
|
|
|
set @sbillno_datepart = substring(@scurdate,1,4)+substring(@scurdate,6,2)
|
|
|
else if @sbilltype_datefmt = 'yyyy'
|
|
|
set @sbillno_datepart = substring(@scurdate,1,4)
|
|
|
else if @sbilltype_datefmt = 'yymmdd'
|
|
|
set @sbillno_datepart = substring(@scurdate,3,2)+substring(@scurdate,6,2)+substring(@scurdate,9,2)
|
|
|
else if @sbilltype_datefmt = 'yymm'
|
|
|
set @sbillno_datepart = substring(@scurdate,3,2)+substring(@scurdate,6,2)
|
|
|
else if @sbilltype_datefmt = 'yy'
|
|
|
set @sbillno_datepart = substring(@scurdate,3,2)
|
|
|
else if @sbilltype_datefmt = ''
|
|
|
set @sbillno_datepart = ''
|
|
|
|
|
|
if @sbilltype_date = @scurdate
|
|
|
begin
|
|
|
update t_bill_type set serialno = serialno + 1 where billcode = @sbilltype
|
|
|
set @sbillno_serialnopart = convert(varchar(20),@ibilltype_serialno)
|
|
|
end
|
|
|
else
|
|
|
begin
|
|
|
update t_bill_type set serialno = 2 ,sdate = @scurdate where billcode = @sbilltype
|
|
|
set @sbillno_serialnopart = '1'
|
|
|
end
|
|
|
set @irealsn_length = @ibilltype_nolength-len(@sbillno_prefixpart)-len(@sbillno_orgcodepart)-len(@sbilltype_datefmt)
|
|
|
set @sbillno_serialnopart = dbo.f_format_str('00000000000000000000',@sbillno_serialnopart,@irealsn_length)
|
|
|
set @sbillno_serialnomax = substring('99999999999999999999', 1, @irealsn_length);
|
|
|
if @sbillno_serialnopart = @sbillno_serialnomax
|
|
|
begin
|
|
|
set @serror_msg = '本日单据序号达到最大值,请联系系统管理员处理';
|
|
|
raiserror(@serror_msg, 16, 1);
|
|
|
end
|
|
|
set @sreturnvalue = @sbillno_prefixpart+@sbillno_orgcodepart+@sbillno_datepart+@sbillno_serialnopart
|
|
|
end
|
|
|
|
|
|
set @snewbillno = @sreturnvalue
|
|
|
end
|
|
|
go
|
|
|
|
|
|
if exists(select * from sysobjects where name ='f_get_auto_plucode' and xtype='p')
|
|
|
drop procedure f_get_auto_plucode
|
|
|
go
|
|
|
create procedure f_get_auto_plucode
|
|
|
(
|
|
|
@psplutype varchar(1),
|
|
|
@psclscode varchar(10),
|
|
|
@psdepcode varchar(10),
|
|
|
@psisweight varchar(1),
|
|
|
@psnewplucode varchar(20) output
|
|
|
)
|
|
|
as
|
|
|
begin
|
|
|
declare @rnt varchar(20)
|
|
|
declare @curorgcode varchar(10)
|
|
|
declare @pluruletype varchar(1)
|
|
|
declare @pluinputrule varchar(1)
|
|
|
declare @iplumaxserial int
|
|
|
declare @ipluminserial int
|
|
|
declare @srulecode varchar(10)
|
|
|
declare @sprecode varchar(20)
|
|
|
declare @nlevel int
|
|
|
declare @ilevelnum int
|
|
|
declare @imaxserial int
|
|
|
declare @optplulen int
|
|
|
declare @optplulenfixed varchar(1)
|
|
|
declare @optdplulen int
|
|
|
declare @optdplulenfixed varchar(1)
|
|
|
declare @i int
|
|
|
set @rnt = ''
|
|
|
set @srulecode = ''
|
|
|
select @pluruletype = itemvalue from t_syscfg where itemname = 'plurule'
|
|
|
select @pluinputrule = itemvalue from t_syscfg where itemname = 'pluinputrule'
|
|
|
select @optplulen = convert(int,itemvalue) from t_syscfg where itemname = 'plulen'
|
|
|
select @optplulenfixed = itemvalue from t_syscfg where itemname = 'plulenfixed'
|
|
|
select @optdplulen = convert(int,itemvalue) from t_syscfg where itemname = 'dplulen'
|
|
|
select @optdplulenfixed = itemvalue from t_syscfg where itemname = 'dplulenfixed'
|
|
|
select @curorgcode = itemvalue from t_syscfg where itemname = 'branchno'
|
|
|
select @iplumaxserial = convert(int,itemvalue) from t_syscfg where itemname = 'plumaxserial'
|
|
|
select @ipluminserial = convert(int,itemvalue) from t_syscfg where itemname = 'pluminserial'
|
|
|
if @psisweight = '0'
|
|
|
begin
|
|
|
if @pluruletype = '0'
|
|
|
return(-1)
|
|
|
if @pluinputrule = '1'
|
|
|
return(-1)
|
|
|
set @nlevel = 0
|
|
|
if @pluruletype = '1'
|
|
|
begin
|
|
|
select @nlevel = deplevel from t_dept where depcode = @psdepcode
|
|
|
select top 1 @ilevelnum =levelnum from t_dep_level where iscode='1' order by levelnum
|
|
|
select @srulecode = case when @nlevel - @ilevelnum = 4 then uppercode4
|
|
|
when @nlevel - @ilevelnum = 3 then uppercode3
|
|
|
when @nlevel - @ilevelnum = 2 then uppercode2
|
|
|
when @nlevel - @ilevelnum = 1 then uppercode1
|
|
|
else depcode end
|
|
|
from t_dept
|
|
|
where depcode = @psdepcode
|
|
|
set @sprecode = @srulecode
|
|
|
end
|
|
|
else if @pluruletype = '2'
|
|
|
begin
|
|
|
select @nlevel = clslevel from t_gclass where clscode = @psclscode
|
|
|
select top 1 @ilevelnum = levelnum from t_gclass_level where iscode='1' order by levelnum
|
|
|
select @srulecode = case when @nlevel - @ilevelnum = 5 then uppercode5
|
|
|
when @nlevel - @ilevelnum = 4 then uppercode4
|
|
|
when @nlevel - @ilevelnum = 3 then uppercode3
|
|
|
when @nlevel - @ilevelnum = 2 then uppercode2
|
|
|
when @nlevel - @ilevelnum = 1 then uppercode1
|
|
|
else clscode end
|
|
|
from t_gclass
|
|
|
where clscode = @psclscode
|
|
|
set @sprecode = @srulecode
|
|
|
end
|
|
|
else if @pluruletype = '3'
|
|
|
begin
|
|
|
set @srulecode = 'x'
|
|
|
set @sprecode = ''
|
|
|
end
|
|
|
else if @pluruletype = '4'
|
|
|
begin
|
|
|
set @srulecode = replace(@curorgcode,'c','')
|
|
|
set @sprecode = @srulecode
|
|
|
end
|
|
|
set @imaxserial = null
|
|
|
select @imaxserial = maxserial from t_max_serial where ruletype= @pluruletype and rulecode = @srulecode
|
|
|
|
|
|
if @imaxserial is not null
|
|
|
begin
|
|
|
set @imaxserial = @imaxserial + 1
|
|
|
if @imaxserial < @ipluminserial
|
|
|
set @imaxserial = @ipluminserial
|
|
|
end
|
|
|
else
|
|
|
begin
|
|
|
set @imaxserial = @ipluminserial
|
|
|
end
|
|
|
if len(@sprecode) > @optplulen
|
|
|
set @sprecode = substring(@sprecode, 1, @optplulen)
|
|
|
set @rnt = @sprecode + dbo.f_format_str('00000000000000000000',convert(varchar(20),@imaxserial),@optplulen - len(@sprecode))
|
|
|
if @psplutype = '0'
|
|
|
begin
|
|
|
if @optplulen <> 0 and @optplulenfixed = '1'
|
|
|
set @rnt = dbo.f_format_str('00000000000000000000',@rnt,@optplulen)
|
|
|
if @optplulen <> 0 and @optplulenfixed = '0' and len(@rnt) > @optplulen
|
|
|
set @rnt = substring(@rnt, 1, @optplulen)
|
|
|
end
|
|
|
else
|
|
|
begin
|
|
|
if (@optdplulen <> 0) and (@optdplulenfixed = '1')
|
|
|
set @rnt = dbo.f_format_str('00000000000000000000',@rnt,@optdplulen)
|
|
|
if (@optdplulen <> 0) and (@optdplulenfixed = '0') and (len(@rnt) > @optdplulen)
|
|
|
set @rnt = substring(@rnt, 1, @optdplulen)
|
|
|
end
|
|
|
|
|
|
set @i = 0
|
|
|
if exists(select * from t_plu where plucode = @rnt or barcode = @rnt) or
|
|
|
exists(select * from t_plu_org where plucode = @rnt) or
|
|
|
exists(select * from t_barcode_ref where plucode = @rnt or barcode = @rnt)
|
|
|
begin
|
|
|
while exists(select * from t_plu where plucode = @rnt or barcode = @rnt) or
|
|
|
exists(select * from t_plu_org where plucode = @rnt) or
|
|
|
exists(select * from t_barcode_ref where plucode = @rnt or barcode = @rnt)
|
|
|
begin
|
|
|
set @rnt = @sprecode + convert(varchar(20),convert(int,replace(@rnt,@sprecode,'')) + 1)
|
|
|
set @i = @i + 1
|
|
|
end
|
|
|
end
|
|
|
set @imaxserial = @imaxserial + @i
|
|
|
if exists(select * from t_max_serial where ruletype= @pluruletype and rulecode = @srulecode)
|
|
|
update t_max_serial set maxserial= @imaxserial where ruletype= @pluruletype and rulecode = @srulecode
|
|
|
else
|
|
|
insert into t_max_serial(ruletype,rulecode,maxserial) values(@pluruletype,@srulecode,@imaxserial)
|
|
|
end
|
|
|
else
|
|
|
begin
|
|
|
if @optdplulen <= 0
|
|
|
return(-1)
|
|
|
if not exists ( select maxserial from t_max_serial where ruletype='w' and rulecode='000000')
|
|
|
insert into t_max_serial(ruletype,rulecode,maxserial) values('w','000000','1')
|
|
|
set @imaxserial = null
|
|
|
select @imaxserial = maxserial from t_max_serial where ruletype='w' and rulecode='000000'
|
|
|
if @imaxserial is null
|
|
|
set @rnt = dbo.f_format_str('00000000000000000000','0',@optdplulen)
|
|
|
else
|
|
|
begin
|
|
|
set @rnt = dbo.f_format_str('00000000000000000000',convert(varchar(20),@imaxserial),@optdplulen)
|
|
|
if exists(select * from t_plu where plucode = @rnt or barcode = @rnt) or
|
|
|
exists(select * from t_plu_org where plucode = @rnt) or
|
|
|
exists(select * from t_barcode_ref where plucode = @rnt or barcode = @rnt)
|
|
|
begin
|
|
|
while exists(select * from t_plu where plucode = @rnt or barcode = @rnt) or
|
|
|
exists(select * from t_plu_org where plucode = @rnt) or
|
|
|
exists(select * from t_barcode_ref where plucode = @rnt or barcode = @rnt)
|
|
|
begin
|
|
|
set @rnt = convert(varchar(20),convert(int,@rnt) + 1)
|
|
|
end
|
|
|
end
|
|
|
end
|
|
|
set @imaxserial = convert(int,@rnt) + 1
|
|
|
update t_max_serial set maxserial= @imaxserial where ruletype='w' and rulecode='000000'
|
|
|
end
|
|
|
set @psnewplucode = @rnt
|
|
|
return(1)
|
|
|
end
|
|
|
go
|
|
|
|
|
|
if exists (select * from sysobjects where id = object_id('p_adjust_job_create') and objectproperty(id, 'isprocedure') = 1)
|
|
|
drop procedure p_adjust_job_create
|
|
|
go
|
|
|
create procedure p_adjust_job_create
|
|
|
(
|
|
|
@sysdbname varchar(20),
|
|
|
@billno varchar(20)
|
|
|
)
|
|
|
with encryption
|
|
|
as
|
|
|
begin
|
|
|
declare @err varchar(200)
|
|
|
declare @jobname varchar(40)
|
|
|
declare @jobproc varchar(8000)
|
|
|
declare @startdate int
|
|
|
declare @starttime int
|
|
|
declare @enddate int
|
|
|
declare @endtime int
|
|
|
declare @jobscript varchar(100)
|
|
|
declare @dbrealname varchar(20)
|
|
|
|
|
|
select @dbrealname = name from master.dbo.sysdatabases where name=@sysdbname
|
|
|
|
|
|
select
|
|
|
@startdate=convert(int,substring(isnull(sxdate,convert(char(10),getdate(),20)),1,4)
|
|
|
+substring(isnull(sxdate,convert(char(10),getdate(),20)),6,2)
|
|
|
+substring(isnull(sxdate,convert(char(10),getdate(),20)),9,2)),
|
|
|
@starttime=case when isnull(sxtime,'')='' then 0 else convert(int,substring(sxtime,1,2)+substring(sxtime,4,2)+substring(sxtime,7,2)) end,
|
|
|
@enddate=99991231,
|
|
|
@endtime=235959,
|
|
|
@jobname=N'计划调价' + @billno,
|
|
|
@jobscript=N'计划调价单自动生成',
|
|
|
@jobproc=N'p_adjust_auto_rz ''' + @billno + ''''
|
|
|
from t_adjprice_head
|
|
|
where billno=@billno
|
|
|
|
|
|
begin transaction
|
|
|
declare @jobid binary(16)
|
|
|
declare @returncode int
|
|
|
select @returncode = 0
|
|
|
if (select count(*) from msdb.dbo.syscategories where name = '[uncategorized (local)]') < 1
|
|
|
execute msdb.dbo.sp_add_category @name = '[uncategorized (local)]'
|
|
|
|
|
|
-- delete the job with the same name (if it exists)
|
|
|
select @jobid = job_id
|
|
|
from msdb.dbo.sysjobs
|
|
|
where (name = @jobname)
|
|
|
if (@jobid is not null)
|
|
|
begin
|
|
|
-- check if the job is a multi-server job
|
|
|
if (exists (select * from msdb.dbo.sysjobservers
|
|
|
where (job_id = @jobid) and (server_id <> 0)))
|
|
|
begin
|
|
|
-- there is, so abort the script
|
|
|
set @err='unable to import job '+@jobname+' since there is already a multi-server job with this name.'
|
|
|
raiserror (@err, 16, 1)
|
|
|
if (@@trancount > 0)
|
|
|
begin
|
|
|
rollback transaction
|
|
|
return(-1)
|
|
|
end
|
|
|
end
|
|
|
else
|
|
|
-- delete the [local] job
|
|
|
execute msdb.dbo.sp_delete_job @job_name =@jobname
|
|
|
select @jobid = null
|
|
|
end
|
|
|
|
|
|
begin
|
|
|
-- add the job
|
|
|
execute @returncode = msdb.dbo.sp_add_job @job_id = @jobid output , @job_name =@jobname, @owner_login_name = 'sa', @description = @jobscript, @category_name = '[uncategorized (local)]', @enabled = 1, @notify_level_email = 0, @notify_level_page = 0, @notify_level_netsend = 0, @notify_level_eventlog = 2, @delete_level= 3
|
|
|
if (@@error <> 0 or @returncode <> 0)
|
|
|
if (@@trancount > 0)
|
|
|
begin
|
|
|
rollback transaction
|
|
|
return(-1)
|
|
|
end
|
|
|
|
|
|
-- add the job steps
|
|
|
execute @returncode = msdb.dbo.sp_add_jobstep @job_id = @jobid,@step_id = 1, @step_name =@jobname, @command =@jobproc, @database_name = @dbrealname, @server = '', @database_user_name = 'dbo', @subsystem = 'tsql', @cmdexec_success_code = 0, @flags = 2, @retry_attempts = 3 , @retry_interval = 1, @output_file_name = 'c:\sqlagentlog.txt', @on_success_step_id = 0, @on_success_action = 1, @on_fail_step_id = 0, @on_fail_action = 2
|
|
|
if (@@error <> 0 or @returncode <> 0)
|
|
|
if (@@trancount > 0)
|
|
|
begin
|
|
|
rollback transaction
|
|
|
return(-1)
|
|
|
end
|
|
|
|
|
|
execute @returncode = msdb.dbo.sp_update_job @job_id = @jobid, @start_step_id = 1
|
|
|
if (@@error <> 0 or @returncode <> 0)
|
|
|
if (@@trancount > 0)
|
|
|
begin
|
|
|
rollback transaction
|
|
|
return(-1)
|
|
|
end
|
|
|
|
|
|
-- add the job schedules
|
|
|
execute @returncode = msdb.dbo.sp_add_jobschedule @job_id = @jobid, @name = '自动任务调度', @enabled = 1,
|
|
|
@freq_type = 1, @active_start_date = @startdate, @active_start_time = @starttime, @freq_interval = 0,
|
|
|
@freq_subday_type = 1, @freq_subday_interval = 0, @freq_relative_interval = 0, @freq_recurrence_factor = 1,
|
|
|
@active_end_date = @enddate, @active_end_time = @endtime
|
|
|
if (@@error <> 0 or @returncode <> 0)
|
|
|
if (@@trancount > 0)
|
|
|
begin
|
|
|
rollback transaction
|
|
|
return(-1)
|
|
|
end
|
|
|
|
|
|
-- add the target servers
|
|
|
execute @returncode = msdb.dbo.sp_add_jobserver @job_id = @jobid, @server_name = '(local)'
|
|
|
if (@@error <> 0 or @returncode <> 0)
|
|
|
if (@@trancount > 0)
|
|
|
begin
|
|
|
rollback transaction
|
|
|
return(-1)
|
|
|
end
|
|
|
end
|
|
|
commit transaction
|
|
|
|
|
|
return(1)
|
|
|
end
|
|
|
go
|
|
|
|
|
|
if exists (select * from sysobjects where id = object_id('p_db_backup_job_create') and objectproperty(id, 'isprocedure') = 1)
|
|
|
drop procedure p_db_backup_job_create
|
|
|
go
|
|
|
create procedure p_db_backup_job_create
|
|
|
(
|
|
|
@jobname varchar(40),
|
|
|
@sysdbname varchar(20),
|
|
|
@vipdbname varchar(20),
|
|
|
@bkpath varchar(100),
|
|
|
@bktime varchar(10)
|
|
|
)
|
|
|
with encryption
|
|
|
as
|
|
|
begin
|
|
|
declare @err varchar(200)
|
|
|
declare @jobproc varchar(8000)
|
|
|
declare @jobprocvip varchar(8000)
|
|
|
declare @startdate int
|
|
|
declare @starttime int
|
|
|
declare @jobscript varchar(100)
|
|
|
declare @dbrealsysname varchar(20)
|
|
|
declare @dbrealvipname varchar(20)
|
|
|
|
|
|
select @dbrealsysname = name from master.dbo.sysdatabases where name=@sysdbname
|
|
|
select @dbrealvipname = name from master.dbo.sysdatabases where name=@vipdbname
|
|
|
|
|
|
select
|
|
|
@startdate=convert(int,convert(char(10),getdate(),112)),
|
|
|
@starttime=convert(int,@bktime),
|
|
|
@jobscript=N'自动备份单自动生成',
|
|
|
@jobproc=N'backup database ['+@sysdbname+'] to disk = '''+@bkpath+'.dbk'' with init, nounload, noskip, stats=10, noformat',
|
|
|
@jobprocvip=N'backup database ['+@vipdbname+'] to disk = '''+@bkpath+'vip.dbk'' with init, nounload, noskip, stats=10, noformat'
|
|
|
|
|
|
begin transaction
|
|
|
declare @jobid binary(16)
|
|
|
declare @returncode int
|
|
|
select @returncode = 0
|
|
|
if (select count(*) from msdb.dbo.syscategories where name = '[uncategorized (local)]') < 1
|
|
|
execute msdb.dbo.sp_add_category @name = '[uncategorized (local)]'
|
|
|
|
|
|
-- delete the job with the same name (if it exists)
|
|
|
select @jobid = job_id
|
|
|
from msdb.dbo.sysjobs
|
|
|
where (name = @jobname)
|
|
|
if (@jobid is not null)
|
|
|
begin
|
|
|
-- check if the job is a multi-server job
|
|
|
if (exists (select * from msdb.dbo.sysjobservers where (job_id = @jobid) and (server_id <> 0)))
|
|
|
begin
|
|
|
-- there is, so abort the script
|
|
|
set @err='unable to import job '+@jobname+' since there is already a multi-server job with this name.'
|
|
|
raiserror (@err, 16, 1)
|
|
|
if (@@trancount > 0)
|
|
|
begin
|
|
|
rollback transaction
|
|
|
return(-1)
|
|
|
end
|
|
|
end
|
|
|
else
|
|
|
-- delete the [local] job
|
|
|
execute msdb.dbo.sp_delete_job @job_name =@jobname
|
|
|
select @jobid = null
|
|
|
end
|
|
|
|
|
|
begin
|
|
|
-- add the job
|
|
|
execute @returncode = msdb.dbo.sp_add_job @job_name=@jobname,
|
|
|
@enabled=1,
|
|
|
@notify_level_eventlog=2,
|
|
|
@notify_level_email=0,
|
|
|
@notify_level_netsend=0,
|
|
|
@notify_level_page=0,
|
|
|
@delete_level=0,
|
|
|
@description=@jobscript,
|
|
|
@category_name=N'[uncategorized (local)]',
|
|
|
@owner_login_name=N'sa', @job_id = @jobid output
|
|
|
|
|
|
if (@@error <> 0 or @returncode <> 0)
|
|
|
if (@@trancount > 0)
|
|
|
begin
|
|
|
rollback transaction
|
|
|
return(-1)
|
|
|
end
|
|
|
|
|
|
-- add the job steps
|
|
|
execute @returncode = msdb.dbo.sp_add_jobstep @job_id=@jobid, @step_name='备份业务数据库',
|
|
|
@step_id=1,
|
|
|
@cmdexec_success_code=0,
|
|
|
@on_success_action=3,
|
|
|
@on_success_step_id=0,
|
|
|
@on_fail_action=2,
|
|
|
@on_fail_step_id=0,
|
|
|
@retry_attempts=3,
|
|
|
@retry_interval=1,
|
|
|
@os_run_priority=0, @subsystem=N'tsql',
|
|
|
@command=@jobproc,
|
|
|
@database_name=N'master',
|
|
|
@output_file_name='c:\sqlagentlog.txt',
|
|
|
@flags=0
|
|
|
|
|
|
if (@@error <> 0 or @returncode <> 0)
|
|
|
if (@@trancount > 0)
|
|
|
begin
|
|
|
rollback transaction
|
|
|
return(-1)
|
|
|
end
|
|
|
|
|
|
execute @returncode = msdb.dbo.sp_add_jobstep @job_id=@jobid, @step_name='备份会员数据库',
|
|
|
@step_id=2,
|
|
|
@cmdexec_success_code=0,
|
|
|
@on_success_action=1,
|
|
|
@on_success_step_id=0,
|
|
|
@on_fail_action=2,
|
|
|
@on_fail_step_id=0,
|
|
|
@retry_attempts=3,
|
|
|
@retry_interval=1,
|
|
|
@os_run_priority=0, @subsystem=N'tsql',
|
|
|
@command=@jobprocvip,
|
|
|
@database_name=N'master',
|
|
|
@output_file_name='c:\sqlagentlog.txt',
|
|
|
@flags=0
|
|
|
|
|
|
if (@@error <> 0 or @returncode <> 0)
|
|
|
if (@@trancount > 0)
|
|
|
begin
|
|
|
rollback transaction
|
|
|
return(-1)
|
|
|
end
|
|
|
|
|
|
execute @returncode = msdb.dbo.sp_update_job @job_id = @jobid, @start_step_id = 1
|
|
|
if (@@error <> 0 or @returncode <> 0)
|
|
|
if (@@trancount > 0)
|
|
|
begin
|
|
|
rollback transaction
|
|
|
return(-1)
|
|
|
end
|
|
|
|
|
|
-- add the job schedules
|
|
|
execute @returncode = msdb.dbo.sp_add_jobschedule @job_id=@jobid, @name=N'自动任务调度',
|
|
|
@enabled=1,
|
|
|
@freq_type=4,
|
|
|
@freq_interval=1,
|
|
|
@freq_subday_type=1,
|
|
|
@freq_subday_interval=0,
|
|
|
@freq_relative_interval=0,
|
|
|
@freq_recurrence_factor=0,
|
|
|
@active_start_date=@startdate,
|
|
|
@active_end_date=99991231,
|
|
|
@active_start_time=@starttime,
|
|
|
@active_end_time=235959
|
|
|
if (@@error <> 0 or @returncode <> 0)
|
|
|
if (@@trancount > 0)
|
|
|
begin
|
|
|
rollback transaction
|
|
|
return(-1)
|
|
|
end
|
|
|
|
|
|
-- add the target servers
|
|
|
execute @returncode = msdb.dbo.sp_add_jobserver @job_id = @jobid, @server_name = '(local)'
|
|
|
if (@@error <> 0 or @returncode <> 0)
|
|
|
if (@@trancount > 0)
|
|
|
begin
|
|
|
rollback transaction
|
|
|
return(-1)
|
|
|
end
|
|
|
end
|
|
|
commit transaction
|
|
|
|
|
|
return(1)
|
|
|
end
|
|
|
go
|
|
|
|
|
|
if exists (select * from sysobjects where name='p_show_sale_data' and xtype='p')
|
|
|
drop procedure p_show_sale_data
|
|
|
go
|
|
|
create procedure [dbo].p_show_sale_data
|
|
|
(
|
|
|
@psusercode varchar(6),
|
|
|
@psorgcode varchar(2000),
|
|
|
@psdate varchar(10),
|
|
|
@psmsg varchar(2000) out
|
|
|
)
|
|
|
as
|
|
|
declare @ssql varchar(2000)
|
|
|
begin
|
|
|
if exists (select 1 from tempdb..sysobjects where name = '#tmpsaledata' and xtype = 'u')
|
|
|
drop table #tmpsaledata
|
|
|
create table #tmpsaledata
|
|
|
(stime varchar(5),
|
|
|
total numeric(19,4),
|
|
|
cost numeric(19,4),
|
|
|
plugross numeric(19,4),
|
|
|
cusflux numeric(19,4))
|
|
|
set @ssql = '
|
|
|
insert into #tmpsaledata(stime,total,cost,plugross,cusflux)
|
|
|
--1.营业额\客流量
|
|
|
select tbla.stime,total,cost,total-cost,cusflux
|
|
|
from
|
|
|
(
|
|
|
select stime,sum(total) as total,sum(cusflux) as cusflux
|
|
|
from
|
|
|
(
|
|
|
select substring(stime,1,5) as stime,total,case when trantype in(''b'',''d'') then 1 else -1 end as cusflux
|
|
|
from t_flow_total
|
|
|
where sdate = '''+@psdate+''' and trantype in (''b'',''d'',''f'',''h'')
|
|
|
and charindex(orgcode + ''-''+posno,'''+@psorgcode+''') > 0
|
|
|
|
|
|
)a
|
|
|
group by stime
|
|
|
)tbla
|
|
|
join
|
|
|
--2.成本
|
|
|
(
|
|
|
select stime,sum(case when plutype <> ''2'' then jprice*pluqty else round(b.plutotal*(100-isnull(dkrate,0))/100,2) end ) as cost
|
|
|
from
|
|
|
(
|
|
|
select substring(stime,1,5) as stime,s.pluqty,
|
|
|
case when isnull(v1.jymode,'''') = ''2'' then ''2'' when (isnull(v1.jymode,'''') = '''' and isnull(v.jymode,'''') = ''2'') then ''2'' else g.plutype end as plutype,
|
|
|
isnull(dkrate,0) dkrate,s.plutotal,
|
|
|
case when isnull(plutype,'''') =''3'' then dbo.f_get_pack_jprice(''0'',s.plucode,s.orgcode) else isnull(o.jprice,0) end jprice
|
|
|
from t_flow_item s
|
|
|
left join t_plu g on s.plucode = g.plucode
|
|
|
left join t_plu_org o on s.plucode = o.plucode and s.orgcode = o.orgcode
|
|
|
left join t_supplier v on g.supcode =v.supcode
|
|
|
left join t_supplier v1 on o.supcode =v1.supcode
|
|
|
where trantype in (''b'',''d'',''f'',''h'')
|
|
|
and sdate = '''+@psdate+'''
|
|
|
and charindex(s.orgcode + ''-''+posno,'''+@psorgcode+''') > 0
|
|
|
) b
|
|
|
group by stime
|
|
|
) tblb on tbla.stime = tblb.stime
|
|
|
'
|
|
|
exec (@ssql)
|
|
|
select a.stime as 时间,round(sum(b.total),2) as 销售额,round(sum(b.plugross),2) as 毛利,sum(b.cusflux) as 客流量
|
|
|
from #tmpsaledata a join #tmpsaledata b on a.stime >= b.stime
|
|
|
group by a.stime,a.total,a.cost,a.plugross,a.cusflux
|
|
|
order by a.stime
|
|
|
if exists (select 1 from tempdb..sysobjects where name = '##tmpsaledata' and xtype = 'u')
|
|
|
drop table #tmpsaledata
|
|
|
end
|
|
|
go
|
|
|
|
|
|
if exists(select * from sysobjects where name = 'p_get_dscprice_forlbl' and xtype = 'p')
|
|
|
drop procedure p_get_dscprice_forlbl
|
|
|
go
|
|
|
create procedure p_get_dscprice_forlbl
|
|
|
(
|
|
|
@psorgcode varchar(10),
|
|
|
@psplucode varchar(20),
|
|
|
@pstblname varchar(100),
|
|
|
@psdate varchar(10),
|
|
|
@psprntype varchar(1),
|
|
|
@psisshow varchar(1),
|
|
|
@pscsbarcode varchar(40),
|
|
|
@psrtnmsg varchar(1000) output
|
|
|
)
|
|
|
as
|
|
|
declare @ssql varchar(8000)
|
|
|
declare @sver varchar(1)
|
|
|
begin
|
|
|
select @sver = itemvalue from t_syscfg where itemname = 'ver' and section = 'system'
|
|
|
if exists(select * from tempdb..sysobjects where id = object_id(N'tempdb..#tmpdscprice') and xtype = 'u')
|
|
|
drop table #tmpdscprice
|
|
|
create table #tmpdscprice
|
|
|
( indexno numeric (19,0) identity (1, 1) not null,
|
|
|
orgcode varchar(10),
|
|
|
plucode varchar(20),
|
|
|
billno varchar(20),
|
|
|
dscname varchar(40),
|
|
|
bgndate varchar(10),
|
|
|
enddate varchar(10),
|
|
|
bgntime varchar(8),
|
|
|
endtime varchar(8),
|
|
|
rzdate varchar(10),
|
|
|
rztime varchar(8),
|
|
|
dscprice numeric(19,4))
|
|
|
if @@error <> 0
|
|
|
begin
|
|
|
set @psrtnmsg ='创建促销价临时表失败'
|
|
|
return -1
|
|
|
end
|
|
|
set @ssql =
|
|
|
'
|
|
|
insert into #tmpdscprice(orgcode,plucode,billno,dscname,bgndate,enddate,bgntime,endtime,rzdate,rztime,dscprice)
|
|
|
select h.orgcode,g.plucode,p.billno,p.dscname,min(tm.bgndate) as bgndate,
|
|
|
max(tm.enddate) enddate,min(tm.bgntime) bgntime,max(tm.endtime) endtime,p.rzdate,p.rztime,
|
|
|
case when grptype=''p'' then yhprice
|
|
|
when dstype=''0'' then round(h.price*(1-dscrate/100),2) else round(o.jprice*(1+dscrate/100),2)
|
|
|
end as dscprice
|
|
|
from
|
|
|
t_prom_head p
|
|
|
,t_prom_body d '
|
|
|
if @sver = '1'
|
|
|
set @ssql = @ssql + ',t_prom_org s '
|
|
|
set @ssql = @ssql + ',t_prom_time tm,t_plu g,t_plu_org o'
|
|
|
if @psisshow = '1'
|
|
|
set @ssql = @ssql + ',(select distinct h.orgcode,h.plucode,h.barcode,h.csbarcode,h.price from t_label_prn_task h where prntype = '''+@psprntype+''') h'
|
|
|
else
|
|
|
begin
|
|
|
if @psprntype = '0' and @pscsbarcode <> ''
|
|
|
set @ssql = @ssql + ',(select o.orgcode,g.plucode,g.barcode, c.csbarcode as csbarcode,o.price from t_plu g '+
|
|
|
'join t_plu_org o on g.plucode = o.plucode '+
|
|
|
'join t_plu_org_cs c on g.plucode = c.plucode and o.orgcode = c.orgcode ' +
|
|
|
'where g.plucode = '''+@psplucode+''' and o.orgcode = '''+@psorgcode+''' and c.csbarcode = '''+@pscsbarcode+''') h'
|
|
|
else
|
|
|
set @ssql = @ssql + ',(select o.orgcode,g.plucode,g.barcode, ''*'' as csbarcode,o.price from t_plu g '+
|
|
|
'join t_plu_org o on g.plucode = o.plucode '+
|
|
|
'where g.plucode = '''+@psplucode+''' and o.orgcode = '''+@psorgcode+''') h'
|
|
|
end
|
|
|
set @ssql = @ssql + ' where exists (select billno from t_prom_time
|
|
|
where billno=p.billno
|
|
|
and '''+@psdate+''' between bgndate and enddate
|
|
|
and convert(varchar(8),getdate(),108)<=endtime
|
|
|
and substring(weekdays,case when datepart(dw,'''+@psdate+''') =1 then 7 else datepart(dw,'''+@psdate+''')-1 end, 1) = ''1'')
|
|
|
and p.custtype=''0'' and p.yhtype=''0''
|
|
|
and ((grptype = ''a'') or
|
|
|
(grptype=''d'' and grpcode = g.depcode) or
|
|
|
(grptype=''p'' and grpcode = h.plucode and (d.csbarcode = h.csbarcode or d.csbarcode = ''*'')) or
|
|
|
(grptype=''b'' and grpcode = g.brandcode ) or
|
|
|
(grptype=''s'' and grpcode = g.supcode ) or
|
|
|
(grptype=''c'' and grpcode = g.clscode))
|
|
|
and not exists (select billno from t_prom_body where billno=p.billno and grpcode = h.plucode and grptype=''n'')
|
|
|
and ('''+@psorgcode+''' = ''<全部>'' or h.orgcode = '''+@psorgcode+''')
|
|
|
and ('''+@psplucode+''' = '''' or h.plucode = '''+@psplucode+''' or h.barcode = '''+@psplucode+''' or h.csbarcode = '''+@psplucode+''')
|
|
|
and h.plucode = g.plucode
|
|
|
and p.billno = d.billno '
|
|
|
if @sver = '1'
|
|
|
set @ssql = @ssql + ' and p.billno = s.billno and s.orgcode = h.orgcode '
|
|
|
set @ssql = @ssql + 'and p.billno = tm.billno
|
|
|
and g.plucode = o.plucode
|
|
|
and o.orgcode = h.orgcode
|
|
|
and rzdate<>'''' and rzdate is not null
|
|
|
group by h.orgcode,g.plucode,p.billno,p.dscname,grptype,yhprice,dstype,h.plucode,d.dscrate,o.jprice,h.price,p.rzdate,p.rztime
|
|
|
order by h.orgcode,g.plucode,
|
|
|
case when grptype=''p'' then ''1'' else ''0'' end desc,
|
|
|
p.rzdate desc,p.rztime desc,dscprice asc'
|
|
|
exec (@ssql)
|
|
|
if @@error <> 0
|
|
|
begin
|
|
|
set @psrtnmsg ='更新促销价临时表失败'
|
|
|
return -1
|
|
|
end
|
|
|
set @ssql = 'truncate table '+ @pstblname
|
|
|
exec (@ssql)
|
|
|
set @ssql = 'insert into '+@pstblname+'(orgcode,plucode,billno,dscname,bgndate,bgntime,enddate,endtime,dscprice)
|
|
|
select a.orgcode,a.plucode,a.billno,a.dscname,a.bgndate,a.bgntime,a.enddate,a.endtime,a.dscprice from #tmpdscprice a join
|
|
|
(select min(indexno) indexno,orgcode,plucode from #tmpdscprice group by orgcode,plucode) b
|
|
|
on a.indexno = b.indexno'
|
|
|
exec (@ssql)
|
|
|
if @@error <> 0
|
|
|
begin
|
|
|
set @psrtnmsg ='查询促销价临时表失败'
|
|
|
return -1
|
|
|
end
|
|
|
return 1
|
|
|
end
|
|
|
go
|
|
|
|
|
|
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[p_deal_pda_pd_data]') and objectproperty(id, N'isprocedure') = 1)
|
|
|
drop procedure [dbo].[p_deal_pda_pd_data]
|
|
|
go
|
|
|
create procedure p_deal_pda_pd_data
|
|
|
@iserialno int,
|
|
|
@susercode varchar(6),
|
|
|
@susername varchar(10),
|
|
|
@srtnmsg varchar(8000) out
|
|
|
as
|
|
|
begin
|
|
|
declare @scurorgcode varchar(10)
|
|
|
declare @scurver varchar(1)
|
|
|
declare @irows int
|
|
|
declare @idetailserialno int
|
|
|
declare @spdno varchar(20)
|
|
|
declare @sorgcode varchar(10)
|
|
|
declare @sbillno varchar(20)
|
|
|
declare @splace varchar(1)
|
|
|
select @scurorgcode = itemvalue from t_syscfg where section = 'system' and itemname = 'branchno'
|
|
|
select @scurver = itemvalue from t_syscfg where section = 'system' and itemname = 'ver'
|
|
|
set @srtnmsg = ''
|
|
|
|
|
|
delete from t_intf_check_data where serialno = @iserialno and isnull(pdno,'') = ''
|
|
|
set @irows = @@rowcount
|
|
|
if @irows <> 0
|
|
|
begin
|
|
|
if @srtnmsg = ''
|
|
|
set @srtnmsg = '有'+convert(varchar(30),@irows)+'条数据盘点任务号为空,不能导入'
|
|
|
else
|
|
|
set @srtnmsg = @srtnmsg + '|有'+convert(varchar(30),@irows)+'条数据盘点任务号为空,不能导入'
|
|
|
end
|
|
|
|
|
|
if @scurver = '0'
|
|
|
begin
|
|
|
delete from t_intf_check_data where serialno = @iserialno and isnull(orgcode,'') <> @scurorgcode
|
|
|
set @irows = @@rowcount
|
|
|
if @irows <> 0
|
|
|
begin
|
|
|
if @srtnmsg = ''
|
|
|
set @srtnmsg = '有'+convert(varchar(30),@irows)+'条数据机构编码和本机构不同,不能导入'
|
|
|
else
|
|
|
set @srtnmsg = @srtnmsg + '|有'+convert(varchar(30),@irows)+'条数据机构编码和本机构不同,不能导入'
|
|
|
end
|
|
|
end
|
|
|
|
|
|
delete a
|
|
|
from t_intf_check_data a left join t_shop b on a.orgcode = b.orgcode
|
|
|
where a.serialno = @iserialno and b.orgcode is null
|
|
|
set @irows = @@rowcount
|
|
|
if @irows <> 0
|
|
|
begin
|
|
|
if @srtnmsg = ''
|
|
|
set @srtnmsg = '有'+convert(varchar(30),@irows)+'条数据机构编码在数据库中不存在,不能导入'
|
|
|
else
|
|
|
set @srtnmsg = @srtnmsg + '|有'+convert(varchar(30),@irows)+'条数据机构编码在数据库中不存在,不能导入'
|
|
|
end
|
|
|
|
|
|
delete a
|
|
|
from t_intf_check_data a left join t_check_task b on a.pdno = b.pdno and a.orgcode = b.orgcode
|
|
|
where a.serialno = @iserialno and b.pdno is null
|
|
|
set @irows = @@rowcount
|
|
|
if @irows <> 0
|
|
|
begin
|
|
|
if @srtnmsg = ''
|
|
|
set @srtnmsg = '有'+convert(varchar(30),@irows)+'条数据盘点任务号在数据库中不存在,不能导入'
|
|
|
else
|
|
|
set @srtnmsg = @srtnmsg + '|有'+convert(varchar(30),@irows)+'条数据盘点任务号在数据库中不存在,不能导入'
|
|
|
end
|
|
|
|
|
|
delete a
|
|
|
from t_intf_check_data a left join t_check_task b on a.pdno = b.pdno and a.orgcode = b.orgcode
|
|
|
where a.serialno = @iserialno and b.pdstatus = '1'
|
|
|
set @irows = @@rowcount
|
|
|
if @irows <> 0
|
|
|
begin
|
|
|
if @srtnmsg = ''
|
|
|
set @srtnmsg = '有'+convert(varchar(30),@irows)+'条数据盘点任务号已经结束,不能导入'
|
|
|
else
|
|
|
set @srtnmsg = @srtnmsg + '|有'+convert(varchar(30),@irows)+'条数据盘点任务号已经结束,不能导入'
|
|
|
end
|
|
|
|
|
|
if exists(select top 1 * from t_intf_check_data where serialno = @iserialno)
|
|
|
begin
|
|
|
set @spdno = ''
|
|
|
set @sorgcode = ''
|
|
|
declare cur_dealpddata cursor for select distinct pdno,orgcode from t_intf_check_data where serialno = @iserialno
|
|
|
open cur_dealpddata
|
|
|
fetch next from cur_dealpddata into @spdno,@sorgcode
|
|
|
while @@fetch_status = 0
|
|
|
begin
|
|
|
delete a
|
|
|
from t_intf_check_data a left join t_plu b on a.plucode = b.plucode
|
|
|
where a.serialno = @iserialno and a.pdno = @spdno and a.orgcode = @sorgcode and b.plucode is null
|
|
|
set @irows = @@rowcount
|
|
|
if @irows <> 0
|
|
|
begin
|
|
|
if @srtnmsg = ''
|
|
|
set @srtnmsg = '盘点任务['+@spdno+']中有'+convert(varchar(30),@irows)+'条商品编码不存在,不能导入'
|
|
|
else
|
|
|
set @srtnmsg = @srtnmsg + '|盘点任务['+@spdno+']中有'+convert(varchar(30),@irows)+'条商品编码不存在,不能导入'
|
|
|
end
|
|
|
|
|
|
delete a
|
|
|
from t_intf_check_data a left join t_plu_org b on a.plucode = b.plucode and a.orgcode = b.orgcode and b.isright = '1'
|
|
|
where a.serialno = @iserialno and a.pdno = @spdno and a.orgcode = @sorgcode and b.plucode is null
|
|
|
set @irows = @@rowcount
|
|
|
if @irows <> 0
|
|
|
begin
|
|
|
if @srtnmsg = ''
|
|
|
set @srtnmsg = '盘点任务['+@spdno+']中有'+convert(varchar(30),@irows)+'条商品没有经营权限,不能导入'
|
|
|
else
|
|
|
set @srtnmsg = @srtnmsg + '|盘点任务['+@spdno+']中有'+convert(varchar(30),@irows)+'条商品没有经营权限,不能导入'
|
|
|
end
|
|
|
|
|
|
delete a
|
|
|
from t_intf_check_data a, t_plu b
|
|
|
where a.serialno = @iserialno and a.pdno = @spdno and a.orgcode = @sorgcode and a.plucode = b.plucode and b.plustatus = '2'
|
|
|
set @irows = @@rowcount
|
|
|
if @irows <> 0
|
|
|
begin
|
|
|
if @srtnmsg = ''
|
|
|
set @srtnmsg = '盘点任务['+@spdno+']中有'+convert(varchar(30),@irows)+'条商品已经淘汰,不能导入'
|
|
|
else
|
|
|
set @srtnmsg = @srtnmsg + '|盘点任务['+@spdno+']中有'+convert(varchar(30),@irows)+'条商品已经淘汰,不能导入'
|
|
|
end
|
|
|
delete a
|
|
|
from t_intf_check_data a, t_plu b
|
|
|
where a.serialno = @iserialno and a.pdno = @spdno and a.orgcode = @sorgcode and a.plucode = b.plucode and b.plustatus = '9'
|
|
|
set @irows = @@rowcount
|
|
|
if @irows <> 0
|
|
|
begin
|
|
|
if @srtnmsg = ''
|
|
|
set @srtnmsg = '盘点任务['+@spdno+']中有'+convert(varchar(30),@irows)+'条商品未审核,不能导入'
|
|
|
else
|
|
|
set @srtnmsg = @srtnmsg + '|盘点任务['+@spdno+']中有'+convert(varchar(30),@irows)+'条商品未审核,不能导入'
|
|
|
end
|
|
|
|
|
|
delete a
|
|
|
from t_intf_check_data a, t_plu b
|
|
|
where a.serialno = @iserialno and a.pdno = @spdno and a.orgcode = @sorgcode and a.plucode = b.plucode and b.plutype = '3'
|
|
|
set @irows = @@rowcount
|
|
|
if @irows <> 0
|
|
|
begin
|
|
|
if @srtnmsg = ''
|
|
|
set @srtnmsg = '盘点任务['+@spdno+']中有'+convert(varchar(30),@irows)+'条商品是商品包,不能导入'
|
|
|
else
|
|
|
set @srtnmsg = @srtnmsg + '|盘点任务['+@spdno+']中有'+convert(varchar(30),@irows)+'条商品是商品包,不能导入'
|
|
|
end
|
|
|
|
|
|
delete a
|
|
|
from t_intf_check_data a left join (select t2.plucode from t_check_task t1,t_check_snap t2 where t1.pdno = @spdno and t1.orgcode = @sorgcode and t1.pdno = t2.pdno) b on a.plucode = b.plucode
|
|
|
where a.serialno = @iserialno and a.pdno = @spdno and a.orgcode = @sorgcode and b.plucode is null
|
|
|
set @irows = @@rowcount
|
|
|
if @irows <> 0
|
|
|
begin
|
|
|
if @srtnmsg = ''
|
|
|
set @srtnmsg = '有'+convert(varchar(30),@irows)+'条商品在盘点任务['+@spdno+']中不存在,不能导入'
|
|
|
else
|
|
|
set @srtnmsg = @srtnmsg + '|有'+convert(varchar(30),@irows)+'条商品在盘点任务['+@spdno+']中不存在,不能导入'
|
|
|
end
|
|
|
|
|
|
delete t_intf_check_data where counts =0
|
|
|
set @irows = @@rowcount
|
|
|
if @irows <> 0
|
|
|
begin
|
|
|
if @srtnmsg = ''
|
|
|
set @srtnmsg = '有'+convert(varchar(30),@irows)+'条商品盘点数量等于0,不导入'
|
|
|
else
|
|
|
set @srtnmsg = @srtnmsg + '|有'+convert(varchar(30),@irows)+'条商品盘点数量等于0,不导入'
|
|
|
end
|
|
|
|
|
|
if exists(select top 1 * from t_intf_check_data where serialno = @iserialno and pdno = @spdno and orgcode = @sorgcode)
|
|
|
begin
|
|
|
set @sbillno = ''
|
|
|
exec f_get_billno 'pd',@sorgcode,'1',@sbillno output
|
|
|
if @@error <> 0
|
|
|
begin
|
|
|
if @srtnmsg = ''
|
|
|
set @srtnmsg = '导入机构['+@sorgcode+']的盘点任务['+@spdno+']的数据,生成实盘单单据号失败,不能导入'
|
|
|
else
|
|
|
set @srtnmsg = @srtnmsg + '|导入机构['+@sorgcode+']的盘点任务['+@spdno+']的数据,生成实盘单单据号失败,不能导入'
|
|
|
fetch next from cur_dealpddata into @spdno,@sorgcode
|
|
|
continue
|
|
|
end
|
|
|
if @sbillno <> ''
|
|
|
begin
|
|
|
set @idetailserialno = 0
|
|
|
set @splace = ''
|
|
|
select @splace = place from t_check_task where orgcode = @sorgcode and pdno = @spdno
|
|
|
|
|
|
update t_intf_check_data set pluserialno = @idetailserialno,@idetailserialno = @idetailserialno + 1
|
|
|
where serialno = @iserialno and pdno = @spdno and orgcode = @sorgcode
|
|
|
if @@error <> 0
|
|
|
begin
|
|
|
if @srtnmsg = ''
|
|
|
set @srtnmsg = '导入机构['+@sorgcode+']的盘点任务['+@spdno+']的数据,调整单据体序列号失败,不能导入'
|
|
|
else
|
|
|
set @srtnmsg = @srtnmsg + '|导入机构['+@sorgcode+']的盘点任务['+@spdno+']的数据,调整单据体序列号失败,不能导入'
|
|
|
fetch next from cur_dealpddata into @spdno,@sorgcode
|
|
|
continue
|
|
|
end
|
|
|
insert into t_check_body(billno,serialno,plucode,pluname,barcode,cargono,spec,unit,jprice,netjprice,price,ocount,counts,sglcount,cost,netcost,total,depcode,depname)
|
|
|
select @sbillno,pluserialno,g.plucode,g.pluname,a.barcode,g.cargono,g.spec,g.unit,o.jprice,o.netjprice,p.price,p.ocount,a.counts,a.counts,0,0,0,isnull(g.depcode,''),isnull(d.depname,'')
|
|
|
from t_intf_check_data a,t_plu_org o,t_check_snap p,t_plu g left join t_dept d on g.depcode = d.depcode
|
|
|
where a.serialno = @iserialno and a.pdno = @spdno and a.orgcode = @sorgcode and
|
|
|
a.plucode = o.plucode and a.orgcode = o.orgcode and a.plucode = p.plucode and a.pdno = p.pdno and
|
|
|
a.plucode = g.plucode and o.isright = '1' and a.counts <> 0
|
|
|
if @@error <> 0
|
|
|
begin
|
|
|
if @srtnmsg = ''
|
|
|
set @srtnmsg = '导入机构['+@sorgcode+']的盘点任务['+@spdno+']的数据,保存实盘单单体失败,不能导入'
|
|
|
else
|
|
|
set @srtnmsg = @srtnmsg + '|导入机构['+@sorgcode+']的盘点任务['+@spdno+']的数据,保存实盘单单体失败,不能导入'
|
|
|
fetch next from cur_dealpddata into @spdno,@sorgcode
|
|
|
continue
|
|
|
end
|
|
|
if exists(select top 1 * from t_check_body where billno = @sbillno)
|
|
|
begin
|
|
|
insert into t_check_head(billno,lrdate,lrtime,rzdate,accdate,orgcode,billtype,pdno,place,gentype,devcode,counts,cost,netcost,total,zdrcode,zdrname,shrcode,shrname,usercode,username,prntimes,chkstatus,remark)
|
|
|
values(@sbillno,convert(varchar(10),getdate(),126),convert(varchar(8),getdate(),8),'','',@sorgcode,'0',@spdno,@splace,'1','',0,0,0,0,@susercode,@susername,'','',@susercode,@susername,0,'0','盘点机导入生成')
|
|
|
if @@error <> 0
|
|
|
begin
|
|
|
if @srtnmsg = ''
|
|
|
set @srtnmsg = '导入机构['+@sorgcode+']的盘点任务['+@spdno+']的数据,保存实盘单单头失败,不能导入'
|
|
|
else
|
|
|
set @srtnmsg = @srtnmsg + '|导入机构['+@sorgcode+']的盘点任务['+@spdno+']的数据,保存实盘单单头失败,不能导入'
|
|
|
delete from t_check_body where billno = @sbillno
|
|
|
fetch next from cur_dealpddata into @spdno,@sorgcode
|
|
|
continue
|
|
|
end
|
|
|
update t_check_body set cost=round(jprice*counts,2),netcost=round(netjprice*counts,2),total=round(price*counts,2)
|
|
|
where billno = @sbillno
|
|
|
if @@error <> 0
|
|
|
begin
|
|
|
if @srtnmsg = ''
|
|
|
set @srtnmsg = '导入机构['+@sorgcode+']的盘点任务['+@spdno+']的数据,调整实盘单单体失败,不能导入'
|
|
|
else
|
|
|
set @srtnmsg = @srtnmsg + '|导入机构['+@sorgcode+']的盘点任务['+@spdno+']的数据,调整实盘单单体失败,不能导入'
|
|
|
delete from t_check_body where billno = @sbillno
|
|
|
delete from t_check_head where billno = @sbillno
|
|
|
fetch next from cur_dealpddata into @spdno,@sorgcode
|
|
|
continue
|
|
|
end
|
|
|
update b set b.counts = a.counts,b.cost = a.cost,b.netcost = a.netcost,b.total=a.total
|
|
|
from (select billno,sum(counts) as counts,sum(cost) as cost,sum(netcost) as netcost,sum(total) as total
|
|
|
from t_check_body where billno = @sbillno group by billno) a,t_check_head b
|
|
|
where a.billno = b.billno
|
|
|
if @@error <> 0
|
|
|
begin
|
|
|
if @srtnmsg = ''
|
|
|
set @srtnmsg = '导入机构['+@sorgcode+']的盘点任务['+@spdno+']的数据,调整实盘单单头失败,不能导入'
|
|
|
else
|
|
|
set @srtnmsg = @srtnmsg + '|导入机构['+@sorgcode+']的盘点任务['+@spdno+']的数据,调整实盘单单头失败,不能导入'
|
|
|
delete from t_check_body where billno = @sbillno
|
|
|
delete from t_check_head where billno = @sbillno
|
|
|
fetch next from cur_dealpddata into @spdno,@sorgcode
|
|
|
continue
|
|
|
end
|
|
|
end
|
|
|
end
|
|
|
else
|
|
|
begin
|
|
|
if @srtnmsg = ''
|
|
|
set @srtnmsg = '导入机构['+@sorgcode+']的盘点任务['+@spdno+']的数据时,生成实盘单单据号为空,不能导入'
|
|
|
else
|
|
|
set @srtnmsg = @srtnmsg + '|导入机构['+@sorgcode+']的盘点任务['+@spdno+']的数据时,生成实盘单单据号为空,不能导入'
|
|
|
end
|
|
|
fetch next from cur_dealpddata into @spdno,@sorgcode
|
|
|
end
|
|
|
else
|
|
|
fetch next from cur_dealpddata into @spdno,@sorgcode
|
|
|
end
|
|
|
close cur_dealpddata
|
|
|
deallocate cur_dealpddata
|
|
|
delete from t_intf_check_data where serialno = @iserialno
|
|
|
end
|
|
|
return(1)
|
|
|
end
|
|
|
go
|
|
|
|
|
|
if exists (select * from sysobjects where id = object_id('p_create_kcpdsnap_cs_detail') and objectproperty(id, 'isprocedure') = 1)
|
|
|
drop procedure p_create_kcpdsnap_cs_detail
|
|
|
go
|
|
|
create procedure p_create_kcpdsnap_cs_detail
|
|
|
(
|
|
|
@porgcode varchar(10),
|
|
|
@ppdno varchar(20),
|
|
|
@prtnmsg varchar(2000) output
|
|
|
)
|
|
|
as
|
|
|
begin
|
|
|
declare @sorgmngcsstock varchar(1)
|
|
|
declare @splace varchar(1)
|
|
|
set @prtnmsg = ''
|
|
|
select @sorgmngcsstock = mngcsstock from t_shop where orgcode= @porgcode
|
|
|
select @splace = place from t_check_task where orgcode = @porgcode and pdno = @ppdno
|
|
|
if @sorgmngcsstock = '1'
|
|
|
begin
|
|
|
insert into t_check_snap_cs(pdno,plucode,csbarcode,colorcode,sizecode,ocounts,pcounts)
|
|
|
select distinct @ppdno,o.plucode,o.csbarcode,colorcode,sizecode,case @splace when '0' then gcount else ccount end ,0
|
|
|
from t_plu_org_cs o,
|
|
|
(select t.pdno,t.plucode,g.mngcs from t_check_snap t left join t_plu g on t.plucode = g.plucode where t.pdno = @ppdno) k
|
|
|
where orgcode=@porgcode and o.plucode = k.plucode and k.mngcs = '1'
|
|
|
if @@error <> 0
|
|
|
begin
|
|
|
set @prtnmsg = '处理管理颜色尺码的商品失败'
|
|
|
return(-1)
|
|
|
end
|
|
|
insert into t_check_snap_cs(pdno,plucode,csbarcode,colorcode,sizecode,ocounts,pcounts)
|
|
|
select distinct @ppdno,o.plucode,g.csbarcode,g.colorcode,g.sizecode,0,0
|
|
|
from t_plu_org o, t_plu_cs g,
|
|
|
(select t.pdno,t.plucode,g.mngcs from t_check_snap t left join t_plu g on t.plucode = g.plucode where t.pdno = @ppdno) k
|
|
|
where orgcode=@porgcode and o.plucode = g.plucode and o.plucode = k.plucode and k.mngcs = '1' and
|
|
|
not exists(select plucode from t_plu_org_cs where plucode=g.plucode and colorcode=g.colorcode and sizecode=g.sizecode and orgcode = @porgcode)
|
|
|
if @@error <> 0
|
|
|
begin
|
|
|
set @prtnmsg = '处理管理颜色尺码但没有色码库存的商品失败'
|
|
|
return(-1)
|
|
|
end
|
|
|
|
|
|
insert into t_check_snap_cs(pdno,plucode,csbarcode,colorcode,sizecode,ocounts,pcounts)
|
|
|
select distinct @ppdno,o.plucode,g.barcode as csbarcode,'00','00',case @splace when '0' then gcount else ccount end,0
|
|
|
from t_plu_org o, t_plu g, (select t.pdno,t.plucode,g.mngcs from t_check_snap t left join t_plu g on t.plucode = g.plucode where t.pdno = @ppdno) k
|
|
|
where k.pdno = @ppdno and orgcode=@porgcode and o.plucode = g.plucode and o.plucode = k.plucode and k.mngcs = '0'
|
|
|
if @@error <> 0
|
|
|
begin
|
|
|
set @prtnmsg = '处理不管理颜色尺码的商品失败'
|
|
|
return(-1)
|
|
|
end
|
|
|
end
|
|
|
else
|
|
|
begin
|
|
|
insert into t_check_snap_cs(pdno,plucode,csbarcode,colorcode,sizecode,ocounts,pcounts)
|
|
|
select distinct @ppdno,o.plucode,g.barcode as csbarcode,'00','00',case @splace when '0' then gcount else ccount end,0
|
|
|
from t_plu_org o, t_plu g, (select t.pdno,t.plucode,g.mngcs from t_check_snap t left join t_plu g on t.plucode = g.plucode where t.pdno = @ppdno) k
|
|
|
where k.pdno = @ppdno and orgcode=@porgcode and o.plucode = g.plucode and o.plucode = k.plucode
|
|
|
if @@error <> 0
|
|
|
begin
|
|
|
set @prtnmsg = '处理商品的颜色尺码数据失败'
|
|
|
return(-1)
|
|
|
end
|
|
|
end
|
|
|
return(1)
|
|
|
end
|
|
|
go
|
|
|
|
|
|
if exists (select * from dbo.sysobjects where id = object_id(N'p_create_order_quote_by_dsc') and objectproperty(id, N'isprocedure') = 1)
|
|
|
drop procedure p_create_order_quote_by_dsc
|
|
|
go
|
|
|
create procedure p_create_order_quote_by_dsc
|
|
|
(
|
|
|
@sdsccode varchar(20),
|
|
|
@sbgndate varchar(10),
|
|
|
@senddate varchar(10),
|
|
|
@susercode varchar(6),
|
|
|
@susername varchar(10),
|
|
|
@ibillcount int output,
|
|
|
@srtnmsg varchar(1000) output
|
|
|
)
|
|
|
as
|
|
|
begin
|
|
|
declare @svendorcode varchar(15)
|
|
|
declare @sbillno varchar(20)
|
|
|
declare @sorgcode varchar(10)
|
|
|
declare @scheckmode varchar(1)
|
|
|
|
|
|
set @ibillcount = 0
|
|
|
set @scheckmode = '0'
|
|
|
select @scheckmode = chkmode from t_bill_type where billcode = 'oq'
|
|
|
set @srtnmsg = ''
|
|
|
select @sorgcode = itemvalue from t_syscfg where itemname='branchno'
|
|
|
|
|
|
if isnull(@sbgndate,'') = ''
|
|
|
begin
|
|
|
set @srtnmsg = '开始日期没有设置'
|
|
|
return(-1)
|
|
|
end
|
|
|
|
|
|
if isnull(@senddate,'') = ''
|
|
|
begin
|
|
|
set @srtnmsg = '截止日期没有设置'
|
|
|
return(-1)
|
|
|
end
|
|
|
|
|
|
declare cur_createquote cursor for
|
|
|
select distinct case when isnull(c.supcode,'') = '' then b.supcode else c.supcode end as supcode
|
|
|
from t_prom_body a,t_plu b,t_plu_org c, t_prom_org d
|
|
|
where a.billno = @sdsccode and d.billno = @sdsccode and a.grptype = 'p' and a.grpcode = b.plucode and a.grpcode = c.plucode and c.orgcode = d.orgcode
|
|
|
|
|
|
open cur_createquote
|
|
|
fetch next from cur_createquote into @svendorcode
|
|
|
|
|
|
while @@fetch_status = 0
|
|
|
begin
|
|
|
if isnull(@svendorcode,'')=''
|
|
|
begin
|
|
|
fetch next from cur_createquote into @svendorcode
|
|
|
continue
|
|
|
end
|
|
|
|
|
|
exec f_get_billno 'oq',@sorgcode,'1',@sbillno output
|
|
|
if @@error <> 0
|
|
|
begin
|
|
|
set @srtnmsg = '生成单据号失败'
|
|
|
close cur_createquote
|
|
|
deallocate cur_createquote
|
|
|
return(-1)
|
|
|
end
|
|
|
|
|
|
insert into t_orderquote_body(billno,serialno,plucode,barcode,pluname,depcode,depname,spec,cargono,unit,jtaxrate,remark)
|
|
|
select distinct @sbillno,a.serialno,a.grpcode as plucode,b.barcode,b.pluname,b.depcode,(select depname from t_dept where depcode=b.depcode) as depname,
|
|
|
b.spec,b.cargono,b.unit,jtaxrate,'促销单自动生成' as remark
|
|
|
from t_prom_body a,t_plu b,t_plu_org c, t_prom_org d
|
|
|
where a.billno = @sdsccode and d.billno = @sdsccode and a.grptype = 'p' and a.grpcode = b.plucode and a.grpcode = c.plucode and c.orgcode = d.orgcode and
|
|
|
case when isnull(c.supcode ,'') = '' then b.supcode else c.supcode end = @svendorcode
|
|
|
|
|
|
if @@error <> 0
|
|
|
begin
|
|
|
set @srtnmsg = '插入商品明细表失败'
|
|
|
close cur_createquote
|
|
|
deallocate cur_createquote
|
|
|
return(-1)
|
|
|
end
|
|
|
|
|
|
if not exists(select * from t_orderquote_body where billno = @sbillno)
|
|
|
begin
|
|
|
set @srtnmsg = @srtnmsg + char(13) + '供应商'+@svendorcode+'没有查询到商品数据'
|
|
|
fetch next from cur_createquote into @svendorcode
|
|
|
continue
|
|
|
end
|
|
|
|
|
|
insert into t_orderquote_org(billno,serialno,plucode,orgcode,jprice,netjprice,remark)
|
|
|
select a.billno,a.serialno,a.plucode,c.orgcode,b.jprice,b.netjprice,'促销单自动生成' as remark
|
|
|
from t_orderquote_body a,t_prom_body b,t_prom_org c
|
|
|
where a.billno = @sbillno and a.plucode = b.grpcode and b.billno = @sdsccode and c.billno = @sdsccode and b.grptype = 'p'
|
|
|
|
|
|
if @@error <> 0
|
|
|
begin
|
|
|
set @srtnmsg = '插入商品机构报价明细表失败'
|
|
|
close cur_createquote
|
|
|
deallocate cur_createquote
|
|
|
return(-1)
|
|
|
end
|
|
|
|
|
|
if not exists(select * from t_orderquote_org where billno = @sbillno)
|
|
|
begin
|
|
|
set @srtnmsg = @srtnmsg + char(13) + '供应商'+@svendorcode+'没有查询到机构报价数据'
|
|
|
delete from t_orderquote_body where billno = @sbillno
|
|
|
fetch next from cur_createquote into @svendorcode
|
|
|
continue
|
|
|
end
|
|
|
|
|
|
insert into t_orderquote_head(billno,orgcode,supcode,supname,quotetype,bgndate,enddate,chkstatus,
|
|
|
shrcode,shrname,rzdate,rztime,lrdate,lrtime,usercode,username,zdrcode,zdrname,remark,dsccode)
|
|
|
select @sbillno,@sorgcode,@svendorcode,supname,'1' as quotetype,@sbgndate,@senddate,case when @scheckmode = '0' then '1' else '0' end as chkstatus,
|
|
|
case when @scheckmode = '0' then @susercode else null end as chkstatus,case when @scheckmode = '0' then @susername else null end as shrname,
|
|
|
'' as rzdate,'' as rztime,convert(varchar(10),getdate(),126) as lrdate,convert(varchar(8),getdate(),8) as lrtime,
|
|
|
@susercode as usercode,@susername as username,@susercode as zdrcode,@susername as zdrname,'促销单自动生成' as remark,@sdsccode as dsccode
|
|
|
from t_supplier
|
|
|
where supcode = @svendorcode
|
|
|
|
|
|
if @@error <> 0
|
|
|
begin
|
|
|
set @srtnmsg = '插入合同报价单主表失败'
|
|
|
close cur_createquote
|
|
|
deallocate cur_createquote
|
|
|
return(-1)
|
|
|
end
|
|
|
|
|
|
if not exists(select * from t_orderquote_head where billno = @sbillno)
|
|
|
begin
|
|
|
set @srtnmsg = @srtnmsg + char(13) + '供应商'+@svendorcode+'没有生成报价单主表'
|
|
|
delete from t_orderquote_body where billno = @sbillno
|
|
|
delete from t_orderquote_org where billno = @sbillno
|
|
|
fetch next from cur_createquote into @svendorcode
|
|
|
continue
|
|
|
end
|
|
|
|
|
|
exec p_rz_oq @sorgcode,@sbillno,'',@srtnmsg output
|
|
|
if @@error <> 0
|
|
|
begin
|
|
|
set @srtnmsg = '报价单记账失败'
|
|
|
close cur_createquote
|
|
|
deallocate cur_createquote
|
|
|
return(-1)
|
|
|
end
|
|
|
set @ibillcount = @ibillcount + 1
|
|
|
fetch next from cur_createquote into @svendorcode
|
|
|
end
|
|
|
|
|
|
close cur_createquote
|
|
|
deallocate cur_createquote
|
|
|
|
|
|
if isnull(@srtnmsg,'') = ''
|
|
|
return(1)
|
|
|
else
|
|
|
return(0)
|
|
|
end
|
|
|
go
|
|
|
|
|
|
if exists (select * from dbo.sysobjects where id = object_id(N'p_deal_pda_lblprn_task_data') and objectproperty(id, N'isprocedure') = 1)
|
|
|
drop procedure p_deal_pda_lblprn_task_data
|
|
|
go
|
|
|
create procedure p_deal_pda_lblprn_task_data
|
|
|
@iserialno int,
|
|
|
@susercode varchar(6),
|
|
|
@susername varchar(10),
|
|
|
@srtnmsg varchar(8000) out
|
|
|
as
|
|
|
begin
|
|
|
declare @scurorgcode varchar(10)
|
|
|
declare @scurver varchar(1)
|
|
|
declare @irows int
|
|
|
declare @idetailserialno int
|
|
|
declare @spdno varchar(20)
|
|
|
declare @sorgcode varchar(10)
|
|
|
declare @sbillno varchar(20)
|
|
|
declare @splace varchar(1)
|
|
|
select @scurorgcode = itemvalue from t_syscfg where section = 'system' and itemname = 'branchno'
|
|
|
select @scurver = itemvalue from t_syscfg where section = 'system' and itemname = 'ver'
|
|
|
set @srtnmsg = ''
|
|
|
set @irows = 0
|
|
|
|
|
|
delete from t_intf_lblprntask_data where serialno = @iserialno and isnull(plucode,'') = '' and prntype = '1'
|
|
|
set @irows = @@rowcount
|
|
|
if @irows <> 0
|
|
|
begin
|
|
|
if @srtnmsg = ''
|
|
|
set @srtnmsg = '导入标价签打印任务:有'+convert(varchar(30),@irows)+'条数据商品编码为空,不能导入'
|
|
|
else
|
|
|
set @srtnmsg = @srtnmsg + '|导入标价签打印任务:有'+convert(varchar(30),@irows)+'条数据商品编码为空,不能导入'
|
|
|
end
|
|
|
|
|
|
delete from t_intf_lblprntask_data
|
|
|
where not exists(select plucode from t_plu where plucode = t_intf_lblprntask_data.plucode) and serialno = @iserialno and prntype = '1'
|
|
|
set @irows = @@rowcount
|
|
|
if @irows <> 0
|
|
|
begin
|
|
|
if @srtnmsg = ''
|
|
|
set @srtnmsg = '导入标价签打印任务:有'+convert(varchar(30),@irows)+'条数据商品编码不存在,不能导入'
|
|
|
else
|
|
|
set @srtnmsg = @srtnmsg + '|导入标价签打印任务:有'+convert(varchar(30),@irows)+'条数据商品编码不存在,不能导入'
|
|
|
end
|
|
|
|
|
|
delete from t_intf_lblprntask_data
|
|
|
where not exists(select plucode from t_plu_org where plucode = t_intf_lblprntask_data.plucode and orgcode = t_intf_lblprntask_data.orgcode and isright = '1') and serialno = @iserialno and prntype = '1'
|
|
|
set @irows = @@rowcount
|
|
|
if @irows <> 0
|
|
|
begin
|
|
|
if @srtnmsg = ''
|
|
|
set @srtnmsg = '导入标价签打印任务:有'+convert(varchar(30),@irows)+'条数据没有机构经营权,不能导入'
|
|
|
else
|
|
|
set @srtnmsg = @srtnmsg + '|导入标价签打印任务:有'+convert(varchar(30),@irows)+'条数据没有机构经营权,不能导入'
|
|
|
end
|
|
|
|
|
|
insert into t_label_prn_task(plucode,pluname,barcode,prncount,orgcode,price,vipprice,unit,spec,prodarea,prntype,remark)
|
|
|
select m.plucode,isnull(r.pluname,g.pluname) as pluname,m.barcode,m.prncount,m.orgcode,o.price,o.vipprice,g.unit,isnull(r.spec,g.spec) as spec,g.prodarea,'1' as prntype,m.remark
|
|
|
from t_intf_lblprntask_data m left join t_plu g on m.plucode = g.plucode
|
|
|
left join t_barcode_ref r on m.plucode = r.plucode and m.barcode = r.barcode
|
|
|
left join t_plu_org o on m.plucode = o.plucode and m.orgcode = o.orgcode
|
|
|
where m.prntype = '1' and serialno = @iserialno
|
|
|
|
|
|
delete from t_intf_lblprntask_data where serialno = @iserialno and isnull(plucode,'') = '' and prntype = '0'
|
|
|
set @irows = @@rowcount
|
|
|
if @irows <> 0
|
|
|
begin
|
|
|
if @srtnmsg = ''
|
|
|
set @srtnmsg = '导入条码打印任务:有'+convert(varchar(30),@irows)+'条数据商品编码为空,不能导入'
|
|
|
else
|
|
|
set @srtnmsg = @srtnmsg + '|导入条码打印任务:有'+convert(varchar(30),@irows)+'条数据商品编码为空,不能导入'
|
|
|
end
|
|
|
|
|
|
delete from t_intf_lblprntask_data
|
|
|
where not exists(select plucode from t_plu where plucode = t_intf_lblprntask_data.plucode) and serialno = @iserialno and prntype = '0'
|
|
|
set @irows = @@rowcount
|
|
|
if @irows <> 0
|
|
|
begin
|
|
|
if @srtnmsg = ''
|
|
|
set @srtnmsg = '导入条码打印任务:有'+convert(varchar(30),@irows)+'条数据商品编码不存在,不能导入'
|
|
|
else
|
|
|
set @srtnmsg = @srtnmsg + '|导入条码打印任务:有'+convert(varchar(30),@irows)+'条数据商品编码不存在,不能导入'
|
|
|
end
|
|
|
|
|
|
delete from t_intf_lblprntask_data
|
|
|
where not exists(select plucode from t_plu_org where plucode = t_intf_lblprntask_data.plucode and orgcode = t_intf_lblprntask_data.orgcode and isright = '1') and serialno = @iserialno and prntype = '0'
|
|
|
set @irows = @@rowcount
|
|
|
if @irows <> 0
|
|
|
begin
|
|
|
if @srtnmsg = ''
|
|
|
set @srtnmsg = '导入条码打印任务:有'+convert(varchar(30),@irows)+'条数据没有机构经营权,不能导入'
|
|
|
else
|
|
|
set @srtnmsg = @srtnmsg + '|导入条码打印任务:有'+convert(varchar(30),@irows)+'条数据没有机构经营权,不能导入'
|
|
|
end
|
|
|
|
|
|
insert into t_label_prn_task(plucode,pluname,barcode,prncount,orgcode,price,vipprice,unit,spec,prodarea,prntype,remark)
|
|
|
select m.plucode,isnull(r.pluname,g.pluname) as pluname,m.barcode,m.prncount,m.orgcode,o.price,o.vipprice,g.unit,isnull(r.spec,g.spec) as spec,g.prodarea,'0' as prntype,m.remark
|
|
|
from t_intf_lblprntask_data m left join t_plu g on m.plucode = g.plucode
|
|
|
left join t_barcode_ref r on m.plucode = r.plucode and m.barcode = r.barcode
|
|
|
left join t_plu_org o on m.plucode = o.plucode and m.orgcode = o.orgcode
|
|
|
where m.prntype = '0' and serialno = @iserialno
|
|
|
|
|
|
delete from t_intf_lblprntask_data where serialno = @iserialno
|
|
|
return(1)
|
|
|
end
|
|
|
go
|
|
|
|
|
|
if exists (select * from dbo.sysobjects where id = object_id(N'p_deal_pda_pdcard_plu_data') and objectproperty(id, N'isprocedure') = 1)
|
|
|
drop procedure p_deal_pda_pdcard_plu_data
|
|
|
go
|
|
|
create procedure p_deal_pda_pdcard_plu_data
|
|
|
@iserialno int,
|
|
|
@susercode varchar(6),
|
|
|
@susername varchar(10),
|
|
|
@srtnmsg varchar(8000) out
|
|
|
as
|
|
|
begin
|
|
|
declare @irows int
|
|
|
declare @sorgcode varchar(10)
|
|
|
declare @scardcode varchar(20)
|
|
|
declare @imaxserialno int
|
|
|
declare @iloop int
|
|
|
set @srtnmsg = ''
|
|
|
set @irows = 0
|
|
|
|
|
|
delete from t_intf_cardplu_data where serialno = @iserialno and isnull(plucode,'') = ''
|
|
|
set @irows = @@rowcount
|
|
|
if @irows <> 0
|
|
|
begin
|
|
|
if @srtnmsg = ''
|
|
|
set @srtnmsg = '有'+convert(varchar(30),@irows)+'条数据商品编码为空,不能导入'
|
|
|
else
|
|
|
set @srtnmsg = @srtnmsg + '|有'+convert(varchar(30),@irows)+'条数据商品编码为空,不能导入'
|
|
|
end
|
|
|
delete from t_intf_cardplu_data where serialno = @iserialno and isnull(orgcode,'') = ''
|
|
|
set @irows = @@rowcount
|
|
|
if @irows <> 0
|
|
|
begin
|
|
|
if @srtnmsg = ''
|
|
|
set @srtnmsg = '有'+convert(varchar(30),@irows)+'条数据机构编码为空,不能导入'
|
|
|
else
|
|
|
set @srtnmsg = @srtnmsg + '|有'+convert(varchar(30),@irows)+'条数据机构编码为空,不能导入'
|
|
|
end
|
|
|
delete from t_intf_cardplu_data where serialno = @iserialno and isnull(cardcode,'') = ''
|
|
|
set @irows = @@rowcount
|
|
|
if @irows <> 0
|
|
|
begin
|
|
|
if @srtnmsg = ''
|
|
|
set @srtnmsg = '有'+convert(varchar(30),@irows)+'条数据货架编码为空,不能导入'
|
|
|
else
|
|
|
set @srtnmsg = @srtnmsg + '|有'+convert(varchar(30),@irows)+'条数据货架编码为空,不能导入'
|
|
|
end
|
|
|
|
|
|
delete from t_intf_cardplu_data
|
|
|
where not exists(select plucode from t_plu where plucode = t_intf_cardplu_data.plucode) and serialno = @iserialno
|
|
|
set @irows = @@rowcount
|
|
|
if @irows <> 0
|
|
|
begin
|
|
|
if @srtnmsg = ''
|
|
|
set @srtnmsg = '有'+convert(varchar(30),@irows)+'条数据商品编码不存在,不能导入'
|
|
|
else
|
|
|
set @srtnmsg = @srtnmsg + '|有'+convert(varchar(30),@irows)+'条数据商品编码不存在,不能导入'
|
|
|
end
|
|
|
|
|
|
delete from t_intf_cardplu_data
|
|
|
where not exists(select plucode from t_plu_org where plucode = t_intf_cardplu_data.plucode and orgcode = t_intf_cardplu_data.orgcode and isright = '1') and serialno = @iserialno
|
|
|
set @irows = @@rowcount
|
|
|
if @irows <> 0
|
|
|
begin
|
|
|
if @srtnmsg = ''
|
|
|
set @srtnmsg = '有'+convert(varchar(30),@irows)+'条数据没有机构经营权,不能导入'
|
|
|
else
|
|
|
set @srtnmsg = @srtnmsg + '|有'+convert(varchar(30),@irows)+'条数据没有机构经营权,不能导入'
|
|
|
end
|
|
|
|
|
|
delete from t_intf_cardplu_data
|
|
|
where not exists(select cardcode from t_chkcard where cardcode = t_intf_cardplu_data.cardcode and orgcode = t_intf_cardplu_data.orgcode ) and serialno = @iserialno
|
|
|
set @irows = @@rowcount
|
|
|
if @irows <> 0
|
|
|
begin
|
|
|
if @srtnmsg = ''
|
|
|
set @srtnmsg = '有'+convert(varchar(30),@irows)+'条数据没有创建货架编码,不能导入'
|
|
|
else
|
|
|
set @srtnmsg = @srtnmsg + '|有'+convert(varchar(30),@irows)+'条数据没有创建货架编码,不能导入'
|
|
|
end
|
|
|
|
|
|
update a set a.pluorderno = b.maxserialno
|
|
|
from t_intf_cardplu_data a,
|
|
|
(select orgcode,cardcode,max(serialno) as maxserialno from t_chkcard_plu
|
|
|
group by orgcode,cardcode) b
|
|
|
where a.orgcode = b.orgcode and a.cardcode = b.cardcode
|
|
|
|
|
|
declare cur_setorderno cursor for select distinct orgcode,cardcode from t_intf_cardplu_data
|
|
|
open cur_setorderno
|
|
|
fetch next from cur_setorderno into @sorgcode,@scardcode
|
|
|
set @iloop = 0
|
|
|
while @@fetch_status = 0
|
|
|
begin
|
|
|
update t_intf_cardplu_data set pluorderno = @imaxserialno + @iloop,@imaxserialno = pluorderno,@iloop = @iloop + 1
|
|
|
where orgcode = @sorgcode and cardcode = @scardcode
|
|
|
fetch next from cur_setorderno into @sorgcode,@scardcode
|
|
|
set @iloop = 0
|
|
|
end
|
|
|
close cur_setorderno
|
|
|
deallocate cur_setorderno
|
|
|
|
|
|
insert into t_chkcard_plu(orgcode,cardcode,serialno,plucode,pluname,barcode,spec)
|
|
|
select m.orgcode,m.cardcode,m.pluorderno,m.plucode,isnull(g.pluname,r.pluname) as pluname,m.barcode,isnull(g.spec,r.spec) as spec
|
|
|
from t_intf_cardplu_data m left join t_plu g on m.plucode = g.plucode
|
|
|
left join t_barcode_ref r on m.plucode = r.plucode and m.barcode = r.barcode
|
|
|
where serialno = @iserialno
|
|
|
|
|
|
delete from t_intf_cardplu_data where serialno = @iserialno
|
|
|
return(1)
|
|
|
end
|
|
|
go
|
|
|
|
|
|
if exists(select * from sysobjects where name = 'p_qry_sup_stock' and xtype = 'p')
|
|
|
drop procedure p_qry_sup_stock
|
|
|
go
|
|
|
create procedure p_qry_sup_stock
|
|
|
(
|
|
|
@psorgcode varchar(10),
|
|
|
@psplucode varchar(20),
|
|
|
@psvendorcode varchar(15),
|
|
|
@psisrealstock varchar(1),
|
|
|
@psrtnmsg varchar(1000) output
|
|
|
)
|
|
|
as
|
|
|
declare @ssql varchar(8000)
|
|
|
begin
|
|
|
if exists(select * from tempdb..sysobjects where id = object_id(N'tempdb..#tmporg') and xtype = 'u')
|
|
|
drop table #tmporg
|
|
|
select orgcode,orgname into #tmporg from t_shop
|
|
|
where (@psorgcode <> 'c00000' and orgcode = @psorgcode ) or (@psorgcode = 'c00000' and orgtype = '2')
|
|
|
if @@error <> 0
|
|
|
begin
|
|
|
set @psrtnmsg = '创建机构临时表失败'
|
|
|
return(-1)
|
|
|
end
|
|
|
|
|
|
if exists(select * from sysobjects where id = object_id(N'tempdb..#tmpvendorplu') and xtype = 'u')
|
|
|
drop table #tmpvendorplu
|
|
|
select supcode,plucode into #tmpvendorplu from t_supaccept_detail c
|
|
|
where (@psvendorcode = '' or supcode = @psvendorcode) and (@psplucode = '' or plucode = @psplucode)
|
|
|
and exists(select 1 from #tmporg where orgcode = c.orgcode) and counts <> ftcounts group by supcode,plucode
|
|
|
if @@error <> 0
|
|
|
begin
|
|
|
set @psrtnmsg = '创建供应商商品临时表失败'
|
|
|
return(-1)
|
|
|
end
|
|
|
|
|
|
if exists(select * from sysobjects where id = object_id(N'tempdb..#tmpvendorplustock') and xtype = 'u')
|
|
|
drop table #tmpvendorplustock
|
|
|
select * into #tmpvendorplustock from t_supaccept_detail c
|
|
|
where exists (select 1 from #tmpvendorplu where plucode = c.plucode and supcode = c.supcode)
|
|
|
and exists (select 1 from #tmporg where orgcode = c.orgcode) and c.counts <> c.ftcounts
|
|
|
if @@error <> 0
|
|
|
begin
|
|
|
set @psrtnmsg = '创建供应商下商品库存明细临时表失败'
|
|
|
return(-1)
|
|
|
end
|
|
|
|
|
|
if exists (select * from sysobjects where id = object_id(N'tempdb..#tmppluvendorstock') and xtype = 'u')
|
|
|
drop table #tmppluvendorstock
|
|
|
select * into #tmppluvendorstock
|
|
|
from t_supaccept_detail c
|
|
|
where exists (select 1 from #tmpvendorplu where plucode = c.plucode)
|
|
|
and exists (select 1 from #tmporg where orgcode = c.orgcode) and c.counts <> c.ftcounts
|
|
|
if @@error <> 0
|
|
|
begin
|
|
|
set @psrtnmsg = '创建商品下各供应商库存明细临时表失败'
|
|
|
return(-1)
|
|
|
end
|
|
|
|
|
|
if exists (select * from sysobjects where id = object_id(N'tempdb..#tmpgoodsorg') and xtype = 'u')
|
|
|
drop table #tmpgoodsorg
|
|
|
create table #tmpgoodsorg
|
|
|
(plucode varchar(20),
|
|
|
stockcount numeric(19,4))
|
|
|
|
|
|
if @psisrealstock <> '1'
|
|
|
insert into #tmpgoodsorg
|
|
|
select plucode,sum(d.gcount + d.ccount) as stockcount from t_plu_org d
|
|
|
where exists (select 1 from #tmpvendorplu where d.plucode = plucode)
|
|
|
and exists (select 1 from #tmporg where d.orgcode = orgcode) group by d.plucode
|
|
|
else
|
|
|
insert into #tmpgoodsorg
|
|
|
select plucode,sum(stockcount) as stockcount from
|
|
|
(select plucode,sum(d.gcount + d.ccount) as stockcount from t_plu_org d
|
|
|
where exists (select 1 from #tmpvendorplu where plucode = d.plucode)
|
|
|
and exists (select 1 from #tmporg where orgcode = d.orgcode) group by d.plucode
|
|
|
union all
|
|
|
select plucode,-1*sum(pluqty) as stockcount from t_flow_item d
|
|
|
where exists (select 1 from #tmpvendorplu where plucode = d.plucode)
|
|
|
and exists (select 1 from #tmporg where orgcode = d.orgcode) group by plucode
|
|
|
) a group by plucode
|
|
|
if @@error <> 0
|
|
|
begin
|
|
|
set @psrtnmsg = '更新商品的库存数据临时表失败'
|
|
|
return(-1)
|
|
|
end
|
|
|
|
|
|
if exists(select * from tempdb..sysobjects where id = object_id(N'tempdb..#tmpstockdest') and xtype = 'u')
|
|
|
drop table #tmpstockdest
|
|
|
create table #tmpstockdest
|
|
|
(indexno int,
|
|
|
billno varchar(20) not null default('*'),
|
|
|
supcode varchar(15) not null,
|
|
|
supname varchar(100) null,
|
|
|
plucode varchar(20) not null,
|
|
|
pluname varchar(40) null,
|
|
|
orgcode varchar(10) not null,
|
|
|
orgname varchar(30) null,
|
|
|
stockcount numeric(19,4) not null default(0),
|
|
|
acceptcount numeric(19,4) not null default(0),
|
|
|
jprice numeric(19,4) not null default(0),
|
|
|
netjprice numeric(19,4) not null default(0),
|
|
|
price numeric(19,4) not null default(0))
|
|
|
|
|
|
insert into #tmpstockdest(indexno,billno,supcode,supname,plucode,pluname,orgcode,orgname,
|
|
|
stockcount,acceptcount,jprice,netjprice,price)
|
|
|
select indexno,billno,supcode,supname,plucode,pluname,orgcode,orgname,
|
|
|
case when (stockcount - deccounts) > 0 then
|
|
|
case when (stockcount - deccounts) - owncounts >=0 then owncounts else stockcount - deccounts end
|
|
|
else 0 end as stockcount, counts,jprice,netjprice,price
|
|
|
from
|
|
|
(select c.indexno,c.billno, c.plucode,c.pluname,c.supcode ,c.supname,c.orgcode,c.orgname,
|
|
|
c.jprice,c.netjprice,c.price,c.counts,
|
|
|
(c.counts-c.ftcounts) as owncounts,isnull(o.stockcount,0) as stockcount,
|
|
|
sum(isnull(d.counts,0) - isnull(d.ftcounts,0)) as deccounts
|
|
|
from #tmpvendorplustock c
|
|
|
left join #tmppluvendorstock d on c.plucode = d.plucode and c.indexno < d.indexno
|
|
|
left join #tmpgoodsorg o on c.plucode = o.plucode
|
|
|
group by c.indexno,c.billno, c.plucode,c.pluname,c.supcode ,c.supname,isnull(o.stockcount,0),c.counts,c.ftcounts,
|
|
|
c.orgcode,c.orgname,c.jprice,c.netjprice,c.price
|
|
|
) a
|
|
|
if @@error <> 0
|
|
|
begin
|
|
|
set @psrtnmsg = '更新商品的库存目标临时表失败'
|
|
|
return(-1)
|
|
|
end
|
|
|
|
|
|
if @psplucode <> '' and @psvendorcode = ''
|
|
|
begin
|
|
|
insert into #tmpstockdest(plucode,pluname,supcode ,supname,orgcode,orgname,stockcount,acceptcount,jprice,netjprice,price)
|
|
|
select s.plucode,s.pluname, 'none','不明确供应商',@psorgcode,'',avg(o.stockcount) - sum(counts - ftcounts) ,0,0,0,0
|
|
|
from #tmppluvendorstock s,#tmpgoodsorg o
|
|
|
where s.plucode = o.plucode
|
|
|
group by s.plucode,s.pluname
|
|
|
having avg(o.stockcount) - sum(counts - ftcounts) > 0
|
|
|
if @@error <> 0
|
|
|
begin
|
|
|
set @psrtnmsg = '更新不明确库存数据失败'
|
|
|
return(-1)
|
|
|
end
|
|
|
end
|
|
|
|
|
|
select a.plucode,a.pluname,b.barcode,b.spec,b.unit,a.supcode ,a.supname,sum(a.stockcount) as counts,sum(stockcount * a.jprice) as cost,sum(stockcount*a.netjprice) as netcost,sum(stockcount * a.price) as total
|
|
|
from #tmpstockdest a,t_plu b where a.plucode=b.plucode
|
|
|
group by b.barcode,b.spec,b.unit,a.supcode ,a.supname,a.plucode,a.pluname
|
|
|
return(1)
|
|
|
end
|
|
|
go
|
|
|
|
|
|
if exists(select * from sysobjects where name = 'p_calc_vip_pt' and xtype = 'p')
|
|
|
drop procedure p_calc_vip_pt
|
|
|
go
|
|
|
create procedure p_calc_vip_pt
|
|
|
(
|
|
|
@svipdbname varchar(100),
|
|
|
@sserialno varchar(8),
|
|
|
@sposno varchar(6),
|
|
|
@sorgcode varchar(10),
|
|
|
@sdate varchar(10),
|
|
|
@stime varchar(8),
|
|
|
@strantype varchar(1),
|
|
|
@serrmsg varchar(2000) out
|
|
|
)
|
|
|
as
|
|
|
begin
|
|
|
declare @ssql nvarchar(4000)
|
|
|
declare @svipcode varchar(20)
|
|
|
declare @svipcanjf varchar(1)
|
|
|
declare @irecordcount int
|
|
|
declare @scurdate varchar(10)
|
|
|
declare @svipbirthday varchar(10)
|
|
|
declare @sposcfg_dscjf varchar(1)
|
|
|
declare @iposcfg_morejfset varchar(10)
|
|
|
declare @sitemplucode varchar(20)
|
|
|
declare @sitemclscode varchar(10)
|
|
|
declare @sitemdepcode varchar(10)
|
|
|
declare @sitembrand varchar(10)
|
|
|
declare @citempludsc numeric(19,4)
|
|
|
declare @citemplutotal numeric(19,4)
|
|
|
declare @sitempageno varchar(2)
|
|
|
declare @sitemitemno varchar(5)
|
|
|
declare @ctrade_total numeric(19,4)
|
|
|
declare @cpay_canjftotal numeric(19,4)
|
|
|
declare @ccanjfpayrate numeric(19,4)
|
|
|
declare @sitempludsctype varchar(1)
|
|
|
declare @ctmpflxftotal numeric(19,4)
|
|
|
declare @ctmpyxrate numeric(19,4)
|
|
|
declare @cjfaddrate numeric(19,4)
|
|
|
declare @cviptypejfaddrate numeric(19,4)
|
|
|
declare @ctmpjftotal numeric(19,4)
|
|
|
declare @sjfistrunc varchar(1)
|
|
|
declare @sclsuppercode1 varchar(10)
|
|
|
declare @sclsuppercode2 varchar(10)
|
|
|
declare @sclsuppercode3 varchar(10)
|
|
|
declare @sclsuppercode4 varchar(10)
|
|
|
declare @sclsuppercode5 varchar(10)
|
|
|
declare @sdepuppercode1 varchar(10)
|
|
|
declare @sdepuppercode2 varchar(10)
|
|
|
declare @sdepuppercode3 varchar(10)
|
|
|
declare @sdepuppercode4 varchar(10)
|
|
|
|
|
|
set @ctmpflxftotal = 0.00
|
|
|
set @ctmpyxrate = 0.00
|
|
|
set @ctmpjftotal = 0.00
|
|
|
|
|
|
set @scurdate = convert(varchar(10),getdate(),126)
|
|
|
|
|
|
set @svipcode = ''
|
|
|
select @svipcode = custcode from t_flow_total
|
|
|
where serialno = @sserialno and posno = @sposno and orgcode = @sorgcode and sdate = @sdate and stime = @stime and trantype = @strantype
|
|
|
if @svipcode = ''
|
|
|
return(1)
|
|
|
|
|
|
set @svipcanjf = ''
|
|
|
set @ssql = N'select @scanjf = b.canjf, @jfaddrate = jfaddrate from '+@svipdbname+'..t_vip a left join '+@svipdbname+'..t_viptype b on a.viptype = b.lxcode where a.vipcode = '''+@svipcode+''''
|
|
|
exec sp_executesql @ssql,N'@scanjf varchar(1) output,@jfaddrate numeric(19,4) output',@svipcanjf out,@cviptypejfaddrate out
|
|
|
if @svipcanjf <> '1'
|
|
|
return(1)
|
|
|
|
|
|
select @sposcfg_dscjf = itemvalue from t_poscfg where posno = @sposno and orgcode = @sorgcode and itemname = 'dsc jf' and section = 'vip'
|
|
|
select @iposcfg_morejfset = itemvalue from t_poscfg where posno = @sposno and orgcode = @sorgcode and itemname = 'morejfset' and section = 'system'
|
|
|
select @sjfistrunc = case when itemvalue = 'no' then '0' else '1' end from t_poscfg where posno = @sposno and orgcode = @sorgcode and section = 'vip' and itemname = 'vipjfistrunc'
|
|
|
|
|
|
declare cur_calcvipjf_item cursor for select a.pageno,a.itemno,a.plucode,a.clscode,a.depcode,isnull(b.brandcode ,''),pludsc,plutotal,pludsctype,isnull(d.uppercode1,''),isnull(d.uppercode2,'') ,isnull(d.uppercode3,''),isnull(d.uppercode4,''),isnull(c.uppercode1,''),isnull(c.uppercode2,''),isnull(c.uppercode3,''),isnull(c.uppercode4,''),isnull(c.uppercode5,'')
|
|
|
from t_flow_item a left join t_plu b on a.plucode = b.plucode
|
|
|
left join t_dept d on b.depcode = d.depcode
|
|
|
left join t_gclass c on b.clscode = c.clscode
|
|
|
where serialno = @sserialno and posno = @sposno and orgcode = @sorgcode and sdate = @sdate and stime = @stime and trantype = @strantype
|
|
|
open cur_calcvipjf_item
|
|
|
fetch next from cur_calcvipjf_item into @sitempageno,@sitemitemno,@sitemplucode,@sitemclscode,@sitemdepcode,@sitembrand,@citempludsc,@citemplutotal,@sitempludsctype,@sdepuppercode1,@sdepuppercode2,@sdepuppercode3,@sdepuppercode4,@sclsuppercode1,@sclsuppercode2,@sclsuppercode3,@sclsuppercode4,@sclsuppercode5
|
|
|
while @@fetch_status = 0
|
|
|
begin
|
|
|
set @sitemclscode = case when isnull(@sitemclscode,'') = '' then 'none' else @sitemclscode end
|
|
|
set @sitemdepcode = case when isnull(@sitemdepcode,'') = '' then 'none' else @sitemdepcode end
|
|
|
set @sitembrand = case when isnull(@sitembrand,'') = '' then 'none' else @sitembrand end
|
|
|
|
|
|
if @sposcfg_dscjf = '0'
|
|
|
begin
|
|
|
if @sitempludsctype <> '' and @sitempludsctype <> 'b'
|
|
|
begin
|
|
|
fetch next from cur_calcvipjf_item into @sitempageno,@sitemitemno,@sitemplucode,@sitemclscode,@sitemdepcode,@sitembrand,@citempludsc,@citemplutotal,@sitempludsctype,@sdepuppercode1,@sdepuppercode2,@sdepuppercode3,@sdepuppercode4,@sclsuppercode1,@sclsuppercode2,@sclsuppercode3,@sclsuppercode4,@sclsuppercode5
|
|
|
continue
|
|
|
end
|
|
|
end
|
|
|
else if @sposcfg_dscjf = '1'
|
|
|
begin
|
|
|
if (@sitempludsctype <> '1') and (@sitempludsctype <> '') and (@sitempludsctype <> 'b')
|
|
|
begin
|
|
|
fetch next from cur_calcvipjf_item into @sitempageno,@sitemitemno,@sitemplucode,@sitemclscode,@sitemdepcode,@sitembrand,@citempludsc,@citemplutotal,@sitempludsctype,@sdepuppercode1,@sdepuppercode2,@sdepuppercode3,@sdepuppercode4,@sclsuppercode1,@sclsuppercode2,@sclsuppercode3,@sclsuppercode4,@sclsuppercode5
|
|
|
continue
|
|
|
end
|
|
|
end
|
|
|
else if @sposcfg_dscjf = '2'
|
|
|
begin
|
|
|
if (@sitempludsctype <> '2') and (@sitempludsctype <> '') and (@sitempludsctype <> 'b')
|
|
|
begin
|
|
|
fetch next from cur_calcvipjf_item into @sitempageno,@sitemitemno,@sitemplucode,@sitemclscode,@sitemdepcode,@sitembrand,@citempludsc,@citemplutotal,@sitempludsctype,@sdepuppercode1,@sdepuppercode2,@sdepuppercode3,@sdepuppercode4,@sclsuppercode1,@sclsuppercode2,@sclsuppercode3,@sclsuppercode4,@sclsuppercode5
|
|
|
continue
|
|
|
end
|
|
|
end
|
|
|
else if @sposcfg_dscjf = '3'
|
|
|
begin
|
|
|
if (@sitempludsctype <> '1') and (@sitempludsctype <> '2') and (@sitempludsctype <> '') and (@sitempludsctype <> 'b')
|
|
|
begin
|
|
|
fetch next from cur_calcvipjf_item into @sitempageno,@sitemitemno,@sitemplucode,@sitemclscode,@sitemdepcode,@sitembrand,@citempludsc,@citemplutotal,@sitempludsctype,@sdepuppercode1,@sdepuppercode2,@sdepuppercode3,@sdepuppercode4,@sclsuppercode1,@sclsuppercode2,@sclsuppercode3,@sclsuppercode4,@sclsuppercode5
|
|
|
continue
|
|
|
end
|
|
|
end
|
|
|
else if @sposcfg_dscjf = '4'
|
|
|
begin
|
|
|
if (@sitempludsctype <> '9') and (@sitempludsctype <> '') and (@sitempludsctype <> 'b')
|
|
|
begin
|
|
|
fetch next from cur_calcvipjf_item into @sitempageno,@sitemitemno,@sitemplucode,@sitemclscode,@sitemdepcode,@sitembrand,@citempludsc,@citemplutotal,@sitempludsctype,@sdepuppercode1,@sdepuppercode2,@sdepuppercode3,@sdepuppercode4,@sclsuppercode1,@sclsuppercode2,@sclsuppercode3,@sclsuppercode4,@sclsuppercode5
|
|
|
continue
|
|
|
end
|
|
|
end
|
|
|
else if @sposcfg_dscjf = '5'
|
|
|
begin
|
|
|
if (@sitempludsctype <> '1') and (@sitempludsctype <> '9') and (@sitempludsctype <> '') and (@sitempludsctype <> 'b')
|
|
|
begin
|
|
|
fetch next from cur_calcvipjf_item into @sitempageno,@sitemitemno,@sitemplucode,@sitemclscode,@sitemdepcode,@sitembrand,@citempludsc,@citemplutotal,@sitempludsctype,@sdepuppercode1,@sdepuppercode2,@sdepuppercode3,@sdepuppercode4,@sclsuppercode1,@sclsuppercode2,@sclsuppercode3,@sclsuppercode4,@sclsuppercode5
|
|
|
continue
|
|
|
end
|
|
|
end
|
|
|
else if @sposcfg_dscjf = '6'
|
|
|
begin
|
|
|
if (@sitempludsctype <> '2') and (@sitempludsctype <> '9') and (@sitempludsctype <> '') and (@sitempludsctype <> 'b')
|
|
|
begin
|
|
|
fetch next from cur_calcvipjf_item into @sitempageno,@sitemitemno,@sitemplucode,@sitemclscode,@sitemdepcode,@sitembrand,@citempludsc,@citemplutotal,@sitempludsctype,@sdepuppercode1,@sdepuppercode2,@sdepuppercode3,@sdepuppercode4,@sclsuppercode1,@sclsuppercode2,@sclsuppercode3,@sclsuppercode4,@sclsuppercode5
|
|
|
continue
|
|
|
end
|
|
|
end
|
|
|
else if @sposcfg_dscjf = '7'
|
|
|
begin
|
|
|
if (@sitempludsctype <> '1') and (@sitempludsctype <> '2') and (@sitempludsctype <> '9') and (@sitempludsctype <> '') and (@sitempludsctype <> 'b')
|
|
|
begin
|
|
|
fetch next from cur_calcvipjf_item into @sitempageno,@sitemitemno,@sitemplucode,@sitemclscode,@sitemdepcode,@sitembrand,@citempludsc,@citemplutotal,@sitempludsctype,@sdepuppercode1,@sdepuppercode2,@sdepuppercode3,@sdepuppercode4,@sclsuppercode1,@sclsuppercode2,@sclsuppercode3,@sclsuppercode4,@sclsuppercode5
|
|
|
continue
|
|
|
end
|
|
|
end
|
|
|
|
|
|
set @irecordcount = 0
|
|
|
set @ssql = N'select @irecordcount = count(*) from '+@svipdbname+'..t_vippt_rate where grpcode = '''+@sitemplucode+''' and grptype = ''9'''
|
|
|
exec sp_executesql @ssql,N'@irecordcount int output',@irecordcount out
|
|
|
if @@error<>0
|
|
|
begin
|
|
|
set @serrmsg = '判断商品['+@sitemplucode+']是不积分商品出错'
|
|
|
close cur_calcvipjf_item
|
|
|
deallocate cur_calcvipjf_item
|
|
|
return(-1)
|
|
|
end
|
|
|
if isnull(@irecordcount,0) > 0
|
|
|
begin
|
|
|
fetch next from cur_calcvipjf_item into @sitempageno,@sitemitemno,@sitemplucode,@sitemclscode,@sitemdepcode,@sitembrand,@citempludsc,@citemplutotal,@sitempludsctype,@sdepuppercode1,@sdepuppercode2,@sdepuppercode3,@sdepuppercode4,@sclsuppercode1,@sclsuppercode2,@sclsuppercode3,@sclsuppercode4,@sclsuppercode5
|
|
|
continue
|
|
|
end
|
|
|
|
|
|
set @ctmpyxrate = null
|
|
|
set @ssql = N'select @yxrate = yxrate from '+@svipdbname+'..t_vippt_rate where grpcode = '''+@sitemplucode+''' and grptype = ''3'''
|
|
|
exec sp_executesql @ssql,N'@yxrate numeric(19,4) output',@ctmpyxrate out
|
|
|
if @@error<>0
|
|
|
begin
|
|
|
set @serrmsg = '查询商品['+@sitemplucode+']的单品积分方案出错'
|
|
|
close cur_calcvipjf_item
|
|
|
deallocate cur_calcvipjf_item
|
|
|
return(-1)
|
|
|
end
|
|
|
if not @ctmpyxrate is null
|
|
|
begin
|
|
|
set @ctmpflxftotal = @ctmpflxftotal + @citemplutotal
|
|
|
set @ctmpjftotal = round(@citemplutotal * @ctmpyxrate / 100.00, 2)
|
|
|
set @ssql = N' insert into '+@svipdbname + '..t_vippt_item_flow(vipcode,posno,orgcode,sdate,stime,serialno,pageno,itemno,trantype,plucode,barcode,pluname,depcode,clscode,brandcode,jftotal,plutotal)'
|
|
|
+' select '''+@svipcode+''',posno,orgcode,sdate,stime,serialno,pageno,itemno,trantype,plucode,barcode,pluname,depcode,clscode,'''+case when @sitembrand = 'none' then '' else @sitembrand end+''',@jftotal,plutotal'
|
|
|
+' from t_flow_item '
|
|
|
+' where pageno = '''+@sitempageno+''' and itemno = '''+@sitemitemno+''' and plucode = '''+@sitemplucode+''' and sdate = '''+@sdate+''' and stime = '''+@stime+''' and '
|
|
|
+' serialno = '''+@sserialno+''' and posno = '''+@sposno+''' and orgcode = '''+@sorgcode+''' and trantype = '''+@strantype+''''
|
|
|
exec sp_executesql @ssql,N'@jftotal numeric(19,4)',@ctmpjftotal
|
|
|
if @@error<>0
|
|
|
begin
|
|
|
set @serrmsg = '生成商品['+@sitemplucode+']的单品积分流水明细出错'
|
|
|
close cur_calcvipjf_item
|
|
|
deallocate cur_calcvipjf_item
|
|
|
return(-1)
|
|
|
end
|
|
|
end
|
|
|
else
|
|
|
begin
|
|
|
set @ctmpyxrate = null
|
|
|
set @ssql = N' select @yxrate = yxrate from '+@svipdbname+'..t_vippt_rate '
|
|
|
+' where ((grpcode = '''+@sitemclscode+''' or grpcode = '''+ @sclsuppercode1+''' or grpcode = '''+ @sclsuppercode2+''' or grpcode = '''+ @sclsuppercode3+''' or grpcode = '''+ @sclsuppercode4+''' or grpcode = '''+ @sclsuppercode5+''') and grptype = ''1'') or '
|
|
|
+' ((grpcode = '''+@sitemdepcode+''' or grpcode = '''+ @sdepuppercode1+''' or grpcode = '''+ @sdepuppercode2+''' or grpcode = '''+ @sdepuppercode3+''' or grpcode = '''+ @sdepuppercode4+''') and grptype = ''0'') or '
|
|
|
+' (grpcode = '''+@sitembrand+''' and grptype = ''2'')'
|
|
|
exec sp_executesql @ssql,N'@yxrate numeric(19,4) output',@ctmpyxrate out
|
|
|
if @@error<>0
|
|
|
begin
|
|
|
set @serrmsg = '查询商品['+@sitemplucode+']的分组积分方案出错'
|
|
|
close cur_calcvipjf_item
|
|
|
deallocate cur_calcvipjf_item
|
|
|
return(-1)
|
|
|
end
|
|
|
if not @ctmpyxrate is null
|
|
|
begin
|
|
|
set @ctmpflxftotal = @ctmpflxftotal + @citemplutotal
|
|
|
set @ctmpjftotal = round(@citemplutotal * @ctmpyxrate / 100.00, 2)
|
|
|
set @ssql = N' insert into '+@svipdbname + '..t_vippt_item_flow(vipcode,posno,orgcode,sdate,stime,serialno,pageno,itemno,trantype,plucode,barcode,pluname,depcode,clscode,brandcode,jftotal,plutotal)'
|
|
|
+' select '''+@svipcode+''',posno,orgcode,sdate,stime,serialno,pageno,itemno,trantype,plucode,barcode,pluname,depcode,clscode,'''+case when @sitembrand = 'none' then '' else @sitembrand end+''',@jftotal,plutotal'
|
|
|
+' from t_flow_item '
|
|
|
+' where pageno = '''+@sitempageno+''' and itemno = '''+@sitemitemno+''' and plucode = '''+@sitemplucode+''' and sdate = '''+@sdate+''' and stime = '''+@stime+''' and '
|
|
|
+' serialno = '''+@sserialno+''' and posno = '''+@sposno+''' and orgcode = '''+@sorgcode+''' and trantype = '''+@strantype+''''
|
|
|
exec sp_executesql @ssql,N'@jftotal numeric(19,4)',@ctmpjftotal
|
|
|
if @@error<>0
|
|
|
begin
|
|
|
set @serrmsg = '生成商品['+@sitemplucode+']的分组积分流水明细出错'
|
|
|
close cur_calcvipjf_item
|
|
|
deallocate cur_calcvipjf_item
|
|
|
return(-1)
|
|
|
end
|
|
|
end
|
|
|
end
|
|
|
|
|
|
fetch next from cur_calcvipjf_item into @sitempageno,@sitemitemno,@sitemplucode,@sitemclscode,@sitemdepcode,@sitembrand,@citempludsc,@citemplutotal,@sitempludsctype,@sdepuppercode1,@sdepuppercode2,@sdepuppercode3,@sdepuppercode4,@sclsuppercode1,@sclsuppercode2,@sclsuppercode3,@sclsuppercode4,@sclsuppercode5
|
|
|
end
|
|
|
close cur_calcvipjf_item
|
|
|
deallocate cur_calcvipjf_item
|
|
|
if @ctmpflxftotal =0
|
|
|
return(1)
|
|
|
|
|
|
set @cjfaddrate = 0
|
|
|
|
|
|
set @ctmpyxrate = null
|
|
|
set @ssql = N'select @yxrate = yxrate from '+@svipdbname+'..t_vippt_rate where grpcode = ''birthday'' and grptype = ''4'''
|
|
|
exec sp_executesql @ssql,N'@yxrate numeric(19,4) output',@ctmpyxrate out
|
|
|
if @@error<>0
|
|
|
begin
|
|
|
set @serrmsg = '查询会员生日多倍积分数据出错'
|
|
|
return(-1)
|
|
|
end
|
|
|
if not @ctmpyxrate is null
|
|
|
begin
|
|
|
set @svipbirthday = ''
|
|
|
set @ssql = N'select @vipbirthday = nextbirth from '+@svipdbname+'..t_vip where vipcode = '''+@svipcode+''''
|
|
|
exec sp_executesql @ssql,N'@vipbirthday varchar(10) output',@svipbirthday out
|
|
|
if @@error<>0
|
|
|
begin
|
|
|
set @serrmsg = '查询会员生日数据出错'
|
|
|
return(-1)
|
|
|
end
|
|
|
if @svipbirthday = @scurdate
|
|
|
begin
|
|
|
set @cjfaddrate = @ctmpyxrate
|
|
|
end
|
|
|
end
|
|
|
|
|
|
set @ctmpyxrate = 0
|
|
|
set @ssql = N'select top 1 @yxrate = yxrate from '+@svipdbname+'..t_vippt_rate where grptype = ''5'' and '''+@scurdate+''' between bgndate and enddate'
|
|
|
exec sp_executesql @ssql,N'@yxrate numeric(19,4) output',@ctmpyxrate out
|
|
|
if @@error<>0
|
|
|
begin
|
|
|
set @serrmsg = '查询节日多倍积分数据出错'
|
|
|
return(-1)
|
|
|
end
|
|
|
|
|
|
set @ctmpyxrate = isnull(@ctmpyxrate,0)
|
|
|
if @iposcfg_morejfset = '0'
|
|
|
begin
|
|
|
if @cjfaddrate < @ctmpyxrate
|
|
|
set @cjfaddrate = @ctmpyxrate
|
|
|
end
|
|
|
else if @iposcfg_morejfset = '1'
|
|
|
set @cjfaddrate = @cjfaddrate + @ctmpyxrate
|
|
|
else if @iposcfg_morejfset = '2'
|
|
|
begin
|
|
|
if @cjfaddrate = 0
|
|
|
set @cjfaddrate = @ctmpyxrate
|
|
|
else
|
|
|
set @cjfaddrate = @ctmpyxrate * @cjfaddrate / 100.00
|
|
|
end
|
|
|
select @ctrade_total = total from t_flow_total
|
|
|
where serialno = @sserialno and posno = @sposno and orgcode = @sorgcode and sdate = @sdate and stime = @stime and trantype = @strantype
|
|
|
|
|
|
set @ctrade_total = isnull(@ctrade_total,0)
|
|
|
|
|
|
set @cpay_canjftotal = 0
|
|
|
select @cpay_canjftotal = sum(case when a.payflag <> 'w' then a.payamount else 0 end) + sum(case when a.payflag <> 'w' then 0 else a.amount end)
|
|
|
from t_flow_pay a left join t_tend b on a.payflag = b.tendcode
|
|
|
where a.serialno = @sserialno and a.posno = @sposno and a.orgcode = @sorgcode and a.sdate = @sdate and a.stime = @stime and a.trantype = @strantype and
|
|
|
b.canpt = '1'
|
|
|
|
|
|
if @ctrade_total = 0 or @cpay_canjftotal = 0
|
|
|
set @ccanjfpayrate = 0
|
|
|
else
|
|
|
set @ccanjfpayrate = @cpay_canjftotal / @ctrade_total
|
|
|
|
|
|
if @cjfaddrate <> 0
|
|
|
begin
|
|
|
set @ssql = N'update '+@svipdbname + '..t_vippt_item_flow set jftotal = round(jftotal * @jfaddrate / 100.00,2) '
|
|
|
+' where sdate = '''+@sdate+''' and stime = '''+@stime+''' and '
|
|
|
+' serialno = '''+@sserialno+''' and posno = '''+@sposno+''' and orgcode = '''+@sorgcode+''' and trantype = '''+@strantype+''''
|
|
|
exec sp_executesql @ssql,N'@jfaddrate numeric(19,4)',@cjfaddrate
|
|
|
if @@error<>0
|
|
|
begin
|
|
|
set @serrmsg = '根据生日和节日倍数计算多倍积分出错'
|
|
|
return(-1)
|
|
|
end
|
|
|
end
|
|
|
|
|
|
if @cviptypejfaddrate > 0
|
|
|
begin
|
|
|
set @ssql = N'update '+@svipdbname + '..t_vippt_item_flow set jftotal = jftotal + round(jftotal * @jfaddrate / 100.00,2) '
|
|
|
+' where sdate = '''+@sdate+''' and stime = '''+@stime+''' and '
|
|
|
+' serialno = '''+@sserialno+''' and posno = '''+@sposno+''' and orgcode = '''+@sorgcode+''' and trantype = '''+@strantype+''''
|
|
|
exec sp_executesql @ssql,N'@jfaddrate numeric(19,4)',@cviptypejfaddrate
|
|
|
if @@error<>0
|
|
|
begin
|
|
|
set @serrmsg = '根据会员类型顺加率计算多倍积分出错'
|
|
|
return(-1)
|
|
|
end
|
|
|
end
|
|
|
|
|
|
set @ssql = N'update '+@svipdbname + '..t_vippt_item_flow set jftotal = round(jftotal * @jfaddrate,2) '
|
|
|
+' where sdate = '''+@sdate+''' and stime = '''+@stime+''' and '
|
|
|
+' serialno = '''+@sserialno+''' and posno = '''+@sposno+''' and orgcode = '''+@sorgcode+''' and trantype = '''+@strantype+''''
|
|
|
exec sp_executesql @ssql,N'@jfaddrate numeric(19,4)',@ccanjfpayrate
|
|
|
if @@error<>0
|
|
|
begin
|
|
|
set @serrmsg = '根据可积分支付方式占比计算多倍积分出错'
|
|
|
return(-1)
|
|
|
end
|
|
|
|
|
|
set @ssql = N' insert into '+@svipdbname + '..t_vippt_flow(orgcode,posno,sdate,stime,serialno,trantype,vipcode,accdate,total,flxftotal,xfjftotal,succflg,posaccdate)'
|
|
|
+' select orgcode,posno,sdate,stime,serialno,trantype,vipcode,'''',@total,sum(plutotal),sum(jftotal),''0'','''+@scurdate+''' from '+@svipdbname + '..t_vippt_item_flow'
|
|
|
+' where sdate = '''+@sdate+''' and stime = '''+@stime+''' and '
|
|
|
+' serialno = '''+@sserialno+''' and posno = '''+@sposno+''' and orgcode = '''+@sorgcode+''' and trantype = '''+@strantype+''''
|
|
|
+' group by sdate,stime,serialno,posno,orgcode,trantype,vipcode'
|
|
|
exec sp_executesql @ssql,N'@total numeric(19,4)',@ctrade_total
|
|
|
if @@error<>0
|
|
|
begin
|
|
|
set @serrmsg = '根据积分明细汇总生成积分流水出错'
|
|
|
return(-1)
|
|
|
end
|
|
|
|
|
|
if @sjfistrunc = '1'
|
|
|
begin
|
|
|
set @ssql = N' update '+@svipdbname + '..t_vippt_flow set xfjftotal = floor(xfjftotal)'
|
|
|
+' where sdate = '''+@sdate+''' and stime = '''+@stime+''' and '
|
|
|
+' serialno = '''+@sserialno+''' and posno = '''+@sposno+''' and orgcode = '''+@sorgcode+''' and trantype = '''+@strantype+''''
|
|
|
exec sp_executesql @ssql
|
|
|
if @@error<>0
|
|
|
begin
|
|
|
set @serrmsg = '调整积分取整出错'
|
|
|
return(-1)
|
|
|
end
|
|
|
end
|
|
|
return(1)
|
|
|
end
|
|
|
go
|
|
|
|
|
|
if exists (select * from dbo.sysobjects where (id = object_id(N'p_remind_fkc')) and objectproperty(id, N'isprocedure') = 1)
|
|
|
drop procedure p_remind_fkc
|
|
|
go
|
|
|
create procedure p_remind_fkc
|
|
|
(
|
|
|
@orgcode varchar(10),
|
|
|
@sysusercode varchar(6)
|
|
|
)
|
|
|
as
|
|
|
declare @sql varchar(2000)
|
|
|
begin
|
|
|
set @sql='select orgcode 机构编码,(select orgname from t_shop where orgcode=o.orgcode) 机构名称,
|
|
|
g.plucode as 商品编码,g.pluname 商品名称,(ccount+gcount) 库存数量
|
|
|
from t_plu_org o,t_plu g
|
|
|
where o.plucode=g.plucode and (o.ccount+o.gcount)<0 and o.orgcode in (select orgcode from t_user_org where usercode = '''+@sysusercode+''') '
|
|
|
if @orgcode <> '' and @orgcode is not null
|
|
|
set @sql=@sql + ' and o.orgcode=''' + @orgcode + ''''
|
|
|
set @sql=@sql + ' order by o.orgcode,o.plucode'
|
|
|
exec (@sql)
|
|
|
end
|
|
|
go
|
|
|
|
|
|
if exists (select * from dbo.sysobjects where id = object_id(N'p_remind_vip_birthdy') and objectproperty(id, N'isprocedure') = 1)
|
|
|
drop procedure p_remind_vip_birthdy
|
|
|
go
|
|
|
|
|
|
|
|
|
create procedure p_remind_vip_birthdy
|
|
|
(
|
|
|
@vipdbname varchar(20),
|
|
|
@indays int
|
|
|
)
|
|
|
as
|
|
|
declare @sql varchar(8000)
|
|
|
begin
|
|
|
select @sql='
|
|
|
select vipcode 会员编码,vipname 会员姓名,case when birthtype=''0'' then ''公历生日''
|
|
|
when birthtype=''1'' then ''农历生日'' end as 生日类型,birth 档案生日,nextbirth 公历生日,
|
|
|
datediff(day,getdate(), nextbirth) as 距生日还有天数,
|
|
|
addr 通讯地址,tel 固定电话,mobile1 手机号1,mobile2 手机号2
|
|
|
from '+@vipdbname+'..t_vip
|
|
|
where nextbirth<>'''' and nextbirth is not null
|
|
|
and nextbirth>=''1900-01-01''
|
|
|
and isdate(nextbirth)=''1''
|
|
|
and nextbirth like ''[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]''
|
|
|
and datediff(day,getdate(), nextbirth)<='+cast(@indays as varchar)+'
|
|
|
and datediff(day,getdate(), nextbirth)>=0'
|
|
|
exec(@sql)
|
|
|
end
|
|
|
go
|
|
|
|
|
|
if exists (select * from dbo.sysobjects where id = object_id(N'p_remind_kcalarm') and objectproperty(id, N'isprocedure') = 1)
|
|
|
drop procedure p_remind_kcalarm
|
|
|
go
|
|
|
create procedure [dbo].[p_remind_kcalarm]
|
|
|
(
|
|
|
@sysorgcode varchar(10),
|
|
|
@sysusercode varchar(6)
|
|
|
)
|
|
|
as
|
|
|
begin
|
|
|
declare @sql varchar(8000)
|
|
|
select @sql='
|
|
|
select o.plucode as 商品编码,g.pluname as 商品名称,o.orgcode as 机构编码,s.orgname as 机构名称,
|
|
|
g.topstock as 库存上限,g.lowstock as 库存下限,(o.gcount + o.ccount) as 当前库存数量
|
|
|
from t_plu_org o left join t_plu g on o.plucode = g.plucode
|
|
|
left join t_shop s on o.orgcode = s.orgcode
|
|
|
left join t_dept d on g.depcode = d.depcode,t_sys_right_dept
|
|
|
where 1=1 and (g.plutype<>''3'' and o.mngstock=''1'') and ((((o.gcount+o.ccount)>=o.topstock)and(o.topstock<>0))or(((o.gcount+o.ccount)<=o.lowstock)and(o.lowstock<>0)))
|
|
|
and o.orgcode in (select orgcode from t_user_org where usercode = '''+@sysusercode+''')
|
|
|
and o.orgcode = '''+@sysorgcode+'''
|
|
|
and (d.uppercode1=t_sys_right_dept.depcode or d.uppercode2=t_sys_right_dept.depcode
|
|
|
or d.uppercode3=t_sys_right_dept.depcode or d.uppercode4=t_sys_right_dept.depcode
|
|
|
or d.depcode=t_sys_right_dept.depcode) and t_sys_right_dept.usercode='''+@sysusercode+'''
|
|
|
order by g.depcode,o.plucode '
|
|
|
exec(@sql)
|
|
|
end
|
|
|
go
|
|
|
|
|
|
if exists (select * from dbo.sysobjects where id = object_id(N'p_remind_accept_unrz') and objectproperty(id, N'isprocedure') = 1)
|
|
|
drop procedure p_remind_accept_unrz
|
|
|
go
|
|
|
create procedure p_remind_accept_unrz
|
|
|
(
|
|
|
@sysusercode varchar(6)
|
|
|
)
|
|
|
as
|
|
|
begin
|
|
|
select orgcode as 机构,billno as 验收单号,bizdate as 验收日期,zdrname as 制单人姓名 from t_accept_head
|
|
|
where (rzdate='' or rzdate is null) and orgcode in (select orgcode from t_user_org where usercode = @sysusercode)
|
|
|
end
|
|
|
go
|
|
|
|
|
|
if exists (select * from dbo.sysobjects where id = object_id(N'p_remind_outofdate_order') and objectproperty(id, N'isprocedure') = 1)
|
|
|
drop procedure p_remind_outofdate_order
|
|
|
go
|
|
|
create procedure p_remind_outofdate_order
|
|
|
(
|
|
|
@sysusercode varchar(6)
|
|
|
)
|
|
|
as
|
|
|
begin
|
|
|
select supcode 供应商编号,supname 供应商名称,billno 单据号,validdate 订单有效期,datediff(day,validdate,getdate()) 过期天数,
|
|
|
'执行中' 订单状态,zdrname 业务员,username 操作员 from t_order_head
|
|
|
where state='1' and billtype='0' and isnull(validdate,'') <> '' and datediff(day,getdate(),validdate)<=1 and
|
|
|
orgcode in (select orgcode from t_user_org where usercode = @sysusercode)
|
|
|
end
|
|
|
go
|
|
|
|
|
|
if exists (select * from dbo.sysobjects where id = object_id(N'p_remind_today_yfk') and objectproperty(id, N'isprocedure') = 1)
|
|
|
drop procedure p_remind_today_yfk
|
|
|
go
|
|
|
create procedure p_remind_today_yfk
|
|
|
(
|
|
|
@sysusercode varchar(6)
|
|
|
)
|
|
|
as
|
|
|
begin
|
|
|
select j.supcode 供应商编号,v.supname 供应商名称,billno 单据号,paydate 应付日期,
|
|
|
cost 应付金额,isnull(jscost,0) 已收金额,
|
|
|
cost-isnull(jscost,0)-isnull(zrcost,0) 未付金额
|
|
|
from t_pay_bill j left join t_supplier v on j.supcode = v.supcode
|
|
|
where isfinished <> '1' and isnull(paydate,'') <> '' and datediff(day,getdate(),paydate)<=0 and
|
|
|
j.orgcode in (select orgcode from t_user_org where usercode = @sysusercode)
|
|
|
end
|
|
|
go
|
|
|
|
|
|
if exists (select * from dbo.sysobjects where id = object_id(N'p_remind_today_ysk') and objectproperty(id, N'isprocedure') = 1)
|
|
|
drop procedure p_remind_today_ysk
|
|
|
go
|
|
|
create procedure p_remind_today_ysk
|
|
|
(
|
|
|
@sysusercode varchar(6)
|
|
|
)
|
|
|
as
|
|
|
begin
|
|
|
select custcode 客户编号,custname 客户名称,billno 单据号,paydate 应收日期,
|
|
|
pftotal-isnull(zrtotal,0) 应收金额,isnull(jstotal,0) 已收金额,
|
|
|
pftotal-isnull(zrtotal,0)-isnull(jstotal,0) 未收金额,zdrname 业务员
|
|
|
from t_whsale_head
|
|
|
where isfinished <> '1' and datediff(day,getdate(),paydate)<=0 and isnull(rzdate,'') <> '' and
|
|
|
orgcode in (select orgcode from t_user_org where usercode = @sysusercode)
|
|
|
end
|
|
|
go
|
|
|
|
|
|
if exists (select * from dbo.sysobjects where id = object_id(N'p_remind_newplu') and objectproperty(id, N'isprocedure') = 1)
|
|
|
drop procedure p_remind_newplu
|
|
|
go
|
|
|
create procedure p_remind_newplu
|
|
|
(
|
|
|
@sysusercode varchar(6)
|
|
|
)
|
|
|
as
|
|
|
begin
|
|
|
select o.orgcode 机构编号,s.orgname 机构名称,g.plucode 商品编码,g.pluname 商品名称,spec 规格,o.jprice 进价,o.price 售价,o.yjdate 引进日期,
|
|
|
dms 日均销量,gcount+ccount 现有库存,
|
|
|
进货数量=(select sum(isnull(d.counts,0)) counts
|
|
|
from t_accept_head f join t_accept_body d on f.billno=d.billno
|
|
|
where isnull(f.rzdate,'') <> '' and f.orgcode=o.orgcode and d.plucode=o.plucode )
|
|
|
from t_plu g join t_plu_org o on g.plucode = o.plucode left join t_shop s on o.orgcode=s.orgcode
|
|
|
where g.plustatus = '' and g.plutype<>'3' and o.orgcode in (select orgcode from t_user_org where usercode = @sysusercode)
|
|
|
order by o.orgcode,g.plucode
|
|
|
end
|
|
|
go
|
|
|
|
|
|
if exists (select * from dbo.sysobjects where id = object_id(N'p_remind_outofdate_ec') and objectproperty(id, N'isprocedure') = 1)
|
|
|
drop procedure p_remind_outofdate_ec
|
|
|
go
|
|
|
create procedure p_remind_outofdate_ec
|
|
|
(
|
|
|
@vipdbname varchar(30),
|
|
|
@days int,
|
|
|
@sysusercode varchar(6)
|
|
|
)
|
|
|
as
|
|
|
begin
|
|
|
declare @sql varchar(8000)
|
|
|
select @sql='
|
|
|
select billno 单据号,billname 活动方案名称,bgndate 开始日期,enddate 截至日期,orgcode 发行机构编码,orgname 发行机构名称,
|
|
|
datediff(day,convert(char(10),getdate(),120), enddate) as 距过期还有天数
|
|
|
from '+@vipdbname+'..t_vipec_head h
|
|
|
where rzdate is not null and rzdate <> '''' and orgcode in (select orgcode from t_user_org where usercode = '''+@sysusercode+''')
|
|
|
and datediff(day,convert(char(10),getdate(),120), enddate)<=' + cast(@days as varchar) + '
|
|
|
and datediff(day,convert(char(10),getdate(),120), enddate)>=0 '
|
|
|
exec(@sql)
|
|
|
end
|
|
|
go
|
|
|
|
|
|
if exists(select * from sysobjects where name ='p_remind_adjust_plan' and xtype='p')
|
|
|
drop procedure p_remind_adjust_plan
|
|
|
go
|
|
|
create procedure p_remind_adjust_plan
|
|
|
(
|
|
|
@sysusercode varchar(6)
|
|
|
)
|
|
|
as
|
|
|
begin
|
|
|
select '售价调整单【' + a.billno + '】将于【' + a.sxdate + ' ' + a.sxtime + '】生效,请及时打印标价签和调整商品进价。' as 计划调价提醒,
|
|
|
billno as 单据号
|
|
|
from t_adjprice_head a
|
|
|
where a.isplan='1' and a.rzdate is not null and a.rzdate<>'' and isnull(exectime,'')=''
|
|
|
and (sxdate + ' ' + sxtime > convert(varchar(20),getdate(),120)) and orgcode in (select orgcode from t_user_org where usercode = @sysusercode)
|
|
|
order by a.orgcode,a.sxdate,a.sxtime
|
|
|
end
|
|
|
go
|
|
|
|
|
|
if exists(select * from sysobjects where name ='p_remind_adjust_plan_noexec' and xtype='p')
|
|
|
drop procedure p_remind_adjust_plan_noexec
|
|
|
go
|
|
|
create procedure p_remind_adjust_plan_noexec
|
|
|
(
|
|
|
@sysusercode varchar(6)
|
|
|
)
|
|
|
as
|
|
|
begin
|
|
|
select '售价调整单【' + a.billno + '】已过期但未执行新价格,请使用【计划调价立即生效】的功能进行调价。' as 计划调价未执行提醒,
|
|
|
billno as 单据号
|
|
|
from t_adjprice_head a
|
|
|
where a.isplan='1' and a.rzdate is not null and a.rzdate<>'' and isnull(exectime,'')=''
|
|
|
and (sxdate + ' ' + sxtime < convert(varchar(20),getdate(),120)) and orgcode in (select orgcode from t_user_org where usercode = @sysusercode)
|
|
|
order by a.orgcode,a.sxdate,a.sxtime
|
|
|
end
|
|
|
go
|
|
|
|
|
|
if exists(select * from sysobjects where name ='p_remind_ask_fnotify' and xtype='p')
|
|
|
drop procedure p_remind_ask_fnotify
|
|
|
go
|
|
|
create procedure p_remind_ask_fnotify
|
|
|
(
|
|
|
@sysusercode varchar(6)
|
|
|
)
|
|
|
as
|
|
|
begin
|
|
|
select distinct f.billno 要货单号,f.orgcode 机构编码,s.orgname 机构名称
|
|
|
from t_ask_head f left join t_shop s on f.orgcode=s.orgcode,t_ask_body d
|
|
|
left join t_plu on d.plucode=t_plu.plucode left join t_dept on t_dept.depcode=t_plu.depcode
|
|
|
left join t_sys_right_dept on t_dept.uppercode1=t_sys_right_dept.depcode
|
|
|
or t_dept.uppercode2=t_sys_right_dept.depcode
|
|
|
or t_dept.uppercode3=t_sys_right_dept.depcode
|
|
|
or t_dept.uppercode4=t_sys_right_dept.depcode
|
|
|
or t_dept.depcode=t_sys_right_dept.depcode
|
|
|
where f.billno = d.billno and f.rzdate <> '' and f.state <> '1'
|
|
|
and f.rzdate = convert(varchar(10),getdate(),120)
|
|
|
and isnull(d.cgdate,'') = '' and isnull(d.psdate,'') = ''
|
|
|
and t_sys_right_dept.usercode = @sysusercode
|
|
|
order by 2,1
|
|
|
end
|
|
|
go
|
|
|
|
|
|
if exists(select * from sysobjects where name ='p_remind_goods_days_alarm' and xtype='p')
|
|
|
drop procedure p_remind_goods_days_alarm
|
|
|
go
|
|
|
|
|
|
create procedure p_remind_goods_days_alarm
|
|
|
(
|
|
|
@sysver varchar(1),
|
|
|
@sysusercode varchar(6),
|
|
|
@sysorgcode varchar(10),
|
|
|
@mindays int,
|
|
|
@maxdays int,
|
|
|
@predays int
|
|
|
)
|
|
|
as
|
|
|
declare @tmptable table
|
|
|
(billno varchar(20),plucode varchar(20),serialno int,bizdate varchar(10),
|
|
|
orgcode varchar(10),orgname varchar(30) null,supname varchar(100) null,
|
|
|
supcode varchar(15),orderno varchar(20),sqauremode varchar(1),paydate varchar(10),
|
|
|
barcode varchar(20),pluname varchar(40),cargono varchar(20),depcode varchar(10) null,depname varchar(16) null,
|
|
|
spec varchar(40), unit varchar(10),keepdays integer null,
|
|
|
jprice numeric(19,4) null,netjprice numeric(19,4) null,newjprice numeric(19,4) null,price numeric(19,4) null,vipprice numeric(19,4) null,jtaxrate integer null,
|
|
|
productdate varchar(10),qualitydate varchar(10),diffdays integer,counts numeric(19,4) null,xccount numeric(19,4) null,
|
|
|
primary key(billno,plucode,orgcode,serialno))
|
|
|
declare @acceptno varchar(20)
|
|
|
declare @plucode varchar(20)
|
|
|
declare @orgcode varchar(10)
|
|
|
declare @serialno int
|
|
|
declare @kccount numeric(19,4)
|
|
|
declare @counts numeric(19,4)
|
|
|
declare @qualitydate varchar(10)
|
|
|
declare @tmpplucode varchar(20)
|
|
|
declare @tmporgcode varchar(10)
|
|
|
declare @tmpkccount numeric(19,4)
|
|
|
declare @tmpxccount numeric(19,4)
|
|
|
begin
|
|
|
if @mindays > @maxdays
|
|
|
return -1
|
|
|
if @predays > @mindays
|
|
|
return -1
|
|
|
|
|
|
set @tmpkccount = 0
|
|
|
set @tmpxccount = 0
|
|
|
set @tmpplucode = ''
|
|
|
set @tmporgcode = ''
|
|
|
|
|
|
declare cur_loop cursor for
|
|
|
select ad.billno,o.plucode,o.orgcode,ad.serialno,o.ccount+o.gcount as kccount,ad.counts as counts,isnull(ad.qualitydate,'') as qualitydate
|
|
|
from t_plu_org o left join t_plu g on o.plucode = g.plucode left join t_dept d on g.depcode = d.depcode
|
|
|
left join t_shop s on o.orgcode = s.orgcode left join t_accept_body ad on ad.plucode = o.plucode
|
|
|
left join t_accept_head af on af.orgcode = o.orgcode and af.billno = ad.billno,t_sys_right_dept
|
|
|
where ((o.orgcode=@sysorgcode and @sysver='0') or (o.orgcode=@sysorgcode and isdbdeploy='1' and @sysver='1'))
|
|
|
and g.keepdays<>0 and isright='1' and o.gcount+o.ccount>0 and af.rzdate is not null and af.rzdate<>''
|
|
|
and datediff(day,af.bizdate,convert(varchar(10),getdate(),120))<=730
|
|
|
and o.orgcode in (select orgcode from t_user_org where usercode=@sysusercode)
|
|
|
and (d.uppercode1=t_sys_right_dept.depcode or d.uppercode2=t_sys_right_dept.depcode
|
|
|
or d.uppercode3=t_sys_right_dept.depcode or d.uppercode4=t_sys_right_dept.depcode
|
|
|
or d.depcode=t_sys_right_dept.depcode) and t_sys_right_dept.usercode=@sysusercode
|
|
|
order by o.plucode,af.bizdate desc,af.billno desc
|
|
|
|
|
|
open cur_loop
|
|
|
fetch next from cur_loop into @acceptno,@plucode,@orgcode,@serialno,@kccount,@counts,@qualitydate
|
|
|
while @@fetch_status = 0
|
|
|
begin
|
|
|
if (@tmpplucode <> @plucode) or (@tmporgcode <> @orgcode)
|
|
|
begin
|
|
|
set @tmpplucode = @plucode
|
|
|
set @tmporgcode = @orgcode
|
|
|
set @tmpkccount = @kccount
|
|
|
end
|
|
|
|
|
|
if (@tmpkccount <= @counts) and (@tmpkccount > 0)
|
|
|
begin
|
|
|
set @tmpxccount = @tmpkccount
|
|
|
end
|
|
|
else
|
|
|
begin
|
|
|
if @tmpkccount > @counts
|
|
|
set @tmpxccount = @counts
|
|
|
else
|
|
|
set @tmpxccount = 0
|
|
|
end
|
|
|
|
|
|
set @tmpkccount = @tmpkccount - @tmpxccount
|
|
|
if (@tmpxccount = 0)
|
|
|
begin
|
|
|
|
|
|
fetch next from cur_loop into @acceptno,@plucode,@orgcode,@serialno,@kccount,@counts,@qualitydate
|
|
|
while ((@@fetch_status = 0) and (@tmpplucode = @plucode) and (@tmporgcode = @orgcode))
|
|
|
begin
|
|
|
fetch next from cur_loop into @acceptno,@plucode,@orgcode,@serialno,@kccount,@counts,@qualitydate
|
|
|
end
|
|
|
continue
|
|
|
end
|
|
|
else
|
|
|
begin
|
|
|
if @qualitydate <> ''
|
|
|
begin
|
|
|
insert into @tmptable(billno,bizdate,orgcode,orgname,supcode ,
|
|
|
supname,orderno,sqauremode,paydate,plucode,
|
|
|
serialno,barcode,pluname,cargono,spec,unit,
|
|
|
jprice,netjprice,newjprice,price,vipprice,jtaxrate,keepdays, productdate,qualitydate,
|
|
|
diffdays,counts,xccount,depcode,depname)
|
|
|
select @acceptno,af.bizdate as bizdate,@orgcode,s.orgname as orgname,af.supcode as supcode ,
|
|
|
af.supname as supname,af.orderno as orderno,af.sqauremode as sqauremode,af.paydate as paydate,@plucode,
|
|
|
ad.serialno as serialno,g.barcode as barcode,g.pluname as pluname,g.cargono as cargono,g.spec as spec,g.unit as unit,
|
|
|
ad.jprice as jprice,ad.netjprice as netjprice,o.jprice as newjprice,o.price as price,o.vipprice,g.jtaxrate as jtaxrate,
|
|
|
g.keepdays as keepdays,ad.productdate as productdate,ad.qualitydate as qualitydate,
|
|
|
datediff(day,getdate(),isnull(ad.qualitydate,'')) as diffdays,ad.counts as counts,@tmpxccount,g.depcode,d.depname
|
|
|
from t_plu_org o left join t_plu g on o.plucode = g.plucode left join t_dept d on g.depcode = d.depcode
|
|
|
left join t_shop s on o.orgcode = s.orgcode left join t_accept_body ad on ad.plucode = o.plucode
|
|
|
left join t_accept_head af on af.orgcode = o.orgcode and af.billno = ad.billno,t_sys_right_dept
|
|
|
where ((o.orgcode=@sysorgcode and @sysver='0') or (o.orgcode=@sysorgcode and isdbdeploy='1' and @sysver='1'))
|
|
|
and g.keepdays<>0 and isright='1' and o.gcount+o.ccount>0 and af.rzdate is not null and af.rzdate<>''
|
|
|
and datediff(day,af.bizdate,convert(varchar(10),getdate(),120))<=730
|
|
|
and o.orgcode in (select orgcode from t_user_org where usercode=@sysusercode)
|
|
|
and (d.uppercode1=t_sys_right_dept.depcode or d.uppercode2=t_sys_right_dept.depcode
|
|
|
or d.uppercode3=t_sys_right_dept.depcode or d.uppercode4=t_sys_right_dept.depcode
|
|
|
or d.depcode=t_sys_right_dept.depcode) and t_sys_right_dept.usercode=@sysusercode
|
|
|
and af.billno=@acceptno and o.plucode=@plucode and o.orgcode=@orgcode and ad.serialno=@serialno
|
|
|
end
|
|
|
end
|
|
|
|
|
|
fetch next from cur_loop into @acceptno,@plucode,@orgcode,@serialno,@kccount,@counts,@qualitydate
|
|
|
end
|
|
|
close cur_loop
|
|
|
deallocate cur_loop
|
|
|
|
|
|
select b.plucode 商品编码,b.pluname 商品名称,b.barcode 条码,b.cargono 货号,b.billno 验收单号,
|
|
|
b.bizdate 验收日期,b.orgcode [机构|编码],b.orgname [机构|名称],
|
|
|
b.supcode [供应商|编码],b.supname [供应商|名称],b.orderno 订货单号,
|
|
|
case b.sqauremode when '0' then '货到付款' when '1' then '延期付款' when '2' then '其它方式' end 结算方式,
|
|
|
b.paydate 付款日期,b.spec 规格,b.unit 计量单位,b.jprice [进价|含税],
|
|
|
b.netjprice [进价|无税],b.price 零售价,b.jtaxrate 进项税率,b.keepdays 保质期,
|
|
|
b.productdate 生产日期,b.qualitydate 到期日期,b.diffdays 有效天数,b.counts 进货数量,b.xccount 现存数量
|
|
|
from t_plu g,@tmptable b
|
|
|
where g.plucode=b.plucode and g.plustatus <> '2' and g.plustatus <> '9'
|
|
|
and b.keepdays>=@mindays and b.keepdays<@maxdays
|
|
|
and datediff(day,convert(varchar(10),getdate(),120),b.qualitydate)<=@predays
|
|
|
end
|
|
|
go
|
|
|
|
|
|
if exists(select * from sysobjects where name ='p_remind_ps_afnotify' and xtype='p')
|
|
|
drop procedure p_remind_ps_afnotify
|
|
|
go
|
|
|
create procedure p_remind_ps_afnotify
|
|
|
(
|
|
|
@sysusercode varchar(6)
|
|
|
)
|
|
|
as
|
|
|
begin
|
|
|
select distinct h.billno 配送验收单号,h.orgcode 机构编码,
|
|
|
(select orgname from t_shop where orgcode=h.orgcode) 机构名称,
|
|
|
(case when isnull(h.qrdate,'') = '' then '未确认' else '已确认' end) 确认状态,
|
|
|
h.cost 合计含税进价
|
|
|
from t_accept_head h left join t_accept_body b
|
|
|
on h.billno=b.billno
|
|
|
where billtype='3'
|
|
|
and exists(select orgcode from t_user_org where orgcode=h.orgcode and usercode=@sysusercode)
|
|
|
and exists(select d.depcode from t_dept d,t_sys_right_dept x where b.depcode=d.depcode and (d.uppercode1=x.depcode
|
|
|
or d.uppercode2=x.depcode or d.uppercode3=x.depcode or d.uppercode4=x.depcode or d.depcode=x.depcode) and x.usercode=@sysusercode)
|
|
|
and (h.lrdate = convert(varchar(10),getdate(),120) or h.rzdate = convert(varchar(10),getdate(),120))
|
|
|
order by 2,4,1
|
|
|
end
|
|
|
go
|
|
|
|
|
|
if exists(select * from sysobjects where name ='p_getbatchstk_data' and xtype='p')
|
|
|
drop procedure p_getbatchstk_data
|
|
|
go
|
|
|
create procedure p_getbatchstk_data
|
|
|
@dectype varchar(max),
|
|
|
@orgcode varchar(max),
|
|
|
@depcode varchar(max),
|
|
|
@place varchar(max),
|
|
|
@plucode varchar(max),
|
|
|
@itemcnt numeric(19,4),
|
|
|
@batchno varchar(max),
|
|
|
@srcbatchno varchar(max),
|
|
|
@plutype varchar(max),
|
|
|
@contrno varchar(max),
|
|
|
@supcode varchar(max),
|
|
|
@jymode varchar(max),
|
|
|
@decmode varchar(max),
|
|
|
@pi_result int output,
|
|
|
@ps_message varchar(max) output
|
|
|
as
|
|
|
begin
|
|
|
begin try
|
|
|
set @pi_result = null
|
|
|
set @ps_message = null
|
|
|
set @pi_result = -1
|
|
|
/*=================取得普通库存冲减批次数据=================*/
|
|
|
if @dectype in ('deckc','deckcxs')
|
|
|
begin
|
|
|
if @decmode = '0' --先进先出方式
|
|
|
select
|
|
|
a.depcode,
|
|
|
a.srcbatchno,
|
|
|
a.batchno,
|
|
|
a.stkcount,
|
|
|
a.jprice,
|
|
|
a.netjprice,
|
|
|
a.cost,
|
|
|
a.netcost,
|
|
|
a.stkcount as kycount,
|
|
|
a.contrno,
|
|
|
a.supcode,
|
|
|
a.jymode,
|
|
|
a.plutype,
|
|
|
a.itemcnt
|
|
|
from t_plu_batch a
|
|
|
with ( updlock )
|
|
|
where
|
|
|
a.orgcode = @orgcode and
|
|
|
a.depcode = @depcode and
|
|
|
--a.place = @place and
|
|
|
a.plucode = @plucode and
|
|
|
(@batchno = '*' or (@batchno <> '*' and a.batchno = @batchno)) and
|
|
|
a.plutype = @plutype and
|
|
|
a.stkcount > 0
|
|
|
order by a.jhdate asc
|
|
|
else
|
|
|
begin
|
|
|
--后进先出 暂不支持
|
|
|
set @ps_message = '暂不支持后进先出方式冲减库存'
|
|
|
set @pi_result = -1
|
|
|
return
|
|
|
end
|
|
|
end
|
|
|
|
|
|
/*=================取得退货冲减批次数据=================*/
|
|
|
if @dectype = 'deckcth'
|
|
|
begin
|
|
|
if @decmode = '0' --先进先出方式
|
|
|
select
|
|
|
a.depcode,
|
|
|
a.srcbatchno,
|
|
|
a.batchno,
|
|
|
a.stkcount,
|
|
|
a.jprice,
|
|
|
a.netjprice,
|
|
|
a.cost,
|
|
|
a.netcost,
|
|
|
a.stkcount as kycount,
|
|
|
a.contrno,
|
|
|
a.supcode,
|
|
|
a.jymode,
|
|
|
a.plutype,
|
|
|
a.itemcnt
|
|
|
from t_plu_batch a
|
|
|
with ( updlock )
|
|
|
where
|
|
|
a.orgcode = @orgcode and
|
|
|
a.depcode = @depcode and
|
|
|
a.supcode = @supcode and
|
|
|
--a.place = @place and
|
|
|
a.plucode = @plucode and
|
|
|
(@batchno = '*' or (@batchno <> '*' and a.batchno = @batchno)) and
|
|
|
a.plutype = @plutype and
|
|
|
a.stkcount > 0
|
|
|
order by a.jhdate asc
|
|
|
else
|
|
|
begin
|
|
|
--后进先出 暂不支持
|
|
|
set @ps_message = '暂不支持后进先出方式冲减库存'
|
|
|
set @pi_result = -1
|
|
|
return
|
|
|
end
|
|
|
end
|
|
|
|
|
|
set @pi_result = 1
|
|
|
|
|
|
end try
|
|
|
begin catch
|
|
|
declare
|
|
|
@errornumber int
|
|
|
set @errornumber = error_number()
|
|
|
declare
|
|
|
@errormessage nvarchar(4000)
|
|
|
set @errormessage = error_message()
|
|
|
begin
|
|
|
begin
|
|
|
set @pi_result = -1
|
|
|
set @ps_message = '批次库存数据获取失败' + ':' + isnull(
|
|
|
@errormessage, '')
|
|
|
return
|
|
|
end
|
|
|
end
|
|
|
end catch
|
|
|
end
|
|
|
go
|
|
|
|
|
|
if exists(select * from sysobjects where name ='p_getbillstkdec_data' and xtype='p')
|
|
|
drop procedure p_getbillstkdec_data
|
|
|
go
|
|
|
create procedure p_getbillstkdec_data
|
|
|
@billno varchar(max),
|
|
|
@ywtype varchar(max),
|
|
|
@orgcode varchar(max) output,
|
|
|
@place varchar(max) output,
|
|
|
@contrno varchar(max) output,
|
|
|
@supcode varchar(max) output,
|
|
|
@jymode varchar(max) output,
|
|
|
@dectype varchar(max) output,
|
|
|
@uppctype varchar(max) /*如何更新批次的累计(0:不更新1:进货2:退货3:销售4:其他)*/ output,
|
|
|
@tablename varchar(max) output,
|
|
|
@pi_result int output,
|
|
|
@ps_message varchar(max) output
|
|
|
as
|
|
|
declare @shop_orgtype varchar(1)
|
|
|
declare @shop_isdbdeploy varchar(1)
|
|
|
begin
|
|
|
begin try
|
|
|
set @orgcode = ''
|
|
|
set @place = ''
|
|
|
set @contrno = ''
|
|
|
set @supcode = ''
|
|
|
set @jymode = ''
|
|
|
set @dectype = ''
|
|
|
set @uppctype = ''
|
|
|
set @tablename = ''
|
|
|
set @pi_result = -1
|
|
|
set @ps_message = ''
|
|
|
|
|
|
if @ywtype not in (
|
|
|
'ps','th','rjyw','rjxs')
|
|
|
begin
|
|
|
set @ps_message = '业务类型:“' + isnull(@ywtype, '') + '”无效'
|
|
|
return
|
|
|
end
|
|
|
|
|
|
set @uppctype = '0'
|
|
|
set @dectype = 'deckc'
|
|
|
|
|
|
if @ywtype in ('ps')
|
|
|
begin
|
|
|
if @ywtype = 'ps'
|
|
|
set @ps_message = '——配送单'
|
|
|
|
|
|
select @orgcode = orgcode, @supcode = orgcode, @place = '1'
|
|
|
from t_dist_head
|
|
|
where billno = @billno
|
|
|
|
|
|
set @tablename = 't_dist_head'
|
|
|
|
|
|
select serialno,depcode,zpcount,'*' as batchno,'0' as plutype,plucode,pluname,spec,unit,itemcnt
|
|
|
from t_dist_body
|
|
|
where billno = @billno
|
|
|
end
|
|
|
|
|
|
if @ywtype = 'th'
|
|
|
begin
|
|
|
set @uppctype = '2'
|
|
|
set @dectype = 'deckcth'
|
|
|
|
|
|
select @orgcode = orgcode,@supcode = supcode,
|
|
|
@ywtype = case billtype when '0' then 'th' when '2' then 'zth' when '3' then 'pth' end, @place = '1'
|
|
|
from t_return_head
|
|
|
where billno = @billno
|
|
|
|
|
|
select @shop_orgtype=orgtype,
|
|
|
@shop_isdbdeploy=isdbdeploy
|
|
|
from t_shop where orgcode = @orgcode
|
|
|
|
|
|
if @ywtype = 'th'
|
|
|
begin
|
|
|
if @shop_orgtype='2'
|
|
|
set @place = '1'
|
|
|
else
|
|
|
set @place = '0'
|
|
|
set @ps_message = '——采购退货单'
|
|
|
end
|
|
|
else if @ywtype = 'zth'
|
|
|
begin
|
|
|
set @place = '0'
|
|
|
set @ps_message = '——直送退货单'
|
|
|
end
|
|
|
else if @ywtype = 'pth'
|
|
|
begin
|
|
|
set @place = '0'
|
|
|
set @ps_message = '——配送退货单'
|
|
|
end
|
|
|
|
|
|
set @tablename = 't_return_head'
|
|
|
|
|
|
select serialno,depcode,counts,'*' as batchno,'0' as plutype,plucode,pluname,spec,unit,itemcnt
|
|
|
from t_return_body
|
|
|
where billno = @billno
|
|
|
end
|
|
|
|
|
|
if @ywtype = 'rjyw'
|
|
|
begin
|
|
|
set @ps_message = '——日结批次业务'
|
|
|
set @uppctype = '4'
|
|
|
set @dectype = 'deckc'
|
|
|
set @supcode = '*'
|
|
|
|
|
|
select @orgcode = orgcode, @place = place
|
|
|
from ##dayover_plubatch_head
|
|
|
where billno = @billno
|
|
|
|
|
|
set @tablename = '##dayover_plubatch_head'
|
|
|
|
|
|
select serialno,depcode,proccount,batchno,plutype,plucode,pluname,spec,unit,itemcnt
|
|
|
from ##dayover_plubatch_body
|
|
|
where billno = @billno
|
|
|
end
|
|
|
|
|
|
if @ywtype = 'rjxs'
|
|
|
begin
|
|
|
set @ps_message = '——日结批次销售'
|
|
|
set @uppctype = '3'
|
|
|
set @dectype = 'deckcxs'
|
|
|
set @supcode = '*'
|
|
|
|
|
|
select @orgcode = orgcode, @place = place
|
|
|
from ##dayover_plubatch_head
|
|
|
where billno = @billno
|
|
|
|
|
|
set @tablename = '##dayover_plubatch_head'
|
|
|
|
|
|
select serialno,depcode,proccount,batchno,plutype,plucode,pluname,spec,unit,itemcnt
|
|
|
from ##dayover_plubatch_body
|
|
|
where billno = @billno
|
|
|
end
|
|
|
|
|
|
set @pi_result = 1
|
|
|
end try
|
|
|
begin catch
|
|
|
declare
|
|
|
@errornumber int
|
|
|
set @errornumber = error_number()
|
|
|
declare
|
|
|
@errormessage nvarchar(4000)
|
|
|
set @errormessage = error_message()
|
|
|
begin
|
|
|
begin
|
|
|
set @pi_result = -1
|
|
|
set @ps_message = '获取冲减库存单据数据' + @ps_message + ':' + isnull(
|
|
|
@errormessage, '')
|
|
|
return
|
|
|
end
|
|
|
end
|
|
|
end catch
|
|
|
end
|
|
|
go
|
|
|
|
|
|
if exists(select * from sysobjects where name ='p_decbatchstk' and xtype='p')
|
|
|
drop procedure p_decbatchstk
|
|
|
go
|
|
|
create procedure p_decbatchstk
|
|
|
@billno varchar(max),
|
|
|
@ywtype varchar(max),
|
|
|
@usercode varchar(max),
|
|
|
@userrname varchar(max),
|
|
|
@procdate datetime,
|
|
|
@pi_result int output,
|
|
|
@ps_message varchar(max) output
|
|
|
as
|
|
|
begin
|
|
|
declare
|
|
|
@cur_bill cursor,
|
|
|
@cur_stock cursor
|
|
|
begin try
|
|
|
set @pi_result = null
|
|
|
set @ps_message = null
|
|
|
|
|
|
declare
|
|
|
@serialno numeric(19, 0),
|
|
|
@vs_plucode varchar(20),
|
|
|
@vs_pluname varchar(40),
|
|
|
@vs_spec varchar(40),
|
|
|
@vs_unit varchar(6),
|
|
|
@vf_clcount numeric(19, 4),
|
|
|
@vf_itemcnt numeric(19, 4),
|
|
|
@vs_batchno varchar(40),
|
|
|
@vs_plutype varchar(4),
|
|
|
@vf_jprice numeric(19, 4),
|
|
|
@vf_netjprice numeric(19, 4),
|
|
|
@vf_cost numeric(19, 2),
|
|
|
@vf_netcost numeric(19, 2),
|
|
|
@vs_orgcode varchar(10),
|
|
|
@vs_orgname varchar(100),
|
|
|
@vs_place varchar(10),
|
|
|
@vs_contrno varchar(40),
|
|
|
@vs_supcode varchar(15),
|
|
|
@vs_jymode varchar(1),
|
|
|
@vs_dectype varchar(20),
|
|
|
@vs_uppctype varchar(1),
|
|
|
@vs_tablename varchar(40),
|
|
|
@vf_jtaxrate numeric(19,4)
|
|
|
|
|
|
set @vs_dectype = 'deckc'
|
|
|
|
|
|
declare
|
|
|
@stock_orgcode varchar(10),
|
|
|
@stock_depcode varchar(10),
|
|
|
@stock_place varchar(10),
|
|
|
@stock_plucode varchar(20),
|
|
|
@stock_itemcnt numeric(19, 4),
|
|
|
@stock_batchno varchar(40),
|
|
|
@stock_srcbatchno varchar(40),
|
|
|
@stock_plutype varchar(4),
|
|
|
@stock_contrno varchar(40),
|
|
|
@stock_supcode varchar(15),
|
|
|
@stock_jymode varchar(1),
|
|
|
@stock_kccount numeric(19, 4),
|
|
|
@stock_jprice numeric(19, 4),
|
|
|
@stock_netjprice numeric(19, 4),
|
|
|
@stock_cost numeric(19, 2),
|
|
|
@stock_netcost numeric(19, 2),
|
|
|
@stock_kycount numeric(19, 4)
|
|
|
|
|
|
declare
|
|
|
@tmp_stkcount numeric(19, 4),
|
|
|
@tmp_cost numeric(19, 2),
|
|
|
@tmp_netcost numeric(19, 2),
|
|
|
@vs_ckbillno varchar(20),
|
|
|
@vi_ordnum int,
|
|
|
@vi_kccount numeric(19, 4),
|
|
|
@vi_tmpcount numeric(19, 4),
|
|
|
@vi_cnt integer,
|
|
|
@vs_proctype integer
|
|
|
|
|
|
create table #pc_bill
|
|
|
(serialno numeric (19, 0) not null default ((0)),
|
|
|
depcode varchar (10) null,
|
|
|
pscount numeric (19, 4) not null default ((0)),
|
|
|
batchno varchar (40) not null default ('*'),
|
|
|
plutype varchar (1) default ('0'),
|
|
|
plucode varchar (20) not null,
|
|
|
pluname varchar (40) null,
|
|
|
spec varchar (40) null,
|
|
|
unit varchar (10) null,
|
|
|
itemcnt numeric (19, 4) not null default ((0)))
|
|
|
|
|
|
create table #pc_pckc
|
|
|
(depcode varchar (10) null,
|
|
|
sourcebatchno varchar (40) not null default ('*'),
|
|
|
batchno varchar (40) not null default ('*'),
|
|
|
stkcount numeric (19, 4) not null default ((0)),
|
|
|
jprice numeric (19, 4) not null default ((0)),
|
|
|
netjprice numeric (19, 4) not null default ((0)),
|
|
|
cost numeric (19, 2) not null default ((0)),
|
|
|
netcost numeric (19, 2) not null default ((0)),
|
|
|
kycount numeric (19, 4) not null default ((0)),
|
|
|
contrno varchar (40) null,
|
|
|
supcode varchar (15) not null,
|
|
|
jymode varchar (1) not null default ('0'),
|
|
|
plutype varchar (4) not null default ('0'),
|
|
|
itemcnt numeric (19, 4) not null default ((0)))
|
|
|
|
|
|
set @pi_result = -1
|
|
|
delete from #pc_bill
|
|
|
insert into [#pc_bill]
|
|
|
execute p_getbillstkdec_data
|
|
|
@billno = @billno,
|
|
|
@ywtype = @ywtype,
|
|
|
@orgcode = @vs_orgcode output,
|
|
|
@place = @vs_place output,
|
|
|
@contrno = @vs_contrno output,
|
|
|
@supcode = @vs_supcode output,
|
|
|
@jymode = @vs_jymode output,
|
|
|
@dectype = @vs_dectype output,
|
|
|
@uppctype = @vs_uppctype output,
|
|
|
@tablename = @vs_tablename output,
|
|
|
@pi_result = @pi_result output,
|
|
|
@ps_message = @ps_message output
|
|
|
|
|
|
if @pi_result <> 1
|
|
|
return
|
|
|
|
|
|
set @cur_bill = cursor for
|
|
|
select * from [#pc_bill]
|
|
|
|
|
|
open @cur_bill
|
|
|
|
|
|
set @pi_result = -1
|
|
|
|
|
|
if not cursor_status('variable', N'@cur_bill') > -1
|
|
|
begin
|
|
|
set @ps_message = '——得到单据数据'
|
|
|
return
|
|
|
end
|
|
|
|
|
|
set @stock_orgcode = @vs_orgcode
|
|
|
set @stock_place = @vs_place
|
|
|
set @stock_supcode = @vs_supcode
|
|
|
set @vs_proctype = 1
|
|
|
|
|
|
exec f_get_billno 'pc',@vs_orgcode,'1',@vs_ckbillno output
|
|
|
|
|
|
set @vi_ordnum = 1
|
|
|
|
|
|
while 1 = 1
|
|
|
begin
|
|
|
fetch @cur_bill into @serialno, @stock_depcode, @vf_clcount, @stock_batchno, @stock_plutype, @vs_plucode, @vs_pluname, @vs_spec, @vs_unit, @stock_itemcnt
|
|
|
|
|
|
if @@fetch_status <> 0
|
|
|
break
|
|
|
|
|
|
if isnull(@stock_itemcnt, 0) = 0
|
|
|
set @stock_itemcnt = 1
|
|
|
|
|
|
set @stock_plucode = @vs_plucode
|
|
|
|
|
|
if @vs_dectype in ('deckc','deckcxs')
|
|
|
set @vi_kccount = dbo.f_getbatchstk(@stock_orgcode, @stock_depcode, @stock_place, @stock_plucode, @stock_plutype, '', @stock_batchno)
|
|
|
else if @vs_dectype = 'deckcth'
|
|
|
set @vi_kccount = dbo.f_getbatchstk(@stock_orgcode, @stock_depcode, @stock_place, @stock_plucode, @stock_plutype, @stock_supcode,@stock_batchno)
|
|
|
|
|
|
if @vf_clcount >= 0
|
|
|
begin
|
|
|
--处理数量>0说明是减库存
|
|
|
set @vs_proctype = 1 --出库
|
|
|
set @vi_tmpcount = @vi_kccount - @vf_clcount
|
|
|
if @vi_tmpcount < 0
|
|
|
begin
|
|
|
/**set @ps_message = isnull(@stock_plucode, '') + '-' + isnull(@vs_pluname, '')
|
|
|
set @ps_message = '——商品“' + isnull(@ps_message, '') + '”库存不足,可支配数量“' + isnull(cast(@vi_kccount as varchar(max)), '') + '”'
|
|
|
if cursor_status('variable', n'@cur_bill') > -1
|
|
|
begin
|
|
|
close @cur_bill
|
|
|
deallocate @cur_bill
|
|
|
end
|
|
|
return */
|
|
|
--如果是退货,则需要指定供应商退货,批次处理的原则应该是不能无库存或者库存不足空退
|
|
|
--也不能指定无某个进货价的批次退货,在此只是简单处理数量,不细究成本
|
|
|
select
|
|
|
/*@vs_supcode = case when isnull(o.supcode ,'')='' then g.supcode
|
|
|
when s.orgtype='2' and v1.suptype='9' then g.supcode
|
|
|
else o.supcode end,*/
|
|
|
@vf_jprice = isnull(case o.ojprice when 0 then o.jprice else o.ojprice end,g.jprice),
|
|
|
@vf_netjprice = round(isnull(case o.ojprice when 0 then o.jprice else o.ojprice end,g.jprice)/(1+g.jtaxrate/100.00),4),
|
|
|
@vf_jtaxrate = g.jtaxrate
|
|
|
from t_plu g left join t_plu_org o on g.plucode = o.plucode and o.orgcode = @stock_orgcode
|
|
|
left join t_shop s on s.orgcode = o.orgcode
|
|
|
left join t_supplier v on g.supcode =v.supcode
|
|
|
left join t_supplier v1 on o.supcode =v1.supcode
|
|
|
where g.plucode = @stock_plucode
|
|
|
|
|
|
--处理成自动增加差额批次进货
|
|
|
insert into t_plu_batch(orgcode,depcode,supcode,jymode,contrno,batchtype,billno,serialno,place,
|
|
|
plucode,plutype,batchno,srcbatchno,stkcount,jtaxrate,jprice,netjprice,cost,netcost,punit,itemcnt,
|
|
|
productdate,jhdate,jhcount)
|
|
|
values(@stock_orgcode,@stock_depcode,
|
|
|
case @vs_dectype when 'deckcth' then @stock_supcode else '*' end,
|
|
|
'0','','v',@billno,@serialno,@stock_place,
|
|
|
@stock_plucode,@stock_plutype,dbo.f_getstockpcno(@billno,'1',@vi_ordnum),dbo.f_getstockpcno(@billno,'1',@vi_ordnum),
|
|
|
abs(@vi_tmpcount),@vf_jtaxrate,@vf_jprice,@vf_netjprice,
|
|
|
round(abs(@vi_tmpcount)*@vf_jprice,2),round(abs(@vi_tmpcount)*@vf_netjprice,2),
|
|
|
'',1,null,getdate(),0) --注意累计进货写0
|
|
|
--虚拟进货暂不写库存记账单
|
|
|
end
|
|
|
end
|
|
|
else
|
|
|
begin
|
|
|
--处理数量<0说明是增库存
|
|
|
set @vs_proctype = 0 --入库
|
|
|
--检查是否存在符合要求未冲减完的批次,不存在则新增库存批次
|
|
|
if @vi_kccount <= 0
|
|
|
begin
|
|
|
select @vi_cnt=count(*)
|
|
|
from t_plu_batch with (nolock)
|
|
|
where
|
|
|
orgcode = @stock_orgcode and
|
|
|
((isnull(@stock_depcode,'') = '') or ((isnull(@stock_depcode,'') <> '') and (depcode = @stock_depcode))) and
|
|
|
((isnull(@stock_supcode,'') = '') or ((isnull(@stock_supcode,'') <> '') and (supcode = @stock_supcode))) and
|
|
|
((isnull(@stock_place,'') = '') or ((isnull(@stock_place,'') <> '') and (place = @stock_place))) and
|
|
|
plucode = @stock_plucode and
|
|
|
((isnull(@stock_plutype,'') = '') or ((@stock_plutype <> '') and (plutype = @stock_plutype))) and
|
|
|
((@stock_batchno = '*') or ((@stock_batchno <> '*') and (batchno = @stock_batchno))) and
|
|
|
stkcount > 0
|
|
|
if @vi_cnt = 0
|
|
|
begin
|
|
|
--如果不存在指定批次,虚拟一个批次增加库存,暂时不用单据中的退货价格,处理完毕直接下一个商品
|
|
|
--配送退货批次正规处理流程应为:按照门店进货先进先出冲减批次的原始批次索引寻找总部批次
|
|
|
--按照该总部批次成本信息新增一笔总部的配送退货入库批次,原始批次索引为原总部进货批次
|
|
|
--理论上不允许无库存空退给总部,这里简单处理,只保证数量正确即可
|
|
|
select
|
|
|
@vf_jprice = isnull(case o.ojprice when 0 then o.jprice else o.ojprice end,g.jprice),
|
|
|
@vf_netjprice = round(isnull(case o.ojprice when 0 then o.jprice else o.ojprice end,g.jprice)/(1+g.jtaxrate/100.00),4),
|
|
|
@vf_jtaxrate = g.jtaxrate
|
|
|
from t_plu g left join t_plu_org o on g.plucode = o.plucode and o.orgcode = @stock_orgcode
|
|
|
left join t_shop s on s.orgcode = o.orgcode
|
|
|
left join t_supplier v on g.supcode =v.supcode
|
|
|
left join t_supplier v1 on o.supcode =v1.supcode
|
|
|
where g.plucode = @stock_plucode
|
|
|
|
|
|
insert into t_plu_batch(orgcode,depcode,supcode,jymode,contrno,batchtype,billno,serialno,place,
|
|
|
plucode,plutype,batchno,srcbatchno,stkcount,jtaxrate,jprice,netjprice,cost,netcost,punit,itemcnt,
|
|
|
productdate,jhdate,jhcount,xscount,othcount)
|
|
|
values(@stock_orgcode,@stock_depcode,@stock_supcode,'0','','v',@billno,@serialno,@stock_place,
|
|
|
@stock_plucode,@stock_plutype,dbo.f_getstockpcno(@billno,'2',@vi_ordnum),dbo.f_getstockpcno(@billno,'2',@vi_ordnum),
|
|
|
abs(@vf_clcount),@vf_jtaxrate,@vf_jprice,@vf_netjprice,
|
|
|
round(abs(@vf_clcount)*@vf_jprice,2),round(abs(@vf_clcount)*@vf_netjprice,2),
|
|
|
'',1,null,getdate(),
|
|
|
case @ywtype when 'rjyw' then 0 when 'rjxs' then 0 else abs(@vf_clcount) end, --非日结业务和销售写进货累计
|
|
|
case @ywtype when 'rjxs' then @vf_clcount else 0 end, --日结销售退货写销售累计
|
|
|
case @ywtype when 'rjyw' then @vf_clcount else 0 end) --日结业务写其他累计
|
|
|
--虚拟进货暂不写库存记账单
|
|
|
--日结销售产生的退货需要写供应商销售明细表数据
|
|
|
if @ywtype = 'rjxs'
|
|
|
begin
|
|
|
insert into t_supsale_detail(billno,serialno,supcode,supname,suptype,plucode,pluname,datatype,
|
|
|
accdate,acctimes,orgcode,orgname,counts,cost,netcost,remark)
|
|
|
select
|
|
|
@vs_ckbillno,@vi_ordnum,@stock_supcode,
|
|
|
isnull((select supname from t_supplier where supcode = @stock_supcode),''),
|
|
|
isnull((select suptype from t_supplier where supcode = @stock_supcode),0),
|
|
|
@vs_plucode,@vs_pluname,'1',accdate,acctimes,
|
|
|
@vs_orgcode,
|
|
|
isnull((select orgname from t_shop where orgcode = @vs_orgcode),''),
|
|
|
@vf_clcount,
|
|
|
round(@vf_clcount*@vf_jprice,2),
|
|
|
round(@vf_clcount*@vf_netjprice,2),
|
|
|
'日结批次处理'
|
|
|
from ##dayover_plubatch_head
|
|
|
where billno = @billno
|
|
|
end
|
|
|
|
|
|
set @vi_ordnum = @vi_ordnum + 1
|
|
|
|
|
|
continue
|
|
|
|
|
|
end
|
|
|
end
|
|
|
end
|
|
|
|
|
|
/*=================循环冲减库存=================*/
|
|
|
set @ps_message = '——取得库存数据'
|
|
|
|
|
|
delete from #pc_pckc
|
|
|
insert into [#pc_pckc]
|
|
|
execute p_getbatchstk_data
|
|
|
@dectype = @vs_dectype,
|
|
|
@orgcode = @stock_orgcode,
|
|
|
@depcode = @stock_depcode,
|
|
|
@place = @stock_place,
|
|
|
@plucode = @stock_plucode,
|
|
|
@itemcnt = @stock_itemcnt,
|
|
|
@batchno = @stock_batchno,
|
|
|
@srcbatchno = @stock_srcbatchno,
|
|
|
@plutype = @stock_plutype,
|
|
|
@contrno = @stock_contrno,
|
|
|
@supcode = @stock_supcode,
|
|
|
@jymode = @stock_jymode,
|
|
|
@decmode = '0',
|
|
|
@pi_result = @pi_result output,
|
|
|
@ps_message = @ps_message output
|
|
|
|
|
|
if @pi_result <> 1
|
|
|
return
|
|
|
set @pi_result = -1
|
|
|
|
|
|
--游标指向存储过程查询返回的结果集
|
|
|
set @cur_stock = cursor for
|
|
|
select * from [#pc_pckc]
|
|
|
|
|
|
open @cur_stock
|
|
|
--if not cursor_status('variable', n'@cur_stock') > -1
|
|
|
-- return
|
|
|
|
|
|
while 1 = 1
|
|
|
begin
|
|
|
fetch @cur_stock
|
|
|
into @stock_depcode, @stock_srcbatchno, @stock_batchno, @stock_kccount, @stock_jprice, @stock_netjprice, @stock_cost, @stock_netcost, @stock_kycount, @stock_contrno, @stock_supcode, @stock_jymode, @stock_plutype, @stock_itemcnt
|
|
|
|
|
|
if @@fetch_status <> 0
|
|
|
break
|
|
|
|
|
|
if @vf_clcount = 0
|
|
|
break
|
|
|
|
|
|
if @stock_kycount > 0
|
|
|
begin
|
|
|
if @vf_clcount >= @stock_kycount
|
|
|
begin
|
|
|
/*使用kycount*/
|
|
|
set @vf_clcount = @vf_clcount - @stock_kycount
|
|
|
set @tmp_stkcount = @stock_kycount
|
|
|
end
|
|
|
else
|
|
|
begin
|
|
|
/*使用clcount*/
|
|
|
set @tmp_stkcount = @vf_clcount
|
|
|
set @vf_clcount = 0
|
|
|
end
|
|
|
|
|
|
set @tmp_cost = @stock_cost * (@tmp_stkcount / @stock_kccount)
|
|
|
set @tmp_netcost = @stock_netcost * (@tmp_stkcount / @stock_kccount)
|
|
|
|
|
|
/*=================冲减库存=================*/
|
|
|
set @ps_message = '——冲减连锁库存'
|
|
|
|
|
|
update t_plu_batch set
|
|
|
stkcount = stkcount - @tmp_stkcount,
|
|
|
cost = cost - @tmp_cost,
|
|
|
netcost = netcost - @tmp_netcost,
|
|
|
emptydate = case stkcount when @tmp_stkcount then @procdate else null end,
|
|
|
jhcount = jhcount + case @vs_uppctype when '1' then abs(@tmp_stkcount) else 0 end,
|
|
|
thcount = thcount + case @vs_uppctype when '2' then abs(@tmp_stkcount) else 0 end,
|
|
|
xscount = xscount + case @vs_uppctype when '3' then @tmp_stkcount else 0 end, --销售和销售退货合并,不用abs
|
|
|
othcount = othcount + case @vs_uppctype when '4' then @tmp_stkcount else 0 end --其他业务出库和入库合并,不用abs
|
|
|
where
|
|
|
orgcode = @stock_orgcode and depcode = @stock_depcode and place = @stock_place and batchno = @stock_batchno
|
|
|
|
|
|
/*=================生成库存记账单明细表=================*/
|
|
|
set @ps_message = '——生成库存记账单明细表'
|
|
|
|
|
|
insert t_batchproc_body(
|
|
|
billno, serialno, depcode, supcode, plucode, pluname, spec, unit, plutype, batchno, srcbatchno,
|
|
|
contrno, jymode, proccount, jprice, netjprice, cost, netcost, refserialno, itemcnt)
|
|
|
values (
|
|
|
@vs_ckbillno, @vi_ordnum, @stock_depcode, @stock_supcode, @vs_plucode, @vs_pluname, @vs_spec, @vs_unit, @stock_plutype, @stock_batchno, @stock_srcbatchno,
|
|
|
@stock_contrno, @stock_jymode, abs(@tmp_stkcount), @stock_jprice, @stock_netjprice, abs(@tmp_cost), abs(@tmp_netcost), @serialno, @stock_itemcnt)
|
|
|
|
|
|
--日结冲减销售时,生成供应商销售明细表数据
|
|
|
if @vs_dectype = 'deckcxs'
|
|
|
begin
|
|
|
insert t_supsale_detail(
|
|
|
billno, serialno, supcode, supname, suptype, plucode, pluname, datatype,
|
|
|
accdate, acctimes, orgcode, orgname, counts, cost, netcost, remark)
|
|
|
select
|
|
|
@vs_ckbillno, @vi_ordnum, @stock_supcode,
|
|
|
isnull((select supname from t_supplier where supcode = @stock_supcode),''),
|
|
|
isnull((select suptype from t_supplier where supcode = @stock_supcode),0),
|
|
|
@vs_plucode, @vs_pluname, '1', accdate, acctimes, @vs_orgcode,
|
|
|
isnull((select orgname from t_shop where orgcode = @vs_orgcode),''),
|
|
|
@tmp_stkcount, @tmp_cost, @tmp_netcost, '日结批次处理'
|
|
|
from ##dayover_plubatch_head
|
|
|
where billno = @billno
|
|
|
end
|
|
|
|
|
|
set @vi_ordnum = @vi_ordnum + 1
|
|
|
end
|
|
|
end
|
|
|
|
|
|
if cursor_status('variable', N'@cur_stock') > -1
|
|
|
begin
|
|
|
close @cur_stock
|
|
|
deallocate @cur_stock
|
|
|
end
|
|
|
|
|
|
if @vf_clcount <> 0
|
|
|
begin
|
|
|
set @ps_message = '——商品(' + isnull(@vs_plucode, '') + '-' + isnull(@vs_pluname, '') + ')库存不足,无法冲减完'
|
|
|
if cursor_status('variable', N'@cur_bill') > -1
|
|
|
begin
|
|
|
close @cur_bill
|
|
|
deallocate @cur_bill
|
|
|
end
|
|
|
return
|
|
|
end
|
|
|
end
|
|
|
|
|
|
if cursor_status('variable', N'@cur1806_bill') > -1
|
|
|
begin
|
|
|
close @cur_bill
|
|
|
deallocate @cur_bill
|
|
|
end
|
|
|
|
|
|
/*=================生成库存记账单主表=================*/
|
|
|
set @ps_message = '——生成库存记账单(出库)主表'
|
|
|
|
|
|
select @tmp_stkcount = sum(proccount), @tmp_cost = sum(cost), @tmp_netcost = sum(netcost)
|
|
|
from t_batchproc_body
|
|
|
where billno = @vs_ckbillno
|
|
|
|
|
|
--如果前面都是虚增进货,是不写记账单明细的,此种情况得到null不写记账单表头
|
|
|
if @tmp_stkcount is not null
|
|
|
insert t_batchproc_head(
|
|
|
billno, billtype, ywtype, ywbillno, procdate, orgcode, place,
|
|
|
proccount, cost, netcost, usercode, username, tag)
|
|
|
values (
|
|
|
@vs_ckbillno, @vs_proctype, @ywtype, @billno, @procdate, @vs_orgcode, @vs_place,
|
|
|
@tmp_stkcount, @tmp_cost, @tmp_netcost, @usercode, @userrname, '0')
|
|
|
|
|
|
set @pi_result = 1
|
|
|
|
|
|
end try
|
|
|
|
|
|
begin catch
|
|
|
declare @errornumber int
|
|
|
set @errornumber = error_number()
|
|
|
declare @errormessage nvarchar(4000)
|
|
|
set @errormessage = error_message()
|
|
|
begin
|
|
|
begin
|
|
|
set @pi_result = -1
|
|
|
if cursor_status('variable', N'@cur_stock') > -1
|
|
|
begin
|
|
|
close @cur_stock
|
|
|
deallocate @cur_stock
|
|
|
end
|
|
|
if cursor_status('variable', N'@cur_bill') > -1
|
|
|
begin
|
|
|
close @cur_bill
|
|
|
deallocate @cur_bill
|
|
|
end
|
|
|
set @ps_message = isnull(@ps_message, '冲减连锁库存时发生未知错误:') + isnull(@errormessage, '')
|
|
|
set @ps_message = substring(@ps_message, 1, 2000)
|
|
|
return
|
|
|
end
|
|
|
end
|
|
|
end catch
|
|
|
end
|
|
|
go
|
|
|
|
|
|
if exists (select * from dbo.sysobjects where id = object_id(N'p_coupon_sale_lock') and objectproperty(id, N'isprocedure') = 1)
|
|
|
drop procedure p_coupon_sale_lock
|
|
|
go
|
|
|
create procedure p_coupon_sale_lock
|
|
|
@datatype varchar(1),
|
|
|
@billno varchar(20),
|
|
|
@cupcode varchar(20),
|
|
|
@vipcode varchar(20),
|
|
|
@msgserialno varchar(12),
|
|
|
@orgcode varchar(10),
|
|
|
@posno varchar(6),
|
|
|
@usercode varchar(6),
|
|
|
@xfls varchar(100),
|
|
|
@verifymark varchar(13),
|
|
|
@lockmark varchar(20),
|
|
|
@smessage varchar(100) output
|
|
|
with encryption
|
|
|
as
|
|
|
declare @snowdate varchar(10)
|
|
|
declare @rzdate varchar(10)
|
|
|
declare @bgndate varchar(10)
|
|
|
declare @enddate varchar(10)
|
|
|
declare @isused varchar(1)
|
|
|
declare @oldverifymark varchar(13)
|
|
|
declare @sql varchar(8000)
|
|
|
declare @canuse varchar(1)
|
|
|
declare @locked varchar(1)
|
|
|
declare @irnt integer
|
|
|
begin
|
|
|
set @snowdate = convert(varchar(10),getdate(),120)
|
|
|
select @rzdate = f.rzdate
|
|
|
from t_coupon_head f,t_coupon_org o
|
|
|
where f.billno = o.billno and f.billno = @billno and o.orgcode = @orgcode
|
|
|
set @irnt = @@rowcount
|
|
|
if isnull(@rzdate,'') = ''
|
|
|
begin
|
|
|
select @smessage = '此券未生效'
|
|
|
return (-1)
|
|
|
end
|
|
|
if @irnt = 0
|
|
|
begin
|
|
|
select @smessage = '此券不能在本机构消费'
|
|
|
return (-1)
|
|
|
end
|
|
|
|
|
|
if @datatype = 0
|
|
|
begin
|
|
|
select @bgndate = f.rcvdate,@enddate = f.enddate,@isused = f.status,@oldverifymark = f.verifymark,
|
|
|
@locked = case when isnull(f.lockmark,'') = '' then '0' else '1' end
|
|
|
from t_vip_coupon f
|
|
|
where f.billno = @billno and f.cupcode = @cupcode and f.vipcode = @vipcode
|
|
|
end
|
|
|
else
|
|
|
begin
|
|
|
select @bgndate = f.rcvdate,@enddate = f.enddate,@isused = f.status,@oldverifymark = f.verifymark,
|
|
|
@locked = case when isnull(f.lockmark,'') = '' then '0' else '1' end
|
|
|
from t_cash_coupon f
|
|
|
where f.billno = @billno and f.cupcode = @cupcode
|
|
|
end
|
|
|
set @irnt = @@rowcount
|
|
|
if @irnt = 0
|
|
|
begin
|
|
|
select @smessage = '此券不存在'
|
|
|
return (-1)
|
|
|
end
|
|
|
|
|
|
if @irnt > 1
|
|
|
begin
|
|
|
select @smessage = '此券号不唯一'
|
|
|
return (-1)
|
|
|
end
|
|
|
|
|
|
if (@bgndate > @snowdate) or (@enddate < @snowdate)
|
|
|
begin
|
|
|
select @smessage = '此券未开始启用或已过期'
|
|
|
return (-1)
|
|
|
end
|
|
|
|
|
|
if @locked = '1'
|
|
|
begin
|
|
|
select @smessage = '此券已锁定'
|
|
|
return (-1)
|
|
|
end
|
|
|
|
|
|
if (@isused = '3')
|
|
|
begin
|
|
|
select @smessage = '此券已被使用'
|
|
|
return (-1)
|
|
|
end
|
|
|
|
|
|
if (@isused= '2')
|
|
|
begin
|
|
|
select @smessage = '此券已作废'
|
|
|
return (-1)
|
|
|
end
|
|
|
|
|
|
if (@oldverifymark <> @verifymark)
|
|
|
begin
|
|
|
select @smessage = '此券校验位检测结果异常'
|
|
|
return (-1)
|
|
|
end
|
|
|
|
|
|
if @datatype = 0
|
|
|
begin
|
|
|
update f set lockmark = @lockmark,msgserialno = @msgserialno,serialno = @xfls,orgcode=@orgcode,posno = @posno,clkcode = @usercode,status = '4'
|
|
|
from t_vip_coupon f
|
|
|
where f.billno = @billno and f.cupcode = @cupcode and f.vipcode = @vipcode
|
|
|
end
|
|
|
else
|
|
|
begin
|
|
|
update f set lockmark = @lockmark,msgserialno = @msgserialno,serialno = @xfls,orgcode=@orgcode,posno = @posno,clkcode = @usercode,status = '4'
|
|
|
from t_cash_coupon f
|
|
|
where f.billno = @billno and f.cupcode = @cupcode
|
|
|
end
|
|
|
|
|
|
if @@error<>0
|
|
|
begin
|
|
|
select @smessage='券锁定异常'
|
|
|
return (-1)
|
|
|
end
|
|
|
else
|
|
|
return (0)
|
|
|
end
|
|
|
go
|
|
|
|
|
|
if exists (select * from dbo.sysobjects where id = object_id(N'p_coupon_confirm') and objectproperty(id, N'isprocedure') = 1)
|
|
|
drop procedure p_coupon_confirm
|
|
|
go
|
|
|
create procedure p_coupon_confirm
|
|
|
@datatype varchar(1),
|
|
|
@cupcoden varchar(1000),
|
|
|
@msgserialno varchar(12),
|
|
|
@smessage varchar(100) output
|
|
|
with encryption
|
|
|
as
|
|
|
declare @snowdate varchar(10)
|
|
|
declare @ssql varchar(8000)
|
|
|
begin
|
|
|
if @datatype= '0'
|
|
|
begin
|
|
|
set @ssql = 'update f set status = ''3'',verifymark = lockmark,lockmark = '''',msgserialno = ''''
|
|
|
from t_vip_coupon f
|
|
|
where f.cupcode in ' + @cupcoden + ' and f.msgserialno = ''' + @msgserialno + ''''
|
|
|
end
|
|
|
else
|
|
|
begin
|
|
|
set @ssql = 'update f set status = ''3'',verifymark = lockmark,lockmark = '''',msgserialno = ''''
|
|
|
from t_cash_coupon f
|
|
|
where f.cupcode in ' + @cupcoden + ' and f.msgserialno = ''' + @msgserialno + ''''
|
|
|
end
|
|
|
exec(@ssql)
|
|
|
if @@error<>0
|
|
|
begin
|
|
|
select @smessage = '券确认消费异常'
|
|
|
return (-1)
|
|
|
end
|
|
|
else
|
|
|
return (0)
|
|
|
end
|
|
|
go
|
|
|
|
|
|
if exists (select * from dbo.sysobjects where id = object_id(N'p_coupon_cancel') and objectproperty(id, N'isprocedure') = 1)
|
|
|
drop procedure p_coupon_cancel
|
|
|
go
|
|
|
create procedure p_coupon_cancel
|
|
|
@datatype varchar(1),
|
|
|
@cupcoden varchar(1000),
|
|
|
@msgserialno varchar(12),
|
|
|
@smessage varchar(100) output
|
|
|
with encryption
|
|
|
as
|
|
|
declare @ssql varchar(8000)
|
|
|
begin
|
|
|
if @datatype= '0'
|
|
|
begin
|
|
|
set @ssql = 'update f set lockmark = '''',msgserialno = '''',orgcode = '''',serialno = '''',clkcode='''',posno='''',status = ''1''
|
|
|
from t_vip_coupon f
|
|
|
where f.cupcode in ' + @cupcoden + ' and f.msgserialno = ''' + @msgserialno + ''' '
|
|
|
end
|
|
|
else
|
|
|
begin
|
|
|
set @ssql = 'update f set lockmark = '''',msgserialno = '''',orgcode = '''',serialno = '''',clkcode='''',posno='''',status = ''1''
|
|
|
from t_cash_coupon f
|
|
|
where f.cupcode in ' + @cupcoden + ' and f.msgserialno = ''' + @msgserialno + ''' '
|
|
|
end
|
|
|
exec(@ssql)
|
|
|
if @@error<>0
|
|
|
begin
|
|
|
select @smessage = '券取消消费异常'
|
|
|
return (-1)
|
|
|
end
|
|
|
else
|
|
|
return (0)
|
|
|
end
|
|
|
go
|
|
|
|
|
|
if exists (select * from dbo.sysobjects where id = object_id(N'p_coupon_open_lock') and objectproperty(id, N'isprocedure') = 1)
|
|
|
drop procedure p_coupon_open_lock
|
|
|
go
|
|
|
create procedure p_coupon_open_lock
|
|
|
@datatype varchar(1),
|
|
|
@billno varchar(20),
|
|
|
@cupcode varchar(20),
|
|
|
@vipcode varchar(20),
|
|
|
@opentype varchar(1),
|
|
|
@smessage varchar(100) output
|
|
|
with encryption
|
|
|
as
|
|
|
declare @ssql varchar(8000)
|
|
|
begin
|
|
|
if @datatype= '0'
|
|
|
begin
|
|
|
select cupcode from t_vip_coupon f
|
|
|
where f.billno = @billno and f.cupcode = @cupcode and f.vipcode = @vipcode and (isnull(f.lockmark,'') <> '')
|
|
|
end
|
|
|
else
|
|
|
begin
|
|
|
select cupcode from t_cash_coupon f
|
|
|
where f.billno = @billno and f.cupcode = @cupcode and (isnull(f.lockmark,'') <> '')
|
|
|
end
|
|
|
if @@rowcount = 0
|
|
|
begin
|
|
|
select @smessage = '此券未被锁定'
|
|
|
return (-1)
|
|
|
end
|
|
|
|
|
|
if @datatype= '0'
|
|
|
begin
|
|
|
if @opentype = '0'
|
|
|
begin
|
|
|
update f set status = '3',verifymark = lockmark,lockmark = '',msgserialno = ''
|
|
|
from t_vip_coupon f
|
|
|
where f.billno = @billno and f.cupcode = @cupcode and f.vipcode = @vipcode
|
|
|
end
|
|
|
else
|
|
|
begin
|
|
|
update f set status = '1',lockmark = '',msgserialno = '',orgcode = '',serialno = '',clkcode='',posno=''
|
|
|
from t_vip_coupon f
|
|
|
where f.billno = @billno and f.cupcode = @cupcode and f.vipcode = @vipcode
|
|
|
end
|
|
|
end
|
|
|
else
|
|
|
begin
|
|
|
if @opentype = '0'
|
|
|
begin
|
|
|
update f set status = '3',verifymark = lockmark,lockmark = '',msgserialno = ''
|
|
|
from t_cash_coupon f
|
|
|
where f.billno = @billno and f.cupcode = @cupcode
|
|
|
end
|
|
|
else
|
|
|
begin
|
|
|
update f set status = '1',lockmark = '',msgserialno = '',orgcode = '',serialno = '',clkcode='',posno=''
|
|
|
from t_cash_coupon f
|
|
|
where f.billno = @billno and f.cupcode = @cupcode
|
|
|
end
|
|
|
end
|
|
|
|
|
|
if @@error<>0
|
|
|
begin
|
|
|
select @smessage = '券解锁出现异常'
|
|
|
return (-1)
|
|
|
end
|
|
|
else
|
|
|
return (0)
|
|
|
end
|
|
|
go
|
|
|
|
|
|
--配送单生成拣货单
|
|
|
if exists (select * from dbo.sysobjects where id = object_id(N'p_turn_picking') and objectproperty(id, N'isprocedure') = 1)
|
|
|
drop procedure p_turn_picking
|
|
|
go
|
|
|
create procedure p_turn_picking
|
|
|
@sbillno varchar(20),
|
|
|
@sorgcode varchar(10),
|
|
|
@sbillsrc varchar(1),
|
|
|
@psusercode varchar(6),
|
|
|
@psremark varchar(200),
|
|
|
@piflag int out,
|
|
|
@psmsg varchar(2000) out
|
|
|
as
|
|
|
begin
|
|
|
declare @detail_areacode varchar(10)
|
|
|
declare @newbillno varchar(20)
|
|
|
declare @scurdate varchar(10)
|
|
|
declare @scurtime varchar(8)
|
|
|
declare @susername varchar(20)
|
|
|
declare @count int
|
|
|
declare @errmsg varchar(1800)
|
|
|
declare @plucode varchar(20)
|
|
|
declare @pluname varchar(40)
|
|
|
if @sorgcode=''
|
|
|
begin
|
|
|
select @sorgcode=orgcode from t_dist_head where billno = @sbillno
|
|
|
end
|
|
|
if (@sbillno='') or (@sorgcode='') or (@psusercode='')
|
|
|
begin
|
|
|
set @piflag=0
|
|
|
set @psmsg='单据号、仓库编码、录入人 有一项或者多项为空'
|
|
|
return (0)
|
|
|
end
|
|
|
set @count = 0
|
|
|
select @count = (count(*)) from t_picking_head where zpbillno = @sbillno
|
|
|
if (@count > 0 )
|
|
|
begin
|
|
|
set @piflag=0
|
|
|
set @psmsg='配送单'+@sbillno+'已生成过拣货单'
|
|
|
return (0)
|
|
|
end
|
|
|
|
|
|
set @errmsg=''
|
|
|
declare cur_checkbilldata cursor for select d.plucode,d.pluname from t_dist_body d left join
|
|
|
(select plucode,bincode from t_plu_bin where orgcode = @sorgcode) b on d.plucode = b.plucode
|
|
|
where isnull(b.bincode,'')='' and billno = @sbillno
|
|
|
open cur_checkbilldata
|
|
|
fetch next from cur_checkbilldata into @plucode,@pluname
|
|
|
while @@fetch_status=0
|
|
|
begin
|
|
|
if @errmsg=''
|
|
|
set @errmsg=''+@plucode+'-'+@pluname+';'
|
|
|
else
|
|
|
set @errmsg=@errmsg+char(13)+''+@plucode+'-'+@pluname+';'
|
|
|
fetch next from cur_checkbilldata into @plucode,@pluname
|
|
|
end
|
|
|
close cur_checkbilldata
|
|
|
deallocate cur_checkbilldata
|
|
|
|
|
|
if (@errmsg <> '' )
|
|
|
begin
|
|
|
set @piflag=0
|
|
|
set @psmsg='配送单'+@sbillno+'没有维护仓位信息的商品有:'+ @errmsg
|
|
|
return (0)
|
|
|
end
|
|
|
select @susername=username from t_user where usercode=@psusercode
|
|
|
set @piflag=0
|
|
|
declare cur cursor for select distinct(pb.areacode) as areacode from t_dist_body d
|
|
|
left join ( select plucode,bincode,(select areacode from t_ware_bin where bincode = t.bincode)as areacode from t_plu_bin t where t.orgcode = @sorgcode)pb on pb.plucode = d.plucode
|
|
|
where d.billno = @sbillno
|
|
|
open cur
|
|
|
fetch next from cur into @detail_areacode
|
|
|
while @@fetch_status=0
|
|
|
begin
|
|
|
if(isnull(@detail_areacode,'') <> '')
|
|
|
begin
|
|
|
while 1=1
|
|
|
begin
|
|
|
exec f_get_billno 'PK',@sorgcode,'1',@newbillno output
|
|
|
if exists(select 1 from t_picking_head where billno=@newbillno)
|
|
|
continue
|
|
|
else
|
|
|
break
|
|
|
end
|
|
|
if @@error<>0
|
|
|
begin
|
|
|
set @piflag=0
|
|
|
set @psmsg='生成拣货单失败'
|
|
|
return (0)
|
|
|
end
|
|
|
select @scurdate=convert(varchar(10),getdate(),23),@scurtime =convert(varchar(8),getdate(),108)
|
|
|
insert into t_picking_body (billno,serialno,plucode,pluname,barcode,cargono,spec,unit,punit,itemcnt,pcount,sglcount,counts,zpcount,bincode,boxno,depcode,depname,remark )
|
|
|
select @newbillno,d.serialno as serialno,d.plucode,d.pluname,d.barcode,d.cargono,d.spec,d.unit,d.punit,d.ItemCnt,0,0,0,d.zpcount,pb.bincode as bincode,'',d.DepCode,d.DepName,''
|
|
|
from t_dist_body d
|
|
|
left join ( select plucode,bincode,(select areacode from t_ware_bin where bincode = t.bincode)as areacode from t_plu_bin t where t.orgcode = @sorgcode )pb on d.plucode = pb.plucode
|
|
|
where d.billno = @sbillno and pb.areacode = @detail_areacode
|
|
|
order by pb.bincode
|
|
|
|
|
|
insert into t_picking_head(billno,orgcode,zpbillno,state,areacode,billsrc,lrdate,lrtime,bizdate,depcode,depname,counts,chkstatus,usercode,username,zdrcode,zdrname,remark)
|
|
|
select @newbillno,@sorgcode,billno,'0',@detail_areacode,@sbillsrc,@scurdate,@scurtime,@scurdate,h.depcode,h.depname,0,'0',@psusercode,@susername,@psusercode,@susername,'配送单'+@sbillno+'自动生成'
|
|
|
from t_dist_head h where h.billno = @sbillno
|
|
|
end
|
|
|
fetch next from cur into @detail_areacode
|
|
|
end
|
|
|
close cur
|
|
|
deallocate cur
|
|
|
update t_dist_head set pickstate = '1' where BillNo = @sbillno
|
|
|
if @@error<>0
|
|
|
begin
|
|
|
set @piflag=0
|
|
|
set @psmsg='更改配送单状态失败'
|
|
|
return (0)
|
|
|
end
|
|
|
set @piflag=1
|
|
|
return (1)
|
|
|
end
|
|
|
go
|
|
|
|
|
|
if exists (select * from dbo.sysobjects where id = object_id(N'p_update_new_prn_format') and objectproperty(id, N'isprocedure') = 1)
|
|
|
drop procedure p_update_new_prn_format
|
|
|
go
|
|
|
create procedure p_update_new_prn_format
|
|
|
@prntype varchar(1),
|
|
|
@prncode varchar(10),
|
|
|
@ver varchar(1),
|
|
|
@prnname varchar(40),
|
|
|
@remark varchar(40),
|
|
|
@isnewformat varchar(1),
|
|
|
@newformat image
|
|
|
as
|
|
|
begin
|
|
|
declare @iisfind int
|
|
|
declare @imgformat varbinary(8000)
|
|
|
declare @prnformat varbinary(8000)
|
|
|
declare cur_loop cursor for
|
|
|
select prnformat from t_prn_format where prntype=@prntype and prncode=@prncode order by serialno
|
|
|
|
|
|
set @iisfind=0
|
|
|
set @imgformat=@newformat
|
|
|
open cur_loop
|
|
|
fetch next from cur_loop into @prnformat
|
|
|
while @@fetch_status=0
|
|
|
begin
|
|
|
if dbo.f_compare_image(@imgformat,@prnformat)=1
|
|
|
begin
|
|
|
set @iisfind=1
|
|
|
break
|
|
|
end
|
|
|
fetch next from cur_loop into @prnformat
|
|
|
end
|
|
|
close cur_loop
|
|
|
deallocate cur_loop
|
|
|
|
|
|
if @iisfind=0
|
|
|
insert into t_prn_format (prntype,prncode,ver,serialno,isdefault,prnname,remark,isnewformat,prnformat)
|
|
|
select @prntype,@prncode,@ver,(select isnull(max(serialno),0)+1 serialno from t_prn_format where prntype=@prntype and prncode=@prncode),'0',@prnname,@remark,@isnewformat,@newformat
|
|
|
end
|
|
|
go
|