<?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;
			}
			@media print {
				.breakBefore {page-break-before: always;}
				.breakAfter {page-break-after: always;}
			}
		</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);
			
		  }
		
		window.print();
		
		setTimeout(function(){
					alert("Please change back the printer to Receipt Paper.");
					setTimeout(function(){
						window.close();
					},500);
				},500);
		</script>
    </head>
    <body>
		<?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++){
		?>
		<div style="text-align: center; width: 400px;" class="breakAfter">
			<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>
		<?php
			}
		?>
    </body>
    
</html>

