Ver Fonte

Added the ability for supervisor and administrator accounts to make individual timesheets as reviewed.

Adam Day há 9 anos atrás
pai
commit
e434cf1ea1

+ 30 - 0
application/controllers/reportsController.php

@@ -69,6 +69,9 @@ class reportsController extends Staple_Controller
         $report = new reportModel($year, $month);
         $this->view->report = $report->getTimesheets();
 
+        $reviewed = new reviewModel();
+        $this->view->reviewed = $reviewed->load($year, $month);
+
         $this->view->accountLevel = $this->authLevel;
 
         $date = new DateTime();
@@ -490,4 +493,31 @@ class reportsController extends Staple_Controller
             $this->view->printTimeSheetForm = $printInactiveTimeSheetForm;
         }
     }
+
+    public function reviewed($userId = null, $year = null, $month = null)
+    {
+        if($userId != null || $year != null || $month != null)
+        {
+            $review = new reviewModel();
+
+            $review->setAccountId($userId);
+            $review->setPayPeriodMonth($month);
+            $review->setPayPeriodYear($year);
+
+            if($review->save())
+            {
+                header("location: ".$this->_link(array('reports',$year,$month,$userId))."");
+            }
+            else
+            {
+                $this->view->year = $year;
+                $this->view->month = $month;
+                $this->view->errorMessage = "Entry already marked as reviewed.";
+            }
+        }
+        else
+        {
+            header("location: ".$this->_link(array('reports',$year,$month,$userId))."");
+        }
+    }
 }

+ 1 - 0
application/models/reportModel.php

@@ -40,6 +40,7 @@ class reportModel extends Staple_Model
             foreach($staffIds as $key => $value)
             {
                 $data[$value] = $this->getTimesheet($key, $year, $month);
+                $data[$value]['id'] = $key;
             }
         }
 

+ 196 - 0
application/models/reviewModel.php

@@ -0,0 +1,196 @@
+<?php
+class reviewModel extends Staple_Model
+{
+    private $db;
+
+    private $accountId;
+    private $payPeriodMonth;
+    private $payPeriodYear;
+    private $supervisorId;
+    private $supervisorFirstName;
+    private $supervisorLastName;
+    private $reviewDate;
+
+    /**
+     * @return mixed
+     */
+    public function getAccountId()
+    {
+        return $this->accountId;
+    }
+
+    /**
+     * @param mixed $accountId
+     */
+    public function setAccountId($accountId)
+    {
+        $this->accountId = $accountId;
+    }
+
+    /**
+     * @return mixed
+     */
+    public function getPayPeriodMonth()
+    {
+        return $this->payPeriodMonth;
+    }
+
+    /**
+     * @param mixed $payPeriodMonth
+     */
+    public function setPayPeriodMonth($payPeriodMonth)
+    {
+        $this->payPeriodMonth = $payPeriodMonth;
+    }
+
+    /**
+     * @return mixed
+     */
+    public function getPayPeriodYear()
+    {
+        return $this->payPeriodYear;
+    }
+
+    /**
+     * @param mixed $payPeriodYear
+     */
+    public function setPayPeriodYear($payPeriodYear)
+    {
+        $this->payPeriodYear = $payPeriodYear;
+    }
+
+    /**
+     * @return mixed
+     */
+    public function getSupervisorId()
+    {
+        return $this->supervisorId;
+    }
+
+    /**
+     * @param mixed $supervisorId
+     */
+    public function setSupervisorId($supervisorId)
+    {
+        $this->supervisorId = $supervisorId;
+    }
+
+    /**
+     * @return mixed
+     */
+    public function getReviewDate()
+    {
+        return $this->reviewDate;
+    }
+
+    /**
+     * @param mixed $reviewDate
+     */
+    public function setReviewDate($reviewDate)
+    {
+        $this->reviewDate = $reviewDate;
+    }
+
+    /**
+     * @return mixed
+     */
+    public function getSupervisorFirstName()
+    {
+        return $this->supervisorFirstName;
+    }
+
+    /**
+     * @param mixed $supervisorFirstName
+     */
+    public function setSupervisorFirstName($supervisorFirstName)
+    {
+        $this->supervisorFirstName = $supervisorFirstName;
+    }
+
+    /**
+     * @return mixed
+     */
+    public function getSupervisorLastName()
+    {
+        return $this->supervisorLastName;
+    }
+
+    /**
+     * @param mixed $supervisorLastName
+     */
+    public function setSupervisorLastName($supervisorLastName)
+    {
+        $this->supervisorLastName = $supervisorLastName;
+    }
+
+    function __construct()
+    {
+        $this->db = Staple_DB::get();
+    }
+
+    function load($year, $month)
+    {
+        $data = array();
+        $sql = "SELECT * FROM timesheetReview WHERE payPeriodYear = '".$this->db->real_escape_string($year)."' AND payPeriodMonth = '".$this->db->real_escape_string($month)."'";
+
+        $query = $this->db->query($sql);
+
+        if($query->num_rows > 0)
+        {
+            while($result = $query->fetch_assoc())
+            {
+                $user = new userModel();
+                $account = $user->userInfo($result['accountId']);
+                $data[$account['lastName'].", ".$account['firstName']] = $result;
+
+                $user2 = new userModel();
+                $account2 = $user2->userInfo($result['supervisorId']);
+
+                $date = new DateTime();
+                $date->setTimestamp(strtotime($result['reviewDate']));
+                $data[$account['lastName'].", ".$account['firstName']]['reviewDateFormatted'] = $date->format('F jS Y');
+
+                $data[$account['lastName'].", ".$account['firstName']]['supervisor'] = $account2['firstName']." ".$account2['lastName'];
+            }
+        }
+        return $data;
+    }
+
+    function save()
+    {
+        if(isset($this->accountId) && isset($this->payPeriodYear) && isset($this->payPeriodMonth))
+        {
+            //Get current users ID.
+            $user = new userModel();
+            $supervisorId = $user->getId();
+
+            //Check if entry already exists
+            $sql = "
+                SELECT id FROM timesheetReview WHERE accountId = '".$this->db->real_escape_string($this->accountId)."' AND payPeriodMonth = '".$this->db->real_escape_string($this->payPeriodMonth)."' AND payPeriodYear = '".$this->db->real_escape_string($this->payPeriodYear)."';
+            ";
+
+            $result = $this->db->query($sql)->num_rows;
+            if($result == 0)
+            {
+                $sql = "
+                    INSERT INTO timesheetReview (accountId, payPeriodMonth, payPeriodYear, supervisorId) VALUES ('".$this->db->real_escape_string($this->accountId)."','".$this->db->real_escape_string($this->payPeriodMonth)."','".$this->db->real_escape_string($this->payPeriodYear)."','".$this->db->real_escape_string($supervisorId)."')
+                ";
+
+                if($this->db->query($sql))
+                {
+                    return true;
+                }
+            }
+        }
+    }
+
+    function remove($userId, $year, $month)
+    {
+        $sql = "DELETE FROM timesheetReview WHERE accountId = '".$userId."' AND  payPeriodMonth = '".$month."' AND payPeriodYear = '".$year."';";
+
+        if($this->db->query($sql))
+        {
+            return true;
+        }
+    }
+}

+ 74 - 60
application/views/reports/index.phtml

@@ -19,7 +19,7 @@
                     $year = $this->nextYear;
                 }
 
-                if($this->momth == 1)
+                if($this->month == 1)
                 {
                     $year = $this->previousYear;
                 }
@@ -62,10 +62,10 @@
     <div class="row">
         <div class="small-12 columns">
             <?php
-
             $i = 0;
             foreach($this->report as $user=>$timesheet)
             {
+                $userId = $timesheet['id'];
                 echo "<h3 id='user'.$i.'' class='timeTitle'>$user <i class='fa fa-chevron-down right'></i></h3>";
                 echo "
         <div class=\"wrapper hide\">";
@@ -100,66 +100,68 @@
 
                 foreach($timesheet as $key=>$entry)
                 {
-                    echo "
-                        <tr>
-                               <td>".date("l, F jS Y",strtotime($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>".date("M. jS Y @ G:i A",strtotime($entry['timestamp']))."</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>";
-
-                    if($this->accountLevel >= 900)
-                    {
-                        echo "<td><a href=\"".$this->link(array('timesheet','remove',$key))."\"><i class=\"fa fa-trash\"></i> Remove</a></td>";
-                    }
-
-                    echo "</tr>";
-
-                    if(strlen($entry['note']) > 0)
-                    {
+                   if($key != 'id')
+                   {
                         echo "
                             <tr>
-                                <td colspan='9'>
-                                    <b>Note:</b> ".$entry['note']."
-                                </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'];
-                    }
-
+                                   <td>".date("l, F jS Y",strtotime($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>".date("M. jS Y @ G:i A",strtotime($entry['timestamp']))."</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>";
+
+                        if($this->accountLevel >= 900)
+                        {
+                            echo "<td><a href=\"".$this->link(array('timesheet','remove',$key))."\"><i class=\"fa fa-trash\"></i> Remove</a></td>";
+                        }
+
+                        echo "</tr>";
+
+                        if(strlen($entry['note']) > 0)
+                        {
+                            echo "
+                                <tr>
+                                    <td colspan='9'>
+                                        <b>Note:</b> ".$entry['note']."
+                                    </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)
@@ -198,6 +200,18 @@
                 </div>";
                 echo "</div>";
 
+                echo "<div class=\"small-12 columns text-center\">";
+
+                if(array_key_exists($user, $this->reviewed))
+                {
+                    echo "<h4><i class='fa fa-check'></i> Reviewed by <b>".$this->reviewed[$user]['supervisor']."</b> on ".$this->reviewed[$user]['reviewDateFormatted']."</h4>";
+                }
+                else
+                {
+                    echo "<a class='button radius' href='".$this->link(array('reports','reviewed',$userId,$this->year,$this->month))."'>Mark as reviewed</a>";
+                }
+
+                echo"</div>";
                 echo "</div>";
 
                 }

+ 20 - 0
application/views/reports/reviewed.phtml

@@ -0,0 +1,20 @@
+<div class="section">
+    <div class="row">
+        <div class="small-12 columns">
+            <h1><i class="fa fa-file"></i>Time Sheet Review <small>Active</small></h1>
+        </div>
+    </div>
+    <div class="row">
+        <div class="small-12 columns">
+            <ul class="button-group radius right">
+                <li><a class='button secondary' href="<?php echo $this->link(array('reports',$this->year,$this->month)) ?>">Back</a></li>
+            </ul>
+        </div>
+        <div class="small-12 columns text-center">
+            <div data-alert class="alert-box alert">
+                <i class="fa fa-warning"></i> <?php echo $this->errorMessage ?>
+                <a href="#" class="close">&times;</a>
+            </div>
+        </div>
+    </div>
+</div>