Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE PROCEDURE [dbo].[crud_tst-chartbar_getItems]
- @filters CRUDFilterParameter READONLY,
- @sort sql_variant,
- @direction nvarchar(8),
- @page int,
- @pageSize int,
- @username nvarchar(32)
- AS
- BEGIN
- -- основная процедура настройки таблицы
- -- результирующая таблица (описываем здесь поля)
- -- спецполя для нее: icon_age, prev_age, prevcolor_age, color_age, backcolor_age, desc_name, color, barPercent_age, barClass_age, badge_age
- declare @result TABLE (id nvarchar(128), title nvarchar(256), ord int)
- declare @langID int
- select @langID = try_cast(Value as int) from @filters where [Key] = 'langID'
- declare @filterWeek nvarchar(256), @d1 datetime, @d2 datetime
- select @filterWeek = Value from @filters where [Key] = 'created'
- if isnull(@filterWeek,'')='' begin
- declare @weeks table (i int, d1 datetime, d2 datetime)
- declare @i int = 0
- while @i > -4
- begin
- insert into @weeks
- select abs(@i), dateadd(week,datediff(week,0,dateadd(week,@i,'2020-03-27 00:00:00.000')),0), dateadd(week,datediff(week,0,dateadd(week,@i+1,'2020-03-27 00:00:00.000')),0)
- set @i = @i - 1
- end
- select top 1 @filterWeek = convert(nvarchar,d1,104)+','+convert(nvarchar,d2,104)
- from @weeks
- order by i
- end
- select @d1 = convert(datetime, dbo.str_splitPart(@filterWeek,',',1), 104)
- select @d2 = convert(datetime, dbo.str_splitPart(@filterWeek,',',2), 104)
- SET DATEFIRST 1
- insert into @result
- select '1' id, '<div class="font-weight-normal">'+iif(@langID=1, 'Mon', 'Понедельник')+'</div><div class="small text-muted">'+isnull(convert(nvarchar,@d1,104),'')+'</div>' title, 1 ord
- union
- select '2' id, '<div class="font-weight-normal">'+iif(@langID=1, 'Tue', 'Вторник')+'</div><div class="small text-muted">'+isnull(convert(nvarchar,dateadd(day,1,@d1),104),'')+'</div>' title, 2 ord
- union
- select '3' id, '<div class="font-weight-normal">'+iif(@langID=1, 'Web', 'Среда')+'</div><div class="small text-muted">'+isnull(convert(nvarchar,dateadd(day,2,@d1),104),'')+'</div>' title, 3 ord
- union
- select '4' id, '<div class="font-weight-normal">'+iif(@langID=1, 'Thur', 'Четверг')+'</div><div class="small text-muted">'+isnull(convert(nvarchar,dateadd(day,3,@d1),104),'')+'</div>' title, 4 ord
- union
- select '5' id, '<div class="font-weight-normal">'+iif(@langID=1, 'Fri', 'Пятница')+'</div><div class="small text-muted">'+isnull(convert(nvarchar,dateadd(day,4,@d1),104),'')+'</div>' title, 5 ord
- union
- select '6' id, '<div class="font-weight-normal">'+iif(@langID=1, 'Sat', 'Суббота')+'</div><div class="small text-muted">'+isnull(convert(nvarchar,dateadd(day,5,@d1),104),'')+'</div>' title, 6 ord
- union
- select '7' id, '<div class="font-weight-normal">'+iif(@langID=1, 'Sun', 'Воскресенье')+'</div><div class="small text-muted">'+isnull(convert(nvarchar,dateadd(day,6,@d1),104),'')+'</div>' title, 7 ord
- /*
- select '1' id, 'ПН '+isnull(left(convert(nvarchar,@d1,104),5),'') title, 1 ord
- union
- select '2' id, 'ВТ '+isnull(left(convert(nvarchar,dateadd(day,1,@d1),104),5),'') title, 2 ord
- union
- select '3' id, 'СР '+isnull(left(convert(nvarchar,dateadd(day,2,@d1),104),5),'') title, 3 ord
- union
- select '4' id, 'ЧТ '+isnull(left(convert(nvarchar,dateadd(day,3,@d1),104),5),'') title, 4 ord
- union
- select '5' id, 'ПТ '+isnull(left(convert(nvarchar,dateadd(day,4,@d1),104),5),'') title, 5 ord
- union
- select '6' id, 'СБ '+isnull(left(convert(nvarchar,dateadd(day,5,@d1),104),5),'') title, 6 ord
- union
- select '7' id, 'ВС '+isnull(left(convert(nvarchar,dateadd(day,6,@d1),104),5),'') title, 7 ord
- */
- -- 1 SELECT - сами данные
- select * from @result
- order by ord
- -- 2 SELECT - кол-во в таблице
- select count(*) from @result
- -- 3 SELECT Дополнительные настройки таблицы
- select 'chartbar' ViewType, 1 InstantFilter, 1 HideTitleCount, iif(@langID=1, 'Orders by weeks', 'Заказы по неделям') Title
- -- 4 SELECT Данные для подвала страницы или данные для Ганта/Канбана (если установлен ViewType в 3 SELECT)
- select cast(id as nvarchar) itemID,
- cast(DATEPART(dw,created) as nvarchar) [from],
- cast(DATEPART(dw,created) as nvarchar) [to],
- '<div class="text-dark font-weight-bold">'+cast(isnull(price*cnt,0) as nvarchar)+'</div>' [title],
- '<div class="small">'+(select name from tst_products where id = productID)+', '+cast(isnull(cnt,0) as nvarchar)+'</div>' [desc],
- '' cssClass,
- case when price*cnt <= 25000 then 'lightBlue'
- when price*cnt > 25000 and price*cnt <= 50000 then 'lightGreen'
- when price*cnt > 50000 then 'pink' end color
- from tst_orders
- where isnull(@filterWeek,'')='' or created between @d1 and @d2
- order by created
- END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement