@php
function ordinal($number)
{
if (!$number) {
return '-';
}
$ends = ['th', 'st', 'nd', 'rd', 'th', 'th', 'th', 'th', 'th', 'th'];
if ($number % 100 >= 11 && $number % 100 <= 13) {
return $number . 'th';
}
return $number . $ends[$number % 10];
}
// Get all main IDs first
$mainIds = $get_outward_data->pluck('id')->toArray();
// Fetch all sub data at once (outside the loop for better performance)
$all_sub_data = [];
if (!empty($mainIds)) {
$all_sub_data = DB::table('Outwardmodel_type1_t2s')
->whereIn('outward_id', $mainIds)
->leftJoin(
'customers',
'customers.customers',
'=',
'Outwardmodel_type1_t2s.customer_se',
)
->select(
'Outwardmodel_type1_t2s.*',
'customers.customers_name',
'customers.type',
'customers.distance',
)
->get()
->groupBy('outward_id');
}
$previous_date = null;
@endphp
| # |
Date |
OUT No |
AOD No |
Lorry No |
Max Weight |
Customer Names |
Weight(MT) |
Out Time |
In time |
Weight(MT) |
No of trips |
@php
$grand_driver_total = 0;
$grand_helper_total = 0;
@endphp
@forelse ($get_outward_data as $key => $data)
@php
$sub_items = $all_sub_data[$data->id] ?? collect([]);
$customer_names = $sub_items
->pluck('customers_name')
->filter()
->implode('/ ');
$aod = $sub_items->pluck('aod_td')->filter()->implode('/ ');
@endphp
{{-- Main Row --}}
| {{ $key + 1 }} |
{{ \Carbon\Carbon::parse($data->created_at)->format('d-m-Y') }} |
{{ $data->outward_number ?? '-' }} |
{{ $aod ?: '-' }} |
{{ $data->vehicle_no ?? '-' }}
{{ isset($data->v_type) ? "({$data->v_type})" : '' }} |
{{ $data->max_weight ?? '-' }} |
{{ $customer_names ?: '-' }} |
{{ $data->Weight ?? '-' }} |
{{ $data->time_out?? '-' }} |
{{ $data->time_in ?? '-' }} |
{{ $data->Weight ?? '-' }} |
{{ ordinal($data->vehicle_trip_no ?? null) }} |
@empty
| No data available |
@endforelse