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

$isAdmin = $_SESSION['isAdmin'];
if (!$isAdmin) {
	header("Location: logout.php");
}
$invoice = new Invoice($_REQUEST['invoice']);

$order = new Order($invoice->OrderID);


 ?>
 <!DOCTYPE html>
  <html lang="en">
    <head><meta http-equiv="Content-Type" content="text/html; charset=windows-1252">

      <meta http-equiv="X-UA-Compatible" content="IE=edge">
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <title><?= $config['CompanyName'] ?></title>

      <!-- Bootstrap -->
      <link href="<?= $root ?>css/bootstrap.min.css" rel="stylesheet">
      <link rel="stylesheet" href="<?= $root ?>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="<?= $root ?>js/bootstrap.min.js"></script>
        	 <script src="<?= $root ?>js/bootstrap-combobox.js"></script>
            <script type="text/javascript">
              $(document).ready(function(){
                $('.combobox').combobox();
        //        $('.grpline').css("width", "100px");
				window.print();

              });

            </script>
		<style>

		</style>
      <![endif]-->
 	<link rel="stylesheet" href="<?= $root ?>css/styles.css"/>
	<style type="text/css" media="print">
		body { margin: 0; background-image: none; font-size: .7em }


	</style>
    </head>
    <body>

    <!-- Stack the columns on mobile by making one full-width and the other half-width -->

 <div class="container-fluid" style="margin-top: -50px;">
 	<div class="row">
 	  <div class="col-xs-6">
 	  	<img class="img-responsive" style="width: 150px;" src="<?= $root ?>img/<?= $config['Logo'] ?>" alt="" />
 	  	<p style="font-size: 18px;">
 	  		<b>Customer: </b><?= $invoice->Customer->Name; ?><br>
 	  		<b>City: </b><?= $invoice->Customer->City; ?><br>
 	  		<b>Customer #: </b><?= $invoice->AccountNumber ?><br />
			<b>PO Number: </b><span style="font-style: italic;"><?= $invoice->PONumber ?></span><br>
 	  </p>

 	  </div>
  	  <div class="col-xs-1"></div>
 	  <div class="col-xs-5">
 		  <h3><b>Picking List</b>
			<span style="margin-top: -20px; float: right;"><b><?= $invoice->InvoiceID ?></b></span>

		  </h3>
 		  <p>
 		  	<b>Order Number: </b><span style="font-style: italic;"><?= $order->OrderID ?></span><br>

			<b>Salesperson: </b><span style="font-style: italic;"><?= $order->Salesman->Name ?></span><br>
 		  <b>Date: </b><?= date("m/d/Y",strtotime($invoice->CreationDate)) ?><br>
 		  <b>Time: </b><?= date("g:i a",strtotime($invoice->CreationDate)) ?><br>
			<?php
			//var_dump($order);
			if(!$order->SalesmanOrder){
				?>
				<h4>Order By Customer</h4>
				<?php
			}
			 ?>
 		  </p>
 	  </div>
 	  <table class="table table-condensed">
 	    <thead>
 	      <tr>
 	        <th style="width: 5%">Line<br>Group</th>
 	        <th style="width: 60%">Item</th>
			<th style="width: 10%">Location</th>
			<th style="width: 5%">On Hand</th>
 	        <th style="width: 5%">Order Quantity</th>
 	        <th style="width: 5%">Packed</th>
 	      </tr>
 	    </thead>
 	  	<tbody>
 	  	<?php
 	  		$index = 0;
			$totalItems = 0;
			$itemArray = $invoice->Items;
			$locations = [];
			foreach($itemArray as $key => $item){
				$locations[$key] = $item->Location;
			}
			array_multisort($locations, SORT_ASC, $itemArray);

			foreach($itemArray as $key => $item){
				$currItem = new Item($item->Group, $item->Line, $item->SKU);
 	  	?>
 	  		<tr>
 	    			<td>
 	        			<span class="itemInfo"><?= $item->Line ?></span>
 	        			<span class="itemInfo"><?= $item->Group ?></span>
 	        		</td>
 	        		<td style="text-overflow: ellipsis;" >
 	        			<span style="font-size:16px;" class="itemInfo"><b><?= $item->SKU ?></b></span>
					<br>
 	        			<span style="font-size:14px;" class="itemInfo"><?= $item->Description . " " . $item->Notes ?></span>

					</td>
					<td style="font-size:2em;">
						<?php

						echo $item->Location?$item->Location . "<br>":"";
						echo $item->LocationB?$item->LocationB . "<br>":"";
						echo $item->LocationC?$item->LocationC . "<br>":"";
						echo $item->LocationD?$item->LocationD . "<br>":"";
						echo $item->LocationE?$item->LocationE . "<br>":"";

						?>
					</td>
					<td style="font-size:2em;">
 	        			<?= $currItem->AvailableQty; ?>
 	        		</td>
 	        		<td class="centered"  style="font-size:16px;">
 	        			<?php
						//var_dump($item);
						echo $item->OrderQty;
						$totalItems += $item->OrderQty;

						?>
 	        		</td>

 	        		<td>
						<br>
 	        			_______________
 	        		</td>
 	      	</tr>
 	      	<?php
 	      	$index++;
 	      	}?>
 	      	<tr>
 	      		<td></td>
 	      		<td><br><b>Picker Name:</b> ________________________________</td>
 	      		<td><span style="font-weight: bold;">Total Items</span></td>
 	      		<td><span><?= $totalItems ?></span></td>
 	      		<td><span style="font-weight: bold;">Box Count</span></td>
				<td><br>_______________</td>
 	      	</tr>
 	      </tr>
 	    </tbody>
 	  </table>
 	</div>
 <?php
	if($order->OrderNotes){


 ?>
 	<center>
		<b><span style="font-size: 32px;">NOTES BELLOW</span></b>
	</center>

 </div>
        <div class="panel panel-default">
          <div class="panel-body">
            <span><b>Order Notes:</b></span><br /><br />
            <span style="font-size: 22px;"><?= $order->OrderNotes ?></span>
          </div>
        </div>
		<?php
	}
 ?>
		<style>
			.deliveryCrate , .deliveryCrate tr, .deliveryCrate tr th, .deliveryCrate tr td {
			border: solid !important;
			border-width: medium;
			border-color: black;

		}
		.deliveryCrate tr, .deliveryCrate td {
			height: 60px;
		}

		</style>

		<div class="row">
			<div class="col-xs-4">
				Delivery Crates:<br>
				<table class="deliveryCrate table" style="">
					<tr>
						<td></td>
						<td></td>
						<td></td>
						<td></td>
						<td></td>
					</tr>
				</table>


			</div>
		</div>


    </body>
  </html>
