<?php 


$extra_sum = 0;
if(!empty($data->priclist_detail)){
    $price_new_arr = json_decode($data->priclist_detail);

   /* var_dump($price_new_arr);
    die('stop');*/

    if($price_new_arr != NULL){
        $price_new_arr = array_column($price_new_arr, 'value_field');
        $extra_sum = array_sum($price_new_arr);    
    }
}

$view_enable = 1; //display all
if(auth()->user()->can('obf-view') == true && auth()->user()->can('obf-rtoview') == false && auth()->user()->can('obf-insuranceview') == false && auth()->user()->can('obf-fasttagview') == false){
    $view_enable = 2; // not display Insurance Details,RTO Department,Fasttag Department
}

?>

@extends('template.app') 

@section('meta')
@endsection

@section('title')
Expired Insurance View
@endsection

@section('styles')
<link href="{{ asset('assets/css/dropify.min.css') }}" rel="stylesheet">
<link href="{{ asset('assets/css/sweetalert2.bundle.css') }}" rel="stylesheet">
<link href="{{ asset('assets/css/select2.css') }}" rel="stylesheet">
<style type="text/css">
    /*#galeria{
        display: flex;
    }*/
    #galeria img{
        width: 85px;
        height: 85px;
        border-radius: 10px;
        box-shadow: 0 0 8px rgba(0,0,0,0.2);
        opacity: 85%;
        padding: 3px;
    }

   /* #pan_image_multi{
        display: flex;
    }*/
    #pan_image_multi img{
        width: 85px;
        height: 85px;
        border-radius: 10px;
        box-shadow: 0 0 8px rgba(0,0,0,0.2);
        opacity: 85%;
        padding: 3px;
    }

    /*#adhar_image_multi{
        display: flex;
    }*/
    #adhar_image_multi img{
        width: 85px;
        height: 85px;
        border-radius: 10px;
        box-shadow: 0 0 8px rgba(0,0,0,0.2);
        opacity: 85%;
        padding: 3px;
    }

    /*#documents_multi{
        display: flex;
    }*/
    #documents_multi img{
        width: 85px;
        height: 85px;
        border-radius: 10px;
        box-shadow: 0 0 8px rgba(0,0,0,0.2);
        opacity: 85%;
        padding: 3px;
    }

    /*#licance_image_multi{
        display: flex;
    }*/
    #licance_image_multi img{
        width: 85px;
        height: 85px;
        border-radius: 10px;
        box-shadow: 0 0 8px rgba(0,0,0,0.2);
        opacity: 85%;
        padding: 3px;
    }
</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">Insurance View</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('expired_insurance') }}" class="text-muted">Expired Insurance</a></li>
                        <li class="breadcrumb-item text-muted active" aria-current="page">View</li>
                    </ol>
                </nav>
            </div>
        </div>
        <div class="col-5 align-self-center">
            <div class="customize-input float-right">
            </div>
        </div>
    </div>
</div>
<div class="container-fluid">
    <div class="row">
        <div class="col-12">
            <div class="card">
                <div class="card-body">
                    
                    <form role="form"  enctype="multipart/form-data">
                      
                        
                        <div class="row" id="step-4">
                            <div class="col-lg-12 ">
                                <div class="col-md-12">
                                 <!--    <h3> Insurance Details</h3> -->
                                    <div class="row">

                                        <div class="form-group col-md-3">
                                            <label class="control-label col-sm-12">Insurance</label>
                                            <label class="checkbox-inline"><input type="radio" value="1" name="insurance_exist" class="chk_ncb insurance_exist" @if($data->insurance_exist == 1) checked @endif disable> Yes</label>
                                            <label class="checkbox-inline"><input type="radio" value="2" name="insurance_exist"  class="chk_ncb insurance_exist" @if($data->insurance_exist == 2) checked @endif disable> No</label>
                                            <span class="kt-form__help error insurance_exist"></span>
                                        </div>

                                        <div class="form-group col-md-3 insurance_exist_c">
                                            <!-- <label class="control-label col-sm-12">NCB - None Claim Bonus</label> -->
                                            <label class="control-label col-sm-12">NCB - No Claim Bonus</label>
                                            <label class="checkbox-inline" disabled><input type="radio" value="yes" name="ncb" class="chk_ncb" disabled @if($data->ncb == 'yes') checked @endif > Yes</label>
                                            <label class="checkbox-inline" disabled><input type="radio" value="no" name="ncb" class="chk_ncb" disabled @if($data->ncb != 'yes') checked @endif > No</label>
                                            <span class="kt-form__help error occupation"></span>
                                        </div>
                                        
                                       <div class="form-group col-md-3 insurance_exist_c">
                                            <div class="row">
                                                <div class="form-group col-md-12">
                                                     <p>Upload Document</p>
                                                </div>
                                                <div class="form-group col-md-12">
                                                    <div id="documents_multi">
                                                    <?php
                                                        if(!empty($data->documents))
                                                        {
                                                            $other_documents_arr = explode(',', $data->documents);
                                                            foreach ($other_documents_arr as $value) {
                                                                if(file_exists(public_path('/uploads/kyc/'.$value))) { ?>
                                                                    <img src="{{asset('uploads/kyc/'. $value )}}">
                                                                <?php }
                                                            }
                                                        }
                                                    ?>
                                                    </div>
                                                </div>
                                            </div>                                           
                                        </div>


                                        <div class="form-group col-md-3 insurance_exist_c">
                                            <label class="control-label">Date of Insurance</label>
                                            <input type="date"  name="date_of_insurance" id="date_of_insurance" class="form-control" placeholder="Date Of Insurance" value="{{ $data->date_of_insurance ?? '' }}" readonly>
                                            <span class="kt-form__help error date_of_insurance"></span>
                                        </div>
                                        <div class="form-group col-md-3 insurance_exist_c">
                                            <label class="control-label">Time of Insurance</label>
                                            <input type="text"  name="time_of_insurance" id="time_of_insurance" class="form-control" placeholder="Time of Insurance" value="{{ $data->time_of_insurance ?? '' }}" readonly>
                                            <span class="kt-form__help error time_of_insurance"></span>
                                        </div>
                                        <div class="form-group col-md-3 insurance_exist_c">
                                            <label class="control-label">Last Date of Insurance</label>
                                            <input type="text"  name="last_time_of_insurance" id="last_time_of_insurance" class="form-control" placeholder="last time of insurance" value="{{ $data->last_time_of_insurance ?? '' }}" readonly>
                                            <span class="kt-form__help error last_time_of_insurance"></span>
                                        </div>
                                        <div class="form-group col-md-3 insurance_not_exist_c">
                                            <label class="control-label">Company Name</label>
                                            <input type="text"  name="company_name" id="company_name" class="form-control" placeholder="Enter Company Name" value="{{ $data->company_name ?? '' }}" readonly>
                                            <span class="kt-form__help error company_name"></span>
                                        </div>
                                        <div class="form-group col-md-3 insurance_not_exist_c">
                                            <label class="control-label">Amount</label>
                                            <input type="number"  name="ncb_amount" id="ncb_amount" class="form-control" placeholder="Enter NCB Amount" value="{{ $data->ncb_amount ?? '' }}" readonly>
                                            <span class="kt-form__help error ncb_amount"></span>
                                        </div>
                                        <div class="form-group col-md-3 insurance_exist_c">
                                            <label class="control-label">Policy Number</label>
                                            <input type="text"  name="policy_number" id="policy_number" class="form-control" placeholder="Enter Policy Number" value="{{ $data->policy_number ?? '' }}" readonly>
                                            <span class="kt-form__help error policy_number"></span>
                                        </div>
                                        
                                        <div class="form-group col-md-3 insurance_exist_c">
                                            <label class="control-label">Status</label>
                                            <select name="insurance_status" id="insurance_status" class="form-control" disabled>
                                                
                                                <option value="1" @if($data->insurance_status == '1') selected @endif>Activate</option>
                                                <option value="0" @if($data->insurance_status != '1') selected @endif>Deactivate</option>
                                            </select>
                                            <span class="kt-form__help error rto_type"></span>
                                        </div>
                                        
                                        
                                        
                                    </div>
                                </div>
                            </div>
                        </div>
                        
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection

@section('scripts')
<script src="{{ asset('assets/js/dropify.min.js') }}"></script>
<script src="{{ asset('assets/js/promise.min.js') }}"></script>
<script src="{{ asset('assets/js/sweetalert2.bundle.js') }}"></script>
<script src="{{ asset('assets/js/select2.js') }}"></script>

<?php
    if(!empty($data->priclist_detail)){
        $data->priclist_detail = json_decode($data->priclist_detail);
    }
 ?>


<script>
    
    function insurance_exist(){
       var insurance_exist =  $('input[name="insurance_exist"]:checked').val();

        if(insurance_exist == 1){
            $('.insurance_exist_c').show();
            $('.insurance_not_exist_c').show();
        }else{
            $('.insurance_exist_c').hide();
            $('.insurance_not_exist_c').show();
        }
    }

    $(document).on('change','.insurance_exist',function(){
        insurance_exist();
    });

    insurance_exist();


    $(document).ready(function(){
        if($('#address_1').val() == $('#address_2').val()){
            $("#chek_address").attr("checked" ,true);
        }

        var copyData = '';
        $('#chek_address').on('click', function(){
            if($('#chek_address').is(":checked")){
                copyData = $('#address_1').val();
                $('#address_2').val(copyData);
            }else{
                $('#address_2').val('');
            }
        })
        $('.dropify').dropify({
            messages: {
                'default': 'Drag and drop profile image here or click',
                'remove':  'Remove',
                'error':   'Ooops, something wrong happended.'
            }
        });

        var drEvent = $('.dropify').dropify();

        var dropifyElements = {};
        $('.dropify').each(function () {
            dropifyElements[this.id] = false;
        });

        drEvent.on('dropify.beforeClear', function(event, element){
            id = event.target.id;
            if(!dropifyElements[id]){
                var url = "{!! route('obf.profile.remove') !!}";
                <?php if(isset($data) && isset($data->id)){ ?>
                    var id_encoded = "{{ base64_encode($data->id) }}";

                    Swal.fire({
                        title: 'Are you sure want delete this image?',
                        text: "",
                        type: 'warning',
                        showCancelButton: true,
                        confirmButtonColor: '#3085d6',
                        cancelButtonColor: '#d33',
                        confirmButtonText: 'Yes'
                    }).then(function (result){
                        if (result.value){
                            $.ajax({
                                url: url,
                                type: "POST",
                                data:{
                                    id: id_encoded,
                                    _token: "{{ csrf_token() }}"
                                },
                                dataType: "JSON",
                                success: function (data){
                                    if(data.code == 200){
                                        Swal.fire('Deleted!', 'Deleted Successfully.', 'success');
                                        dropifyElements[id] = true;
                                        element.clearElement();
                                    }else{
                                        Swal.fire('', 'Failed to delete', 'error');
                                    }
                                },
                                error: function (jqXHR, textStatus, errorThrown){
                                    Swal.fire('', 'Failed to delete', 'error');
                                }
                            });
                        }
                    });

                    return false;
                <?php } else { ?>
                    Swal.fire({
                        title: 'Are you sure want delete this image?',
                        text: "",
                        type: 'warning',
                        showCancelButton: true,
                        confirmButtonColor: '#3085d6',
                        cancelButtonColor: '#d33',
                        confirmButtonText: 'Yes'
                    }).then(function (result){
                        if (result.value){
                            Swal.fire('Deleted!', 'Deleted Successfully.', 'success');
                            dropifyElements[id] = true;
                            element.clearElement();
                        }else{
                            Swal.fire('Cancelled', 'Discard Last Operation.', 'error');
                        }
                    });
                    return false;
                <?php } ?>
            } else {
                dropifyElements[id] = false;
                return true;
            }
        });
    });
</script>
<script>
    $(document).ready(function(){
        $('.select2').select2({
            placeholder:"Select Accessory",
        })

         $('.select_priclist').select2({
            placeholder:"Select Pricelist Detail",
        })
    }); 
     


    $('#accessories').on('change' , function(){
        var sum = 0;
        $('#accessories :selected').each(function() {
            sum  += parseInt($(this).data("price"));
        })
        //console.log(sum);
        $('#total').html(sum);
    });

     $('#pricelist_manager_id').attr('disabled',true);

       function car_mveriant(e){
          var id = e.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 e_row = resp.data.pricelist_arr;

                   console.log(e_row);

                    html = '';
                    jQuery.each(e_row, function(key, val){ 
                        $('#pricelist_manager_id').removeAttr('disabled');
                        html += '<option value="'+val.price_id+'">'+val.price_list_name+' | '+val.transmission+'</option>';
                    });
                    console.log(html);
                    jQuery("#pricelist_manager_id").empty();
                    jQuery("#pricelist_manager_id").html(html);

                }
            });
            
        }



        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 e_row = resp.data.pricelist_arr;

                       console.log(e_row);

                       var data_veriant = "<?php echo $data->product_id ?>"; 

                       html = '';

                       

                       var pricelist_id = "<?php echo $data->pricelist_id ?>"; 

                       jQuery.each(e_row, function(key, val){ 
                            var selected = '';
                            if(pricelist_id != '' && pricelist_id == val.id){
                                selected = "selected";
                            }

                           $('#pricelist_manager_id').removeAttr('disabled');
                           html += '<option value="'+val.id+'" '+selected+'>'+val.price_list_name+' | '+val.transmission+'</option>';
                       });
                       console.log(html);
                       jQuery("#pricelist_manager_id").empty();
                       jQuery("#pricelist_manager_id").html(html);
                   }
               });
               
           }
                                
            var data_veriant = "<?php echo $data->product_id ?>"; 
                console.log(data_veriant);
        if(data_veriant != ''){
            car_mveriant_edit(data_veriant);
        }

        var priclist_detail_arr_f = <?php echo json_encode($data->priclist_detail); ?>;
        const arrayColumn = (array, column) => {
            return array.map(item => item[column]);
        };
        const priclist_detail_arr = arrayColumn(priclist_detail_arr_f, 'detail_field');

        function Getpricelist_edit_get(id){

            if(id != ''){
                var URL='{{route('obf.getpricelist')}}';
                $.ajax({
                        url: URL,
                        type: 'post',
                        data: {id:id,_token: "{{ csrf_token() }}"},
                        cache: false,
                        success: function(data) {
                            if(data.detail_value != ''){
                                var e_row = jQuery.parseJSON(data.detail_value);

                               

                                var html = '';                     

                                if(e_row.length > 0){
                                    // html +='<option value="">Select Veriant</option>';
                                    jQuery.each(e_row, function(key, val){
                                        console.log("---");
                                        console.log(val.value_field);
                                        console.log("---");
                                        var selected = '';

                                        // if(jQuery.inArray(val.value_field, priclist_detail_arr)) {
                                        if(jQuery.inArray(val.detail_field, priclist_detail_arr) != -1) {
                                            console.log('selected');
                                             selected = 'selected';
                                        }
                                       html +='<option value="'+val.detail_field+'__'+val.value_field+'" '+selected+' data-value_field="'+val.value_field+'">'+val.detail_field+' - '+val.value_field+'</option>';
                                    });


                                    jQuery("#priclist_detail").empty();
                                    jQuery("#priclist_detail").html(html);
                                }
                            }              
                        },
                        error: function(data) {
                            
                        }
                });
            }
        }

        Getpricelist_edit_get("<?php echo $data->product_id; ?>");
    
</script>

@endsection