Bläddra i källkod

Corrected a few reporting issues with the Monthly report, daily report, and edit time entry function.

Adam Day 9 år sedan
förälder
incheckning
074279c9e6

+ 1 - 0
application/controllers/reportsController.php

@@ -364,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;

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

+ 33 - 1
application/models/reportModel.php

@@ -303,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();
@@ -326,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);
@@ -355,4 +386,5 @@ class reportModel extends Staple_Model
         }
         return $data;
     }
+    */
 }

+ 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>";
     }
     ?>