<?php
include '../../db_connect.php';

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

$sql = "SELECT `prodname`, `hsncode`, `size`, `qnty`, `fresh`, `reprocess`, `demage`, `price`, `mrp` FROM `prodvar` WHERE prodname = '$_POST[prodcode]'";

//echo $sql;exit;
 $emparray= array();
if($result = mysqli_query($con,$sql))
{
	while($row = mysqli_fetch_array($result))
	$emparray['productvar'][] = $row;
}
echo json_encode($emparray);

}
	
else{

$items = mysqli_query($con,"SELECT code, `gencode`, `color`, `stock`, `cat`, `sizesetcode`, `desc`, `hsncode`, `unit`, `pnamount`,  `gstper`, `ratiotot`,taxtype FROM prodreg");

	while($row = mysqli_fetch_array($items)) 
	{
		$gstresult = mysqli_query($con,"SELECT * FROM master  where mstype = 'TAXTYPE' and code='$row[taxtype]'");
       $gstrow = mysqli_fetch_array($gstresult);
	   
	   $clientgst = substr($_GET['gstin'],0,2);
	   $inhousegst = substr($_SESSION['SESS_SERTAX'],0,2);
	   if($_GET['gstin']!=''){
		   
		 if(trim($clientgst)==trim($inhousegst)){
			 $cgst= $gstrow['desc']/2;
			 $sgst= $gstrow['desc']/2;
			 $igst= 0;
			 }
			 else{
			 $cgst= 0;
			 $sgst= 0;
			 $igst= $gstrow['desc']; 
			  }
	   }
	   else{
		   $cgst= 0;
		   $sgst= 0;
		   $igst= 0; 
		   
		   }
	 
	  echo $row['code']."|".$row['cat']."|".$row['color']."|".$row['desc']."|".$row['hsncode']."|".$row['pnamount']."|".$row['qty']."|".$row['gstper']."|".$row['reprocess']."|".$row['demage']."|".$row['ratiotot']."|".$row['gencode']."|".$cgst."|".$sgst."|".$igst."\n";
	
	
	}

}

mysqli_close($con);


?>
