<?php
$modid=$_REQUEST['modid'];
$frmid=$_REQUEST['frmid'];
$rurl="&modid=".$modid."&frmid=".$frmid;
if(isset($_POST['Save']))
{
	 //$sql="select * from production_operator_master where shift_id='".$_REQUEST['shift_name']."' and branch_code='".$_REQUEST['site']."'";
	//$query1=DB_query($sql,$db);
	//$numrows = DB_num_rows($query1);
	//if($numrows<=0)
	//{
$insert="insert into production_operator_master set shift_id='".$_REQUEST['shift_name']."'
         ,branch_code='".$_REQUEST['site']."',calender_days='".$_REQUEST['calender_days']."',monthly_wages='".$_REQUEST['monthly_wages']."',
          working_wages='".$_REQUEST['working_hrs']."',cost_per_hours='".$_REQUEST['cost_per_hours']."',operator_name='".$_REQUEST['operator_name']."'";
$query=Db_query($insert,$db);	
//}
}	
if(isset($_POST['Update']))
{
$update="update production_operator_master set shift_id='".$_REQUEST['shift_name']."'
         ,branch_code='".$_REQUEST['site']."',calender_days='".$_REQUEST['calender_days']."',monthly_wages='".$_REQUEST['monthly_wages']."',
          working_wages='".$_REQUEST['working_hrs']."',cost_per_hours='".$_REQUEST['cost_per_hours']."',operator_name='".$_REQUEST['operator_name']."'
          where id='".$_REQUEST['Id']."'";
$query=DB_query($update,$db);  
        	
$s->pageLocation("index.php?route=Production_operator&daction=Updated".$rurl);	
}
if($_REQUEST['action']=='delete')
{
$del="delete from production_operator_master where id='".$_REQUEST['Id']."'";
$query=DB_query($del,$db);	
}

?>

<?php if($_REQUEST['action']=='') { ?>
<h2 align="center"><strong>Production Operator</strong></h2>
<form action="" method="post">
<table width="40%" border="0" cellspacing="1" cellpadding="2" align="center">
<tr>
  <th><strong>BRANCH</strong></th>	
	  <td> <select name="site" style="width:135px">
	  	<option value="0">-----Select-----</option>
	  <?php 
            $site_sql=DB_query("Select loccode,locationname from locations ",$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>Operator Name </strong></th>
<td><input name="operator_name" id="operator_name" style="width:135px" type="text">
</td>
</tr>  
<tr>
<th><strong>SHIFT NAME </strong></th>
<td><div id="orderid">
<select name="shift_name" style="width:135px" id="shift_name">
<option value="0">-----Select----</option>
	<?php 
            $site_sql1=DB_query("Select id,shift_name from production_shift ",$db);
                        while($site_row1=DB_fetch_array($site_sql1)){
                    ?>
                      <option value="<?php echo $site_row1['id'];?>"><?php echo $site_row1['shift_name'];?></option>
                      <?php } ?>		
</select></div>
</td>
</tr>
<tr>
<th><strong>Calender Days </strong></th>
<td><?php        
	$end = date("Y-m-d",strtotime("+0 months"));
	 $monthdate=explode('-',$end);
    
	$num = cal_days_in_month(CAL_GREGORIAN, $monthdate[1], $monthdate[0]);
	 ?>
	<input name="calender_days" id="calender_days" style="width:135px" type="text" value="<?php echo $num; ?>" readonly>
</td>
</tr>  
<tr>
<th><strong>Monthly Wages </strong></th>
<td><input name="monthly_wages" id="monthly_wages" style="width:135px" type="text">
</td>
</tr>  
<tr>
<th><strong>Working Hours </strong></th>
<td><input name="working_hrs" id="working_hrs" style="width:135px" type="text" onchange="count(this.value);">
</td>
</tr>  
 <tr>
<th><strong>CostPer Hours </strong></th>
<td><input name="cost_per_hours" id="cost_per_hours" style="width:135px" type="text">
</td>
</tr>   
</table>
<p align="center">
<input type="submit" value="Save" name="Save"></p>
</form>	
<?php } if($_REQUEST['action']=='edit' and $_REQUEST['Id']!='') {
$sql1="select * from production_operator_master where id='".$_REQUEST['Id']."'";
$query1=DB_query($sql1,$db);
$row1=DB_fetch_array($query1);	
?>
<h2 align="center"><strong>Edit Production Operator</strong></h2>
<form action="" method="post">
<table width="40%" border="0" cellspacing="1" cellpadding="2" align="center">
<tr>
  <th><strong>BRANCH</strong></th>	
	  <td> <select name="site" style="width:135px">
	  	<option value="0">-----Select-----</option>
	  <?php 
            $site_sql=DB_query("Select loccode,locationname from locations ",$db);
                        while($site_row=DB_fetch_array($site_sql)){
                        $k='';
						if($site_row['loccode']==$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>Operator Name </strong></th>
<td><input name="operator_name" id="operator_name" style="width:135px" type="text" value="<?php echo $row1['operator_name']; ?>">
</td>
</tr>  
<tr>
<th><strong>SHIFT NAME </strong></th>
<td><div id="orderid">
<select name="shift_name" style="width:135px" id="shift_name">
<option value="0">-----Select----</option>
	<?php 
            $site_sql1=DB_query("Select id,shift_name from production_shift ",$db);
                        while($site_row1=DB_fetch_array($site_sql1)){
                        	$j='';
							if($site_row1['id']==$row1['shift_id'])
							{
							$j="selected";	
							}
                    ?>
                      <option value="<?php echo $site_row1['id'];?>"<?php echo $j; ?>><?php echo $site_row1['shift_name'];?></option>
                      <?php } ?>		
</select></div>
</td>
</tr>
<tr>
<th><strong>Calender Days </strong></th>
<td><?php        
	$end = date("Y-m-d",strtotime("+0 months"));
	 $monthdate=explode('-',$end);
    
	$num = cal_days_in_month(CAL_GREGORIAN, $monthdate[1], $monthdate[0]);
	 ?>
	<input name="calender_days" id="calender_days" style="width:135px" type="text" value="<?php if(!empty($row1['calender_days'])) { echo $row1['calender_days']; } else { echo $num;} ?>" readonly>
</td>
</tr>  
<tr>
<th><strong>Monthly Wages </strong></th>
<td><input name="monthly_wages" id="monthly_wages" style="width:135px" type="text" value="<?php echo $row1['monthly_wages']; ?>">
</td>
</tr>  
<tr>
<th><strong>Working Hours </strong></th>
<td><input name="working_hrs" id="working_hrs" style="width:135px" type="text"  value="<?php echo $row1['working_wages']; ?>" onchange="count(this.value);" >
</td>
</tr>  
 <tr>
<th><strong>CostPer Hours </strong></th>
<td><input name="cost_per_hours" id="cost_per_hours" style="width:135px" type="text" value="<?php echo $row1['cost_per_hours']; ?>">
</td>
</tr>   
</table>	
<p align="center">
<input type="submit" value="Update" name="Update"></p>
</form>	
<?php } ?>	
<br>	
<br>
<table width="80%" border="0" cellspacing="2" cellpadding="2" align="center">
<tr>
<th><strong>BRANCH</strong></th>
<th><strong>Operator Name  </strong></th>
<th><strong>SHIFT NAME  </strong></th>
<th><strong>Calender Days  </strong></th>
<th><strong>Monthly Wages  </strong></th>
<th><strong>Working Hours  </strong></th>
<th><strong>CostPer Hours </strong></th>
<th colspan="2"><strong>ACTION</strong></th>
</tr>
<?php
$sql="select * from production_operator_master";
$query=DB_query($sql,$db);
while($row=DB_fetch_array($query))
{	
?>
<tr bgcolor="#FFFFFF">	
<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['operator_name']; ?></td>
<td><?php
$db1="select * from production_shift where id='".$row['shift_id']."'";
$query1=Db_query($db1,$db);
$row11=Db_fetch_array($query1); 
echo $row11['shift_name'];
	  ?></td>
<td><?php echo $row['calender_days']; ?></td>
<td><?php echo $row['monthly_wages']; ?></td>
<td><?php echo $row['working_wages']; ?></td>
<td><?php echo $row['cost_per_hours']; ?></td>

<td><a href="index.php?route=Production_operator&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_operator&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>
<?php 
include('includes/footer.inc');
?>
<script language="JavaScript" type="text/javascript">
function count(str)
{
var i=document.getElementById("monthly_wages").value;
var k=document.getElementById("calender_days").value;
var j=i/k;
var t=j/str; 
document.getElementById("cost_per_hours").value=float(t);	
}	
</script>