<style>
#slidingDiv {
    display: none;
	height:100px;
	background-color: #D9D6DA;
	padding:20px;
}
</style>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1>Asset Opening Register </h1>
<form action="" method="post">
<table width="100%" border="0" cellspacing="0" cellpadding="3">
 
  <?php if(isset($daction))
  {?>
    <tr>  
    <td colspan="7" ><div class="success">
	<?php 
	 if($_REQUEST['daction']!=1 && $_REQUEST['daction']!=2)
	 echo "Record ".$_REQUEST['daction']." Successfully";
	 elseif($_REQUEST['daction']==1)
	 	 echo "Can't Delete This Record because AccountName Attatch with LedgerDayBook table ";
	 elseif($_REQUEST['daction']==2)		 
		 echo "Can't Delete This Record. First Delete it's Parent Record   ";
		 ?>
	</div></td>
  </tr>
  <?php }
  if(isset($msgErr)&&$msgErr!='' )
   {?>
    <tr>  
    <td colspan="7" ><div class="error"><?php 
for($kp=0;$kp<count($msgErr);$kp++)
 {
		echo  $msgErr[$kp].'<br>';
 }
  ?></div></td>
  </tr>
   <?php }?>
<tr class="row1">
	<td width="13%" align="right"><strong>Branch:</strong></td>
     <td width="20%">
	<?php  
 	$SQL_client=DB_query("SELECT loccode,prefix,locationname from locations Where companyid='".$_SESSION['ACGCompanyId']."'",$db);
	?>
<!--   <select  name="site" id="site" style="width:150px;"  onchange="ShowDiv(this.value,'hid-Godown-div','GoDownByBranch.php')"  >
-->   
   <select  name="site" id="site" style="width:98%;" onchange="getAssetList();">
	<option value="0" >--Select--</option>
   <?php
	while($row_client=DB_fetch_array($SQL_client)){?>
          <option value="<?php  echo $row_client['loccode']?>" <?php echo ($row_client['loccode']==$_REQUEST['site']) ? "selected" : "";?> >
          <?php  echo $row_client['locationname']?>
          </option>
          <?php }?>
      </select>   </td>
    <td width="13%" align="right"><strong>Asset Group:</strong></td>
    <td width="20%"><select name="asset_group" id="asset_group" style="width:98%;" onchange="getAssetList();">
      <option value="0">--Select--</option>
      <?php
		  $query2=DB_query("Select id, machine_gp_location from machine_group_master where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
			while($row2=DB_fetch_array($query2)){?>
      <option value="<?php echo $row2['id'];?>" <?php echo ($row2['id']==$_REQUEST['asset_group']) ? "selected" : "";?>><?php echo $row2['machine_gp_location'];?></option>
      <?php }
		  ?>
    </select></td>
	  <!-- <td width="13%" align="right"><strong>Asset Type</strong></td>
      <td>
		<select name="asset_type" id="asset_type" onchange="getAssetList();" style="width:98%;">
		<option value="0">-Select-</option>
		<option value="Heavy Machinary" <?php echo ($_REQUEST['asset_type'] == "Heavy Machinary") ? "selected" : "";?>>Heavy Machinary</option>
		<option value="Tool Plants" <?php echo ($_REQUEST['asset_type'] == "Tool Plants") ? "selected" : "";?>>Tool &amp; Plants</option>
		</select>		 
	  </td> -->
  	    <td width="13%" align="right"><strong>Asset Name:</strong></td> 
  	    <td>
		<?php $SQLMachine=db_query("SELECT * FROM machine_center WHERE CompanyId='".$_SESSION['ACGCompanyId']."'",$db );?> 
		<select  style="width:98%;" name="asset_name" id="asset_name">
			<option value="0">--Select--</option>
		<?php while($MachineNa=db_fetch_array($SQLMachine)){ ?>
		 	<option value="<?php echo $MachineNa['id']?>"  <?php echo ($MachineNa['id']==$_REQUEST['asset_name']) ? "selected" : "";; ?>><?php echo $MachineNa['name']; ?></option>
		<?php }?>
		</select></td>
	</tr>
	<tr class="row1">
		<td align="right"><strong>From Date:</strong></td>
    	<td><input type="text" name="frmdate" value="<?php echo $_REQUEST['frmdate']; ?>" id="frmdate" style="width:98%;" class="datepicker" /></td>
		<td align="right"><strong>To Date:</strong></td>
    	<td><input type="text" name="todate" value="<?php echo $_REQUEST['todate']; ?>" id="todate" style="width:98%;" class="datepicker" /></td>
    	<td colspan="2">&nbsp;</td>
	</tr>  
	<tr class="row1">
	<td style="text-align:center;" colspan="6"><input type="submit" name="Search" class="search" value="Search" /></td>
	</tr>
</table>
</form>

<?php
if(isset($_POST['Search']))
{
	if($_REQUEST['site']!='0')
	{	
		$filter[]="O.site='".$_REQUEST['site']."'";
	}
	if($_REQUEST['asset_group']!='0')	
	{
		$filter[]="A.under_group='".$_REQUEST['asset_group']."'";
	}
	/* if($_REQUEST['asset_type']!='0')	
	{
		$filter[]="A.asset_type='".$_REQUEST['asset_type']."'";
	} */
	if($_REQUEST['asset_name']!='0')	
	{
		$filter[]="A.id='".$_REQUEST['asset_name']."'";
	}
	
	if($_REQUEST['todate']!='' && $_REQUEST['frmdate']!= '')
	{ 
	 	$filter[]="O.opening_date  between '".FormatDateFORSQL($_REQUEST['frmdate'])."' and '".FormatDateFORSQL($_REQUEST['todate'])."'";
	}
	if($filter!='')
	{			
		$filter1 = implode(" and ",$filter);	
	}
	if($filter1=='')
	{
		$filter1 ="1=1";
	}
	
   /* $GetRecord = "SELECT O.opening_date, O.stock, O.rate, O.amount, A.asset_name, U.unitname, L.locationname 
			  FROM opening_stock_for_toolsplants_machine O
			  INNER JOIN tpl_fixed_asset_definition A ON A.id=O.machine_id
			  LEFT JOIN unitsofmeasure U ON U.unitid=A.unit_of_measurement			  
			  LEFT JOIN locations L ON L.loccode=O.site			  
			  WHERE O.CompanyId='". $_SESSION['ACGCompanyId']."' and $filter1"; */

			 $GetRecord = "SELECT O.opening_date, O.stock, O.rate, O.amount, A.name, U.unitname, L.locationname 
			  FROM opening_stock_for_toolsplants_machine O
			  INNER JOIN machine_center A ON A.id=O.machine_id
			  LEFT JOIN unitsofmeasure U ON U.unitid=A.unit			  
			  LEFT JOIN locations L ON L.loccode=O.site			  
			  WHERE O.CompanyId='". $_SESSION['ACGCompanyId']."' and $filter1";


?>
<table width="100%" border="1" cellspacing="0" cellpadding="3" style="border:#808080 1px solid; border-collapse:collapse;">
<tr>
	<th width="3%">S.No.</th>
	<th width="17%">Branch</th>
	<th>Asset Name</th>
	<th width="6%">UOM</th> 
	<th width="12%">Opening Qty.</th>
	<th width="8%">Rate</th>
	<th width="12%">Amount</th>
	<th width="9%">Opening Date</th> 
</tr>
<?php
$ResultData = DB_query($GetRecord,$db);
$i=1;
if(DB_num_rows($ResultData)>0){

$j=0;
while($RowData = DB_fetch_array($ResultData))
{
if($j++%2==0)
$bg="style='background-color:#FFFFFF'";
else
$bg="style='background-color:#CCCCCC'";
?>
<tr bgcolor="#fff">
	<td><?php echo $i;?></td>
	<td><?php echo $RowData['locationname'];?></td>
	<td><?php echo $RowData['name'];?></td>
	<td><?php echo $RowData['unitname'];?></td>
	<td style="text-align:right;"><?php echo $RowData['stock'];?></td>
	<td style="text-align:right;"><?php echo $RowData['rate'];?></td>
	<td style="text-align:right;"><?php echo $RowData['amount'];?></td>
	<td><?php echo ConvertSQLDate($RowData['opening_date']);?></td>
</tr>
	<?php $i++;}
}else{   
   ?> 
  <tr bgcolor="#fff"><td colspan="8" align="center"><font color="#FF0000">No Records Found</font></td></tr>
<?php }?>
</table> 
<?php
}?> 

<script language="JavaScript">

function getAssetList()
{

var site = document.getElementById("site").value;
var group = document.getElementById("asset_group").value;
var type = document.getElementById("asset_type").value;

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","getAsset.php?site="+site+"&group="+group+"&type="+type,true);
	xmlhttp.send();
}
$('.datepicker').removeClass('hasDatepicker').datepicker({ dateFormat: 'dd/mm/yy',changeMonth: true, changeYear: true,yearRange: '-80:+20'});
</script>
</div>
</div>