{{-- resources/views/exports/monthly_sales_report.blade.php --}} @php $monthsArray = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ]; $reportSubTitle = ''; if ($filters['month'] != 12 && isset($monthsArray[$filters['month']])) { $reportSubTitle = 'FOR ' . strtoupper($monthsArray[$filters['month']]) . ', ' . $filters['year']; } else { $reportSubTitle = 'FOR THE YEAR ' . $filters['year']; } $grandTotalSales = 0; @endphp @if ($filters['month'] != 12) {{-- Specific Month View --}} @else {{-- All Months View --}} @endif @if ($filters['month'] != 12) {{-- Specific Month View --}} @php $currentMonthName = isset($monthsArray[$filters['month']]) ? $monthsArray[$filters['month']] : 'N/A'; @endphp @forelse($salesData as $index => $item) @php // For sales, 'amount' is the direct sale amount $dailySale = $item->amount ?? 0; $grandTotalSales += $dailySale; @endphp @empty @endforelse @if(count($salesData) > 0) @endif @else @php $monthlySalesStructured = []; $monthKeysForLoop = [ 'jansales' => 'January', 'febsales' => 'February', 'marsales' => 'March', 'aprsales' => 'April', 'maysales' => 'May', 'junsales' => 'June', 'julsales' => 'July', 'augsales' => 'August', 'sepsales' => 'September', 'octsales' => 'October', 'novsales' => 'November', 'decsales' => 'December', ]; foreach($monthKeysForLoop as $key => $name) { if (isset($salesData[$key]) && (float)$salesData[$key] != 0) { $monthlySalesStructured[] = ['name' => $name, 'sale' => (float)$salesData[$key]]; } } $grandTotalSales = isset($salesData['totalsales']) ? (float)$salesData['totalsales'] : 0; @endphp @if(empty($monthlySalesStructured)) @else @foreach($monthlySalesStructured as $data) @endforeach @endif @endif
MONTHLY SALES ANALYSIS REPORT
{{ $reportSubTitle }}
S/N MONTH OF SALE DATE OF SALE TOTAL DAILY SALE
MONTH TOTAL MONTHLY SALE
{{ $loop->iteration }} {{ $currentMonthName }} {{ \Carbon\Carbon::parse($item->date)->format('Y-m-d') }} {{ number_format($dailySale, 0) }}
No sales data available for this month.
Total Sales for {{ $currentMonthName }}: {{ number_format($grandTotalSales, 0) }}
No sales data available for the year {{ $filters['year'] }}.
{{ $data['name'] }} {{ number_format($data['sale'], 0) }}
Grand Total Yearly Sales: {{ number_format($grandTotalSales, 0) }}