File: D:/web/hyperflight/inxpress/inxpress - Copy (4).asp
<%@ Language="VBScript" %>
<%
Option Explicit
'=== Helper Functions ===
Function IIf(expr, truePart, falsePart)
If expr Then IIf = truePart Else IIf = falsePart
End Function
Function FmtNum(val)
Dim n
If IsNull(val) Then FmtNum = "" : Exit Function
On Error Resume Next
n = CDbl(val)
On Error GoTo 0
If n = 0 Then FmtNum = "" Else FmtNum = FormatNumber(n, 2, -1, 0, -1)
End Function
Function NumVal(v)
If IsNull(v) Or Trim(v & "") = "" Then NumVal = 0 Else NumVal = CDbl(v)
End Function
Function SafeHTML(val)
On Error Resume Next
If IsNull(val) Then
SafeHTML = ""
Else
SafeHTML = Server.HTMLEncode(CStr(val))
End If
If Err.Number <> 0 Then
SafeHTML = ""
Err.Clear
End If
On Error GoTo 0
End Function
Function CleanServiceType(txt)
If IsNull(txt) Then CleanServiceType = "" : Exit Function
Dim s : s = Trim(CStr(txt))
If Right(s, 10) = " - Package" Then s = Left(s, Len(s) - 10)
CleanServiceType = Server.HTMLEncode(s)
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
'=== Connect ===
Const PAGE_SIZE = 10000
Const DSN = "MySQL_hyperflight"
Dim conn : Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "DSN=" & DSN
'=== Filters ===
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"
'=== WHERE ===
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,"'","''") & "'"
If missingOrders Then
whereSQL = whereSQL & " AND NOT EXISTS (SELECT 1 FROM orders o WHERE o.OrderNo = s.Reference)"
End If
If duplicateRefs Then
whereSQL = whereSQL & _
" AND s.Reference <> '' AND s.Reference IN (" & _
"SELECT Reference FROM inxpress_shipments_parsed WHERE Reference <> '' GROUP BY Reference HAVING COUNT(*) > 1)"
End If
'=== SQL ===
Dim sql : sql = "SELECT s.*, d.ShipmentDetails, d.ReceiverAddress, d.PiecesWeightDimensionsZone, d.Charges, " & _
"d.Total AS DetailTotal, d.Invoice_Number FROM inxpress_shipments_parsed s " & _
"LEFT JOIN inxpress_shipments d ON s.shipment_id = d.shipment_id" & _
whereSQL & " ORDER BY s." & sortField & " " & sortDir & " LIMIT " & PAGE_SIZE
Dim rs : Set rs = conn.Execute(sql)
%>
<!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-sm th,.table-sm td{padding:0.4rem 0.5rem;}
.table thead th{position:sticky;top:0;background:#f8f9fa;}
tfoot td{font-weight:bold;background:#e9f7ef;}
tr.duplicate-row td{background-color:#fff6c9!important;}
td.num,th.num{text-align:right;}
.modal-lg{max-width:900px;}
</style>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
<script>
function showShipment(btn){
const details = btn.dataset;
document.getElementById('m_id').innerText = details.id;
document.getElementById('m_invoice').innerText = details.invoice;
document.getElementById('m_shipdet').innerText = details.shipdet;
document.getElementById('m_recv').innerText = details.recv;
document.getElementById('m_pieces').innerText = details.pieces;
document.getElementById('m_charges').innerText = details.charges;
document.getElementById('m_total').innerText = details.total;
const modal = new bootstrap.Modal(document.getElementById('shipmentModal'));
modal.show();
}
</script>
</head>
<body>
<div class="container-fluid">
<h3>InXpress Shipments</h3>
<div class="table-responsive">
<table class="table table-sm table-striped table-bordered">
<thead><tr>
<th class="num">ID</th><th>Carrier</th><th>Ship Date</th><th>Reference</th><th>Receiver</th><th>Country</th>
<th>Service Type</th><th class="num">Weight</th><th class="num">Length</th><th class="num">Base (£)</th>
<th class="num">Fuel (£)</th><th class="num">Other (£)</th><th class="num">Net (£)</th>
<th class="num">VAT (£)</th><th class="num total">Total (£)</th>
</tr></thead><tbody>
<%
Dim refCount : Set refCount = Server.CreateObject("Scripting.Dictionary")
If Not rs.EOF Then rs.MoveFirst
Do Until rs.EOF
Dim highlight, rid : rid=Trim(rs("Reference")&"")
highlight = ""
If Not duplicateRefs Then
If refCount.Exists(rid) Then highlight=" class='duplicate-row'"
refCount(rid)=1
End If
%>
<tr<%=highlight%>>
<td class="num">
<button class="btn btn-link p-0 m-0" type="button" onclick="showShipment(this)"
data-id="<%=rs("shipment_id")%>"
data-invoice="<%=SafeHTML(rs("Invoice_Number"))%>"
data-shipdet="<%=Replace(SafeHTML(rs("ShipmentDetails")),"""",""")%>"
data-recv="<%=Replace(SafeHTML(rs("ReceiverAddress")),"""",""")%>"
data-pieces="<%=Replace(SafeHTML(rs("PiecesWeightDimensionsZone")),"""",""")%>"
data-charges="<%=Replace(SafeHTML(rs("Charges")),"""",""")%>"
data-total="<%=FmtNum(rs("DetailTotal"))%>">
<%=rs("shipment_id")%></button>
</td>
<td><%=SafeHTML(rs("Carrier"))%></td>
<td><%=Day(rs("ShipDate"))&"/"&Month(rs("ShipDate"))&"/"&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"><%=FmtNum(rs("WeightKg"))%></td>
<td class="num"><%=FmtNum(rs("Length"))%></td>
<td class="num"><%=FmtNum(rs("BaseCharge"))%></td>
<td class="num"><%=FmtNum(rs("FuelSurcharge"))%></td>
<td class="num"><%=FmtNum(rs("OtherCharges"))%></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
rs.Close : Set rs = Nothing
conn.Close : Set conn = Nothing
%>
</tbody></table>
</div>
</div>
<!-- Modal -->
<div class="modal fade" id="shipmentModal" tabindex="-1">
<div class="modal-dialog modal-lg"><div class="modal-content">
<div class="modal-header"><h5 class="modal-title">Shipment Details</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button></div>
<div class="modal-body">
<p><strong>ID:</strong> <span id="m_id"></span></p>
<p><strong>Invoice:</strong> <span id="m_invoice"></span></p>
<p><strong>Shipment Details:</strong><br><span id="m_shipdet"></span></p>
<p><strong>Receiver Address:</strong><br><span id="m_recv"></span></p>
<p><strong>Pieces / Weight / Dimensions / Zone:</strong><br><span id="m_pieces"></span></p>
<p><strong>Charges:</strong><br><span id="m_charges"></span></p>
<p><strong>Total:</strong> £<span id="m_total"></span></p>
</div>
<div class="modal-footer"><button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button></div>
</div></div>
</div>
</body>
</html>