        <!-- page content -->
        <link href="<?php echo base_url(); ?>assets/vendors/select2/dist/css/select2.min.css" rel="stylesheet">
        <div class="right_col" role="main">
          <div class="">
            <div class="page-title">
                <div class="title_left">
                    <h3>Advance</h3>
                </div>
            </div>
            <div class="clearfix"></div>

            <div class="row">
              <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
                  <div class="x_title">
                    <h2>Assign Advance</h2>
                    <ul class="nav navbar-right panel_toolbox">
                      <li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a></li>
                    </ul>
                    <div class="clearfix"></div>
                  </div>
                  <div class="x_content">

<!--action salary/saveadv-->
                    <form class="form-horizontal form-label-left" id="save_advance" action="save_advance" method="post">
                        
                      <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Type <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <select class="form-control" name="type" id="type" required>
                                    <option value="">Select Type</option>
                                    <option value="teacher">Teacher</option>
                                    <option value="staff">Staff</option>
                                 </select> 
                           </div>
                      </div>
                       
                       
                        
                        
                      <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Employee <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        <select class="form-control" name="emp" id="emp" required>
                        <!--<option value="" >Employee</option>!-->
                                 </select>                    
                        </div>
                      </div>  
                      <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="month">Month <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <input type="month" id='month' name="month" value="<?php echo date('Y-m');?>" class="form-control" required>
                           <div class="error" style="color:red;"></div>
                           </div>
                           
                      </div>
                       <div class="item form-group">
                       <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Basic Salary<span class="required"></span>
                        </label>
                         <div class='col-md-6 col-sm-6 col-xs-12'>
                        <input type="text" class="form-control" name="basic_salary" id="basic_salary" readonly>
                        </div>
                     </div>

                      <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="b_head">Amount<span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                          <input id="adv_amount" class="form-control col-md-7 col-xs-12 num" maxlength="50" name="adv_amount" placeholder="Advance Amount...." required="required" type="text">
                        </div>
                      </div>

                      <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="b_head">Description<span class="required"></span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                          <textarea id="des" class="form-control col-md-7 col-xs-12 abc1" maxlength="200" name="des" placeholder="Description Here...."></textarea>
                        </div>
                      </div>
                      
                      <div class="ln_solid"></div>
                      <div class="form-group">
                        <div class="col-md-6 col-md-offset-3">
                          <button  style="float:right" id="send" type="submit" class="btn btn-success">Add</button>
                        </div>
                      </div>
                    </form>
                  </div>
                </div>
             
              </div>
               </div><!--end extra-->

                <div class="row">
             <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
                  <div class="x_title">
                    <h2>Advance Salary View</h2>
                    <ul class="nav navbar-right panel_toolbox">
                      <li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a></li>
                    </ul>
                    <div class="clearfix"></div>
                  </div>
                  <div class="x_content">
                  <div class="x_content">
                     <div class="row">
                        
                    <table id="datatable" class="table">
                      <thead>
                        <tr>
                          <th>#</th>
                          <th>Name</th>
                          <th>Amount</th>
                          <th>Month</th>
                          <th>Description</th>
                          <!--<th>Status</th>-->
                          <th>Actions</th>
                        </tr>
                      </thead>


                      <tbody class="center">
                       
                      </tbody>
                    </table>

                   
                    
                  </div>
                    
                  </div>
                </div>
             
              </div>
              </div>
            
            
            
            </div>
            
              
               
             
              
            
            </div>
          </div>
        </div>
        <!-- /page content -->
        <script src="<?php echo base_url(); ?>assets/vendors/jquery/dist/jquery.min.js"></script>
        <script src="<?php echo base_url(); ?>assets/vendors/select2/dist/js/select2.full.min.js"></script>
          <!-- Datatables -->
    <script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
    <script src="https://cdn.datatables.net/buttons/1.5.2/js/dataTables.buttons.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/pdfmake.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/vfs_fonts.js"></script>
    <script src="https://cdn.datatables.net/buttons/1.5.2/js/buttons.html5.min.js"></script>

 <!-- Datatables -->
     <script>
     $(document).ready(function() {
    $('#datatable').DataTable(
            {
                "lengthMenu": [ [10, 25, 50, -1], [10, 25, 50, "All"] ],
                 "bPaginate":true,
                "paging":   true,
                "bFilter":true,
                "pageLength": 20,
                 dom: 'lBfrtip',
        buttons: [
            'excelHtml5',
            'csvHtml5',
            'pdfHtml5'
        ]
                    }
        );
           });
 </script>
        <script>

    $('#type').change(function(){
                 
                var value=$(this).val();
if(value=="teacher"){
     $.ajax({
     url: '<?php echo base_url(); ?>Salary/load_teacher_advance/',
      success: function (result) {
           $("#datatable").dataTable().fnDestroy();
           setTimeout(function(){ 
                $("tbody.center").html(result);
                $('#datatable').DataTable({
                    "lengthMenu": [ [10, 25, 50, -1], [10, 25, 50, "All"] ],
                 "bPaginate":true,
                "paging":   true,
                "bFilter":true,
                "pageLength": 20,
                 dom: 'lBfrtip',
        buttons: [
            'excelHtml5',
            'csvHtml5',
            'pdfHtml5'
        ]
                   } );
            },500);
           }
      });
}else{
  $.ajax({
     url: '<?php echo base_url(); ?>Salary/load_staff_advance/',
      success: function (result) {
           $("#datatable").dataTable().fnDestroy();
           setTimeout(function(){ 
                $("tbody.center").html(result);
                $('#datatable').DataTable({
                "lengthMenu": [ [10, 25, 50, -1], [10, 25, 50, "All"] ],
                 "bPaginate":true,
                "paging":   true,
                "bFilter":true,
                "pageLength": 20,
                 dom: 'lBfrtip',
        buttons: [
            'excelHtml5',
            'csvHtml5',
            'pdfHtml5'
        ]
                    });
            },500);
           }
      });
}
                
                $.get("<?php echo base_url(); ?>load/getemp/"+value,{},function(d){
                    var pre = '<option value="">Select Employee</opiton>';
                    $("#emp").html(pre+d);
                });
                //tabledata(value);

            });
            //function tabledata(val){
               //$.get("<?php echo base_url(); ?>salary/getemp_advance/"+val,{},function(d){
                  // $("tbody.center").html(d);

                    
                //});
            //}
 
  
 


            $('#emp').change(function(){
                 var ref=$('#type').val();
                 var val=$(this).val();
                 var month=$('#month').val();
                if(val != "")
                {
                if(ref=='teacher')
                  {
                     $.ajax({
                      url: "<?php echo base_url();?>Salary/teacher_salaryinc/"+val+"/"+month,
                     success: function(result){
                   // $("#empee").html(result);
                   $('#basic_salary').val(result);    
                         }
                         }); 

                         $.ajax({
                      url: "<?php echo base_url();?>Salary/teacher_advnc/"+val,
                     success: function (result) {
                $("#datatable").dataTable().fnDestroy();
                setTimeout(function(){ 
                $("tbody.center").html(result);
                $('#datatable').DataTable(
                    {
                "lengthMenu": [ [10, 25, 50, -1], [10, 25, 50, "All"] ],        
                 "bPaginate":true,
                "paging":   true,
                "bFilter":true,
                "pageLength": 20,
                 dom: 'lBfrtip',
        buttons: [
            'excelHtml5',
            'csvHtml5',
            'pdfHtml5'
        ]
                    }
                    );
                  },500);
                    }
                         }); 
              
                  }else
                  {
                     $.ajax({
                      url: "<?php echo base_url();?>Salary/staff_salaryinc/"+val+"/"+month,
                     success: function(result){
                   // $("#empee").html(result);
                    $('#basic_salary').val(result);    
                         }
                         }); 

                          $.ajax({
                      url: "<?php echo base_url();?>Salary/staff_advnc/"+val,
                     success: function (result) {
                $("#datatable").dataTable().fnDestroy();
                setTimeout(function(){ 
                $("tbody.center").html(result);
                $('#datatable').DataTable(
                        {
                "lengthMenu": [ [10, 25, 50, -1], [10, 25, 50, "All"] ],            
                 "bPaginate":true,
                "paging":   true,
                "bFilter":true,
                "pageLength": 20,
                 dom: 'lBfrtip',
        buttons: [
            'excelHtml5',
            'csvHtml5',
            'pdfHtml5'
        ]
                    }
                    );
                  },500);
                    }
                         });
                  }
                }else
                {
                  $('#basic_salary').val("");   
                  if(ref=="teacher"){
     $.ajax({
     url: '<?php echo base_url(); ?>Salary/load_teacher_advance/',
      success: function (result) {
           $("#datatable").dataTable().fnDestroy();
           setTimeout(function(){ 
                $("tbody.center").html(result);
                $('#datatable').DataTable(
                        {
                "lengthMenu": [ [10, 25, 50, -1], [10, 25, 50, "All"] ],            
                 "bPaginate":true,
                "paging":   true,
                "bFilter":true,
                "pageLength": 20,
                 dom: 'lBfrtip',
        buttons: [
            'excelHtml5',
            'csvHtml5',
            'pdfHtml5'
        ]
                    }
                    );
            },500);
           }
      });
}else{
  $.ajax({
     url: '<?php echo base_url(); ?>Salary/load_staff_advance/',
      success: function (result) {
           $("#datatable").dataTable().fnDestroy();
           setTimeout(function(){ 
                $("tbody.center").html(result);
                $('#datatable').DataTable(
                        {
                "lengthMenu": [ [10, 25, 50, -1], [10, 25, 50, "All"] ],            
                 "bPaginate":true,
                "paging":   true,
                "bFilter":true,
                "pageLength": 20,
                 dom: 'lBfrtip',
        buttons: [
            'excelHtml5',
            'csvHtml5',
            'pdfHtml5'
        ]
                    }
                    );
            },500);
           }
      });
}
                }
              

            });
            $('#month').change(function(){
              var val=$('#month').val();
              var orgm=$('#month').val();
              var alag = val.split("-");
              var sy=parseInt(alag[0]);
              var sm=parseInt(alag[1]);
             // alert(sy);
             // alert(sm);
              var d = new Date();
              var m = d.getMonth()+1;
              var y = d.getFullYear();
              if(sy>=y && sm>m){
                $('#send').prop("disabled",false);
                  $('.error').html("");
                  
                  //
   var emp = $('#emp').val();
    var ref=$('#type').val();
    if(emp.length < 0)
    {
        
    }else{
         if(ref=='teacher')
          {
             $.ajax({
              url: "<?php echo base_url();?>Salary/teacher_salaryinc/"+emp+"/"+orgm,
             success: function(result){
           $('#basic_salary').val(result);    
                 }
                 });
                  
      
          }else
          {
             $.ajax({
              url: "<?php echo base_url();?>Salary/staff_salaryinc/"+emp+"/"+orgm,
             success: function(result){
            $('#basic_salary').val(result);    
                 }
                 }); 
          }
    }
    
          
              }else{
                $('.error').html("Month in advance should be greater current month");
                $('#send').prop("disabled",true);
                
              }
              });
      
        </script>   
        <script>
        $('#adv_amount').on("change",function(){
         var value=parseInt($(this).val());
         var salary=parseInt($("#basic_salary").val());
         if(value > salary)
         {
            $("#send").attr("disabled","disabled");
           alert("Advance amount always less then salary...");
           return false;
         
         }
         else{
           $("#send").removeAttr("disabled");
         }
         
         var mnth=$("#month").val();
         var ref=$('#type').val();
         var bothid=$('#emp').val();
          $.ajax({
                      url: "<?php echo base_url();?>Salary/get_alladvance/"+mnth+"/"+ref+"/"+bothid,
                     success: function(result){
                     
                     var total_amont=parseInt(value) + parseInt(result);
                    // alert(total_amont);
                      if(total_amont> salary)
         {
             $("#send").attr("disabled","disabled");
           alert("Total Advance can't increase by salary..");
           return false;
         } else{
           $("#send").removeAttr("disabled");
         }
                   
                    
                         }
                         }); 
                         
        });
        </script>

 <script>
 function edit_id(id,event){
   event.preventDefault();
   $.ajax({
      url: "<?php echo base_url();?>Salary/edit_adv/"+id,
          success: function(result){
               var obj=JSON.parse(result);
               //$("#edit_id").val(obj.id);
              // $("#type select").val(obj.id);
               //$("#type option[value='United State']").attr("disabled", true);
               $("#type").val("United State");
                
                 }
                 });
  
 }
 </script>

  <script>
 function dell_id(id,event){
   event.preventDefault();
  $.ajax({
      url: "<?php echo base_url();?>Salary/dell_adv/"+id,
          success: function(result){
               
                 }
                 }); 
 }
 </script>

        <script>
$('#send').on("click",function(){
  
  var type=$("#type").val();
  var bothid=$("#emp").val();
  var month=$("#month").val();
  var amount=$("#adv_amount").val();
  var des=$("#des").val();

if(type=="" || bothid=="" || month=="" || amount=="")
{
 alert("Please fill the form");
 return false;
}else
{
  $("#save_advance").submit();
  //$.ajax({
        //url: "<?php echo base_url();?>Salary/save_advance/"+type+"/"+bothid+"/"+month+"/"+amount+"/"+des,
         //success: function(result){
                      
                         //}
                        // }); 
}

});
        </script>

       <script type="text/javascript">
      $(document).ready(function() {
        
        $("#emp").select2({
          
        });
      });
    </script>