<?php 

$PageSecurity = 4;
global  $db;
include('includes/session.inc');
include('includes/function_lib.php');
include('includes/stockcalculation.php');
$function_filter[]=$_REQUEST['site'];
$function_filter[]=$_REQUEST['store'];

$function_filter[]=date('Y-m-d');

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

    
?>

<link href="css/professional/default.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="css/new_mxerp.css" />
<style type="text/css">
	/*table tr.row1 {
    background-color: #c1e0c0;
    border: 1px solid #778d77;
    height: 30px;
}*/
</style>
<div class="body_contain">
<div class="tab_div">
<table width="100%" border="0" align="left" cellspacing="0" cellpadding="3">
<tr class="row1">
	<td width="13%" align="right">Main Category</td>
	<td width="35%"><select id="srch_cateory" onchange="getSubCategory()">
		<option value="">Select</option>
		<?php
		if($_SESSION['UserType']=='Dealer')
		{
			$item_query="SELECT * FROM stockmaincategory where CompanyId='".$_SESSION['ACGCompanyId']."'  ";
		}
		else
		{
			$item_query="SELECT * FROM stockmaincategory where CompanyId='".$_SESSION['ACGCompanyId']."'";	
		}
		 
        
		$res=DB_query($item_query ,$db);
		while($item_row1=DB_fetch_array($res)){
		$p='';
		if($item_row1['id'] == $_REQUEST['CategoryID'])	
		$p="selected";?>
		 <option value="<?php echo $item_row1['id'];?>"<?php echo $p;?>><?php echo $item_row1['stockmaincategoryname'];?></option>
       <?php }?>
      </select></td>
      <td width="13%" align="right">Sub Category</td>
      <td><select id="srch_subcateory">
		<option value="">Select</option>
		<?php
        $item_subquery="SELECT * FROM stockcategory where CompanyId='".$_SESSION['ACGCompanyId']."'";
		$subres=DB_query($item_subquery ,$db);
		while($item_subrow=DB_fetch_array($subres)){
		$p='';
		if($item_subrow['id'] == $_REQUEST['CategoryID'])	
		$p="selected";?>
		 <option value="<?php echo $item_subrow['id'];?>"<?php echo $p;?>><?php echo $item_subrow['categorydescription'];?></option>
       <?php }?>
      </select></td>
</tr>
<tr class="row1">
      <td align="right">Code</td>
	  <td><input type="text" id="srch_code" placeholder="Item Code" onkeyup="getData1();" /></td>
 	  <td align="right">Name</td>
	  <td><input type="text" id="srch_name" placeholder="Item Name" onkeyup="getData1();" /></td>  
</tr>
<!-- <tr class="row1">
	  <td colspan="4" style="text-align:center;"><input type="button" value="Search" onclick="getData1()" class="search" /></td>
</tr> -->
</table>

<div id="ItemListDiv" style="width:100%; float:left; margin-top:10px;">
<form name="form1" action="" method="post">
<table width="100%" border="0" align="left" cellspacing="0" cellpadding="3" class="thborder">
<tr>
	<th width="5%">Select</th>
	<th width="15%">Item Code</th>
	<th>Item Name</th>
	<th width="9%">UOM</th>
	<th width="20%" class="text-right">Issuing Store Stock</th>
	<!-- <td width="21%"><strong>To Store Stock</strong></td> -->
</tr>
<?php  //echo "Select id,StockID,item_name,item_desc,mst_unitid,mrp_rate,net_rate from item_master where CompanyId='".$_SESSION['ACGCompanyId']."'";
//echo "Select * from item_master where CompanyId='".$_SESSION['ACGCompanyId']."'  and id in(select itemcode from opening_stockitemwise where store='".$_REQUEST['store']."' )  ";
$sql=DB_query($str="Select * from item_master where CompanyId='".$_SESSION['ACGCompanyId']."'  limit 30  ",$db); 
$sqll=DB_query($str="Select * from item_master where CompanyId='".$_SESSION['ACGCompanyId']."' limit 30  ",$db); 
$i=1;
	while($myrow=DB_fetch_array($sql))
	{ 	
		        $myrow1=DB_fetch_array($sqll);
		  	    $op=openingBalance($function_filter,$myrow['id']);
		  	    $op1=openingBalance($function_filter1,$myrow1['id']);
				$in_1=receivedMRN($function_filter,$myrow['id']);
				$out_1=issueSlip($function_filter,$myrow['id']);
				$out_11=issueSlip($function_filter1,$myrow1['id']);
				$out_2=issueSiteToSite($function_filter,$myrow['id']);
				$out_21=issueSiteToSite($function_filter1,$myrow1['id']);    
				$in_2=receivedSiteToSite($function_filter,$myrow['id']);
				$in_21=receivedSiteToSite($function_filter1,$myrow1['id']);
				$out_3=issueMatarialReturn($function_filter,$myrow['id']);
				$out_31=issueMatarialReturn($function_filter1,$myrow1['id']);
				$in_3=receivedReturn($function_filter,$myrow['id']);  
				$in_31=receivedReturn($function_filter1,$myrow1['id']);
				$out_4=Rgpchallan($function_filter,$myrow['id']);
				$out_41=Rgpchallan($function_filter1,$myrow1['id']);
				$out_5=Nrgp($function_filter,$myrow['id']);
				$out_51=Nrgp($function_filter1,$myrow1['id']);
				$in_4=Rgpreturn($function_filter,$myrow['id']);
				$in_41=Rgpreturn($function_filter1,$myrow1['id']);  
				$in_5=FinishedMR($function_filter,$myrow['id']);
				$in_51=FinishedMR($function_filter1,$myrow1['id']);
				$in_6=MaterialConReceived($function_filter,$myrow['id']);
				$in_61=MaterialConReceived($function_filter1,$myrow1['id']);
				$out_6=MaterialConIssue($function_filter,$myrow['id']);
				$out_61=MaterialConIssue($function_filter1,$myrow1['id']);
				$in_7=PhysicalStockPlus($function_filter,$myrow['id']);
				$in_71=PhysicalStockPlus($function_filter1,$myrow1['id']);
				$out_7=PhysicalStockMinus($function_filter,$myrow['id']);
				$out_71=PhysicalStockMinus($function_filter1,$myrow1['id']);
				$out_8=dispatchIssue($function_filter,$myrow['id']);
				$out_81=dispatchIssue($function_filter1,$myrow1['id']);
				$out_9=jobWorkChallan57Issue($function_filter,$myrow['id']);
				$out_91=jobWorkChallan57Issue($function_filter1,$myrow1['id']);
				$in_8=jobWorkChallan57Received($function_filter,$myrow['id']);
				$in_81=jobWorkChallan57Received($function_filter1,$myrow1['id']);
				$in_9=directPurchase($function_filter,$myrow['id']);
				$in_91=directPurchase($function_filter1,$myrow1['id']);
				$in_10=saleReturn($function_filter,$myrow['id']);
				$in_101=saleReturn($function_filter1,$myrow1['id']);
				$out_10=invoice($function_filter,$myrow['id']);
				$out_101=invoice($function_filter1,$myrow1['id']);
				$in11=storereceipt($function_filter,$myrow['id']);
				$invalue=($op+$in_1+$in_2+$in_3+$in_4+$in_5 + $in_6 + $in_7 + $in_8+$in_9 + $in_10+$in11);
				$invalue1=($op1+$in_11+$in_21+$in_31+$in_41+$in_51 + $in_61 + $in_71 + $in_81+$in_91 + $in_101);
				$outvalue=($out_1+$out_2+$out_3+$out_4+$out_5 + $out_6 + $out_7 + $out_8 + $out_9+$out_10);
				$outvalue1=($out_11+$out_21+$out_31+$out_41+$out_51 + $out_61 + $out_71 + $out_81 + $out_91+$out_101);
				$tot=$invalue-$outvalue;
				$tot1=$invalue1-$outvalue1;
				$stockallitems=$tot;
				$stockallitems1=$tot1;
	 		    $total_current=$tot;
	 		    $total_current1=$tot1;

		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_row=DB_fetch_array($unit2))
			 {
			   $data22.="<option value=".$unit_row['unitid'].">".$unit_row['unitname']."</option>";
			 }
		 }
?>
<tr>
	<td style="text-align:center;"><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 $confac; ?>','<?php echo $data22; ?>','<?php echo $i; ?>','<?php echo $total_current; ?>','<?php echo $total_current1; ?>')"/></td>
	<td><strong><?php echo $myrow['StockID'];?></strong></td>
	<td><?php echo  $myrow['item_name'];?></td>
	<td><?php  echo $unit;?></td>
	<td class="text-right"><?php echo $total_current; ?></td>
<!-- 	<td><?php echo $total_current1; ?></td> -->
</tr>
	<?php $i++;} ?>
 </table>
</form>
</div>
<?php
function string_sanitize($s) 
{	
    $result = preg_replace("/[^a-zA-Z0-9]+/", "", html_entity_decode($s, ENT_QUOTES));
    return $result;
} 
?>

</div>
</div>
