<?php  
session_start(); 
	include("connect.php");	
	include("connectp.php");
	header("Access-Control-Allow-Origin: *");
	
	$cmpmid=$_SESSION['linkarisecmpmid'];
	$brmid=$_SESSION['linkarisebranchid'];
	$umid = $_SESSION['linkariseumid'];
	
	
		$q = $db7->prepare("select * from res_item_master where cmpmid=$cmpmid");
	//$q->bindValue(':p1', "$par1");
	//$q->bindValue(':p2',  "$par2");
	$q->execute();
	
	
	
	
	$response = array();
	$posts = array();
	
	$result="0";
	
	if ($q->rowCount() > 0)
	{
		$i=1;
		while($i<=$q->rowCount())
		{
			$rt = $q->fetch(PDO::FETCH_ASSOC);
			
			 	$itemid=$rt['itemid'];
				
				 $uedit="<a href='itemedit.php?id=".$rt['itemid']."' data-toggle='tooltip' data-placement='top' title='Edit' class='fa fa-edit fa-lg'>  </a>"; 
			
			
				 $udelete="<a href='itemdelete.php?id=".$rt['itemid']."' onclick='return confirm(&#39;Are you sure you want to delete ?&#39;);' data-toggle='tooltip' data-placement='top' title='Delete' class='far fa-trash-alt fa-lg'>  </a>"; 
				
				
				 $view="<a href='itemdetail.php?id=".$rt['itemid']."' data-toggle='tooltip' data-placement='top' title='View' class='fa fa-eye fa-lg' >  </a>"; 
				
				$duplicate="<form action='itemadd.php' method='post' style='flex: 1; margin-right: 2px;'><button  class='fa fa-clone fa-lg' name='itemid' type='submit' value='$itemid'></button></form> ";
				$duplicate="";
				/* $duplicate="<a href='itemadd.php?id=".$rt['itemid']."' data-toggle='tooltip' data-placement='top' title='Duplicate' class='fa fa-clone' >  </a>"; */
				
				$op=$view."&nbsp;&nbsp;&nbsp; ".$uedit."&nbsp;&nbsp;&nbsp; ".$udelete;
				
				$itemcode=$rt['itemcode'];
				$itemcategory=$rt['itemcategory'];
				$itemname=$rt['itemname'];
				$itemhsncode=$rt['itemhsncode'];
				$itemunit=$rt['itemunit'];
				$itemtaxper=$rt['itemtaxper'];
				$itemsalesrate=$rt['itemsalesrate'];
				$iunitmasterstock=$rt['iunitmasterstock'];
				
				$iinqty='';
				$eve1 = "select * from res_item_detail where itemid ='$itemid'";

				$re1 = mysqli_query($conn, $eve1);
																			
				if(mysqli_num_rows($re1) > 0)

				{											
																				
				while($rt1 = mysqli_fetch_assoc($re1))
				{
					$iinqty=$rt1['iinqty'];
						
				}
																				 
				}
				
				$iunitmasterstock=
						"<div style='display: flex; flex-direction: row;'><form action='itemstockdetail.php' method='post' style='flex: 1; margin-right: 2px;'><button name='itemid' type='submit' value='$itemid'>$iunitmasterstock</button></form>";

				/* $iunitmasterstock="<a href='itemstockdetail.php?id=".$rt['itemid']."'> $rt[iunitmasterstock]</a>"; */
						

				
				$posts[] = array('srno'=> $i++, 'iunitmasterstock'=> $iunitmasterstock,'itemcode'=> $itemcode,'itemcategory'=> $itemcategory,'itemname'=> $itemname, 'itemtaxper'=> $itemtaxper, 'itemhsncode'=> $itemhsncode, 'iunitmaster'=> $itemunit, 'itemsalesrate'=> $itemsalesrate, 'op'=> $op);
		}
		 
		$response['posts'] = $posts;
		echo stripslashes(json_encode( array('data' => $posts)));
		//mysqli_close($conn);
		//return;
	}
	
   else
	{
		$result="0";
		$msg="Invalid Error";
		
		$posts[] = array('p1'=> $result,'p2'=> $msg);
	
		$response['posts'] = $posts;
		echo stripslashes(json_encode( array('item' => $posts)));
	}
   
	mysqli_close($conn);	
?>