Browse Source

Changed the timesheetmodel to appropriately handle the different time codes and to correctly tally up the total time worked for a specified time period.

Adam Day 9 years ago
parent
commit
ee6672ff52

+ 6 - 2
application/forms/insertTimeForm.php

@@ -26,12 +26,16 @@ class insertTimeForm extends Staple_Form
 
         $lessTime = new Staple_Form_FoundationSelectElement('lessTime','Less Time');
         $lessTime->setRequired()
-            ->addOptionsArray(array("0"=>"None","60"=>"1 Hour","30"=>"30 Minutes","15"=>"15 Minutes"));
+            ->addOptionsArray(array("0"=>"None","60"=>"1 Hour","30"=>"30 Minutes","15"=>"15 Minutes"))
+            ->addValidator(new Staple_Form_Validate_InArray(array('0','60','30','15')));
 
         $timeCodes = new codeModel();
         $code = new Staple_Form_FoundationSelectElement('code','Code');
         $code->setRequired()
-            ->addOptionsArray($timeCodes->allCodes());
+            ->addOption("x","Select an option")
+            ->addOptionsArray($timeCodes->allCodes())
+            ->addValidator(new Staple_Form_Validate_InArray(array_keys($timeCodes->allCodes())));
+        $code->setValue($timeCodes->getIdFor('Normal')['id']);
 
         $submit = new Staple_Form_FoundationSubmitElement('submit','Submit');
         $submit->addClass('button expand radius');

+ 4 - 3
application/models/codeModel.php

@@ -76,8 +76,8 @@
 		function __construct()
 		{
 			$this->db = Staple_DB::get();
-		}	
-	
+		}
+
 		function load($id = NULL)
 		{
 			$sql = "SELECT * FROM timeCodes WHERE id = '" . $this->db->real_escape_string($id) . "'";
@@ -96,7 +96,7 @@
 
 		function allCodes()
 		{
-			$sql = "SELECT id, name FROM timeCodes WHERE 1";
+			$sql = "SELECT id, name FROM timeCodes WHERE 1 ORDER BY name ASC";
 			if($this->db->query($sql)->fetch_row() > 0)
 			{
 				$query = $this->db->query($sql);
@@ -119,6 +119,7 @@
 				{
 					$query = $this->db->query($sql);
 					$result = $query->fetch_assoc();
+
 					return $result;
 				}
 			}

+ 100 - 10
application/models/timesheetModel.php

@@ -24,9 +24,14 @@
 
 		private $entries;
 
+		private $totals;
+
 		private $vacationUsed;
 		private $normalWorked;
 		private $sickUsed;
+		private $holidayUsed;
+		private $holidayWorkedUsed;
+		private $payPeriodTotal;
 
 		/**
 		 * @return string
@@ -316,6 +321,72 @@
 			$this->sickUsed = $sickUsed;
 		}
 
+		/**
+		 * @return float|int
+		 */
+		public function getHolidayUsed()
+		{
+			return $this->holidayUsed;
+		}
+
+		/**
+		 * @param float|int $holidayUsed
+		 */
+		public function setHolidayUsed($holidayUsed)
+		{
+			$this->holidayUsed = $holidayUsed;
+		}
+
+		/**
+		 * @return float|int
+		 */
+		public function getHolidayWorkedUsed()
+		{
+			return $this->holidayWorkedUsed;
+		}
+
+		/**
+		 * @param float|int $holidayWorkedUsed
+		 */
+		public function setHolidayWorkedUsed($holidayWorkedUsed)
+		{
+			$this->holidayWorkedUsed = $holidayWorkedUsed;
+		}
+
+		/**
+		 * @return float|int
+		 */
+		public function getPayPeriodTotal()
+		{
+			return $this->payPeriodTotal;
+		}
+
+		/**
+		 * @param float|int $payPeriodTotal
+		 */
+		public function setPayPeriodTotal($payPeriodTotal)
+		{
+			$this->payPeriodTotal = $payPeriodTotal;
+		}
+
+		/**
+		 * @return mixed
+		 */
+		public function getTotals()
+		{
+			return $this->totals;
+		}
+
+		/**
+		 * @param mixed $totals
+		 */
+		public function setTotals($totals)
+		{
+			$this->totals = $totals;
+		}
+
+
+
 		function __construct($year, $month)
 		{
 			$this->db = Staple_DB::get();
@@ -362,17 +433,16 @@
 
 			$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);
+			//Get time code totals
+			$totals = array();
+			foreach ($timeCode->allCodes() as $code)
+			{
+				$codeId = $timeCode->getIdFor($code);
+				$totals[$code] = $this->calculatedTotals($codeId['id'],$this->startDate,$this->endDate);
+			}
+			$totals['Total Time'] = array_sum($totals);
 
-			//Sick Total
-			$code = $timeCode->getIdFor('sick');
-			$this->sickUsed = $this->calculatedTotals($code['id'],$this->startDate,$this->endDate);
+			$this->setTotals($totals);
 		}
 
 		function validate($batchId)
@@ -409,6 +479,26 @@
 			}
 		}
 
+		function payPeriodCalculatedTotals($startDate, $endDate)
+		{
+			//Get user ID from Auth
+			$user = new userModel();
+			$userId = $user->getId();
+
+			$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";
+
+			if($this->db->query($sql)->num_rows > 0)
+			{
+				$query = $this->db->query($sql);
+				$result = $query->fetch_assoc();
+				return round($result['totalTime'],2);
+			}
+			else
+			{
+				return 0;
+			}
+		}
+
 		function calculatedTotals($code,$startDate,$endDate)
 		{
 			//Get user ID from Auth

+ 56 - 15
application/views/timesheet/index.phtml

@@ -20,6 +20,16 @@
         </div>
     </div><!-- end row -->
 <?php
+    echo "
+        <div class=\"row\">
+            <div class=\"small-12 columns\">
+                <ul class=\"inline-list right\">
+                    <li><a id=\"hideAll\" href=\"#\"><i class=\"fa fa-eye-slash\"></i> Hide All</a></li>
+                    <li><a id=\"showAll\" href=\"#\"><i class=\"fa fa-eye\"></i> Show All</a></li>
+                </ul>
+            </div>
+        </div>
+    ";
 
     if(count($this->timesheet->entries) > 0)
     {
@@ -45,19 +55,33 @@
                 </div>
             </div><!-- end row -->
         ";
+
         $date = 0;
 
         foreach($this->timesheet->entries as $entry)
         {
             if($date != $entry->date)
             {
-                echo "
+                if($this->timesheet->getBatch() != $entry->batchId)
+                {
+                    echo "
                     <div class=\"row marker\" style=\"border-bottom:1px #ccc solid; background-color:#eaeaea; padding-top:15px; padding-bottom:15px;\"> \n
                         <div class=\"small-12 columns timeTitle\" >
                             <b>".$entry->fullDate."</b><i class=\"right fa fa-chevron-up\"></i>\n
                         </div>
                     </div> <!-- end row --> \n
-                ";
+                    ";
+                }
+                else
+                {
+                    echo "
+                    <div class=\"row marker\" style=\"border-bottom:1px #ccc solid; background-color:#FFF4A8; padding-top:15px; padding-bottom:15px;\"> \n
+                        <div class=\"small-12 columns timeTitle\" >
+                            <b>".$entry->fullDate."</b><i class=\"right fa fa-chevron-up\"></i>\n
+                        </div>
+                    </div> <!-- end row --> \n
+                    ";
+                }
             }
 
             echo "
@@ -121,22 +145,25 @@
             <h3 id="modalTitle"><i class="fa fa-calculator"></i> Totals for this month</h3>
         </div>
         <div class="small-2 columns text-right">
-            <a class="button secondary small radius toggleTotals" href="#"><i class="fa fa-chevron-up"></i></a>
+            <a class="button small radius toggleTotals" href="#"><i class="fa fa-chevron-up"></i></a>
         </div>
     </div> <!-- end row -->
     <div class="row">
-        <div class="small-6 medium-4 large-3 columns totals">
-            <b>Normal: </b> <?php echo $this->timesheet->normalWorked ?>
-        </div>
-        <div class="small-6 medium-4 large-3 columns totals">
-            <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>Total: </b> <?php echo $this->timesheet->sickUsed ?>
-        </div>
+        <?php
+
+        foreach($this->timesheet->totals as $key=>$value)
+        {
+            if($value != '0')
+            {
+                echo "
+                    <div class=\"small-6 medium-4 columns totals end\">
+                    ".$key.": ".$value."
+                    </div>
+                ";
+            }
+        }
+
+        ?>
     </div>
 </div>
 
@@ -161,5 +188,19 @@
             $(this).find("i").toggleClass("fa-chevron-up fa-chevron-down")
         });
 
+        $("#hideAll").click(function() {
+           $(".marker").nextUntil(".marker").slideUp();
+            $(".marker").find("i").removeClass("fa-chevron-up")
+            $(".marker").find("i").addClass("fa-chevron-down")
+            return false;
+        });
+
+        $("#showAll").click(function() {
+            $(".marker").nextUntil(".marker").slideDown();
+            $(".marker").find("i").removeClass("fa-chevron-down")
+            $(".marker").find("i").addClass("fa-chevron-up")
+            return false;
+        });
+
     });
 </script>

File diff suppressed because it is too large
+ 0 - 0
public/scripts/jquery.knob.min.js


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


+ 2 - 2
public/timetrackerStyle/scss/_settings.scss

@@ -206,13 +206,13 @@ $primary-color: #315476;
 }
 
 .totals {
-  font-size:1.5em;
+  font-size:1.3em;
   border-bottom:0px #eaeaea dotted;
   padding:5px;
 }
 
 .totalsPanel {
-  background-color:#fff;
+  background-color:#eaeaea;
   padding:20px;
   border-bottom:10px $primary-color solid;
   width:100%;

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