<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1>Fixed Asset Definition Report</h1>
<form name="" id="" method="POST">
<fieldset class="bggreen">
<table width="100%" cellpadding="3" cellspacing="0" border="0">
<tr class="row3" style="height:5px;"><td colspan="8"></td></tr>
<tr class="row3">
	<td width="10%" align="right"><strong>Branch:</strong></td>         
    <td width="15%"><select name="project" id="project" class="detailedViewTextBox" style="width:98%;">
          <option value="0">Select Branch</option>
          <?php
		    $query4=DB_query("Select * from locations where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);	
			while($row4=DB_fetch_array($query4))
				{
					$s='';
					if($_REQUEST['project']==$row4['loccode'])
					$s="selected"; 
					?>
					<option value=<?php echo $row4['loccode'];?> <?php echo $s;?>><?php echo $row4['locationname'];?></option>
				<?php }
		  ?>
          </select></td>
    <td width="10%" align="right"><strong>Asset Group:</strong></td>
    <td width="15%"><select name="asset_group" id="asset_group" class="detailedViewTextBox" style="width:98%;" onchange="getassetname(this.value);">
          <option value="0">--Select--</option>
          <?php
		  $query2=DB_query("Select * from machine_group_master where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
			while($row2=DB_fetch_array($query2))
				{
					$s='';
					if($_REQUEST['asset_group']==$row2['id'])
					$s="selected";
					?>
					<option value=<?php echo $row2['id'];?> <?php echo $s;?>><?php echo $row2['machine_gp_location'];?></option>
				<?php }
		  ?>
          </select></td>
          <td width="10%" align="right"><strong>Asset Name:</strong></td>
          <td><select name="asset_name"  id="asset_name" class="detailedViewTextBox" style="width:98%;" >
          <option value="">--Select--</option>
		  <option value="">All</option>
          <?php $SQLMachine=db_query("SELECT * FROM machine_center where CompanyId='".$_SESSION['ACGCompanyId']."'",$db );
		 while($MachineNa=db_fetch_array($SQLMachine)){
			$p='';
	 		if($MachineNa['id']==$_REQUEST['asset_name'])
	  		$p="selected"; ?>
		 	<option value="<?php echo $MachineNa['id']?>"  <?php echo $p; ?>><?php echo $MachineNa['name']; ?></option>
		<?php }?>
          </select></td>
		  <td width="10%" align="right"><strong>Source:</strong></td>
		  <td width="15%"><select name="source" id="source" style="width:98%; class="detailedViewTextBox"">
						 <option value="0">Select</option>
						 <option value="Grant Fund">Grant Fund</option>
						 <option value="Owned Fund">Owned Fund</option>
				</select>
		  </td>
</tr>
<!--tr class="row1">
	<td align="right"><strong>From Date:</strong></td>
    <td><input type="text" name="frmdate" id="frmdate" style="width:98%;" class="datepicker" value="<?php echo $fd= $_REQUEST['frmdate'] ?>"/></td>
    <td align="right"><strong>To Date:</strong></td>
    <td><input type="text" name="todate" id="todate" style="width:98%;" value="<?php echo  $_REQUEST['todate'] ?>" class="datepicker" /></td>
    <td align="right"><strong>Source:</strong></td>
    <td><select name="source" id="source" style="width:98%; class="detailedViewTextBox"">
    			 <option value="0">Select</option>
	             <option value="Grant Fund">Grant Fund</option>
	             <option value="Owned Fund">Owned Fund</option>
	    </select>
    </td>
</tr-->
<tr class="row3">
	<td colspan="8" style="text-align:center;"><input type="submit" name="Search" class="search" value="Search" onclick="return validation();" /></td>
</tr>
<tr class="row3" style="height:5px;"><td colspan="8"></td></tr>
</table>
</fieldset>
<?php
if(isset($_REQUEST['Search']))
{?>
<p align="right"><a href="fixed_asset_register_print.php" target="_blank" class="search">Print</a></p>

    <div style="width:100%; height:330px; overflow:auto; margin:auto; float:left;">
	<table width="170%" border="1" cellspacing="0" cellpadding="3" style="border:#808080 1px solid; border-collapse:collapse;">
  	<tr>
  		<th width="2%">S.No.</th>
	  	<th>Branch</th>
	    <th width="6%">Asset Code</th>
	    <th width="6%">Asset Name</th>
	    <th width="6%">Asset Group</th>
	    <th width="6%">Asset Type</th>
	    <th width="6%">Source</th>
	   	<?php 
   $title='';
   $title1=DB_query("select * from tbl_title_master order by serial_no ASC",$db);
   while($r=DB_fetch_array($title1))
   { 
    
    ?>
    <th width="4%"><?php echo $r['title_name'];?></th>
    <?php } ?>
	   	<th width="4%">Purchase Date</th>
	   	<th width="4%">Purchase Amount</th>
        <th width="4%">Installed By</th>
   </tr>
<?php
     $sr = $_POST['source']; 
     $td="All";
 	$fordate = $_POST['frmdate'];		
	   $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($_REQUEST['project']) && $_REQUEST['project']!= '0')	
	$filter[]="location='".$_REQUEST['project']."'";
	if(isset($_REQUEST['asset_group']) && $_REQUEST['asset_group']!= '0')	
	$filter[]="under_group='".$_REQUEST['asset_group']."'";
	if(isset($_REQUEST['asset_name']) && $_REQUEST['asset_name']!= ''){	
		$filter[]="id='".$_REQUEST['asset_name']."'";
	}
	/* if($_REQUEST['todate']!='' && $_REQUEST['frmdate']!= '') 
	 $filter[]="purchase_date  between '".$fdate."' and '".$toyrdate."'"; */

if(isset($_REQUEST['source']) && $_REQUEST['source']!= '0')	
	$filter[]="source='".$_REQUEST['source']."'";

	
	
	if($filter!='')
	{			
	$filter1 = implode(" and ",$filter);	
	}
	if($filter1=='')
	{
	$filter1 ="CompanyId='".$_SESSION['ACGCompanyId']."'";
	}

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


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

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


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


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

 if($_REQUEST['todate']!='')
 {
    $_SESSION['todate']=$todate;
 }
 else
 {
 	$_SESSION['todate']="";
 } */ 
      
     $qry="select * from machine_center where $filter1";  
     $_SESSION['qry']=$qry;

	 $sql=DB_query($qry,$db); 

	 //print_r($_SESSION['qry']);

$i=1;
$num=DB_num_rows($sql);
if($num>0)
{
while($row=DB_fetch_array($sql))
	{
	//$loc=DB_query("select locationname from locations where loccode='".$row['location']."'",$db);	
	//$location=DB_fetch_array($loc);
		$sqlG=DB_query("Select * from machine_group_master where id='".$row['under_group']."' ",$db); 
		 $myrow_group=DB_fetch_array($sqlG);	
?>
<tr bgcolor="#FFFFFF">
	<td><?php echo $i; ?></td>
	<td><?php echo $row['location']; //$location['locationname']; ?></td>
	<td><?php echo $row['code']; ?></td>
	<td><?php echo $row['name']; ?></td>
	<td><?php echo $myrow_group['machine_gp_location']; ?></td>
	<td><?php if($row['asset_type']=='A'){echo "Asset";}else{ echo "Sub Asset";	} ?></td>
	<td><?php echo $row['source']; ?></td>    
<?php 
   $title='';
   $title1=DB_query("select * from tbl_title_master order by serial_no ASC",$db);
   while($r=DB_fetch_array($title1))
   {     
    ?>
    <td width="4%" style="word-break:break-all;"><?php echo $row[$r['db_field_name']] ?></td>
    <?php } ?>
        <td width="4%"><?php  echo ConvertSQLDate($row['purchase_date']);?></td>
        <td width="4%"><?php  echo $row['purchase_amt'];?></td>
        <td width="4%"><?php  echo $row['insatallation_by'];?></td>
</tr>
<?php $i++; }} else { ?>
	<tr bgcolor="#fff"><td colspan="28" style="text-align: center;"><font color="#FF0000" style="font-weight:bold;"><?php echo "No Records Found"; ?></font></td></tr>	 
	<?php } }?> 
</table>	
	</div>

</form>
</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("asset_name").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","tbl_asset_name.php?code="+str,true);
xmlhttp.send();
}	


function validation()
 {
    if(document.getElementById("project").value=='0')
    {
        alert("Please Select Branch");
        return false;
    }
    return true;
}

</script>

