<?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'];
$function_filter[]=$_REQUEST['site1'];
$function_filter[]=$_REQUEST['store1'];
$data_date=explode('/',$_REQUEST['date1']);
$date55=$data_date[2].'-'.$data_date[1].'-'.$data_date[0];
$date22= strtotime(date("Y-m-d", strtotime($date55)) . " +0 day");
if($_REQUEST['date']=='')
$date1=date('Y-m-d');
else
$date1= date("Y-m-d",$date22);
$function_filter[]=$date1;
if($_REQUEST['site']!='')
{	
 	
  	$sql_search="";?>
	
<?php 
$sql=DB_query("Select id,StockID,item_name,item_desc,mst_unitid,mrp_rate,net_rate,item_exciable from item_master  where  item_exciable = '".$_REQUEST['site']."' and CompanyId='".$_SESSION['ACGCompanyId']."' ",$db); ?>
<table width="100%" border="0" cellspacing="3" cellpadding="2" align="center">
<tr>
<th width="5%"><strong>SELECT</strong></th>
<th width="20%"><strong>ITEM CODE</strong></th>
<th width="20%"><strong>ITEM NAME</strong></th>
<th width="35%"><strong>ITEM DESCRIPTION </strong></th>
<th width="20%"><strong>UNIT</strong></th>
<th width="20%"><strong>Stock </strong></th>
<th width="20%"><strong>Price</strong></th>
</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']);
$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']);
 $out_6=dispatchsaleorder($function_filter,$myrow['id']);
$invalue=($op+$in_1+$in_2+$in_3+$in_4+$in_5);
$outvalue=($out_1+$out_2+$out_3+$out_4+$out_5+$out_6);
$tot=trim($invalue)-trim($outvalue);
$total_current=$tot;
$excise=$myrow['item_exciable'];
$unit=$s->getField('unitsofmeasure','unitid',$myrow['mst_unitid'],'unitname');
  ?>
 <tr bgcolor="#CCCCCC">
      <td width="9%"><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 $i;?>')"/></td>
      <td width="20%"><strong><?php echo $myrow['StockID'];?></strong></td>
	     <td width="20%"><?php echo  $myrow['item_name'];?></td>
      <td width="35%"><?php echo $myrow['item_desc'];?></td>
      <td width="20%"><?php $unit=$s->getField('unitsofmeasure','unitid',$myrow['mst_unitid'],'unitname'); echo $unit;?></td>
	  <td width="22"><?php echo $total_current; ?></td>
	  <td width="22"><?php echo $myrow['net_rate']; ?></td>
    </tr>
<?php $i++;} }?>
 </table>
 <?php }
 
 
 if($_REQUEST['site2']!='')
{	 	
 $sql_search="";?>
	
<?php  

$sql=DB_query("Select id,StockID,item_name,item_desc,mst_unitid,mrp_rate,net_rate,item_exciable from item_master  where  CompanyId='".$_SESSION['ACGCompanyId']."' and  (item_name  like '%".$_REQUEST['site2']."%' ||  StockID like '%".$_REQUEST['site2']."%')",$db); ?>
<table width="100%" border="0" cellspacing="3" cellpadding="2" align="center">
<tr>
<th width="5%"><strong>SELECT</strong></th>
<th width="20%"><strong>ITEM CODE</strong></th>
<th width="20%"><strong>ITEM NAME</strong></th>
<th width="35%"><strong>ITEM DESCRIPTION </strong></th>
<th width="20%"><strong>UNIT</strong></th>
<th width="20%"><strong>Stock </strong></th>
<th width="20%"><strong>Price</strong></th>
</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']);
 $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']);
$out_6=dispatchsaleorder($function_filter,$myrow['id']);
$invalue=($op+$in_1+$in_2+$in_3+$in_4+$in_5);
$outvalue=($out_1+$out_2+$out_3+$out_4+$out_5+$out_6);
$tot=trim($invalue)-trim($outvalue);
$total_current=$tot;
$excise=$myrow['item_exciable'];
$unit=$s->getField('unitsofmeasure','unitid',$myrow['mst_unitid'],'unitname');?>
<tr bgcolor="#CCCCCC">
      <td width="9%"><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 $i;?>')"/></td>
      <td width="20%"><strong><?php echo $myrow['StockID'];?></strong></td>
	     <td width="20%"><?php echo  $myrow['item_name'];?></td>
      <td width="35%"><?php echo $myrow['item_desc'];?></td>
      <td width="20%"><?php $unit=$s->getField('unitsofmeasure','unitid',$myrow['mst_unitid'],'unitname'); echo $unit;?></td>
	  <td width="22"><?php echo $total_current; ?></td>
	  <td width="22"><?php echo $myrow['net_rate']; ?></td>
    </tr>
<?php $i++;} }?>
</table>
<?php } ?>




	  		