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

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

<h1>Bom Type</h1>
<br>
<strong><?php echo $message; ?></strong>
<br>
<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 } ?>		
		</select></td></tr>
</tr>
<tr>
   <th><strong>BOM Type</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_edit=DB_query("select * from bom_type where id='".$_REQUEST['Id']."'",$db);
	$edit_row=DB_fetch_array($sql_edit);	
	?>


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

<h1>Edit Bom Type</h1>
<br>
<?php echo $message; ?>
<br>
<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%" >
	  	
	  <?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['loccode']==$edit_row['branch_id'])
							{
							$k="selected";	
							}
                    ?>
                      <option value="<?php echo $site_row['loccode'];?>" <?php echo $k; ?>><?php echo $site_row['locationname'];?></option>
                      <?php } ?>		
		</select></td></tr>
</tr>
<tr>
     <th><strong>BOM Type </strong></th>	
<td><input name="shift_category" id="shift_category" style="width:100%" type="text" value="<?php echo $edit_row['bom_type']; ?>">
</td>
</tr>  
   
</table>
<p align="center">
<input type="submit" value="Update" name="Update"></p>
<?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">Branch Type </td>
<td class="tabledata" colspan="2">Action</td>
</tr>
<?php
$sql="select * from bom_type 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_id']."'";
$query1=Db_query($db1,$db);
$row11=Db_fetch_array($query1); 
echo $row11['locationname']; ?></td>
<td><?php echo $row['bom_type']; ?></td>

<td><a href="index.php?route=bom_type&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=bom_type&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&action=delete&Id=<?php echo $row['id'];?>" onclick="return confirm('Are you sure you want to delete?')">Delete</a></td>

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

</div></div>


<?php 
//include('includes/footer.inc');
?>
<script language="JavaScript">
function valid()
{
	if(document.getElementById("site").value=='000')
	{
	alert("Must Select Branch Name");
	document.getElementById("site").focus();
	return false;	
	}
	if(document.getElementById("shift_category").value=='')
	{
	alert("Please Bom Type");
	document.getElementById("shift_category").focus();
	return false;	
	}
	return true;
	}		
</script>
