Sfoglia il codice sorgente

Added the weekly report for total hours reported for a given fiscal week. Updated the timesheet view and form to truly reflect the correct pay period based on the calendar day.

Adam Day 9 anni fa
parent
commit
5c0c95c5a7

+ 31 - 47
application/controllers/timesheetController.php

@@ -28,65 +28,42 @@ 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)
+                if($date->format('d') > 25)
                 {
-                    $startYear = date('Y',strtotime('last year'));
+                    $date->modify('+1 month');
                 }
-                else
-                {
-                    $startYear = date('Y');
-                }
-
-                $endMonth = date('m');
-                $endYear = date('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)
                 {
-                    //Compare in Times and out Times.
-                    /*
-                    if(strtotime($data['inTime']) < strtotime($data['outTime']))
+                    //Create a new entry object and set properties
+                    $entry = new timeEntryModel();
+                    $entry->setDate($data['date']);
+                    $entry->setInTime($data['inTime']);
+                    $entry->setOutTime($data['outTime']);
+                    $entry->setLessTime($data['lessTime']);
+                    $entry->setCodeId($data['code']);
+
+                    //Save entry data to table.
+                    if($entry->save())
                     {
-                    */
-                        //Create a new entry object and set properties
-                        $entry = new timeEntryModel();
-                        $entry->setDate($data['date']);
-                        $entry->setInTime($data['inTime']);
-                        $entry->setOutTime($data['outTime']);
-                        $entry->setLessTime($data['lessTime']);
-                        $entry->setCodeId($data['code']);
-
-                        //Save entry data to table.
-                        if($entry->save())
-                        {
-                            //Return a new time form with success message
-                            $form = new insertTimeForm();
-                            $form->successMessage = array("<i class=\"fa fa-check\"></i> Entry saved for ".$data['date']."");
-                            $this->view->insertTimeForm = $form;
-                        }
-                        else
-                        {
-                            //Return the same form with a warning message
-                            $message = "<i class=\"fa fa-warning\"></i> Cannot insert overlapping time entries. Please add a new entry or edit an already existing one.";
-                            $form->errorMessage = array($message);
-                            $this->view->insertTimeForm = $form;
-                        }
-                    /*
+                        //Return a new time form with success message
+                        $form = new insertTimeForm();
+                        $form->successMessage = array("<i class=\"fa fa-check\"></i> Entry saved for ".$data['date']."");
+                        $this->view->insertTimeForm = $form;
                     }
                     else
                     {
-                        //Return the same form with error message.
-                        $form->errorMessage = array("<b>'Time In'</b> entry cannot be before <b>'Time Out'</b> entry.");
+                        //Return the same form with a warning message
+                        $message = "<i class=\"fa fa-warning\"></i> Cannot insert overlapping time entries. Please add a new entry or edit an already existing one.";
+                        $form->errorMessage = array($message);
                         $this->view->insertTimeForm = $form;
                     }
-                    */
                 }
                 else
                 {
@@ -117,7 +94,14 @@ class timesheetController extends Staple_Controller
         if($month == null)
         {
             $date = new DateTime();
-            $month = $date->format('m');
+            if($date->format("j") >= 26)
+            {
+                $month = $date->modify('+1 month')->format('m');
+            }
+            else
+            {
+                $month = $date->format('m');
+            }
         }
 
         //Load timesheet for user.

+ 13 - 2
application/forms/layouts/insertFormLayout.phtml

@@ -69,11 +69,22 @@
 </div>
 
 <script>
-    <?php $timesheet = new timesheetModel(date('Y'),date('m')) ?>
+    <?php
+    $date = new DateTime();
+
+    if($date->format('d') > 25)
+    {
+        $date->modify('+1 month');
+    }
+    $maxDate = $date->setDate($date->format('Y'),$date->format('m'),25)->format('m/d/Y');
+    $minDate = $date->modify('-1 month +1 day');
+    $minDate = $date->format('m/d/Y');
+    ?>
+
     $(document).ready(function() {
 
         $(function() {
-            $( "#date" ).datepicker({numberOfMonths:2, minDate: "<?php echo date('m',strtotime('last month'))."/26/".date('Y') ?>", maxDate: "<?php echo date('m',strtotime('m'))."/25/".date('Y') ?>" });
+            $( "#date" ).datepicker({numberOfMonths:2, minDate: "<?php echo $minDate ?>", maxDate: "<?php echo $maxDate ?>" });
         });
 
         $('#entryToggle').click(function()

+ 7 - 7
application/views/reports/index.phtml

@@ -24,9 +24,9 @@
             $i = 0;
             foreach($this->report as $user=>$timesheet)
             {
-                echo "<h3 id='user'.$i.'' class='timeTitle'>$user <i class='fa fa-chevron-up right'></i></h3>";
+                echo "<h3 id='user'.$i.'' class='timeTitle'>$user <i class='fa fa-chevron-down right'></i></h3>";
                 echo "
-        <div class=\"wrapper\">";
+        <div class=\"wrapper hide\">";
 
                 if(count($timesheet) > 0)
                 {
@@ -35,11 +35,11 @@
                         <thead>
                         <tr>
                             <th>Date</th>
-                            <th>In Time</th>
-                            <th>Out Time</th>
-                            <th>Less Worked</th>
-                            <th>Total Worked</th>
-                            <th>Time Code</th>
+                            <th>In</th>
+                            <th>Out</th>
+                            <th>Less Time</th>
+                            <th>Hours</th>
+                            <th>Code</th>
                             <th>Validated</th>
                         </tr>
                         </thead>