@extends('template.app')

@section('meta')
@endsection

@section('title')
    Transfer Create
@endsection

@section('styles')
<link href="{{ asset('assets/css/dropify.min.css') }}" rel="stylesheet">
<link href="{{ asset('assets/css/sweetalert2.bundle.css') }}" rel="stylesheet">
@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">Transfers</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('transfer') }}" class="text-muted">Transfers</a></li>
                        <li class="breadcrumb-item text-muted active" aria-current="page">Create</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">
                    <form action="{{ route('transfer.update',$transferEdit->id) }}" name="form" id="form" method="post" enctype="multipart/form-data">
                        @csrf
                        @method('POST')

                        <div class="row">
                            @if(auth()->user()->roles->pluck('name')[0] == 'admin')
                                <div class="form-group col-sm-3">
                                    <label for="from_branch">From Branch :-</label>
                                    <select class="form-control" name="from_branch" id="from_branch">
                                        <option value="">Select From Branch</option>
                                        @if(isset($branch) && $branch->isNotEmpty())
                                            @foreach($branch as $row)
                                                <option value="{{ $row->id }}" @if($row->id == $transferEdit->from_branch) selected @endif> {{ $row->name }} </option>
                                            @endforeach
                                        @endif
                                    </select>
                                    <span class="kt-form__help error from_branch"></span>
                                </div>
                            @endif
                            <div class="form-group col-sm-3">
                                <label for="to_branch">To Branch :-</label>
                                <select class="form-control" name="to_branch" id="to_branch">
                                    <option value="">Select To Branch</option>
                                    @if(isset($branch) && $branch->isNotEmpty())
                                        @foreach($branch as $row)
                                            <option value="{{ $row->id }}"@if($row->id == $transferEdit->to_branch) selected @endif> {{ $row->name }} </option>
                                        @endforeach
                                    @endif
                                </select>
                                <span class="kt-form__help error to_branch"></span>
                            </div>
                            <!--<div class="form-group col-sm-3">-->
                            <!--    <label for="product_id">Product</label>-->
                            <!--    <select class="form-control" name="product_id" id="product_id">-->
                            <!--        <option value="">Select Product</option>-->
                            <!--        @if(isset($products) && $products->Empty())-->
                            <!--            @foreach($products as $row)-->
                            <!--                <option value="{{ $row->id }}"> {{ $row->name }} - {{ $row->variant->name }} </option>-->
                            <!--            @endforeach-->
                            <!--        @endif-->
                            <!--    </select>-->
                            <!--    <span class="kt-form__help error product_id"></span>-->
                            <!--</div>-->
                             <div class="form-group col-sm-3">
                                <label for="to_branch">Car Model :-</label>
                                <select class="form-control" name="car_model" id="car_model">
                                    <option value="">Select Car Model</option>
                                    @if(isset($carmodel) && $carmodel->isNotEmpty())
                                        @foreach($carmodel as $row)
                                            <option value="{{ $row->id }}" @if($row->id == $transfercarModel->car_model) selected @endif> {{ $row->name }} </option>
                                        @endforeach
                                    @endif
                                </select>
                                <span class="kt-form__help error to_branch"></span>
                            </div>
                             <div class="form-group col-sm-3">
                                <label for="to_branch">Car Varient :-</label>
                                <select class="form-control" name="car_varient" id="car_varient">
                                    <option value="">Select Car Varient</option>
                                    @if(isset($carvarient) && $carvarient->isNotEmpty())
                                        @foreach($carvarient as $row)
                                            <option value="{{ $row->id }}" @if($row->id == $transfercarModel->veriant) selected @endif> {{ $row->name }} </option>
                                        @endforeach
                                    @endif
                                </select>
                                <span class="kt-form__help error to_branch"></span>
                            </div>
                            <div class="form-group col-sm-3">
                                <label for="to_branch">VIN Number :-</label>
                                <select class="form-control" name="vin_number" id="vin_number">
                                    <option value="">Select VIN Number</option>
                                    @if(isset($query) && $query->isNotEmpty())
                                        @foreach($query as $row)
                                            <option value="{{ $row->id }}"@if($row->id == $transferVinNumber->id) selected @endif> {{ $row->vin_number }} </option>
                                        @endforeach
                                    @endif
                                </select>
                                <span class="kt-form__help error to_branch"></span>
                            </div>
                            <div class="form-group col-sm-3">
                                <label for="to_branch">Driver Name :-</label>
                                <input type="text" class="form-control" placeholder="Enter Driver Name" value="{{ $transferEdit->driver_name }}" name="driver_name" id="driver_name">
                                <span class="kt-form__help error to_branch"></span>
                            </div>
                            <div class="form-group col-sm-3">
                                <label for="to_branch">Driver Licence Number :-</label>
                                <input type="text" class="form-control" placeholder="Enter Driver Licence Number" value="{{ $transferEdit->driver_lic }}" name="driver_lic" id="driver_lic_number">
                                <span class="kt-form__help error to_branch"></span>
                            </div>
                            <div class="form-group col-sm-3">
                                <label for="to_branch">Driver Pan Number :-</label>
                                <input type="text" class="form-control" placeholder="Enter Driver Pan Number" name="driver_pan" value="{{ $transferEdit->driver_pan }}" id="driver_pan_number">
                                <span class="kt-form__help error to_branch"></span>
                            </div>
                            <div class="form-group col-sm-3">
                                <label for="to_branch">Car Image 1 :-</label>
                                <input type="file" class="form-control" name="car_image_1">
                                <span class="kt-form__help error to_branch"></span>
                                <div class="remove-image" style='display:inline-block;width:100px;margin-right: 10px;'><div style='position:absolute;color:#000;width:100px;text-align:center;'></div><img src="{{ asset('storage/'.$transferEdit->car_image_1) }}" width='100' height='100' style='display:inline-block; margin-top: 15px;' class='m-b-15'></div>
                            </div>
                            <div class="form-group col-sm-3">
                                <label for="to_branch">Car Image 2 :-</label>
                                <input type="file" class="form-control" name="car_image_2">
                                <span class="kt-form__help error to_branch"></span>
                                <div class="remove-image" style='display:inline-block;width:100px;margin-right: 10px;'><div style='position:absolute;color:#000;width:100px;text-align:center;'></div><img src="{{ asset('storage/'.$transferEdit->car_image_2) }}" width='100' height='100' style='display:inline-block; margin-top: 15px;' class='m-b-15'></div>
                            </div>
                            <div class="form-group col-sm-3">
                                <label for="to_branch">Car Image 3 :-</label>
                                <input type="file" class="form-control" name="car_image_3">
                                <span class="kt-form__help error to_branch"></span>
                                <div class="remove-image" style='display:inline-block;width:100px;margin-right: 10px;'><div style='position:absolute;color:#000;width:100px;text-align:center;'></div><img src="{{ asset('storage/'.$transferEdit->car_image_3) }}" width='100' height='100' style='display:inline-block; margin-top: 15px;' class='m-b-15'></div>
                            </div>
                            <div class="form-group col-sm-3">
                                <label for="to_branch">Car Image 4 :-</label>
                                <input type="file" class="form-control" name="car_image_4">
                                <span class="kt-form__help error to_branch"></span>
                                <div class="remove-image" style='display:inline-block;width:100px;margin-right: 10px;'><div style='position:absolute;color:#000;width:100px;text-align:center;'></div><img src="{{ asset('storage/'.$transferEdit->car_image_4) }}" width='100' height='100' style='display:inline-block; margin-top: 15px;' class='m-b-15'></div>
                            </div>
                            <div class="form-group col-sm-3">
                                <label for="to_branch">Car Image 5 :-</label>
                                <input type="file" class="form-control" name="car_image_5">
                                <span class="kt-form__help error to_branch"></span>
                                <div class="remove-image" style='display:inline-block;width:100px;margin-right: 10px;'><div style='position:absolute;color:#000;width:100px;text-align:center;'></div><img src="{{ asset('storage/'.$transferEdit->car_image_5) }}" width='100' height='100' style='display:inline-block; margin-top: 15px;' class='m-b-15'></div>
                            </div>
                            <div class="form-group col-sm-3">
                                <label for="to_branch">Transfer Remark :-</label>
                                <textarea class="form-control" placeholder="Enter Transfer Remark" name="remark">{{ $transferEdit->remarks }}</textarea>
                                <span class="kt-form__help error to_branch"></span>
                            </div>
                            <div class="form-group col-sm-3">
                                <label for="status">Tool Kit</label>
                                <div class="form-check">
                                    <input class="form-check-input" type="radio" name="tool_kit" id="tool_kit" value="1" {{ $transferEdit->toolkit == 1 ? 'checked' : '' }}>
                                    <label class="form-check-label" for="tool_kit">Yes</label>
                                </div>
                                <div class="form-check">
                                    <input class="form-check-input" type="radio" name="tool_kit" id="tool_kit1" value="0" {{ $transferEdit->toolkit == 0 ? 'checked' : '' }}>
                                    <label class="form-check-label" for="tool_kit1">No</label>
                                </div>
                            </div>                                                        
                            <div class="form-group col-sm-3">
                                <label for="status">Health Kit</label>  
                                <div class="form-check">
                                  <input class="form-check-input" type="radio" name="health_kit" id="health_kit" value='1' {{ $transferEdit->medikit == 1 ? 'checked' : '' }}>
                                  <label class="form-check-label" for="health_kit">
                                    Yes
                                  </label>
                                </div>
                                <div class="form-check">
                                  <input class="form-check-input" type="radio" name="health_kit" id="health_kit1" value='0' {{ $transferEdit->medikit == 0 ? 'checked' : '' }}>
                                  <label class="form-check-label" for="health_kit1">
                                     No
                                  </label>
                                </div>
                            </div>                            
                            <div class="form-group col-sm-3">
                                <label for="status">Spare blub</label>
                                <div class="form-check">
                                  <input class="form-check-input" type="radio" name="spare_bulb" id="spare_bulb" value='1' {{ $transferEdit->spare_bulb == 1 ? 'checked' : '' }}>
                                  <label class="form-check-label" for="spare_bulb">
                                    Yes
                                  </label>
                                </div>
                                <div class="form-check col-sm-3">
                                  <input class="form-check-input" type="radio" name="spare_bulb" id="spare_bulb1" value='0' {{ $transferEdit->spare_bulb == 0 ? 'checked' : '' }}>
                                  <label class="form-check-label" for="spare_bulb1">
                                     No
                                  </label>
                                </div>
                            </div>
                            <div class="form-group col-sm-3">
                                <label for="status">Harzard Triangle</label>
                                 <div class="form-check">
                                  <input class="form-check-input" type="radio" name="harzard_triangle" id="harzard_triangle" value='1' {{ $transferEdit->   hazard_trinagle == 1 ? 'checked' : '' }}>
                                  <label class="form-check-label" for="harzard_triangle">
                                    Yes
                                  </label>
                                </div>
                                <div class="form-check col-sm-3">
                                  <input class="form-check-input" type="radio" name="harzard_triangle" id="harzard_triangle1" value='0' {{ $transferEdit->   hazard_trinagle == 0 ? 'checked' : '' }}>
                                  <label class="form-check-label" for="harzard_triangle1">
                                     No
                                  </label>
                                </div>
                            </div>
                            <div class="form-group col-sm-3">
                                <label for="status">Received vehicle in good condition</label>
                                <div class="form-check">
                                  <input class="form-check-input" type="radio" name="good_condition" id="good_condition" value='1' {{ $transferEdit->   good_condtiton == 1 ? 'checked' : '' }}>
                                  <label class="form-check-label" for="good_condition">
                                    Yes
                                  </label>
                                </div>
                                <div class="form-check col-sm-3">
                                  <input class="form-check-input" type="radio" name="good_condition" id="good_condition1" value='0' {{ $transferEdit->   good_condtiton == 0 ? 'checked' : '' }}>
                                  <label class="form-check-label" for="good_condition1">
                                     No
                                  </label>
                                </div>
                            </div>
                        </div>
                        <input type="hidden" value="{{ $transferVinNumber->id }}" name="vin_number">
                        <div class="form-group">
                            <button type="submit" class="btn waves-effect waves-light btn-rounded btn-outline-primary">Update</button>
                            <a href="{{ route('transfer') }}" class="btn waves-effect waves-light btn-rounded btn-outline-secondary">Cancel</a>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection

@section('scripts')
<!-- varient as per car model -->
<script>
    $(document).ready(function(){
      $('#car_model').change(function(){
        var car_model = $('#car_model').val();
        $.ajax({
             url : "{{ url('transfer/varientaspercarmodel') }}",
             data : {'car_model' : car_model,"_token": "{{ csrf_token() }}"},
             type : 'post',
             dataType : 'html',
             success: function(html) {
                //alert("success");
                $('#car_varient').html(html)
              }
              /*error: function(request) {
                console.log("error");
              }*/
        });
        return false;
      });
    });
</script>

<!-- vin number as per car varient -->
<script>
    $(document).ready(function(){
      $('#car_varient').change(function(){
        var car_varient = $('#car_varient').val();
        $.ajax({
             url : "{{ url('transfer/vinaspercarvarient') }}",
             data : {'car_varient' : car_varient,"_token": "{{ csrf_token() }}"},
             type : 'post',
             dataType : 'html',
             success: function(html) {
              // alert("success");
                $('#vin_number').html(html)
              }
              /*error: function(request) {
                console.log("error");
              }*/
        });
        return false;
      });
    });
</script>

<script>
    $(document).ready(function() {
        var form = $('#form');
        $('.kt-form__help').html('');
        form.submit(function(e) {
            $('.help-block').html('');
            $('.m-form__help').html('');
            $.ajax({
                url: form.attr('action'),
                type: form.attr('method'),
                data: new FormData($(this)[0]),
                dataType: 'json',
                async: false,
                processData: false,
                contentType: false,
                success: function(json) {
                    return true;
                },
                error: function(json) {
                    if (json.status === 422) {
                        e.preventDefault();
                        var errors_ = json.responseJSON;
                        $('.kt-form__help').html('');
                        $.each(errors_.errors, function(key, value) {
                            $('.' + key).html(value);
                        });
                    }
                }
            });
        });
    });
</script>
@endsection