Files
Kent-logistics-Laravel/resources/views/admin/orders.blade.php
Utkarsh Khedkar 9cc6959396 Pdf Changes Done
2026-03-09 10:24:44 +05:30

1116 lines
32 KiB
PHP

@extends('admin.layouts.app')
@section('page-title', 'Invoices')
@section('content')
<style>
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');
:root {
--admin-font: 'Inter', sans-serif;
--primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
--success-gradient: linear-gradient(135deg, #10b981, #34d399);
--warning-gradient: linear-gradient(135deg, #fef3c7, #fde68a);
--danger-gradient: linear-gradient(135deg, #fef2f2, #fecaca);
--info-gradient: linear-gradient(135deg, #dbeafe, #bfdbfe);
--purple-gradient: linear-gradient(135deg, #e9d5ff, #d8b4fe);
}
body, input, select, textarea, button, table, th, td, .orders-container {
font-family: var(--admin-font);
}
:root {
--primary-color: #3b82f6;
--primary-hover: #2563eb;
--border-light: #e5e7eb;
--bg-container: #ffffff;
--bg-light: #f9fafb;
--bg-hover: #f3f4f6;
--text-dark: #1f2937;
--text-muted: #6b7280;
--shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
--shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
}
.orders-container {
background: var(--bg-container);
padding: 24px;
border-radius: 16px;
box-shadow: var(--shadow-lg);
margin-top: 28px;
border: 1px solid rgba(0,0,0,0.05);
}
.orders-title {
font-size: 28px;
font-weight: 700;
margin-bottom: 24px;
color: var(--text-dark);
display: flex;
align-items: center;
gap: 12px;
}
.orders-title i {
background: var(--primary-gradient);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
font-size: 32px;
}
.stats-container {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 16px;
margin-bottom: 24px;
}
.stat-card {
display: flex;
align-items: center;
gap: 16px;
padding: 20px 22px;
border-radius: 14px;
border-left: 4px solid;
box-shadow: 0 2px 8px rgba(0,0,0,0.06);
transition: transform 0.3s ease, box-shadow 0.3s ease;
position: relative;
overflow: hidden;
}
.stat-card:hover {
transform: translateY(-4px);
box-shadow: 0 8px 20px rgba(0,0,0,0.1);
}
.stat-card.total {
background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
border-left-color: #3b82f6;
}
.stat-card.paid {
background: linear-gradient(135deg, #f0fdf4 0%, #dcfce7 100%);
border-left-color: #22c55e;
}
.stat-card.pending {
background: linear-gradient(135deg, #fffbeb 0%, #fef9c3 100%);
border-left-color: #f59e0b;
}
.stat-card.overdue {
background: linear-gradient(135deg, #fff5f5 0%, #fee2e2 100%);
border-left-color: #ef4444;
}
.stat-icon-wrap {
width: 48px;
height: 48px;
border-radius: 12px;
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
font-size: 20px;
}
.stat-card.total .stat-icon-wrap { background: rgba(59,130,246,0.12); color: #3b82f6; }
.stat-card.paid .stat-icon-wrap { background: rgba(34,197,94,0.15); color: #16a34a; }
.stat-card.pending .stat-icon-wrap{ background: rgba(245,158,11,0.15); color: #d97706; }
.stat-card.overdue .stat-icon-wrap{ background: rgba(239,68,68,0.12); color: #dc2626; }
.stat-text {
display: flex;
flex-direction: column;
gap: 4px;
}
.stat-value {
font-size: 26px;
font-weight: 700;
line-height: 1;
color: var(--text-dark);
}
.stat-label {
font-size: 13px;
color: var(--text-muted);
font-weight: 500;
}
.download-section {
display: flex;
justify-content: flex-end;
margin-bottom: 20px;
gap: 12px;
}
.download-btn {
display: inline-flex;
align-items: center;
gap: 8px;
padding: 12px 20px;
border: none;
border-radius: 10px;
font-size: 14px;
font-weight: 600;
cursor: pointer;
transition: all 0.3s ease;
text-decoration: none;
box-shadow: var(--shadow-sm);
}
.download-btn i {
font-size: 16px;
}
.download-btn.pdf {
background: linear-gradient(135deg, #ef4444, #dc2626);
color: white;
}
.download-btn.pdf:hover {
background: linear-gradient(135deg, #dc2626, #b91c1c);
transform: translateY(-2px);
box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}
.download-btn.excel {
background: linear-gradient(135deg, #10b981, #059669);
color: white;
}
.download-btn.excel:hover {
background: linear-gradient(135deg, #059669, #047857);
transform: translateY(-2px);
box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}
.download-btn:disabled {
opacity: 0.6;
cursor: not-allowed;
transform: none !important;
}
.table-wrapper {
overflow-x: auto;
max-width: 100%;
border-radius: 12px;
border: 1px solid var(--border-light);
box-shadow: var(--shadow-sm);
background: white;
}
.orders-table {
width: 100%;
min-width: 1000px;
border-collapse: separate;
border-spacing: 0;
font-size: 14px;
color: var(--text-dark);
}
.orders-table thead {
background: var(--primary-gradient);
position: sticky;
top: 0;
z-index: 10;
}
.orders-table th {
padding: 16px 20px;
text-align: center;
font-size: 14px;
font-weight: 600;
color: white;
border-bottom: none;
white-space: nowrap;
position: relative;
transition: background 0.3s ease;
}
.orders-table th:hover {
background: rgba(255, 255, 255, 0.1);
}
.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;
transition: background 0.2s ease;
}
.orders-table tbody tr:last-child td {
border-bottom: none;
}
.orders-table tbody tr:hover td {
background: var(--bg-hover);
}
.status-badge {
font-size: 11px !important;
font-weight: 600 !important;
padding: 8px 14px 8px 10px !important;
border-radius: 20px !important;
text-transform: uppercase;
letter-spacing: 0.3px;
display: inline-flex !important;
align-items: center;
justify-content: center;
color: #fff !important;
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;
transition: all 0.3s ease;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.status-badge:hover {
transform: translateY(-2px);
box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}
.status-badge::before {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: inherit;
opacity: 0.9;
z-index: -1;
}
.status-icon {
font-size: 11px;
display: flex;
align-items: center;
justify-content: center;
position: relative;
z-index: 1;
}
.status-paid {
background: var(--success-gradient) !important;
color: white !important;
border-color: #059669 !important;
width: 99px;
}
.status-pending {
background: var(--warning-gradient) !important;
color: #d97706 !important;
border-color: #f59e0b !important;
width: 99px;
}
.status-overdue {
background: var(--danger-gradient) !important;
color: #dc2626 !important;
border-color: #ef4444 !important;
width: 99px;
}
.no-data {
padding: 60px 40px;
text-align: center;
font-size: 16px;
color: var(--text-muted);
background: var(--bg-light);
border-radius: 12px;
margin-top: 10px;
border: 1px solid var(--border-light);
display: flex;
flex-direction: column;
align-items: center;
gap: 16px;
}
.no-data i {
font-size: 48px;
color: #d1d5db;
}
.pagination-container {
display: flex;
justify-content: space-between;
align-items: center;
margin-top: 20px;
padding: 16px 0;
border-top: 1px solid #eef3fb;
}
.pagination-info {
font-size: 14px;
color: #6b7280;
font-weight: 500;
}
.pagination-controls {
display: flex;
align-items: center;
gap: 8px;
}
.pagination-img-btn {
background: white;
border: 1px solid #e3eaf6;
border-radius: 8px;
cursor: pointer;
transition: all 0.3s ease;
display: flex;
align-items: center;
justify-content: center;
width: 40px;
height: 40px;
padding: 0;
box-shadow: var(--shadow-sm);
}
.pagination-img-btn:hover:not(:disabled) {
background: var(--primary-color);
border-color: var(--primary-color);
transform: translateY(-2px);
box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}
.pagination-img-btn:disabled {
background: #f8fafc;
border-color: #e2e8f0;
cursor: not-allowed;
opacity: 0.5;
}
.pagination-page-btn {
background: white;
border: 1px solid #e3eaf6;
color: #1a2951;
padding: 8px 12px;
border-radius: 8px;
font-size: 14px;
font-weight: 600;
cursor: pointer;
transition: all 0.3s ease;
min-width: 40px;
text-align: center;
box-shadow: var(--shadow-sm);
}
.pagination-page-btn:hover {
background: var(--primary-color);
color: white;
border-color: var(--primary-color);
transform: translateY(-2px);
}
.pagination-page-btn.active {
background: var(--primary-color);
color: white;
border-color: var(--primary-color);
box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}
.pagination-pages {
display: flex;
gap: 4px;
align-items: center;
}
.pagination-ellipsis {
color: #9ba5bb;
font-size: 14px;
padding: 0 8px;
}
.filter-bar {
display: flex;
gap: 16px;
margin-bottom: 24px;
flex-wrap: wrap;
align-items: center;
}
.search-box {
flex: 1;
min-width: 300px;
position: relative;
}
.search-input {
width: 100%;
padding: 12px 16px 12px 44px;
border: 1px solid var(--border-light);
border-radius: 10px;
font-size: 14px;
transition: all 0.3s ease;
background: white;
box-shadow: var(--shadow-sm);
}
.search-input:focus {
outline: none;
border-color: var(--primary-color);
box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}
.search-icon {
position: absolute;
left: 16px;
top: 50%;
transform: translateY(-50%);
color: var(--text-muted);
}
.filter-select {
padding: 12px 16px;
border: 1px solid var(--border-light);
border-radius: 10px;
font-size: 14px;
background: white;
box-shadow: var(--shadow-sm);
cursor: pointer;
min-width: 160px;
}
.date-range {
display: flex;
gap: 12px;
align-items: center;
}
.date-input {
padding: 12px 16px;
border: 1px solid var(--border-light);
border-radius: 10px;
font-size: 14px;
background: white;
box-shadow: var(--shadow-sm);
min-width: 150px;
}
.date-label {
font-size: 14px;
color: var(--text-muted);
font-weight: 500;
white-space: nowrap;
}
@media(max-width: 768px) {
.orders-title { font-size: 24px; }
.orders-container { padding: 16px; }
.stats-container { grid-template-columns: 1fr 1fr; }
.stat-card { padding: 14px 16px; }
.stat-value { font-size: 22px; }
.download-section { justify-content: stretch; }
.download-btn { flex: 1; justify-content: center; }
.filter-bar { flex-direction: column; align-items: stretch; }
.search-box { min-width: 100%; }
.filter-select, .date-input { width: 100%; }
.date-range { flex-direction: column; align-items: stretch; }
.pagination-container { flex-direction: column; gap: 16px; }
}
@media(max-width: 480px) {
.stats-container { grid-template-columns: 1fr; }
}
</style>
<div class="orders-container">
<div class="orders-title">
<i class="fas fa-file-invoice-dollar"></i> Invoices Management
</div>
<div class="stats-container">
@php
$totalInvoices = $invoices->count();
$paidInvoices = $invoices->where('invoice_status', 'paid')->count();
$pendingInvoices = $invoices->where('invoice_status', 'pending')->count();
$overdueInvoices = $invoices->where('invoice_status', 'overdue')->count();
@endphp
<div class="stat-card total">
<div class="stat-icon-wrap">
<i class="fas fa-file-invoice"></i>
</div>
<div class="stat-text">
<div class="stat-value">{{ $totalInvoices }}</div>
<div class="stat-label">Total Invoices</div>
</div>
</div>
<div class="stat-card paid">
<div class="stat-icon-wrap">
<i class="fas fa-check-circle"></i>
</div>
<div class="stat-text">
<div class="stat-value">{{ $paidInvoices }}</div>
<div class="stat-label">Paid Invoices</div>
</div>
</div>
<div class="stat-card pending">
<div class="stat-icon-wrap">
<i class="fas fa-clock"></i>
</div>
<div class="stat-text">
<div class="stat-value">{{ $pendingInvoices }}</div>
<div class="stat-label">Pending Invoices</div>
</div>
</div>
<div class="stat-card overdue">
<div class="stat-icon-wrap">
<i class="fas fa-exclamation-triangle"></i>
</div>
<div class="stat-text">
<div class="stat-value">{{ $overdueInvoices }}</div>
<div class="stat-label">Overdue Invoices</div>
</div>
</div>
</div>
<div class="download-section">
<button class="download-btn pdf" id="downloadPdf" {{ $invoices->count() == 0 ? 'disabled' : '' }}>
<i class="fas fa-file-pdf"></i>
Download PDF
</button>
<button class="download-btn excel" id="downloadExcel" {{ $invoices->count() == 0 ? 'disabled' : '' }}>
<i class="fas fa-file-excel"></i>
Download Excel
</button>
</div>
<div class="filter-bar">
<div class="search-box">
<i class="fas fa-search search-icon"></i>
<input type="text" class="search-input" placeholder="Search invoices..." id="searchInput">
</div>
<select class="filter-select" id="statusFilter">
<option value="">All Invoice Status</option>
<option value="paid">Paid</option>
<option value="pending">Pending</option>
<option value="overdue">Overdue</option>
</select>
<div class="date-range">
<span class="date-label">From:</span>
<input type="date" class="date-input" id="fromDate">
<span class="date-label">To:</span>
<input type="date" class="date-input" id="toDate">
</div>
</div>
@if($invoices->count() > 0)
<div class="table-wrapper">
<table class="orders-table">
<thead>
<tr>
<th>Invoice No</th>
<th>Invoice Date</th>
{{-- <th>Mark No</th> --}}
<th>Container No</th>
<th>Container Date</th>
<th>Company</th>
<th>Customer</th>
<th>Amount</th>
<th>Amount + GST</th>
<th>Status</th>
</tr>
</thead>
<tbody id="ordersTableBody">
@foreach($invoices as $inv)
@php
$status = strtolower($inv->invoice_status ?? 'pending');
@endphp
<tr>
<td>
@if($inv->invoice_number)
<a href="javascript:void(0);"
class="invoice-popup-link"
data-invoice-id="{{ $inv->id }}">
{{ $inv->invoice_number }}
</a>
@else
-
@endif
</td>
<td>{{ $inv->invoice_date ? \Carbon\Carbon::parse($inv->invoice_date)->format('d-m-Y') : '-' }}</td>
{{-- <td>{{ $inv->mark_no ?? '-' }}</td> --}}
<td>
@if(!empty($inv->container_id) && !empty($inv->container_number))
<a href="javascript:void(0);"
class="container-popup-link"
data-container-id="{{ $inv->container_id }}">
{{ $inv->container_number }}
</a>
@else
-
@endif
</td>
<td>{{ $inv->container_date ? \Carbon\Carbon::parse($inv->container_date)->format('d-m-Y') : '-' }}</td>
<td>{{ $inv->company_name ?? '-' }}</td>
<td>{{ $inv->customer_name ?? '-' }}</td>
<td>{{ $inv->final_amount ? '₹'.number_format($inv->final_amount, 2) : '-' }}</td>
<td>{{ $inv->final_amount_with_gst ? '₹'.number_format($inv->final_amount_with_gst, 2) : '-' }}</td>
<td>
<span class="status-badge status-{{ $status }}">
{{ ucfirst($status) }}
</span>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
<div class="pagination-container">
<div class="pagination-info" id="pageInfo">
Showing 1 to {{ min(10, count($invoices)) }} of {{ count($invoices) }} entries
</div>
<div class="pagination-controls">
<button class="pagination-img-btn" id="prevPageBtn" title="Previous page" disabled>
<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"></div>
<button class="pagination-img-btn" id="nextPageBtn" title="Next page" {{ count($invoices) > 10 ? '' : 'disabled' }}>
<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
<div class="no-data">
<i class="fas fa-inbox"></i>
<div>No invoices found</div>
<p class="text-muted">There are currently no invoices in the system.</p>
</div>
@endif
</div>
<div class="modal fade" id="invoiceModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog modal-xl modal-dialog-scrollable">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="invoiceModalTitle">Invoice Details</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body" id="invoiceModalBody">
<p class="text-center text-muted">Loading...</p>
</div>
</div>
</div>
</div>
<script>
let currentPage = 1;
const itemsPerPage = 10;
let allInvoices = {!! $invoices->toJson() !!};
let filteredInvoices = [...allInvoices];
function getInvoiceStatusIcon(status) {
switch(status) {
case 'paid': return '<i class="fas fa-check-circle status-icon"></i>';
case 'pending': return '<i class="fas fa-clock status-icon"></i>';
case 'overdue': return '<i class="fas fa-exclamation-triangle status-icon"></i>';
default: return '';
}
}
function isValidDate(dateString) {
if (!dateString) return false;
const date = new Date(dateString);
return date instanceof Date && !isNaN(date);
}
function isDateBetween(dateToCheck, fromDate, toDate) {
if (!dateToCheck) return true;
const checkDate = new Date(dateToCheck);
if (!isValidDate(checkDate)) return true;
checkDate.setHours(0,0,0,0);
if (fromDate && isValidDate(fromDate)) {
const from = new Date(fromDate);
from.setHours(0,0,0,0);
if (checkDate < from) return false;
}
if (toDate && isValidDate(toDate)) {
const to = new Date(toDate);
to.setHours(23,59,59,999);
if (checkDate > to) return false;
}
return true;
}
function invoiceMatchesFilters(inv, searchTerm, statusFilter, fromDate, toDate) {
let matchesSearch = true;
if (searchTerm) {
const term = searchTerm.toLowerCase();
const fields = [
inv.invoice_number?.toString().toLowerCase(),
// inv.mark_no?.toString().toLowerCase(),
inv.container_number?.toString().toLowerCase(),
inv.company_name?.toString().toLowerCase(),
inv.customer_name?.toString().toLowerCase()
];
matchesSearch = fields.some(f => f && f.includes(term));
}
const status = (inv.invoice_status || 'pending').toLowerCase();
const matchesStatus = !statusFilter || status === statusFilter;
const invDate = inv.invoice_date;
const matchesDate = isDateBetween(invDate, fromDate, toDate);
return matchesSearch && matchesStatus && matchesDate;
}
document.addEventListener('DOMContentLoaded', function () {
renderTable();
updatePaginationControls();
document.getElementById('prevPageBtn').addEventListener('click', goToPreviousPage);
document.getElementById('nextPageBtn').addEventListener('click', goToNextPage);
document.getElementById('searchInput').addEventListener('input', handleFilter);
document.getElementById('statusFilter').addEventListener('change', handleFilter);
document.getElementById('fromDate').addEventListener('change', handleFilter);
document.getElementById('toDate').addEventListener('change', handleFilter);
document.getElementById('downloadPdf').addEventListener('click', downloadPdf);
document.getElementById('downloadExcel').addEventListener('click', downloadExcel);
document.addEventListener('click', function(e) {
const invLink = e.target.closest('.invoice-popup-link');
if (invLink) {
e.preventDefault();
openInvoicePopup(invLink.dataset.invoiceId);
return;
}
const contLink = e.target.closest('.container-popup-link');
if (contLink) {
e.preventDefault();
openContainerPopup(contLink.dataset.containerId);
}
});
});
function handleFilter() {
const searchTerm = document.getElementById('searchInput').value;
const statusFilter = document.getElementById('statusFilter').value;
const fromDate = document.getElementById('fromDate').value;
const toDate = document.getElementById('toDate').value;
filteredInvoices = allInvoices.filter(inv =>
invoiceMatchesFilters(inv, searchTerm, statusFilter, fromDate, toDate)
);
currentPage = 1;
renderTable();
updatePaginationControls();
const hasResults = filteredInvoices.length > 0;
document.getElementById('downloadPdf').disabled = !hasResults;
document.getElementById('downloadExcel').disabled = !hasResults;
}
function goToPreviousPage() {
if (currentPage > 1) {
currentPage--;
renderTable();
updatePaginationControls();
}
}
function goToNextPage() {
const totalPages = Math.ceil(filteredInvoices.length / itemsPerPage);
if (currentPage < totalPages) {
currentPage++;
renderTable();
updatePaginationControls();
}
}
function updatePaginationControls() {
const totalPages = Math.ceil(filteredInvoices.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;
const startIndex = (currentPage - 1) * itemsPerPage + 1;
const endIndex = Math.min(currentPage * itemsPerPage, filteredInvoices.length);
pageInfo.textContent = `Showing ${startIndex} to ${endIndex} of ${filteredInvoices.length} entries`;
paginationPages.innerHTML = '';
if (totalPages <= 7) {
for (let i = 1; i <= totalPages; i++) addPageButton(i, paginationPages);
} else {
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);
}
function renderTable() {
const tbody = document.getElementById('ordersTableBody');
tbody.innerHTML = '';
if (filteredInvoices.length === 0) {
tbody.innerHTML = '<tr><td colspan="9" class="text-center py-4 text-muted">No invoices found matching your criteria.</td></tr>';
return;
}
const startIndex = (currentPage - 1) * itemsPerPage;
const endIndex = startIndex + itemsPerPage;
const paginated = filteredInvoices.slice(startIndex, endIndex);
paginated.forEach(inv => {
const status = (inv.invoice_status || 'pending').toLowerCase();
const row = document.createElement('tr');
row.innerHTML = `
<td>
${
inv.invoice_number
? `<a href="javascript:void(0);" class="invoice-popup-link" data-invoice-id="${inv.id}">
${inv.invoice_number}
</a>`
: '-'
}
</td>
<td>${inv.invoice_date ? new Date(inv.invoice_date).toLocaleDateString('en-GB') : '-'}</td>
<!-- <td>${inv.mark_no || '-'}</td> -->
<td>
${
inv.container_id && inv.container_number
? `<a href="javascript:void(0);" class="container-popup-link" data-container-id="${inv.container_id}">
${inv.container_number}
</a>`
: '-'
}
</td>
<td>${inv.container_date ? new Date(inv.container_date).toLocaleDateString('en-GB') : '-'}</td>
<td>${inv.company_name || '-'}</td>
<td>${inv.customer_name || '-'}</td>
<td>${inv.final_amount ? '₹' + Number(inv.final_amount).toLocaleString('en-IN', {minimumFractionDigits: 2, maximumFractionDigits: 2}) : '-'}</td>
<td>${inv.final_amount_with_gst ? '₹' + Number(inv.final_amount_with_gst).toLocaleString('en-IN', {minimumFractionDigits: 2, maximumFractionDigits: 2}) : '-'}</td>
<td>
<span class="status-badge status-${status}">
${getInvoiceStatusIcon(status)}${status.charAt(0).toUpperCase() + status.slice(1)}
</span>
</td>
`;
tbody.appendChild(row);
});
}
function openInvoicePopup(invoiceId) {
const modal = new bootstrap.Modal(document.getElementById('invoiceModal'));
document.getElementById('invoiceModalTitle').textContent = 'Invoice Details';
document.getElementById('invoiceModalBody').innerHTML =
"<div class='text-center py-4'>" +
"<div class='spinner-border text-primary' role='status'></div>" +
"<p class='mt-2 text-muted'>Loading invoice details...</p>" +
"</div>";
modal.show();
fetch(`/admin/invoices/${invoiceId}/popup`)
.then(res => {
if (!res.ok) throw new Error('Network error');
return res.text();
})
.then(html => {
document.getElementById('invoiceModalBody').innerHTML = html;
})
.catch(error => {
console.error(error);
document.getElementById('invoiceModalBody').innerHTML =
"<div class='text-center py-4 text-danger'>" +
"<i class='bi bi-exclamation-triangle fs-1'></i>" +
"<p class='mt-2'>Failed to load invoice details. Please try again.</p>" +
"</div>";
});
}
function openContainerPopup(containerId) {
const modal = new bootstrap.Modal(document.getElementById('invoiceModal'));
document.getElementById('invoiceModalTitle').textContent = 'Container Details';
document.getElementById('invoiceModalBody').innerHTML =
"<div class='text-center py-4'>" +
"<div class='spinner-border text-primary' role='status'></div>" +
"<p class='mt-2 text-muted'>Loading container details...</p>" +
"</div>";
modal.show();
fetch(`/admin/containers/${containerId}/popup`)
.then(res => {
if (!res.ok) throw new Error('Network error');
return res.text();
})
.then(html => {
document.getElementById('invoiceModalBody').innerHTML = html;
})
.catch(error => {
console.error(error);
document.getElementById('invoiceModalBody').innerHTML =
"<div class='text-center py-4 text-danger'>" +
"<i class='bi bi-exclamation-triangle fs-1'></i>" +
"<p class='mt-2'>Failed to load container details.</p>" +
"</div>";
});
}
function downloadPdf() {
if (filteredInvoices.length === 0) {
showNotification('No data available to download', 'warning');
return;
}
showNotification('Preparing PDF download...', 'info');
const searchTerm = document.getElementById('searchInput').value;
const statusFilter = document.getElementById('statusFilter').value;
const fromDate = document.getElementById('fromDate').value;
const toDate = document.getElementById('toDate').value;
let downloadUrl = "{{ route('admin.orders.download.pdf') }}";
let params = new URLSearchParams();
params.append('search', searchTerm || '');
params.append('status', statusFilter || '');
params.append('from_date', fromDate || '');
params.append('to_date', toDate || '');
window.location.href = downloadUrl + '?' + params.toString();
}
function downloadExcel() {
if (filteredInvoices.length === 0) {
showNotification('No data available to download', 'warning');
return;
}
showNotification('Preparing Excel download...', 'info');
const searchTerm = document.getElementById('searchInput').value;
const statusFilter = document.getElementById('statusFilter').value;
const fromDate = document.getElementById('fromDate').value;
const toDate = document.getElementById('toDate').value;
let downloadUrl = "{{ route('admin.orders.download.excel') }}";
let params = new URLSearchParams();
params.append('search', searchTerm || '');
params.append('status', statusFilter || '');
params.append('from_date', fromDate || '');
params.append('to_date', toDate || '');
window.location.href = downloadUrl + '?' + params.toString();
}
function showNotification(message, type = 'info') {
const existing = document.querySelector('.download-notification');
if (existing) existing.remove();
const notification = document.createElement('div');
notification.className = `download-notification alert alert-${type}`;
notification.style.cssText = `
position: fixed;
top: 20px;
right: 20px;
z-index: 10000;
padding: 12px 20px;
border-radius: 8px;
color: white;
font-weight: 500;
box-shadow: 0 4px 12px rgba(0,0,0,0.15);
animation: slideIn 0.3s ease;
`;
if (type === 'info') {
notification.style.background = 'linear-gradient(135deg, #3b82f6, #1d4ed8)';
} else if (type === 'warning') {
notification.style.background = 'linear-gradient(135deg, #f59e0b, #d97706)';
} else if (type === 'success') {
notification.style.background = 'linear-gradient(135deg, #10b981, #059669)';
}
notification.textContent = message;
document.body.appendChild(notification);
setTimeout(() => {
notification.style.animation = 'slideOut 0.3s ease';
setTimeout(() => notification.remove(), 300);
}, 3000);
}
const style = document.createElement('style');
style.textContent = `
@keyframes slideIn {
from { transform: translateX(100%); opacity: 0; }
to { transform: translateX(0); opacity: 1; }
}
@keyframes slideOut {
from { transform: translateX(0); opacity: 1; }
to { transform: translateX(100%); opacity: 0; }
}
`;
document.head.appendChild(style);
</script>
@endsection