File: D:/web/hyperflight/! bs3/inc-template-sales-map.asp
<%
' (SS,7/12/11) sales map
' (SS,24/3/14) added "to" to date range and default to past year if "from" and "to" not entered
' (SS,23/2/18) added to latest Bootstrap site, had add link to https://www.google.com/jsapi for this to work, also added Piechart
Sub ShowPage_salesmap
Dim LBarChart, LPieChart
LBarChart = Request("chart") = "bar"
LPieChart = Request("chart") = "pie" ' (SS,23/2/18)
%>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
<%If LBarChart Then%>
google.load('visualization', '1', {packages: ['corechart']});
<%ElseIf LPieChart Then%>
google.load('visualization', '1', {packages: ['corechart']});
<%Else%>
google.load('visualization', '1', {packages: ['geochart']});
<%End If%>
function drawVisualization() {
var data = new google.visualization.DataTable();
<%
CreateGraphValues
Dim LRegion
LRegion = Request("region")
If LRegion = "" Then LRegion = "world"
%>
<%If LBarChart Then%>
var chart = new google.visualization.BarChart(document.getElementById('visualization'))
<%ElseIf LPieChart Then%>
var chart = new google.visualization.PieChart(document.getElementById('visualization'))
<%Else%>
var chart = new google.visualization.GeoChart(document.getElementById('visualization'))
<%End If%>
var options = {};
options['width'] = 1030;
options['region'] = '<%=LRegion%>';
options['height'] = 560;
options['colorAxis'] ={minValue: 0, colors: ['#E0FFD4', '#216411']};
//options['colorAxis'] ={minValue: 0, colors: ['#E0FFD4', '#A5EF63', '#50AA00', '#267114']};
options['backgroundColor'] = '#EBF7FE';
<%If LBarChart Then%>
options['height'] = 2000;
options['legend'] = 'none';
options['chartArea'] = {height:"100%"};
<%End If%>
chart.draw(data, options);
}
google.setOnLoadCallback(drawVisualization);
</script>
<div id="visualization" style="min-height: 560px; margin-top: 15px"></div>
<div style="margin-left: 5px; margin-top: 5px">
<%
Dim LURL
LURL = GetScriptName + "?page=" + GetPageName
If Request("from") <> "" Then LURL = LURL + "&from=" + Request("from")
If Request("to") <> "" Then LURL = LURL + "&to=" + Request("to") ' (SS,24/3/14)
If Request("type") <> "" Then LURL = LURL + "&type=" + Request("type")
%>
<a style="font-size: 10px" href="<%=LURL%>">WORLD</a>
<a style="font-size: 10px" href="<%=LURL + "®ion=150"%>">EUROPE</a>
<!--<a style="font-size: 10px" href="<%=LURL + "&uk=yes"%>">WORLD+UK</a> -->
<!--<a style="font-size: 10px" href="<%=LURL + "®ion=150&uk=yes"%>">EU+UK</a> -->
<a style="font-size: 10px" href="<%=LURL + "&chart=bar"%>">BARCHART</a>
<a style="font-size: 10px" href="<%=LURL + "&chart=pie"%>">PIECHART</a>
</div>
<%
End Sub
Sub CreateGraphValues
Dim LSQL, LCount, LCountry, LIncludeUK
LSQL = "SELECT c.CodeA2, c.Country, "
If Request("type") = "orders" Then
LSQL = LSQL & "COUNT(*) AS Total "
Else
LSQL = LSQL & "SUM(GrandTotal) AS Total "
End If
LSQL = LSQL &_
"FROM orders o " &_
"INNER JOIN countries c ON c.Country = o.Country " &_
"WHERE Status <> 'CANCELLED' AND Status <> 'ORDER PLACED' "
If Request("from") <> "" Then LSQL = LSQL + " AND DateTimeOrdered >= " & ParseInt(Request("from")) ' date must be in sql format, ParseInt ensures SQL is always correct
If Request("to") <> "" Then LSQL = LSQL + " AND DateTimeOrdered <= " & ParseInt(Request("to")) ' (SS,24/3/14) added "to" parameter
If Request("from") = "" And Request("to") = "" Then LSQL = LSQL + "AND DateTimeOrdered >= DATE_SUB(NOW(),INTERVAL 1 YEAR)" ' (SS,24/3/14) default to past year if from and to not entered
LSQL = LSQL + " GROUP BY c.CodeA2 ORDER BY Total DESC"
OpenQuery(LSQL)
Response.Write("data.addColumn('string', 'Country');" & NL)
Response.Write("data.addColumn('number', '" + Iif(Request("type") = "orders", "Orders", "Sales (GBP)") & "');" & NL)
OpenQuery(LSQL)
' LIncludeUK = Request("uk") = "yes"
' (SS,23/2/18) replaced above with following to include UK by default, and exclude if uk=no
LIncludeUK = Request("uk") <> "no"
Do While Not EndOfQuery
LCountry = GetFieldValue("Country")
If Left(LCountry, 14) = "United Kingdom" Then LCountry = "United Kingdom" ' because it may be off mainland etc at the end
If LIncludeUK Or LCountry <> "United Kingdom" Then ' ignore UK
Response.Write("data.addRow(['" & LCountry & "'," & Round(GetFieldValue("Total")) & "]);" & NL)
End If
NextQueryRecord
Loop
CloseQuery
End Sub
%>