@extends('template.app')

@section('meta')
@endsection

@section('title')
    View Inventory
@endsection

@section('styles')

@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">Inventories</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('inventory') }}" class="text-muted">Inventories</a></li>
                        <li class="breadcrumb-item text-muted active" aria-current="page">View</li>
                    </ol>
                </nav>
            </div>
        </div>
    </div>
</div>
<div class="container-fluid">

    <div class="row">
        <div class="col-12">
            <div class="card">
                <div class="card-body">
                    <div class="row">
                        <div class="form-group col-sm-3">
                            <label for="branch_id">Branch</label>
                            <select class="form-control" name="branch_id" id="branch_id" disabled>
                                <option value="">Select Branch</option>
                                @if(isset($branches) && $branches->isNotEmpty())
                                    @foreach($branches as $row)
                                        <option value="{{ $row->id }}" @if(!empty($data) && $data->branch_id == $row->id) selected @endif> {{ $row->name }} </option>
                                    @endforeach
                                @endif
                            </select>
                            <span class="kt-form__help error branch_id"></span>
                        </div>
                        <div class="form-group col-sm-3">
                                <label for="name">Select Car</label>
                                <select class="form-control" name="name" id="name" onchange="car_mveriant(this);" disabled>
                                    <option value="">Select Car</option>
                                    @if(isset($carmodel))
                                        @foreach($carmodel as $car_model)
                                          <option value="{{ $car_model->car_id }}" @if(!empty($data) && $data->name == $car_model->car_id) selected @endif> {{ $car_model->car_name }} | {{$car_model->varient_name}} {{$car_model->exterior_color}} {{$car_model->interior_color}} </option>
                                        @endforeach
                                    @endif
                                </select>
                                <span class="kt-form__help error name"></span>
                            </div>
                        <div class="form-group col-sm-3">
                                <label for="car_name">Car Model</label>
                                <input type="text" class="form-control" name="car_name" id="car_name" value="" readonly>
                                       
                                <span class="kt-form__help error car_name"></span>
                            </div>
                            <div class="form-group col-sm-3">
                                <label for="veriant">Car Variant</label><br>
                                <input type="text" class="form-control" name="veriant" id="veriant" value="" readonly>
                                <span class="kt-form__help error veriant"></span>
                            </div>
                            <div class="form-group col-sm-3">
                                <label for="exterior_color">Exterior Color</label><br>
                                <input type="text" class="form-control" name="exterior_color" id="exterior_color" value="" readonly>
                                <span class="kt-form__help error exterior_color"></span>
                            </div>
                            <div class="form-group col-sm-3">
                                <label for="interior_color">Interior Color</label><br>
                                <input type="text" class="form-control" name="interior_color" id="interior_color" value="" readonly>
                                <span class="kt-form__help error interior_color"></span>
                            </div>
                            <div class="form-group col-md-3">
                                <label class="control-label">KIN Invoice Date</label>
                                <!-- <span class="required" style="color: red;">*</span> -->
                                <input type="date" name="kin_invoice_date" id="kin_invoice_date" class="form-control" value="{{$data->kin_invoice_date}}" readonly>
                                <span class="kt-form__help error kin_invoice_date"></span>
                            </div>
                            <div class="form-group col-sm-3">
    <label for="manufacturing_year">Manufacturing Year</label>
    <select class="form-control" name="manufacturing_year" id="manufacturing_year" disabled>
        <option value="">Select Manufacturing Year</option>
        <option value="2024" {{ $data->manufacturing_year == '2024' ? 'selected' : '' }}>2024</option>
        <option value="2025" {{ $data->manufacturing_year == '2025' ? 'selected' : '' }}>2025</option>
        <option value="2026" {{ $data->manufacturing_year == '2026' ? 'selected' : '' }}>2026</option>
        <option value="2027" {{ $data->manufacturing_year == '2027' ? 'selected' : '' }}>2027</option>
        <option value="2028" {{ $data->manufacturing_year == '2028' ? 'selected' : '' }}>2028</option>
    </select>
    <span class="kt-form__help manufacturing_year"></span>
</div>

                        <div class="form-group col-sm-3">
                            <label for="key_number">Key number</label>
                            <input type="text" name="key_number" id="key_number" class="form-control" placeholder="Enter key number" value="{{ $data->key_number ?? '' }}" readonly>
                            <span class="kt-form__help error key_number"></span>
                        </div>
                        <div class="form-group col-sm-3">
                            <label for="engine_number">Engine number</label>
                            <input type="text" name="engine_number" id="engine_number" class="form-control" placeholder="Enter engine number" value="{{ $data->engine_number ?? '' }}" readonly>
                            <span class="kt-form__help error engine_number"></span>
                        </div>
                       <!-- <div class="form-group col-sm-3">
                            <label for="chassis_number">Chassis number</label>
                            <input type="text" name="chassis_number" id="chassis_number" class="form-control" placeholder="Enter chassis number" value="{{ $data->chassis_number ?? '' }}" readonly>
                            <span class="kt-form__help error chassis_number"></span>
                        </div>-->
                        <div class="form-group col-sm-3">
                            <label for="vin_number">Vin number</label>
                            <input type="text" name="vin_number" id="vin_number" class="form-control" placeholder="Enter vin number" value="{{ $data->vin_number ?? '' }}" readonly>
                            <span class="kt-form__help error vin_number"></span>
                        </div>
                        <div class="form-group col-sm-3">
                            <label for="ex_showroom_price">EX Showroom price</label>
                            <input type="text" name="ex_showroom_price" id="ex_showroom_price" class="form-control" placeholder="Enter ex showroom price" value="{{ $data->ex_showroom_price ?? '' }}" readonly>
                            <span class="kt-form__help error ex_showroom_price"></span>
                        </div>
                        <div class="form-group col-sm-3">
                                <label for="purchase_price">Purchase Price [Without GST - B]</label>
                                <input type="text" name="purchase_price" id="purchase_price" class="form-control" placeholder="Enter Purchase Price" value="{{ $data->purchase_price ?? '' }}" readonly>
                                <span class="kt-form__help error vin_number"></span>
                        </div>

                        <div class="form-group col-sm-3">
                                <label for="kin_margin">KIN Margin [C = A-B]</label>
                                <input type="text" name="kin_margin" id="kin_margin" class="form-control" placeholder="Enter kin margin price" value="{{ $data->kin_margin ?? '' }}" readonly>
                                <span class="kt-form__help error kin_margin"></span>
                        </div>

                        <div class="form-group col-sm-3" id="fule_type">
                                <label for="fule_type">Fuel Type</label>  
                                <select class="form-control" name="fuel_type" id="fuel_type" readonly>
                                     <option value="{{ $data->id }}"> {{ $data->title }}</option>
                                 @if(isset($fuel_type)) 
                                     @foreach($fuel_type as $fuel)
                                       <option value="{{ $fuel->id }}"> {{ $fuel->title }}</option>
                                     @endforeach
                                 @endif
                                 </select>
                                <span class="kt-form__help error fule_type"></span>
                        </div>
                        
                    </div>
                    <div class="form-group">
                        <a href="{{ route('inventory') }}" class="btn waves-effect waves-light btn-rounded btn-outline-secondary">Back</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection

@section('scripts')

<script>
  
    function car_mveriant_edit(value){

    var id = value;
        $.ajax({
           url : "{{ url('obf/carvarient/') }}",
           data : {'id' : id},
           type : 'get',
           dataType : 'json',

           success : function(resp){
               
               var html = ihtml = ehtml = vhtml = '';
                  
               jQuery.each(resp.cardeails, function(key, val){ 
                   html = val.car_name;
                   vhtml = val.varient_name;
                   ehtml = val.exterior_color;
                   ihtml = val.interior_color;
               });
               jQuery("#exterior_color").val(ehtml);
               jQuery("#interior_color").val(ihtml);
               jQuery("#veriant").val(vhtml);
               jQuery("#car_name").val(html);
           }
       });           
    }
                            
    var data_veriant = "<?php echo $data->name ?>"; 
    console.log(data_veriant);
    if(data_veriant != ''){
        car_mveriant_edit(data_veriant);
    }
</script>
@endsection