Quellcode durchsuchen

Merge pull request #31 from advation/supervisorReview

Supervisor review
Adam vor 9 Jahren
Ursprung
Commit
08291a24ee

+ 31 - 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();
@@ -361,6 +364,7 @@ class reportsController extends Staple_Controller
         $this->view->span = $interval->days;
 
         $reports = new reportModel($year, $month);
+
         $this->view->report = $reports->payroll($year, $month);
         $this->view->startDate = $date->format("F jS Y");
         $days = $interval->days - 1;
@@ -509,4 +513,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))."");
+        }
+    }
 }

+ 21 - 0
application/models/calculateModel.php

@@ -49,4 +49,25 @@ class calculateModel extends Staple_Model
             return 0;
         }
     }
+
+    function calculatedCodeTotals($uid,$startDate,$endDate)
+    {
+        $codes = new codeModel();
+        $codes = $codes->allCodes();
+
+        $data = array();
+
+        foreach($codes as $codeKey=>$codeName)
+        {
+            $sql = "SELECT ROUND((TIME_TO_SEC(SEC_TO_TIME(SUM(outTime - inTime)-SUM(lessTime*60)))/3600)*4)/4 AS 'totalTime' FROM timeEntries WHERE inTime >= $startDate AND outTime <= $endDate AND userId = $uid AND codeId = $codeKey";
+
+            if($this->db->query($sql)->num_rows > 0)
+            {
+                $query = $this->db->query($sql);
+                $result = $query->fetch_assoc();
+                $data[$codeKey] = round($result['totalTime'],2);
+            }
+        }
+        return $data;
+    }
 }

+ 34 - 1
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;
             }
         }
 
@@ -302,6 +303,37 @@ class reportModel extends Staple_Model
         return $data;
     }
 
+    function payroll($year, $month)
+    {
+        $data = array();
+
+        $users = new userModel();
+        $accounts = $users->listAll();
+
+        $date = new DateTime();
+        $date->setTime(0,0,0);
+        $date->setDate($year,$month,26);
+        $date->modify('-1 month');
+        $startDate = $date->format('U');
+        $endDate = $date->modify('+1 month -1 day')->setTime(23,59,59)->format('U');
+
+        $i=0;
+        foreach($accounts as $account)
+        {
+            $data[$i]['userInfo'] = $account;
+
+            $timeCalulation = new calculateModel();
+            $time = $timeCalulation->calculatedCodeTotals($data[$i]['userInfo']['id'],$startDate,$endDate);
+
+            $data[$i]['totals'] = $time;
+
+            $i++;
+        }
+
+        return $data;
+    }
+
+    /*
     function payroll($year, $month)
     {
         $users = new userModel();
@@ -325,7 +357,7 @@ class reportModel extends Staple_Model
             $userId = $account['id'];
             $userName = $account['lastName'] . ", " . $account['firstName'];
             $sql = "
-                SELECT * FROM timeEntries WHERE inTime >= '" . $this->db->real_escape_string($startDate) . "' AND inTime <= '" . $this->db->real_escape_string($endDate) . "' AND userId = '" . $this->db->real_escape_string($userId) . "' ORDER BY inTime ASC;
+                SELECT * FROM timeEntries WHERE inTime >= '" . $this->db->real_escape_string($startDate) . "' AND inTime <= '" . $this->db->real_escape_string($endDate) . "' AND userId = '" . $this->db->real_escape_string($userId) . "';
             ";
 
             $query = $this->db->query($sql);
@@ -354,4 +386,5 @@ class reportModel extends Staple_Model
         }
         return $data;
     }
+    */
 }

+ 118 - 21
application/models/reviewModel.php

@@ -3,27 +3,13 @@ class reviewModel extends Staple_Model
 {
     private $db;
 
-    private $id;
     private $accountId;
     private $payPeriodMonth;
     private $payPeriodYear;
     private $supervisorId;
-
-    /**
-     * @return mixed
-     */
-    public function getId()
-    {
-        return $this->id;
-    }
-
-    /**
-     * @param mixed $id
-     */
-    public function setId($id)
-    {
-        $this->id = $id;
-    }
+    private $supervisorFirstName;
+    private $supervisorLastName;
+    private $reviewDate;
 
     /**
      * @return mixed
@@ -89,11 +75,122 @@ class reviewModel extends Staple_Model
         $this->supervisorId = $supervisorId;
     }
 
-    function __construct($year, $month, $uid)
+    /**
+     * @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."';";
 
-        echo $uid;
+        if($this->db->query($sql))
+        {
+            return true;
+        }
     }
-}
-?>
+}

+ 74 - 66
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)
@@ -192,13 +194,19 @@
                 </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>";
-                    echo "
-                    <div class='row'>
-                        <div class='small-12 columns text-center'>";
-                    echo "<a class='button radius' href=\"\">Mark as reviewed</a>";
-                    echo"</div>
-                    </div>";
 
                 }
                 else

+ 22 - 15
application/views/reports/payroll.phtml

@@ -65,9 +65,9 @@
                     <tr>
                        <th style="width:150px;"></th>
                        <?php
-                           foreach($this->codes as $code)
+                           foreach($this->codes as $codeKey=>$codeName)
                            {
-                                echo "<th>$code</th>";
+                                echo "<th>$codeName</th>";
                            }
                        ?>
                        <th>Total</th>
@@ -77,31 +77,38 @@
 
                     <?php
 
-                    foreach($this->report as $user=>$codes)
+                    foreach($this->report as $account)
                     {
 
                         echo "<tr>";
-                        echo "<td style='border-bottom:1px solid #ccc;'><b>$user</b></td>";
+                        echo "<td style='border-bottom:1px solid #ccc;'><b>".$account['userInfo']['lastName'].", ".$account['userInfo']['firstName']."</b></td>";
 
-                        $totals=0;
-                        foreach($this->codes as $id=>$timeCode)
+                        foreach($account['totals'] as $totals)
                         {
                             echo "<td class='text-center' style='border-bottom:1px solid #ccc;'>";
-                            $value = "-";
-                            foreach ($codes as $code => $total)
+                            if($totals == 0)
                             {
-                                if($timeCode == $code)
-                                {
-                                    $value = $total;
-                                    $totals = $totals + $total;
-                                }
+                                echo " - ";
                             }
-                            echo $value;
+                            else
+                            {
+                                echo $totals;
+                            }
+
                             echo "</td>";
                         }
-                        echo "<td class='text-center'><b>$totals</b></td>";
+
+                        $grandTotal = 0;
+                        foreach($account['totals'] as $total)
+                        {
+                            $grandTotal = $grandTotal + $total;
+                        }
+
+                        echo "<td class='text-center'><b>$grandTotal</b></td>";
                         echo "</tr>";
                     }
+
+
                     ?>
                     </tbody>
                 </table>

+ 19 - 13
application/views/reports/payrollprint.phtml

@@ -44,28 +44,34 @@
     <tbody>
     <?php
 
-    foreach($this->report as $user=>$codes)
+    foreach($this->report as $account)
     {
+
         echo "<tr>";
-        echo "<td style='border-bottom:1px solid #ccc;'><b>$user</b></td>";
+        echo "<td style='border-bottom:1px solid #ccc;'><b>".$account['userInfo']['lastName'].", ".$account['userInfo']['firstName']."</b></td>";
 
-        $totals=0;
-        foreach($this->codes as $id=>$timeCode)
+        foreach($account['totals'] as $totals)
         {
             echo "<td class='text-center' style='border-bottom:1px solid #ccc;'>";
-            $value = "-";
-            foreach ($codes as $code => $total)
+            if($totals == 0)
+            {
+                echo " - ";
+            }
+            else
             {
-                if($timeCode == $code)
-                {
-                    $value = $total;
-                    $totals = $totals + $total;
-                }
+                echo $totals;
             }
-            echo $value;
+
             echo "</td>";
         }
-        echo "<td class='text-center'><b>$totals</b></td>";
+
+        $grandTotal = 0;
+        foreach($account['totals'] as $total)
+        {
+            $grandTotal = $grandTotal + $total;
+        }
+
+        echo "<td class='text-center'><b>$grandTotal</b></td>";
         echo "</tr>";
     }
     ?>

+ 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>