@extends('layouts.app') @section('title', 'Final Close Tickets Report') @section('page-title', 'Final Close Tickets Report') @section('content')
@if(session('success')) @endif @if(session('error')) @endif
Total Closed
{{ $stats['total_closed'] ?? 0 }}
All closed tickets
Ready for Final Close
{{ $stats['ready_for_final_close'] ?? 0 }}
Pending final closure
Final Closed
{{ $stats['final_closed'] ?? 0 }}
Completed tickets
Total Overuse
{{ number_format($stats['total_overuse'] ?? 0, 2) }} Mbps
Bandwidth overuse
Approved Bandwidth

{{ number_format($stats['total_approved_bandwidth'] ?? 0, 2) }} Mbps

Total approved bandwidth
Used Bandwidth

{{ number_format($stats['total_used_bandwidth'] ?? 0, 2) }} Mbps

Total used bandwidth
Ready for Final Close
Tickets ready for final closure
{{ $totalReadyTickets ?? 0 }}
Total Tickets
@if(($readyGroups ?? collect())->isEmpty())
No Tickets Ready for Final Close

There are no closed tickets waiting for final closure.

@else @foreach($readyGroups as $customerId => $logs)
{{ optional($logs->first()->customer)->company_name ? $logs->first()->customer->company_name . ' - ' . $logs->first()->customer->name : optional($logs->first()->customer)->name ?? 'Unknown Customer' }} @if(optional($logs->first()->customer)->email) ({{ $logs->first()->customer->email }}) @endif
Total tickets ready for final close: {{ $logs->count() }}
0 selected
@php // Debug: Check if logs have salesInvoiceItem $hasInvoiceItems = $logs->filter(function($log) { return $log->salesInvoiceItem !== null; })->count(); $logsByInvoice = $logs->groupBy(function($log) { if ($log->salesInvoiceItem && $log->salesInvoiceItem->salesInvoice) { return $log->salesInvoiceItem->salesInvoice->id ?? 'no-invoice'; } return 'no-invoice'; }); @endphp @if($logsByInvoice->isEmpty())
No invoices found for this customer. @if($hasInvoiceItems > 0)
Found {{ $hasInvoiceItems }} logs with invoice items, but unable to group by invoice. @endif
@else
@foreach($logsByInvoice as $invoiceId => $invoiceLogs) @php $firstLog = $invoiceLogs->first(); $invoice = null; if ($firstLog->salesInvoiceItem && $firstLog->salesInvoiceItem->salesInvoice) { $invoice = $firstLog->salesInvoiceItem->salesInvoice; } $invoiceNumber = 'No Invoice'; $invoiceDate = ''; if ($invoice) { $invoiceNumber = $invoice->invoice_number ?? $invoice->invoice_no ?? 'N/A'; if ($invoice->invoice_date) { $invoiceDate = \Carbon\Carbon::parse($invoice->invoice_date)->format('M d, Y'); } } $uniqueId = 'invoice-' . $customerId . '-' . ($invoiceId !== 'no-invoice' ? $invoiceId : 'no-inv-' . $customerId); @endphp @endforeach
Select Action Invoice Number Invoice Date Items Count
{{ $invoiceNumber }} @if($invoiceDate) {{ $invoiceDate }} @else - @endif {{ $invoiceLogs->count() }} item(s)
@endif
@endforeach @endif
Final Closed Tickets
Tickets that have been final closed
{{ $totalFinalClosedTickets ?? 0 }}
Total Tickets
@if(($finalClosedGroups ?? collect())->isEmpty())
No Final Closed Tickets

There are no final closed tickets in the system.

@else @foreach($finalClosedGroups as $customerId => $logs)
{{ optional($logs->first()->customer)->company_name ? $logs->first()->customer->company_name . ' - ' . $logs->first()->customer->name : optional($logs->first()->customer)->name ?? 'Unknown Customer' }} @if(optional($logs->first()->customer)->email) ({{ $logs->first()->customer->email }}) @endif
Total final closed tickets: {{ $logs->count() }}
@php $logsByInvoice = $logs->groupBy(function($log) { $invoice = $log->salesInvoiceItem->salesInvoice ?? null; return $invoice ? $invoice->id : 'no-invoice-' . $log->id; }); @endphp @if($logsByInvoice->count() > 0)
@foreach($logsByInvoice as $invoiceId => $invoiceLogs) @php $firstLog = $invoiceLogs->first(); $invoice = $firstLog->salesInvoiceItem->salesInvoice ?? null; $invoiceNumber = $invoice ? ($invoice->invoice_number ?? 'N/A') : 'No Invoice'; $invoiceDate = $invoice && $invoice->invoice_date ? \Carbon\Carbon::parse($invoice->invoice_date)->format('M d, Y') : null; $uniqueId = 'final-' . $customerId . '-' . $invoiceId; @endphp @endforeach
Invoice Number Invoice Date Items Count
{{ $invoiceNumber }} @if($invoiceDate) {{ $invoiceDate }} @else - @endif {{ $invoiceLogs->count() }} item(s)
@endif
@endforeach @endif
@endsection @section('styles') @endsection @section('scripts') @endsection