@extends('template.app') @section('meta') @endsection @section('title') Inventory Report @endsection @section('styles') @endsection @section('content')
| Model | @foreach ($branches as $branch) @php $branch_full = $branch->name ?? ''; $b_name = str_contains($branch_full, 'Rajkot') ? 'Rajkot' : (str_contains($branch_full, 'Rjt_1s') ? 'Rajkot-1s' : (str_contains($branch_full, 'Jamnagar') ? 'Jamnagar' : (str_contains($branch_full, 'Junagadh') ? 'Junagadh' : (str_contains($branch_full, 'Morbi') ? 'Morbi' : (str_contains($branch_full, '_M') ? 'Mehsana' : (str_contains($branch_full, '_K') ? 'Kadi' : $branch_full)))))); @endphp{{ $b_name }} | @endforeachTotal | Transit | {{-- moved Transit right after Total --}}Grand Total | {{-- NEW Grand Total column --}}Allocated | Free Stock | PDI Hold |
|---|---|---|---|---|---|---|---|
| {{ $model->name }} | @foreach ($branches as $branch) @php $branchTotal = 0; $branchInventoryIds = []; if (!empty($data[$model->id])) { foreach ($data[$model->id] as $fuelTypeId => $fuel_data) { $statuses = $fuel_data[$branch->id] ?? []; foreach ($statuses as $status => $value) { if ($status !== 'inventory_ids' && is_numeric($value)) { $branchTotal += $value; } } if (isset($statuses['inventory_ids'])) { foreach ($statuses['inventory_ids'] as $status => $ids) { $branchInventoryIds = array_merge($branchInventoryIds, $ids); $modelInventoryIds['total'] = array_merge($modelInventoryIds['total'], $ids); if (in_array($status, ['allocated', 'allocatedDealer'])) { $modelInventoryIds['allocated'] = array_merge($modelInventoryIds['allocated'], $ids); } elseif ($status === 'active') { $modelInventoryIds['free'] = array_merge($modelInventoryIds['free'], $ids); } elseif ($status === 'pdi_hold') { $modelInventoryIds['pdi_hold'] = array_merge($modelInventoryIds['pdi_hold'], $ids); } } } $modelAllocated += $statuses['allocated'] ?? 0; $modelFree += $statuses['active'] ?? 0; $modelPdi += $statuses['pdi_hold'] ?? 0; } } @endphp@if (count($branchInventoryIds)) {{ count(array_unique($branchInventoryIds)) }} @else 0 @endif | @endforeach @php $modelTotal = count(array_unique($modelInventoryIds['total'])); foreach (['total', 'allocated', 'free', 'pdi_hold'] as $key) { $grandInventoryIds[$key] = array_merge($grandInventoryIds[$key], $modelInventoryIds[$key]); } @endphp {{-- Total --}}@if ($modelTotal) {{ $modelTotal }} @else 0 @endif | {{-- Transit (moved here for sequence) --}} @php $transitIds = []; if (isset($transitData[$model->id])) { foreach ($transitData[$model->id] as $fuelTransit) { foreach ($fuelTransit as $branchTransit) { $transitIds = array_merge($transitIds, $branchTransit['inventory_ids']); } } } $transitIds = array_unique($transitIds); // collect for footer $grandTransitIdsAll = array_merge($grandTransitIdsAll, $transitIds); @endphp@if (count($transitIds)) {{ count($transitIds) }} @else 0 @endif | {{-- Grand Total = unique(inventory_total_ids + transit_ids) --}} @php $grandTotalIdsModel = array_unique(array_merge( $modelInventoryIds['total'], $transitIds )); @endphp@if (count($grandTotalIdsModel)) {{ count($grandTotalIdsModel) }} @else 0 @endif | {{-- Allocated --}}@if (count($modelInventoryIds['allocated'])) {{ count(array_unique($modelInventoryIds['allocated'])) }} @else 0 @endif | {{-- Free Stock --}}@if (count($modelInventoryIds['free'])) {{ count(array_unique($modelInventoryIds['free'])) }} @else 0 @endif | {{-- PDI Hold --}}@if (count($modelInventoryIds['pdi_hold'])) {{ count(array_unique($modelInventoryIds['pdi_hold'])) }} @else 0 @endif |
| {{ $fuelTypes[$fuelTypeId] ?? 'Unknown' }} | @foreach ($branches as $branch) @php $statuses = $branchData[$branch->id] ?? []; $cellIds = []; if (isset($statuses['inventory_ids'])) { foreach ($statuses['inventory_ids'] as $status => $ids) { if (in_array($status, ['allocated', 'allocatedDealer', 'active', 'pdi_hold'])) { $fuelInventoryIds['total'] = array_merge($fuelInventoryIds['total'], $ids); if (in_array($status, ['allocated', 'allocatedDealer'])) { $fuelInventoryIds['allocated'] = array_merge($fuelInventoryIds['allocated'], $ids); } elseif ($status === 'active') { $fuelInventoryIds['free'] = array_merge($fuelInventoryIds['free'], $ids); } elseif ($status === 'pdi_hold') { $fuelInventoryIds['pdi_hold'] = array_merge($fuelInventoryIds['pdi_hold'], $ids); } $cellIds = array_merge($cellIds, $ids); } } } @endphp@if (count($cellIds)) {{ count(array_unique($cellIds)) }} @else 0 @endif | @endforeach {{-- Fuel Total --}}@if (count($fuelInventoryIds['total'])) {{ count(array_unique($fuelInventoryIds['total'])) }} @else 0 @endif | {{-- Fuel Transit (moved earlier) --}} @php $fuelTransitIds = []; if (isset($transitData[$model->id][$fuelTypeId])) { foreach ($branches as $branch) { if (!empty($transitData[$model->id][$fuelTypeId][$branch->id]['inventory_ids'])) { $fuelTransitIds = array_merge( $fuelTransitIds, $transitData[$model->id][$fuelTypeId][$branch->id]['inventory_ids'] ); } } } $fuelTransitIds = array_unique($fuelTransitIds); @endphp@if (count($fuelTransitIds)) {{ count(array_unique($fuelTransitIds)) }} @else 0 @endif | {{-- Fuel Grand Total --}} @php $fuelGrandIds = array_unique(array_merge($fuelInventoryIds['total'], $fuelTransitIds)); @endphp@if (count($fuelGrandIds)) {{ count($fuelGrandIds) }} @else 0 @endif | {{-- Fuel Allocated --}}@if (count($fuelInventoryIds['allocated'])) {{ count(array_unique($fuelInventoryIds['allocated'])) }} @else 0 @endif | {{-- Fuel Free --}}@if (count($fuelInventoryIds['free'])) {{ count(array_unique($fuelInventoryIds['free'])) }} @else 0 @endif | {{-- Fuel PDI --}}@if (count($fuelInventoryIds['pdi_hold'])) {{ count(array_unique($fuelInventoryIds['pdi_hold'])) }} @else 0 @endif |
| Total Stock | @foreach ($branches as $branch) @php $branchInventoryIds = []; foreach ($models as $model) { foreach ($data[$model->id] ?? [] as $fuelData) { $statuses = $fuelData[$branch->id] ?? []; foreach ($statuses['inventory_ids'] ?? [] as $status => $ids) { if (in_array($status, ['allocated', 'allocatedDealer', 'active', 'pdi_hold'])) { $branchInventoryIds = array_merge($branchInventoryIds, $ids); } } } } @endphp@if (count($branchInventoryIds)) {{ count(array_unique($branchInventoryIds)) }} @else 0 @endif | @endforeach {{-- Grand Total of Inventory, Transit, and Footer --}} @php // Unique Inventory IDs $inventoryUnique = array_unique($grandInventoryIds['total']); // Unique Transit IDs $transitUnique = array_unique($grandTransitIdsAll); // Footer Grand Total = unique IDs across inventory + transit $footerGrandIds = array_merge($inventoryUnique, $transitUnique); @endphp {{-- Inventory Total --}}@if(count($inventoryUnique)) {{ count($inventoryUnique) }} @else 0 @endif | {{-- Transit Total --}}@if(count($transitUnique)) {{ count($transitUnique) }} @else 0 @endif | {{-- Footer Grand Total --}}@if(count($footerGrandIds)) {{ count($footerGrandIds) }} @else 0 @endif | {{-- Allocated / Free / PDI --}}{{ count(array_unique($grandInventoryIds['allocated'])) }} | {{ count(array_unique($grandInventoryIds['free'])) }} | {{ count(array_unique($grandInventoryIds['pdi_hold'])) }} |
| Car Name | Variant | Status | VIN Number | Branch | Team Leader | KEC Name | Ex Showroom Price | Purchase Price | Kin Margin | Fuel Type | Customer Name | Aging Days | Inventory Type | FSC Code |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|