@include('hk.header')
User Activity Report
{{-- Filter Form --}}
{{-- Data Table --}}
| User Name |
Date |
No. of Companies Added |
No. of Products Added |
@php
$grandTotalCompanies = 0;
$grandTotalProducts = 0;
@endphp
@foreach ($users as $user)
@php
// use the aggregated properties created in controller
$companyDates = collect($user->company_dates);
$productDates = collect($user->product_dates);
// merge dates from both collections
$dates = $companyDates
->pluck('date')
->merge($productDates->pluck('date'))
->unique()
->sort()
->values(); // reindex
@endphp
@if ($dates->isEmpty())
{{-- show a single empty row for user if no data --}}
| {{ $user->name }} |
- |
0 |
0 |
@else
@foreach ($dates as $index => $date)
@php
// get counts from aggregated rows (null-safe)
$companyRow = $companyDates->firstWhere('date', $date);
$productRow = $productDates->firstWhere('date', $date);
$companyCount = $companyRow->companies_count ?? 0;
$productCount = $productRow->products_count ?? 0;
$grandTotalCompanies += $companyCount;
$grandTotalProducts += $productCount;
$rowspan = $dates->count();
@endphp
@if ($index === 0)
| {{ $user->name }} |
@endif
{{ $date }} |
{{ $companyCount }} |
{{ $productCount }} |
@endforeach
@endif
@endforeach
| Total |
{{ $grandTotalCompanies }} |
{{ $grandTotalProducts }} |
{{ $users->links() }}
@include('hk.footer')