<?php 
session_name('CAKEPHP'); session_start();
error_reporting(FALSE);
$url_add = "index.php?route=ToolPlants/Transaction/breakdown_add_progress_testing".$rurl;

$PageSecurity = 11;
include('includes/DefinePOClass.php');
include('includes/DefineSerialItems.php');
include('includes/SQL_CommonFunctions.inc');
//include('includes/function_lib.php');

?>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
 <div class="tab_div">
<h1>Multiple Approval</h1>
  <form action="" method="post">
  <table width="100%" cellpadding="3" cellspacing="0" border="0">
      <tr class="row1">
        <td width="13%" style="text-align:right;"><strong>Branch:</strong></td>
        <td width="35%"><select  id = "site" name="site" onchange= "showJobCardNo(this.value)" style="width:98%;">
        <option value = "">--Select--</option>
        <?php 
            $site_sql=DB_query("Select loccode,locationname from locations where CompanyId='".$_SESSION['ACGCompanyId']."' ",$db);
                        while($site_row=DB_fetch_array($site_sql))
						{						
			?>
        <option value="<?php echo $site_row['loccode']?>"<?php echo($_REQUEST['site']==$site_row['loccode']?'selected':''); ?>><?php echo $site_row['locationname']?></option>
        <?php } ?>
      	</select></td>
		<td width="13%" style="text-align:right;"><strong>Job Card No.:</strong></td>
        <td><?php $record1=$s->GetRecordById('tpl_breakdown_mgmt',1); ?>
            <div id = "storedata7"><select name="job_card_no" id="job_card_no" style="width:98%">
              <option value="">---Select---</option>
			  <option value="00"<?php echo $_REQUEST['job_card_no']=='00'?'selected':''; ?>>All</option>
              <?php while($row1=DB_fetch_array($record1)){ 
					extract($row1); ?>
              <option  value="<?php echo $id; ?>"<?php echo($_REQUEST['job_card_no']==$id?'selected':''); ?>><?php echo $tt_no; ?></option>
              <?php }?>
            </select></div>
        </td>      
      </tr>
      <tr class="row1">
      	<td style="text-align:right;"><strong>From Date:</strong></td>
        <td><input type="text" name="fromdate" id="fromdate" class="datepicker" value="<?php echo $_REQUEST['fromdate']?>" style="width:98%;" /></td>
		<td style="text-align:right;"><strong>To Date:</strong></td>
	    <td><input type="text" name="todate" id="todate" class="datepicker" value="<?php echo $_REQUEST['todate']?>" style="width:98%;"/></td>
      </tr>
      <tr class="row1">
        <td colspan="4" style="text-align:center;"><input type="submit" name="submit" value="View" id="view" onClick="return validatefrm()" class="search" /></td>
      </tr>
  </table>
</form>

<?php 
if($_REQUEST['submit']!='')
{
	$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('tpl_fixed_asset_definition','id',$_REQUEST['asset_name'],'asset_name');
	$jobCardNo = $_REQUEST['job_card_no'];
	
	$filter=array();
	if($_REQUEST['site']!='')
	{
		$filter[]="tpl_breakdown_mgmt_assig.site = '".$_REQUEST['site']."'";
	}
		
	if($_REQUEST['fromdate']!='' && $_REQUEST['todate']!='')
	{
		$filter[]="tpl_breakdown_mgmt_assig.assign_date BETWEEN '".$from."' and '".$to."'";
	}
	if($_REQUEST['job_card_no']!='' && $_REQUEST['job_card_no']!='00')
	{
		$filter[]="tpl_breakdown_mgmt_assig.job_id  = '".$_REQUEST['job_card_no']."'";
	}
	if($_REQUEST['job_card_no']=='00')
	{
		$filter[]="1=1";
	}
	//print_r($filter);exit();
	if($filter!='')
	{
		$filter1=implode(' and ',$filter); 
		
	}
   $sql="Select * from tpl_breakdown_mgmt_assig where $filter1 and tpl_breakdown_mgmt_assig.CompanyId='".$_SESSION['ACGCompanyId']."' and test_status=1 and (T_main_app=0 || T_process_app=0  || T_safty_app=0)order by id ";


if($_REQUEST['site']!='' && $_REQUEST['fromdate']=='' && $_REQUEST['todate']=='' && $_REQUEST['asset_name']=='')
	{
		$message="Showing Records of Site ".$sitename." ";
	
	}
elseif($_REQUEST['site']!='' && $_REQUEST['fromdate']!='' && $_REQUEST['todate']!='' && $_REQUEST['asset_name']=='')
	{
	$message="Showing Records of Site ".$sitename."   From  ".$fromdate." to ".$todate."";
	}
	
	
elseif($_REQUEST['site']!='0' && $_REQUEST['fromdate']!='' && $_REQUEST['todate']!='' && $_REQUEST['asset_name']!='')
	{
	$message="Showing Records of Site ".$sitename." for  ".$assetname."  From  ".$fromdate." to ".$todate." ";
	}
else if($_REQUEST['site']!='0' && $_REQUEST['fromdate']=='' && $_REQUEST['todate']=='' && $_REQUEST['asset_name']!='')
	{
		$message="Showing Records of Site ".$sitename." for ".$assetname."";
	
	}
}
else
{
 $sql="Select * from tpl_breakdown_mgmt_assig where  tpl_breakdown_mgmt_assig.CompanyId='".$_SESSION['ACGCompanyId']."' and  test_status=1 and
   (T_main_app=0 || T_process_app=0  || T_safty_app=0) order by id ";
 $message="Showing All Records ";
}
	//echo $sql;
   
	$_SESSION['mrnreport']=$sql;
	$_SESSION['mess']=$message;

$numrow1=DB_num_rows(DB_query($sql,$db));
if($numrow1>0)
{
  
 
?>
  <form method="post" action=""  name="frm"  id="frm">
<p align="center"><strong><?php echo $message; ?></strong></p>

<table width="100%" cellpadding="3" cellspacing="0" border="1" style="border:#808080 1px solid; border-collapse:collapse;">
  <tr>
    <td width="2%">S. No.</td>
	<td width="7%">Job Card No.</td>
    <td width="7%">Date</td>
	<td width="9%">Received From</td>
	<td>Asset Name</td>
    <td width="80">Breakdown Type</td>
	<td width="100">Breakdown Sub Type<?php echo $break_reason;	?></td>
	<td width="100">Breakdown Reason</td>
    <td width="100">Technician</td>
	<td width="80">Exp. Com. Date</td>
    <td width="80">Completed Date</td>
    <td width="7%">Testing Date</td>
    <td width="7%">Testing Status</td>
    <td width="6%">Action</td>
  </tr>
<?php 
$i=0;
//echo $sql;
$result=DB_query($sql,$db);
while($myrow=DB_fetch_array($result))
{
$i++;
extract($myrow);
$id1=$id;
$asset_id=$s->GetFieldValue('tpl_breakdown_mgmt_machine',"id='".$job_id."'",'asset_id');

        
 
?>
  <tr bgcolor="#FFFFFF">
	<td><?php echo $i;?> <input type="hidden" name="mainid[]" id="mainid_<?php echo $i; ?>" value="<?php echo $id; ?>">  </td>
	<td><?php echo $s->getField('tpl_breakdown_mgmt','id',$job_id,'tt_no');?></td>
	<td><?php echo ConvertSQLDate($assign_date  );?></td>
	<td><?php echo $rec_from;?></td>
	<td><?php echo $s->GetFieldValue('machine_center',"id='".$asset_id."'",'name');?></td>
	<td colspan="8" align="left" valign="top" style="padding:0px;">
	<div id="amc-tab">
	<table cellspacing="0" cellpadding="3" border="0" width="100%">
		<?php 
	$id_query1=DB_query("SELECT * FROM tpl_breakdown_mgmt_details WHERE master_id='".$id."'",$db);
	while($id_row_type=DB_fetch_array($id_query1))
	 {
	 extract($id_row_type);
	?>
<tr>
<td width="80">
	<?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="80">
	<?php $com_date;
	echo ConvertSQLDate($com_date);
	?></td>
   <td width="80">
	<?php $tested_date;
	echo ConvertSQLDate($tested_date);
	?></td>
   <td>
	<?php if($test_details=='Y')
    echo "Done";  else echo  "Pending"; 
	?></td>   
	</tr>
	<?php } ?>
	</table>
</div>
	</td>
   <td>
    <div style="float:left;" id="main_app_<?php echo $i; ?>">
     <?php if($T_main_app==0) { ?>     
     <input type="radio" name="main_app" id="main_appid_<?php echo $i; ?>" value="Y" onclick="checkupdate1(this.value,<?php echo $i; ?>);"><strong>Maintenance Head Approval</strong>
     <?php } else if($T_process_app==0){ ?>
     <input type="radio" name="process_app" id="process_app_<?php echo $i; ?>" value="Y" onclick="checkupdate2(this.value,<?php echo $i; ?>);"><strong>Process Head Approval</strong>
     <?php } else if($T_safty_app==0) { ?>
     <input type="radio" name="safty_app" value="Y" onclick="checkupdate3(this.value,<?php echo $i; ?>);" id="safty_app_<?php echo $i; ?>"><strong>Safty Head Approval</strong>
     <?php } else { echo "All Approval Done"; }?>
    </div>         
		</td>	
	</tr>
<?php } ?>

</table>
  </form>
 </div>
</div>

<?php } else { echo "<p align='center' style='font-size:14px; color:#ff0000;'>No Records</p>"; } ?> 

<script type="text/javascript" language="javascript">
function checkupdate1(str,i)
{
  var mainid=document.getElementById("mainid_"+i).value;
//alert(site1);
	  
  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("main_app_"+i).innerHTML=xmlhttp.responseText;		
	}
	}	
	xmlhttp.open("GET","ajax_testing_approval.php?str="+mainid+"&k="+i,true);
	xmlhttp.send(); 	
}

function checkupdate2(str,i)
{
  var mainid=document.getElementById("mainid_"+i).value;
//alert(site1);
	  
  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("main_app_"+i).innerHTML=xmlhttp.responseText;		
	}
	}
	
	xmlhttp.open("GET","ajax_testing_approval2.php?str="+mainid+"&k="+i,true);
	xmlhttp.send();
	
}

function checkupdate3(str,i)
{
  var mainid=document.getElementById("mainid_"+i).value;
//alert(site1);
	  
  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("main_app_"+i).innerHTML=xmlhttp.responseText;		
	}
	}
	
	xmlhttp.open("GET","ajax_testing_approval3.php?str="+mainid+"&k="+i,true);
	xmlhttp.send();
}

</script>