<?php 
    $user_new = auth()->user(); 
    $is_finance_display_filds = 1;
    if($user_role == 'KEC' ||  $user_role == 'Team leader'){
        $is_finance_display_filds = 0;    
    }
?>

@extends('template.app')

@section('meta') @endsection

@section('title') Obf Insert @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">
    <link rel="stylesheet" href="//code.jquery.com/ui/1.13.2/themes/base/jquery-ui.css">

    <style type="text/css">
    
        #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 img{
            width: 85px;
            height: 85px;
            border-radius: 10px;
            box-shadow: 0 0 8px rgba(0,0,0,0.2);
            opacity: 85%;
            padding: 3px;
        }
    
        #aadhar_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 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 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 img{
            width: 85px;
            height: 85px;
            border-radius: 10px;
            box-shadow: 0 0 8px rgba(0,0,0,0.2);
            opacity: 85%;
            padding: 3px;
        }
        
        #offer_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;
        }
    
        .column { 
            float: left; 
        }
    
        .half { 
            width: 49%; 
            margin-top: 100px;
        }
    
        .last { 
            float: right; 
            width: 49%; 
            margin-top: 100px;
        }
        
        #address_1 {
            height: 70px !important;
        }
        #address_2 {
            height: 70px !important;
        }
    
        .dark_font {
            font-weight: bold!important;
        }
        .red_colour {
            background: #7a7c89!important;
            color: white !important;
            border-radius:30px;
        }
        .uploaded_images{
            border:1px solid white;
            margin-bottom: 20px;
            border-radius: 5px;
        }
        .select2-container .select2-selection--single {
            height:38px!important;
            width:365px!important;
        }
    </style>
@endsection

@section('content')
    <div class="page-breadcrumb">
        <div class="row">
            <div class="col-7 align-self-center">
                <h4 class="page-title text-truncate  font-weight-medium mb-1">OBF - Order Booking Form</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="">Dashboard</a></li>
                            <li class="breadcrumb-item"><a href="{{ route('obf') }}" class="">OBF</a></li>
                            <li class="breadcrumb-item  active" aria-current="page">Insert</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">
                        <div class="stepwizard col-md-offset-3">
                            <div class="stepwizard-row setup-panel">

                                <div class="stepwizard-step">
                                    <a href="#step-1" type="button" class="btn btn-primary btn-circle text-white">1</a>
                                    <p>Personal Details</p>
                                </div>

                                <div class="stepwizard-step">
                                    <a href="#step-2" id="second_new" type="button" class="btn btn-default btn-circle text-white" disabled="disabled">2</a>
                                    <p>Car Details</p>
                                </div>

                                @canany(['obf-finance'])
                                    <div class="stepwizard-step">
                                        <a href="#step-3" id="thrid_new" type="button" class="btn btn-default btn-circle text-white" disabled="disabled">3</a>
                                        <p>Finance Details</p>
                                    </div>
                                @endcanany 
                            </div>
                        </div>

                        <form role="form" action="{{ route('obf.insert') }}" method="post" enctype="multipart/form-data" id="obf_creation">
                            <input type="hidden" name="basic" id="basic" value="0" >
                            <input type="hidden" name="gst_amount" id="gst_amount" value="0" >
                            <input type="hidden" name="cess_amount" id="cess_amount" value="0" >
                            @csrf

                            <div class="row setup-content" id="step-1">
                                <div class="col-lg-12 ">
                                    <div class="col-md-12">
                                        <h5> Personal Details</h5>
                                        <div class="row">

                                            
                                            <div class="form-group col-md-3">
                                                <label class="control-label">Booking Date<span class="required" style="color: red;">*</span></label>
                                                <input type="text" id="booking_date" name="booking_date" class="form-control">
                                                <span class="kt-form__help error booking_date"></span>
                                            </div>
                                            
                                            <div class="form-group col-md-3">
                                                <label class="control-label">Customer Name(Bill To)<span class="required" style="color: red;">*</span></label>
                                                <input type="text"  name="customer_name" id="customer_name" class="form-control" placeholder="Enter Customer Name" style="text-transform:uppercase">
                                            </div>

                                            <div class="form-group col-md-3">
                                                <label for="is_csd">CSD<span class="required" style="color: red;">*</span></label>
                                                <select class="form-control" name="is_csd" id="is_csd">
                                                    <option value="">Select CSD</option>
                                                    <option value="Yes">Yes</option>
                                                    <option value="No" selected>No</option>
                                                </select>
                                                <span class="kt-form__help error to_branch"></span>
                                            </div>     

                                            <div class="form-group col-md-3">
                                                <label class="control-label">RTO Type <span class="required" style="color: red;">*</span></label>
                                                <select  name="customer_type" id="customer_type" class="form-control" placeholder="Enter RTO Type" style="text-transform:uppercase">
                                                    <option selected value="regular_rto">Regular RTO</option>
                                                    <option value="handicap">Handicap</option>
                                                    <option value="taxi">M-Drive(Taxi)</option>
                                                    <option value="electric">Electric</option>
                                                    <option value="crtem">Crtem</option>
                                                    <option value="bh_parsing">BH Passing</option>
                                                    <option value="ev_six">EV6</option>
                                                </select>
                                            </div>

                                            <div class="form-group col-md-3">
                                                <label class="control-label">Customer Type</label>
                                                <select name="customer_type_new" id="customer_type_new" class="form-control" style="text-transform:uppercase">
                                                    <option value="">Please Customer Type</option>
                                                    @if(isset($CustomerTypeMaster) && $CustomerTypeMaster->isNotEmpty())
                                                        @foreach($CustomerTypeMaster AS $row)
                                                            <option value="{{ $row->id }}">{{ $row->name ??'' }}</option>
                                                        @endforeach
                                                    @endif
                                                </select>
                                                <span class="kt-form__help error customer_type_new"></span>
                                            </div>

                                            <div class="form-group col-md-3">
                                                <label class="control-label">Branch<span class="required" style="color: red;">*</span></label>
                                                <select name="branch" id="branch" class="form-control" style="text-transform:uppercase">
                                                    <option value="">Select Branch</option>
                                                    @if(isset($branch) && $branch->isNotEmpty())
                                                        @foreach($branch AS $branch)
                                                            <option value="{{ $branch->id }}" data-start_value1="{{ $branch->start_value1 }}" data-end_value1="{{ $branch->end_value1 }}" data-tax_percentage1="{{ $branch->tax_percentage1 }}" data-start_value2="{{ $branch->start_value2 }}" data-end_value2="{{ $branch->end_value2 }}" data-tax_percentage2="{{ $branch->tax_percentage2 }}">{{ $branch->name }}</option>
                                                        @endforeach
                                                    @endif
                                                </select>
                                            </div>

                                            <div class="form-group col-md-3">
                                                <label class="control-label">Company Name(Bill To)</label>
                                                <input type="text"  name="company_name" id="company_name" class="form-control" placeholder="Enter Company Name" style="text-transform:uppercase">
                                                <span class="kt-form__help error company_name"></span>
                                            </div>

                                            <div class="form-group col-md-3">
                                                <label class="control-label">e-Invoice Applicable?<span class="required" style="color: red;">*</span></label>
                                                <select name="einvoapp" id="einvoapp" class="form-control" style="text-transform:uppercase">
                                                    <option value="">Select e-Invoicing</option>
                                                    <option value="yes">Yes</option>
                                                    <option value="no">No</option>
                                                </select>
                                            </div>
                                            
                                            <div class="form-group col-md-3">
                                                <label class="control-label">GST Required ?</label>
                                                <select name="gst_required" id="gst_required" class="form-control" style="text-transform:uppercase">
                                                    <option value="yes">Yes</option>
                                                    <option value="no">No</option>
                                                </select>
                                            </div>

                                            <div class="form-group col-md-3" id="gst_hs">
                                                <label class="control-label">GST No.</label>
                                                <input type="text"  name="gst" id="gst" class="form-control" placeholder="Enter GST No" style="text-transform:uppercase">
                                                <span class="kt-form__help error gst"></span>
                                            </div>

                                            <div class="form-group col-md-3">
                                                <label class="control-label mt-3">Address Of Correspondence(Bill To)<span class="required" style="color: red;">*</span></label>
                                                <textarea  name="address_1" id="address_1" class="form-control" placeholder="Enter Address Correspondence" style="text-transform:uppercase; height:150px;"></textarea>
                                            </div>

                                            <div class="form-group col-md-3">
                                                <label class="control-label mt-3">Registration Correspondence(Bill To)</label>
                                                <input id="chek_address" type="checkbox" class="form-check-input mt-4 largerCheckbox" value="" style="width:20px;height: 20px;"  data-toggle='tooltip' title="Same as Address Correspondence">
                                                <textarea  name="address_2" id="address_2" class="form-control" placeholder="Enter Registration Correspondence" style="text-transform:uppercase"></textarea>
                                                <span class="kt-form__help error address_2"></span>
                                            </div>
                                            
                                            <div class="form-group col-md-3">
                                                <label for="state_id">State (Bill To)</label>
                                                    <select name="state_id" id="state_id" class="form-control state_id_select2">
                                                        <option value="">Select State</option>
                                                        @foreach($states as $state)
                                                            <option value="{{ $state->id }}">
                                                                {{ $state->name }}
                                                            </option>
                                                        @endforeach
                                                    </select>
                                                <span class="kt-form__help error state_id"></span>
                                            </div>
                                            
                                            <div class="form-group col-md-3">
                                                <label for="district_id">District (Bill To)</label>
                                                    <select name="district_id" id="district_id" class="form-control district_id_select2">
                                                        <option value="">Select District</option>
                                                        @foreach($districts as $district)
                                                            <option value="{{ $district->id }}">
                                                                {{ $district->name }}
                                                            </option>
                                                        @endforeach
                                                    </select>
                                                <span class="kt-form__help error district_id"></span>
                                            </div>
                                            
                                            <div class="form-group col-md-3">
                                                <label for="city_id">City (Bill To)</label>
                                                    <select name="city_id" id="city_id" class="form-control city_id_select2">
                                                        <option value="">Select City</option>
                                                        @foreach($cities as $city)
                                                            <option value="{{ $city->id }}">
                                                                {{ $city->name }}
                                                            </option>
                                                        @endforeach
                                                    </select>
                                                <span class="kt-form__help error city_id"></span>
                                            </div>
                                            
                                            <div class="form-group col-md-3">
                                                <label for="city_id">RTO Passing Code</label>
                                                    <select name="rto_passing_id" id="rto_passing_id" class="form-control rto_passing_id_select2">
                                                        <option value="">Select Code</option>
                                                        @foreach($passing_code as $code)
                                                            <option value="{{ $code->id }}">
                                                                {{ $code->code_area }}
                                                            </option>
                                                        @endforeach
                                                    </select>
                                                <span class="kt-form__help error rto_passing_id"></span>
                                            </div>
                                            
                                            <div class="form-group col-md-3">
                                                <label class="control-label">Ship To Required:</label>
                                                <select name="ship_to_required" id="ship_to_required" class="form-control">
                                                    <option value="">Select Options</option>
                                                    <option value="yes">Yes</option>
                                                    <option value="no">No</option>
                                                </select>
                                            </div>
                                            
                                            <div class="form-group col-md-3" id="ship_to_customer_name" style="display: none;">
                                                <label class="control-label">Customer Name (Ship To):</label>
                                                <input type="text" name="ship_to_customer_name" id="ship_to_customer_name" class="form-control" placeholder="Enter Customer Name" style="text-transform:uppercase">
                                            </div>
                                                                                
                                            <div class="form-group col-md-3" id="ship_to_address" style="display: none;">
                                                <label class="control-label">Address (Ship To):</label>
                                                <input type="text" name="ship_to_address" id="ship_to_address" class="form-control" placeholder="Enter Address" style="text-transform:uppercase">
                                            </div>

                                            <div class="form-group col-md-3" id="ship_to_state_id" style="display: none;">
                                                <label class="ship_to_state_id">State (Ship To):</label>
                                                <select name="ship_to_state_id" id="ship_to_state_id" class="form-control ship_to_state_id_select2">
                                                    <option value="">Select State</option>
                                                    @foreach($states as $state)
                                                        <option value="{{ $state->id }}">
                                                            {{ $state->name }}
                                                        </option>
                                                    @endforeach
                                                </select>
                                                <span class="kt-form__help error ship_to_state_id"></span>
                                            </div>

                                            <div class="form-group col-md-3" id="ship_to_district_id" style="display: none;">
                                                <label class="ship_to_district_id">District (Ship To):</label>
                                                <select name="ship_to_district_id" id="ship_to_district_id" class="form-control ship_to_district_id_select2">
                                                    <option value="">Select District</option>
                                                    @foreach($districts as $district)
                                                        <option value="{{ $district->id }}">
                                                            {{ $district->name }}
                                                        </option>
                                                    @endforeach
                                                </select>
                                                <span class="kt-form__help error ship_to_district_id"></span>
                                            </div>

                                            <div class="form-group col-md-3" id="ship_to_city_id" style="display: none;">
                                                <label class="ship_to_city_id">City (Ship To):</label>
                                                <select name="ship_to_city_id" id="ship_to_city_id" class="form-control ship_to_city_id_select2">
                                                    <option value="">Select City</option>
                                                    @foreach($cities as $city)
                                                        <option value="{{ $city->id }}">
                                                            {{ $city->name }}
                                                        </option>
                                                    @endforeach
                                                </select>
                                                <span class="kt-form__help error ship_to_city_id"></span>
                                            </div>

                                            <div class="form-group col-md-3">
                                                <label class="control-label">e-Mail</label>
                                                <input type="email"  name="email" id="email" class="form-control" placeholder="Enter Email Address" >
                                                <span class="kt-form__help error email"></span>
                                            </div>

                                            <div class="form-group col-md-3">
                                                <label class="control-label">Mobile No.<span class="required" style="color: red;">*</span></label>
                                                <input type="number"  name="contact_number" id="contact_number" class="form-control" placeholder="Enter Mobile Number" maxlength="10" required>
                                            </div>

                                            <div class="form-group col-md-3">
                                                <label class="control-label">PAN No.<span class="required" style="color: red;">*</span></label>
                                                <input type="text"  name="pan_number" id="pan_number" class="form-control" placeholder="Enter PAN Number" value="{{ $data->pan_number ??'' }}"  maxlength="10" required>
                                                <span class="kt-form__help error pan_number"></span>
                                            </div>

                                            <div class="form-group col-md-3">
                                                <label class="control-label">Aadhar No.<span class="required" style="color: red;">*</span></label>
                                                <input type="text"  name="adhar_number" id="aadhar_number" class="form-control" placeholder="Enter Aadhar Number" value="{{ $data->aadhar_number ??'' }}" maxlength="12">
                                                <span class="kt-form__help error aadhar_number"></span>
                                            </div>

                                            <div class="form-group col-md-3">
                                                <label class="control-label">Voter Id No.</label>
                                                <input type="text"  name="license_number" id="license_number" class="form-control" placeholder="Enter Voter Id Number" value="{{ $data->licance_number ??'' }}" >
                                                <span class="kt-form__help error license_number"></span>
                                            </div>

                                            <div class="form-group col-md-3">
                                                <label class="control-label">Date of Birth</label>
                                                <input type="text" name="dob" id="dob" class="form-control" placeholder="dd-mm-yyyy"placeholder="dd-mm-yyyy">
                                                <span class="kt-form__help error dob"></span>
                                            </div>

                                            <div class="form-group col-md-3">
                                                <label class="control-label">Nominee Name</label>
                                                <input type="text"  name="nominee_name" id="nominee_name" class="form-control" placeholder="Enter Nominee Name" style="text-transform:uppercase">
                                                <span class="kt-form__help error nominee_name"></span>
                                            </div>

                                            <div class="form-group col-md-3">
                                                <label class="control-label">Nominee Date of Birth</label>
                                                <input type="text"  name="nominee_dob" id="nominee_dob" class="form-control" placeholder="dd-mm-yyyy">
                                                <span class="kt-form__help error dob"></span>
                                            </div>

                                            <div class="form-group col-md-3">
                                                <label class="control-label">Nominee Relation</label>
                                                <input type="text"  name="nominee_relation" id="nominee_relation" class="form-control" placeholder="Enter Nominee Relation" style="text-transform:uppercase">
                                                <span class="kt-form__help error nominee_relation"></span>
                                            </div>

                                            <div class="form-group col-md-3">
                                                <label class="control-label">Nominee Age</label>
                                                <input type="number" name="nominee_age" id="nominee_age" class="form-control" placeholder="Enter Nominee Age">
                                                <span class="kt-form__help error nominee_age"></span>
                                            </div>
                                            
                                            <div class="form-group col-md-3">
                                                <label class="control-label">Anniversary Date</label>
                                                <input type="date"  name="anniversary_date" id="anniversary_date" class="form-control" placeholder="dd-mm-yyyy">
                                                <span class="kt-form__help error anniversary_date"></span>
                                            </div>

                                        <div class="form-group col-md-3">
                                            <label for="occupation">Occupation</label>
                                            <select name="occupation" id="occupation" class="form-control">
                                                <option value="">Select Occupation</option>
                                                @foreach($occupation_lists as $occupation_list)
                                                    <option value="{{ $occupation_list->occupation_title }}"
                                                        @if(old('occupation') == $occupation_list->occupation_title) selected @endif>
                                                        {{ $occupation_list->occupation_title }}
                                                    </option>
                                                @endforeach
                                            </select>
                                            <span class="kt-form__help error occupation"></span>
                                        </div>

                                            
                                            <div class="form-group col-md-3">
                                                <label class="control-label">Aadhar & Pan Linked ?</label>
                                                <select name="aadhar_pan_link" id="aadhar_pan_link" class="form-control">
                                                    <option value="">Select Options</option>
                                                    <option value="yes">Yes</option>
                                                    <option value="no">No</option>
                                                </select>
                                            </div>

                                            <div class="form-group col-md-3" id="aadhar_pan_div">
                                                <label class="control-label">Aadhar & Pan Linked Document</label>
                                                <input type="file" name="aadhar_pan_image[]" id="aadhar_pan_image" onchange="previewMultiple(event,'aadhar_pan_image_multi','aadhar_pan_image')" class="form-control dropify" data-default-file="" data-max-file-size-preview="2M" multiple>
                                                <span class="kt-form__help error aadhar_pan_image"></span>
                                            </div>

                                            <div class="form-group col-md-3">
                                                <label class="control-label">Upload PAN</label>
                                                <span class="required" style="color: red;">*</span>
                                                <input type="file" name="pan_image[]" id="pan_image" onchange="previewMultiple(event,'pan_image_multi','pan_image')" class="form-control dropify" data-default-file="" data-max-file-size-preview="2M" multiple>
                                                <span class="kt-form__help error pan_image"></span>
                                            </div>

                                            <div class="form-group col-md-3">
                                                <label class="control-label">Upload Aadhar</label>
                                                <span class="required" style="color: red;">*</span>
                                                <input type="file" name="adhar_image[]" id="adhar_image" onchange="previewMultiple(event,'adhar_image_multi','adhar_image')" class="form-control dropify" data-default-file=""  data-max-file-size-preview="2M" multiple>
                                                <span class="kt-form__help error adhar_image"></span>
                                            </div>

                                            <div class="form-group col-md-3">
                                                <label class="control-label">Upload Voter ID</label>
                                                <input type="file" name="licance_image[]" id="licance_image" onchange="previewMultiple(event,'licance_image_multi','licance_image')"  class="form-control dropify" data-default-file=""  data-max-file-size-preview="2M" multiple>
                                                <span class="kt-form__help error licance_image"></span>
                                            </div>

                                            <div class="form-group col-md-3">
                                                <label class="control-label">Upload Other Documents</label>
                                                <input type="file" name="other_documents[]" id="other_documents" onchange="previewMultiple(event,'galeria','other_documents')" class="form-control dropify" data-default-file=""  data-max-file-size-preview="2M" multiple>   
                                                <span class="kt-form__help error other_documents"></span>
                                            </div>
                                        </div>
                                        
                                        <div class="uploaded_images">
                                            <div class="col-md-12 row">
                                                <h3>Images Section</h3>
                                                <div id="aadhar_pan_image_multi" class="form-group col-md-2"></div>        
                                                <div id="pan_image_multi" class="form-group col-md-2"></div>
                                                <div id="adhar_image_multi" class="form-group col-md-2"></div>
                                                <div id="licance_image_multi" class="form-group col-md-2"></div>      
                                                <div id="galeria" class="form-group col-md-2"></div>
                                            </div>
                                        </div>
                                        <a href="{{ route('obf') }}"><button class="btn btn-outline-secondary btn-sm pull-right" type="button">Back</button></a>
                                        <button class="btn btn-outline-secondary btn-sm pull-right submit_once" type="submit">Save as Draft</button>
                                        <button class="btn waves-effect waves-light btn-rounded btn-outline-secondary nextBtn btn-sm pull-right next_one" type="button">Next</button>
                                    </div>
                                </div>
                            </div>

                            <div class="row setup-content" id="step-2">
                                <div class="col-lg-12 ">
                                    <div class="col-md-12">
                                        <h5> Car Details</h5>
                                        <div class="row">
                                            <div class="form-group col-md-3">
                                                <label class="control-label">Sales Person Name <span class="required" style="color: red;">*</span></label>
                                                <select name="sales_person_name" id="sales_person_name" class="form-control">
                                                    <option value="">Select Sales Person</option>
                                                    @if(isset($sales) && $sales->isNotEmpty())
                                                        @foreach($sales AS $row)
                                                            <option value="{{ $row->id }}" @if($user_new->id == $row->id) selected @endif>{{ $row->sales_person_name ??'' }}</option>
                                                        @endforeach
                                                    @else        
                                                        <option value="1">Super Admin</option>
                                                    @endif
                                                </select>
                                                <span class="kt-form__help error sales_person_name"></span>
                                            </div>

                                            <div class="form-group col-sm-3">
                                                <label for="car_name">Car Model <span class="required" style="color: red;">*</span></label>
                                                <select class="form-control" name="car_name" id="car_name">
                                                    <option value="">Select Car Model</option>
                                                    @if(isset($Carmodel_arr)) 
                                                        @foreach($Carmodel_arr as $car_model)
                                                        <option value="{{ $car_model->id }}" @if(!empty($data) && $data->product_id == $car_model->id) selected @endif> {{ $car_model->name }}</option>
                                                        @endforeach
                                                    @endif
                                                </select>
                                                <span class="kt-form__help error car_name"></span>
                                            </div>

                                            <div class="form-group col-sm-3">
                                                <label for="fuel_type">Fuel Type <span class="required" style="color: red;">*</span></label>
                                                <select class="form-control" name="fuel_type" id="fuel_type">
                                                    <option value="">Select Fuel Type</option>
                                                    @if(isset($fuel_type)) 
                                                        @foreach($fuel_type as $val)
                                                            <option value="{{ $val->id }}" > {{ $val->title }}</option>
                                                        @endforeach
                                                    @endif
                                                </select>
                                                <span class="kt-form__help error fuel_type"></span>
                                            </div>

                                            <div class="form-group col-sm-3">
                                                <label for="car_name">Car Variant <span class="required" style="color: red;">*</span></label>
                                                <select class="form-control" name="veriant" id="veriant"></select>
                                                <span class="kt-form__help error car_name"></span>
                                            </div>

                                            <div class="form-group col-md-3">
                                                <label class="control-label">Exterior Color <span class="required" style="color: red;">*</span></label>
                                                <select name="exterior_color" id="exterior_color" class="form-control exterior_color_select" style="width:100%" ></select>
                                                <span class="kt-form__help error exterior_color"></span>
                                            </div>
                                            
                                            <div class="form-group col-md-3">
                                                <label class="control-label">Interior Color</label>
                                                <select name="interior_color" id="interior_color" class="form-control interior_color_select" style="width:100%" ></select>                                           
                                                <span class="kt-form__help error interior_color"></span>
                                                <input type="hidden" name="product_id" id="product_id">
                                            </div>
                                            
                                            <div class="form-group col-md-3">
                                                <label for="discount_year">Discount Year</label>
                                                <select name="discount_year" id="discount_year" class="form-control">
                                                    <option value="">Select Year</option>
                                                    @php
                                                        $currentYear = date('Y');
                                                    @endphp
                                            
                                                    @for ($i = $currentYear; $i >= $currentYear - 50; $i--)
                                                        <option value="{{ $i }}">{{ $i }}</option>
                                                    @endfor
                                                </select>
                                                <span class="kt-form__help error discount_year"></span>
                                            </div>
                                        </div>    

                                        <div id="pictures" class="column half">
                                            <table>
                                                <thead>
                                                    <h3> Price Details</h3>
                                                </thead>

                                                <tbody>
                                                    <input type="hidden" name="rto_mas_company" id="rto_mas_company" value="">
                                                    <input type="hidden" name="rto_amount" id="rto_amount_from_pl" value="">
                                                    <input type="hidden" name="rto_amount_indevidual" id="rto_amount_indevidual" value="">
                                                    <input type="hidden" name="rto_mas_indevidual" id="rto_mas_indevidual" value="">
                                                    <input type="hidden" name="pl_rto_custom_handling_charges" id="pl_rto_custom_handling_charges" value="">
                                                    <input type="hidden" name="below_1_lac" id="below_1_lac" value="">
                                                    <input type="hidden" name="10_20_lac" id="10_20_lac" value="">
                                                    <input type="hidden" name="above_20_lac" id="above_20_lac" value="">
                                                    <input type="hidden" name="parsing_percentage" id="parsing_percentage" value="">
                                                    <input type="hidden" name="bh_parsing_validity" id="bh_parsing_validity" value="">
                                                    <input type="hidden" name="total_parsing_validity" id="total_parsing_validity" value="">
                                                    <input type="hidden" name="rto_master_custom_handling_charges" id="rto_master_custom_handling_charges" value="">
                                                    
                                                    <tr>
                                                        <td>
                                                            <label class="control-label text-center" style="background-color:#7a7c89;color: white !important; font-size:18px; border-radius:20px;">Pricelist ( WEF )<span class="required" style="color: red;">*</span></label>
                                                        </td>
                                                        <td>
                                                            <select name="pricelist_manager_id" id="pricelist_manager_id" class="form-control" onchange="Getpricelist(this);"></select>
                                                            <span class="kt-form__help error pricelist_manager_id"></span>
                                                        </td>                                
                                                    </tr>

                                                    <tr>
                                                        <td>
                                                            <label class="control-label text-center">Standard Ex-Showroom Price</label>
                                                        </td>
                                                        <td>
                                                            <input type="number"  name="ex_showroom_price" id="ex_showroom_price" class="form-control" placeholder="Enter Standard Ex-Showroom Price" value="" readonly>
                                                            <span class="kt-form__help error ex_showroom_price"></span>
                                                        </td>
                                                    </tr>

                                                    <tr>
                                                        <td>
                                                            <label class="control-label text-center">1% for TCS Tax</label>
                                                        </td>
                                                        <td>
                                                            <input type="number"  name="tcs_tax" id="tcs_tax" class="form-control" placeholder="Enter TCS Tax" value="{{ $taxThree->percentage ?? '' }}" readonly>
                                                            <span class="kt-form__help error tcs_tax"></span>
                                                        </td>
                                                    </tr> 
                                                    
                                                    <tr>
                                                        <td>
                                                            <label class="control-label text-center">Registration Tax</label>
                                                        </td>
                                                        <td>
                                                            <input type="number"  name="registration_tax" id="registration_tax" class="form-control" placeholder="Enter Registration Tax" value="{{ $taxOne->percentage ?? '' }}" readonly>
                                                            <span class="kt-form__help error registration_tax"></span>
                                                        </td>
                                                    </tr>

                                                    <tr>
                                                        <td>
                                                            <label class="control-label ml-1">RTO Custom Handling Charges</label>
                                                        </td>
                                                        <td>
                                                            <input type="number"  name="rto_custom_handling_charges" id="rto_custom_handling_charges" class="form-control" placeholder="Enter RTO Custom Handling Charges" value="{{ $data->rto_custom_handling_charges ?? '' }}" readonly>
                                                            <span class="kt-form__help error registration_tax"></span>
                                                        </td>
                                                    </tr>
                                                    
                                                    <tr>
                                                        <td>
                                                            <label class="control-label">RTO Type<span class="required" style="color: red;">*</span></label>
                                                        </td>
                                                        <td>
                                                            <select  name="customer_type_2nd" id="customer_type_2nd" class="form-control" placeholder="Enter RTO Type" disabled>
                                                                <option value="regular_rto">Regular RTO</option>
                                                                <option value="handicap">Handicap</option>
                                                                <option value="taxi">M-Drive(Taxi)</option>
                                                                <option value="electric">Electric</option>
                                                                <option value="crtem">Crtem</option>
                                                                <option value="bh_parsing">BH Passing</option>
                                                            </select>
                                                        </td>
                                                    </tr>
                                                    <tr> 
                                                        <td>
                                                            <label class="control-label">Municipal Tax Type</label>
                                                        </td>
                                                        <td>
                                                            <select name="municipal_tax_type" id="municipal_tax_type" class="form-control">
                                                                <option value="self">Self</option>
                                                                <option value="in_house">In-house</option>
                                                                <option value="not_applicable">Not Applicable</option>
                                                            </select>
                                                            <span class="kt-form__help error municipal_tax_type"></span>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td>
                                                            <label class="control-label text-center">Municipal Tax</label>
                                                        </td>
                                                        <td>
                                                            <input type="checkbox" name="municipal_tax_applicable" id="municipal_tax_applicable" value="1" checked style="display: none;">
                                                            <input type="number" name="municipal_tax_handling" id="municipal_tax_handling" class="form-control" placeholder="Enter Municipal Handling Tax Charges" style="display: none;">
                                                            <input type="number"  name="municipal_tax" id="municipal_tax" class="form-control" placeholder="Enter Municipal Tax" value="{{ $taxTwo->percentage ?? '' }}" readonly>
                                                            <span class="kt-form__help error municipal_tax"></span>
                
                                                        </td>
                                                    </tr>
                                                    <tr> 
                                                        <td>
                                                            <label class="control-label">Municipal Custom Handling Charges</label>
                                                        </td>
                                                        <td>
                                                            <input type="number"  name="municipal_custom_handling_charges" id="municipal_custom_handling_charges" class="form-control" placeholder="Enter Municipal Custom Handling Charges" value="">
                                                            <span class="kt-form__help error municipal_custom_handling_charges"></span>
                                                        </td>
                                                    </tr>

                                                    <tr>
                                                        <td>
                                                            <label class="control-label text-center">Insurance</label>
                                                        </td>
                                                        <td>
                                                            <input type="number" name="insurance" id="insurance" class="form-control" placeholder="Enter Insurance">
                                                            <span class="kt-form__help error insurance"></span>
                                                        </td>
                                                    </tr>

                                                    <tr>
                                                        <td>
                                                            <label class="control-label text-center">Insurance Company</label>
                                                        </td>
                                                        <td>
                                                            <select name="insurance_company_name" id="car_insurance_company_name" class="form-control" >
                                                                <option value="">Select Insurance Company</option>
                                                                @if(isset($insurance) && $insurance->isNotEmpty())
                                                                    @foreach($insurance AS $row)
                                                                        <option value="{{ $row->id }}">{{ $row->name }}</option>
                                                                    @endforeach
                                                                @endif
                                                            </select>
                                                            <!--<input type="text" name="insurance_company_name" id="car_insurance_company_name"class="form-control" placeholder="Enter Insurance Company Name">-->
                                                            <span class="kt-form__help error insurance_company_name"></span>
                                                        </td>
                                                    </tr>

                                                    <tr>
                                                        <td>
                                                            <label class="control-label text-center">Insurance Remark</label>
                                                        </td>
                                                        <td>
                                                            <textarea name="step3_remarks" class="form-control car-remarks" 
                                                                        placeholder="Enter Remarks"></textarea>
                                                        </td>
                                                    </tr>

                                                    <!--<tr>-->
                                                    <!--    <td>-->
                                                    <!--        <label class="control-label text-center">RSA MASTER</label>-->
                                                    <!--    </td>-->
                                                    <!--    <td>-->
                                                    <!--        <select name="rsa_master_obf" id="rsa_master_obf" class="form-control" >-->
                                                    <!--            <option value="">Select RSA</option>-->
                                                    <!--            @if(isset($rsa) && $rsa->isNotEmpty())-->
                                                    <!--                @foreach($rsa AS $row)-->
                                                    <!--                    <option value="{{ $row->id }}" data-rsa_master="{{ $row->amount }}">{{ $row->amount ??'' }} - {{ $row->name }}</option>-->
                                                    <!--                @endforeach-->
                                                    <!--            @endif-->
                                                    <!--        </select>-->
                                                    <!--        <span class="kt-form__help error rsa_master_obf"></span>-->
                                                    <!--    </td>-->
                                                    <!--</tr>-->
                                                    
                                                    <tr>
                                                        <td>
                                                            <label class="control-label text-center">RSA MASTER</label>
                                                        </td>
                                                        <td>
                                                            <select name="rsa_master_obf" id="rsa_master_obf" class="form-control" >
                                                                <option value="">Select RSA</option>
                                                            </select>
                                                            <span class="kt-form__help error rsa_master_obf"></span>
                                                        </td>
                                                    </tr>
                                                    
                                                    <tr>
                                                        <td>
                                                            <label class="control-label text-center">CCS MASTER</label>
                                                        </td>
                                                        <td>
                                                            <select name="ccs_master_obf" id="ccs_master_obf" class="form-control" >
                                                                <option value="">Select CCS</option>
                                                            </select>
                                                            <span class="kt-form__help error ccs_master_obf"></span>
                                                        </td>
                                                    </tr>

                                                    <tr>
                                                        <td>
                                                            <label class="control-label text-center">Extended Warranty</label>
                                                        </td>
                                                        <td>
                                                            <select name="extended_warranty" id="extended_warranty" class="form-control" >                                                
                                                                <option value="">Select Extended Warranty</option>
                                                            </select>
                                                            <span class="kt-form__help error extended_warranty"></span>
                                                        </td>
                                                    </tr>

                                                    <tr>
                                                        <td>
                                                            <label class="control-label text-center">My Convinience Program</label>
                                                        </td>
                                                        <td>
                                                            &nbsp;&nbsp;
                                                            <input type="checkbox" name="convinience_program">
                                                            <select name="convinience_program" id="convinience_program" class="form-control"></select>
                                                            <span class="kt-form__help error convinience_program"></span>
                                                        </td>
                                                    </tr>

                                                    <tr>
                                                        <td> 
                                                            <label class="control-label text-center">Fastag Brand Name</label>
                                                        </td>
                                                        <td>
                                                            <select name="fasttag_brand_name" id="fasttag_brand_name" class="form-control" >
                                                                <option value="">Select FastTag</option>
                                                                @if(isset($fasttag) && $fasttag->isNotEmpty())
                                                                    @foreach($fasttag AS $row)
                                                                        <option value="{{ $row->id }}" data-price="{{ $row->amount }}">{{ $row->brand_name ??'' }} - {{ $row->amount }}</option>
                                                                    @endforeach
                                                                @endif
                                                            </select>
                                                            <span class="kt-form__help error fasttag_brand_name"></span>
                                                        </td>
                                                    </tr>

                                                    <tr>
                                                        <td>
                                                            <label class="control-label text-center">Accessories</label>
                                                        </td>
                                                        <td>
                                                            &nbsp;&nbsp;&nbsp;<input type="checkbox" name="other_application" id="other_application" value="1" >Other Accessories
                                                            <select name="accessories[]" id="accessories" class="form-control accessories_select2" style="width:100%" multiple>
                                                                <option value="">Select Accessory</option>
                                                                @if(isset($accessory) && $accessory->isNotEmpty())
                                                                    <option value="">Select Accessory</option>
                                                                    @foreach($accessory AS $row)
                                                                        <option value="{{ $row->id }}" data-price="{{ $row->price }}">{{ $row->name ??'' }} - {{ $row->price }}</option>
                                                                    @endforeach
                                                                @endif
                                                            </select>
                                                            <span class="kt-form__help error accessories"></span>
                                                            <span style="color:white;">Accessories Total -</span>
                                                            <span id="total" style="color:white;">0</span>
                                                        </td>
                                                    </tr>

                                                    <tr id="otheraccessoriesid" class="hide">
                                                        <td>
                                                            <label class="control-label text-center">Other Accessories Item Name</label>
                                                        </td>
                                                        <td>
                                                            <input type="text"  name="other_accesssories_detail" id="other_accesssories_detail" class="form-control" placeholder="Enter Other Accessories Detail" value="" onkeypress="return /[a-zA-Z\s]/i.test(event.key)">
                                                        </td>
                                                    </tr>

                                                    <tr>
                                                        <td>
                                                            <label class="control-label text-center">Other Accessories Amount</label>
                                                        </td>
                                                        <td>
                                                            <input type="text"  name="other_accesssories_prise" oninput="myfunction();" id="other_accesssories_prise" class="form-control" placeholder="Enter Other Accessories Price" value="">
                                                        </td>
                                                    </tr>

                                                    <tr>
                                                        <td>
                                                            <label class="control-label text-center">Other Details 1</label>
                                                        </td>
                                                        <td>
                                                            <select name="other_details_1[]" id="other_details_1" class="form-control other_details_1_select2" style="width:100%" multiple>
                                                                <option value="">Please Select Data</option>
                                                                @if(isset($OtherOne) && $OtherOne->isNotEmpty())
                                                                    @foreach($OtherOne AS $row)
                                                                        <option value="{{ $row->id }}">{{ $row->name ??'' }}</option>
                                                                    @endforeach
                                                                @endif
                                                            </select>
                                                            <span class="kt-form__help error other_details_1"></span>
                                                        </td>
                                                    </tr>

                                                    <tr> 
                                                        <td>
                                                            <label class="control-label text-center">Other Details 2</label>
                                                        </td>
                                                        <td>
                                                            <select name="other_details_2[]" id="other_details_2" class="form-control other_details_2_select2" style="width:100%" multiple>
                                                            <option value="">Please Select Data</option>
                                                                @if(isset($OtherTwo) && $OtherTwo->isNotEmpty())
                                                                    @foreach($OtherTwo AS $row)
                                                                        <option value="{{ $row->id }}">{{ $row->name ??'' }}</option>
                                                                    @endforeach
                                                                @endif
                                                            </select>
                                                            <span class="kt-form__help error other_details_2"></span>
                                                        </td>
                                                    </tr>

                                                    <tr>
                                                        <td>
                                                            <label class="control-label text-center red_colour" style="font-size:22px;">On Road Price</label>
                                                        </td>
                                                        <td>
                                                            <input type="number" name="on_road_price" id="on_road_price" class="form-control" placeholder="Enter On Road Price" readonly>
                                                            <span class="kt-form__help error on_road_price"></span>
                                                        </td>
                                                    </tr> 

                                                    <tr>
                                                        <td>
                                                            <label class="control-label text-center">On Road Price (In Words)</label>
                                                        </td>
                                                        <td>
                                                            <input type="text" name="on_road_price_word" id="on_road_price_word" class="form-control" placeholder="Enter On Road Price In Words" readonly>
                                                            <span class="kt-form__help error on_road_price_word"></span>
                                                        </td>
                                                    </tr>
                                                    
                                                    <tr>
                                                        <td>- - - - - - - - - - - - - - - - - - - -</td>
                                                        <td>- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -</td>
                                                    </tr>

                                                    <tr style="display:none;">
                                                        <td>
                                                            <label class="control-label text-center">Extras</label>
                                                        </td>
                                                        <td>
                                                            <select name="priclist_detail[]" id="priclist_detail" class="form-control select_priclist" style="width:100%" multiple></select>
                                                            <span class="kt-form__help error priclist_detail"></span>
                                                            <span>Extras Total -</span>
                                                            <span id="extras_total">0</span>
                                                        </td>
                                                    </tr>

                                                    <tr>
                                                        <td>
                                                            <label class="control-label text-center">Exchange Car </label>
                                                        </td>
                                                        <td>
                                                            <select name="trade_car_value" id="trade_car_value" class="form-control">
                                                                <option value="">Select Exchange Car</option>
                                                                <option value="yes">Yes</option>
                                                                <option value="no">No</option>
                                                            </select>
                                                            <span class="kt-form__help error trade_car_value"></span>
                                                        </td>
                                                    </tr>

                                                    <tr id="tradecarname" style="display:none;">
                                                        <div class="form-group col-md-6" >
                                                            <td> 
                                                                <label class="control-label text-center">Trade In Car Name</label>
                                                            </td>
                                                            <td> 
                                                                <input type="text"  name="trade_car_name" id="trade_car_name" class="form-control" placeholder="Enter Trade In Car Name" value="">
                                                                <span class="kt-form__help error trade_car_name"></span>
                                                            </td>
                                                        </div>
                                                    </tr>

                                                    <tr>
                                                        <td>
                                                            <label class="control-label text-center">Lead Source</label>
                                                        </td>
                                                        <td>
                                                            <select name="lead" id="lead" class="form-control" >
                                                                <option value="">Select Lead Source</option>
                                                                @if(isset($lead) && $lead->isNotEmpty())
                                                                    @foreach($lead AS $row)
                                                                        <option value="{{ $row->id }}">{{ $row->name ??'' }}</option>
                                                                    @endforeach
                                                                @endif
                                                            </select>
                                                            <span class="kt-form__help error lead_source"></span>
                                                        </td>
                                                    </tr>

                                                    <tr>
                                                        <td> 
                                                            <label class="control-label text-center">Sub Lead Source</label>
                                                        </td>
                                                        <td>
                                                            <select name="sub_lead_id" id="sub_lead_id" class="form-control" ></select>
                                                            <span class="kt-form__help error sub_lead_id"></span>
                                                        </td>
                                                    </tr>

                                                    <tr>
                                                        <td>
                                                            <label class="control-label text-center">Mode of Payment</label>
                                                        </td>
                                                        <td>
                                                            <select name="mode_of_payment" id="mode_of_payment" class="form-control" >
                                                                <option value="">Select Mode Of Payment</option>
                                                                <option value="cash_on_delivery">Cash</option>
                                                                <option value="online">Online/Cradit Card/Debit Card/UPI</option>
                                                            </select>
                                                            <span class="kt-form__help error mode_of_payment"></span>
                                                        </td>
                                                    </tr>

                                                    <tr>
                                                        <td>
                                                            <label class="control-label text-center">Booking Amount</label>
                                                        </td>
                                                        <td>
                                                            <input type="text"  name="booking_amount" id="booking_amount" class="form-control" placeholder="Enter Booking Amount">
                                                            <span class="kt-form__help error booking_amount"></span>
                                                        </td>
                                                    </tr>

                                                    <tr>
                                                        <td>
                                                            <label class="control-label text-center">Tentative Delivery Date</label>
                                                        </td>
                                                        <td>
                                                            <input type="date" name="tentative_delivery_date" id="tentative_delivery_date" class="form-control">
                                                            <span class="kt-form__help error tentative_delivery_date"></span>
                                                        </td>
                                                    </tr>
                                                </tbody>
                                            </table>
                                        </div>

                                        <div id="pictures" class="column last">
                                            <h3> Offers & Discounts</h3>
                                            <div class="row">

                                                <div class="col-md-3"></div>
                                                
                                                <div class="form-group col-md-6">
                                                    <label for="offers">Select offers Type </label>
                                                    <select class="form-control" name="offer_type" id="offer_type">
                                                        <option value="">Select Offer Type</option>                      
                                                        <option value="KIN"> KIN Offers</option>
                                                        <option value="ShivamIB"> Shivam IB Offers</option> 
                                                    </select>      
                                                    <span class="kt-form__help error offer"></span>
                                                </div>
                                                
                                                <div class="col-md-3"></div>

                                                <div class="form-group col-md-6">
                                                    <label for="offers">Select KIN offers </label>
                                                    <select name="offer_kin[]" id="offer_kin" class="form-control total_amount_select2" style="width:100%" multiple>       
                                                        <span class="kt-form__help error offer"></span>
                                                    </select>
                                                </div>

                                                <div class="form-group col-md-6">
                                                    <label for="offers">Select Shivam IB offers </label>
                                                    <select name="offer_ib[]" id="offer_ib" class="form-control total_amount_ib_select2" style="width:100%" multiple>       
                                                        <span class="kt-form__help error offer"></span>
                                                    </select>
                                                </div>

                                            </div> 
                                            
                                            <div class="row">
                                                <h5>( To Select Multiple Offer Please Use Ctrl + Mouse Click or Shift + Mouse Click )</h5>
                                            </div>

                                            <table style="margin-left: 150px; margin-top: 50px;"> 
                                                
                                                <thead> 
                                                    <tr>
                                                        <th class="text-black" width="200">Offer Name </th>
                                                        <th class="text-black" width="200"> Amount</th>    
                                                    </tr>   
                                                </thead>

                                                <tbody> 
                                                    <tr> 
                                                        <td><input type="text" name="offers_kin_name" class="form-control"  id="offers_kin_name" readonly="readonly"> </td>
                                                        <td><input type="text" name="offers_kin_amount" class="form-control"  id="offers_kin_amount" readonly="readonly"> </td>
                                                    </tr>
                                                
                                                    <tr> 
                                                        <td><input type="text" name="offers_ib_name" class="form-control"  id="offers_ib_name" readonly="readonly"> </td>
                                                        <td><input type="text" name="offers_ib_amount" class="form-control"  id="offers_ib_amount" readonly="readonly"> </td>
                                                    </tr>

                                                    <tr> 
                                                        <td class="text-black" style="text-align:center!important;">Total Discount Amount </td>
                                                        <td> <input type="text" name="offer_amount" class="form-control"  id="offers_amt" readonly="readonly">   </td>
                                                    </tr>
                                                    
                                                    <tr>
                                                        <td></td>
                                                        <td style="color:black;"><b><i class="fa-solid fa-arrow-up"></i> Click Here For Calculate Tax</b></td>
                                                    </tr>

                                                    <tr>
                                                        <td style="padding-top:30px;"></td>
                                                    </tr>

                                                    <tr>
                                                        <td class="control-label red_colour" style="text-align:center!important;">On Road Price </td>
                                                        <td> <input type="text" name="offer_amount" class="form-control"  id="offer_amt" readonly="readonly">   </td>
                                                    </tr>

                                                    <tr> 
                                                        <td class="text-black" style="text-align:center!important;">Total Discount Amount </td>
                                                        <td> <input type="text" name="offe_amount" class="form-control"  id="offe_amt" readonly="readonly">   </td>
                                                    </tr>

                                                    <tr> 
                                                        <td class="text-black" style="text-align:center!important;"> Deal price (With Offer)</td> 
                                                        <td> <input type="text" name="deal_price" class="form-control"  id="deal_price" readonly="readonly">  </td>
                                                    </tr>

                                                    <tr>
                                                        <td class="control-label text-white" style="background-color: #7a7c89;border-radius: 20px;text-align:center!important;">Enter Cash Discount Amount</td>
                                                        <td><input type="text" name="way_off" class="form-control"  id="way_off" value=""></td>
                                                    </tr>
                                                    
                                                    <tr>
                                                        <td colspan="2" style="color:black;"><b><small class="text-danger d-none" id="kec_limit_error" style="font-size:15px;!important">Maximum allowed discount is â‚¹0 </small></b></td>
                                                    </tr>
                                                    
                                                    <tr>
                                                        <td style="padding-top:10px;"></td>
                                                    </tr>
                                                    
                                                    <tr>
                                                        <td class="control-label text-white" style="background-color: #7a7c89;border-radius: 20px;text-align:center!important;">Need More Discount</td>
                                                        <td>
                                                            <select class="form-control" name="discount_flag" id="discount_flag">
                                                                <option value="">Select Authorise Person</option>                      
                                                                <option value="4">General Manager</option>
                                                            </select> 
                                                        </td>
                                                    </tr>

                                                    <tr>
                                                        <td class="control-label text-black" style="text-align:center!important;">FOC Accessories</td>
                                                        <td>
                                                            <input type="text" name="foc_accessories" class="form-control"  id="foc_accessories" value="">
                                                        </td>
                                                    </tr>

                                                    <tr>
                                                        <td class="control-label red_colour" style="text-size:12px;text-align:center!important;">Total Amount Receivable</td>
                                                        <td>
                                                            <input type="text" name="final_on_road_price_after_way_off" class="form-control" id="cash_discount" value="" readonly="readonly">
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td class="control-label text-black" style="text-align:center!important;">Discount Remarks</td>
                                                        <td>
                                                            <textarea  name="step1_remarks" id="step1_remarks" class="form-control" placeholder="Enter Remarks" style="text-transform:uppercase" rows="3" style="min-height:90px;"></textarea>
                                                            <span class="kt-form__help error step1_remarks"></span>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td class="control-label text-black" style="text-align:center!important;">Upload Offer & Discount Document</td>
                                                        <td>
                                                            <div class="form-group">
                                                                <span class="required" style="color: red;">*</span>
                                                                <input type="file" name="offer_image[]" id="offer_image" onchange="previewMultiple(event,'offer_image_multi','offer_image')" class="form-control dropify" data-default-file="" data-max-file-size-preview="2M" multiple>
                                                                <span class="kt-form__help error offer_image"></span>
                                                            </div>
                                                            <div class="uploaded_images">
                                                                <div class="row">
                                                                    <h5>Uploaded Image</h5>
                                                                    <div id="offer_image_multi" class="form-group col-md-2"></div>
                                                                </div>
                                                            </div>
                                                        </td>
                                                    </tr>
                                                </tbody>
                                            </table>
                                        </div>
                                    </div>
                                </div>
                                <button class="btn  btn-outline-secondary prevBtn btn-sm pull-left" type="button">Previous</button>
                                <button class="btn waves-effect waves-light btn-rounded btn-outline-secondary nextBtn btn-sm pull-right next_two" type="button">Next</button>
                                <button class="btn btn-outline-secondary btn-sm pull-right submit_once" type="submit">Save as Draft</button>
                            </div>

                            
                            <div class="row setup-content" id="step-3">
                                <div class="col-lg-12 ">
                                    <div class="col-md-12">
                                        <h5 class="text-white"> Finance Details</h5>
                                        
                                        <div class="row">
                                            <br/>

                                            <div class="form-group col-md-3">
                                                <label class="control-label">Finance Required</label>
                                                <label class="checkbox-inline">
                                                <input type="radio" value="yes" name="finance_required" class="chk_ncb" checked> Yes</label>
                                                <label class="checkbox-inline">
                                                <input type="radio" value="no" name="finance_required" class="chk_ncb"> No</label>
                                                <span class="kt-form__help error finance_required"></span>
                                            </div>
                                        </div>

                                        <button class="btn  btn-outline-secondary prevBtn btn-sm pull-left" type="button">Previous</button>
                                        <button class="btn btn-outline-secondary btn-sm pull-right submit_once" type="submit">Save as Draft</button>
                                        <button class="btn btn-outline-secondary nextBtn btn-lg pull-right submit_once" type="submit">Submit</button>
                                    </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>
    <script src="https://code.jquery.com/ui/1.13.2/jquery-ui.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/flatpickr"></script>

    <script>
        

        $(document).ready(function () {
            
            $('#branch').on('change', function () {
                // Remove selected attribute from all options
                $('#branch option').removeAttr('selected');
        
                // Add selected attribute to the chosen one
                $('#branch option:selected').attr('selected', 'selected');
            });
            
            $('#aadhar_pan_link').on('change', function() {
                if ($(this).val() === 'no') {
                    alert('TCS Tax Will Apply 5% When Aadhar & Pan Not Linked...');
                }
            });
            
            flatpickr("#booking_date", {
                enableTime: true,
                time_24hr: true,
                enableSeconds: true,
                dateFormat: "d-m-Y H:i:S",
                defaultDate: new Date(),
            });
            
            let rsaData = @json($rsa);

            // When car model changes, populate RSA dropdown
            $("#pricelist_manager_id").change(function() {
                let carModel = $("#car_name").val();
                let c_html = '<option value="">Select RSA</option>';
                let e_html = '<option value="">Select CCS</option>';
        
                $.each(rsaData, function(key, val) {
                    if (val.car_model === carModel) {
                        c_html += '<option value="' + val.id + '" data-rsa_amount="' + val.amount + '">' + val.amount + ' - ' + val.name + '</option>';
                    }
                });
        
                $("#rsa_master_obf").html(c_html);
                
                 $.each(ccsData, function(css_key, css_val) {
                    if (css_val.car_model === carModel) {
                        e_html += '<option value="' + css_val.id + '" data-ccs_amount="' + css_val.amount + '">' + css_val.amount + ' - ' + css_val.name + '</option>';
                    }
                });
                
                $("#ccs_master_obf").html(e_html);
            });
            
            let ccsData = @json($ccs);
            
            // Set initial value from #customer_type to #customer_type_2nd
            $('#customer_type_2nd').val($('#customer_type').val());
    
            // Optional: Sync on change if not disabled
            $('#customer_type').on('change', function () {
                $('#customer_type_2nd').val($(this).val());
            });
            
            $('#ship_to_required').change(function () {
                if ($(this).val() === 'yes') {
                    $('#ship_to_customer_name').show();
                    $('#ship_to_address').show();
                    $('#ship_to_state_id').show();
                    $('#ship_to_district_id').show();
                    $('#ship_to_city_id').show(); 
                } else {
                    $('#ship_to_customer_name').hide();
                    $('#ship_to_address').hide();
                    $('#ship_to_state_id').hide();
                    $('#ship_to_district_id').hide();
                    $('#ship_to_city_id').hide();
                }
            });
            
            $('#handicap_doc_section').hide();

            // Change event listener
            $('#handicap').change(function () {
                if ($(this).val() === 'yes') {
                    $('#handicap_doc_section').show();
                } else {
                    $('#handicap_doc_section').hide();
                }
            });
            
            // function getTodayDate() {
            //     const today = new Date();
            //     const yyyy = today.getFullYear();
            //     const mm = String(today.getMonth() + 1).padStart(2, '0');
            //     const dd = String(today.getDate()).padStart(2, '0');
            //     return `${yyyy}-${mm}-${dd}`;
            // }

            // // Set only min attribute (no default value)
            // window.onload = function () {
            //     const today = getTodayDate();
            //     document.getElementById('issue_date').min = today;
            //     document.getElementById('risk_start_date').min = today;
            //     document.getElementById('risk_end_date').min = today;
            // };

            // Function to toggle the #gst_hs div
            function toggleGstHs() {
                if ($('#gst_required').val() === 'yes') {
                    $('#gst_hs').show();
                } else {
                    $('#gst_hs').hide();
                }
            }

            // Run on page load
            toggleGstHs();

            // Run when #gst_required value changes
            $('#gst_required').on('change', function () {
                toggleGstHs();
            });
            
            // Function to toggle the #aadhar_pan_div div
            function toggleLinkedDiv() {
                if ($('#aadhar_pan_link').val() === 'yes') {
                    $('#aadhar_pan_div').show();
                } else {
                    $('#aadhar_pan_div').hide();
                }
            }

            // Run on page load
            toggleLinkedDiv();
            

            // Run when #gst_required value changes
            $('#aadhar_pan_link').on('change', function () {
                toggleLinkedDiv();
            });
            
            $('#nominee_dob').on('change',function(){
                var date = $('#nominee_dob').datepicker('getDate');
                if (!date) {
                    $('#nominee_age').val('');
                    return;
                }
        
                var dob = new Date(date);
                var today = new Date();
                var age = Math.floor((today - dob) / (365.25 * 24 * 60 * 60 * 1000));
                
                if(age >= 18){
                    $('#nominee_age').val(age);
                }else{
                    $('#nominee_age').val('');
                    $('#nominee_dob').val('');
                    alert("nominee person age must be above 18 years old.");
                }
            });

        });

        window.tex_master_gst = 0;

        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();

        $( function() {
            $( "#dob" ).datepicker({ dateFormat: 'dd-mm-yy' });
            $( "#nominee_dob" ).datepicker({ dateFormat: 'dd-mm-yy' });
        });



    

    $('.required').show();

    $('#second_new').css('pointer-events','none');

    $('#thrid_new').css('pointer-events','none');

    $(".next_one").removeClass('nextBtn');

    $('.next_one').on('click', function(){
        var contact_number = $("#contact_number").val();
        var pan_number = $("#pan_number").val();
        var aadhar_number = $("#aadhar_number").val();
        var customer_type = $("#customer_type").val();
        var branch = $("#branch").val();
        var customer_name = $("#customer_name").val();
        var einvoapp = $("#einvoapp").val();
        var gst_required = $("#gst_required").val();
    
        var gst = $("#gst").val();

        var address_1 = $("#address_1").val();

        var pancard = $('#pan_image').val();

        var aadhar = $('#adhar_image').val();
        
        var aadhar_pan_link = $('#aadhar_pan_link').val();

        var aadhar_pan = $('#aadhar_pan_image').val();
        
        var customer_type_new = $('#customer_type_new').val();

        

        var data = {};

        data.contact_number = contact_number;
        
        data.pan_number = pan_number;

        data.aadhar_number = aadhar_number;

        data.customer_type = customer_type;

        data.branch = branch;

        data.customer_name = customer_name;

        data.einvoapp = einvoapp;
        
        data.gst_required = gst_required;

        data.gst = gst;

        data.address_1 = address_1;

        data.pancard = pancard;

        data.aadhar = aadhar;
    
        data.aadhar_pan_link = aadhar_pan_link;

        data.aadhar_pan = aadhar_pan;
        
        data.customer_type_new = customer_type_new;

        var data = JSON.stringify(data);

        

        $.ajax({

            url  : "{{ url('obf/obf_validation') }}",

            type : "POST",

            dataType : 'json',

            data : { "_token": "{{ csrf_token() }}" , data : data },

            success:function(response){

                if(response.status == 200){                    

                    $('.second_new').attr('disabled',false);

                    // $(".second_new").trigger('click');

                    $("#second_new").trigger('click');



                    $('#second_new').css('pointer-events','');

                    $('#thrid_new').css('pointer-events','');

                    $('#forth_new').css('pointer-events','');

                    $('#fifth_new').css('pointer-events','');

                    $('#six_new').css('pointer-events','');

                }

                else{

                    toastr.error(response.message);

                }

            }

        });

    });



    $(".next_two").removeClass('nextBtn');

    $('.next_two').on('click', function(e){


        var discount_year = $('#discount_year').val();

        if (discount_year === "" || discount_year === null || discount_year === undefined) {
            e.preventDefault();
            toastr.error('Discount year not selected. Please select one first.');
            return false;
        }


        var data = {};

        data.sales_person_name = $("#sales_person_name").val();

        data.car_name = $("#car_name").val();

        data.veriant = $("#veriant").val();

        data.exterior_color = $("#exterior_color").val();

        data.interior_color = $("#interior_color").val();

        data.pricelist_manager_id = $("#pricelist_manager_id").val();
        
        data.step1_remarks = $("#step1_remarks").val();

        var data = JSON.stringify(data);


        $.ajax({

            url  : "{{ url('obf/obf_validation_step_two') }}",

            type : "POST",

            dataType : 'json',

            data : { "_token": "{{ csrf_token() }}" , data : data },

            success:function(response){

                if(response.status == 200){

                    if($('.next_two').text() == 'submit'){

                       var x = document.getElementsByClassName("form_class");

                        x[0].submit();

                    }

                    

                    $('#thrid_new').attr('disabled',false);

                    $("#thrid_new").trigger('click');



                    $('#second_new').css('pointer-events','');

                    $('#thrid_new').css('pointer-events','');

                    $('#forth_new').css('pointer-events','');

                    $('#fifth_new').css('pointer-events','');

                    $('#six_new').css('pointer-events','');

                }

                else{

                    toastr.error(response.message);

                }

            }

        });

    });
  



    $(document).ready(function(){

        $('#model').on('change' ,function(){

            var is_applicable_for_mcp = $('#model :selected').data("is_applicable_for_mcp");

            if(is_applicable_for_mcp == 'yes'){

                $('.convinience_program_div').show();

            }else{

                $('.convinience_program_div').hide();

            }

        });

        

        $('#convinience_program').on('change' ,function(){

            var convinience_program = $('#convinience_program :selected').val();

            if(convinience_program == 'mcp_plus'){

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

                $("#extended_warranty").val([]);

            }else{

                $('#extended_warranty').removeAttr('disabled',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(){

        $('.accessories_select2').select2({

            placeholder:"Select Accessory",

        })



        $('.select_priclist').select2({

            placeholder:"Select Pricelist Detail",

        })



        $('.other_details_1_select2').select2({

            placeholder:"Other Details 1",

        })



        $('.other_details_2_select2').select2({

            placeholder:"Other Details 2",

        })

        

        $('.total_amount_select2').select2({

            placeholder:"Total Amount",

        })
        
        
        $('.state_id_select2').select2({

            placeholder:"Select State",

        })
        
        $('.district_id_select2').select2({
	
        	placeholder:"Select District",
        
        })
        $('.city_id_select2').select2({
        	
        	placeholder:"Select City",
        
        })
        $('.ship_to_state_id_select2').select2({
        	
        	placeholder:"Select Ship to State",
        
        })
        $('.ship_to_district_id_select2').select2({
        	
        	placeholder:"Select Ship to District",
        
        })
        $('.ship_to_city_id_select2').select2({
        	
        	placeholder:"Select Ship to City",
        
        })
        $('.rto_passing_id_select2').select2({
        	
        	placeholder:"Select RTO Passing Code",
        
        })
    }); 

     

    $('#accessories').on('change' , function(){

        var sum = 0;

           

        var otheracc =  parseInt($('#other_accesssories_prise').val());

        if(isNaN(otheracc))

        {

           $('#accessories :selected').each(function() 

           {

            sum  += parseInt($(this).data("price"))|| 0;

           })

          $('#total').html(sum);



                   

        }

        else

        {

            $('#accessories :selected').each(function() {

            sum  += parseInt($(this).data("price"))|| 0;

            })

            sum = sum+otheracc;

            $('#total').html(sum);



        }



    });

    



     $('#priclist_detail').on('change' , function(){

        var sum = 0;

        $('#priclist_detail :selected').each(function() {

            sum  += parseInt($(this).data("value_field"));

        })

       // console.log(sum);

        var otheracc =  parseInt($('#other_accesssories_prise').val());

     

       sum = sum+otheracc;

        $('#extras_total').html(sum);

    });

    

      function myfunction()

    {

        //  var sum = 0;

        // $('#accessories :selected').each(function() {

        //     sum  += parseInt($(this).data("price"));

        // })

        // var otheracc =  parseInt($('#other_accesssories_prise').val());

     

    //   sum = sum+otheracc;

        // $('#total').html(sum);
        
        var sum = 0;
        
        var otheracc =  parseInt($('#other_accesssories_prise').val());
        if(isNaN(otheracc))
        {
            $('#accessories :selected').each(function(){
                sum  += parseInt($(this).data("price"))|| 0;
            })
            $('#total').html(sum);
        } else {
            $('#accessories :selected').each(function() {
                sum  += parseInt($(this).data("price"))|| 0;
            })
            sum = sum+otheracc;
            $('#total').html(sum);
        }
        
        new_clalculate();
    }

</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);

                        });

                    }

                }

            });

        });

    });



    $('.documents_upload_class').hide();

    $(document).on('click','.chk_ncb',function(){

        var value=$(this).val();

        html='';

        if(value == 'yes'){

            html+='<div class="form-group col-md-3">';

            html+='<label class="control-label">Date of Insurance</label>';

            html+='<input type="date"  name="date_of_insurance" id="date_of_insurance" class="form-control" placeholder="Date Of Insurance">';

            html+='<span class="kt-form__help error date_of_insurance"></span>';

            html+='</div>';

            html+='<div class="form-group col-md-3">';

            html+='<label class="control-label">Time of Insurance</label>';

            html+='<select name="time_of_insurance" id="time_of_insurance" class="form-control">';

            html+='<option value="" selected disabled>Please Select Year</option>';

            html+='<option value="1">1 Year</option>';

            html+='<option value="3">3 Year</option>';

            html+='</select>';

            html+='<span class="kt-form__help error time_of_insurance"></span>';

            html+='</div>';

            html+='<div class="form-group col-md-3">';

            html+='<input type="text" name="last_time_of_insurance" id="last_time_of_insurance" hidden>';

            html+='<label class="control-label">Last Date of Insurance</label>';

            html+='<input type="text"  name="last_time_of_insurance1" id="last_time_of_insurance1" class="form-control" placeholder="last time of insurance" disabled>';

            html+='<span class="kt-form__help error last_time_of_insurance1"></span>';

            html+='</div>';

            html+='<div class="form-group col-md-3">';

            html+='<label class="control-label">Company Name</label>';

            html+='<input type="text"  name="insurance_company_name" id="insurance_company_name" class="form-control" placeholder="Enter Company Name">';

            html+='<span class="kt-form__help error insurance_company_name"></span>';

            html+='</div>';

            html+='<div class="form-group col-md-3">';

            html+='<label class="control-label">Amount</label>';

            html+='<input type="number"  name="ncb_amount" id="ncb_amount" class="form-control" placeholder="Enter NCB Amount">';

            html+='<span class="kt-form__help error ncb_amount"></span>';

            html+='</div>';

            html+='<div class="form-group col-md-3">';

            html+='<label class="control-label">Policy Number</label>';

            html+='<input type="text"  name="policy_number" id="policy_number" class="form-control" placeholder="Enter Policy Number">';

            html+='<span class="kt-form__help error policy_number"></span>';

            html+='</div>';

            

            $('#ncb_data').html(html);

            $('.documents_upload_class').show();





        }

        else{

            $('#ncb_data').html(html);

            $('.documents_upload_class').hide();

        }

    })

    

   

   $(document).ready(function() {

    $('#time_of_insurance').change(function() {

        var start_date = document.getElementById("date_of_insurance").value;

        var currentDate = moment().format('DD-MM-YYYY');



        var date1Year = moment(start_date, "YYYY-MM-DD").add(1, 'year').subtract(1, 'day').format('DD-MM-YYYY');

        var date3Year = moment(start_date, "YYYY-MM-DD").add(3, 'year').subtract(1, 'day').format('DD-MM-YYYY');



        $("#last_time_of_insurance1").val(date1Year);

        $("#last_time_of_insurance3").val(date3Year);

    });

});





    $(document).on('change','#rto_type',function(){

        var value=$(this).val();

        if(value == 'in_house'){

        var html = '' + 

'<div class="form-group col-md-3">' + 

'                                            <label class="control-label">Registration Date</label>' + 

'                                            <input type="date"  name="registration_date" id="registration_date" class="form-control">' + 

'                                            <span class="kt-form__help error registration_date"></span>' + 

'                                        </div>' + 

'                                        ' + 

'                                        <div class="form-group col-md-3">' + 

'                                            <label class="control-label">Application Number</label>' + 

'                                            <input type="text"  name="application_number" id="application_number" class="form-control" placeholder="Application Number">' + 

'                                            <span class="kt-form__help error application_number"></span>' + 

'                                        </div>' + 

'                                        ' + 

'                                        <div class="form-group col-md-3">' + 

'                                            <label class="control-label">Temporary Number</label>' + 

'                                            <input type="text"  name="temporary_number" id="temporary_number" class="form-control" placeholder="Temporary Number" >' + 

'                                            <span class="kt-form__help error temporary_number"></span>' + 

'                                        </div>' + 

'                                        ' + 

'                                        <div class="form-group col-md-3">' + 

'                                            <label class="control-label">Final amount</label>' + 

'                                            <input type="text"  name="final_amount" id="final_amount" class="form-control" placeholder="Final Amount">' + 

'                                            <span class="kt-form__help error final_amount"></span>' + 

'                                        </div>' + 

'                                        ' + 

'                                        <div class="form-group col-md-3">' + 

'                                            <label class="control-label">Vehicle Number</label>' + 

'                                            <input type="text"  name="vehicle_number" id="vehicle_number" class="form-control" placeholder="Add Vehicle Number">' + 

'                                            <span class="kt-form__help error vehicle_number"></span>' + 

'                                        </div>' + 

'';

    

    }else{

        html='';

    }

    $('#rto_details').html(html);

})



    function Getpricelist(event){

        var id = event.value;

        var URL='{{route('obf.getpricelist')}}';

        var customer_type = $('#customer_type').val();

        var is_csd = $('#is_csd').val();

         

             var rtoURL = '{{route('obf.getpricelist')}}'

         $.ajax({

            url: rtoURL,

            type: 'post',

            data: {customer_type:customer_type,_token: "{{ csrf_token() }}",is_csd:is_csd,id:id},

            cache: false,

            success: function(data) {
                
                $('#rto_mas_indevidual').val(data.rto_tax_individual);
    
                $('#rto_mas_company').val(data.rto_tax_company);
    
                $('#rto_amount_from_pl').val(data.totalcharges);
                
                if(customer_type == 'crtem'){
                    $('#rto_custom_handling_charges').val(0);
                } else{
                    $('#rto_custom_handling_charges').val(data.rto_custome_handling_charges);
                }
    
                $('#rto_amount_indevidual').val(data.totali_individual_charges);

                $('#below_1_lac').val(data.below_1_lac);
                
                $('#10_20_lac').val(data['10_20_lac']);
                
                $('#above_20_lac').val(data.above_20_lac);
                
                $('#parsing_percentage').val(data.parsing_percentage);
                
                $('#bh_parsing_validity').val(data.bh_parsing_validity);
                
                $('#total_parsing_validity').val(data.total_parsing_validity);
                
                $('#rto_master_custom_handling_charges').val(data.rto_master_custom_handling_charges);

            }

         });

            



            

        $.ajax({

            url: URL,

            type: 'post',

            data: {id:id,_token: "{{ csrf_token() }}"},

            cache: false,

            success: function(data) {

             
             

            

                $('#ex_showroom_price').val(data.ex_showroom_price);



                var customer_type = $('#customer_type').val();



                //console.log(customer_type);



                var extended_warranty = parseInt($('option:selected', '#extended_warranty').attr('data-amount'));

                var sum = 0;

                $('#accessories option:selected').each(function(){

                    sum  += parseInt($(this).attr("data-price"));

                });



                var on_road_price = 0;

            /*    if(customer_type == 'corporate'){

                    $('#registration_tax').val(data.registration_corporate_charges);                        



                    on_road_price = parseInt(sum + extended_warranty + parseInt(data.on_road_corporate_charges));

                }else if(customer_type == 'individual' || customer_type == 'govt' || customer_type == ''){

                    $('#registration_tax').val(data.registration_individual_charges);                     

                    on_road_price = parseInt(sum + extended_warranty + parseInt(data.on_road_individual_charges)); 

                }

*/

                if(isNaN(on_road_price)) {

                    on_road_price = 0;

                }                        

                $('#on_road_price').val(on_road_price);



                var word_price = inWords(on_road_price);

                $('#on_road_price_word').val(word_price);
                
                var is_csd = $('#is_csd').val();
                if(is_csd === 'No'){
                    var aadhar_linked = $('#aadhar_pan_link').val();
                    var customer_type_new = $('#customer_type_new').val();
                    
                    if(aadhar_linked === 'yes'){
                        $('#tcs_tax').val(data.tcs);        
                    } else if(aadhar_linked === 'no' && customer_type_new == '4'){
                        var tcs= ((data.ex_showroom_price * 1) / 100);    
                        $("#tcs_tax").val(Math.round(tcs));
                    }else {
                        var tcs= ((data.ex_showroom_price * 5) / 100);    
                        $("#tcs_tax").val(Math.round(tcs));
                    }    
                } else {
                    $("#tcs_tax").val(0);
                }
                
                var municipal_tax_type = $('#municipal_tax_type').val();
                if(municipal_tax_type == 'in_house'){
                   $('#municipal_tax').val(Math.round(data.statutory_charges));
                }else{
                   $('#municipal_tax').val(0);
                }     

                $('#insurance').val(data.insurance);

                $('#basic').val(data.basic);

                $('#gst_amount').val(data.gst_amount);

                $('#cess_amount').val(data.cess_amount);

                // $('#rsa_master_obf').val(data.rsa_master);
                
                $('#fasttag_brand_name').val(data.fasttag);
                
                $('#convinience_program').val(data.convinience_program);
                
                $('#extended_warranty').val(data.extended_warranty);
                
                $('#rto_amount').val(data.totalcharges);
                           

         

     

                 if(data.detail_value != ''){

                        var e_row = jQuery.parseJSON(data.detail_value);

                        var html = '';

                        if(e_row != null && e_row.length > 0){

                            jQuery.each(e_row, function(key, val){      

                                var selected = 'selected';                         

                                html +='<option value="'+val.detail_field+'__'+val.value_field+'" data-value_field="'+val.value_field+'" '+selected+'>'+val.detail_field+' - '+val.value_field+'</option>';

                            });

                            jQuery("#priclist_detail").empty();

                            jQuery("#priclist_detail").html(html);

                        }

                    }



                    if(data.other_details_1 != null){

                        var other_details_1 = data.other_details_1.split(" ,");

                        $('#other_details_1').val(other_details_1);

                        $('#other_details_1').trigger('change');     

                    }



                    if(data.other_details_2 != null){

                        var other_details_2 = data.other_details_2.split(" ,");

                        $('#other_details_2').val(other_details_2);

                        $('#other_details_2').trigger('change'); 

                    }





                

                /*if(data.accessories_kit != ''){

                    data.accessories_kit = data.accessories_kit.split(' ,');    

                    if(data.accessories_kit.length > 0){

                        console.log(data.accessories_kit);

                        $('#accessories').val(data.accessories_kit).trigger('change');

                    }

                }*/                    

            },

            error: function(data) {

                

            }

        });

        

    const myTimeout = setTimeout(myGreeting, 1500);



function myGreeting() {

        var basic = $('#basic').val();

        var rto_amount = parseFloat($('#rto_amount_from_pl').val());

        var rto_amount_indevidual = $('#rto_amount_indevidual').val();
        
        var rto_mas_indevidual = $('#rto_mas_indevidual').val();

        var rto_mas_company = $('#rto_mas_company').val();

        var customer_type_new = $('#customer_type_new').val();
        
        var rto_custom_handling_charges = $('#rto_custom_handling_charges').val();
        
        var below_10_lac = parseFloat($('#below_1_lac').val());
                
        var ten_20_lac = parseFloat($('#10_20_lac').val());
        
        var above_20_lac = parseFloat($('#above_20_lac').val());
        
        var parsing_percentage = parseFloat($('#parsing_percentage').val());
        
        var bh_parsing_validity = $('#bh_parsing_validity').val();
        
        var total_parsing_validity = $('#total_parsing_validity').val();
        
        var rto_type = $('#customer_type').val();
        
        var rto_master_custom_handling_charges = $('#rto_master_custom_handling_charges').val();

      if(basic != 0)

        { 
            if(rto_type == 'bh_parsing'){
                if (basic < 1000000) {
                    let validity_ratio = bh_parsing_validity / total_parsing_validity;
                    let rto_tax_percentage = (below_10_lac * parsing_percentage * validity_ratio);
                    let rto_tax_multiply = basic * (rto_tax_percentage / 100);
                    let registration_tax = rto_tax_multiply + rto_amount;
                    
                    if(isNaN(registration_tax)) {
                        registration_tax = 0;
                    }
                    
                    $('#registration_tax').val(Math.round(registration_tax));
                } else if (basic >= 1000000 && basic <= 2000000) {
                    let validity_ratio = bh_parsing_validity / total_parsing_validity;
                    let rto_tax_percentage = (ten_20_lac * parsing_percentage * validity_ratio);
                    let rto_tax_multiply = basic * (rto_tax_percentage / 100);
                    let registration_tax = rto_tax_multiply + rto_amount;
                    
                    if(isNaN(registration_tax)) {
                        registration_tax = 0;
                    }
                    
                    $('#registration_tax').val(Math.round(registration_tax));
                } else if (basic > 2000000) {
                    let validity_ratio = bh_parsing_validity / total_parsing_validity;
                    let rto_tax_percentage = (above_20_lac * parsing_percentage * validity_ratio);
                    let rto_tax_multiply = basic * (rto_tax_percentage / 100);
                    let registration_tax = rto_tax_multiply + rto_amount;
                    
                    if(isNaN(registration_tax)) {
                        registration_tax = 0;
                    }
                    
                    $('#registration_tax').val(Math.round(registration_tax));
                }
                $('#pl_rto_custom_handling_charges').val(rto_custom_handling_charges);
            }else if(rto_type == 'crtem'){
                    let registration_tax = parseInt(rto_master_custom_handling_charges);
        
                    if(isNaN(registration_tax)) {
                        registration_tax = 0;
                    }
                    
                    $('#registration_tax').val(Math.round(registration_tax));  
                    $('#pl_rto_custom_handling_charges').val(rto_custom_handling_charges);
            } else {
                if(customer_type_new == 1 || customer_type_new == 2){
                    registration_tax = ((basic)/100*rto_mas_indevidual)+parseInt(rto_amount);
                    if(isNaN(registration_tax)) {
                        registration_tax = 0;
                    }
                    $('#registration_tax').val(Math.round(registration_tax));
                } else {
                    registration_tax = ((basic)/100*rto_mas_company)+parseInt(rto_amount);
                    if(isNaN(registration_tax)) {
                        registration_tax = 0;
                    }
                    $('#registration_tax').val(Math.round(registration_tax));
                }  
                $('#pl_rto_custom_handling_charges').val(rto_custom_handling_charges);
            }    

        } 

        else {

             $('#registration_tax').val('0');

        }

        new_clalculate();

     

}    

   

    }



    $('#pan_number,#aadhar_number').on('input', function() {

        $(this).val($(this).val().replace(/[^a-z0-9]/gi, ''));

        $(this).val($(this).val().toUpperCase());

    });

    



   



    function product_data_get(){

         var model = jQuery("#model").val();

         var veriant = jQuery("#veriant").val();

         var exterior_color = jQuery("#exterior_color").val();

         var interior_color = jQuery("#interior_color").val();



         $.ajax({

            url : "{{ url('obf/product_data_get/') }}",

            data : {"_token": "{{ csrf_token() }}",'model' : model,'veriant':veriant,'exterior_color' : exterior_color,'interior_color':interior_color},

            type : 'post',

            dataType : 'json',

            success : function(resp){                

                var html = ihtml = '';

                var ex_showroom_price = resp.data.ex_showroom_price;

                $('#ex_showroom_price').val(ex_showroom_price);

            }

        });

        

    }



    product_data_get();







    function car_name_new(id,option_check,new_mcp,fuel){

        var is_csd = $('#is_csd').val();

          $.ajax({

              url : "{{ url('obf/car_drop_down_get/') }}",

              data : {'id' : id,'option_check': option_check,'new_mcp':new_mcp,'fuel':fuel,is_csd:is_csd == 'Yes'?1:0},

              type : 'get',

              dataType : 'json',

                // console.log(option_check);

              success : function(resp){  

                  var html = c_html = '';

                  var e_row = resp.data.Carvarient_arr;

                   var c_row = resp.data.Mcp_arr;

                  html = '';



                  html +='<option value="">Select Veriant</option>';

                  jQuery.each(e_row, function(key, val){ 

                      html += '<option value="'+val.id+'">'+val.name+'</option>';

                  });



                  c_html +='<option value="">Select Convinience Program</option>';

                    jQuery.each(c_row, function(key, val){

                        c_html +='<option value="'+val.id+'" data-convinience_amount="'+val.amount+'">'+val.name+'</option>';

                    });





                   var fule_html = '';

                   if(html == '<option value="">Select Veriant</option>'){

                        fule_html += '<label for="fule_type">Fuel Type</label>  <input type="text"  name="fule_type" id="fule_type" value="No Data" class="form-control" placeholder="Fuel Type" readonly><span class="kt-form__help error fule_type"></span>';                   

                   }

                   if(html != '<option value="">Select Veriant</option>'){

                        fule_html += '<label for="fule_type">Fuel Type</label>  <input type="text"  name="fule_type" id="fule_type" value="Fuel Type" class="form-control" placeholder="Fuel Type" readonly><span class="kt-form__help error fule_type"></span>';                   

                   }

                  jQuery("#veriant").empty();

                  jQuery("#veriant").html(html);

                  jQuery("#fule_type").html(fule_html);

                  jQuery("#convinience_program").empty();

                  jQuery("#convinience_program").html(c_html);

              }

          });

    }



    function car_fuel_type(id,model_id){

        $.ajax({

            url : "{{ url('pricelist/car_fuel_type/') }}",

            data : {'id' : id,model_id:model_id},

            type : 'get',

            dataType : 'json',

            success : function(resp){

                var fule_html = '';

                $.each(resp.data, function (id, value){

                    var id = value.id;

                    var title = value.title;



                    if(resp.id.fule_type == id){

                        fule_html += '<label for="fule_type">Fuel Type</label><input type="text" name="fule_type" id="fule_type" value="'+title+'" class="form-control" placeholder="Fuel Type" readonly><span class="kt-form__help error fule_type"></span>';

                    }

                });

                $("#fule_type").html(fule_html);





                var e_row = resp.ExtandWarranty_arr;



                if(e_row != null && e_row.length > 0){

                  var html2 = '';

                  html2 = '';

                  html2 +='<option value="">Select Extanded Warranty</option>';

                  jQuery.each(e_row, function(key, val){

                      html2 += '<option value="'+val.id+'" data-amount="'+val.amount+'" >'+val.years+' - '+val.amount+'</option>';                      

                  });


                  jQuery("#extended_warranty").empty();

                  jQuery("#extended_warranty").html(html2);

                }

            }

        });

    }



      jQuery(document).on('change', '#fuel_type', function(e){

            $('#exterior_color').val('');

            $('#interior_color').val('');

            $('#product_id').val('');



          var id = $('#car_name').val();

          var option_check = 'Carvarient';

          var new_mcp = 'Mcp';

          // alert('1');

          var fuel = $('#fuel_type').val();

         car_name_new(id,option_check,new_mcp,fuel);

      });



    jQuery(document).on('change', '#veriant', function(e){

        var id = $('#veriant').val();

        var model_id = $('#car_name').val();

        car_fuel_type(id,model_id);

    });



        $('#pricelist_manager_id').attr('disabled',true);
        var from = 'create';
        function car_list_new(id,option_check,pricelist){
            var is_csd = $("#is_csd").val();
            var branch_id = $("#branch").val();
            $.ajax({

                url : "{{ url('obf/car_drop_down_get/') }}",

                data : {'id' : id,'option_check': option_check,'pricelist': pricelist, is_csd:is_csd == 'Yes'? 'Yes' : 'No','branch_id':branch_id,'from':from},

                type : 'get',

                dataType : 'json',



                success : function(resp){  

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

                    var html = phtml = '' ;

                    var e_row = resp.data.carname_arr;

                    var p_row = resp.data.Pricelist_arr;



                    window.tex_master_gst = parseInt(resp.data.tex_master_gst);



                     // console.log(p_row);

                    /*html = '';

                    html +='<option value="">Select Car</option>';

                    jQuery.each(e_row, function(key, val){ 

                       

                        html += '<option value="'+val.id+'">'+val.exterior_color+' | '+val.interior_color+'</option>';

                    });

                    jQuery("#name").empty();

                    jQuery("#name").html(html);*/



                    phtml = '';

                    phtml +='<option value="">Select Price List</option>';

                    jQuery.each(p_row, function(key, val){ 

                        $('#pricelist_manager_id').removeAttr('disabled');

                        

                    phtml += '<option value="'+val.id+'">'+val.price_list_name+'</option>';
                    // var branchIds = val.branch_id.toString().split(',');

                    // if ($.inArray(branch_id.toString(), branchIds) !== -1) {
                    //     phtml += '<option value="' + val.id + '" ' + selected + '>' + val.price_list_name + '</option>';
                    // } else {
                    //     phtml += '<option value="">Select Price List</option>';
                    // }

                    });

                    jQuery("#pricelist_manager_id").empty();

                    jQuery("#pricelist_manager_id").html(phtml);



                    //new_clalculate();



                }

            });

        }



      /*jQuery(document).on('change', '#veriant', function(e){

          var id = $('#veriant').val();

          var option_check = 'carname';

          var pricelist = 'pricelist_master';

          // alert('1');

          car_list_new(id,option_check,pricelist);

          

      });*/





      



    /*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){ 

                     ehtml = val.exterior_color;

                     ihtml = val.interior_color;

                 });

                 jQuery("#exterior_color").val(ehtml);

                 jQuery("#interior_color").val(ihtml);

             }

         });

         

     }*/



     var a = ['', 'one ', 'two ', 'three ', 'four ', 'five ', 'six ', 'seven ', 'eight ', 'nine ', 'ten ', 'eleven ', 'twelve ', 'thirteen ', 'fourteen ', 'fifteen ', 'sixteen ', 'seventeen ', 'eighteen ', 'nineteen '];

     var b = ['', '', 'twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety'];

     

     function inWords(num) {

         if ((num = num.toString()).length > 9) return 'overflow';

         n = ('000000000' + num).substr(-9).match(/^(\d{2})(\d{2})(\d{2})(\d{1})(\d{2})$/);

         if (!n) return;

         var str = '';

         str += (n[1] != 0) ? (a[Number(n[1])] || b[n[1][0]] + ' ' + a[n[1][1]]) + 'crore ' : '';

         str += (n[2] != 0) ? (a[Number(n[2])] || b[n[2][0]] + ' ' + a[n[2][1]]) + 'lakh ' : '';

         str += (n[3] != 0) ? (a[Number(n[3])] || b[n[3][0]] + ' ' + a[n[3][1]]) + 'thousand ' : '';

         str += (n[4] != 0) ? (a[Number(n[4])] || b[n[4][0]] + ' ' + a[n[4][1]]) + 'hundred ' : '';

         str += (n[5] != 0) ? ((str != '') ? 'and ' : '') + (a[Number(n[5])] || b[n[5][0]] + ' ' + a[n[5][1]]) + 'only ' : '';

         return str;

     }



      jQuery(document).on('change', '#on_road_price', function(e){

         var on_road_price = $('#on_road_price').val();



         /*var on_road_price_word = convert_number(on_road_price);



          $('#on_road_price_word').val(on_road_price_word+' ONLY');*/



          var on_road_price_word = inWords(on_road_price);



          $('#on_road_price_word').val(on_road_price_word);

     });





     function new_clalculate(){


           // ,#registration_individual_charges,#tcs,#municipal_tax,#registration_individual_charges,#insurance,#fasttag,#on_road_individual_charges,#branch_id,#on_road_corporate_charges



           var basic = parseInt($("#basic").val());

           if(isNaN(basic)) {

               basic = 0;

           }



           var gst_amount = parseInt($("#gst_amount").val());

           if(isNaN(gst_amount)) {

               gst_amount = 0;

           }



           var cess_amount = parseInt($("#cess_amount").val());

           if(isNaN(cess_amount)) {

               cess_amount = 0;

           }



            // var ex_showroom_price = parseInt($("#ex_showroom_price").val()); 



            var ex_showroom_price = basic + gst_amount + cess_amount;



            if(isNaN(ex_showroom_price)) {

                ex_showroom_price = 0;

            }

            $("#ex_showroom_price").val(Math.round(ex_showroom_price));



            // tcs 1%


            var is_csd = $('#is_csd').val();
            if(is_csd === 'No'){
                if(ex_showroom_price > 1000000){
                    
                    var aadhar_linked = $('#aadhar_pan_link').val();
                    var customer_type_new = $('#customer_type_new').val();
                    if(aadhar_linked === 'yes'){
                        var tcs= ((ex_showroom_price * 1) / 100);    
                        $('#tcs_tax').val(Math.round(tcs));        
                    } else if(aadhar_linked === 'no' && customer_type_new == '4'){
                        var tcs= ((ex_showroom_price * 1) / 100);    
                        $("#tcs_tax").val(Math.round(tcs));
                    } else {
                        var tcs= ((ex_showroom_price * 5) / 100);    
                        $("#tcs_tax").val(Math.round(tcs));
                    }
                }else{
                    $("#tcs_tax").val(0);
                }
            }else{
                $("#tcs_tax").val(0);
            }


            var tcs = parseInt($("#tcs_tax").val());

            if(isNaN(tcs)) {

                tcs = 0;

            }

















            /*var branch_persentage = parseInt($('option:selected', '#branch').attr('data-branchper'));

            if(isNaN(branch_persentage)) {

                branch_persentage = 1;

            }*/



           /* console.log('**************');

                  console.log(window.tex_master_gst);

                  console.log(typeof(window.tex_master_gst));

                  console.log('**************');



            var statutory_charges_1=((ex_showroom_price/1.48)+(ex_showroom_price/1.48)*window.tex_master_gst/100);

            var statutory_charges = (statutory_charges_1/100)*branch_persentage;*/



             // console.log(typeof(on_road_individual_charges_1));



             var start_value1 = parseInt($('option:selected', '#branch').attr('data-start_value1'));

             var end_value1 = parseInt($('option:selected', '#branch').attr('data-end_value1'));

             var tax_percentage1 = parseFloat($('option:selected', '#branch').attr('data-tax_percentage1'));

             var start_value2 = parseInt($('option:selected', '#branch').attr('data-start_value2'));

             var end_value2 = parseInt($('option:selected', '#branch').attr('data-end_value2'));

             var tax_percentage2 = parseFloat($('option:selected', '#branch').attr('data-tax_percentage2'));



             

             var branch_persentage = 1; 

             if(ex_showroom_price >= start_value1 && ex_showroom_price <= end_value1){

                 branch_persentage = tax_percentage1; 

             }else if(ex_showroom_price >= start_value1 && ex_showroom_price <= end_value2){

                 branch_persentage = tax_percentage2; 

             }   



              /*console.log('********');

              console.log(basic);

              console.log(gst_amount);

              console.log(start_value1);

              console.log(tax_percentage2);

              console.log(branch_persentage);

              console.log('********');*/



             var statutory_charges = ((basic + gst_amount)/100)*branch_persentage;



             if(isNaN(statutory_charges)) {

                 statutory_charges = 0;

             }
             
            var municipal_tax_type = $('#municipal_tax_type').val();
            if(municipal_tax_type == 'in_house'){
               $('#municipal_tax').val(Math.round(statutory_charges));
            }else{
               $('#municipal_tax').val(0);
            }      



            var customer_type = $('#customer_type').val();

            

  

      

            var handling_charges = parseInt(Math.round($("#municipal_tax_handling").val()));

            if(isNaN(handling_charges)) {

                handling_charges = 0;

            }

           

            var statutory_charges = parseInt(Math.round($("#municipal_tax").val()));

            if(isNaN(statutory_charges)) {

                statutory_charges = 0;

            } 



            var registration_tax=parseInt($("#registration_tax").val());

            if(isNaN(registration_tax)) {

                registration_tax = 0;

            } 
            
            var rto_custom_handling_charges=parseInt($("#pl_rto_custom_handling_charges").val());
            if(isNaN(rto_custom_handling_charges)) {
                rto_custom_handling_charges = 0;
            } 



            var insurance=parseInt($("#insurance").val());

            if(isNaN(insurance)) {

                insurance = 0;

            } 



            var fasttag = parseInt($('option:selected', '#fasttag_brand_name').attr('data-price'));

            if(isNaN(fasttag)) {

                fasttag = 0;

            } 



            var extended_warranty = parseInt($('option:selected', '#extended_warranty').attr('data-amount'));

            if(isNaN(extended_warranty)) {

                extended_warranty = 0;

            } 



            var sum = 0;

            $('#accessories option:selected').each(function(){

                sum  += parseInt($(this).attr("data-price"));

            });



            if(isNaN(sum)) {

                sum = 0;

            } 



            var convinience_program_amount = parseInt($('option:selected', '#convinience_program').attr('data-convinience_amount'));

            if (isNaN(convinience_program_amount)) {

                convinience_program_amount = 0;

            }

           

           var rsa_master = parseInt($('#rsa_master_obf option:selected').attr('data-rsa_amount'));
            if (isNaN(rsa_master)) {
                rsa_master = 0;
            }
            
            var ccs_master = parseInt($('#ccs_master_obf option:selected').attr('data-ccs_amount'));
            if (isNaN(ccs_master)) {
                ccs_master = 0;
            }
            
            console.log(rsa_master);
            console.log(ccs_master);

             var otheracc =  parseInt($('#other_accesssories_prise').val());

              if (isNaN(otheracc)){

                otheracc = 0;

            }
            
            var municipal_cus_hand_charg = parseInt($('#municipal_custom_handling_charges').val());
            if (isNaN(municipal_cus_hand_charg)){
                municipal_cus_hand_charg = 0;
            }

            

            var on_road_price=otheracc+handling_charges+ex_showroom_price+tcs+statutory_charges+registration_tax+rto_custom_handling_charges+insurance+fasttag+extended_warranty+sum + convinience_program_amount+rsa_master+ccs_master+municipal_cus_hand_charg;   



            /*console.log('ex_showroom_price=>'+ex_showroom_price);

            console.log('tcs=>'+tcs);

            console.log('statutory_charges=>'+statutory_charges);

            console.log('registration_tax=>'+registration_tax);

            console.log('insurance=>'+insurance);

            console.log('fasttag=>'+fasttag);

            console.log('extended_warranty=>'+extended_warranty);

            console.log('sum=>'+sum);*/



         

         

            if(isNaN(on_road_price)) {

                on_road_price = 0;

            }                        

            $('#on_road_price').val(on_road_price);

            var word_price = inWords(on_road_price);

            $('#on_road_price_word').val(word_price);  

         }   



    $("#ex_showroom_price,#tcs_tax,#municipal_tax,#registration_tax,#insurance,#branch,#customer_type,#accessories,#on_road_price,#extended_warranty,#fasttag_brand_name,#convinience_program,#municipal_tax_applicable,#rsa_master_obf,#ccs_master_obf,#municipal_tax_handling,#municipal_custom_handling_charges,#municipal_tax_type").change(function(){

        new_clalculate();



    })



     function previewMultiple(event,idnamediv,id_name){

        var saida = document.getElementById(id_name);

        var quantos = saida.files.length;

         $('#'+idnamediv).empty();

        for(i = 0; i < quantos; i++){

            var urls = URL.createObjectURL(event.target.files[i]);

            document.getElementById(idnamediv).innerHTML += '<img src="'+urls+'">';

        }

    }



    function color_select(id,option_check,car_model){

        $.ajax({

            url : "{{ url('obf/color_select/') }}",

            data : {'id' : id,'option_check': option_check,car_model:car_model},

            type : 'get',

            dataType : 'json',

            success : function(resp){  



                if(option_check == 'exterior_color'){

                    var e_row = resp.data.exterior_color_arr;

                    var html = '';

                    html +='<option value="">Select Exterior Color</option>';

                    jQuery.each(e_row, function(key, val){

                        html +='<option value="'+val.id+'" >'+val.name+'</option>';

                    });

                    jQuery("#exterior_color").empty();

                    jQuery("#exterior_color").html(html);

                }    

            }

        });

    }



    // get Exterior Color

    jQuery(document).on('change', '#veriant', function(e){

        var id = $('#veriant').val();

        var option_check = 'carname';

        var pricelist = 'pricelist_master';

        // alert('1');

        car_list_new(id,option_check,pricelist);





        var option_check = 'exterior_color';

        car_model = $('#car_name').val();

        color_select($('#veriant').val(),option_check,car_model);

    });





    function color_select_interior_color(id,car_model,veriant){

        var option_check = 'interior_color';



        $.ajax({

            url : "{{ url('obf/color_select/') }}",

            data : {'id' : id,'option_check': option_check,car_model:car_model,veriant:veriant},

            type : 'get',

            dataType : 'json',

            success : function(resp){  

                if(option_check == 'interior_color'){

                    var e_row = resp.data.interior_color_arr;

                    var html = '';

                    html +='<option value="">Select Interior Color</option>';

                    jQuery.each(e_row, function(key, val){

                        html +='<option value="'+val.id+'" data-product_id='+val.product_id+'>'+val.name+'</option>';

                    });

                    jQuery("#interior_color").empty();

                    jQuery("#interior_color").html(html);

                }                

            }

        });

    }



    jQuery(document).on('change', '#exterior_color', function(e){

        id = $('#exterior_color').val();

        car_model = $('#car_name').val();

        veriant = $('#veriant').val();

        color_select_interior_color(id,car_model,veriant);

    });



    jQuery(document).on('change', '#interior_color', function(e){

        var product_id = parseInt($('option:selected', '#interior_color').attr('data-product_id'));

        jQuery("#product_id").val(product_id);

    });



     jQuery(document).on('change', '#lead', function(e){

            var id = $('#lead').val();

            sub_lead_html(id);

        });



        function sub_lead_html(id){

          $.ajax({

              url : "{{ url('obf/sub_lead_html/') }}",

              data : {'id' : id},

              type : 'get',

              dataType : 'json',

              success : function(resp){  

                  var c_row = resp.data.sub_lead_html; 

                  var html = '';

                  html +='<option value="">Select Sub Lead</option>';

                  jQuery.each(c_row, function(key, val){

                      html +='<option value="'+val.id+'">'+val.name+'</option>';

                  });                 

                  jQuery("#sub_lead_id").empty();

                  jQuery("#sub_lead_id").html(html);

              }

          });

        }

        

       //As per offer type

        jQuery(document).on('change', '#offer_type', function(e){

            var car_name = $('#car_name').val();

            var fuel = $('#fuel_type').val();

            //alert(fuel);

            var varient = $('#veriant').val();

            var offer_type = $('#offer_type').val();

            sub_offer_html(car_name,varient,fuel,offer_type);

        });



        function sub_offer_html(car_name,varient,fuel,offer_type){             

             

          $.ajax({

              url : "{{ url('obf/offer_asper_varient') }}",

              data : {'car_name' : car_name,'varient':varient,'fuel':fuel,'offer_type':offer_type},

              type : 'get',

              dataType : 'json',

              success : function(resp){  

                  var c_row = resp.data.sub_offer_html;

                  var e_row = resp.data.sub_offer_ShivamIB; 

                  var html = '';

                  html +='<option value="">Select Offers</option>';

                  jQuery.each(c_row, function(key, val){

                      html +='<option value="'+val.id+'">'+val.title+' - '+ val.amount+'</option>';

                  });                 

                  jQuery("#offer_kin").empty();

                  jQuery("#offer_kin").html(html);



                  var html_s = '';

                  html_s +='<option value="">Select Offers</option>';

                  jQuery.each(e_row, function(key, val){

                      html_s +='<option value="'+val.id+'">'+val.title+' - '+ val.amount+'</option>';

                  });  



                  jQuery("#offer_ib").empty();

                  jQuery("#offer_ib").html(html_s);

              }

          });

        }



        // from offers to amount 

        jQuery(document).on('change', '#offer_kin', function(e){

            var offer = $('#offer_kin').val();

           

            var items = $("#offer_kin option:selected").map((i, el) => el.textContent.trim()).get();

            //console.log(items.join());

            $("#offers_kin_name").val(items.join());

            sub_offer_amount(offer);

        });

        function sub_offer_amount(offer){             

             

          $.ajax({

              url : "{{ url('obf/amount_asper_offer') }}",

              data : {'offer':offer},

              type : 'get',

              dataType : 'json',

              success : function(resp){  

                  var c_row = resp.data; 

                  var row = resp.data.details;

                 // $('#o_amount').val(resp.data.offer_amount); 

               //   $('#offers_amt').val(resp.data.offer_amount); 

                //  $('#offe_amt').val(resp.data.offer_amount); 

                 // $('#offers_amount').val(resp.data.offer_amount); 

                  $('#offers_kin_amount').val(resp.data.offer_amount); 

                      

                //console.log(resp.data.offer_amount);

                  /*jQuery("#o_amount").empty();

                  jQuery("#o_amount").html(html);*/

              }

          });

        }





        jQuery(document).on('change', '#offer_ib', function(e){

            

            var offer_ib = $('#offer_ib').val();  

            //alert(offer_ib);

            sub_offer_ib_amount(offer_ib);

            var item = $("#offer_ib option:selected").map((i, el) => el.textContent.trim()).get();

            //console.log(item.join());

            $("#offers_ib_name").val(item.join());            

        });



        function sub_offer_ib_amount(offer_ib){             

             

          $.ajax({

              url : "{{ url('obf/amount_asper_offer_ib') }}",

              data : {'offer_ib':offer_ib},

              type : 'get',

              dataType : 'json',

              success : function(resp){  

                  var c_row = resp.data; 

                  var row = resp.data.details;

                  //$('#o_amount').val(resp.data.offer_amount); 

                 // $('#offers_amt').val(resp.data.offer_amount); 

                 // $('#offe_amt').val(resp.data.offer_amount); 

                  //$('#offers_amount').val(resp.data.offer_amount);

                  $('#offers_ib_amount').val(resp.data.offer_amount_ib);      

                //console.log(resp.data.offer_amount);

                  /*jQuery("#o_amount").empty();

                  jQuery("#o_amount").html(html);*/

              }

          });

        }
        
        
        jQuery(document).on('click', '#offers_amt', function () {

            var offers_kin_amount = parseInt($('#offers_kin_amount').val()) || 0;
            var offers_ib_amount  = parseInt($('#offers_ib_amount').val()) || 0;
        
            var total_ofr_amount = offers_kin_amount + offers_ib_amount;
        
            // set offers_amt value
            $('#offers_amt').val(total_ofr_amount);
        
            // get offer_amt as number
            var offer_amt = parseInt($('#offer_amt').val()) || 0;
        
            var total_amt = offer_amt - total_ofr_amount;
        
            // set final amount
            $('#offe_amt').val(total_ofr_amount);
            $('#deal_price').val(total_amt);
        });
            
            
        $(document).ready(function () {

            let discountLimit = 0;
            let limitLoaded = false;
        
            // Fetch limit only once (or when model/fuel/variant changes)
            function fetchDiscountLimit() {
        
                $.ajax({
                    url: '/check-kec-discount-limit',
                    type: 'POST',
                    data: {
                        model: $('#car_name').val(),
                        fuel: $('#fuel_type').val(),
                        veriant: $('#veriant').val(),
                        discount: 0,
                        discount_year: $('#discount_year').val(),
                        _token: $('meta[name="csrf-token"]').attr('content')
                    },
                    success: function (response) {
        
                        if (response.status !== 'no_discount_found') {
                            discountLimit = parseFloat(response.limit) || 0;
                        } else {
                            discountLimit = 0;
                        }
        
                        limitLoaded = true;
                    },
                    error: function () {
                        console.log('Error fetching discount limit');
                    }
                });
            }
        
            // Fetch on page load
            fetchDiscountLimit();
        
            // 🔥 Refetch if model/fuel/variant changes
            $('#car_name, #fuel_type, #veriant').on('change', function () {
                limitLoaded = false;
                fetchDiscountLimit();
            });
        
            // 🔥 Local validation only (NO AJAX here)
            $('#way_off').on('input', function () {
            
                if (!limitLoaded) return;
        
                let wayOff = parseFloat($(this).val()) || 0;
        
                if (wayOff > discountLimit) {
        
                    $('#kec_limit_error').text(
                        'Maximum allowed discount is ₹' +
                        discountLimit.toLocaleString('en-IN')
                    ).removeClass('d-none');
        
                    $('#way_off').addClass('is-invalid');
        
                    // Cap to max allowed (better UX than reset 0)
                    $(this).val(discountLimit);
                    wayOff = discountLimit;
        
                } else {
        
                    $('#kec_limit_error').text('').addClass('d-none');
                    $('#way_off').removeClass('is-invalid');
                }
        
                // Calculate cash discount
                let dealPrice = parseFloat($('#deal_price').val()) || 0;
                let discount = dealPrice - wayOff;
        
                $('#cash_discount').val(discount);
            });

            
            $('#foc_accessories').on('keyup', function() {
                var dealPrice = $('#deal_price').val() || 0;
                var wayOff = $("#way_off").val() || 0;
                var foc_accessories = $(this).val() || 0;
            
                var discount = dealPrice - wayOff;
                
                var final_foc_dis = discount - foc_accessories;
            
                $('#cash_discount').val(final_foc_dis);
            });
        });


</script>



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

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.css" />

<script>

    $(document).ready(function(){

     $("input[name$='pay_booster']").click(function() {     

        var value = $("input:radio[name=pay_booster]:checked").val();      

      //alert(value);

          if(value == 'yes')  

          {

             $('#boostper').show();

             $('#boostamt').show();

          }

          else

          {

            $('#boostper').hide();

            $('#boostamt').hide();

          }

        });      

    });   

</script>





<script>

    $(document).ready(function(){

     $("input[name$='disbursement']").click(function() {     

      var value = $("input:radio[name=disbursement]:checked").val();

      //alert(value);

          if(value == 'no')  

          {

             $('#delivery').show();

          }

          else

          {

            $('#delivery').hide();

          }

        });      

    });   

</script>



<!--loan amount - net disbusment = processing fee.-->

<script> 

    $(document).ready(function(){

        $('#net_disbusment').keyup(function(){

            //alert('hi');

        var loan_amount = $('#loan_amount').val();

        var net_disbusment = $('#net_disbusment').val();

         //alert(loan_amount);

        var fee = loan_amount - net_disbusment; 

        var processing_fee = $('#processing_fee').val(fee);

        });

    });

</script>



<!--loan amount x payout percentage/100 = payout amount.-->

<script> 

    $(document).ready(function(){        

        $('#payout_amount').click(function(){            

            var loan_amount = $('#loan_amount').val(); 

            var pay_amount = $('#payout').val();           

            var pay = (loan_amount) * (pay_amount)/100;             

            var payout = $('#payout_amount').val(pay);

        });       

    });

</script>



<!--loan amount x booster percentage/100 = booster amount.-->

<script> 

    $(document).ready(function(){        

        $('#boost_amt').click(function(){            

            var loan_amount = $('#loan_amount').val(); 

            var boost_amount = $('#boost_per').val();           

            var pay = (loan_amount) * (boost_amount)/100;             

            var payout = $('#boost_amt').val(pay);

        });       

    });

</script>



<!--loan amount x booster percentage/100 = booster amount.-->

<!--<script> 

    $(document).ready(function(){        

        $('#total_payout_amount').click(function(){  

            var payout = parseInt($('#payout_amount').val());            

            var boost_amt = parseInt($('#boost_amt').val());             

            var lumsum_amt = parseInt($('#lumsum_amount').val());           

            var pay = payout+boost_amt+lumsum_amt; 

                 //alert(pay);       

            var payout = $('#total_payout_amount').val(pay);

        });       

    });

</script>-->



<!--loan amount x booster percentage/100 = booster amount.-->

<script> 

    $(document).ready(function(){ 

       

        $('#total_payout_amount').click(function(){ 

            // $('input[type=radio][name=pay_booster]').change(function(){ 

            // alert($("input:radio[name=pay_booster]:checked").val());    

            var val = $("input:radio[name=pay_booster]:checked").val();

            if(val == 'yes'){

                var boost_amt = parseInt($('#boost_amt').val()); 

             }  

             else{

                var boost_amt = 0;

             }

       

            // alert(boost_amt);

                var payout = parseInt($('#payout_amount').val());            

                            

                var lumsum_amt = parseInt($('#lumsum_amount').val());           

                var pay = payout+boost_amt+lumsum_amt; 

                  //   alert(boost_amt);       

                var payout = $('#total_payout_amount').val(pay);

            });       

        // });

    });



    

$(document).ready(function() {

    $('#other_application').click(function() {

        if ($(this).is(':checked')) {

            $('#otheraccessoriesid').removeClass('hide');                

        } else {

            $('#otheraccessoriesid').addClass('hide');                

        }

    });

});

</script>



<script>

    $(document).ready(function(){

        $('#trade_car_value').change(function(){

            var val = $('#trade_car_value').val();

            if(val == 'yes'){

                $('#tradecarname').show();

            }

            else{

                $('#tradecarname').hide();   

            }

            //$('#tradecarname').hide();

        });

        

        // $('#offers_ib_amount').click(function(){

        //     var ib = parseInt($('#offers_ib_amount').val()) || 0;
        //     var kin = parseInt($('#offers_kin_amount').val()) || 0;
            
        //     var total = ib + kin;
        //     $('#offers_amt').val(total);
        //     $('#offe_amt').val(total);

        
        //     var val = parseInt($('#on_road_price').val()) || 0;           
        //     var amount = parseInt($('#offe_amt').val());

        //     var price = val - amount;

        //     // var withval = $('#with_offer_ex_showroom_price').val(price); 

        //      $('#offer_amt').val(val);
        //      $('#deal_price').val(price);
        // });      
        $("#ex_showroom_price,#tcs_tax,#municipal_tax,#registration_tax,#insurance,#branch,#customer_type,#accessories,#on_road_price,#extended_warranty,#fasttag_brand_name,#convinience_program,#municipal_tax_applicable,#rsa_master_obf,#ccs_master_obf,#municipal_custom_handling_charges,#municipal_tax_type").change(function(){
            var ib = parseInt($('#offers_ib_amount').val()) || 0;
            var kin = parseInt($('#offers_kin_amount').val()) || 0;
            
            var total = ib + kin;
            $('#offers_amt').val(total);
            $('#offe_amt').val(total);

        
            var val = parseInt($('#on_road_price').val()) || 0;           
            var amount = parseInt($('#offe_amt').val());

            var price = val - amount;

            // var withval = $('#with_offer_ex_showroom_price').val(price); 

             $('#offer_amt').val(val);
             $('#deal_price').val(price);
        }); 
        
        $("#ex_showroom_price,#tcs_tax,#municipal_tax,#registration_tax,#insurance,#branch,#customer_type,#accessories,#on_road_price,#extended_warranty,#fasttag_brand_name,#convinience_program,#municipal_tax_applicable,#rsa_master_obf,#ccs_master_obf,#other_accesssories_prise,#municipal_custom_handling_charges,#municipal_tax_type").change(function(){
            var dealPrice = parseFloat($('#deal_price').val()) || 0;
            var foc_accessories = parseFloat($('#foc_accessories').val()) || 0;
            var wayOff = parseFloat($('#way_off').val()) || 0;
            var foc_accessories = parseFloat($('#foc_accessories').val()) || 0;
        
            var discount = dealPrice - wayOff;
            var finalDiscount = discount - foc_accessories;
        
            $('#cash_discount').val(finalDiscount);
        });
        
        $("#other_accesssories_prise").keyup(function(){
            var ib = parseInt($('#offers_ib_amount').val()) || 0;
            var kin = parseInt($('#offers_kin_amount').val()) || 0;

            var total = ib + kin;
            $('#offers_amt').val(total);
            $('#offe_amt').val(total);
            
            var val = parseInt($('#on_road_price').val()) || 0;           
            //alert(val);
            var amount = parseInt($('#offe_amt').val()) || 0;

            var price = val - amount;

            //var withval = $('#with_offer_ex_showroom_price').val(price); 
             $('#offer_amt').val(val);
             $('#deal_price').val(price);
            
            
            var dealPrice = parseFloat($('#deal_price').val()) || 0;
            var foc_accessories = parseFloat($('#foc_accessories').val()) || 0;
            var wayOff = parseFloat($('#way_off').val()) || 0;
            var foc_accessories = parseFloat($('#foc_accessories').val()) || 0;
        
            var discount = dealPrice - wayOff;
            var finalDiscount = discount - foc_accessories;
        
            $('#cash_discount').val(finalDiscount);
        });

    });

        $(document).ready(function() {
            $('#way_off').on('keyup', function() {
                var dealPrice = $('#deal_price').val() ? parseFloat($('#deal_price').val()) : 0;
                var wayOff = $(this).val() ? parseFloat($(this).val()) : 0;
                var discount = dealPrice - wayOff;
        
                $('#cash_discount').text(discount);
            });
        });

        // code to autofilling insurance company name and remarks
        const carInsuranceInput = document.getElementById('car_insurance_company_name');
        const insuranceDetailsInput = document.getElementById('insurance_details_company_name');
        
        carInsuranceInput.addEventListener('input', function () {
            insuranceDetailsInput.value = this.value; 
        });
        
        
        const carRemarksInput = document.querySelector('.car-remarks'); // Car Details Remarks
        const insuranceRemarksInput = document.querySelector('.insurance-remarks'); // Insurance Details Remarks
        
        // Add input listener for autofill
        carRemarksInput.addEventListener('input', function () {
            insuranceRemarksInput.value = this.value;
        });
        
</script>

@endsection