<?php
session_start();
if(!isset ($_SESSION['user_id'])){
	header("Location:../login.php?msg=Log in first");
    exit();
}else{
	
	include('../Server/connection.php');
	include('includes/session.php');
	echo "<div class='div-request div-hide'>editOrd</div>";
    	
?>

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <!-- Meta, title, CSS, favicons, etc. -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

	
	 <?php
  include 'title.php';
         ?>
	
	
	<link type = "image/png" rel="icon" href="images/brvision.png" />

    <!-- Bootstrap must-->
    <link href="../vendors/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
	
    <!-- Font Awesome must-->
    <link href="../vendors/font-awesome/css/font-awesome.min.css" rel="stylesheet">
	
	<!-- custom css -->
    <link rel="stylesheet" href="custom/css/custom.css">
	
    <!-- NProgress must-->
    <link href="../vendors/nprogress/nprogress.css" rel="stylesheet">
	
    <!-- Custom Theme Style must-->
    <link href="../build/css/custom.min.css" rel="stylesheet">
	
	<!-- must-->
	<script src="assests/jquery/jquery.min.js"></script>
	
  <!-- jquery ui -->  
  <link rel="stylesheet" href="assests/jquery-ui/jquery-ui.min.css">
  <script src="assests/jquery-ui/jquery-ui.min.js"></script>
	
  <!-- Must Bootstrap -->
    <script src="../vendors/bootstrap/dist/js/bootstrap.min.js"></script>
	
	<script type="text/javascript">
$(document).ready(function(){
    $('#entryId').on('change',function(){
        var regID = $(this).val();
        if(regID){
            $.ajax({
                type:'POST',
                url:'ajaxData2.php',
                data:'entryId='+regID,
                success:function(html){
                    $('#entryNameId').html(html);
                }
            }); 
        }else{
            $('#entryNameId').html('<option value="">Select EntryPoint Type First</option>');
        }
    });

});
</script>
	
  </head>

  <body class="nav-md">
  
    <div class="container body">
	
      <div class="main_container">
        <div class="col-md-3 left_col">
          <div class="left_col scroll-view">
		  
             <?php  
		include 'includes/role.php';
               ?>

            <div class="clearfix"></div>
            
			
			<?php
            include 'includes/profile.php';
			print '</br></br>';
			include 'includes/menu.php';
			?>


           

        <!-- page content -->
        <div class="right_col" role="main">
          <div class="">
		  
			
			
            <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">
				  
                    <a href="dashboard.php">  <h2><span class="glyphicon glyphicon-step-backward"></span> Back</h2></a>
					
					<?php
					/*
				$inv_id = $_GET['i'];
				$sql81 = "SELECT * FROM invoices WHERE inv_id = {$inv_id}";
				$result81 = $conn->query($sql81);
				while($data81 = mysqli_fetch_array($result81))
							{
							$client_id = $data81['client_id'];
							$currency_id = $data81['currency_id'];
							$inv_date = $data81['inv_date'];
							$due_date = $data81['due_date'];
							$payment_mode_id = $data81['payment_mode_id'];
							$totalAmount = number_format($data81['total_amount'],2);
							$totalAmount11 = $data81['total_amount'];
							$orderNo = $data81['orderNo'];
				            }
*/							
				      ?>
					
					
					
                    <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" style="overflow: auto;">
				
				<?php if (isset($_SESSION['success_message']) && !empty($_SESSION['success_message'])) { ?>
                        <div class="success-message" style="margin-bottom: 20px;font-size: 20px;color: green;"><?php echo $_SESSION['success_message']; ?></div>
                        <?php
                        unset($_SESSION['success_message']);
                    }
                    ?>	
				 
				  <div class="success-messages"></div> <!--/success-messages-->

               <form class="form-horizontal" method="POST" action="php_action/process_payroll.php" enctype="multipart/form-data">
			   
			   <span class="section">Process Payroll</span>
			   
			    <input type="hidden" name="inv_id" value="<?php echo $inv_id; ?>">
				
				
			

              <table class="table" id="productTable">
			  	<thead>
			  		<tr>			  			
			  			<th style="width:5px;">S/No.</th>
						<th style="width:10000px;">Employee Name</th>
						<th style="width:10000px;">Basic Salary in Tsh.</th>
			  			<th style="width:8000px;">Deductions in Tsh.</th>
			  			<th style="width:8000px;">Employee Nssf Contri</th>
                        <th style="width:8000px;">Employee Nhif Contri</th>
                        <th style="width:30px;">Taxable Amount</th>			  			
			  			<th style="width:30px;">Paye</th>
                        <th style="width:30px;">Heslb</th>
                        <th style="width:30px;">Net Pay</th>
						
						<th style="width:30px;">Employer SDL Contri</th>			  			
			  			<th style="width:30px;">Employer NSSF Contri</th>
                        <th style="width:30px;">Employer NHIF Contri</th>
                        <th style="width:30px;">Employer WCF Contri</th>
			  		</tr>
			  	</thead>
			  	<tbody>
			  		<?php
			  		//$arrayNumber = 0;
					//$no 	= 1;
			  		//for($x = 1; $x < 4; $x++) { 
					
					$invItemSql = "SELECT * FROM staff WHERE status_id = 1 order by firstname";
					$invItemResult = $conn->query($invItemSql);
						// $orderItemData = $orderItemResult->fetch_all();						
						
						// print_r($orderItemData);
			  		$arrayNumber = 0;
			  		// for($x = 1; $x <= count($orderItemData); $x++) {
			  		$x = 1;
			  		while($invItemData = $invItemResult->fetch_array()) { 
					$staff_id = $invItemData['staff_id'];
					$basicSalary = $invItemData['BasicSalary'];
					$HesBen_id	= $invItemData['HesBenId'];
					$fname = $invItemData['firstname'];
					$lname = $invItemData['lastname'];
					$empName = $fname.' '.$lname;
					
					if($HesBen_id==1){
	 //$HeslbStatus =1; 
	 $EmployeeHeslbContri = 0.15 * $basicSalary;
	 $EmployeeNssfContri = 0.1 * $basicSalary;
	 $EmployerNssfContri = 0.1 * $basicSalary;
	 $EmpNhifContri = 0.03 * $basicSalary;
	 if($EmpNhifContri>40000){
	 $EmployeeNhifContri = $EmpNhifContri;
	 $EmployerNhifContri = 0.03 * $basicSalary;
	 $EmployerWcfContri = 0.006 * $basicSalary;
	 $EmployerSdlContri = 0.04 * $basicSalary;
	 }else{
	 $EmployeeNhifContri = 0;
     $EmployerNhifContri = 40000;
     $EmployerWcfContri = 0.006 * $basicSalary;	
     $EmployerSdlContri = 0.04 * $basicSalary;	 
	 }
	 $taxableAmount = $basicSalary -($EmployeeNssfContri+$EmployeeNhifContri);
	 if($taxableAmount>270000 && $taxableAmount<=520000){
		 $paye = ($taxableAmount - 270000)* 0.08;
		 $netPay = $taxableAmount -($paye+$EmployeeHeslbContri);
	 }else if($taxableAmount>520000 && $taxableAmount<=760000){
		 $paye = (($taxableAmount - 520000)* 0.2) + 22500;
		 $netPay = $taxableAmount -($paye+$EmployeeHeslbContri);
	 }else if($taxableAmount>760000 && $taxableAmount<=1000000){
		 $paye = (($taxableAmount - 760000)* 0.25) + 70500;
		 $netPay = $taxableAmount -($paye+$EmployeeHeslbContri);
	 }else if($taxableAmount>1000000){
		 $paye = (($taxableAmount - 1000000)* 0.3) + 130500;
		 $netPay = $taxableAmount -($paye+$EmployeeHeslbContri);
	 }else{
		 $paye = 0;
		 $netPay = $taxableAmount -($paye+$EmployeeHeslbContri);
	 }
  }else{
	 //$HeslbStatus =0;  
	 $EmployeeHeslbContri =0;
	 $EmployeeNssfContri = 0.1 * $basicSalary;
	 $EmployerNssfContri = 0.1 * $basicSalary;
	 $EmpNhifContri = 0.03 * $basicSalary;
	 if($EmpNhifContri>40000){
	 $EmployeeNhifContri = $EmpNhifContri;
	 $EmployerNhifContri = 0.03 * $basicSalary;
	 $EmployerWcfContri = 0.006 * $basicSalary;
	 $EmployerSdlContri = 0.04 * $basicSalary;
	 }else{
	 $EmployeeNhifContri = 0;
     $EmployerNhifContri = 0.03 * $basicSalary;
	 $EmployerWcfContri = 0.006 * $basicSalary;
     $EmployerSdlContri = 0.04 * $basicSalary;	 
	 }
	 $taxableAmount = $basicSalary -($EmployeeNssfContri+$EmployeeNhifContri);
	 if($taxableAmount>270000 && $taxableAmount<=520000){
		 $paye = ($taxableAmount - 270000)* 0.08;
		 $netPay = $taxableAmount -($paye+$EmployeeHeslbContri);
	 }else if($taxableAmount>520000 && $taxableAmount<=760000){
		 $paye = (($taxableAmount - 520000)* 0.2) + 22500;
		 $netPay = $taxableAmount -($paye+$EmployeeHeslbContri);
	 }else if($taxableAmount>760000 && $taxableAmount<=1000000){
		 $paye = (($taxableAmount - 760000)* 0.25) + 70500;
		 $netPay = $taxableAmount -($paye+$EmployeeHeslbContri);
	 }else if($taxableAmount>1000000){
		 $paye = (($taxableAmount - 1000000)* 0.3) + 130500;
		 $netPay = $taxableAmount -($paye+$EmployeeHeslbContri);
	 }else{
		 $paye = 0;
		 $netPay = $taxableAmount -($paye+$EmployeeHeslbContri);
	 }
  }
					          ?>
					
			  			<tr id="row<?php echo $x; ?>" class="<?php echo $arrayNumber; ?>">	
						
						   
						   <td>	
			  					<div class="form-group">
								<?php
								print $x;
								?>
			  					</div>
			  				</td>
							
							<!--choosed -->
			  				<td>	
			  					<div class="form-group">
			  					<input type="text"   value="<?php echo $empName; ?>" autocomplete="off" class="form-control" disabled="true"/>
								<input type="hidden" name="staff_id[]" id="staff_id<?php echo $x; ?>"  value="<?php echo $staff_id; ?>" autocomplete="off" class="form-control"/>
			  					</div>
			  				</td>
							<!--choosed -->
							
							<!--choosed -->
							<td>
			  					<div class="form-group">
			  					<input type="number" name="quantity[]" id="quantity<?php echo $x; ?>" onkeyup="getTotal(<?php echo $x ?>)" value="<?php echo $basicSalary; ?>" autocomplete="off" class="form-control" min="1" required />
			  					</div>
			  				</td>
							<!--choosed -->
							
							<td>		  					
			  					<input type="number" name="rate[]" id="rate<?php echo $x; ?>" onkeyup="getTotal(<?php echo $x ?>)"  autocomplete="off"  class="form-control" min="0" />			  					
			  					<input type="hidden" name="rateValue[]" id="rateValue<?php echo $x; ?>"  autocomplete="off" class="form-control" />			  					
							</td>
							
							<td>		  					
			  					<input type="text" name="total[]" id="total<?php echo $x; ?>" value="<?php echo number_format($EmployeeNssfContri,2); ?>" autocomplete="off" class="form-control" disabled="true" />			  					
			  					<input type="hidden" name="totalValue[]" id="totalValue<?php echo $x; ?>" value="<?php echo $EmployeeNssfContri; ?>" autocomplete="off" class="form-control" />			  					
			  				</td>
							
							<td>		  					
			  					<input type="text" name="total[]" id="total<?php echo $x; ?>" value="<?php echo number_format($EmployeeNhifContri,2); ?>" autocomplete="off" class="form-control" disabled="true" />			  					
			  					<input type="hidden" name="totalValue[]" id="totalValue<?php echo $x; ?>" value="<?php echo $EmployeeNhifContri; ?>" autocomplete="off" class="form-control" />			  					
			  				</td>
							
							<td>			  					
			  					<input type="text" name="total[]" id="total<?php echo $x; ?>" value="<?php echo number_format($taxableAmount,2); ?>" autocomplete="off" class="form-control" disabled="true" />			  					
			  					<input type="hidden" name="totalValue[]" id="totalValue<?php echo $x; ?>" value="<?php echo $taxableAmount; ?>" autocomplete="off" class="form-control" />			  					
			  				</td>
							
							
							<td>		  					
			  					<input type="text" name="total[]" id="total<?php echo $x; ?>" value="<?php echo number_format($paye,2); ?>" autocomplete="off" class="form-control" disabled="true" />			  					
			  					<input type="hidden" name="totalValue[]" id="totalValue<?php echo $x; ?>" value="<?php echo $paye; ?>" autocomplete="off" class="form-control" />			  					
			  				</td>
							
							<td>	  					
			  					<input type="text" name="total[]" id="total<?php echo $x; ?>" value="<?php echo number_format($EmployeeHeslbContri,2); ?>" autocomplete="off" class="form-control" disabled="true" />			  					
			  					<input type="hidden" name="totalValue[]" id="totalValue<?php echo $x; ?>" value="<?php echo $EmployeeHeslbContri; ?>" autocomplete="off" class="form-control" />			  					
			  				</td>
							
							<td>			  					
			  					<input type="text" name="total[]" id="total<?php echo $x; ?>" value="<?php echo number_format($netPay,2); ?>" autocomplete="off" class="form-control" disabled="true" />			  					
			  					<input type="hidden" name="totalValue[]" id="totalValue<?php echo $x; ?>" value="<?php echo $netPay; ?>" autocomplete="off" class="form-control" />			  					
			  				</td>
							
							
							
							<td>			  					
			  					<input type="text" name="total[]" id="total<?php echo $x; ?>" value="<?php echo number_format($taxableAmount,2); ?>" autocomplete="off" class="form-control" disabled="true" />			  					
			  					<input type="hidden" name="totalValue[]" id="totalValue<?php echo $x; ?>" value="<?php echo $taxableAmount; ?>" autocomplete="off" class="form-control" />			  					
			  				</td>
							
							
							<td>		  					
			  					<input type="text" name="total[]" id="total<?php echo $x; ?>" value="<?php echo number_format($paye,2); ?>" autocomplete="off" class="form-control" disabled="true" />			  					
			  					<input type="hidden" name="totalValue[]" id="totalValue<?php echo $x; ?>" value="<?php echo $paye; ?>" autocomplete="off" class="form-control" />			  					
			  				</td>
							
							<td>	  					
			  					<input type="text" name="total[]" id="total<?php echo $x; ?>" value="<?php echo number_format($EmployeeHeslbContri,2); ?>" autocomplete="off" class="form-control" disabled="true" />			  					
			  					<input type="hidden" name="totalValue[]" id="totalValue<?php echo $x; ?>" value="<?php echo $EmployeeHeslbContri; ?>" autocomplete="off" class="form-control" />			  					
			  				</td>
							
							<td>			  					
			  					<input type="text" name="total[]" id="total<?php echo $x; ?>" value="<?php echo number_format($netPay,2); ?>" autocomplete="off" class="form-control" disabled="true" />			  					
			  					<input type="hidden" name="totalValue[]" id="totalValue<?php echo $x; ?>" value="<?php echo $netPay; ?>" autocomplete="off" class="form-control" />			  					
			  				</td>
							
						
			  			</tr>
		  			<?php
		  			//$arrayNumber++;
					//$no++;
			  		//} // /for
					$arrayNumber++;
		  			$x++;
			  		} // /for
			  		?>
			  	</tbody>			  	
			  </table>
			  
			  <div class="col-md-6">
			  
			       <div class="form-group">
				    <div class="col-sm-6">
				      <!--<button type="button" class="btn btn-default" onclick="addRow()" id="addRowBtn" data-loading-text="Loading..."> <i class="glyphicon glyphicon-plus-sign"></i> Add Row </button>-->
				    </div>
				  </div> <!--/form-group-->	
				  
				 </br>
				 
			  	<div class="form-group">
				    <label for="subTotal" class="col-sm-3 control-label">Total Employees Basic Salaries</label>
				    <div class="col-sm-9">
				      <input type="text" class="form-control" id="subTotal" name="subTotal"  disabled="true" />
				      <input type="hidden" class="form-control" id="subTotalValue"  name="subTotalValue" />
				    </div>
				  </div> <!--/form-group-->	
				  
				    
	  		  
			  </div> <!--/col-md-6-->
			  
			  
			  </br></br></br></br></br>
			  
			 
			
			  <div class="form-group submitButtonFooter">
			    <div class="col-sm-12">
			      <button type="submit" id="createOrderBtn" data-loading-text="Loading..." class="btn btn-success"><i class="glyphicon glyphicon-ok-sign"></i> Save Changes</button>
                  </br></br>
			      <!--<button type="reset" class="btn btn-default" onclick="resetOrderForm()"><i class="glyphicon glyphicon-erase"></i> Reset</button>-->
			    </div>
			  </div>
			  
			  
			</form>                  
				
                </div>
              </div>
            </div>
          </div>
        </div>
        <!-- /page content -->
		
		
		<?php
		include 'includes/footer.php';
		?>
		
        
      </div>
    </div>
	
	<script>
	// order date picker
		$("#inv_date").datepicker();
		
		// delivery date picker
		$("#due_date").datepicker();
	
	</script>

   <!-- Must -->
    <script src="custom/js/process_payroll.js"></script>
	
    <!-- Must Custom Theme Scripts -->
    <script src="../build/js/custom.min.js"></script>
	
	<!-- file input -->
	<script src="assests/plugins/fileinput/js/plugins/canvas-to-blob.min.js'); ?>" type="text/javascript"></script>	
	<script src="assests/plugins/fileinput/js/plugins/sortable.min.js" type="text/javascript"></script>	
	<script src="assests/plugins/fileinput/js/plugins/purify.min.js" type="text/javascript"></script>
	<script src="assests/plugins/fileinput/js/fileinput.min.js"></script>	


	<!-- DataTables -->
	<script src="assests/plugins/datatables/jquery.dataTables.min.js"></script>

  </body>
</html>



<?php
}
?>