<?php 
@session_start();
$db='laabh';
$conn = mysql_connect('localhost', 'akhilagya', 'abhinay@2018AB') or die ("connection not found");
	mysql_select_db($db) or die ("connection not found");

$result=$_REQUEST["item_name"];
            $result_explode = explode('|', $result);
            $item_name = $result_explode[0];
            $pur_price =  $result_explode[1];
			 $sell_price =  $result_explode[2];

$sqlitm=mysql_query('select item_id,item_name,unit_id,unit_name,sell_price,pur_price as unit_price,sum(pur_qty) as pur_qty,hsn_code,cgst,sgst,igst from view_purchase_det where session_login_id ="'.$_SESSION['login_id'].'" and item_name like "%'. $item_name .'%" and pur_price ="'.$pur_price.'" and sell_price = "'.$sell_price.'" group by item_id,item_name,unit_id,unit_name,sell_price order by item_name');
							
							if(mysql_num_rows($sqlitm)>0){
						$row_itm=mysql_fetch_array($sqlitm);

			 $array[] = $row_itm['item_id'];
			  $array[] = $row_itm['unit_name'];
			   $array[] = $row_itm['unit_id'];
			   $array[] = $row_itm['unit_price'];
			   $array[] = $row_itm['sell_price'];
			 
			
			
		
	$index=$row_itm['item_id'];
	$item_id=$row_itm["item_id"];
					$unit_id=$row_itm["unit_id"];
					$sell_price=$row_itm["sell_price"];
					$pur_qty=$row_itm["pur_qty"];
					
					$sqlret="select sum(ret_qty) as purret_qty from view_purchasereturn_det where session_login_id = '".$_SESSION['login_id']."' and item_id='$item_id' and unit_id='$unit_id' and sell_price='$sell_price'";
					$exeret=mysql_query($sqlret);
					$rowsret=mysql_fetch_assoc($exeret);
					$purret_qty=$rowsret["purret_qty"];
					
					$sqlsel="select sum(qty) as sale_qty from view_sales_mstrdet where session_login_id = '".$_SESSION['login_id']."' and item_id='$item_id' and unit_id='$unit_id' and unit_price='$sell_price' and cancel_status=0";
					$exesel=mysql_query($sqlsel);
					$rowssel=mysql_fetch_assoc($exesel);
					$sale_qty=$rowssel["sale_qty"];
					
					$sqlselret="select sum(ret_qty) as saleret_qty from view_saleret_masdet where session_login_id = '".$_SESSION['login_id']."' and item_id='$item_id' and unit_id='$unit_id' and sell_price='$sell_price'";
					$exeselret=mysql_query($sqlselret);
					$rowsselret=mysql_fetch_assoc($exeselret);
					$saleret_qty=$rowsselret["saleret_qty"];
					
					$sqldem="select sum(dem_qty) as dem_qty from tbl_itemdamage_details	 where session_login_id = '".$_SESSION['login_id']."' and item_id='$item_id' and unit_id='$unit_id' and sell_price='$sell_price'";
					$exedem=mysql_query($sqldem);
					$rowsdem=mysql_fetch_assoc($exedem);
					$dem_qty=$rowsdem["dem_qty"];
					
					
						$stock=($pur_qty+$saleret_qty)-($purret_qty+$sale_qty+$dem_qty);
						
						 $array[] = $stock;
						 $array[] = $row_itm['cgst'];
						 $array[] = $row_itm['sgst'];
						 $array[] = $row_itm['igst'];
	
			
			
			
			
		}
		
		 echo json_encode($array);
?>

                  
               
 