<?php
session_name('CAKEPHP'); session_start();
$PageSecurity = 1;
include('config.php');
include('includes/ConnectDB.inc');
include('includes/function_lib.php');
include('includes/LanguageSetup.php');
include('includes/DateFunctions.inc');
$sql1=$_SESSION['sql1'];
$massage=$_SESSION['mess'];

$sqlq=$_SESSION['asset_issue_rep'];
$Compamies=DB_query("select * from companies",$db);
$CompamiesRow=DB_fetch_array($Compamies);
$sql1 = "SELECT * FROM companies where CompanyId='".$_SESSION['ACGCompanyId']."'";
  $sqlres = DB_query($sql1,$db);
  $companyRow = DB_fetch_array($sqlres);
  $s=new db_query(); 
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
  <meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />
<title>Asset Log Book Report</title>

<style type="text/css" media="print">
  @page port {size: portrait;}
@page land {size: landscape;}
 .portrait {page: port;}
.wrapper {page: land;}

</style>

<style type="text/css"> 
@print {size: portrait; margin:10px;}

@media print{
body{ margin:0px; padding:0px;  font-size:12px; line-height: 18px; font-family: Arial, Helvetica, sans-serif; color:#000; font-weight:normal;}

h1,h2,h3,h4,h5,p{ margin:0px; padding:0px;}
p{ text-align:left;}

h1{
  font-size: 20px;
  font-weight:normal;
  font-family:Arial, Helvetica, sans-serif !important;
}
h2{
  font-size: 18px;
  font-weight:normal;
  font-family:Arial, Helvetica, sans-serif !important;
}
thead{display: table-header-group; border-top:#000000 1px solid;}
.wrapper{width:99%; height: auto; float:left; border:#000000 1px solid; border-bottom:#000000 1px solid;}
.div_first, .div_first .full{
  width: 100%; height: auto;
  /*border-bottom: #000000 1px solid;
  border-top: #000000 1px solid;*/
  /*border-left: #000000 1px solid;
  border-right: #000000 1px solid;*/
  float: left;
}
.div_first .full{text-align: center; border:0;}
 .div_first .left
  {
    width:18%; text-align:left; height:auto; vertical-align:middle; height:auto; padding: 1%; float:left;
  }
  .div_first .middle
  {
    width:58%; text-align:center; padding: 1%; margin:0 auto; float: left;
  }
  .div_first .right
  {
    width:18%; text-align:right; padding: 1%; float: left;
  }
.div_second, .div_third, .div_forth{
  width: 100%;
  height:auto;
  border-top: #000000 1px solid;
  /*border-bottom: #000000 1px solid;*/
  /*border-left: #000000 1px solid;
  border-right: #000000 1px solid;*/
  float: left;
}
.div_second table tr th, .div_second table tr td{border-right:#000000 1px solid; border-bottom:#000000 1px solid;}
.div_second table tr th{text-align: left;}
.div_second table tr th:last-child, .div_second table tr td:last-child{border-right:0;}
.div_second table tr:last-child td{border-bottom:0;}
.div_second table tr td > table tr td{border-right:#000000 1px solid; border-bottom:#000000 1px solid;}
.div_second table tr td > table tr td:last-child{border-right:0;}
.div_second table tr td > table tr:last-child td{border-bottom:0;}

.div_third table tr th, .div_third table tr td{ border-bottom:#000 1px solid; border-right:#000 1px solid;}
.div_third table tr th{background-color:transparent; text-align: left;}
.div_third table tr th:last-child, .div_third table tr td:last-child{border-right:none;}
.div_third table tr:last-child td{border-bottom:none;}

.div_forth table tr th, .div_forth table tr td{ border-bottom:0; border-right:0;}
.div_forth table tr th{text-align: left;}
.div_forth table tr th:last-child, .div_forth table tr td:last-child{border-right:0;}
/*.div_forth table tr:last-child td{border-bottom: #000000 1px solid;}*/

.f12{ font-weight: bold; color:#000; font-size:12px;}
.f11{color:#000; font-size:12px; line-height:18px;}
.f14{color:#000; font-size:18px;}
.mt26{margin-top:4px; width:90%;}
.mt27{margin-top:0px; width:70%;}
.mt28{margin-top:0px; width:100%;}
.border_top{border-top:#000 1px solid;}
.border_bottom{border-bottom:#000 1px solid;}
.panel{width:100%; height:auto; float:left;}
.wdt1{width:8%;}
.wdt2{width:100px;}
.wdt3{width: 66px;}
.wdt4{width: 80px;}
.wdt5{width: 52px;}
.wdt6{width: 60px;}
.tab-wdth{width:100%;}
}

@media screen{
/* CSS Document */
body{ margin:0px; padding:0px; background-color:#fff; font-size:12px; font-family: Arial, Helvetica, sans-serif; color:#000; font-weight:normal;}
h1,h2,h3,h4,h5,p{ margin:0px; padding:0px;}
p{ text-align:left;}

#foo{width:1070px; height: auto; margin:0px auto;}
.wrapper{width:1070px; height: auto; margin:10px auto; border-top:#000000 1px solid;}

h1{
  font-size: 24px; line-height: 28px;
  font-weight:bold;
  font-family:Arial, Helvetica, sans-serif !important;
}
h2{
  font-size: 18px; line-height: 22px;
  font-weight:normal;
  font-family:Arial, Helvetica, sans-serif !important;  
}
.div_first, .div_first .full{
  width: 100%; height: auto;
  /*border-bottom: #000000 1px solid;
  border-top: #000000 1px solid;*/
  border-left: #000000 1px solid;
  border-right: #000000 1px solid;
  float: left; position: relative; display: table;
}
.div_first .full{text-align: center; border: 0; margin:10px 0 0;}
.div_first .left, .div_first .middle, .div_first .right{float: left; display: table-cell; vertical-align: middle;}
.div_first .left
{
  width:18%; text-align:center; height:auto; vertical-align:middle; padding: 1%; 
}
.div_first .middle
{
  width:58%; text-align:center; padding: 1%; position: relative; margin:0 auto;
}
.div_first .right
{
  width:18%; text-align:center; padding:1%; 
}
.div_second, .div_third, .div_forth{
  width: 100%; height: auto;
  /*border-bottom: #000000 1px solid;*/
  border-top: #000000 1px solid;
  border-left: #000000 1px solid;
  border-right: #000000 1px solid;
  float: left;
}
.div_second table tr th, .div_second table tr td{border-right:#000000 1px solid; border-bottom:#000000 1px solid;}
.div_second table tr th{background-color: #ccc; text-align: left;}
.div_second table tr th:last-child, .div_second table tr td:last-child{border-right:0;}
/*.div_second table tr:last-child td{border-bottom:0;}*/
.div_second table tr td > table tr td{border-right:#000000 1px solid; border-bottom:#000000 1px solid;}
.div_second table tr td > table tr td:last-child{border-right:0;}
.div_second table tr td > table tr:last-child td{border-bottom:0;}

.div_third table tr th, .div_third table tr td{ border-bottom:#000 1px solid; border-right:#000 1px solid;}
.div_third table tr th{background-color: #ccc; text-align: left;}
.div_third table tr th:last-child, .div_third table tr td:last-child{border-right:none;}
/*.div_third table tr:last-child td{border-bottom:none;}*/

.f12{font-weight: bold; color:#000; font-size:12px;}
.f11{ color:#000; font-size:12px; line-height:18px;}
.f14{ color:#000; font-size:18px;}
.mt26{margin-top:4px; width:90%;}
.mt27{margin-top:0px; width:100%;}
.mt28{margin-top:0px; width:90%;}
.border_top{border-top:#000 1px solid;}
.border_bottom{border-bottom:#000 1px solid;}
.panel{width:100%; height:auto; float:left; overflow: auto;}
.wdt1{width:10%;}
.wdt2{width:180px;}
.wdt3{width: 66px;}
.wdt4{width: 120px;}
.wdt5{width: 52px;}
.wdt6{width: 70px;}
.tab-wdth{width:180%;}
}
</style>
</head>
<body>
<div id="foo">
  <p style="text-align:right;"><input type="button" onclick="javascript:toggle_visibility('foo');" value="Print" /></p>
</div>
<div class="wrapper">
<div class="div_first">
<?php $logoImage=($CompamiesRow['CompanyLogo']=='')?'Final_Logo_RM.png':$CompamiesRow['CompanyLogo']; ?>
      <div class="left"><img src="Setup/CompanyLogo/<?php echo $logoImage; ?>" class="mt26" /></div>
      <div class="middle"><?php 
    if($CompamiesRow['CompanyName']!="") {echo "<h1>".$CompamiesRow['CompanyName']."</h1>"; } else { echo "";}
    
    if($InoRow['deladd1']!="") { echo $InoRow['deladd1']; } else { echo "";}
    if($InoRow['deladd2']!="") { echo ", ". $InoRow['deladd2']; } else { echo "";}
    if($InoRow['deladd3']!="") { echo ", ". $InoRow['deladd3']; } else { echo "";}
    if($InoRow['city']!="") { echo ", ". $s->getFieldValue("city_master", "id='".$InoRow['city']."'", "city"); } else { echo "";}
    if($InoRow['pincode']!="") { echo " - ".$InoRow['pincode']; } else { echo "";}
    if($InoRow['state']!="") { echo ", ". $s->getFieldValue("state_master", "id='".$InoRow['state']."'", "state"); } else { echo "";}
    if($InoRow['country']!="") { echo ", ". $s->getFieldValue("country_master", "id='".$InoRow['country']."'", "country");
    
     } else { echo "";}
    ?>
     <div class="full"><span class="f11"><?php echo "Phone No.:".$CompamiesRow['Phone'].",   Fax No.: ".$CompamiesRow['fax'].", Email ID.: ".$CompamiesRow['email'].",   Website: ".$CompamiesRow['website']; ?><br>
  <?php  echo $_SESSION['mess']; ?>
  </span></div>
       <h2>Job Card Report</h2>
      </div>
      <div class="right"></div>
</div>

<div class="div_second">
<?php 

	$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']!='')
	{
		$filter[]="tpl_breakdown_mgmt.site = '".$_REQUEST['site']."'";
	}
	if($_REQUEST['asset_name']!='' && $_REQUEST['asset_name']!='0')
	{
		$filter[]="tpl_breakdown_mgmt_machine.asset_id = '".$_REQUEST['asset_name']."'";
	}
	if($_REQUEST['asset_name']=='0')
	{
		$filter[]="1=1";
	}
	if($_REQUEST['fromdate']!='' && $_REQUEST['todate']!='')
	{
		$filter[]="tpl_breakdown_mgmt.asset_rec_date_time BETWEEN '".$from."' and '".$to."'";
	}
	//print_r($filter);
	if($filter!='')
	{
		$filter1=implode(' and ',$filter); 
		
	}
 $sql12="Select *, tpl_breakdown_mgmt.id as main_id from tpl_breakdown_mgmt join tpl_breakdown_mgmt_machine on (tpl_breakdown_mgmt.id=tpl_breakdown_mgmt_machine.master_id) where $filter1 and tpl_breakdown_mgmt.CompanyId='".$_SESSION['ACGCompanyId']."' group by tpl_breakdown_mgmt.id order by tpl_breakdown_mgmt.asset_rec_date_time ";




?>

<div class="panel">
   <table class="tab-wdth" cellpadding="3" cellspacing="0" border="0">
   <thead>
     <tr>
       <th width="3%" class="f12" style="text-align:left;">S. No.</th>
       <th class="f12" style="text-align:left;">Job Card No.</th>
       <th width="4%" class="f12" style="text-align:left;">Date</th>
       <th width="8%" class="f12" style="text-align:left;">Break Down Location</th>
       <th width="8%" class="f12" style="text-align:left;">Received By</th>
       <th class="f12" style="text-align:left;">Asset Code</th>
       <th width="80" class="f12" style="text-align:left;">Asset Name </th>
       <th width="80" class="f12" style="text-align:left;">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="80" class="f12" style="text-align:left;"><?php echo $r['title_name'];?></th>
       <?php } ?>
       <th width="80" class="f12" style="text-align:left;">Breakdown Type</th>
       <th width="80" class="f12" style="text-align:left;">Breakdown Sub Type</th>
       <th width="80" class="f12" style="text-align:left;">Breakdown Reason</th>
       <th width="80" class="f12" style="text-align:left;">Technician</th>
       <th class="f12" style="text-align:left;">Exp.Com. Date</th>
     </tr>
     </thead>
     <?php 
$i=0;
//echo $sql;
$result12=DB_query($sql12,$db);
while($myrow1=DB_fetch_array($result12))
{
	$i++;
	extract($myrow1);
?>
     <tr class="f11">
       <td class="f11"><?php echo $i;?></td>
       <td class="f11"><?php echo $tt_no;?></td>
       <td class="f11"><?php echo ConvertSQLDate($asset_rec_date_time);?></td>
       <td class="f11"><?php  echo $rec_from; ?></td>
       <td class="f11"><?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 class="f11"><?php  echo $assetRow['code'];?></td>
           <td width="80" class="f11"><?php  echo $assetRow['name'];?></td>
           <td width="80" class="f11"><?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="80" class="f11"><?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="80%">
         <?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 width="80" class="f11"><?php  $break_type; echo $s->GetFieldValue('break_down_type',"id='".$break_type."'",'breakdown_reason'); ?></td>
           <td width="80" class="f11"><?php  $break_sub_type; echo $s->GetFieldValue('tbl_sub_break_type',"id='".$break_sub_type."'",'sub_breaktype'); ?></td>
           <td width="80" class="f11"><?php echo $break_reason; ?></td>
           <td width="80" class="f11"><?php $technician; echo $s->GetFieldValue('technicians',"id='".$technician."'",'technician'); ?></td>
           <td class="f11"><?php $com_date; echo ConvertSQLDate($com_date); ?></td>
         </tr>
         <?php } ?>
       </table></td>
     </tr>
     <?php } ?>
   </table>
 </div>
	</div>
<script type="text/javascript" language="javascript">
function toggle_visibility(id) 
{
    var e = document.getElementById(id);
    e.style.display = 'none';
	window.print();
}
</script>

</div>
</body>
</html>