浏览代码

Added entry overlap validation and updated the timesheet view to reflect entrys under each day.

Adam Day 9 年之前
父节点
当前提交
ebb572a4b4

+ 3 - 2
application/controllers/timesheetController.php

@@ -40,13 +40,14 @@ class timesheetController extends Staple_Controller
 
                     if($entry->save())
                     {
-                        $this->view->message = "Entry saved.";
                         $form = new insertTimeForm();
+                        $form->successMessage = array("<i class=\"fa fa-check\"></i> Entry saved for ".$data['date']."");
                         $this->view->insertTimeForm = $form;
                     }
                     else
                     {
-                        $this->view->message = "ERROR: Unable to save entry.";
+                        $message = $entry->save()->getMessage();
+                        $form->errorMessage = array($message);
                         $this->view->insertTimeForm = $form;
                     }
                 }

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

@@ -5,23 +5,39 @@
         </div>
     </div>
     <div id="entryForm">
+        <div class="row">
+            <?php
+            if(count($this->errorMessage) > 0)
+            {
+                echo "<div class=\"small-12 columns\">";
+                echo "<div data-alert class=\"alert-box alert\">";
+                foreach($this->errorMessage as $message)
+                {
+                    echo $message;
+                }
+                echo "<a href=\"#\" class=\"close\">&times;</a></div>";
+                echo "</div>";
+            }
+
+            if(count($this->successMessage) > 0)
+            {
+                echo "<div class=\"small-12 columns\">";
+                echo "<div data-alert class=\"alert-box success\">";
+                foreach($this->successMessage as $message)
+                {
+                    echo $message;
+                }
+                echo "<a href=\"#\" class=\"close\">&times;</a></div>";
+                echo "</div>";
+            }
+            ?>
+        </div>
         <div class="row">
             <div class="small-12 columns">
                 <div class="row">
-                    <?php
-                    if(count($this->message) > 0)
-                    {
-                        echo "<div class=\"small-12 columns\">";
-                        echo "<div data-alert class=\"alert-box alert\">";
-                        foreach($this->message as $message)
-                        {
-                            echo $message;
-                        }
-                        echo "<a href=\"#\" class=\"close\">&times;</a></div>";
-                        echo "</div>";
-                    }
+                   <?php
                     echo $this->formstart();
-                    ?>
+                   ?>
                 </div>
                 <div class="row">
                     <div class="small-6 medium-4 columns">

+ 75 - 17
application/models/timeEntryModel.php

@@ -6,6 +6,7 @@
 
 		private $id;
         private $date;
+        private $fullDate;
         private $inTime;
         private $inTimeRaw;
         private $roundedInTime;
@@ -226,6 +227,22 @@
             $this->batchId = $batchId;
         }
 
+        /**
+         * @return mixed
+         */
+        public function getFullDate()
+        {
+            return $this->fullDate;
+        }
+
+        /**
+         * @param mixed $fullDate
+         */
+        public function setFullDate($fullDate)
+        {
+            $this->fullDate = $fullDate;
+        }
+
 		function __construct($id = null)
 		{
             $this->db = Staple_DB::get();
@@ -242,6 +259,7 @@
                     $this->setId($result['id']);
                     $this->setBatchId($result['batchId']);
                     $this->setDate(date("m/d/Y",$result['inTime']));
+                    $this->setFullDate(date("l, F jS Y",$result['inTime']));
 
                     //Set inTime
                     $inTime = new DateTime();
@@ -333,19 +351,40 @@
 
             if($this->getId() == NULL)
 			{
-				//Insert new item
-				$sql = "INSERT INTO timeEntries (userId, inTime, outTime, lessTime, codeId, batchId)
-					VALUES (
-						'".$this->db->real_escape_string($userId)."',
-						'".$this->db->real_escape_string($inTime)."',
-						'".$this->db->real_escape_string($outTime)."',
-						'".$this->db->real_escape_string($this->getLessTime())."',
-						'".$this->db->real_escape_string($this->getCodeId())."',
-						'".$this->db->real_escape_string($batchId)."'
-						)";
+                //TODO Check for overlap
+                if($this->_overlap($inTime))
+                {
+                    //Insert new item
+                    $sql = "INSERT INTO timeEntries (userId, inTime, outTime, lessTime, codeId, batchId)
+                    VALUES (
+                        '" . $this->db->real_escape_string($userId) . "',
+                        '" . $this->db->real_escape_string($inTime) . "',
+                        '" . $this->db->real_escape_string($outTime) . "',
+                        '" . $this->db->real_escape_string($this->getLessTime()) . "',
+                        '" . $this->db->real_escape_string($this->getCodeId()) . "',
+                        '" . $this->db->real_escape_string($batchId) . "'
+                        )";
+
+                    $query = $this->db->query($sql);
+                    if($query === true)
+                    {
+                        return true;
+                    }
+                    else
+                    {
+                        return false;
+                    }
+                }
+                else
+                {
+                    $ex = new Exception('Time block already in use. Submit a new entry or edit an already existing one.');
+                    return $ex;
+                }
 			}
 			else
 			{
+                //TODO Check for overlap
+
 				//Update item
 				$sql = "UPDATE timeEntries SET
 					userId='".$this->db->real_escape_string($userId)."',
@@ -356,13 +395,13 @@
                     batchId='".$this->db->real_escape_string($this->getBatchId())."',
 					WHERE id='".$this->db->real_escape_string($batchId)."'
 				";
-			}
-			
-			$query = $this->db->query($sql);
-			
-			if($query === true)
-			{
-				return true;
+
+                $query = $this->db->query($sql);
+
+                if($query === true)
+                {
+                    return true;
+                }
 			}
 		}
 
@@ -392,5 +431,24 @@
             }
         }
 
+        function _overlap($inTime)
+        {
+            $this->db = Staple_DB::get();
+
+            $auth = Staple_Auth::get();
+            $user = new userModel($auth->getAuthId());
+            $userId = $user->getId();
+
+            $sql = "SELECT id FROM timeEntries WHERE '".$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;
+            }
+        }
 	}
 ?>

+ 33 - 16
application/views/timesheet/index.phtml

@@ -38,28 +38,41 @@
                     <b>Less Time</b>
                 </div>
                 <div class=\"small-4 medium-2 columns\">
-                    <b>Time Worked</b>
+                    <b>Total</b>
                 </div>
                 <div class=\"small-4 medium-2 columns\">
-                    <b>Time Code</b>
+                    <b>Code</b>
                 </div>
                 <hr>
             </div>
         ";
-
+        $date = null;
         foreach($this->timesheet->entries as $entry)
         {
+            if($date != $entry->date)
+            {
+                echo "
+                    <div class=\"row\">
+                        <div class=\"small-12 columns\" style=\"padding:10px;\">
+                            <b>$entry->fullDate</b>
+                        </div>
+                    </div>
+                ";
+            }
+
             echo "
             <div class=\"row\">
                 <div class=\"small-4 medium-2 columns\">";
-                   if($this->timesheet->getBatch() == $entry->batchId)
-                   {
-                       echo "<i class=\"fa fa-square-o\"></i> <a href=\"".$this->link(array('timesheet','edit',$entry->id))."\">".$entry->date."</a>";
-                   }
-                   else
-                   {
-                       echo "<i class=\"fa fa-check-square-o green\"></i> ".$entry->date." ";
-                   }
+
+               if($this->timesheet->getBatch() == $entry->batchId)
+               {
+                    echo "<a href=\"".$this->link(array('timesheet','edit',$entry->id))."\"><i class=\"fa fa-edit\"></i> Edit</a>";
+               }
+               else
+               {
+                   echo "<i class=\"fa fa-check green\"></i> Validated ";
+               }
+
             echo "
                 </div>
                 <div class=\"small-4 medium-2 columns\">
@@ -72,14 +85,15 @@
                     ".$entry->lessTime." Min.
                 </div>
                 <div class=\"small-4 medium-2 columns\">
-                    <b>".$entry->timeWorked."</b> Hours
+                    ".$entry->timeWorked." Hours
                 </div>
                 <div class=\"small-4 medium-2 columns\">
                     ".$entry->codeName."
                 </div>
-                <hr>
             </div>
             ";
+
+            $date = $entry->date;
         }
     }
     else
@@ -113,13 +127,16 @@
     </div>
     <div class="row">
         <div class="small-6 medium-4 large-3 columns totals">
-            <b>Total hours: </b> <?php echo $this->timesheet->normalWorked ?>
+            <b>Normal: </b> <?php echo $this->timesheet->normalWorked ?>
         </div>
         <div class="small-6 medium-4 large-3 columns totals">
-            <b>Vacation used: </b> <?php echo $this->timesheet->vacationUsed ?>
+            <b>Vacation: </b> <?php echo $this->timesheet->vacationUsed ?>
+        </div>
+        <div class="small-6 medium-4 large-3 columns totals end">
+            <b>Sick: </b> <?php echo $this->timesheet->sickUsed ?>
         </div>
         <div class="small-6 medium-4 large-3 columns totals end">
-            <b>Sick used: </b> <?php echo $this->timesheet->sickUsed ?>
+            <b>Total: </b> <?php echo $this->timesheet->sickUsed ?>
         </div>
     </div>
 </div>

文件差异内容过多而无法显示
+ 0 - 0
public/style/app.css


文件差异内容过多而无法显示
+ 0 - 0
public/style/app.css.map


+ 5 - 1
public/timetrackerStyle/scss/_settings.scss

@@ -131,6 +131,10 @@ $primary-color: #374350;
   color:$success-color;
 }
 
+.orange {
+  color:$warning-color !important;
+}
+
 .keyButton {
   font-size:1.5em !important;
   margin:0px !important;
@@ -368,7 +372,7 @@ $primary-color: #374350;
 // $anchor-text-decoration-hover: none;
 
 // $anchor-font-color: $primary-color;
-   $anchor-font-color: #395ea7;
+   $anchor-font-color: #79797e;
 // $anchor-font-color-hover: scale-color($anchor-font-color, $lightness: -14%);
 
 // We use these to style the <hr> element

部分文件因为文件数量过多而无法显示