<?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')
{
	
 	
  	$sql_search="";?>
	
<?php  


$sql=DB_query("Select id,StockID,item_name,item_desc,mst_unitid,mrp_rate,net_rate from item_master  where  CategoryID = '".$_REQUEST['site']."' and  CompanyId='".$_SESSION['ACGCompanyId']."'  ",$db); ?>
<table width="100%" border="0" style="border:1px solid #333333;" align="right" cellspacing="0" cellpadding="3">
<tr style="height:30px;">
	<td style="border-bottom:1px solid #FF0000;"><strong>Select</strong></td>
	<td style="border-bottom:1px solid #FF0000;"><strong>Item Code</strong></td>
	<td style="border-bottom:1px solid #FF0000;"><strong>Item Name</strong></td>
	<td style="border-bottom:1px solid #FF0000;"><strong>Item Description</strong></td>
	<td style="border-bottom:1px solid #FF0000;"><strong>UOM</strong></td>
	<td style="border-bottom:1px solid #FF0000;"><strong>Stock Bal</strong></td>
</tr>
	<?php	$i=0;
	if(DB_num_rows($sql)>0)
	{
		while($myrow=DB_fetch_array($sql))
	  	{ 	
		$parameter=$myrow['id'];
		$op=openingBalance($function_filter,$myrow['id']);
		//echo "openingBalance"."<br>";
		$in_1=receivedMRN($function_filter,$myrow['id']);
		//echo "receivedMRN"."<br>";
		$out_1=issueSlip($function_filter,$myrow['id']);
		// echo "issueSlip"."<br>";
		$out_2=issueSiteToSite($function_filter,$myrow['id']);		
		// echo "issuesitetosite"."<br>";
		$in_2=receivedSiteToSite($function_filter,$myrow['id']);
		// echo " receivesitetosite"."<br>";
		$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=return_rejection($function_filter,$myrow['id']);
		$in_4=Rgpreturn($function_filter,$myrow['id']);
		$invalue=($op+$in_1[0]+$in_2+$in_3+$in_4);
		
		$outvalue=($out_1+$out_2+$out_3+$out_4+$out_5);
		$tot=trim($invalue)-trim($outvalue);
  ?>
 <tr bgcolor="#c1c1c1">
	<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 $myrow['StockID'];?>','<?php echo  $myrow['item_name'];?>','<?php echo $myrow['item_desc'];?>','<?php echo $myrow['net_rate'];?>','<?php echo $myrow['mrp_rate'];?>',<?php echo $total_current; ?>,'<?php echo $i;?>')"/></td>
	<td><strong><?php echo $myrow['StockID'];?></strong></td>
	<td><?php echo  $myrow['item_name'];?></td>
	<td><?php echo $myrow['item_desc'];?></td>
	<td><?php $unit=$s->getField('unitsofmeasure','unitid',$myrow['unit'],'unitname'); echo $unit;?></td>
	<td><?php echo $total_current; ?></td>
</tr>
	<?php $i++;} }?>
 </table>
 <?php }else {?>

	
<?php  
$sql=DB_query("Select id,StockID,item_name,item_desc,mst_unitid,mrp_rate,net_rate from item_master where   CompanyId='".$_SESSION['ACGCompanyId']."'",$db); ?>
<table width="100%" border="0" style="border:1px solid #333333;" align="right" cellspacing="0" cellpadding="3">
<tr style="height:30px;">
	<td style="border-bottom:1px solid #FF0000;"><strong>Select</strong></td>
	<td style="border-bottom:1px solid #FF0000;"><strong>Item Code</strong></td>
	<td style="border-bottom:1px solid #FF0000;"><strong>Item Name</strong></td>
	<td style="border-bottom:1px solid #FF0000;"><strong>Item Description</strong></td>
	<td style="border-bottom:1px solid #FF0000;"><strong>UOM</strong></td>
	<td style="border-bottom:1px solid #FF0000;"><strong>Stock Bal</strong></td>
</tr>
	<?php	$i=0;
	if(DB_num_rows($sql)>0)
	{
		while($myrow=DB_fetch_array($sql))
	  	{ 	
		$parameter=$myrow['id'];
		$op=openingBalance($function_filter,$myrow['id']);
		//echo "openingBalance"."<br>";
		$in_1=receivedMRN($function_filter,$myrow['id']);
		//echo "receivedMRN"."<br>";
		$out_1=issueSlip($function_filter,$myrow['id']);
		// echo "issueSlip"."<br>";
		$out_2=issueSiteToSite($function_filter,$myrow['id']);		
		// echo "issuesitetosite"."<br>";
		$in_2=receivedSiteToSite($function_filter,$myrow['id']);
		// echo " receivesitetosite"."<br>";
		$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=return_rejection($function_filter,$myrow['id']);
		$in_4=Rgpreturn($function_filter,$myrow['id']);
		$invalue=($op+$in_1[0]+$in_2+$in_3+$in_4);
		
		$outvalue=($out_1+$out_2+$out_3+$out_4+$out_5);
		$tot=trim($invalue)-trim($outvalue);


$total_current=$tot;
  ?>
 <tr bgcolor="#c1c1c1">
	<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 $myrow['StockID'];?>','<?php echo  $myrow['item_name'];?>','<?php echo $myrow['item_desc'];?>','<?php echo $myrow['net_rate'];?>','<?php echo $myrow['mrp_rate'];?>',<?php echo $total_current; ?>,'<?php echo $i;?>')"/></td>
	<td><strong><?php echo $myrow['StockID'];?></strong></td>
	<td><?php echo  $myrow['item_name'];?></td>
	<td><?php echo $myrow['item_desc'];?></td>
	<td><?php $unit=$s->getField('unitsofmeasure','unitid',$myrow['unit'],'unitname'); echo $unit;?></td>
	<td><?php echo $total_current; ?></td>
</tr>
	<?php $i++;} }?>
 </table>




<?php }?>

<?php 

if($_REQUEST['q']!='')
{		
	  $sql_search="Select id,StockID,item_name,item_desc,mst_unitid,mrp_rate,net_rate from item_master where  StockID Like '%".$_REQUEST['q']."%' || item_name Like '%".$_REQUEST['q']."%'";
	$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" style="border:1px solid #333333;" align="right" cellspacing="0" cellpadding="3">

	<?php 
	if(DB_num_rows($search_result)>0)
	{
		while($myrow=DB_fetch_array($search_result))
	  	{ 	
	  		$parameter=$myrow['id']; 
			
			$op=openingBalance($function_filter,$myrow['id']);
		//echo "openingBalance"."<br>";
		$in_1=receivedMRN($function_filter,$myrow['id']);
		//echo "receivedMRN"."<br>";
		$out_1=issueSlip($function_filter,$myrow['id']);
		// echo "issueSlip"."<br>";
		$out_2=issueSiteToSite($function_filter,$myrow['id']);		
		// echo "issuesitetosite"."<br>";
		$in_2=receivedSiteToSite($function_filter,$myrow['id']);
		// echo " receivesitetosite"."<br>";
		$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=return_rejection($function_filter,$myrow['id']);
		$in_4=Rgpreturn($function_filter,$myrow['id']);
		$invalue=($op+$in_1[0]+$in_2+$in_3+$in_4);
		
		$outvalue=($out_1+$out_2+$out_3+$out_4+$out_5);
		$tot=trim($invalue)-trim($outvalue);
		
		
		$total_current=$tot;
			
			
			
			
			
			
			
			
			
			
			
			?>
 <tr bgcolor="#c1c1c1">
	<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 $myrow['StockID'];?>','<?php echo  $myrow['item_name'];?>','<?php echo $myrow['item_desc'];?>','<?php echo $myrow['net_rate'];?>','<?php echo $myrow['mrp_rate'];?>',<?php echo $total_current; ?>,'<?php echo $i;?>')"/></td>
	<td><strong><?php echo $myrow['StockID'];?></strong></td>
	<td><?php echo  $myrow['item_name'];?></td>
	<td><?php echo $myrow['item_desc'];?></td>
	<td><?php $unit=$s->getField('unitsofmeasure','unitid',$myrow['unit'],'unitname'); echo $unit;?></td>
	<td><?php echo $total_current; ?></td>
</tr>
	<?php $i++;} }?>
</table>
<?php }?>

<?php if($_REQUEST['q2']!='')
{		
	 $sql_search="Select id,StockID,item_name,item_desc,mst_unitid,mrp_rate,net_rate 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="9%"><input type="checkbox" name="row_id[<?php echo $i;?>]" id="row_id_<?php echo $i;?>" value="<?php echo $parameter;?>"<?php echo $c;?> /></td>
      <td width="14%"><strong><?php echo $myrow['StockID'];?></strong></td>
      <td width="24%"><?php echo $myrow['item_name'];?></td>
  	  <td width="34%"><?php echo $myrow['item_desc'];?></td>
       <td width="19%"><?php $unit=$s->getField('unitsofmeasure','unitid',$myrow['unit'],'unitname'); echo $unit;?></td>
     
    </tr>
<?php $i++;
		} 
}?>
<input type="hidden" name="row_sount" id="row_count" value="<?php echo $i;?>">
</table>

<?php 
}
?>




	  		