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






$tripfromDate=$_POST['fromDate'];
				$triptoDate=$_POST['toDate'];
				$ename=$_POST['ename'];
				
$emp_code=mysqli_query($conn,"select * from employee_master  where id='$ename'");
        while($rowe_code = mysqli_fetch_array($emp_code)){
		$ecode=$rowe_code['ecode'];
		}

?>
<!DOCTYPE html>
<html>
<head>
    <title>Emp.Payment  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="salaryreport.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_master  order by ename");
        while($rowe = mysqli_fetch_array($emp)){
        ?>
        <option value="<?php echo $rowe['id'] ?>" > <?php echo $rowe['ename']; ?> </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 id="a">
<div class="container col-sm-12">

<table id="salestockDashboard" class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">
<caption>Employee Advance</caption>
        <thead>
            <tr>
                <th>Adv No</th>
                <th>Date</th>
                <th>Employee</th>
               
                <th>Amount</th>
                 <th>Remarks</th>
            </tr>
        </thead>
        
        <?php
				


	 
	  if($tripfromDate !=''  && $triptoDate !=''   && $ename !='' ) {
		$sql="SELECT sh.advance_no, sh.advance_date, sh.employee_id, sh.advance_amount, sh.remarks, sh.id,em.ename FROM employee_advance as sh LEFT JOIN employee_master as em on em.id = sh.employee_id WHERE 1=1 and  sh.status='' and sh.employee_id='".$ename."'   and advance_date BETWEEN '".$tripfromDate."' AND '".$triptoDate."' ORDER BY sh.advance_date ASC ";

   	 }
	 
	// echo $sql;
	 
				?>
        
        <tbody>
            <?php
			$query=mysqli_query($conn, $sql) ;
			$total_price = 0;
			$total_qty = 0;
			while($row=mysqli_fetch_array($query))
{
	$deliver_date=$row["advance_date"];
$date=date_create($deliver_date);
$sale_date2=date_format($date,"d-m-Y");
				
				?>
			<tr>
            <td><?php echo $row["advance_no"];?></td>
            <td><?php echo $sale_date2;?></td>
			<td><?php echo $row["ename"];?></td>
            
           <td align="right"><?php echo number_format((float)$row["advance_amount"], 2, '.', '');?></td>
           <td><?php echo $row["remarks"];?></td>
           
			</tr>
            <?php
			
			$total_price  += $row["advance_amount"];
			
}


?>
       <tr>
           
          
           
			<td  align="right" colspan="3"><strong>Total Amount</strong></td>
            <td align="right"><strong><?php echo number_format(round($total_price), 2, '.', '');?></strong></td>
			</tr>             
           
        </tbody>
       
    </table>
    </div>
    
    <!--Advance-->
    
    <div class="container col-sm-12">

<table id="salestockDashboard" class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">
        <thead>
        <caption><strong>Advance&nbsp;Collection</strong></caption>
            <tr>
                <th>Collection No</th>
                <th>Date</th>
                <th>Employee</th>
               
               
                <th>Collected Amt</th>
                 <th>Remarks</th>
            </tr>
        </thead>
        
        <?php
				
				
	
	 

	 
	  if($tripfromDate !=''  && $triptoDate !=''   && $ename !='' ) {
		$sql_collection="SELECT sh.advance_no, sh.advance_date, sh.employee_id,sh.advance_collection_amount, sh.advance_amount, sh.remarks, sh.id,em.ename FROM employee_advance_collection as sh LEFT JOIN employee_master as em on em.id = sh.employee_id WHERE 1=1 and  sh.status='' and sh.employee_id='".$ename."'   and advance_date BETWEEN '".$tripfromDate."' AND '".$triptoDate."' ORDER BY sh.advance_date ASC ";

   	 }
	 
	 
	 
				?>
        
        <tbody>
            <?php
			$query_collection=mysqli_query($conn, $sql_collection) ;
			$total_collection = 0;
			
			while($row_colection=mysqli_fetch_array($query_collection))
{
	$deliver_date=$row_colection["advance_date"];
$date_collection=date_create($deliver_date);
$sale_date_collection=date_format($date_collection,"d-m-Y");
				
				?>
			<tr>
            <td><?php echo $row_colection["advance_no"];?></td>
            <td><?php echo $sale_date_collection;?></td>
			<td><?php echo $row_colection["ename"];?></td>
            
           
           <td align="right"><?php echo number_format((float)$row_colection["advance_collection_amount"], 2, '.', '');?></td>
           <td><?php echo $row_colection["remarks"];?></td>
           
			</tr>
            <?php
			
			$total_collection  += $row_colection["advance_collection_amount"];
			
}


?>
       <tr>
           
          
           
			<td  align="right" colspan="3"><strong>Total Collected Amount</strong></td>
            <td align="right"><strong><?php echo number_format(round($total_collection), 2, '.', '');?></strong></td>
			</tr>             
           
        </tbody>
       
    </table>
    
</div>
<!--Attentance-->
<div class="container col-sm-12">&nbsp;</div>

<div class="container col-sm-12">

<table class="table table-responsive table-striped table-bordered dt-responsive nowrap" id="accLabourDetailsAdd" cellspacing="0">
          <thead>
          <caption>Attendance&nbsp;Salary</caption>
            <tr>
              
              <th>Total&nbsp;Working&nbsp;Shift </th>
              <th>Extra Working Hours</th>
               <th>Salary/Shift</th> 
              <th>Salary/Extra Hour</th>
              <th>Salary</th>
            </tr>
          </thead>
          <tbody>
          <?php
		  
		  if($tripfromDate !=''  && $triptoDate !=''   && $ename !='' ) { 

$sql1 ="SELECT att.enameid,sum(att.shifttype) as shifttype,sum(att.extraworkinghrs) as extraworkinghrs,emp.shiftworkamt,emp.extrahoursamt FROM employee_attendance_dtl as att inner join employee_master as emp on att.enameid=emp.id WHERE att.enameid='$ename' and invoicedate between '".$tripfromDate."' AND '".$triptoDate."'  and att.isdelete=1   ";


}
//echo $sql1;

$Query_Adv  = mysqli_query($conn,$sql1); 

		  
            $trlength = 0;
            //lm.ename,lad.shifttype,lad.extraworkinghrs,lad.shiftworkamt,lad.extrahoursamt,lad.enameid
            while($drow = mysqli_fetch_array($Query_Adv))
            {
			
			$totalshifsalary=$drow['shifttype']*$drow['shiftworkamt'];
			$totalotsalary=$drow['extraworkinghrs']*$drow['extrahoursamt'];
			
			$totalsalary=$totalshifsalary+$totalotsalary;
			
              ?>
              <tr>
              
              <td><?php echo $drow['shifttype']; ?></td>
              <td><?php echo $drow['extraworkinghrs']; ?></td>
              <td><?php echo $drow['shiftworkamt']; ?></td>
              <td><?php echo $drow['extrahoursamt']; ?></td>
              <td align="right"><strong><?php echo number_format($totalshifsalary,2,'.','');?></strong></td>
              
              
              </tr>
              
              
              
              <?php
                   
            }
          ?>
          </tbody>
        </table>


</div>

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

<div class="container col-sm-12">

<table id="salestockDashboard" class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">
        <thead>
        <caption>Paid Salary</caption>
            <tr>
                <th>Emp.Name</th>
                <th>Date</th>
                <th>Salary paid Date</th>
               
               <th>Total&nbsp;Salary</th>
               
                <th>Paid&nbsp;Salary</th>
                <th>Deducted Adv</th>
                <th>In Hand </th>
                 <th>Remarks</th>
            </tr>
        </thead>
        
        <?php
				


	 
	  if($tripfromDate !=''  && $triptoDate !=''   && $ename !='' ) {
		$sql_salary="SELECT employee_name, given_date,fromdate,todate, paidamount,ecode, givenby, refno,paytype,id,pending_salary,total_salary,remarks,deducted_amt,cash_hand FROM employee_payment WHERE 1=1 and isdelete=1 and status='' and ecode='".$ecode."'   and given_date BETWEEN '".$tripfromDate."' AND '".$triptoDate."' ORDER BY given_date ASC ";

   	 }
	 
	
	// echo $sql_salary;
	 
				?>
        
        <tbody>
            <?php
			$query_salary=mysqli_query($conn, $sql_salary);
			$total_recieved_salary = 0;
		
			while($row_salary=mysqli_fetch_array($query_salary))
{
	$salary_date=$row_salary["given_date"];
$date_salary=date_create($salary_date);
$salery_date2=date_format($date_salary,"d-m-Y");
				
				?>
			<tr>
            <td><?php echo $row_salary["employee_name"];?></td>
            <td><?php echo $salery_date2;?></td>
			<td><?php echo $row_salary["fromdate"]." To ".$row_salary["todate"];?></td>
            
          
            <td align="right"><?php echo number_format((float)$row_salary["total_salary"], 2, '.', '');?></td>
             <td align="right"><?php echo number_format((float)$row_salary["paidamount"], 2, '.', '');?></td>
             
             <td align="right"><?php echo number_format((float)$row_salary["deducted_amt"], 2, '.', '');?></td>
             <td align="right"><?php echo number_format((float)$row_salary["cash_hand"], 2, '.', '');?></td>
             
           <td><?php echo $row["remarks"];?></td>
           
			</tr>
            <?php
			
			$total_recieved_salary  += $row_salary["paidamount"];
			
}


?>
       <tr>
           
          
           
			<td  align="right" colspan="4"><strong>Total Amount</strong></td>
            <td align="right"><strong><?php echo number_format(round($total_recieved_salary), 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>