<form name="" id="" method="POST">
<div align="center">
<fieldset style="width:800px"><legend><strong>Fixed Asset Sale Entry Report</strong></legend>	
<table width="100%" cellpadding="0" cellspacing="0" border="0">
  <tr>
    <td style="padding:5px"><!-- General details -->
      <table width="50%" cellspacing="4" cellpadding="4" border="0" style="color:#FF0000" align="center">
        <tr>
          <td style="padding:5px; text-align:center;"  align="right"></td>
        </tr>       
         
          <tr>
          <th>Project</th>         
          <td  align="left" >
          <select name="project" id="project" class="detailedViewTextBox" style="width:100%;">
          <option value="0">Select Project</option>
          <?php
		    $query4=DB_query("Select * from locations ",$db);
			while($row4=DB_fetch_array($query4))
				{
					$s='';
					if($project==$row4['loccode'])
					$s="selected";
					?>
					<option value=<?php echo $row4['loccode'];?> <?php echo $s;?>><?php echo $row4['locationname'];?></option>
				<?php }
		  ?>
          </select>
          </td>
          </tr>
          <tr>
          <th>Asset Group</th>
          <td>
          	<select name="asset_group" id="asset_group" class="detailedViewTextBox" style="width:100%;" onchange="getassetname(this.value);">
          <option value="0">Select Asset Group</option>
          <?php
		  $query2=DB_query("Select * from tpl_MaterialCategoryDefinition ",$db);
			while($row2=DB_fetch_array($query2))
				{
					$s='';
					if($asset_group==$row2['id'])
					$s="selected";
					?>
					<option value=<?php echo $row2['id'];?> <?php echo $s;?>><?php echo $row2['asset_capitalisation'];?></option>
				<?php }
		  ?>
          </select>
          	
		  </td>
        </tr>
        <tr><th>Asset Name</th>
        <td id="data1"><select name="asset_name"  id="asset_name" class="detailedViewTextBox" style="width:100%;" >
        <option value="0">Select</option>        	
        </select></td> 	
        </tr>
        <tr><th>Invoice No</th>
        <td id="data1"><select name="request_no"  id="request_no" class="detailedViewTextBox" style="width:100%;" >
        	<option value="0">Select</option>
        	<?php
		  $query2=DB_query("Select * from tpl_fixed_assetsales_entry ",$db);
			while($row2=DB_fetch_array($query2))
				{
					$s='';
					if($request_no==$row2['invoice'])
					$s="selected";
					?>
					<option value=<?php echo $row2['invoice'];?> <?php echo $s;?>><?php echo $row2['invoice'];?></option>
				<?php }
		  ?>
        	
        </select></td> 	
        </tr>
       <tr>
       	<th>Date</th>
       	<td><strong> From :</strong><input type="text" name="frmdate" id="frmdate" size="20" class="datepicker" />
       		<strong> To :</strong><input type="text" name="todate" id="todate" size="20" class="datepicker" />
       	</td>
       </tr> 
      </table></td>
  </tr>
</table>
<p align="center"><input type="submit" name="Search" value="Search" /></p>
</fieldset>
</div>
</form>
<div align="center">
<div style="overflow:auto; width:800px;" >

<table  border="0" cellspacing="1" cellpadding="5" align="center">
  	<tr>
  		<th><strong>Sr.No.</strong></th>
	  	<th><strong>Project</strong></th>
	  	<th><strong>Asset Group</strong></th>
	   	<th><strong>Invoice No</strong></th>
	   	<th><strong>Invoice Date</strong></th>
	   	<th><strong>Asset Name</strong></th>
	   	<th><strong>Sale Value</strong></th>
	    <th><strong>Other Receivables</strong></th>
	    <th><strong>Asset Amount</strong></th>
	    <th><strong>Tax</strong></th>
	    <th><strong>Tax Addition</strong></th>
	    <th><strong>Tax Deductions</strong></th>
	   	<th><strong>Total Amount</strong></th>  	
   </tr>
<?php
		if(isset($_POST['Search']))
		{
							       $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[]="tpl_fixed_assetsales_entry.project='".$_REQUEST['project']."'";
			if(isset($_REQUEST['asset_group']) && $_REQUEST['asset_group']!= '0')	
			$filter[]="tpl_fixed_assetsales_entry.asset_group='".$_REQUEST['asset_group']."'";
			if(isset($_REQUEST['asset_name']) && $_REQUEST['asset_name']!= '0')	
			{
			$assetname=DB_query("select asset_name from tpl_fixed_asset_definition where id='".$_REQUEST['asset_name']."'",$db);
			$assetdata=DB_fetch_array($assetname);
			$filter[]="tpl_fixed_assetsales_entry_details.asset_name='".$assetdata['asset_name']."'";
			}
			if($_REQUEST['todate']!='' && $_REQUEST['frmdate']!= '') 
			$filter[]="tpl_fixed_assetsales_entry.invoice_date  between '".$fdate."' and '".$toyrdate."'";
			if(isset($_REQUEST['request_no']) && $_REQUEST['request_no']!='0')
			$filter[]="tpl_fixed_assetsales_entry.invoice='".$_REQUEST['request_no']."'";
			if($filter!='')
			{			
			$filter1 = implode(" and ",$filter);	
			}
			if($filter1=='')
			{
			$filter1 ="1=1";
			}				
			
	$sql=DB_query("select tpl_fixed_assetsales_entry.*,tpl_fixed_assetsales_entry_details.* from tpl_fixed_assetsales_entry_details
	  inner join  tpl_fixed_assetsales_entry on (tpl_fixed_assetsales_entry.id=tpl_fixed_assetsales_entry_details.tpl_fixed_assetsales_entry_id)
	   where $filter1",$db);		

$i=1;
$total=0;
$asset_amt=0;
$num=DB_num_rows($sql);
if($num>0)
{
while($row=DB_fetch_array($sql))
	{
			$asset=DB_query("select * from tpl_materialcategorydefinition where id='".$row['asset_group']."' ",$db);
			$asset1=DB_fetch_array($asset);
			$assetgroupt=$asset1['asset_capitalisation'];  	
			$loc=DB_query("select * from locations where loccode='".$row['project']."'",$db);	
			$location=DB_fetch_array($loc);
			$total=$total+$row['total_amount'];
			$asset_amt=$asset_amt+$row['asset_amount'];
?>
    <tr>
	<td><?php echo $i; ?></td>
	<td><?php echo $location['locationname']; ?></td>
	<td><?php echo $assetgroupt; ?></td>
	<td><?php echo $row['invoice'] ?></td>
	<td><?php echo $row['invoice_date'] ?></td>
	<td><?php echo $row['asset_name']; ?></td>
	<td><?php echo $row['sale_value']; ?></td>
	<td><?php echo $row['other_receivables']; ?></td>
	<td><?php echo $row['asset_amount']; ?></td>
	<td><?php echo $row['tax']; ?></td>
	<td><?php echo $row['tax_addition']; ?></td>
	<td><?php echo $row['tax_deductions']; ?></td>
	<td><?php echo $row['total_amount']; ?></td>
  </tr>
<?php $i++; } ?> 
<tr><td colspan="7"></td>
<th>Total Asset</th><th><?php echo $asset_amt ; ?></th>
<td  colspan="2"></td><th>Grand Total</th><th><?php echo $total; ?></th>	
</tr>

<?php } else { ?>
	<tr><td colspan="13" style="text-align: center;"><strong><?php echo "No records"; ?></strong></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>




