Parcourir la source

Resolved the incorrect span of days calculation in the payperiod report.

Adam Day il y a 9 ans
Parent
commit
6b454236b4

+ 61 - 25
application/controllers/reportsController.php

@@ -27,24 +27,41 @@ class reportsController extends Staple_Controller
             $month = date('m');
         }
 
+        $date = new DateTime();
+        $date->setDate($year,$month,26);
+        $date->setTime(0,0,0);
+
+        $this->view->year = $date->format('Y');
+
+        $this->view->date = $date->format("F Y");
+
+        $date->modify('+1 year');
+        $this->view->nextYear = $date->format('Y');
+
+        $date->modify('-2 year');
+        $this->view->previousYear = $date->format('Y');
+
+        $date->modify('+1 year');
+
+        $month = $date->format('m');
+        $this->view->month = $month;
+
+        $date->modify('-1 month');
+        $this->view->previousMonth = $date->format('m');
+        $date->modify('+2 month');
+        $this->view->nextMonth = $date->format('m');
+
         $report = new reportModel($year, $month);
         $this->view->report = $report->getTimesheets();
 
-        $timesheet = new timesheetModel($year, $month);
-        $this->view->nextMonth = $timesheet->getNextMonth();
-        $this->view->previousMonth = $timesheet->getPreviousMonth();
-        $this->view->year = $timesheet->getCurrentYear();
-        $yearForm = new changeYearForm();
-        $yearForm->setAction($this->_link(array('reports','changeyear')));
-        $this->view->yearForm = $yearForm;
-
         $this->view->accountLevel = $this->authLevel;
 
         $date = new DateTime();
         $date->setDate($year, $month, 1);
-        $this->view->month = $date->format('F');
+        $this->view->monthName = $date->format('F');
 
         $printTimeSheetForm = new printTimeSheetForm();
+        $printTimeSheetForm->setAction($this->_link(array("reports",$year,$month)));
         if($printTimeSheetForm->wasSubmitted())
         {
             $printTimeSheetForm->addData($_POST);
@@ -171,10 +188,8 @@ class reportsController extends Staple_Controller
         $this->view->year = $year;
         $this->view->month = date('F',$month);
 
-
         $timesheet = new timesheetModel($year, $month,$uid);
         $this->view->timesheet = $timesheet;
-
     }
 
     public function payperiod($year = null, $month = null)
@@ -186,33 +201,54 @@ 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->date = $date->format("F Y");
+        $year = $date->format('Y');
+        $this->view->year = $year;
 
-        $date->modify('+1 year');
-        $this->view->nextYear = $date->format('Y');
+        $nextYear = $date->modify('+1 year')->format('Y');
+        $this->view->nextYear = $nextYear;
 
-        $date->modify('-2 year');
-        $this->view->previousYear = $date->format('Y');
+        $previousYear = $date->modify('-2 year')->format('Y');
+        $this->view->previousYear = $previousYear;
 
-        $this->view->month = $date->format('m');
-        $date->modify('-1 month');
-        $this->view->previousMonth = $date->format('m');
-        $date->modify('+2 month');
-        $this->view->nextMonth = $date->format('m');
+        $month = $date->format('m');
+        $this->view->month = $month;
+
+        $nextMonth = $date->modify('+1 month')->format('m');
+        $this->view->nextMonth = $nextMonth;
+
+        $previousMonth = $date->modify('-2 month')->format('m');
+        $this->view->previousMonth = $previousMonth;
+
+        $date->setDate($year,$month,26);
+        $date->setTime(0,0,0);
+
+        $newDate = new DateTime();
+
+        switch($month)
+        {
+            case 1:
+                $newDate->setDate($previousYear,$previousMonth,26);
+                break;
+            default:
+                $newDate->setDate($year,$previousMonth,26);
+        }
+
+        $newDate->setTime(0,0,0);
 
         $date2 = new DateTime();
         $date2->setDate($year,$month,25);
-        $date2->setTime(24,0,0);
+        $date2->setTime(24,00,00);
+        $interval = date_diff($newDate,$date2);
 
-        $interval = date_diff($date,$date2);
+        $span = $interval->days;
+        $this->view->span = $span;
 
-        $this->view->span = $interval->days;
+        $this->view->date = $date->format("F Y");
 
         $reports = new reportModel($year, $month);
         $this->view->report = $reports->payPeriodTotals($year, $month);

+ 8 - 0
application/models/timesheetModel.php

@@ -321,12 +321,20 @@
 			$currentDate = new DateTime();
 			$currentDate->setDate($year, $month, 1);
 
+			//Just added for test. Might need to keep. Fixed the wrong
+			$currentDate->setTime(0,0,0);
+
+
 			$this->currentYear = $currentDate->format('Y');
 			$this->currentMonth = $currentDate->format('m');
 			$this->currentMonthText = $currentDate->format('F');
+
+
 			$this->startDate = $currentDate->modify('-1 month +25 day')->format('Y-m-d');
 			$this->startDateTimeString = strtotime($this->startDate);
+
 			$currentDate->setDate($year, $month, 1);
+
 			$this->endDate = $currentDate->modify('+25 day')->format('Y-m-d');
 			$this->endDateTimeString = strtotime($this->endDate);
 

+ 28 - 4
application/views/reports/index.phtml

@@ -4,7 +4,7 @@
             <h1><i class="fa fa-file"></i> Reports</h1>
         </div>
         <div class="small-6 columns text-right">
-            <h1 class="subheader"><?php echo $this->month ?> <?php echo $this->year?></h1>
+            <h1 class="subheader"><?php echo $this->monthName ?> <?php echo $this->year?></h1>
         </div>
     </div>
     <div class="row">
@@ -32,9 +32,33 @@
 
 
                 ?>
-                <li><a class="button small secondary" href="<?php echo $this->link(array('reports',$year, $this->previousMonth))?> "><i class="fa fa-caret-left"></i> Previous</a></li>
-                <li><a class="button small secondary" href="<?php echo $this->link(array('reports',$year, $this->nextMonth))?> ">Next <i class="fa fa-caret-right"></i></a></li>
-                <li><a class="button small secondary" data-reveal-id="yearForm" href="#"><i class="fa fa-calendar"></i> Change Year</a></li>
+
+                <li><a class="button small secondary" href="
+                    <?php
+                    switch ($this->month)
+                    {
+                        case 01:
+                            echo $this->link(array('reports',$this->previousYear, $this->previousMonth));
+                            break;
+                        default:
+                            echo $this->link(array('reports',$this->year, $this->previousMonth));
+                    }
+                    ?>
+                    "><i class="fa fa-caret-left"></i> Previous</a></li>
+                <li><a class="button small secondary" href="
+                    <?php
+                    switch ($this->month)
+                    {
+                        case 12:
+                            echo $this->link(array('reports',$this->nextYear, $this->nextMonth));
+                            break;
+                        default:
+                            echo $this->link(array('reports',$this->year, $this->nextMonth));
+                    }
+                    ?>
+                    ">Next <i class="fa fa-caret-right"></i></a></li>
+
+
                 <li><a id="showAll" class="button small secondary" href="#"><i class="fa fa-eye"></i> Show All</a></li>
                 <li><a id="hideAll" class="button small secondary" href="#"><i class="fa fa-eye-slash"></i> Hide All</a></li>
             </ul>