<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="0" cellspacing="0" border="0">
<tr class="row1">
	<td width="10%" class="tabledata1"><strong>Branch</strong></td>         
    <td width="40%"><select name="site" id="site" style="width:50%;">
          <option value="0">Select Branch</option>
          <?php
		    $query4=DB_query("Select loccode, locationname from locations where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
			while($row4=DB_fetch_array($query4))
				{
					$s='';
					if($_REQUEST['site']==$row4['loccode'])
					$s="selected";
					?>
					<option value=<?php echo $row4['loccode'];?> <?php echo $s;?>><?php echo $row4['locationname'];?></option>
				<?php }
		  ?>
          </select>          </td>
		  <td width="10%" class="tabledata1"><strong>ATN No.</strong></td>
    <td><select name="issue_no"  id="issue_no" style="width:50%;" >
      <option value="0">Select</option>
      <?php
		  $query2=DB_query("Select issue_no from tpl_asset_transfer_issue ",$db);
			while($row2=DB_fetch_array($query2))
				{
					$s='';
					if($_REQUEST['issue_no']==$row2['issue_no'])
					$s="selected";
					?>
      <option value=<?php echo $row2['issue_no'];?> <?php echo $s;?>><?php echo $row2['issue_no'];?></option>
      <?php }
		  ?>
    </select></td>
</tr>

<tr class="row1">
	<td class="tabledata1"><strong>From Date</strong></td>
    <td><input type="text" name="frmdate" id="frmdate" style="width:50%;" value="<?php echo $_REQUEST['frmdate'] ?>" class="datepicker" /></td>
    <td class="tabledata1"><strong>To Date</strong></td>
	<td><input type="text" name="todate" id="todate" style="width:50%;" value="<?php echo $_REQUEST['todate'] ?>" class="datepicker" /></td>
</tr>
<tr class="row1">
	<td class="tabledata1" colspan="4" style="text-align:center;"><input type="submit" name="Search" class="search" value="Search" /></td>
</tr>
</table>


</form>
<?php 
if(isset($_POST['Search']))
{
    $fordate = $_POST['frmdate'];
	$todate = $_POST['todate'];      
	$filter = array();
	
	if(isset($_REQUEST['site']) && $_REQUEST['site']!= '0')	
	$filter[]="I.site='".$_REQUEST['site']."'";
	
	
	if($_REQUEST['todate']!='' && $_REQUEST['frmdate']!= '') 
	
	 $filter[]="I.issue_date  between '".FormatDateFORSQL($_REQUEST['frmdate'])."' and '".FormatDateFORSQL($_REQUEST['todate'])."'";
	 
	if(isset($_REQUEST['issue_no']) && $_REQUEST['issue_no']!='0')
	$filter[]="I.issue_no='".$_REQUEST['issue_no']."'";
	
	if($filter!='')
	{			
	$filter1 = implode(" and ",$filter);	
       
	}
	if($filter1=='')
	{
	$filter1 ="R.CompanyId='".$_SESSION['ACGCompanyId']."'";
	}

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


 if($_REQUEST['frmdate']!='')
 {
    $_SESSION['frmdate']=$fordate;
 }
 else
 {
 	$_SESSION['frmdate']="";
 } 
 if($_REQUEST['todate']!='')
 {
    $_SESSION['todate']=$todate;
 }
 else
 {
 	$_SESSION['todate']="";
 } 






	 $sqlq = "SELECT I.issue_no, I.id, I.issue_date, I.issued_by, R.request_no, L.loccode , E.emp_name 
			 FROM tpl_asset_transfer_issue I
	  		 INNER JOIN  tpl_asset_transfer_request R ON (R.id=I.transfer_reqno)
			 inner JOIN empmaster E on E.id=I.issued_by
			 INNER JOIN locations L ON L.loccode=R.requested_site
	   		 WHERE $filter1 order by issue_no";
			 
	$_SESSION['asset_issue_rep'] = $sqlq;
	$sql=DB_query($sqlq,$db);
	$s=new db_query();
?>
<p align="right"><a href="fixed_asset_issue_report_print.php" target="_blank" class="search">Print</a></p>

<table width="100%"  border="1" cellspacing="0" cellpadding="3" style="border:#808080 1px solid;">
  	<tr bgcolor="#CCCCCC" height="25">
  		<td width="4%"><strong>S. No.</strong></td>
	  	<td width="5%"><strong>ATN No.</strong></td>
	    <td width="5%"><strong>ATN Date</strong></td>
	    <td width="10%"><strong>Issued By</strong></td>
	   	<td width="8%"><strong>ATR No.</strong></td>
	   	<td width="10%"><strong>Requested Branch</strong></td>
	  	<td width="80"><strong>Asset Code</strong></td>
	   	<td width="100"><strong>Asset Name</strong></td>
	   	<td><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="80"><strong><?php echo $r['title_name'];?></strong></td>
    <?php } ?>
   </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['issue_no']; ?></td>
	<td><?php echo ConvertSQLDate($row['issue_date']); ?></td>
	<td><?php echo $row['emp_name'] ?></td>
	<td><?php echo $row['request_no']; ?></td>
	<td><?php echo $row['loccode']; ?></td>
	<td colspan="6" style="padding:0px;">
		<table width="100%" border="0" cellpadding="3" cellspacing="0">
	<?php
		$reqDet_sql = "SELECT R.required_qty, R.asset_group, I.status, I.issue_qty, A.*
					   FROM tpl_asset_transfer_issue_details I
					   INNER JOIN tpl_asset_transfer_request_details R ON R.id=I.asset_row_id
					   INNER JOIN machine_center A ON A.id=I.asset_id
					   WHERE I.issue_id='".$row['id']."'";
		$result = DB_query($reqDet_sql,$db);
		if(DB_num_rows($result)>0){
			while($assetRow = DB_fetch_array($result)){?>
				<tr>
					<td style="border-right:#808080 1px solid;" width="80"><?php  echo $assetRow['code'];?></td>
					<td width="100" style="border-right:#808080 1px solid;"><?php  echo $assetRow['name'];?></td>
					<td 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="80" style="border-right:#808080 1px solid;"><?php echo $assetRow[$r['db_field_name']];?></td>
    <?php } ?>
				</tr>
		<?php	}
		}
	?>
	
	</table>
	
	</td>
</tr>
<?php $i++; }} else { ?>
	<tr><td colspan="11" style="text-align: center;"><font color="#FF0000" style="font-weight:bold;"><?php echo "No Records Found"; ?></font></td></tr>	 
	<?php } }?> 
</table>
</div></div>
<script language="JavaScript">
function getassetname(str)	
{	
	
if(str=="")
  {
  document.getElementById("data1").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("data1").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","tbl_asset_name.php?code="+str,true);
xmlhttp.send();
}	

</script>

