<?php
include ("../include/session.php");
if(!$session->isRadstoneReceptionUser() && !$session->isAdmin() && !$session->isRadstoneStoreUser()){
	header("Location: ../HR/employeeMenu.php");
} else {
	include "../header.php";

    $q = "SELECT empId, empFName, empLName FROM nam_employees ORDER BY empFName ASC";
	$arrId = array();
	$arrName = array();
	$result = execsql($q);
	$num = mysql_num_rows($result);
	$b = 0;
	while($b < $num){
		$arrId[mysql_result($result, $b, "empId")] = mysql_result($result, $b, "empFName") ." ". mysql_result($result, $b, "empLName");
		$b++; } 

	//	include ("../include/db.php");
	$id = mysql_real_escape_string($_GET['id']);
	$inputId = mysql_real_escape_string($_GET['empId']);
	$type = mysql_real_escape_string($_GET['type']);
	if($type == ""){
		if($session -> isAdmin()){
			$type = "personal";
		}

		if($session -> isRadstoneReceptionUser()){
			$type = "personal";
		}

		if($session -> isRadstoneStoreUser()){
			$type = "loan";
		}
	}
	$dMonth = date("m");
	$dYear = date("y");

	$query = "";
	if (strlen($id) > 1) {
		$query = "SELECT * FROM nam_employees WHERE empId = '" . $id . "'";
	} else {
		$query = "SELECT * FROM nam_employees WHERE empId = '" . $inputId . "'";
	}

	$result = execsql($query);
	if (!$result) {
		die('Could not query: ' . mysql_error());
	}

	$vioName = mysql_result($result, 0, "empId");
	$num = mysql_num_rows($result);

	$queryRemarks = "SELECT * FROM nam_minorviolations WHERE empId = '" . $vioName . "' AND orientation = 'Positive'";
	$resultRemarks = execsql($queryRemarks);
	$numRemarks = mysql_num_rows($resultRemarks);

	$queryVio = "SELECT * FROM nam_minorviolations WHERE empId = '" . $vioName . "' AND orientation = 'Negative' ORDER BY vioDate DESC";
	$resultVio = execsql($queryVio);
	$numVio = mysql_num_rows($resultVio);


	$dateOvertime = date("Y-m-d", mktime(0, 0, 0, date("m"), 01, date("Y")));

	$queryLate = "SELECT * FROM nam_timekeeping WHERE empId = '" . $vioName . "' AND date >= '$dateOvertime'";
	$resultLate = execsql($queryLate);
	$numLate = mysql_num_rows($resultLate);

	$queryLateA = "SELECT * FROM nam_timekeeping WHERE empId = '" . $vioName . "' ORDER BY date DESC";
	$resultLateA = execsql($queryLateA);
	$numLateA = mysql_num_rows($resultLateA);


	$queryOver = "SELECT * FROM nam_overtime WHERE empId = '" . $vioName . "' AND date >= '$dateOvertime'";
	$resultOver = execsql($queryOver);
	$numOver = mysql_num_rows($resultOver);

	$queryLoan = "SELECT * FROM nam_loan WHERE empId = '" . $vioName . "' AND returned = '0' ORDER BY date DESC";
	$resultLoan = execsql($queryLoan);
	$numLoan = mysql_num_rows($resultLoan);

	$queryLoan = "SELECT * FROM nam_loan WHERE empId = '" . $vioName . "' AND returned = '1' ORDER BY date DESC";
	$resultLoanN = execsql($queryLoan);
	$numLoanN = mysql_num_rows($resultLoanN);

	$q = "SELECT productId, productName FROM nam_products";
	$resultPro = execsql($q);
	$numPro = mysql_num_rows($resultPro);
	$j = 0;
	$proArray = array ();
	while ($j < $numPro) {
		$proArray[mysql_result($resultPro, $j, "productId")] = mysql_result($resultPro, $j, "productName");
		$j++;
	}
	?>
<style type="text/css">
<!--
.style5 {
	font-family: Arial, Helvetica, sans-serif;
	font-size: small;
}
.style11 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: medium;
	color: #0066CC;
}
.style12 {font-family: Verdana, Arial, Helvetica, sans-serif}
-->
</style>
<div class="headerbox">Employee Personal Details</div>
<div class="menubox"> <form name="form">
    <div align="right"><span class="style5">Select another Employee:</span><br />
      
      <select name="URL" onchange="window.location.href= this.form.URL.options[this.form.URL.selectedIndex].value">
        <option value="">Select</option>
        <?php 
			foreach($arrId as $key=>$value){
				echo "<option value=\"searchAndDisplayE.php?empId=$key\">$value</option>";	
			}?>
      </select>
      <br />
      <a href="searchAndDisplay.php"><img src="../../Images/employees_back_btn.png" alt="." width="110" height="25" border="0" /></a></div>
</form> </div>
<div class="subheaderbox"> <?php echo mysql_result($result, 0, "empFName") . " " . mysql_result($result, 0, "empLName") ?></div><br /><br /><br /><br />
<h4>
  <ul id="sad-navigation"><?php if($session->isAdmin() || $session->isRadstoneReceptionUser() ){ ?>
  <li <?php if($type== "personal"){echo "class=\"active\"";}?>><span><span><a
		href="searchAndDisplayE.php?empId=<?php echo $vioName?>&type=personal">Personal</a></span></span></li>
	     
	<li <?php if($type== "discipline"){echo "class=\"active\"";}?>><span><span><a
		href="searchAndDisplayE.php?empId=<?php echo $vioName?>&type=discipline">Discipline</a></span></span> </li>      
	<?php } ?>
	<li <?php if($type== "loan"){echo "class=\"active\"";}?>><span><span><a
		href="searchAndDisplayE.php?empId=<?php echo $vioName?>&type=loan">Loan</a></span></span></li>
</ul>
</h4>

	<?php
	if($type == "personal"){
		if($session->isAdmin() || $session->isRadstoneReceptionUser()){
			$i = 0;
			while ($i < $num) {
				$f1 = mysql_result($result, $i, "empFName");
				$f2 = mysql_result($result, $i, "empLName");
				$f3 = mysql_result($result, $i, "empContact");
				$f4 = mysql_result($result, $i, "empAge");
				$f5 = mysql_result($result, $i, "emergName");
				$f6 = mysql_result($result, $i, "emergNo");
				$f7 = mysql_result($result, $i, "emergRelation");
				//	$f8=mysql_result($result,$i,"education");
				//	$f9=mysql_result($result,$i,"isEmployed");
				//	if($f9 < 1) {
				//		$employed = "Employed";
				//	}
				//	else {
				//		$employed = "Fired";
				//	}
				$f10 = mysql_result($result, $i, "empId");
				//    $f11=mysql_result($result, $i, "pob");
				$f12 = mysql_result($result, $i, "empSex");
				$f13 = mysql_result($result, $i, "empMStatus");
				$f14 = mysql_result($result, $i, "empIdNo");
				//		$f15=mysql_result($result, $i, "empPass");
				$f17 = mysql_result($result, $i, "empCountry");
				$f18 = mysql_result($result, $i, "empPost");
				//		$f19=mysql_result($result, $i, "empRes");
				$f20 = mysql_result($result, $i, "empAccNo");
				$f21 = mysql_result($result, $i, "empBranch");
				$f22 = mysql_result($result, $i, "empDepend");
				$f23 = mysql_result($result, $i, "empPos");
				$f27 = mysql_result($result, $i, "empSection");
				$f24 = mysql_result($result, $i, "empDateEmp");
				$f25 = mysql_result($result, $i, "empShoe");
				$f26 = mysql_result($result, $i, "empOverall");
				$f28 = mysql_result($result, $i, "empEmployDate");
				$f30 = mysql_result($result, $i, "firstWarning");
				$f31 = mysql_result($result, $i, "writtenWarning");
				$f32 = mysql_result($result, $i, "finalWarning");
				$f33 = mysql_result($result, $i, "empRate");
				$f34 = mysql_result($result, $i, "empBank");
				$f35 = mysql_result($result, $i, "performance");


				?>
				<?php


				//		echo $date;
				?>





				<?php


				$amountOver = 0.00;
				$v = 0;
				$rate = mysql_result($result, $y, "empRate");

				while ($v < $numOver) {
					$m1 = mysql_result($resultOver, $v, "hours");
					$m2 = mysql_result($resultOver, $v, "bonus");
					$amountOver += ((($rate * $m1) / 100) * $m2);
					$v++;
				}
				if ($numLate < 1) {
					$amountOver = $amountOver +50;
//					echo "<br />This employee has not been late this month and has been given a bonus of P50!<br />" . "Overtime Pay: P" . $amountOver . "<br />";
				} else {
//					echo "<br />Overtime Pay: P" . $amountOver . "<br />";
				}

				$dd = date("d");
				$mm = date("m");
				$yy = date("Y");
				$c = 0;
				$sundays = 0;
				$saturdays = 0;
				while ($c < $dd) {
					if (date("l", mktime(0, 0, 0, $mm, date("d") - $c, $yy)) == "Sunday") {
						$sundays++;
					}
					$c++;
				}

				while ($c < $dd) {
					if (date("l", mktime(0, 0, 0, $mm, date("d") - $c, $yy)) == "Saturday") {
						$saturdays++;
					}
					$c++;
				}
				//$day = date("d");
				//$dayNow = date("d");
				$days = $dd - ($sundays + $saturdays);
				$amount = 0.00;
				$x = 0;

				while ($x < $numLate) {
					$l1 = mysql_result($resultLate, $x, "hours");
					$amount = $amount + $l1;
					$x++;
				}

				$amountLost = $amount * $rate;
				$fullDay = $rate * 9;
				$owed = (($days * $fullDay) - $amountLost);
//	no longer wanted			echo "<br />Amount owed this month(not incl. overtime) : P" . $owed . "<br />";
//	no longer wanted			echo "Amount owed this month in Total : P" . ($owed + $amountOver);
				?>

<table>
	<tr>
		<td id="row1">ID Number:</td>
		<td id="row1"><?php echo $f10; ?></td>
		<td>Employees Contact Number:</td>
		<td><?php echo $f3; ?></td>
	</tr>

	<tr>
		<td>Employees First Name:</td>
		<td><?php echo $f1; ?></td>
		<td>Employees Last Name:</td>
		<td><?php echo $f2; ?></td>
	</tr>


	<tr>
		<td>Date of Birth</td>
		<td><?php echo $f4; ?></td>

		<td>Employees National Id Number:</td>
		<td><?php echo $f14; ?></td>
	</tr>

	<tr>
		<td>Employees Place of Birth:</td>
		<td><?php echo $f11; ?></td>
		<td>Employees sex:</td>
		<td><?php echo $f12; ?></td>
	</tr>
	<tr>
		<td>Employees Marital Status:</td>
		<td><?php echo $f13; ?></td>
		<td>Number of Dependants:</td>
		<td><?php echo $f22; ?></td>
	</tr>

	<tr>
		<td>Employees Postal Address:</td>
		<td><?php echo $f18; ?></td>
		<td>Citizen:</td>
		<td><?php echo $f17; ?></td>
	</tr>

	<tr></tr>
	<tr>
		<td>Bank Name:</td>
		<td><?php echo $f34;?></td>
		<td>Branch Number:</td>
		<td><?php echo $f21; ?></td>
	</tr>

	<tr>

		<td>Account number:</td>
		<td><?php echo $f20; ?></td>
	</tr>

	<tr></tr>

	<tr>
		<td>Employment Date:</td>
		<td><?php echo $f24; ?></td>
		<td>End of Employment Date:</td>
		<td><?php echo $f28; ?></td>
	</tr>

	<tr>
		<td>Position:</td>
		<td><?php echo $f23; ?></td>
		<td>Section:</td>
		<td><?php echo $f27;?></td>
	</tr>

	<tr>

		<td>Rate:P</td>
		<td><?php echo $f33;?> /Hour</td>
	</tr>

	<tr>
		<td>Shoe size:</td>
		<td><?php echo $f25; ?></td>
		<td>Overall Size:</td>
		<td><?php echo $f26; ?></td>
	</tr>
	<tr></tr>
	<tr>
		<td>Emergency Contact:</td>
		<td><?php echo $f5; ?></td>

		<td>Emergency Contacts Relation to Employee:</td>
		<td><?php echo $f7; ?></td>
	</tr>
	<tr>
		<td>Emergency Contacts Number:</td>
		<td><?php echo $f6; ?></td>
		<td>Emergency Contacts Education:</td>
		<td><?php echo $f8; ?></td>
	</tr>
	<tr>
		<td>Employement :</td>
		<td><?php echo $employed; ?></td>
	</tr>
	<tr></tr>


	<tr>
		<td>HAS RECEIVED FIRST WARNING:</td>
		<td><?php echo $f30; ?></td>
		<td>HAS RECEIVED WRITTEN WARNING:</td>
		<td><?php echo $f31; ?></td>
	</tr>
	<tr>
		<td>HAS RECEIVED FINAL WARNING:</td>
		<td><?php echo $f32; ?></td>
		<td>Performance:</td>
		<td><?php echo $f35?></td>
	</tr>
</table>
				<p>
  <?php

				$i++;
			}
		}
	}elseif($type == "discipline"){
		if($session->isAdmin() || $session->isRadstoneReceptionUser()){
			?>
  </p>
  <div class="tablebox">
				 <div class="subheaderbox"><a name="Absenteism" id="Absenteism"></a><span class="style11">Absenteism</span>&nbsp;&nbsp;&nbsp;<a href="#Violations">Violations</a>&nbsp;&nbsp;&nbsp;<a href="#Remarks">General Remarks</a></div> 
				 
				 <table  class="tablebox.newtable">
	<thead>
		<tr>
			<!--			<th class="sortable-numeric">Late Coming ID</th>-->
			<th class="sortable-date-ymd">Date</th>
			<th class="sortable-text">Absent/Late</th>
			<th class="sortable-text">Permission</th>
			<th class="sortable-numeric">Hours</th>
			<th class="sortable-text">Details</th>
		</tr>
	</thead>
	<tbody>


	<?php

	//$permission = "";
	$a = 0;
	if ($numLateA != 0) {

		while ($a < $numLateA) {
						$b1 = mysql_result($resultLateA, $a, "absent");
			$b2 = mysql_result($resultLateA, $a, "date");
			$b3 = mysql_result($resultLateA, $a, "permission");
			if ($b3 < 1) {
				$permission = "No";
			} else {
				$permission = "Yes";
			}
			$b4 = mysql_result($resultLateA, $a, "details");
			$b5 = mysql_result($resultLateA, $a, "hours");
			$b6 = mysql_result($resultLateA, $a, "timeId");
			?>
		<tr >
			<td><?php echo $b2?></td>
			<td><?php echo $b1?></td>
			<td><a href="manipulate/editPermission.php?id=<?php echo $b6?>&empId=<?php echo $vioName?>"><?php echo $permission?></a></td>
			<td><?php echo $b5?></td>
			<td>
			<a href="editComment.php?id=<?php echo $b6?>&type=timekeeping&empId=<?php echo $vioName?>"><?php echo $b4?></a></td>
		</tr>


		<?php

		$a++;
		}
	} else {

		echo "this employee has not been late this month<br />";

	}
	?>
	</tbody>
</table></div>
<div class="tablebox">
<div class="subheaderbox"><a name="Violations" id="Violations"></a><a href="#Absenteism">Absenteism</a> &nbsp;&nbsp;&nbsp;<span class="style11">Violations</span>&nbsp;&nbsp;&nbsp;<a href="#Remarks">General Remarks</a></div>

<table id="test1" cellpadding="0" cellspacing="0" border="0"
	class="rowstyle-alt colstyle-alt no-arrow">
	<thead>
		<tr>
			<th class="sortable-numeric">Warning?</th>
			<th class="sortable-text">Violation Type</th>
			<th class="sortable-text">Details</th>
			<th class="sortable-date-ymd">Date</th>
		</tr>
</thead>
	<tbody>
	<?php

	$j = 0;
	if ($numVio < 1) {

		echo "This employee has no minor violations";
	} else {
		while ($j < $numVio) {
			$g1 = mysql_result($resultVio, $j, "warning");
			$g2 = mysql_result($resultVio, $j, "vioDate");
			$g3 = mysql_result($resultVio, $j, "vioType");
			$g4 = mysql_result($resultVio, $j, "vioDetails");
			$g5 = mysql_result($resultVio, $j, "vioId");
			echo "<tr><td>$g1</td> <td>$g3</td> <td><a href=\"editComment.php?id=$g5&type=remark&empId=$vioName\"> $g4</a></td><td>$g2</td></tr>";

			$j++;

		}

	}
	echo "</tbody></table></div>";
	?></tbody>
<br />
		<!-- GOOD STUFF -->
<div class="tablebox">		
		<div class="subheaderbox" width="600"><a name="Remarks" id="Remarks"></a><a href="#Absenteism">Absenteism</a> &nbsp;&nbsp;&nbsp;<a href="#Violations">Violations</a>&nbsp;&nbsp;&nbsp;<span class="style11">General Remarks</span></div> <div class="subheaderbox">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div><br />
		
		
		
		<table id="test1" cellpadding="0" cellspacing="0" border="0" width="580"
			class="rowstyle-alt colstyle-alt no-arrow">
			<thead>
				<tr>
					<th class="sortable-text">Type</th>
					<th class="sortable-text">Details</th>
					<th class="sortable-date-ymd">Date</th>
				</tr>
			</thead>
			<tbody>
			  <?php

			$j = 0;
			if ($numRemarks < 1) {

				echo "This employee has no positive remarks";
			} else {
				while ($j < $numRemarks) {
					$g1 = mysql_result($resultRemarks, $j, "vioId");
					$g2 = mysql_result($resultRemarks, $j, "vioDate");
					$g3 = mysql_result($resultRemarks, $j, "vioType");
					$g4 = mysql_result($resultRemarks, $j, "vioDetails");
					echo "<tr><td>$g3</td><td><a href=\"editComment.php?id=$g1&type=remark&empId=$vioName\">$g4</a></td><td>$g2</td></tr>";

					$j++;

				}

			}
			echo "</tbody></table></div>";

		}



	}elseif($type == "loan"){
		if($session->isAdmin() || $session->isRadstoneStoreUser() || $session->isRadstoneReceptionUser() ){

			?><div class="tablebox">
			<div class="subheaderbox"><a name="Outstanding" id="Outstanding"></a><span class="style11">Outstanding Items</span>&nbsp;&nbsp;&nbsp;<a href="#Returned">Returned Items</a></div><br />
			
				<table id="test1" cellpadding="0" cellspacing="0" border="0"
					class="rowstyle-alt colstyle-alt no-arrow">
					<thead>
						<tr>
							<th class="sortable-numeric">Loan ID</th>
							<th class="sortable-text">Product Name</th>
							<th class="sortable-numeric">Employee Id</th>
							<th class="sortable-numeric">Quantity</th>
							<th class="sortable-date-ymd">Date Loaned</th>
							<th>Return?</th>
							<!--			<th>Date Returned</th>-->
						</tr>
					</thead>
					<tbody>

					<?php

					//$permission = "";
					$a = 0;
					if ($numLoan != 0) {

						while ($a < $numLoan) {
							$b1 = mysql_result($resultLoan, $a, "loanId");
							$b2 = mysql_result($resultLoan, $a, "productId");
							$b3 = mysql_result($resultLoan, $a, "empId");
							$b4 = mysql_result($resultLoan, $a, "quantity");
							$b5 = mysql_result($resultLoan, $a, "date");
							$b6 = mysql_result($resultLoan, $a, "returned");
							//			$b7 = mysql_result($resultLoan, $a, "dateReturned");
							?>
						<tr class="alt">
							<td><?php echo $b1?></td>
							<td><a href="../Store/showProduct.php?productId=<?php echo $b2?>"><?php echo $proArray[$b2];?></a></td>
							<td><?php echo $b3?></td>
							<td><?php echo $b4?></td>
							<td><?php echo $b5?></td>
							<?php							if($b6 != '1'){
								?>
							<td><a
								href="manipulate/returnLoan.php?loanId=<?php echo $b1?>&productId=<?php echo $b2?>&quantity=<?php echo $b4?>&empId=<?php echo $vioName?>">Return</a>
							/ <a
								href="manipulate/returnRemove.php?loanId=<?php echo $b1?>&productId=<?php echo $b2?>&quantity=<?php echo $b4?>&empId=<?php echo $vioName?>">Return
							+ Discard</a></td>
							<?php							}else{
								echo "<td>Returned</td>";
							}
							?>
							<!--			<td><?php echo $b7?></td>-->
						</tr>


						<?php
						$a++;
						}
					} else {

						echo "this employee does not currently have any items out on loan!<br /><br />";

					}
					?>
					</tbody>
				</table> </div>
				<br />

                <div class="tablebox">
				<div class="subheaderbox"><a name="Returned" id="Returned"></a><a href="#Outstanding">Outstanding items</a> &nbsp;&nbsp;&nbsp;<span class="style11">Returned Items</span></div>
				<table id="test1" cellpadding="0" cellspacing="0" border="0"
					class="rowstyle-alt colstyle-alt no-arrow">
					<thead>
						<tr>
							<th class="sortable-numeric">Loan ID</th>
							<th class="sortable-text">Product Name</th>
							<th class="sortable-numeric">Employee Id</th>
							<th class="sortable-numeric">Quantity</th>
							<th class="sortable-date-ymd">Date Loaned</th>
							<!--			<th>Return?</th>-->
							<th>Date Returned</th>
						</tr>
					</thead>
					<tbody>				  <br />			
						<?php

						//$permission = "";
						$a = 0;
						if ($numLoanN != 0) {

							while ($a < $numLoanN) {
								$b1 = mysql_result($resultLoanN, $a, "loanId");
								$b2 = mysql_result($resultLoanN, $a, "productId");
								$b3 = mysql_result($resultLoanN, $a, "empId");
								$b4 = mysql_result($resultLoanN, $a, "quantity");
								$b5 = mysql_result($resultLoanN, $a, "date");
								$b6 = mysql_result($resultLoanN, $a, "returned");
								$b7 = mysql_result($resultLoanN, $a, "dateReturned");
								?>
						<tr class="alt">
							<td><?php echo $b1?></td>
							<td><a href="../Store/showProduct.php?productId=<?php echo $b2?>"><?php echo $proArray[$b2];?></a></td>
							<td><?php echo $b3?></td>
							<td><?php echo $b4?></td>
							<td><?php echo $b5?></td>

							<td><?php echo $b7?></td>
						</tr>


						<?php
						$a++;
							}
						} else {

							echo "this employee has yet to return any items<br /><br />";

						}
						?>
					</tbody>
				</table></div>
				<?php
		}
	}
	?>

				<br />
				<br />



				<?php
}
				include "../footer.php";

?>