<?php
	date_default_timezone_set("Pacific/Auckland");

	$cnt = 0;

	$phxcrmclient_id = $_COOKIE['phxcrmclient_id'];
	
	$c_shortdisc = 0;
	
	 include 'configi.php';

	
	$result = '';
	
	$cart_id	= 0;
	
	 
 	$phxcrmclient_id = $_COOKIE['phxcrmclient_id'];
	
	$cart_id =  $_REQUEST['sales_id'];
//	echo "cart id is " . $cart_id;
	
	$prod_image_url1 = "";

$sqlstaff = "SELECT * FROM phx_userid where idphx_userid = " . $phxcrmclient_id;
		
//		echo $sqlstaff;
					

		$resultstaff = $conn->query($sqlstaff);

		if ($resultstaff->num_rows > 0) {
			// output data of each row
			while($rowcompany = $resultstaff->fetch_assoc()) {

				$uid_company 			= $rowcompany["idphx_userid"];
				$company_name 			= $rowcompany["comp_name"];
				$contact_name 			= $rowcompany["contact_name"];
				$comp_phys_addr1 		= $rowcompany["comp_phys_addr1"];
				$comp_phys_addr2 		= $rowcompany["comp_phys_addr2"];
				$comp_phys_addr3 		= $rowcompany["comp_phys_addr3"];
				$comp_phys_addr4		= $rowcompany["comp_phys_addr4"];
				$comp_phys_addr5 		= $rowcompany["comp_phys_addr5"];
			//	$company_logo	 		= $rowcompany["company_logo"];
				$comp_ird_no	 		= $rowcompany["comp_ird_no"];
				$comp_phone	 			= $rowcompany["comp_phone"];
				$company_email	 		= $rowcompany["email"];	
		//		$hssigned_id	 		= $rowcompany["hssigned_id"];	
		//		$handsplan		 		= $rowcompany["handsplan"];					
		//		$hssigned_date		 	= strtotime($rowcompany["hssigned_date"]);
		
				$comp_country				= $rowcompany["comp_country"];
				$comp_gst_rate			= $rowcompany["comp_gst_rate"];
				$comp_gst_registered	= $rowcompany["comp_gst_registered"];
				$comp_website_url		= $rowcompany["comp_website_url"];
				$comp_type2				= $rowcompany["comp_type2"];
				$comp_stock_type		= $rowcompany["comp_stock_type"];
				$comp_eftpos_type		= $rowcompany["comp_eftpos_type"];
				$short_userid			= $rowcompany["short_userid"];
				
				
				


			}
			
		}
		
		$querystl="SELECT * from ".$_COOKIE['phxcrmclient_id']."_st where st_id = " . $cart_id;
//		echo $querystl;
		$resultstl=mysqli_query($conn, $querystl);

		while($rowstl=mysqli_fetch_array($resultstl)) { 

			$st_id			 				= $rowstl['st_id'];
			$uid_client		 				= $rowstl['uid_client'];
			
					
				$queryclient="SELECT * from ".$_COOKIE['phxcrmclient_id']."_client where uid_client = " . $uid_client;
				//		echo $querystl;
				$resultclient=mysqli_query($conn, $queryclient);

				while($rowclient=mysqli_fetch_array($resultclient)) { 

					$comp_name						= $rowclient['comp_name'];
				
				}
				
		}

	 
	 ?>
     
                
				<table valign="top" style="font-size: 12px; width: 250px; font-family: Helvetica, Sans-Serif;">
				<tr style="width: 100%">
					<td style="width: 100%; text-align: center">
                       	<img src="../images/logo/<?php echo $_COOKIE['phxcrmclient_id']?>.jpg" alt="icon" style="height: 50px">
						  <span><?php echo htmlspecialchars($company_email)?></span><br>
                        <span><?php echo htmlspecialchars($comp_phys_addr1)?><br><?php echo htmlspecialchars($comp_phys_addr2)?> </span>
                    
                    </td>

					</tr>
					
					
					
				</table>
				
								<table valign="top" style="font-size: 12px; width: 250px; font-family: Helvetica, Sans-Serif;">
				<tr style="width: 100%">
					<td  style="width: 100%; text-align: center;">
					<div class="invoice-id">#SALE <?php echo $cart_id ?></div>
					</td>
					</tr>
				</table>
				
               
				<table valign="top" style="font-size: 10px;  width: 250px; font-family: Helvetica, Sans-Serif;">
				<tr valign="top">
				<td  style="width: 100%; text-align: center;">
                    <div class="invoice-to"  style="font-size: 12px">
                        <h4  style="font-size: 12px"><?php echo htmlspecialchars($comp_name)?></h4>
                    </div>
							</td>

					</tr>
					</table>
             
       
				<table  valign="top" style="font-size: 10px;  width: 250px;font-family: Helvetica, Sans-Serif;">
				<th>
			<tr>
			<td><span>Title</span></td>
			<td  style="width: 80px; text-align: right"><span>Item $</span></td>
			<td  style="width: 80px; text-align: right"><span>Qty</span></td>
			<td  style="width: 80px; text-align: right"><span>Total</span></td>
			</tr>
				</th>
				<?php
				
					 include 'configi.php';

		$querystl="SELECT * from ".$_COOKIE['phxcrmclient_id']."_stl where st_id = " . $cart_id . " order by id_stl desc";
//		echo $querystl;
		$resultstl=mysqli_query($conn, $querystl);

		while($rowstl=mysqli_fetch_array($resultstl)) { 

			$id_stl			 				= $rowstl['id_stl'];
			$prodserv_uid		 			= $rowstl['prodserv_uid'];
			$qty	 						= $rowstl['qty'];
			$stl_title 						= $rowstl['stl_title'];
			$line_amount 					= $rowstl['line_amount'];
			$item_amount 					= $rowstl['item_amount'];
			
			echo '
			<tr>
						<table style="width: 250px; font-size: 12px">
				<tr style="width: 250px; font-size: 12px">
					<td style="width: 250px; font-size: 10px"><span style="font-size: 10px">'.$stl_title.'</span></td>
				</tr>
			</table>

			<table style="width: 250px; font-size: 12px">
				<tr>
					<td style="width: 90px; text-align: right; font-size: 14px;"><span>$'.$item_amount.'</span></td>
					<td style="width: 80px; text-align: right; font-size: 14px;"><span>'.$qty.'</span></td>
					<td style="width: 80px; text-align: right; font-size: 14px;"><span>$'.$line_amount.'</span></td>
				</tr>
			</table>

			';
		
		
	$cnt = $cnt + 1;
	

		}
		


			
			?>
</table>
             
				
				<?php

	$total_sale = 0;
		$total_postage = 0;
		$total_items = 0;
	
	 include 'configi.php';
	 $total_paid = 0;
	 $total_sale = 0;
	 $postage = 0;
	 

		$querystt="SELECT * from ".$_COOKIE['phxcrmclient_id']."_st where st_id = " . $cart_id;
	//	echo $queryprod;
		$resultstt=mysqli_query($conn, $querystt);
	


		while($rowstt=mysqli_fetch_array($resultstt)) { 

			$total_sale			 			= $rowstt['total_sale'];
			$postage			 			= $rowstt['postage'];
			$total_paid			 			= $rowstt['total_paid'];


		}
		
		
		$total_items = $total_sale ;
		
		?>

             
                   
<table style="width: 250px; font-size: 14px; text-align: right;font-family: Helvetica, Sans-Serif;">
<tr>
<td style="text-align: right">
                        Total&nbsp;&nbsp;<span class="totaltext text-primary">$<?php echo number_format($total_sale,2)?></span>
   </td>
</tr>
</table>   
              

                <div class="invoice-bottom"  style="width: 250px; font-size: 10px; text-align: center;font-family: Helvetica, Sans-Serif;">
				<br>
                    This invoice includes 15% GST.
					
					<?php
					if ($comp_ird_no == ""){
					?>
									
					<?php
					}else{
						?>
						
							<br>GST No: <?php echo $comp_ird_no; ?> <br>
						<?php
					}
					?>
										<center>
										Printed at : <?php echo date("d-m-Y h:i"); ?> 
				</center>
                </div>
				<div style="width:12.5em;">
				<center>
					<svg style="width:12.5em;"  id="barcode"></svg>
					</center>
					<br>
					<br>
				</div>
           
    