<?php









//user_action.php









include('db_con.php');




include('function.php');




if (isset($_SESSION['user_id'])) {




		$user_type = $_SESSION['user_type'];




		$user_id = $_SESSION['user_id'];




		$user_name = $_SESSION['user_name'];




		$branch_id = $_SESSION['branch_id'];




		$branch_name = $_SESSION['branch_name'];




		$store_id = $_SESSION['store_id'];




    $store_name = $_SESSION['store_name'];




}else{




	header('Location: login');




	die();




}




if(isset($_POST['btn_action']))









{









	




	if($_POST['btn_action'] == 'fetch_single')




	{









 		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>';




			  $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)




				{




					




					




					




		         $image = '';




				 if($row["item_image"] != '')




				 {




				  $image = '<img src="upload/'.$row["item_image"].'" class="img-thumbnail" width="300" height="300" />';




				 }




				 else




				 {




				  $image = '';




				 }




		          




				}









				$item_detail .=' <br /> ' .''.$image.'




				</div>';









				









				









				




 			




				




 			$output['item_detail']  =  $item_detail;
























		echo json_encode($output);




	}




	




}









?>