<?php
if(false){
	class Pickup {
		public $PickupID, $PickupTicket, $Customer, $PickupDate, $Items, $PickupNotes, $Packages, $Salesman, $AccountNumber, $RequestedBy;
		public function __construct($PickupID) {
			$query = "SELECT * FROM PICKUP_HEAD WHERE PickupID = $PickupID";
			global $con;
			$result = mysqli_query($con, $query);
			$row = mysqli_fetch_array($result);
			$this->PickupID = $row['PickupID'];
			$this->PickupTicket = $row['PickupTicket'];
			$this->AccountNumber = $row['AccountNumber'];
			$this->Customer = new Customer($row['AccountNumber']);
			$this->PickupDate = $row['PickupDate'];
			$this->PickupNotes = $row['PickupNotes'];
			$this->Packages = $row['Packages'];
			$this->Salesman = new Salesman($row['Salesman']);
			$this->RequestedBy	= $row['RequestedBy'];
			$this->Items = array();
			$query = "SELECT id FROM PICKUP_DETAIL WHERE PickupID = $PickupID";
			$result = mysqli_query($con, $query);
			while($row = mysqli_fetch_array($result)){
				$item = new PickupItem($row['id']);
				array_push($this->Items, $item);
				unset($item);
			}
		
		}
	}
	
	class PickupItem {
		public $Line, $SKU, $InvoiceNumber, $Reason, $Qty, $ReasonText;
		public function __construct($id) {
			$query = "SELECT * FROM PICKUP_DETAIL, INVENTORY WHERE `id` = $id AND PICKUP_DETAIL.SKU = INVENTORY.SKU AND PICKUP_DETAIL.LINE = INVENTORY.LINE";
			global $con;
			$result = mysqli_query($con, $query);
			$row = mysqli_fetch_array($result);
			$this->Line = $row['Line'];
			$this->SKU = $row['SKU'];
			$this->InvoiceNumber = $row['InvoiceNumber'];
			$this->Reason = $row['Reason'];
			$this->Qty = $row['Qty'];
			$this->ReasonText = getReasonText($row['Reason']);
			
		}	
	}
}

include_once("connect.php");
include_once("session.php");

$pickupID = $_REQUEST['id'];

$pickup = new Pickup($pickupID);



?>
<html>
    <head>
        <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
            <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
		<style>
			.center {
				text-align: center;
			}
			.itemsTable {
				border-collapse: collapse;
			}
			.itemsTable tr {
				border: 1px solid black;
			}
			.itemsTable td{
				text-align: right;
				padding-right: 15px;
			}
			.creditsTable td{
				text-align: right;
				padding-right: 15px;
			}
			.infoBlock {
				margin-left: 10px;
			}
			.moneyBlock {
				margin-left: 60px;
			}
			body {
				font-family: "Trebuchet MS", Helvetica, sans-serif;
			}
		</style>
		<script src="/js/jquery-barcode.min.js"></script>
		<script>
			function generateBarcode(bcValue, selector){
			var value = bcValue
			var btype = "code128"
			var renderer = "bmp"
			
			var quietZone = false;
			var settings = {
			  output:renderer,
			  bgColor: "#FFFFFF",
			  color: "#000000",
			  barWidth: "2",
			  barHeight: "50",
			  moduleSize: null,
			//  posX: $("#posX").val(),
			  //posY: $("#posY").val(),
			  //addQuietZone: $("#quietZoneSize").val()
			};
			
			$(selector).barcode(value, btype, settings);
			
		  }
			
		</script>
    </head>
    <body>
		<div style="width: 400px;">
			<div class="center">
				<img style="width: 300px;" src="img/logo_ej_small.png" alt=""><br />
				<!--<span style="font-size: 28px; font-weight: bold;">EuroJapon Auto Supply</span>-->
				<span>PO Box 191538</span><br />
				<span>San Juan, PR 00919-1538</span><br />
				<span>(787) 760-7295</span>
				
				<h3>Pickup and Return Request</h3>
			</div>
			<div class="infoBlock">
				<?= $pickup->Void?"<center><h1>VOID</h1></center>":"" ?>
				<span>Customer: </span><?= $pickup->Customer->AccountNumber ?><br />
				<?= $pickup->Customer->Name . " - " . $pickup->Customer->City ?><br />
				<span>Requested By: </span><?= $pickup->RequestedBy ?><br />
				<span>Salesman: </span><?= $pickup->Salesman->ID . " - " . $pickup->Salesman->Name ?><br />
				<span>Pickup Request #</span><b><?= $pickup->PickupID ?></b><br />
				<span>Pickup Date: </span><?= date("m/d/Y g:i a",strtotime($pickup->PickupDate	)) ?><br />
				
				
				<br />
			</div>
			<?php
				if($_REQUEST['reprint'] == "true"){
			?>
			<div class="center">
				<span><b>*R E P R I N T*</b></span><br /><br />
			</div>
			<?php
				}
			?>
			<?= $pickup->Void?"<center><h1>VOID</h1></center>":"" ?>
			<div class="center">
				<span><b>Items</b></span><br />
				<table class="itemsTable" style="width: 90%; margin: auto;">
					<thead>
						<tr>
							<th style="text-align: left;">Line - Part Number<br>Description</th>
							<th>Qty</th>
							<th>Order</th>
							<th>Reason</th>
						</tr>
					</thead>
				<?php
					foreach($pickup->Items as $item){
						$warrantyReasonText = "<i>" . $item->WarrantyReasonText . "</i>";
						echo "<tr>\n";
						echo "<td style=\"text-align: left;\"><b>" . $item->Line . " " . $item->SKU . "</b><br><small>" . $item->Description . "</small></td>\n";
						echo "<td style=\"vertical-align: top;\">" . $item->Qty . "</td>\n";
						echo "<td style=\"vertical-align: top;\">" . $item->OrderID. "</td>\n";
						echo "<td style=\"vertical-align: top;\"><small>" . str_ireplace(" - DETALLAR EN NOTAS","",$item->ReasonText) . "<br />" . $warrantyReasonText . "</small></td>\n";
						
					}
				?>
				</table>
			</div>
			<br />
			<div class="infoBlock">
				<?= $pickup->Void?"<center><h1>VOID</h1></center>":"" ?>
				<table>
					<thead></thead>
					<tbody>
						<tr>
							<td style="min-width: 120px;"><b>Total Packages</b></td>
							<td style="padding-left: 10px;"><?= $pickup->Packages ?></td>
						</tr>
						<tr>
							<td style="vertical-align: top;"><b>Notes</b></td>
							<td style="padding-left: 10px;"><?= $pickup->PickupNotes ?></td>
						</tr>
						<tr>
							<td style="vertical-align: top;"><b>Via</b></td>
							<td style="padding-left: 10px;"><?= $pickup->Via ?></td>
						</tr>
					</tbody>
				</table>
			</div>
			
			<hr />
			
			<div class="center">
				<br /><br />
				<br /><br />
				<span><b>Salesman Signature</b></span>
				<br /><br />
				<br /><br />
				<span><b>Cutomer Signature</b></span>
			</div>
		</div>
		<?php
			if(!$pickup->Loaded){
		?>
		<script>
			
			window.print();
			//alert("Press Ok to Print Customer Copy");
			window.print();
			//window.close();
			<?php
			if(!isset($_REQUEST['reprint']) || $_REQUEST['reprint'] != "true"){
			?>
			setTimeout(function(){
					window.close();
				},500);
			<?php } ?>
		</script>
		
		<?php
				$text = "";
				if($pickup->Packages == 0){
					$text = "Via Vendedor";
				}elseif($pickup->Packages == 1){
					$text = "Bulto";	
				}else{
					$text = "Bultos";
				}
		
			for($i = 0; $i < $pickup->Packages; $i++){
		?>
		<hr>
		<div style="text-align: center; width: 400px;">
			<span style="font-size: 25px;"><?= $pickup->Customer->Name ?></span><br />
			<span style="font-size: 60px;"><?= $pickup->PickupID ?></span><br />
			<span id="barcode-<?= $pickup->PickupID . "-" . ($i+1) ?>" style="font-size: 60px;"></span><br />
			<script>
				generateBarcode("<?= $pickup->PickupID . "-" . ($i+1) ?>", "#barcode-<?= $pickup->PickupID . "-" . ($i+1) ?>");
			</script>
			<!--<img alt="<?= $pickup->PickupID ?>" src="assets/barcode.php?text=<?= $pickup->PickupID . "-" . ($i+1) . "&print=true&size=40" ?>" /><br />-->
			<span style="font-size: 30px;"><?= $i+1 . "/" . $pickup->Packages . " " . $text ?> </span><br >
			<span style="font-size: 30px;"><?= $config['CompanyName'] ?></span>
		</div>
		<br /><br />
		
		<?php
			}
		?>
		<hr style="border-top: dotted 1px;" />
		
		<!--  END 2ND PRINT  -->
		<?php
			}
		?>
		</div>
    </body>
    
</html>

