Explorar el Código

Fixed errors when editing a time entry. Fixed Daily totals report to show the correct dates.

Adam Day hace 9 años
padre
commit
87d7c72519

+ 12 - 1
application/controllers/reportsController.php

@@ -232,6 +232,7 @@ class reportsController extends Staple_Controller
         $date->setTime(0,0,0);
 
         $year = $date->format('Y');
+
         $this->view->year = $year;
 
         $nextYear = $date->modify('+1 year')->format('Y');
@@ -253,7 +254,6 @@ class reportsController extends Staple_Controller
         $date->setTime(0,0,0);
 
         $newDate = new DateTime();
-
         switch($month)
         {
             case 1:
@@ -268,6 +268,7 @@ class reportsController extends Staple_Controller
         $date2 = new DateTime();
         $date2->setDate($year,$month,25);
         $date2->setTime(24,00,00);
+
         $interval = date_diff($newDate,$date2);
 
         $span = $interval->days;
@@ -275,6 +276,11 @@ class reportsController extends Staple_Controller
 
         $this->view->date = $date->format("F Y");
 
+        $date = new dateTime();
+        $date->setDate($year, $month, 25);
+        $this->view->currentDate = $date->format('Y-m-d');
+        $this->view->previousDate = $date->modify('-1 month +1 day')->format('Y-m-d');
+
         $reports = new reportModel($year, $month);
         $this->view->report = $reports->payPeriodTotals($year, $month);
     }
@@ -361,6 +367,11 @@ class reportsController extends Staple_Controller
         $date->modify("+$days days");
         $this->view->endDate = $date->format("F jS Y");
 
+        $date = new dateTime();
+        $date->setDate($year, $month, 25);
+        $this->view->currentDate = $date->format('Y-m-d');
+        $this->view->previousDate = $date->modify('-1 month +1 day')->format('Y-m-d');
+
         $codes = new codeModel();
         $this->view->codes = $codes->allCodes();
 

+ 6 - 16
application/controllers/timesheetController.php

@@ -283,28 +283,18 @@ class timesheetController extends Staple_Controller
                     $data = $form->exportFormData();
 
                     //Check if dates are within the current pay period.
-                    $startMonth = date('m',strtotime('last month'));
+                    $date = new DateTime();
 
-                    if($startMonth == 1)
-                    {
-                        $startYear = date('Y',strtotime('last year'));
-                    }
-                    else
+                    if($date->format('d') > 25)
                     {
-                        $startYear = date('Y');
+                        $date->modify('+1 month');
                     }
-
-                    $date = new DateTime();
-                    $endMonth = $date->modify('+1 month')->format('m');
-                    $endYear = $date->format('Y');
-
-                    $startDate= strtotime($startMonth.'/26/'.$startYear);
-                    $endDate = strtotime($endMonth.'/25/'.$endYear);
-
+                    $maxDate = $date->setDate($date->format('Y'),$date->format('m'),25)->setTime(23,59,59)->getTimestamp();
+                    $minDate = $date->modify('-1 month +1 day')->setTime(0,0,0)->getTimestamp();
                     $userDate = strtotime($data['date']);
 
                     //Date is within pay period
-                    if($userDate >= $startDate && $userDate <= $endDate)
+                    if($userDate >= $minDate && $userDate <= $maxDate)
                     {
                         //Create a new entry object and set properties
                         $entry = new timeEntryModel();

+ 2 - 0
application/models/reportModel.php

@@ -313,9 +313,11 @@ class reportModel extends Staple_Model
         $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)

+ 6 - 1
application/views/reports/payperiod.phtml

@@ -66,8 +66,12 @@
                         <th style="width:150px;"></th>
                         <?php
 
+                            $previousDate = explode("-",$this->previousDate);
+
                             $date = new DateTime();
-                            $date->setDate($this->year,$this->previousMonth,26);
+                            $date->setDate($previousDate[0],$previousDate[1],$previousDate[2]);
+
+                            $date->setTime(0,0,0);
 
                             for($i=1;$i<=$this->span;$i++)
                             {
@@ -79,6 +83,7 @@
                                 {
                                     echo "<th style='border-bottom:1px solid #ccc;'>".$date->format('D')."<br>".$date->format('n')."/".$date->format('j')."</th>";
                                 }
+
                                 $date->modify('+1 day');
                             }
                         ?>