File: D:/web/hyperflight/apps/~tab/index - Copy.asp
<%Option Explicit%>
<!--#include virtual="/dbfunctions.asp"-->
<!--#include virtual="/apputils.asp"-->
<%DisableCache%>
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=windows-1252">
<meta charset="windows-1252" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Orders</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<script type='text/javascript' src='https://s3.amazonaws.com/dynatable-docs-assets/js/jquery-1.9.1.min.js'></script>
<link rel="stylesheet" media="all" href="https://s3.amazonaws.com/dynatable-docs-assets/css/jquery.dynatable.css" />
<script type='text/javascript' src='https://s3.amazonaws.com/dynatable-docs-assets/js/jquery.dynatable.js'></script>
<link href="flags.css" rel=stylesheet type="text/css">
</head>
<body>
<%
' (SS,8/8/19) modified to add cookie feature for access outside of these IP addresses, cookie gets created when page accessed in one of these IP addresses
Dim LIP, LCookie
Const TAB_ACCESS_COOKIE_VALUE = "t!L^:SZ+6IoK"
LIP = Request.ServerVariables("REMOTE_ADDR")
LCookie = GetCookie("TabAccess")
If LIP = "192.168.1.2" Or LIP = "88.98.246.98" Or LIP = "80.229.231.82" Or LIP = "86.10.87.170" Or LCookie = TAB_ACCESS_COOKIE_VALUE Then
If LCookie = "" Then SetCookie "TabAccess", TAB_ACCESS_COOKIE_VALUE
ShowWIPTable
ShowOrdersTable
Else
Response.Write "No access for IP: " & LIP & BR & NL
End If
%>
</body>
</html>
<%
' (SS,30/4/19)
Sub ShowWIPTable
Dim LSQL
' , MIN(Date) AS Oldest, MAX(Date) AS Newest
LSQL = "SELECT a.Stat, a.Status, COUNT(*) AS Orders, FORMAT(SUM(Total), 0) AS Total FROM (" & GetOrdersSQL & ") a INNER JOIN status s ON s.Status = a.Status GROUP BY Status ORDER BY s.SortOrder"
OpenQuery(LSQL)
ShowTableHeader "S" ' should be after OpenQuery
Do While Not EndOfQuery
ShowTableRecord "S"
NextQueryRecord
Loop
ShowTableFooter "S"
End Sub
Sub ShowOrdersTable
OpenQuery(GetOrdersSQL)
ShowTableHeader "D" ' should be after OpenQuery
Do While Not EndOfQuery
ShowTableRecord "D"
NextQueryRecord
Loop
ShowTableFooter "D"
End Sub
' (SS,30/4/19)
Function GetOrdersSQL
Dim LSQL1, LSQL2
' (SS,25/5/19) removed FORMAT from GrandTotal to fix issue where values with commas were ignored in WIP totals
LSQL1 = "SELECT OrderNo, DATE_FORMAT(DateTimeOrdered, '%d/%m') AS Date, " &_
"orders.Status, status.Stat, " &_
"PaymentMethod AS Pay, " &_
"countries.CodeA2 AS Country, " &_
"GrandTotal AS Total, " &_
"TRIM(CONCAT(FirstName, ' ', Surname)) AS Name, " &_
"Telephone, EmailAddress AS Email, " &_
"Message AS CustomerMessage, Notes AS InternalNotes, SessionID, IPAddress " &_
"FROM orders " &_
"LEFT JOIN countries ON countries.Country = IF(orders.DeliveryAddressSameAsInvoice, orders.Country, orders.DeliveryCountry) " &_
"INNER JOIN status ON status.Status = orders.Status "
LSQL2 = "(" + LSQL1 + " WHERE orders.Status <> 'CANCELLED' AND orders.Status <> 'COMPLETED')" ' no limit on status other than CANCELLED and COMPLETED
LSQL2 = LSQL2 + " UNION ALL (" + LSQL1 + " WHERE orders.Status = 'CANCELLED' OR orders.Status = 'COMPLETED' ORDER BY OrderNo DESC LIMIT 1000)" ' limit for CANCELLED or COMPLETED
LSQL2 = LSQL2 + " ORDER BY OrderNo DESC"
GetOrdersSQL = LSQL2
End Function
Sub ShowTableHeader(AType)
' for each field
Dim LoRS
Set LoRS = oRS ' *** oRS is a global defined in dbfunctions.asp perhaps create a function to return this, or a create a different solutions
%>
<div class="dynatable-demo">
<%If AType = "D" Then%>
<div id="search-example-status-filter" style="float: left; margin: 5px">
Status:
<select id="search-stat" name="stat">
<option></option>
<option>CMP</option>
<option>REC</option>
<option>POA</option>
<option>AWT</option>
<option>PLA</option>
<option>CAN</option>
</select>
Search: <input type="search" id="dynatable-query-search" data-dynatable-query="search" style="width:150px">
<button id="clear-search-button" type="button" class="btn btn-primary btn-sm">Clear</button>
</div>
<%Else%>
<script>
function ClickStatus(AStat) {
$('#search-stat').val(AStat).change();
}
</script>
<%End If%>
<table id="search-example<%=AType%>" class="table table-responsive table-sm table-bordered table-striped">
<thead>
<tr>
<%
Dim i, LFieldName, LFieldCount
LFieldCount = oRS.Fields.Count
For i = 0 To LFieldCount - 1
LFieldName = LoRS.Fields.Item(i).Name
If LFieldName = "OrderNo" Then
LFieldName = "Order"
'ElseIf LFieldName = "Status" Then
' LFieldName = "Stat"
ElseIf LFieldName = "Country" Then
LFieldName = "Ctry"
ElseIf LFieldName = "CustomerMessage" Then
LFieldName = "Customer Message" & " "
ElseIf LFieldName = "InternalNotes" Then
LFieldName = "Internal Notes" & " "
End If
If Not ((AType = "D" And LFieldName = "Status") Or LFieldName = "SessionID" Or LFieldName = "IPAddress") Then
Response.Write "<th>" & LFieldName & "</th>"
End If
Next
%>
</tr>
</thead>
<tbody>
<%
End Sub
Sub ShowTableRecord(AType)
' for each field
Dim LoRS
Set LoRS = oRS ' *** oRS is a global defined in dbfunctions.asp perhaps create a function to return this, or a create a different solutions
%>
<tr>
<%
Dim i, LFieldName, LFieldValue, LFieldCount
LFieldCount = oRS.Fields.Count
For i = 0 To LFieldCount - 1
LFieldName = LoRS.Fields.Item(i).Name
LFieldValue = LoRS.Fields.Item(i)
' if OrderNo then added the link to show order in new tab
If LFieldName = "OrderNo" Then
LFieldValue = "<a target=""_blank"" href=""/order-details.asp?orderno=" & LFieldValue & "&sid=" & GetFieldValue("SessionID") & "&ip=" & GetFieldValue("IPAddress") & """>" & LFieldValue & "</a>"
ElseIf LFieldName = "Status" Then
LFieldValue = "<a href=""#"" onclick=""ClickStatus('" & GetFieldValue("Stat") & "')"">" & LFieldValue & "</a>"
' If LFieldValue = "COMPLETED" Then
' LFieldValue = "CMP"
' ElseIf LFieldValue = "PAYMENT RECEIVED" Then
' LFieldValue = "REC"
' ElseIf LFieldValue = "PAYMENT ON ACCOUNT" Then
' LFieldValue = "POA"
' ElseIf LFieldValue = "AWAITING PAYMENT" Then
' LFieldValue = "AWT"
' ElseIf LFieldValue = "ORDER PLACED" Then
' LFieldValue = "PLA"
' ElseIf LFieldValue = "CANCELLED" Then
' LFieldValue = "CAN"
' Else
' LFieldValue = "???"
' End If
ElseIf LFieldName = "Pay" Then
If LFieldValue = "CHEQUE" Then
LFieldValue = "CHQ"
ElseIf LFieldValue = "CASH" Then
LFieldValue = "CSH"
ElseIf LFieldValue = "OTHER" Then
LFieldValue = "OTH"
ElseIf LFieldValue = "PAYPAL" Then
LFieldValue = "PP"
ElseIf LFieldValue = "PAYPAL MANUAL" Then
LFieldValue = "PPM"
ElseIf LFieldValue = "PAYZONE" Then
LFieldValue = "PZ"
ElseIf LFieldValue = "BANK TRANSFER" Then
LFieldValue = "B"
ElseIf LFieldValue = "BANK TRANSFER - GBP" Then
LFieldValue = "BGB"
ElseIf LFieldValue = "BANK TRANSFER - EUR" Then
LFieldValue = "BEU"
ElseIf LFieldValue = "BANK TRANSFER - USD" Then
LFieldValue = "BUS"
ElseIf LFieldValue = "" Then
LFieldValue = ""
Else
LFieldValue = "???"
End If
ElseIf LFieldName = "Country" Then
LFieldValue = "<img src=""blank.gif"" class=""flag flag-" & LCase(LFieldValue) & """ />" & " " & LFieldValue
ElseIf LFieldName = "Email" Then
LFieldValue = "<a href=""mailto:" & LFieldValue & """>" & LFieldValue & "</a>"
ElseIf LFieldName = "Total" Then
LFieldValue = "£" & FormatNumber(LFieldValue, 0) ' (SS,25/5/19) added FormatNumber here rather than in SQL because summary WIP SQL was ignoring records with commas in Total
ElseIf LFieldName = "Name" Then
LFieldValue = ReplaceStr(LFieldValue, " ", " ")
End If
If Not ((AType = "D" And LFieldName = "Status") Or LFieldName = "SessionID" Or LFieldName = "IPAddress") Then
Response.Write "<td>" & LFieldValue & "</td>"
End If
Next
%>
</tr>
<%
End Sub
Sub ShowTableFooter(AType)
%>
</tbody>
</table>
</div>
<script>
(function() {
var dynatable = $('#search-example<%=AType%>').dynatable({
features: {
paginate: <%=IIF(AType = "D", "true", "false")%>,
recordCount: <%=IIF(AType = "D", "true", "false")%>,
sorting: false,
perPageSelect: false,
search: false
},
dataset: {
perPageDefault: 100
}
}).data('dynatable');
$('#search-stat').change( function() {
var value = $(this).val();
if (value === "") {
dynatable.queries.remove("stat");
} else {
dynatable.queries.add("stat",value);
}
dynatable.process();
});
$('#dynatable-query-search').change(function() {
var value = $(this).val();
if (value === "") {
dynatable.queries.remove("search");
} else {
ClickStatus(""); // (SS,1/5/19) clear the status filter to ensure search across all instead of selected status
dynatable.queries.add("search", value);
}
dynatable.process();
});
$('#clear-search-button').click( function(e) {
dynatable.sorts.clear();
dynatable.queries.remove("search");
$('#dynatable-query-search').val("");
dynatable.process();
e.preventDefault()
});
})();
// (SS,2/5/19) following from https://techoverflow.net/2018/03/30/copying-strings-to-the-clipboard-using-pure-javascript/
function copyStringToClipboard(str) {
// Create new element
var el = document.createElement('textarea');
// Set value (string to be copied)
el.value = str;
// Set non-editable to avoid focus and move outside of view
el.setAttribute('readonly', '');
el.style = {position: 'absolute', left: '-9999px'};
document.body.appendChild(el);
// Select text inside element
el.select();
// Copy text to clipboard
document.execCommand('copy');
// Remove temporary element
document.body.removeChild(el);
}
</script>
<%
End Sub
%>