@extends('template.app')

@section('meta')
@endsection

@section('title')
   RTO Master Update
@endsection

@section('styles')
<style>
    .col-sm-3{
        font-size: 15px;
    }
    .custom-form-spacing {
      margin-bottom: -5px !important;
    }
    input[type="number"]::-webkit-outer-spin-button,
    input[type="number"]::-webkit-inner-spin-button {
        -webkit-appearance: none;
        margin: 0;
    }
    
    /* Firefox */
    input[type="number"] {
        -moz-appearance: textfield;
    }
</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">RTO Master</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('rto_master') }}" class="text-muted">RTO Master</a></li>
                        <li class="breadcrumb-item text-muted active" aria-current="page">Update</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('rto_master.update') }}" name="form" id="form" method="post" enctype="multipart/form-data">
                        @csrf
                        @method('PATCH')
                 
                        <input type="hidden" name="id" value="{{ $data->id }}">
                        <div class="row">
                             <div class="form-group col-sm-4">
                                <label for="to_branch" >RTO Type</label>
                                <select class="form-control" name="rto_type" id="rto_type">
                                    <option value="regular_rto" <?php if('regular_rto' ==  $data->rto_type){ echo "selected"; } ?>>Regular Rto</option>
                                    <option value="csd"  <?php if('csd' ==  $data->rto_type){ echo "selected"; } ?>>CSD</option>
                                    <option value="handicap"  <?php if('handicap' ==  $data->rto_type){ echo "selected"; } ?>>Handicap</option>
                                    <option value="taxi"  <?php if('taxi' ==  $data->rto_type){ echo "selected"; } ?>>M-Drive(Taxi)</option>
                                    <option value="electric"  <?php if('electric' ==  $data->rto_type){ echo "selected"; } ?>>Electric</option>
                                    <option value="crtem"  <?php if('crtem' ==  $data->rto_type){ echo "selected"; } ?>>Crtem</option>
                                    <option value="bh_parsing" <?php if('bh_parsing' ==  $data->rto_type){ echo "selected"; } ?>>BH Parsing</option>
                                    <option value="ev_six" <?php if('ev_six' ==  $data->rto_type){ echo "selected"; } ?>>EV6</option>
                                </select>
                                <span class="kt-form__help error to_branch"></span>
                            </div>    
                            
                             <div class="form-group col-sm-4" id="rto_tax_individual_show">
                                <label for="name">RTO Tax Individual (%)</label>
                                <input type="number" name="rto_tax_individual" id="rto_tax_individual" class="form-control" placeholder="Enter Rto Tax Individual" min="0"  value="{{ $data->rto_tax_individual ??'' }}">
                                <span class="kt-form__help error name"></span>
                            </div>  
                            
                               
                            <div class="form-group col-sm-4" id="rto_tax_company_show">
                                <label for="name">RTO Tax Company (%)</label>
                                <input type="number" name="rto_tax_company" id="rto_tax_company" class="form-control" placeholder="Enter Rto Tax Company" min="0" value="{{ $data->rto_tax_company ??'' }}">
                                <span class="kt-form__help error name"></span>
                            </div> 
                            
                            <div class="form-group col-sm-4 d-none" id="fuel_tyle_show">
                                <label for="fuel_type">Fuel Type</label>
                                <select class="form-control" name="fuel_type" id="fuel_tyle">
                                    <option value="petrol_cng" <?php if('petrol_cng' ==  $data->fuel_type){ echo "selected"; } ?>>Petrol / CNG</option>
                                    <option value="diesel" <?php if('diesel' ==  $data->fuel_type){ echo "selected"; } ?>>Diesel</option>
                                    <option value="ev" <?php if('ev' ==  $data->fuel_type){ echo "selected"; } ?>>EV</option>
                                </select>
                                <span class="kt-form__help error fuel_type"></span>
                            </div>   
                            
                            <div class="form-group col-sm-4">
                                <label for="name">Temporary Registration</label>
                                <input type="number" name="temporary_registration" id="temporary_registration" class="form-control" placeholder="Enter Temporary Registration" min="0" value="{{ $data->temporary_registration ??'' }}">
                                <span class="kt-form__help error name"></span>
                            </div> 
                            
                            <div class="form-group col-sm-4">
                                <label for="name">Smart Card Fee</label>
                                <input type="number" name="smart_card_fee" id="smart_card_fee" class="form-control" placeholder="Enter Smart Card Fee" min="0" value="{{ $data->smart_card_fee ??'' }}">
                                <span class="kt-form__help error name"></span>
                            </div> 
                            
                            
                              <div class="form-group col-sm-4">
                                <label for="name">Hypothecation</label>
                                <input type="number" name="hypothecation" id="hypothecation" class="form-control" placeholder="Enter Hypothecation" min="0" value="{{ $data->hypothecation ??'' }}">
                                <span class="kt-form__help error name"></span>
                            </div> 
                            
                            
                              <div class="form-group col-sm-4">
                                <label for="name">Fresh Permit</label>
                                <input type="number" name="fresh_permit" id="fresh_permit" class="form-control" placeholder="Enter Fresh Permit" min="0" value="{{ $data->fresh_permit ??'' }}">
                                <span class="kt-form__help error name"></span>
                            </div> 
                            
                            
                              <div class="form-group col-sm-4">
                                <label for="name">New Registration </label>
                                <input type="number" name="new_registion" id="new_registion" class="form-control" placeholder="Enter New Registration" min="0" value="{{ $data->new_registion ??'' }}">
                                <span class="kt-form__help error name"></span>
                            </div> 
                            
                              <div class="form-group col-sm-4">
                                <label for="name">Number Plat </label>
                                <input type="number" name="crtem" id="crtem" class="form-control" placeholder="Enter New Crtem" min="0" value="{{ $data->crtem ??'' }}" >
                                <span class="kt-form__help error name"></span>
                            </div>
                            
                            
                            <div class="form-group col-sm-4">
                                <label for="name">Agent Charges </label>
                                <input type="number" name="agent_charges" id="agent_charges" class="form-control" placeholder="Enter Agent Charges" min="0" value="{{ $data->agent_charges ??'' }}">
                                <span class="kt-form__help error name"></span>
                            </div>
                            
                            <div class="form-group col-sm-4">
                                <label for="name">RTO Heandling Charges </label>
                                <input type="number" name="rto_heandling_charges" id="rto_heandling_charges" class="form-control" placeholder="Enter RTO Heading Charges" value="{{ $data->rto_heandling_charges ??'' }}"  >
                                <span class="kt-form__help error name"></span>
                            </div>
                            
                            <div class="form-group col-sm-4 d-none" id="below_1_lac_show">
                                <label for="below_1_lac">Below 10 Lac</label>
                                <input type="number" name="below_1_lac" id="below_1_lac" class="form-control" placeholder="Enter Percentage" min="0" step="0.01" value="{{ $data->below_1_lac ??'' }}">
                                <span class="kt-form__help error below_1_lac"></span>
                            </div>
                            
                            <div class="form-group col-sm-4 d-none" id="10_20_lac_show">
                                <label for="10_20_lac">10 - 20 Lac</label>
                                <input type="number" name="10_20_lac" id="10_20_lac" class="form-control" placeholder="Enter Percentage" min="0" step="0.01" value="{{ $data->{'10_20_lac'} ?? '' }}">
                                <span class="kt-form__help error 10_20_lac"></span>
                            </div>
                            
                            <div class="form-group col-sm-4 d-none" id="above_20_lac_show">
                                <label for="above_20_lac">Above 20 Lac</label>
                                <input type="number" name="above_20_lac" id="above_20_lac" class="form-control" placeholder="Enter Percentage" min="0" step="0.01" value="{{ $data->above_20_lac ??'' }}">
                                <span class="kt-form__help error above_20_lac"></span>
                            </div>
                            
                            <div class="form-group col-sm-4 d-none" id="parsing_percentage_show">
                                <label for="parsing_percentage">BH Parsing Percentage</label>
                                <input type="number" name="parsing_percentage" id="parsing_percentage" class="form-control" placeholder="Enter BH Parsing Percentage" min="0" step="0.01" value="{{ $data->parsing_percentage ??'' }}">
                                <span class="kt-form__help error parsing_percentage"></span>
                            </div>
                            
                            <div class="form-group col-sm-4 d-none" id="bh_parsing_validity_show">
                                <label for="bh_parsing_validity">BH Parsing Validity</label>
                                <input type="number" name="bh_parsing_validity" id="bh_parsing_validity" class="form-control" placeholder="Enter BH Parsing Validity" min="0" step="0.01" value="{{ $data->bh_parsing_validity ??'' }}">
                                <span class="kt-form__help error bh_parsing_validity"></span>
                            </div>
                            
                            <div class="form-group col-sm-4 d-none" id="total_parsing_validity_show">
                                <label for="total_parsing_validity">Total Parsing Validity</label>
                                <input type="number" name="total_parsing_validity" id="total_parsing_validity" class="form-control" placeholder="Enter Total Parsing Validity" min="0" step="0.01" value="{{ $data->total_parsing_validity ??'' }}">
                                <span class="kt-form__help error total_parsing_validity"></span>
                            </div>
                            
                        </div>
                        <div class="form-group">
                            <button type="submit" class="btn waves-effect waves-light btn-rounded btn-outline-primary">Submit</button>
                            <a href="{{ route('rto_master') }}" class="btn waves-effect waves-light btn-rounded btn-outline-secondary">Back</a>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection

@section('scripts')
<!-- <script>
    $("#percentage").keyup(function(e){
        $('.percentage').html('');
        if ($(this).val() > 99){
            $('.percentage').html('');
            $('.percentage').html('Enter Value Between 0 to 100!');
            $(this).val();
            $(this).val(100);
        }else if($(this).val() <= 99){
            $('.percentage').html('');
        }
    });

</script> -->

<!-- varient as per car model -->
<script>
    $(document).ready(function(){
        var rto_type = $("#rto_type").val();
        if(rto_type === 'bh_parsing'){
            $("#rto_tax_individual_show").addClass("d-none");
            $("#rto_tax_company_show").addClass("d-none");
            $("#fuel_tyle_show").removeClass("d-none");
            $("#below_1_lac_show").removeClass("d-none");
            $("#10_20_lac_show").removeClass("d-none");
            $("#above_20_lac_show").removeClass("d-none");
            $("#parsing_percentage_show").removeClass("d-none");
            $("#bh_parsing_validity_show").removeClass("d-none");
            $("#total_parsing_validity_show").removeClass("d-none");
        } else {
            $("#rto_tax_individual_show").removeClass("d-none");
            $("#rto_tax_company_show").removeClass("d-none");
            $("#fuel_tyle_show").addClass("d-none");
            $("#below_1_lac_show").addClass("d-none");
            $("#10_20_lac_show").addClass("d-none");
            $("#above_20_lac_show").addClass("d-none");
            $("#parsing_percentage_show").addClass("d-none");
            $("#bh_parsing_validity_show").addClass("d-none");
            $("#total_parsing_validity_show").addClass("d-none");
        }
        
        $('#rto_type').change(function(){
            var rto_type = $(this).val();
            if(rto_type === 'bh_parsing'){
                $("#rto_tax_individual_show").addClass("d-none");
                $("#rto_tax_company_show").addClass("d-none");
                $("#fuel_tyle_show").removeClass("d-none");
                $("#below_1_lac_show").removeClass("d-none");
                $("#10_20_lac_show").removeClass("d-none");
                $("#above_20_lac_show").removeClass("d-none");
                $("#parsing_percentage_show").removeClass("d-none");
                $("#bh_parsing_validity_show").removeClass("d-none");
                $("#total_parsing_validity_show").removeClass("d-none");
            } else {
                $("#rto_tax_individual_show").removeClass("d-none");
                $("#rto_tax_company_show").removeClass("d-none");
                $("#fuel_tyle_show").addClass("d-none");
                $("#below_1_lac_show").addClass("d-none");
                $("#10_20_lac_show").addClass("d-none");
                $("#above_20_lac_show").addClass("d-none");
                $("#parsing_percentage_show").addClass("d-none");
                $("#bh_parsing_validity_show").addClass("d-none");
                $("#total_parsing_validity_show").addClass("d-none");
            }
        });    
        
        
        $('#car_model').change(function(){
            var car_model = $('#car_model').val();
            $.ajax({
                 url : "{{ url('rto_master/varient_carmodel') }}",
                 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('rto_master/pricelistaspercarvarient') }}",
             data : {'car_varient' : car_varient,"_token": "{{ csrf_token() }}"},
             type : 'post',
             dataType : 'html',
             success: function(html) {
               // alert("success");
                $('#pricelist').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