Эх сурвалжийг харах

Created a report for viewing staff time sheets for the current pay period.

Adam Day 9 жил өмнө
parent
commit
86a5812fe2

+ 2 - 1
application/controllers/reportsController.php

@@ -26,7 +26,8 @@ class reportsController extends Staple_Controller
             $month = date('m');
         }
 
-        $report = new reportModel($year,$month);
+        $report = new reportModel($year, $month);
+        $this->view->report = $report->getTimesheets();
 
     }
 }

+ 28 - 6
application/models/reportModel.php

@@ -4,6 +4,22 @@ 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();
@@ -16,10 +32,6 @@ class reportModel extends Staple_Model
             $data[$value] = $this->getTimesheet($key, $year, $month);
         }
 
-        echo "<pre>";
-        print_r($data);
-        echo "</pre>";
-
         $this->timesheets = $data;
     }
 
@@ -91,8 +103,6 @@ class reportModel extends Staple_Model
         $query = $this->db->query($sql);
         $result = $query->fetch_assoc();
 
-        print_r($result);
-
         //Set inTime
         $inTime = new DateTime();
         $inTime->setTimestamp($result['inTime']);
@@ -157,6 +167,18 @@ class reportModel extends Staple_Model
         $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;
     }
 

+ 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)."'";
 

+ 12 - 12
application/models/userModel.php

@@ -158,21 +158,13 @@
 			$this->pin = $pin;
 		}
 
-		function __construct($user = null)
+		function __construct()
 		{
 			$this->db = Staple_DB::get();
-
-			if($user == null)
-			{
-				$auth = Staple_Auth::get();
-				$username = $auth->getAuthId();
-			}
-			else
-			{
-				$username = $user;
-			}
-
+			$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)."'";
+
 			if($this->db->query($sql)->fetch_row() > 0)
 			{
 				$query = $this->db->query($sql);
@@ -191,5 +183,13 @@
 				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;
+		}
 	}
 ?>

+ 158 - 1
application/views/reports/index.phtml

@@ -5,6 +5,163 @@
         </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>
+</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>

Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 0 - 0
public/style/app.css


Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 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;

Энэ ялгаанд хэт олон файл өөрчлөгдсөн тул зарим файлыг харуулаагүй болно