<link rel="stylesheet" href="css/new_mxerp.css">


<?php $PageSecurity = 11;
include('includes/DefinePOClass.php');
include('includes/DefineSerialItems.php');
include('includes/SQL_CommonFunctions.inc');
$title = _('MRN Register');
$date = date($_SESSION['DefaultDateFormat']);
$_SESSION['modid']=$_REQUEST['modid'];
$_SESSION['frmid']=$_REQUEST['frmid'];
$frmpermission= $px->GetFileAccess($_SESSION['modid'],$_SESSION['frmid'],$_SESSION['ACGRoleId']);
$_SESSION['frmView']=$frmpermission[3];
if($_SESSION['frmView']=='0')
{echo "<strong>You are not authorised to view this form. Contact your administrator</strong>"; exit;}
?>
<script language="javascript" type="text/javascript">
function get_itemsubgroup(str)
{
	if(str=="")
  {
  document.getElementById("sub_id").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("sub_id").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","item_subcategory.php?main="+str,true);
xmlhttp.send();
}
function get_item(str)
{
if(str=="")
  {
  document.getElementById("itemid").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("itemid").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","Get_itemcode.php?sub="+str,true);
xmlhttp.send();
}
function showItems(str)
{
    if(str=="")
  {
  document.getElementById("itemid").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("itemid").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","ajax_inventory.php?partName="+str,true);
xmlhttp.send();
}
</script>

<div class="body_contain">
<div class="tab_div">



<h1>MRN Register</h1>
<form action="" method="post">
<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
    <tr>
      <td class="tabledata1" style="width:146px;">Branch</td>
      <td>
	  <select name="site" style="width:100%">
	  <option value="0">Select</option>
	  <?php 
	  $site_sql=DB_query("Select loccode,locationname from locations where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
	  while($site_row=DB_fetch_array($site_sql))
	  {?>
	  <option value="<?php echo $site_row['loccode'];?>"<?php echo($_REQUEST['site']==$site_row['loccode']?'selected':'')?>><?php echo $site_row['locationname'];?></option>
	  <?php	
	  }
	  ?>
	  </select>	  
	  </td>
    </tr>
    <tr>
      <td class="tabledata1">Store</td>
	  <td>
	  <select name="storecode"  style="width:100%">
	  <option value="0">Select</option>
	  <?php 
	  $store_sql=DB_query("select distinct StoreCode,StoreName from storetype",$db);
	  while($store_row=DB_fetch_array($store_sql))
	  {?>
	  <option value="<?php echo $store_row['StoreCode'];?>"<?php echo($_REQUEST['storecode']==$store_row['StoreCode']?'selected':'')?>><?php echo $store_row['StoreName'];?></option>
	  <?php 
	  }
	  ?>
	  </select>
	  </td>
    </tr>
    <tr>
      <td class="tabledata1">Date</td>
      <td><input type="text" name="fromdate" id="fromdate" class="datepicker"  style="width:48%" value="<?php  echo $_REQUEST['fromdate']?>"/>
      TO 
        <input type="text" name="todate" id="todate" class="datepicker"  style="width:47%" value="<?php  echo $_REQUEST['todate']?>"/></td>
    </tr>
  	<tr>
	  <td class="tabledata1">Vendor</td>
	  <td>
	   <?php
		$sql_store = "select vendor_code, vendor_name from suppliers where CompanyId='".$_SESSION['ACGCompanyId']."'";
		$vendor_result = DB_query($sql_store,$db);
		?>
		<select name="supplierid"  style="width:100%">
		<option value="select">Select</option>
		<?php 
		while ($myrow=DB_fetch_array($vendor_result))
		{?>
		<option Value="<?php echo $myrow['vendor_code'];?>"<?php echo($_REQUEST['supplierid']==$myrow['vendor_code']?'selected':'')?>><?php echo $myrow['vendor_name'];?></option>
<?php 	}
		?>
		</select>
	</tr>
  </table>
<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
    <tr>
    <td class="tabledata1" style="width:146px;">Enter Part Name Of Item</td>
    <td>
    <input type="text" name="itemName" value="" onkeyup="showItems(this.value)"  style="width:100%" />
    </td> 
  </tr>
  <tr>
    <td class="tabledata1">ITEM</td>
    <td> <div id="itemid">
	<div style="overflow:auto; height:150px; border:1px solid; ">
	<?php 
	$item_sql=DB_query("select StockID,item_name from item_master where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
	$c3=0;
	while($row3=DB_fetch_array($item_sql))
	{ 
		$c='';
		if($_REQUEST['item'][$c3]==$row3['StockID'])
		{$c="checked";}
	?>
	<input type="checkbox" name="item[<?php echo $c3;?>]" id="item_<?php echo $c3;?>" value="<?php echo $row3['StockID'];?>" <?php echo $c;?>/><?php echo $row3['StockID']." - ".$row3['item_name'];?><br />
	<?php 	
	$c3++;
	}
	?>
	</div>
		
	</div></td>
  </tr>
</table>
  <p align="left" style="padding-left:10px;"><input type="submit" name="submit" value="View" id="view" /></p>
</form>
<p align="right"><a href="mrnreportexport.php?modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>">Export</a></p>
   <table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
	
		<tr style="background-color:#666666; color:#FFFF99"><td class="tabledata1" colspan="2">CHALLAN</td>
		<td class="tabledata1" colspan="3">ORDER</td>
		<td class="tabledata1" colspan="3">ITEM</td></tr>
		<tr>
		<td class="tabledata">Number</td>
		<td class="tabledata">Date</td>
		<td class="tabledata">Number</td>
		<td class="tabledata">Date</td>
		<td class="tabledata">Vendor</td>
		<td class="tabledata">Code</td>
		<td class="tabledata">Description</td>
		<td class="tabledata">Quantity</td>
		</tr>
<?php
if(isset($_POST['submit']))	
{
	$fordate = $_POST['fromdate'];
	$todate = $_POST['todate'];
	$fromdate = explode("/", $fordate);
	$daydate = $fromdate['0'];
	$Monthdate = $fromdate['1'];
	$yeardate = $fromdate['2'];
	$fdate = $yeardate."-".$Monthdate."-".$daydate;
					   
	$tredate   = explode("/", $todate);
	$dayda     = $tredate['0'];
	$Monthda   = $tredate['1'];
	$yearda    = $tredate['2'];
	$toyrdate  = $yearda."-".$Monthda."-".$dayda;
	
	$filter=array();

	if(isset($_POST['site']) && $_POST['site'] != '0')
  	$filter[]="addmrn.OrderFromSite='".$_POST['site']."'";
 	if(isset($_POST['fromdate']) && $_POST['fromdate'] != '' && isset($_POST['todate']) && $_POST['todate'] != '')
 	$filter[]="addmrn.MRNDate between '".$fdate."' and '".$toyrdate."' ";
 	if(isset($_REQUEST['storecode']) && $_REQUEST['storecode'] != '0')
 	$filter[]="addmrn.StoreCode = '".$_POST['storecode']."'";
	if(isset($_POST['supplierid']) && $_POST['supplierid'] != 'select')
	$filter[].="addmrn.ReceivedFrom = '".$_POST['supplierid']."'";
	
	$itemArray=array();
	if($_REQUEST['item']!=''){
	$itemArray=$_REQUEST['item'];
	$itemString="'".implode("','",$itemArray)."'"; }
 
	
	if($_REQUEST['item'] != '')
	{$filter[]="addmrnqty.itemcode in (".$itemString.")";}
	
	if($filter != '')
	{
		$filter = implode(" and ",$filter);
	}
	
	
	$sql="SELECT addmrnqty.*, addmrn.* from addmrn INNER JOIN addmrnqty on(addmrnqty.issue_id = addmrn.id) where $filter";
	//echo $sql;
	$_SESSION['data1']=$sql;
		
$result = DB_query($sql, $db);
if(DB_num_rows($result) > 0)
	{
while($myrow = DB_fetch_array($result))
{ ?>
   <tr bgcolor="#c1c1c1">
		<td><?php echo $myrow['BillNo']?></td>
		<td><?php echo ConvertSQLDate($myrow['BillDate'])?></td>
		<td><?php echo $myrow['PO_WO_MTO']?></td>
		<td><?php echo ConvertSQLDate($myrow['OrderDate'])?></td>
		<td><?php 
		if($myrow['ReceivedAgainst'] == 'PO' || $myrow['ReceivedAgainst'] == 'Direct')
		{
			$vendor_sql = "select vendor_name from suppliers where vendor_code='".$myrow['ReceivedFrom']."' ";
			$vendor_res = DB_query($vendor_sql,$db);
			$vendor_row = DB_fetch_array($vendor_res);
			echo $vendor_row['vendor_name'];
		}
		else if($myrow['ReceivedAgainst'] == 'APCM')
		{
			$pc_sql = "select pc_name from pcopening where id='".$myrow['ReceivedFrom']."' ";
			$pc_result = DB_query($pc_sql,$db);
			$pc_row = DB_fetch_array($pc_result);
			echo $pc_row['pc_name']; }?></td>
		<td><?php echo $myrow['itemcode']?></td>
		<td><?php echo $myrow['description']?></td>
		<td><?php echo $myrow['reciveqty']?></td>
		</tr>
<?php				
}}
else
	{
	echo '<td><div align="center"><font color="#FF0000"> Record Not Found </font></div></td>';}
}
?>
</table>

</div></div>