@extends('template.app')



@section('meta') @endsection

@section('title') Inventory Report @endsection



@section('styles')

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css">

<link href="https://cdn.jsdelivr.net/npm/select2@4.0.13/dist/css/select2.min.css" rel="stylesheet">

<link rel="stylesheet" href="https://cdn.datatables.net/1.13.7/css/jquery.dataTables.min.css">

<style>

    /*table {

        font-family: Arial, sans-serif;

        border-collapse: collapse;

        width: 100%;

    }



    td, th {

        border: 1px solid #dddddd;

        text-align: left;

        padding: 8px;

    }*/



    /*tr:nth-child(even) {*/

    /*    background-color: #313762;*/

    /*}*/



    /*div.dataTables_wrapper div.dataTables_filter label {

        font-weight: normal;

        white-space: nowrap;

        margin-left: auto;

        margin-right: auto;

    }



    .table-responsive {

        overflow-x: auto;

        max-width: 100%;

    }



    .card-body {

        overflow-x: auto;

        max-width: 100%;

        margin-right: 40px;

        margin-left: 40px;

    }



    .card-header {

        margin-right: 40px;

        margin-left: 40px;

    }



    .card.mt-4, .card {

        margin: 20px 40px;

    }



    .dataTables_wrapper {

        width: 100%;

        max-width: 100%;

        overflow-x: auto;

    }*/

</style>

@endsection



@section('content')

<div class="page-breadcrumb">

    <div class="row">

        <div class="col-7 align-self-center">

            <h4 class="page-title text-truncate text-dark font-weight-medium mb-1">Inventory Report</h4>

            <div class="d-flex align-items-center">

                <nav aria-label="breadcrumb">

                    <ol class="breadcrumb m-0 p-0">

                        <li class="breadcrumb-item"><a href="{{ route('dashboard') }}" class="text-muted">Dashboard</a></li>
                        <li class="breadcrumb-item"><a href="{{ route('allReport') }}" class="text-muted">Mis Report</a></li>
                        <li class="breadcrumb-item text-muted active" aria-current="page">Inventory Report</li>

                    </ol>

                </nav>

            </div>

        </div>

        <div class="col-5 align-self-center">

            <div class="customize-input float-right">

                <button class="btn waves-effect waves-light btn-rounded btn-outline-primary pull-right" type="button" data-toggle="collapse" data-target="#collapseExample" aria-expanded="false" aria-controls="collapseExample">

                    Export

                </button>

            </div>

        </div>

        <div class="col-sm-8"></div>

        <div class="col-sm-4">

            <div class="col-md-12 align-self-center collapse" id="collapseExample">

                <div class="customize-input float-right">

                    <form action="{{ route('InventoryExport') }}" method="get">

                        @csrf

                        <div class="row">

                            <div class="form-group col-md-6">

                                <select name="slug" class="form-control" required>

                                    <option value="">Select Status</option>

                                    <option value="all">All</option>

                                </select>

                            </div>

                            <div class="form-group col-md-6">

                                <button class="btn btn-primary" type="submit">Submit</button>

                            </div>

                        </div>

                    </form>

                </div>

            </div>

        </div>

    </div>

</div>



<div class="container-fluid">

    @if(auth()->user()->can('physical-stock-report'))
        <div class="card shadow mb-4">
            <div class="card-header bg-success text-white">
                <h6 class="mb-0">Location Wise Physical Stock Report</h6>
            </div>
            <div class="card-body p-2">
                <div class="table-responsive">
                    
                    @php
                        // PHP setup before table if needed
                    @endphp
                    
                    <table class="table table-bordered w-100 mis-report-table">
                        <thead class="table-header">
                            <tr>
                                <th>Model</th>
                                @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
                                    <th>{{ $b_name }}</th>
                                @endforeach
                                <th class="custom-total-color">Total</th>
                                <th>Transit</th>        {{-- moved Transit right after Total --}}
                                <th>Grand Total</th>    {{-- NEW Grand Total column --}}
                                <th>Allocated</th>
                                <th>Free Stock</th>
                                <th>PDI Hold</th>
                            </tr>
                        </thead>
                        <tbody>
                            @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
                                <tr class="model-header black-bg text-white">
                                    <td>{{ $model->name }}</td>
                                    @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
                                        <td>
                                            @if (count($branchInventoryIds))
                                                <a class="black_anchor_tag" href="javascript:void(0);" onclick='showCarDetails(@json(array_unique($branchInventoryIds)))'>
                                                    {{ count(array_unique($branchInventoryIds)) }}
                                                </a>
                                            @else
                                                0
                                            @endif
                                        </td>
                                    @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 --}}
                                    <td class="custom-total-data-color">
                                        @if ($modelTotal)
                                            <a class="black_anchor_tag" href="javascript:void(0);" onclick='showCarDetails(@json(array_unique($modelInventoryIds["total"])))'>
                                                {{ $modelTotal }}
                                            </a>
                                        @else
                                            0
                                        @endif
                                    </td>
    
                                    {{-- 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
                                    <td>
                                        @if (count($transitIds))
                                            <a class="black_anchor_tag" href="javascript:void(0);" onclick='showCarDetails([], @json($transitIds))'>
                                                {{ count($transitIds) }}
                                            </a>
                                        @else
                                            0
                                        @endif
                                    </td>
    
                                    {{-- Grand Total = unique(inventory_total_ids + transit_ids) --}}
                                    @php
                                        $grandTotalIdsModel = array_unique(array_merge(
                                            $modelInventoryIds['total'],
                                            $transitIds
                                        ));
                                    @endphp
                                    <td class="custom-total-data-color">
                                        @if (count($grandTotalIdsModel))
                                            <a class="black_anchor_tag" href="javascript:void(0);" onclick='showCarDetails(@json(array_values(array_unique($modelInventoryIds["total"]))), @json(array_values($transitIds)))'>
                                                {{ count($grandTotalIdsModel) }}
                                            </a>
                                        @else
                                            0
                                        @endif
                                    </td>
    
                                    {{-- Allocated --}}
                                    <td>
                                        @if (count($modelInventoryIds['allocated']))
                                            <a class="black_anchor_tag" href="javascript:void(0);" onclick='showCarDetails(@json(array_unique($modelInventoryIds["allocated"])))'>
                                                {{ count(array_unique($modelInventoryIds['allocated'])) }}
                                            </a>
                                        @else
                                            0
                                        @endif
                                    </td>
    
                                    {{-- Free Stock --}}
                                    <td>
                                        @if (count($modelInventoryIds['free']))
                                            <a class="black_anchor_tag" href="javascript:void(0);" onclick='showCarDetails(@json(array_unique($modelInventoryIds["free"])))'>
                                                {{ count(array_unique($modelInventoryIds['free'])) }}
                                            </a>
                                        @else
                                            0
                                        @endif
                                    </td>
    
                                    {{-- PDI Hold --}}
                                    <td>
                                        @if (count($modelInventoryIds['pdi_hold']))
                                            <a class="black_anchor_tag" href="javascript:void(0);" onclick='showCarDetails(@json(array_unique($modelInventoryIds["pdi_hold"])))'>
                                                {{ count(array_unique($modelInventoryIds['pdi_hold'])) }}
                                            </a>
                                        @else
                                            0
                                        @endif
                                    </td>
                                </tr>
                    
                                {{-- Fuel Type Rows --}}
                                @foreach ($data[$model->id] ?? [] as $fuelTypeId => $branchData)
                                    @php
                                        $fuelInventoryIds = ['total' => [], 'allocated' => [], 'free' => [], 'pdi_hold' => []];
                                    @endphp
                                    <tr>
                                        <td>{{ $fuelTypes[$fuelTypeId] ?? 'Unknown' }}</td>
                                        @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
                                            <td>
                                                @if (count($cellIds))
                                                    <a class="white_anchor_tag" href="javascript:void(0);" onclick='showCarDetails(@json(array_unique($cellIds)))'>
                                                        {{ count(array_unique($cellIds)) }}
                                                    </a>
                                                @else
                                                    0
                                                @endif
                                            </td>
                                        @endforeach
    
                                        {{-- Fuel Total --}}
                                        <td class="custom-total-fuel-color">
                                            @if (count($fuelInventoryIds['total']))
                                                <a class="white_anchor_tag" href="javascript:void(0);" onclick='showCarDetails(@json(array_unique($fuelInventoryIds["total"])))'>
                                                    {{ count(array_unique($fuelInventoryIds['total'])) }}
                                                </a>
                                            @else
                                                0
                                            @endif
                                        </td>
    
                                        {{-- 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
                                        <td>
                                            @if (count($fuelTransitIds))
                                                <a class="white_anchor_tag" href="javascript:void(0);" onclick='showCarDetails([], @json($fuelTransitIds))'>
                                                    {{ count(array_unique($fuelTransitIds)) }}
                                                </a>
                                            @else
                                                0
                                            @endif
                                        </td>
    
                                        {{-- Fuel Grand Total --}}
                                        @php
                                            $fuelGrandIds = array_unique(array_merge($fuelInventoryIds['total'], $fuelTransitIds));
                                        @endphp
                                        <td>
                                            @if (count($fuelGrandIds))
                                                <a class="white_anchor_tag" href="javascript:void(0);" onclick='showCarDetails(@json(array_values(array_unique($fuelInventoryIds["total"]))), @json(array_values($fuelTransitIds)))'>
                                                    {{ count($fuelGrandIds) }}
                                                </a>
                                            @else
                                                0
                                            @endif
                                        </td>
    
                                        {{-- Fuel Allocated --}}
                                        <td>
                                            @if (count($fuelInventoryIds['allocated']))
                                                <a class="white_anchor_tag" href="javascript:void(0);" onclick='showCarDetails(@json(array_unique($fuelInventoryIds["allocated"])))'>
                                                    {{ count(array_unique($fuelInventoryIds['allocated'])) }}
                                                </a>
                                            @else
                                                0
                                            @endif
                                        </td>
    
                                        {{-- Fuel Free --}}
                                        <td>
                                            @if (count($fuelInventoryIds['free']))
                                                <a class="white_anchor_tag" href="javascript:void(0);" onclick='showCarDetails(@json(array_unique($fuelInventoryIds["free"])))'>
                                                    {{ count(array_unique($fuelInventoryIds['free'])) }}
                                                </a>
                                            @else
                                                0
                                            @endif
                                        </td>
    
                                        {{-- Fuel PDI --}}
                                        <td>
                                            @if (count($fuelInventoryIds['pdi_hold']))
                                                <a class="white_anchor_tag" href="javascript:void(0);" onclick='showCarDetails(@json(array_unique($fuelInventoryIds["pdi_hold"])))'>
                                                    {{ count(array_unique($fuelInventoryIds['pdi_hold'])) }}
                                                </a>
                                            @else
                                                0
                                            @endif
                                        </td>
                                    </tr>
                                @endforeach
                            @endforeach
                    
                            {{-- Footer Total --}}
                            <tr class="table-footer">
                                <th>Total Stock</th>
                                @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
                                    <th>
                                        @if (count($branchInventoryIds))
                                            <a class="black_anchor_tag" href="javascript:void(0);" onclick='showCarDetails(@json(array_unique($branchInventoryIds)))'>
                                                {{ count(array_unique($branchInventoryIds)) }}
                                            </a>
                                        @else
                                            0
                                        @endif
                                    </th>
                                @endforeach
    
                                <!--{{-- Grand Total of inventory across models (Total column) --}}
                                <th class="custom-total-color">
                                    <a class="black_anchor_tag" href="javascript:void(0);" onclick='showCarDetails(@json(array_unique($grandInventoryIds["total"])))'>
                                        {{ count(array_unique($grandInventoryIds['total'])) }}
                                    </a>
                                </th>
    
                                {{-- Transit Total Footer --}}
                                @php
                                    $uniqueGrandTransitIds = array_unique($grandTransitIdsAll);
                                @endphp
                                <th>
                                    @if (count($uniqueGrandTransitIds))
                                        <a class="black_anchor_tag" href="javascript:void(0);" onclick='showCarDetails([], @json($uniqueGrandTransitIds))'>
                                            {{ count(array_unique($uniqueGrandTransitIds)) }}
                                        </a>
                                    @else
                                        0
                                    @endif
                                </th>
    
                                {{-- Footer Grand Total = unique(inventory total ids + transit total ids) --}} 
                                @php 
                                    $footerGrandIds = array_unique(array_merge( $grandInventoryIds['total'], $uniqueGrandTransitIds ));
                                @endphp 
                                <th class="custom-total-color"> 
                                    @if (count($footerGrandIds)) 
                                        <a class="black_anchor_tag" href="javascript:void(0);" onclick='showCarDetails(@json(array_values(array_unique($grandInventoryIds["total"]))), @json(array_values($uniqueGrandTransitIds)))'> 
                                            {{ count($footerGrandIds) }} 
                                        </a> 
                                    @else 
                                        0 
                                    @endif 
                                </th>-->
                                {{-- 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 --}}
                                <th class="custom-total-color">
                                    @if(count($inventoryUnique))
                                        <a class="black_anchor_tag" href="javascript:void(0);" onclick='showCarDetails(@json(array_values($inventoryUnique)))'>
                                            {{ count($inventoryUnique) }}
                                        </a>
                                    @else
                                        0
                                    @endif
                                </th>
                                
                                {{-- Transit Total --}}
                                <th>
                                    @if(count($transitUnique))
                                        <a class="black_anchor_tag" href="javascript:void(0);" onclick='showCarDetails([], @json(array_values($transitUnique)))'>
                                            {{ count($transitUnique) }}
                                        </a>
                                    @else
                                        0
                                    @endif
                                </th>
                                
                                {{-- Footer Grand Total --}}
                                <th class="custom-total-color">
                                    @if(count($footerGrandIds))
                                        <a class="black_anchor_tag" href="javascript:void(0);" onclick='showCarDetails(@json(array_values($inventoryUnique)), @json(array_values($transitUnique)))'>
                                            {{ count($footerGrandIds) }}
                                        </a>
                                    @else
                                        0
                                    @endif
                                </th>
    
                                {{-- Allocated / Free / PDI --}}
                                <th>
                                    <a class="black_anchor_tag" href="javascript:void(0);" onclick='showCarDetails(@json(array_unique($grandInventoryIds["allocated"])))'>
                                        {{ count(array_unique($grandInventoryIds['allocated'])) }}
                                    </a>
                                </th>
                                <th>
                                    <a class="black_anchor_tag" href="javascript:void(0);" onclick='showCarDetails(@json(array_unique($grandInventoryIds["free"])))'>
                                        {{ count(array_unique($grandInventoryIds['free'])) }}
                                    </a>
                                </th>
                                <th>
                                    <a class="black_anchor_tag" href="javascript:void(0);" onclick='showCarDetails(@json(array_unique($grandInventoryIds["pdi_hold"])))'>
                                        {{ count(array_unique($grandInventoryIds['pdi_hold'])) }}
                                    </a>
                                </th>
                            </tr>
                        </tbody>
                    </table>
    
                </div>
            </div>
        </div>
        @endif
        
  <div class="row">

        <div class="col-12">

            <div class="card">

                <div class="col-md-4 mt-2">

                <input type="text" class="form-control" id="vin-input" placeholder="Enter VIN Number">

                </div>

                <div class="col-md-4 mt-2">

                <button type="button" id="submit-btn" class="btn btn-primary">Submit</button>

                </div>

            </div>

        </div>

        <div class="col-12">

            <div class="card mt-4">

                <div class="card-body table-responsive" id="datatable" style="text-align: center;">

                    <table class="table table-bordered data-table tables" id="data-table" cellspacing="0" width="100%">

                        <thead>

                            <tr>

                                <th>Car Name</th>

                                <th>Variant</th>

                                <th>Status</th>

                                <th>VIN Number</th>

                                <th>Branch</th>

                                <th>Team Leader</th>

                                <th>KEC Name</th>

                                <th>Ex Showroom Price</th>

                                <th>Purchase Price</th>

                                <th>Kin Margin</th>

                                <th>Fuel Type</th>

                                <th>Customer Name</th>

                                <th>Aging Days</th>

                                <th>Inventory Type</th>

                                <th>FSC Code</th>

                            </tr>

                            <tr class="filterrow">

                                <th>

                                    <div class="search-box-container datatable-form-filter width_150">

                                        <div class="form-group is-empty">

                                            <input type="text" name="car_name" value="{{ request()->get('car_name', '') }}" class="form-control text-capitalize" id="car_name" autocomplete="off" tabindex="1">

                                        </div>

                                    </div>

                                </th>

                                <th>

                                    <div class="search-box-container datatable-form-filter width_150">

                                        <div class="form-group is-empty">

                                            <input type="text" name="varient_name" value="{{ request()->get('varient_name', '') }}" class="form-control text-capitalize" id="varient_name" autocomplete="off" tabindex="1">

                                        </div>

                                    </div>

                                </th>



                                <th>

                                    <div class="search-box-container datatable-form-filter width_250">

                                        <div class="form-group is-empty">

                                            <input type="text" name="status" value="{{ request()->get('status', '') }}" class="form-control text-capitalize custom_color" id="status" autocomplete="off" autofocus tabindex="2">

                                        </div>

                                    </div>

                                </th>

                                <th>

                                    <div class="search-box-container datatable-form-filter width_300">

                                        <div class="form-group is-empty">

                                            <input type="text" name="vin_number" value="{{ request()->get('vin_number', '') }}" class="form-control text-capitalize custom_color" id="vin_number" autocomplete="off" autofocus tabindex="3">

                                        </div>

                                    </div>

                                </th>

                                <th>

                                    <div class="search-box-container datatable-form-filter width_150">

                                        <div class="form-group is-empty">

                                            <input type="text" name="branch" value="{{ request()->get('branch', '') }}" class="form-control text-capitalize custom_color" id="branch" autocomplete="off" autofocus tabindex="4">

                                        </div>

                                    </div>

                                </th>

                                <th>

                                    <div class="search-box-container datatable-form-filter width_150">

                                        <div class="form-group is-empty">

                                            <input type="text" name="team_name" value="{{ request()->get('team_name', '') }}" class="form-control text-capitalize custom_color" id="team_name" autocomplete="off" autofocus tabindex="4">

                                        </div>

                                    </div>

                                </th>

                                <th>

                                    <div class="search-box-container datatable-form-filter width_150">

                                        <div class="form-group is-empty">

                                            <input type="text" name="sales_person_name" value="{{ request()->get('sales_person_name', '') }}" class="form-control text-capitalize custom_color" id="sales_person_name" autocomplete="off" autofocus tabindex="4">

                                        </div>

                                    </div>

                                </th>

                                <th>

                                    <div class="search-box-container datatable-form-filter width_150">

                                        <div class="form-group is-empty">

                                            <input type="text" name="ex_showroom_price" value="{{ request()->get('ex_showroom_price', '') }}" class="form-control text-capitalize custom_color" id="ex_showroom_price" autocomplete="off" autofocus tabindex="4">

                                        </div>

                                    </div>

                                </th>

                                <th>

                                    <div class="search-box-container datatable-form-filter width_150">

                                        <div class="form-group is-empty">

                                            <input type="text" name="purchase_price" value="{{ request()->get('purchase_price', '') }}" class="form-control text-capitalize custom_color" id="purchase_price" autocomplete="off" autofocus tabindex="4">

                                        </div>

                                    </div>

                                </th>

                                <th>

                                    <div class="search-box-container datatable-form-filter width_150">

                                        <div class="form-group is-empty">

                                            <input type="text" name="kin_margin" value="{{ request()->get('kin_margin', '') }}" class="form-control text-capitalize custom_color" id="kin_margin" autocomplete="off" autofocus tabindex="4">

                                        </div>

                                    </div>

                                </th>

                                <th>

                                    <div class="search-box-container datatable-form-filter width_150">

                                        <div class="form-group is-empty">

                                            <input type="text" name="fuel_type" value="{{ request()->get('fuel_type', '') }}" class="form-control text-capitalize custom_color" id="fuel_type" autocomplete="off" autofocus tabindex="4">

                                        </div>

                                    </div>

                                </th>

                                <th>

                                    <div class="search-box-container datatable-form-filter width_150">

                                        <div class="form-group is-empty">

                                            <input type="text" name="customer_name" value="{{ request()->get('customer_name', '') }}" class="form-control text-capitalize custom_color" id="customer_name" autocomplete="off" autofocus tabindex="4">

                                        </div>

                                    </div>

                                </th>

                                <th>

                                    <div class="search-box-container datatable-form-filter width_150">

                                        <div class="form-group is-empty">

                                            <input type="text" name="aging_days" value="{{ request()->get('aging_days', '') }}" class="form-control text-capitalize custom_color" id="aging_days" autocomplete="off" autofocus tabindex="4">

                                        </div>

                                    </div>

                                </th>

                                <th>

                                    <div class="search-box-container datatable-form-filter width_150">

                                        <div class="form-group is-empty">

                                            <input type="text" name="inventory_type" value="{{ request()->get('inventory_type', '') }}" class="form-control text-capitalize custom_color" id="inventory_type" autocomplete="off" autofocus tabindex="4">

                                        </div>

                                    </div>

                                </th>

                                <th>

                                    <div class="search-box-container datatable-form-filter width_150">

                                        <div class="form-group is-empty">

                                            <input type="text" name="fsc_code" value="{{ request()->get('fsc_code', '') }}" class="form-control text-capitalize custom_color" id="fsc_code" autocomplete="off" autofocus tabindex="4">

                                        </div>

                                    </div>

                                </th>

                            </tr>

                        </thead>

                    </table>

                </div>

            </div>

        </div>

@endsection



@section('scripts')

<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>

<script src="https://cdn.datatables.net/1.13.6/js/jquery.dataTables.min.js"></script>

<script src="https://cdn.datatables.net/1.13.6/js/dataTables.bootstrap5.min.js"></script>

<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>

<script src="https://cdn.jsdelivr.net/npm/flatpickr"></script>

<script src="https://cdn.datatables.net/1.13.7/js/jquery.dataTables.min.js"></script>

<script src="https://cdn.jsdelivr.net/npm/select2@4.0.13/dist/js/select2.min.js"></script>

<script src="https://cdn.jsdelivr.net/momentjs/latest/moment.min.js"></script>



<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.css" />

<script src="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.min.js"></script>



<script type="text/javascript">

    $.ajaxSetup({

        headers: {

            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')

        }

    });

</script>

<script type="text/javascript">

    



    $(document).ready(function() {

        

        let rowCount = $("table tbody tr").length;

        if (rowCount < 3) {

            $(".table").css("height", "600px");

        }



        $('.js-example-basic-single').select2();



        var tableColumns = [

            { data: 'car_name' },

            { data: 'varient_name' },

            { data: 'status' },

            { data: 'vin_number'},

            { data: 'branch'},

            { data: 'team_name' },

            { data: 'sales_person_name' },

            { data: 'ex_showroom_price'},

            { data: 'purchase_price'},

            { data: 'kin_margin'},

            { data: 'fuel_type'},

            { data: 'customer_name'},

            { data: 'aging_days'},

            { data: 'inventory_type'},

            { data: 'fsc_code'}

        ];



        (function(window, $) {

            window.LaravelDataTables = window.LaravelDataTables || {};

            window.LaravelDataTables["dataTableBuilder"] = $("#data-table").DataTable({

                processing: true,

                serverSide: true,

                language: {

                    "info": "_START_ - _END_ of _TOTAL_",

                    "lengthMenu": "_MENU_ ",

                    "infoFiltered": ""

                },

                // scrollY: '400px',

                scrollCollapse: true,

                paging: true,

                searching: false,



                bSortCellsTop : true,

                ajax: {

                    url: '{!! route("inventory.getInventory") !!}',

                    method: "POST",

                    data: function (d) {

                        d.car_name = jQuery(".datatable-form-filter input[name='car_name']").val();

                        d.varient_name = jQuery(".datatable-form-filter input[name='varient_name']").val();

                        d.status = jQuery(".datatable-form-filter input[name='status']").val();

                        d.vin_number = jQuery(".datatable-form-filter input[name='vin_number']").val();

                        d.branch = jQuery(".datatable-form-filter input[name='branch']").val();

                        d.team_name = jQuery(".datatable-form-filter input[name='team_name']").val();

                        d.sales_person_name = jQuery(".datatable-form-filter input[name='sales_person_name']").val();

                        d.ex_showroom_price = jQuery(".datatable-form-filter input[name='ex_showroom_price']").val();

                        d.purchase_price = jQuery(".datatable-form-filter input[name='purchase_price']").val();

                        d.kin_margin = jQuery(".datatable-form-filter input[name='kin_margin']").val();

                        d.fuel_type = jQuery(".datatable-form-filter input[name='fuel_type']").val();

                        d.customer_name = jQuery(".datatable-form-filter input[name='customer_name']").val();

                        d.aging_days = jQuery(".datatable-form-filter input[name='aging_days']").val();

                        d.inventory_type = jQuery(".datatable-form-filter input[name='inventory_type']").val();

                        d.fsc_code = jQuery(".datatable-form-filter input[name='fsc_code']").val();

                        

                        

                        d.vin = $('#vin-input').val();

                    },

                    error : function(d) {}

                },

                columns: tableColumns,

                lengthMenu: [

                    [25, 50,100, -1 ],['25', '50','100', 'Show all' ]

                ],

                order: [ [0,'DESC'] ],

                responsive: true,

                colReorder:{

                    enable: false,

                },

                dom: '<"top"f>rt<"bottom"ipl><"clear">',

                fnInitComplete: function(settings, json) {

                    jQuery('table.table input:checkbox').map(function() {

                        if(jQuery(this).prop("checked") != true){

                            var column = table.column( jQuery(this).attr('data-column') );

                            column.visible(false);

                        }

                    });

                },

                pageLength: 25,

            });

        })(window, jQuery);



        $("#min").flatpickr({ onSelect: function () { window.LaravelDataTables["dataTableBuilder"].draw(); }, changeMonth: true, changeYear: true });



        $(document).on("change", "#min", function () {

            window.LaravelDataTables["dataTableBuilder"].draw();

        });

        

        $('#submit-btn').on('click', function () {

            window.LaravelDataTables["dataTableBuilder"].draw();

        });





    jQuery('.datatable-form-filter input').on('keyup', function (e) {

        if(jQuery(this).val().length >= 3 || e.keyCode == 13 || !jQuery(this).val()) {

            window.LaravelDataTables["dataTableBuilder"].draw();

            e.preventDefault();

        }

    });



    jQuery('.datatable-form-filter select').on('change', function (e) {

        window.LaravelDataTables["dataTableBuilder"].draw();

        e.preventDefault();

    });



    jQuery('input:checkbox[name="name_sort_asc"],input:checkbox[name="name_sort_desc"]').on('click', function (e) {

        window.LaravelDataTables["dataTableBuilder"].draw();

        e.preventDefault();

    });

}); 

</script>

@endsection