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/hyperflight/inxpress/inxpress - Copy (2).asp
<%@ Language="VBScript" %>
<%
Option Explicit

'=== IIf Helper ===
Function IIf(expr, truePart, falsePart)
    If expr Then IIf = truePart Else IIf = falsePart
End Function

'=== Enhanced Number Formatter ===
Function FmtNum(val)
    Dim s, n
    If IsNull(val) Then FmtNum = "" : Exit Function
    s = Trim(val & "")
    If s = "" Then FmtNum = "" : Exit Function
    On Error Resume Next
    n = CDbl(val)
    If Err.Number <> 0 Then Err.Clear : On Error GoTo 0 : FmtNum = "" : Exit Function
    On Error GoTo 0
    If n = 0 Then FmtNum = "" Else FmtNum = FormatNumber(n, 2, -1, 0, -1)
End Function

Function NumVal(v)
    On Error Resume Next
    If IsNull(v) Or Trim(v & "") = "" Then
        NumVal = 0
    Else
        NumVal = CDbl(v)
    End If
    On Error GoTo 0
End Function

Function SafeHTML(val)
    If IsNull(val) Then SafeHTML = "" Else SafeHTML = Server.HTMLEncode(val)
End Function

Function CleanServiceType(txt)
    If IsNull(txt) Then
        CleanServiceType = ""
    Else
        Dim s : s = Trim(CStr(txt))
        If Right(s, 10) = " - Package" Then s = Left(s, Len(s) - 10)
        CleanServiceType = Server.HTMLEncode(s)
    End If
End Function

Function CountryFlag(code)
    If IsNull(code) Or Trim(code) = "" Then CountryFlag = "" : Exit Function
    code = UCase(Trim(code))
    CountryFlag = "<img src='/common/geoip/flags/" & code & ".svg' alt='" & code & _
        "' style='width:20px;height:14px;border:1px solid #ccc;margin-right:4px;vertical-align:middle;'>"
End Function

Response.Expires = -1
Response.Buffer = True

'=== CONFIG ===
Const PAGE_SIZE = 10000
Const DSN = "MySQL_hyperflight"
Const TABLE_NAME = "inxpress_shipments_parsed"

Dim conn : Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "DSN=" & DSN

Dim searchText, carrierSel, invoiceSel, countrySel, sortField, sortDir, missingOrders, duplicateRefs
searchText    = Trim(Request("search"))
carrierSel    = Trim(Request("carrier"))
invoiceSel    = Trim(Request("invoice"))
countrySel    = Trim(Request("country"))
sortField     = Trim(Request("sort"))
sortDir       = UCase(Trim(Request("dir")))
missingOrders = (Request("missingorders") = "1")
duplicateRefs = (Request("duplicates") = "1")

If sortField = "" Then sortField = "shipment_id"
If sortDir <> "DESC" Then sortDir = "ASC"

Dim whereSQL : whereSQL = " WHERE 1=1"
If searchText <> "" Then whereSQL = whereSQL & " AND (s.Reference LIKE '%" & Replace(searchText,"'","''") & _
    "%' OR s.ReceiverName LIKE '%" & Replace(searchText,"'","''") & "%')"
If carrierSel <> "" Then whereSQL = whereSQL & " AND s.Carrier='" & Replace(carrierSel,"'","''") & "'"
If invoiceSel <> "" Then whereSQL = whereSQL & " AND s.InvoiceNumber='" & Replace(invoiceSel,"'","''") & "'"
If countrySel <> "" Then whereSQL = whereSQL & " AND s.DestCountry='" & Replace(countrySel,"'","''") & "'"

' Filter: missing orders
If missingOrders Then
    whereSQL = whereSQL & " AND NOT EXISTS (SELECT 1 FROM orders o WHERE o.OrderNo = s.Reference)"
End If

' Filter: duplicate references
If duplicateRefs Then
    whereSQL = whereSQL & _
      " AND s.Reference <> '' AND s.Reference IN (" & _
      "SELECT Reference FROM " & TABLE_NAME & _
      " WHERE Reference <> '' GROUP BY Reference HAVING COUNT(*) > 1)"
End If

Dim sortSQL : sortSQL = " ORDER BY s." & sortField & " " & sortDir
Dim sql : sql = "SELECT s.* FROM " & TABLE_NAME & " s" & whereSQL & sortSQL & " LIMIT " & PAGE_SIZE
Dim rs : Set rs = conn.Execute(sql)
Dim totalCount : totalCount = conn.Execute("SELECT COUNT(*) FROM " & TABLE_NAME & " s" & whereSQL)(0)

' Dropdowns
Dim rsC, rsI, rsCn
Set rsC = conn.Execute("SELECT DISTINCT Carrier FROM " & TABLE_NAME & " ORDER BY Carrier")
Set rsI = conn.Execute("SELECT DISTINCT InvoiceNumber FROM " & TABLE_NAME & " ORDER BY InvoiceNumber DESC")
Set rsCn = conn.Execute("SELECT DISTINCT DestCountry FROM " & TABLE_NAME & " ORDER BY DestCountry")
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>InXpress Shipments</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
body{padding:20px;}
.table-responsive{max-height:85vh;overflow-y:auto;}
.table-sm th,.table-sm td{padding:0.4rem 0.5rem;}
.table thead th{position:sticky;top:0;background:#f8f9fa;z-index:2;}
tfoot tr{position:sticky;bottom:0;background:#e9f7ef;z-index:2;}
tfoot td{font-weight:bold;border-top:2px solid #999;}
td.num,th.num{text-align:right;}
td.total,th.total{font-weight:bold;background:#f9f9f9;}
th a.sort{text-decoration:none;color:inherit;}
th.active-sort{background:#e0f0ff!important;color:#004085;}
th.active-sort a.sort::after{content:" ▲";font-size:0.8em;}
th.active-sort.desc a.sort::after{content:" ▼";}
</style>
<script>
function autoSubmitFilters() { document.getElementById('filterForm').submit(); }
</script>
</head>
<body>
<div class="container-fluid">
<h3 class="mb-3">InXpress Shipments</h3>

<form id="filterForm" class="row row-cols-lg-auto g-2 align-items-center mb-3" method="get">
  <div class="col"><input type="text" name="search" value="<%=SafeHTML(searchText)%>" class="form-control" placeholder="Search Reference or Receiver"></div>
  <div class="col">
    <select name="carrier" class="form-select" onchange="autoSubmitFilters()">
      <option value="">All Carriers</option>
      <% Do Until rsC.EOF
        Response.Write "<option value='" & SafeHTML(rsC("Carrier")) & "'"
        If carrierSel=rsC("Carrier") Then Response.Write " selected"
        Response.Write ">" & SafeHTML(rsC("Carrier")) & "</option>"
        rsC.MoveNext : Loop : rsC.Close %>
    </select>
  </div>
  <div class="col">
    <select name="invoice" class="form-select" onchange="autoSubmitFilters()">
      <option value="">All Invoices</option>
      <% Do Until rsI.EOF
        Response.Write "<option value='" & SafeHTML(rsI("InvoiceNumber")) & "'"
        If invoiceSel=rsI("InvoiceNumber") Then Response.Write " selected"
        Response.Write ">" & SafeHTML(rsI("InvoiceNumber")) & "</option>"
        rsI.MoveNext : Loop : rsI.Close %>
    </select>
  </div>
  <div class="col">
    <select name="country" class="form-select" onchange="autoSubmitFilters()">
      <option value="">All Countries</option>
      <% Do Until rsCn.EOF
        Response.Write "<option value='" & SafeHTML(rsCn("DestCountry")) & "'"
        If countrySel=rsCn("DestCountry") Then Response.Write " selected"
        Response.Write ">" & SafeHTML(rsCn("DestCountry")) & "</option>"
        rsCn.MoveNext : Loop : rsCn.Close %>
    </select>
  </div>

  <div class="col form-check">
    <input class="form-check-input" type="checkbox" name="missingorders" value="1" id="missingorders" onchange="autoSubmitFilters()" <%=IIf(missingOrders,"checked","")%>>
    <label class="form-check-label" for="missingorders">Only show where Reference not in Orders</label>
  </div>

  <div class="col form-check">
    <input class="form-check-input" type="checkbox" name="duplicates" value="1" id="duplicates" onchange="autoSubmitFilters()" <%=IIf(duplicateRefs,"checked","")%>>
    <label class="form-check-label" for="duplicates">Only show duplicate References</label>
  </div>

  <div class="col">
    <button class="btn btn-primary btn-sm">Filter</button>
    <a href="inxpress.asp" class="btn btn-secondary btn-sm">Reset</a>
  </div>
</form>

<div class="table-responsive">
<table class="table table-sm table-striped table-bordered align-middle">
<thead class="table-light">
<tr>
<%
Dim cols, headers, i, fieldName, headerName, sortClass
cols = Array("shipment_id","Carrier","ShipDate","Reference","ReceiverName","DestCountry","ServiceType","WeightKg","Length","BaseCharge","FuelSurcharge","OtherCharges","NetAmount","VATAmount","Total")
headers = Array("ID","Carrier","Ship Date","Reference","Receiver","Country","Service Type","Weight","Length","Base (£)","Fuel (£)","Other (£)","Net (£)","VAT (£)","Total (£)")

For i = 0 To UBound(cols)
    fieldName = cols(i)
    headerName = headers(i)
    sortClass = ""
    If sortField = fieldName Then sortClass = "active-sort " & LCase(sortDir)
    Dim numClass
    numClass = ""
    If InStr(headerName,"£")>0 Or fieldName="WeightKg" Or fieldName="Length" Or fieldName="shipment_id" Then numClass="num"
    If fieldName="Total" Then numClass=numClass & " total"
    Response.Write "<th class='" & sortClass & " " & numClass & "'>"
    Response.Write "<a class='sort' href='?sort=" & fieldName & "&dir=" & IIf(sortDir="ASC","DESC","ASC") & _
      "&search=" & Server.URLEncode(searchText) & "&carrier=" & Server.URLEncode(carrierSel) & _
      "&invoice=" & Server.URLEncode(invoiceSel) & "&country=" & Server.URLEncode(countrySel) & _
      IIf(missingOrders,"&missingorders=1","") & IIf(duplicateRefs,"&duplicates=1","") & "'>" & headerName & "</a></th>"
Next
%>
</tr>
</thead>
<tbody>
<%
Dim totalBase, totalFuel, totalOther, totalNet, totalVAT, totalGrand
totalBase=0 : totalFuel=0 : totalOther=0 : totalNet=0 : totalVAT=0 : totalGrand=0

Do Until rs.EOF
  Dim otherTotal
  otherTotal = NumVal(rs("Handling")) + NumVal(rs("Insurance")) + NumVal(rs("AreaSurcharge")) + NumVal(rs("ProcessingFee")) + NumVal(rs("ResidentialFee")) + NumVal(rs("OtherCharges"))
  totalBase = totalBase + NumVal(rs("BaseCharge"))
  totalFuel = totalFuel + NumVal(rs("FuelSurcharge"))
  totalOther = totalOther + otherTotal
  totalNet  = totalNet  + NumVal(rs("NetAmount"))
  totalVAT  = totalVAT  + NumVal(rs("VATAmount"))
  totalGrand = totalGrand + NumVal(rs("Total"))
%>
<tr>
  <td class="num"><%=rs("shipment_id")%></td>
  <td><%=SafeHTML(rs("Carrier"))%></td>
  <td><%=IIf(IsNull(rs("ShipDate")),"",Right("0"&Day(rs("ShipDate")),2)&"/"&Right("0"&Month(rs("ShipDate")),2)&"/"&Year(rs("ShipDate")))%></td>
  <td><%=SafeHTML(rs("Reference"))%></td>
  <td><%=SafeHTML(rs("ReceiverName"))%></td>
  <td><%=CountryFlag(rs("DestCountry")) & SafeHTML(rs("DestCountry"))%></td>
  <td><%=CleanServiceType(rs("ServiceType"))%></td>
  <td class="num"><%=SafeHTML(rs("WeightKg"))%></td>
  <td class="num"><%=SafeHTML(rs("Length"))%></td>
  <td class="num"><%=FmtNum(rs("BaseCharge"))%></td>
  <td class="num"><%=FmtNum(rs("FuelSurcharge"))%></td>
  <td class="num"><%=FmtNum(otherTotal)%></td>
  <td class="num"><%=FmtNum(rs("NetAmount"))%></td>
  <td class="num"><%=FmtNum(rs("VATAmount"))%></td>
  <td class="num total"><%=FmtNum(rs("Total"))%></td>
</tr>
<%
  rs.MoveNext
Loop
%>
</tbody>
<tfoot>
<tr>
  <td colspan="9" class="text-end">Totals:</td>
  <td class="num"><%=FmtNum(totalBase)%></td>
  <td class="num"><%=FmtNum(totalFuel)%></td>
  <td class="num"><%=FmtNum(totalOther)%></td>
  <td class="num"><%=FmtNum(totalNet)%></td>
  <td class="num"><%=FmtNum(totalVAT)%></td>
  <td class="num total"><%=FmtNum(totalGrand)%></td>
</tr>
</tfoot>
</table>
</div>

<p class="text-muted mt-2">Total records: <%=totalCount%></p>
</div>
</body>
</html>
<%
rs.Close : Set rs = Nothing
conn.Close : Set conn = Nothing
%>