<?php  
$url_cancel= "index.php?route=ToolPlants/Transaction/amc_entry".$rurl;
$url_add= "index.php?route=ToolPlants/Transaction/amc_entry_index".$rurl;

if($_REQUEST['action']=='delete' && !empty($_REQUEST['rid']))
{
	if($s->DeleteRecord('tpl_asset_transfer_request',"id=".$_REQUEST['rid']))
	{
	$s->DeleteRecord('tpl_asset_transfer_request_details',"asset_req_id=".$_REQUEST['rid']);
	$_SESSION['success_msg']="Delete Successfully";
	}
}

if($_REQUEST['Cancel']!='')
{
unset($_SESSION['manvi']);
unset($_SESSION['qutotation_itemcode']);	
	unset($_REQUEST);
}
?>
<link rel="stylesheet" href="css/new_mxerp.css">
<form action="" method="post">
<div class="body_contain">
<div class="tab_div">
<h1>AMC Entry </h1>

<table width="100%" cellpadding="3" cellspacing="0" border="0">
<tr class="row1">
	<td width="13%" align="right">Branch</td>
	<td width="20%"><select  id="site" name="site" onchange="showJobCardNo(this.value)">
	  <option value ="0">--Select--</option>
	<?php 
	$site_sql=DB_query("Select loccode,locationname from locations where CompanyId='".$_SESSION['ACGCompanyId']."' ",$db);
	    while($site_row=DB_fetch_array($site_sql))
	{
		
	?>
	<option value="<?php echo $site_row['loccode']?>"<?php echo($_REQUEST['site']==$site_row['loccode']?'selected':''); ?>><?php echo $site_row['locationname']?></option>
	<?php } ?>
	</select></td>
	<td width="13%" align="right">From Date</td>
	<td width="20%"><input type="text" name="fromdate" id="fromdate" class="datepicker" value="<?php  echo $_REQUEST['fromdate']?>"  onchange="return validatefield();" /></td>
	<td width="13%" align="right">To Date</td>
	<td><input type="text" name="todate" id="todate" class="datepicker" value="<?php  echo $_REQUEST['todate']?>"   onchange="return validatefield();"/></td>
</tr>						
<tr class="row1">
	<td colspan="6" align="center" style="text-align:center;"><input type="submit" name="submit" value="Search" id="view" onClick="return validate()" class="search"  /></td>
</tr>
</table>
  <p style="text-align:left;">
<a href="index.php?route=ToolPlants/Transaction/amc_entry_index&rid=<?php echo $id;?>&modid=<?php echo $_REQUEST['modid']; ?>&frmid=<?php echo $_REQUEST['frmid']; ?>"><input class="search" type="button" name="submit" value="Add New" id="view1"  /></a>
  </p>

  				<?php 
if($_REQUEST['submit']!='')
{
	$fromdate=$_REQUEST['fromdate'];
	$todate=$_REQUEST['todate'];
	
	$fromdate_brk=explode('/',$fromdate);
	$from=$fromdate_brk[2]."-".$fromdate_brk[1]."-".$fromdate_brk[0];
	$todate_brk=explode('/',$todate);
	$to=$todate_brk[2]."-".$todate_brk[1]."-".$todate_brk[0];
	
	$sitename=$s->getField('locations','loccode',$_REQUEST['site'],'locationname');
	$assetname=$s->getField('machine_center','id',$_REQUEST['asset_name'],'name');	
	
	$filter=array();
	if($_REQUEST['site']!='0')
	{
		$filter[]="site = '".$_REQUEST['site']."'";
	}
	
		if($_REQUEST['fromdate']!='' && $_REQUEST['todate']!='')
	{
		$filter[]="created_date BETWEEN '".$from."' and '".$to."'";
	}
	//print_r($filter);
	if($filter!='')
	{
		$filter1=implode(' and ',$filter);		
     }

     if($filter1!='')
     {
     	$sql="select * from tpl_amc where $filter1";
     }
     else
     {
     	$sql="select * from tpl_amc";
     }	
}
?>
<?php $_SESSION['myone']=$sql; ?>

<table width="100%" border="0" cellspacing="0" cellpadding="3" class="thborder">
<tr>
	<th width="4%" rowspan="2">S. No.</th>
	<th width="15%" rowspan="2">Branch</th>
	<th width="10%" rowspan="2">AMC No.</th>
	<th width="15%" rowspan="2">Vendor Name</th>
	<th width="8%" rowspan="2">Financial Year</th>				
	<th rowspan="2">Asset Name</th>
<!--	<?php 
   $title1=DB_query("select * from tbl_title_master order by serial_no ASC limit 0,3",$db);
   while($r=DB_fetch_array($title1))
   { 
    ?>
    <th width="150"><?php echo $r['title_name'];?></th>
    <?php } ?> -->	
	<th width="90" rowspan="2">Start date</th>
	<th width="90" rowspan="2">End date</th>
	<th width="100" class="text-center" rowspan="2">Amount</th>
	<th colspan="2" style="text-align:center;">Action</th>	
</tr>
<tr>
	<th width="5%" class="text-center">Edit</th>
	<th width="5%" class="text-center">Delete</th>
</tr>
<?php 
//$record=$s->GetRecordById('tpl_asset_transfer_request',1);
if($filter1!='')
     {
     	$sql="select * from tpl_amc where $filter1";
     }
     else
     {
     	$sql="select * from tpl_amc";
     }
		// $_SESSION['myone']=$sql;	 
 $record=DB_query($sql,$db);
$i=0;
if(DB_num_rows($record)>0){
while($row=DB_fetch_array($record))
{
$i++;
extract($row);
$pid=$row['id'];


?>
<tr>
<td><?php echo $i;?></td>
<td><?php echo $s->getField('locations','loccode',$row['site'] ,'locationname'); ?></td>
<td><?php echo $row['slip_no']; ?></td>
<td><?php echo $s->getField('suppliers','id',$row['vendor_id'] ,'vendor_name'); ?></td>
<td><?php
 $sdate=$s->getField('company_financial_years','id',$row['fin_year'] ,'year_start');
 $sdate1=explode("-",$sdate);
 $sdate2=$sdate1[0];
 $edate=$s->getField('company_financial_years','id',$row['fin_year'] ,'year_end');
$edate1=explode("-",$edate);
$edate2=$edate1[0];
echo $sdate2."-".$edate2;
?></td>
<td colspan="4" style="padding:0px;" valign="top">
	<div id="amc-tab">
	<table width="100%" border="0" cellpadding="3" cellspacing="0">
	<?php
		$reqDet_sql = "select * from tpl_amc_dtls where tpl_amc_id=$pid;";
					
		$result = DB_query($reqDet_sql,$db);
		if(DB_num_rows($result)>0){
			while($assetRow = DB_fetch_array($result)){?>
				<tr>
				    <td><?php  echo $s->getField('machine_center','id',$assetRow['asset_id'] ,'name');?></td>
					<td width="90"><?php  echo date('d/m/Y',strtotime($assetRow['start_date']));?></td>
				    <td width="90"><?php  echo date('d/m/Y',strtotime($assetRow['end_date']));?></td>
    				<td width="100" style="text-align:right;"><?php  echo $assetRow['amount'];?></td>	
			  </tr>
		<?php	}
		}
	?>	
	</table>
	</div>
</td>
<!--<td ><?php  echo $approved_status;?> </td>
<td><?php  echo $issued_status;?> </td>
<td><?php  echo $received_status;?> </td>-->
<td style="text-align:center;">
<?php //$url ="index.php?route=ToolPlants/Transaction/amc_edit&modid=24&frmid=839 ";?>
<a href="index.php?route=ToolPlants/Transaction/amc_edit&rid=<?php echo $id;?>&modid=<?php echo $_REQUEST['modid']; ?>&frmid=<?php echo $_REQUEST['frmid']; ?>"><img src="images/icon-edit.png" width="15" height="15" title="Edit" ></a></td>
<!--
<td width="">
<a  href="index.php?route=ToolPlants/Transaction/amc_view&rid=<?php echo $id;?>&modid=<?php echo $_REQUEST['modid']; ?>&frmid=<?php echo $_REQUEST['frmid']; ?>" >View</a>
</td>-->
<td style="text-align:center;"><a target="_blank" href="amc_print.php?rid=<?php echo $id;?>" ><img width="18" height="18" src="images/icon_print.jpg" title="Print" ></a></td>
</tr><?php 
    } } 

else{?>
<tr>
<td colspan="15"><font color="#FF0000">No Record Found</font></td>
</tr>
<?php }?>
</table>
<?php if(isset($_SESSION['success_msg']))
{ ?>
	<script> alert("<?php echo ($_SESSION['success_msg']);?>");</script>
<?php 
}	unset($_SESSION['success_msg']);
?>
</div>
</div>
</form>
<script>
function validate()
{
	if(document.getElementById("site").value=='0')
	{
	alert("Must Select Branch Name");
	document.getElementById("site").focus();
	return false;	
	}	
	return true;
}	

/* function validatefield()
{
	//alert("hi");
	
		$( "#fromdate" ).datepicker({ dateFormat: 'dd-mm-yy' });
		$( "#todate" ).datepicker({ dateFormat: 'dd-mm-yy' });

		if(document.getElementById("fromdate").value!='' && document.getElementById("todate").value!='')
		{

			var start = $('#fromdate').datepicker('getDate');
			var end   = $('#todate').datepicker('getDate');
             alert(start);
             alert(end);
			if (start>end) 
			{
			    var days   = (end - start)/1000/60/60/24;
				if(days>1)
				{
					return true;
				}
			   else
			    {
					alert("From date cannot be greater than To Date.");
					return false;
		        } 

		       // alert("From date cannot be greater than To Date");
			    //return false;
           }
      }
    else
     {

			alert("Please Fill From Date and To Date" );
			return false;
     }

} */


</script>