<script>
function showsitename160(str)
{
//alert(str);
var xmlhttp;
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_group").innerHTML=xmlhttp.responseText;
		
	 }
  }
  xmlhttp.open("GET","ajax_get_asset_group.php?branch="+str,true);
	xmlhttp.send();

//xmlhttp.open("GET","getSort.php?s="+str+"&cat="+cat,true);
	
}
</script>
<script>
function showsitename161(str)
{
//alert(str);
var xmlhttp;
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;
	showsitename162(str);

	 }
  }
  xmlhttp.open("GET","ajax_get_asset_name.php?branch1="+str,true);
	xmlhttp.send();
}

/*
function showsitename162(str)
{
//alert(str);
var xmlhttp;
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("request_no").innerHTML=xmlhttp.responseText;
	 }
  }
  xmlhttp.open("GET","ajax_get_request_no.php?id="+str,true);
	xmlhttp.send();
}
//xmlhttp.open("GET","getSort.php?s="+str+"&cat="+cat,true);
	*/

function showsitename162(str)
{
//alert(str);
var xmlhttp;
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest();
  }
else
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
	document.getElementById("vender").innerHTML=xmlhttp.responseText;
	 }
  }
  xmlhttp.open("GET","ajax_get_vendor_name.php?group_id="+str,true);
	xmlhttp.send();

//xmlhttp.open("GET","getSort.php?s="+str+"&cat="+cat,true);
	
}
</script>

<?php global $db; 
    $s=new DB_query();
 ?>
<?php ///echo $_REQUEST['vendor']; 
//echo $_REQUEST['location'];
//echo $_REQUEST['branch'];
?>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
 <div class="tab_div">
<form name="" id="" method="POST">
<h1>AMC Entry Report</h1>	
<table width="100%" cellpadding="3" cellspacing="0" border="0">
      <tr class="row1">
          <td width="13%" align="right"><strong>Branch:</strong></td>
          <td width="20%">
         <select name="branch" id="branch" onchange="showsitename160(this.value);" 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))
				{
					$s1='';
					if($_REQUEST['branch']==$row4['loccode'])
					$s1="selected";
					?>
					<option value=<?php echo $row4['loccode'];?> <?php echo $s1;?>><?php echo $row4['locationname'];?></option>
				<?php }
		  ?>
          </select>
          </td>
          <td width="13%" align="right"><strong>Asset Group:</strong></td>
          <td width="20%">
          <!--onchange="showsitename161(this.value);"-->
          	<select name="asset_group" id="asset_group" class="detailedViewTextBox" style="width:98%;"onchange="showsitename161(this.value)">           	
          <option value="0">Select Asset Group</option>
          <?php 
             $store_sql =DB_query("SELECT * FROM machine_group_master where branch_code = '".$_REQUEST['branch']."' 
             	order by branch_code",$db);
             while($row2=DB_fetch_array($store_sql))
             {
             	$t='';
             	if($_REQUEST['asset_group']==$row2['id'])
             		$t="selected";
             ?>	
            <option value="<?php echo $row2['id']; ?>" <?php echo $t; ?>><?php echo $row2['machine_gp_location']; ?></option>
            <?php } ?>
          </select>          
		  </td>
        <td width="13%" align="right"><strong>Asset Name:</strong></td>
        <td id="data1"><select name="asset_name"  id="asset_name" class="detailedViewTextBox" style="width:98%;" onchange="showsitename162(this.value);"   >
        <option value="0">Select</option> 
        		<?php 
             $store_sql1=DB_query("SELECT * FROM machine_center where id = '".$_REQUEST['asset_name']."'  ",$db);
             while($row21=DB_fetch_array($store_sql1))
             {
             	$t12='';
             	if($_REQUEST['asset_name']==$row21['id'])
             		$t12="selected";

             ?>	
            <option value="<?php echo $row21['id']; ?>" <?php echo $t12; ?>><?php echo $row21['name']; ?></option>
            <?php } ?>
        </select></td><!--
        <tr><th>Request No</th>
        <td id="data1">
        <<select name="request_no"  id="request_no" class="detailedViewTextBox" style="width:100%;" onchange="showsitename163(this.value);" >
        	<option value="">Select request no</option>
        	<?php 
        		$sql9=DB_query("SELECT * FROM tpl_amc where id = '".$_REQUEST['vendor']."'",$db);
        		while($row4=DB_fetch_array($sql9))
        		{
        			$u='';
        			if($_REQUEST['request_no']==$row4['id'])
        				$u='selected';
        		        	?>
        		    <option value="<?php echo $row4['id']; ?>" <?php echo $u; ?>><?php echo $row4['slip_no']; ?></option>
        		     <?php } ?>
        	
        	
        </select></td> 	
        </tr>-->
    </tr>
    <tr class="row1">
        <td align="right"><strong>Vendor Name:</strong></td>
        <td id="data1"><select name="vender" id="vender" class="detailedViewTextBox" style="width:98%;" >
        <option value="0">Select vendor name</option> 
        <?php 
        		$sql8=DB_query("SELECT * FROM suppliers where id = '".$_REQUEST['vendor']."'",$db);
        		while($row3=DB_fetch_array($sql8))
        		{
        			$p='';
        			if($_REQUEST['request_no']==$row3['id'])
        				$p='selected';
        		        	?>
        		    <option value="<?php echo $row3['id']; ?>" <?php echo $p; ?>><?php echo $row3['vendor_name']; ?></option>
        		     <?php } ?>           	
        </select></td>
        <td align="right"><strong>From Date:</strong></td>
        <td id="data1"><input type="text" name="frmdate" id="frmdate" style="width:98%;" value="<?php echo $_REQUEST['frmdate'] ?>" class="datepicker" /></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>
    </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>     -->   
    <tr class="row1">
      <td colspan="6" align="center"><input type="submit" name="Search" value="Search" class="search" /></td>
    </tr> 
		</table>

</form>

<p align="right" id="print"><a href="amc_entry_print.php" target="_blank" class="search">Print</a></p>

<table  border="1" cellspacing="0" cellpadding="3" align="center" width="100%" style="border:#808080 1px solid; border-collapse:collapse;">
  	<tr>
  		<th width="4%">S.No.</th>
	  	<th width="12%">Branch</th>
	  	<th width="12%">Asset Group</th>
	  	<th>Asset Name</th>
	   	<th width="8%">Request No.</th>
	   	<th width="12%">Vendor Name</th>	   	
	   	<th width="8%">AMC Start Date</th>
	   	<th width="8%">AMC End Date</th>
	    <th width="9%">AMC Amount</th>
	    <!--
	    <th><strong>AMC Amount Billed</strong></th>
	    <th><strong>Additional Amount</strong></th>
	    <th><strong>Additional Billed Amount</strong></th>
	    <th><strong>Total Amount</strong></th>
	    <th><strong>Balance Amount</strong></th>	  --> 	  	
   </tr>
<?php
if(isset($_POST['Search']))
{
   echo "<script>
document.getElementById('print').style.display = 'block';
</script>";

    $fordate = $_POST['frmdate'];
	$todate = $_POST['todate']; 
	//echo $_REQUEST['frmdate'];
	//echo $_REQUEST['todate'];



	// $filter[]="tpl_amc_dtls.start_date  between '".FormatDateFORSQL($_REQUEST['frmdate'])."' and '".FormatDateFORSQL($_REQUEST['todate'])."'";
	//echo "<pre>";
	//print_r($_REQUEST);
	//echo $_REQUEST['asset_group'];
	$filter = array();
	if($_REQUEST['branch']!= '0')	
	$filter[]="tpl_amc.site='".$_REQUEST['branch']."'";
	
	
	if($_REQUEST['asset_group']!='0')	
	  $filter[]="machine_center.under_group='".$_REQUEST['asset_group']."'";  

	//if($_REQUEST['vender']!='0' && $_REQUEST['vender']!='')	
	//$filter[]="tpl_amc.vendor_id='".$_REQUEST['vender']."'";
	if($_REQUEST['asset_name']!='0' && $_REQUEST['asset_name']!='')	
	$filter[]="tpl_amc_dtls.asset_id='".$_REQUEST['asset_name']."'";
	//$asset_id=$s->GetFieldValue('machine_center',"under_group='".$_REQUEST['asset_name']."'",'id');
	
	//if($_REQUEST['asset_name']!='0' && $_REQUEST['asset_name']!='')	
	//$filter[]="tpl_amc_dtls.asset_id=$asset_id";

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

if($_REQUEST['todate']!='' && $_REQUEST['frmdate']!='')
	{ 
	//	echo "hi";
	$filter[]="(tpl_amc_dtls.start_date  between '".FormatDateFORSQL($_REQUEST['frmdate'])."' and '".FormatDateFORSQL($_REQUEST['todate'])."')" or
	"(tpl_amc_dtls.end_date  between '".FormatDateFORSQL($_REQUEST['frmdate'])."' and '".FormatDateFORSQL($_REQUEST['todate'])."')" ;
	
	}	

	/*if(isset($_REQUEST['asset_name']) && $_REQUEST['asset_name']!= '0')	
	{
	//$assetname=DB_query("select name from machine_center where id='".$_REQUEST['asset_name']."'",$db);
	//$assetdata=DB_fetch_array($assetname);
	$filter[]="tpl_amc_dtls.asset_id='".$_REQUEST['asset_name']."'";
	}
	
	if(isset($_REQUEST['request_no']) && $_REQUEST['request_no']!='0')
	$filter[]="tpl_amc.slip_no='".$_REQUEST['request_no']."'";
	if(isset($_REQUEST['vender']) && $_REQUEST['vender']!='0')
	$filter[]="tpl_amc.vendor_id='".$_REQUEST['vender']."'"; */
	
	//echo "<pre>";
	//print_r($filter);	
	if($filter!='')
	{			
	$filter1 = implode(" and ",$filter);	
	}
	/*if($filter1=='')
	{
	$filter1 ="CompanyId='".$_SESSION['ACGCompanyId']."'";
	}*/
		 if($filter1!='')
		 {
		$sql1="select tpl_amc.*,tpl_amc_dtls.end_date,tpl_amc_dtls.start_date,tpl_amc_dtls.amount,tpl_amc_dtls.asset_id,machine_center.under_group from tpl_amc_dtls left join  tpl_amc on tpl_amc.id=tpl_amc_dtls.tpl_amc_id left join machine_center on tpl_amc_dtls.asset_id=machine_center.id where $filter1";// echo "select tpl_amc.*,tpl_amc_dtls.*,machine_center.under_group from tpl_amc_dtls left join  tpl_amc on tpl_amc.id=tpl_amc_dtls.tpl_amc_id left join machine_center on tpl_amc_dtls.asset_id=machine_center.id where $filter1";
	
	  }
	  else
	  {
	  	$sql1="select tpl_amc.*,tpl_amc_dtls.end_date,tpl_amc_dtls.start_date,tpl_amc_dtls.amount,tpl_amc_dtls.asset_id,machine_center.under_group from tpl_amc_dtls left join  tpl_amc on tpl_amc.id=tpl_amc_dtls.tpl_amc_id left join machine_center on tpl_amc_dtls.asset_id=machine_center.id";
	 	//echo "select tpl_amc.*,tpl_amc_dtls.end_date,tpl_amc_dtls.start_date,tpl_amc_dtls.amount,tpl_amc_dtls.asset_id,machine_center.under_group from tpl_amc_dtls left join  tpl_amc on tpl_amc.id=tpl_amc_dtls.tpl_amc_id left join machine_center on tpl_amc_dtls.asset_id=machine_center.id";

	  }	
 $_SESSION['myone']=$sql1;

$amount=0;
$balamt=0;	
$sql=	DB_query($sql1,$db);

$i=0;
//$sql=DB_query("select p.slip_no,c.start_date,c.end_date,c.amount from tpl_amc p inner join tpl_amc_dtls c on p.id=c.tpl_amc_id",$db);
 $num=DB_num_rows($sql);
if($num>0)
{
while($row=DB_fetch_array($sql))
	{
		$i++;
		
	 /*
	$asset=DB_query("select * from machine_group_master where id='".$row['asset_group']."' ",$db);
	$asset1=DB_fetch_array($asset);
	$assetgroupt=$asset1['machine_gp_location'];  	
	$loc=DB_query("select * from locations where loccode='".$row['site']."'",$db);	
	$location=DB_fetch_array($loc);
	$venderdata=DB_query("select vendor_name from suppliers where id='".$row['vendor_id']."'",$db);
	$vender1=DB_fetch_array($venderdata);
	$amount=$amount+$row['total_amt'];
	$balamt=$balamt+$row['bal_amt'];
	<?php echo $location['locationname']; ?>
	<?php echo $assetgroupt; ?>
	<?php echo $s->GetFiel('machine_center',"id='".$row['asset_id']."'",'name'); ?>
	*/


?>
<tr bgcolor="#fff">
	<td> <?php echo $i; ?></td>
	<td><?php echo $s->getField('locations','loccode',$row['site'],'locationname'); ?></td>
	<td><?php $asset_id=$s->getField('machine_center','id',$row['asset_id'],'under_group');
	      echo $group=$s->getField('machine_group_master','id',$asset_id,'machine_gp_location');
	       ?></td>
	<td><?php echo $s->getField('machine_center','id',$row['asset_id'],'name'); ?></td>
	<td><?php echo $row['slip_no']; ?></td>
	<td><?php echo $s->getField('suppliers','id',$row['vendor_id'],'vendor_name'); ?></td>	
	<td><?php  echo date('d/m/Y',strtotime($row['start_date']));?></td>
	<td><?php  echo date('d/m/Y',strtotime($row['end_date']));?></td>	
	<td><?php echo $row['amount'];  ?></td>	
</tr>
<?php  } ?>

<?php } else { ?>
	<tr bgcolor="#fff"><td colspan="14" style="text-align: center;"><strong><?php echo "No records"; ?></strong></td></tr>	 
	<?php } }?> 
</table>
</div></div>


