<?php
session_start();
$username = $_SESSION['staff'];

include ("connect.php");

if($_POST["Print"] == "Print")
{
$slipNo = $_POST['slipNo'];

	echo "<script language='javascript'>window.location='printsalary.php?slipID=$slipNo'</script>";
}
	
if($_POST["Back"] == "Back")
{
	echo "<script language='javascript'>window.location='salarylist.php'</script>";
}
if($_SESSION['staff']!= null)
{
?>
	
<html>
<head>
<title>Daily Bookstore - Management System</title>
<!--include css file-->
<link href="bookstaff.css" rel="stylesheet" type="text/css"/>

<script language="Javascript">
	function showPreview(ele)
	{
		document.addbook.imgAvatar.src=ele.value;
	}
</script>
</head>

<body>

<?php
include ("stafffunctionbar.php");
?>
</div>
</fieldset>
</td>
</tr>
</table>

</center>

<hr/>
<center>
<h2>Daily Bookstore Management - Calculate Salary</h2>
</center>

<div id="mainpage">
<table width="90%">
<tr>
<td width="15%" valign="top">
<fieldset>
<legend><img src="Picture/salary.gif" width="30" height="30">Salary</legend>
<table>
<td valign="top">
<a href="salarylist.php"><img src="Picture/salary.gif" width="30" height="30" alt="EPF"><a href="salarylist.php">Salary List</a><br/>
<br/>
<a href="addsalary.php"><img src="Picture/addsalary.jpg" width="30" height="30" alt="EPF"><a href="addsalary.php">Add Salary</a><br/>
<br/>
<a href="editepf.php"><img src="Picture/epf.gif" width="30" height="30" alt="EPF"><a href="editepf.php">EPF</a><br/>
<br/>
<a href="socsolist.php"><img src="Picture/socso.gif" width="30" height="30" alt="Socso"><a href="socsolist.php">Socso</a><br/>
</td>
</tr>
</table>
</fieldset>
</td>

<td width="75%">
<center>
<form name="salarypay" method="post">
<fieldset style="width:80%">
<legend><img src="Picture/salary.gif" width="30" height="30">Calculate Salary</legend>

<?php

$slipID=$_GET['slipID'];
$result = mysql_query("SELECT * FROM salaryslip WHERE slipNo = '$slipID'");   

$row = mysql_fetch_array($result);
	
echo "<table align='center'>";
echo "<tr>";
echo "<td>Salary No: </td>";
echo "<td><input type='hidden' name='slipNo' value='".$row['slipNo']."'>".$row['slipNo']."</td>";
echo "</tr>";

echo "<tr>";
echo "<td>Month: </td>";

if($row['month'] == 1){
	$monthdata = "January";
	}else if($row['month'] == 2){
	$monthdata = "February";
	}else if($row['month'] == 3){
	$monthdata = "March";
	}else if($row['month'] == 4){
	$monthdata = "April";
	}else if($row['month'] == 5){
	$monthdata = "May";
	}else if($row['month'] == 6){
	$monthdata = "June";
	}else if($row['month'] == 7){
	$monthdata = "July";
	}else if($row['month'] == 8){
	$monthdata = "August";
	}else if($row['month'] == 9){
	$monthdata = "September";
	}else if($row['month'] == 10){
	$monthdata = "October";
	}else if($row['month'] == 11){
	$monthdata = "November";
	}else if($row['month'] == 12){
	$monthdata = "December";
	}else{
	}

echo "<td>$monthdata</td>";
echo "</tr>";

echo "<tr>";
echo "<td>Period: </td>";
echo "<td>".$row['startdate']." To ".$row['enddate']."</td>";
echo "</tr>";

echo "<tr>";
echo "<td>Month Working Day: </td>";
echo "<td>".$row['workingday']."</td>";
echo "</tr>";

echo "<tr>";
echo "<td colspan='2'><br/></td>";
echo "</tr>";

echo "<tr>";
echo "<td>Employee Name: </td>";
echo "<td>".$row['name']."</td>";
echo "</tr>";

echo "<tr>";
echo "<td>Basic Salary: </td>";
echo "<td>RM ";
printf("%10.2f",$row["basicsalary"]);
echo "</td>";
echo "</tr>";

echo "<tr>";
echo "<td colspan='2'><br/></td>";
echo "</tr>";

echo "<tr>";
echo "<td colspan='2'>Allowance</td>";
echo "</tr>";

echo "<tr>";
echo "<td>Transport: </td>";
echo "<td>RM ";
printf("%10.2f",$row["allowance1"]);
echo "</td>";
echo "</tr>";

echo "<tr>";
echo "<td>Handphone: </td>";
echo "<td>RM ";
printf("%10.2f",$row["allowance2"]);
echo "</td>";
echo "</tr>";

echo "<tr>";
echo "<td>Meal: </td>";
echo "<td>RM ";
printf("%10.2f",$row["allowance3"]);
echo "</td>";
echo "</tr>";

echo "<tr>";
echo "<td colspan='2'><br/></td>";
echo "</tr>";

echo "<tr>";
echo "<td colspan='2'>No Pay Leave</td>";
echo "</tr>";

echo "<tr>";
echo "<td>No Pay Leave Hour(s): </td>";
echo "<td>".$row['staffNoPayHour']." Hour(s)</td>";
echo "</tr>";

echo "<tr>";
echo "<td>No Pay Leave: </td>";
echo "<td>RM ";
printf("%10.2f",$row["leaveRM"]);
echo "</td>";
echo "</td>";
echo "</tr>";

echo "<tr>";
echo "<td>Gross Pay: </td>";
echo "<td>RM ";
printf("%10.2f",$row["grosspay"]);
echo "</td>";
echo "</tr>";

echo "<tr>";
echo "<td colspan='2'><br/></td>";
echo "</tr>";

echo "<tr>";
echo "<td>EPF (Employee): </td>";
echo "<td>RM ";
printf("%10.2f",$row["epfrate1"]);
echo "</td>";
echo "</tr>";

echo "<tr>";
echo "<td>EPF (Company): </td>";
echo "<td>RM ";
printf("%10.2f",$row["epfrate2"]);
echo "</td>";
echo "</tr>";

echo "<tr>";
echo "<td>Socso (Employee): </td>";
echo "<td>RM ";
printf("%10.2f",$row["socso1"]);
echo "</td>";
echo "</tr>";

echo "<tr>";
echo "<td>Socso (Company): </td>";
echo "<td>RM ";
printf("%10.2f",$row["socso2"]);
echo "</td>";
echo "</tr>";

echo "<tr>";
echo "<td>PCB: </td>";
echo "<td>RM ";
printf("%10.2f",$row["pcb"]);
echo "</td>";
echo "</tr>";

echo "<tr>";
echo "<td colspan='2'><br/></td>";
echo "</tr>";

echo "<tr>";
echo "<td>Net Pay: </td>";
echo "<td>RM ";
printf("%10.2f",$row["netpay"]);
echo "</td>";
echo "</tr>";
?>

<tr>
<td colspan="2" align="center">
<input type="submit" name="Print" value="Print">
<input type="submit" name="Back" value="Back">
</td>
</tr>

</table>
</fieldset>
</form>
</center>
</body>
</html>
<?php
}else{
	echo "<script language='javascript'>alert ('Please login.')</script>";
	echo "<script language='javascript'>window.location='index.php'</script>";
}
?>