<?php $PageSecurity = 2;
include('includes/DefineSuppTransClass.php');
include('includes/DefinePOClass.php');
include('includes/SQL_CommonFunctions.inc');
include('includes/session.inc');
include('includes/function_lib.php');
include('includes/stockcalculation.php');

//For User Store
$sql_user_store="select hmis_storeid,StoreCode from www_users left join storetype on storetype.id=www_users.hmis_storeid where www_users.id='".$_SESSION['UserID']."'";
$result_user_store=DB_query($sql_user_store,$db);
$rs_user_store=DB_fetch_array($result_user_store);
$main_store=$rs_user_store[0];

$sql_other_store="select store_id,StoreCode from www_users_dtls left join storetype on storetype.id=www_users_dtls.store_id where user_id='".$_SESSION['UserID']."'";
$result_other_store=DB_query($sql_other_store,$db);
while($rs_other_store=DB_fetch_array($result_other_store))
{
  $store[]=$rs_other_store['store_id'];
}
if(!empty($store))
{
  $get_store_id=implode(",",$store);
}

if($main_store!=0 && $get_store_id!='')
{
	$all_store=$main_store.",".$get_store_id;
}
else
{
	$all_store=$main_store;
}

$function_filter[]=$_REQUEST['site'];
$function_filter[]=$all_store;
$function_filter[]=date('Y-m-d');       
							
?>
<link href="css/professional/default.css" rel="stylesheet" type="text/css" />
<link href="css/new_mxerp.css" rel="stylesheet" type="text/css" />
<div class="body_contain">
<div class="tab_div">
<form name="form1" action="" method="post">
<table width="100%" border="0" cellspacing="0" cellpadding="3">
	<tr class="row1">
		<td width="13%" align="right">Main Category</td>
		<td width="35%"><select id="srch_cateory" onchange="getSubCategory()">
			<option value="">Select</option>
			<?php
	        $item_query="SELECT * FROM stockmaincategory WHERE CompanyId='".$_SESSION['ACGCompanyId']."'";
			$res=DB_query($item_query ,$db);
			while($item_row1=DB_fetch_array($res)){
			$p='';
			if($item_row1['id'] == $_REQUEST['CategoryID'])	
			$p="selected";?>
			 <option value="<?php echo $item_row1['id'];?>"<?php echo $p;?>><?php echo $item_row1['stockmaincategoryname'];?></option>
	               <?php }?>
	      </select></td>
	      <td width="13%" align="right">Sub Category</td>
	      <td><select id="srch_subcateory" name="srch_subcateory" onchange="getdata1()">
			<option value="">Select</option>
			<?php
	        $item_subquery="SELECT id,categorydescription FROM stockcategory where CompanyId='".$_SESSION['ACGCompanyId']."'";
			$subres=DB_query($item_subquery ,$db);
			while($item_subrow=DB_fetch_array($subres)){
			$p='';
			if($item_subrow['id'] == $_REQUEST['CategoryID'])	
			$p="selected";?>
			 <option value="<?php echo $item_subrow['id'];?>"<?php echo $p;?>><?php echo $item_subrow['categorydescription'];?></option>
	       <?php }?>
	      </select></td>     
	</tr>
	<tr class="row1">
	   	<td align="right">Code</td>
		<td><input type="text" id="srch_code" onkeyup="getdata1();" placeholder="Item Code"/></td>
	  	<td align="right">Name</td>
		<td><input type="text" id="srch_name" onkeyup="getdata1();" placeholder="Item Name"/></td>  
	</tr>
</table>
<br />
<div id="ItemListDiv">
<table width="100%" border="0" cellspacing="0" cellpadding="3" class="thborder">
<thead>
<tr>
	<th width="5%">Select</th>
	<th width="14%">Item Code</th>
	<th>Item Name</th>
	<th width="10%">UOM</th>
	<th width="10%">Stock Balance</th>	
</tr>
</thead>
<tbody>
<?php 
         /*  if($get_store_id!='')
          {
		    $sql=DB_query("SELECT  * FROM item_master ORDER BY StockID DESC LIMIT 10".$w,$db);
		}
		else if($main_store!='')
		{
           $sql=DB_query("SELECT  * FROM item_master ORDER BY StockID DESC LIMIT 10".$w,$db);
		}
		else
		{ */
		  $sql=DB_query("SELECT  * FROM item_master  ORDER BY StockID DESC LIMIT 10".$w,$db);	
		//}
 
$i=0;
if(DB_num_rows($sql)>0)
{
	while($myrow=DB_fetch_array($sql))
	{ 	
		$parameter=$myrow['id'];
		$unitname= $s->GetFieldValue('unitsofmeasure',"unitid='".$myrow['mst_unitid']."'",'unitname');
		 $op=openingBalancepr($function_filter,$myrow['id']);
				$in_1=receivedMRN($function_filter,$myrow['id']);
				$out_1=issueSlip($function_filter,$myrow['id']);
				$out_2=issueSiteToSite($function_filter,$myrow['id']);    
				$in_2=receivedSiteToSite($function_filter,$myrow['id']);
				$out_3=issueMatarialReturn($function_filter,$myrow['id']);
				$in_3=receivedReturn($function_filter,$myrow['id']);  
				//$out_4=Rgpchallan($function_filter,$myrow['id']);
				//$out_5=Nrgp($function_filter,$myrow['id']);
				//$in_4=Rgpreturn($function_filter,$myrow['id']);  
				//$in_5=FinishedMR($function_filter,$myrow['id']);
				$in_6=MaterialConReceived($function_filter,$myrow['id']);
				$out_6=MaterialConIssue($function_filter,$myrow['id']);
				$in_7=PhysicalStockPlus($function_filter,$myrow['id']);
				$out_7=PhysicalStockMinus($function_filter,$myrow['id']);
				$out_8=dispatchIssue($function_filter,$myrow['id']);
				//$out_9=jobWorkChallan57Issue($function_filter,$myrow['id']);
				//$in_8=jobWorkChallan57Received($function_filter,$myrow['id']);
				$in_9=directPurchase($function_filter,$myrow['id']);
				$in_10=saleReturn($function_filter,$myrow['id']);
				$out_10=invoice($function_filter,$myrow['id']);
				$out_11=drugissue($function_filter,$myrow['id']);
				$in_11=storereceipt($function_filter,$myrow['id']);
				$out_11=drugissue($function_filter,$myrow['id']);

				$invalue=($op+$in_1+$in_2+$in_3+ $in_6 + $in_7 +$in_9+$in_10+$in_11);
				$outvalue=($out_1+$out_2+$out_3+ $out_6 + $out_7 + $out_8 +$out_10+ $out_11);
				$tot=$invalue-$outvalue;
				$stockallitems=$tot;

			 	$total_current=$stockallitems;?>
			 	
			 	<tr>
					<td><input type="checkbox" name="row_id[<?php echo $i;?>]" id="row_id_<?php echo $i;?>" value="<?php echo $parameter;?>" onclick="getItemsList('<?php echo $parameter;?>','<?php echo htmlspecialchars($myrow['StockID'],ENT_QUOTES);?>','<?php echo  htmlspecialchars($myrow['item_name'], ENT_QUOTES);?>','<?php echo $total_current;?>','<?php echo $unitname; ?>','<?php echo $i;?>')"/></td>
					<td><strong><?php echo htmlspecialchars_decode($myrow['StockID'],ENT_QUOTES);?></strong></td>
					<td><?php echo  htmlspecialchars_decode($myrow['item_name'],ENT_QUOTES);?></td>
					<td><?php echo $unitname;?></td>
					<td><?php echo $total_current;?></td>	
				</tr>
	<?php $i++;} }?>
	</tbody>
 </table>
 </div>
</form>

</div>
</div>
