소스 검색

Working on a monthly report that shows account daily totals.

Adam Day 9 년 전
부모
커밋
a218c3400a
4개의 변경된 파일183개의 추가작업 그리고 0개의 파일을 삭제
  1. 34 0
      application/controllers/reportsController.php
  2. 1 0
      application/layouts/main.phtml
  3. 54 0
      application/models/reportModel.php
  4. 94 0
      application/views/reports/payperiod.phtml

+ 34 - 0
application/controllers/reportsController.php

@@ -176,4 +176,38 @@ class reportsController extends Staple_Controller
         $this->view->timesheet = $timesheet;
 
     }
+
+    public function payperiod($year = null, $month = null)
+    {
+        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);
+        $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;
+
+        echo $date->format('Y-m-d');
+
+
+        $reports = new reportModel($year, $month);
+        $this->view->report = $reports->payPeriodTotals($year, $month);
+
+    }
 }

+ 1 - 0
application/layouts/main.phtml

@@ -71,6 +71,7 @@
                                     <li><a href=\"".$this->link(array('timesheet','admininsert'))."\" ><i class=\"fa fa-plus\" ></i > Admin Time Insert </a ></li >
                                     <li><a href=\"".$this->link(array('audit')) ."\" ><i class=\"fa fa-list-alt\" ></i > Audit Log</a ></li>
                                     <li><a href=\"".$this->link(array('reports','unlock'))."\"><i class=\"fa fa-unlock\"></i> Time Unlock</a></li>
+                                    <li><a href=\"".$this->link(array('reports','payperiod'))."\"><i class=\"fa fa-file\"></i> Pay Period Report</a></li>
                                 </ul>
                             </li>
                             ";

+ 54 - 0
application/models/reportModel.php

@@ -216,4 +216,58 @@ class reportModel extends Staple_Model
     {
 
     }
+
+    function payPeriodTotals($year, $month)
+    {
+        //Get all users
+        $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)."';
+            ";
+
+            $query = $this->db->query($sql);
+            $data2 = array();
+
+            $setDate = 0;
+            $timeWorked = 0;
+            while($result = $query->fetch_assoc())
+            {
+                $day = new DateTime();
+                $day->setTimestamp($result['inTime']);
+                $date = $day->format('Y-m-d');
+                $entry = $this->calculateEntry($result['id']);
+
+                if($date == $setDate)
+                {
+                    $timeWorked = $timeWorked + $entry['timeWorked'];
+                }
+                else
+                {
+                    $timeWorked = $entry['timeWorked'];
+                }
+
+                $data2[$date] = $timeWorked;
+                $setDate = $date;
+            }
+            $data[$userName] = $data2;
+        }
+        return $data;
+    }
 }

+ 94 - 0
application/views/reports/payperiod.phtml

@@ -0,0 +1,94 @@
+<div class="section">
+    <div class="row">
+        <div class="small-12 columns">
+            <h2><i class="fa fa-file"></i> Pay Period Report</h2>
+        </div>
+    </div>
+    <?php echo $this->spanDays ?>
+    <div class="row full">
+        <div class="small-12 columns full">
+            <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;
+                }
+
+            </style>
+            <table>
+                <thead>
+                <tr>
+                    <th style="width:150px;"></th>
+                    <?php
+
+                        $date3 = new DateTime();
+                        $date3->setDate($this->year,$this->previousMonth,26);
+                        for($i=1;$i<=$this->span;$i++)
+                        {
+                            if($date3->format('d') >= 26)
+                            {
+                                echo "<th style='background-color:#fff;border-bottom:1px solid #ccc; '>".$date3->format('D')."<br>".$date3->format('n')."/".$date3->format('j')."</th>";
+                            }
+                            else
+                            {
+                                echo "<th style='border-bottom:1px solid #ccc;'>".$date3->format('D')."<br>".$date3->format('n')."/".$date3->format('j')."</th>";
+                            }
+                            $date3->modify('+1 day');
+                        }
+                    ?>
+                </tr>
+                </thead>
+                <tbody>
+                <?php
+
+                    foreach($this->report as $user=>$dates)
+                    {
+                        echo "<tr>";
+                        echo "<td style='border-bottom:1px solid #ccc;'><b>$user</b></td>";
+
+                        $date = new DateTime();
+                        $date->setDate($this->year,$this->previousMonth,26);
+                        for($j=1;$j<=$this->span;$j++)
+                        {
+                            foreach ($dates as $entryDate => $total)
+                            {
+                                $newDate = explode("-", $entryDate);
+                                $dayOfMonth = $newDate[2];
+                                if($dayOfMonth == $date->format('d'))
+                                {
+                                    echo "<td class='text-center' style='border-bottom:1px solid #ccc;'>$total</td>";
+                                    $j++;
+                                }
+                            }
+
+                            echo "<td class='text-center'> - </td>";
+                            $date->modify('+1 day');
+                        }
+                        echo "</tr>";
+                    }
+
+
+                ?>
+                </tbody>
+            </table>
+        </div>
+    </div>
+
+</div>
+<pre>
+
+    <?php
+        print_r($this->report);
+    ?>
+
+</pre>