<style>
#defination{
  display:none;
}
#back{
  display:none;
}
</style>
<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>Report</h3>
                   
                </div>
            </div>
            <div class="clearfix"></div>
             <?php if ($this->session->flashdata('errormsg')): ?>
<div class="alert alert-danger">
<?php echo $this->session->flashdata('errormsg'); ?>
</div>
<?php endif ?>

             <?php if ($this->session->flashdata('errormsg2')): ?>
<div class="alert alert-danger">
<?php echo $this->session->flashdata('errormsg2'); ?>
</div>
<?php endif ?>
    <div class="row" id="Allowance">

                 <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
                  <div class="x_title">
                    <h2>Salary Slips</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">
 <form class="form-horizontal form-label-left" action="<?php echo $base_url; ?>Report/print_salary_slip" 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-6">
                            <select class="form-control" required name="type" id="type">
                              <option value=''>Select Type</option>
                              <option value='teacher'>Teacher</option>
                              <option value='staff'>Staff</option>
                              
                                                </select> 
                           </div>
                      </div>
              
                     <div class="item form-group" id="myemp">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Employee Name<span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-6">
                            <select class="form-control" required name="emp" id="empee">
                              <option value=''>Select Employee</option>
                                                </select> 
                           </div>
                      </div>
                     
                       <div class="item form-group">
                       <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Month<span class="required"></span>
                        </label>
                         <div class="col-md-6 col-sm-6 col-xs-6">
                        <input type="month" class="form-control" name="month" id="month">
                        </div>
                     </div>

             <div class="ln_solid"></div>
                      <div class="form-group">
                        <div class="col-md-9">
                          <button id="save" type="submit" class="btn btn-success pull-right">Get Report</button>
                        </div>
                      </div>
                    </form>
                  </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>
 <script>
window.setTimeout(function() {
$(".alert").fadeTo(500, 0).slideUp(500, function(){
    $(this).remove(); 
});
}, 3000);
</script>
    <!-- Datatables -->
    <script src="<?php echo base_url(); ?>assets/vendors/datatables.net/js/jquery.dataTables.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/datatables.net-bs/js/dataTables.bootstrap.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/datatables.net-buttons/js/dataTables.buttons.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/datatables.net-buttons-bs/js/buttons.bootstrap.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/datatables.net-buttons/js/buttons.flash.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/datatables.net-buttons/js/buttons.html5.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/datatables.net-buttons/js/buttons.print.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/datatables.net-fixedheader/js/dataTables.fixedHeader.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/datatables.net-keytable/js/dataTables.keyTable.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/datatables.net-responsive/js/dataTables.responsive.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/datatables.net-responsive-bs/js/responsive.bootstrap.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/datatables.net-scroller/js/datatables.scroller.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/jszip/dist/jszip.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/pdfmake/build/pdfmake.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/pdfmake/build/vfs_fonts.js"></script>

    

    <!-- Datatables -->
     <script>
     $(document).ready(function() {
    $('#datatable').DataTable();
           });
 </script>

  <script>
     $(document).ready(function() {
    $('#datatable2').DataTable();
           });
 </script>
    <!-- /Datatables -->
<script>
$(document).ready(function(){

   $.ajax({
    url: '<?php echo base_url(); ?>Salary/allallowncee/',data: {},
         success: function (result) {
               $("#get_data").html(result);
           }
     });//end ajax for loading form


});
</script>


  <script>
$("#add_def").click(function(event){
 
  var house="allonce";
        $.ajax({
    url: '<?php echo base_url(); ?>Salary/act_dec/'+house,data: {},
         success: function (result) {
           $("#datatable").dataTable().fnDestroy();
           setTimeout(function(){ 
                $("tbody.center").html(result);
                $('#datatable').DataTable();
            },500);
           }
     });//end ajax for loading datatables
 $("#Allowance").hide();
 $("#defination").show();
 $("#back").show();
 $("#add_def").hide();
 $("#assigned_allownce").hide();
 
});//end add defination button click functionalty

 $("#back").click(function(event){
 $("#Allowance").show();
 $("#defination").hide();
 $("#back").hide();
 $("#assigned_allownce").show();
 $("#add_def").show();
 $.ajax({
    url: '<?php echo base_url(); ?>Salary/allallowncee/',data: {},
         success: function (result) {
         console.log(result);
               $("#get_data").html(result);
           }
     });//end ajax for loading form

  });//end assign allownce button click functionalty

$("#new_type").click(function(event){
  event.preventDefault();
  var value=$("#new_type").val();
  var name=$("#alloncename").val();
  var des=$("#allonce_des").val();
  if(name=="" || des=="")
  {
    alert("Please fill the fields");
    return false;
  }
if(value=="Add")
{
$.ajax({
 url:'<?php echo base_url();?>Salary/save_allonce/'+name+'/'+des,data:{},
        success: function (result) {
        
        if(result != "false")
        {
           $("#datatable").dataTable().fnDestroy();
           setTimeout(function(){ 
                $("tbody.center").html(result);
                $('#datatable').DataTable();
            },500);
            
            }
            else
            {
             alert("This name of allownce already added");
             return false;
            }
            
           }
    });
$("#alloncename").val("");
 $("#allonce_des").val("");
}
else if(value=="Update")
{
  var id=$("#edit_id").val();
  var up_name=$("#alloncename").val();
  var up_des=$("#allonce_des").val();
   $.ajax({
    url:'<?php echo base_url()?>Salary/update_allonceee/'+id+"/"+up_name+"/"+up_des,data:{},
    success: function (result) {
           $("#datatable").dataTable().fnDestroy();
           setTimeout(function(){ 
                $("tbody.center").html(result);
                $('#datatable').DataTable();
            },500);
           }
  });
   $("#alloncename").val("");
 $("#allonce_des").val("");
 $("#new_type").val("Add");
}
});//end if for button type checking
</script>

<script>
function deactive(id,event){
  event.preventDefault();
   $.ajax({
     url: '<?php echo base_url(); ?>Salary/deactive/'+id,data: {},
      success: function (result) {
           $("#datatable").dataTable().fnDestroy();
           setTimeout(function(){ 
                $("tbody.center").html(result);
                $('#datatable').DataTable();
            },500);
           }
      });

}
</script>
<script>
function active(id,event){
event.preventDefault();
  $.ajax({
     url: '<?php echo base_url(); ?>Salary/active/'+id,
      success: function (result) {
           $("#datatable").dataTable().fnDestroy();
           setTimeout(function(){ 
                $("tbody.center").html(result);
                $('#datatable').DataTable();
            },500);
           }
      });
}
</script>
<script>
function edit(id,event){
  event.preventDefault();
  $.ajax({
     url: '<?php echo base_url(); ?>Salary/get_record/'+id,
         success: function (result)
          { 
           
            var obj=JSON.parse(result);
           
            $("#edit_id").val(obj.id);
            $("#alloncename").val(obj.name);
            $("#allonce_des").val(obj.description);
            $("#new_type").val("Update");
            
            //$("tbody.center").html(result);
            }
      });
}
</script>

<script>
function Per(id,event){
     
  event.preventDefault(); 
 var rup_id='#allowance_rup'+id;
 var per_id='#allowance_per'+id;
 
 $(per_id).prop("readonly", false); 

 $(rup_id).val(0);
 var value=$(per_id).val();
 $(rup_id).prop("readonly", true); 

 $(per_id).keypress(function(event){
  var inputValue = event.which;
  if (inputValue != 8 && inputValue != 0 && (inputValue < 48 || inputValue > 57)) {
        //display error message
        alert("Please press only digit..");
               return false;
    }
    
    });

     $(per_id).change(function(event){
  var inputValue = $(this).val();
  if (inputValue > 100) {
        //display error message
        $("#save").attr("disabled","disabled");
        alert("Maximum 100% allowed");
          return false;         
    }else
    {
            $("#save").removeAttr("disabled");
    }
    
    });

}
</script>

<script>
function Rup(id,event){
  event.preventDefault();
 var per_id='#allowance_per'+id;
 var rup_id='#allowance_rup'+id;
 $(rup_id).prop("readonly", false); 
 $(per_id).val(0);
var value=$(rup_id).val();
 $(per_id).prop("readonly", true); 
 $(rup_id).keypress(function(event){
  var inputValue = event.which;
  if (inputValue != 8 && inputValue != 0 && (inputValue < 48 || inputValue > 57)) {
        //display error message
        alert("Please press only digit..");
               return false;
    }
 });
}
</script>

 <script>

    $('#type').change(function() {


   var c=$(this).val();
   
   if(c=="teacher"){
      $.ajax({
            url: "<?php echo base_url();?>Load/checkval/"+c, 
          success: function(result){
                 
                $("#empee").html(result);
                jq('#empee').multiselect('reload');
                
            }}
            );
       $.ajax({
     url: '<?php echo base_url(); ?>Salary/load_teacher_allownce/',
      success: function (result) {
           $("#datatable2").dataTable().fnDestroy();
           setTimeout(function(){ 
                $("tbody.center22").html(result);
                $('#datatable2').DataTable();
            },500);
           }
      });


   }else{
      $.ajax({
            url: "<?php echo base_url();?>Load/checkval1/"+c, 
          success: function(result){
                $("#empee").html(result);
                jq('#empee').multiselect('reload');
                
            }});
             
             $.ajax({
     url: '<?php echo base_url(); ?>Salary/load_staff_allownce/',
      success: function (result) {
           $("#datatable2").dataTable().fnDestroy();
           setTimeout(function(){ 
                $("tbody.center22").html(result);
                $('#datatable2').DataTable();
            },500);
           }
      });


    }
        
        
        $("#empee").select2({
          
        });
   

            //loading form again
            $.ajax({
    url: '<?php echo base_url(); ?>Salary/allallowncee/',data: {},
         success: function (result) {
               $("#get_data").html(result);
           }
     });//end ajax for loading form

  });
   


 
  $("#myemp").change(function() {
  
                    var value = $('#empee').val();
                    var ref=$('#type').val();
                   
                    $.ajax({
     url: '<?php echo base_url(); ?>Salary/teacher_allownce_selected/'+value+"/"+ref,
      success: function (result) {
           $("#datatable2").dataTable().fnDestroy();
           
           setTimeout(function(){ 
                $("tbody.center22").html(result);
                $('#datatable2').DataTable();
            },500);
           }
      });

                  if(ref=='teacher')
                  {
                     $.ajax({
                      url: "<?php echo base_url();?>Salary/teacher_salary/"+value,
                     success: function(result){
                   // $("#empee").html(result);
                   $('#basic_salary').val(result);    
                         }
                         });
                          
              
                  }else
                  {
                     $.ajax({
                      url: "<?php echo base_url();?>Salary/staff_salary/"+value,
                     success: function(result){
                   // $("#empee").html(result);
                    $('#basic_salary').val(result);    
                         }
                         }); 
                  }




                        $.post("<?php echo base_url(); ?>Load/checkallowan/"+value+"/"+ref,{},function(data){
                        data = JSON.parse(data);
                       if(data!=""){
                        $.each( data, function( key, value ) {
                            $('.allowance_id:input[value="'+value.allowance_id+'"]').prop('checked',true);
                             var amount=value.percentage;
                               var amount2=value.rupess;

                            $('#allowance_per'+value.allowance_id).val(amount);
                            $('#allowance_rup'+value.allowance_id).val(amount2);
                            var s=value.id;
                            $('#hid'+value.allowance_id).val(s);
                             });
                    }
                    else{
                      //loading form again
                       $.ajax({
                        url: '<?php echo base_url(); ?>Salary/allallowncee/',data: {},
                       success: function (result) {
                        $("#get_data").html(result);
                          }
                            });//end ajax for loading form
                    }
                    


                        });
                     
                    }); 
 


  </script> 