<?php
//user_action.php
include('db_con.php');
include('function.php');
 		stock_instore($connect);
		$query = "
		SELECT * FROM items WHERE item_id = :item_no";
		
		$statement = $connect->prepare($query);
		$statement->execute(
			array(
				':item_no'	=>	$_POST["item_no"]
			)
		);
		$result = $statement->fetchAll();
		foreach($result as $row)
		{
			
			
			
           $output['item_name']          =  $row['item_name'];
           $output['stock']          =  $row['stock'];
          
          
		}
		$sql = "select s.store_name,sum(d.purchase-d.sale-d.pr+d.sr+d.qty_in-d.qty_out-qty_from+qty_to) as stock from
		 stock_instore d, store s where s.store_id=d.store_id and 
		  d.item_no = '".$_POST["item_no"]."' group by store_name";
		   $statement = $connect->prepare($sql);
		 $statement->execute();
		  
		 
		 $result = $statement->fetchAll();
		
 			$item_detail = '';
 			$item_detail .='
 			<div class="row">
 			<div class="col-md-6">
 			<table width ="100%">
 			<tr>
 			<th>Store</th>
 			<th>Stock</th>
 			</tr>
 			';
			foreach($result as $row)
			 {
			  
			  $stock = $row["stock"];
			$item_detail .= '
			  
			  
			  
			<tr>
			  <td width="50%">'.$row["store_name"].'</td>
			   <td width="50%" class="rightside"><b>'.number_format($stock, 2).'</b></td>
			  
			   
			    
			   </tr>
			  ';
			   
			  }
			  $item_detail .='</table></div>';
			
				
				
				
 			
			  $output['item_detail'] = $item_detail;
		echo json_encode($output);
?>