live-update-your-order
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Order Tracking System</title>
<style>
:root {
--primary: #4361ee;
--primary-light: #5a75f5;
--success: #4cc9f0;
--warning: #f8961e;
--danger: #f72585;
--complete: #2ec4b6;
--gray: #6c757d;
--light-gray: #e9ecef;
--shadow-sm: 0 1px 3px rgba(0,0,0,0.12);
--shadow-md: 0 4px 6px rgba(0,0,0,0.1);
--shadow-lg: 0 10px 15px rgba(0,0,0,0.1);
}
body {
font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
background-color: #f8f9fa;
padding: 20px;
text-align: center;
line-height: 1.6;
}
h2 {
color: #212529;
font-size: 28px;
font-weight: 700;
margin-bottom: 25px;
}
.search-container {
display: flex;
justify-content: center;
align-items: center;
margin-bottom: 20px;
gap: 12px;
max-width: 600px;
margin-left: auto;
margin-right: auto;
background: white;
padding: 16px 20px;
border-radius: 6px;
box-shadow: var(--shadow-lg);
transition: all 0.3s ease;
border: 1px solid rgba(0,0,0,0.05);
}
.search-container:focus-within {
box-shadow: 0 10px 25px rgba(67, 97, 238, 0.15);
border-color: rgba(67, 97, 238, 0.2);
transform: translateY(-2px);
}
.search-box {
position: relative;
width: 100%;
flex: 1;
}
.search-icon {
position: absolute;
left: 16px;
top: 50%;
transform: translateY(-50%);
color: #adb5bd;
z-index: 2;
}
.search-input {
padding: 14px 20px 14px 48px !important;
border-radius: 6px !important;
font-size: 16px;
border: 1px solid #e0e0e0 !important;
transition: all 0.3s ease;
background: white !important;
box-shadow: var(--shadow-sm);
}
.search-input:focus {
border-color: var(--primary) !important;
box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.15) !important;
}
.search-input::placeholder {
color: #adb5bd;
font-weight: 400;
}
.track-button {
padding: 14px 28px;
border: none;
background: linear-gradient(135deg, var(--primary), var(--primary-light));
color: white;
border-radius: 6px;
font-size: 16px;
font-weight: 600;
cursor: pointer;
transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
white-space: nowrap;
box-shadow: var(--shadow-md);
display: flex;
align-items: center;
justify-content: center;
min-width: 120px;
}
.track-button:hover {
transform: translateY(-2px);
box-shadow: 0 10px 20px rgba(67, 97, 238, 0.3);
background: linear-gradient(135deg, var(--primary-light), var(--primary));
}
.track-button:active {
transform: translateY(0);
box-shadow: var(--shadow-sm);
}
.track-button svg {
margin-right: 8px;
transition: transform 0.3s ease;
}
.track-button:hover svg {
transform: rotate(15deg);
}
@keyframes pulse {
0% { box-shadow: 0 0 0 0 rgba(67, 97, 238, 0.4); }
70% { box-shadow: 0 0 0 10px rgba(67, 97, 238, 0); }
100% { box-shadow: 0 0 0 0 rgba(67, 97, 238, 0); }
}
.track-button.pulse {
animation: pulse 1.5s infinite;
}
.result-box {
margin: 30px auto;
background-color: #fff;
padding: 30px;
border-radius: 12px;
box-shadow: 0 8px 30px rgba(0,0,0,0.08);
text-align: left;
width: 90%;
max-width: 650px;
border-left: 5px solid var(--primary);
}
.cancelled-box {
border-left-color: var(--danger);
background-color: #fff9fa;
}
.status-header {
display: flex;
align-items: center;
margin-bottom: 25px;
padding-bottom: 20px;
border-bottom: 1px solid #f1f3f5;
}
.status-icon {
width: 60px;
height: 60px;
border-radius: 50%;
background-color: rgba(67, 97, 238, 0.1);
display: flex;
align-items: center;
justify-content: center;
margin-right: 18px;
font-size: 24px;
color: var(--primary);
}
.cancelled-icon {
background-color: rgba(247, 37, 133, 0.1);
color: var(--danger);
}
.status-title {
font-size: 20px;
font-weight: 600;
color: #212529;
}
.status-value {
font-size: 18px;
font-weight: 600;
margin-left: 8px;
}
.status-value.completed {
color: var(--complete);
}
.status-value.processing {
color: var(--primary);
}
.status-value.cancelled {
color: var(--danger);
}
.status-value.on-the-way {
color: var(--warning);
}
.note-box {
background-color: #f8f9fa;
padding: 18px;
border-radius: 8px;
margin-top: 20px;
border-left: 4px solid var(--primary);
}
.note-box.info {
border-left-color: var(--success);
background-color: #f0f9ff;
}
.cancelled-note {
border-left-color: var(--danger);
background-color: #fff0f3;
}
.note-title {
font-weight: 600;
color: #495057;
margin-bottom: 10px;
display: flex;
align-items: center;
font-size: 15px;
}
.note-title svg {
margin-right: 8px;
}
.note-content {
color: #212529;
line-height: 1.6;
font-size: 15px;
}
.timeline {
position: relative;
padding-left: 40px;
margin-top: 25px;
}
.timeline:before {
content: "";
position: absolute;
left: 15px;
top: 0;
bottom: 0;
width: 2px;
background: #f1f3f5;
}
.timeline-item {
position: relative;
margin-bottom: 20px;
}
.timeline-item:last-child {
margin-bottom: 0;
}
.timeline-dot {
position: absolute;
left: -40px;
top: 3px;
width: 24px;
height: 24px;
border-radius: 50%;
background: white;
border: 4px solid var(--primary);
display: flex;
align-items: center;
justify-content: center;
}
.timeline-dot.completed {
border-color: var(--complete);
}
.timeline-dot.cancelled {
border-color: var(--danger);
}
.timeline-content {
font-size: 15px;
color: #495057;
padding-bottom: 5px;
}
.error {
color: var(--danger);
font-weight: 600;
margin-top: 20px;
font-size: 16px;
padding: 12px 20px;
background: rgba(247, 37, 133, 0.1);
border-radius: 8px;
display: inline-block;
}
#loader {
display: none;
margin-top: 20px;
}
.loading-text {
font-size: 16px;
color: #495057;
display: flex;
align-items: center;
justify-content: center;
}
.loading-text:after {
content: ".";
animation: dots 1.5s steps(5, end) infinite;
}
@keyframes dots {
0%, 20% { color: rgba(0,0,0,0); text-shadow: .25em 0 0 rgba(0,0,0,0), .5em 0 0 rgba(0,0,0,0); }
40% { color: #495057; text-shadow: .25em 0 0 rgba(0,0,0,0), .5em 0 0 rgba(0,0,0,0); }
60% { text-shadow: .25em 0 0 #495057, .5em 0 0 rgba(0,0,0,0); }
80%, 100% { text-shadow: .25em 0 0 #495057, .5em 0 0 #495057; }
}
.success {
color: var(--complete);
font-size: 16px;
margin-top: 20px;
font-weight: 500;
padding: 12px 20px;
background: rgba(46, 196, 182, 0.1);
border-radius: 8px;
display: inline-block;
}
.status-tracker {
display: flex;
justify-content: space-between;
margin: 30px 0;
position: relative;
}
.status-tracker:before {
content: "";
position: absolute;
top: 16px;
left: 0;
right: 0;
height: 4px;
background: #f1f3f5;
border-radius: 2px;
z-index: 1;
}
.status-step {
display: flex;
flex-direction: column;
align-items: center;
position: relative;
z-index: 2;
flex: 1;
}
.status-bubble {
width: 36px;
height: 36px;
border-radius: 50%;
background: #f1f3f5;
display: flex;
align-items: center;
justify-content: center;
color: white;
font-weight: bold;
margin-bottom: 8px;
font-size: 14px;
transition: all 0.3s ease;
}
.status-label {
font-size: 13px;
color: #868e96;
text-align: center;
max-width: 100px;
font-weight: 500;
transition: all 0.3s ease;
}
.status-step.completed .status-bubble {
background: var(--complete);
box-shadow: 0 4px 12px rgba(46, 196, 182, 0.3);
}
.status-step.completed .status-label {
color: var(--complete);
font-weight: 600;
}
.status-step.current .status-bubble {
background: var(--primary);
transform: scale(1.1);
box-shadow: 0 4px 16px rgba(67, 97, 238, 0.3);
}
.status-step.current .status-label {
color: var(--primary);
font-weight: 700;
}
.status-step.cancelled .status-bubble {
background: var(--danger);
box-shadow: 0 4px 12px rgba(247, 37, 133, 0.3);
}
.status-step.cancelled .status-label {
color: var(--danger);
font-weight: 700;
}
.status-step.pending .status-bubble {
background: #f1f3f5;
color: #adb5bd;
}
.status-step.pending .status-label {
color: #adb5bd;
}
.status-connector {
position: absolute;
top: 16px;
left: 0;
height: 4px;
background: var(--complete);
border-radius: 2px;
z-index: 1;
transition: all 0.4s ease;
}
.cancelled-connector {
background: var(--danger);
}
.cancellation-display {
text-align: left;
padding: 20px;
background-color: #fff0f3;
border-radius: 10px;
margin-top: 20px;
}
.cancellation-title {
font-size: 18px;
font-weight: 700;
color: var(--danger);
margin-bottom: 15px;
display: flex;
align-items: center;
}
.cancellation-title svg {
margin-right: 10px;
}
.cancellation-reason {
font-size: 15px;
color: #212529;
line-height: 1.6;
}
.auto-update-notice {
font-size: 14px;
color: #6c757d;
margin-top: 10px;
display: flex;
align-items: center;
justify-content: center;
}
.auto-update-notice svg {
margin-right: 8px;
}
@media (max-width: 600px) {
.search-container {
flex-direction: column;
padding: 16px;
}
.search-box {
width: 100%;
}
.track-button {
width: 100%;
margin-top: 10px;
}
.status-label {
font-size: 11px;
}
}
</style>
</head>
<body>
<div class="search-container">
<div class="search-box">
<svg class="search-icon" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<circle cx="11" cy="11" r="8"></circle>
<line x1="21" y1="21" x2="16.65" y2="16.65"></line>
</svg>
<input type="text" id="phoneInput" class="search-input" placeholder="Enter your phone number" />
</div>
<button class="track-button" onclick="searchOrder()">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M3 12a9 9 0 1 0 18 0a9 9 0 0 0-18 0"></path>
<path d="M9 12l2 2l4-4"></path>
</svg>
Track Order
</button>
</div>
<div id="loader" class="loading-text">Loading</div>
<div id="result" class="result-box" style="display: none;"></div>
<div id="error" class="error"></div>
<div id="success" class="success"></div>
<div id="autoUpdateNotice" class="auto-update-notice" style="display: none;">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<circle cx="12" cy="12" r="10"></circle>
<polyline points="12 6 12 12 16 14"></polyline>
</svg>
Order status will auto-update every 30 seconds
</div>
<script>
let currentOrderData = null;
let pollingInterval = null;
let currentPhoneNumber = null;
function updateOrderUI(data, showNotifications = true) {
const resultDiv = document.getElementById("result");
const errorDiv = document.getElementById("error");
const successDiv = document.getElementById("success");
// Determine current status
const status = data.Selectbox.toLowerCase();
let currentStep = 0;
let statusText = "";
let isCancelled = status.includes('cancel');
if (isCancelled) {
currentStep = -1;
statusText = "Cancelled";
} else if (status.includes('accepted')) {
currentStep = 0;
statusText = "Order Accepted";
} else if (status.includes('pickup') || status.includes('pick up')) {
currentStep = 1;
statusText = "Picked Up";
} else if (status.includes('way') || status.includes('delivering') || status.includes('on the way')) {
currentStep = 2;
statusText = "On the Way";
} else if (status.includes('complete') || status.includes('delivered')) {
currentStep = 3;
statusText = "Delivered";
} else {
currentStep = 0;
statusText = "Order Received";
}
// Create result HTML
let resultHtml = '';
if (isCancelled) {
resultHtml = `
<div class="status-header">
<div class="status-icon cancelled-icon">❌</div>
<div class="status-title">Order Status:
<span class="status-value cancelled">${statusText}</span>
</div>
</div>
${data.CommentsG && data.CommentsG.trim() !== "" ? `
<div class="cancellation-display">
<div class="cancellation-title">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<circle cx="12" cy="12" r="10"></circle>
<line x1="12" y1="8" x2="12" y2="12"></line>
<line x1="12" y1="16" x2="12.01" y2="16"></line>
</svg>
Cancellation Note
</div>
<div class="cancellation-reason">${data.CommentsG}</div>
</div>
` : ''}
`;
resultDiv.className = "result-box cancelled-box";
} else {
const statusTrackerHtml = `
<div class="status-tracker">
<div class="status-connector ${isCancelled ? 'cancelled-connector' : ''}" style="width: ${currentStep * 33.33}%"></div>
<div class="status-step ${currentStep >= 0 ? 'completed' : 'pending'} ${currentStep === 0 ? 'current' : ''}">
<div class="status-bubble">${currentStep > 0 ? '✓' : '1'}</div>
<div class="status-label">Accepted</div>
</div>
<div class="status-step ${currentStep >= 1 ? 'completed' : 'pending'} ${currentStep === 1 ? 'current' : ''}">
<div class="status-bubble">${currentStep > 1 ? '✓' : '2'}</div>
<div class="status-label">Pick Up</div>
</div>
<div class="status-step ${currentStep >= 2 ? 'completed' : 'pending'} ${currentStep === 2 ? 'current' : ''}">
<div class="status-bubble">${currentStep > 2 ? '✓' : '3'}</div>
<div class="status-label">On the Way</div>
</div>
<div class="status-step ${currentStep >= 3 ? 'completed' : 'pending'} ${currentStep === 3 ? 'current' : ''}">
<div class="status-bubble">${currentStep >= 3 ? '✓' : '4'}</div>
<div class="status-label">Delivered</div>
</div>
</div>
`;
resultHtml = `
<div class="status-header">
<div class="status-icon">📦</div>
<div class="status-title">Order Status:
<span class="status-value ${currentStep === 3 ? 'completed' : currentStep === 2 ? 'on-the-way' : 'processing'}">
${statusText}
</span>
</div>
</div>
${statusTrackerHtml}
<div class="timeline">
<div class="timeline-item">
<div class="timeline-dot ${currentStep >= 0 ? 'completed' : ''}"></div>
<div class="timeline-content">Order received and being processed</div>
</div>
`;
if (currentStep >= 1) {
resultHtml += `
<div class="timeline-item">
<div class="timeline-dot ${currentStep >= 1 ? 'completed' : ''}"></div>
<div class="timeline-content">Order picked up by delivery agent</div>
</div>
`;
}
if (currentStep >= 2) {
resultHtml += `
<div class="timeline-item">
<div class="timeline-dot ${currentStep >= 2 ? 'completed' : ''}"></div>
<div class="timeline-content">Order is on the way to your location</div>
</div>
`;
}
if (currentStep >= 3) {
resultHtml += `
<div class="timeline-item">
<div class="timeline-dot ${currentStep >= 3 ? 'completed' : ''}"></div>
<div class="timeline-content">Order delivered successfully</div>
</div>
`;
}
resultHtml += `</div>`;
// Show comments from Column G
if (data.CommentsG && data.CommentsG.trim() !== "") {
resultHtml += `
<div class="note-box">
<div class="note-title">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path>
<polyline points="14 2 14 8 20 8"></polyline>
<line x1="16" y1="13" x2="8" y2="13"></line>
<line x1="16" y1="17" x2="8" y2="17"></line>
<polyline points="10 9 9 9 8 9"></polyline>
</svg>
Order Note
</div>
<div class="note-content">${data.CommentsG}</div>
</div>
`;
}
// Show comments from Column H
if (data.CommentsH && data.CommentsH.trim() !== "") {
resultHtml += `
<div class="note-box info">
<div class="note-title">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<circle cx="12" cy="12" r="10"></circle>
<line x1="12" y1="16" x2="12" y2="12"></line>
<line x1="12" y1="8" x2="12.01" y2="8"></line>
</svg>
Additional Information
</div>
<div class="note-content">${data.CommentsH}</div>
</div>
`;
}
resultDiv.className = "result-box";
}
resultDiv.innerHTML = resultHtml;
resultDiv.style.display = "block";
if (showNotifications) {
successDiv.innerText = "✅ Order details loaded successfully";
successDiv.style.display = "block";
}
currentOrderData = data;
}
function fetchOrderDetails(phone, showNotifications = true) {
const loader = document.getElementById("loader");
const errorDiv = document.getElementById("error");
const trackButton = document.querySelector('.track-button');
const resultDiv = document.getElementById("result");
const successDiv = document.getElementById("success");
// Show loading indicator
if (showNotifications) {
loader.style.display = "flex";
trackButton.classList.add('pulse');
errorDiv.innerText = "";
successDiv.style.display = "none";
}
fetch("https://script.google.com/macros/s/AKfycbxoN3TRbSfuktnFtov7UK2ib7PG-dmv0zgl3yu3j1-S27-J61ThC8jwLme7euOuRG46dQ/exec?phone=" + phone)
.then(res => res.json())
.then(data => {
loader.style.display = "none";
trackButton.classList.remove('pulse');
if (!data.Selectbox) {
if (showNotifications) {
errorDiv.innerText = "❌ No order found with this phone number";
}
return;
}
// Only update UI if data has changed
if (!currentOrderData || JSON.stringify(currentOrderData) !== JSON.stringify(data)) {
updateOrderUI(data, showNotifications);
}
})
.catch(err => {
console.error(err);
loader.style.display = "none";
trackButton.classList.remove('pulse');
if (showNotifications) {
errorDiv.innerText = "❌ Server Error. Please try again later.";
}
});
}
function startPolling(phone) {
// Clear any existing polling
if (pollingInterval) clearInterval(pollingInterval);
// Show auto-update notice
document.getElementById("autoUpdateNotice").style.display = "flex";
// Start new polling interval (every 30 seconds)
pollingInterval = setInterval(() => {
fetchOrderDetails(phone, false); // Silent update
}, 30000);
currentPhoneNumber = phone;
}
function stopPolling() {
if (pollingInterval) {
clearInterval(pollingInterval);
pollingInterval = null;
}
document.getElementById("autoUpdateNotice").style.display = "none";
currentPhoneNumber = null;
}
function searchOrder() {
const phone = document.getElementById("phoneInput").value.trim();
const errorDiv = document.getElementById("error");
// Validate phone number
if (!phone.match(/^(\+88)?\d{11}$/)) {
errorDiv.innerText = "⚠️ Please enter a valid 11-digit phone number";
stopPolling();
return;
}
// Save phone number
localStorage.setItem('savedPhoneNumber', phone);
// Stop any existing polling
stopPolling();
// Fetch order details and start polling
fetchOrderDetails(phone);
startPolling(phone);
}
// Auto-fill saved phone number on page load
window.onload = function() {
const savedPhone = localStorage.getItem('savedPhoneNumber');
if (savedPhone) {
document.getElementById("phoneInput").value = savedPhone;
searchOrder();
}
// Add event listener for Enter key
document.getElementById("phoneInput").addEventListener("keypress", function(e) {
if (e.key === "Enter") {
searchOrder();
}
});
// Focus on input field
document.getElementById("phoneInput").focus();
};
// Stop polling when page is unloaded
window.addEventListener('beforeunload', function() {
stopPolling();
});
</script>
</body>
</html>