I'm sorry, this is my source code
-----------------------------------------
if object_id('sp_DBR_test2','P') is not null
drop procedure sp_DBR_test2
go
CREATE PROCEDURE sp_DBR_test2
@filterDepartment NVARCHAR(255) = '',
@startDate date,
@endDate date,
@inLogin VARCHAR(128) = '',
@priceFormat VARCHAR(20) = 'One',
@currencyType VARCHAR(20) = 'VND',
@language VARCHAR(50) = 'vni',
@version varchar(50) = '',
@filterAccount varchar(255) = ''
AS
BEGIN
DECLARE @user_group_id INT;
DECLARE @noteTyGia nvarchar(255);
DECLARE @notePriceFormat nvarchar(255);
DECLARE @exchange_rate varchar(50);
SET @exchange_rate = (SELECT rate FROM khns..dim_exchange_rate WHERE currency_from = @currencyType);
SET @user_group_id = (SELECT group_id FROM mydbr..mydbr_groupsusers WHERE username = @inLogin);
SET @noteTyGia = N'Tỷ giá: ' + @exchange_rate;
SET @notePriceFormat = N'Định dạng tiền: ' + @priceFormat;
SELECT 'dbr.title', 'dbr.html:<span style="font-size:1.4em">Profit and Loss Statement: January - February<span>';
IF @priceFormat != 'One'
BEGIN
SELECT 'dbr.text', 'dbr.html:<span style="text-align: left;font-size:1.1em;margin-right: 750px">' + @notePriceFormat + '<span>';
END
IF @currencyType != 'VND'
BEGIN
SELECT 'dbr.text', 'dbr.html:<span style="text-align: left;font-size:1.1em;margin-right: 800px;">' + @noteTyGia + '</span>';
END
SELECT 'dbr.parameters.show';
SELECT 'dbr.css', '
td.cell { white-space:nowrap; padding-left: 2px; padding-right: 5px; }
td.prev_year, td.prev_year a { color: #777 !important; }
th.TableHdrTableData {padding-left: 2px; padding-right: 2px}
td.cell a {text-decoration:none}
td.this_year a { color: #444 }
.whitebg {background-color:white !important; border-bottom: 1px solid #DDDDDD !important}
td.group_allocation {color: #666;}
.toggledrows .row, .toggledrows .row.odd, {background-color:white;}
.toggledrows tr.acc_header td {border-bottom:none;background-color:white;}
.pl_report .toggle_img {display:none}
.acc_header {font-weight: 500;background: #F4F4F4;}
.acc_header td {border-top: 1px solid #CCC;border-bottom: 1px solid #CCC;}
.acc_header td {border-top: 1px solid #CCC;border-bottom: 1px solid #CCC;}
tr.acc_header td {border-bottom: 1px solid #666;}
--.account td {padding-left: 2em !important}
--tr.account td.padded_account {padding-left: 30px; background-color: white;}
--tr.account {background-color: white;}
.level1 td:first-child {
color: #006600; /* Màu xanh lá cây cho level1 */
padding-left: 2em;
}
.level2 td:first-child {
color: #663300; /* Màu nâu đất cho level2 */
padding-left: 4em;
}
.level3 td:first-child {
color: #330099; /* Màu xanh đậm cho level3 */
padding-left: 6em;
}
.account td:first-child {
color: #990033; /* Màu đỏ tối cho level4 */
padding-left: 8em;
}
.spark {padding:0}
';
select 'dbr.purehtml', '<input type="button" value="Hide/show detail rows" onclick="$(''.rowbutton'')[0].click();">';
select 'dbr.purehtml', '<input type="button" value="Hide/show extra columns" onclick="$(''.colbutton'')[0].click();">';
--select 'dbr.javascript', 'function myfunc(checkbox) { alert("Callback"); }';
--select 'dbr.javascript', '
--<script type="text/javascript">
--function toggleRows() {
-- $(".rowclass").toggle();
--}
--</script>';
--select 'dbr.javascript', '
--function toggleDetailRows() {
-- var detailRows = document.getElementsByClassName("toggledrows")[0].getElementsByClassName("rowclass");
-- console.log(detailRows);
-- var isHidden = detailRows[0].style.display === "none";
-- for (var i = 0; i < detailRows.length; i++) {
-- detailRows[i].style.display = isHidden ? "" : "none";
-- }
-- var button = document.getElementById("toggleDetailRows");
-- button.value = isHidden ? "Hide detail rows" : "Show detail rows";
--}
--';
SELECT 'dbr.search', '0';
select 'dbr.toggle','[
{
"name":"Show/Hide rows",
"class":"rowbutton",
"resultclass":"toggledrows",
"rows":["account"]
}]
';
select 'dbr.toggle','[
{
"name":"Show/Hide columns",
"class":"colbutton",
"cols":["Budget"]
}]
';
select 'dbr.toggle.options', 'speed', 700;
SELECT 'dbr.resultclass', 'pl_report';
SELECT 'dbr.hidecolumns', 'rowclass';
SELECT 'dbr.crosstab', 'Month';
SELECT 'dbr.colclass', 'account', 'padded_account border_left freeze';
SELECT 'dbr.lockcolumns', 'account';
SELECT 'dbr.colclass', 'account_code';
--select 'dbr.colclass', 'Sparkline', 'spark';
SELECT 'dbr.colclass', 'ty_ga', 'border_left border_right this_year group_allocation';
SELECT 'dbr.colclass', 'ty', 'this_year';
SELECT 'dbr.colclass', 'Budget', 'budget';
SELECT 'dbr.colclass', '%', '%'; --=recent/budget_value
SELECT 'dbr.colclass', 'ly', 'border_right prev_year';
SELECT 'dbr.colclass', 'chg', 'border_right chg';
SELECT 'dbr.header.colclass', 'ty_ga', 'group_allocation';
SELECT 'dbr.header.colclass', 'MOM', 'MOM';
SELECT 'dbr.colclass', '%MOM', '%MOM'; --(recent/value_lastmonth)-1
SELECT 'dbr.header.colclass', 'ly', 'prev_year';
SELECT 'dbr.header.colclass', 'chg', '%YOY'; --(recent/value_lastyear)-1
SELECT 'dbr.rowclass', 'rowclass';
SELECT 'dbr.lockcolumns', 'account';
SELECT 'dbr.summary.calc', 'chg', '[ly]==0 ? 0 : ([ty]-([ly]))/abs([ly])*100';
SELECT 'dbr.colstyle', 'ty_ga', '%.0f; ;%.0f';
SELECT 'dbr.colstyle', 'ty', '%.0f; ;%.0f';
SELECT 'dbr.colstyle', 'ly', '%.0f; ;%.0f';
SELECT 'dbr.colstyle', 'chg', '%.0f %; ;%.0f %';
SELECT 'dbr.colstyle', '%', '%.0f %; ;%.0f %';
SELECT 'dbr.nosort', 0;
SELECT 'dbr.hidecolumn', 'ty_ga';
SELECT 'dbr.report', 'sp_DBR_test2', '[account]', 'new_window', 'filterAccount=account';
--có đoạn code window, new popup
--'new_window', '[new_window]'
--declare table sparkline code, chart_value (string)
--insert into bangphu (tu bang chinh lay recent)
--bang chinh
--select chart_value as 'Sparkline' from bangphu join bangchinh on a.code = b.code
-- Kiểm tra nếu bảng tồn tại thì xóa đi
DROP TABLE IF EXISTS pl_sparkline_temple;
-- Tạo bảng mới
CREATE TABLE pl_sparkline_temple (
account_code VARCHAR(255),
actual DECIMAL(10,2),
month VARCHAR(50)
);
-- Insert dữ liệu vào bảng mới
INSERT INTO pl_sparkline_temple (account_code, actual, month)
SELECT
b.code as 'account_code',
--sum(b.recent) as 'Sparkline',
--CONCAT(
-- SUM(CASE WHEN b.month = 1 THEN b.recent ELSE 0 END), ',',
-- SUM(CASE WHEN b.month = 2 THEN b.recent ELSE 0 END)
--) AS 'Sparkline',
--11, 12, 1, 2, 3--
--STRING_AGG(CAST(b.recent AS VARCHAR(20)), ',') WITHIN GROUP (ORDER BY b.month) AS 'Sparkline[max]',
--'8,4,1,0,6,0,1,4,4,10,10,8,10,0,2,0,4,6,5,9,10' as 'Sparkline',
sum(b.recent) as 'actual',
b.month as 'month'
FROM cdc_KT1S_Release_App_2024..pl_report b
where b.month is not null and (@filterDepartment = '' OR b.ma_bp IN (SELECT REPLACE(value, '''', '') FROM STRING_SPLIT(@filterDepartment, ',')))
and (@version = '' OR b.Version IN (SELECT REPLACE(value, '''', '') FROM STRING_SPLIT(@version, ',')))
and (b.date BETWEEN @startDate AND @endDate)
GROUP BY
CASE
WHEN @language = 'vni' THEN b.description
WHEN @language = 'eng' THEN b.e_name
END,
b.row_class,
b.pos,
b.date,
b.month,
b.year,
b.code
ORDER BY b.pos, b.date, b.month, b.year;
------------------------------------------------------------
SELECT
CASE
WHEN @language = 'vni' THEN b.description
WHEN @language = 'eng' THEN b.e_name
END AS '[account]',
b.code as 'account_code',
--sum(b.recent) as 'Sparkline',
--CONCAT(
-- SUM(CASE WHEN b.month = 1 THEN b.recent ELSE 0 END), ',',
-- SUM(CASE WHEN b.month = 2 THEN b.recent ELSE 0 END)
--) AS 'Sparkline',
--11, 12, 1, 2, 3--
--STRING_AGG(CAST(b.recent AS VARCHAR(20)), ',') WITHIN GROUP (ORDER BY b.month) AS 'Sparkline[max]',
--'8,4,1,0,6,0,1,4,4,10,10,8,10,0,2,0,4,6,5,9,10' as 'Sparkline',
b.month AS Month,
3 AS 'GA[ty_ga]',
--ACTUAL
CASE
WHEN @currencyType = 'USD' THEN
CASE
WHEN @priceFormat = 'Thousand' THEN sum(b.recent) / 1000 / @exchange_rate
WHEN @priceFormat = 'Million' THEN sum(b.recent) / 1000000 / @exchange_rate
WHEN @priceFormat = 'Billion' THEN sum(b.recent) / 1000000000 / @exchange_rate
ELSE sum(b.recent) / @exchange_rate
END
ELSE
CASE
WHEN @priceFormat = 'Thousand' THEN sum(b.recent) / 1000
WHEN @priceFormat = 'Million' THEN sum(b.recent) / 1000000
WHEN @priceFormat = 'Billion' THEN sum(b.recent) / 1000000000
ELSE sum(b.recent)
END
END AS 'Actual[ty]',
--BUDGET
CASE
WHEN @currencyType = 'USD' THEN
CASE
WHEN @priceFormat = 'Thousand' THEN sum(b.budget_value) / 1000 / @exchange_rate
WHEN @priceFormat = 'Million' THEN sum(b.budget_value) / 1000000 / @exchange_rate
WHEN @priceFormat = 'Billion' THEN sum(b.budget_value) / 1000000000 / @exchange_rate
ELSE sum(b.budget_value) / @exchange_rate
END
ELSE
CASE
WHEN @priceFormat = 'Thousand' THEN sum(b.budget_value) / 1000
WHEN @priceFormat = 'Million' THEN sum(b.budget_value) / 1000000
WHEN @priceFormat = 'Billion' THEN sum(b.budget_value) / 1000000000
ELSE sum(b.budget_value)
END
END AS 'Budget',
--%BUDGET ACTUAL
sum(b.recent) / sum(b.budget_value) * 100 as '%',
--MOM
CASE
WHEN @currencyType = 'USD' THEN
CASE
WHEN @priceFormat = 'Thousand' THEN sum(b.value_lastmonth) / 1000 / @exchange_rate
WHEN @priceFormat = 'Million' THEN sum(b.value_lastmonth) / 1000000 / @exchange_rate
WHEN @priceFormat = 'Billion' THEN sum(b.value_lastmonth) / 1000000000 / @exchange_rate
ELSE sum(b.value_lastmonth) / @exchange_rate
END
ELSE
CASE
WHEN @priceFormat = 'Thousand' THEN sum(b.value_lastmonth) / 1000
WHEN @priceFormat = 'Million' THEN sum(b.value_lastmonth) / 1000000
WHEN @priceFormat = 'Billion' THEN sum(b.value_lastmonth) / 1000000000
ELSE sum(b.value_lastmonth)
END
END AS 'MOM',
--%MOM
(sum(recent)/sum(value_lastmonth)-1) * 100 as '%MOM',
CASE
WHEN @currencyType = 'USD' THEN
CASE
WHEN @priceFormat = 'Thousand' THEN sum(b.value_lastyear) / 1000 / @exchange_rate
WHEN @priceFormat = 'Million' THEN sum(b.value_lastyear) / 1000000 / @exchange_rate
WHEN @priceFormat = 'Billion' THEN sum(b.value_lastyear) / 1000000000 / @exchange_rate
ELSE sum(b.value_lastyear) / @exchange_rate
END
ELSE
CASE
WHEN @priceFormat = 'Thousand' THEN sum(b.value_lastyear) / 1000
WHEN @priceFormat = 'Million' THEN sum(b.value_lastyear) / 1000000
WHEN @priceFormat = 'Billion' THEN sum(b.value_lastyear) / 1000000000
ELSE sum(b.value_lastyear)
END
END AS 'Year before[ly]',
(SUM(b.recent) - SUM(b.value_lastyear)) / NULLIF(SUM(b.value_lastyear), 0) * 100 AS 'Chg%[chg]',
b.row_class AS 'rowclass'
FROM cdc_KT1S_Release_App_2024..pl_report b
where b.month is not null and (@filterDepartment = '' OR b.ma_bp IN (SELECT REPLACE(value, '''', '') FROM STRING_SPLIT(@filterDepartment, ',')))
and (@version = '' OR b.Version IN (SELECT REPLACE(value, '''', '') FROM STRING_SPLIT(@version, ',')))
and (b.date BETWEEN @startDate AND @endDate)
GROUP BY
CASE
WHEN @language = 'vni' THEN b.description
WHEN @language = 'eng' THEN b.e_name
END,
b.row_class,
b.pos,
b.date,
b.month,
b.year,
b.code
ORDER BY b.pos, b.date, b.month, b.year;
select 'dbr.javascript', "$('.spark').sparkline('html', { type: 'line', height: '30px', width: '220px' });", 'onload';
select @startDate,'and', @endDate;
END
go