<?php $PageSecurity = 2;
include('includes/DefineSuppTransClass.php');
include('includes/DefinePOClass.php');
include('includes/SQL_CommonFunctions.inc');
include('includes/session.inc');
include('includes/function_lib.php');
include('includes/stockcalculation.php');
$function_filter[]=$_REQUEST['site'];
$function_filter[]='';
$function_filter[]=date('Y-m-d');

$function_filter1[]=$_REQUEST['site'];
$function_filter1[]=$_REQUEST['to_store'];
$function_filter1[]=date('Y-m-d');

if(isset($_REQUEST['vendor']))  
 $vendor_state=$s->getField('suppliers','id',$_REQUEST['vendor'],'state');
if(isset($_REQUEST['site']))
 $loc_state=$s->getField('locations','loccode',$_REQUEST['site'],'state');
?>
<link href="css/professional/default.css" rel="stylesheet" type="text/css" />
<form name="form1" action="" method="post">
<div id="ItemListDiv" style="width:100%; float:left;">

<table width="100%" border="1" style="border:1px solid #808080;" align="left" cellspacing="0" cellpadding="3">
<tr>
	<th width="5%">Select</th>
	<th width="15%">Item Code</th>
	<th>Item Name</th>
	<th width="9%">UOM</th>
	<th width="20%">Issuing Store Stock</th>
	<!--<td><strong>To Store Stock</strong></td> -->
</tr>
<?php $where='';
if($_REQUEST['code']!=''){
    $where[]="  StockID LIKE '%".$_REQUEST['code']."%'";
}
if($_REQUEST['name']!=''){
    $where[]=" item_name LIKE '%".htmlspecialchars($_REQUEST['name'])."%'";
}
if($_REQUEST['cat']!=''){
    $where[]=" CategoryID='".$_REQUEST['cat']."'";
}
if($_REQUEST['subcat']!=''){
    $where[]=" SubCategoryID='".$_REQUEST['subcat']."'";
}

if(!empty($where))
$filter2=implode(" and ", $where);
if(!empty($where))
{
//echo "SELECT id,StockID,item_name,mst_unitid,item_no FROM item_master WHERE $filter2";
	//echo "SELECT id,StockID,item_name,mst_unitid,item_no FROM item_master WHERE $filter2 and id in(select itemcode from opening_stockitemwise where store='".$_REQUEST['store']."' )";
  $sql=DB_query("SELECT id,StockID,item_name,mst_unitid,item_no,conv_unit FROM item_master WHERE $filter2 limit 30",$db); 

 // $sql=DB_query($str="SELECT id,StockID,item_name,mst_unitid,item_no,conv_unit FROM item_master WHERE $filter2 and id in(select itemcode from opening_stockitemwise where store='".$_REQUEST['to_store']."' )",$db);
$i=0;
if(DB_num_rows($sql)>0)
{
	while($myrow=DB_fetch_array($sql))
	{ 	
		$purchase_vat='';
		$$purchase_cst='';
		$parameter=$myrow['id'];
		$unitname= $s->GetFieldValue('unitsofmeasure',"unitid='".$myrow['mst_unitid']."'",'unitname');
		        $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']);
				$in_6=MaterialConReceived($function_filter,$myrow['id']);
				$out_6=MaterialConIssue($function_filter,$myrow['id']);
				$in_7=PhysicalStockPlus($function_filter,$myrow['id']);
				$out_7=PhysicalStockMinus($function_filter,$myrow['id']);
				$out_8=dispatchIssue($function_filter,$myrow['id']);
				$out_9=jobWorkChallan57Issue($function_filter,$myrow['id']);
			//	$in_8=jobWorkChallan57Received($function_filter,$myrow['id']);
			
				$in_9=directPurchase($function_filter,$myrow['id']);
			
				$in_10=saleReturn($function_filter,$myrow['id']);
				
				 $out_10=invoice($function_filter,$myrow['id']);
				 $in11=storereceipt($function_filter,$myrow['id']);
			
				$invalue=($op+$in_1+$in_2+$in_3 + $in_6 + $in_7 + $in_8+$in_11);
			
				$outvalue=($out_1+$out_2+$out_3+$out_4+$out_5 + $out_6 + $out_7 + $out_8 + $out_9+$out_10);
			
				$tot=$invalue-$outvalue;
				$tot1=$invalue1-$outvalue1;
				$stockallitems=$tot;
			
	 		     $total_current=$tot;
	 		   

			 	$vatid='';
			 	 $purchase_vat=$s->GetFieldValue('item_master',"id='".$myrow['id']."'",'vat_purchase');
	             $purchase_cst=$s->GetFieldValue('item_master',"id='".$myrow['id']."'",'cst_purchase');
	             if($vendor_state==$loc_state)
	             {
	              $vatid=$purchase_vat;
	             }
	             else
	             {
	              $vatid=$purchase_cst;
	             }
	               $taxdtls='';
	             
	               $Taxsql="SELECT salestax_id,tax_code, taxrate,surcharge_rate FROM sales_tax_master where salestax_id='".$vatid."'";
                   $Taxresult1=DB_query($Taxsql,$db);
                   if(DB_num_rows($Taxresult1)>0)
                   {
                   $rowdtls=DB_fetch_array($Taxresult1);
                   $vatdtlsid=$rowdtls['salestax_id'];
                   $vatdesc=$rowdtls['taxrate'];
                   $surcharge_rate=$rowdtls['surcharge_rate'];
                   }
                    

                    if(!is_null($myrow['conv_factor']))
		$confac=$myrow['conv_factor'];
	    else
	    $confac="null";	
		$total_current=$tot;
		
		$unit=$s->getField('unitsofmeasure','unitid',$myrow['mst_unitid'],'unitname');

		$unit1=DB_query("select * from  unitsofmeasure where unitid ='".$myrow['mst_unitid']."' ",$db);
		$numrow=DB_num_rows($unit1);
		$data1 = '';
		if($numrow>0)
		{                  
						   while($unit_row=DB_fetch_array($unit1))
						   {
						   $data1.="<option value=".$unit_row['unitid'].">".$unit_row['unitname']."</option>";
						   }
		 
		 }
		 $data22='';
		 $unit2=DB_query("select * from  unitsofmeasure where unitid ='".$myrow['conv_unit']."' ",$db);
		 $numrow1=DB_num_rows($unit2);
		 if($numrow1>0)
		 {                  
			 while($unit_row12=DB_fetch_array($unit2))
			 {
			   $data22.="<option value=".$unit_row12['unitid'].">".$unit_row12['unitname']."</option>";
			 }
		 }
			 	

		
?>
<tr bgcolor="#fff">
	<td><input type="checkbox" name="row_id[<?php echo $i;?>]" id="row_id_<?php echo $i;?>" onclick="getItemsList('<?php echo $myrow['id'];?>','<?php echo filter_var($myrow['StockID'],FILTER_SANITIZE_STRING);?>','<?php echo filter_var($myrow['item_name'],FILTER_SANITIZE_STRING);?>','<?php echo $data1;?>','<?php echo $myrow['conv_unit'];?>','<?php echo $data22; ?>','<?php echo $i; ?>','<?php echo $total_current; ?>')"/></td>
	<td><?php echo $myrow['StockID'];?></td>
	<td><?php echo  $myrow['item_name'];?></td>
	<td><?php echo $unitname;?></td>
	<td><?php echo $total_current; ?></td>
	<!--<td><?php echo $total_current1; ?></td> -->	
</tr>
	<?php $i++; } } }?>
 </table>
 </div>
</form>
