<?php 
session_name('CAKEPHP'); session_start();
ob_start();
$PageSecurity = 11;
include('includes/session.inc');
include('includes/function_lib.php');
include('includes/SQL_CommonFunctions.inc');
//echo $country;
  global $db;
  global $s;
 if($_REQUEST['str']!='')
 { 
  
//echo "select * from machine_center where under_group='".$_REQUEST['str']."' and asset_type='NA' and id NOT IN (select asset_id from tbl_prementive)";
$data='';
$data.="<option value='0'>Select</option>";
$sql_machine=DB_query("select * from machine_center where under_group='".$_REQUEST['str']."' and asset_type in('A','NA')
 and id NOT IN (select asset_id from tbl_prementive)",$db);
while($row=DB_fetch_array($sql_machine))
{
$data.="<option value='".$row['id']."'>".$row['name']."</option>";
}
echo $data;
}
else if($_REQUEST['asset']!='')
{
$warrenty=array("Y"=>"Yes","N"=>"No");
$row=DB_fetch_array(DB_query("select * from machine_center where id='".$_REQUEST['asset']."'",$db));
$data="<option value='".$row['warranty_type']."'>".$warrenty[$row['warranty_type']]."</option>";
$data1="<option value='".$row['working']."'>".$warrenty[$row['working']]."</option>";
$data2=$row['code'];

$breakdown='';$breakdown_details='';
$sql_breakdown=DB_query("select id from break_down_type where  CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
while($row_break=DB_fetch_array($sql_breakdown))
{
  $breakdown[]=$row_break['id'];


$sql_breakdown1=DB_query("select id from tbl_sub_break_type where breakdownid='".$row_break['id']."' and asset_group='".$row['under_group']."'",$db);
while($row_break1=DB_fetch_array($sql_breakdown1))
{
  $breakdown_details[$row_break['id']][]=$row_break1['id'];
}
}

$subasset='';
$subasset[]=$row['id'];
$sql_asset=DB_query("select machine_center_id from machine_center_details where asset_id='".$row['id']."'",$db);
while($row_asset=DB_fetch_array($sql_asset))
{
  $subasset[]=$row_asset['machine_center_id'];
}


$data3.='';
$data3.='<table width="100%" border="0" cellspacing="0" cellpadding="3" class="thborder">
  <tr>
    <th>Break Down</th>
    <th width="398">Sub Break Down</th>
    <th width="150">Service Day</th>
    <th width="150">Last Service Date</th>
  </tr>';
      $i=1;
  foreach($breakdown as $key=>$val)
  {

  $data3.='<tr bgcolor="#c1e0c0">
    <td colspan="4"><strong>'.$s->GetFieldValue("break_down_type","id='".$val."'","breakdown_reason").'<input type="hidden" name="breakdown[]" value="'.$val.'"></strong></td>
   
  </tr>';
   
   
   foreach($subasset as $key1=>$val1)
   {
   
    $data3.='<tr>
     <td>'.$s->GetFieldValue("machine_center","id='".$val1."'","name").'<input type="hidden" name="assetid['.$val.'][]" value="'.$val1.'"></td>
    <td colspan="3" style="padding:0px;" valign="top"><div id="amc-tab"><table width="100%" border="0" cellspacing="0" cellpadding="3">';
if(!empty($breakdown_details[$val]))
  {
  foreach($breakdown_details[$val] as $key2=>$val2)
   {
   $data3.='<tr><td width="398">'.$s->GetFieldValue("tbl_sub_break_type","id='".$val2."'","sub_breaktype").'<input type="hidden" name="subbreak['.$val.']['.$val1.'][]" value="'.$val2.'"></td>
          <td width="150"><input type="text" name="service_day['.$val.']['.$val1.'][]"  autocomplete="off"></td>
          <td width="150"><input type="text" id="lastdate_'.$i.'" class="datepicker" name="last_service_date['.$val.']['.$val1.'][]"  autocomplete="off"></td>
   </tr>';
    $i++;

  }
}
    $data3.='</table></div></td>
   
    </tr>';

    }

   } 
  
$data3.='</table>';

    $data3.='<p style="text-align:center;"><input type="submit" class="search" id="view" value="Save" name="Search"></p>';





echo $data."__".$data1."__".$data2."__".$data3;
}

?>

 
   