HEX
Server: Microsoft-IIS/10.0
System: Windows NT ITPWINWEBSVR22 10.0 build 20348 (Windows Server 2022) AMD64
User: www.conferencesearch.co.uk (0)
PHP: 8.3.30
Disabled: NONE
Upload Files
File: D:/web/castironradiatorcentre/changes prev/2024-02-29 (old reports)/radiator-quota-v1.asp
<%Option Explicit%>
<!--#include file="dbfunctions.asp"-->
<!--#include file="apputils.asp"-->
<!--#include file="customutils.asp"-->
<%DisableCache%>

<html>
<head>
<title>Radiator Quota</title>
<link href="css/all.min.css" rel="stylesheet" />
<style>
.table td, .table th {
   text-align: center;   
}
.table2 th {
   text-align: right;   
}
</style>
</head>
<body>

<div class="container">

<h1>Daily Radiator Quota</h1>

<table class="table table2 table-responsive table-sm table-bordered table-striped" style="width: auto;"> 
<%
CustomOrderingCheckDailyQuota(True)
%>
</table>
<%
  Dim LSQL
  ' (SS,24/4/20) changed from past 31 to 60 days
  'LSQL = _
  '  "SELECT DAYNAME(o.DateTimeOrdered) AS Day, DATE(o.DateTimeOrdered) AS Date, SUM(od.Qty) AS Radiators, COUNT(DISTINCT o.OrderNo) AS Orders " &_
  '  "FROM orderdetails od " &_
  '  "INNER JOIN orders o ON o.OrderNo = od.OrderNo " &_
  '  "INNER JOIN products p ON p.ProductID = od.ProductID " &_
  '  "LEFT JOIN product_attributes pa ON pa.ProductID = od.ProductID AND pa.AttributeID = 1 " &_
  '  "WHERE " &_
  '  "DATE(o.DateTimeOrdered) BETWEEN DATE_SUB(CURDATE(), INTERVAL 31 DAY) AND CURDATE() AND " &_
  '  "(o.Status = 'COMPLETED' OR o.Status = 'PAYMENT RECEIVED' OR o.Status = 'AWAITING PAYMENT') AND " &_
  '  "AttributeValue = 'Radiator' AND SubproductOrderDetailID IS NULL " &_
  '  "GROUP BY Date " &_
  '  "ORDER BY Date DESC"  
  
  ' above is older version which doesn't show empty days, following links to common calendar table to show all days
    
  LSQL =_   
    "SELECT DAYNAME(c.CalendarDate) AS Day, c.CalendarDate AS Date, a.Radiators, a.Orders, DATE_FORMAT(a.Latest, '%H:%i') AS Latest " &_
    "FROM common.Calendar c " &_
    "LEFT JOIN " &_
    "( " &_
    "SELECT DATE(o.DateTimeOrdered) AS Date, SUM(od.Qty) AS Radiators, COUNT(DISTINCT o.OrderNo) AS Orders, MAX(o.DateTimeOrdered) AS Latest " &_
    "FROM orderdetails od " &_
    "INNER JOIN orders o ON o.OrderNo = od.OrderNo " &_
    "INNER JOIN products p ON p.ProductID = od.ProductID " &_
    "LEFT JOIN product_attributes pa ON pa.ProductID = od.ProductID AND pa.AttributeID = 1 " &_
    "WHERE " &_
    "DATE(o.DateTimeOrdered) BETWEEN DATE_SUB(CURDATE(), INTERVAL 60 DAY) AND CURDATE() AND " &_
    "(o.Status = 'COMPLETED' OR o.Status = 'PAYMENT RECEIVED' OR o.Status = 'AWAITING PAYMENT') AND " &_
    "AttributeValue = 'Radiator' AND SubproductOrderDetailID IS NULL " &_
    "GROUP BY Date " &_
    ") a ON a.Date = c.CalendarDate " &_
    "WHERE c.CalendarDate BETWEEN DATE_SUB(CURDATE(), INTERVAL 60 DAY) AND CURDATE() " &_
    "ORDER BY Date DESC"
  
  ' (SS,25/4/20) replaced above with new SQL held in settings (easy to store by copying and pasting from EMS MySQL Manager)
  ' this new version adds a WeeklyCumulative field
  LSQL = GetSettingMemo("SQLStore", "RadiatorQuota")
  
  ' SET &days = 373;
  ' SET @startdate = SUBDATE(DATE_SUB(CURDATE(), INTERVAL @days DAY), WEEKDAY(DATE_SUB(CURDATE(), INTERVAL @days DAY)));
  ' ODBC only allows one SQL statement, so doing a replace here, (could get around this some other way, even add a stored function or view) (can't use views, they don't allow more than one statement)
  ' ODBC might have an option to get around this
  Dim LDays, LStartDate
  LDays = 500
  LStartDate = "SUBDATE(DATE_SUB(CURDATE(), INTERVAL @days DAY), WEEKDAY(DATE_SUB(CURDATE(), INTERVAL @days DAY)))"
  LStartDate = ReplaceStr(LStartDate, "@days", CStr(LDays))
  LSQL = ReplaceStr(LSQL, "@startdate", LStartDate)  
  
  L_ShowTable LSQL
%>


<%Finalise%>

</div>

</body>
</html>

<%

Sub L_ShowTable(ASQL)
  OpenQuery(ASQL)
  L_ShowTableHeader
  Do While Not EndOfQuery
    L_ShowTableRecord
    NextQueryRecord
  Loop
  L_ShowTableFooter
End Sub

Sub L_ShowTableHeader
  ' 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 
  
  %>

<table class="table table-responsive table-sm table-bordered table-striped" style="width: auto;"> 
  <thead>
    <tr>
  <%
  Dim i, LFieldName, LFieldCount
  
  LFieldCount = oRS.Fields.Count
    
  For i = 0 To LFieldCount - 1
    LFieldName = LoRS.Fields.Item(i).Name
    Response.Write "<th>" & LFieldName & "</th>"
  Next
%>  
    </tr>
  </thead>
  <tbody>
<%
End Sub

Sub L_ShowTableRecord
  ' 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) 
    Response.Write "<td>" & LFieldValue & "</td>"
  Next
%>  
    </tr>
<%
End Sub

Sub L_ShowTableFooter
%>
  </tbody>
</table>
<%
End Sub
%>