 <?php
 
 $fromDate = $_REQUEST['fromDate'];
 $toDate = $_REQUEST['toDate'];
 $user = $_REQUEST['user'];
 
 ?>
 <!DOCTYPE html>
 <html lang="en">
   <head>
     <meta charset="utf-8">
     <meta http-equiv="X-UA-Compatible" content="IE=edge">
     <!--<meta name="viewport" content="width=device-width, initial-scale=1">-->
     <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
     <title><?= $config['CompanyName'] ?></title>
 
     <!-- Bootstrap -->
     <link href="../css/bootstrap.min.css" rel="stylesheet">
     <link rel="stylesheet" href="../css/bootstrap-combobox.css" />
 
     <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
     <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
     <!--[if lt IE 9]>
       <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
       <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
       <script src="../js/functions.js"></script>
       <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
       <script src="../js/functions.js"></script>
           <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
           <!-- Include all compiled plugins (below), or include individual files as needed -->
           <script src="../js/bootstrap.min.js"></script>
       	 <script src="../js/bootstrap-combobox.js"></script>
       	 <script src="../js/excellentexport.js"></script>
           <script type="text/javascript">
             $(document).ready(function(){
             
             });
           </script>
					<link rel="stylesheet" href="../css/jquery.filthypillow.css" type="text/css" />
					<script src="../js/jquery.filthypillow.min.js" type="text/javascript"></script>
					<script src="../js/moment.js" type="text/javascript"></script>
     <![endif]-->
	<link rel="stylesheet" href="../css/styles.css"/>
   </head>
   <body>
<?php 
	include("navbar.php");
?>
        <br /><br />
   <!-- Stack the columns on mobile by making one full-width and the other half-width -->
    
	<div class="container" style="padding-top: 10px;">
		<link href="../css/fileinput.min.css" media="all" rel="stylesheet" type="text/css" />
		<script src="../js/fileinput.js" type="text/javascript"></script>
		
		<div class="panel panel-default">
			<div class="panel-heading form-inline">
				<a class="btn btn-success" role="button" style="float: right;" href="#" download="QuantityBreaks<?= "(" . date("m.d.Y") . ")" ?>.xls" href="#" onclick="return ExcellentExport.excel(this, 'QtyBreakTable', 'Quantity Breaks');" data-toggle="tooltip" data-placement="left" title="Does not work with Internet Explorer">Export To Excel</a>
				<div style="margin-right: 10px; float: right;">
					<div class="input-group">
						<div id="clearButton" style="display: none;" class="input-group-addon" onclick="clearFilter()">
							<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
						</div>
						<input type="text"   class="form-control" name="filter" placeholder="Filter" value="" />
						<div class="input-group-addon" onclick="filter()">
							<span class="glyphicon glyphicon-search" aria-hidden="true"></span>
						</div>
					</div>
					
				</div>
				<h3 class="panel-title">Cart Log</h3>
				<small>Click on a row to edit the Item</small>
			</div>
			<div class="panel-body">
				<table id="QtyBreakTable" class="table table-hover">
					<thead>
						<tr>
							<th>Customer/Salesman</th>
							<th>Transaction Date</th>
							<th>Action</th>
							<th>Group</th>
							<th>Line</th>
							<th>SKU</th>
							<th>Qty</th>
							
						</tr>
					</thead>
					<tbody>
						<?php 
						 $query = "SELECT * FROM `CART_LOG` WHERE TransactionDate BETWEEN '$fromDate' AND '$toDate 23:59:59' AND User LIKE '$user' ORDER BY TransactionDate ASC";
						 //var_dump($query);
						 $result = mysqli_query($con, $query);
						 while ($row = mysqli_fetch_array($result)) {
							$user = new Customer($row['User']);
							
							if($user->Name === NULL){
								//$user->Name = $row['User'];
								$user = new Salesman($row['User']);
							}
						?>
							 <tr>
								 <td><?= ($user->Name) ?></td>
								 <td><?= date("m/d/Y h:i a", strtotime($row['TransactionDate'])) ?></td>
								 <td><?= $row['Action'] ?></td>
								 <td><?= $row['Group'] ?></td>
								 <td><?= $row['Line'] ?></td>
								 <td><?= $row['SKU'] ?></td>
								 <td><?= $row['Qty'] ?></td>
								 <!--  -->
							 </tr>
						<?php		
						 }
						 ?>
					</tbody>
				</table>
			</div>
		</div>
	</div>
		 
	   <script type="text/javascript">
		   $('[name=filter]').on('keypress', function(e) {
			   if (e.which == 13) {
				   filter();
			   }
		   
		   });
		   
		   function clearFilter() {
			   $('[name=filter]').val("");
			   $('#clearButton').css('display', 'none');
			   $('tr').css('display', '');
			   
		   }
		   function filter() {
			   var	name = $('[name=filter]').val();
			   filterByName(name);
		   }
		   function filterByName(name) {
			   $('#clearButton').css('display', '');
			   for (var i = 0; i < $('tr').length; i++) {
				   if (i != 0) {
					   var result = $('tr')[i].innerText.toUpperCase().indexOf(name.toUpperCase());
					   if (result < 0) {
						   $($('tr')[i]).css('display', 'none');
					   }else {
						   $($('tr')[i]).css('display', '');
					   }
				   }
			   }
		   }
		   </script>
	
	 </div>    
     
   </body>
 </html>