<?php 

require_once("config/configDB.php"); 
require "userPermission.php";
//require_once("config/constant.php");
error_reporting(0);
$sql_supplier = mysqli_query($conn,"SELECT sh.contractor,cm.sname FROM explosive_utiliz_hdr as sh  join supplier_master as cm on cm.id=sh.contractor WHERE cm.isdelete='1' GROUP BY sh.contractor ");

$row_supplier = '';



$fromdate=$_POST['fromDate'];
$todate=$_POST['toDate'];
$supplierName=$_POST['supplierName'];


//echo $fromdate;

?>
<!DOCTYPE html>
<html>
<head>
    <title>Stock 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" action="elgi_report.php" method="post">
    
    <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="pwd">Please Select the supplier </label>
      <select class="form-control  supplierStock" name="supplierName">
        <option value=""> Select the supplier </option>
        <?php
        while($row = mysqli_fetch_array($sql_supplier)){
        ?>
        <option value="<?php echo $row['contractor'] ?>" > <?php echo $row['sname']; ?> </option>
        <?php
        }
        ?>
        </select>
    </div>
   
    

  

    <div class="form-group">
    

    <button type="submit" class="btn btn-primary btn-md datewise-submit-sale">Submit</button>&nbsp;
    
   <button type="button" class="btn btn-primary" onClick="tableToExcel('a', 'W3C Example Table')">Download</button> 

</div>
   


  </form>  
</div>
<br>

<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>S.No</th>
             <th>Ref.No</th>
            <th>Process&nbsp;Date</th>
            <th>Supplier Name</th>
            <th>Process&nbsp;Type</th>
                <th>Starting Hrs</th>
                <th>Closing Hrs</th>
               <th>Total Hrs</th>
                 <th>Starting Unit</th>
                <th>Closing Unit</th>
               <th>Total Unit</th>
               <th>Holes</th>
               <th>Total&nbsp;Holes</th>
               <th>Total&nbsp;Ft</th>
               <th>Explosives</th>
               <th>Cost/Ft</th>
               <!--<th>No.Of.Labour</th>-->
                <th>Total.Amt</th>
               
            </tr>
        </thead>
<tbody>

<?php

$sql="select id,utilize_code,utilizedate,contractor,contractor_name,process_type,starting_hrs,closing_hrs,starting_unit,closing_unit,running_hrs,running_unit,one,two,three,four,six,eight,hole,totalfeet,labour,cost_feet,total_cost,remark from explosive_utiliz_hdr where status='' and process_type='ELGI'";

if($fromdate !=''  && $todate !='' && $supplierName ==''  ) {
	 	$sql.=" and utilizedate BETWEEN '".$fromdate."' AND '".$todate."' ORDER BY utilizedate ASC ";

	 }
	 
	 else if($fromdate !=''  && $todate !='' && $supplierName !=''  ) {
	 	$sql.=" and utilizedate BETWEEN '".$fromdate."' AND '".$todate."' and contractor='".$supplierName."' ORDER BY utilizedate ASC ";

	 }
	 
	 else if($fromdate ==''  && $todate =='' && $supplierName !=''  ) {
	 	$sql.=" and contractor='".$supplierName."' ORDER BY utilizedate ASC ";

	 }

//echo $sql;
$querry=mysqli_query( $conn, $sql );

$sno=0;
$amt=0;
while($rowu=mysqli_fetch_array($querry))
{
$hid=$rowu['id'];
?>
<tr>
<td><?php echo ++$sno;?></td>
<td><?php echo $rowu['utilize_code'];?> </td>
<td><?php echo $rowu['utilizedate'];?> </td>
<td><?php echo $rowu['contractor_name'];?> </td>
<td><?php echo $rowu['process_type'];?> </td>
<td><?php echo $rowu['starting_hrs'];?> </td>
<td><?php echo $rowu['closing_hrs'];?> </td>
<td><?php echo $rowu['running_hrs'];?> </td>
<td><?php echo $rowu['starting_unit'];?> </td>
<td><?php echo $rowu['closing_unit'];?> </td>
<td><?php echo $rowu['running_unit'];?> </td>
<td>
1Ft-<?php echo $rowu['one'];?><br>
2Ft-<?php echo $rowu['two'];?><br>
3Ft-<?php echo $rowu['three'];?><br>
4Ft-<?php echo $rowu['four'];?><br>
6Ft-<?php echo $rowu['six'];?><br>
8Ft-<?php echo $rowu['eight'];?><br>

 </td>
<td><?php echo $rowu['hole'];?> </td>
<td><?php echo $rowu['totalfeet'];?> </td>
<td>
<?php

$sql_dtl="select * from explosive_utiliz_dtl where hdr_id='$hid' and status=''";

$querry_dtl=mysqli_query( $conn, $sql_dtl );

while($rowdtl=mysqli_fetch_array($querry_dtl))
{
?>
<?php echo $rowdtl['explosivename'];?>-<?php echo $rowdtl['qty'];?>,

<?php
}
?>
 </td>
<!--<td><?php echo $rowu['labour'];?> </td>-->
<td><?php echo $rowu['cost_feet'];?> </td>
<td align="right"><?php echo number_format($rowu['total_cost'],2,'.','');?> </td>


</tr>

<?php

$amt=$amt+$rowu['total_cost'];

}
?>
<tr>

<td colspan="16" align="right"> <strong>Total&nbsp;Amount</strong></td>
<td align="right"><strong><?php echo number_format($amt,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>