
@extends('layouts.app')

@section('title')
Edit Statement 
@stop

@section('breadcrumb')
<ol class="breadcrumb pull-right">
        <li><a href="{{route('home')}}"><i class="fa fa-dashboard"></i> Home</a></li>
        @permission('list-membership')
        <li ><a href="{{route('statement.all')}}">Statements</a></li>
        @endpermission
        <li class="active">Add Statement</li>
      </ol>
@stop


@section('content')

<div class="container-fluid">
    <div class="row">

            <form class="form-horizontal" method='post' action="{{route('statement.schedule.update')}}" enctype="multipart/form-data">
                {{csrf_field()}}
                <input type="hidden" name="property_id" value="{{$property->id}}">
        <div class="col-md-12">
             @if($errors->any())
                        <div class="white-box"><h2>Errors</h2><ul>
    {!! implode('', $errors->all('<li><span class="help-block"><strong>:message</strong></span></li>')) !!}
</ul></div>@endif
                        <div class="white-box">
                           <h3 class="box-title m-b-0"><i class="icon-layers fa-fw"></i> Add New Statement</h3>
                            <p class="text-muted  font-13"> Note: All * fields are mandatory </p>

                            <hr>

                        </div>
                    </div>

                    <div class="col-lg-12 col-sm-12 col-xs-12"  >
                        <div class="white-box">
                            <h3 class="box-title">Customer Information </h3>
                            <hr>
                                <div class="clearfix"></div>
                            <!-- Nav tabs -->
                            <ul class="nav customtab nav-tabs" role="tablist" >
                                <li  role="presentation" class="active">
                                    <a href="#profile1" aria-controls="profile" role="tab" data-toggle="tab" aria-expanded="false" style="font-weight: 700;" ><span class="visible-xs"><i class="ti-user"></i></span> <span class="hidden-xs">Property Customer</span></a></li>                        
                            </ul>
                            <!-- Tab panes -->
                            <div class="tab-content">




                            <div role="tabpanel" class="tab-pane fade active in" id="profile1">
                            <div class="col-md-6">
                            <div class="form-group">
                            <label class="control-label col-md-4">Name of Applicant</label>
                            <div class="col-md-8">
                            <select  autocomplete="off" readonly class="form-control" id="customer_id" name="customer_id" style="width: 100%!important;">
                           
                                <option value="{{$customer->id}}" selected="">{{$customer->name}} -
                                    <b>{{$customer->cnic}}</b>
                                    </option>
                            </select>
                            </div>
                            </div>
                            </div>
                            <div class="clearfix"></div>
                           
                            </div>

                            </div>

                                    <div class="clearfix"></div>
                                </div>
                            </div>
                  

                   

                    <div class="col-lg-12 col-sm-12 col-xs-12">
                        <div class="white-box1">
                            <h3 class="box-title">Unit Information</h3>
                            <hr>
                             <input type="hidden" name='inventory_id' id='inventory-id' value='{{old("inventory_id")}}'>

                            <div class="col-md-6" >
                            <div class="form-group">
                            <label style="padding-top: 8px;" class="control-label col-md-4">Unit # <span style="color:red">*</span></label>
                            <div class="col-md-8">
                            <select class="form-control " id="unit_number" name="unit_number">
                                <option value="{{$unitNumber->id}}">{{$unitNumber->unit_number}}</option>
                           
                            </select>

                            @if ($errors->has('unit_number'))
                            <span class="help-block">
                            <strong>{{ $errors->first('unit_number') }}</strong>
                            </span>
                            @endif</div>
                            </div>
                            </div>
                            

                            <div class="col-md-6" id="inventory_type">
                                <div class="form-group">
                                <label style="padding-top: 8px;" class="control-label col-md-4">Type</label>
                                <div class="col-md-8">
                                <input readonly="" type="text" class="form-control" name="type" value="{{$unitNumber->type->name}}" id="type">
                                @if ($errors->has('type'))
                                <span class="help-block">
                                <strong>{{ $errors->first('type') }}</strong>
                                </span>
                                @endif</div>
                                </div>
                            </div>
                            <div class="clearfix"></div>
                            <div class="col-md-6">
                            <div class="form-group">
                            <label style="padding-top: 8px;" class="control-label col-md-4">Size</label>
                            <div class="col-md-8">
                            <input readonly="" type="text" class="form-control" name="size" value="{{$unitNumber->size->name}}" id="size">
                            @if ($errors->has('size'))
                            <span class="help-block">
                            <strong>{{ $errors->first('size') }}</strong>
                            </span>
                            @endif</div>
                            </div>
                            </div>
                            

                           
                            <div class="col-md-6">
                            <div class="form-group">
                            <label class="control-label col-md-4">Total Price</label>
                            <div class="col-md-8">
@php
$total_price=(int)$unitNumber->total_price - (int)$unitNumber->extra_amount;
@endphp
                            <input readonly="" type="text"  id='total-amount' class="form-control" name="total_price" value="{{$total_price}}">
                            @if ($errors->has('total_price'))
                            <span class="help-block">
                            <strong>{{ $errors->first('total_price') }}</strong>
                            </span>
                            @endif
                            <div style="color:black;" class="help-block" id='total-amount-label'></div>
                            </div>
                            </div>
                            </div>


                            <div class="clearfix"></div>

                            <div class="col-md-6">
                            <div class="form-group">
                            <label class="control-label col-md-4">Category</label>
                            <div class="col-md-8">
                                @php
                                 $categories_name= '';   
                                @endphp
                            @foreach( $unitNumber->categories as $category)
                                 
                            @php
                            $categories_name =   $category->category->name .','. $categories_name ;   
                           @endphp
                            @endforeach
                            <input readonly="" type="category" class="form-control" name="category" value="{{ $categories_name}}" id="category" >
                            @if ($errors->has('category'))
                            <span class="help-block">
                            <strong>{{ $errors->first('category') }}</strong>
                            </span>
                            @endif</div>
                            </div>
                            </div>

                            
                            <div class="col-md-6">
                            <div class="form-group">
                            <label class="control-label col-md-4">Extra Charges </label>
                            <div class="col-md-8">

                            <input readonly="" type="text"  id='extra_charges' class="form-control" name="extra_charges" value="{{ $unitNumber->extra_amount}}">

                            <div style="color:black;" class="help-block" id='extra-charges-label'></div>
                            </div>
                            </div>
                            </div>

                            


                            <div class="col-md-6" >
                                <div class="form-group">
                                     <label class="control-label col-md-4">Booking Date</label>
                                    <div class="col-md-8">

                                    <input type="text" readonly class="form-control" name="original_boooking_date" value=" {{date('d-m-Y', strtotime($property->original_boooking_date)) }}" id="original_boooking_date" placeholder="Enter Booking Date">
                                    @if ($errors->has('original_boooking_date'))
                                    <span class="help-block">
                                    <strong>{{ $errors->first('original_boooking_date') }}</strong>
                                    </span>
                                    @endif
                                    </div>
                            </div>
                            </div>
                            <div class="col-md-6" >
                                <div class="form-group">
                                     <label class="control-label col-md-4">Discount Amount</label>
                                    <div class="col-md-8">

                                    <input type="text" readonly class="form-control" name="discount" value="{{$property->discount}}" id="discount"  >
                                    @if ($errors->has('discount'))
                                    <span class="help-block">
                                    <strong>{{ $errors->first('discount') }}</strong>
                                    </span>
                                    @endif
                                    </div>
                            </div>

                            
                            </div>

                            

                            {{-- <div class="clearfix"></div>

                            <div class="col-md-6">
                            <div class="form-group">
                            <label class="control-label col-md-4">Unit Description </label>
                            <div class="col-md-8">

                            <input readonly="" type="text"  id='description' class="form-control" name="description" value="{{old('description')}}">


                            </div>
                            </div>
                            </div> --}}
                               

                            <div class="clearfix"></div>


                            <div class="col-md-6">
                            <div class="form-group">
                            <label class="control-label col-md-4">Net Amount</label>
                            <div class="col-md-8">
                            {{-- <input type="hidden" id="dummy_net_amount"> --}}
                            <input readonly="" type="text" id='net_amount' class="form-control" name="net_amount" value="{{$property->net_pay}}" >
                            @if ($errors->has('net_amount'))
                            <span class="help-block">
                            <strong>{{ $errors->first('net_amount') }}</strong>
                            </span>
                            @endif
                            <div style="color:black;" class="help-block" id='net_amount-label'></div>

                            </div>
                            </div>
                            </div>
                            <div class="col-md-6" >
                                <div class="form-group">
                                     {{-- <label class="control-label col-md-4">Add Discount </label> --}}
                                     <label class="control-label col-md-4">Add New Discount <br> (use percent <input type="checkbox" onclick="percentCheckbox()" name="discount_percent" id="discount_percent">)</label>
                                
                                    <div class="col-md-8">
                                        <div class="input-group" >
                                        <span class="input-group-addon" style="font-size: 12px;" id="dis_input">PKR</span>
                                    <input type="number"   class="form-control" name="newdiscount"   id="add_new_discount"   max={{$remaining_amount}} placeholder="Enter Discount" >
                                        </div>
                                    @if ($errors->has('newdiscount'))
                                    <span class="help-block">
                                    <strong>{{ $errors->first('newdiscount') }}</strong>
                                    </span>
                                    @endif
                                    </div>
                            </div>

                            
                            </div>
                            <div class="clearfix"></div>



                            

                            <div class="col-md-6">
                            <div class="form-group">
                            <label class="control-label col-md-4">Remaining Payable</label>
                            <div class="col-md-8">
                            <input type="hidden" id="dummy_net_amount">
                            <input  type="text" id='net_amount' class="form-control" name="net_amount" value="{{$remaining_amount}}" >
                            @if ($errors->has('net_amount'))
                            <span class="help-block">
                            <strong>{{ $errors->first('net_amount') }}</strong>
                            </span>
                            @endif
                            <div style="color:black;" class="help-block" id='net_amount-label'></div>

                            </div>
                            </div>
                            </div>

                            <div class="clearfix"></div>

                            

                            
                    

                    <div class="col-md-6" >
                    <div class="form-group">
                    <label class="control-label col-md-5">Booking Type </label>
                    <div class="col-md-7">
                        @if($property->booking_type == \App\CustomerProperty::normal)
                        
                        <input type='radio' onchange="activeNormal()" name="booking_type" value='{{\App\CustomerProperty::normal}}' checked=""  > Installment<br>

                        <input type='radio' onchange="activeFullPayment()"  name="booking_type" value='{{\App\CustomerProperty::full_payment}}' disabled > Full Payment
                       
                        @elseif($property->booking_type == \App\CustomerProperty::full_payment)
                        <input type='radio' onchange="activeNormal()" name="booking_type" value='{{\App\CustomerProperty::normal}}' disabled> Installment<br>

                    <input type='radio' onchange="activeFullPayment()"  name="booking_type" value='{{\App\CustomerProperty::full_payment}}' checked=""  > Full Payment
                        @endif
                   
                    @if ($errors->has('booking_type'))
                    <span class="help-block">
                    <strong>{{ $errors->first('booking_type') }}</strong>
                    </span>
                    @endif</div>
                    </div>
                    </div>




                        </div>
                    </div>
                            <div class="col-lg-12 col-sm-12 col-xs-12"  >
                            <div class="white-box">
                            <h3 class="box-title" style="display: inline-block;">Dealer Rebate Information</h3>  
                             {{-- <span style="margin-left:17%">% 
                                <input type="float" name="rebate_in_percentage" style="width: 5%;display: inherit;" class="form-control"  id="rebate_in_percentage"><input type="float" class="form-control" style="width: 10%;display: inherit;" name="rebate_in_amount" id="rebate_in_amount"> PKR</span> --}}
                            {{-- <a class="btn btn-outline btn-default waves-effect waves-light pull-right add_field_button5" style="margin-top: 9px">  <span>Add More</span></a> --}}
                            <hr>
                            <div class="col-md-6">
                            <div class="form-group">
                            {{-- <label class="control-label col-md-4">Authorized Dealer <span style="color: red">*</span></label> --}}
                            <div class="col-md-8">
                                 @foreach($dealers_involved_in_property as $d)
                                
                                <tr>
                                    <td ><b>Name :</b></td>
                                    <td> {{$d->dealer->name}} </td>

                                    <td  ><b>Rebate : </b></td>
                                    <td> {{number_format($d->amount)}} </td>

                                    
                                </tr>

                                @endforeach
                            {{-- <select class="form-control chosen-select" name="dealer_id[]" > --}}
                            {{-- <option value="" >None</option> --}}
                            {{-- @foreach($dealers as $dealer)
                            @foreach($dealer as $d)
                            @if($loop->first)
                            <optgroup label="{{$dealerTypes[$d->dealer_type_id]}}">
                            @endif
                            @if(old('dealer_id'))
                            @if(old('dealer_id') == $d->id)
                            <option value="{{$d->id}}" selected="">{{$d->name}} ( {{$d->percentage}} %)</option>
                            @else
                            <option value="{{$d->id}}" >{{$d->name}} ( {{$d->percentage}} %)</option>
                            @endif
                            @else
                            <option value="{{$d->id}}" >{{$d->name}} ( {{$d->percentage}} %)</option>
                            @endif
                            @endforeach
                            <!-- </optgroup> -->

                            @endforeach
                            </select> --}}
                            @if ($errors->has('dealer_id'))
                            <span class="help-block">
                            <strong>{{ $errors->first('dealer_id') }}</strong>
                            </span>
                            @endif
                            </div>
                            </div>
                            </div>
                            <br><div class="clearfix"></div>


                            {{-- <div class="col-md-8">
                            <div class="form-group">
                            <label class="control-label col-md-6"> Rebate <span style="color: red">*</span></label>
                            <div class="col-md-6" >
                            <div class="input-group">
                            <span class="input-group-addon" style="font-size: 10px;">PKR</span>
                            <input id="total_rebate1" type="text" class="form-control total_rebate" name="total_rebate[]" value="" >


                            @if ($errors->has('total_rebate'))
                            <span class="help-block">
                            <strong>{{ $errors->first('total_rebate') }}</strong>
                            </span>
                            @endif
                            </div>
                            </div>
                            </div>
                            </div> --}}








                            <div class="input_fields_wrap5">
                            <div class="clearfix"></div>
                            <div>
                            </div>


                            </div>

                            {{-- <input style="    width: 20%;" readonly="" type="integer" id='remaining_amount_in_rebate' class="form-control"   placeholder="Remaining amount"> --}}



                            </div>
                            </div>


                    

    <div class="col-lg-12 col-sm-12 col-xs-12" id="full_payment" >
                        <div class="white-box">
                            <h3 class="box-title">Discount Payment Terms</h3>
                              isDiscounted? <input type = "checkbox" name="full_discount" value="1" id="discount_full_payment" onclick="fullPaymentBox()">
                              <div id="discount_div" style="display: none">
                            <hr>
                            <div class="col-md-6">
                                                    <div class="form-group">
                                                        <label class="control-label col-md-5">Total Amount <span style="color: red">*</span></label>
                                                        <div class="col-md-7">

                                                            <input id="total_amount_full_payment" readonly="" class="form-control" type='number' name="total_amount_full_payment"  >
                                        @if ($errors->has('total_amount_full_payment'))
                                    <span class="help-block">
                                        <strong>{{ $errors->first('total_amount_full_payment') }}</strong>
                                    </span>
                                @endif
                                <div style="color:black;" class="help-block" id='total-amount-full-payment-label'></div>
                            </div>
                                                    </div>
                            </div>
                            <div class="col-md-6">
                                                    <div class="form-group">
                                                        <label class="control-label col-md-5">Total Tenure (months)<span style="color: red">*</span></label>
                                                        <div class="col-md-7">

                                                            <input class="form-control" id="total_tenure_full_payment" type='number' name="total_tenure_full_payment"  >
                                        @if ($errors->has('total_tenure_full_payment'))
                                    <span class="help-block">
                                        <strong>{{ $errors->first('total_tenure_full_payment') }}</strong>
                                    </span>
                                @endif</div>
                                                    </div>
                            </div>
                            <div class="clearfix"></div>
                            <div class="col-md-6">
                                                    <div class="form-group">
                                                        <label class="control-label col-md-5">Discount Percentage <span style="color: red">*</span></label>
                                                        <div class="col-md-7">

                                                            <input id="discount_percentage_full_payment" class="form-control" type='numeric' name="discount_percentage_full_payment"  >
                                        @if ($errors->has('discount_percentage_full_payment'))
                                    <span class="help-block">
                                        <strong>{{ $errors->first('discount_percentage_full_payment') }}</strong>
                                    </span>
                                @endif</div>
                                                    </div>
                            </div>
<div class="col-md-6">
<div class="form-group">
<label class="control-label col-md-5">Return Tenure <span style="color: red">*</span></label>
<div class="col-md-7">
<select class="form-control chosen-select" name="return_tenure_full_payment" id="return_tenure_full_payment">
@if(old('return_tenure_full_payment'))
@if(old('reutrn_tenure_full_payment') == \App\CustomerProperty::monthly)

<option selected="" value="{{\App\CustomerProperty::monthly}}">Monthly</option>
<option value="{{\App\CustomerProperty::quarterly}}">Quarterly</option>
<option value="{{\App\CustomerProperty::semi_annually}}">Semi Annually</option>
<option value="{{\App\CustomerProperty::annually}}">Annually</option>
@elseif(old('reutrn_tenure_full_payment') == \App\CustomerProperty::quarterly)

<option  value="{{\App\CustomerProperty::monthly}}">Monthly</option>
<option selected="" value="{{\App\CustomerProperty::quarterly}}">Quarterly</option>
<option value="{{\App\CustomerProperty::semi_annually}}">Semi Annually</option>
<option value="{{\App\CustomerProperty::annually}}">Annually</option>
@elseif(old('reutrn_tenure_full_payment') == \App\CustomerProperty::semi_annually)

<option value="{{\App\CustomerProperty::monthly}}">Monthly</option>
<option value="{{\App\CustomerProperty::quarterly}}">Quarterly</option>
<option selected="" value="{{\App\CustomerProperty::semi_annually}}">Semi Annually</option>
<option value="{{\App\CustomerProperty::annually}}">Annually</option>
@elseif(old('reutrn_tenure_full_payment') == \App\CustomerProperty::annually)

<option  value="{{\App\CustomerProperty::monthly}}">Monthly</option>
<option value="{{\App\CustomerProperty::quarterly}}">Quarterly</option>
<option value="{{\App\CustomerProperty::semi_annually}}">Semi Annually</option>
<option selected="" value="{{\App\CustomerProperty::annually}}">Annually</option>
@else

<option selected="" value="{{\App\CustomerProperty::monthly}}">Monthly</option>
<option value="{{\App\CustomerProperty::quarterly}}">Quarterly</option>
<option value="{{\App\CustomerProperty::semi_annually}}">Semi Annually</option>
<option value="{{\App\CustomerProperty::annually}}">Annually</option>
@endif
@else

<option selected="" value="{{\App\CustomerProperty::monthly}}">Monthly</option>
<option value="{{\App\CustomerProperty::quarterly}}">Quarterly</option>
<option value="{{\App\CustomerProperty::semi_annually}}">Semi Annually</option>
<option value="{{\App\CustomerProperty::annually}}">Annually</option>
@endif

</select>
@if ($errors->has('return_tenure_full_payment'))
<span class="help-block">
<strong>{{ $errors->first('return_tenure_full_payment') }}</strong>
</span>
@endif</div>
</div>
</div>
                            <div class="clearfix"></div>
                            <div class="col-md-6">
                                                    <div class="form-group">
                                                        <label class="control-label col-md-5">Discount Amount<span style="color: red">*</span></label>
                                                        <div class="col-md-7">

                                                            <input readonly="" class="form-control" id="discount_amount_full_payment" type='number' name="discount_amount_full_payment"  >
                                        @if ($errors->has('discount_amount_full_payment'))
                                    <span class="help-block">
                                        <strong>{{ $errors->first('discount_amount_full_payment') }}</strong>
                                    </span>
                                @endif
                                <div style="color:black;" class="help-block" id='rebate-amount-full-payment-label'></div>
                            </div>
                                                    </div>
                            </div>
                            <div class="col-md-6">
                                                    <div class="form-group">
                                                        <label class="control-label col-md-5">Deduction Amount </label>
                                                        <div class="col-md-7">

                                                            <input id="deduction_amount_full_payment" class="form-control" type='number' name="deduction_amount_full_payment"  >
                                        @if ($errors->has('deduction_amount_full_payment'))
                                    <span class="help-block">
                                        <strong>{{ $errors->first('deduction_amount_full_payment') }}</strong>
                                    </span>
                                @endif</div>
                                                    </div>
                            </div>
                            <div class="clearfix"></div>

                             <div class="col-md-6">
                                                    <div class="form-group">
                                                        <label class="control-label col-md-5">Net Amount after Deduction<span style="color: red">*</span></label>
                                                        <div class="col-md-7">

                                                            <input readonly="" id="net_amount_full_payment" class="form-control" type='number' name="net_amount_full_payment"  >
                                        @if ($errors->has('net_amount_full_payment'))
                                    <span class="help-block">
                                        <strong>{{ $errors->first('net_amount_full_payment') }}</strong>
                                    </span>
                                @endif
                                <div style="color:black;" class="help-block" id='net-amount-full-payment-label'></div>
                            </div>
                                                    </div>
                            </div>

                            <div class="col-md-6">
                                                    <div class="form-group">
                                                        <label class="control-label col-md-5">Per tenure Amount</label>
                                                        <div class="col-md-7">

                                                            <input readonly="" id="per_full_payment" class="form-control" type='number' name="per_full_payment"  >
                                        @if ($errors->has('per_full_payment'))
                                    <span class="help-block">
                                        <strong>{{ $errors->first('per_full_payment') }}</strong>
                                    </span>
                                @endif
                                <div style="color:black;" class="help-block" id='per-full-payment-label'></div>
                            </div>
                                                    </div>
                            </div>


                        </div>
                    </div>
                    </div>


                  <div class="col-lg-12 col-sm-12 col-xs-12" id = "normal">
                        <div class="white-box">
                            <h3 class="box-title">Payment Scheduler</h3>
                            <hr>

                            
                            <div class="col-md-12">

                                <div class="form-group">
                                  <label class="control-label col-md-2">Schedular Type<span style="color: red">*</span></label>


                                    <div class="col-md-10">


                                    <div class="col-md-4">
                                    <input type='radio' onchange="disableAnn(this.value)" name="schedule_type" value='{{\App\CustomerProperty::inst_mon}}' > Monthly
                                    </div>


                                    <div class="col-md-4">
                                        <input type='radio' onchange="enableQuar()"  name="schedule_type" value='{{\App\CustomerProperty::inst_mon_w_quar}}' checked="" > Monthly with Quarterly
                                    </div>


                                    <div class="col-md-4">
                                        <input type='radio' onchange="enableSemi()"  name="schedule_type" value='{{\App\CustomerProperty::inst_mon_w_semi}}' checked="" > Monthly with Semi Annually
                                    </div>


                                    <div class="clearfix"></div>


                                     <div class="col-md-4">
                                        <input type='radio' onchange="enableAnn()"  name="schedule_type" value='{{\App\CustomerProperty::inst_mon_w_ann}}' checked="" > Monthly with Annually
                                    </div>
                                    

                                    <div class="col-md-4">
                                        <input type='radio' onchange="disableAnn(this.value)"  name="schedule_type" value='{{\App\CustomerProperty::inst_bi_mon}}'  > Bi Monthly
                                    </div>


                                    <div class="col-md-4">
                                        <input type='radio' onchange="disableAnn(this.value)"  name="schedule_type" value='{{\App\CustomerProperty::inst_quar}}'  > Quarterly
                                    </div>


                                    <div class="clearfix"></div>

                                    <div class="col-md-4">
                                        <input type='radio' onchange="enableSemi()"  name="schedule_type" value='{{\App\CustomerProperty::inst_quar_w_semi}}'  > Quarterly with SemiAnnually
                                    </div>


                                    <div class="col-md-4">
                                        <input type='radio' onchange="disableAnn(this.value)"  name="schedule_type" value='{{\App\CustomerProperty::inst_semi}}'  > SemiAnnually
                                    </div>


                                    <div class="col-md-4">
                                        <input type='radio' onchange="disableAnn(this.value)"  name="schedule_type" value='{{\App\CustomerProperty::inst_ann}}'  > Annually
                                    </div>

                                    <div class="clearfix"></div>


                                    <div class="col-md-4">
                                        <input type='radio' onchange="enableAnn()"  name="schedule_type" value='{{\App\CustomerProperty::inst_mon_exclude_ann}}'  > Monthly exclude Annually
                                    </div>


                                    <div class="col-md-4">
                                        <input type='radio' onchange="enableQuar()"  name="schedule_type" value='{{\App\CustomerProperty::inst_mon_exclude_quar}}'  > Monthly exclude Quarterly
                                    </div>


                                    <div class="col-md-4">
                                        <input type='radio' onchange="enableSemi()"  name="schedule_type" value='{{\App\CustomerProperty::inst_mon_exclude_semi}}'> Monthly exclude Semi Annually
                                    </div>


                                    <div class="col-md-4">
                                        <input type='radio' onchange="enableSemi()"  name="schedule_type" value='{{\App\CustomerProperty::inst_quar_exclude_semi}}'  > Quarterly exclude SemiAnnually
                                    </div>



                                    <div class="col-md-4">
                                        <input type='radio' onchange="enableCustom(this.value)"  name="schedule_type" value='{{\App\CustomerProperty::inst_custom}}'  > Custom
                                    </div>


                                        @if ($errors->has('schedule_type'))
                                    <span class="help-block">
                                        <strong>{{ $errors->first('schedule_type') }}</strong>
                                    </span>
                                @endif
                            </div>
                                                    </div>
                            </div>
                            <div class='clearfix'></div>
                            <hr>
       

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

                <div class="col-md-12">
                <label class="control-label ">Schedule Start Date <span style="color:red">*</span></label>

                <input type="date" class="form-control" name="schedule_start_date" value="{{date('Y-m-d')}}" id="schedule_start_date" placeholder="Enter Schedule Start Date">
                @if ($errors->has('schedule_start_date'))
                <span class="help-block">
                <strong>{{ $errors->first('schedule_start_date') }}</strong>
                </span>
                @endif

                </div>
                </div>
                </div>



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

                <div class="col-md-12">
                <label class="control-label">Down Payment Date <span style="color:red">*</span></label>

                <input type="date" class="form-control" name="booking_date" value="{{date('Y-m-d')}}" id="booking_date" >
                @if ($errors->has('booking_date'))
                <span class="help-block">
                <strong>{{ $errors->first('booking_date') }}</strong>
                </span>
                @endif
                </div>
                </div>
                </div>



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

                <div class="col-md-12">
                <label class="control-label ">Possession Date </label>
                <input type="date" id='possession_date' class="form-control" name="possession_date" value="{{$possession_date}}" >

                @if ($errors->has('possession_date'))
                <span class="help-block">
                <strong>{{ $errors->first('possession_date') }}</strong>
                </span>
                @endif

                </div>
                </div>
                </div>


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

                <div class="col-md-12">
                <label class="control-label ">Allotment Date </label>
                <input type="date" id='allotment_date' class="form-control" value="{{date('Y-m-d')}}" name="allotment_date"  >

                @if ($errors->has('allotment_date'))
                <span class="help-block">
                <strong>{{ $errors->first('allotment_date') }}</strong>
                </span>
                @endif

                </div>
                </div>
                </div>



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

                <div class="col-md-12">
                <label class="control-label ">Confirmation Date </label>
                <input type="date" id='confirmation_date' value="{{date('Y-m-d')}}" class="form-control" name="confirmation_date"  >

                @if ($errors->has('confirmation_date'))
                <span class="help-block">
                <strong>{{ $errors->first('confirmation_date') }}</strong>
                </span>
                @endif

                </div>
                </div>
                </div>



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

                <div class="col-md-12">
                <label class="control-label ">Development Date </label>
                <input type="date" id='development_date' value="{{date('Y-m-d')}}" class="form-control" name="development_date"  >

                @if ($errors->has('development_date'))
                <span class="help-block">
                <strong>{{ $errors->first('development_date') }}</strong>
                </span>
                @endif

                </div>
                </div>
                </div>



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

                <div class="col-md-12">
                <label class="control-label ">File Processing Date </label>
                <input type="date" id='file_processing_date' value="{{date('Y-m-d')}}" class="form-control" name="file_processing_date"  >

                @if ($errors->has('file_processing_date'))
                <span class="help-block">
                <strong>{{ $errors->first('file_processing_date') }}</strong>
                </span>
                @endif

                </div>
                </div>
                </div>


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

                <div class="col-md-12">
                <label class="control-label ">Registration Date </label>
                <input type="date" id='registration_date' value="{{date('Y-m-d')}}" class="form-control" name="registration_date"  >

                @if ($errors->has('registration_date'))
                <span class="help-block">
                <strong>{{ $errors->first('registration_date') }}</strong>
                </span>
                @endif

                </div>
                </div>
                </div>



                <div class="clearfix"></div>
                <hr>



                <div class="col-md-1"></div>

                <div class="col-md-5">

                <div class="form-group">

                <label class="control-label col-md-4"></label>

                <div class="col-md-4" style="padding-left: 0;padding-right: 0;" >
                <label class="control-label">Possession <span style="color: red">*</span></label>
                <input type="integer" id='possession' class="form-control"  name="possession" value="{{old('possession')}}" placeholder="Enter Possession">
                <div style="color:black;" class="help-block" id='possession-label'></div>
                </div>


                <div class="col-md-4" style="padding-left: 0;padding-right: 0;margin-top: 5.2%;" >
                <div class="input-group">
                <span class="input-group-addon" style="font-size: 16px;background: none;">%</span>
                <input  type="float" class="form-control" id="per_possession" placeholder="%" style="width: 85%;"> 
                </div>   
                </div>


                @if ($errors->has('possession'))
                <span class="help-block">
                <strong>{{ $errors->first('possession') }}</strong>
                </span>
                @endif
                

                </div>

                </div>




                <div class="col-md-5">

                <div class="form-group" style="margin-left: -5rem;">


                <div class="col-md-5" style="padding-right: 0;">
                <label class="control-label">Down Payment <span style="color: red">*</span></label> 
                <input type="integer" id='down-payment'  class="form-control" name="down_payment" value="{{old('down_payment')}}"  placeholder="Down Payment">

                <div style="color:black;" class="help-block" id='down-payment-label'></div>
                </div>


                <div class="col-md-7" style="padding-left: 0;padding-right: 0;margin-top: 4.8%;" >
                <div class="input-group">
                <span class="input-group-addon" style="font-size: 16px;background: none;">%</span>
                <input  type="float" class="form-control" id="per_down_payment" placeholder="%" style="width: 58%;"> 
                </div>   
                </div>


                @if ($errors->has('down_payment'))
                <span class="help-block">
                <strong>{{ $errors->first('down_payment') }}</strong>
                </span>
                @endif
                

                </div>

                </div>


                <div class="col-md-1"></div>


                <div class="clearfix"></div>

                <div class="col-md-1"></div>

                <div class="col-md-5">

                <div class="form-group">

                <label class="control-label col-md-4"></label>

                <div class="col-md-4" style="padding-left: 0;padding-right: 0;" >
                <label class="control-label">Allotment <span style="color: red">*</span></label>
                <input type="integer" id='allotment' class="form-control"  name="allotment" value="{{old('allotment')}}" placeholder="Enter Allotment">
                <div style="color:black;" class="help-block" id='allotment-label'></div>
                </div>


                <div class="col-md-4" style="padding-left: 0;padding-right: 0;margin-top: 5.2%;" >
                <div class="input-group">
                <span class="input-group-addon" style="font-size: 16px;background: none;">%</span>
                <input  type="float" class="form-control" id="per_allotment" placeholder="%" style="width: 85%;"> 
                </div>   
                </div>


                @if ($errors->has('allotment'))
                <span class="help-block">
                <strong>{{ $errors->first('allotment') }}</strong>
                </span>
                @endif
                

                </div>

                </div>




                <div class="col-md-5">

                <div class="form-group" style="margin-left: -5rem;">


                <div class="col-md-5" style="padding-right: 0;">
                <label class="control-label">Confirmation <span style="color: red">*</span></label> 
                <input type="integer" id='confirmation'  class="form-control" name="confirmation" value="{{old('confirmation')}}"  placeholder="Confirmation">
                <div style="color:black;" class="help-block" id='confirmation-label'></div>

                </div>


                <div class="col-md-7" style="padding-left: 0;padding-right: 0;margin-top: 4.8%;" >
                <div class="input-group">
                <span class="input-group-addon" style="font-size: 16px;background: none;">%</span>
                <input  type="float" class="form-control" id="per_confirmation" placeholder="%" style="width: 58%;"> 
                </div>   
                </div>


                @if ($errors->has('confirmation'))
                <span class="help-block">
                <strong>{{ $errors->first('confirmation') }}</strong>
                </span>
                @endif

                </div>

                </div>


                <div class="col-md-1"></div>

                <div class="clearfix"></div>

                <div class="col-md-1"></div>

                <div class="col-md-5">

                <div class="form-group">

                <label class="control-label col-md-4"></label>

                <div class="col-md-4" style="padding-left: 0;padding-right: 0;" >
                <label class="control-label">Booking <span style="color: red">*</span></label>
                <input type="integer" id='booking' class="form-control"  name="booking" value="{{old('booking')}}" placeholder="Enter Booking">
                <div style="color:black;" class="help-block" id='booking-label'></div>
                </div>


                <div class="col-md-4" style="padding-left: 0;padding-right: 0;margin-top: 5.2%;" >
                <div class="input-group">
                <span class="input-group-addon" style="font-size: 16px;background: none;">%</span>
                <input  type="float" class="form-control" id="per_booking" placeholder="%" style="width: 85%;"> 
                </div>   
                </div>


                @if ($errors->has('booking'))
                <span class="help-block">
                <strong>{{ $errors->first('booking') }}</strong>
                </span>
                @endif
                

                </div>

                </div>




                <div class="col-md-5">

                <div class="form-group" style="margin-left: -5rem;">


                <div class="col-md-5" style="padding-right: 0;">
                <label class="control-label">Development <span style="color: red">*</span></label> 
                <input type="integer" id='development'  class="form-control" name="development" value="{{old('development')}}"  placeholder="Development">
                     <div style="color:black;" class="help-block" id='development-label'></div>
                </div>


                <div class="col-md-7" style="padding-left: 0;padding-right: 0;margin-top: 4.8%;" >
                <div class="input-group">
                <span class="input-group-addon" style="font-size: 16px;background: none;">%</span>
                <input  type="float" class="form-control" id="per_development" placeholder="%" style="width: 58%;"> 
                </div>   
                </div>


                @if ($errors->has('development'))
                <span class="help-block">
                <strong>{{ $errors->first('development') }}</strong>
                </span>
                @endif
           

                </div>

                </div>


                <div class="col-md-1"></div>

                <div class="clearfix"></div>

                <div class="col-md-1"></div>




                <div class="col-md-5">

                <div class="form-group">

                <label class="control-label col-md-4"></label>

                <div class="col-md-4" style="padding-left: 0;padding-right: 0;" >
                <label class="control-label">File Processing <span style="color: red">*</span></label>
                <input type="integer" id='file_processing' class="form-control"  name="file_processing" value="{{old('file_processing')}}" placeholder="Enter File Processing">
                 <div style="color:black;" class="help-block" id='file_processing-label'></div>
                </div>


                <div class="col-md-4" style="padding-left: 0;padding-right: 0;margin-top: 5.2%;" >
                <div class="input-group">
                <span class="input-group-addon" style="font-size: 16px;background: none;">%</span>
                <input  type="float" class="form-control" id="per_file_processing" placeholder="%" style="width: 85%;"> 
                </div>   
                </div>


                @if ($errors->has('file_processing'))
                <span class="help-block">
                <strong>{{ $errors->first('file_processing') }}</strong>
                </span>
                @endif
               

                </div>

                </div>




                <div class="col-md-5">

                <div class="form-group" style="margin-left: -5rem;">


                <div class="col-md-5" style="padding-right: 0;">
                <label class="control-label">Registration <span style="color: red">*</span></label> 
                <input type="integer" id='registration'  class="form-control" name="registration" value="{{old('registration')}}"  placeholder="Registration">
                 <div style="color:black;" class="help-block" id='registration-label'></div>
                </div>


                <div class="col-md-7" style="padding-left: 0;padding-right: 0;margin-top: 4.8%;" >
                <div class="input-group">
                <span class="input-group-addon" style="font-size: 16px;background: none;">%</span>
                <input  type="float" class="form-control" id="per_registration" placeholder="%" style="width: 58%;"> 
                </div>   
                </div>


                @if ($errors->has('registration'))
                <span class="help-block">
                <strong>{{ $errors->first('registration') }}</strong>
                </span>
                @endif
               

                </div>

                </div>


                        <div class="col-md-1"></div>


                        <div class="clearfix"></div>

                        <div id = "auto" style="margin-top: 2%;">

                        <div class="col-md-10">
                        <div class="form-group">
                        <label class="control-label col-md-3">Per Installment <span style="color: red">*</span></label>
                        <div class="col-md-9">

                        <input style="display: inline-block;width: 23%;" type="integer" id='installment' class="form-control" name="installment" value="{{old('installment')}}"  placeholder="Per installment">
                        <span>%</span>
                        <input  type="float" class="form-control" id="per_installment" placeholder="%" style="width: 15%;display: inline-block;"> 




                        <input style="display: inline-block;width: 28%;" type="integer" readonly="" id='total_installment' class="form-control" name="total_installment" value="{{old('total_installment')}}" placeholder="Total amount">

                        <span>%</span>
                        <input  type="float" class="form-control" readonly id="per_total_installment" placeholder="%" style="width: 10%;display: inline-block;"> 


                        <!-- <label class="control-label col-md-5">Total Installments (Months) <span style="color: red">*</span></label> -->
                        <input type="integer" style="width: 10.5%;display: inline-block;" id='total-months' class="form-control" name="installment_plan" value="{{old('installment_plan')}}"  placeholder="Count">

                        <div style="display: inline-block;width: 49%;color:black;" class="help-block" id='installment-label'></div>
                        <div style="display: inline-block;width: 49%;color:black;" class="help-block" id='total-installment-label'></div>
                        @if ($errors->has('installment'))
                        <span class="help-block">
                        <strong>{{ $errors->first('installment') }}</strong>
                        </span>
                        @endif

                        @if ($errors->has('installment_plan'))
                        <span class="help-block">
                        <strong>{{ $errors->first('installment_plan') }}</strong>
                        </span>
                        @endif
                        <div style="color:black;" class="help-block" id='total-months-label'></div>
                        </div>


                        </div>
                        </div>


                        <div class="col-md-10" id="ann_div">
                        <div class="form-group">
                        <label class="control-label col-md-3">Annual Installments <br> <span style="color: red">*</span></label>
                        <div class="col-md-9">
                        <input style="display: inline-block;width: 43%;" type="integer" id='annual-installment' class="form-control" name="annual_installment" value="{{old('annual_installment')}}" id="exampleInputEmail1" placeholder=" Annual">

                        <input style="display: inline-block;width: 40%;" type="integer"  id='total_annual_installment' class="form-control" name="total_annual_installment" value="{{old('total_annual_installment')}}" id="exampleInputEmail1" placeholder="Total Annual">
                        <input style="display: inline-block;width: 15%;" type="integer" id='total_annual_installment_count' class="form-control" name="total_annual_installment_count" value="{{old('total_annual_installment_count')}}" id="exampleInputEmail1" placeholder="Count">
                        <div style="display: inline-block;width: 40%;color:black;" class="help-block"  id='annual-installment-label'></div>
                        <div style="display: inline-block;width: 40%;color:black;" class="help-block"  id='total-annual-installment-label'></div>
                        @if ($errors->has('annual_installment'))
                        <span class="help-block">
                        <strong>{{ $errors->first('annual_installment') }}</strong>
                        </span>
                        @endif

                                </div>
                            </div>
                        </div>

                        <div class="col-md-10" id="semi_div" style="display: none">
                        <div class="form-group">
                        <label class="control-label col-md-3">Semi Installments <br> <span style="color: red">*</span></label>
                        <div class="col-md-9">
                        <input style="display: inline-block;width: 43%;" type="integer" id='semi-installment' class="form-control" name="semi_installment" value="{{old('semi_installment')}}" id="exampleInputEmail1" placeholder=" Semi">

                        <input style="display: inline-block;width: 40%;" type="integer" id='total_semi_installment' class="form-control" name="total_semi_installment" value="{{old('total_semi_installment')}}" id="exampleInputEmail1" placeholder="Total Semi Annually">
                        <input style="display: inline-block;width: 15%;" type="integer" id='total_semi_installment_count' class="form-control" name="total_semi_installment_count" value="{{old('total_semi_installment_count')}}" id="exampleInputEmail1" placeholder="Count">
                        <div style="display: inline-block;width: 40%;color:black;" class="help-block"  id='semi-installment-label'></div>
                        <div style="display: inline-block;width: 40%;color:black;" class="help-block"  id='total-semi-installment-label'></div>
                        @if ($errors->has('semi_installment'))
                        <span class="help-block">
                        <strong>{{ $errors->first('semi_installment') }}</strong>
                        </span>
                        @endif

                        </div>
                        </div>
                        </div>

                        <div class="col-md-10" id="bi_mon_div" style="display: none;">
                        <div class="form-group">
                        <label class="control-label col-md-3">Bi Monthly Installments <br> <span style="color: red">*</span></label>
                        <div class="col-md-9">
                        <input style="display: inline-block;width: 40%;" type="integer" id='bi-mon-installment' class="form-control" name="bi_mon_installment" value="{{old('bi_mon_installment')}}" id="exampleInputEmail1" placeholder=" Bi Monthly">

                        <input style="display: inline-block;width: 40%;" type="integer" readonly="" id='total_bi_mon_installment' class="form-control" name="total_bi_mon_installment" value="{{old('total_bi_mon_installment')}}" id="exampleInputEmail1" placeholder="Total Bi Monthly">
                        <input style="display: inline-block;width: 15%;" type="integer" readonly="" id='total_bi_mon_installment_count' class="form-control" name="total_bi_mon_installment_count" value="{{old('total_bi_mon_installment_count')}}" id="exampleInputEmail1" placeholder="Count">
                        <div style="display: inline-block;width: 40%;color:black;" class="help-block"  id='bi-mon-installment-label'></div>
                        <div style="display: inline-block;width: 40%;color:black;" class="help-block"  id='total-bi-mon-installment-label'></div>
                        @if ($errors->has('bi_mon_installment'))
                        <span class="help-block">
                        <strong>{{ $errors->first('bi_mon_installment') }}</strong>
                        </span>
                        @endif

                            </div>
                        </div>
                        </div>

                            <div class="col-md-10" id="quar_div" style="display: none;">
                            <div class="form-group">
                            <label class="control-label col-md-3">Quarterly Installments <br> <span style="color: red">*</span></label>
                            <div class="col-md-9">
                            <input style="display: inline-block;width: 43%;" type="integer" id='quarterly-installment' class="form-control" name="quarterly_installment" value="{{old('quarterly_installment')}}" id="exampleInputEmail1" placeholder=" Quarterly">

                            <input style="display: inline-block;width: 40%;" type="integer"  id='total_quarterly_installment' class="form-control" name="total_quarterly_installment" value="{{old('total_quarterly_installment')}}" id="exampleInputEmail1" placeholder="Total Quarterly">
                            <input style="display: inline-block;width: 15%;" type="integer" readonly="" id='total_quarterly_installment_count' class="form-control" name="total_quarterly_installment_count" value="{{old('total_quarterly_installment_count')}}" id="exampleInputEmail1" placeholder="Count">
                            <div style="display: inline-block;width: 40%;color:black;" class="help-block"  id='quarterly-installment-label'></div>
                            <div style="display: inline-block;width: 40%;color:black;" class="help-block"  id='total-quarterly-installment-label'></div>
                            @if ($errors->has('quarterly_installment'))
                            <span class="help-block">
                            <strong>{{ $errors->first('quarterly_installment') }}</strong>
                            </span>
                            @endif

                            </div>
                            </div>
                            </div>




                            <div class="col-md-6">
                            <div class="form-group">
                            <label class="control-label col-md-5">Remaining Amount</label>
                            <div class="col-md-7">

                            <input readonly="" type="integer" id='remaining_amount' class="form-control" value="{{old('remaining_amount')}}"  placeholder="Remaining amount">
                            <br>
                           

                            Adjust to <br>
                            <ul type="none">
                            <li><input type="radio" id="adjust" name="adjust" onclick="adjustAmount(1)" > Installment</li>
                            <!-- <li><input type="radio" name="adjust" id="adjust" onclick="adjustAmount(2)"> Semi-Installment</li> -->
                            <li><input type="radio" name="adjust" id="adjust" onclick="adjustAmount(3)"> Down Payment</li>
                            <li><input type="radio" name="adjust" id="adjust" onclick="adjustAmount(4)"> Possession</li>

                            <li><input type="radio" name="adjust" id="adjust" onclick="adjustAmount(5)"> Allotment</li>
                            <li><input type="radio" name="adjust" id="adjust" onclick="adjustAmount(6)"> Confirmation</li>

                            <li><input type="radio" name="adjust" id="adjust" onclick="adjustAmount(7)"> Booking</li>
                            <li><input type="radio" name="adjust" id="adjust" onclick="adjustAmount(8)"> Development</li>

                            <li><input type="radio" name="adjust" id="adjust" onclick="adjustAmount(9)"> File Processing</li>
                            <li><input type="radio" name="adjust" id="adjust" onclick="adjustAmount(10)"> Registration</li>

                            </ul>

                            <div style="color:black;" class="help-block" id='remaining-amount-label'></div>
                            </div>
                            </div>
                            </div>

                            <div class="clearfix"></div>
                            <div class="input_fields_wrap1">
                            <!-- <button type="button" style="float: left!important;" class="btn btn-primary add_field_button" >Add Payment</button> -->
                            <div class="clearfix"></div>
                            </div>
                            <div class="clearfix"></div>


                            </div>

                            <!---Custom-->
                            <div id="custom" style="display: none;">

                            <div class="col-md-10">
                            <div class="form-group">
                            <label class="control-label col-md-3">Installment <span style="color: red">*</span></label>
                            <div class="col-md-9">

                            <input style="display: inline-block;width: 43%;" type="date" id='installment' class="form-control" name="custom_date[]"  placeholder="Date">

                            <input style="display: inline-block;width: 49%;" type="integer"  class="form-control" name="custom_amount[]" onkeyup="customPayment()"  placeholder="Amount">
                            </div>
                            </div>
                            </div>


                            <div class="clearfix"></div>
                            <div class="input_fields_wrap2 col-md-10">

                            <div class="clearfix"></div>
                            </div>
                            <div class="clearfix"></div>
                            <button type="button" class="btn btn-primary add_field_button2" >Add Installment</button>&nbsp;&nbsp;&nbsp;
                            <input style="display: inline-block;width: 30%;" type="integer" readonly="" id='custome_rem' class="form-control"   placeholder="Remaining amount">
                            <div class="clearfix"></div>
                            </div>

                            <!-- Custom End -->

                            </div>
                            </div>
                            <!--receipt module -->




                            <div class="col-md-12" style="height: 70px;">
                            <button style="float: right;" type="submit" class="btn btn-info  waves-effect waves-light btn-lg">Save</button>
                            </div>


                            </div>
                            </div>


                            </form>
                            </div>
                            </div>
                            <input type='hidden' id="possession_per">
                            <input type='hidden' id="down_payment_per">
                            <input type='hidden' id="total_month_per">
                            <input type='hidden' id="annual_installment_per">
                            <input type='hidden' id="monthly_installment_per">
                            <input type="hidden" id="down_payment_dis">
                            <input type="hidden" name="percentage" id="percentage">
                            <input type="hidden" name="rebate_in_percent" id="rebate_in_percent">

@stop

@section('js')
<script>
$( document ).ready(function() {
    $("#unit_number").val('{{$property->inventory->id}}').change();
});

  function hideFields(self)
    {

    if (self === 'company') 
    {
        $('#father_name').val('null');
        $('#father_name_parent').hide();
        $('#passport_no').hide()
        $('#date_of_birth').html('Date of Incorporation <span style="color: red">*</span>')
        $('#cnic_no').html('Incorporation no <span style="color: red">*</span>')
        $('#mobile_number').html('Phone Number <span style="color: red">*</span>')
        $('#res_number').hide()
        $('#phone_number').hide()
        $('#photo_s').hide()
        $('#mailing_label').html('Company Registered Address <span style="color: red">*</span>')
        $('#permanent_address').val($('#mailing_address').val())
        $('#permanent_add').hide()
        $('#occupations').html('Type Of Company <span style="color: red">*</span>')
        $('#imgs_label').html('Certificate  <span style="color: red">*</span>')
        $('#type').val(1)
    }

            if (self === 'individual') 
            {
                $('#type').val(0)
                $('#father_name').val('');
                $('#father_name_parent').show();
                $('#passport_no').show()
                $('#date_of_birth').html('Date of Birth <span style="color: red">*</span>')
                $('#cnic_no').html('Cnic <span style="color: red">*</span>')
                $('#mobile_number').html('Mobile Number <span style="color: red">*</span>')
                $('#res_number').show()
                $('#photo_s').show()
                $('#phone_number').show()
                $('#mailing_label').html('Mailing Address <span style="color: red">*</span>')
                $('#permanent_add').show()
                $('#occupations').html('Occupation <span style="color: red">*</span>')
                $('#imgs_label').html('Passport size photo  <span style="color: red">*</span>')
            }
        

            return false;
        }

      function validateCnic(self) 
        {
           var cnic = $(self).val().replaceAll('-', '');

        $.ajaxSetup({
        headers: {
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
          }
        });

        $.ajax({
        url:"{{ route('validate.dnfbp.cnic') }}",
        method:'POST',
        dataType:'json',
        data: {cnic:cnic},
        success:function(data)
        {
          if (data.response == 'invalid') 
          {
                $(self).closest('.form-group').find('#cnic_error1').show();
          }

        }
        })



        return false;
        }

    //multiple nominees
    $(document).ready(function() {
    var max_fields      = 5; //maximum input boxes allowed
    var wrapper         = $(".input_fields_wrap4"); //Fields wrapper
   
    var add_button      = $(".add_field_button4"); //Add button ID

    var x = 1; //initlal text box count
    $(add_button).click(function(e){ //on add input button click
        e.preventDefault();
        if(x < max_fields){ //max input box allowed
            x++; //text box increment
            $(wrapper).append('<div><div class="col-md-6"><div class="form-group"><label class="control-label col-md-3">Nominee Name <span style="color: red">*</span></label><div class="col-md-9"><input type="text" class="form-control" name="nominee_name_1[]" value="" id="exampleInputuname" placeholder="Enter Name"></div></div></div><div class="col-md-6"><div class="form-group"><label class="control-label col-md-3">S/O, D/O, W/O.<span style="color: red">*</span></label><div class="col-md-9"><input  type="text" class="form-control" name="nominee_so_do_wo_1[]" value="" id="exampleInputuname" placeholder="Enter Father Name"></div></div></div><div <div class="form-group"><label class="control-label col-md-1">CNIC</label><div class="col-md-5"><input type="text"  class="form-control" value="" name="nominee_cnic_1[]" id="nominee_cnic"  placeholder="XXXXXXXXXXXXX" onfocusout="return validateCnic(this)" ></div><div class="col-md-12" style="color: red;display: none;" id="cnic_error1">This Customer cnic is found in list of DNFBP. You cant add this Customer record.</div></div></div><div class="col-md-6"><div class="form-group"><label class="control-label col-md-3">Passport No.</label><div class="col-md-9"><input type="text"  class="form-control" value="" name="nominee_passport_no_1[]" id="nominee_passport_no"  placeholder="XXXXXXXXX" ></div></div></div><div class="clearfix"></div><div class="col-md-6"><div class="form-group"><label class="control-label col-md-3">Relation With Applicant <span style="color: red">*</span></label><div class="col-md-9"><input type="text" class="form-control" name="nominee_relation_1[]" value=""  placeholder="Enter Relation"></div></div></div><div class="col-md-6"><div class="form-group"><label class="control-label col-md-3">Email</label><div class="col-md-9"><input type="text" class="form-control" name="nominee_email_1[]" value=""  placeholder="Enter Email"></div></div></div><div class="clearfix"></div><div class="col-md-6"><div class="form-group"><label class="control-label col-md-3">Mobile Number </label><div class="col-md-9"><input type="text" class="form-control" name="nominee_mobile_number_1[]" value=""  placeholder="Enter Mobile Number"></div></div></div><div class="col-md-6"><div class="form-group"><label class="control-label col-md-3">Res. Number </label><div class="col-md-9"><input type="text" class="form-control" name="nominee_res_number_1[]" value=""  placeholder="Enter Res Number"></div></div></div><div class="clearfix"></div><div class="col-md-6"><div class="form-group"><label class="control-label col-md-3">Phone Number </label><div class="col-md-9"><input type="text" class="form-control" name="nominee_phone_number_1[]" value=""  placeholder="Enter Phone Number"></div></div></div><a href="#"class="remove_field">Remove</a>'); //add input box

        }
    });

    $(wrapper).on("click",".remove_field", function(e){ //user click on remove text
        e.preventDefault(); $(this).parent('div').remove(); x--;
    })
    
});

    $(document).ready(function() {
    var max_fields      = 2; //maximum input boxes allowed
    var wrapper         = $(".input_fields_wrap3"); //Fields wrapper
    
    var add_button      = $(".add_field_button3"); //Add button ID

    var x = 1; //initlal text box count
    $(add_button).click(function(e){ //on add input button click
        e.preventDefault();
        if(x < max_fields){ //max input box allowed
            x++; //text box increment
            $(wrapper).append('<div><div class="col-md-6"><div class="form-group"><label class="control-label col-md-3">Nominee Name <span style="color: red">*</span></label><div class="col-md-9"><input type="text" class="form-control" name="nominee_name_n" value="" id="exampleInputuname" placeholder="Enter Name"></div></div></div><div class="col-md-6"><div class="form-group"><label class="control-label col-md-3">S/O, D/O, W/O.<span style="color: red">*</span></label><div class="col-md-9"><input  type="text" class="form-control" name="nominee_so_do_wo_n" value="" id="exampleInputuname" placeholder="Enter Father Name"></div></div></div><div class="clearfix"></div><div class="col-md-6"><div class="form-group"><label class="control-label col-md-3">CNIC</label><div class="col-md-9"><input type="text"  class="form-control" value="" name="nominee_cnic_n" id="nominee_cnic"  placeholder="XXXXXXXXXXXXX"  onfocusout="return validateCnic(this)"><input type="radio" name="nominee_cnic_flag_n" value="1"> Locally<input type="radio" name="nominee_cnic_flag_n" value="2"> Internationally</div><div style="color: red;display: none;" class="col-md-12"  id="cnic_error1">This Customer cnic is found in list of DNFBP. You cant add this Customer record. </div></div></div> <div class="col-md-6"><div class="form-group" id="nominee_address"><label for="address" class="col-sm-3 control-label" id="nominee_address">Nominee Address <span style="color: red">*</span></label><div class="col-sm-9"><div class="input-group"><div class="input-group-addon"><i class="icon-location-pin"></i></div><textarea class="form-control" id="nominee_address" name="nominee_address" ></textarea></div></div> </div></div><div class="col-md-6"><div class="form-group"><label class="control-label col-md-3">Passport No.</label><div class="col-md-9"><input type="text"  class="form-control" value="" name="nominee_passport_no_n" id="nominee_passport_no"  placeholder="XXXXXXXXX" ></div></div></div><div class="clearfix"></div><div class="col-md-6"><div class="form-group"><label class="control-label col-md-3">Relation With Applicant <span style="color: red">*</span></label><div class="col-md-9"><input type="text" class="form-control" name="nominee_relation_n" value=""  placeholder="Enter Relation"></div></div></div><div class="col-md-6"><div class="form-group"><label class="control-label col-md-3">Email</label><div class="col-md-9"><input type="text" class="form-control" name="nominee_email_n" value=""  placeholder="Enter Email"></div></div></div><div class="clearfix"></div><div class="col-md-6"><div class="form-group"><label class="control-label col-md-3">Mobile Number </label><div class="col-md-9"><input type="text" class="form-control" name="nominee_mobile_number_n" value=""  placeholder="Enter Mobile Number"></div></div></div><div class="col-md-6"><div class="form-group"><label class="control-label col-md-3">Res. Number </label><div class="col-md-9"><input type="text" class="form-control" name="nominee_res_number_n" value=""  placeholder="Enter Res Number"></div></div></div><div class="clearfix"></div><div class="col-md-6"><div class="form-group"><label class="control-label col-md-3">Phone Number </label><div class="col-md-9"><input type="text" class="form-control" name="nominee_phone_number_n" value=""  placeholder="Enter Phone Number"></div></div></div><a href="#"class="remove_field">Remove</a>'); //add input box

        }
    });

    $(wrapper).on("click",".remove_field", function(e){ //user click on remove text
        e.preventDefault(); $(this).parent('div').remove(); x--;
    })
    
});


    //multiple dealers
    $(document).ready(function() {
    var max_fields      = 5; //maximum input boxes allowed
    var wrapper         = $(".input_fields_wrap5"); //Fields wrapper
   
    var add_button      = $(".add_field_button5"); //Add button ID

    var x = 1; //initlal text box count
    $(add_button).click(function(e){ //on add input button click
        e.preventDefault();
        if(x < max_fields){ //max input box allowed
            x++; //text box increment
            $(wrapper).append('<div><hr><div class="col-md-6"><div class="form-group"><label class="control-label col-md-4">Authorized Dealer <span style="color: red">*</span></label><div class="col-md-8"><select class="form-control chosen-select" name="dealer_id[]" ><option value="" >None</option>@foreach($dealers as $dealer)@foreach($dealer as $d)@if($loop->first)<optgroup label="{{$dealerTypes[$d->dealer_type_id]}}">@endif<option value="{{$d->id}}" >{{$d->name}} ( {{$d->percentage}} %)</option>@endforeach</optgroup>@endforeach</select></div></div></div><br><div class="clearfix"></div><div class="col-md-8"><div class="form-group"><label class="control-label col-md-6">Rebate <span style="color: red">*</span></label><div class="col-md-6" ><div class="input-group"><span class="input-group-addon" style="font-size: 10px;">PKR</span><input id="total_rebate' + x + '" type="text" class="form-control total_rebate" name="total_rebate[]" value="0" ></div></div></div></div> <div class="clearfix"></div> <a href="#"class="remove_field">Remove</a>'); //add input box

        }
    });

    $(wrapper).on("click",".remove_field", function(e){ //user click on remove text
        e.preventDefault(); $(this).parent('div').remove(); x--;
    })
    
});


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

        downPC = $('#d_rebate_p1').val();
        rebate = $('#total_rebate1').val();

        $('#d_rebate1').val(Math.round((downPC * rebate) / 100));

        insPC = $('#i_rebate_p1').val();
        $('#i_rebate1').val(Math.round((insPC * rebate )/ 100));

});

$('#d_rebate1').keyup(function() {
    downVC = $('#d_rebate1').val();
    rebate = $('#total_rebate1').val(); 

    $('#d_rebate_p1').val(Math.round((downVC * 100 )/ rebate));
    $('#i_rebate_p1').val(Math.round(100 -  $('#d_rebate_p1').val()));

    insPC = $('#i_rebate_p1').val();
    rebate = $('#total_rebate1').val();

    $('#i_rebate1').val(Math.round((insPC * rebate )/ 100));

});

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

    downPC = $('#d_rebate_p1').val();

    rebate = $('#total_rebate1').val();

    $('#d_rebate1').val(Math.round((downPC * rebate) / 100));
    $('#i_rebate_p1').val(Math.round(100 - downPC));

    insPC = $('#i_rebate_p1').val();
    rebate = $('#total_rebate1').val();

    $('#i_rebate1').val(Math.round((insPC * rebate )/ 100));

});

    

function openRebate(val,id) {

    if(val) {
        $('.preloader').fadeIn();
        var data = { 'id': val};
        $.get('/getDealerById', data, function (data) {
            amount = $('#total-amount').val();
            if(data.rebate_in_percent)
            rebate = (data.percentage * amount ) / 100;
            else
              rebate = data.percentage;  
            $('#percentage' + id).val(data.percentage);
            $('#rebate_in_percent' + id).val(data.rebate_in_percent);
            $('#total_rebate' + id).val(rebate);
            $('#d_rebate' + id).val(Math.round((rebate * data.down_payment_rebate ) / 100));
            $('#i_rebate' + id).val(Math.round((rebate * data.installment_rebate)/ 100));
            $('#d_rebate_p' + id).val(Math.round(data.down_payment_rebate));
            $('#i_rebate_p' + id).val(Math.round(data.installment_rebate));
            $('#p_rebate' + id).val(Math.round(data.paid_installment_rebate));
        });
        rebate = 'rebate' + id;
        document.getElementById(rebate).style.display = 'block';
        $('.preloader').fadeOut();
    }
    else
        document.getElementById('rebate').style.display = 'none';
}

$(document).ready(function() {
    var max_fields = 50; //maximum input boxes allowed
    var wrapper = $(".input_fields_wrap1"); //Fields wrapper
    var wrapper1 = $(".input_fields_wrap"); //Fields wrapper
    var add_button = $(".add_field_button"); //Add button ID

    var x = 1; //initlal text box count
    $(add_button).click(function(e) { //on add input button click
        e.preventDefault();
        if(x < max_fields){ //max input box allowed
            x++; //text box increment
            $(wrapper).append('<div class="clearfix"><br><div class="form-group"><label class="control-label col-md-3">Add Extra Payment<br> <span style="color: red">*</span></label><div class="col-md-9"><input style="display: inline-block;width: 49%;" onkeyup="addPayment()" type="integer" class="form-control" name="add_amount[]" placeholder="Amount"><input style="display: inline-block;width: 49%;" type="date" class="form-control"  name="add_date[]"  placeholder=""></div> </div><a href="#" class="remove_field">Remove</a>'); //add input box
            $(".bdpk").datepicker(
            {
                dateFormat: "dd-mm-yy"
            });
        }
    });

    $(wrapper).on("click",".remove_field", function(e){ //user click on remove text
        e.preventDefault(); $(this).parent('div').remove(); x--;
    })
    $(wrapper1).on("click",".remove_field", function(e){ //user click on remove text
        e.preventDefault(); $(this).parent('div').remove(); x--;
    })
});

//custom
$(document).ready(function() {
    var max_fields      = 100; //maximum input boxes allowed
    var wrapper         = $(".input_fields_wrap2"); //Fields wrapper
    var wrapper1         = $(".input_fields_wrap2"); //Fields wrapper
    var add_button      = $(".add_field_button2"); //Add button ID

    var x = 1; //initlal text box count
    $(add_button).click(function(e){ //on add input button click
        e.preventDefault();
        if(x < max_fields){ //max input box allowed
            x++; //text box increment
            $(wrapper).append('<div class="clearfix"><br><div class="form-group"><label class="control-label col-md-3">Installment-'+ x +'<br> <span style="color: red">*</span></label><div class="col-md-9"><input style="display: inline-block;width: 43%;margin-right: 4px;" type="date" class="form-control" name="custom_date[]" placeholder="Date"><input style="display: inline-block;width: 49%;" type="integer" class="form-control" name="custom_amount[]" onkeyup="customPayment()"  placeholder="Amount"></div> </div><a href="#" class="remove_field">Remove</a>'); //add input box
            $(".bdpk").datepicker(
            {
                dateFormat: "dd-mm-yy"
            });
        }
    });

    $(wrapper).on("click",".remove_field", function(e){ //user click on remove text
        e.preventDefault(); $(this).parent('div').remove(); x--;
    })
    $(wrapper1).on("click",".remove_field", function(e){ //user click on remove text
        e.preventDefault(); $(this).parent('div').remove(); x--;
    })
});

//end custom

function customPayment() {

    net_amount = parseInt($('#net_amount').val());
    down_payment = parseInt($('#down-payment').val());
    possession = parseInt($('#possession').val());
    
    var cus_amount = 0;

    $("input[name='custom_amount[]']").each(function() {
        if(!this.value){
            cus_amount += 0;
        }
        else {
            cus_amount += parseInt($(this).val());
        }
        
    });

    remaining_amount = net_amount - down_payment - possession - cus_amount;

    $('#custome_rem').val(Math.round(remaining_amount));

}

function addPayment() {

    net_amount = parseInt($('#net_amount').val());
    if($('#down-payment').val())
        down_payment = parseInt($('#down-payment').val());
    else
        down_payment = 0;
    possession = parseInt($('#possession').val());
    monthly_installment = parseInt($('#total_installment').val());
    annual_installment = 0;

    val = parseInt($('input[name="schedule_type"]:checked').val());
    if(val =={{\App\CustomerProperty::inst_mon_w_semi}}) {
        annual_installment = $('#total_semi_installment').val();
    }
    else if(val =={{\App\CustomerProperty::inst_mon_w_ann}}) {
        annual_installment = $('#total_annual_installment').val();
    }
    else if(val =={{\App\CustomerProperty::inst_mon_w_quar}}) {
        annual_installment = $('#total_quarterly_installment').val();
    }


    var add_amount = 0;

    $("input[name='add_amount[]']").each(function() {
        if(!this.value){
            add_amount += 0;
        }
        else {
            add_amount += parseInt($(this).val());
        }
        
    });


    remaining_amount = net_amount - down_payment - possession - monthly_installment - annual_installment - add_amount;

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

    var radioValue = $("input[name='schedule_type']:checked").val();

    if (radioValue == '{{\App\CustomerProperty::inst_custom}}') 
    {
        remaining_amount = remaining_amount + parseInt($('#custome_rem').val())
    }
    $('#custome_rem').val(Math.round(remaining_amount));
}


function receiptBox(){
    if($('#receipt').prop("checked") == true) {
        $('#receipt_div').css('display','block');
    }
    else if($('#receipt').prop("checked") == false) {
        $('#receipt_div').css('display','none');
    }
}

function fullPaymentBox(){
            if($('#discount_full_payment').prop("checked") == true){
                $('#discount_div').css('display','block');
            }
            else if($('#discount_full_payment').prop("checked") == false){
                $('#discount_div').css('display','none');
            }
        }
    
function changeFunc(a){
    if(a == {{\App\Receipt::cash}}) {
        $('#bank').css('display', 'none');
        $('#company-bank').css('display', 'none');
        $('#cheque').css('display', 'none');
        $('#adjustment').css('display', 'none');
    }
    else if(a == {{\App\Receipt::bank}}) {
        $('#bank').css('display', 'block');
        $('#company-bank').css('display', 'block');
        $('#cheque').css('display', 'none');
        $('#adjustment').css('display', 'none');
    }
    else if(a == {{\App\Receipt::cheque}}) {
        $('#bank').css('display', 'block');
        $('#company-bank').css('display', 'block');
        $('#cheque').css('display', 'block');
        $('#adjustment').css('display', 'none');
    }
    else if(a == {{\App\Receipt::adjustment}}) {
        $('#bank').css('display', 'none');
        $('#company-bank').css('display', 'none');
        $('#cheque').css('display', 'none');
        $('#adjustment').css('display', 'block');
    }
}
</script>


<script>
    $('input[type="checkbox"]').click(function() {
        if($(this).prop("checked") == true) {
            $('textarea#permanent_address').val($('textarea#mailing_address').val());
        }
        else if($(this).prop("checked") == false) {
            $('textarea#permanent_address').val('');
        }
    });

    function updateSchedule() {

        var type =  $('#type').val();
        var size = $('#size').val();
        var floor =  $('#floor').val();

        var data = {'type':type,'size':size,'floor':floor};
        $.get('/statement/updateSchedule',data,function(data){
           // console.log(data);
            if(data) {
               $('#cost-amount').val( Math.round(data.cost_amount));
               $('#down-payment').val( Math.round(data.down_payment / 100 * data.cost_amount));
               $('#possession').val( Math.round(data.possession / 100 * data.cost_amount));
                $('#annual-installment').val( Math.round(data.annual_installment / 100 * data.cost_amount / 4));
               $('#total-months').val( Math.round(data.total_months));
               $('#total_annual_installment_count').val( Math.round(data.total_months / 12));
               $('#total_semi_installment_count').val( Math.round(data.total_months / 6));
               $('#total_quarterly_installment_count').val( Math.round(data.total_months / 3));
               $('#total_bi_mon_installment_count').val( Math.round(data.total_months / 2));
               $('#installment').val( Math.round(data.installment / 100 * data.cost_amount / data.total_months));

               updateCurrency();
            }

        });

    }

   </script>


   <script>

    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'];

//update the cost label
   //update the total months label
    $("#total-months").keyup(function(){

   $('#installment').val(Math.round(parseInt($("#total_installment").val()  / parseInt($('#total-months').val() ))));

   num = $("#installment").val();
   $("#installment-label").text(number2TextConversion(num));


    });



//update the down payemnt label

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

    

    net_amount = parseInt($('#net_amount').val());

    if($('#down-payment').val())
    down_payment = parseInt($('#down-payment').val());
    else
    down_payment = 0;
    registration = parseInt($('#registration').val());
    possession = parseFloat($('#possession').val());
    $('#per_registration').val(((registration / net_amount) * 100).toFixed(2));
    monthly_installment = parseInt($('#total_installment').val());
    annual_installment = 0;

    num=$("#registration").val();
    $("#registration-label").text(number2TextConversion(num));

    val = parseInt($('input[name="schedule_type"]:checked').val());
    if(val =={{\App\CustomerProperty::inst_mon_w_semi}}) {
    annual_installment = $('#total_semi_installment').val();
    }
    else if(val =={{\App\CustomerProperty::inst_mon_w_ann}}) {
    annual_installment = $('#total_annual_installment').val();
    }
    else if(val =={{\App\CustomerProperty::inst_mon_w_quar}}) {
    annual_installment = $('#total_quarterly_installment').val();
    }

    var add_amount = 0;

    $("input[name='add_amount[]']").each(function() {
    if(!this.value){
    add_amount += 0;
    }
    else {
    add_amount += parseInt($(this).val());
    }

    });


    allotment = parseFloat($('#allotment').val());
    confirmation = parseFloat($('#confirmation').val());
    booking = parseFloat($('#booking').val());
    development = parseFloat($('#development').val());
    file_processing = parseFloat($('#file_processing').val());
    registration = parseFloat($('#registration').val());

    remaining_amount = net_amount - down_payment - possession - monthly_installment - annual_installment - add_amount - allotment - confirmation - booking - development - file_processing - registration;

    $('#remaining_amount').val(remaining_amount);
var radioValue = $("input[name='schedule_type']:checked").val();

    if (radioValue == '{{\App\CustomerProperty::inst_custom}}') 
    {
        remaining_amount = remaining_amount + parseInt($('#custome_rem').val())
    }
    $('#custome_rem').val(Math.round(remaining_amount));
    });



    //update the down payemnt label

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

    

    net_amount = parseInt($('#net_amount').val());
    if($('#down-payment').val())
        down_payment = parseInt($('#down-payment').val());
    else
        down_payment = 0;
    per_registration = parseFloat($('#per_registration').val());
    possession = parseFloat($('#possession').val());

    $('#registration').val(percentage(net_amount , per_registration));

    monthly_installment = parseInt($('#total_installment').val());
    annual_installment = 0;

    num=$("#registration").val();
    $("#registration-label").text(number2TextConversion(num));

    val = parseInt($('input[name="schedule_type"]:checked').val());
    if(val =={{\App\CustomerProperty::inst_mon_w_semi}}) {
        annual_installment = $('#total_semi_installment').val();
    }
    else if(val =={{\App\CustomerProperty::inst_mon_w_ann}}) {
        annual_installment = $('#total_annual_installment').val();
    }
    else if(val =={{\App\CustomerProperty::inst_mon_w_quar}}) {
        annual_installment = $('#total_quarterly_installment').val();
    }

    var add_amount = 0;

    $("input[name='add_amount[]']").each(function() {
        if(!this.value){
            add_amount += 0;
        }
        else {
            add_amount += parseInt($(this).val());
        }
        
    });

   allotment = parseFloat($('#allotment').val());
    confirmation = parseFloat($('#confirmation').val());
    booking = parseFloat($('#booking').val());
    development = parseFloat($('#development').val());
    file_processing = parseFloat($('#file_processing').val());
    registration = parseFloat($('#registration').val());


    remaining_amount = net_amount - down_payment - possession - monthly_installment - annual_installment - add_amount - allotment - confirmation - booking - development - file_processing - registration;


    $('#remaining_amount').val(remaining_amount);
var radioValue = $("input[name='schedule_type']:checked").val();

    if (radioValue == '{{\App\CustomerProperty::inst_custom}}') 
    {
        remaining_amount = remaining_amount + parseInt($('#custome_rem').val())
    }
    $('#custome_rem').val(Math.round(remaining_amount));
    });


//update the down payemnt label

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

   

    net_amount = parseInt($('#net_amount').val());

    if($('#down-payment').val())
    down_payment = parseInt($('#down-payment').val());
    else
    down_payment = 0;
    file_processing = parseInt($('#file_processing').val());
    possession = parseFloat($('#possession').val());
    $('#per_file_processing').val(((file_processing / net_amount) * 100).toFixed(2));
    monthly_installment = parseInt($('#total_installment').val());
    annual_installment = 0;

     num=$("#file_processing").val();
    $("#file_processing-label").text(number2TextConversion(num));

    val = parseInt($('input[name="schedule_type"]:checked').val());
    if(val =={{\App\CustomerProperty::inst_mon_w_semi}}) {
    annual_installment = $('#total_semi_installment').val();
    }
    else if(val =={{\App\CustomerProperty::inst_mon_w_ann}}) {
    annual_installment = $('#total_annual_installment').val();
    }
    else if(val =={{\App\CustomerProperty::inst_mon_w_quar}}) {
    annual_installment = $('#total_quarterly_installment').val();
    }

    var add_amount = 0;

    $("input[name='add_amount[]']").each(function() {
    if(!this.value){
    add_amount += 0;
    }
    else {
    add_amount += parseInt($(this).val());
    }

    });


   allotment = parseFloat($('#allotment').val());
    confirmation = parseFloat($('#confirmation').val());
    booking = parseFloat($('#booking').val());
    development = parseFloat($('#development').val());
    file_processing = parseFloat($('#file_processing').val());
    registration = parseFloat($('#registration').val());


    remaining_amount = net_amount - down_payment - possession - monthly_installment - annual_installment - add_amount - allotment - confirmation - booking - development - file_processing - registration;

    $('#remaining_amount').val(remaining_amount);
var radioValue = $("input[name='schedule_type']:checked").val();

    if (radioValue == '{{\App\CustomerProperty::inst_custom}}') 
    {
        remaining_amount = remaining_amount + parseInt($('#custome_rem').val())
    }
    $('#custome_rem').val(Math.round(remaining_amount));
    });



//update the down payemnt label

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

    

    net_amount = parseInt($('#net_amount').val());
    if($('#down-payment').val())
        down_payment = parseInt($('#down-payment').val());
    else
        down_payment = 0;
    per_file_processing = parseFloat($('#per_file_processing').val());
    possession = parseFloat($('#possession').val());

    $('#file_processing').val(percentage(net_amount , per_file_processing));

    monthly_installment = parseInt($('#total_installment').val());
    annual_installment = 0;

    num=$("#file_processing").val();
    $("#file_processing-label").text(number2TextConversion(num));

    val = parseInt($('input[name="schedule_type"]:checked').val());
    if(val =={{\App\CustomerProperty::inst_mon_w_semi}}) {
        annual_installment = $('#total_semi_installment').val();
    }
    else if(val =={{\App\CustomerProperty::inst_mon_w_ann}}) {
        annual_installment = $('#total_annual_installment').val();
    }
    else if(val =={{\App\CustomerProperty::inst_mon_w_quar}}) {
        annual_installment = $('#total_quarterly_installment').val();
    }

    var add_amount = 0;

    $("input[name='add_amount[]']").each(function() {
        if(!this.value){
            add_amount += 0;
        }
        else {
            add_amount += parseInt($(this).val());
        }
        
    });

    allotment = parseFloat($('#allotment').val());
    confirmation = parseFloat($('#confirmation').val());
    booking = parseFloat($('#booking').val());
    development = parseFloat($('#development').val());
    file_processing = parseFloat($('#file_processing').val());
    registration = parseFloat($('#registration').val());


    remaining_amount = net_amount - down_payment - possession - monthly_installment - annual_installment - add_amount - allotment - confirmation - booking - development - file_processing - registration;


    $('#remaining_amount').val(remaining_amount);
var radioValue = $("input[name='schedule_type']:checked").val();

    if (radioValue == '{{\App\CustomerProperty::inst_custom}}') 
    {
        remaining_amount = remaining_amount + parseInt($('#custome_rem').val())
    }
    $('#custome_rem').val(Math.round(remaining_amount));
    });

//update the down payemnt label

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

    

    net_amount = parseInt($('#net_amount').val());

    if($('#down-payment').val())
    down_payment = parseInt($('#down-payment').val());
    else
    down_payment = 0;
    booking = parseInt($('#booking').val());
    possession = parseFloat($('#possession').val());
    $('#per_booking').val(((booking / net_amount) * 100).toFixed(2));
    monthly_installment = parseInt($('#total_installment').val());
    annual_installment = 0;

    num=$("#booking").val();
    $("#booking-label").text(number2TextConversion(num));

    val = parseInt($('input[name="schedule_type"]:checked').val());
    if(val =={{\App\CustomerProperty::inst_mon_w_semi}}) {
    annual_installment = $('#total_semi_installment').val();
    }
    else if(val =={{\App\CustomerProperty::inst_mon_w_ann}}) {
    annual_installment = $('#total_annual_installment').val();
    }
    else if(val =={{\App\CustomerProperty::inst_mon_w_quar}}) {
    annual_installment = $('#total_quarterly_installment').val();
    }

    var add_amount = 0;

    $("input[name='add_amount[]']").each(function() {
    if(!this.value){
    add_amount += 0;
    }
    else {
    add_amount += parseInt($(this).val());
    }

    });


    allotment = parseFloat($('#allotment').val());
    confirmation = parseFloat($('#confirmation').val());
    booking = parseFloat($('#booking').val());
    development = parseFloat($('#development').val());
    file_processing = parseFloat($('#file_processing').val());
    registration = parseFloat($('#registration').val());


    remaining_amount = net_amount - down_payment - possession - monthly_installment - annual_installment - add_amount - allotment - confirmation - booking - development - file_processing - registration;

    $('#remaining_amount').val(remaining_amount);
var radioValue = $("input[name='schedule_type']:checked").val();

    if (radioValue == '{{\App\CustomerProperty::inst_custom}}') 
    {
        remaining_amount = remaining_amount + parseInt($('#custome_rem').val())
    }
    $('#custome_rem').val(Math.round(remaining_amount));
    });




//update the down payemnt label

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

    

    net_amount = parseInt($('#net_amount').val());
    if($('#down-payment').val())
        down_payment = parseInt($('#down-payment').val());
    else
        down_payment = 0;
    per_booking = parseFloat($('#per_booking').val());
    possession = parseFloat($('#possession').val());

    $('#booking').val(percentage(net_amount , per_booking));

    monthly_installment = parseInt($('#total_installment').val());
    annual_installment = 0;

    num=$("#booking").val();
    $("#booking-label").text(number2TextConversion(num));

    val = parseInt($('input[name="schedule_type"]:checked').val());
    if(val =={{\App\CustomerProperty::inst_mon_w_semi}}) {
        annual_installment = $('#total_semi_installment').val();
    }
    else if(val =={{\App\CustomerProperty::inst_mon_w_ann}}) {
        annual_installment = $('#total_annual_installment').val();
    }
    else if(val =={{\App\CustomerProperty::inst_mon_w_quar}}) {
        annual_installment = $('#total_quarterly_installment').val();
    }

    var add_amount = 0;

    $("input[name='add_amount[]']").each(function() {
        if(!this.value){
            add_amount += 0;
        }
        else {
            add_amount += parseInt($(this).val());
        }
        
    });

    allotment = parseFloat($('#allotment').val());
    confirmation = parseFloat($('#confirmation').val());
    booking = parseFloat($('#booking').val());
    development = parseFloat($('#development').val());
    file_processing = parseFloat($('#file_processing').val());
    registration = parseFloat($('#registration').val());


    remaining_amount = net_amount - down_payment - possession - monthly_installment - annual_installment - add_amount - allotment - confirmation - booking - development - file_processing - registration;


    $('#remaining_amount').val(remaining_amount);
var radioValue = $("input[name='schedule_type']:checked").val();

    if (radioValue == '{{\App\CustomerProperty::inst_custom}}') 
    {
        remaining_amount = remaining_amount + parseInt($('#custome_rem').val())
    }
    $('#custome_rem').val(Math.round(remaining_amount));
    });



//update the down payemnt label

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

    net_amount = parseInt($('#net_amount').val());

    if($('#down-payment').val())
    down_payment = parseInt($('#down-payment').val());
    else
    down_payment = 0;
    confirmation = parseInt($('#confirmation').val());
    possession = parseFloat($('#possession').val());
    $('#per_confirmation').val(((confirmation / net_amount) * 100).toFixed(2));
    monthly_installment = parseInt($('#total_installment').val());
    annual_installment = 0;


    num=$("#confirmation").val();
    $("#confirmation-label").text(number2TextConversion(num));

    val = parseInt($('input[name="schedule_type"]:checked').val());
    if(val =={{\App\CustomerProperty::inst_mon_w_semi}}) {
    annual_installment = $('#total_semi_installment').val();
    }
    else if(val =={{\App\CustomerProperty::inst_mon_w_ann}}) {
    annual_installment = $('#total_annual_installment').val();
    }
    else if(val =={{\App\CustomerProperty::inst_mon_w_quar}}) {
    annual_installment = $('#total_quarterly_installment').val();
    }

    var add_amount = 0;

    $("input[name='add_amount[]']").each(function() {
    if(!this.value){
    add_amount += 0;
    }
    else {
    add_amount += parseInt($(this).val());
    }

    });


    allotment = parseFloat($('#allotment').val());
    confirmation = parseFloat($('#confirmation').val());
    booking = parseFloat($('#booking').val());
    development = parseFloat($('#development').val());
    file_processing = parseFloat($('#file_processing').val());
    registration = parseFloat($('#registration').val());


    remaining_amount = net_amount - down_payment - possession - monthly_installment - annual_installment - add_amount - allotment - confirmation - booking - development - file_processing - registration;

    $('#remaining_amount').val(remaining_amount);
var radioValue = $("input[name='schedule_type']:checked").val();

    if (radioValue == '{{\App\CustomerProperty::inst_custom}}') 
    {
        remaining_amount = remaining_amount + parseInt($('#custome_rem').val())
    }
    $('#custome_rem').val(Math.round(remaining_amount));
    });



//update the down payemnt label

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

    

    net_amount = parseInt($('#net_amount').val());
    if($('#down-payment').val())
        down_payment = parseInt($('#down-payment').val());
    else
        down_payment = 0;
    per_confirmation = parseFloat($('#per_confirmation').val());
    possession = parseFloat($('#possession').val());

    $('#confirmation').val(percentage(net_amount , per_confirmation));

    monthly_installment = parseInt($('#total_installment').val());
    annual_installment = 0;

    num=$("#confirmation").val();
    $("#confirmation-label").text(number2TextConversion(num));

    val = parseInt($('input[name="schedule_type"]:checked').val());
    if(val =={{\App\CustomerProperty::inst_mon_w_semi}}) {
        annual_installment = $('#total_semi_installment').val();
    }
    else if(val =={{\App\CustomerProperty::inst_mon_w_ann}}) {
        annual_installment = $('#total_annual_installment').val();
    }
    else if(val =={{\App\CustomerProperty::inst_mon_w_quar}}) {
        annual_installment = $('#total_quarterly_installment').val();
    }

    var add_amount = 0;

    $("input[name='add_amount[]']").each(function() {
        if(!this.value){
            add_amount += 0;
        }
        else {
            add_amount += parseInt($(this).val());
        }
        
    });

   allotment = parseFloat($('#allotment').val());
    confirmation = parseFloat($('#confirmation').val());
    booking = parseFloat($('#booking').val());
    development = parseFloat($('#development').val());
    file_processing = parseFloat($('#file_processing').val());
    registration = parseFloat($('#registration').val());


    remaining_amount = net_amount - down_payment - possession - monthly_installment - annual_installment - add_amount - allotment - confirmation - booking - development - file_processing - registration;


    $('#remaining_amount').val(remaining_amount);
var radioValue = $("input[name='schedule_type']:checked").val();

    if (radioValue == '{{\App\CustomerProperty::inst_custom}}') 
    {
        remaining_amount = remaining_amount + parseInt($('#custome_rem').val())
    }
    $('#custome_rem').val(Math.round(remaining_amount));
    });



//update the down payemnt label

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

    net_amount = parseInt($('#net_amount').val());

    if($('#down-payment').val())
    down_payment = parseInt($('#down-payment').val());
    else
    down_payment = 0;
    possession = parseFloat($('#possession').val());
    allotment = parseFloat($('#allotment').val());
    $('#per_allotment').val(((allotment / net_amount) * 100).toFixed(2));
    monthly_installment = parseInt($('#total_installment').val());
    annual_installment = 0;

    num=$("#allotment").val();
    $("#allotment-label").text(number2TextConversion(num));

    val = parseInt($('input[name="schedule_type"]:checked').val());
    if(val =={{\App\CustomerProperty::inst_mon_w_semi}}) {
    annual_installment = $('#total_semi_installment').val();
    }
    else if(val =={{\App\CustomerProperty::inst_mon_w_ann}}) {
    annual_installment = $('#total_annual_installment').val();
    }
    else if(val =={{\App\CustomerProperty::inst_mon_w_quar}}) {
    annual_installment = $('#total_quarterly_installment').val();
    }

    var add_amount = 0;

    $("input[name='add_amount[]']").each(function() {
    if(!this.value){
    add_amount += 0;
    }
    else {
    add_amount += parseInt($(this).val());
    }

    });


    allotment = parseFloat($('#allotment').val());
    confirmation = parseFloat($('#confirmation').val());
    booking = parseFloat($('#booking').val());
    development = parseFloat($('#development').val());
    file_processing = parseFloat($('#file_processing').val());
    registration = parseFloat($('#registration').val());


    remaining_amount = net_amount - down_payment - possession - monthly_installment - annual_installment - add_amount - allotment - confirmation - booking - development - file_processing - registration;

    $('#remaining_amount').val(remaining_amount);
var radioValue = $("input[name='schedule_type']:checked").val();

    if (radioValue == '{{\App\CustomerProperty::inst_custom}}') 
    {
        remaining_amount = remaining_amount + parseInt($('#custome_rem').val())
    }
    $('#custome_rem').val(Math.round(remaining_amount));
    });



//update the down payemnt label

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

   

    net_amount = parseInt($('#net_amount').val());
    if($('#down-payment').val())
        down_payment = parseInt($('#down-payment').val());
    else
        down_payment = 0;
    allotment_per = parseFloat($('#per_allotment').val());
    possession = parseFloat($('#possession').val());

    $('#allotment').val(percentage(net_amount , allotment_per));

    monthly_installment = parseInt($('#total_installment').val());
    annual_installment = 0;


     num=$("#allotment").val();
    $("#allotment-label").text(number2TextConversion(num));

    val = parseInt($('input[name="schedule_type"]:checked').val());
    if(val =={{\App\CustomerProperty::inst_mon_w_semi}}) {
        annual_installment = $('#total_semi_installment').val();
    }
    else if(val =={{\App\CustomerProperty::inst_mon_w_ann}}) {
        annual_installment = $('#total_annual_installment').val();
    }
    else if(val =={{\App\CustomerProperty::inst_mon_w_quar}}) {
        annual_installment = $('#total_quarterly_installment').val();
    }

    var add_amount = 0;

    $("input[name='add_amount[]']").each(function() {
        if(!this.value){
            add_amount += 0;
        }
        else {
            add_amount += parseInt($(this).val());
        }
        
    });

   allotment = parseFloat($('#allotment').val());
    confirmation = parseFloat($('#confirmation').val());
    booking = parseFloat($('#booking').val());
    development = parseFloat($('#development').val());
    file_processing = parseFloat($('#file_processing').val());
    registration = parseFloat($('#registration').val());


    remaining_amount = net_amount - down_payment - possession - monthly_installment - annual_installment - add_amount - allotment - confirmation - booking - development - file_processing - registration;


    $('#remaining_amount').val(remaining_amount);
var radioValue = $("input[name='schedule_type']:checked").val();

    if (radioValue == '{{\App\CustomerProperty::inst_custom}}') 
    {
        remaining_amount = remaining_amount + parseInt($('#custome_rem').val())
    }
    $('#custome_rem').val(Math.round(remaining_amount));
    });



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

    

    access_amount = parseInt($(this).val())

    if (access_amount > 0) 
    {
       $('#net_amount').val(net_amount + access_amount) 
    }
    else
    {
        $('#net_amount').val($('#dummy_net_amount').val())
    }
    

    if($('#down-payment').val())
    down_payment = parseInt($('#down-payment').val());
    else
    down_payment = 0;
    possession = parseInt($('#possession').val());
    $('#per_possession').val(((possession / net_amount) * 100).toFixed(2));
    monthly_installment = parseInt($('#total_installment').val());
    annual_installment = 0;


    num=$("#possession").val();
    $("#possession-label").text(number2TextConversion(num));

    val = parseInt($('input[name="schedule_type"]:checked').val());
    if(val =={{\App\CustomerProperty::inst_mon_w_semi}}) {
    annual_installment = $('#total_semi_installment').val();
    }
    else if(val =={{\App\CustomerProperty::inst_mon_w_ann}}) {
    annual_installment = $('#total_annual_installment').val();
    }
    else if(val =={{\App\CustomerProperty::inst_mon_w_quar}}) {
    annual_installment = $('#total_quarterly_installment').val();
    }

    var add_amount = 0;

    $("input[name='add_amount[]']").each(function() {
    if(!this.value){
    add_amount += 0;
    }
    else {
    add_amount += parseInt($(this).val());
    }

    });


    allotment = parseFloat($('#allotment').val());
    confirmation = parseFloat($('#confirmation').val());
    booking = parseFloat($('#booking').val());
    development = parseFloat($('#development').val());
    file_processing = parseFloat($('#file_processing').val());
    registration = parseFloat($('#registration').val());


    remaining_amount = net_amount - down_payment - possession - monthly_installment - annual_installment - add_amount - allotment - confirmation - booking - development - file_processing - registration;

    $('#remaining_amount').val(remaining_amount);
var radioValue = $("input[name='schedule_type']:checked").val();

    if (radioValue == '{{\App\CustomerProperty::inst_custom}}') 
    {
        remaining_amount = remaining_amount + parseInt($('#custome_rem').val())
    }
    $('#custome_rem').val(Math.round(remaining_amount));
    });



//update the down payemnt label

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

    

    net_amount = parseInt($('#net_amount').val());

    if($('#down-payment').val())
    down_payment = parseInt($('#down-payment').val());
    else
    down_payment = 0;
    possession = parseInt($('#possession').val());
    $('#per_possession').val(((possession / net_amount) * 100).toFixed(2));
    monthly_installment = parseInt($('#total_installment').val());
    annual_installment = 0;


    num=$("#possession").val();
    $("#possession-label").text(number2TextConversion(num));

    val = parseInt($('input[name="schedule_type"]:checked').val());
    if(val =={{\App\CustomerProperty::inst_mon_w_semi}}) {
    annual_installment = $('#total_semi_installment').val();
    }
    else if(val =={{\App\CustomerProperty::inst_mon_w_ann}}) {
    annual_installment = $('#total_annual_installment').val();
    }
    else if(val =={{\App\CustomerProperty::inst_mon_w_quar}}) {
    annual_installment = $('#total_quarterly_installment').val();
    }

    var add_amount = 0;

    $("input[name='add_amount[]']").each(function() {
    if(!this.value){
    add_amount += 0;
    }
    else {
    add_amount += parseInt($(this).val());
    }

    });


    allotment = parseFloat($('#allotment').val());
    confirmation = parseFloat($('#confirmation').val());
    booking = parseFloat($('#booking').val());
    development = parseFloat($('#development').val());
    file_processing = parseFloat($('#file_processing').val());
    registration = parseFloat($('#registration').val());


    remaining_amount = net_amount - down_payment - possession - monthly_installment - annual_installment - add_amount - allotment - confirmation - booking - development - file_processing - registration;

    $('#remaining_amount').val(remaining_amount);
var radioValue = $("input[name='schedule_type']:checked").val();

    if (radioValue == '{{\App\CustomerProperty::inst_custom}}') 
    {
        remaining_amount = remaining_amount + parseInt($('#custome_rem').val())
    }
    $('#custome_rem').val(Math.round(remaining_amount));
    });




function percentage(num, per)
{
  return (num/100)*per;
}

//update the down payemnt label

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

   

    net_amount = parseInt($('#net_amount').val());
   
    possession_per = parseFloat($('#per_possession').val());

    $('#possession').val(percentage(net_amount , possession_per));

     if($('#down-payment').val())
        down_payment = parseInt($('#down-payment').val());
    else
        down_payment = 0;


     possession = parseFloat($('#possession').val());

    monthly_installment = parseInt($('#total_installment').val());
    annual_installment = 0;

     num=$("#possession").val();
    $("#possession-label").text(number2TextConversion(num));

    val = parseInt($('input[name="schedule_type"]:checked').val());
    if(val =={{\App\CustomerProperty::inst_mon_w_semi}}) {
        annual_installment = $('#total_semi_installment').val();
    }
    else if(val =={{\App\CustomerProperty::inst_mon_w_ann}}) {
        annual_installment = $('#total_annual_installment').val();
    }
    else if(val =={{\App\CustomerProperty::inst_mon_w_quar}}) {
        annual_installment = $('#total_quarterly_installment').val();
    }

    var add_amount = 0;

    $("input[name='add_amount[]']").each(function() {
        if(!this.value){
            add_amount += 0;
        }
        else {
            add_amount += parseInt($(this).val());
        }
        
    });


   
   
    allotment = parseFloat($('#allotment').val());
    confirmation = parseFloat($('#confirmation').val());
    booking = parseFloat($('#booking').val());
    development = parseFloat($('#development').val());
    file_processing = parseFloat($('#file_processing').val());
    registration = parseFloat($('#registration').val());


    remaining_amount = net_amount - down_payment - possession - monthly_installment - annual_installment - add_amount - allotment - confirmation - booking - development - file_processing - registration;


    $('#remaining_amount').val(remaining_amount);
var radioValue = $("input[name='schedule_type']:checked").val();

    if (radioValue == '{{\App\CustomerProperty::inst_custom}}') 
    {
        remaining_amount = remaining_amount + parseInt($('#custome_rem').val())
    }
    $('#custome_rem').val(Math.round(remaining_amount));
    });


$('#down-payment').keyup(function(){

  
    net_amount = parseInt($('#net_amount').val());
    if($('#down-payment').val())
        down_payment = parseInt($('#down-payment').val());
    else
        down_payment = 0;
    
    monthly_installment = parseInt($('#total_installment').val());

    $('#per_down_payment').val(((down_payment / net_amount) * 100).toFixed(2));

    possession = parseInt($('#possession').val());

    num=$("#down-payment").val();
    $("#down-payment-label").text(number2TextConversion(num));


    annual_installment = 0;

    val = parseInt($('input[name="schedule_type"]:checked').val());
    if(val =={{\App\CustomerProperty::inst_mon_w_semi}}) {
        annual_installment = $('#total_semi_installment').val();
    }
    else if(val =={{\App\CustomerProperty::inst_mon_w_ann}}) {
        annual_installment = $('#total_annual_installment').val();
    }
    else if(val =={{\App\CustomerProperty::inst_mon_w_quar}}) {
        annual_installment = $('#total_quarterly_installment').val();
    }

    var add_amount = 0;

    $("input[name='add_amount[]']").each(function() {
        if(!this.value){
            add_amount += 0;
        }
        else {
            add_amount += parseInt($(this).val());
        }
        
    });

    allotment = parseFloat($('#allotment').val());
    confirmation = parseFloat($('#confirmation').val());
    booking = parseFloat($('#booking').val());
    development = parseFloat($('#development').val());
    file_processing = parseFloat($('#file_processing').val());
    registration = parseFloat($('#registration').val());


    remaining_amount = net_amount - down_payment - possession - monthly_installment - annual_installment - add_amount - allotment - confirmation - booking - development - file_processing - registration;


    $('#remaining_amount').val(remaining_amount);
var radioValue = $("input[name='schedule_type']:checked").val();

    if (radioValue == '{{\App\CustomerProperty::inst_custom}}') 
    {
        remaining_amount = remaining_amount + parseInt($('#custome_rem').val())
    }
    $('#custome_rem').val(Math.round(remaining_amount));
    });


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

    

    net_amount = parseInt($('#net_amount').val());
    
    // possession = parseInt($('#possession').val());
    monthly_installment = parseInt($('#total_installment').val());

     per_down_payment = parseFloat($('#per_down_payment').val());
   

    $('#down-payment').val(percentage(net_amount , per_down_payment));

     possession = parseFloat($('#possession').val());

    if($('#down-payment').val())
        down_payment = parseInt($('#down-payment').val());
    else
        down_payment = 0;

    num=$("#down-payment").val();
    $("#down-payment-label").text(number2TextConversion(num));

    annual_installment = 0;

    val = parseInt($('input[name="schedule_type"]:checked').val());
    if(val =={{\App\CustomerProperty::inst_mon_w_semi}}) {
        annual_installment = $('#total_semi_installment').val();
    }
    else if(val =={{\App\CustomerProperty::inst_mon_w_ann}}) {
        annual_installment = $('#total_annual_installment').val();
    }
    else if(val =={{\App\CustomerProperty::inst_mon_w_quar}}) {
        annual_installment = $('#total_quarterly_installment').val();
    }

    var add_amount = 0;

    $("input[name='add_amount[]']").each(function() {
        if(!this.value){
            add_amount += 0;
        }
        else {
            add_amount += parseInt($(this).val());
        }
        
    });

    allotment = parseFloat($('#allotment').val());
    confirmation = parseFloat($('#confirmation').val());
    booking = parseFloat($('#booking').val());
    development = parseFloat($('#development').val());
    file_processing = parseFloat($('#file_processing').val());
    registration = parseFloat($('#registration').val());


    remaining_amount = net_amount - down_payment - possession - monthly_installment - annual_installment - add_amount - allotment - confirmation - booking - development - file_processing - registration;


    $('#remaining_amount').val(remaining_amount);
var radioValue = $("input[name='schedule_type']:checked").val();

    if (radioValue == '{{\App\CustomerProperty::inst_custom}}') 
    {
        remaining_amount = remaining_amount + parseInt($('#custome_rem').val())
    }
    $('#custome_rem').val(Math.round(remaining_amount));
    });




//update the six installment fee label
$("#annual-installment").keyup(function(){

    num = $("#annual-installment").val();
    $("#annual-installment-label").text(number2TextConversion(num));

    count = $('#total_annual_installment_count').val();
    $('#total_annual_installment').val(Math.round(parseInt($("#annual-installment").val()) * count));

    num = $("#total_annual_installment").val();
    $("#total-annual-installment-label").text(number2TextConversion(num));

    net_amount = parseInt($('#net_amount').val());
    down_payment = parseInt($('#down-payment').val());
    possession = parseInt($('#possession').val());
    monthly_installment = parseInt($('#total_installment').val());
    annual_installment = parseInt($('#total_annual_installment').val());

    var add_amount = 0;
    $("input[name='add_amount[]']").each(function() {
        if(!this.value)
            add_amount += 0;
        else 
            add_amount += parseInt($(this).val());
    });

    allotment = parseFloat($('#allotment').val());
    confirmation = parseFloat($('#confirmation').val());
    booking = parseFloat($('#booking').val());
    development = parseFloat($('#development').val());
    file_processing = parseFloat($('#file_processing').val());
    registration = parseFloat($('#registration').val());

    remaining_amount = net_amount - down_payment - possession - monthly_installment - annual_installment - add_amount - allotment - confirmation - booking - development - file_processing - registration;


    $('#remaining_amount').val(Math.round(remaining_amount));
});

//update the semi installment fee label
$("#semi-installment").keyup(function(){
    
    num = $("#semi-installment").val();
    $("#semi-installment-label").text(number2TextConversion(num));

    count = $('#total_semi_installment_count').val();
    $('#total_semi_installment').val(Math.round(parseInt($("#semi-installment").val()) * count));

    num = $("#total_semi_installment").val();
    $("#total-semi-installment-label").text(number2TextConversion(num));

    net_amount = parseInt($('#net_amount').val())
    down_payment = parseInt($('#down-payment').val());
    possession = parseInt($('#possession').val());
    monthly_installment = parseInt($('#total_installment').val());
    annual_installment = parseInt($('#total_semi_installment').val());

    var add_amount = 0;
    $("input[name='add_amount[]']").each(function() {
        if(!this.value)
            add_amount += 0;
        else
            add_amount += parseInt($(this).val());
        
    });

    allotment = parseFloat($('#allotment').val());
    confirmation = parseFloat($('#confirmation').val());
    booking = parseFloat($('#booking').val());
    development = parseFloat($('#development').val());
    file_processing = parseFloat($('#file_processing').val());
    registration = parseFloat($('#registration').val());


    remaining_amount = net_amount - down_payment - possession - monthly_installment - annual_installment - add_amount - allotment - confirmation - booking - development - file_processing - registration;


    $('#remaining_amount').val(Math.round(remaining_amount));

});

//update the quarterly installment fee label
$("#bi-mon-installment").keyup(function(){
    
    num = $("#bi-mon-installment").val();
    $("#bi-mon-installment-label").text(number2TextConversion(num));

    count = $('#total_bi_mon_installment_count').val();
    $('#total_bi_mon_installment').val(Math.round(parseInt($("#bi-mon-installment").val()) * count));

    num = $("#total_bi_mon_installment").val();
    $("#total-bi-mon-installment-label").text(number2TextConversion(num));

    net_amount = parseInt($('#net_amount').val());
    down_payment = parseInt($('#down-payment').val());
    possession = parseInt($('#possession').val());
    monthly_installment = parseInt($('#total_installment').val());
    annual_installment = parseInt($('#total_bi_mon_installment').val());

    var add_amount = 0;
    $("input[name='add_amount[]']").each(function() {
        if(!this.value){
            add_amount += 0;
        }
        else {
            add_amount += parseInt($(this).val());
        }
        
    });

    allotment = parseFloat($('#allotment').val());
    confirmation = parseFloat($('#confirmation').val());
    booking = parseFloat($('#booking').val());
    development = parseFloat($('#development').val());
    file_processing = parseFloat($('#file_processing').val());
    registration = parseFloat($('#registration').val());


    remaining_amount = net_amount - down_payment - possession - monthly_installment - annual_installment - add_amount - allotment - confirmation - booking - development - file_processing - registration;

    $('#remaining_amount').val(Math.round(remaining_amount));

});





//update the quarterly installment fee label
$("#quarterly-installment").keyup(function(){
    
    num = $("#quarterly-installment").val();
    $("#quarterly-installment-label").text(number2TextConversion(num));

    count = $('#total_quarterly_installment_count').val();
    $('#total_quarterly_installment').val(Math.round(parseInt($("#quarterly-installment").val()) * count));

    num = $("#total_quarterly_installment").val();
    $("#total-quarterly-installment-label").text(number2TextConversion(num));

    net_amount = parseInt($('#net_amount').val());
    down_payment = parseInt($('#down-payment').val());
    possession = parseInt($('#possession').val());
    monthly_installment = parseInt($('#total_installment').val());
    annual_installment = parseInt($('#total_quarterly_installment').val());

    var add_amount = 0;
    $("input[name='add_amount[]']").each(function() {
        if(!this.value){
            add_amount += 0;
        }
        else {
            add_amount += parseInt($(this).val());
        }
        
    });

    allotment = parseFloat($('#allotment').val());
    confirmation = parseFloat($('#confirmation').val());
    booking = parseFloat($('#booking').val());
    development = parseFloat($('#development').val());
    file_processing = parseFloat($('#file_processing').val());
    registration = parseFloat($('#registration').val());

    remaining_amount = net_amount - down_payment - possession - monthly_installment - annual_installment - add_amount - allotment - confirmation - booking - development - file_processing - registration;

    $('#remaining_amount').val(Math.round(remaining_amount));

});



//update the quarterly installment fee label
$("#total_quarterly_installment").keyup(function(){

per_inst =  parseInt($('#total_quarterly_installment').val()) / parseInt($('#total_quarterly_installment_count').val());

$('#quarterly-installment').val(Math.round(per_inst));

$('#remaining_amount').val(Math.round(0));
});

//update the installment label
    $("#installment").keyup(function(){
        num1 = $("#installment").val();
        $("#installment-label").text(number2TextConversion(num1));

        $('#total_installment').val(Math.round(parseInt($("#installment").val()) * parseInt($('#total-months').val())));
        
        num = $("#total_installment").val();
        $("#total-installment-label").text(number2TextConversion(num));

        net_amount = parseInt($('#net_amount').val());
        down_payment = parseInt($('#down-payment').val());
        possession = parseInt($('#possession').val());
        monthly_installment = parseInt($('#total_installment').val());


        $('#per_installment').val(((num1 / net_amount) * 100).toFixed(2));

        $('#per_total_installment').val(Math.round(parseFloat($("#per_installment").val()) * parseFloat($('#total-months').val())))

        annual_installment = 0;
        val = parseInt($('input[name="schedule_type"]:checked').val());
        if(val =={{\App\CustomerProperty::inst_mon_w_semi}}) {
            annual_installment = $('#total_semi_installment').val();
        }
        else if(val =={{\App\CustomerProperty::inst_mon_w_ann}}) {
            annual_installment = $('#total_annual_installment').val();
        }
        else if(val =={{\App\CustomerProperty::inst_mon_w_quar}}) {
            annual_installment = $('#total_quarterly_installment').val();
        }

        var add_amount = 0;
        $("input[name='add_amount[]']").each(function() {
            if(!this.value) {
                add_amount += 0;
            }
            else {
                add_amount += parseInt($(this).val());
            }
        });

     allotment = parseFloat($('#allotment').val());
    confirmation = parseFloat($('#confirmation').val());
    booking = parseFloat($('#booking').val());
    development = parseFloat($('#development').val());
    file_processing = parseFloat($('#file_processing').val());
    registration = parseFloat($('#registration').val());


    remaining_amount = net_amount - down_payment - possession - monthly_installment - annual_installment - add_amount - allotment - confirmation - booking - development - file_processing - registration;

       
        $('#remaining_amount').val(Math.round(remaining_amount));

});


        $("#per_installment").keyup(function(){
        num1 = $("#installment").val();
        $("#installment-label").text(number2TextConversion(num1));

        $('#total_installment').val(Math.round(parseInt($("#installment").val()) * parseInt($('#total-months').val())));
        
        num = $("#total_installment").val();
        $("#total-installment-label").text(number2TextConversion(num));

        net_amount = parseInt($('#net_amount').val());
        down_payment = parseInt($('#down-payment').val());
        possession = parseInt($('#possession').val());
        monthly_installment = parseInt($('#total_installment').val());


        $('#installment').val(percentage(net_amount ,  $('#per_installment').val() ));
        $('#per_total_installment').val(Math.round(parseFloat($("#per_installment").val()) * parseFloat($('#total-months').val())))

        annual_installment = 0;
        val = parseInt($('input[name="schedule_type"]:checked').val());
        if(val =={{\App\CustomerProperty::inst_mon_w_semi}}) {
            annual_installment = $('#total_semi_installment').val();
        }
        else if(val =={{\App\CustomerProperty::inst_mon_w_ann}}) {
            annual_installment = $('#total_annual_installment').val();
        }
        else if(val =={{\App\CustomerProperty::inst_mon_w_quar}}) {
            annual_installment = $('#total_quarterly_installment').val();
        }

        var add_amount = 0;
        $("input[name='add_amount[]']").each(function() {
            if(!this.value) {
                add_amount += 0;
            }
            else {
                add_amount += parseInt($(this).val());
            }
        });

    allotment = parseFloat($('#allotment').val());
    confirmation = parseFloat($('#confirmation').val());
    booking = parseFloat($('#booking').val());
    development = parseFloat($('#development').val());
    file_processing = parseFloat($('#file_processing').val());
    registration = parseFloat($('#registration').val());

    remaining_amount = net_amount - down_payment - possession - monthly_installment - annual_installment - add_amount - allotment - confirmation - booking - development - file_processing - registration;

       
        $('#remaining_amount').val(Math.round(remaining_amount));

});


    //update the total months label
$("#total-months").keyup(function(){

        num = $("#installment").val();
        $("#installment-label").text(number2TextConversion(num));
        
        $('#total_installment').val(Math.round(parseInt($("#installment").val()) * parseInt($('#total-months').val())));

        num = $("#total_installment").val();
        $("#total-installment-label").text(number2TextConversion(num));

});




    //update the total months label
$("#total_semi_installment").keyup(function(){

        price = $("#total_semi_installment").val();
        count = $("#total_semi_installment_count").val();
        
        
        $('#semi-installment').val((Math.round(price/count)));

        $("#remaining_amount").val(0);

});



function updateCurrency() {
    
//update the cost label

    num=$("#total-amount").val();

    $("#total-amount-label").text(number2TextConversion(num));

//update the net amount
    num=$("#net_amount").val();

    $("#net_amount-label").text(number2TextConversion(num));


//update the down payemnt label
    num=$("#down-payment").val();

    $("#down-payment-label").text(number2TextConversion(num));


//update the annual installment text
   num=$("#annual-installment").val();
   
   $("#annual-installment-label").text(number2TextConversion(num));


//update the total annual installment text
    num=$("#total_annual_installment").val();

    $("#total-annual-installment-label").text(number2TextConversion(num));

//update the semi installment text
    num=$("#semi-installment").val();

    $("#semi-installment-label").text(number2TextConversion(num));


//update the total semi installment
    num=$("#total_semi_installment").val();

    $("#total-semi-installment-label").text(number2TextConversion(num));

    //upte the quarterly installment text
    num = $("#bi-mon-installment").val();

    $("#bi-mon-installment-label").text(number2TextConversion(num));

//upte the quarterly installment text
    num = $("#quarterly-installment").val();

    $("#quarterly-installment-label").text(number2TextConversion(num));

    //update the total quarterly installment
    num=$("#total_bi_mon_installment").val();

    $("#total-bi-mon-installment-label").text(number2TextConversion(num));


//update the total quarterly installment
    num=$("#total_quarterly_installment").val();

    $("#total-quarterly-installment-label").text(number2TextConversion(num));

//update the installment label

    num=$("#installment").val();

    $("#installment-label").text(number2TextConversion(num));

//update the total_installment
    num=$("#total_installment").val();

    $("#total-installment-label").text(number2TextConversion(num));

}


//update the unit information when unit number change
$('#unit_numberl').change(function() {
    $('.preloader').fadeIn();
        var data = { 'unit_number': $(this).val() };

        $.get('/getInformationByUnitEdit', data, function (data) {
            if(data) 
            {

                $('#total-amount').val(data.info.total_price );

           data.info.total_price = parseInt(data.info.total_price) + parseInt(data.info.extra_amount) - parseInt(data.receivedAmt);

            

            $('#net_amount').val(data.info.total_price);

            if(data.info.customer_property.schedule_start_date != '')
            {
                $('#schedule_start_date').val(data.info.customer_property.schedule_start_date)
            }
            
            $('#booking_date').val(data.down_payment_date)
            $('#possession_date').val(data.possession_date)
            $('#allotment_date').val(data.allotment_date)
            $('#confirmation_date').val(data.confirmation_date)
            $('#development_date').val(data.development_date)
            $('#file_processing_date').val(data.file_processing_date)
            $('#registration_date').val(data.registration_date)
            if (data.info.customer_property.original_boooking_date != '') 
            {
               $('#original_boooking_date').val(data.info.customer_property.original_boooking_date) 
            }
            

            $('#dummy_net_amount').val(data.info.total_price)

            $('#extra_charges').val(data.info.extra_amount);
            
            $('#size').val(data.info.size.name  + ' {{env('SIZE')}}');

            $('#inventory-id').val(data.info.id);

            $('#description').val(data.info.description);

             name = '';
             for( i = 0 ; i<data.info.categories.length ; i++)
             {
                name += data.info.categories[i].category.name + ', ';
             }

            $('#category').val(name);
            //$('#category').val(data.info.category.name);
            $("#inventory_type #type").val(data.info.type.name);


             $('#down_payment_per').val(data.schedule.down_payment);
             $('#possession_per').val(data.schedule.possession);

             $('#per_allotment').val(data.schedule.allotment);
             $('#per_confirmation').val(data.schedule.confirmation);


             $('#per_booking').val(data.schedule.booking);
             $('#per_development').val(data.schedule.development);


             $('#per_file_processing').val(data.schedule.file_processing);
             $('#per_registration').val(data.schedule.registration);



             $('#annual_installment_per').val(data.schedule.annual_installment);
             $('#monthly_installment_per').val(data.schedule.monthly_installment);
             $('#total_month_per').val(data.schedule.total_months);
             $('#total_annual_installment_count').val( Math.round(data.schedule.total_months / 12));
               $('#total_semi_installment_count').val( Math.round(data.schedule.total_months / 6));
               $('#total_quarterly_installment_count').val( Math.round(data.schedule.total_months / 3));
               $('#total_bi_mon_installment_count').val( Math.round(data.schedule.total_months / 3));


               $('#down-payment').val( Math.round((parseInt(data.schedule.down_payment) / 100 * data.info.total_price )));
               $('#down_payment_dis').val(Math.round((parseInt(data.schedule.down_payment) / 100 * data.info.total_price )));
               $('#possession').val( Math.round((parseInt(data.schedule.possession) / 100 * data.info.total_price )));
               $('#possession1').val( Math.round((parseInt(data.schedule.possession) / 100 * data.info.total_price )));

               $('#allotment').val( Math.round((parseInt(data.schedule.allotment) / 100 * data.info.total_price )));

               $('#confirmation').val( Math.round((parseInt(data.schedule.confirmation) / 100 * data.info.total_price )));



               $('#booking').val( Math.round((parseInt(data.schedule.booking) / 100 * data.info.total_price )));

               $('#development').val( Math.round((parseInt(data.schedule.development) / 100 * data.info.total_price )));



               $('#file_processing').val( Math.round((parseInt(data.schedule.file_processing) / 100 * data.info.total_price )));

               $('#registration').val( Math.round((parseInt(data.schedule.registration) / 100 * data.info.total_price )));


                $('#annual-installment').val( Math.round(data.schedule.annual_installment / 100 * data.info.total_price / (data.schedule.total_months / 12)));
               $('#total-months').val( Math.round(data.schedule.total_months));

               $('#total_annual_installment').val( Math.round(data.schedule.annual_installment / 100 * data.info.total_price));

               $('#installment').val( Math.round(data.schedule.monthly_installment / 100 * data.info.total_price / (data.schedule.total_months)));

               $('#total_installment').val( Math.round(data.schedule.monthly_installment / 100 * data.info.total_price));

               manToPer() 
               updateCurrency();

               //Full Payment
               $('#total_amount_full_payment').val(data.info.total_price);

               net_amount = parseInt($('#net_amount').val());
               down_payment = parseInt($('#down-payment').val());
               possession = parseInt($('#possession').val());
               monthly_installment = parseInt($('#total_installment').val());
               annual_installment = parseInt($('#total_annual_installment').val());


               allotment = parseInt($('#allotment').val());
               confirmation = parseInt($('#confirmation').val());
               booking = parseInt($('#booking').val());
               development = parseInt($('#development').val());
               file_processing = parseInt($('#file_processing').val());
               registration = parseInt($('#registration').val());


               remaining_amount = net_amount - down_payment - possession - monthly_installment - annual_installment - allotment - confirmation - booking - development - file_processing - registration;

               $('#remaining_amount').val(Math.round(remaining_amount));

               //set the rebate 
               $('#rebate_in_percentage').val(Math.round(5));

               $('#rebate_in_amount').val(Math.round((data.info.total_price - data.info.extra_amount) * 0.05));

               $('#sqrt').html(data.info.size.name);
               $('#per_sqrt_value').val(net_amount/data.info.size.name);
            }
        });

        // $('#amount_schedule').click()
         $('.preloader').fadeOut();
    });

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

    amount = $('#rebate_in_amount').val();
    percentage = $('#rebate_in_percentage').val();
    total_value = $('#net_amount').val();

    $('#rebate_in_percentage').val(Math.round((amount / total_value) * 100));

});

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

    amount = $('#rebate_in_amount').val();
    percentage = $('#rebate_in_percentage').val();
    total_value = $('#net_amount').val();

    $('#rebate_in_amount').val(Math.round((total_value) * (percentage / 100)));

});

$(document).on('keyup', '.total_rebate', function() {



    var id = document.getElementsByClassName('total_rebate');
    var rebate = $('#rebate_in_amount').val();

    given_rebate = 0;

    for(i = 0; i <id.length; i++) {

        given_rebate += parseFloat(id[i].value);
    }

    $('#remaining_amount_in_rebate').val(rebate - given_rebate);

});


    function manToPer() {
        cost = $('#net_amount').val();
        if(cost){

        down_payment = $('#down-payment').val();
         if(down_payment) {
             $('#per_down_payment').val(((down_payment / cost) * 100).toFixed(2));

         }
         possession = $('#possession').val();
         if(possession) {
             $('#per_possession').val(((possession / cost) * 100).toFixed(2));

         }

         // annual_installment = $('#annual-installment').val();
         // if(annual_installment) {
         //     $('#annual-installment').val( ((annual_installment / cost) * 100).toFixed(2));

         // }


         // total_annual_installment = $('#total_annual_installment').val();
         // if(total_annual_installment) {
         //     $('#total_annual_installment').val( ((total_annual_installment / cost) * 100).toFixed(2));

         // }

         total_months = $('#total-months').val();
         if(total_months) {
             installment = $('#installment').val();
             if(installment) {
                $('#per_installment').val(  (((installment) / cost) * 100).toFixed(2));

            }
             total_installment = $('#total_installment').val();
             if(total_installment) {
                $('#per_total_installment').val(  (((total_installment) / cost) * 100).toFixed(2));

            }
         }
          updateCurrency();

    }
    }

    function perToMan() {
        cost = $('#net_amount').val();
        if(cost){

        down_payment = $('#down-payment').val();
         if(down_payment) {
            $('#down-payment').val(  ((down_payment * cost) / 100).toFixed(0));

         }
         possession = $('#possession').val();
         if(possession) {
            $('#possession').val(  ((possession * cost) / 100).toFixed(0));

         }


         annual_installment = $('#annual-installment').val();
         if(annual_installment) {
           $('#annual-installment').val(  ((annual_installment  * cost) / 100).toFixed(0));

         }
         total_annual_installment = $('#total_annual_installment').val();
         if(total_annual_installment) {
           $('#total_annual_installment').val(  ((total_annual_installment  * cost) / 100).toFixed(0));

         }
         total_months = $('#total-months').val();
         if(total_months) {
             installment = $('#installment').val();
             if(installment) {
               $('#installment').val(  ( (installment  * cost) / 100).toFixed(0));

               total_installment = $('#total_installment').val();
             if(total_installment) {
               $('#total_installment').val(  ( (total_installment  * cost) / 100).toFixed(0));

            }}
         }
          updateCurrency();

    }
    }


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

if($('#discount_s').val()) {

    discount = 0;
    if($('#discount_percent').prop("checked") == false)
    {
        price = Math.round(parseInt($('#total-amount').val()) + parseInt($('#extra_charges').val()) - parseFloat($('#discount_s').val()));
        discount = parseFloat($('#discount_s').val());
    }
    else 
    {
        price = Math.round(parseInt($('#total-amount').val()) + parseInt($('#extra_charges').val()) - parseFloat($('#discount_s').val()) / 100 * (parseInt($('#total-amount').val())+  parseInt($('#extra_charges').val())));
      
        discount = parseFloat($('#discount_s').val()) / 100 * (parseInt($('#total-amount').val())+  parseInt($('#extra_charges').val()));
    }


         $('#net_amount').val(price);
         var total_value = price/$('#sqrt').text()

         $('#per_sqrt_value').val(total_value.toFixed(1));
        
        $('#down-payment').val(Math.round(($('#down_payment_per').val()/100)*price));
        $('#possession1').val(Math.round(($('#possession_per').val()/100)*price));
        $('#possession').val(Math.round(($('#possession_per').val()/100)*price));
        
         disableAnn(1);

      //  $('#down-payment').val( Math.round($('#down_payment_dis').val() -  discount));

        updateCurrency();
}
else {
    price = Math.round(parseInt($('#total-amount').val()) + parseInt($('#extra_charges').val()));

        $('#net_amount').val(price);

      //  $('#down-payment').val( Math.round($('#down_payment_dis').val()));
      
      
      
      $('#down-payment').val(Math.round(($('down_payment_per').val()/100)*price));
      $('#possession1').val(Math.round(($('#possession_per').val()/100)*price));
      $('#possession').val(Math.round(($('#possession_per').val()/100)*price));
      
      disableAnn(1);

        updateCurrency();

}




    amount = $('#rebate_in_amount').val();
    percentage = $('#rebate_in_percentage').val();
    total_value = $('#net_amount').val();

    $('#rebate_in_percentage').val( Math.round((amount / total_value) * 100  ));

    $('#rebate_in_amount').val( Math.round( (total_value) * (percentage / 100) ));


    });

    function percentCheckbox() {

        if($('#discount_percent').prop("checked") == false) {
            document.getElementById('dis_input').innerHTML = 'PKR';
        }
        else {
            document.getElementById('dis_input').innerHTML = '%';
        }

        // if($('#discount_s').val()) {
        //     discount = 0;
        //     if($('#discount_percent').prop("checked") == false) {
        //         price = Math.round(parseInt($('#total-amount').val()) + parseInt($('#extra_charges').val()) - parseFloat($('#discount_s').val()));
        //         discount = parseFloat($('#discount_s').val());
        //     }
        //     else {
        //         price = Math.round(parseInt($('#total-amount').val()) + parseInt($('#extra_charges').val()) - parseFloat($('#discount_s').val()) / 100 * (parseInt($('#total-amount').val()) + parseInt($('#extra_charges').val())));
        //         discount = parseFloat($('#discount_s').val()) / 100 * (parseInt($('#total-amount').val())+  parseInt($('#extra_charges').val()));
        //     }

        // $('#net_amount').val(price);

        // $('#down-payment').val( Math.round($('#down_payment_dis').val() -  discount));
        // updateCurrency();
        // }
    //    else {
    //          price = Math.round(parseInt($('#total-amount').val()) + parseInt($('#extra_charges').val()));

    //     $('#net_amount').val(price);

    //     $('#down-payment').val( Math.round($('#down_payment_dis').val()));

    //     updateCurrency();

    //       }
    }


function enableAnn() {

    document.getElementById('custom').style.display = 'none';
    document.getElementById('auto').style.display = 'block';

    $('#remaining_amount').val(0);
    document.getElementById('ann_div').style.display = 'block';
    document.getElementById('semi_div').style.display = 'none';
    document.getElementById('quar_div').style.display = 'none';
    document.getElementById('bi_mon_div').style.display = 'none';

    price = parseInt($('#net_amount').val());
    count = $('#total_annual_installment_count').val();

     $('#installment').val( Math.round(parseFloat($('#monthly_installment_per').val()) / 100 * price / (parseInt($('#total_month_per').val()))));

    $('#total_installment').val( Math.round(parseFloat($('#monthly_installment_per').val()) / 100 * price));

    net_amount = parseInt($('#net_amount').val());
    down_payment = parseInt($('#down-payment').val());
    possession = parseInt($('#possession').val());
    monthly_installment = parseInt($('#total_installment').val());

    annual_installment = parseInt($('#total_annual_installment').val());

    allotment = parseInt($('#allotment').val());
    confirmation = parseInt($('#confirmation').val());
    booking = parseInt($('#booking').val());
    development = parseInt($('#development').val());
    file_processing = parseInt($('#file_processing').val());
    registration = parseInt($('#registration').val());


    remaining_amount = net_amount - down_payment - possession - monthly_installment - annual_installment - allotment - confirmation - booking - development - file_processing - registration;




     $('#annual-installment').val( Math.round(remaining_amount / count));
    $('#total-months').val( Math.round(parseInt($('#total_month_per').val())));

    $('#total_annual_installment').val( Math.round(remaining_amount));

}


function enableAnn() {

    document.getElementById('custom').style.display = 'none';
    document.getElementById('auto').style.display = 'block';

    $('#remaining_amount').val(0);
    document.getElementById('ann_div').style.display = 'block';
    document.getElementById('semi_div').style.display = 'none';
    document.getElementById('quar_div').style.display = 'none';
    document.getElementById('bi_mon_div').style.display = 'none';

    price = parseInt($('#net_amount').val());
    count = $('#total_annual_installment_count').val();

     $('#installment').val( Math.round(parseFloat($('#monthly_installment_per').val()) / 100 * price / (parseInt($('#total_month_per').val()))));

    $('#total_installment').val( Math.round(parseFloat($('#monthly_installment_per').val()) / 100 * price));

    net_amount = parseInt($('#net_amount').val());
    down_payment = parseInt($('#down-payment').val());
    possession = parseInt($('#possession').val());
    monthly_installment = parseInt($('#total_installment').val());

    annual_installment = parseInt($('#total_annual_installment').val());

    allotment = parseInt($('#allotment').val());
    confirmation = parseInt($('#confirmation').val());
    booking = parseInt($('#booking').val());
    development = parseInt($('#development').val());
    file_processing = parseInt($('#file_processing').val());
    registration = parseInt($('#registration').val());


    remaining_amount = net_amount - down_payment - possession - monthly_installment - annual_installment - allotment - confirmation - booking - development - file_processing - registration;


    $('#annual-installment').val( Math.round(remaining_amount / count));
    $('#total-months').val( Math.round(parseInt($('#total_month_per').val())));

    $('#total_annual_installment').val( Math.round(remaining_amount));

}

function enableBiMonth() {

    document.getElementById('custom').style.display = 'none';
    document.getElementById('auto').style.display = 'block';

    $('#remaining_amount').val(0);
    document.getElementById('bi_mon_div').style.display = 'block';
    document.getElementById('quar_div').style.display = 'none';

    document.getElementById('semi_div').style.display = 'none';
    document.getElementById('ann_div').style.display = 'none';

    price = $('#net_amount').val();
    count = $('#total_bi_mon_installment_count').val();

     $('#installment').val( Math.round(parseFloat($('#monthly_installment_per').val()) / 100 * price / (parseInt($('#total_month_per').val()))));

    $('#total_installment').val( Math.round(parseFloat($('#monthly_installment_per').val()) / 100 * price));

    net_amount = parseInt($('#net_amount').val());
    down_payment = parseInt($('#down-payment').val());
    possession = parseInt($('#possession').val());
    monthly_installment = parseInt($('#total_installment').val());

    annual_installment = parseInt($('#total_annual_installment').val());

    allotment = parseInt($('#allotment').val());
    confirmation = parseInt($('#confirmation').val());
    booking = parseInt($('#booking').val());
    development = parseInt($('#development').val());
    file_processing = parseInt($('#file_processing').val());
    registration = parseInt($('#registration').val());


    remaining_amount = net_amount - down_payment - possession - monthly_installment - annual_installment - allotment - confirmation - booking - development - file_processing - registration;


     $('#bi-mon-installment').val( Math.round(remaining_amount / count));
    $('#total-months').val( Math.round(parseInt($('#total_month_per').val())));

    $('#total_bi_mon_installment').val( Math.round(remaining_amount));

}

function enableQuar() {

    document.getElementById('custom').style.display = 'none';
    document.getElementById('auto').style.display = 'block';

    $('#remaining_amount').val(0);
    document.getElementById('quar_div').style.display = 'block';
    document.getElementById('bi_mon_div').style.display = 'none';
    document.getElementById('semi_div').style.display = 'none';
    document.getElementById('ann_div').style.display = 'none';

    price = $('#net_amount').val();
    count = $('#total_quarterly_installment_count').val();

     $('#installment').val( Math.round(parseFloat($('#monthly_installment_per').val()) / 100 * price / (parseInt($('#total_month_per').val()))));

    $('#total_installment').val( Math.round(parseFloat($('#monthly_installment_per').val()) / 100 * price));

    net_amount = parseInt($('#net_amount').val());
    down_payment = parseInt($('#down-payment').val());
    possession = parseInt($('#possession').val());
    monthly_installment = parseInt($('#total_installment').val());

    annual_installment = parseInt($('#total_annual_installment').val());

    allotment = parseInt($('#allotment').val());
    confirmation = parseInt($('#confirmation').val());
    booking = parseInt($('#booking').val());
    development = parseInt($('#development').val());
    file_processing = parseInt($('#file_processing').val());
    registration = parseInt($('#registration').val());


    remaining_amount = net_amount - down_payment - possession - monthly_installment - annual_installment - allotment - confirmation - booking - development - file_processing - registration;


     $('#quarterly-installment').val( Math.round(remaining_amount / count));
    $('#total-months').val( Math.round(parseInt($('#total_month_per').val())));

    $('#total_quarterly_installment').val( Math.round(remaining_amount));

}

function enableSemi() {

    document.getElementById('custom').style.display = 'none';
    document.getElementById('auto').style.display = 'block';

    $('#remaining_amount').val(0);
    document.getElementById('semi_div').style.display = 'block';
    document.getElementById('ann_div').style.display = 'none';
    document.getElementById('quar_div').style.display = 'none';
    document.getElementById('bi_mon_div').style.display = 'none';

    price = $('#net_amount').val();
    count = $('#total_semi_installment_count').val();

     $('#installment').val( Math.round(parseFloat($('#monthly_installment_per').val()) / 100 * price / (parseInt($('#total_month_per').val()))));

    $('#total_installment').val( Math.round(parseFloat($('#monthly_installment_per').val()) / 100 * price));

    net_amount = parseInt($('#net_amount').val());
    down_payment = parseInt($('#down-payment').val());
    possession = parseInt($('#possession').val());

    monthly_installment = parseInt($('#total_installment').val());

    annual_installment = parseInt($('#total_annual_installment').val());

    allotment = parseInt($('#allotment').val());
    confirmation = parseInt($('#confirmation').val());
    booking = parseInt($('#booking').val());
    development = parseInt($('#development').val());
    file_processing = parseInt($('#file_processing').val());
    registration = parseInt($('#registration').val());


    remaining_amount = net_amount - down_payment - possession - monthly_installment - annual_installment - allotment - confirmation - booking - development - file_processing - registration;


     $('#semi-installment').val( Math.round(remaining_amount / count));
    $('#total-months').val( Math.round(parseInt($('#total_month_per').val())));

    $('#total_semi_installment').val( Math.round(remaining_amount));

}

function disableAnn(val) {

    document.getElementById('custom').style.display = 'none';
    document.getElementById('auto').style.display = 'block';

    $('#remaining_amount').val(0);
    document.getElementById('semi_div').style.display = 'none';
    document.getElementById('ann_div').style.display = 'none';
    document.getElementById('quar_div').style.display = 'none';
    document.getElementById('bi_mon_div').style.display = 'none';
    price = $('#net_amount').val();

    if(val == {{\App\CustomerProperty::inst_mon}}) {

        net_amount = parseInt($('#net_amount').val());
        down_payment = parseInt($('#down-payment').val());
        possession = parseInt($('#possession').val());

        $('#total_installment').val(Math.round(net_amount - down_payment - possession));

        $('#installment').val(Math.round((net_amount - down_payment - possession)/parseInt($('#total_month_per').val())));

        //$('#installment').val( Math.round((parseFloat($('#monthly_installment_per').val()) + parseFloat($('#annual_installment_per').val())) / 100 * price / (parseInt($('#total_month_per').val()))));
        //$('#total_installment').val( Math.round((parseFloat($('#monthly_installment_per').val()) + parseFloat($('#annual_installment_per').val())) / 100 * price));
        $('#total-months').val( Math.round(parseInt($('#total_month_per').val())));
    }
    else if(val == {{\App\CustomerProperty::inst_bi_mon}}) {

        net_amount = parseInt($('#net_amount').val());
        down_payment = parseInt($('#down-payment').val());
        possession = parseInt($('#possession').val());

        $('#total_installment').val(Math.round(net_amount - down_payment - possession));

        $('#installment').val(Math.round((net_amount - down_payment - possession)/(parseInt($('#total_month_per').val())/2)));
        //$('#installment').val( Math.round((parseFloat($('#monthly_installment_per').val()) + parseFloat($('#annual_installment_per').val())) / 100 * price / (parseInt($('#total_month_per').val() / 3))));
        //$('#total_installment').val( Math.round((parseFloat($('#monthly_installment_per').val()) + parseFloat($('#annual_installment_per').val())) / 100 * price));
        $('#total-months').val( Math.round(parseInt($('#total_month_per').val()/2)));

    }
    else if(val == {{\App\CustomerProperty::inst_quar}}) {

        net_amount = parseInt($('#net_amount').val());
        down_payment = parseInt($('#down-payment').val());
        possession = parseInt($('#possession').val());

        $('#total_installment').val(Math.round(net_amount - down_payment - possession));

        $('#installment').val(Math.round((net_amount - down_payment - possession)/(parseInt($('#total_month_per').val())/3)));
        //$('#installment').val( Math.round((parseFloat($('#monthly_installment_per').val()) + parseFloat($('#annual_installment_per').val())) / 100 * price / (parseInt($('#total_month_per').val() / 3))));
        //$('#total_installment').val( Math.round((parseFloat($('#monthly_installment_per').val()) + parseFloat($('#annual_installment_per').val())) / 100 * price));
        $('#total-months').val( Math.round(parseInt($('#total_month_per').val()/3)));

    }
    else if(val == {{\App\CustomerProperty::inst_semi}}) {

        net_amount = parseInt($('#net_amount').val());
        down_payment = parseInt($('#down-payment').val());
        possession = parseInt($('#possession').val());

        $('#total_installment').val(Math.round(net_amount - down_payment - possession));

        $('#installment').val(Math.round((net_amount - down_payment - possession)/(parseInt($('#total_month_per').val())/6)));

        //$('#installment').val( Math.round((parseFloat($('#monthly_installment_per').val()) + parseFloat($('#annual_installment_per').val())) / 100 * price / (parseInt($('#total_month_per').val()/6))));
        //$('#total_installment').val( Math.round((parseFloat($('#monthly_installment_per').val()) + parseFloat($('#annual_installment_per').val())) / 100 * price));
        $('#total-months').val( Math.round(parseInt($('#total_month_per').val()/6)));

    }
    else if(val == {{\App\CustomerProperty::inst_ann}}) {

        net_amount = parseInt($('#net_amount').val());
        down_payment = parseInt($('#down-payment').val());
        possession = parseInt($('#possession').val());

        $('#total_installment').val(Math.round(net_amount - down_payment - possession));

        $('#installment').val(Math.round((net_amount - down_payment - possession)/
            (parseInt($('#total_month_per').val()/12))));
        //$('#installment').val( Math.round((parseFloat($('#monthly_installment_per').val()) + parseFloat($('#annual_installment_per').val())) / 100 * price / (parseInt($('#total_month_per').val()/12))));
        //$('#total_installment').val( Math.round((parseFloat($('#monthly_installment_per').val()) + parseFloat($('#annual_installment_per').val())) / 100 * price));
        $('#total-months').val( Math.round(parseInt($('#total_month_per').val()/12)));

    }



}


function enableCustom(val) {
    document.getElementById('custom').style.display = 'block';
    document.getElementById('auto').style.display = 'none';

}



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

    price = $('#total_annual_installment').val();
    count = $('#total_annual_installment_count').val();

    $('#annual-installment').val(Math.round(price/count));

    $('#remaining_amount').val(0);
});




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

    price = $('#net_amount').val();
    count = $('#total_annual_installment_count').val();

    $('#annual-installment').val(Math.round($('#total_annual_installment').val()/count));

    //$('#annual-installment').val( Math.round(parseFloat($('#annual_installment_per').val()) / 100 * price / count));

});

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

    price = $('#net_amount').val();
    count = $('#total_semi_installment_count').val();

    $('#semi-installment').val(Math.round($('#total_semi_installment').val()/count)
        );

    //$('#semi-installment').val( Math.round(parseFloat($('#annual_installment_per').val()) / 100 * price / count));

});

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

    price = $('#net_amount').val();
    count = $('#total_bi_mon_installment_count').val();

    $('#bi-mon-installment').val(Math.round($('#total_bi_mon_installment').val()/count));

    //$('#quarterly-installment').val( Math.round(parseFloat($('#annual_installment_per').val()) / 100 * price / count));

});

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

    price = $('#net_amount').val();
    count = $('#total_quarterly_installment_count').val();

    $('#quarterly-installment').val(Math.round($('#total_quarterly_installment').val()/count));

    //$('#quarterly-installment').val( Math.round(parseFloat($('#annual_installment_per').val()) / 100 * price / count));

});

function number2TextConversion(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]]) + 'lac ' : '';
    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;
}


function adjustAmount(val) {

    amount = parseInt($('#remaining_amount').val());

    

    if(amount) {
        if(val == 1) 
        { //amount adjustment to per installment
            $('#total_installment').val(parseInt($('#total_installment').val()) + amount);
            $('#installment').val(Math.round( ( parseInt($('#total_installment').val())) / parseInt($('#total-months').val()) ) );

            $('#per_installment').val((( parseInt($('#installment').val()) / net_amount) * 100).toFixed(2));
        }
        else if( val == 2) 
        {
            val = parseInt($('input[name="schedule_type"]:checked').val());
        if(val =={{\App\CustomerProperty::inst_mon_w_semi}}) {
            $('#total_semi_installment').val(parseInt($('#total_semi_installment').val()) + amount);
            $('#semi-installment').val(Math.round( ( parseInt($('#total_semi_installment').val())) / parseInt($('#total_semi_installment_count').val()) ) );
        }
        else if(val =={{\App\CustomerProperty::inst_mon_w_ann}}) {
            $('#total_annual_installment').val(parseInt($('#total_annual_installment').val()) + amount);
            $('#annual-installment').val(Math.round( ( parseInt($('#total_annual_installment').val())) / parseInt($('#total_annual_installment_count').val()) ) );
        }
        else if(val =={{\App\CustomerProperty::inst_mon_w_quar}}) {

            $('#total_quarterly_installment').val(parseInt($('#total_quarterly_installment').val()) + amount);
            $('#quarterly-installment').val(Math.round( ( parseInt($('#total_quarterly_installment').val())) / parseInt($('#total_quarterly_installment_count').val()) ) );
        }

        }
        else if(val == 3) {

            $('#down-payment').val(parseInt($('#down-payment').val()) + amount);


            $('#per_down_payment').val(((parseInt($('#down-payment').val()) / net_amount) * 100).toFixed(2));

        }
        else if(val == 4) {
            $('#possession').val(parseInt($('#possession').val()) + amount);

            $('#per_possession').val(((parseInt($('#possession').val()) / net_amount) * 100).toFixed(2));
        }

        else if(val == 5) {
            $('#allotment').val(parseInt($('#allotment').val()) + amount);

            $('#per_allotment').val(((parseInt($('#allotment').val()) / net_amount) * 100).toFixed(2));
        }
        else if(val == 6) {
            $('#confirmation').val(parseInt($('#confirmation').val()) + amount);

            $('#per_confirmation').val(((parseInt($('#confirmation').val()) / net_amount) * 100).toFixed(2));
        }
        else if(val == 7) {
            $('#booking').val(parseInt($('#booking').val()) + amount);

            $('#per_booking').val(((parseInt($('#booking').val()) / net_amount) * 100).toFixed(2));
        }
        else if(val == 8) {
            $('#development').val(parseInt($('#development').val()) + amount);

            $('#per_development').val(((parseInt($('#development').val()) / net_amount) * 100).toFixed(2));
        }
        else if(val == 9) {
            $('#file_processing').val(parseInt($('#file_processing').val()) + amount);

            $('#per_file_processing').val(((parseInt($('#file_processing').val()) / net_amount) * 100).toFixed(2));
        }
        else if(val == 10) {
            $('#registration').val(parseInt($('#registration').val()) + amount);

            $('#per_registration').val(((parseInt($('#registration').val()) / net_amount) * 100).toFixed(2));
        }


        $('#remaining_amount').val(0);
        $("input:radio[name='adjust']").each(function(i) {
            this.checked = false;
        });
        updateCurrency();
    }
}

function activeNormal() {

        document.getElementById('normal').style.display = 'block';
       
        document.getElementById('full_payment').style.display = 'none';
         }

    
    function activeFullPayment() {
        document.getElementById('normal').style.display = 'none';
     
        document.getElementById('full_payment').style.display = 'block';
    }

$('#return_tenure_full_payment').change(function() {
        tenure = $('#return_tenure_full_payment').val();
            total_month = $('#total_tenure_full_payment').val();

            if(tenure == 2) {
                total_month = total_month / 3;
            }
            else if(tenure == 3) {
                total_month = total_month / 6;
            }
            else if(tenure == 4) {
                total_month = total_month / 12;
            }

            $('#per_full_payment').val(Math.round($('#net_amount_full_payment').val() / total_month));

            //update the total_installment
        num=$("#per_full_payment").val();
        var str = '';
        if ((num = num.toString()).length < 9){
            n = ('000000000' + num).substr(-9).match(/^(\d{2})(\d{2})(\d{2})(\d{1})(\d{2})$/);
            if (n){
                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]]) + 'lac ' : '';
                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 ' : '';
            }
            $("#per-full-payment-label").text(str);
        }
    });

$('#total_tenure_full_payment').keyup(function() {
        tenure = $('#return_tenure_full_payment').val();
            total_month = $('#total_tenure_full_payment').val();

            if(tenure == 2) {
                total_month = total_month / 3;
            }
            else if(tenure == 3) {
                total_month = total_month / 6;
            }
            else if(tenure == 4) {
                total_month = total_month / 12;
            }

            $('#per_full_payment').val(Math.round($('#net_amount_full_payment').val() / total_month));

            //update the total_installment
        num=$("#per_full_payment").val();
        var str = '';
        if ((num = num.toString()).length < 9){
            n = ('000000000' + num).substr(-9).match(/^(\d{2})(\d{2})(\d{2})(\d{1})(\d{2})$/);
            if (n){
                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]]) + 'lac ' : '';
                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 ' : '';
            }
            $("#per-full-payment-label").text(str);
        }
    });

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

        if($('#discount_percentage_full_payment').val()) {

            price = Math.round(parseFloat($('#discount_percentage_full_payment').val())  / 100 * $('#total_amount_full_payment').val());

            $('#discount_amount_full_payment').val(price);
            $('#net_amount_full_payment').val(price);

            //update per tenure full payment

            tenure = $('#return_tenure_full_payment').val();
            total_month = $('#total_tenure_full_payment').val();

            if(tenure == 2) {
                total_month = total_month / 3;
            }
            else if(tenure == 3) {
                total_month = total_month / 6;
            }
            else if(tenure == 4) {
                total_month = total_month / 12;
            }

            $('#per_full_payment').val(Math.round(price / total_month));



//update the total_installment
        num=$("#discount_amount_full_payment").val();
        var str = '';
        if ((num = num.toString()).length < 9){
            n = ('000000000' + num).substr(-9).match(/^(\d{2})(\d{2})(\d{2})(\d{1})(\d{2})$/);
            if (n){
                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]]) + 'lac ' : '';
                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 ' : '';
            }
            $("#discount-amount-full-payment-label").text(str);
        }

        //update the total_installment
        num=$("#net_amount_full_payment").val();
        var str = '';
        if ((num = num.toString()).length < 9){
            n = ('000000000' + num).substr(-9).match(/^(\d{2})(\d{2})(\d{2})(\d{1})(\d{2})$/);
            if (n){
                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]]) + 'lac ' : '';
                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 ' : '';
            }
            $("#net-amount-full-payment-label").text(str);
        }

        //update the total_installment
        num=$("#per_full_payment").val();
        var str = '';
        if ((num = num.toString()).length < 9){
            n = ('000000000' + num).substr(-9).match(/^(\d{2})(\d{2})(\d{2})(\d{1})(\d{2})$/);
            if (n){
                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]]) + 'lac ' : '';
                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 ' : '';
            }
            $("#per-full-payment-label").text(str);
        }
    }
    else {
            $('#discount_amount_full_payment').val('');
        }

     });

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

    if($('#deduction_amount_full_payment').val()) {

            price = Math.round(parseInt($('#discount_amount_full_payment').val()) -  parseInt($('#deduction_amount_full_payment').val()));

            $('#net_amount_full_payment').val(price);

    }
    else {
            $('#net_amount_full_payment').val($('rebate_amount_full_payment').val());
        }

        //update per tenure full payment

            tenure = $('#return_tenure_buy_back').val();
            total_month = $('#total_tenure_buy_back').val();

            if(tenure == 2) {
                total_month = total_month / 3;
            }
            else if(tenure == 3) {
                total_month = total_month / 6;
            }
            else if(tenure == 4) {
                total_month = total_month / 12;
            }

            $('#per_buy_back').val(Math.round($('#net_amount_full_payment').val() / total_month));



        //update the total_installment
        num=$("#net_amount_full_payment").val();
        var str = '';
        if ((num = num.toString()).length < 9){
            n = ('000000000' + num).substr(-9).match(/^(\d{2})(\d{2})(\d{2})(\d{1})(\d{2})$/);
            if (n){
                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]]) + 'lac ' : '';
                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 ' : '';
            }
            $("#net-amount-full-payment-label").text(str);
        }

        //update the total_installment
        num=$("#per_full_payment").val();
        var str = '';
        if ((num = num.toString()).length < 9){
            n = ('000000000' + num).substr(-9).match(/^(\d{2})(\d{2})(\d{2})(\d{1})(\d{2})$/);
            if (n){
                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]]) + 'lac ' : '';
                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 ' : '';
            }
            $("#per-full-payment-label").text(str);
        }

     });



    </script>
@stop