<?php include('parent/callMe.php');?>
<?php include('Sessioncheck.php');?>
<?php   


$sessionid;
$PaidDateSession;
    
    if($_GET["session"]!=NULL ){
      $sessionid= $_GET["session"];
      $PaidDateSession= $yr[0];
    }
    else{
      $sessionid= $_SESSION['current_session'];
      $PaidDateSession= date("Y");
    }

$default;
    
    if($_GET["month"]!=NULL ){
      $default= $_GET["month"];   
  

    }
    else{
      $default= date("m");
     
    }
  

  $m->where("session_id", $_REQUEST['session']);
  $session=$m->get("edu_session_config");


  // getting branch details

  $m->where("branch_id", $_SESSION['branch']);
  $branch=$m->get("edu_branch_config");

    
  $m->where("Month_Id", $_REQUEST['month']);
  $month=$m->get("eduportal_month_config");



$branch=$_SESSION['branch'];
 


  if (!isset($_REQUEST['designation']) ) {
    
// $m->where("status", '0');
 $m->where("branch_id", $_SESSION['branch']);
 $m->orderBy("user_id", 'desc');
 $WorkAssignListings = $m->get("edu_user_config");

  } elseif ($_REQUEST['designation']=='All') {

 //$m->where("status", '0');
 $m->where("branch_id", $_SESSION['branch']);
 $m->orderBy("user_id", 'desc');
 $WorkAssignListings = $m->get("edu_user_config");

 
} else {

 //$m->where("status", '0');
 $m->where("branch_id", $_SESSION['branch']);
 //$m->where("designation_id!=14");
 $m->where("designation_id", $_REQUEST['designation']);
 $m->orderBy("user_id", 'desc');
 $WorkAssignListings = $m->get("edu_user_config");

}



 ?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Print PayRoll Sheet</title>
<link rel="icon" type="image/png" href="img/favicon.png" sizes="32x32" />
<script type="text/javascript">
// window.print();
</script>
<style type="text/css">

tr th {border-top:1px solid gray;border-left:1px solid black;border-bottom:1px solid black;text-align:center;background-color:lightgray;font-size:14px; padding:3px;}
tr td {border-bottom:1px solid gray;border-left:1px solid black;font-size:14px; padding:3px;}
  
.border{border:1px solid black;}
.center{text-align:center;}
.alignment{padding-left:1%;text-align:left;}
.borderTop{
  border-top: none;
}
</style>
</head>
<body style="font-size:12px;">





<br>

<div style="text-align:center;font-size:24px;font-weight:bold;">Employee's Monthly Salary Reports

 </div>

<hr style="width:100%;">
<div style="width:33%; float:left;font-size:18px; margin-left:10px; "> <b> Month:</b> <?php echo $month[0]['Month_Name'];?> </div>


<br><br>
   
    <table style="width:100%;font-size:12px;" cellspacing="0">
          
          <thead>
            <tr>
                <th width="3%" class="center">S.No</th>
                <th width="12%" class="center">Employee Name</th>
                <th width="8%" class="center"> Designation </th>
                <th width="8%" class="center"> Pre Balance </th> 
                <th width="8%" class="center"> Advance </th> 
                <th width="8%" class="center"> Basic Salary </th>  
                <th width="12%" class="center"> Total Allowance  </th>  
                <th width="9%" class="center"> Total Deduction</th>  
                <th width="5%" class="center"> Net Payable</th>  
                <th width="5%" class="center">Paid Date </th>  
                <th width="8%" class="center">Paid Amount</th>    
                <th width="8%" class="center" style="border-right:1px solid black;"> Remaining </th>                                   
            </tr>
        </thead>
        <tbody>
   
<?php 
   $count=1; 
   $total_net=0;
   $total_paid=0;

      foreach($WorkAssignListings as $WorkAssignListVal)
      { 
//echo $WorkAssignListVal['user_id']."<br>";
        $m->where("designation_id", $WorkAssignListVal['designation_id']);
        $designation=$m->get("eduportal_designation_config");
        $m->where("department_id", $WorkAssignListVal['department_id']);
        $department=$m->get("eduportal_hrm_department_config");

        $m->where("branch_id", $_SESSION['branch']);
        $m->where("session_id",$sessionid);
        $m->where("user_id", $WorkAssignListVal['user_id']);
        $m->where("month_id", $_GET['month']);
        $payrolldata=$m->get("employee_payroll");
//print_r($payrolldata);
      
         /*$userID=$WorkAssignListVal['user_id'];
         $branch=$_SESSION['branch'];
         $paidDate=$PaidDateSession."-".$default;
         $sessionidid=$_SESSION['current_session'];
   $qr="SELECT * FROM employee_payroll where branch_id ='$branch' and session_id='$sessionidid' and user_id='$userID' and paid_date like '$paidDate%'";
   //echo "$qr";
   $payrolldata=$m->query($qr);*/


          if ($payrolldata[0]['user_id']=="") {
          
          continue;
        }
        

        $totalDeduction=$payrolldata[0]['security_deductions']+$payrolldata[0]['other_deductions']+$payrolldata[0]['leave_deduction']+$payrolldata[0]['advance_deductions'];

        $totalAllowances=$payrolldata[0]['leave_encashment']+$payrolldata[0]['travelling_allowance']+$payrolldata[0]['reimbursement']+$payrolldata[0]['other_allowances'];

        $netPayble=($payrolldata[0]['basic_salary']+$payrolldata[0]['paid_again_amount']+$totalAllowances+$payrolldata[0]['previous_balance'])-($totalDeduction);

        $remaning =$netPayble - $payrolldata[0]['paid_amount']-$payrolldata[0]['paid_again_amount']-$payrolldata[0]['paid_again_salary_amount'];

$total_net=$total_net+$netPayble;
$total_paid=$total_paid+$payrolldata[0]['paid_amount']+$payrolldata[0]['paid_again_amount']+$payrolldata[0]['paid_again_salary_amount'];
$previous+=$payrolldata[0]['previous_balance'];
$paid_again_amount+=$payrolldata[0]['paid_again_amount'];
$basic+=$payrolldata[0]['basic_salary'];
$Tallowance+=$payrolldata[0]['leave_encashment']+$payrolldata[0]['travelling_allowance']+$payrolldata[0]['reimbursement']+$payrolldata[0]['other_allowances'];
$Tdeduction+=$totalDeduction;


   ?>
   			<tr> 
      <td style="text-align:center;"> <?php echo $count; $count++; ?>  </td>    		   
      <td style="text-align:center;"> <?php echo $WorkAssignListVal['user_fname'];?> </td>
      <td style="text-align:center;"> <?php echo $designation[0]['designation_name'];?> </td>
      <td style="text-align:center;"> <?php echo $payrolldata[0]['previous_balance'];?></td>
      <td style="text-align:center;"> <?php echo $payrolldata[0]['paid_again_amount'];?></td>
      <td style="text-align:center;"> <?php echo $payrolldata[0]['basic_salary'];?></td>
      <td style="text-align:center;"> <?php echo $totalAllowances;?> </td>
      <td style="text-align:center;"> <?php echo $totalDeduction;?> </td>
      <td style="text-align:center;"> <?php echo $netPayble;?> </td>
      <td style="text-align:center;"> <?php echo $payrolldata[0]['paid_date'];?> </td>
      <td style="text-align:center;"> <?php echo $payrolldata[0]['paid_amount']+$payrolldata[0]['paid_again_amount']+$payrolldata[0]['paid_again_salary_amount'];?> </td>
      <td style="border-right: 1px solid black;text-align:center;"> <?php echo $remaning ;?> </td>
                                                                  
      </tr>

       <?php } ?>
       <tr>
        <th colspan="3" class="center borderTop">Total</th>
        <th class="center borderTop"><?php echo $previous; ?></th>
        <th class="center borderTop"><?php echo $paid_again_amount; ?></th>
        <th class="center borderTop"><?php echo $basic; ?></th>
        <th class="center borderTop"><?php echo $Tallowance; ?></th>
        <th class="center borderTop"><?php echo $Tdeduction; ?></th>
        <th colspan="2" class="borderTop"><?php echo $total_net; ?></th>
        <th class="center borderTop"><?php echo $total_paid; ?></th> 
        <th class="center borderTop" style="border-right: 1px solid black;"><?php echo $total_net- $total_paid;?></th> 

       </tr>
 
             
        </tbody>
        
    </table><br>
     
      
      

</body>
</html>
