<?php
ob_start();
session_name('CAKEPHP'); session_start();
$PageSecurity = 3;
 include ('includes/session.inc');
 include ('includes/function_lib.php');
 include('includes/fun-php.php');
 include('includes/fun-HRClass.php');
function getField($table,$condition,$val,$field)
{
  	 global $db;
   	 $sql=DB_query("select ".$field." from ".$table." where ".$condition." ='".$val."'",$db);
	 $r=DB_fetch_array($sql);
   	 return ($r[$field]);
}

global $db; 
$Compamies=DB_query("select * from companies",$db);
$CompamiesRow=DB_fetch_array($Compamies);
$CompamiesRow['CompanyId'];
//$branch=$s->GetFieldValue('locations',"CompanyId='".$CompamiesRow['Branch_Permission']."'",'locationname');
?>
<?php error_reporting(0); ?>

<script language="javascript" type="text/javascript">
  function toggle_visibility(id) {
	
	 
       var e = document.getElementById(id);
	      e.style.display = 'none';
		       //alert(e.style.display);
			   window.print();
    }
  
</script>
<title>Salary Register</title>
<link rel="stylesheet" href="css/purchase_requision_print.css">
<div class="body_contain">
<div class="tab_div">
     

<?php
      $sql12 = $_SESSION['mybook'];
      //unset($_SESSION['trf_req_rep']);
      $sql=DB_query($sql,$db);
      $s=new db_query();
?>
<!--<div id="foo">
  <p align="center"><input type="button" onclick="javascript:toggle_visibility('foo');" value="Print" /></p>
</div> 
-->
<p align="center" style="font-size:14px;"><strong><?php echo $messeg; ?></strong></p>
<div style="width:1246px; margin:auto; overflow:auto;">
   <table width="2400" cellpadding="3" cellspacing="0" border="1" style="border:#808080 1px solid;">
   <tr class="row1">
<td colspan="5"style="text-align:center;">
  <?php if($_SESSION['site']!='') { echo "<strong>Branch:-</strong>". $s->getField('locations','loccode',$_SESSION['site'],'locationname'); } else { echo ""; } ?> 
     <?php if($_SESSION['fromdate']!='') { echo "<strong>From Date:-</strong>". $_SESSION['fromdate']; } else { echo $_SESSION['fromdate']; } ?>

     <?php if($_SESSION['todate']!='') { echo "<strong>To date:-</strong>". $_SESSION['todate']; } else { echo $_SESSION['todate']; } ?>

</td></tr>
     <tr style="background-color:#CCCCCC; height: 25px">
       <td width="2%"><strong>S. No.</strong></td>
       <td width="6%"><strong>Job Card No.</strong></td>
       <td width="4%"><strong>Date</strong></td>
       <td width="8%"><strong>Break Down Location</strong></td>
       <td width="8%"><strong>Received By</strong></td>
       <td width="100"><strong>Asset Code</strong></td>
       <td width="100"><strong>Asset Name </strong></td>
       <td width="200"><strong>Asset Group</strong></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="150"><strong><?php echo $r['title_name'];?></strong></td>
       <?php } ?>
       <td width="150"><strong>Breakdown Type</strong></td>
       <td width="150"><strong>Breakdown Sub Type</strong></td>
       <td width="150"><strong>Breakdown Reason</strong></td>
       <td width="150"><strong>Technician</strong></td>
       <td ><strong> Exp.Com. Date</strong></td>
     </tr>
     <?php 

$i=0;
//echo $sql;
$result12=DB_query($sql12,$db);
while($myrow1=DB_fetch_array($result12))
{
  $i++;
  extract($myrow1);
?>
     <tr bgcolor="#FFFFFF">
       <td class="jjrs_tablehead"><?php echo $i;?></td>
       <td class="jjrs_tablehead"><?php echo $tt_no;?></td>
       <td class="jjrs_tablehead"><?php echo ConvertSQLDate($asset_rec_date_time);?></td>
       <td><?php  echo $rec_from; ?></td>
       <td><?php  echo $rec_by; ?></td>
       <td colspan="6" align="left" valign="top" style="padding:0px;">
       <table width="100%" border="0" align="left"  cellpadding="3" cellspacing="0">
         <?php 
    $reqDet_sql = "SELECT * FROM machine_center WHERE ID= ".$asset_id."";
    $result = DB_query($reqDet_sql,$db);
    if(DB_num_rows($result)>0){
      while($assetRow = DB_fetch_array($result)){
      $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="99" style="border-right:#808080 1px solid; border-bottom:#808080 1px solid;"><?php  echo $assetRow['code'];?></td>
           <td width="100" style="border-right:#808080 1px solid; border-bottom:#808080 1px solid;"><?php  echo $assetRow['name'];?></td>
           <td style="border-right:#808080 1px solid; border-bottom:#808080 1px solid;" width="200" ><?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="150" style="border-right:#808080 1px solid; border-bottom:#808080 1px solid;"><?php echo $assetRow[$r['db_field_name']];?></td>
           <?php } ?>
         </tr>
         <?php  }
    }?>
       </table></td>
       <td colspan="5" align="left" valign="top" style="padding:0px;"><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."'";
    $id_query1=DB_query("SELECT * FROM tpl_breakdown_mgmt_details WHERE master_id='".$main_id."'",$db);
    while($id_row_type=DB_fetch_array($id_query1))
    {
    extract($id_row_type);
    ?>
         <tr>
           <td style="border-right:#808080 1px solid; border-bottom:#808080 1px solid;" width="150"><?php  $break_type; echo $s->GetFieldValue('break_down_type',"id='".$break_type."'",'breakdown_reason'); ?></td>
           <td style="border-right:#808080 1px solid; border-bottom:#808080 1px solid;" width="150"><?php  $break_sub_type; echo $s->GetFieldValue('tbl_sub_break_type',"id='".$break_sub_type."'",'sub_breaktype'); ?></td>
           <td style="border-right:#808080 1px solid; border-bottom:#808080 1px solid;" width="150"><?php echo $break_reason; ?></td>
           <td style="border-right:#808080 1px solid; border-bottom:#808080 1px solid;" width="150"><?php $technician; echo $s->GetFieldValue('technicians',"id='".$technician."'",'technician'); ?></td>
           <td style="border-bottom:#808080 1px solid;"><?php $com_date; echo ConvertSQLDate($com_date); ?></td>
         </tr>
         <?php } ?>
       </table></td>
     </tr>
     <?php } ?>
   </table>
 </div>
 </div>
  </div>      

</div><!---END OF body_contain DIV -------->
<?php  
$header='';  		
header("Content-type: application/x-msdownload"); 
header("Content-Disposition: attachment; filename=asset_breakdown_report.xls"); 
header("Pragma: no-cache"); 
header("Expires: 0"); 
print "$header\n$data"; 
?>