



<link rel="stylesheet" href="css/new_mxerp.css">
<script>
	function showItems(str)
{
    if(str=="")
  {
  document.getElementById("itemid").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("itemid").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","Get_itemcode.php?partName="+str,true);
xmlhttp.send();
}
</script>

<?php 
unset($_SESSION['query1']);
$flag=0;
?>

<div class="body_contain">
<div class="tab_div">
	
<h1>Stock Valuation Report</h1>


<form method="post" action="">
   <table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
  	  <tr>
  	    <th class="tabledata1">Branch</th>
  	    <?php 
				
		?>
  	    <td><select name="site" id="site" style="width:82%">
            <option value="">Select Branch</option>
            <?php 
			if($_SESSION['AssignedSites']!='0'){ 
		$site_sql = "SELECT loccode, locationname from locations where CompanyId='".$_SESSION['ACGCompanyId']."' ";}
		else
		{$site_sql = "SELECT loccode, locationname from locations where CompanyId='".$_SESSION['ACGCompanyId']."'";}
		$site_result = DB_query($site_sql,$db);
		while($site_row = DB_fetch_array($site_result))
		{
			$p='';
			if($site_row['loccode'] == $_POST['site'])	
			$p="selected";
		?>
            <option value="<?php echo $site_row['loccode']; ?>" <?php echo $p;?>><?php echo $site_row['locationname']; ?></option>
            <?php } ?>
          </select>       
  	      All 
          <input type="checkbox" name="checkbox" id="checkbox" /></td>
          
  	    <th class="tabledata1">Period</th>
  	    
  	    <td>From :<input type="text" name="frmdate" size="10" id="frmdate" class="datepicker" style="width:40%" /> To <input type="text" name="todate" size="10" id="todata" class="datepicker" style="width:40%" /></td>
  	    </tr>
  	  <tr>
  	    <th class="tabledata1">Group</th>
  	    
  	    <td><select name="group" id="group" style="width:100%">
            <option value="">Select Group</option>
            <?php 
		 $store_sql = "SELECT * FROM stockmaincategory where CompanyId='".$_SESSION['ACGCompanyId']."'";
		$store_result = DB_query($store_sql,$db);
		while($store_row = DB_fetch_array($store_result))
		{
			$p='';
			if($store_row['stockmaincategoryid'] == $_POST['store'])	
			$p="selected";
		
		?>
            <option value="<?php echo $store_row['stockmaincategoryid']; ?>" <?php echo $p;?>><?php echo $store_row['stockmaincategoryname']; ?></option>
            <?php } ?>
          </select>  </td>
  	    <th class="tabledata1">Sub Ggroup</th>
  	    <td><select name="categoryid" id="categoryid" style="width:100%">
            <option value="">Select Sub Ggroup</option>
            <?php 
		 $store_sql = "SELECT * FROM stockcategory where CompanyId='".$_SESSION['ACGCompanyId']."'";
		$store_result = DB_query($store_sql,$db);
		while($store_row = DB_fetch_array($store_result))
		{
			$p='';
			if($store_row['categoryid'] == $_POST['store'])	
			$p="selected";
		
		?>
            <option value="<?php echo $store_row['categoryid']; ?>" <?php echo $p;?>><?php echo $store_row['categorydescription']; ?></option>
            <?php } ?>
          </select> </td>
  	    </tr>
  	  <tr>
  	    <th class="tabledata1">Item Desc</th>
  	    <td><select name="itemdesc" id="itemdesc" style="width:100%">
            <option value="">Select Item Desc</option>
            <?php 
		 $store_sql = "SELECT * FROM item_master  where CompanyId='".$_SESSION['ACGCompanyId']."' group by item_name ";
		$store_result = DB_query($store_sql,$db);
		while($store_row = DB_fetch_array($store_result))
		{
			$p='';
			if($store_row['StockID'] == $_POST['store'])	
			$p="selected";
		
		?>
            <option value="<?php echo $store_row['StockID']; ?>" <?php echo $p;?>><?php echo $store_row['item_name']; ?></option>
            <?php } ?>
          </select></td>
  	    <th class="tabledata1">Method of Calculation</th>
  	  
  	    <td><select name="select4" style="width:100%">
  	      <option>Select</option>
	      </select></td>
  	    </tr>

    </table>
	 <p align="left" style="padding-left:10px;">
      	  <input type="submit" name="view" value="Proceed"></p>
	
	</form>
	
  
  
<div >

<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
    	        <tr style="background-color:#CCCCCC">
    	          <td class="tabledata1">Company Name</td>
    	          <td class="tabledata1">Webtech Packing India Pvt Ltd</td>
    	          <td class="tabledata1">Date From</td>
    	          <td class="tabledata1"><?php echo $_REQUEST['frmdate']; ?>  To <?php echo $_REQUEST['todate']; ?>
    	          </td>
                </tr>
  	        </table>
				
<table width="100%" border="1" cellspacing="0" cellpadding="3">
    <tr>
	<th width="5%"><strong>S.R</strong></th>
      <th width="5%"><strong>Date</strong></th>
	   <th width="31%"><strong>Receiving from / issue to</strong></th>
      <th width="20%"><strong>Transaction No.</strong></th>
       <th width="20%"><strong>Item.</strong></th>
      <th width="10%"><strong>Against Bill/Challan </strong></th>  
    <th width="15%"><center>Received</center></th>
    <th width="15%"><center>Issued</center></th>	   
    <th width="15%"><center>Closing Balance</center></th>
  </tr>  
  <tr> 
   <th colspan="6"></th>
    <td style="padding:0px; margin:0px;">
		<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <th align="left">QTY.</th>
   <th align="left" >Rate</th>
    <th align="left">Value</th>
  </tr>
</table>	</td>
    <td style="padding:0px; margin:0px;">
		<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <th align="left" >QTY.</th>
   <th align="left" >Rate</th>
    <th align="left">Value</th>
  </tr>
</table></td>
 
   <td style="padding:0px; margin:0px;">
		<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <th>QTY.  </th>
   <th>Rate</th>
    <th>Value</th>
  </tr>
</table></td>
  </tr>
<?php 
	$filter = array();
	if($_REQUEST['site']!='')
	{
  	$filter[]=$_REQUEST['site'];
	}
   else
   {
    $sitedata=DB_query("select * from locations where 
     CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
    while($site1=DB_fetch_array($sitedata))
    {
    $site2[]=$site1['loccode']; 
    } 
    
   
    
    $site=implode("','",$site2);
    $filter[]=$site;
    
   }
	if($_POST['from_date']!='')
	{
 	$filter[]=$fdate;
    }
	if($_POST['to_date']!='')
	{ 
	$filter[]=$toyrdate;
	}
	
	
	$filter2=implode(",",$filter);
	if($_REQUEST['frmdate']=='' && $_REQUEST['todate']=='')
   {
    $fdate=$_SESSION['financialYrStart'];
    $toyrdate=$_SESSION['financialYrEnd'];
   }   
   else
   {
    $fdate=FormatDateForSQL($_REQUEST['frmdate']);
    $toyrdate=FormatDateForSQL($_REQUEST['todate']);
   }
   
   if($_REQUEST['group']!='')
   {
   $main_cat_array[]=$_REQUEST['group'];    
   }
   else
   {
   $sql_cat=DB_query("select * from stockmaincategory where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
   while($row2=DB_fetch_array($sql_cat))
   {
   $main_cat_array[]=$row2['id']; 
   }
   }
   
   
   
   
   
   for($rd=0;$rd<count($main_cat_array);$rd++)
   {
   $sql1="select * from item_master where SubCategoryID='".$main_cat_array[$rd]."' ORDER BY StockID ASC";
   
   
    $sql2=$sql1;
	 $sql=DB_query($sql1,$db);
	 $num_row2=DB_num_rows(DB_query($sql2,$db));
    while($row1=DB_fetch_array($sql))
    {
    
    $sqlopen=DB_query("select reveive_date as date,itemcode as itemid,stock as reciveqty,rate,amount
	from opening_stockitemwise  where site in('".$site."') 
	  and reveive_date between '".$fdate."' 
	 and '".$toyrdate."' and itemcode='".$row1['id']."'",$db);
	 $num1=DB_num_rows($sqlopen);
          if($num1>0)
          {
              while($addopen=DB_fetch_array($sqlopen))
              {	
              //$vender=$s->getField('suppliers','id',$addmrn['vendor'],'vendor_name');
           $data[]=array('slipno'=>$addopen['slipno'],'itemid'=>$addopen['itemid'],
           'date'=>$addopen['date'],'reciveqty'=>$addopen['reciveqty'],'issueqty'=>''
            ,'doc'=>'','description'=>'Opening','rate'=>$addopen['rate'],'amount'=>$addopen['amount']);
              }


          }
   
          
          
          
          
          
    }
   }
 
   
   foreach ($data as $key => $row1)
    {
    $volume[$key]= $row1['date'];
	$edition1[$key]=$row1['reciveqty'];
	
    }
    array_multisort($volume,$edition1,SORT_DESC,$data);
	
	if(count($data)>0)
	{
	$var=0;
	$i=1;
	foreach($data as $key=>$value)
	{	
	if($value['description']=='Opening')
	{
	$bgcolor='#999999';
	}
	else
	{
	$bgcolor='#FFFFFF';
	}
   
	
	?>	
  
	 <tr>
	<td><?php echo $i++;?></td>
	<td><?php echo $value['date'];?></td>
	<td><?php echo $value['description'];?></td>
    <td><?php echo $value['slipno'];?></td>
    <td><?php echo $s->getField('item_master','id',$value['itemid'],'item_name');?></td>
    <td><?php echo $value['doc'];?></td>  
     <td style="padding:0px; margin:0px;">
		<table width="100%" border="0" cellspacing="0" cellpadding="4">
		<tr>
    <td width="33%" align="left" style="border-right:#808080 1px solid;"><?php if($value['reciveqty']=='') { echo "0"; } else {	echo $value['reciveqty']; }?></td>
   <td width="30%" align="left" style="border-right:#808080 1px solid;"><?php  if($value['rate']=='') { echo "0"; } else {  echo $value['rate'];}?></td>
    <td align="left" style="text-align:right;"><?php if($value['amount']=='') { echo "0"; } else { echo $value['amount'];}?></td>
  </tr>
</table>	</td>
    <td style="padding:0px; margin:0px;">
		<table width="100%" border="0" cellspacing="0" cellpadding="4">
  <tr>
    <td width="33%" align="left" style="border-right:#808080 1px solid;"><?php if($issueded_qty=='') { echo "0"; } else {	echo $issueded_qty; }?></td>
   <td width="30%" align="left" style="border-right:#808080 1px solid;"><?php if($issueded_rate=='') { echo "0"; } else {  echo  $issueded_rate;}?></td>
    <td align="left" style="text-align:right;"><?php if($issueded_amount=='') { echo "0"; } else { echo $issueded_amount;}?></td>
  </tr>
</table></td>
<td style="padding:0px; margin:0px;">
		<table width="100%" border="0" cellspacing="0" cellpadding="4">
  <tr>
    <td width="33%" align="left" style="border-right:#808080 1px solid;"><?php if($issueded_qty=='') { echo "0"; } else {	echo $issueded_qty; }?></td>
   <td width="30%" align="left" style="border-right:#808080 1px solid;"><?php if($issueded_rate=='') { echo "0"; } else {  echo  $issueded_rate;}?></td>
    <td align="left" style="text-align:right;"><?php if($issueded_amount=='') { echo "0"; } else { echo $issueded_amount;}?></td>
  </tr>
</table></td>

   
  </tr>
    
 
   <?php }  } ?>
 

  </table>
		
</div>

</div></div>


	
