<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1><?php echo $s->getField('modules_form','id',$_REQUEST['frmid'],'description');?></h1>
<form name="" id="" method="POST">
<table width="100%" cellpadding="3" cellspacing="0" border="0">
<tr class="row1">
	
	<td width="13%" class="tabledata1"><strong>Requested Branch</strong></td>
    <td width="20%"><select name="req_site" id="req_site"  style="width:98%;" onchange="getEmployeeList(this.value);">
          <option value="0">Select Requested Branch</option>
         <?php
	$query5=DB_query("Select loccode, locationname from locations where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
	while($row5=DB_fetch_array($query5))
	{
	$s1='';
	if($_REQUEST['req_site']==$row5['loccode'])
	$s1="selected";
	?>
	<option value=<?php echo $row5['loccode'];?> <?php echo $s1;?>><?php echo $row5['locationname'];?></option>
	<?php }
	?>
          </select>
		  </td>

	<td width="13%" class="tabledata1"><strong>ATR No.</strong></td>
    <td width="20%"><select name="request_no"  id="request_no"  style="width:98%;">
        	<option value="0">Select</option>
        	<?php
		  $query2=DB_query("Select * from tpl_asset_transfer_request where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
			while($row2=DB_fetch_array($query2)){?>
					<option value="<?php echo $row2['request_no'];?>"<?php echo ($_REQUEST['request_no']==$row2['request_no']) ? "selected" : "" ;?>><?php echo $row2['request_no'];?></option>
				<?php }
		  ?>
        	
        </select></td> 	 	
	<td width="13%" class="tabledata1"><strong>Requested By</strong></td>
    <td id="data1">
	<select name="req_by"  id="req_by" style="width:98%;">
        <option value="0">--Select--</option>
		<?php if($_REQUEST['req_site'] !=''){
			$empsql = "select id, emp_name from empmaster where emp_site='".$_REQUEST['req_site']."' and CompanyId='".$_SESSION['ACGCompanyId']."'";
			$empres = DB_query($empsql,$db);
			while($empRow = DB_fetch_array($empres)){?>
		<option value="<?php echo $empRow['id'];?>" <?php echo ($empRow['id']==$_REQUEST['req_by']) ? "selected" : ""; ?>><?php echo $empRow['emp_name'];?></option>
		<?php }
		}?>
        </select>
	</td>
</tr>
<tr class="row1">
	<td class="tabledata1"><strong>From Date</strong></td>
    <td><input type="text" name="frmdate" value="<?php echo $_REQUEST['frmdate']; ?>" id="frmdate" style="width:98%;" class="datepicker" /></td>
	<td class="tabledata1"><strong>To Date</strong></td>
    <td><input type="text" name="todate" value="<?php echo $_REQUEST['todate']; ?>" id="todate" style="width:98%;" class="datepicker" /></td>
    <td colspan="2">&nbsp;</td>
</tr>  
<tr class="row1">
	<td style="text-align:center;" colspan="6" class="tabledata1"><input type="submit" name="Search" class="search" value="Search" /></td>
</tr> 
<?php
if(isset($_POST['Search']))
{
	$fordate = $_POST['frmdate'];
	$todate = $_POST['todate'];
	
	if($_REQUEST['req_site']!='0')
	{	
	$filter[]="R.requested_site='".$_REQUEST['req_site']."'";
	}
	if($_REQUEST['request_no']!='0')	
	{
	$filter[]="R.request_no='".$_REQUEST['request_no']."'";
	}
	if($_REQUEST['req_by']!='0')
	{
	$filter[]="R.requested_by='".$_REQUEST['req_by']."'";
	}
	if($_REQUEST['todate']!='' && $_REQUEST['frmdate']!= '')
	{ 
	 $filter[]="R.request_date  between '".FormatDateFORSQL($_REQUEST['frmdate'])."' and '".FormatDateFORSQL($_REQUEST['todate'])."'";
	}
	if($filter!='')
	{			
	$filter1 = implode(" and ",$filter);	
	}
	if($filter1=='')
	{
	$filter1 ="L.CompanyId='".$_SESSION['ACGCompanyId']."'";
	}
	

if($_REQUEST['req_site']!='0')
 {
   $_SESSION['req_site']=$_REQUEST['req_site'];
 }
 else
 {
 	$_SESSION['req_site']="";
 }  


 if($_REQUEST['frmdate']!='')
 {
    $_SESSION['frmdate']=$fordate;
 }
 else
 {
 	$_SESSION['frmdate']="";
 } 
 if($_REQUEST['todate']!='')
 {
    $_SESSION['todate']=$todate;
 }
 else
 {
 	$_SESSION['todate']="";
 } 
	
	$sql = "SELECT R.*, L.locationname, E.emp_name FROM tpl_asset_transfer_request R
					   INNER JOIN locations L ON(L.loccode=R.requested_site) 
					   INNER JOIN empmaster E ON(E.id=R.requested_by) 
					   WHERE $filter1 order by request_no";
	$_SESSION['trf_req_rep']=$sql;
	$sql=DB_query($sql,$db);

$s=new db_query();
?>
<tr class="row1">
  		<td colspan="6" style="text-align:right;" class="tabledata1" align="right"><a href="asset_transfer_req_print.php?req_site=<?php echo $_REQUEST['req_site'];?>&request_no=<?php echo $_REQUEST['request_no'];?>&req_by=<?php echo $_REQUEST['req_by'];?>&frmdate=<?php echo $_REQUEST['frmdate'];?>&todate=<?php echo $_REQUEST['todate'];?>" target="_blank" class="search">Print</a></td>

</tr>
<tr class="row1">
	<td colspan="6" class="tabledata1" style="padding:0px;">
    <div style="width:1246px; overflow:auto; margin:auto;">
	<table width="100%"  border="1" cellspacing="0" cellpadding="3" style="border:#808080 1px solid;">
  	<tr bgcolor="#CCCCCC" height="25">
  		<td width="3%"><strong>S. No.</strong></td>
	  	<td width="10%"><strong>ATR No.</strong></td>
	   	<td width="8%"><strong>ATR Date</strong></td>
	   	<td width="10%"><strong>Requested By</strong></td>
	  	<td width="6%"><strong>Asset Code</strong></td>
	  	<td><strong>Asset Name</strong></td>
	  	<td width="10%"><strong>Asset Group</strong></td>
	  	<?php 
   $title1=DB_query("select * from tbl_title_master order by serial_no ASC limit 0,3",$db);
   while($r=DB_fetch_array($title1))
   { 
    ?>
    <td width="8%"><strong><?php echo $r['title_name'];?></strong></td>
    <?php } ?>
	<td width="8%"><strong>Purpose</strong></td>
	<td width="8%"><strong>Status</strong></td>
   	</tr>
<?php 
$i=1;
$num=DB_num_rows($sql);
if($num>0)
{
while($row=DB_fetch_array($sql))
{

?>
<tr bgcolor="#FFFFFF">
	<td> <?php echo $i; ?></td>
	<td><?php echo $row['request_no']; ?></td>
	<td><?php echo ConvertSQLDate($row['request_date']); ?></td>
	<td><?php echo $row['emp_name']; ?></td>
	<td colspan="8" style="padding:0px;">
		<table width="100%" border="0" cellspacing="0" cellpadding="3">
	<?php
		$reqDet_sql = "SELECT R.required_qty, R.status AS RS, R.asset_group, R.purpose, A.* 
					   FROM tpl_asset_transfer_request_details R
					   INNER JOIN machine_center A ON A.id=R.asset_code
					   WHERE R.asset_req_id='".$row['id']."'";
		$result = DB_query($reqDet_sql,$db);
		if(DB_num_rows($result)>0){
			while($assetRow = DB_fetch_array($result)){?>
				<tr>
					<td width="9%" style="border-right:#808080 1px solid;"><?php  echo $assetRow['code'];?></td>
					<td style="border-right:#808080 1px solid;"><?php  echo $assetRow['name'];?></td>
					<td width="14%" style="border-right:#808080 1px solid;"><?php  echo $assetRow['asset_group'];?></td>
					<?php 
   $title1=DB_query("select * from tbl_title_master order by serial_no ASC limit 0,3",$db);
   while($r=DB_fetch_array($title1))
   { 
    ?>
    <td width="12%" style="border-right:#808080 1px solid;"><?php echo $assetRow[$r['db_field_name']];?></td>
    <?php } ?>
					<td width="12%" style="border-right:#808080 1px solid;"><?php  echo $assetRow['purpose'];?></td>
					<td width="10%"><?php  echo $assetRow['RS'];?></td> 
				</tr>
		<?php	}
		}
	?>
	
	</table>
		
	</td>
	
	
	
	
</tr>
<?php $i++; }} else { ?>
	<tr><td colspan="10" style="text-align: center;"><font color="#FF0000"><?php echo "No records found"; ?></font></td></tr>	 
	<?php } }?> 
</table>
	</div>
	</td>
</tr> 
</table>
</form>
</div>
</div>
<script language="JavaScript">

function getEmployeeList(str){
if(str=="")
  {
  document.getElementById("req_by").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("req_by").innerHTML=xmlhttp.responseText;
	}
	}
	
	
	xmlhttp.open("GET","getEmpList.php?site="+str,true);
	xmlhttp.send();

}
</script>

