Просмотр исходного кода

Added print view for pay period report.

Adam Day 9 лет назад
Родитель
Сommit
5c47140cc5

+ 36 - 1
application/controllers/reportsController.php

@@ -186,12 +186,12 @@ class reportsController extends Staple_Controller
         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');
 
@@ -206,4 +206,39 @@ class reportsController extends Staple_Controller
         $reports = new reportModel($year, $month);
         $this->view->report = $reports->payPeriodTotals($year, $month);
     }
+
+    public function payperiodprint($year, $month)
+    {
+        if($year != null || $month != null)
+        {
+            $this->_setLayout('print');
+            $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->payPeriodTotals($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");
+        }
+        else
+        {
+            header("location:".$this->_link(array('reports','payperiod'))."");
+        }
+    }
 }

+ 7 - 1
application/layouts/main.phtml

@@ -71,7 +71,13 @@
                                     <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>
+                            <li class=\"has-dropdown\">
+                                <a href=\"#\"><i class='fa fa-file'></i> Reports</a>
+                                <ul class=\"dropdown\">
+                                    <li><a href=\"".$this->link(array('reports','payroll'))."\"><i class=\"fa fa-usd\"></i> Payroll Report</a></li>
+                                    <li><a href=\"".$this->link(array('reports','payperiod'))."\"><i class=\"fa fa-clock-o\"></i> Pay Period Report</a></li>
                                 </ul>
                             </li>
                             ";

+ 5 - 3
application/views/reports/payperiod.phtml

@@ -1,12 +1,14 @@
 <div class="section">
     <div class="row">
-        <div class="small-12 columns">
+        <div class="small-6 columns">
             <h2><i class="fa fa-file"></i> Pay Period Report</h2>
         </div>
+        <div class="small-6 columns text-right">
+            <a class="button radius" target="_blank" href="<?php echo $this->link(array('reports','payperiodprint',$this->year,$this->month)) ?>"><i class='fa fa-print'></i> Print</a>
+        </div>
     </div>
-    <?php echo $this->spanDays ?>
     <div class="row">
-        <div class="small-12 columns full">
+        <div class="small-12 columns">
             <style>
                 table {
                     border:1px solid #ccc;

+ 84 - 0
application/views/reports/payperiodprint.phtml

@@ -0,0 +1,84 @@
+<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 width="100%" style="border:0px; padding:0px; margin:0px;">
+    <tr>
+        <td style="border:0px;"><h3><i class="fa fa-clock-o"></i> Total Hours: <?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></th>
+        <?php
+
+        $date = new DateTime();
+        $date->setDate($this->year,$this->previousMonth,26);
+
+        for($i=1;$i<=$this->span;$i++)
+        {
+            if($date->format('d') >= 26)
+            {
+                echo "<th style='background-color:#fff;border-bottom:1px solid #ccc; '>".$date->format('D')."<br>".$date->format('n')."/".$date->format('j')."</th>";
+            }
+            else
+            {
+                echo "<th style='border-bottom:1px solid #ccc;'>".$date->format('D')."<br>".$date->format('n')."/".$date->format('j')."</th>";
+            }
+            $date->modify('+1 day');
+        }
+        ?>
+    </tr>
+    </thead>
+    <tbody>
+    <?php
+
+    foreach($this->report as $user=>$dates)
+    {
+        $totalTime = array_sum($dates);
+        echo "<tr>";
+        echo "<td style='border-bottom:1px solid #ccc;'><b>$user</b><br>Total: $totalTime</td>";
+
+        $date = new DateTime();
+        $date->setDate($this->year,$this->previousMonth,26);
+        for($j=1;$j<=$this->span;$j++)
+        {
+            echo "<td class='text-center' style='border-bottom:1px solid #ccc;'>";
+            $value = "-";
+            foreach ($dates as $entryDate => $total)
+            {
+                $newDate = explode("-", $entryDate);
+                $dayOfMonth = $newDate[2];
+
+                if($dayOfMonth == $date->format('d'))
+                {
+                    $value = $total;
+                }
+            }
+            echo $value;
+            echo "</td>";
+
+            $date->modify('+1 day');
+        }
+        echo "</tr>";
+    }
+    ?>
+    </tbody>
+</table>