PageRenderTime 34ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/SERVER/timesheet/payrolldetail.php

https://github.com/joelbrock/is4c_nofc
PHP | 116 lines | 100 code | 14 blank | 2 comment | 25 complexity | 3decc1af8b7356ea61ccdfb60e73af2e MD5 | raw file
  1. <html>
  2. <head>
  3. <Title>Payroll Detail</Title>
  4. <link rel="stylesheet" href="../includes/style.css" type="text/css" />
  5. </head>
  6. <body>
  7. <?php # payrolldetail.php - Gives a detailed view of a selected employee in a given pay period.
  8. require_once ('../define.conf');
  9. // mysql_select_db($db_master, 'is4c_log');
  10. // mysql_select_db($db_slave, 'is4c_log');
  11. if (is_numeric($_GET['periodID']) && is_numeric($_GET['emp_no'])) { // If submitted.
  12. $emp_no = $_GET['emp_no'];
  13. $periodID = $_GET['periodID'];
  14. $query = "SELECT ROUND(SUM(TIMESTAMPDIFF(MINUTE, t.time_in, t.time_out))/60, 2),
  15. date_format(t.date, '%a %b %D'),
  16. t.emp_no,
  17. e.FirstName,
  18. date_format(p.periodStart, '%M %D, %Y'),
  19. date_format(p.periodEnd, '%M %D, %Y'),
  20. t.date
  21. FROM is4c_log.timesheet AS t
  22. INNER JOIN is4c_op.employees AS e
  23. ON (t.emp_no = e.emp_no)
  24. INNER JOIN is4c_log.payperiods AS p
  25. ON (t.periodID = p.periodID)
  26. WHERE t.emp_no = $emp_no
  27. AND t.periodID = $periodID
  28. AND t.area <> 13
  29. GROUP BY t.date";
  30. $weekoneQ = "SELECT ROUND(SUM(TIMESTAMPDIFF(MINUTE, t.time_in, t.time_out))/60, 2)
  31. FROM is4c_log.timesheet AS t
  32. INNER JOIN is4c_log.payperiods AS p
  33. ON (p.periodID = t.periodID)
  34. WHERE t.emp_no = $emp_no
  35. AND t.periodID = $periodID
  36. AND t.area <> 13
  37. AND t.date >= DATE(p.periodStart)
  38. AND t.date < DATE(date_add(p.periodStart, INTERVAL 7 day))";
  39. $weektwoQ = "SELECT ROUND(SUM(TIMESTAMPDIFF(MINUTE, t.time_in, t.time_out))/60, 2)
  40. FROM is4c_log.timesheet AS t
  41. INNER JOIN is4c_log.payperiods AS p
  42. ON (p.periodID = t.periodID)
  43. WHERE t.emp_no = $emp_no
  44. AND t.periodID = $periodID
  45. AND t.area <> 13
  46. AND t.date >= DATE(date_add(p.periodStart, INTERVAL 7 day)) AND t.date <= DATE(p.periodEnd)";
  47. $vacationQ = "SELECT ROUND(vacation, 2)
  48. FROM is4c_log.timesheet AS t
  49. WHERE t.emp_no = $emp_no
  50. AND t.periodID = $periodID
  51. AND t.area = 13";
  52. $weekoneR = mysql_query($weekoneQ);
  53. $weektwoR = mysql_query($weektwoQ);
  54. $vacationR = mysql_query($vacationQ);
  55. list($weekone) = mysql_fetch_row($weekoneR);
  56. if (is_null($weekone)) $weekone = 0;
  57. list($weektwo) = mysql_fetch_row($weektwoR);
  58. if (is_null($weektwo)) $weektwo = 0;
  59. if (mysql_num_rows($vacationR) != 0) {
  60. list($vacation) = mysql_fetch_row($vacationR);
  61. } elseif (is_null($vacation)) {
  62. $vacation = 0;
  63. } else {
  64. $vacation = 0;
  65. }
  66. $result = mysql_query($query);
  67. if (mysql_num_rows($result) > 0) {
  68. $first = TRUE;
  69. $periodHours = 0;
  70. while ($row = mysql_fetch_array($result)) {
  71. if ($first == TRUE) {
  72. echo "<p>Timesheet for $row[3] from $row[4] to $row[5]:</p>";
  73. echo '<table><tr><th>Date</th><th>Total Hours Worked</th><th></th></tr>';
  74. }
  75. if ($row[0] > 24) {$fontopen = '<font color="red">'; $fontclose = '</font>';} else {$fontopen = NULL; $fontclose = NULL;}
  76. echo "<tr><td>$row[1]</td><td>$fontopen$row[0]$fontclose</td><td><a target=\"_blank\" href=\"editdate.php?emp_no=$emp_no&periodID=$periodID&date=$row[6]\">(Edit)</a></td></tr>";
  77. $first = FALSE;
  78. $periodHours += $row[0];
  79. }
  80. $roundhour = explode('.', number_format($periodHours, 2));
  81. if ($roundhour[1] < 13) {$roundhour[1] = 00;}
  82. elseif ($roundhour[1] >= 13 && $roundhour[1] < 37) {$roundhour[1] = 25;}
  83. elseif ($roundhour[1] >= 37 && $roundhour[1] < 63) {$roundhour[1] = 50;}
  84. elseif ($roundhour[1] >= 63 && $roundhour[1] < 87) {$roundhour[1] = 75;}
  85. elseif ($roundhour[1] >= 87) {$roundhour[1] = 00; $roundhour[0]++;}
  86. $periodHours = number_format($roundhour[0] . '.' . $roundhour[1], 2);
  87. echo "</table>
  88. <p>Total hours in this pay period: $periodHours</p>
  89. <p>Week One: ";
  90. if ($weekone > 40) {echo '<font color="red">'; $font = '</font>';} else {$font = NULL;}
  91. echo "$weekone" . $font . "</p>
  92. <p>Week Two: ";
  93. if ($weektwo > 40) {echo '<font color="red">'; $font = '</font>';} else {$font = NULL;}
  94. echo "$weektwo" . $font . "</p>
  95. <p>Vacation Pay: ";
  96. if ($vacation > 0) {echo '<font color="red">'; $font = '</font>';} else {$font = NULL;}
  97. echo "$vacation" . $font . "</p>";
  98. } else {
  99. echo '<p>There is no timesheet available for that pay period.</p>';
  100. }
  101. }
  102. ?>