<?php 

class stockDetails
{
function openingStock($itemcode,$itemString) 
			{
				global $db;
				$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]!='')
				{
				$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";
				}
				echo $sql= "SELECT * FROM opening_stockitemwise where $filter1";
				$sqlquery=DB_query($sql,$db);
				while($row=DB_fetch_array($sqlquery))
				{
				return ($row['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 receivedQty1($itemcode,$itemString)
			{
				global $db;
				$opening_var=explode(",",$itemcode);
				if($opening_var[0]!='')
				{
					$filter[]= "material_return.site='".$opening_var[0]."'";
				}
				if($opening_var[1]!='' && $opening_var[1]!='--')
				{
					$filter[]= "material_return.store='".$opening_var[1]."'";
				}
				if($opening_var[2]!='' && $opening_var[3]!='')
				{
					$filter[]="material_return.returndate between '".$opening_var[2]."' and '".$opening_var[3]."'";
				}
				if($itemString != '' && $itemString != '0')
					{
					$filter[]="mt.itemcode='".$itemString."'";
					}
				if($filter != '')
				{
					$filter1 = implode(" and ",$filter);
				}
				  $sql= "SELECT sum(mt.receiveqty)
					FROM material_return INNER JOIN  material_return_details mt ON material_return.id=mt.parentId
   					 where $filter1";
				 $sqlquery=DB_query($sql,$db);
			
				while($row=DB_fetch_array($sqlquery))
				{
					 	
					 $received=(integer)$row['sum(mt.receiveqty)'];
					return ($received); 
				}	
				 	
			}
			function receivedQty2($itemcode,$itemString)
			{
				global $db;
				$opening_var=explode(",",$itemcode);
				if($opening_var[0]!='')
				{
					$filter[]= "job_work_return.site='".$opening_var[0]."'";
				}
				if($opening_var[1]!='' && $opening_var[1]!='--')
				{
					$filter[]= "job_work_return.vendor='".$opening_var[1]."'";
				}
				if($opening_var[2]!='' && $opening_var[3]!='')
				{
					$filter[]="job_work_return.returnDate between '".$opening_var[2]."' and '".$opening_var[3]."'";
				}
				if($itemString != '')
					{
					$filter[]="jd.itemcode='".$itemString."'";
					}
				if($filter != '')
				{
					$filter1 = implode(" and ",$filter);
				}
				  $sql= "SELECT sum(jd.receivedQty)
					FROM job_work_return INNER JOIN  job_return_details jd ON job_work_return.id=jd.masterId
   					 where $filter1";
				 $sqlquery=DB_query($sql,$db);
			
				while($row=DB_fetch_array($sqlquery))
				{
					 	
					 $received=(integer)$row['sum(jd.receivedQty)'];
					return ($received); 
				}	
				 	
			}
			function receivedQty3($itemcode,$itemString)
			{
				global $db;
				$opening_var=explode(",",$itemcode);
				if($opening_var[0]!='')
				{
					$filter[]= "finished_recieved.site='".$opening_var[0]."'";
				}
				if($opening_var[1]!='' && $opening_var[1]!='--')
				{
					
					$filter[]= "finished_recieved.store='".$opening_var[1]."'";
				}
				if($opening_var[2]!='' && $opening_var[3]!='')
				{
					$filter[]="finished_recieved.recieved_date between '".$opening_var[2]."' and '".$opening_var[3]."'";
				}
				if($itemString != '' && $itemString != '0')
				{
					$filter[]="fd.itemcode='".$itemString."'";
				}
				if($filter != '')
				{
					$filter1 = implode(" and ",$filter);
				}
				 $sql= "SELECT sum(fd.reciveqty)
					FROM finished_recieved INNER JOIN  finished_recieved_details fd ON finished_recieved.id=fd.finished_recieved_id
   					 where $filter1";
				 $sqlquery=DB_query($sql,$db);
			
				while($row=DB_fetch_array($sqlquery))
				{
					 	
					 $received=(integer)$row['sum(fd.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); 
				}	
				 	
			}
			function issueQty2($itemcode,$itemString)
			{
				global $db;
				$opening_var=explode(",",$itemcode);
				if($opening_var[0]!='')
				{
					$filter[]= "job_work_return.site='".$opening_var[0]."'";
				}
				if($opening_var[1]!='' && $opening_var[1]!='--')
				{
					$filter[]= "job_work_return.vendor='".$opening_var[1]."'";
				}
				if($opening_var[2]!='' && $opening_var[3]!='')
				{
					$filter[]="job_work_return.returnDate between '".$opening_var[2]."' and '".$opening_var[3]."'";
				}
				if($itemString != '' && $itemString != '0')
					{
					$filter[]="j.itemcode='".$itemString."'";
					}
				if($filter != '')
				{
					$filter1 = implode(" and ",$filter);
				}
				 $sql= "SELECT SUM(j.quantity)
  				FROM job_work_return INNER JOIN  job_work_details j ON job_work_return.id=j.masterId
  		 		where  $filter1";
				$sqlquery=DB_query($sql,$db);
			
				while($row=DB_fetch_array($sqlquery))
				{
					 $received=(integer)$row['SUM(j.quantity)'];
					
					return ($received); 
				}	
			}
			function issueQty3($itemcode,$itemString)
			{
				global $db;
				$opening_var=explode(",",$itemcode);
				if($opening_var[0]!='')
				{
					$filter[]= "nrgp_challan.site='".$opening_var[0]."'";
				}
				if($opening_var[1]!='' && $opening_var[1]!='--')
				{
					$filter[]= "nrgp_challan.store='".$opening_var[1]."'";
				}
				if($opening_var[2]!='' && $opening_var[3]!='')
				{
					$filter[]="nrgp_challan.challan_date between '".$opening_var[2]."' and '".$opening_var[3]."'";
				}
				if($itemString != '' && $itemString != '0')
					{
					$filter[]="j.itemcode='".$itemString."'";
					}
				if($filter != '')
				{
					$filter1 = implode(" and ",$filter);
				}
				 $sql= "SELECT SUM(j.issueqty)
				 FROM nrgp_challan INNER JOIN  nrgp_challan_details j ON nrgp_challan.id=j.nrgp_challan_id
  		 		where  $filter1";
  				
				$sqlquery=DB_query($sql,$db);
			
				while($row=DB_fetch_array($sqlquery))
				{
					 $received=(integer)$row['SUM(j.issueqty)'];
					
					return ($received); 
				}	
			}
}

$getstock=new stockDetails();
?>