<link rel="stylesheet" href="css/new_mxerp.css">
<?php
$modid=$_REQUEST['modid'];
$frmid=$_REQUEST['frmid'];
$rurl="&modid=".$modid."&frmid=".$frmid;
if(isset($_POST['Submit']))
{
$check=DB_query("select * from production_maintenance_master where maintenance_name='".$_REQUEST['shift_category']."' and branch_code='".$_REQUEST['site']."' and CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
$num=DB_num_rows($check);
if($num<=0)
{		
$insert="insert into production_maintenance_master set maintenance_name='".$_REQUEST['shift_category']."',branch_code='".$_REQUEST['site']."',CompanyId='".$_SESSION['ACGCompanyId']."' ";
$query=Db_query($insert,$db);
}
}
if(isset($_POST['Update']))
{
$check=DB_query("select * from production_maintenance_master where maintenance_name='".$_REQUEST['shift_category']."' and branch_code='".$_REQUEST['site']."'",$db);
$num=DB_num_rows($check);
if($num<=0)
{		
$update="update production_maintenance_master set maintenance_name='".$_REQUEST['shift_category']."',branch_code='".$_REQUEST['site']."' where id='".$_REQUEST['Id']."'";
$query=DB_query($update,$db);	
}
$s->pageLocation("index.php?route=production_process&daction=Updated".$rurl);	
}
if($_REQUEST['action']=='delete')
{
$del="delete from production_maintenance_master where id='".$_REQUEST['Id']."'";
$query=DB_query($del,$db);
$s->pageLocation("index.php?route=production_mainten_master&daction=Updated".$rurl);		
}
?>
<?php if($_REQUEST['action']=='')
{?>

<div class="">
<div class="">

<h1>Production Process</h1>
<form action="" method="post">
<table width="40%" border="0" cellpadding="2" cellspacing="1" style="border:#666666 solid 1px;">
<tr>
 <th><strong>Branch</strong></th>	
	  <td> <select name="site" style="width:100%" id="site">
	  <?php 
            $site_sql=DB_query("Select loccode,locationname from locations where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in ('".$_SESSION['AssignedBranch']."')",$db);
             while($site_row=DB_fetch_array($site_sql)){
             ?>
             <option value="<?php echo $site_row['loccode'];?>"><?php echo $site_row['locationname'];?></option>
             <?php } ?>		
		</option></select></td></tr>
</tr>
<tr>
<th><strong>Production Maintenance </strong></th>	
<td><input name="shift_category" id="shift_category" style="width:100%" type="text">
</td>
</tr>  
   
</table>
<p align="center">
<input type="submit" value="Save" name="Submit" onclick="return valid();"></p>
</form><?php }
if($_REQUEST['action']=='edit' and $_REQUEST['Id']!='' )
{
$sql="select * from production_maintenance_master where id='".$_REQUEST['Id']."'";
$query=DB_query($sql,$db);
$row1=DB_fetch_array($query);	
?>
<div class="">
<div class="">

<h1>Production Process</h1>
<form action="" method="post">
<table width="40%" border="0" cellpadding="2" cellspacing="1" style="border:#666666 solid 1px;">
<tr>
  <th><strong>Branch </strong></th>	
  
	  <td> <select name="site" style="width:100%" id="site">
	  	
	  <?php 
            $site_sql=DB_query("Select loccode,locationname from locations where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in ('".$_SESSION['AssignedBranch']."')",$db);
             while($site_row=DB_fetch_array($site_sql)){
             	$k='';
				 if($site_row['']==$row1['branch_code'])
				 {
				 $k="selected";	
				 }
             ?>
             <option value="<?php echo $site_row['loccode'];?>"<?php echo $k; ?>><?php echo $site_row['locationname'];?></option>
             <?php } ?>		
		</option></select></td></tr>
</tr>
<tr>
<th><strong>Production Maintenance </strong></th>	
<td><input name="shift_category" id="shift_category" style="width:100%" type="text" value="<?php echo $row1['manuf_process_name']; ?>">
</td>
</tr>  
   
</table>
<p align="center">
<input type="submit" value="Update" name="Update" onclick="return valid();"></p>
</form><?php } ?>

<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
<tr>
<td class="tabledata">Branch</td>
<td class="tabledata">Maintenance Name  </td>
<td class="tabledata" colspan="2">Action</td>
</tr>
<?php
$sql="select * from production_maintenance_master where CompanyId='".$_SESSION['ACGCompanyId']."'";
$query=DB_query($sql,$db);

while($row=DB_fetch_array($query))
{
	
?>
<tr>
	
<td><?php $db1="select * from locations where loccode='".$row['branch_code']."'";
$query1=Db_query($db1,$db);
$row11=Db_fetch_array($query1); 
echo $row11['locationname']; ?></td>
<td><?php echo $row['maintenance_name']; ?></td>

<td><a href="index.php?route=Production_process&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&action=edit&Id=<?php echo $row['id'];?>">Edit</a></td>
<td><a href="index.php?route=Production_process&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&action=delete&Id=<?php echo $row['id'];?>">Delete</a></td>

</tr>
<?php } ?>
</table>


</div></div>


<?php 
//include('includes/footer.inc');
?>
<script language="JavaScript">
function valid()
{
if(document.getElementById("site").value==0)
{
alert("Must Select Site Name");
document.getElementById("site").focus();
return false;	
}
if(document.getElementById("shift_category").value=='')
{
alert("Must Enter Manufacturing Process");
document.getElementById("shift_category").focus();
return false;	
}
return true;	
}	
	
	
	
</script>