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

if($_GET['mode']=='pcode')
{
	$items = mysqli_query($con,"SELECT `code`, `gencode`, `desc` FROM prodreg");

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

else if($_GET['mode']=='taxtype')
{
	$items = mysqli_query($con,"SELECT * FROM  `master` where mstype = 'GST' ");

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

else if($_GET['mode']=='barcode')
{
	$items = mysqli_query($con,"SELECT `code`, `gencode`, `desc`, prodvar.size as size, prodvar.qnty as qnty, `cat`, `color`, mrp FROM prodreg inner join prodvar on code = prodname");

	while($row = mysqli_fetch_array($items)) 
	{
		if (strpos(strtolower($row['code']), $q) !== false) 
		{
			echo $row['code']."|".$row['gencode']."|".$row['desc']."|".$row['qnty']."|".$row['size']."|".$row['mrp']."\n";
		}
	}
}

else if($_GET['mode']=='colorfill')
{
	$items = mysqli_query($con,"SELECT code, `desc` FROM master where mstype = 'COLOR'");

	while($row = mysqli_fetch_array($items)) 
	{
					echo $row['desc']."|".$row['code']."\n";
		
	}
}
else if($_GET['mode']=='singleproductfill')
{

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

	$row = mysqli_fetch_assoc($items);
	
	 // 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']."|".$row['taxtype']."\n";
		
}


else if($_GET['mode']=='sorderentry')
{

$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);
	
	 // 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']."\n";
	
	
}
else if($_GET['mode']=='subprdcd')
{

$items = mysqli_query($con,"SELECT code, `gencode`, `color`, `stock`, `cat`,subcat, `sizesetcode`, `desc`, `unit`, `sets`,  `vat`, `ratiotot`, `ratio`, `diffmrp`, `diffprice` FROM prodreg");

	while($row = mysqli_fetch_array($items)) 
	{
	
	 // if (strpos(strtolower($row['code']), $q) !== false)
	  echo $row['gencode']."|".$row['cat']."|".$row['subcat']."|".$row['desc']."|".$row['sizesetcode']."|".$row['sets']."|".$row['qty']."|".$row['fresh']."|".$row['reprocess']."|".$row['demage']."|".$row['ratiotot']."|".$row['ratio']."|".$row['diffmrp']."|".$row['diffprice']."\n";
	}
	
}
else
{
	
$items = mysqli_query($con,"SELECT code, `gencode`, `color`, `stock`, `cat`, `sizesetcode`, `desc`, `unit`, `sets`,  `vat`, `ratiotot` FROM prodreg");

	while($row = mysqli_fetch_array($items)) 
	{
       
	 
	  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']."\n";
	
	
	}
}


mysqli_close($con);


?>
