Browse Source

Merge pull request #17 from advation/staff

Staff
Adam 9 years ago
parent
commit
b1c216d1d0

+ 15 - 3
application/controllers/reportsController.php

@@ -8,14 +8,26 @@ class reportsController extends Staple_Controller
     {
         $auth = Staple_Auth::get();
         $this->authLevel = $auth->getAuthLevel();
-        if($this->authLevel < 900)
+        if($this->authLevel < 500)
         {
             header("location:".$this->_link(array('index','index'))."");
         }
     }
 
-    public function index()
+    public function index($year = null, $month = null)
     {
-        echo "Reports";
+        if($year == null)
+        {
+            $year = date('Y');
+        }
+
+        if($month == null)
+        {
+            $month = date('m');
+        }
+
+        $report = new reportModel($year, $month);
+        $this->view->report = $report->getTimesheets();
+
     }
 }

+ 210 - 0
application/models/reportModel.php

@@ -0,0 +1,210 @@
+<?php
+class reportModel extends Staple_Model
+{
+    private $db;
+    private $timesheets;
+
+    /**
+     * @return array
+     */
+    public function getTimesheets()
+    {
+        return $this->timesheets;
+    }
+
+    /**
+     * @param array $timesheets
+     */
+    public function setTimesheets($timesheets)
+    {
+        $this->timesheets = $timesheets;
+    }
+
+    function __construct($year, $month)
+    {
+        $this->db = Staple_DB::get();
+        $staffIds = $this->getStaffIds();
+
+        $data = array();
+
+        foreach($staffIds as $key => $value)
+        {
+            $data[$value] = $this->getTimesheet($key, $year, $month);
+        }
+
+        $this->timesheets = $data;
+    }
+
+    function getStaffIds()
+    {
+        $auth = Staple_Auth::get();
+        $user = new userModel($auth->getAuthId());
+        $userId = $user->getId();
+        $authLevel = $user->getAuthLevel();
+
+        if($authLevel >= 900)
+        {
+            $sql = "
+            SELECT id, firstName, lastName FROM accounts WHERE 1 ORDER BY lastName ASC
+            ";
+        }
+        else
+        {
+            $sql = "
+            SELECT id, firstName, lastName FROM accounts WHERE supervisorId = '".$this->db->real_escape_string($userId)."' ORDER BY lastName ASC
+            ";
+        }
+
+        $query = $this->db->query($sql);
+
+        while($result = $query->fetch_assoc())
+        {
+            $data[$result['id']] = $result['lastName'].", ".$result['firstName'];
+        }
+        return $data;
+    }
+
+    function getTimesheet($userId, $year, $month)
+    {
+
+        $currentDate = new DateTime();
+        $currentDate->setDate($year, $month, 1);
+
+        $currentYear = $currentDate->format('Y');
+        $currentMonth = $currentDate->format('m');
+        $currentMonthText = $currentDate->format('F');
+        $startDate = $currentDate->modify('-1 month +25 day')->format('Y-m-d');
+        $startDateTimeString = strtotime($startDate);
+        $currentDate->setDate($year, $month, 1);
+        $endDate = $currentDate->modify('+25 day')->format('Y-m-d');
+        $endDateTimeString = strtotime($endDate);
+
+        $sql = "
+            SELECT id FROM timeEntries WHERE inTime > $startDateTimeString AND inTime < $endDateTimeString AND userId = $userId ORDER BY inTime ASC;
+        ";
+
+        $data = array();
+
+        $query = $this->db->query($sql);
+
+        while($result = $query->fetch_assoc())
+        {
+            $data[] = $this->calculateEntry($result['id']);
+        }
+        return $data;
+    }
+
+    function calculateEntry($id)
+    {
+        $sql = "
+            SELECT * FROM timeEntries WHERE id = '".$this->db->real_escape_string($id)."';
+        ";
+
+        $query = $this->db->query($sql);
+        $result = $query->fetch_assoc();
+
+        //Set inTime
+        $inTime = new DateTime();
+        $inTime->setTimestamp($result['inTime']);
+        $roundedInTime = $this->nearestQuarterHour($result['inTime']);
+        $inTimeRaw = $result['inTime'];
+        $inTimeDate = date("Y-m-d", $result['inTime']);
+
+        //Out Time
+        $outTime = new DateTime();
+        $outTime->setTimestamp($result['outTime']);
+        $roundedOutTime = $this->nearestQuarterHour($result['outTime']);
+        $outTimeRaw = $result['outTime'];
+        $roundedOutTime = $this->nearestQuarterHour($result['outTime']);
+        $outTimeDate = date("Y-m-d", $result['outTime']);
+
+        $lessTime = $result['lessTime'];
+
+        //Calculate Time Worked
+        switch($result['lessTime'])
+        {
+            case 60:
+                $lessTime = 1;
+                break;
+            case 30:
+                $lessTime = 0.5;
+                break;
+            case 15:
+                $lessTime = 0.25;
+                break;
+            default:
+                $lessTime = 0;
+        }
+
+        //Total Worked Time
+        $dateTime1 = new DateTime($roundedInTime);
+        $dateTime1->setDate(date('Y',strtotime($inTimeDate)), date('m',strtotime($inTimeDate)), date('d',strtotime($inTimeDate)));
+        $dateTime2 = new DateTime($roundedOutTime);
+        $dateTime2->setDate(date('Y',strtotime($outTimeDate)), date('m',strtotime($outTimeDate)), date('d',strtotime($outTimeDate)));
+        $interval = $dateTime1->diff($dateTime2);
+
+        $timeWorked = $this->timeToDecimal($interval->h.":".$interval->i)-$lessTime;
+
+        if($timeWorked !== 0)
+        {
+            $timeWorked = $timeWorked;
+        }
+        else
+        {
+            $timeWorked = 0;
+        }
+
+        //Get Code Information
+        $code = new codeModel();
+        $codeId = $result['codeId'];
+        $code->load($result['codeId']);
+        $codeName = $code->getName();
+
+        $data['date'] = date('Y-m-d', $inTimeRaw);
+        $data['inTime'] = $inTimeRaw;
+        $data['outTime'] = $outTimeRaw;
+        $data['lessTime'] = $lessTime;
+        $data['timeWorked'] = $timeWorked;
+        $data['code'] = $codeName;
+
+        //Get the user of the entry.
+        $entry = new timeEntryModel($id);
+
+        if($entry->validated($id,$result['userId']))
+        {
+            $data['validated'] = 0;
+        }
+        else
+        {
+            $data['validated'] = 1;
+        }
+
+        return $data;
+    }
+
+    function nearestQuarterHour($time)
+    {
+        //$time = strtotime($time);
+        $round = 15*60;
+        $rounded = round($time/$round)*$round;
+
+        return date("g:i A", $rounded);
+    }
+
+    function timeToDecimal($time)
+    {
+        $timeArr = explode(':', $time);
+        $hours = $timeArr[0]*1;
+        $minutes = $timeArr[1]/60;
+        $dec = $hours + $minutes;
+
+        if($dec > 0)
+        {
+            return round($dec,2);
+        }
+        else
+        {
+            return 0;
+        }
+    }
+}

+ 15 - 6
application/models/timeEntryModel.php

@@ -547,13 +547,22 @@
             }
         }
 
-        function _validated($id)
+        function validated($id,$uid = null)
         {
-            $auth = Staple_Auth::get();
-            $user = new userModel($auth->getAuthId());
-
-            $userId = $user->getId();
-            $batchId = $user->getBatchId();
+            if($uid == null)
+            {
+                $auth = Staple_Auth::get();
+                $user = new userModel($auth->getAuthId());
+                $userId = $user->getId();
+                $batchId = $user->getBatchId();
+            }
+            else
+            {
+                $user = new userModel();
+                $info = $user->userInfo($uid);
+                $userId = $info['id'];
+                $batchId = $info['batchId'];
+            }
 
             $sql = "SELECT id FROM timeEntries WHERE userId = '".$this->db->real_escape_string($userId)."' AND batchId = '".$this->db->real_escape_string($batchId)."' AND id = '".$this->db->real_escape_string($id)."'";
 

+ 11 - 4
application/models/timesheetModel.php

@@ -282,13 +282,20 @@
 			$this->totals = $totals;
 		}
 
-		function __construct($year, $month)
+		function __construct($year, $month, $user = null)
 		{
 			$this->db = Staple_DB::get();
 
-			//Get batchID
-			$user = new userModel();
-			$this->batch = $user->getBatchId();
+			if($user == null)
+			{
+				//Get batchID
+				$user = new userModel();
+				$this->batch = $user->getBatchId();
+			}
+			else
+			{
+				$user = new userModel($user);
+			}
 
 			//Current Dates
 			$currentDate = new DateTime();

+ 10 - 2
application/models/userModel.php

@@ -161,11 +161,10 @@
 		function __construct()
 		{
 			$this->db = Staple_DB::get();
-
 			$auth = Staple_Auth::get();
 			$username = $auth->getAuthId();
+			$sql = "SELECT id, username, firstName, lastName, authLevel, batchId, supervisorId FROM accounts WHERE username = '".$this->db->real_escape_string($username)."'";
 
-			$sql = "SELECT id, username, firstName, lastName, authLevel, batchId FROM accounts WHERE username = '".$this->db->real_escape_string($username)."'";
 			if($this->db->query($sql)->fetch_row() > 0)
 			{
 				$query = $this->db->query($sql);
@@ -177,11 +176,20 @@
 				$this->setLastName($result['lastName']);
 				$this->setAuthLevel($result['authLevel']);
 				$this->setBatchId($result['batchId']);
+				$this->setSupervisorId($result['supervisorId']);
 			}
 			else
 			{
 				return false;
 			}
 		}
+
+		function userInfo($id)
+		{
+			$sql = "SELECT id, username, firstName, lastName, authLevel, batchId, supervisorId FROM accounts WHERE id = '".$this->db->real_escape_string($id)."'";
+			$query = $this->db->query($sql);
+			$result = $query->fetch_assoc();
+			return $result;
+		}
 	}
 ?>

+ 167 - 0
application/views/reports/index.phtml

@@ -0,0 +1,167 @@
+<div class="section">
+    <div class="row">
+        <div class="small-12 columns text-center">
+            <h1><i class="fa fa-file"></i> Reports</h1>
+        </div>
+    </div>
+    <div class="row">
+        <div class="small-12 columns">
+            <ul class="button-group round right">
+                <li><a id="showAll" class="button small secondary" href="#"><i class="fa fa-eye"></i> Show All</a></li>
+                <li><a id="hideAll" class="button small secondary" href="#"><i class="fa fa-eye-slash"></i> Hide All</a></li>
+            </ul>
+        </div>
+    </div>
+    <div class="row">
+        <div class="small-12 columns">
+            <?php
+
+            $i = 0;
+            foreach($this->report as $user=>$timesheet)
+            {
+                echo "
+                    <h3 id='user'.$i.'' class='timeTitle'>$user <i class='fa fa-chevron-up right'></i></h3>
+                ";
+
+                echo "
+        <div class=\"wrapper\">";
+
+                if(count($timesheet) > 0)
+                {
+                    echo"
+                    <table width='100%'>
+                        <thead>
+                        <tr>
+                            <th>Date</th>
+                            <th>In Time</th>
+                            <th>Out Time</th>
+                            <th>Less Worked</th>
+                            <th>Total Worked</th>
+                            <th>Time Code</th>
+                            <th>Validated</th>
+                        </tr>
+                        </thead>
+                    ";
+                }
+
+                $totalValidated = 0;
+                $totalInvalid = 0;
+                $totalVacation = 0;
+                $totalSick = 0;
+
+                foreach($timesheet as $entry)
+                {
+                    echo "
+                        <tr>
+                               <td>".$entry['date']."</td>
+                               <td>".date("g:i A",$entry['inTime'])."</td>
+                               <td>".date("g:i A",$entry['outTime'])."</td>
+                               <td>".$entry['lessTime']." <small>Hours</small></td>
+                               <td>".$entry['timeWorked']."</td>
+                               <td>".$entry['code']."</td><td><div class='text-center'>";
+
+                    if($entry['validated'] == 1)
+                    {
+                        echo "<i class=\"fa fa-check green\"></i>";
+                    }
+                    else
+                    {
+                        echo "<i class=\"fa fa-close red\"></i>";
+                    }
+
+                    echo "</td>
+                        </tr>
+                    ";
+
+                    if($entry['validated'] == 1)
+                    {
+                        $totalValidated += $entry['timeWorked'];
+                    }
+
+                    if($entry['validated'] == 0)
+                    {
+                        $totalInvalid += $entry['timeWorked'];
+                    }
+
+                    if($entry['code'] == "Vacation")
+                    {
+                        $totalVacation += $entry['timeWorked'];
+                    }
+
+                    if($entry['code'] == "Sick")
+                    {
+                        $totalSick += $entry['timeWorked'];
+                    }
+
+                }
+
+                if(count($timesheet) > 0) {
+                    echo "</table>";
+
+
+                echo "<div class=\"row\">";
+                echo "<div class=\"small-6 medium-4 large-3 columns\">";
+                                        echo "<div class=\"card success\">
+                                            <div class=\"title\">Validated</div>
+                                            <div class=\"value\">".$totalValidated." <small>Hours</small></div>
+                                        </div>";
+                echo "</div>";
+                echo "<div class=\"small-6 medium-4 large-3 columns\">";
+                                        echo "<div class=\"card warning\">
+                                            <div class=\"title\">Not Validated</div>
+                                            <div class=\"value\">".$totalInvalid." <small>Hours</small></div>
+                                        </div>";
+                echo "</div>";
+                echo "<div class=\"small-6 medium-4 large-3 columns end\">";
+                                     echo "<div class=\"card\">
+                                            <div class=\"title\">Sick</div>
+                                            <div class=\"value\">".$totalSick." <small>Hours</small></div>
+                                        </div>";
+                echo "</div>";
+                echo "<div class=\"small-6 medium-4 large-3 columns end\">";
+                                        echo "<div class=\"card\">
+                                            <div class=\"title\">Vacation</div>
+                                            <div class=\"value\">".$totalVacation." <small>Hours</small></div>
+                                        </div>";
+                echo "</div>";
+                echo "</div>";
+
+                }
+                else
+                {
+                    echo "<div class=\"text-center\">No time submitted</div>";
+                }
+
+                $i++;
+                echo "</div><hr>";
+            }
+            ?>
+        </div>
+    </div>
+</div>
+
+<script>
+    $(function() {
+
+        $(".timeTitle").click(function() {
+            $(this).next(".wrapper").slideToggle("slow");
+            $(this).find("i").toggleClass("fa-chevron-up fa-chevron-down")
+            return false;
+        });
+
+        $("#hideAll").click(function() {
+            $(".wrapper").slideUp();
+            $(".timeTitle").find("i").removeClass("fa-chevron-up")
+            $(".timeTitle").find("i").addClass("fa-chevron-down")
+            return false;
+        });
+
+        $("#showAll").click(function() {
+            $(".wrapper").slideDown();
+            $(".timeTitle").find("i").removeClass("fa-chevron-down")
+            $(".timeTitle").find("i").addClass("fa-chevron-up")
+            return false;
+        });
+
+    });
+</script>

File diff suppressed because it is too large
+ 0 - 0
public/style/app.css


File diff suppressed because it is too large
+ 0 - 0
public/style/app.css.map


+ 22 - 5
public/timetrackerStyle/scss/_settings.scss

@@ -135,6 +135,10 @@ $primary-color: #315476;
   color:$warning-color !important;
 }
 
+.red {
+  color:$alert-color !important;
+}
+
 .keyButton {
   font-size:1.5em !important;
   margin:0px !important;
@@ -152,6 +156,7 @@ $primary-color: #315476;
 .warning {
   background-color:$warning-color !important;
   color:#fff !important;
+  border:1px #ff6500 solid !important;
 }
 
 .alert {
@@ -159,6 +164,12 @@ $primary-color: #315476;
   color:#fff !important;
 }
 
+.success {
+  background-color:$success-color !important;
+  color:#fff !important;
+  border:1px #009b00 solid !important;
+}
+
 .warning h2 {
   color:#fff !important;
 }
@@ -210,22 +221,28 @@ $primary-color: #315476;
 }
 
 .card {
-  border:1px solid #eaeaea;
-  margin:0px;
+  border:1px solid #ccc;
   padding:20px;
+  margin-bottom:20px;
+  background-color: #f5f5f5;
+  border-radius:5px;
 }
 
 .card .title {
   text-align:center;
-  font-size:1.5em;
-  text-transform: uppercase;
+  font-size:1.3em;
 }
 
 .card .value {
   text-align:center;
-  font-size:3.0em;
+  font-size:2.5em;
 }
 
+.wrapper {
+  border:1px #eaeaea solid;
+  background-color: #fafafa;
+  padding:20px;
+}
 // We use these to control various global styles
 // $body-bg: $white;
 // $body-font-color: $jet;

Some files were not shown because too many files changed in this diff