<?php $PageSecurity = 2;
include('includes/DefineSuppTransClass.php');
include('includes/DefinePOClass.php');
include('includes/SQL_CommonFunctions.inc');
include('includes/session.inc');
include('includes/stockcalculation.php');

?>
<?php 
	$query = "select * from item_master where id ='".$_REQUEST['item_id']."'";
	$dd = DB_query($query,$db); 
	$item_data = DB_fetch_assoc($dd,$db);
?>
<table width="100%"  border="0" style="border:1px solid #808080;" cellspacing="0" cellpadding="3">
<!--<tr style="height:30px;">
	<td colspan="4"  style='text-align:center'>
		<strong ><?php //echo $item_data['StockID']."&#8594;".$item_data['item_name']; ?></strong>
	</td>
</tr>-->
<tr>
	<th width="4%"><strong>Select</strong></th>
	<th><strong>Batch No.</strong></th>
	<th width="10%"><strong>Date of MFG</strong></th>
	<th width="10%"><strong>Date oF Expiry</strong></th>
	<th width="10%"><strong>Qty.</strong></th>
	<th width="10%"><strong>Rate</strong></th>
</tr>
<?php
 	  $query = "SELECT sum(inwardqty_primary) as inwardqty_primary,sum(outwardqty_primary) as outwardqty_primary,date_of_mfg,date_of_expiry,batch_no FROM `stock_valuation_tbl` where mst_itemid = '".$_REQUEST['item_id']."'  and site='".$_REQUEST['site']."' and store='".$_REQUEST['store']."'  group by batch_no";
	//echo $query;
	$sql = DB_query($query,$db); 
	$i=0;
	if(DB_num_rows($sql)>0)
	{
		while($myrow=DB_fetch_array($sql))
		{
			$query1 = "select * from item_master where id ='".$_REQUEST['item_id']."'";
			$result = DB_query($query1,$db);
			$items_data = DB_fetch_assoc($result,$db);
			$qty=$myrow['inwardqty_primary'] - $myrow['outwardqty_primary'];
			//$unitname=$s->getField('unitsofmeasure','unitid',$items_data['mst_unitid'],'unitname');
			$sql_mrn_rate="select mrprate from addmrnqty inner join addmrn on addmrn.id=addmrnqty.issue_id where mst_itemid='".$_REQUEST['item_id']."' order by addmrn.id desc limit 1";
			$result_mrn_rate=DB_query($sql_mrn_rate,$db);
			$rs_mrn_rate=DB_fetch_array($result_mrn_rate);
			
			 $item_rate=$rs_mrn_rate[0];
			if($item_rate=='')
			{

				$sql_op="select rate from opening_stockitemwise where itemcode='".$_REQUEST['item_id']."' and site='".$_REQUEST['site']."' and store='".$_REQUEST['store']."'";
				$result_op=DB_query($sql_op,$db);
				$rs_op=DB_fetch_array($result_op);
			   $item_rate=$rs_op[0];


			}

			//echo $item_rate;

			$unitname='';
			if($qty!=0)
			{
			?>
			<tr>
				<td><input type="checkbox" name="row_id[<?php echo $i;?>]" id="row_id_<?php echo $i;?>" value="<?php echo $_REQUEST['item_id'];?>" onclick="addBatchData('<?php echo $_REQUEST['batch_id']; ?>','<?php echo $qty;?>','<?php echo $_REQUEST['unit']; ?>','<?php echo $myrow['batch_no']; ?>','<?php echo ConvertSQLDate($myrow['date_of_mfg']);?>','<?php echo ConvertSQLDate($myrow['date_of_expiry']);?>','<?php echo $item_rate; ?>');" /></td>
				<td><?php echo $myrow['batch_no'];?></td>
				<td><?php echo ConvertSQLDate($myrow['date_of_mfg']);?></td>
				<td><?php echo ConvertSQLDate($myrow['date_of_expiry']);?></td>
				<td><?php echo $qty;?></td>
				<td><?php echo $item_rate;?></td>
			</tr>
		<?php
			}
		$i++;
	    }
	}
	else
	{
		echo "<tr colspan='4'><td>No Batch Found</td></tr>";
	}


 ?>
</table>
