Browse Source

Completed the monthly payroll report that shows a users time code totals for the month.

Adam Day 9 years ago
parent
commit
b9b84ab2e2

+ 48 - 0
application/controllers/reportsController.php

@@ -277,5 +277,53 @@ class reportsController extends Staple_Controller
         $days = $interval->days - 1;
         $date->modify("+$days days");
         $this->view->endDate = $date->format("F jS Y");
+
+        $codes = new codeModel();
+        $this->view->codes = $codes->allCodes();
+    }
+
+    public function payrollprint($year = null, $month =  null)
+    {
+        if($year != null || $month != null) {
+            $this->_setLayout('print');
+            if ($year == null) {
+                $year = date('Y');
+            }
+
+            if ($month == null) {
+                $month = date('m');
+            }
+
+            $this->view->year = $year;
+
+            $date = new DateTime();
+            $date->setDate($year, $month, 26);
+            $date->setTime(0, 0, 0);
+            $this->view->month = $date->format('m');
+            $date->modify('-1 month');
+            $this->view->previousMonth = $date->format('m');
+
+            $date2 = new DateTime();
+            $date2->setDate($year, $month, 25);
+            $date2->setTime(24, 0, 0);
+
+            $interval = date_diff($date, $date2);
+
+            $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;
+            $date->modify("+$days days");
+            $this->view->endDate = $date->format("F jS Y");
+
+            $codes = new codeModel();
+            $this->view->codes = $codes->allCodes();
+        }
+        else
+        {
+            header("location:".$this->_link(array('reports','payroll'))."");
+        }
     }
 }

+ 43 - 0
application/models/reportModel.php

@@ -276,6 +276,49 @@ class reportModel extends Staple_Model
         $users = new userModel();
         $accounts = $users->listAll();
 
+        $data = array();
+
+        $date = new DateTime();
+        $date->setTime(0,0,0);
+        $date->setDate($year,$month,26);
+        $date->modify('-1 month');
+        $startDate = $date->format('U');
+        $date->modify('+1 month -1 day');
+        $date->setTime(23,59,59);
+        $endDate = $date->format('U');
+
+        foreach($accounts as $account)
+        {
+            $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;
+            ";
+
+            $query = $this->db->query($sql);
+            $data2 = array();
+
+            $setCode = 0;
+            $timeWorked = 0;
+            while($result = $query->fetch_assoc())
+            {
+                $entry = $this->calculateEntry($result['id']);
+                $code = $entry['code'];
+
+                if($code == $setCode)
+                {
+                    $timeWorked = $timeWorked + $entry['timeWorked'];
+                }
+                else
+                {
+                    $timeWorked = $entry['timeWorked'];
+                }
 
+                $data2[$code] = $timeWorked;
+                $setCode = $code;
+            }
+            $data[$userName] = $data2;
+        }
+        return $data;
     }
 }

+ 98 - 0
application/views/reports/payroll.phtml

@@ -0,0 +1,98 @@
+<div class="section">
+    <div class="row">
+        <div class="small-6 columns">
+            <h2><i class="fa fa-file"></i> Payroll Report</h2>
+        </div>
+        <div class="small-6 columns text-right">
+            <a class="button radius" target="_blank" href="<?php echo $this->link(array('reports','payrollprint',$this->year,$this->month)) ?>"><i class='fa fa-print'></i> Print</a>
+        </div>
+    </div>
+    <div class="row">
+        <div class="small-12 columns">
+            <style>
+                table {
+                    border:1px solid #ccc;
+                }
+
+                th {
+                    border:1px solid #ccc;
+                    padding:0px;
+                    margin:0px;
+                    background-color: #eaeaea;
+                }
+
+                td {
+                    border:1px solid #ccc;
+                    padding:0px;
+                    margin:0px;
+                }
+
+                .scroll {
+                    overflow-x:scroll;
+                    overflow-y:visible;
+                }
+
+            </style>
+            <div class="">
+                <table>
+                    <thead>
+                    <tr>
+                       <th style="width:150px;"></th>
+                       <?php
+
+                           foreach($this->codes as $code)
+                           {
+                               if($code == 'Normal')
+                               {
+                                   echo "<th style='background-color:#d8ffd3;'>$code</th>";
+                               }
+                               else
+                               {
+                                   echo "<th>$code</th>";
+                               }
+
+                           }
+
+                       ?>
+                    </tr>
+                    </thead>
+                    <tbody>
+                    <?php
+
+                    foreach($this->report as $user=>$codes)
+                    {
+
+                        echo "<tr>";
+                        echo "<td style='border-bottom:1px solid #ccc;'><b>$user</b></td>";
+
+                        //for($j=1;$j<=count($this->codes);$j++)
+                        foreach($this->codes as $id=>$timeCode)
+                        {
+                            if($timeCode == 'Normal')
+                            {
+                                echo "<td class='text-center' style='background-color:#d8ffd3; border-bottom:1px solid #ccc;'>";
+                            }
+                            else
+                            {
+                                echo "<td class='text-center' style='border-bottom:1px solid #ccc;'>";
+                            }
+                            $value = "-";
+                            foreach ($codes as $code => $total)
+                            {
+                                if($timeCode == $code)
+                                {
+                                    $value = $total;
+                                }
+                            }
+                            echo $value;
+                            echo "</td>";
+                        }
+                        echo "</tr>";
+                    }
+                    ?>
+                    </tbody>
+                </table>
+            </div>
+        </div>
+    </div>
+</div>

+ 89 - 0
application/views/reports/payrollprint.phtml

@@ -0,0 +1,89 @@
+
+<style>
+    table {
+        border:1px solid #ccc;
+    }
+
+    th {
+        border:1px solid #ccc;
+        padding:0px;
+        margin:0px;
+        background-color: #eaeaea;
+    }
+
+    td {
+        border:1px solid #ccc;
+        padding:0px;
+        margin:0px;
+    }
+
+    .scroll {
+        overflow-x:scroll;
+        overflow-y:visible;
+    }
+
+</style>
+<table width="100%" style="border:0px; padding:0px; margin:0px;">
+    <tr>
+        <td style="border:0px;"><h3><i class="fa fa-clock-o"></i> Payroll Report: <?php echo date("F",$this->month) ?> <?php echo $this->year ?></h3></td>
+        <td style="border:0px;" class="text-right"><?php echo $this->startDate ?> - <?php echo $this->endDate ?></td>
+    </tr>
+</table>
+<table width="100%">
+    <thead>
+    <tr>
+       <th style="width:150px;"></th>
+       <?php
+
+           foreach($this->codes as $code)
+           {
+               if($code == 'Normal')
+               {
+                   echo "<th style='background-color:#d8ffd3;'>$code</th>";
+               }
+               else
+               {
+                   echo "<th>$code</th>";
+               }
+
+           }
+
+       ?>
+    </tr>
+    </thead>
+    <tbody>
+    <?php
+
+    foreach($this->report as $user=>$codes)
+    {
+
+        echo "<tr>";
+        echo "<td style='border-bottom:1px solid #ccc;'><b>$user</b></td>";
+
+        //for($j=1;$j<=count($this->codes);$j++)
+        foreach($this->codes as $id=>$timeCode)
+        {
+            if($timeCode == 'Normal')
+            {
+                echo "<td class='text-center' style='background-color:#d8ffd3; border-bottom:1px solid #ccc;'>";
+            }
+            else
+            {
+                echo "<td class='text-center' style='border-bottom:1px solid #ccc;'>";
+            }
+            $value = "-";
+            foreach ($codes as $code => $total)
+            {
+                if($timeCode == $code)
+                {
+                    $value = $total;
+                }
+            }
+            echo $value;
+            echo "</td>";
+        }
+        echo "</tr>";
+    }
+    ?>
+    </tbody>
+</table>