Эх сурвалжийг харах

Added a total drop down menu for the timesheet.

Adam Day 9 жил өмнө
parent
commit
adfc18c256

+ 22 - 0
application/controllers/timesheetController.php

@@ -145,5 +145,27 @@ class timesheetController extends Staple_Controller
             //header("location: ".$this->_link(array('timesheet'))."");
         }
     }
+
+    public function changeyear()
+    {
+        $form = new changeYearForm();
+        if($form->wasSubmitted())
+        {
+            $form->addData($_POST);
+            if($form->validate())
+            {
+                $data = $form->exportFormData();
+                header("location: ".$this->_link(array('timesheet',$data['year']))."");
+            }
+            else
+            {
+                header("location: ".$this->_link(array('timesheet'))."");
+            }
+        }
+        else
+        {
+            header("location: ".$this->_link(array('timesheet'))."");
+        }
+    }
 }
 ?>

+ 27 - 2
application/forms/changeYearForm.php

@@ -6,10 +6,13 @@ class changeYearForm extends Staple_Form
     {
         //$this->setLayout('');
 
-        $this->setName('changeYearForm');
+        $this->setName('changeYearForm')
+         ->setAction($this->link(array('timesheet','changeyear')));
 
         $year = new Staple_Form_FoundationSelectElement('year','Year');
-        $year->setRequired();
+        $year->setRequired()
+            ->addOptionsArray($this->getYears())
+            ->addValidator(new Staple_Form_Validate_InArray($this->getYears()));
 
         $submit = new Staple_Form_FoundationSubmitElement('submit','Submit');
         $submit->addClass('button expand radius');
@@ -19,6 +22,28 @@ class changeYearForm extends Staple_Form
 
     function getYears()
     {
+        $db = Staple_DB::get();
+
+        //Get user ID from Auth
+        $user = new userModel();
+        $userId = $user->getId();
+
+        $sql = "SELECT YEAR(FROM_UNIXTIME(inTime)) AS 'year' FROM timeEntries WHERE userId = $userId GROUP BY year ORDER by year ASC";
+
+        if($db->query($sql)->num_rows > 0)
+        {
+            $query = $db->query($sql);
+            $data = array();
+            while($result = $query->fetch_assoc())
+            {
+                $data[$result['year']] = $result['year'];
+            }
+            return $data;
+        }
+        else
+        {
+            return array();
+        }
 
     }
 }

+ 0 - 383
application/models/timesheetModel.php.backup

@@ -1,383 +0,0 @@
-<?php
-
-	class timesheetModel extends Staple_Model
-	{
-		private $db;
-
-		private $id;
-		private $userId;
-        private $date;
-		private $inTime;
-		private $outTime;
-		private $lessTime;
-		private $codeId;
-
-        /**
-         * @return mixed
-         */
-        public function getId()
-        {
-            return $this->id;
-        }
-
-        /**
-         * @param mixed $id
-         */
-        public function setId($id)
-        {
-            $this->id = $id;
-        }
-
-        /**
-         * @return mixed
-         */
-        public function getUserId()
-        {
-            return $this->userId;
-        }
-
-        /**
-         * @param mixed $userId
-         */
-        public function setUserId($userId)
-        {
-            $this->userId = $userId;
-        }
-
-        /**
-         * @return mixed
-         */
-        public function getDate()
-        {
-            return $this->date;
-        }
-
-        /**
-         * @param mixed $date
-         */
-        public function setDate($date)
-        {
-            $this->date = $date;
-        }
-
-        /**
-         * @return mixed
-         */
-        public function getInTime()
-        {
-            return $this->inTime;
-        }
-
-        /**
-         * @param mixed $inTime
-         */
-        public function setInTime($inTime)
-        {
-            $this->inTime = $inTime;
-        }
-
-        /**
-         * @return mixed
-         */
-        public function getOutTime()
-        {
-            return $this->outTime;
-        }
-
-        /**
-         * @param mixed $outTime
-         */
-        public function setOutTime($outTime)
-        {
-            $this->outTime = $outTime;
-        }
-
-        /**
-         * @return mixed
-         */
-        public function getLessTime()
-        {
-            return $this->lessTime;
-        }
-
-        /**
-         * @param mixed $lessTime
-         */
-        public function setLessTime($lessTime)
-        {
-            $this->lessTime = $lessTime;
-        }
-
-        /**
-         * @return mixed
-         */
-        public function getCodeId()
-        {
-            return $this->codeId;
-        }
-
-        /**
-         * @param mixed $codeId
-         */
-        public function setCodeId($codeId)
-        {
-            $this->codeId = $codeId;
-        }
-
-		function __construct()
-		{
-			$this->db = Staple_DB::get();
-		}	
-	
-		function load()
-		{
-			$authId = Staple_Auth::get()->getAuthId();
-			//Get User ID.
-
-            if(isset($authId))
-            {
-                $sql = "SELECT id FROM accounts WHERE username = '".$this->db->real_escape_string($authId)."'";
-
-                if($this->db->query($sql)->fetch_row() > 0)
-                {
-                    $query = $this->db->query($sql);
-                    $result = $query->fetch_assoc();
-
-                    $this->setUserId($result['id']);
-                }
-
-				if(isset($this->userId))
-				{
-					$sql = "SELECT * FROM timeEntries WHERE userId = '" . $this->db->real_escape_string($this->userId) . "' ORDER BY inTime ASC";
-
-					if ($this->db->query($sql)->fetch_row() > 0)
-					{
-						$query = $this->db->query($sql);
-						$data = array();
-						while ($row = $query->fetch_assoc())
-						{
-							$data[] = $row;
-						}
-
-						foreach($data as $entry)
-						{
-							$code = new codeModel();
-							$code->load($entry['codeId']);
-							$codeName = $code->getName();
-
-							$data2['id'] = $entry['id'];
-
-							//Set Date Object
-							$date = new DateTime();
-							$date->setTimestamp($entry['inTime']);
-
-							//Date
-							$data2['date']['ymd'] = $date->format("Y-m-d");
-
-							//Formatted Date
-							$data2['date']['formatted'] = $date->format("F jS, Y");
-
-							//Day
-							$data2['date']['dayOfWeek'] = $date->format("l");
-
-							//Day Abbreviated
-							$data2['date']['dayShort'] = $date->format("D.");
-
-							//MonthYear
-							$data2['date']['my'] = $date->format("m/y");
-
-                            //MonthDay
-                            $data2['date']['md'] = $date->format("m/d");
-
-                            //DateMonthYear
-                            $data2['date']['mdy'] = $date->format("m/d/y");
-
-							//In Time
-							$data2['rawInTime'] = $date->format("g:i A");
-							$data2['roundedInTime'] = $this->nearestQuarterHour($date->format("g:i A"));
-
-							//Out Time
-							$date->setTimestamp($entry['outTime']);
-							$data2['rawOutTime'] = $date->format("g:i A");
-							$data2['roundedOutTime'] = $this->nearestQuarterHour($date->format("g:i A"));
-
-							//Less Time
-							$data2['lessTime'] = $entry['lessTime'];
-
-                            switch($entry['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($data2['roundedInTime']);
-							$dateTime2 = new DateTime($data2['roundedOutTime']);
-							$interval = $dateTime1->diff($dateTime2);
-
-							$data2['timeWorked'] = $interval->h.":".$interval->i;
-
-                            $timeWorked = $this->timeToDecimal($interval->h.":".$interval->i)-$lessTime;
-
-                            if($timeWorked > 0)
-                            {
-                                $data2['timeWorkedDec'] = $timeWorked;
-                            }
-                            else
-                            {
-                                $data2['timeWorkedDec'] = 0;
-                            }
-
-							$data2['code'] = $codeName;
-
-							$data3[] = $data2;
-						}
-
-						return $data3;
-					}
-					else
-					{
-						return array();
-					}
-				}
-            }
-		}
-
-		private function nearestQuarterHour($time)
-		{
-			$time = strtotime($time);
-			$round = 15*60;
-			$rounded = round($time/$round)*$round;
-
-			return date("g:i A", $rounded);
-		}
-
-		private function timeToDecimal($time)
-		{
-			$timeArr = explode(':', $time);
-			$hours = $timeArr[0]*1;
-			$minutes = $timeArr[1]/60;
-			$dec = $hours + $minutes;
-
-            if($dec > 0)
-            {
-                return round($dec,2);
-            }
-            else
-            {
-                return 0;
-            }
-		}
-
-        function exists($id)
-        {
-            if($id !== null)
-            {
-                $sql = "SELECT id FROM timeEntries WHERE id = '".$this->db->real_escape_string($id)."'";
-
-                if($this->db->query($sql)->fetch_row() > 0)
-                {
-                    return true;
-                }
-            }
-        }
-
-        function remove($id)
-        {
-            if($id !== null)
-            {
-                $auth = Staple_Auth::get();
-                $user = new userModel($auth->getAuthId());
-                $userId = $user->getId();
-
-                $sql = "DELETE FROM timeEntries WHERE id = '".$this->db->real_escape_string($id)."' AND userId = '".$this->db->real_escape_string($userId)."'";
-
-                if($this->db->query($sql))
-                {
-                    return true;
-                }
-            }
-        }
-
-        function entry($id)
-        {
-            $sql = "SELECT * FROM timeEntries WHERE id = '".$this->db->real_escape_string($id)."'";
-
-            if($this->db->query($sql)->fetch_row() > 0)
-            {
-                $query = $this->db->query($sql);
-                $result = $query->fetch_assoc();
-
-                $data['date'] = date("m/d/Y",$result['inTime']);
-                $data['inTime'] = date("h:i A",$result['inTime']);
-                $data['outTime'] = date("h:i A",$result['outTime']);
-                $data['lessTime'] = $result['lessTime'];
-                $data['code'] = $result['codeId'];
-
-                return $data;
-
-            }
-            else
-            {
-                return array();
-            }
-        }
-
-		function save($id = null)
-		{
-            $inTime = strtotime($this->getDate()." ".$this->getInTime());
-            $outTime = strtotime($this->getDate()." ".$this->getOutTime());
-
-            if($id == null)
-			{
-                echo "Inserting";
-				//Insert new item
-				$sql = "INSERT INTO timeEntries (userId, inTime, outTime, lessTime, codeId)
-					VALUES (
-						'".$this->db->real_escape_string($this->getUserId())."',
-						'".$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())."'
-						)";
-			}
-			else
-			{
-
-                echo "Updating";
-				//Update item
-				$sql = "UPDATE timeEntries SET
-					userId='".$this->db->real_escape_string($this->getUserId())."',
-					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($id)."'
-				";
-			}
-			
-			$query = $this->db->query($sql);
-			
-			if($query === true)
-			{
-				return true;
-			}
-			else
-			{
-				return false;
-			}
-			
-		}
-
-	}
-
-?>

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

@@ -6,13 +6,14 @@
         </div>
         <div class="small-12 medium-8 text-right columns">
             <ul class="button-group radius even-4 stack-for-small">
-                <li><a class="button 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 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"><i class="fa fa-print"></i> Print</a></li>
+                <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 success\"><i class=\"fa fa-check\"></i> Validate</a></li>";
+                        echo "<li><a class=\"button small success\"><i class=\"fa fa-check\"></i> Validate</a></li>";
                     }
                 ?>
             </ul>
@@ -85,21 +86,49 @@
 
 ?>
 </div>
-<div class="section">
+
+<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>
+
+<div id="totals" class="totalsPanel">
     <div class="row">
-        <div class="small-4 text-center columns">
-            <h5><b>Total Hours Submitted:</b> <?php echo $this->timesheet->normalWorked ?></h5>
+        <div class="small-10 columns">
+            <h3 id="modalTitle"><i class="fa fa-calculator"></i> Totals for this month</h3>
         </div>
-        <div class="small-4 text-center columns">
-            <h5><b>Vacation Used:</b> <?php echo $this->timesheet->vacationUsed ?></h5>
+        <div class="small-2 columns text-right">
+            <a class="button secondary small radius toggleTotals" href="#"><i class="fa fa-chevron-up"></i></a>
         </div>
-        <div class="small-4 text-center columns">
-            <h5><b>Sick Time Used:</b> <?php echo $this->timesheet->sickUsed ?></h5>
+    </div>
+    <div class="row">
+        <div class="small-6 medium-4 large-3 columns totals">
+            <b>Total hours: </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 ?>
+        </div>
+        <div class="small-6 medium-4 large-3 columns totals end">
+            <b>Sick used: </b> <?php echo $this->timesheet->sickUsed ?>
         </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>
+
+<script>
+    $(function() {
+        $(".toggleTotals").click(function() {
+
+            if($("#totals").is(":visible"))
+            {
+                $('#entryForm').slideDown();
+            }
+            else
+            {
+                $('#entryForm').slideUp();
+            }
+
+            $("#totals").slideToggle();
+        });
+    });
+</script>

Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 0 - 0
public/style/app.css


Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 0 - 0
public/style/app.css.map


+ 15 - 14
public/timetrackerStyle/scss/_settings.scss

@@ -196,23 +196,24 @@ $primary-color: #374350;
   background-color: #fffea9;
 }
 
-.switch-on {
-  position: absolute;
-  left: -55px;
-  top: 10px;
-  color: white;
-  font-weight: bold;
-  font-size: 9px;
+.totals {
+  font-size:1.5em;
+  border-bottom:0px #eaeaea dotted;
+  padding:5px;
 }
 
-.switch-off {
-  position: absolute;
-  left: -25px;
-  top: 10px;
-  color: white;
-  font-weight: bold;
-  font-size: 9px;
+.totalsPanel {
+  background-color:#fff;
+  padding:20px;
+  border-bottom:10px $primary-color solid;
+  width:100%;
+  position:fixed;
+  top:0px;
+  left:0px;
+  display:none;
+  color:$primary-color;
 }
+
 // We use these to control various global styles
 // $body-bg: $white;
 // $body-font-color: $jet;

Энэ ялгаанд хэт олон файл өөрчлөгдсөн тул зарим файлыг харуулаагүй болно