<link rel="stylesheet" href="css/new_mxerp.css">
<style type="text/css">
#amc-tab{}
  #amc-tab table{border:none; border-collapse:collapse; }
  #amc-tab table tr td{border-right:#808080 1px solid; border-bottom:#808080 1px solid;}
  #amc-tab table tr td:last-child{border-right:none;}
  #amc-tab table tr:last-child td{border-bottom:none;}
  #amc-tab table tr td > table tr td{border-right:#808080 1px solid; border-bottom:#808080 1px solid;}
  #amc-tab table tr td > table tr td:last-child{border-right:none;}
  #amc-tab table tr td > table tr:last-child td{border-bottom:none;}
</style>
<div class="body_contain">
<div class="tab_div">
<h1><?php echo $s->getField('modules_form','id',$_REQUEST['frmid'],'description');?></h1>
<form name="" id="" method="POST">
<fieldset class="bggreen">
<table width="100%" border="0" align="center" cellpadding="3" cellspacing="0">
<tr class="row3" style="height:5px"><td colspan="4"></td></tr>
<tr class="row3">
	<td width="13%" align="right"><strong>Branch:</strong></td>         
    <td width="35%"><select name="site" id="site" style="width:98%;">
          <option value="0">Select Branch</option>
          <?php
		    $query4=DB_query("Select loccode, locationname from locations where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
			while($row4=DB_fetch_array($query4))
				{
					$s='';
					if($_REQUEST['site']==$row4['loccode'])
					$s="selected";
					?>
					<option value=<?php echo $row4['loccode'];?> <?php echo $s;?>><?php echo $row4['locationname'];?></option>
				<?php }
		  ?>
          </select>          </td>
	<td width="13%" align="right"><strong>Job Card No.:</strong></td>
    <td><select name="slip_no"  id="slip_no" style="width:98%;" >
      <option value="0">Select</option>
      <?php
		  $query2=DB_query("Select id,tt_no from tpl_breakdown_mgmt ",$db);
			while($row2=DB_fetch_array($query2))
				{
					$s='';
					if($_REQUEST['slip_no']==$row2['id'])
					$s="selected";
					?>
      <option value=<?php echo $row2['id'];?> <?php echo $s;?>><?php echo $row2['tt_no'];?></option>
      <?php }
		  ?>
    </select></td>
</tr>

<tr class="row3">
	<td align="right"><strong>From Date:</strong></td>
    <td><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 class="row3">
	<td colspan="4" style="text-align:center;"><input type="submit" name="Search" class="search" value="Search" /></td>
</tr>
<tr class="row3" style="height:5px"><td colspan="4"></td></tr> 
<?php if(isset($_POST['Search']))
{
      
	$filter = array();
	
	if(isset($_REQUEST['site']) && $_REQUEST['site']!= '0')	
	$filter[]="R.site='".$_REQUEST['site']."'";
	
	
	if($_REQUEST['todate']!='' && $_REQUEST['frmdate']!= '') 
	
	 $filter[]="R.assign_date  between '".FormatDateFORSQL($_REQUEST['frmdate'])."' and '".FormatDateFORSQL($_REQUEST['todate'])."'";
	 
	if(isset($_REQUEST['slip_no']) && $_REQUEST['slip_no']!='0')
	$filter[]="I.id='".$_REQUEST['slip_no']."'";
	
	if($filter!='')
	{			
	$filter1 = implode(" and ",$filter);	
	}
	if($filter1=='')
	{
	$filter1 ="I.CompanyId='".$_SESSION['ACGCompanyId']."'";
	}
	$sqlq = "SELECT I.*,R.*, I.site,I.tt_no,I.rec_from,I.rec_by,I.id AS MAIN_ID,R.id
	         FROM tpl_breakdown_mgmt I
	         INNER JOIN tpl_breakdown_mgmt_assig R ON (I.id=R.job_id)
	         WHERE $filter1";
			 
	$_SESSION['machine_breakdown_assign_report'] = $sqlq;
	$sql=DB_query($sqlq,$db);
	$s=new db_query();	
?>     
</table>
</fieldset>
<p align="right"><a href="machine_breakdown_assign_report_print.php?site=<?php echo $_REQUEST['site'];?>&slip_no=<?php echo $_REQUEST['slip_no'];?>&frmdate=<?php echo $_REQUEST['frmdate'];?>&todate=<?php echo $_REQUEST['todate'];?>" target="_blank" class="search">Print</a></p>
<div style="width:100%; margin:auto; overflow:auto;">
<table width="180%" border="1" cellspacing="0" cellpadding="3" style="border:#808080 1px solid; border-collapse:collapse;">
  	<tr>
  		<th width="2%">S. No.</th>
	  	<th>Branch</th>
	    <th width="6%">Slip No.</th>
	    <th width="3%">Slip Date</th>
	    <th width="5%">Job Card No.</th>
	    <th width="5%">Job Card Date</th>
	    <th width="7%">Breakdown Location</th>
	   	<th width="6%">Received By</th>
	   	<th width="100">Asset Code</th>
	   	<th width="200">Asset Name</th>
	   	<th width="160">Asset Group</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="100"><?php echo $r['title_name'];?></th>
    <?php } ?>
      <th width="100">Breakdown Type</th>
	  <th width="100">Breakdown Sub Type</th>
	  <th width="100">Breakdown Reason</th>
      <th width="100">Technician</th>
      <th width="100">Received Date</th>
	  <th width="100">Exp.Com. Date</th>
   </tr>
<?php

$i=1;
$num=DB_num_rows($sql);
if($num>0)
{
while($row=DB_fetch_array($sql))
	{
		//echo $row['id'];
		//echo "<pre>";print_r($row);
?>
<tr bgcolor="#FFFFFF">
	<td><?php echo $i; ?></td>
	<td><?php echo $row['site']; ?></td>
	<td><?php echo $row['slip_no']; ?></td>
	<td><?php echo date("d/m/Y",strtotime($row['assign_date'])); ?></td>
	<td><?php echo $row['tt_no']; ?></td>
	<td><?php echo date("d/m/Y",strtotime($row['asset_rec_date_time'])); ?></td>
	<td><?php echo $row['rec_from'] ?></td>
	<td><?php echo $row['rec_by']; ?></td>
	<td colspan="6" valign="top" style="padding:0px;">
	 <div id="amc-tab">
		<table width="100%" border="0" cellpadding="3" cellspacing="0">
	<?php
		$reqDet_sql = "SELECT asset_id FROM tpl_breakdown_mgmt_machine
					   WHERE master_id='".$row['MAIN_ID']."'";
		$result = DB_query($reqDet_sql,$db);
		if(DB_num_rows($result)>0){
			while($assetid = DB_fetch_array($result)){
                $assets = DB_query("SELECT * FROM machine_center WHERE id='".$assetid['asset_id']."'",$db);
                $assetRow = DB_fetch_array($assets);

                $reqDet_sql1 = "SELECT * FROM machine_group_master WHERE id= ".$assetRow['under_group']."";
		$result1 = DB_query($reqDet_sql1,$db);
		$assetRow1 = DB_fetch_array($result1);
                            ?>
				<tr>
				  <td width="100"><?php  echo $assetRow['code'];?></td>
				  <td width="200"><?php  echo $assetRow['name'];?></td>
				  <td width="160"><?php  echo $assetRow1['machine_gp_location'];?></td>
					<?php 
   $title1=DB_query("select * from tbl_title_master order by serial_no ASC limit 0,3",$db);
   while($r=DB_fetch_array($title1))
   { 
    ?>
    <td width="100"><?php echo $assetRow[$r['db_field_name']];?></td>
    <?php } ?>
				</tr>
		<?php	}
		}
	?>	
	</table>
	</div>
	</td>
	<td colspan="6" align="left" valign="top" style="padding:0px;">
	 <div id="amc-tab">
		<table cellspacing="0" cellpadding="3" border="0" width="100%" style="border:none;">
		<?php 
		//echo "SELECT * FROM tpl_breakdown_mgmt_details WHERE master_id='".$main_id."'";
		//echo "SELECT * FROM tpl_breakdown_mgmt_details WHERE master_id='".$row['MAIN_ID']."'";
		$id_query1=DB_query("SELECT * FROM tpl_breakdown_mgmt_details WHERE master_id='".$row['id']."'",$db);
		while($id_row_type=DB_fetch_array($id_query1))
	 	{
	 	extract($id_row_type);
		?>
		<tr>
			<td width="100"><?php  $break_type; echo $s->GetFieldValue('break_down_type',"id='".$break_type."'",'breakdown_reason'); ?></td>
			<td width="100"><?php  $break_sub_type; echo $s->GetFieldValue('tbl_sub_break_type',"id='".$break_sub_type."'",'sub_breaktype'); ?></td>
			<td width="100"><?php echo $break_reason; ?></td>
			<td width="100"><?php $technician; echo $s->GetFieldValue('technicians',"id='".$technician."'",'technician'); ?></td>
			<td width="100"><?php $com_date; echo ConvertSQLDate($rec_date); ?></td>
			<td width="100"><?php $com_date; echo ConvertSQLDate($com_date); ?></td>
		</tr>
		<?php } ?>
		</table>
	 </div>
	</td>	
</tr>
<?php $i++; }} else { ?>
	<tr bgcolor="#fff"><td colspan="11" style="text-align: center;"><font color="#FF0000" style="font-weight:bold;"><?php echo "No Records Found"; ?></font></td></tr>	 
	<?php } }?> 
</table>
</div>
</form>
</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();
}	
$('.datepicker').removeClass('hasDatepicker').datepicker({ dateFormat: 'dd/mm/yy',changeMonth: true, changeYear: true,yearRange: '-80:+20'});

</script>

