<?php 
include_once("../connect.php");
include_once("../session.php");

$webTitle = "Receive Report";
$poid = mysqli_real_escape_string($con,$_REQUEST['poid']);
 ?>
 
 <!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">
     <title><?= $config['CompanyName'] ?> - <?= $webTitle ?></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>
       <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
           <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(){
       //        $('.grpline').css("width", "100px");
             });
           </script>

     <![endif]-->
	<link rel="stylesheet" href="../css/styles.css"/>
	<style>
		.truncate {
			width: 150px;
			max-width: 2.5in;
			white-space: nowrap;
			overflow: hidden;
			text-overflow: ellipsis;
		}
	</style>
   </head>
   <body>
   
       <?php
	   //error_reporting(E_ALL);
	   include("navbar.php"); ?>     

   
   <!-- Stack the columns on mobile by making one full-width and the other half-width -->
<div class="container " style="padding-top: 10px;">
	<div class="panel panel-default">
	  <div class="panel-heading form-inline">
	  
	  
	  	
	  		    <h3 class="panel-title">Receive Report</h3><br />
						<div class="">
							<?php
							$po = new PurchaseOrder($poid);
							//var_dump($po);
							echo "Supplier: " . ($po->Vendor->Name) . "<br>";
							echo "Invoice #: " . ($po->InvoiceNumber) . "<br>";
							echo "PO#: " . ($po->PurchaseOrderID) . "<br>";
							?>
							
						<a href="mod.php?p=purchasing&a=receivereport&poid=<?= $poid ?>" class="hidden-print btn btn-primary">
							Go Back
						</a>
						<button onclick="window.print();" class="hidden-print btn btn-primary">
							Print
						</button>
						
					</div>
	  </div>
	  <div class="panel-body">
	  	<table class="table table-hover table-condensed" id="receiveReportTable">
	  		<thead>
	  			<tr>
						<th>SKU</th>
						<th>Description</th>
						<th>Locations</th>
						<th>Recevied</th>
						<th>Packages Scanned</th>
						<th>Manual Count</th>
						
	  			</tr>
	  			
	  		</thead>
			<tbody>
	    <?php
		$query = "SELECT id FROM PURCHASE_ORDER_HEADER JOIN PURCHASE_ORDER_DETAIL USING(PurchaseOrderID) WHERE PurchaseOrderID = $poid";
		//echo $query;
		$result = mysqli_query($con,$query);
		while($row = mysqli_fetch_array($result)){
			//$invoice = new Invoice(322);
			$poItem = new PurchaseOrderItem($row['id']);
			$poItemObj = new Item($poItem->Group, $poItem->Line, $poItem->SKU);
			$rowClass = $poItem->ReceivedQty==$poItem->ConfirmedQty?"success":"danger";
		?>
				<tr class="<?= $rowClass ?>" <?= $rowClass=="danger"?"style=\"font-weight: bold;\"":"" ?>>
					<td>
					<?= $poItem->SKU ?></td>
					<td class="truncate">
					<?= $poItem->Description ?></td>
					<td><?php
						echo implode("<br>",array_filter($poItemObj->getLocations()));
					?></td>
					<td><?= $poItem->ReceivedQty . "/" . $poItem->ConfirmedQty ?></td>
					<td><?= $poItem->PackagesReceived ?></td>
					
					<td valign="bottom">
						__________
					</td>
		<?php
		}
		?>
			</tbody>
	     </table>
	  </div>
	  <div class="panel-footer" >
			<div class="pull-left">
				
				
			</div>
	  	<div class="pull-right">
				
			</div>
			<br>
				<br>
	  </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', '');
		var cols = $('#paymenthistory th').length;
		for (var i = 0; i < $('#paymenthistory td').length; i=i+cols) {
		
			var text = $($('td')[i]).text();
			
			var result = text.toUpperCase().indexOf(name.toUpperCase());
			if (text != name) {
				$($('tr')[i/cols+1]).css('display', 'none');
			}else {
				$($('tr')[i/cols+1]).css('display', '');
			}
			
		}
	}
	</script>

   </body>
   
 </html>