<?php
error_reporting(E_ALL ^ E_NOTICE ^E_WARNING);
$q = strtolower($_GET["q"]);
if (!$q) return;
include '../../db_connect.php';

if($_GET['mode']=='singleproductfill')
{

$items = mysqli_query($con,"SELECT code, `gencode`, `color`, `stock`, `cat`, `sizesetcode`, `desc`, `unit`, `sets`,  `vat`, `ratiotot` FROM prodreg where code = '$_POST[prodcode]'");

	$row = mysqli_fetch_assoc($items);
	
	//Get size wise qty
	$svarItems = mysqli_query($con,"SELECT size, sum(qnty) as qnty FROM  `sordervar` WHERE prodname =  '$_POST[prodcode]' AND (qnty - pissued) >0 group by size order by size");

	while($svarrow = mysqli_fetch_array($svarItems)) 
	{
		$qtyval= $qtyval.$svarrow['size']."-".$svarrow['qnty'].",";
		
		
	}
	
	 // if (strpos(strtolower($row['code']), $q) !== false)
	  echo $row['code']."|".$row['cat']."|".$row['color']."|".$row['desc']."|".$row['sizesetcode']."|".$row['sets']."|".$row['qty']."|".$row['fresh']."|".$row['reprocess']."|".$row['demage']."|".$row['ratiotot']."|".$row['gencode']."|".$qtyval."\n";
		
}
else 
{
	
$items = mysqli_query($con,"SELECT code, `gencode`, `color`, `stock`, `cat`, `sizesetcode`, `desc`, `hsncode`, `unit`, `pnamount`,  `gstper`, `ratiotot` FROM prodreg");

	while($row = mysqli_fetch_array($items)) 
	{
	 if (strpos(strtolower($row['code']), $q) !== false) 
		{
	  echo $row['code']."|".$row['cat']."|".$row['color']."|".$row['desc']."|".$row['hsncode']."|".$row['pnamount']."|".$row['gstper']."|".$row['ratiotot']."|".$row['gencode']."\n";
		}
	
	}

}

mysqli_close($con);


?>
