Browse Source

Have a basic check working for overlap however a user can still edit a time entry can cause overlap. Resolved an issue with the 25th day of the payperiod not showing up in the timesheet.

Adam Day 10 năm trước cách đây
mục cha
commit
a0dbd3c956

+ 35 - 7
application/models/timeEntryModel.php

@@ -433,22 +433,50 @@
             $user = new userModel($auth->getAuthId());
             $userId = $user->getId();
 
+            $dateString = strtotime(date("Y-m-d", $inTime));
+            $nextDateString = $dateString + 86400;
+
+            //Find the earliest time for the given date.
             $sql = "
-                SELECT id FROM timeEntries
-                WHERE ('".$this->db->real_escape_string($outTime)."' > inTime AND '".$this->db->real_escape_string($outTime)."' < outTime)
-                OR ('".$this->db->real_escape_string($inTime)."' > inTime AND '".$this->db->real_escape_string($inTime)."' < outTime)
-                AND userId = '".$this->db->real_escape_string($userId)."'
+                SELECT inTime FROM timeEntries WHERE inTime > '".$this->db->real_escape_string($dateString)."' AND userId = '".$this->db->real_escape_string($userId)."' ORDER BY inTime ASC LIMIT 1
             ";
 
-            if($this->db->query($sql)->num_rows > 0)
+            $query = $this->db->query($sql);
+            $result = $query->fetch_assoc();
+            $firstInTime = $result['inTime'];
+
+            //Find the latest time for the given date.
+            $sql = "
+                SELECT outTime FROM timeEntries WHERE outTime > '".$this->db->real_escape_string($dateString)."' AND outTime < '".$this->db->real_escape_string($nextDateString)."' AND userId = '".$this->db->real_escape_string($userId)."' ORDER BY outTime DESC LIMIT 1
+            ";
+
+            $query = $this->db->query($sql);
+            $result = $query->fetch_assoc();
+            $lastOutTime = $result['outTime'];
+
+            if($inTime < $firstInTime && $outTime > $lastOutTime)
             {
                 return false;
             }
             else
             {
-                return true;
+                //Check if inTime and out time fall between already existing dates.
+                $sql = "
+                    SELECT id FROM timeEntries
+                    WHERE ('".$this->db->real_escape_string($outTime)."' > inTime AND '".$this->db->real_escape_string($outTime)."' < outTime)
+                    OR ('".$this->db->real_escape_string($inTime)."' > inTime AND '".$this->db->real_escape_string($inTime)."' < outTime)
+                    AND userId = '".$this->db->real_escape_string($userId)."'
+                ";
+
+                if($this->db->query($sql)->num_rows > 0)
+                {
+                    return false;
+                }
+                else
+                {
+                    return true;
+                }
             }
-
         }
 
         function _validated($id)

+ 1 - 1
application/models/timesheetModel.php

@@ -405,7 +405,7 @@
 			$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('+24 day')->format('Y-m-d');
+			$this->endDate = $currentDate->modify('+25 day')->format('Y-m-d');
 			$this->endDateTimeString = strtotime($this->endDate);
 
 			//Previous Dates

+ 2 - 1
application/views/timesheet/index.phtml

@@ -5,7 +5,7 @@
             <h3><i class="fa fa-calendar"></i> <?php echo $this->timesheet->currentMonthText ?> <a href="#" data-reveal-id="yearForm"><?php echo $this->timesheet->currentYear ?></a></h3>
         </div>
         <div class="small-12 medium-8 text-right columns">
-            <ul class="button-group radius even-5 stack-for-small">
+            <ul class="button-group round even-5 stack-for-small">
                 <li><a class="button small secondary" href="<?php echo $this->link(array('timesheet',$this->timesheet->currentYear,$this->timesheet->previousMonth)) ?>"><i class="fa fa-caret-left"></i> Prev.</a></li>
                 <li><a class="button small secondary" href="<?php echo $this->link(array('timesheet',$this->timesheet->currentYear,$this->timesheet->nextMonth)) ?>">Next <i class="fa fa-caret-right"></i></a></li>
                 <li><a class="button small toggleTotals" href="#"><i class="fa fa-calculator"></i> Totals</a></li>
@@ -186,6 +186,7 @@
         $(".timeTitle").click(function() {
             $(this).parent().nextUntil(".marker").slideToggle("slow");
             $(this).find("i").toggleClass("fa-chevron-up fa-chevron-down")
+            return false;
         });
 
         $("#hideAll").click(function() {