<div class="content-header">
    <div class="container-fluid">
        <div class="row mb-2">
            <div class="col-sm-6">
                <!-- <h1 class="m-0">Deactive Member </h1> -->
            </div>
            <div class="col-sm-6">
                <ol class="breadcrumb float-sm-right">
                    <li class="breadcrumb-item"><a href="#">Loan</a></li>
                    <li class="breadcrumb-item active">Add Loan </li>
                </ol>
            </div>
        </div>
    </div>
</div>




<section class="content">
    <div class="container-fluid">




        <div class="row">

            <section class="col-lg-12 connectedSortable">

                <div class="card">
                    <div class="card-header " style="background-color:#31708e;color:white">
                        <h3 class="card-title">
                            Add Loan Details
                        </h3>
                        <div class="card-tools">
                            <ul class="nav nav-pills ml-auto">
                            </ul>
                        </div>
                    </div>
                    <div class="card-body">
                        <div class="tab-content p-0">

                            <h3 class="text-center btn btn-lg btn-light  float-left"><a href="<?php echo base_url(); ?>index.php/Member/loan_details">Back</a></h3>

                            <div class="row">
                                <div class="col-sm-3"></div>
                                <div class="col-sm-6">
                                    <form method="post" action="<?php echo base_url(); ?>index.php/member/insert_loan" id="edit_loan" enctype='multipart/form-data'>
                                        <input type="hidden" name="updated_on" value="<?php echo date("Y-m-d H:i:s"); ?>">
                                        <div class="row mt-3">
                                            <div class="col-sm-6"><b>Member Number</b></div>
                                            <div class="col-sm-6">
                                                <select name="me_no" id="me_no" class="form-control">
                                                    <option value="">All</option>
                                                    <?php foreach ($members as $mem) { ?>
                                                        <option value="<?php echo $mem['me_no']; ?>"><?php echo $mem['me_no'] . "-" . $mem['mem_name']; ?></option>
                                                    <?php } ?>
                                                </select>
                                            </div>
                                        </div><br>
                                        <div class="row mt-3">
                                            <div class="col-sm-6"><b>Loan Number</b></div>
                                            <div class="col-sm-6">
                                                <input type="number" class="form-control" name="loan_no" id="loan_no">
                                            </div>
                                        </div><br>
                                        <div class="row mt-3">
                                            <div class="col-sm-6"><b>Loan Amount</b></div>
                                            <div class="col-sm-6">
                                                <input type="number" class="form-control" name="loan_amount" id="loan_amount">
                                            </div>
                                        </div><br>
                                        <div class="row mt-3">
                                            <div class="col-sm-6"><b>Loan OS Amount</b></div>
                                            <div class="col-sm-6">
                                                <input type="number" class="form-control" name="loan_os_amt" id="loan_os_amt">
                                            </div>
                                        </div><br>
                                        <div class="row mt-3">
                                            <div class="col-sm-6"><b>Loan Principal Amount</b></div>
                                            <div class="col-sm-6">
                                                <input type="number" class="form-control" name="loan_principle_amt" id="loan_principle_amt">
                                            </div>
                                        </div><br>
                                        <div class="row mt-3">
                                            <div class="col-sm-6"><b>Current Instalment</b></div>
                                            <div class="col-sm-6">
                                                <input type="number" class="form-control" name="curr_instalment" id="curr_instalment">
                                            </div>
                                        </div><br>
                                        <div class="row mt-3">
                                            <div class="col-sm-6"><b>Total Instalment</b></div>
                                            <div class="col-sm-6">
                                                <input type="number" class="form-control" name="loan_instalment" id="loan_instalment">
                                            </div>
                                        </div><br>
                                        <div class="row mt-3">
                                            <div class="col-sm-6"><b>Interest Rate</b></div>
                                            <div class="col-sm-6">
                                                <input type="text" class="form-control" name="loan_int_rate" id="loan_int_rate" value="11.5">
                                            </div>
                                        </div><br>

                                        <div class="row mt-3">
                                            <div class="col-sm-6"><b>ML No. Of Days</b>&nbsp;&nbsp;&nbsp;<input type='checkbox' class='ml-5' name='fst_int' id='fst_int' value='1'><input type='hidden' class='ml-5' name='fst_int' id='fst_int_hidden' value='0'></div>
                                            <div class="col-sm-6">
                                                <input type="text" class="form-control" <?php echo $checked; ?> name="no_of_days" id="no_of_days">
                                            </div>
                                        </div><br>
                                        <div class="row mt-3">
                                            <div class="col-sm-6"><b>ML Date</b></div>
                                            <div class="col-sm-6">
                                                <input type="text" class="form-control" name="loan_date" id="loan_date" value="<?php echo date("d-m-Y"); ?>">
                                            </div>
                                        </div><br>
                                        <div class="row mt-3">
                                            <div class="col-sm-6"><b>FL Number</b></div>
                                            <div class="col-sm-6">
                                                <input type="text" class="form-control" name="f_loan_no" id="f_loan_no">
                                            </div>
                                        </div><br>
                                        <div class="row mt-3">
                                            <div class="col-sm-6"><b>FL Amount</b></div>
                                            <div class="col-sm-6">
                                                <input type="text" class="form-control" name="f_loan_amount" id="f_loan_amount">
                                            </div>
                                        </div><br>
                                        <div class="row mt-3">
                                            <div class="col-sm-6"><b>FL OS Amount</b></div>
                                            <div class="col-sm-6">
                                                <input type="text" class="form-control" name="f_os" id="f_os">
                                            </div>
                                        </div><br>
                                        <div class="row mt-3">
                                            <div class="col-sm-6"><b>FL Principal Amount</b></div>
                                            <div class="col-sm-6">
                                                <input type="text" class="form-control" name="f_pri" id="f_pri">
                                            </div>
                                        </div><br>
                                        <div class="row mt-3">
                                            <div class="col-sm-6"><b>FL Int Rate</b></div>
                                            <div class="col-sm-6">
                                                <input type="text" class="form-control" name="f_int_rate" id="f_int_rate">
                                            </div>
                                        </div><br>
                                        <div class="row mt-3">
                                            <div class="col-sm-6"><b>FL No. Of Days</b><input type='checkbox' <?php echo $checked; ?> class='ml-5' name='f_fst_int' id='f_fst_int' value='1'><input type='hidden' class='ml-5' name='f_fst_int' id='f_fst_int_hidden' value='0'></div>
                                            <div class="col-sm-6">
                                                <input type="text" class="form-control" name="f_no_of_days" id="f_no_of_days">
                                            </div>
                                        </div><br>
                                        <div class="row mt-3">
                                            <div class="col-sm-6"><b>FL Date</b></div>
                                            <div class="col-sm-6">
                                                <input type="text" class="form-control" name="f_loan_date" id="f_loan_date" value="<?php echo date("d-m-Y"); ?>">
                                            </div>
                                        </div><br>
                                        <div class="row mt-3">
                                            <div class="col-sm-6"><b>Surety Member</b></div>
                                            <div class="col-sm-6">
                                                <select name="surety_memno" id="surety_memno" class="form-control">
                                                    <option value="">All</option>
                                                    <?php foreach ($members as $mem) { ?>
                                                        <option value="<?php echo $mem['me_no']; ?>"><?php echo $mem['me_no'] . "-" . $mem['mem_name']; ?></option>
                                                    <?php } ?>
                                                </select>
                                            </div>
                                        </div><br>
                                        <div class="row mt-3">
                                            <div class="col-sm-6"><b>Ent. Fees</b></div>
                                            <div class="col-sm-6">
                                                <input type="number" class="form-control" name="ent_fees" id="ent_fees" value="0">
                                            </div>
                                        </div><br>
                                        <div class="row mt-3">
                                            <div class="col-sm-6"><b>Share</b></div>
                                            <div class="col-sm-6">
                                                <input type="number" class="form-control" name="d_share" id="d_share" value="0">
                                            </div>
                                        </div><br>
                                        <div class="row mt-3">
                                            <div class="col-sm-6"><b>Insurance</b></div>
                                            <div class="col-sm-6">
                                                <input type="number" class="form-control" name="d_ins" id="d_ins" value="0">
                                            </div>
                                        </div><br>
                                        <div class="row mt-3">
                                            <div class="col-sm-6"><b>Others</b></div>
                                            <div class="col-sm-6">
                                                <input type="number" class="form-control" name="d_others" id="d_others" value="0">
                                            </div>
                                        </div>
                                        <br>
                                        <div class="row mt-3">
                                            <div class="col-sm-6"><b>Cash Type Bank:</b></div>
                                            <div class="col-sm-6">
                                                <input type="radio" id="tdccb" name="cash_type" value="tdccb">&nbsp;TDCCB&nbsp;&nbsp;&nbsp;&nbsp;
                                                <input type="radio" checked id="sbi" name="cash_type" value="sbi">&nbsp;SBI&nbsp;&nbsp;
                                            </div>
                                        </div>
                                        <br>

                                        <div class='row'>
                                            <div class='col-sm-5'></div>
                                            <button type="submit" id="save" onclick="check_validation();" class="btn btn-primary col-sm-2">Save</button>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
        </div>
</section>
</div>
</div>
</section>



<script>
    function check_validation() {
        if (document.getElementById("fst_int").checked) {
            document.getElementById('fst_int_hidden').disabled = true;
        }

        if (document.getElementById("f_fst_int").checked) {
            document.getElementById('f_fst_int_hidden').disabled = true;
        }
        
    }

    $('#me_no').on('change', function() {
        var me_no = this.value;
        $.ajax({
            type: 'POST',
            url: "<?php echo base_url() ?>index.php/Member/loan_search",
            data: {
                me_no: me_no
            },
            dataType: 'html',
            success: function(data) {
                if (data == '1') {
                    alert('This Member alredy have Loan amount');
                    $('#loan_no').attr('readonly', 'readonly');

                    $('#loan_amount').attr('readonly', 'readonly');

                    $('#loan_os_amt').attr('readonly', 'readonly');

                    $('#loan_principle_amt').attr('readonly', 'readonly');

                    $('#curr_instalment').attr('readonly', 'readonly');

                    $('#loan_instalment').attr('readonly', 'readonly');

                    $('#loan_int_rate').attr('readonly', 'readonly');

                    $('#no_of_days').attr('readonly', 'readonly');

                    $('#loan_date').attr('readonly', 'readonly');

                    $('#surety_memno').attr('readonly', 'readonly');

                    $('#ent_fees').attr('readonly', 'readonly');

                    $('#d_share').attr('readonly', 'readonly');

                    $('#d_ins').attr('readonly', 'readonly');

                    $('#f_loan_no').attr('readonly', 'readonly');

                    $('#f_loan_amount').attr('readonly', 'readonly');

                    $('#f_os').attr('readonly', 'readonly');

                    $('#f_pri').attr('readonly', 'readonly');

                    $('#f_int_rate').attr('readonly', 'readonly');

                    $('#f_no_of_days').attr('readonly', 'readonly');

                    $('#f_loan_date').attr('readonly', 'readonly');

                    $('#d_others').attr('readonly', 'readonly');
                    $('#surety_memno').prop('disabled', true);
                    $('#save').prop('disabled', true);

                } else {
                    $('#loan_no').attr('readonly', false);

                    $('#loan_amount').attr('readonly', false);

                    $('#loan_os_amt').attr('readonly', false);

                    $('#loan_principle_amt').attr('readonly', false);

                    $('#curr_instalment').attr('readonly', false);

                    $('#loan_instalment').attr('readonly', false);

                    $('#loan_int_rate').attr('readonly', false);

                    $('#no_of_days').attr('readonly', false);

                    $('#loan_date').attr('readonly', false);

                    $('#surety_memno').attr('readonly', false);

                    $('#ent_fees').attr('readonly', false);

                    $('#d_share').attr('readonly', false);

                    $('#d_ins').attr('readonly', false);


                    $('#f_loan_no').attr('readonly', false);

                    $('#f_loan_amount').attr('readonly', false);

                    $('#f_os').attr('readonly', false);

                    $('#f_pri').attr('readonly', false);

                    $('#f_int_rate').attr('readonly', false);

                    $('#f_no_of_days').attr('readonly', false);

                    $('#f_loan_date').attr('readonly', false);

                    $('#d_others').attr('readonly', false);
                    $('#surety_memno').prop('disabled', false);

                    $('#save').prop('disabled', false);
                }

            }
        });

    });
</script>