 <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <div class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <h1 class="m-0 text-dark">Recive Instalment</h1>
          </div><!-- /.col -->
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
              <li class="breadcrumb-item"><a href="<?php echo base_url() ?>admin/admin/dashboard">Dashboard</a></li>
              <li class="breadcrumb-item"><a href="#">Fees Management</a></li>
              <li class="breadcrumb-item active">Recive Instalment</li>

            </ol>
          </div><!-- /.col -->
        </div><!-- /.row -->
      </div><!-- /.container-fluid -->
    </div>
    <!-- /.content-header -->
    <?php echo form_open(base_url().'admin/fees_management/update_instalment_amount');?>
    <section class="content">
      <div class="container-fluid">

        <div class="row">
          <div class="col-sm-12">
            <div class="card card-default">
              <div class="card-header">
                <h3 class="card-title">Add Instalment Amount for <b><?php echo $student->user_name; ?></b></h3>
              </div>
              <!-- /.card-header -->
              <div class="card-body">
                <div class="row">

                  <div class="col-md-12">
                    <div class="form-group">
                       <label for="inputEmail" class="col-sm-12 col-form-label">Select Course <span class="required">*</span></label>
                       <div class="col-sm-12">
                          <select class="form-control" onchange="get_course_price(this.value)" name="instalment_course_id" placeholder="Enter Notice Content" required="required" id="fee_student_course">
                            <option value="">Select</option>
                          </select>
                       </div>
                    </div>
                  </div>

                  <div class="col-md-4">
                    <div class="form-group">
                       <label for="inputEmail" class="col-sm-12 col-form-label">Course Price <span class="required">*</span></label>
                       <div class="col-sm-12">
                          <input class="form-control"  name="fee_student_course_price" placeholder="Enter Course Price" required="required" id="course_price" readonly>
                       </div>
                    </div>
                  </div>
                  <div class="col-md-4">
                    <div class="form-group">
                       <label for="inputEmail" class="col-sm-12 col-form-label">Course Discount (%) <span class="required">*</span></label>
                       <div class="col-sm-12">
                          <input class="form-control" onkeyup="percantage(this.value)" name="fee_student_course_discount" placeholder="Enter Course Discount" required="required" id="course_discount" readonly>
                       </div>
                    </div>
                  </div>
                  <div class="col-md-4">
                    <div class="form-group">
                       <label for="inputEmail" class="col-sm-12 col-form-label">Total Course Amount <span class="required">*</span></label>
                       <div class="col-sm-12">
                          <input class="form-control"  name="fee_student_course_main_price"  required="required" id="main_price" readonly>
                       </div>
                    </div>
                  </div>
                  <script type="text/javascript">
                    function percantage(e) 
                    {
                      var course_price = $('#course_price').val();
                      var per = (e / 100) * course_price;
                      var main_per = course_price - per;
                      $('#main_price').val(main_per);
                    }
                    function calculate(e) 
                    {
                      alert("jhfjf")
                      var due_amt = $('#due_ammount').val();
                      $('#due_ammount').val(due_amt - e);
                      var down_payment = $('#down_payment').val();
                      $('#down_payment').val(+down_payment + +e)
                    }
                  </script>
                  <div class="col-md-2">
                    <div class="form-group">
                       <label for="inputEmail" class="col-sm-12 col-form-label">Total Due Amount <span class="required">*</span></label>
                       <div class="col-sm-12">
                          <input class="form-control"  name="fee_student_course_due"  required="required" id="due_ammount" readonly>
                       </div>
                    </div>
                  </div>

                  <div class="col-md-3">
                    <div class="form-group">
                       <label for="inputEmail" class="col-sm-12 col-form-label">Select A Instalment<span class="required">*</span></label>
                       <div class="col-sm-12">
                          <select onchange="get_instalment_amt(this.value)" class="form-control"  name="instalment_id" required="required" id="instalment">
                            <option value="">Select</option>
                          </select>
                       </div>
                    </div>
                  </div>
                  <div class="col-md-3">
                    <div class="form-group">
                       <label for="inputEmail" class="col-sm-12 col-form-label">Payment Amount<span class="required">*</span></label>
                       <div class="col-sm-12">
                          <input class="form-control" onchange="calculate(this.value)" name="payment_amt" placeholder="Enter Days" required="required" id="pay_amt" readonly>
                       </div>
                    </div>
                  </div>
                  <div class="col-md-3">
                    <div class="form-group">
                       <label for="inputEmail" class="col-sm-12 col-form-label">Payment Date<span class="required">*</span></label>
                       <div class="col-sm-12">
                          <input type="date" class="form-control"  name="instalment_pay_date" placeholder="Enter Days" required="required" >
                       </div>
                    </div>
                  </div>

                  <input type="hidden" class="form-control"  name="fee_student_id" value="<?php echo $student->user_id; ?>">
                  <input type="hidden" class="form-control"  name="st_course_id" id="course_table_id">

                  <div class="col-md-12">
                    <div class="form-group">
                       <button name="form1" style="float: right" type="submit" class="btn btn-success">Save</button>
                    </div>
                  </div>
                  
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </section>

    <?php echo form_close();?>
    <!-- /.content -->
  </div>


  
<script type="text/javascript">
$(function () {
    get_course_by_student_id(<?php echo $student->user_id; ?>)
  });

function get_course_by_student_id(e) 
{
  $.ajax({
    beforeSend: function() {
       $(".loader").show();
    },
    type: "GET",
    dataType:"JSON",
    async: true,
    url: '<?php echo base_url(); ?>admin/students/get_course_by_student_id_for_add_installment/'+e,
    success: function (data) 
    {
        $('#fee_student_course').html(data.option);
        $(".loader").hide();
    },
    error: function (e) {
      console.log(e.responseText)
      $(".loader").hide();
    }
  });
}
function get_course_price(e) 
{
  var st_id = '<?php echo $student->user_id; ?>';
  $.ajax({
    beforeSend: function() {
       $(".loader").show();
    },
    type: "GET",
    dataType:"JSON",
    async: true,
    url: '<?php echo base_url(); ?>admin/students/get_course_price_by_course_id_for_fee_recive/'+e+'/'+st_id,
    success: function (data) 
    {
        $('#course_price').val(data.price);
        $('#main_price').val(data.main_price);
        $('#course_discount').val(data.course_discount);
        $('#down_payment').val(data.down_payment);
        $('#due_ammount').val(data.due_ammount);
        $('#instalment').html(data.option);
        $('#course_table_id').val(data.course_table_id);
        $(".loader").hide();
    },
    error: function (e) {
      console.log(e.responseText)
      $(".loader").hide();
    }
  });
}

function get_instalment_amt(e) 
{
  $.ajax({
    beforeSend: function() {
       $(".loader").show();
    },
    type: "GET",
    dataType:"JSON",
    async: true,
    url: '<?php echo base_url(); ?>admin/students/get_instalment_amt/'+e,
    success: function (data) 
    {
        $('#pay_amt').val(data);
        $(".loader").hide();
    },
    error: function (e) {
      console.log(e.responseText)
      $(".loader").hide();
    }
  });
}

</script>
<style type="text/css">
.check-box
{

}
</style>