<?php
ob_start();
$PageSecurity = 11;
include('includes/session.inc');
include('includes/function_lib.php');
include('includes/SQL_CommonFunctions.inc');
include('includes/stockcalculation.php');
//echo $_REQUEST['q2'];

if($_REQUEST['site']!='0')
{
//$data1='';
//	   $data1.="<select name='subcategory' id='subcategory' onchange='getItems(this.value)'>";
//  	 $data1.="<option>Select Sub Group</option>";
//		  $store_sql = "SELECT * FROM stockcategory where stockmaincategory ='".$_REQUEST['site']."'";
//		$store_result = DB_query($store_sql,$db);
//		while($store_row = DB_fetch_array($store_result))
//		{
//			$p1='';
//			if($store_row['categoryid'] == $_REQUEST['subcategory'])	
//			$p1="selected";		
//		
//            $data1.="<option value='".$store_row['categoryid']."' .'".$p1."'>".$store_row['categorydescription']."</option>";
//           } 
//	$data1.="</select>";	
//	$catid=$s->getField('stockmaincategory','id',$_REQUEST['site'],'stockmaincategoryid');
	//**************************************************************************************//
	
	//$sql_search1=DB_query("Select * from item_master where  CategoryID = '".$_REQUEST['site']."'",$db);
	//$numrow=DB_num_rows($sql_search1);
	//echo $numrow;
	//$records=0;
	//$pagelimit=15;
	
	
     
     



/////////////// WE have to find out the number of records in our table. We will use this to break the pages///////


//echo $query2=" SELECT * FROM item_master  where  CategoryID = '".$_REQUEST['site']."'";
//$result2=DB_query($query2,$db);
////echo DB_error_msg($db);
//$nume=DB_num_rows($result2);
	//*************************************************************************************//
	//$sql_search="Select * from item_master where  CategoryID Like '%".$catid."%'  ||  CategoryID Like '%".$_REQUEST['site']."%' ";
 	//$x=explode(',',$_SESSION['Telephonic']);
//print_r($x);
  	$sql_search="";?>
	
<?php  
//echo "Select id,StockID,item_name,item_desc,unit,mrp_rate,net_rate from item_master  where  CategoryID = '".$_REQUEST['site']."' 
// and SubCategoryID='".$_REQUEST['mainid']."'";


$sql=DB_query("Select mst_unitid,id,StockID,item_name,item_desc,unit,mrp_rate,net_rate from item_master  where  CategoryID = '".$_REQUEST['site']."'  ",$db); ?>
	<table width="100%" border="0" cellspacing="3" cellpadding="2" align="center">
	<?php	$i=0;
	if(DB_num_rows($sql)>0)
	{
		while($myrow=DB_fetch_array($sql))
	  	{ 	
		$parameter=$myrow['id'];
		$op=openingBalance($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']);
		$out_4=Rgpchallan($function_filter,$myrow['id']);
		$out_5=Nrgp($function_filter,$myrow['id']);
		$in_3=receivedReturn($function_filter,$myrow['id']);		 
		$in_4=Rgpreturn($function_filter,$myrow['id']);
		$in_5=FinishedMR($function_filter,$myrow['id']);
		//$out_6=invoice($function_filter,$row1['id']);
		//$out_7=dispatch($function_filter,$row1['id']);	
		$invalue=($op+$in_1[0]+$in_2+$in_3+$in_4+$in_5);
		//$outvalue=($out_1+$out_2+$out_3+$out_4+$out_5+$out_6+$out_7);
		$outvalue=($out_1+$out_2+$out_3+$out_4+$out_5);
		$tot=trim($invalue)-trim($outvalue);
		$total_current=$tot;
  ?>
 <tr bgcolor="#CCCCCC">
      <td width="58"><input type="checkbox" onclick="getItemsList('<?php echo $parameter;?>','<?php echo $myrow['StockID'];?>','<?php echo $myrow['item_name'];?>','<?php echo $unit;?>','<?php echo $i;?>');" name="row_id[]" id="row_id_<?php echo $i;?>" value="<?php echo $parameter;?>"	<?php echo $c;?> /></td>
      <td width="142"><strong><?php echo $myrow['StockID'];?></strong></td>
	     <td width="162"><?php echo  $myrow['item_name'];?></td>
      <td>
	<?php $unit=$s->getField('unitsofmeasure','unitid',$myrow['mst_unitid'],'unitname'); echo $unit;?>
	 </td>
    </tr>
<?php $i++;} }?>
 </table>
 <?php }else {?>

	
<?php  
$sql=DB_query("Select mst_unitid,id,StockID,item_name,item_desc,unit,mrp_rate,net_rate from item_master",$db); ?>
	<table width="100%" border="0" cellspacing="3" cellpadding="2" align="center">
	<?php	$i=0;
	if(DB_num_rows($sql)>0)
	{
		while($myrow=DB_fetch_array($sql))
	  	{ 	
		$parameter=$myrow['id'];
		$op=openingBalance($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']);
		$out_4=Rgpchallan($function_filter,$myrow['id']);
		$out_5=Nrgp($function_filter,$myrow['id']);
		$in_3=receivedReturn($function_filter,$myrow['id']);		 
		$in_4=Rgpreturn($function_filter,$myrow['id']);
		$in_5=FinishedMR($function_filter,$myrow['id']);
		//$out_6=invoice($function_filter,$row1['id']);
		//$out_7=dispatch($function_filter,$row1['id']);	
		$invalue=($op+$in_1[0]+$in_2+$in_3+$in_4+$in_5);
		//$outvalue=($out_1+$out_2+$out_3+$out_4+$out_5+$out_6+$out_7);
		$outvalue=($out_1+$out_2+$out_3+$out_4+$out_5);
		$tot=trim($invalue)-trim($outvalue);
		$total_current=$tot;
  ?>
 <tr bgcolor="#CCCCCC">
      <td width="58"><input type="checkbox" onclick="getItemsList('<?php echo $parameter;?>','<?php echo $myrow['StockID'];?>','<?php echo $myrow['item_name'];?>','<?php echo $unit;?>','<?php echo $i;?>');" name="row_id[]" id="row_id_<?php echo $i;?>" value="<?php echo $parameter;?>"	<?php echo $c;?> /></td>
      <td width="142"><strong><?php echo $myrow['StockID'];?></strong></td>
	   <td width="162"><?php echo  $myrow['item_name'];?></td>
      <td>
	 	<?php $unit=$s->getField('unitsofmeasure','unitid',$myrow['mst_unitid'],'unitname'); echo $unit;?>
	 </td>
    </tr>
<?php $i++;} }?>
 </table>




<?php }?>

<?php 

if($_REQUEST['q']!='')
{		
	 $sql_search="Select * from item_master where SubCategoryID= '".$_REQUEST['q']."' and CompanyId='".$_SESSION['ACGCompanyId']."' ||  StockID Like '%".$_REQUEST['q']."%' and CompanyId='".$_SESSION['ACGCompanyId']."' || item_name Like '%".$_REQUEST['q']."%' and CompanyId='".$_SESSION['ACGCompanyId']."'";
	$search_result = DB_query($sql_search, $db);
	//echo $sql_search;
$i=0;
  	if($i%2==0)
	{$bg="#CCCCCC";}
	else
	$bg="#C8BECB";
	?>

	<table width="100%" border="0" cellspacing="3" cellpadding="2" align="center">
	<?php 
	if(DB_num_rows($search_result)>0)
	{
		while($myrow=DB_fetch_array($search_result))
	  	{ 	
	  		$parameter=$myrow['id']; ?>
 <tr bgcolor="<?php echo $bg;?>">
    <td width="58">
	<input type="checkbox" onclick="getItemsList('<?php echo $parameter;?>','<?php echo $myrow['StockID'];?>','<?php echo $myrow['item_name'];?>','<?php echo $unit;?>','<?php echo $i;?>');" name="row_id[]" id="row_id_<?php echo $i;?>" value="<?php echo $parameter;?>"	<?php echo $c;?> /></td>
      <td width="142"><strong><?php echo $myrow['StockID'];?></strong></td>
      <td width="162"><?php echo $myrow['item_name'];?></td>
      <td>
	<?php $unit=$s->getField('unitsofmeasure','unitid',$myrow['mst_unitid'],'unitname'); echo $unit;?>
	 </td>
     
    </tr>
<?php $i++;}}
else {?>

NO Record Found
<?php } ?>
</table>
<?php }?>

<?php if($_REQUEST['q2']!='')
{		
	 $sql_search="Select * from item_master where item_no Like '%".$_REQUEST['q2']."%'";
	$search_result = DB_query($sql_search, $db);
	//echo $sql_search;
$i=0;
  	if($i%2==0)
	{$bg="#CCCCCC";}
	else
	$bg="#C8BECB";
	?>
	<table width="100%" border="0" cellspacing="3" cellpadding="2" align="center">
	<?php 
	if(DB_num_rows($search_result)>0)
	{
		while($myrow=DB_fetch_array($search_result))
	  	{ 	
	  		$parameter=$myrow['id'];
	  		$c='';
			
  ?>
 <tr bgcolor="<?php echo $bg;?>">
      <td width="58"><input type="checkbox" onclick="getItemsList('<?php echo $parameter;?>','<?php echo $myrow['StockID'];?>','<?php echo $myrow['item_name'];?>','<?php echo $unit;?>','<?php echo $i;?>');" name="row_id[]" id="row_id_<?php echo $i;?>" value="<?php echo $parameter;?>"	<?php echo $c;?> /></td>
      <td width="142"><strong><?php echo $myrow['StockID'];?></strong></td>
      <td width="162"><?php echo $myrow['item_name'];?></td>
  	 <td>
	 <?php $unit=$s->getField('unitsofmeasure','unitid',$myrow['mst_unitid'],'unitname'); echo $unit;?>
	 </td>
    </tr>
<?php $i++;
		} 
} ?>

<input type="hidden" name="row_sount" id="row_count" value="<?php echo $i;?>">
</table>

<?php 
}
?>

	  		