<?php 
error_reporting(0);
require_once("config/configDB.php"); 
require "userPermission.php";
require 'financial_year_calculation.php';



$tripfromDate=$_POST['fromDate'];
				$triptoDate=$_POST['toDate'];
				$ename=$_POST['ename'];
				$customer=$_POST['customer'];
				$vno=$_POST['vname'];
				$product=$_POST['product'];


?>
<!DOCTYPE html>
<html>
<head>
    <title>Explosive Utilize 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="explosive_utilize_report.php">
    
    <div class="form-group">
      <label for="email">From Date:</label>
      <input type="text" class="form-control" id="fromDate" name="fromDate" autocomplete="off">
    </div>
    <div class="form-group">
      <label for="pwd">To Date</label>
      <input type="text" class="form-control" id="toDate" name="toDate" autocomplete="off">
    </div>


    
    
    
    <br><br>
    
    

    <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>


<br><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>Date</th>
                    <th>Contractor</th> 
                    <th>Total Hole</th>                    
                   <th>Total Feet</th>
                    <th>Total Cost</th>
                                       
                    <th>Utilize</th>
               
                <!-- <th>Action</th> -->
            </tr>
        </thead>
        
        <?php
				
				
				//$sql = "SELECT t1.utilize_code, t1.utilizedate,t1.hole,t1.contractor,t1.total_cost, t1.totalfeet, t1.labour ,t1.id,sum(t2.qty) as qty ,t2.explosivename FROM explosive_utiliz as t1 inner join explosive_utiliz_dtl as t2 on t1.id=t2.hdr_id WHERE 1=1 and t1.isdelete=1  ";
				
				
				
				if($tripfromDate !=''  && $triptoDate !=''  ) {
	 	$sql="SELECT t1.utilize_code, t1.utilizedate,t1.hole,t1.contractor,t1.total_cost, t1.totalfeet, t1.labour ,t1.id FROM explosive_utiliz as t1 WHERE 1=1 and t1.isdelete=1 and utilizedate BETWEEN '".$tripfromDate."' AND '".$triptoDate."' group by t1.utilizedate ";

	 }
	 else
	 {
		 
		 $sql = "SELECT t1.utilize_code, t1.utilizedate,t1.hole,t1.contractor,t1.total_cost, t1.totalfeet, t1.labour ,t1.id FROM explosive_utiliz as t1 WHERE 1=1 and t1.isdelete=1 group by t1.utilizedate ";
	 }
	 
	
	
	 
				?>
        
        <tbody>
            <?php
			$query=mysqli_query($conn, $sql) or die("brandgriddata.php: get brand Data step 1".$sql);
			
			$sno=0;
			while($row=mysqli_fetch_array($query))
{
	$deliver_date=$row["utilizedate"];
$date=date_create($deliver_date);
$sale_date2=date_format($date,"d-m-Y");
				
				?>
			<tr>
            <td><?php echo ++$sno;?></td>
            
            <td><?php echo $sale_date2;?></td>
			<td><?php echo $row["contractor"];?></td>
           
            <td><?php echo $row["hole"];?></td>
           
            <td><?php echo $row["totalfeet"];?></td>
			
			<td><?php echo $row["total_cost"];?></td>
            <td>
           <?php
		   $su=mysqli_query($conn,"select sum(qty) as qty,explosivename from explosive_utiliz_dtl where utilizedate='".$row['utilizedate']."' and flag='1' group by explosivename");
		   while($rowd=mysqli_fetch_array($su))
{
		   ?>
				
                <p><?php echo $rowd['explosivename'];?>-<?php echo $rowd['qty'];?></p>
             <?php
}
?>
            </td>
			
            
            
			</tr>
            <?php
			
			
}


?>
                    
           
        </tbody>
       
    </table>
    </div>
</div>



    <?php require 'footer.php' ?>

    <script type="text/javascript">var base_url = "<?= $base_url ?>";</script>
  
   <script type="text/javascript" src="js/jquery-1.11.3.min.js"></script>

<!-- Include Date Range Picker -->
<script type="text/javascript" src="js/bootstrap-datepicker.min.js"></script>


    <script>
	$(document).ready(function(){
		var date_input=$('input[name="fromDate"]'); //our date input has the name "date"
		var container=$('form >  .datepicker-purchase').length>0 ? $('form > .datepicker-purchase ').parent() : "body";
		date_input.datepicker({
			format: 'yyyy-mm-dd',
			container: container,
			todayHighlight: true,
			autoclose: true,
        });

        
        

	});
	
	
	$(document).ready(function(){
		var date_input=$('input[name="toDate"]'); //our date input has the name "date"
		var container=$('form >  .datepicker-purchase').length>0 ? $('form > .datepicker-purchase ').parent() : "body";
		date_input.datepicker({
			format: 'yyyy-mm-dd',
			container: container,
			todayHighlight: true,
			autoclose: true,
        });

        
        

	});
</script>

</body>
</html>