<?php 
include("connect.php");
//include("session.php");
include_once("functions.php");
$pickup = new Pickup($_REQUEST['pickup']);
$realKey = md5($pickup->PickupID . $config["SaltKey"]);
$realKey = substr($realKey, -16); 
$key = $_REQUEST['key'];
if (isset($_REQUEST['key'])) {
	if ($realKey != $key) {
		header("Location: index.php");
		exit();
	}
}else {
	header("Location: index.php");
	exit();
}

/*
//validate so the user can't see other customers orders
if ($_SESSION['isCustomer']) {
	$customer = new Customer($_SESSION['AccountNumber']);	
	if ($order->Customer->AccountNumber != $customer->AccountNumber) {
		header("Location: index.php");
	}
}else {
	$salesman = new Salesman($_SESSION['SalesmanID']);
	if ($order->Salesman->ID != $salesman->ID) {
		header("Location: index.php");
	}
}
*/
 ?>
 <html>
	<head>
		<script>
			<?php if(isset($_REQUEST['print']) && $_REQUEST['print'] == "true"){ ?>
				window.print();
				setTimeout(window.close, 1000);
			<?php } ?>
		</script>
	</head>
 <body style="font-family: sans-serif;">
   
    <!-- Stack the columns on mobile by making one full-width and the other half-width -->
 <img src="<?= $root ?>img/<?= $config['SmallLogo'] ?>" style="width: 202px; height: 63px;" /><br />
 <br />
 	<div id="header" style="margin-top: 0px;">
 		<div style="width: 60%;  height: 120px; float: left;">
 			
 			<b>Customer Name: </b><?= substr($pickup->Customer->Name, 0, 29) ?><br />
 			<b>City: </b><?= $pickup->Customer->City; ?><br />
 			<b>Customer Number: </b><?= $pickup->Customer->AccountNumber ?><br />
 			<b>Requested By:</b>
 			<?= ($pickup->RequestedBy) ?><br />
 			<b>Packages: </b>
 				<?= ($pickup->Packages) ?><br />
			<b>Via: </b>
 				<?= ($pickup->Via) ?>
 				
 				
 			
 		</div>
 		<div style="width: 38%; height: 120px; float: right;">
 			<b>Pickup Number: </b><span style="font-style: italic;"><?= $pickup->PickupID ?></span><br />
 			<b>Pickup Ticket: </b><?= $pickup->PickupTicket ?><br />
 			<b>Date: </b><?= date("m/d/Y",strtotime($pickup->PickupDate)) ?><br />
 			<b>Time: </b><?= date("g:i a",strtotime($pickup->PickupDate)) ?><br />
 			<b>Salesman: </b><?= $pickup->Salesman->ID . " - " . $pickup->Salesman->Name ?><br />
 		</div>
 	</div>
 
 <div id="content" style="width: 100%;">
 	<h4 style="text-align: center;">PICKUP AND RETURN REQUEST</h4>
 	<table style="border: 1px solid #333; border-collapse: collapse;">
 		<thead>
 			<tr>
 				<th style="border: solid 1px black; width: 5%;">Line</th>
 				<th style="border: solid 1px black; width: 60%;">Item</th>
 				<th style="border: solid 1px black; width: 5%;">Quantity</th>
				<th style="border: solid 1px black; width: 5%;">Order ID</th>
 				<th style="border: solid 1px black; width: 5%;">Invoice Number</th>
 				<th style="border: solid 1px black; width: 5%;">Reason</th>
 			</tr>
 		</thead>
 		<tbody>
 			<?php
 				$query = "SELECT * FROM PICKUP_DETAIL WHERE PickupID = '$pickup->PickupID'";
 				$result = mysqli_query($con, $query);
 				$index = 0;
 				while ($row = mysqli_fetch_array($result)) {
 			?>
 			<tr>
 				<td style="border: solid 1px black; text-align: center;">
 					<?= $row['Line'] ?></td>
 				<td style="border: solid 1px black;"><b><?= $row['SKU'] ?></b><br /><small><?php getProductDescription($row['Line'], $row['SKU']) ?></small></td>
 				<td style="border: solid 1px black; text-align: center;"><?= $row['Qty'] ?></td>
 				<td style="border: solid 1px black; text-align: right; padding-right: 5px;">
 					<?= ($row['OrderID'] == 0?"":$row['OrderID']) ?>
 				</td>
				<td style="border: solid 1px black; text-align: right; padding-right: 5px;">
 					<?= ($row['InvoiceNumber'] == 0?"":$row['InvoiceNumber']) ?>
 				</td>
 				<td style="border: solid 1px black; text-align: right; padding-right: 5px;">
 					<?= getReasonText($row['Reason'])  ?>
 				</td>
 			</tr>
 			<?php 
 
 			}?>
 		</tbody>
 	</table>
 	<div style="float: right; text-align: right; padding-top: 10px; padding-right: 5px; font-size: 1.2em;">
 	</div>
 	<div style="padding: 5px; margin-top: 5px; border: 1px solid #333; width: 50%; word-wrap: break-word;"><b>Pickup Notes: </b><br />
 		 <?= $pickup->PickupNotes ?>
 	</div>
	<br />
 	<br />
 	<div style=" margin: 0 auto; margin-top: 5px; padding: 10px; text-align: center; border: 1px solid #333; width: 75%; word-wrap: break-word;">ESTO ES UNA FORMA DE DEVOLUCI&Oacute;N Y <b>NO</b> UN CR&Eacute;DITO.<br />
 			EST&Aacute; SUJETO A VERIFICACI&Oacute;N Y APROBACI&Oacute;N.
 	</div>
 	
 </div>
 </body>
 </html>