


<script> 



$(function() {
	

    //Initialize Select2 Elements
    $(".select2").select2();
//$('#content').html('<img id="loader-img" alt="" src="<?php echo base_url();?>assets/dist/loader.gif"  align="center" />');
    $('#All').click(function(){
		//alert('clicked');
		if ($('#All').prop('checked'))		 
		 {
			$('#Employee').attr('disabled', 'true');			
	  
		 }
		 else
		 {
			$('#Employee').removeAttr('disabled');
			
		 }
	  
    });

	 $('#PayOn').change(function(){
    
 var id = $('#PayOn').val();
		if(id != '-1')
		{
			$('#content').loader('show');

		 $.ajax({
			data:{id1:id},
			
			type:"POST",
			url:"<?php echo base_url();?>payslip/getEmployee",
			success:function(result) {
				if(result)
				{
                $("#Employee").empty();	
				$('#content').loader('hide'); 
				$("#Employee").append(result);
				 
				}
					
		      }
			});	
		}
		else
		{
			alert('Please select the PayOn');
			return false;
		}
  
});


	$("#Calculate").click(function(){
       
	   var count=0;
       var payon = $('#PayOn').val();
       var employee = $('#Employee').val();
	   
      // alert(payon+employee); 
	   
       if(payon != '-1' && employee !='-1')
		{
			var check = $('#All').is(":checked");
			if(check){
					//alert(check);
				
					$('#Employee').find('option').each(function() {
					//alert($(this).val());
					count++;
					//AJAX STARTED
						var employee=$(this).val();
						$.ajax({
									data:{payon:payon,employee:employee},
									type:"POST",
									url:"<?php echo base_url();?>payslip/callsp",
			
										success:function(result){
											
											$('#content').loader('hide');
										//alert("Procedure Called Sucessfully!");
										}
								});
								
								
					//AJAX ENDED
				});
			alert(count + "  Employees Salary Added Successfully!");
			
			} // else for select all not selected
			else{
				
			$('#content').loader('show');

		 $.ajax({
			data:{payon:payon,employee:employee},
			type:"POST",
			url:"<?php echo base_url();?>payslip/callsp",
			
			success:function(result) {
				
                $('#content').loader('hide');
                alert("Employees Salary Added Successfully!");
				 
				
					
		      }
			});	
			
			}// else for select all not selected
			
		}// check payon select/not selected
		else
		{
			alert('Please select the PayOn');
			return false;
		}


		




   });  

 
	 });



</script>

<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <h1>
       <center>Siddharth Industries - PaySlip Generator</center>
        
      </h1>
    </section>
    <section class="content">
	<div class="row" style="border:2px dotted; padding:5%">
	 <form id="PayslipGenerator" action="<?php echo base_url() ?>PrintPdf" method="post" role="form" > 
        <div class="row"  >
		<div class="col-md-4">
	
				<span for="selectmonth">Select Month</span>
					<select id="PayOn" name="PayOn"   class="form-control select2" style="width: 100%;">
							<option  value="-1">Select Payon Month</option>
								<?php	
                                            if(!empty($Payon))
                                            {
                                                foreach ($Payon as $rl)
                                                {
													 $Pay =$rl->PayOn;
                                                  													
													if ($_POST['PayOn'] == $Pay) 
													{

												echo "<option value=\"".$Pay."\" selected=\"selected\">".$Pay."</option>"; 
													}
													else 
													{
													echo "<option value=\"".$Pay."\">".$Pay."</option>";       
													}		
                                                    
                                                }
                                            }
                                            ?>
						</select>
			</div>
				<div id="content"></div>
			<div class="col-md-4 col-md-offset-2">
				
					
						<span>Employee</span>
						<select id="Employee" name="Employee"  class="form-control select2" type="text"  class="form-control">
							<option value="-1">Select Employee</option> 
							
								</select>
								<br/>
								<input type="checkbox" name="All" id="All"   > Select All<br>
					</div>
					
			</div>
			
			<div  class="col-md-4 col-md-offset-6" align = "right">
		
		    <input type="button" class="btn btn-info" id="Calculate" value="Calculate Pay"/>
			<input type="submit" class="btn btn-info" id="Generate" value="Generate"/>
		
			<a href="<?php echo base_url(); ?>payslip/updatepayroll" ><input type="submit" class="btn btn-info" value="Update" /></a>
				</div>
			 
			</div>
			 <div class="row"  >
			  
			
				
				 <?php
                    $this->load->helper('form');
                    $error = $this->session->flashdata('error');
                    if($error)
                    {
                ?>
                <div class="alert alert-danger alert-dismissable">
                    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                    <?php echo $this->session->flashdata('error'); ?>                    
                </div>
                <?php } ?>
                <?php  
                    $success = $this->session->flashdata('success');
                    if($success)
                    {
                ?>
                <div class="alert alert-success alert-dismissable">
                    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                    <?php echo $this->session->flashdata('success'); ?>
                </div>
                <?php } ?>
                
                <div class="row">
                    <div class="col-md-4">
                        <?php echo validation_errors('<div class="alert alert-danger alert-dismissable">', ' <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button></div>'); ?>
                    </div>
                </div>
            </div>
        </div>
		
         
    </section>
</div>