<?php
error_reporting(0);

?>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="datatable/data.css">
<script src="datatable/data.js" type="text/javascript"></script>
<script src="datatable/table.js" type="text/javascript"></script>
<script src="datatable/datatable.js"></script>
<link rel="stylesheet" href="datatable/data-boot.css">
<link href="javascript/select2.css" rel="stylesheet" >
<script src="javascript/selectt2.js"></script>
<link rel="stylesheet" href="calendar-15/calendar-15/fonts/icomoon/style.css">

<link rel="stylesheet" href="calendar-15/calendar-15/css/rome.css">
<link rel="stylesheet" href="calendar-15/calendar-15/css/style.css">
<!-- <script src = "ajax/loadoutreport1.js"></script>
<script src = "ajax/loadoutreport2.js"></script>
<script src = "ajax/loadoutreport3.js"></script> -->
<script src="js/quotationreport.js"></script>
<style>
    
    #navbar
    {
        flex:15%;
        height:100%; 
        flex-direction:row;
        overflow:auto;
        
    }
    #content
    {
        flex:90%;
        overflow:auto;
        padding-left:5px;
        padding-right:5px;
    }
    #fullbody
    {
        display:flex;
        
         height:100%;         
    }
    label
    {
      font-size:20px;
    }
    .edit
    {
        font-size:18px;
        color:green;
        cursor:pointer;
    }
    .dele
    {
        font-size:18px;
        color:red;
        cursor:pointer;
    }
    .edit:hover
    {
        font-size:20px;
        
    }
    .dele:hover
    {
        font-size:20px;
        color:red;
        cursor:pointer;
        
    }
    td
    {
      
      padding:8px;
     border:1px solid rgba(24, 7, 173); 
      background-color:#FFFFE0;
      color:black;
    }
    th
    {
      background-color:rgba(24, 7, 173);
      text-align:center;
      padding:8px;
     border-bottom:1px solid #FFFFE0; 
     color:#FFFFE0;
    }
    li a 
    {
      color:black;
    }
    .page-item.active .page-link {
    
    background-color:yellow;
    border-color: #007bff;
}
.reportModal
{
  height:800px;
}
.searchfeilds input
{
height:30px;
}
.daterow
{
  margin-top:10px;
}
    @media (max-width: 800px) {
        #fullbody
    {
        display:flex;
        flex-wrap: wrap;
                 
    }
        #navbar,#content {
    flex: 100%;
  }
}
</style>
<script>
  function printDiv() 
{

  var divToPrint=document.getElementById('printdiv');

  var newWin=window.open('','Print-Window');

  newWin.document.open();

  newWin.document.write('<html><head><link rel="stylesheet" href="tablestyle/tablereport.css"></head><body onload="window.print()">'+divToPrint.innerHTML+'</body></html>');
  newWin.document.close();
}
  $(function () {

// INITIALIZE DATEPICKER PLUGIN
$('.datepicker').datepicker({
    clearBtn: true,
    format: "dd/mm/yyyy"
});


// FOR DEMO PURPOSE
$('#reservationDate').on('change', function () {
    var pickedDate = $('input').val();
    $('#pickedDate').html(pickedDate);
});
});

</script>
<script>
$(document).ready( function () {
    $('#protable').DataTable();
} );
</script>

</head>
<body>
    <div ><?php include "navbar.php"?></div>
    <div id="fullbody"> 

<div id="content">
<br>
<h3>Day Report</h3>
<br>

<!-- search collaspe -->

<!-- date -->
<form action="machinereport.php" method="post">
<div class="row daterow" style="overflow:auto">  
                <div class="col-sm-1"></div>
                
           <div class="col-sm-2">
                <input type="text" class="form-control" id="input_from" name="fromdate" autocomplete="off" placeholder="Start Date"></div>
                <div class="col-sm-2">
                            
                <input type="text" class="form-control" id="input_to" name="todate" autocomplete="off" placeholder="To Date">
              </div>
			  
			  
			       
              <div class="col-sm-1"><button class="btn btn-info" type="submit"><i class="fas fa-calendar-check" style="font-size:23px;"></i></button></div> 
              <div class="col-sm-1"><button type="button" class="btn btn-primary" onClick="printDiv()">Download</button></div>       
            </div>
            </form>
           

 



    <br>
    
    <div  id="printdiv">
  <div class="row">
    <div class="col-md-12">
   
   
   <table class="table table-bordered table-sm">
            <thead>
                 <?php 
			   $fromdate=$_POST['fromdate'];
			   $todate=$_POST['todate'];
			  
               $proedit=mysqli_query($connect,"select * from partydetail order by id desc");
               while($proshowedi = mysqli_fetch_array($proedit))
               {
                 $party=  $proshowedi['party'];
               }
               //echo $time_from;
			   
			   $fromdate1=date_create($_POST['fromdate']);
			   $todate1=date_create($_POST['todate']);
               ?>
               <tr align="center"><th colspan="24"><?php echo $party ?>&nbsp;-PRIMARY</th></tr>
               <tr align="center"><th colspan="24">Daily Update:<?php echo date_format($fromdate1,"d/m/Y");?>-<?php echo date_format($todate1,"d/m/Y");?>-Machine Report</th></tr>

                <tr class="section-header">
                    <th rowspan="2">DATE</th>
                    <th colspan="6">JAW CRUSHER</th>
                    <th colspan="6">CONE CRUSHER</th>
                    <th colspan="6">VSI UNIT</th>
                    <th rowspan="2">CRUSHING UNITS</th>
                    <th colspan="3">EB CONSUMPTION UNITS</th>
                    <th rowspan="2">AVG EB UNIT P/C UNIT</th>
                </tr>

                <tr class="sub-header">
                    <!-- Jaw -->
                    <th colspan="3">FEEDER</th>
                    <th colspan="3">MACHINE</th>

                    <!-- Cone -->
                    <th colspan="3">FEEDER</th>
                    <th colspan="3">MACHINE</th>

                    <!-- VSI -->
                    <th colspan="3">FEEDER</th>
                    <th colspan="3">MACHINE</th>

                    <!-- EB -->
                    <th>PREVIOUS</th>
                    <th>CURRENT</th>
                    <th>TOTAL</th>
                </tr>
            </thead>

            <tbody>
			
			<?php
			
			$sql_qry=mysqli_query($connect,"select * from  machine_units  where status=''  AND date >= '$fromdate ' AND date <= '$todate ' order by date ASC");
	
	
		
			
			 
			 $sno=0;
			
			$jaw_feeder=0;
		 $jaw_machine=0;
			 
			 $cone_feeder=0;
		 $cone_machine=0;
		 
		 $vsi_feeder=0;
		 $vsi_machine=0;
		 $eb=0;
			
			 while($row_result=mysqli_fetch_array($sql_qry))
			 {
			 
			 
			
			 
			 $date=date_create($row_result['date']);

			 ?>
                <tr>
                    <td><?php echo date_format($date,"d-m-Y");?></td>
                    <td><?php echo number_format($row_result['jaw_feeder_opening'],2,'.','');?></td><td><?php echo number_format($row_result['jaw_feeder_closing'],2,'.','');?></td><td><?php echo number_format(($row_result['jaw_feeder_closing']-$row_result['jaw_feeder_opening']),2,'.','');?></td>
                    <td><?php echo number_format($row_result['jaw_machine_opening'],2,'.','');?></td><td><?php echo number_format($row_result['jaw_machine_closing'],2,'.','');?></td><td><?php echo number_format(($row_result['jaw_machine_closing']-$row_result['jaw_machine_opening']),2,'.','');?></td>
                   
				   
				   
				   <td><?php echo number_format($row_result['cone_feeder_opening'],2,'.','');?></td><td><?php echo number_format($row_result['cone_feeder_closing'],2,'.','');?></td><td><?php echo number_format(($row_result['cone_feeder_closing']-$row_result['cone_feeder_opening']),2,'.','');?></td>
                    <td><?php echo number_format($row_result['cone_machine_opening'],2,'.','');?></td><td><?php echo number_format($row_result['cone_machine_closing'],2,'.','');?></td><td><?php echo number_format(($row_result['cone_machine_closing']-$row_result['cone_machine_opening']),2,'.','');?></td>
				   
				  
				  
				    <td><?php echo number_format($row_result['vsi_feeder_opening'],2,'.','');?></td><td><?php echo number_format($row_result['vsi_feeder_closing'],2,'.','');?></td><td><?php echo number_format(($row_result['vsi_feeder_closing']-$row_result['vsi_feeder_opening']),2,'.','');?></td>
                    <td><?php echo number_format($row_result['vsi_machine_opening'],2,'.','');?></td><td><?php echo number_format($row_result['vsi_machine_closing'],2,'.','');?></td><td><?php echo number_format(($row_result['vsi_machine_closing']-$row_result['vsi_machine_opening']),2,'.','');?></td>
				  
                   
                    <td>0.00</td>
					  <td><?php echo number_format($row_result['eb_opening'],2,'.','');?></td><td><?php echo number_format($row_result['eb_closing'],2,'.','');?></td><td><?php echo number_format(($row_result['eb_closing']-$row_result['eb_opening']),2,'.','');?></td>
                    
                    <td>0.00</td>
                </tr>

                <?php
				
				$jaw_feeder+=number_format(($row_result['jaw_feeder_closing']-$row_result['jaw_feeder_opening']),2,'.','');
		 $jaw_machine+=number_format(($row_result['jaw_machine_closing']-$row_result['jaw_machine_opening']),2,'.','');
			 
			 $cone_feeder+=number_format(($row_result['cone_feeder_closing']-$row_result['cone_feeder_opening']),2,'.','');
		 $cone_machine+=number_format(($row_result['cone_machine_closing']-$row_result['cone_machine_opening']),2,'.','');
		 
		 $vsi_feeder+=number_format(($row_result['vsi_feeder_closing']-$row_result['vsi_feeder_opening']),2,'.','');
		 $vsi_machine+=number_format(($row_result['vsi_machine_closing']-$row_result['vsi_machine_opening']),2,'.','');
		 $eb+=number_format(($row_result['eb_closing']-$row_result['eb_opening']),2,'.','');
				}
				?>

                

                

                <tr class="total-row">
                    <td><strong>TOTAL</strong></td>
                    <td colspan="2"></td>
                    <td><strong><?php echo number_format($jaw_feeder,2,'.','');?></strong></td>
                    <td colspan="2"></td>
                    <td><strong><?php echo number_format($jaw_machine,2,'.','');?></strong></td>
					
					<td colspan="2"></td>
                    <td><strong><?php echo number_format($cone_feeder,2,'.','');?></strong></td>
					<td colspan="2"></td>
                    <td><strong><?php echo number_format($cone_machine,2,'.','');?></strong></td>
					
					<td colspan="2"></td>
                    <td><strong><?php echo number_format($vsi_feeder,2,'.','');?></strong></td>
					<td colspan="2"></td>
                    <td><strong><?php echo number_format($vsi_machine,2,'.','');?></strong></td>
					<td><strong>0.00</strong>
					<td colspan="2"><strong>TUNNEL CRUSH NOT INCL</strong></td>
                    <td><strong><?php echo number_format($eb,2,'.','');?></strong></td>
					<td><strong>0.00</strong>
                </tr>
            </tbody>
        </table>
           </div>
		   
		   <div>&nbsp;</div><br>
		   
		   
		   
		   
		   
		   </div>
           <div>&nbsp;</div>
		   
		  
		   
           
           </div><!--print-->

</div>
</div>


<script>
    $('.selectpro').select2({ width: '100%',height:'420px;' });
    
</script>
<script src="calendar-15/calendar-15/js/rome.js"></script>

<script src="calendar-15/calendar-15/js/main.js"></script>
 <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>
</body>
</html>