<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1>Fixed Asset Transfer Receipt Report</h1>
<form name="" id="" method="POST">	
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr class="row1">
	<td width="9%" class="tabledata1">Receive Site </td>         
	<td width="24%">
	<select name="receive_site" id="receive_site" class="detailedViewTextBox" style="width:150px;" onchange="getEmployeeList(this.value);">
	<option value="0">Select Project</option>
	<?php
	$query4=DB_query("Select loccode, locationname from locations where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
	while($row4=DB_fetch_array($query4))
	{
	$s='';
	if($receive_site==$row4['loccode'])
	$s="selected";
	?>
	<option value=<?php echo $row4['loccode'];?> <?php echo $s;?>><?php echo $row4['locationname'];?></option>
	<?php }
	?>
	</select>
	</td>
	<td width="9%" class="tabledata1">Received By </td>
	<td width="25%">
	<select name="received_by" id="received_by" style="width:150px;" class="detailedViewTextBox">
			<option value="0">--Select--</option>
			<?php
			echo $empsql = "select id, emp_name from empmaster where emp_site='".$reqRow['requested_site']."' and CompanyId='".$_SESSION['ACGCompanyId']."' ORDER BY emp_name";
			$empres = DB_query($empsql,$db);
			while($empRow = DB_fetch_array($empres)){?>
		<option value="<?php echo $empRow['id'];?>" <?php echo ($empRow['id']==$requested_by) ? "selected" : ""; ?>><?php echo $empRow['emp_name'];?></option>
		<?php }
			?>
	</select>

	</td>
	<td width="8%" class="tabledata1">Receive No</td>
    <td width="24%"><select name="receive_no"  id="receive_no"  style="width:150px;">
        	<option value="0">Select</option>
        	<?php
		  $query2=DB_query("Select receive_no from tpl_asset_transfer_receive ",$db);
			while($row2=DB_fetch_array($query2)){?>
					<option value="<?php echo $row2['receive_no'];?>"<?php echo ($_REQUEST['receive_no']==$row2['receive_no']) ? "selected" : "" ;?>><?php echo $row2['receive_no'];?></option>
				<?php }
		  ?>
        	
        </select></td> 	
	
	
</tr>
<tr class="row1">
	<td class="tabledata1">From Date</td>
	<td><input type="text" name="frmdate" id="frmdate" style="width:150px;" class="datepicker" /></td>
	<td class="tabledata1">To Date</td>
	<td colspan="3"><input type="text" name="todate" id="todate" style="width:150px;" class="datepicker" /></td>
	<td width="1%"></td>
</tr> 
<tr class="row1">
	<td class="tabledata1" style="text-align:center;" colspan="6">
	<input type="submit" name="Search" class="search" value="Search" />
	</td>
</tr>        
</table>
</form>
<table width="100%"  border="1" cellspacing="1" cellpadding="3">
  <tr class="row1">
    <td width="3%" class="tabledata">Sr. No.</td>
    <td width="11%" class="tabledata">Received slip No</td>
    <td width="5%" class="tabledata">Date</td>
    <td width="10%" class="tabledata">Request No</td>
    <td width="9%" class="tabledata">Request Date</td>
    <td width="10%" class="tabledata">Received From</td>
    <td width="8%" class="tabledata">Asset Code</td>
    <td width="14%" class="tabledata">Asset Name</td>
    <td width="13%" class="tabledata">Asset Group</td>
    <td width="4%" class="tabledata">Rec Qty</td>
    <td width="4%" class="tabledata">Req Qty</td>
    <td width="9%" class="tabledata">Pending Qty</td>
  </tr>
  <?php
if(isset($_POST['Search']))
{
      
	$filter = array();
	
	if(isset($_REQUEST['received_site']) && $_REQUEST['received_site']!= '0')	
	$filter[]="R.received_site='".$_REQUEST['received_site']."'";
	
	if($_REQUEST['todate']!='' && $_REQUEST['frmdate']!= ''){
		//$fromdate = date(''
	 $filter[]="R.receive_date  between '".FormatDateForSQL($_REQUEST['frmdate'])."' and '".FormatDateForSQL($_REQUEST['todate'])."'";
	 }
	
	if(isset($_REQUEST['received_by']) && $_REQUEST['received_by']!='0')
	$filter[]="R.received_by='".$_REQUEST['received_by']."'";

	if(isset($_REQUEST['receive_no']) && $_REQUEST['receive_no']!='0')
	$filter[]="R.receive_no='".$_REQUEST['receive_no']."'";
	
	if($filter!='')
	{			
	$filter1 = implode(" and ",$filter);	
	}
	if($filter1=='')
	{
	$filter1 ="L.CompanyId='".$_SESSION['ACGCompanyId']."'";
	}
	
	$sql1 = "select R.id, R.receive_no, R.receive_date, R.received_by, RE.request_no, RE.request_date, L.locationname, E.emp_name
					from tpl_asset_transfer_receive R
	  				INNER JOIN tpl_asset_transfer_request RE ON (RE.id=R.requested_id)
					INNER JOIN tpl_asset_transfer_issue I ON (I.id=R.issue_id)
					INNER JOIN locations L ON L.loccode=I.site
					INNER JOIN empmaster E on E.id=R.received_by
				    WHERE $filter1";
	   
	$sql=DB_query($sql1,$db);
		

$i=1;
$j=0;
$assetrequired=array();
$num=DB_num_rows($sql);
if($num>0)
{
while($row=DB_fetch_array($sql))
	{
		//echo "select required_qty  from tpl_asset_transfer_issue_details where tpl_asset_transfer_issue_id='".$row['transfer_issueno']."'";
	$assetid=DB_query("select required_qty from tpl_asset_transfer_receive_details where receive_id='".$row['id']."'",$db);
	while($assetdata=DB_fetch_array($assetid))
	{
	$assetrequired[]=$assetdata['required_qty'];
	}
	
		
?>
  <tr class="row1">
    <td><?php echo $i; ?></td>
    <td><?php echo $row['receive_no']; ?></td>
    <td><?php echo ConvertSQLDate($row['receive_date']); ?></td>
    <td><?php echo $row['request_no'] ?></td>
    <td><?php echo ConvertSQLDate($row['receive_date']); ?></td>
    <td><?php echo $row['locationname']; ?></td>
    <td colspan="6"><table width="100%" border="1" cellspacing="1" cellpadding="3" style="border-color:#000000">
      <?php
		$reqDet_sql = "SELECT R.required_qty, R.asset_group, RE.received_qty, A.asset_code_prefix, A.asset_name 
					   FROM tpl_asset_transfer_receive_details RE
					   INNER JOIN tpl_asset_transfer_issue_details I ON I.id=RE.issue_row_id
					   INNER JOIN tpl_asset_transfer_request_details R ON R.id=I.asset_row_id
					   INNER JOIN tpl_fixed_asset_definition 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 bgcolor="#99CCCC">
        <td width="15%"><?php  echo $assetRow['asset_code_prefix'];?></td>
        <td width="27%"><?php  echo $assetRow['asset_name'];?></td>
        <td width="25%"><?php  echo $assetRow['asset_group'];?></td>
        <td width="8%"><?php  echo $assetRow['received_qty'];?></td>
        <td width="8%"><?php  echo $assetRow['required_qty'];?></td>
        <td width="17%"><?php  echo (int)$assetRow['required_qty']-(int)$assetRow['received_qty'];?></td>
      </tr>
      <?php	}
		}
	?>
    </table></td>
  </tr>
  <?php $i++;}
	} else { ?>
  <tr>
    <td colspan="8" 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 getEmployeeList(str){
if(str=="")
  {
  document.getElementById("received_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("received_by").innerHTML=xmlhttp.responseText;
	}
	}
	
	
	xmlhttp.open("GET","getEmpList.php?site="+str,true);
	xmlhttp.send();

}
</script>

