<?php
include('../headertop.php');
//include('../datepicker.php');
include('../db.php');

$disp = '';
$pagetitle = 'View Salary';

if(!isset($_POST['viewsalarysubmit']))
{
echo '<meta http-equiv="refresh" content="0;URL=viewsalary.php">';
exit;
}

$salary_month = $_POST['salary_month'];
$salary_year = $_POST['salary_year'];

if(empty($salary_month) or empty($salary_year))
{
echo '<meta http-equiv="refresh" content="0;URL=addsalary.php?sm=Please select salary month and year">';
//echo $salary_month.','.$salary_year.','.$doe;
exit;
}

$q = "select * from employee";
$res = mysqli_query($dbcon,$q);
if(mysqli_num_rows($res)<1)
{
$sm = 'No employees found';
echo '<meta http-equiv="refresh" content="0;URL=addsalary.php?sm='.$sm.'">';
}

if(isset($_REQUEST['sm']))
$disp .= '<div class="col-md-7"><div class="smdiv">'.$_REQUEST['sm'].'</div></div>';
else
$disp .= '<div class="col-md-9"><div class="smdiv">View Employee Salary for Month: '.$salary_month.', '.$salary_year.'</div></div>
';

 
$disp .= '
<div class="row">
                <div class="col-md-12">
                    <!-- Advanced Tables -->
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            Viewing Employee Salaries
                        </div>
                        <div class="panel-body">
                            <div class="table-responsive">
                                <table class="table table-striped table-bordered table-hover" id="dataTables-example">
                                    <thead>
                                        <tr>
											<th>Employee Name</th>
                                            <th>Father/Husband Name</th>
                                            <th>Phone</th>
											<th>Monthly Salary</th>
											<th>Amount Paid</th>
											<th>Payment Date</th>
											<th></th>
                                            
                                        </tr>
                                    </thead>
                                    <tbody>';
									
$dispp = '
<div class="row">
                <div class="col-md-12">
                    <!-- Advanced Tables -->
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            Viewing Employee Salaries
                        </div>
                        <div class="panel-body">
                            <div class="table-responsive">
                                <table class="table table-striped table-bordered table-hover" id="dataTables-example">
                                    <thead>
                                        <tr>
											<th>Employee Name</th>
                                            <th>Father/Husband Name</th>
                                            <th>Phone</th>
											<th>Monthly Salary</th>
											<th>Amount Paid</th>
											<th>Payment Date</th>
											
                                            
                                        </tr>
                                    </thead>
                                    <tbody>';								
									
  while($row=mysqli_fetch_array($res))
{              
$qsal = "select * from salary where emp_id='".$row['id']."' and salary_month='$salary_month' and salary_year='$salary_year'";
$rsal = mysqli_query($dbcon,$qsal) or die(mysqli_error($dbcon));
while($rwsal = mysqli_fetch_array($rsal))
                    {
   $disp .='<tr class="odd gradeX">
                                             <td>'.$row['name'].'</td>
                                            <td>'.$row['fname'].'</td>
											<td class="center">'.$row['mobile'].'</td>
                                            <td>'.$row['salary'].'</td>
                                            <td class="center">'.$rwsal['amount'].'</td>
                                            <td class="center">'.$rwsal['payment_date'].'</td>
											
											<td><a href="editexpenses3.php?exp_id='.$rwsal['exp_id'].'"><img src="../assets/img/edit.png"></a> &nbsp; <a href="deleteexpenses.php?exp_id='.$rwsal['exp_id'].'"><img src="../assets/img/delete.png"></a> &nbsp;</td>
                                        </tr>
                                       ';
									   
  $dispp .='<tr class="odd gradeX">
                                             <td>'.$row['name'].'</td>
                                            <td>'.$row['fname'].'</td>
											<td class="center">'.$row['mobile'].'</td>
                                            <td>'.$row['salary'].'</td>
                                            <td class="center">'.$rwsal['amount'].'</td>
                                            <td class="center">'.$rwsal['payment_date'].'</td>
											
											
                                        </tr>
                                       '; 
		}//end of inner while  
} //end of while

$disp .='            </tbody>
                                </table>
                            </div>
                            
                        </div>
                    </div>
                    <!--End Advanced Tables -->
					
                </div>
            </div>
			
			 ';
		
		$disp2 = '<form method="post" action="../printtemplate.php">
		<input type="hidden" name="disp" value="'.htmlspecialchars($dispp).'"><input type="submit" value="Print">
		</form>';
		
		$disp .= $disp2;
			
			include('../header.php');
			?>
		
     <script>
            $(document).ready(function () {
                $('#dataTables-example').dataTable();
            });
    </script>
    
 
          <?php
		 
			
			include('../template.php');
               