Files
Kent-logistics-Laravel/resources/views/admin/reports.blade.php
2025-11-27 19:39:36 +05:30

1304 lines
42 KiB
PHP

@extends('admin.layouts.app')
@section('page-title', 'Shipping Report List')
@section('content')
<style>
/* ===== GLOBAL RESPONSIVE STYLES ===== */
html, body {
overflow-x: hidden !important;
max-width: 100%;
}
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');
.report-container {
background: #ffffff;
padding: 25px;
border-radius: 16px;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.08);
margin: 20px auto;
max-width: 100%;
font-family: 'Inter', sans-serif;
border: 1px solid #f0f0f0;
}
.report-header {
display: flex;
align-items: center;
gap: 18px;
margin-bottom: 8px;
padding-bottom: 20px;
border-bottom: 2px solid #f8f9fa;
}
.header-icon {
width: 55px;
height: 55px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
border-radius: 14px;
display: flex;
align-items: center;
justify-content: center;
box-shadow: 0 6px 20px rgba(102, 126, 234, 0.3);
}
.header-icon i {
font-size: 24px;
color: white;
}
.header-text {
flex: 1;
}
.report-title {
font-size: 24px;
font-weight: 700;
color: #1a202c;
letter-spacing: -0.6px;
margin-bottom: 4px;
}
.report-subtitle {
font-size: 14px;
color: #718096;
font-weight: 500;
}
.stats-container {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
gap: 15px;
margin: 20px 0;
}
.stat-card {
background: linear-gradient(135deg, #f8f9ff 0%, #f0f4ff 100%);
padding: 18px 15px;
border-radius: 12px;
border-left: 4px solid #4f46e5;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
transition: transform 0.3s ease;
text-align: center;
}
.stat-card:hover {
transform: translateY(-2px);
}
.stat-card.warning {
border-left-color: #f59e0b;
background: linear-gradient(135deg, #fffbeb 0%, #fef3c7 100%);
}
.stat-card.success {
border-left-color: #10b981;
background: linear-gradient(135deg, #ecfdf5 0%, #d1fae5 100%);
}
.stat-card.danger {
border-left-color: #ef4444;
background: linear-gradient(135deg, #fef2f2 0%, #fee2e2 100%);
}
.stat-card.info {
border-left-color: #3b82f6;
background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
}
.stat-card.secondary {
border-left-color: #8b5cf6;
background: linear-gradient(135deg, #faf5ff 0%, #f3e8ff 100%);
}
.stat-icon i {
font-size: 18px;
color: #4f46e5;
}
.stat-card.warning .stat-icon {
background: rgba(245, 158, 11, 0.1);
}
.stat-card.warning .stat-icon i {
color: #f59e0b;
}
.stat-card.success .stat-icon {
background: rgba(16, 185, 129, 0.1);
}
.stat-card.success .stat-icon i {
color: #10b981;
}
.stat-card.danger .stat-icon {
background: rgba(239, 68, 68, 0.1);
}
.stat-card.danger .stat-icon i {
color: #ef4444;
}
/* .stat-card.info .stat-icon {
background: rgba(59, 130, 246, 0.1);
} */
.stat-card.info .stat-icon i {
color: #3b82f6;
}
.stat-card.secondary .stat-icon {
background: rgba(139, 92, 246, 0.1);
}
.stat-card.secondary .stat-icon i {
color: #8b5cf6;
}
.stat-value {
font-size: 22px;
font-weight: 700;
color: #1a202c;
margin-bottom: 4px;
line-height: 1.2;
}
.stat-label {
font-size: 13px;
color: #718096;
font-weight: 500;
line-height: 1.3;
}
.filter-section {
background: #f8fafc;
border-radius: 12px;
padding: 20px;
margin-bottom: 20px;
border: 1px solid #e2e8f0;
}
.filter-row {
display: flex;
gap: 15px;
flex-wrap: wrap;
align-items: end;
}
.filter-group {
display: flex;
flex-direction: column;
gap: 6px;
min-width: 180px;
flex: 1;
}
.filter-label {
font-size: 13px;
font-weight: 600;
color: #374151;
display: flex;
align-items: center;
gap: 6px;
}
.filter-label i {
color: #6b7280;
font-size: 13px;
}
.filter-control {
padding: 10px 12px;
border-radius: 8px;
border: 1.5px solid #e5e7eb;
background: #ffffff;
font-size: 13px;
color: #1f2937;
transition: all 0.3s ease;
font-family: 'Inter', sans-serif;
}
.filter-control:focus {
outline: none;
border-color: #4f46e5;
box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}
/* ===== IMPROVED TABLE CONTAINER FOR HORIZONTAL SCROLL ===== */
.table-container {
overflow-x: auto;
border-radius: 12px;
border: 1px solid #e5e7eb;
background: white;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
margin-top: 10px;
-webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}
/* Ensure table takes full width and doesn't wrap */
.report-table {
width: 100%;
border-collapse: collapse;
min-width: 1200px; /* Minimum width to prevent squeezing */
table-layout: auto; /* Allow columns to adjust based on content */
}
/* Table header styling - CENTER ALIGNED */
.report-table thead {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
position: sticky;
top: 0;
z-index: 10;
}
.report-table th {
padding: 15px 12px;
text-align: center; /* Center align header text */
font-size: 13px;
font-weight: 600;
color: white;
border-bottom: none;
white-space: nowrap;
position: relative;
min-width: 120px; /* Minimum column width */
}
.report-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);
}
/* Table cell styling with proper text handling - CENTER ALIGNED */
.report-table td {
padding: 12px;
font-size: 13px;
color: #374151;
border-bottom: 1px solid #f3f4f6;
vertical-align: middle;
white-space: nowrap; /* Prevent text wrapping */
overflow: hidden;
text-overflow: ellipsis; /* Show ellipsis for overflow */
max-width: 200px; /* Maximum width before ellipsis */
min-width: 120px; /* Minimum column width */
text-align: center; /* Center align all table data */
}
/* Specific column width adjustments */
.report-table th:nth-child(1), /* Order ID */
.report-table td:nth-child(1) {
min-width: 100px;
max-width: 150px;
}
.report-table th:nth-child(2), /* Shipment ID */
.report-table td:nth-child(2) {
min-width: 120px;
max-width: 180px;
}
.report-table th:nth-child(3), /* Company Name */
.report-table td:nth-child(3) {
min-width: 150px;
max-width: 200px;
}
.report-table th:nth-child(4), /* User Name */
.report-table td:nth-child(4) {
min-width: 120px;
max-width: 160px;
}
.report-table th:nth-child(5), /* Origin */
.report-table td:nth-child(5),
.report-table th:nth-child(6), /* Destination */
.report-table td:nth-child(6) {
min-width: 120px;
max-width: 180px;
}
.report-table th:nth-child(7), /* Date */
.report-table td:nth-child(7),
.report-table th:nth-child(9), /* Invoice Date */
.report-table td:nth-child(9) {
min-width: 100px;
max-width: 120px;
}
.report-table th:nth-child(8), /* Invoice ID */
.report-table td:nth-child(8) {
min-width: 120px;
max-width: 160px;
}
.report-table th:nth-child(10), /* Invoice Amount */
.report-table td:nth-child(10) {
min-width: 120px;
max-width: 150px;
}
.report-table th:nth-child(11), /* Invoice Status */
.report-table td:nth-child(11),
.report-table th:nth-child(12), /* Shipment Status */
.report-table td:nth-child(12) {
min-width: 120px;
max-width: 140px;
}
/* Row hover effects */
.report-table tbody tr {
transition: all 0.3s ease;
}
.report-table tbody tr:hover {
background-color: #f8faff;
transform: translateY(-1px);
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}
.report-table tbody tr:nth-child(even) {
background-color: #fafafa;
}
.report-table tbody tr:nth-child(even):hover {
background-color: #f3f4ff;
}
/* ===== BADGE STYLES - CENTER ALIGNED ===== */
.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-badge i {
font-size: 8px;
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;
}
.data-highlight {
font-weight: 600;
color: #1a202c;
display: flex;
align-items: center;
justify-content: center; /* Center content */
gap: 4px;
font-size: 13px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
margin: 0 auto; /* Center the highlight container */
}
.data-highlight i {
color: #4f46e5;
font-size: 11px;
flex-shrink: 0; /* Prevent icon from shrinking */
}
.empty-state {
text-align: center;
padding: 50px 20px;
color: #6b7280;
}
.empty-icon {
width: 60px;
height: 60px;
background: #f8f9fa;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
margin: 0 auto 15px;
border: 2px dashed #e5e7eb;
}
.empty-icon i {
font-size: 24px;
color: #9ca3af;
}
.empty-state h3 {
font-size: 16px;
margin-bottom: 6px;
color: #4b5563;
}
.empty-state p {
font-size: 13px;
color: #6b7280;
}
/* Scrollbar styling for better appearance */
.table-container::-webkit-scrollbar {
height: 8px;
}
.table-container::-webkit-scrollbar-track {
background: #f1f1f1;
border-radius: 4px;
}
.table-container::-webkit-scrollbar-thumb {
background: #c1c1c1;
border-radius: 4px;
}
.table-container::-webkit-scrollbar-thumb:hover {
background: #a8a8a8;
}
/* ---------- 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%);
}
@media (max-width: 1024px) {
.stats-container {
grid-template-columns: repeat(3, 1fr);
}
.report-table {
min-width: 1100px;
}
}
@media (max-width: 768px) {
.report-container {
padding: 15px;
}
.report-header {
flex-direction: column;
text-align: center;
gap: 12px;
}
.header-icon {
width: 50px;
height: 50px;
}
.report-title {
font-size: 20px;
}
.stats-container {
grid-template-columns: repeat(2, 1fr);
gap: 12px;
}
.stat-card {
padding: 15px 12px;
}
.stat-value {
font-size: 20px;
}
.filter-row {
flex-direction: column;
align-items: stretch;
gap: 12px;
}
.filter-group {
min-width: 100%;
}
.report-table {
min-width: 1000px;
}
/* Adjust column widths for mobile */
.report-table th,
.report-table td {
min-width: 100px;
padding: 10px 8px;
}
.pagination-container {
flex-direction: column;
gap: 10px;
align-items: stretch;
}
.pagination-controls {
justify-content: center;
}
}
@media (max-width: 480px) {
.stats-container {
grid-template-columns: 1fr;
}
.stat-card {
padding: 15px;
}
.report-table {
min-width: 900px;
}
.report-table th,
.report-table td {
min-width: 90px;
padding: 8px 6px;
font-size: 12px;
}
.status-badge {
font-size: 10px !important;
padding: 4px 8px 4px 6px !important;
}
}
</style>
<div class="report-container">
<!-- HEADER SECTION -->
<div class="report-header">
<div class="header-icon">
<i class="fas fa-shipping-fast"></i>
</div>
<div class="header-text">
<h1 class="report-title">Shipping Report List</h1>
<p class="report-subtitle">Comprehensive overview of all shipping activities and invoices</p>
</div>
</div>
<!-- DYNAMIC STATS CARDS -->
<div class="stats-container">
<div class="stat-card">
<div class="stat-icon">
<i class="fas fa-box-open"></i>
</div>
<div class="stat-value" id="totalShipments">{{ count($reports) }}</div>
<div class="stat-label">Total Shipments</div>
</div>
<div class="stat-card warning">
<div class="stat-icon">
<i class="fas fa-clock"></i>
</div>
<div class="stat-value" id="pendingShipments">0</div>
<div class="stat-label">Pending Shipments</div>
</div>
<div class="stat-card info">
<div class="stat-icon">
<i class="fas fa-truck-moving"></i>
</div>
<div class="stat-value" id="inTransitShipments">0</div>
<div class="stat-label">In Transit</div>
</div>
<div class="stat-card secondary">
<div class="stat-icon">
<i class="fas fa-shipping-fast"></i>
</div>
<div class="stat-value" id="dispatchedShipments">0</div>
<div class="stat-label">Dispatched</div>
</div>
<div class="stat-card success">
<div class="stat-icon">
<i class="fas fa-check-circle"></i>
</div>
<div class="stat-value" id="deliveredShipments">0</div>
<div class="stat-label">Delivered</div>
</div>
<div class="stat-card danger">
<div class="stat-icon">
<i class="fas fa-exclamation-triangle"></i>
</div>
<div class="stat-value" id="overdueInvoices">0</div>
<div class="stat-label">Overdue Invoices</div>
</div>
</div>
<!-- FILTER SECTION -->
<div class="filter-section">
<div class="filter-row">
<div class="filter-group">
<label class="filter-label">
<i class="fas fa-calendar-alt"></i>
From Date
</label>
<input type="date" class="filter-control" id="fromDate">
</div>
<div class="filter-group">
<label class="filter-label">
<i class="fas fa-calendar-check"></i>
To Date
</label>
<input type="date" class="filter-control" id="toDate">
</div>
<div class="filter-group">
<label class="filter-label">
<i class="fas fa-building"></i>
Company
</label>
<select class="filter-control" id="companyFilter">
<option value="" selected>All Companies</option>
<option value="ABC Corporation">ABC Corporation</option>
<option value="XYZ Enterprises">XYZ Enterprises</option>
<option value="Global Traders">Global Traders</option>
<option value="Tech Solutions Ltd">Tech Solutions Ltd</option>
</select>
</div>
<div class="filter-group">
<label class="filter-label">
<i class="fas fa-truck-loading"></i>
Shipping Status
</label>
<select class="filter-control" id="statusFilter">
<option value="" selected>All Status</option>
<option value="pending">Pending</option>
<option value="in_transit">In Transit</option>
<option value="dispatched">Dispatched</option>
<option value="delivered">Delivered</option>
</select>
</div>
</div>
</div>
<!-- TABLE SECTION -->
<div class="table-container">
<table class="report-table">
<thead>
<tr>
<th><i class="fas fa-hashtag"></i> Order ID</th>
<th><i class="fas fa-barcode"></i> Shipment ID</th>
<th><i class="fas fa-building"></i> Company Name</th>
<th><i class="fas fa-user"></i> User Name</th>
<th><i class="fas fa-map-marker-alt"></i> Origin</th>
<th><i class="fas fa-location-arrow"></i> Destination</th>
<th><i class="fas fa-calendar"></i> Date</th>
<th><i class="fas fa-file-invoice"></i> Invoice ID</th>
<th><i class="fas fa-calendar-day"></i> Invoice Date</th>
<th><i class="fas fa-money-bill-wave"></i> Invoice Amount</th>
<th><i class="fas fa-receipt"></i> Invoice Status</th>
<th><i class="fas fa-shipping-fast"></i> Shipment Status</th>
</tr>
</thead>
<tbody id="reportTableBody">
@forelse ($reports as $r)
<tr data-status="{{ $r->shipment_status }}" data-invoice-status="{{ strtolower($r->invoice_status) }}" data-company="{{ $r->company_name ?? '' }}" data-date="{{ $r->shipment_date }}">
<td>
<span class="data-highlight" title="{{ $r->order_id }}">
<i class="fas fa-hashtag"></i>
{{ $r->order_id }}
</span>
</td>
<td>
<span class="data-highlight" title="{{ $r->shipment_id }}">
<i class="fas fa-barcode"></i>
{{ $r->shipment_id }}
</span>
</td>
<td title="{{ $r->company_name ?? '-' }}">{{ $r->company_name ?? '-' }}</td>
<td title="{{ $r->customer_name ?? '-' }}">{{ $r->customer_name ?? '-' }}</td>
<td>
<span class="data-highlight" title="{{ $r->origin }}">
<i class="fas fa-map-marker-alt"></i>
{{ $r->origin }}
</span>
</td>
<td>
<span class="data-highlight" title="{{ $r->destination }}">
<i class="fas fa-location-arrow"></i>
{{ $r->destination }}
</span>
</td>
<td>{{ \Carbon\Carbon::parse($r->shipment_date)->format('d/m/Y') }}</td>
<td>
<span class="data-highlight" title="{{ $r->invoice_number }}">
<i class="fas fa-file-invoice"></i>
{{ $r->invoice_number }}
</span>
</td>
<td>{{ \Carbon\Carbon::parse($r->invoice_date)->format('d/m/Y') }}</td>
<td>
<span class="data-highlight" title="{{ number_format($r->final_amount) }}">
<i class="fas fa-rupee-sign"></i>
{{ number_format($r->final_amount) }}
</span>
</td>
<td>
@php $ist = strtolower($r->invoice_status); @endphp
<span class="status-badge
@if($ist === 'paid') status-paid
@elseif($ist === 'pending') status-pending
@elseif($ist === 'overdue') status-overdue
@endif">
<i class="fas fa-circle"></i>
{{ ucfirst($ist) }}
</span>
</td>
<td>
<span class="status-badge ship-{{ $r->shipment_status }}">
<i class="fas fa-circle"></i>
{{ ucfirst(str_replace('_',' ', $r->shipment_status)) }}
</span>
</td>
</tr>
@empty
<tr>
<td colspan="12">
<div class="empty-state">
<div class="empty-icon">
<i class="fas fa-inbox"></i>
</div>
<h3>No Shipping Reports Found</h3>
<p>There are no shipping reports matching your current filters</p>
</div>
</td>
</tr>
@endforelse
</tbody>
</table>
</div>
<!-- Pagination Controls -->
<div class="pagination-container">
<div class="pagination-info" id="pageInfo">Showing 1 to {{ min(10, count($reports)) }} of {{ count($reports) }} 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($reports) > 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>
</div>
<script>
// Pagination state
let currentPage = 1;
const itemsPerPage = 10;
let allReports = @json($reports);
let filteredReports = [...allReports];
document.addEventListener('DOMContentLoaded', function() {
// Initialize statistics and pagination
updateStatistics();
renderTable();
updatePaginationControls();
// Set default dates for demo purposes
const today = new Date();
const lastMonth = new Date(today.getFullYear(), today.getMonth() - 1, today.getDate());
const formatDate = (date) => {
return date.toISOString().split('T')[0];
};
document.getElementById('fromDate').value = formatDate(lastMonth);
document.getElementById('toDate').value = formatDate(today);
// Add event listeners for filters
document.getElementById('fromDate').addEventListener('change', filterTable);
document.getElementById('toDate').addEventListener('change', filterTable);
document.getElementById('companyFilter').addEventListener('change', filterTable);
document.getElementById('statusFilter').addEventListener('change', filterTable);
// Bind pagination events
document.getElementById('prevPageBtn').addEventListener('click', goToPreviousPage);
document.getElementById('nextPageBtn').addEventListener('click', goToNextPage);
function updateStatistics() {
const rows = document.querySelectorAll('#reportTableBody tr');
let totalShipments = 0;
let pendingShipments = 0;
let inTransitShipments = 0;
let dispatchedShipments = 0;
let deliveredShipments = 0;
let overdueInvoices = 0;
rows.forEach(row => {
// Skip if row is hidden or empty state
if (row.style.display === 'none' || row.querySelector('.empty-state')) return;
totalShipments++;
// Count shipment statuses
const status = row.getAttribute('data-status');
if (status === 'pending') pendingShipments++;
if (status === 'in_transit') inTransitShipments++;
if (status === 'dispatched') dispatchedShipments++;
if (status === 'delivered') deliveredShipments++;
// Count invoice statuses
const invoiceStatus = row.getAttribute('data-invoice-status');
if (invoiceStatus === 'overdue') overdueInvoices++;
});
// Update statistics cards
document.getElementById('totalShipments').textContent = totalShipments;
document.getElementById('pendingShipments').textContent = pendingShipments;
document.getElementById('inTransitShipments').textContent = inTransitShipments;
document.getElementById('dispatchedShipments').textContent = dispatchedShipments;
document.getElementById('deliveredShipments').textContent = deliveredShipments;
document.getElementById('overdueInvoices').textContent = overdueInvoices;
}
// Pagination Functions
function goToPreviousPage() {
if (currentPage > 1) {
currentPage--;
renderTable();
updatePaginationControls();
}
}
function goToNextPage() {
const totalPages = Math.ceil(filteredReports.length / itemsPerPage);
if (currentPage < totalPages) {
currentPage++;
renderTable();
updatePaginationControls();
}
}
function updatePaginationControls() {
const totalPages = Math.ceil(filteredReports.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, filteredReports.length);
pageInfo.textContent = `Showing ${startIndex} to ${endIndex} of ${filteredReports.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('reportTableBody');
tbody.innerHTML = '';
if (filteredReports.length === 0) {
tbody.innerHTML = `
<tr>
<td colspan="12">
<div class="empty-state">
<div class="empty-icon">
<i class="fas fa-inbox"></i>
</div>
<h3>No Shipping Reports Found</h3>
<p>There are no shipping reports matching your current filters</p>
</div>
</td>
</tr>
`;
return;
}
// Calculate pagination
const startIndex = (currentPage - 1) * itemsPerPage;
const endIndex = startIndex + itemsPerPage;
const paginatedItems = filteredReports.slice(startIndex, endIndex);
paginatedItems.forEach(report => {
const ist = (report.invoice_status || '').toLowerCase();
const row = document.createElement('tr');
row.setAttribute('data-status', report.shipment_status);
row.setAttribute('data-invoice-status', ist);
row.setAttribute('data-company', report.company_name || '');
row.setAttribute('data-date', report.shipment_date);
row.innerHTML = `
<td>
<span class="data-highlight" title="${report.order_id}">
<i class="fas fa-hashtag"></i>
${report.order_id}
</span>
</td>
<td>
<span class="data-highlight" title="${report.shipment_id}">
<i class="fas fa-barcode"></i>
${report.shipment_id}
</span>
</td>
<td title="${report.company_name || '-'}">${report.company_name || '-'}</td>
<td title="${report.customer_name || '-'}">${report.customer_name || '-'}</td>
<td>
<span class="data-highlight" title="${report.origin}">
<i class="fas fa-map-marker-alt"></i>
${report.origin}
</span>
</td>
<td>
<span class="data-highlight" title="${report.destination}">
<i class="fas fa-location-arrow"></i>
${report.destination}
</span>
</td>
<td>${new Date(report.shipment_date).toLocaleDateString('en-GB')}</td>
<td>
<span class="data-highlight" title="${report.invoice_number}">
<i class="fas fa-file-invoice"></i>
${report.invoice_number}
</span>
</td>
<td>${new Date(report.invoice_date).toLocaleDateString('en-GB')}</td>
<td>
<span class="data-highlight" title="₹${Number(report.final_amount).toLocaleString('en-IN')}">
<i class="fas fa-rupee-sign"></i>
${Number(report.final_amount).toLocaleString('en-IN')}
</span>
</td>
<td>
<span class="status-badge
${ist === 'paid' ? 'status-paid' : ''}
${ist === 'pending' ? 'status-pending' : ''}
${ist === 'overdue' ? 'status-overdue' : ''}">
<i class="fas fa-circle"></i>
${ist.charAt(0).toUpperCase() + ist.slice(1)}
</span>
</td>
<td>
<span class="status-badge ship-${report.shipment_status}">
<i class="fas fa-circle"></i>
${report.shipment_status.charAt(0).toUpperCase() + report.shipment_status.slice(1).replace('_', ' ')}
</span>
</td>
`;
tbody.appendChild(row);
});
}
function filterTable() {
const fromDate = document.getElementById('fromDate').value;
const toDate = document.getElementById('toDate').value;
const companyFilter = document.getElementById('companyFilter').value;
const statusFilter = document.getElementById('statusFilter').value;
filteredReports = allReports.filter(report => {
let include = true;
// Date filter
if (fromDate && toDate) {
const reportDate = new Date(report.shipment_date);
const from = new Date(fromDate);
const to = new Date(toDate);
to.setHours(23, 59, 59, 999);
if (reportDate < from || reportDate > to) {
include = false;
}
}
// Company filter
if (companyFilter && report.company_name !== companyFilter) {
include = false;
}
// Status filter
if (statusFilter && report.shipment_status !== statusFilter) {
include = false;
}
return include;
});
currentPage = 1;
renderTable();
updatePaginationControls();
updateStatistics();
}
// Add hover effects to table rows
const tableRows = document.querySelectorAll('.report-table tbody tr');
tableRows.forEach(row => {
row.addEventListener('mouseenter', function() {
this.style.transform = 'translateY(-2px)';
});
row.addEventListener('mouseleave', function() {
this.style.transform = 'translateY(0)';
});
});
// Initial filter application
filterTable();
});
</script>
@endsection