<script>
    //updates events on keyupr
    $('#remaining_registration').keyup(function() {
        remaining_net_amount = parseInt($('#remianing_payable').val());
        net_amount = parseInt($('#net_amount').val());
        if ($('#remaining_down-payment').val())
            down_payment = parseInt($('#remaining_down-payment').val());
        else
            down_payment = 0;
        registration = parseInt($('#remaining_registration').val());
        possession = parseFloat($('#remaining_possession').val());
        $('#remaining_per_registration').val(((registration / net_amount) * 100).toFixed(2));

        
        monthly_installment = parseInt($('#remaining_total_installment').val());
        annual_installment = 0;
        num = $("#remaining_registration").val();
        $("#remaining_registration-label").text(number2TextConversion(num));

        val = parseInt($('input[name="schedule_type"]:checked').val());
        if (val == {{ \App\CustomerProperty::inst_mon_w_semi }} || val ==
            {{ \App\CustomerProperty::inst_quar_exclude_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 }} || val ==
            {{ \App\CustomerProperty::inst_mon_exclude_quar }}) {
            annual_installment = $('#total_quarterly_installment').val();
        } else if (val == {{ \App\CustomerProperty::inst_quar_w_semi }} || val ==
            {{ \App\CustomerProperty::inst_mon_exclude_semi }}) {
            annual_installment = $('#total_semi_installment').val();
        }
        else if (val == {{ \App\CustomerProperty::inst_custom }}) {
                // monthly_installment = $('#custome_rem').val();
                monthly_installment =0;
            }
            
 var cus_amount = 0;
            $("input[name='custom_amount[]']").each(function() {
                if (!this.value) {
                    cus_amount += 0;
                } else {
                    cus_amount += parseInt($(this).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($('#remaining_allotment').val());
        confirmation = parseFloat($('#remaining_confirmation').val());
        booking = parseFloat($('#remaining_booking').val());

        file_processing = parseFloat($('#remaining_file_processing').val());
        registration = parseFloat($('#remaining_registration').val());
        balloting = parseFloat($('#remaining_balloting').val());
        ballon = parseFloat($('#remaining_ballon').val());

        if (isNaN(registration)) {
            registration = 0;
            $('#remaining_per_registration').val(0);
        }
        remaining_amount = remaining_net_amount - down_payment - possession - monthly_installment -
            annual_installment - add_amount - allotment - confirmation - booking -
            file_processing - registration - ballon - balloting - cus_amount ;
        //            console.log( 'remaining_net_amount::',remaining_net_amount ,'down_payment::', down_payment , 'possession::',possession , 'monthly_installment::',monthly_installment ,
        //              'annual_installment::',annual_installment ,'add_amount::', add_amount ,'allotment::', allotment , 'confirmation::',confirmation , 'booking::',booking ,
        //             'file_processing::', file_processing , 'registration::',registration , 'ballon::', ballon ,  'balloting::',balloting);

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

        if (radioValue == '{{ \App\CustomerProperty::inst_custom }}') {

            // parseInt($('#custome_rem').val());

            remaining_amount = parseInt(remaining_amount) + parseInt($('#custome_rem').val())
        }
        //  console.log($('#custome_rem').val(), remaining_amount);
        $('#custome_rem').val(Math.round(remaining_amount));
    });
    $('#remaining_per_registration').keyup(function() {

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

        if ($('#remaining_down-payment').val())
            down_payment = parseInt($('#remaining_down-payment').val());
        else
            down_payment = 0;
        per_registration = parseFloat($('#remaining_per_registration').val());
        possession = parseFloat($('#remaining_possession').val());
        $('#remaining_registration').val(percentage(net_amount, per_registration));
        monthly_installment = parseInt($('#remaining_total_installment').val());
        annual_installment = 0;
        num = $("#remaining_registration").val();
        $("#remaining_registration-label").text(number2TextConversion(num));
        val = parseInt($('input[name="schedule_type"]:checked').val());
        if (val == {{ \App\CustomerProperty::inst_mon_w_semi }} || val ==
            {{ \App\CustomerProperty::inst_quar_exclude_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 }} || val ==
            {{ \App\CustomerProperty::inst_mon_exclude_quar }}) {
            annual_installment = $('#total_quarterly_installment').val();
        } else if (val == {{ \App\CustomerProperty::inst_quar_w_semi }} || val ==
            {{ \App\CustomerProperty::inst_mon_exclude_semi }}) {
            annual_installment = $('#total_semi_installment').val();
        }
        else if (val == {{ \App\CustomerProperty::inst_custom }}) {
                // monthly_installment = $('#custome_rem').val();
                monthly_installment =0;
            }
        var add_amount = 0;
        $("input[name='add_amount[]']").each(function() {
            if (!this.value) {
                add_amount += 0;
            } else {
                add_amount += parseInt($(this).val());
            }

        });
        var cus_amount = 0;
            $("input[name='custom_amount[]']").each(function() {
                if (!this.value) {
                    cus_amount += 0;
                } else {
                    cus_amount += parseInt($(this).val());
                }
            });
        allotment = parseFloat($('#remaining_allotment').val());
        confirmation = parseFloat($('#remaining_confirmation').val());
        booking = parseFloat($('#remaining_booking').val());

        file_processing = parseFloat($('#remaining_file_processing').val());
        registration = parseFloat($('#remaining_registration').val());
        balloting = parseFloat($('#remaining_balloting').val());
        ballon = parseFloat($('#remaining_ballon').val());

        if (isNaN(registration)) {
            registration = 0;
                $('#remaining_registration').val(0);

            }
        remaining_amount = remaining_net_amount - down_payment - possession - monthly_installment -
            annual_installment - add_amount - allotment - confirmation - booking -
            file_processing - registration - ballon - balloting - cus_amount;
        $('#remaining_amount').val(remaining_amount);
        var radioValue = $("input[name='schedule_type']:checked").val();
        if (radioValue == '{{ \App\CustomerProperty::inst_custom }}') {
            if(isNaN(parseInt($('#custome_rem').val()))){
                $('#custome_rem').val(0);
            }

            // remaining_amount = remaining_amount + parseInt($('#custome_rem').val())
        }
        $('#custome_rem').val(Math.round(remaining_amount));
    });


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


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

        if ($('#remaining_down-payment').val())
            down_payment = parseInt($('#remaining_down-payment').val());
        else
            down_payment = 0;
        file_processing = parseInt($('#remaining_file_processing').val());
        possession = parseFloat($('#remaining_possession').val());
        $('#remaining_per_file_processing').val(((file_processing / net_amount) * 100).toFixed(2));

        if (isNaN(file_processing)) {
            file_processing = 0;
            $('#remaining_per_file_processing').val(0);
        }
        monthly_installment = parseInt($('#remaining_total_installment').val());
        annual_installment = 0;

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

        val = parseInt($('input[name="schedule_type"]:checked').val());
        if (val == {{ \App\CustomerProperty::inst_mon_w_semi }} || val ==
            {{ \App\CustomerProperty::inst_quar_exclude_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 }} || val ==
            {{ \App\CustomerProperty::inst_mon_exclude_quar }}) {
            annual_installment = $('#total_quarterly_installment').val();
        } else if (val == {{ \App\CustomerProperty::inst_quar_w_semi }} || val ==
            {{ \App\CustomerProperty::inst_mon_exclude_semi }}) {
            annual_installment = $('#total_semi_installment').val();
        }
        else if (val == {{ \App\CustomerProperty::inst_custom }}) {
                // monthly_installment = $('#custome_rem').val();
                monthly_installment =0;
            }
            
 var cus_amount = 0;
            $("input[name='custom_amount[]']").each(function() {
                if (!this.value) {
                    cus_amount += 0;
                } else {
                    cus_amount += parseInt($(this).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($('#remaining_allotment').val());
        confirmation = parseFloat($('#remaining_confirmation').val());
        booking = parseFloat($('#remaining_booking').val());

        // file_processing = parseFloat($('#remaining_file_processing').val());
        registration = parseFloat($('#remaining_registration').val());
        balloting = parseFloat($('#remaining_balloting').val());
        ballon = parseFloat($('#remaining_ballon').val());


        if(monthly_installment == '')
        {
            monthly_installment=0;  
            $('#custome_rem').val(0);
        }
        remaining_amount = remaining_net_amount - down_payment - possession - monthly_installment -
            annual_installment - add_amount - allotment - confirmation - booking -
            file_processing - registration - balloting - ballon - cus_amount ;

            console.log(  remaining_net_amount , down_payment , possession , monthly_installment ,
            annual_installment , add_amount , allotment , confirmation , booking ,
            file_processing , registration , balloting , ballon , cus_amount);


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

        if (radioValue == '{{ \App\CustomerProperty::inst_custom }}') {
            if(isNaN(parseInt($('#custome_rem').val()))){
                $('#custome_rem').val(0);
            }

            // remaining_amount = remaining_amount + parseInt($('#custome_rem').val())
        }
        $('#custome_rem').val(Math.round(remaining_amount));
    });
    $('#remaining_per_file_processing').keyup(function() {
        remaining_net_amount = parseInt($('#remianing_payable').val());
        net_amount = parseInt($('#net_amount').val());

        if ($('#remaining_down-payment').val())
            down_payment = parseInt($('#remaining_down-payment').val());
        else
            down_payment = 0;
        per_file_processing = parseFloat($('#remaining_per_file_processing').val());
        possession = parseFloat($('#remaining_possession').val());
         
        $('#remaining_file_processing').val(percentage(net_amount, per_file_processing));
        monthly_installment = parseInt($('#remaining_total_installment').val());
        annual_installment = 0;
        num = $("#remaining_file_processing").val();
        $("#remaining_file_processing-label").text(number2TextConversion(num));
        val = parseInt($('input[name="schedule_type"]:checked').val());
        if (val == {{ \App\CustomerProperty::inst_mon_w_semi }} || val ==
            {{ \App\CustomerProperty::inst_quar_exclude_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 }} || val ==
            {{ \App\CustomerProperty::inst_mon_exclude_quar }}) {
            annual_installment = $('#total_quarterly_installment').val();
        } else if (val == {{ \App\CustomerProperty::inst_quar_w_semi }} || val ==
            {{ \App\CustomerProperty::inst_mon_exclude_semi }}) {
            annual_installment = $('#total_semi_installment').val();
        }
        else if (val == {{ \App\CustomerProperty::inst_custom }}) {
                // monthly_installment = $('#custome_rem').val();
                monthly_installment =0;
            }
            var cus_amount = 0;
            $("input[name='custom_amount[]']").each(function() {
                if (!this.value) {
                    cus_amount += 0;
                } else {
                    cus_amount += parseInt($(this).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($('#remaining_allotment').val());
        confirmation = parseFloat($('#remaining_confirmation').val());
        booking = parseFloat($('#remaining_booking').val());

        file_processing = parseFloat($('#remaining_file_processing').val());
        registration = parseFloat($('#remaining_registration').val());
        balloting = parseFloat($('#remaining_balloting').val());
        ballon = parseFloat($('#remaining_ballon').val());
        if (isNaN(possession)) {
            possession = 0;
                $('#remaining_possession').val(0);

            }


        remaining_amount = remaining_net_amount - down_payment - possession - monthly_installment -
            annual_installment - add_amount - allotment - confirmation - booking -
            file_processing - registration - balloting - ballon - cus_amount ;


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

        if (radioValue == '{{ \App\CustomerProperty::inst_custom }}') {
            if(isNaN(parseInt($('#custome_rem').val()))){
                $('#custome_rem').val(0);
            }

            // remaining_amount = remaining_amount + parseInt($('#custome_rem').val())
        }
        $('#custome_rem').val(Math.round(remaining_amount));
    });


    $('#remaining_booking').keyup(function() {
        remaining_net_amount = parseInt($('#remianing_payable').val());
        net_amount = parseInt($('#net_amount').val());
 

        if ($('#remaining_down-payment').val())
            down_payment = parseInt($('#remaining_down-payment').val());
        else
            down_payment = 0;
        booking = parseInt($('#remaining_booking').val());
        possession = parseFloat($('#remaining_possession').val());
        $('#remaining_per_booking').val(((booking / net_amount) * 100).toFixed(2));
      
        monthly_installment = parseInt($('#remaining_total_installment').val());
        annual_installment = 0;

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

        val = parseInt($('input[name="schedule_type"]:checked').val());
        if (val == {{ \App\CustomerProperty::inst_mon_w_semi }} || val ==
            {{ \App\CustomerProperty::inst_quar_exclude_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 }} || val ==
            {{ \App\CustomerProperty::inst_mon_exclude_quar }}) {
            annual_installment = $('#total_quarterly_installment').val();
        } else if (val == {{ \App\CustomerProperty::inst_quar_w_semi }} || val ==
            {{ \App\CustomerProperty::inst_mon_exclude_semi }}) {
            annual_installment = $('#total_semi_installment').val();
        }
        else if (val == {{ \App\CustomerProperty::inst_custom }}) {
                // monthly_installment = $('#custome_rem').val();
                monthly_installment =0;
            }
            var cus_amount = 0;
            $("input[name='custom_amount[]']").each(function() {
                if (!this.value) {
                    cus_amount += 0;
                } else {
                    cus_amount += parseInt($(this).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($('#remaining_allotment').val());
        confirmation = parseFloat($('#remaining_confirmation').val());

        booking = parseFloat($('#remaining_booking').val());
        if (isNaN(booking)) {
            booking = 0;
            $('#remaining_per_booking').val(0);
        }
        file_processing = parseFloat($('#remaining_file_processing').val());
        registration = parseFloat($('#remaining_registration').val());
        balloting = parseFloat($('#remaining_balloting').val());
        ballon = parseFloat($('#remaining_ballon').val());


        remaining_amount = remaining_net_amount - down_payment - possession - monthly_installment -
            annual_installment - add_amount - allotment - confirmation - booking -
            file_processing - registration - balloting - ballon - cus_amount ;


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

        if (radioValue == '{{ \App\CustomerProperty::inst_custom }}') {
            if(isNaN(parseInt($('#custome_rem').val()))){
                $('#custome_rem').val(0);
            }

            // remaining_amount = remaining_amount + parseInt($('#custome_rem').val())
        }
        $('#custome_rem').val(Math.round(remaining_amount));
    });
    $('#remaining_per_booking').keyup(function() {
        remaining_net_amount = parseInt($('#remianing_payable').val());
        net_amount = parseInt($('#net_amount').val());
        // net_amount = parseInt($('#remianing_payable').val());
        if ($('#remaining_down-payment').val())
            down_payment = parseInt($('#remaining_down-payment').val());
        else
            down_payment = 0;
        per_booking = parseFloat($('#remaining_per_booking').val());
        possession = parseFloat($('#remaining_possession').val());

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

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

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

        val = parseInt($('input[name="schedule_type"]:checked').val());
        if (val == {{ \App\CustomerProperty::inst_mon_w_semi }} || val ==
            {{ \App\CustomerProperty::inst_quar_exclude_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 }} || val ==
            {{ \App\CustomerProperty::inst_mon_exclude_quar }}) {
            annual_installment = $('#total_quarterly_installment').val();
        } else if (val == {{ \App\CustomerProperty::inst_quar_w_semi }} || val ==
            {{ \App\CustomerProperty::inst_mon_exclude_semi }}) {
            annual_installment = $('#total_semi_installment').val();
        }
        else if (val == {{ \App\CustomerProperty::inst_custom }}) {
                // monthly_installment = $('#custome_rem').val();
                monthly_installment =0;
            }

        var add_amount = 0;

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

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


        allotment = parseFloat($('#remaining_allotment').val());
        confirmation = parseFloat($('#remaining_confirmation').val());
        booking = parseFloat($('#remaining_booking').val());

        file_processing = parseFloat($('#remaining_file_processing').val());
        registration = parseFloat($('#remaining_registration').val());
        balloting = parseFloat($('#remaining_balloting').val());
        ballon = parseFloat($('#remaining_ballon').val());


        if (isNaN(booking)) {
                booking = 0;
                $('#remaining_booking').val(0);

            }

        remaining_amount = remaining_net_amount - down_payment - possession - monthly_installment -
            annual_installment - add_amount - allotment - confirmation - booking -
            file_processing - registration - balloting - ballon - cus_amount;

           

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

        if (radioValue == '{{ \App\CustomerProperty::inst_custom }}') {
            if(isNaN(parseInt($('#custome_rem').val()))){
                $('#custome_rem').val(0);
            }

            // remaining_amount = remaining_amount + parseInt($('#custome_rem').val())
        }
        $('#custome_rem').val(Math.round(remaining_amount));
    });



    $('#remaining_confirmation').keyup(function() {
        remaining_net_amount = parseInt($('#remianing_payable').val());
        net_amount = parseInt($('#net_amount').val());
        if ($('#remaining_confirmation').val())
            confirmation = parseInt($('#remaining_confirmation').val());
        else
            confirmation = 0;

        possession = parseFloat($('#remaining_possession').val());
        $('#remaining_per_confirmation').val(((confirmation / net_amount) * 100).toFixed(2));
        monthly_installment = parseInt($('#remaining_total_installment').val());
        annual_installment = 0;
        num = $("#remaining_confirmation").val();
        $("#remaining_confirmation-label").text(number2TextConversion(num));
        val = parseInt($('input[name="schedule_type"]:checked').val());
        if (val == {{ \App\CustomerProperty::inst_mon_w_semi }} || val ==
            {{ \App\CustomerProperty::inst_quar_exclude_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 }} || val ==
            {{ \App\CustomerProperty::inst_mon_exclude_quar }}) {
            annual_installment = $('#total_quarterly_installment').val();
        } else if (val == {{ \App\CustomerProperty::inst_quar_w_semi }} || val ==
            {{ \App\CustomerProperty::inst_mon_exclude_semi }}) {
            annual_installment = $('#total_semi_installment').val();
        }
        else if (val == {{ \App\CustomerProperty::inst_custom }}) {
                // monthly_installment = $('#custome_rem').val();
                monthly_installment =0;
            }
        var add_amount = 0;
        $("input[name='add_amount[]']").each(function() {
            if (!this.value) {
                add_amount += 0;
            } else {
                add_amount += parseInt($(this).val());
            }
        });
        var cus_amount = 0;
            $("input[name='custom_amount[]']").each(function() {
                if (!this.value) {
                    cus_amount += 0;
                } else {
                    cus_amount += parseInt($(this).val());
                }
            });
        allotment = parseFloat($('#remaining_allotment').val());

        booking = parseFloat($('#remaining_booking').val());
        down_payment = parseInt($('#remaining_down-payment').val());
        file_processing = parseFloat($('#remaining_file_processing').val());
        registration = parseFloat($('#remaining_registration').val());
        balloting = parseFloat($('#remaining_balloting').val());

        ballon = parseFloat($('#remaining_ballon').val());
        if (isNaN(confirmation)) {
            confirmation = 0;
                $('#remaining_per_confirmation').val(0);

            }

        // console.log('remaining_net_amount::', remaining_net_amount, 'down_payment::', down_payment,
        //     'possession::', possession, 'monthly_installment::', monthly_installment,
        //     'annual_installment::', annual_installment, 'add_amount::', add_amount, 'allotment::',
        //     allotment, 'confirmation::', confirmation, 'booking::', booking,
        //     'file_processing:', file_processing, 'registration::', registration, 'balloting::', balloting,
        //     'ballon::', ballon);

        remaining_amount = remaining_net_amount - down_payment - possession - monthly_installment -
            annual_installment - add_amount - allotment - confirmation - booking -
            file_processing - registration - balloting - ballon - cus_amount ;


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

        if (radioValue == '{{ \App\CustomerProperty::inst_custom }}') {
            if(isNaN(parseInt($('#custome_rem').val()))){
                $('#custome_rem').val(0);
            }

            // remaining_amount = remaining_amount + parseInt($('#custome_rem').val())
        }
        $('#custome_rem').val(Math.round(remaining_amount));
    });
    $('#remaining_per_confirmation').keyup(function() {
        remaining_net_amount = parseInt($('#remianing_payable').val());
        net_amount = parseInt($('#net_amount').val());
        if ($('#remaining_down-payment').val())
            down_payment = parseInt($('#remaining_down-payment').val());
        else
            down_payment = 0;
        per_confirmation = parseFloat($('#remaining_per_confirmation').val());
        possession = parseFloat($('#remaining_possession').val());
        $('#remaining_confirmation').val(percentage(net_amount, per_confirmation));
        monthly_installment = parseInt($('#remaining_total_installment').val());
        annual_installment = 0;
        num = $("#remaining_confirmation").val();
        $("#remaining_confirmation-label").text(number2TextConversion(num));
        val = parseInt($('input[name="schedule_type"]:checked').val());
        if (val == {{ \App\CustomerProperty::inst_mon_w_semi }} || val ==
            {{ \App\CustomerProperty::inst_quar_exclude_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 }} || val ==
            {{ \App\CustomerProperty::inst_mon_exclude_quar }}) {
            annual_installment = $('#total_quarterly_installment').val();
        } else if (val == {{ \App\CustomerProperty::inst_quar_w_semi }} || val ==
            {{ \App\CustomerProperty::inst_mon_exclude_semi }}) {
            annual_installment = $('#total_semi_installment').val();
        }
        else if (val == {{ \App\CustomerProperty::inst_custom }}) {
                // monthly_installment = $('#custome_rem').val();
                monthly_installment =0;
            }
            var cus_amount = 0;
            $("input[name='custom_amount[]']").each(function() {
                if (!this.value) {
                    cus_amount += 0;
                } else {
                    cus_amount += parseInt($(this).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($('#remaining_allotment').val());
        confirmation = parseFloat($('#remaining_confirmation').val());
        booking = parseFloat($('#remaining_booking').val());

        file_processing = parseFloat($('#remaining_file_processing').val());
        registration = parseFloat($('#remaining_registration').val());
        balloting = parseFloat($('#remaining_balloting').val());
        ballon = parseFloat($('#remaining_ballon').val());
        if (isNaN(confirmation)) {
            confirmation = 0;
                $('#remaining_confirmation').val(0);

            }

        remaining_amount = remaining_net_amount - down_payment - possession - monthly_installment -
            annual_installment - add_amount - allotment - confirmation - booking -
            file_processing - registration - balloting - ballon - cus_amount ;


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

        if (radioValue == '{{ \App\CustomerProperty::inst_custom }}') {
            if(isNaN(parseInt($('#custome_rem').val()))){
                $('#custome_rem').val(0);
            }

            // remaining_amount = remaining_amount + parseInt($('#custome_rem').val())
        }
        $('#custome_rem').val(Math.round(remaining_amount));
    });


    $('#remaining_allotment').keyup(function() {
        remaining_net_amount = parseInt($('#remianing_payable').val());
        net_amount = parseInt($('#net_amount').val());
        if ($('#remaining_down-payment').val())
            down_payment = parseInt($('#remaining_down-payment').val());
        else
            down_payment = 0;
        possession = parseFloat($('#remaining_possession').val());
        allotment = parseFloat($('#remaining_allotment').val());
        $('#remaining_per_allotment').val(((allotment / net_amount) * 100).toFixed(2));
        if (isNaN(allotment)) {
            allotment = 0;
            $('#remaining_per_allotment').val(0);
        }
        monthly_installment = parseInt($('#remaining_total_installment').val());
        annual_installment = 0;
        num = $("#remaining_allotment").val();
        $("#remaining_allotment-label").text(number2TextConversion(num));
        val = parseInt($('input[name="schedule_type"]:checked').val());
        if (val == {{ \App\CustomerProperty::inst_mon_w_semi }} || val ==
            {{ \App\CustomerProperty::inst_quar_exclude_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 }} || val ==
            {{ \App\CustomerProperty::inst_mon_exclude_quar }}) {
            annual_installment = $('#total_quarterly_installment').val();
        } else if (val == {{ \App\CustomerProperty::inst_quar_w_semi }} || val ==
            {{ \App\CustomerProperty::inst_mon_exclude_semi }}) {
            annual_installment = $('#total_semi_installment').val();
        }
        else if (val == {{ \App\CustomerProperty::inst_custom }}) {
                // monthly_installment = $('#custome_rem').val();
                monthly_installment =0;
            }
            var cus_amount = 0;
            $("input[name='custom_amount[]']").each(function() {
                if (!this.value) {
                    cus_amount += 0;
                } else {
                    cus_amount += parseInt($(this).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($('#remaining_allotment').val());
        confirmation = parseFloat($('#remaining_confirmation').val());
        booking = parseFloat($('#remaining_booking').val());

        file_processing = parseFloat($('#remaining_file_processing').val());
        registration = parseFloat($('#remaining_registration').val());
        balloting = parseFloat($('#remaining_balloting').val());
        ballon = parseFloat($('#remaining_ballon').val());

        if (isNaN(allotment)) {
            allotment = 0;
            $('#remaining_per_allotment').val(0);
        }
        remaining_amount = remaining_net_amount - down_payment - possession - monthly_installment -
            annual_installment - add_amount - allotment - confirmation - booking -
            file_processing - registration - balloting - ballon - cus_amount;
        $('#remaining_amount').val(remaining_amount);
        var radioValue = $("input[name='schedule_type']:checked").val();

        if (radioValue == '{{ \App\CustomerProperty::inst_custom }}') {
            if(isNaN(parseInt($('#custome_rem').val()))){
                $('#custome_rem').val(0);
            }

            // remaining_amount = remaining_amount + parseInt($('#custome_rem').val())
        }
        $('#custome_rem').val(Math.round(remaining_amount));
    });
    $('#remaining_per_allotment').keyup(function() {
        remaining_net_amount = parseInt($('#remianing_payable').val());
        net_amount = parseInt($('#net_amount').val());
        if ($('#remaining_down-payment').val())
            down_payment = parseInt($('#remaining_down-payment').val());
        else
            down_payment = 0;
        allotment_per = parseFloat($('#remaining_per_allotment').val());
        possession = parseFloat($('#remaining_possession').val());
        $('#remaining_allotment').val(percentage(net_amount, allotment_per));
        monthly_installment = parseInt($('#remaining_total_installment').val());
        annual_installment = 0;
        num = $("#remaining_allotment").val();
        $("#remaining_allotment-label").text(number2TextConversion(num));
        val = parseInt($('input[name="schedule_type"]:checked').val());
        if (val == {{ \App\CustomerProperty::inst_mon_w_semi }} || val ==
            {{ \App\CustomerProperty::inst_quar_exclude_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 }} || val ==
            {{ \App\CustomerProperty::inst_mon_exclude_quar }}) {
            annual_installment = $('#total_quarterly_installment').val();
        } else if (val == {{ \App\CustomerProperty::inst_quar_w_semi }} || val ==
            {{ \App\CustomerProperty::inst_mon_exclude_semi }}) {
            annual_installment = $('#total_semi_installment').val();
        }
        else if (val == {{ \App\CustomerProperty::inst_custom }}) {
                // monthly_installment = $('#custome_rem').val();
                monthly_installment =0;
                
            }
        var add_amount = 0;
        $("input[name='add_amount[]']").each(function() {
            if (!this.value) {
                add_amount += 0;
            } else {
                add_amount += parseInt($(this).val());
            }

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

        allotment = parseFloat($('#remaining_allotment').val());
        confirmation = parseFloat($('#remaining_confirmation').val());
        booking = parseFloat($('#remaining_booking').val());
        development = parseFloat($('#remaining_development').val());
        file_processing = parseFloat($('#remaining_file_processing').val());
        registration = parseFloat($('#remaining_registration').val());
        balloting = parseFloat($('#remaining_balloting').val());
        ballon = parseFloat($('#remaining_ballon').val());

        if (isNaN(allotment)) {
            allotment = 0;
                $('#remaining_allotment').val(0);

            }
        remaining_amount = remaining_net_amount - down_payment - possession - monthly_installment -
            annual_installment - add_amount - allotment - confirmation - booking -
            file_processing - registration - balloting - ballon - cus_amount ;


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

        if (radioValue == '{{ \App\CustomerProperty::inst_custom }}') {
            if(isNaN(parseInt($('#custome_rem').val()))){
                $('#custome_rem').val(0);
            }

            // remaining_amount = remaining_amount + parseInt($('#custome_rem').val())
        }
        $('#custome_rem').val(Math.round(remaining_amount));
    });


    $('#remaining_possession').keyup(function() {
        remaining_net_amount = parseInt($('#remianing_payable').val());
        net_amount = parseInt($('#net_amount').val());
        if ($('#remaining_down-payment').val())
            down_payment = parseInt($('#remaining_down-payment').val());
        else
            down_payment = 0;
        possession = parseInt($('#remaining_possession').val());
        $('#remaining_per_possession').val(((possession / net_amount) * 100).toFixed(2));


        if (isNaN(possession)) {
            possession = 0;
            $('#remaining_per_possession').val(0);

        }

        monthly_installment = parseInt($('#remaining_total_installment').val());
        annual_installment = 0;
        num = $("#remaining_possession").val();
        $("#remaining_possession-label").text(number2TextConversion(num));
        val = parseInt($('input[name="schedule_type"]:checked').val());
        if (val == {{ \App\CustomerProperty::inst_mon_w_semi }} || val ==
            {{ \App\CustomerProperty::inst_quar_exclude_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 }} || val ==
            {{ \App\CustomerProperty::inst_mon_exclude_quar }}) {
            annual_installment = $('#total_quarterly_installment').val();
        } else if (val == {{ \App\CustomerProperty::inst_quar_w_semi }} || val ==
            {{ \App\CustomerProperty::inst_mon_exclude_semi }}) {
            annual_installment = $('#total_semi_installment').val();
        }
        else if (val == {{ \App\CustomerProperty::inst_custom }}) {
                // monthly_installment = $('#custome_rem').val();
                monthly_installment =0;
            }
        var add_amount = 0;
        $("input[name='add_amount[]']").each(function() {
            if (!this.value) {
                add_amount += 0;
            } else {
                add_amount += parseInt($(this).val());
            }

        });
        var cus_amount = 0;
            $("input[name='custom_amount[]']").each(function() {
                if (!this.value) {
                    cus_amount += 0;
                } else {
                    cus_amount += parseInt($(this).val());
                }
            });
        allotment = parseFloat($('#remaining_allotment').val());
        confirmation = parseFloat($('#remaining_confirmation').val());
        booking = parseFloat($('#remaining_booking').val());

        file_processing = parseFloat($('#remaining_file_processing').val());
        registration = parseFloat($('#remaining_registration').val());
        balloting = parseFloat($('#remaining_balloting').val());
        ballon = parseFloat($('#remaining_ballon').val());
        if (isNaN(possession)) {
            possession = 0;
                $('#remaining_per_possession').val(0);

            }
        remaining_amount = remaining_net_amount - down_payment - possession - monthly_installment -
            annual_installment - add_amount - allotment - confirmation - booking -
            file_processing - registration - balloting - ballon - cus_amount;
        $('#remaining_amount').val(remaining_amount);
        var radioValue = $("input[name='schedule_type']:checked").val();
        if (radioValue == '{{ \App\CustomerProperty::inst_custom }}') {
            if(isNaN(parseInt($('#custome_rem').val()))){
                $('#custome_rem').val(0);
            }

            // remaining_amount = remaining_amount + parseInt($('#custome_rem').val())
        }
        $('#custome_rem').val(Math.round(remaining_amount));
    });
    $('#remaining_per_possession').keyup(function() {
        remaining_net_amount = parseInt($('#remianing_payable').val());
        net_amount = parseInt($('#net_amount').val());
        possession_per = parseFloat($('#remaining_per_possession').val());
        $('#remaining_possession').val(percentage(net_amount, possession_per));

        if ($('#remaining_down-payment').val())
            down_payment = parseInt($('#remaining_down-payment').val());
        else
            down_payment = 0;
        possession = parseFloat($('#remaining_possession').val());
        monthly_installment = parseInt($('#remaining_total_installment').val());
        annual_installment = 0;
        num = $("#remaining_possession").val();
        $("#remaining_possession-label").text(number2TextConversion(num));

        val = parseInt($('input[name="schedule_type"]:checked').val());
        if (val == {{ \App\CustomerProperty::inst_mon_w_semi }} || val ==
            {{ \App\CustomerProperty::inst_quar_exclude_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 }} || val ==
            {{ \App\CustomerProperty::inst_mon_exclude_quar }}) {
            annual_installment = $('#total_quarterly_installment').val();
        } else if (val == {{ \App\CustomerProperty::inst_quar_w_semi }} || val ==
            {{ \App\CustomerProperty::inst_mon_exclude_semi }}) {
            annual_installment = $('#total_semi_installment').val();
        }
        else if (val == {{ \App\CustomerProperty::inst_custom }}) {
                // monthly_installment = $('#custome_rem').val();
                monthly_installment =0;
            }
            var cus_amount = 0;
            $("input[name='custom_amount[]']").each(function() {
                if (!this.value) {
                    cus_amount += 0;
                } else {
                    cus_amount += parseInt($(this).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($('#remaining_allotment').val());
        confirmation = parseFloat($('#remaining_confirmation').val());
        booking = parseFloat($('#remaining_booking').val());

        file_processing = parseFloat($('#remaining_file_processing').val());
        registration = parseFloat($('#remaining_registration').val());
        balloting = parseFloat($('#remaining_balloting').val());
        ballon = parseFloat($('#remaining_ballon').val());
        if (isNaN(possession)) {
            possession = 0;
                $('#remaining_possession').val(0);

            }
        remaining_amount = remaining_net_amount - down_payment - possession - monthly_installment -
            annual_installment - add_amount - allotment - confirmation - booking -
            file_processing - registration - balloting - ballon - cus_amount;
        $('#remaining_amount').val(remaining_amount);
        var radioValue = $("input[name='schedule_type']:checked").val();

        if (radioValue == '{{ \App\CustomerProperty::inst_custom }}') {
            if(isNaN(parseInt($('#custome_rem').val()))){
                $('#custome_rem').val(0);
            }

            // remaining_amount = remaining_amount + parseInt($('#custome_rem').val())
      }
        $('#custome_rem').val(Math.round(remaining_amount));
    });


    $('#remaining_down-payment').keyup(function() {
        remaining_net_amount = parseInt($('#remianing_payable').val());
        net_amount = parseInt($('#net_amount').val());
        if ($('#remaining_down-payment').val())
            down_payment = parseInt($('#remaining_down-payment').val());
        else
            down_payment = 0;
        monthly_installment = parseInt($('#remaining_total_installment').val());
        $('#remaining_per_down_payment').val(((down_payment / net_amount) * 100).toFixed(2));
        possession = parseInt($('#remaining_possession').val());
        num = $("#remaining_down-payment").val();
        $("#remaining_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 }} || val ==
            {{ \App\CustomerProperty::inst_quar_exclude_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 }} || val ==
            {{ \App\CustomerProperty::inst_mon_exclude_quar }}) {
            annual_installment = $('#total_quarterly_installment').val();
        } else if (val == {{ \App\CustomerProperty::inst_quar_w_semi }} || val ==
            {{ \App\CustomerProperty::inst_mon_exclude_semi }}) {
            annual_installment = $('#total_semi_installment').val();
        }
        else if (val == {{ \App\CustomerProperty::inst_custom }}) {
                // monthly_installment = $('#custome_rem').val();
                monthly_installment =0;
            }
        var add_amount = 0;
        $("input[name='add_amount[]']").each(function() {
            if (!this.value) {
                add_amount += 0;
            } else {
                add_amount += parseInt($(this).val());
            }

        });
        
 var cus_amount = 0;
            $("input[name='custom_amount[]']").each(function() {
                if (!this.value) {
                    cus_amount += 0;
                } else {
                    cus_amount += parseInt($(this).val());
                }
            });
        allotment = parseFloat($('#remaining_allotment').val());
        confirmation = parseFloat($('#remaining_confirmation').val());
        booking = parseFloat($('#remaining_booking').val());

        file_processing = parseFloat($('#remaining_file_processing').val());
        registration = parseFloat($('#remaining_registration').val());
        balloting = parseFloat($('#remaining_balloting').val());
        ballon = parseFloat($('#remaining_ballon').val());
        if (isNaN(down_payment)) {
            down_payment = 0;
                $('#remaining_per_down_payment').val(0);

            }
        remaining_amount = remaining_net_amount - down_payment - possession - monthly_installment -
            annual_installment - add_amount - allotment - confirmation - booking -
            file_processing - registration - balloting - ballon - cus_amount ;
        $('#remaining_amount').val(remaining_amount);
        var radioValue = $("input[name='schedule_type']:checked").val();
        if (radioValue == '{{ \App\CustomerProperty::inst_custom }}') {
            if(isNaN(parseInt($('#custome_rem').val()))){
                $('#custome_rem').val(0);
            }

            // remaining_amount = remaining_amount + parseInt($('#custome_rem').val())
        }
        $('#custome_rem').val(Math.round(remaining_amount));
    });
    $('#remaining_per_down_payment').keyup(function() {
        remaining_net_amount = parseInt($('#remianing_payable').val());
        net_amount = parseInt($('#net_amount').val());
        // possession = parseInt($('#possession').val());
        monthly_installment = parseInt($('#remaining_total_installment').val());
        per_down_payment = parseFloat($('#remaining_per_down_payment').val());
        $('#remaining_down-payment').val(percentage(net_amount, per_down_payment));
        possession = parseFloat($('#remaining_possession').val());
        if ($('#remaining_down-payment').val())
            down_payment = parseInt($('#remaining_down-payment').val());
        else
            down_payment = 0;
        num = $("#remaining_down-payment").val();
        $("#remaining_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 }} || val ==
            {{ \App\CustomerProperty::inst_quar_exclude_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 }} || val ==
            {{ \App\CustomerProperty::inst_mon_exclude_quar }}) {
            annual_installment = $('#total_quarterly_installment').val();
        } else if (val == {{ \App\CustomerProperty::inst_quar_w_semi }} || val ==
            {{ \App\CustomerProperty::inst_mon_exclude_semi }}) {
            annual_installment = $('#total_semi_installment').val();
        }
        else if (val == {{ \App\CustomerProperty::inst_custom }}) {
                // monthly_installment = $('#custome_rem').val();
                monthly_installment =0;
            }
        var add_amount = 0;
        $("input[name='add_amount[]']").each(function() {
            if (!this.value) {
                add_amount += 0;
            } else {
                add_amount += parseInt($(this).val());
            }

        });
        var cus_amount = 0;
            $("input[name='custom_amount[]']").each(function() {
                if (!this.value) {
                    cus_amount += 0;
                } else {
                    cus_amount += parseInt($(this).val());
                }
            });
        allotment = parseFloat($('#remaining_allotment').val());
        confirmation = parseFloat($('#remaining_confirmation').val());
        booking = parseFloat($('#remaining_booking').val());

        file_processing = parseFloat($('#remaining_file_processing').val());
        registration = parseFloat($('#remaining_registration').val());
        balloting = parseFloat($('#remaining_balloting').val());
        ballon = parseFloat($('#remaining_ballon').val());
        if (isNaN(down_payment)) {
            down_payment = 0;
                $('#remaining_down-payment').val(0);

            }

        remaining_amount = remaining_net_amount - down_payment - possession - monthly_installment -
            annual_installment - add_amount - allotment - confirmation - booking -
            file_processing - registration - balloting - ballon -cus_amount ;
        $('#remaining_amount').val(remaining_amount);
        var radioValue = $("input[name='schedule_type']:checked").val();
        if (radioValue == '{{ \App\CustomerProperty::inst_custom }}') {
            if(isNaN(parseInt($('#custome_rem').val()))){
                $('#custome_rem').val(0);
            }

            // remaining_amount = remaining_amount + parseInt($('#custome_rem').val())
        }
        $('#custome_rem').val(Math.round(remaining_amount));
    });

    //remaining ballon 
    $('#remaining_ballon').keyup(function() {
        remaining_net_amount = parseInt($('#remianing_payable').val());
        net_amount = parseInt($('#net_amount').val());
        if ($('#remaining_ballon').val())
            ballon = parseInt($('#remaining_ballon').val());
        else
            ballon = 0;
        monthly_installment = parseInt($('#remaining_total_installment').val());
        $('#remaining_per_file_ballon').val(((ballon / net_amount) * 100).toFixed(2));
        possession = parseInt($('#remaining_possession').val());
        num = $("#remaining_ballon").val();
        $("#remaining_ballon-label").text(number2TextConversion(num));
        annual_installment = 0;
        val = parseInt($('input[name="schedule_type"]:checked').val());

        if (val == {{ \App\CustomerProperty::inst_mon_w_semi }} || val ==
            {{ \App\CustomerProperty::inst_quar_exclude_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 }} || val ==
            {{ \App\CustomerProperty::inst_mon_exclude_quar }}) {
            annual_installment = $('#total_quarterly_installment').val();

        } else if (val == {{ \App\CustomerProperty::inst_quar_w_semi }} || val ==
            {{ \App\CustomerProperty::inst_mon_exclude_semi }}) {
            annual_installment = $('#total_semi_installment').val();
        }
        else if (val == {{ \App\CustomerProperty::inst_custom }}) {
                // monthly_installment = $('#custome_rem').val();
                monthly_installment =0;
            }

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

        });
        var cus_amount = 0;
            $("input[name='custom_amount[]']").each(function() {
                if (!this.value) {
                    cus_amount += 0;
                } else {
                    cus_amount += parseInt($(this).val());
                }
            });
        allotment = parseFloat($('#remaining_allotment').val());
        confirmation = parseFloat($('#remaining_confirmation').val());
        booking = parseFloat($('#remaining_booking').val());
        down_payment = parseInt($('#remaining_down-payment').val());
        file_processing = parseFloat($('#remaining_file_processing').val());
        registration = parseFloat($('#remaining_registration').val());
        balloting = parseFloat($('#remaining_balloting').val());
        if (isNaN(ballon)) {
            ballon = 0;
                $('#remaining_per_file_ballon').val(0);

            }
        remaining_amount = remaining_net_amount - down_payment - possession - monthly_installment -
            annual_installment - add_amount - allotment - confirmation - booking -
            file_processing - registration - balloting - ballon - cus_amount;

        console.log('remaining_net_amount::', remaining_net_amount, 'down_payment::', down_payment,
            'possession::', possession, 'monthly_installment::', monthly_installment,
            'annual_installment::', annual_installment, 'add_amount::', add_amount, 'allotment::',
            allotment, 'confirmation::', confirmation, 'booking::', booking,
            'file_processing::', file_processing, 'registration::', registration, 'ballon::', ballon,
            'balloting::', balloting);
            console.log( remaining_amount);

        $('#remaining_amount').val(remaining_amount);
        var radioValue = $("input[name='schedule_type']:checked").val();
        if (radioValue == '{{ \App\CustomerProperty::inst_custom }}') {
            if(isNaN(parseInt($('#custome_rem').val()))){
                $('#custome_rem').val(0);
            }
           
            // remaining_amount = remaining_amount + parseInt($('#custome_rem').val())
        }
        // console.log( remaining_amount, parseInt($('#custome_rem').val()));
        $('#custome_rem').val(Math.round(remaining_amount));
    });
    $('#remaining_per_file_ballon').keyup(function() {
        remaining_net_amount = parseInt($('#remianing_payable').val());
        net_amount = parseInt($('#net_amount').val());
        // possession = parseInt($('#possession').val());
        monthly_installment = parseInt($('#remaining_total_installment').val());
        per_ballon_payment = parseFloat($('#remaining_per_file_ballon').val());
        $('#remaining_ballon').val(percentage(net_amount, per_ballon_payment));
        ballon = parseFloat($('#remaining_ballon').val());

        if (ballon) {
            ballon = parseInt($('#remaining_ballon').val());

        } else {
            ballon = 0;
        }

        num = $("#remaining_ballon").val();
        $("#remaining_ballon-label").text(number2TextConversion(num));
        annual_installment = 0;
        val = parseInt($('input[name="schedule_type"]:checked').val());
        if (val == {{ \App\CustomerProperty::inst_mon_w_semi }} || val ==
            {{ \App\CustomerProperty::inst_quar_exclude_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 }} || val ==
            {{ \App\CustomerProperty::inst_mon_exclude_quar }}) {
            annual_installment = $('#total_quarterly_installment').val();
        } else if (val == {{ \App\CustomerProperty::inst_quar_w_semi }} || val ==
            {{ \App\CustomerProperty::inst_mon_exclude_semi }}) {
            annual_installment = $('#total_semi_installment').val();
        }
        else if (val == {{ \App\CustomerProperty::inst_custom }}) {
                // monthly_installment = $('#custome_rem').val();
                monthly_installment =0;
            }
        var add_amount = 0;
        $("input[name='add_amount[]']").each(function() {
            if (!this.value) {
                add_amount += 0;
            } else {
                add_amount += parseInt($(this).val());
            }

        });
        var cus_amount = 0;
            $("input[name='custom_amount[]']").each(function() {
                if (!this.value) {
                    cus_amount += 0;
                } else {
                    cus_amount += parseInt($(this).val());
                }
            });
        possession = parseFloat($('#remaining_possession').val());
        allotment = parseFloat($('#remaining_allotment').val());
        confirmation = parseFloat($('#remaining_confirmation').val());
        booking = parseFloat($('#remaining_booking').val());
        down_payment = parseInt($('#remaining_down-payment').val());
        file_processing = parseFloat($('#remaining_file_processing').val());
        registration = parseFloat($('#remaining_registration').val());
        balloting = parseFloat($('#remaining_balloting').val());
        if (isNaN(ballon)) {
            ballon = 0;
                $('#remaining_ballon').val(0);

            }
        // console.log( remaining_net_amount , down_payment , possession , monthly_installment ,
        //      annual_installment, add_amount ,allotment , confirmation , booking  ,
        //      file_processing , registration , balloting , ballon);
        remaining_amount = remaining_net_amount - down_payment - possession - monthly_installment -
            annual_installment - add_amount - allotment - confirmation - booking -
            file_processing - registration - balloting - ballon - cus_amount;
        $('#remaining_amount').val(remaining_amount);
        var radioValue = $("input[name='schedule_type']:checked").val();
        if (radioValue == '{{ \App\CustomerProperty::inst_custom }}') {
            if(isNaN(parseInt($('#custome_rem').val()))){
                $('#custome_rem').val(0);
            }

            // remaining_amount = remaining_amount + parseInt($('#custome_rem').val())
        }
        $('#custome_rem').val(Math.round(remaining_amount));
    });


    // remaining balloting
    $('#remaining_balloting').keyup(function() {
        remaining_net_amount = parseInt($('#remianing_payable').val());
        net_amount = parseInt($('#net_amount').val());
        if ($('#remaining_balloting').val())
            balloting = parseInt($('#remaining_balloting').val());
        else
            balloting = 0;
        monthly_installment = parseInt($('#remaining_total_installment').val());
        $('#remaining_per_balloting').val(((balloting / net_amount) * 100).toFixed(2));
        possession = parseInt($('#remaining_possession').val());
        num = $("#remaining_balloting").val();
        $("#remaining_per_balloting").text(number2TextConversion(num));
        annual_installment = 0;
        val = parseInt($('input[name="schedule_type"]:checked').val());
        if (val == {{ \App\CustomerProperty::inst_mon_w_semi }} || val ==
            {{ \App\CustomerProperty::inst_quar_exclude_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 }} || val ==
            {{ \App\CustomerProperty::inst_mon_exclude_quar }}) {
            annual_installment = $('#total_quarterly_installment').val();
        } else if (val == {{ \App\CustomerProperty::inst_quar_w_semi }} || val ==
            {{ \App\CustomerProperty::inst_mon_exclude_semi }}) {
            annual_installment = $('#total_semi_installment').val();
        }
        else if (val == {{ \App\CustomerProperty::inst_custom }}) {
                // monthly_installment = $('#custome_rem').val();
                monthly_installment =0;
            }
        var add_amount = 0;
        $("input[name='add_amount[]']").each(function() {
            if (!this.value) {
                add_amount += 0;
            } else {
                add_amount += parseInt($(this).val());
            }

        });
        var cus_amount = 0;
            $("input[name='custom_amount[]']").each(function() {
                if (!this.value) {
                    cus_amount += 0;
                } else {
                    cus_amount += parseInt($(this).val());
                }
            });
        allotment = parseFloat($('#remaining_allotment').val());
        confirmation = parseFloat($('#remaining_confirmation').val());
        booking = parseFloat($('#remaining_booking').val());
        down_payment = parseInt($('#remaining_down-payment').val());
        file_processing = parseFloat($('#remaining_file_processing').val());
        registration = parseFloat($('#remaining_registration').val());
        ballon = parseFloat($('#remaining_ballon').val());
        if (isNaN(balloting)) {
            balloting = 0;
                $('#remaining_per_balloting').val(0);

            }
        remaining_amount = remaining_net_amount - down_payment - possession - monthly_installment -
            annual_installment - add_amount - allotment - confirmation - booking -
            file_processing - registration - balloting - ballon - cus_amount ;
        $('#remaining_amount').val(remaining_amount);
        var radioValue = $("input[name='schedule_type']:checked").val();
        if (radioValue == '{{ \App\CustomerProperty::inst_custom }}') {
            if(isNaN(parseInt($('#custome_rem').val()))){
                $('#custome_rem').val(0);
            }

            // remaining_amount = remaining_amount + parseInt($('#custome_rem').val())
        }
        $('#custome_rem').val(Math.round(remaining_amount));
    });
    $('#remaining_per_balloting').keyup(function() {
        remaining_net_amount = parseInt($('#remianing_payable').val());
        net_amount = parseInt($('#net_amount').val());
        // possession = parseInt($('#possession').val());
        monthly_installment = parseInt($('#remaining_total_installment').val());
        per_balloting_payment = parseFloat($('#remaining_per_balloting').val());
        $('#remaining_balloting').val(percentage(net_amount, per_balloting_payment));
        balloting = parseFloat($('#remaining_balloting').val());

        if (balloting) {
            balloting = parseInt($('#remaining_balloting').val());

        } else {
            balloting = 0;
        }

        num = $("#remaining_balloting").val();
        $("#remaining_per_balloting").text(number2TextConversion(num));
        annual_installment = 0;
        val = parseInt($('input[name="schedule_type"]:checked').val());
        if (val == {{ \App\CustomerProperty::inst_mon_w_semi }} || val ==
            {{ \App\CustomerProperty::inst_quar_exclude_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 }} || val ==
            {{ \App\CustomerProperty::inst_mon_exclude_quar }}) {
            annual_installment = $('#total_quarterly_installment').val();
        } else if (val == {{ \App\CustomerProperty::inst_quar_w_semi }} || val ==
            {{ \App\CustomerProperty::inst_mon_exclude_semi }}) {
            annual_installment = $('#total_semi_installment').val();
        }
        else if (val == {{ \App\CustomerProperty::inst_custom }}) {
                // monthly_installment = $('#custome_rem').val();
                monthly_installment =0;
            }

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

        });
        
 var cus_amount = 0;
            $("input[name='custom_amount[]']").each(function() {
                if (!this.value) {
                    cus_amount += 0;
                } else {
                    cus_amount += parseInt($(this).val());
                }
            });
        possession = parseFloat($('#remaining_possession').val());
        allotment = parseFloat($('#remaining_allotment').val());
        confirmation = parseFloat($('#remaining_confirmation').val());
        booking = parseFloat($('#remaining_booking').val());
        down_payment = parseInt($('#remaining_down-payment').val());
        file_processing = parseFloat($('#remaining_file_processing').val());
        registration = parseFloat($('#remaining_registration').val());
        ballon = parseFloat($('#remaining_ballon').val());
        if (isNaN(balloting)) {
            balloting = 0;
                $('#remaining_balloting').val(0);

            }

        // console.log( remaining_net_amount , down_payment , possession , monthly_installment ,
        //      annual_installment, add_amount ,allotment , confirmation , booking  ,
        //      file_processing , registration , balloting , ballon);
        remaining_amount = remaining_net_amount - down_payment - possession - monthly_installment -
            annual_installment - add_amount - allotment - confirmation - booking -
            file_processing - registration - balloting - ballon - cus_amount;
        $('#remaining_amount').val(remaining_amount);
        var radioValue = $("input[name='schedule_type']:checked").val();
        if (radioValue == '{{ \App\CustomerProperty::inst_custom }}') {
            if(isNaN(parseInt($('#custome_rem').val()))){
                $('#custome_rem').val(0);
            }

            // remaining_amount = remaining_amount + parseInt($('#custome_rem').val())
        }
        $('#custome_rem').val(Math.round(remaining_amount));
    });



    $("#remaining_single_installment").keyup(function() {
        remaining_net_amount = parseInt($('#remianing_payable').val());
        net_amount = parseInt($('#net_amount').val());
        num1 = $("#remaining_single_installment").val();
        $("#remaining_installment-label").text(number2TextConversion(num1));

        $('#remaining_total_installment').val(Math.round(parseInt($("#remaining_single_installment").val()) *
            parseInt(
                $('#remaining-total-months').val())));

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

        // net_amount = parseInt($('#remianing_net_amount').val());
        down_payment = parseInt($('#remaining_down-payment').val());
        possession = parseInt($('#remaining_possession').val());
        monthly_installment = parseInt($('#remaining_total_installment').val());


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

        $('#remaining_per_total_installment').val(Math.round(parseFloat($("#remaining_per_installment").val()) *
            parseFloat($('#remaining-total-months').val())))

        if (isNaN(monthly_installment)) {
            monthly_installment = 0;
            $('#remaining_per_installment').val(0);

            $('#remaining_per_total_installment').val(0)
            $("#remaining_total_installment").val(0)
        }

        annual_installment = 0;
        val = parseInt($('input[name="schedule_type"]:checked').val());
        if (val == {{ \App\CustomerProperty::inst_mon_w_semi }} || val ==
            {{ \App\CustomerProperty::inst_quar_exclude_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 }} || val ==
            {{ \App\CustomerProperty::inst_mon_exclude_quar }}) {
            annual_installment = $('#total_quarterly_installment').val();
        } else if (val == {{ \App\CustomerProperty::inst_quar_w_semi }} || val ==
            {{ \App\CustomerProperty::inst_mon_exclude_semi }}) {
            annual_installment = $('#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($('#remaining_allotment').val());
        confirmation = parseFloat($('#remaining_confirmation').val());
        booking = parseFloat($('#remaining_booking').val());

        file_processing = parseFloat($('#remaining_file_processing').val());
        registration = parseFloat($('#remaining_registration').val());
        balloting = parseFloat($('#remaining_balloting').val());
        ballon = parseFloat($('#remaining_ballon').val());
        //   console.log('remaining_net_amount::',remaining_net_amount , 'down_payment::',down_payment , 'possession::',possession , 'monthly_installment::',monthly_installment ,
        //      'annual_installment::',annual_installment , 'add_amount::',add_amount , 'allotment::',allotment , 'confirmation::',confirmation , 'booking::',booking  ,
        //      'file_processing:',file_processing , 'registration::',registration , 'balloting::',balloting , 'ballon::',ballon);


        remaining_amount = remaining_net_amount - down_payment - possession - monthly_installment -
            annual_installment - ballon -
            add_amount - allotment - confirmation - booking - balloting - file_processing - registration;


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

    });
    $('#remaining_per_installment').keyup(function() {

        remaining_net_amount = parseInt($('#remianing_payable').val());
        net_amount = parseInt($('#net_amount').val());
        // possession = parseInt($('#possession').val());

        remaining_per_installment = parseFloat($('#remaining_per_installment').val());
        $('#remaining_single_installment').val(percentage(net_amount, remaining_per_installment));
        $('#remaining_total_installment').val(Math.round(parseInt($("#remaining_single_installment").val()) *
            parseInt(
                $('#remaining-total-months').val())));
        monthly_installment = parseInt($('#remaining_total_installment').val());
        possession = parseFloat($('#remaining_possession').val());
        down_payment = parseInt($('#remaining_down-payment').val());
        num = $("#remaining_down-payment").val();
        $("#remaining_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 }} || val ==
            {{ \App\CustomerProperty::inst_quar_exclude_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 }} || val ==
            {{ \App\CustomerProperty::inst_mon_exclude_quar }}) {
            annual_installment = $('#total_quarterly_installment').val();
        } else if (val == {{ \App\CustomerProperty::inst_quar_w_semi }} || val ==
            {{ \App\CustomerProperty::inst_mon_exclude_semi }}) {
            annual_installment = $('#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());
            }

        });
        $('#remaining_per_total_installment').val(Math.round(parseFloat($("#remaining_per_installment").val()) *
            parseFloat($('#remaining-total-months').val())));


        allotment = parseFloat($('#remaining_allotment').val());
        confirmation = parseFloat($('#remaining_confirmation').val());
        booking = parseFloat($('#remaining_booking').val());
        development = parseFloat($('#remaining_development').val());
        file_processing = parseFloat($('#remaining_file_processing').val());
        registration = parseFloat($('#remaining_registration').val());
        balloting = parseFloat($('#remaining_balloting').val());
        ballon = parseFloat($('#remaining_ballon').val());
        remaining_amount = remaining_net_amount - down_payment - possession - monthly_installment -
            annual_installment - add_amount - allotment - confirmation - booking -
            file_processing - registration - balloting - ballon;
        $('#remaining_amount').val(remaining_amount);
        var radioValue = $("input[name='schedule_type']:checked").val();
        if (radioValue == '{{ \App\CustomerProperty::inst_custom }}') {
            if(isNaN(parseInt($('#custome_rem').val()))){
                $('#custome_rem').val(0);
            }

            // remaining_amount = remaining_amount + parseInt($('#custome_rem').val())
        }
        $('#custome_rem').val(Math.round(remaining_amount));
    });
    $("#remaining_total_installment").keyup(function() {
        remaining_net_amount = parseInt($('#remianing_payable').val());
        net_amount = parseInt($('#net_amount').val());


        down_payment = parseInt($('#remaining_down-payment').val());
        possession = parseInt($('#remaining_possession').val());
        monthly_installment = parseInt($('#remaining_total_installment').val());

        // $('#remaining_per_total_installment').val(((this.value / net_amount) * 100).toFixed(2));
        $('#remaining_single_installment').val(Math.round(parseInt($("#remaining_total_installment").val() /
            parseInt($('#remaining-total-months').val()))));

        num1 = $("#remaining_single_installment").val();
        $('#remaining_per_installment').val(((num1 / net_amount) * 100).toFixed(2));

        $("#remaining_installment-label").text(number2TextConversion(num1));



        $('#remaining_per_total_installment').val(Math.round(parseFloat($("#remaining_per_installment").val()) *
            parseFloat($('#remaining-total-months').val())))

        if (isNaN(monthly_installment)) {
            monthly_installment = 0;
            $('#remaining_per_installment').val(0);

            $('#remaining_per_total_installment').val(0)
            $("#remaining_total_installment").val(0)
        }

        annual_installment = 0;
        val = parseInt($('input[name="schedule_type"]:checked').val());
        if (val == {{ \App\CustomerProperty::inst_mon_w_semi }} || val ==
            {{ \App\CustomerProperty::inst_quar_exclude_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 }} || val ==
            {{ \App\CustomerProperty::inst_mon_exclude_quar }}) {
            annual_installment = $('#total_quarterly_installment').val();
        } else if (val == {{ \App\CustomerProperty::inst_quar_w_semi }} || val ==
            {{ \App\CustomerProperty::inst_mon_exclude_semi }}) {
            annual_installment = $('#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($('#remaining_allotment').val());
        confirmation = parseFloat($('#remaining_confirmation').val());
        booking = parseFloat($('#remaining_booking').val());

        file_processing = parseFloat($('#remaining_file_processing').val());
        registration = parseFloat($('#remaining_registration').val());
        balloting = parseFloat($('#remaining_balloting').val());
        ballon = parseFloat($('#remaining_ballon').val());
        //   console.log('remaining_net_amount::',remaining_net_amount , 'down_payment::',down_payment , 'possession::',possession , 'monthly_installment::',monthly_installment ,
        //      'annual_installment::',annual_installment , 'add_amount::',add_amount , 'allotment::',allotment , 'confirmation::',confirmation , 'booking::',booking  ,
        //      'file_processing:',file_processing , 'registration::',registration , 'balloting::',balloting , 'ballon::',ballon);


        remaining_amount = remaining_net_amount - down_payment - possession - monthly_installment -
            annual_installment - ballon -
            add_amount - allotment - confirmation - booking - balloting - file_processing - registration;


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

    });
    $('#remaining_per_total_installment').keyup(function() {

        remaining_net_amount = parseInt($('#remianing_payable').val());
        net_amount = parseInt($('#net_amount').val());
        // possession = parseInt($('#possession').val());




        //  remaining_total_installment

        // remaining_single_installment

        remaining_per_total_installment = parseFloat($('#remaining_per_total_installment').val());
        $('#remaining_total_installment').val(percentage(net_amount, remaining_per_total_installment));




        $('#remaining_single_installment').val(Math.round(parseInt($("#remaining_total_installment").val() /
            parseInt($('#remaining-total-months').val()))));

        num1 = $("#remaining_single_installment").val();
        $('#remaining_per_installment').val(((num1 / net_amount) * 100).toFixed(2));






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

        if (isNaN(monthly_installment)) {
            monthly_installment = 0;
            $('#remaining_per_installment').val(0);

            $('#remaining_per_total_installment').val(0)
            $("#remaining_total_installment").val(0)
        }
        annual_installment = 0;
        val = parseInt($('input[name="schedule_type"]:checked').val());
        if (val == {{ \App\CustomerProperty::inst_mon_w_semi }} || val ==
            {{ \App\CustomerProperty::inst_quar_exclude_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 }} || val ==
            {{ \App\CustomerProperty::inst_mon_exclude_quar }}) {
            annual_installment = $('#total_quarterly_installment').val();
        } else if (val == {{ \App\CustomerProperty::inst_quar_w_semi }} || val ==
            {{ \App\CustomerProperty::inst_mon_exclude_semi }}) {
            annual_installment = $('#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());
            }

        });
        // $('#remaining_per_total_installment').val(Math.round(parseFloat($("#remaining_per_installment").val()) *
        //     parseFloat($('#remaining-total-months').val())));
        possession = parseFloat($('#remaining_possession').val());
        down_payment = parseInt($('#remaining_down-payment').val());
        num = $("#remaining_down-payment").val();
        $("#remaining_down-payment-label").text(number2TextConversion(num));

        allotment = parseFloat($('#remaining_allotment').val());
        confirmation = parseFloat($('#remaining_confirmation').val());
        booking = parseFloat($('#remaining_booking').val());
        development = parseFloat($('#remaining_development').val());
        file_processing = parseFloat($('#remaining_file_processing').val());
        registration = parseFloat($('#remaining_registration').val());
        balloting = parseFloat($('#remaining_balloting').val());
        ballon = parseFloat($('#remaining_ballon').val());
        remaining_amount = remaining_net_amount - down_payment - possession - monthly_installment -
            annual_installment - add_amount - allotment - confirmation - booking -
            file_processing - registration - balloting - ballon;
        $('#remaining_amount').val(remaining_amount);
        var radioValue = $("input[name='schedule_type']:checked").val();
        if (radioValue == '{{ \App\CustomerProperty::inst_custom }}') {
            if(isNaN(parseInt($('#custome_rem').val()))){
                $('#custome_rem').val(0);
            }

            // remaining_amount = remaining_amount + parseInt($('#custome_rem').val())
        }
        $('#custome_rem').val(Math.round(remaining_amount));
    });
    $("#remaining-total-months").keyup(function() {


        net_amount = parseInt($('#net_amount').val());
        $('#remaining_single_installment').val(Math.round(parseInt($("#remaining_total_installment").val() /
            parseInt($('#remaining-total-months').val()))));

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

        $('#remaining_per_installment').val(((num / net_amount) * 100).toFixed(2));
        if (isNaN(num)) {
            $('#remaining_single_installment').val(0);
            $('#remaining_per_installment').val(0);

        }

    });

    $("#total_semi_installment").keyup(function() {
        remaining_net_amount = parseInt($('#remianing_payable').val());
        net_amount = parseInt($('#net_amount').val());


      

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

        num1 = $("#semi-installment").val();
        $('#per_semi_installment').val(((num1 / net_amount) * 100).toFixed(2));

     



        $('#per_total_semi_installment').val(Math.round(parseFloat($("#per_semi_installment").val()) *
            parseFloat($('#total_semi_installment_count').val())))




           
        monthly_installment = parseInt($('#remaining_total_installment').val());
        if (isNaN(num1)) {
           
            $('#semi-installment').val(0);
            $('#per_semi_installment').val(0)
            $("#per_total_semi_installment").val(0)
        }

        annual_installment = 0;
        val = parseInt($('input[name="schedule_type"]:checked').val());
        if (val == {{ \App\CustomerProperty::inst_mon_w_semi }} || val ==
            {{ \App\CustomerProperty::inst_quar_exclude_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 }} || val ==
            {{ \App\CustomerProperty::inst_mon_exclude_quar }}) {
            annual_installment = $('#total_quarterly_installment').val();
        } else if (val == {{ \App\CustomerProperty::inst_quar_w_semi }} || val ==
            {{ \App\CustomerProperty::inst_mon_exclude_semi }}) {
            annual_installment = $('#total_semi_installment').val();
        }
        if (isNaN(annual_installment)) {
            annual_installment =0;
        }

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

        down_payment = parseInt($('#remaining_down-payment').val());
        possession = parseInt($('#remaining_possession').val());
        allotment = parseFloat($('#remaining_allotment').val());
        confirmation = parseFloat($('#remaining_confirmation').val());
        booking = parseFloat($('#remaining_booking').val());

        file_processing = parseFloat($('#remaining_file_processing').val());
        registration = parseFloat($('#remaining_registration').val());
        balloting = parseFloat($('#remaining_balloting').val());
        ballon = parseFloat($('#remaining_ballon').val());
    
        remaining_amount = remaining_net_amount - down_payment - possession - monthly_installment -
            annual_installment - ballon -
            add_amount - allotment - confirmation - booking - balloting - file_processing - registration;

            // console.log(remaining_net_amount , down_payment , possession , monthly_installment ,
            // annual_installment , ballon ,
            // add_amount , allotment , confirmation , booking , balloting , file_processing , registration);

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

    });

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

        remaining_net_amount = parseInt($('#remianing_payable').val());
        net_amount = parseInt($('#net_amount').val());
        // possession = parseInt($('#possession').val());




       
        
       


        per_total_semi_installment = parseFloat($('#per_total_semi_installment').val());
        $('#total_semi_installment').val(percentage(net_amount, per_total_semi_installment));




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

        num1 = $("#semi-installment").val();
        $('#per_semi_installment').val(((num1 / net_amount) * 100).toFixed(2));






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

        if (isNaN(num1)) {
           
            $('#per_semi_installment').val(0);

            $('#semi-installment').val(0)
            $("#total_semi_installment").val(0)
        }
        annual_installment = 0;
        val = parseInt($('input[name="schedule_type"]:checked').val());
        if (val == {{ \App\CustomerProperty::inst_mon_w_semi }} || val ==
            {{ \App\CustomerProperty::inst_quar_exclude_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 }} || val ==
            {{ \App\CustomerProperty::inst_mon_exclude_quar }}) {
            annual_installment = $('#total_quarterly_installment').val();
        } else if (val == {{ \App\CustomerProperty::inst_quar_w_semi }} || val ==
            {{ \App\CustomerProperty::inst_mon_exclude_semi }}) {
            annual_installment = $('#total_semi_installment').val();
        }
        if (isNaN(annual_installment)) {
            annual_installment =0;
        }
        var add_amount = 0;
        $("input[name='add_amount[]']").each(function() {
            if (!this.value) {
                add_amount += 0;
            } else {
                add_amount += parseInt($(this).val());
            }

        });
        // $('#remaining_per_total_installment').val(Math.round(parseFloat($("#remaining_per_installment").val()) *
        //     parseFloat($('#remaining-total-months').val())));
        possession = parseFloat($('#remaining_possession').val());
        down_payment = parseInt($('#remaining_down-payment').val());
        num = $("#remaining_down-payment").val();
        $("#remaining_down-payment-label").text(number2TextConversion(num));

        allotment = parseFloat($('#remaining_allotment').val());
        confirmation = parseFloat($('#remaining_confirmation').val());
        booking = parseFloat($('#remaining_booking').val());
        development = parseFloat($('#remaining_development').val());
        file_processing = parseFloat($('#remaining_file_processing').val());
        registration = parseFloat($('#remaining_registration').val());
        balloting = parseFloat($('#remaining_balloting').val());
        ballon = parseFloat($('#remaining_ballon').val());
        remaining_amount = remaining_net_amount - down_payment - possession - monthly_installment -
            annual_installment - add_amount - allotment - confirmation - booking -
            file_processing - registration - balloting - ballon;
        $('#remaining_amount').val(remaining_amount);
        var radioValue = $("input[name='schedule_type']:checked").val();
        if (radioValue == '{{ \App\CustomerProperty::inst_custom }}') {
            if(isNaN(parseInt($('#custome_rem').val()))){
                $('#custome_rem').val(0);
            }

            // remaining_amount = remaining_amount + parseInt($('#custome_rem').val())
        }
        $('#custome_rem').val(Math.round(remaining_amount));
    });
    $("#total_semi_installment_count").keyup(function() {


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


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

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

        $('#per_semi_installment').val(((num / net_amount) * 100).toFixed(2));
        if (isNaN(num)) {
            $('#semi-installment').val(0);
            $('#per_semi_installment').val(0);

        }

    });



    // remaining_development
    // remaining_per_development



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




        remaining_net_amount = parseInt($('#remianing_payable').val());
        net_amount = parseInt($('#net_amount').val());
        down_payment = parseInt($('#remaining_down-payment').val());
        possession = parseInt($('#remaining_possession').val());
        monthly_installment = parseInt($('#remaining_total_installment').val());
        annual_installment = parseInt($('#total_annual_installment').val());
        $('#per_annual-installment').val((($("#annual-installment").val() / net_amount) * 100).toFixed(2));

        $('#per_total_annual_installment').val((($("#total_annual_installment").val() / net_amount) * 100)
            .toFixed(2));

        // $('#per_total_annual_installment').val(Math.round(parseFloat($("#per_annual-installment").val()) *
        //     parseFloat($('#total_annual_installment_count').val())));
        if (isNaN(annual_installment)) {
            annual_installment = 0;
            $('#total_annual_installment').val(0);
            $('#per_annual-installment').val(0);

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

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

        allotment = parseFloat($('#remaining_allotment').val());
        confirmation = parseFloat($('#remaining_confirmation').val());
        booking = parseFloat($('#remaining_booking').val());
        file_processing = parseFloat($('#remaining_file_processing').val());
        registration = parseFloat($('#remaining_registration').val());
        balloting = parseFloat($('#remaining_balloting').val());
        ballon = parseFloat($('#remaining_ballon').val());


        remaining_amount = remaining_net_amount - down_payment - possession - monthly_installment -
            annual_installment - add_amount - allotment - confirmation - booking -
            file_processing - registration - balloting - ballon;

            console.log(remaining_net_amount , down_payment , possession , monthly_installment ,
            annual_installment , add_amount , allotment , confirmation , booking ,
            file_processing , registration , balloting , ballon);

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

    //update per  annual installement
    $('#per_annual-installment').keyup(function() {

        remaining_net_amount = parseInt($('#remianing_payable').val());
        net_amount = parseInt($('#net_amount').val());
        // possession = parseInt($('#possession').val());

        per_annual_installment = parseFloat($('#per_annual-installment').val());
        $('#annual-installment').val(percentage(net_amount, per_annual_installment));
        $('#total_annual_installment').val(Math.round(parseInt($("#annual-installment").val()) *
            parseInt(
                $('#total_annual_installment_count').val())));

        if (isNaN(per_annual_installment)) {

            $('#annual-installment').val(0);
            $('#total_annual_installment').val(0);
        }

        monthly_installment = parseInt($('#remaining_total_installment').val());
        possession = parseFloat($('#remaining_possession').val());
        down_payment = parseInt($('#remaining_down-payment').val());
        num = $("#remaining_down-payment").val();
        $("#remaining_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 }} || val ==
            {{ \App\CustomerProperty::inst_quar_exclude_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 }} || val ==
            {{ \App\CustomerProperty::inst_mon_exclude_quar }}) {
            annual_installment = $('#total_quarterly_installment').val();
        } else if (val == {{ \App\CustomerProperty::inst_quar_w_semi }} || val ==
            {{ \App\CustomerProperty::inst_mon_exclude_semi }}) {
            annual_installment = $('#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());
            }

        });
        $('#remaining_per_total_installment').val(Math.round(parseFloat($("#remaining_per_installment").val()) *
            parseFloat($('#remaining-total-months').val())));


        allotment = parseFloat($('#remaining_allotment').val());
        confirmation = parseFloat($('#remaining_confirmation').val());
        booking = parseFloat($('#remaining_booking').val());
        development = parseFloat($('#remaining_development').val());
        file_processing = parseFloat($('#remaining_file_processing').val());
        registration = parseFloat($('#remaining_registration').val());
        balloting = parseFloat($('#remaining_balloting').val());
        ballon = parseFloat($('#remaining_ballon').val());
        remaining_amount = remaining_net_amount - down_payment - possession - monthly_installment -
            annual_installment - add_amount - allotment - confirmation - booking -
            file_processing - registration - balloting - ballon;
        $('#remaining_amount').val(remaining_amount);

    });

    //updatetotal_annual_installment

    $("#total_annual_installment").keyup(function() {
        if (isNaN(this.value)) {
            this.value = 0;
        }
        num1 = $("#total_annual_installment").val();
        $("#total-annual-installment-label").text(number2TextConversion(num1));



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


        if (isNaN(this.value) || this.value == '' || this.value == ' ' || this.value == 0) {
            $('#per_annual-installment').val(0);
            $('#annual-installment').val(0);
            $('#per_total_annual_installment').val(0);

        } else {
            $('#per_annual-installment').val(((this.value / net_amount) * 100).toFixed(2));
            $('#annual-installment').val(Math.round(parseInt($("#total_annual_installment").val() / parseInt($(
                '#total_annual_installment_count').val()))));
                
            num = $("#annual-installment").val();
            $("#annual-installment-label").text(number2TextConversion(num));
            $('#per_total_annual_installment').val((($("#total_annual_installment").val() / net_amount) * 100)
                .toFixed(2));

        }


        // $('#installment').val(percentage(net_amount ,  $('#per_installment').val() ));





        annual_installment = 0;
        val = parseInt($('input[name="schedule_type"]:checked').val());
        if (val == {{ \App\CustomerProperty::inst_mon_w_semi }} || val ==
            {{ \App\CustomerProperty::inst_quar_exclude_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 }} || val ==
            {{ \App\CustomerProperty::inst_mon_exclude_quar }}) {
            annual_installment = $('#total_quarterly_installment').val();
        } else if (val == {{ \App\CustomerProperty::inst_quar_w_semi }} || val ==
            {{ \App\CustomerProperty::inst_mon_exclude_semi }}) {
            annual_installment = $('#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());
            }
        });



        monthly_installment = parseInt($('#remaining_total_installment').val());
        possession = parseFloat($('#remaining_possession').val());
        down_payment = parseInt($('#remaining_down-payment').val());
        allotment = parseFloat($('#remaining_allotment').val());
        confirmation = parseFloat($('#remaining_confirmation').val());
        booking = parseFloat($('#remaining_booking').val());

        file_processing = parseFloat($('#remaining_file_processing').val());
        registration = parseFloat($('#remaining_registration').val());
        balloting = parseFloat($('#remaining_balloting').val());
        ballon = parseFloat($('#remaining_ballon').val());

        annual_installment =parseFloat(annual_installment); 
        remaining_amount = remaining_net_amount - down_payment - possession - monthly_installment - annual_installment -
            add_amount - allotment - confirmation - booking - file_processing - registration - ballon -
            balloting;

            console.log(remaining_net_amount , down_payment , possession , monthly_installment ,
            annual_installment , add_amount , allotment , confirmation , booking ,
            file_processing , registration , balloting , ballon);


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

    });

    $("#total_annual_installment_count").keyup(function() {
        if (isNaN(this.value)) {
            this.value = 0;
        }
        if (isNaN(this.value) || this.value == '' || this.value == ' ' || this.value == 0) {
            $('#per_annual-installment').val(0);



            $('#annual-installment').val(0);
        } else {


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

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

            $('#per_annual-installment').val(((num / net_amount) * 100).toFixed(2));
        }

    });





    //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));
        annual_installment = parseInt($('#total_semi_installment').val());
        $('#per_semi_installment').val(((num / net_amount) * 100).toFixed(2));

        $('#per_total_semi_installment').val(Math.round(parseFloat($("#per_semi_installment").val()) *
            parseFloat(count)))

        if (isNaN(annual_installment)) {
            annual_installment = 0;
            $('#total_semi_installment').val(0);
            $('#per_semi_installment').val(0);

            $('#per_total_semi_installment').val(0)

        }

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

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


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

        });

        down_payment = parseInt($('#remaining_down-payment').val());
        possession = parseInt($('#remaining_possession').val());
        monthly_installment = parseInt($('#remaining_total_installment').val());
        allotment = parseFloat($('#remaining_allotment').val());
        confirmation = parseFloat($('#remaining_confirmation').val());
        booking = parseFloat($('#remaining_booking').val());

        file_processing = parseFloat($('#remaining_file_processing').val());
        registration = parseFloat($('#remaining_registration').val());

        balloting = parseFloat($('#remaining_balloting').val());
        ballon = parseFloat($('#remaining_ballon').val());

        //  console.log(remaining_net_amount , down_payment , possession , monthly_installment ,
        //      annual_installment , add_amount , allotment , confirmation , booking , 
        //      file_processing , registration , balloting , ballon);
        remaining_amount = remaining_net_amount - down_payment - possession - monthly_installment -
            annual_installment - add_amount - allotment - confirmation - booking -
            file_processing - registration - balloting - ballon;


        $('#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());

        file_processing = parseFloat($('#file_processing').val());
        registration = parseFloat($('#registration').val());
        balloting = parseFloat($('#remaining_balloting').val());
        ballon = parseFloat($('#remaining_ballon').val());

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

        $('#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));



        monthly_installment = parseInt($('#total_installment').val());
        annual_installment = parseInt($('#total_quarterly_installment').val());
        if (isNaN(annual_installment)) {
            annual_installment = 0;
            $('#total_quarterly_installment').val(0);
        }

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

        });
        net_amount = parseInt($('#net_amount').val());
        down_payment = parseInt($('#remaining_down-payment').val());
        possession = parseInt($('#remaining_possession').val());
        monthly_installment = parseInt($('#remaining_total_installment').val());
        allotment = parseFloat($('#remaining_allotment').val());
        confirmation = parseFloat($('#remaining_confirmation').val());
        booking = parseFloat($('#remaining_booking').val());

        file_processing = parseFloat($('#remaining_file_processing').val());
        registration = parseFloat($('#remaining_registration').val());

        balloting = parseFloat($('#remaining_balloting').val());
        ballon = parseFloat($('#remaining_ballon').val());
        remaining_net_amount = parseInt($('#remianing_payable').val());

        remaining_amount = remaining_net_amount - down_payment - possession - monthly_installment -
            annual_installment - add_amount - allotment - confirmation - booking -
            file_processing - registration - balloting - ballon;


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

    });

    $("#total_quarterly_installment").keyup(function() {
        if (isNaN(this.value)) {
            this.value = 0;
        }
        num1 = $("#total_quarterly_installment").val();
        $("#total-annual-installment-label").text(number2TextConversion(num1));


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


        if (isNaN(this.value) || this.value == '' || this.value == ' ' || this.value == 0) {
            $('#quarterly-installment').val(0);


        } else {

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


        }


        // $('#installment').val(percentage(net_amount ,  $('#per_installment').val() ));





        annual_installment = 0;
        val = parseInt($('input[name="schedule_type"]:checked').val());
        if (val == {{ \App\CustomerProperty::inst_mon_w_semi }} || val ==
            {{ \App\CustomerProperty::inst_quar_exclude_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 }} || val ==
            {{ \App\CustomerProperty::inst_mon_exclude_quar }}) {
            annual_installment = $('#total_quarterly_installment').val();
        } else if (val == {{ \App\CustomerProperty::inst_quar_w_semi }} || val ==
            {{ \App\CustomerProperty::inst_mon_exclude_semi }}) {
            annual_installment = $('#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());
            }
        });



        monthly_installment = parseInt($('#remaining_total_installment').val());
        possession = parseFloat($('#remaining_possession').val());
        down_payment = parseInt($('#remaining_down-payment').val());
        allotment = parseFloat($('#remaining_allotment').val());
        confirmation = parseFloat($('#remaining_confirmation').val());
        booking = parseFloat($('#remaining_booking').val());

        file_processing = parseFloat($('#remaining_file_processing').val());
        registration = parseFloat($('#remaining_registration').val());
        balloting = parseFloat($('#remaining_balloting').val());
        ballon = parseFloat($('#remaining_ballon').val());
        remaining_net_amount = parseInt($('#remianing_payable').val());

        remaining_amount = remaining_net_amount - down_payment - possession - monthly_installment - annual_installment -
            add_amount - allotment - confirmation - booking - file_processing - registration - ballon -
            balloting;


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

    });




    $("#remianing_payable").on('input', function() {
        // $("#remianing_payable").keyup(function() {

        remaining_net_amount = parseInt($('#remianing_payable').val());

        down_payment = parseInt($('#remaining_down-payment').val());
        possession = parseFloat($('#remaining_possession').val());
        allotment = parseFloat($('#remaining_allotment').val());
        monthly_installment = parseInt($('#remaining_total_installment').val());
        annual_installment = 0;
        var add_amount = 0;
        val = parseInt($('input[name="schedule_type"]:checked').val());



        if (val == {{ \App\CustomerProperty::inst_mon_w_semi }} || val ==
            {{ \App\CustomerProperty::inst_quar_exclude_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 }} || val ==
            {{ \App\CustomerProperty::inst_mon_exclude_quar }}) {
            annual_installment = $('#total_quarterly_installment').val();
        } else if (val == {{ \App\CustomerProperty::inst_quar_w_semi }} || val ==
            {{ \App\CustomerProperty::inst_mon_exclude_semi }}) {
            annual_installment = $('#total_semi_installment').val();
        }
        $("input[name='add_amount[]']").each(function() {
            if (!this.value) {
                add_amount += 0;
            } else {
                add_amount += parseInt($(this).val());
            }

        });
        confirmation = parseFloat($('#remaining_confirmation').val());
        booking = parseFloat($('#remaining_booking').val());

        file_processing = parseFloat($('#remaining_file_processing').val());
        registration = parseFloat($('#remaining_registration').val());
        balloting = parseFloat($('#remaining_balloting').val());
        ballon = parseFloat($('#remaining_ballon').val());

        remaining_amount = remaining_net_amount - down_payment - possession - monthly_installment -
            parseInt(annual_installment) - add_amount - allotment - confirmation - booking -
            file_processing - registration - balloting - ballon;

        $('#remaining_amount').val(remaining_amount);
        //     #remianing_payable
        // submit_button
        // $(':input[type="submit"]').prop('disabled', false);
    });
</script>
