ソースを参照

Working on getting timesheet validation working. Added a new MySQL template.

Adam Day 9 年 前
コミット
5a9154720a

+ 15 - 0
application/controllers/timesheetController.php

@@ -167,5 +167,20 @@ class timesheetController extends Staple_Controller
             header("location: ".$this->_link(array('timesheet'))."");
         }
     }
+
+    public function validate($year, $month)
+    {
+        $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;
+
+
+    }
 }
 ?>

+ 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 - 1
application/forms/layouts/insertFormLayout.phtml

@@ -53,10 +53,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({ minDate: "<?php echo date('m',strtotime('last month'))."/26/".date('Y') ?>", maxDate: "<?php echo date('m',strtotime('m'))."/25/".date('Y') ?>" });
         });
 
         $('#entryToggle').click(function()

+ 25 - 4
application/models/timeEntryModel.php

@@ -16,6 +16,7 @@
 		private $codeId;
         private $codeName;
         private $timeWorked;
+        private $batchId;
 
         /**
          * @return mixed
@@ -209,6 +210,22 @@
             $this->roundedOutTime = $roundedOutTime;
         }
 
+        /**
+         * @return mixed
+         */
+        public function getBatchId()
+        {
+            return $this->batchId;
+        }
+
+        /**
+         * @param mixed $batchId
+         */
+        public function setBatchId($batchId)
+        {
+            $this->batchId = $batchId;
+        }
+
 		function __construct($id = null)
 		{
             $this->db = Staple_DB::get();
@@ -223,6 +240,7 @@
 
                     //Set ID and Date
                     $this->setId($result['id']);
+                    $this->setBatchId($result['batchId']);
                     $this->setDate(date("m/d/Y",$result['inTime']));
 
                     //Set inTime
@@ -308,6 +326,7 @@
             $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());
@@ -315,13 +334,14 @@
             if($this->getId() == NULL)
 			{
 				//Insert new item
-				$sql = "INSERT INTO timeEntries (userId, inTime, outTime, lessTime, codeId)
+				$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($this->getCodeId())."',
+						'".$this->db->real_escape_string($batchId)."'
 						)";
 			}
 			else
@@ -332,8 +352,9 @@
 					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)."'
 				";
 			}
 			

+ 46 - 0
application/models/timesheetModel.php

@@ -20,6 +20,11 @@
 		private $previousMonthText;
 		private $previousYear;
 
+		private $validated;
+		private $validatedDate;
+		private $approved;
+		private $approvalDate;
+
 		private $entries;
 
 		private $vacationUsed;
@@ -353,6 +358,16 @@
 			$this->sickUsed = $this->calculatedTotals($code['id'],$this->startDate,$this->endDate);
 		}
 
+		function validated($startDate,$endDate)
+		{
+			//Get user ID from Auth
+			$user = new userModel();
+			$userId = $user->getId();
+
+
+
+		}
+
 		function entries($startDate,$endDate)
 		{
 			//Get user ID from Auth
@@ -396,6 +411,37 @@
 				return 0;
 			}
 		}
+
+		function genSetNewBatch()
+		{
+			$this->db = Staple_DB::get();
+
+			$id = $this->getId();
+
+			$key = sha1(time().$this->getUsername());
+
+			//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=$id";
+
+				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
 			{

+ 4 - 9
application/views/timesheet/index.phtml

@@ -5,17 +5,12 @@
             <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>
-                <?php
-                    if($this->validateRange)
-                    {
-                        echo "<li><a class=\"button small success\"><i class=\"fa fa-check\"></i> Validate</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>
             </ul>
         </div>
     </div>

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

@@ -0,0 +1,97 @@
+<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>
+        </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
+{
+    echo "
+            <div class=\"row\">
+                <div class=\"small-12 columns text-center\">
+                    No time submitted.
+                </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\">
+                    <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>
+                </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 */;