<?php
require( "php_con.php" );
?>
<link href="data_table/css/bootstrap.css" rel="stylesheet" type="text/css">


<table class="table table-sm table-hover" style="font-size: 14px;">
	<thead>
		<tr class="table-active">
			<th>Product/Code</th>
			<th>Badge</th>
			<th>Cost</th>
			<th>MRP</th>
		</tr>
	</thead>
	<tbody>
		<?php
		$search_text=mysqli_real_escape_string($connation,$_GET['search_text']);
		$search_type=mysqli_real_escape_string($connation,$_GET['search_type']);
		if($search_type=="sup_wise"){
		$l_qury=mysqli_query($connation,"SELECT *
		FROM price_details prd INNER JOIN product_details pd ON prd.price_systemid=pd.product_systemid
        WHERE pd.product_supplier='$search_text'
		ORDER BY pd.product_name");
		}		
		elseif($search_type="search_text"){
		$l_qury=mysqli_query($connation,"SELECT *
		FROM price_details prd INNER JOIN product_details pd ON prd.price_systemid=pd.product_systemid
        WHERE pd.product_name LIKE '%$search_text%' OR pd.product_name_sinhala LIKE '%$search_text%' OR pd.product_barcode='$search_text' OR pd.product_productid='$search_text'
		ORDER BY pd.product_name");
		}
		
		if(!mysqli_num_rows($l_qury)>0){
		echo "<tr>
			<td colspan='4' align='center'>Product not found!</td>
		</tr>";
		}
		else{
		while($l_resalt=mysqli_fetch_assoc($l_qury)){
		?>
		<tr onClick="load_details('<?php echo $l_resalt['product_id'] ?>','<?php echo $l_resalt['product_name']; ?>','<?php echo $l_resalt['product_barcode']; ?>','<?php echo $l_resalt['product_productid']; ?>','<?php echo $l_resalt['price_id']; ?>','<?php echo $l_resalt['price_buy']; ?>','<?php echo $l_resalt['price_sale']; ?>','<?php echo $l_resalt['price_wholesale']; ?>','<?php echo $l_resalt['price_discount']; ?>');">
			<td><?php echo $l_resalt['product_name']; ?><br><?php echo $l_resalt['product_barcode']; ?></td>
			<td><?php echo $l_resalt['price_name']; ?><br><em class="text-secondary"><?php echo $l_resalt['price_addtime']; ?></em></td>
			<td align="right"><?php echo number_format((float)$l_resalt['price_buy'],2); ?></td>
			<td align="right"><?php echo number_format((float)$l_resalt['price_sale'],2); ?></td>
		</tr>
		<?php } } ?>
	</tbody>
</table>