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

$PageSecurity = 11;
include('includes/DefinePOClass.php');
include('includes/DefineSerialItems.php');
include('includes/SQL_CommonFunctions.inc');
//include('includes/function_lib.php');
$title = _('Machine Breakdown Register');
$date = date($_SESSION['DefaultDateFormat']);
$_SESSION['modid']=$_REQUEST['modid'];
$_SESSION['frmid']=$_REQUEST['frmid'];
$frmpermission= $px->GetFileAccess($_SESSION['modid'],$_SESSION['frmid'],$_SESSION['ACGRoleId']);
$_SESSION['frmView']=$frmpermission[3];
if($_SESSION['frmView']=='0')
{echo "<strong>You are not authorised to view this form. Contact your administrator</strong>"; exit;}
?>

<script language="javascript" type="text/javascript">
function get_itemsubgroup(str)
{
	if(str=="")
	{
	document.getElementById("sub_id").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("sub_id").innerHTML=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","item_subcategory.php?main="+str,true);
	xmlhttp.send();
}


function get_item(str)
{
	if(str=="")
	{
	document.getElementById("itemid").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("itemid").innerHTML=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","Get_itemcode.php?sub="+str,true);
	xmlhttp.send();
}


function showJobCardNo2(str)
{ 
	var sites = document.getElementById("site").value;
	
	if(str=="")
	{
	document.getElementById("itemid").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("storedata7").innerHTML=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","get_card_no2.php?asset="+str+"&sd="+sites,true);
	xmlhttp.send();
}


function showJobCardNo(str)
{ 
	var xmlhttp;
	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)
	{
	var data=xmlhttp.responseText.split("__");	
	document.getElementById("storedata7").innerHTML=data[0];
	document.getElementById("storedata2").innerHTML=data[1];
	}
	}
	xmlhttp.open("GET","get_card_no.php?site="+str,true);
	xmlhttp.send();
	//xmlhttp.open("GET","getSort.php?s="+str+"&cat="+cat,true);
}


function validatefrm()
{
	if(document.getElementById("site").value=='')
	{
	alert("Please Select Branch");
	document.getElementById("site").focus();
	return false;
	}
	/*if(document.getElementById("fromdate").value=='')
	{
	alert("Select From Date");
	document.getElementById("fromdate").focus();
	return false;
	}
	if(document.getElementById("todate").value=='')
	{
	alert("Select To Date");
	document.getElementById("todate").focus();
	return false;
	} */
	if(document.getElementById("asset_name").value=='')
	{
	alert("Select Asset Name First");
	document.getElementById("asset_name").focus();
	return false;
	}
	if(document.getElementById("job_card_no").value=='')
	{
	alert("Select Job card NO");
	document.getElementById("job_card_no").focus();
	return false;
	}
}
</script>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<form action="" method="post">
<h1>Pending List</h1>
  	<table width="100%" cellpadding="3" cellspacing="0" border="0">
	    <tr class="row1">
	        <td width="13%" align="right">Branch</td>
	        <td width="35%"><select id="site" name="site" onchange="showJobCardNo(this.value)" >
	        <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%" align="right">Job Card No. </td>
	        <td><?php $record1=$s->GetRecordById('tpl_breakdown_mgmt',1); ?>
	            <select name="job_card_no" id="job_card_no" >
	              <option value="">---Select---</option>
				 <div id = "storedata7">
				  <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 }?>
	              </div>
	            </select></td>
	    </tr>
	    <tr class="row1">
	        <td align="right">From Date</td>
	        <td><input type="text" name="fromdate" id="fromdate" class="datepicker" readonly value="<?php  echo $_REQUEST['fromdate']?>"  /></td>
			<td align="right">To Date</td>
			<td><input type="text" name="todate" id="todate" class="datepicker" readonly value="<?php  echo $_REQUEST['todate']?>"  /></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('machine_center','id',$_REQUEST['asset_name'],'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  saft_appv=1 and dept_appv=1 and process_appv=1 and completion_status=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  saft_appv=1 and dept_appv=1 and process_appv=1 and completion_status=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)
{
?>
<p align="center"><strong><?php echo $message; ?></strong></p>

<table width="100%" cellpadding="3" cellspacing="0" border="0" class="thborder">
  <tr>
    <th width="3%">S. No.</th>
	<th width="10%">Job Card No.</th>
    <th width="5%">Date</th>
	<th width="8%">Received From</th>
	<th>Asset Name</th>     
	<th width="100">Breakdown Type</th>
	<th width="150">Breakdown Sub Type<?php //echo $break_reason;?></th>
	<th width="120">Breakdown Reason</th>
    <th width="150">Technician</th>
	<th width="80">Exp.Com. Date</th>
    <th width="9%" class="text-center">Progress</th>
  </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>
	<td><?php echo $i;?></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  $s->getField('tpl_breakdown_mgmt','id',$job_id,'rec_from'); //$rec_from;?></td>
	<td><?php echo $s->GetFieldValue('machine_center',"id='".$asset_id."'",'name');?></td>
	<td colspan="5" align="left" valign="top" style="padding:0;">
	<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="100"><?php  $break_type;
				echo $s->GetFieldValue('break_down_type',"id='".$break_type."'",'breakdown_reason');
				?></td>
				<td width="150"><?php  $break_sub_type;
				echo $s->GetFieldValue('tbl_sub_break_type',"id='".$break_sub_type."'",'sub_breaktype');
				?></td>
				<td width="120"><?php echo $break_reason; ?></td>
				<td width="150"><?php $technician;
				echo $s->GetFieldValue('technicians',"id='".$technician."'",'technician');
				?></td>
				<td width="80"><?php $com_date;
				echo ConvertSQLDate($com_date);
				?></td>
			</tr>
		<?php } ?>
		</table>
	</div></td>
	<td class="text-center"><a href="<?php echo $url_add;?>&action=addProdress&rid2=<?php echo $id1;?>&assetID=<?php echo $asset_id; ?>" ><input type="button" class="search" value="Add Progress"></a></td>
</tr>
<?php } ?>
</table>
<?php } else { echo "No Records"; } ?> 

</div>
</div>

