
<?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']."',CompanyId='".$_SESSION['ACGCompanyId']."'";
		  
$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['Delete'])
{
	for($i=0;$i<count($_REQUEST['leadid']);$i++){
	$del="delete from production_operator_master where id='".$_REQUEST['leadid'][$i]."'";
	$query=DB_query($del,$db);	
	}
$s->pageLocation("index.php?route=Production_operator&daction=Updated".$rurl);	
}

?>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<?php if($_REQUEST['action']=='') { ?>
<h1>Production Operator</h1>
<form action="" method="post">
<table width="100%" border="0" cellpadding="3" cellspacing="0">
<tr class="row1">
	<td class="tabledata1">Branch</td>	
	<td><select name="site" style="width:150px;">
 <?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($branch==$site_row['loccode']?'selected':'')?>><?php echo $site_row['locationname']?></option>
<?php }?>		</select></td>
	<td class="tabledata1">Operator Name</td>	
	<td><input name="operator_name" id="operator_name" style="width:150px;" type="text"></td>
</tr>
<tr class="row1">
	<td class="tabledata1">Shift Name</td>	
	<td><div id="orderid">
	<select name="shift_name" style="width:150px;" 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>
	<td class="tabledata1">Calender Days</td>	
	<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:150px;" type="text" value="<?php echo $num; ?>" readonly>
	</td>

</tr>
<tr class="row1">
	<td class="tabledata1">Monthly Wages </td>	
	<td><input name="monthly_wages" id="monthly_wages" style="width:150px;" type="text"></td>
	<td class="tabledata1"> Working Hours</td>	
	<td><input name="working_hrs" id="working_hrs" style="width:150px;" type="text" onchange="count(this.value);"></td>
</tr>

  
 
<tr class="row1">
	<td class="tabledata1">CostPer Hours</td>	
	<td colspan="3"><input name="cost_per_hours" id="cost_per_hours" style="width:150px;" type="text"></td>
</tr>  
<tr class="row1">
	<td colspan="4">
		<p align="center"><input type="submit" value="Save" name="Save" class="search"></p>
	</td>
</tr> 
</table>
</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);	
?>

<h1>Edit Production Operator</h1>
<form action="" method="post">
<table width="100%" border="0" cellpadding="3" cellspacing="0">
<tr class="row1">
   <td class="tabledata1">Branch</td>		
	  <td><select name="site" style="width:150px;">
	  <?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']==$row1['branch_code'])
						{
						$k="selected";	
						}?>
		<option value="<?php echo $site_row['loccode']; ?>"<?php echo $k; ?>><?php echo $site_row['locationname']; ?></option>
						
				<?php }		?></select>
	</td>
	<td class="tabledata1">Operator Name </td>	
	<td><input name="operator_name" id="operator_name" style="width:150px;" type="text" value="<?php echo $row1['operator_name']; ?>"></td>
</tr>
<tr class="row1">
	<td class="tabledata1">Shift Name</td>	
	<td><div id="orderid">
	<select name="shift_name" style="width:150px;" 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>
	<td class="tabledata1">Calender Days</td>	
	<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:150px;" type="text" value="<?php if(!empty($row1['calender_days'])) { echo $row1['calender_days']; } else { echo $num;} ?>" readonly>
	</td>

</tr>
<tr class="row1">
	<td class="tabledata1">Monthly Wages</td>	
	<td><input name="monthly_wages" id="monthly_wages" style="width:150px;" type="text" value="<?php echo $row1['monthly_wages']; ?>">
	</td>
	<td class="tabledata1">Working Hours</td>	
	<td><input name="working_hrs" id="working_hrs" style="width:150px;" type="text"  value="<?php echo $row1['working_wages']; ?>" onchange="count(this.value);" >
</td>
</tr>  
<tr class="row1"> 
	<td class="tabledata1">CostPer Hours</td>	
	<td colspan="3"><input name="cost_per_hours" id="cost_per_hours" style="width:150px;" type="text" value="<?php echo $row1['cost_per_hours']; ?>">
	</td>
</tr>  
<tr class="row1">
	<td colspan="4">
		<p align="center"><input type="submit" value="Update" name="Update" class="search"></p>
	</td>
</tr> 
</table>	
</form>	
<?php }  ?>	
<form name="myform" method="post">
<p align="left">
	<input type="submit" name="Delete" value="Delete" class="search" onclick="return confirm('Are you sure you want to delete?')" />
</p>
<table width="100%" border="1" cellpadding="3" cellspacing="0">
<tr>
<td class="tabledata"><input name="leadid" type="checkbox"   id="leadid" onclick="LeadData()"    /></td>
<td class="tabledata">Branch</td>
<td class="tabledata">Operator Name  </td>
<td class="tabledata">Shift Name  </td>
<td class="tabledata">Calender Days  </td>
<td class="tabledata">Monthly Wages  </td>
<td class="tabledata">Working Hours  </td>
<td class="tabledata">Costper Hours </td>
</tr>
<?php $i=0;
 $sql="select * from production_operator_master where CompanyId='".$_SESSION['ACGCompanyId']."'";
$query=DB_query($sql,$db);

while($row=DB_fetch_array($query))
{	
?>
<tr class="row1">
<td style="white-space:nowrap;"><input name="leadid[]" type="checkbox" id="leadid_<?php echo $i+1; ?>"   value="<?php  echo $row['id']?>" />
	
	<a href="index.php?route=Production_operator&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&action=edit&Id=<?php echo $row['id'];?>"><img src="images/icon_edit.gif" width="12px"  height="12" /></a>
	
	<!--<a href="index.php?route=CRM/dot_request_form&action=View&id=<?php echo $fetchArray['id']; ?>&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>"><img src="images/search.gif" width="12px"  height="12" /></a>-->
	</td>
<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>
</tr>
<?php $i++;} ?>
</table>
</form>




</div></div>
<?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);	
}	

function LeadData()
{	
	myCheckboxArray = document.myform.elements["leadid[]"];
	var t=myCheckboxArray.length;
	//alert(myCheckboxArray);
	if(document.getElementById('leadid').checked==true)
	{	
	if(t==undefined)
	document.getElementById('leadid_'+1).checked=true;		
	for (var i = 1; i <= t; i++)
	{
	document.getElementById('leadid_'+i).checked=true;	
	}	
	}
	else
	{
	if(t==undefined)		
	document.getElementById('leadid_'+1).checked=false;		
	for (var i = 1; i <= t; i++)
	{
	document.getElementById('leadid_'+i).checked=false;	
	}
	}
}

</script>
