Browse Source

Merge pull request #2 from advation/timesheetValidation

Timesheet validation
Adam 9 years ago
parent
commit
b247fb67fb

+ 118 - 31
application/controllers/timesheetController.php

@@ -27,43 +27,79 @@ class timesheetController extends Staple_Controller
                 //Export form data into an array
                 $data = $form->exportFormData();
 
-                //Compare in Times and out Times.
-                if(strtotime($data['inTime']) < strtotime($data['outTime']))
+                //Check if dates are within the current pay period.
+                $startMonth = date('m',strtotime('last month'));
+
+                if($startMonth == 1)
+                {
+                    $startYear = date('Y',strtotime('last year'));
+                }
+                else
+                {
+                    $startYear = date('Y');
+                }
+
+                $endMonth = date('m');
+                $endYear = date('Y');
+
+                $startDate= strtotime($startMonth.'/26/'.$startYear);
+                $endDate = strtotime($endMonth.'/25/'.$endYear);
+
+                $userDate = strtotime($data['date']);
+
+                //Date is within pay period
+                if($userDate >= $startDate && $userDate <= $endDate)
                 {
-                    //Create a new entry object
-                    $entry = new timeEntryModel();
-                    $entry->setDate($data['date']);
-                    $entry->setInTime($data['inTime']);
-                    $entry->setOutTime($data['outTime']);
-                    $entry->setLessTime($data['lessTime']);
-                    $entry->setCodeId($data['code']);
-
-                    if($entry->save())
+                    //Compare in Times and out Times.
+                    if(strtotime($data['inTime']) < strtotime($data['outTime']))
                     {
-                        $this->view->message = "Entry saved.";
-                        $form = new insertTimeForm();
-                        $this->view->insertTimeForm = $form;
+                        //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;
+                        }
                     }
                     else
                     {
-                        $this->view->message = "ERROR: Unable to save entry.";
+                        //Return the same form with error message.
+                        $form->errorMessage = array("<b>'Time In'</b> entry cannot be before <b>'Time Out'</b> entry.");
                         $this->view->insertTimeForm = $form;
                     }
                 }
                 else
                 {
-                    //Send form with error message back.
-                    $form->message = array("<b>'Time In'</b> entry cannot be before <b>'Time Out'</b> entry.");
+                    //Return the same form with error message.
+                    $form->errorMessage = array("<i class='fa fa-warning'></i> You may only submit time for the current date period.");
                     $this->view->insertTimeForm = $form;
                 }
             }
             else
             {
+                //Return form with invalid data.
                 $this->view->insertTimeForm = $form;
             }
         }
         else
         {
+            //Return form
             $this->view->insertTimeForm = $form;
         }
 
@@ -86,6 +122,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;
     }
@@ -124,20 +179,7 @@ class timesheetController extends Staple_Controller
         if($id != null)
         {
             $entry = new timeEntryModel($id);
-            if($entry)
-            {
-                $form = new editTimeForm();
-                $form->setAction($this->_link(array('timesheet','edit',$id)));
-                //$form->addData();
-
-                $this->view->form = $form;
-
-            }
-            else
-            {
-                echo "Entry loaded";
-                //header("location: ".$this->_link(array('timesheet'))."");
-            }
+            print_r($entry);
         }
         else
         {
@@ -167,5 +209,50 @@ class timesheetController extends Staple_Controller
             header("location: ".$this->_link(array('timesheet'))."");
         }
     }
+
+    public function validate($year, $month)
+    {
+        $timesheet = new timesheetModel($year,$month);
+
+        //Get Current Batch ID
+        $auth = Staple_Auth::get();
+        $user = new userModel($auth->getAuthId());
+        $batchId = $user->getBatchId();
+
+        //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);
+                header("location:".$this->_link(array('timesheet'))."");
+            }
+            else
+            {
+                $this->view->form = $form;
+                $this->view->needsValidation = false;
+            }
+        }
+        else
+        {
+            $this->view->needsValidation = false;
+            $this->view->timesheet = array();
+        }
+
+    }
 }
 ?>

+ 1 - 1
application/forms/accountForm.php

@@ -12,7 +12,7 @@ class accountForm extends Staple_Form
 		$pin = new Staple_Form_FoundationPasswordElement('pin','User PIN');
 		$pin->setRequired()
 			->addAttrib("readonly","true")
-			->addValidator(new Staple_Form_Validate_Length(4,4))
+			->addValidator(new Staple_Form_Validate_Length(1,4))
 			->addValidator(new Staple_Form_Validate_Numeric());
 
 		$submit = new Staple_Form_FoundationSubmitElement('submit','Submit');

+ 2 - 3
application/forms/insertTimeForm.php

@@ -11,18 +11,17 @@ class insertTimeForm extends Staple_Form
 
         $date = new Staple_Form_FoundationTextElement('date','Date');
         $date->setRequired()
-            ->addValidator(new Staple_Form_Validate_Length('1','10'))
             ->addValidator(new Staple_Form_Validate_Date())
             ->addAttrib('placeholder','mm/dd/yyyy');
 
         $inTime = new Staple_Form_FoundationTextElement('inTime','Time In');
         $inTime->setRequired()
-            ->addValidator(new Staple_Form_Validate_Length('1','8'))
+            ->addValidator(new Staple_Form_Validate_Regex('/^(0|[0-9]|1[012]):[0-5][0-9] ?((a|p)m|(A|P)M)$/','Invalid time format. Expected format: h:mm am/pm.'))
             ->addAttrib('placeholder','h:mm am/pm');
 
         $outTime = new Staple_Form_FoundationTextElement('outTime','Time Out');
         $outTime->setRequired()
-            ->addValidator(new Staple_Form_Validate_Length('1','8'))
+            ->addValidator(new Staple_Form_Validate_Regex('/^(0|[0-9]|1[012]):[0-5][0-9] ?((a|p)m|(A|P)M)$/','Invalid time format. Expected format: h:mm am/pm.'))
             ->addAttrib('placeholder','h:mm am/pm');;
 
         $lessTime = new Staple_Form_FoundationSelectElement('lessTime','Less Time');

+ 31 - 14
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 data-alert class=\"alert-box warning\">";
+                foreach($this->errorMessage as $message)
+                {
+                    echo $message;
+                }
+                echo "<a href=\"#\" class=\"close\">&times;</a></div>";
+
+            }
+
+            if(count($this->successMessage) > 0)
+            {
+
+                echo "<div data-alert class=\"alert-box success\">";
+                foreach($this->successMessage as $message)
+                {
+                    echo $message;
+                }
+                echo "<a href=\"#\" class=\"close\">&times;</a></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">
@@ -53,10 +69,11 @@
 </div>
 
 <script>
+    <?php $timesheet = new timesheetModel(date('Y'),date('m')) ?>
     $(document).ready(function() {
 
         $(function() {
-            $( "#date" ).datepicker({ minDate: "<?php echo date("m/d/Y", strtotime("-2 month + 23 days")) ?>", maxDate: "<?php echo date("m/d/Y", strtotime("+6 month")) ?>" });
+            $( "#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') ?>" });
         });
 
         $('#entryToggle').click(function()

+ 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);
+        }
+    }
+
+?>

+ 96 - 18
application/models/timeEntryModel.php

@@ -6,6 +6,7 @@
 
 		private $id;
         private $date;
+        private $fullDate;
         private $inTime;
         private $inTimeRaw;
         private $roundedInTime;
@@ -16,6 +17,7 @@
 		private $codeId;
         private $codeName;
         private $timeWorked;
+        private $batchId;
 
         /**
          * @return mixed
@@ -209,6 +211,38 @@
             $this->roundedOutTime = $roundedOutTime;
         }
 
+        /**
+         * @return mixed
+         */
+        public function getBatchId()
+        {
+            return $this->batchId;
+        }
+
+        /**
+         * @param mixed $batchId
+         */
+        public function setBatchId($batchId)
+        {
+            $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();
@@ -223,7 +257,9 @@
 
                     //Set ID and Date
                     $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();
@@ -308,40 +344,63 @@
             $auth = Staple_Auth::get();
             $user = new userModel($auth->getAuthId());
             $userId = $user->getId();
+            $batchId = $user->getBatchId();
 
             $inTime = strtotime($this->getDate()." ".$this->getInTime());
             $outTime = strtotime($this->getDate()." ".$this->getOutTime());
 
             if($this->getId() == NULL)
 			{
-				//Insert new item
-				$sql = "INSERT INTO timeEntries (userId, inTime, outTime, lessTime, codeId)
-					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())."'
-						)";
+                //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
+                {
+                    return false;
+                }
 			}
 			else
 			{
+                //TODO Check for overlap
+
 				//Update item
 				$sql = "UPDATE timeEntries SET
 					userId='".$this->db->real_escape_string($userId)."',
 					inTime='".$this->db->real_escape_string($inTime)."',
 					outTime='".$this->db->real_escape_string($outTime)."',
 					lessTime='".$this->db->real_escape_string($this->getLessTime())."',
-                    codeId='".$this->db->real_escape_string($this->getCodeId())."'
-					WHERE id='".$this->db->real_escape_string($this->getId())."'
+                    codeId='".$this->db->real_escape_string($this->getCodeId())."',
+                    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;
+                }
 			}
 		}
 
@@ -371,5 +430,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;
+            }
+        }
 	}
 ?>

+ 99 - 35
application/models/timesheetModel.php

@@ -20,6 +20,8 @@
 		private $previousMonthText;
 		private $previousYear;
 
+		private $batch;
+
 		private $entries;
 
 		private $vacationUsed;
@@ -91,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()
 		{
@@ -99,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
 		 */
@@ -205,53 +239,37 @@
 		/**
 		 * @return mixed
 		 */
-		public function getEntries()
+		public function getBatch()
 		{
-			return $this->entries;
+			return $this->batch;
 		}
 
 		/**
-		 * @param mixed $entries
+		 * @param mixed $batch
 		 */
-		public function setEntries($entries)
+		public function setBatch($batch)
 		{
-			$this->entries = $entries;
+			$this->batch = $batch;
 		}
 
 		/**
-		 * @return int
-		 */
-		public function getEndDateTimeString()
-		{
-			return $this->endDateTimeString;
-		}
-
-		/**
-		 * @param int $endDateTimeString
+		 * @return array
 		 */
-		public function setEndDateTimeString($endDateTimeString)
+		public function getEntries()
 		{
-			$this->endDateTimeString = $endDateTimeString;
+			return $this->entries;
 		}
 
 		/**
-		 * @return int
+		 * @param array $entries
 		 */
-		public function getStartDateTimeString()
-		{
-			return $this->startDateTimeString;
-		}
-
-		/**
-		 * @param int $startDateTimeString
-		 */
-		public function setStartDateTimeString($startDateTimeString)
+		public function setEntries($entries)
 		{
-			$this->startDateTimeString = $startDateTimeString;
+			$this->entries = $entries;
 		}
 
 		/**
-		 * @return int
+		 * @return float|int
 		 */
 		public function getVacationUsed()
 		{
@@ -259,7 +277,7 @@
 		}
 
 		/**
-		 * @param int $vacationUsed
+		 * @param float|int $vacationUsed
 		 */
 		public function setVacationUsed($vacationUsed)
 		{
@@ -267,7 +285,7 @@
 		}
 
 		/**
-		 * @return int
+		 * @return float|int
 		 */
 		public function getNormalWorked()
 		{
@@ -275,7 +293,7 @@
 		}
 
 		/**
-		 * @param int $normalWorked
+		 * @param float|int $normalWorked
 		 */
 		public function setNormalWorked($normalWorked)
 		{
@@ -283,7 +301,7 @@
 		}
 
 		/**
-		 * @return int
+		 * @return float|int
 		 */
 		public function getSickUsed()
 		{
@@ -291,7 +309,7 @@
 		}
 
 		/**
-		 * @param int $sickUsed
+		 * @param float|int $sickUsed
 		 */
 		public function setSickUsed($sickUsed)
 		{
@@ -302,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);
@@ -353,6 +375,16 @@
 			$this->sickUsed = $this->calculatedTotals($code['id'],$this->startDate,$this->endDate);
 		}
 
+		function validate($batchId)
+		{
+			//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)
 		{
 			//Get user ID from Auth
@@ -396,6 +428,38 @@
 				return 0;
 			}
 		}
+
+		function genSetNewBatch()
+		{
+			$this->db = Staple_DB::get();
+
+			$user = new userModel();
+			$userId = $user->getId();
+
+			$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)."'";
+			if($this->db->query($sql)->fetch_row() > 0)
+			{
+				//Key already in use
+				return false;
+			}
+			else
+			{
+				//Set new key in user account
+				$sql = "UPDATE accounts SET batchId='".$this->db->real_escape_string($key)."' WHERE id=$userId";
+
+				if($this->db->query($sql))
+				{
+					return true;
+				}
+				else
+				{
+					return false;
+				}
+			}
+		}
 	}
 
 ?>

+ 19 - 1
application/models/userModel.php

@@ -9,6 +9,7 @@
 		private $firstName;
 		private $lastName;
 		private $accountType;
+		private $batchId;
 
 		/**
 		 * @return mixed
@@ -90,6 +91,22 @@
 			$this->accountType = $accountType;
 		}
 
+		/**
+		 * @return mixed
+		 */
+		public function getBatchId()
+		{
+			return $this->batchId;
+		}
+
+		/**
+		 * @param mixed $batchId
+		 */
+		public function setBatchId($batchId)
+		{
+			$this->batchId = $batchId;
+		}
+
 		function __construct()
 		{
 			$this->db = Staple_DB::get();
@@ -97,7 +114,7 @@
 			$auth = Staple_Auth::get();
 			$username = $auth->getAuthId();
 
-			$sql = "SELECT id, username, firstName, lastName, accountType FROM accounts WHERE username = '".$this->db->real_escape_string($username)."'";
+			$sql = "SELECT id, username, firstName, lastName, accountType, batchId FROM accounts WHERE username = '".$this->db->real_escape_string($username)."'";
 			if($this->db->query($sql)->fetch_row() > 0)
 			{
 				$query = $this->db->query($sql);
@@ -108,6 +125,7 @@
 				$this->setFirstName($result['firstName']);
 				$this->setLastName($result['lastName']);
 				$this->setAccountType($result['accountType']);
+				$this->setBatchId($result['batchId']);
 			}
 			else
 			{

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

@@ -5,21 +5,22 @@
             <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-4 stack-for-small">
+            <ul class="button-group radius 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"><i class="fa fa-calculator"></i> Totals</a></li>
-                <li><a class="button small"><i class="fa fa-print"></i> Print</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>
                 <?php
-                    if($this->validateRange)
+                    if($this->needsValidation)
                     {
-                        echo "<li><a class=\"button small success\"><i class=\"fa fa-check\"></i> Validate</a></li>";
+                        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 "
@@ -37,21 +38,42 @@
                     <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\">
-                    <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 "<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\">
                     <span data-tooltip aria-haspopup=\"true\" class=\"has-tip\" title=\"Entered as: ".$entry->inTime."\">".$entry->roundedInTime."</span>
@@ -63,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
@@ -87,7 +110,7 @@
 ?>
 </div>
 
-<div id="yearForm" class="reveal-modal small text-center" data-reveal aria-labelledby="Change Year" aria-hidden="true" role="dialog">
+<div id="yearForm" class="reveal-modal small" data-reveal aria-labelledby="Change Year" aria-hidden="true" role="dialog">
     <h2 id="modalTitle">Select a Year</h2>
     <?php echo $this->changeYearForm ?>
     <a class="close-reveal-modal" aria-label="Close">&#215;</a>
@@ -104,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>

+ 108 - 0
application/views/timesheet/validate.phtml

@@ -0,0 +1,108 @@
+<div class="section">
+    <div class="row">
+        <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>
+
+<div class="section">
+<?php
+
+if(count($this->timesheet) > 0)
+{
+    echo "
+            <div class=\"row\">
+                <div class=\"small-4 medium-2 columns\">
+                    <b>Date</b>
+                </div>
+                <div class=\"small-4 medium-2 columns\">
+                    <b>Time In</b> <small>(Adjusted)</small>
+                </div>
+                <div class=\"small-4 medium-2 columns\">
+                    <b>Time Out</b> <small>(Adjusted)</small>
+                </div>
+                <div class=\"small-4 medium-2 columns\">
+                    <b>Less Time</b>
+                </div>
+                <div class=\"small-4 medium-2 columns\">
+                    <b>Time Worked</b>
+                </div>
+                <div class=\"small-4 medium-2 columns\">
+                    <b>Time Code</b>
+                </div>
+                <hr>
+            </div>
+        ";
+
+    foreach($this->timesheet->entries as $entry)
+    {
+        echo "
+            <div class=\"row\">
+                <div class=\"small-4 medium-2 columns\">
+                    ".$entry->date."
+                </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>
+                </div>
+                <div class=\"small-4 medium-2 columns\">
+                    <span data-tooltip aria-haspopup=\"true\" class=\"has-tip\" title=\"Entered as: ".$entry->outTime."\">".$entry->roundedOutTime."</span>
+                </div>
+                <div class=\"small-4 medium-2 columns\">
+                    ".$entry->lessTime." Min.
+                </div>
+                <div class=\"small-4 medium-2 columns\">
+                    <b>".$entry->timeWorked."</b> Hours
+                </div>
+                <div class=\"small-4 medium-2 columns\">
+                    ".$entry->codeName."
+                </div>
+                <hr>
+            </div>
+            ";
+    }
+}
+else
+{
+    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>
+            ";
+    }
+}
+
+?>
+</div>
+
+<?php
+
+if(count($this->timesheet) > 0)
+{
+    echo "
+        <div class=\"section\">
+            <div class=\"row\">
+                <div class=\"small-12 medium-6 medium-centered columns\">
+                   ".$this->form."
+                </div>
+            </div>
+        </div>
+    ";
+}
+?>

+ 0 - 59
mysql/timeEntries.sql

@@ -1,59 +0,0 @@
--- phpMyAdmin SQL Dump
--- version 4.4.13.1deb1
--- http://www.phpmyadmin.net
---
--- Host: localhost
--- Generation Time: Nov 03, 2015 at 05:17 PM
--- Server version: 5.6.27-0ubuntu1
--- PHP Version: 5.6.11-1ubuntu3.1
-
-SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
-SET time_zone = "+00:00";
-
-
-/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
-/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
-/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
-/*!40101 SET NAMES utf8mb4 */;
-
---
--- Database: `timetracker`
---
-
--- --------------------------------------------------------
-
---
--- Table structure for table `timeEntries`
---
-
-CREATE TABLE IF NOT EXISTS `timeEntries` (
-  `id` int(11) NOT NULL,
-  `userId` int(11) NOT NULL,
-  `inTime` int(11) NOT NULL,
-  `outTime` int(11) NOT NULL,
-  `lessTime` int(11) NOT NULL,
-  `codeId` int(11) NOT NULL
-) ENGINE=InnoDB AUTO_INCREMENT=30 DEFAULT CHARSET=latin1;
-
---
--- Indexes for dumped tables
---
-
---
--- Indexes for table `timeEntries`
---
-ALTER TABLE `timeEntries`
-  ADD PRIMARY KEY (`id`);
-
---
--- AUTO_INCREMENT for dumped tables
---
-
---
--- AUTO_INCREMENT for table `timeEntries`
---
-ALTER TABLE `timeEntries`
-  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=30;
-/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
-/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
-/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

+ 163 - 0
mysql/timeTracker.sql

@@ -0,0 +1,163 @@
+-- phpMyAdmin SQL Dump
+-- version 4.4.13.1deb1
+-- http://www.phpmyadmin.net
+--
+-- Host: localhost
+-- Generation Time: Nov 05, 2015 at 05:04 PM
+-- Server version: 5.6.27-0ubuntu1
+-- PHP Version: 5.6.11-1ubuntu3.1
+
+SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
+SET time_zone = "+00:00";
+
+
+/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
+/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
+/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
+/*!40101 SET NAMES utf8mb4 */;
+
+--
+-- Database: `timetracker`
+--
+
+-- --------------------------------------------------------
+
+--
+-- Table structure for table `accounts`
+--
+
+CREATE TABLE IF NOT EXISTS `accounts` (
+  `id` int(11) NOT NULL,
+  `username` varchar(255) NOT NULL,
+  `password` varchar(255) NOT NULL,
+  `pin` varchar(255) NOT NULL,
+  `firstName` varchar(255) NOT NULL,
+  `lastName` varchar(255) NOT NULL,
+  `accountType` varchar(255) NOT NULL,
+  `batchId` varchar(255) NOT NULL
+) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=latin1;
+
+--
+-- Dumping data for table `accounts`
+--
+
+INSERT INTO `accounts` (`id`, `username`, `password`, `pin`, `firstName`, `lastName`, `accountType`, `batchId`) VALUES
+(6, 'test', 'a94a8fe5ccb19ba61c4c0873d391e987982fbbd3', '7110eda4d09e062aa5e4a390b0a572ac0d2c0220', 'Test', 'Tester', '900', '12345');
+
+-- --------------------------------------------------------
+
+--
+-- Table structure for table `timeCodes`
+--
+
+CREATE TABLE IF NOT EXISTS `timeCodes` (
+  `id` int(11) NOT NULL,
+  `name` varchar(20) NOT NULL,
+  `multiplier` int(11) NOT NULL,
+  `description` text NOT NULL
+) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=latin1;
+
+--
+-- Dumping data for table `timeCodes`
+--
+
+INSERT INTO `timeCodes` (`id`, `name`, `multiplier`, `description`) VALUES
+(1, 'Normal', 1, 'Normal time entry. '),
+(2, 'Vacation', 1, 'Normal Vacation entry.'),
+(3, 'Sick', 1, 'Normal sick entry. '),
+(4, 'Holiday', 1, 'Normal Holiday entry. '),
+(5, 'Holiday - Worked', 2, 'Holiday worked rate. ');
+
+-- --------------------------------------------------------
+
+--
+-- Table structure for table `timeEntries`
+--
+
+CREATE TABLE IF NOT EXISTS `timeEntries` (
+  `id` int(11) NOT NULL,
+  `userId` int(11) NOT NULL,
+  `inTime` int(11) NOT NULL,
+  `outTime` int(11) NOT NULL,
+  `lessTime` int(11) NOT NULL,
+  `codeId` int(11) NOT NULL,
+  `batchId` varchar(255) NOT NULL
+) ENGINE=InnoDB AUTO_INCREMENT=64 DEFAULT CHARSET=latin1;
+
+--
+-- Dumping data for table `timeEntries`
+--
+
+INSERT INTO `timeEntries` (`id`, `userId`, `inTime`, `outTime`, `lessTime`, `codeId`, `batchId`) VALUES
+(1, 1, 12345, 12345, 0, 0, '12345');
+
+-- --------------------------------------------------------
+
+--
+-- Table structure for table `timeSheetBatches`
+--
+
+CREATE TABLE IF NOT EXISTS `timeSheetBatches` (
+  `id` int(11) NOT NULL,
+  `batchId` int(255) NOT NULL,
+  `approved` int(1) NOT NULL,
+  `approvedDate` int(11) NOT NULL,
+  `approvalUserId` int(3) NOT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+
+--
+-- Indexes for dumped tables
+--
+
+--
+-- Indexes for table `accounts`
+--
+ALTER TABLE `accounts`
+  ADD PRIMARY KEY (`id`),
+  ADD UNIQUE KEY `pin` (`pin`);
+
+--
+-- Indexes for table `timeCodes`
+--
+ALTER TABLE `timeCodes`
+  ADD PRIMARY KEY (`id`);
+
+--
+-- Indexes for table `timeEntries`
+--
+ALTER TABLE `timeEntries`
+  ADD PRIMARY KEY (`id`);
+
+--
+-- Indexes for table `timeSheetBatches`
+--
+ALTER TABLE `timeSheetBatches`
+  ADD PRIMARY KEY (`id`);
+
+--
+-- AUTO_INCREMENT for dumped tables
+--
+
+--
+-- AUTO_INCREMENT for table `accounts`
+--
+ALTER TABLE `accounts`
+  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=7;
+--
+-- AUTO_INCREMENT for table `timeCodes`
+--
+ALTER TABLE `timeCodes`
+  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=6;
+--
+-- AUTO_INCREMENT for table `timeEntries`
+--
+ALTER TABLE `timeEntries`
+  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=64;
+--
+-- AUTO_INCREMENT for table `timeSheetBatches`
+--
+ALTER TABLE `timeSheetBatches`
+  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
+/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
+/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
+/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

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


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

@@ -126,6 +126,15 @@ $primary-color: #374350;
  $info-color: #cde0e8;
 
 //TimeTracker
+
+.green {
+  color:$success-color;
+}
+
+.orange {
+  color:$warning-color !important;
+}
+
 .keyButton {
   font-size:1.5em !important;
   margin:0px !important;
@@ -361,7 +370,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: #79797e;
 // $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