<?php 
error_reporting(0);
require_once("config/configDB.php");
require_once("config/constant.php");

$sql_customer = mysqli_query($conn,"SELECT sh.employee_id,cm.ename FROM employee_advance as sh  join employee_master as cm on cm.id=sh.employee_id WHERE cm.isdelete='1' and sh.status='' GROUP BY sh.employee_id order by cm.ename asc");

$row_customer = '';




$tripfromDate=$_POST['fromDate'];
				$triptoDate=$_POST['toDate'];
				$ename=$_POST['ename'];
				


?>
<!DOCTYPE html>
<html>
<head>
    <title>Emp.Paymen Report</title>
    <?php require 'header.php' ?>
    <link href = "https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css"
         rel = "stylesheet">
<script >
var tableToExcel = (function() {
  var uri = 'data:application/vnd.ms-excel;base64,'
    , template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>'
    , base64 = function(s) { return window.btoa(unescape(encodeURIComponent(s))) }
    , format = function(s, c) { return s.replace(/{(\w+)}/g, function(m, p) { return c[p]; }) }
  return function(table, name) {
    if (!table.nodeType) table = document.getElementById(table)
    var ctx = {worksheet: name || 'Worksheet', table: table.innerHTML}
    window.location.href = uri + base64(format(template, ctx))
  }
})()

</script>
</head>
<body>
    <?php require 'menu.php' ?>


    <div class="container text-center" id="saleStock">
  
  <form class="form-inline" method="post" action="emp_salary_payment.php">
    
    <div class="form-group">
      <label for="email">From Date:</label>
      <input type="date" class="form-control" id="fromDate" name="fromDate" autocomplete="off">
    </div>
    <div class="form-group">
      <label for="pwd">To Date</label>
      <input type="date" class="form-control" id="toDate" name="toDate" autocomplete="off">
    </div>


    <div class="form-group">
    <label for="">Employee </label>

        <select class="form-control  customerStock" name="ename">
        <option value=""> Select the Employee </option>
        <?php
		$emp=mysqli_query($conn,"select * from employee_payment where status='' group by ecode");
        while($rowe = mysqli_fetch_array($emp)){
        ?>
        <option value="<?php echo $rowe['ecode'] ?>" > <?php echo $rowe['employee_name']; ?> </option>
        <?php
        }
        ?>
        </select>
    </div>
    

    <button type="submit" class="btn btn-primary btn-md datewise-submit-sale">Submit</button>

    <button type="button" class="btn btn-info btn-md datewise-submit-sale" onClick="tableToExcel('a', 'W3C Example Table')">Excel</button>
    
  </form>
  
</div>



    <div class="container col-sm-12">
    &nbsp;
    </div>



<div class="container col-sm-12">
<div id="a">
<table id="salestockDashboard" class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">
        <thead>
            <tr>
                <th>Emp.Name</th>
                <th>Date</th>
                <th>Salary paid Date</th>
               <th>Prevoius&nbsp;Pending&nbsp;Salary</th>
               <th>Total&nbsp;Salary</th>
               
                <th>Paid&nbsp;Amount</th>
                 <th>Remarks</th>
            </tr>
        </thead>
        
        <?php
				
				
				$sql = "SELECT employee_name, given_date,fromdate,todate, paidamount,ecode, givenby, refno,paytype,id,pending_salary,total_salary,remarks FROM employee_payment WHERE 1=1 and isdelete=1 and status='' ";
				
				if($tripfromDate !=''  && $triptoDate !='' &&  $ename ==''  ) {
	 	$sql.=" and given_date BETWEEN '".$tripfromDate."' AND '".$triptoDate."' ORDER BY given_date ASC ";

	 }
	 

	 
	 else if($tripfromDate !=''  && $triptoDate !=''   && $ename !='' ) {
		$sql.=" and ecode='".$ename."'   and given_date BETWEEN '".$tripfromDate."' AND '".$triptoDate."' ORDER BY given_date ASC ";

   	 }
	 
	 
	 
	 else if($tripfromDate ==''  && $triptoDate ==''   && $ename !=''  )  {
		$sql.="  and ecode='".$ename."'   ORDER BY given_date ASC ";

	}
	 
	 //echo $sql;
	 
				?>
        
        <tbody>
            <?php
			$query=mysqli_query($conn, $sql) or die("brandgriddata.php: get brand Data step 1".$sql);
			$total_price = 0;
			$total_qty = 0;
			while($row=mysqli_fetch_array($query))
{
	$deliver_date=$row["given_date"];
$date=date_create($deliver_date);
$sale_date2=date_format($date,"d-m-Y");
				
				?>
			<tr>
            <td><?php echo $row["employee_name"];?></td>
            <td><?php echo $sale_date2;?></td>
			<td><?php echo $row["fromdate"]." To ".$row["todate"];?></td>
            
           <td align="right"><?php echo number_format((float)$row["pending_salary"], 2, '.', '');?></td>
            <td align="right"><?php echo number_format((float)$row["total_salary"], 2, '.', '');?></td>
             <td align="right"><?php echo number_format((float)$row["paidamount"], 2, '.', '');?></td>
           <td><?php echo $row["remarks"];?></td>
           
			</tr>
            <?php
			
			$total_price  += $row["paidamount"];
			
}


?>
       <tr>
           
          
           
			<td  align="right" colspan="5"><strong>Total Amount</strong></td>
            <td align="right"><strong><?php echo number_format(round($total_price), 2, '.', '');?></strong></td>
			</tr>             
           
        </tbody>
       
    </table>
    </div>
</div>



    <?php require 'footer.php' ?>

    <script type="text/javascript">var base_url = "<?= $base_url ?>";</script>
  
    <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.9.2/jquery-ui.min.js"></script>

    
</body>
</html>