Browse Source

Have a basic validation process working.

Adam Day 9 years ago
parent
commit
0928266da7

+ 52 - 3
application/controllers/timesheetController.php

@@ -86,6 +86,25 @@ class timesheetController extends Staple_Controller
         //Pass timesheet object to view
         $this->view->timesheet = $timesheet;
 
+        //Check for unvalidated entries
+        $i = 0;
+        foreach($timesheet->getEntries() as $entry)
+        {
+            if($entry->batchId == $timesheet->getBatch())
+            {
+                $i++;
+            }
+        }
+
+        if($i > 0)
+        {
+            $this->view->needsValidation = true;
+        }
+        else
+        {
+            $this->view->needsValidation = false;
+        }
+
         $changeYearForm = new changeYearForm();
         $this->view->changeYearForm = $changeYearForm;
     }
@@ -172,14 +191,44 @@ class timesheetController extends Staple_Controller
     {
         $timesheet = new timesheetModel($year,$month);
 
-        echo $timesheet->getStartDateTimeString();
-
         //Get Current Batch ID
         $auth = Staple_Auth::get();
         $user = new userModel($auth->getAuthId());
         $batchId = $user->getBatchId();
-        $this->view->timesheet = $timesheet;
 
+        //Check for unvalidated entries
+        $i = 0;
+        foreach($timesheet->getEntries() as $entry)
+        {
+            if($entry->batchId == $timesheet->getBatch())
+            {
+                $i++;
+            }
+        }
+
+        if($i > 0)
+        {
+            $this->view->timesheet = $timesheet;
+
+            $form = new validateTimeSheetForm();
+            $form->setAction($this->_link(array('timesheet','validate',$timesheet->getCurrentYear(),$timesheet->getCurrentMonth())));
+
+            if($form->wasSubmitted())
+            {
+                $timesheet->validate($batchId);
+                $this->view->needsValidation = true;
+            }
+            else
+            {
+                $this->view->form = $form;
+                $this->view->needsValidation = false;
+            }
+        }
+        else
+        {
+            $this->view->needsValidation = false;
+            $this->view->timesheet = array();
+        }
 
     }
 }

+ 10 - 0
application/forms/layouts/validateTimeSheetFormLayout.phtml

@@ -0,0 +1,10 @@
+<?php echo $this->formstart(); ?>
+<div class="row">
+    <div class="small-6 columns">
+        <a class="button radius secondary expand" href="<?php echo $this->link(array('timesheet')) ?>">Cancel</a>
+    </div>
+    <div class="small-6 columns">
+        <?php echo $this->fields['submit'] ?>
+    </div>
+</div>
+<?php echo $this->formend(); ?>

+ 18 - 0
application/forms/validateTimeSheetForm.php

@@ -0,0 +1,18 @@
+<?php
+
+    class validateTimeSheetForm extends Staple_Form
+    {
+        public function _start()
+        {
+            $this->setLayout('validateTimeSheetFormLayout');
+
+            $this->setName('validateTimeSheet');
+
+            $submit = new Staple_Form_FoundationSubmitElement('submit','Submit');
+            $submit->addClass('button radius success expand');
+
+            $this->addField($submit);
+        }
+    }
+
+?>

+ 67 - 49
application/models/timesheetModel.php

@@ -20,10 +20,7 @@
 		private $previousMonthText;
 		private $previousYear;
 
-		private $validated;
-		private $validatedDate;
-		private $approved;
-		private $approvalDate;
+		private $batch;
 
 		private $entries;
 
@@ -96,7 +93,23 @@
 		}
 
 		/**
-		 * @return DateTime
+		 * @return int
+		 */
+		public function getStartDateTimeString()
+		{
+			return $this->startDateTimeString;
+		}
+
+		/**
+		 * @param int $startDateTimeString
+		 */
+		public function setStartDateTimeString($startDateTimeString)
+		{
+			$this->startDateTimeString = $startDateTimeString;
+		}
+
+		/**
+		 * @return string
 		 */
 		public function getEndDate()
 		{
@@ -104,13 +117,29 @@
 		}
 
 		/**
-		 * @param DateTime $endDate
+		 * @param string $endDate
 		 */
 		public function setEndDate($endDate)
 		{
 			$this->endDate = $endDate;
 		}
 
+		/**
+		 * @return int
+		 */
+		public function getEndDateTimeString()
+		{
+			return $this->endDateTimeString;
+		}
+
+		/**
+		 * @param int $endDateTimeString
+		 */
+		public function setEndDateTimeString($endDateTimeString)
+		{
+			$this->endDateTimeString = $endDateTimeString;
+		}
+
 		/**
 		 * @return string
 		 */
@@ -210,53 +239,37 @@
 		/**
 		 * @return mixed
 		 */
-		public function getEntries()
-		{
-			return $this->entries;
-		}
-
-		/**
-		 * @param mixed $entries
-		 */
-		public function setEntries($entries)
-		{
-			$this->entries = $entries;
-		}
-
-		/**
-		 * @return int
-		 */
-		public function getEndDateTimeString()
+		public function getBatch()
 		{
-			return $this->endDateTimeString;
+			return $this->batch;
 		}
 
 		/**
-		 * @param int $endDateTimeString
+		 * @param mixed $batch
 		 */
-		public function setEndDateTimeString($endDateTimeString)
+		public function setBatch($batch)
 		{
-			$this->endDateTimeString = $endDateTimeString;
+			$this->batch = $batch;
 		}
 
 		/**
-		 * @return int
+		 * @return array
 		 */
-		public function getStartDateTimeString()
+		public function getEntries()
 		{
-			return $this->startDateTimeString;
+			return $this->entries;
 		}
 
 		/**
-		 * @param int $startDateTimeString
+		 * @param array $entries
 		 */
-		public function setStartDateTimeString($startDateTimeString)
+		public function setEntries($entries)
 		{
-			$this->startDateTimeString = $startDateTimeString;
+			$this->entries = $entries;
 		}
 
 		/**
-		 * @return int
+		 * @return float|int
 		 */
 		public function getVacationUsed()
 		{
@@ -264,7 +277,7 @@
 		}
 
 		/**
-		 * @param int $vacationUsed
+		 * @param float|int $vacationUsed
 		 */
 		public function setVacationUsed($vacationUsed)
 		{
@@ -272,7 +285,7 @@
 		}
 
 		/**
-		 * @return int
+		 * @return float|int
 		 */
 		public function getNormalWorked()
 		{
@@ -280,7 +293,7 @@
 		}
 
 		/**
-		 * @param int $normalWorked
+		 * @param float|int $normalWorked
 		 */
 		public function setNormalWorked($normalWorked)
 		{
@@ -288,7 +301,7 @@
 		}
 
 		/**
-		 * @return int
+		 * @return float|int
 		 */
 		public function getSickUsed()
 		{
@@ -296,7 +309,7 @@
 		}
 
 		/**
-		 * @param int $sickUsed
+		 * @param float|int $sickUsed
 		 */
 		public function setSickUsed($sickUsed)
 		{
@@ -307,6 +320,10 @@
 		{
 			$this->db = Staple_DB::get();
 
+			//Get batchID
+			$user = new userModel();
+			$this->batch = $user->getBatchId();
+
 			//Current Dates
 			$currentDate = new DateTime();
 			$currentDate->setDate($year, $month, 1);
@@ -358,14 +375,14 @@
 			$this->sickUsed = $this->calculatedTotals($code['id'],$this->startDate,$this->endDate);
 		}
 
-		function validated($startDate,$endDate)
+		function validate($batchId)
 		{
-			//Get user ID from Auth
-			$user = new userModel();
-			$userId = $user->getId();
-
-
-
+			//Generate a new Batch ID for the user.
+			if($this->genSetNewBatch())
+			{
+				//TODO need to log how and when the timesheet validated.
+				return true;
+			}
 		}
 
 		function entries($startDate,$endDate)
@@ -416,9 +433,10 @@
 		{
 			$this->db = Staple_DB::get();
 
-			$id = $this->getId();
+			$user = new userModel();
+			$userId = $user->getId();
 
-			$key = sha1(time().$this->getUsername());
+			$key = sha1(time().$user->getUsername().rand(999,9999999999));
 
 			//Check if key exists
 			$sql = "SELECT id FROM accounts WHERE batchId = '".$this->db->real_escape_string($key)."'";
@@ -430,7 +448,7 @@
 			else
 			{
 				//Set new key in user account
-				$sql = "UPDATE accounts SET batchId='".$this->db->real_escape_string($key)."' WHERE id=$id";
+				$sql = "UPDATE accounts SET batchId='".$this->db->real_escape_string($key)."' WHERE id=$userId";
 
 				if($this->db->query($sql))
 				{

+ 17 - 3
application/views/timesheet/index.phtml

@@ -10,11 +10,17 @@
                 <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>
                 <li><a class="button small" href="#"><i class="fa fa-print"></i> Print</a></li>
-                <li><a class="button small success" href="<?php echo $this->link(array('timesheet','validate',$this->timesheet->currentYear,$this->timesheet->currentMonth))?>"><i class="fa fa-check"></i> Validate</a></li>
+                <?php
+                    if($this->needsValidation)
+                    {
+                        echo "<li><a class=\"button small success\" href=\"".$this->link(array('timesheet','validate',$this->timesheet->currentYear,$this->timesheet->currentMonth))."\"><i class=\"fa fa-check\"></i> Validate</a></li>";
+                    }
+                ?>
             </ul>
         </div>
     </div>
 <?php
+
     if(count($this->timesheet->entries) > 0)
     {
         echo "
@@ -45,8 +51,16 @@
         {
             echo "
             <div class=\"row\">
-                <div class=\"small-4 medium-2 columns\">
-                    <a href=\"".$this->link(array('timesheet','edit',$entry->id))."\" class=\"\">".$entry->date."</a>
+                <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." ";
+                   }
+            echo "
                 </div>
                 <div class=\"small-4 medium-2 columns\">
                     <span data-tooltip aria-haspopup=\"true\" class=\"has-tip\" title=\"Entered as: ".$entry->inTime."\">".$entry->roundedInTime."</span>

+ 17 - 6
application/views/timesheet/validate.phtml

@@ -3,6 +3,7 @@
         <div class="small-12 text-center">
             <h1>Validate Time Sheet</h1>
             <p>Review the following entries and if accurate submit for approval.</p>
+            <p>Once a time sheet has been validated entries <b>cannot</b> be modified.</p>
         </div>
     </div>
 </div>
@@ -65,13 +66,26 @@ if(count($this->timesheet) > 0)
 }
 else
 {
-    echo "
+    if($this->needsValidation)
+    {
+        echo "
             <div class=\"row\">
                 <div class=\"small-12 columns text-center\">
                     No time submitted.
                 </div>
             </div>
-        ";
+            ";
+    }
+    else
+    {
+        echo "
+            <div class=\"row\">
+                <div class=\"small-12 columns text-center\">
+                    Timesheet already validated.
+                </div>
+            </div>
+            ";
+    }
 }
 
 ?>
@@ -85,10 +99,7 @@ if(count($this->timesheet) > 0)
         <div class=\"section\">
             <div class=\"row\">
                 <div class=\"small-12 medium-6 medium-centered columns\">
-                    <ul class=\"button-group even-2 radius\">
-                        <li><a class=\"button secondary\" href=\"\"><i class=\"fa fa-close\"> Cancel</i></a></li>
-                        <li><a class=\"button success\" href=\"\"><i class=\"fa fa-check\"> Submit</i></a></li>
-                    </ul>
+                   ".$this->form."
                 </div>
             </div>
         </div>

File diff suppressed because it is too large
+ 0 - 0
public/style/app.css


File diff suppressed because it is too large
+ 0 - 0
public/style/app.css.map


+ 7 - 0
public/timetrackerStyle/scss/_settings.scss

@@ -126,6 +126,11 @@ $primary-color: #374350;
  $info-color: #cde0e8;
 
 //TimeTracker
+
+.green {
+  color:$success-color;
+}
+
 .keyButton {
   font-size:1.5em !important;
   margin:0px !important;
@@ -361,7 +366,9 @@ $primary-color: #374350;
 // We use these to style anchors
 // $anchor-text-decoration: none;
 // $anchor-text-decoration-hover: none;
+
 // $anchor-font-color: $primary-color;
+   $anchor-font-color: #395ea7;
 // $anchor-font-color-hover: scale-color($anchor-font-color, $lightness: -14%);
 
 // We use these to style the <hr> element

Some files were not shown because too many files changed in this diff