Files
Kent-logistics-Laravel/resources/views/admin/orders.blade.php
2025-12-01 10:38:52 +05:30

691 lines
23 KiB
PHP

@extends('admin.layouts.app')
@section('page-title', 'Orders')
@section('content')
<style>
/* ===== GLOBAL RESPONSIVE STYLES ===== */
html, body {
overflow-x: hidden !important;
max-width: 100%;
}
/* Use Inter globally */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');
:root { --admin-font: 'Inter', sans-serif; }
body, input, select, textarea, button, table, th, td, .orders-container {
font-family: var(--admin-font);
}
/* VARIABLES AND BASE STYLES */
:root {
--primary-color: #3b82f6; /* Blue 500 */
--primary-hover: #2563eb; /* Blue 600 */
--border-light: #e5e7eb; /* Gray 200 */
--bg-container: #ffffff;
--bg-light: #f9fafb; /* Gray 50 */
--bg-hover: #f3f4f6; /* Gray 100 */
--text-dark: #1f2937; /* Gray 800 */
--text-muted: #6b7280; /* Gray 500 */
--shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}
.orders-container {
background: var(--bg-container);
padding: 24px;
border-radius: 12px;
box-shadow: var(--shadow-lg);
margin-top: 28px;
}
.orders-title {
font-size: 28px;
font-weight: 700;
margin-bottom: 24px;
color: var(--text-dark);
border-bottom: 1px solid var(--border-light);
padding-bottom: 16px;
}
/* TABLE STRUCTURE & WRAPPER FOR RESPONSIVENESS */
.table-wrapper {
overflow-x: auto; /* Enables horizontal scrollbar */
max-width: 100%;
border-radius: 8px;
border: 1px solid var(--border-light);
}
.orders-table {
width: 100%;
min-width: 1300px; /* Minimum width to prevent excessive squeezing of columns */
border-collapse: separate; /* Required for border-radius on cells in the future */
border-spacing: 0;
font-size: 14px;
color: var(--text-dark);
}
/* GRADIENT HEADER STYLES FROM SHIPPING REPORT */
.orders-table thead {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
position: sticky;
top: 0;
z-index: 10;
}
.orders-table th {
padding: 16px 20px;
text-align: center; /* Center align header text */
font-size: 14px;
font-weight: 600;
color: white;
border-bottom: none;
white-space: nowrap;
position: relative;
}
.orders-table th:not(:last-child)::after {
content: '';
position: absolute;
right: 0;
top: 50%;
transform: translateY(-50%);
width: 1px;
height: 16px;
background: rgba(255, 255, 255, 0.3);
}
.orders-table td {
padding: 14px 20px;
border-bottom: 1px solid var(--border-light);
white-space: nowrap;
text-align: center; /* Center align all table data */
}
.orders-table tbody tr:last-child td {
border-bottom: none;
}
.orders-table tbody tr:hover {
background: var(--bg-hover);
transition: background 0.2s ease;
}
/* ===== IMPROVED STATUS BADGES (FROM SHIPPING REPORT) ===== */
.status-badge {
font-size: 11px !important;
font-weight: 600 !important;
padding: 6px 12px 6px 8px !important;
border-radius: 20px !important;
text-transform: uppercase;
letter-spacing: 0.3px;
display: inline-flex !important;
align-items: center;
justify-content: center;
background-size: cover !important;
background-position: center !important;
color: #fff !important;
text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
border: 2px solid transparent !important;
min-width: 40px;
box-sizing: border-box;
line-height: 1.2;
gap: 6px;
position: relative;
overflow: hidden;
white-space: nowrap;
margin: 0 auto; /* Center badges */
}
.status-badge::before {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: inherit;
opacity: 0.9;
z-index: -1;
}
/* Status icons */
.status-icon {
font-size: 11px;
display: flex;
align-items: center;
justify-content: center;
position: relative;
z-index: 1;
}
/* Invoice Status Badges */
.status-paid {
background: linear-gradient(135deg, #10b981, #34d399) !important;
color: white !important;
border-color: #059669 !important;
width: 99px;
}
.status-pending {
background: linear-gradient(135deg, #fef3c7, #fde68a) !important;
color: #d97706 !important;
border-color: #f59e0b !important;
width: 99px;
}
.status-overdue {
background: linear-gradient(135deg, #fef2f2, #fecaca) !important;
color: #dc2626 !important;
border-color: #ef4444 !important;
width: 99px;
}
/* Shipment Status Badges */
.ship-pending {
background: linear-gradient(135deg, #fef3c7, #fde68a) !important;
color: #d97706 !important;
border-color: #f59e0b !important;
width: 99px;
}
.ship-in_transit {
background: linear-gradient(135deg, #dbeafe, #bfdbfe) !important;
color: #1e40af !important;
border-color: #3b82f6 !important;
width: 99px;
}
.ship-dispatched {
background: linear-gradient(135deg, #e9d5ff, #d8b4fe) !important;
color: #7e22ce !important;
border-color: #8b5cf6 !important;
width: 99px;
}
.ship-delivered {
background: linear-gradient(135deg, #d1fae5, #a7f3d0) !important;
color: #065f46 !important;
border-color: #10b981 !important;
width: 99px;
}
.shipstatus{
}
/* ACTION BUTTON */
.action-btn {
color: var(--text-muted);
cursor: pointer;
transition: color 0.2s ease, transform 0.2s ease;
font-size: 18px;
}
.action-btn:hover {
color: var(--primary-color);
transform: scale(1.15);
}
/* EMPTY STATE */
.no-data {
padding: 40px;
text-align: center;
font-size: 16px;
color: var(--text-muted);
background: var(--bg-light);
border-radius: 8px;
margin-top: 10px;
border: 1px solid var(--border-light);
}
/* RESPONSIVE ADJUSTMENTS */
@media(max-width: 768px) {
.orders-title {
font-size: 24px;
}
.orders-container {
padding: 16px;
}
}
/* ---------- Pagination Styles (Same as Account Dashboard) ---------- */
.pagination-container {
display: flex;
justify-content: space-between;
align-items: center;
margin-top: 15px;
padding: 12px 0;
border-top: 1px solid #eef3fb;
}
.pagination-info {
font-size: 13px;
color: #9ba5bb;
font-weight: 600;
}
.pagination-controls {
display: flex;
align-items: center;
gap: 8px;
}
.pagination-btn {
background: #fff;
border: 1px solid #e3eaf6;
color: #1a2951;
padding: 8px 12px;
border-radius: 6px;
font-size: 13px;
font-weight: 600;
cursor: pointer;
transition: all 0.3s ease;
display: flex;
align-items: center;
justify-content: center;
min-width: 40px;
height: 32px;
}
.pagination-btn:hover:not(:disabled) {
background: #1a2951;
color: white;
border-color: #1a2951;
}
.pagination-btn:disabled {
background: #f8fafc;
color: #cbd5e0;
border-color: #e2e8f0;
cursor: not-allowed;
opacity: 0.6;
}
.pagination-page-btn {
background: #fff;
border: 1px solid #e3eaf6;
color: #1a2951;
padding: 6px 12px;
border-radius: 6px;
font-size: 13px;
font-weight: 600;
cursor: pointer;
transition: all 0.3s ease;
min-width: 36px;
text-align: center;
}
.pagination-page-btn:hover {
background: #1a2951;
color: white;
border-color: #1a2951;
}
.pagination-page-btn.active {
background: #1a2951;
color: white;
border-color: #1a2951;
}
.pagination-pages {
display: flex;
gap: 4px;
align-items: center;
}
.pagination-ellipsis {
color: #9ba5bb;
font-size: 13px;
padding: 0 4px;
}
/* Image-based pagination buttons */
.pagination-img-btn {
background: #fff;
border: 1px solid #e3eaf6;
border-radius: 6px;
cursor: pointer;
transition: all 0.3s ease;
display: flex;
align-items: center;
justify-content: center;
min-width: 40px;
height: 32px;
padding: 0;
}
.pagination-img-btn:hover:not(:disabled) {
background: #1a2951;
border-color: #1a2951;
}
.pagination-img-btn:disabled {
background: #f8fafc;
border-color: #e2e8f0;
cursor: not-allowed;
opacity: 0.5;
}
.pagination-img-btn img {
width: 16px;
height: 16px;
filter: brightness(0) saturate(100%) invert(26%) sepia(89%) saturate(748%) hue-rotate(201deg) brightness(93%) contrast(89%);
transition: filter 0.3s ease;
}
.pagination-img-btn:hover:not(:disabled) img {
filter: brightness(0) saturate(100%) invert(100%) sepia(100%) saturate(0%) hue-rotate(288deg) brightness(106%) contrast(101%);
}
.pagination-img-btn:disabled img {
filter: brightness(0) saturate(100%) invert(84%) sepia(8%) saturate(165%) hue-rotate(179deg) brightness(89%) contrast(86%);
}
</style>
{{-- Make sure you include Font Awesome CDN in your main layout file, e.g., in <head>:
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
--}}
<div class="orders-container">
<div class="orders-title">
<i class="fas fa-box-open mr-2"></i> Orders List
</div>
@if(isset($orders) && $orders->count() > 0)
<div class="table-wrapper">
<table class="orders-table">
<thead>
<tr>
<th>Order ID</th>
<th>Shipment ID</th>
<th>Customer ID</th>
<th>Company</th>
<th>Origin</th>
<th>Destination</th>
<th>Order Date</th>
<th>Invoice No</th>
<th>Invoice Date</th>
<th>Amount</th>
<th>Amount + GST</th>
<th>Invoice Status</th>
<th>Shipment Status</th>
<th>Action</th>
</tr>
</thead>
<tbody id="ordersTableBody">
@foreach($orders as $order)
@php
$mark = $order->markList ?? null;
$invoice = $order->invoice ?? null;
$shipment = $order->shipments->first() ?? null;
$invoiceStatus = strtolower($invoice->status ?? '');
$shipmentStatus = strtolower(str_replace('_', ' ', $shipment->status ?? ''));
@endphp
<tr>
<td>{{ $order->order_id ?? '-' }}</td>
<td>{{ $shipment->shipment_id ?? '-' }}</td>
<td>{{ $mark->customer_id ?? '-' }}</td>
<td>{{ $mark->company_name ?? '-' }}</td>
<td>{{ $mark->origin ?? $order->origin ?? '-' }}</td>
<td>{{ $mark->destination ?? $order->destination ?? '-' }}</td>
<td>{{ $order->created_at ? $order->created_at->format('d-m-Y') : '-' }}</td>
<td>{{ $invoice->invoice_number ?? '-' }}</td>
<td>
{{ $invoice?->invoice_date ? date('d-m-Y', strtotime($invoice->invoice_date)) : '-' }}
</td>
<td>
{{ $invoice?->final_amount ? '₹'.number_format($invoice->final_amount, 2) : '-' }}
</td>
<td>
{{ $invoice?->final_amount_with_gst ? '₹'.number_format($invoice->final_amount_with_gst, 2) : '-' }}
</td>
<td>
@if($invoice?->status)
<span class="status-badge status-{{ $invoiceStatus }}">
{{ ucfirst($invoice->status) }}
</span>
@else
<span class="status-badge status-pending">Pending</span>
@endif
</td>
<td>
@if($shipment?->status)
<span class="status-badge ship-{{ str_replace(' ', '_', $shipmentStatus) }}">
{{ ucfirst($shipmentStatus) }}
</span>
@else
<span class="status-badge ship-pending">Pending</span>
@endif
</td>
<td class="text-center">
<a href="{{ route('admin.orders.show', $order->id) }}" title="View Details">
<i class="fas fa-eye action-btn"></i>
</a>
</td>
</tr>
@endforeach
</tbody>
</table>
</div> {{-- End table-wrapper --}}
<!-- Pagination Controls -->
<div class="pagination-container">
<div class="pagination-info" id="pageInfo">Showing 1 to {{ min(10, count($orders)) }} of {{ count($orders) }} entries</div>
<div class="pagination-controls">
<button class="pagination-img-btn" id="prevPageBtn" title="Previous page" disabled>
<!-- Left arrow SVG -->
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M10 12L6 8L10 4" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
</button>
<div class="pagination-pages" id="paginationPages">
<!-- Page numbers will be inserted here -->
</div>
<button class="pagination-img-btn" id="nextPageBtn" title="Next page" {{ count($orders) > 10 ? '' : 'disabled' }}>
<!-- Right arrow SVG -->
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M6 4L10 8L6 12" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
</button>
</div>
</div>
@else
<p class="no-data">
<i class="fas fa-info-circle mr-2"></i> No orders found.
</p>
@endif
</div>
<script>
// Pagination state
let currentPage = 1;
const itemsPerPage = 10;
let allOrders = @json($orders);
let filteredOrders = [...allOrders];
// Status icon helper functions
function getInvoiceStatusIcon(status) {
switch(status) {
case 'paid':
return '<i class="bi bi-check-circle-fill status-icon"></i>';
case 'pending':
return '<i class="bi bi-clock-fill status-icon"></i>';
case 'overdue':
return '<i class="bi bi-exclamation-triangle-fill status-icon"></i>';
default:
return '';
}
}
function getShipmentStatusIcon(status) {
switch(status) {
case 'pending':
return '<i class="bi bi-clock-fill status-icon"></i>';
case 'in_transit':
return '<i class="bi bi-truck status-icon"></i>';
case 'dispatched':
return '<i class="bi bi-send-fill status-icon"></i>';
case 'delivered':
return '<i class="bi bi-check-circle-fill status-icon"></i>';
default:
return '';
}
}
// Initialize pagination
document.addEventListener('DOMContentLoaded', function() {
renderTable();
updatePaginationControls();
// Bind pagination events
document.getElementById('prevPageBtn').addEventListener('click', goToPreviousPage);
document.getElementById('nextPageBtn').addEventListener('click', goToNextPage);
});
// Pagination Functions
function goToPreviousPage() {
if (currentPage > 1) {
currentPage--;
renderTable();
updatePaginationControls();
}
}
function goToNextPage() {
const totalPages = Math.ceil(filteredOrders.length / itemsPerPage);
if (currentPage < totalPages) {
currentPage++;
renderTable();
updatePaginationControls();
}
}
function updatePaginationControls() {
const totalPages = Math.ceil(filteredOrders.length / itemsPerPage);
const prevBtn = document.getElementById('prevPageBtn');
const nextBtn = document.getElementById('nextPageBtn');
const pageInfo = document.getElementById('pageInfo');
const paginationPages = document.getElementById('paginationPages');
prevBtn.disabled = currentPage === 1;
nextBtn.disabled = currentPage === totalPages || totalPages === 0;
// Update page info text
const startIndex = (currentPage - 1) * itemsPerPage + 1;
const endIndex = Math.min(currentPage * itemsPerPage, filteredOrders.length);
pageInfo.textContent = `Showing ${startIndex} to ${endIndex} of ${filteredOrders.length} entries`;
// Generate page numbers
paginationPages.innerHTML = '';
if (totalPages <= 7) {
// Show all pages
for (let i = 1; i <= totalPages; i++) {
addPageButton(i, paginationPages);
}
} else {
// Show first page, current page range, and last page
addPageButton(1, paginationPages);
if (currentPage > 3) {
paginationPages.innerHTML += '<span class="pagination-ellipsis">...</span>';
}
const start = Math.max(2, currentPage - 1);
const end = Math.min(totalPages - 1, currentPage + 1);
for (let i = start; i <= end; i++) {
addPageButton(i, paginationPages);
}
if (currentPage < totalPages - 2) {
paginationPages.innerHTML += '<span class="pagination-ellipsis">...</span>';
}
addPageButton(totalPages, paginationPages);
}
}
function addPageButton(pageNumber, container) {
const button = document.createElement('button');
button.className = 'pagination-page-btn';
if (pageNumber === currentPage) {
button.classList.add('active');
}
button.textContent = pageNumber;
button.addEventListener('click', () => {
currentPage = pageNumber;
renderTable();
updatePaginationControls();
});
container.appendChild(button);
}
// Render Table Function
function renderTable() {
const tbody = document.getElementById('ordersTableBody');
tbody.innerHTML = '';
if (filteredOrders.length === 0) {
tbody.innerHTML = '<tr><td colspan="14" class="text-center py-4 text-muted">No orders found.</td></tr>';
return;
}
// Calculate pagination
const startIndex = (currentPage - 1) * itemsPerPage;
const endIndex = startIndex + itemsPerPage;
const paginatedItems = filteredOrders.slice(startIndex, endIndex);
paginatedItems.forEach(order => {
const mark = order.markList || null;
const invoice = order.invoice || null;
const shipment = order.shipments?.[0] || null;
const invoiceStatus = (invoice?.status || '').toLowerCase();
const shipmentStatus = (shipment?.status || '').toLowerCase().replace('_', ' ');
const row = document.createElement('tr');
row.innerHTML = `
<td>${order.order_id || '-'}</td>
<td>${shipment?.shipment_id || '-'}</td>
<td>${mark?.customer_id || '-'}</td>
<td>${mark?.company_name || '-'}</td>
<td>${mark?.origin || order.origin || '-'}</td>
<td>${mark?.destination || order.destination || '-'}</td>
<td>${order.created_at ? new Date(order.created_at).toLocaleDateString('en-GB') : '-'}</td>
<td>${invoice?.invoice_number || '-'}</td>
<td>${invoice?.invoice_date ? new Date(invoice.invoice_date).toLocaleDateString('en-GB') : '-'}</td>
<td>${invoice?.final_amount ? '₹' + Number(invoice.final_amount).toLocaleString('en-IN', {minimumFractionDigits: 2, maximumFractionDigits: 2}) : '-'}</td>
<td>${invoice?.final_amount_with_gst ? '₹' + Number(invoice.final_amount_with_gst).toLocaleString('en-IN', {minimumFractionDigits: 2, maximumFractionDigits: 2}) : '-'}</td>
<td>
${invoice?.status
? `<span class="status-badge status-${invoiceStatus}">${getInvoiceStatusIcon(invoiceStatus)}${invoice.status.charAt(0).toUpperCase() + invoice.status.slice(1)}</span>`
: '<span class="status-badge status-pending"><i class="bi bi-clock-fill status-icon"></i>Pending</span>'
}
</td>
<td>
${shipment?.status
? `<span class="status-badge ship-${shipmentStatus.replace(' ', '_')}">${getShipmentStatusIcon(shipmentStatus.replace(' ', '_'))}${shipment.status.charAt(0).toUpperCase() + shipment.status.slice(1)}</span>`
: '<span class="status-badge ship-pending"><i class="bi bi-clock-fill status-icon"></i>Pending</span>'
}
</td>
<td class="text-center">
<a href="/admin/orders/${order.id}" title="View Details">
<i class="fas fa-eye action-btn"></i>
</a>
</td>
`;
tbody.appendChild(row);
});
}
</script>
@endsection