optimization, begin refactor, basic reports
This commit is contained in:
107
reports.php
107
reports.php
@@ -16,18 +16,21 @@ echo "<h2 class=\"content-subhead\">You are not logged in!!!</h2>";
|
||||
else
|
||||
{
|
||||
//********** BEGIN CONTENT **********//
|
||||
|
||||
echo "<h2 class=\"content-subhead\">Punch History</h2>";
|
||||
echo "<p>Below is your company punch history. You can use the form boxes to narrow down the results as needed, by date, user, or a combination.</p>";
|
||||
echo "<p>Below is your company punch history. The below drop-down can be used to select pre-configured reports. Other reports are currently being written.</p>";
|
||||
|
||||
|
||||
echo "<form class=\"pure-form pure-form-stacked\" action=\"reports.php\" method=\"post\">";
|
||||
echo " <fieldset>";
|
||||
echo " <div class=\"pure-g\">";
|
||||
echo " <div class=\"pure-u-1 pure-u-md-1-3\">";
|
||||
echo " <label for=\"order\">Sort Order</label>";
|
||||
echo " <select name=\"order\" class=\"pure-input-1-2\">";
|
||||
echo " <option>Newest to Oldest</option>";
|
||||
echo " <option>Oldest to Newest</option>";
|
||||
echo " <div class=\"pure-u-1\">";
|
||||
echo " <label for=\"reporttype\">Report Type</label>";
|
||||
echo " <select name=\"reporttype\" class=\"pure-input-1-2\">";
|
||||
if (isset($_POST['reporttype'])) { echo "<option value=\"" . $_POST['reporttype'] . "\">" . $_POST['reporttype'] . "</option><option>----------</option>";}
|
||||
else { echo "<option></option>";}
|
||||
echo " <option value=\"Hours per week per user\">Hours per week per user</option>";
|
||||
echo " <option value=\"Hours per month per user\">Hours per month per user</option>";
|
||||
echo " </select>";
|
||||
echo " </div>";
|
||||
echo " </div>";
|
||||
@@ -35,18 +38,15 @@ echo " <button type=\"submit\" class=\"pure-button pure-button-primary\">
|
||||
echo " </fieldset>";
|
||||
echo "</form>";
|
||||
|
||||
|
||||
|
||||
// tag order to query depending on drop-down
|
||||
if ($_POST['order'] == "Newest to Oldest") {
|
||||
$order="ORDER BY punches.id DESC"; }
|
||||
else {
|
||||
$order="ORDER BY punches.id"; }
|
||||
|
||||
// actual query
|
||||
if (isset($_POST['reporttype'])) {
|
||||
if ($_POST['reporttype'] == "Hours per week per user") {
|
||||
$query = "SELECT
|
||||
YEAR(punches.intime) AS g_year,
|
||||
WEEK(punches.intime) AS g_week,
|
||||
SUM(TIME_TO_SEC(TIMEDIFF(punches.outtime, punches.intime))/3600) AS punchhours,
|
||||
punches.id as punchid,
|
||||
users.id as user,
|
||||
users.username as username,
|
||||
users.firstname as firstname,
|
||||
users.lastname as lastname,
|
||||
punches.intime as intime,
|
||||
@@ -54,34 +54,85 @@ $query = "SELECT
|
||||
punches.notes as notes,
|
||||
punches.modified as modified
|
||||
FROM punches
|
||||
INNER JOIN users ON punches.userid = users.id $order";
|
||||
|
||||
$stmt = $sql->prepare($query);
|
||||
INNER JOIN users ON punches.userid = users.id
|
||||
GROUP BY g_year, g_week, users.username;";
|
||||
$stmt = $sql->prepare($query);
|
||||
$stmt->execute();
|
||||
|
||||
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
//set up table header and open table
|
||||
echo '<table class="pure-table">';
|
||||
echo '<thead>';
|
||||
echo '<tr>';
|
||||
echo '<th>First Name</th>';
|
||||
echo '<th>Last Name</th>';
|
||||
echo '<th>Time In</th>';
|
||||
echo '<th>Time Out</th>';
|
||||
echo '<th>Year</th>';
|
||||
echo '<th>Week#</th>';
|
||||
echo '<th>Username</th>';
|
||||
echo '<th>Hours</th>';
|
||||
echo '<th>Flag</th>';
|
||||
echo '<th>Notes</th>';
|
||||
echo '</tr>';
|
||||
echo '</thead>';
|
||||
echo '<tbody>';
|
||||
|
||||
// $rows is an array containing all records...
|
||||
foreach ($rows as $row)
|
||||
echo "<tr><td>" . $row['firstname'] . "</td><td>" . $row['lastname'] . "</td><td>" . $row['intime'] . "</td><td>" . $row['outtime'] . "</td><td>" . $row['hours'] . "</td><td>" . $row['flag'] . "</td><td>" . $row['notes'] . "</td></tr>";
|
||||
|
||||
foreach ($rows as $row) {
|
||||
echo "<tr>";
|
||||
echo "<td>" . $row['g_year'] . "</td>";
|
||||
echo "<td>" . $row['g_week'] . "</td>";
|
||||
echo "<td>" . $row['username'] . "</td>";
|
||||
echo "<td>" . $row['punchhours'] . "</td>";
|
||||
echo "</tr>";
|
||||
}
|
||||
echo '</tbody>';
|
||||
echo '</table>';
|
||||
}
|
||||
elseif ($_POST['reporttype'] == "Hours per month per user") {
|
||||
$query = "SELECT
|
||||
YEAR(punches.intime) AS g_year,
|
||||
MONTH(punches.intime) AS g_month,
|
||||
SUM(TIME_TO_SEC(TIMEDIFF(punches.outtime, punches.intime))/3600) AS punchhours,
|
||||
punches.id as punchid,
|
||||
users.id as user,
|
||||
users.username as username,
|
||||
users.firstname as firstname,
|
||||
users.lastname as lastname,
|
||||
punches.intime as intime,
|
||||
punches.outtime as outtime,
|
||||
punches.notes as notes,
|
||||
punches.modified as modified
|
||||
FROM punches
|
||||
INNER JOIN users ON punches.userid = users.id
|
||||
GROUP BY g_year, g_month, users.username;";
|
||||
$stmt = $sql->prepare($query);
|
||||
$stmt->execute();
|
||||
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
//set up table header and open table
|
||||
echo '<table class="pure-table">';
|
||||
echo '<thead>';
|
||||
echo '<tr>';
|
||||
echo '<th>Year</th>';
|
||||
echo '<th>Month</th>';
|
||||
echo '<th>Username</th>';
|
||||
echo '<th>Hours</th>';
|
||||
echo '</tr>';
|
||||
echo '</thead>';
|
||||
echo '<tbody>';
|
||||
|
||||
// $rows is an array containing all records...
|
||||
foreach ($rows as $row) {
|
||||
echo "<tr>";
|
||||
echo "<td>" . $row['g_year'] . "</td>";
|
||||
echo "<td>" . $row['g_month'] . "</td>";
|
||||
echo "<td>" . $row['username'] . "</td>";
|
||||
echo "<td>" . $row['punchhours'] . "</td>";
|
||||
echo "</tr>";
|
||||
}
|
||||
echo '</tbody>';
|
||||
echo '</table>';
|
||||
}
|
||||
else {
|
||||
echo "no query";
|
||||
}
|
||||
} else { echo "no query"; }
|
||||
|
||||
//********** END CONTENT **********//
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user