<?php 			function openingStock($itemcode,$itemString) 
				{
				global $db;
				//print_r($itemcode);
				
				$opening_var=explode(",",$itemcode);
				if($opening_var[0]!='')
				{
					$filter[]= "opening_stockitemwise.site='".$opening_var[0]."'";
				}
				if($opening_var[1]!='' && $opening_var[1]!='--')
				{
				$filter[]= "opening_stockitemwise.store='".$opening_var[1]."'";
				}
				if($opening_var[2]!='' && $opening_var[3]!='' && $opening_var[2]!='--'&& $opening_var[3]!='--')
				{
				$filter[]="opening_stockitemwise.reveive_date between '".$opening_var[2]."' and '".$opening_var[3]."'";
				}
				if($itemString != '' && $itemString != '0')
				{
				$filter[]="opening_stockitemwise.itemcode='".$itemString."'";
				}
				
				if($filter != '')
				{
					$filter1 = implode(" and ",$filter);
				}
				if($filter == '')
				{
					$filter1 ="0";
				}
				 $sql= "SELECT SUM(stock) FROM opening_stockitemwise where $filter1";
				$sqlquery=DB_query($sql,$db);
				while($row=DB_fetch_array($sqlquery))
				{
				return ($row['SUM(stock)']); 
				}	
			}
			function receivedQty($itemcode,$itemString)
			{
				global $db;
				$opening_var=explode(",",$itemcode);
				if($opening_var[0]!='')
				{
				$filter[]= "addmrn.site='".$opening_var[0]."'";
				}
				if($opening_var[1]!='' && $opening_var[1]!='--')
				{
				$filter[]= "addmrn.StoreCode='".$opening_var[1]."'";
				}
				if($opening_var[2]!='' && $opening_var[3]!='')
				{
				$filter[]="addmrn.BillDate between '".$opening_var[2]."' and '".$opening_var[3]."'";
				}
				if($itemString != '' && $itemString != '0')
				{
					$filter[]="ta.itemcode='".$itemString."'";
				}
				if($filter != '')
				{
					$filter1 = implode(" and ",$filter);
				}
				
				  $sql= "SELECT sum(ta.reciveqty)
					FROM addmrn INNER JOIN  addmrnqty ta ON addmrn.id=ta.issue_id
   					 where $filter1";
				$sqlquery=DB_query($sql,$db);
			
				while($row=DB_fetch_array($sqlquery))
				{
					 	
					 $received=(integer)$row['sum(ta.reciveqty)'];
					return ($received); 
				}	
				 	
			}
		 
			function issueQty($itemcode,$itemString)
			{
				global $db;
				$opening_var=explode(",",$itemcode);
				if($opening_var[0]!='')
				{
					$filter[]= "addissue.site='".$opening_var[0]."'";
				}
				if($opening_var[1]!='' && $opening_var[1]!='--')
				{
					
					$filter[]= "addissue.store='".$opening_var[1]."'";
				}
				if($opening_var[2]!='' && $opening_var[3]!='')
				{
					$filter[]="addissue.issuedate between '".$opening_var[2]."' and '".$opening_var[3]."'";
				}
				if($itemString != '' && $itemString != '0')
				{
					$filter[]="a.itemcode='".$itemString."'";
				}
				if($filter != '')
				{
					$filter1 = implode(" and ",$filter);
				}
				  $sql= "SELECT SUM(a.issueqty)
  						 FROM addissue INNER JOIN  issueqty a ON addissue.id=a.issue_id
   					 where $filter1";
				$sqlquery=DB_query($sql,$db);
			
				while($row=DB_fetch_array($sqlquery))
				{
					 $received=(integer)$row['SUM(a.issueqty)'];
					
					return ($received); 
				}	
				 	
			}
			?>