Browse Source

timesheet view now reports vacation, sick, and normal time used for a specified date range.

Adam Day 9 years ago
parent
commit
29513cee8c

+ 3 - 0
application/controllers/timesheetController.php

@@ -82,6 +82,9 @@ class timesheetController extends Staple_Controller
 
         //Pass timesheet object to view
         $this->view->timesheet = $timesheet;
+
+        $changeYearForm = new changeYearForm();
+        $this->view->changeYearForm = $changeYearForm;
     }
 
     public function remove($id)

+ 26 - 0
application/forms/changeYearForm.php

@@ -0,0 +1,26 @@
+<?php
+
+class changeYearForm extends Staple_Form
+{
+    public function _start()
+    {
+        //$this->setLayout('');
+
+        $this->setName('changeYearForm');
+
+        $year = new Staple_Form_FoundationSelectElement('year','Year');
+        $year->setRequired();
+
+        $submit = new Staple_Form_FoundationSubmitElement('submit','Submit');
+        $submit->addClass('button expand radius');
+
+        $this->addField($year,$submit);
+    }
+
+    function getYears()
+    {
+
+    }
+}
+
+?>

+ 73 - 75
application/models/timesheetModel.php

@@ -22,6 +22,10 @@
 
 		private $entries;
 
+		private $vacationUsed;
+		private $normalWorked;
+		private $sickUsed;
+
 		/**
 		 * @return string
 		 */
@@ -246,6 +250,54 @@
 			$this->startDateTimeString = $startDateTimeString;
 		}
 
+		/**
+		 * @return int
+		 */
+		public function getVacationUsed()
+		{
+			return $this->vacationUsed;
+		}
+
+		/**
+		 * @param int $vacationUsed
+		 */
+		public function setVacationUsed($vacationUsed)
+		{
+			$this->vacationUsed = $vacationUsed;
+		}
+
+		/**
+		 * @return int
+		 */
+		public function getNormalWorked()
+		{
+			return $this->normalWorked;
+		}
+
+		/**
+		 * @param int $normalWorked
+		 */
+		public function setNormalWorked($normalWorked)
+		{
+			$this->normalWorked = $normalWorked;
+		}
+
+		/**
+		 * @return int
+		 */
+		public function getSickUsed()
+		{
+			return $this->sickUsed;
+		}
+
+		/**
+		 * @param int $sickUsed
+		 */
+		public function setSickUsed($sickUsed)
+		{
+			$this->sickUsed = $sickUsed;
+		}
+
 		function __construct($year, $month)
 		{
 			$this->db = Staple_DB::get();
@@ -286,8 +338,19 @@
 			//Time Entries
 			$this->entries = $this->entries($this->startDate, $this->endDate);
 
-			//Totals
-			$vacationTotal = $this->vacationEntries($this->startDate, $this->endDate);
+			$timeCode = new codeModel();
+
+			//Vacation Total
+			$code = $timeCode->getIdFor('vacation');
+			$this->vacationUsed = $this->calculatedTotals($code['id'],$this->startDate, $this->endDate);
+
+			//Normal Total
+			$code = $timeCode->getIdFor('normal');
+			$this->normalWorked = $this->calculatedTotals($code['id'],$this->startDate, $this->endDate);
+
+			//Sick Total
+			$code = $timeCode->getIdFor('sick');
+			$this->sickUsed = $this->calculatedTotals($code['id'],$this->startDate,$this->endDate);
 		}
 
 		function entries($startDate,$endDate)
@@ -314,88 +377,23 @@
 			}
 		}
 
-		function vacationEntries($startDate,$endDate)
+		function calculatedTotals($code,$startDate,$endDate)
 		{
 			//Get user ID from Auth
 			$user = new userModel();
 			$userId = $user->getId();
 
-			//Get vacation timecode ID.
-			$code = new codeModel();
-			$codes = $code->getIdFor('vacation');
-			$timeCode = $codes['id'];
-
-			$sql = "SELECT * FROM timeEntries WHERE inTime BETWEEN $this->startDateTimeString AND $this->endDateTimeString AND userId = $userId AND codeId = $timeCode";
-
-			echo $sql;
+			$sql = "SELECT ROUND((TIME_TO_SEC(SEC_TO_TIME(SUM(outTime - inTime)-SUM(lessTime*60)))/3600)*4)/4 AS 'totalTime' FROM timeEntries WHERE inTime > UNIX_TIMESTAMP('$startDate 00:00:00') AND outTime < UNIX_TIMESTAMP('$endDate 00:00:00') AND userId = $userId AND codeId = $code;";
 
-			if($this->db->query($sql)->fetch_row() > 0)
+			if($this->db->query($sql)->num_rows > 0)
 			{
 				$query = $this->db->query($sql);
 				$result = $query->fetch_assoc();
-
-				//Set inTime
-				$inTime = new DateTime();
-				$inTime->setTimestamp($result['inTime']);
-
-				//$this->setInTime($inTime->format('h:i A'));
-				$vacationInTime = $inTime->format('h:i A');
-
-				//$this->setInTimeRaw($result['inTime']);
-				$vacationInTimeRaw = $result['inTime'];
-
-				//$this->setRoundedInTime($this->nearestQuarterHour($result['inTime']));
-
-				/*
-				//Out Time
-				$outTime = new DateTime();
-				$outTime->setTimestamp($result['outTime']);
-				$this->setOutTime($outTime->format('h:i A'));
-				$this->setOutTimeRaw($result['outTime']);
-				$this->setRoundedOutTime($this->nearestQuarterHour($result['outTime']));
-
-				$this->setLessTime($result['lessTime']);
-
-				//Calculate Time Worked
-				switch($result['lessTime'])
-				{
-					case 60:
-						$lessTime = 1;
-						break;
-					case 30:
-						$lessTime = 0.5;
-						break;
-					case 15:
-						$lessTime = 0.25;
-						break;
-					default:
-						$lessTime = 0;
-				}
-
-				//Total Worked Time
-				$dateTime1 = new DateTime($this->roundedInTime);
-				$dateTime2 = new DateTime($this->roundedOutTime);
-				$interval = $dateTime1->diff($dateTime2);
-
-				$timeWorked = $this->timeToDecimal($interval->h.":".$interval->i)-$lessTime;
-
-				if($timeWorked !== 0)
-				{
-					$this->setTimeWorked($timeWorked);
-				}
-				else
-				{
-					$this->setTimeWorked(0);
-				}
-
-				//Get Code Information
-				$code = new codeModel();
-				$this->setCodeId($result['codeId']);
-				$code->load($result['codeId']);
-				$this->setCodeName($code->getName());
-
-				return true;
-				*/
+				return round($result['totalTime'],2);
+			}
+			else
+			{
+				return 0;
 			}
 		}
 	}

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

@@ -2,7 +2,7 @@
 <div class="section">
     <div class="row">
         <div class="small-12 medium-4 text-left columns">
-            <h3><?php echo $this->timesheet->currentMonthText." ".$this->timesheet->currentYear ?></h3>
+            <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">
@@ -18,7 +18,6 @@
             </ul>
         </div>
     </div>
-
 <?php
     if(count($this->timesheet->entries) > 0)
     {
@@ -85,4 +84,22 @@
     }
 
 ?>
+</div>
+<div class="section">
+    <div class="row">
+        <div class="small-4 text-center columns">
+            <h5><b>Total Hours Submitted:</b> <?php echo $this->timesheet->normalWorked ?></h5>
+        </div>
+        <div class="small-4 text-center columns">
+            <h5><b>Vacation Used:</b> <?php echo $this->timesheet->vacationUsed ?></h5>
+        </div>
+        <div class="small-4 text-center columns">
+            <h5><b>Sick Time Used:</b> <?php echo $this->timesheet->sickUsed ?></h5>
+        </div>
+    </div>
+</div>
+<div id="yearForm" class="reveal-modal small text-center" 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>
 </div>