<?php 
$where 	= " WHERE 1=1 ";
$query_string = "";

$next_page_condition 	= "";

if($_REQUEST['hide_top']){
	$next_page_condition.="&hide_top=1";
}
if($_REQUEST['hide_left']){
	$next_page_condition.="&hide_left=1";
}

if($_REQUEST['po_id']){
	$po_id = $_REQUEST['po_id'];
	$where .= " AND id = '$po_id' ";
}


$sql = "SELECT * FROM purchase_order $where ";
$rs = mysqli_query($conn,$sql);
$row = mysqli_fetch_assoc($rs);
$purchase_order_number = $row["id"];
$delivery_instruction = $row["delivery_instruction"];
$pu_supplier_id = $gsi->getSupplierById($row["supplier_id"]);
$supplier_quote_ref = $row["supplier_quote_ref"];


$supplier_id = $row['supplier_id'];
$supplier_sql = "SELECT id,address1,address2,address3,town_city,postcode,country,account_manager_telephone FROM supplier_management WHERE id = '$supplier_id' ";
$supplier_rs = mysqli_query($conn,$supplier_sql);
if(mysqli_num_rows($supplier_rs) > 0){
	$supplier_row = mysqli_fetch_assoc($supplier_rs);
	$supplier_row = utility::validate_crypt_data($supplier_row);
	
	$supplier_address = "";
	if(isset($supplier_row["address1"]) && $supplier_row["address1"] !=""){
		$supplier_address .= $supplier_row["address1"]."<br/>";
	}
	if(isset($supplier_row["address2"]) && $supplier_row["address2"] !=""){
		$supplier_address .= $supplier_row["address2"]."<br/>";
	}
	if(isset($supplier_row["address3"]) && $supplier_row["address3"] !=""){
		$supplier_address .= $supplier_row["address3"]."<br/>";
	}
	if(isset($supplier_row["town_city"]) && $supplier_row["town_city"] !=""){
		$supplier_address .= $supplier_row["town_city"]."<br/>";
	}
	if(isset($supplier_row["postcode"]) && $supplier_row["postcode"] !=""){
		$supplier_address .= $supplier_row['postcode']."<br/>";
	}
	if(isset($supplier_row["country"]) && $supplier_row["country"] !=""){
		$supplier_address .= $gsi->getCountryById($supplier_row['country']);
	}
		$supplier_telephone = $supplier_row['account_manager_telephone'];
	}

		
$site_id = $row['site_id'];
$site_sql = "SELECT id,address1,address2,address3,address4,postcode,country FROM site_management WHERE id = '$site_id' ";
$site_rs = mysqli_query($conn,$site_sql);
if(mysqli_num_rows($site_rs) > 0){
	$site_row = mysqli_fetch_assoc($site_rs);
	
	$delivery_address = "";
	if(isset($site_row["address1"]) && $site_row["address1"] !=""){
		$delivery_address .= $site_row["address1"]."<br/>";
	}
	if(isset($site_row["address2"]) && $site_row["address2"] !=""){
		$delivery_address .= $site_row["address2"]."<br/>";
	}
	if(isset($site_row["address3"]) && $site_row["address3"] !=""){
		$delivery_address .= $site_row["address3"]."<br/>";
	}
	if(isset($site_row["address4"]) && $site_row["address4"] !=""){
		$delivery_address .= $site_row["address4"]."<br/>";
	}
	if(isset($site_row["postcode"]) && $site_row["postcode"] !=""){
		$delivery_address .= $site_row['postcode']."<br/>";
	}
	if(isset($site_row["country"]) && $site_row["country"] !=""){
		$delivery_address .= $gsi->getCountryById($site_row['country'])."<br/>";
	}

}

?>
<style>
body{
	font-size:12px;
}
table.equip_table{
	width: 100%;
	border-collapse: collapse;
	margin: 15px 0;
	border: 2px solid #000;
}
table.equip_table_3{
	width: 100%;
	border-collapse: collapse;
	margin: 15px 0;
	border: 2px solid #000;
}
table.equip_table_3, table.equip_table_3 td {
	border: 2px solid #000;
	padding: 10px;
}
table.equip_table, table.equip_table th {
	border: 2px solid #000;
	padding: 10px;
}
table.equip_table td {
	border-right: 2px solid #000;
	padding: 10px;
}

.col-sm-1, .col-sm-2, .col-sm-3, .col-sm-4, .col-sm-5, .col-sm-6, .col-sm-7, .col-sm-8, .col-sm-9, .col-sm-10, .col-sm-11, .col-sm-12 {
	float: left;
}
.col-sm-12 {
	width: 100%;
}
.col-sm-11 {
	width: 91.66666667%;
}
.col-sm-10 {
	width: 83.33333333%;
}
.col-sm-9 {
	width: 75%;
}
.col-sm-8 {
	width: 66.66666667%;
}
.col-sm-7 {
	width: 58.33333333%;
}
.col-sm-6 {
	width: 50%;
}
.col-sm-5 {
	width: 41.66666667%;
}
.col-sm-4 {
	width: 33.33333333%;
}
.col-sm-3 {
	width: 25%;
}
.col-sm-2 {
	width: 16.66666667%;
}
.col-sm-1 {
	width: 8.33333333%;
}

@page {
	size: A4;
   margin: 0;
   /* size: portrait; */
}

@media print{

    table.equip_table{
		width: 100%;
		border-collapse: collapse;
		margin: 15px 0;
		border: 2px solid #000;
	}
	table.equip_table_3{
		width: 100%;
		border-collapse: collapse;
		margin: 15px 0;
		border: 2px solid #000;
	}
	table.equip_table_3, table.equip_table_3 td {
		border: 2px solid #000;
		padding: 10px;
	}
	table.equip_table, table.equip_table th, table.equip_table td {
		border: 2px solid #000;
		padding: 10px;
	}
   
   .col-sm-1, .col-sm-2, .col-sm-3, .col-sm-4, .col-sm-5, .col-sm-6, .col-sm-7, .col-sm-8, .col-sm-9, .col-sm-10, .col-sm-11, .col-sm-12 {
        float: left;
   }
   .col-sm-12 {
        width: 100%;
   }
   .col-sm-11 {
        width: 91.66666667%;
   }
   .col-sm-10 {
        width: 83.33333333%;
   }
   .col-sm-9 {
        width: 75%;
   }
   .col-sm-8 {
        width: 66.66666667%;
   }
   .col-sm-7 {
        width: 58.33333333%;
   }
   .col-sm-6 {
        width: 50%;
   }
   .col-sm-5 {
        width: 41.66666667%;
   }
   .col-sm-4 {
        width: 33.33333333%;
   }
   .col-sm-3 {
        width: 25%;
   }
   .col-sm-2 {
        width: 16.66666667%;
   }
   .col-sm-1 {
        width: 8.33333333%;
   }
}
</style>
<section class="content" id="print_section">
	<div class="row">
		<div class="col-lg-12">
              <div class="card box-primary" style="box-shadow: none;">
                <form class="form-horizontal" method="post" name="form1" id="form1" action="#" onsubmit="return validateForm(this)" enctype="multipart/form-data">
                  <div class="card-body" style="padding:0;">
					<div class="form-group">
						<div class="col-sm-12 no-padding">
							<div class="row mb-2">
								<div class="col-sm-4">
									<img src="../images/arolite-logo.jpg" style="width: 280px;margin-top: 0;"/>
								</div>
								<div class="col-sm-4" style="text-align:center;">
									<b><h1 style="text-align:center;margin-top: 0;font-weight:bold;">PURCHASE ORDER</h1></b>
									<b>Order No: </b><? echo $purchase_order_number;?>
								</div>
								<div class="col-sm-4">
									&nbsp;
								</div>
								<div class="col-sm-12" style="text-align:center;">
									<hr style="margin-top: 15px;border-top: 2px solid #000;" />
								</div>
							</div>
							<div class="row mb-2">
								<div class="col-sm-4">
									<div style="border:2px solid #000;height: 245px;width: 100%;float: left;">
										<b style="display:block;text-transform:uppercase;border-bottom:2px solid #000;padding: 5px;">SUPPLIER: <span style="float:right;text-transform:uppercase;"><? echo $pu_supplier_id;?></span></b>
										<p style="padding: 5px;margin-bottom: 0;margin-top: 5px;">
										<? echo $supplier_address;?>
										</p>
										<p style="padding: 5px;">
										Tel:&nbsp;<? echo $supplier_telephone;?>
										</p>
									</div>
								</div>
								<div class="col-sm-4">
									&nbsp;
								</div>
								<div class="col-sm-4" style="">
									<div style="border:2px solid #000;height: 245px;width: 100%;float: left;">
										<b style="display:block;text-transform:uppercase;border-bottom:2px solid #000;padding: 5px;">DELIVERY ADDRESS</b>
										<p style="padding: 5px;margin-bottom: 0;margin-top: 5px;line-height:2;">
										<? echo $delivery_address;?>
										Tel: 01492 532 404
										</p>
									</div>
								</div>
							</div>
							<div class="row mb-2">
								<div class="col-sm-12" style="margin:15px 0;">
									<b>Delivery Instruction:</b> <?echo $delivery_instruction;?><br /><br />
									<b>Your Quote Ref:&nbsp;</b><? echo $supplier_quote_ref;?>
								</div>
							</div>
							<?	
								$final_total=0;
								$purchaseorder_item_mapping_query = "SELECT * FROM purchase_order_items_mapping WHERE po_id='".$po_id."'";
								$purchaseorder_item_mapping_sql=mysqli_query($conn,$purchaseorder_item_mapping_query);
								$purchase_item_mapping_count=mysqli_num_rows($purchaseorder_item_mapping_sql);
							?>
							
							<div class="row">
								<div class="col-sm-12 col-12">
									<table class="equip_table">
										<thead>
										  <tr>
											<th style="text-align:center;">Qty</th>
											<th style="">Stock Ref</th>
											<th style="">Supplier Ref</th>
											<th style="width:50%;">Description</th>
											<th style="text-align:center;">Unit Price</th>
											<th style="text-align:center;">Total</th>
										  </tr>
										</thead>
										<tbody>
										<? 
										if($purchase_item_mapping_count>0){
										while($row_wo_item_mapping = mysqli_fetch_array($purchaseorder_item_mapping_sql)){
										?>
										  <tr>
											<td style="text-align:center;"><?php echo $row_wo_item_mapping['quantity'];?></td>
											<td><?php echo $row_wo_item_mapping['stock_ref'];?></td><td><?php echo $row_wo_item_mapping['supplier_ref'];?></td>
											<td><?php echo stripslashes($row_wo_item_mapping['description']);?></td>
											<td style="text-align:center;"><?php echo number_format($row_wo_item_mapping['unit_price'],2);?></td>
											<td style="text-align:center;"><?php echo number_format($row_wo_item_mapping['total'],2);?></td>
										  </tr>
										  <?
										$final_total=$final_total+$row_wo_item_mapping['total'];
										
										}
										}?> 
										</tbody>
									</table>
								</div>
								<div class="col-sm-12" style="text-align: right;">
									<b style="width: 121px;display: inline-block;text-align: left;margin-right: 10px;">Total Order Value excl VAT:</b><b style="border: 2px solid #000;padding: 10px 10px 10px 68px;float: right;margin-top: 0;">128.05</b>
								</div>
							</div>
							<div class="row mb-2" style="">
								<div class="col-sm-12" style="">&nbsp;</div>
								<div class="col-sm-12" style="">&nbsp;</div>
								<div class="col-sm-12" style="">&nbsp;</div>
								<div class="col-sm-12" style="">&nbsp;</div>
								<div class="col-sm-12" style="">&nbsp;</div>
								<div class="col-sm-12" style="">&nbsp;</div>
								<div class="col-sm-12" style="">&nbsp;</div>
								<div class="col-sm-12" style="">&nbsp;</div>
								<div class="col-sm-12" style="">&nbsp;</div>
								<div class="col-sm-12" style="">&nbsp;</div>
								<div class="col-sm-12" style="">&nbsp;</div>
							</div>
							<div class="row mb-2" style="">
								<div class="col-sm-8">
									<p style="font-size: 12px;">
									<b>IMPORTANT INSTRUCTIONS:</b><br />
									Please accept our Purchase Order in good faith.<br />
									To avoid any unnecessary delay in the payment of subsequent purchase invoice we would be obliged if you would ensure the following:-<br />
									1. The purchase order number is quoted on your invoice for this order and this order only.<br />
									2. Your invoice value must match our order in a line by line basis. If this is not possible please contact the originator prior to dispatch of goods/services.<br />
									3. Please send your invoice to the Purchase Ledger section at the Invoice address: accounts@arolite.co.uk<br />
									4. All invoices must quote a valid order number.
									</p>
								</div>
								<div class="col-sm-4">
									<p style="text-align:right;">
									23 Paterson Road<br/>
									Finedon Road Industrial Estate,<br/>
									Wellingborough<br/>
									Northants<br/>
									NN8 4BZ<br/>
									Tel: +44 (0)844 811 1254
									</p>
								</div>
							</div>
						</div>
					</div>
                  </div>
                </form>
              </div>
		</div>
	</div>
</section>
