@extends('template.app') @section('meta') @endsection @section('title') Inventory Report @endsection @section('styles') @endsection @section('content')
@if(auth()->user()->can('physical-stock-report'))
Location Wise Physical Stock Report
@php // PHP setup before table if needed @endphp @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 @endforeach {{-- moved Transit right after Total --}} {{-- NEW Grand Total column --}} @php $grandInventoryIds = [ 'total' => [], 'allocated' => [], 'free' => [], 'pdi_hold' => [] ]; $grandTransitIdsAll = []; // collect transit ids for footer @endphp {{-- Model Rows --}} @foreach ($models as $model) @php $modelInventoryIds = ['total' => [], 'allocated' => [], 'free' => [], 'pdi_hold' => []]; $modelAllocated = $modelFree = $modelPdi = 0; @endphp @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 @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 --}} {{-- 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 {{-- Grand Total = unique(inventory_total_ids + transit_ids) --}} @php $grandTotalIdsModel = array_unique(array_merge( $modelInventoryIds['total'], $transitIds )); @endphp {{-- Allocated --}} {{-- Free Stock --}} {{-- PDI Hold --}} {{-- Fuel Type Rows --}} @foreach ($data[$model->id] ?? [] as $fuelTypeId => $branchData) @php $fuelInventoryIds = ['total' => [], 'allocated' => [], 'free' => [], 'pdi_hold' => []]; @endphp @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 @endforeach {{-- Fuel Total --}} {{-- 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 {{-- Fuel Grand Total --}} @php $fuelGrandIds = array_unique(array_merge($fuelInventoryIds['total'], $fuelTransitIds)); @endphp {{-- Fuel Allocated --}} {{-- Fuel Free --}} {{-- Fuel PDI --}} @endforeach @endforeach {{-- Footer Total --}} @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 @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 --}} {{-- Transit Total --}} {{-- Footer Grand Total --}} {{-- Allocated / Free / PDI --}}
Model{{ $b_name }}Total TransitGrand TotalAllocated Free Stock PDI Hold
{{ $model->name }} @if (count($branchInventoryIds)) {{ count(array_unique($branchInventoryIds)) }} @else 0 @endif @if ($modelTotal) {{ $modelTotal }} @else 0 @endif @if (count($transitIds)) {{ count($transitIds) }} @else 0 @endif @if (count($grandTotalIdsModel)) {{ count($grandTotalIdsModel) }} @else 0 @endif @if (count($modelInventoryIds['allocated'])) {{ count(array_unique($modelInventoryIds['allocated'])) }} @else 0 @endif @if (count($modelInventoryIds['free'])) {{ count(array_unique($modelInventoryIds['free'])) }} @else 0 @endif @if (count($modelInventoryIds['pdi_hold'])) {{ count(array_unique($modelInventoryIds['pdi_hold'])) }} @else 0 @endif
{{ $fuelTypes[$fuelTypeId] ?? 'Unknown' }} @if (count($cellIds)) {{ count(array_unique($cellIds)) }} @else 0 @endif @if (count($fuelInventoryIds['total'])) {{ count(array_unique($fuelInventoryIds['total'])) }} @else 0 @endif @if (count($fuelTransitIds)) {{ count(array_unique($fuelTransitIds)) }} @else 0 @endif @if (count($fuelGrandIds)) {{ count($fuelGrandIds) }} @else 0 @endif @if (count($fuelInventoryIds['allocated'])) {{ count(array_unique($fuelInventoryIds['allocated'])) }} @else 0 @endif @if (count($fuelInventoryIds['free'])) {{ count(array_unique($fuelInventoryIds['free'])) }} @else 0 @endif @if (count($fuelInventoryIds['pdi_hold'])) {{ count(array_unique($fuelInventoryIds['pdi_hold'])) }} @else 0 @endif
@endif
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
@endsection @section('scripts') @endsection