Explorar el Código

Merge pull request #24 from advation/overrideDates

Override dates
Adam hace 9 años
padre
commit
a0f222643f

+ 3 - 1
application/controllers/indexController.php

@@ -6,7 +6,6 @@ class indexController extends Staple_Controller
 
 	public function _start()
 	{
-		$auth = Staple_Auth::get();
 		$user = new userModel();
 		$this->authLevel = $user->getAuthLevel();
 		$this->userId = $user->getId();
@@ -29,6 +28,9 @@ class indexController extends Staple_Controller
 		$report = new weeklyReportModel();
 
 		$this->view->week = $report->getWeekWorked($this->userId, $week, $year);
+
+		$unlock = new unlockModel();
+		$this->view->unlockedTimes = count($unlock->load($this->userId));
 	}
 }
 ?>

+ 83 - 16
application/controllers/reportsController.php

@@ -3,63 +3,130 @@
 class reportsController extends Staple_Controller
 {
     private $authLevel;
+    private $uid;
 
     public function _start()
     {
         $auth = Staple_Auth::get();
         $this->authLevel = $auth->getAuthLevel();
-        if($this->authLevel < 500)
-        {
-            header("location:".$this->_link(array('index','index'))."");
+        $user = new userModel();
+        $this->uid = $user->getId();
+        if ($this->authLevel < 500) {
+            header("location:" . $this->_link(array('index', 'index')) . "");
         }
     }
 
     public function index($year = null, $month = null)
     {
-        if($year == null)
-        {
+        if ($year == null) {
             $year = date('Y');
         }
 
-        if($month == null)
-        {
+        if ($month == null) {
             $month = date('m');
         }
 
         $report = new reportModel($year, $month);
         $this->view->report = $report->getTimesheets();
+
+        $timesheet = new timesheetModel($year, $month);
+        $this->view->nextMonth = $timesheet->getNextMonth();
+        $this->view->previousMonth = $timesheet->getPreviousMonth();
+        $this->view->year = $timesheet->getCurrentYear();
+        $yearForm = new changeYearForm();
+        $yearForm->setAction($this->_link(array('reports','changeyear')));
+        $this->view->yearForm = $yearForm;
+
+        $this->view->accountLevel = $this->authLevel;
     }
 
-    public function weekly()
+    public function changeyear()
     {
-        //Weekly report form
-        $form = new weeklyReportForm();
-
+        $form = new changeYearForm();
         if($form->wasSubmitted())
         {
             $form->addData($_POST);
             if($form->validate())
             {
+                $data = $form->exportFormData();
+                header("location: ".$this->_link(array('reports',$data['year']))."");
+            }
+            else
+            {
+                header("location: ".$this->_link(array('reports'))."");
+            }
+        }
+        else
+        {
+            header("location: ".$this->_link(array('reports'))."");
+        }
+    }
+
+    public function weekly()
+    {
+        //Weekly report form
+        $form = new weeklyReportForm();
+
+        if ($form->wasSubmitted()) {
+            $form->addData($_POST);
+            if ($form->validate()) {
                 $data = $form->exportFormData();
                 $report = new weeklyReportModel();
-                $this->view->report = $report->timeWorked($data['account'],$data['year']);
+                $this->view->report = $report->timeWorked($data['account'], $data['year']);
 
                 $account = new userModel();
                 $this->view->account = $account->userInfo($data['account']);
 
                 $this->view->year = $data['year'];
-            }
-            else
-            {
+            } else {
                 $this->view->form = $form;
             }
+        } else {
+            $this->view->form = $form;
+        }
+    }
+
+    public function unlock()
+    {
+        $auth = Staple_Auth::get();
+        $this->authLevel = $auth->getAuthLevel();
+        if ($this->authLevel < 900)
+        {
+            header("location:" . $this->_link(array('index', 'index')) . "");
         }
         else
         {
-            $this->view->form = $form;
+
+            $year = date('Y');
+            $month = date('m');
+
+            $timesheets = new reportModel($year, $month);
+
+            $this->view->accounts = $timesheets;
         }
+    }
 
+    public function unlockid($id)
+    {
+        $auth = Staple_Auth::get();
+        $this->authLevel = $auth->getAuthLevel();
 
+        if ($this->authLevel < 900)
+        {
+            header("location:" . $this->_link(array('index', 'index')) . "");
+        }
+        else
+        {
+            $unlock = new unlockModel();
 
+            if ($unlock->unlock($id))
+            {
+                $this->view->message = "<i class='fa fa-check'></i> Time entry unlocked.";
+            }
+            else
+            {
+                $this->view->message = "<i class='fa fa-close'></i> ERROR: Unable to unlock your own time entries.";
+            }
+        }
     }
 }

+ 124 - 39
application/controllers/timesheetController.php

@@ -1,9 +1,16 @@
 <?php
 class timesheetController extends Staple_Controller
 {
+    private $userId;
+    private $accountLevel;
+
     public function _start()
     {
-
+        $auth = Staple_Auth::get();
+        $user = new userModel();
+        $user->userInfo($auth->getAuthId());
+        $this->userId = $user->getId();
+        $this->accountLevel = $user->getAuthLevel();
     }
 
     public function index($year = null, $month = null)
@@ -215,39 +222,29 @@ class timesheetController extends Staple_Controller
                     //Date is within pay period
                     if($userDate >= $startDate && $userDate <= $endDate)
                     {
-                        //Compare in Times and out Times.
-                        //if(strtotime($data['inTime']) < strtotime($data['outTime']))
-                        //{
-                            //Create a new entry object and set properties
-                            $entry = new timeEntryModel();
-                            $entry->setId($id);
-                            $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->successMessage = array("<i class=\"fa fa-check\"></i> Entry saved for ".$data['date']."");
-                                $this->view->form = $form;
-                            }
-                            else
-                            {
-                                //Return the same form with a warning message
-                                $message = "<i class=\"fa fa-warning\"></i> Cannot insert overlapping time entries. If you are updating an already existing entry, remove that entry and submit a new one.";
-                                $form->errorMessage = array($message);
-                                $this->view->form = $form;
-                            }
-                        //}
-                        //else
-                        //{
-                            //Return the same form with error message.
-                        //    $form->errorMessage = array("<i class='fa fa-warning'></i> <b>'Time In'</b> entry cannot be before <b>'Time Out'</b> entry.");
-                        //    $this->view->form = $form;
-                        //}
+                        //Create a new entry object and set properties
+                        $entry = new timeEntryModel();
+                        $entry->setId($id);
+                        $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->successMessage = array("<i class=\"fa fa-check\"></i> Entry saved for ".$data['date']."");
+                            $this->view->form = $form;
+                        }
+                        else
+                        {
+                            //Return the same form with a warning message
+                            $message = "<i class=\"fa fa-warning\"></i> Cannot insert overlapping time entries. If you are updating an already existing entry, remove that entry and submit a new one.";
+                            $form->errorMessage = array($message);
+                            $this->view->form = $form;
+                        }
                     }
                     else
                     {
@@ -305,13 +302,16 @@ class timesheetController extends Staple_Controller
         $user = new userModel($auth->getAuthId());
         $batchId = $user->getBatchId();
 
-        //Check for unvalidated entries
+        //Check for unvalidated entries within the current pay period.
         $i = 0;
         foreach($timesheet->getEntries() as $entry)
         {
-            if($entry->batchId == $timesheet->getBatch())
+            if($entry->inTimeRaw >= $timesheet->getStartDateTimeString() && $entry->inTimeRaw <= $timesheet->getEndDateTimeString())
             {
-                $i++;
+                if($entry->batchId == $timesheet->getBatch())
+                {
+                    $i++;
+                }
             }
         }
 
@@ -324,8 +324,11 @@ class timesheetController extends Staple_Controller
 
             if($form->wasSubmitted())
             {
-                $timesheet->validate($batchId);
-                header("location:".$this->_link(array('timesheet'))."");
+                if($entry->inTimeRaw >= $timesheet->getStartDateTimeString() && $entry->inTimeRaw <= $timesheet->getEndDateTimeString())
+                {
+                    $timesheet->validate($batchId);
+                    header("location:" . $this->_link(array('timesheet')) . "");
+                }
             }
             else
             {
@@ -340,5 +343,87 @@ class timesheetController extends Staple_Controller
         }
 
     }
+
+    public function unlocked()
+    {
+        $form = new unlockDatesForm();
+
+        if($form->wasSubmitted())
+        {
+            $form->addData($_POST);
+            if($form->validate())
+            {
+                $data = $form->exportFormData();
+                echo "<pre>";
+                print_r($data);
+                echo "</pre>";
+            }
+            else
+            {
+                $this->view->form = $form;
+            }
+        }
+        else
+        {
+            $this->view->form = $form;
+        }
+
+    }
+
+    public function admininsert()
+    {
+        if($this->accountLevel >= 900)
+        {
+            $form = new insertTimeForm();
+            $form->admin(1);
+
+            if($form->wasSubmitted())
+            {
+                $form->addData($_POST);
+                if($form->validate())
+                {
+                    $data = $form->exportFormData();
+
+                    //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']);
+                    $entry->setUserId($data['account']);
+
+                    //Save entry data to table.
+                    if($entry->adminSave())
+                    {
+                        //Return a new time form with success message
+                        $form = new insertTimeForm();
+                        $form->admin(1);
+                        $form->successMessage = array("<i class=\"fa fa-check\"></i> Entry saved for ".$data['date']."");
+                        $this->view->form = $form;
+                    }
+                    else
+                    {
+                        //Return the same form with a warning message
+                        $message = "<i class=\"fa fa-warning\"></i> Administrative action not allowed on your own timesheet.";
+                        $form->errorMessage = array($message);
+                        $this->view->form = $form;
+                    }
+                }
+                else
+                {
+                    $this->view->form = $form;
+                }
+            }
+            else
+            {
+                $this->view->form = $form;
+            }
+        }
+        else
+        {
+            header("location: ".$this->_link(array('index'))."");
+        }
+    }
 }
 ?>

+ 2 - 1
application/forms/changeYearForm.php

@@ -33,7 +33,8 @@ class changeYearForm extends Staple_Form
         $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";
+        //$sql = "SELECT YEAR(FROM_UNIXTIME(inTime)) AS 'year' FROM timeEntries WHERE userId = $userId GROUP BY year ORDER by year ASC";
+        $sql = "SELECT YEAR(FROM_UNIXTIME(inTime)) AS 'year' FROM timeEntries GROUP BY year ORDER by year ASC";
 
         if($db->query($sql)->num_rows > 0)
         {

+ 102 - 0
application/forms/insertTimeForm.php

@@ -2,8 +2,48 @@
 
 class insertTimeForm extends Staple_Form
 {
+    private $accountLevel;
+    private $adminAction;
+
+    /**
+     * @return mixed
+     */
+    public function getAdminAction()
+    {
+        return $this->adminAction;
+    }
+
+    /**
+     * @param mixed $adminAction
+     */
+    public function setAdminAction($adminAction)
+    {
+        $this->adminAction = $adminAction;
+    }
+
+    /**
+     * @return mixed
+     */
+    public function getAccountLevel()
+    {
+        return $this->accountLevel;
+    }
+
+    /**
+     * @param mixed $accountLevel
+     */
+    public function setAccountLevel($accountLevel)
+    {
+        $this->accountLevel = $accountLevel;
+    }
+
     public function _start()
     {
+        $auth = Staple_Auth::get();
+        $user = new userModel();
+        $user->userInfo($auth->getAuthId());
+        $this->accountLevel = $user->getAuthLevel();
+
         $this->setLayout('insertFormLayout');
 
         $this->setName('insertTimeForm')
@@ -42,6 +82,68 @@ class insertTimeForm extends Staple_Form
 
         $this->addField($date, $inTime, $outTime, $lessTime, $code, $submit);
     }
+
+    public function admin($key)
+    {
+        if($key == 1)
+        {
+            $this->setAdminAction(1);
+            if($this->accountLevel >= 900)
+            {
+                if($this->adminAction == 1)
+                {
+                    $this->setAction($this->link(array('timesheet','admininsert')));
+                    $this->setLayout('adminInsertFormLayout');
+                    $account = new Staple_Form_FoundationSelectElement('account','Account');
+
+                    $account->setRequired()
+                        ->addOption('','Select an account')
+                        ->addOptionsArray($this->accounts())
+                        ->addValidator(new Staple_Form_Validate_InArray($this->accounts(1)));
+                    $this->addField($account);
+                }
+            }
+        }
+        else
+        {
+            $this->setAdminAction(0);
+        }
+
+    }
+
+    public function accounts($ids = null)
+    {
+        $user = new userModel();
+        $id = $user->getId();
+        $authLevel = $user->getAuthLevel();
+
+        $accounts = new userModel();
+        $users = $accounts->listAll();
+        $data = array();
+        if($ids == null)
+        {
+            foreach($users as $user)
+            {
+                if($user['supervisorId'] == $id)
+                {
+                    $data[$user['id']] = $user['lastName'].", ".$user['firstName']." (". $user['type'] .")";
+                }
+                elseif($authLevel >= 900)
+                {
+                    $data[$user['id']] = $user['lastName'].", ".$user['firstName']." (". $user['type'] .")";
+                }
+            }
+        }
+        else
+        {
+            foreach($users as $user)
+            {
+                $data[] = $user['id'];
+            }
+        }
+
+        return $data;
+    }
 }
 
 ?>

+ 119 - 0
application/forms/layouts/adminInsertFormLayout.phtml

@@ -0,0 +1,119 @@
+<div class="section">
+    <div class="row">
+        <div class="small-12 columns text-center">
+            <h2>Admin Time Insert</h2>
+        </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
+                    echo $this->formstart();
+                   ?>
+                </div>
+                <div class="row">
+                    <div class="small-12 medium-12 columns">
+                        <?php echo $this->fields['account'] ?>
+                    </div>
+                </div>
+                <div class="row">
+                    <div class="small-6 medium-4 columns">
+                        <?php echo $this->fields['date'] ?>
+                    </div>
+                    <div class="small-6 medium-4 columns">
+                        <?php echo $this->fields['inTime'] ?>
+                    </div>
+                    <div class="small-6 medium-4 columns">
+                        <?php echo $this->fields['outTime'] ?>
+                    </div>
+                </div>
+                <div class="row">
+                    <div class="small-6 medium-4 columns">
+                        <?php echo $this->fields['lessTime'] ?>
+                    </div>
+                    <div class="small-6 medium-4 columns">
+                        <?php echo $this->fields['code'] ?>
+                    </div>
+                    <div class="small-6 medium-4 columns">
+                        <br>
+                        <?php echo $this->fields['submit'] ?>
+                    </div>
+                    <?php echo $this->formend(); ?>
+                </div>
+            </div>
+        </div>
+    </div>
+</div>
+
+<script>
+    <?php
+    $date = new DateTime();
+
+    if($date->format('d') > 25)
+    {
+        $date->modify('+1 month');
+    }
+    $maxDate = $date->setDate($date->format('Y'),$date->format('m'),25)->format('m/d/Y');
+    $minDate = $date->modify('-1 month +1 day');
+    $minDate = $date->format('m/d/Y');
+    ?>
+
+    $(document).ready(function() {
+
+        $(function() {
+            $( "#date" ).datepicker({
+                numberOfMonths:2,
+                maxDate: "<?php echo $maxDate ?>",
+                showWeek: true,
+                showButtonPanel: true
+            });
+        });
+
+        $('#entryToggle').click(function()
+        {
+            if($('#entryForm').is(":visible"))
+            {
+                $('#entryToggleIcon').addClass('fa-chevron-circle-down');
+                $('#entryToggleIcon').removeClass('fa-chevron-circle-up');
+                $('#entryToggleText').html('Show');
+            }
+            else
+            {
+                $('#entryToggleIcon').addClass('fa-chevron-circle-up');
+                $('#entryToggleIcon').removeClass('fa-chevron-circle-down');
+                $('#entryToggleText').html('Hide')
+            }
+            $('#entryForm').slideToggle(400);
+        });
+
+
+    });
+</script>

+ 7 - 2
application/forms/layouts/insertFormLayout.phtml

@@ -82,9 +82,14 @@
     ?>
 
     $(document).ready(function() {
-
         $(function() {
-            $( "#date" ).datepicker({numberOfMonths:2, minDate: "<?php echo $minDate ?>", maxDate: "<?php echo $maxDate ?>" });
+            $( "#date" ).datepicker({
+                numberOfMonths:2,
+                minDate: "<?php echo $minDate ?>",
+                maxDate: "<?php echo $maxDate ?>",
+                showWeek: true,
+                showButtonPanel: true
+            });
         });
 
         $('#entryToggle').click(function()

+ 12 - 9
application/layouts/main.phtml

@@ -53,20 +53,23 @@
                         ";
                     }
 
-                    //Administrative Accounts
-                    if($user->getAuthLevel() >= 900)
-                    {
-                        echo "
-                            <li><a href=\"".$this->link(array('accounts')) ."\"><i class=\"fa fa-users\"></i> Accounts</a></li>
-                            <li><a href=\"".$this->link(array('audit')) ."\" ><i class=\"fa fa-list-alt\" ></i > Audit Log</a ></li >
-                        ";
-                    }
-
                     ?>
                 </ul>
 
                 <!-- Right Nav Section -->
                 <ul class="right">
+                    <?php
+                        //Administrative Accounts
+                        if($user->getAuthLevel() >= 900)
+                        {
+                            echo "
+                            <li><a href=\"".$this->link(array('accounts')) ."\"><i class=\"fa fa-users\"></i> Accounts</a></li>
+                            <li><a href=\"".$this->link(array('audit')) ."\" ><i class=\"fa fa-list-alt\" ></i > Audit Log</a ></li>
+                            <li><a href=\"".$this->link(array('reports','unlock'))."\"><i class=\"fa fa-unlock\"></i> Time Unlock</a></li>
+                            <li><a href=\"".$this->link(array('timesheet','admininsert'))."\" ><i class=\"fa fa-plus\" ></i > Admin Time Insert</a ></li>
+                            ";
+                        }
+                    ?>
                     <li><a href="<?php echo $this->link(array('account','logout')) ?>"><i class="fa fa-close"></i> Logout</a></li>
                 </ul>
             </section>

+ 2 - 2
application/models/auditModel.php

@@ -142,13 +142,13 @@ class auditModel extends Staple_Model
         if($uid == null)
         {
             $sql = "
-              SELECT * FROM audit ORDER BY timestamp ASC LIMIT ".$pager->getStartingItem().", ".$pager->getItemsPerPage()."
+              SELECT * FROM audit ORDER BY timestamp DESC LIMIT ".$pager->getStartingItem().", ".$pager->getItemsPerPage()."
             ";
         }
         else
         {
             $sql = "
-                SELECT * FROM audit WHERE userId = '".$this->db->real_escape_string($uid)."' ORDER BY timestamp ASC LIMIT ".$pager->getStartingItem().", ".$pager->getItemsPerPage()."
+                SELECT * FROM audit WHERE userId = '".$this->db->real_escape_string($uid)."' ORDER BY timestamp DESC LIMIT ".$pager->getStartingItem().", ".$pager->getItemsPerPage()."
             ";
         }
 

+ 1 - 1
application/models/reportModel.php

@@ -89,7 +89,7 @@ class reportModel extends Staple_Model
 
         while($result = $query->fetch_assoc())
         {
-            $data[] = $this->calculateEntry($result['id']);
+            $data[$result['id']] = $this->calculateEntry($result['id']);
         }
         return $data;
     }

+ 92 - 3
application/models/timeEntryModel.php

@@ -20,6 +20,7 @@
         private $codeName;
         private $timeWorked;
         private $batchId;
+        private $userId;
 
         /**
          * @return mixed
@@ -277,6 +278,22 @@
             $this->batchId = $batchId;
         }
 
+        /**
+         * @return mixed
+         */
+        public function getUserId()
+        {
+            return $this->userId;
+        }
+
+        /**
+         * @param mixed $userId
+         */
+        public function setUserId($userId)
+        {
+            $this->userId = $userId;
+        }
+
 		function __construct($id = null)
 		{
             $this->db = Staple_DB::get();
@@ -353,6 +370,8 @@
                     $code->load($result['codeId']);
                     $this->setCodeName($code->getName());
 
+                    $this->setUserId($result['userId']);
+
                     return true;
                 }
             }
@@ -366,16 +385,46 @@
                 $auth = Staple_Auth::get();
                 $user = new userModel($auth->getAuthId());
                 $userId = $user->getId();
+                $accountLevel = $user->getAuthLevel();
+
+                $entry = new timeEntryModel($id);
+                $fullDate = $entry->getFullDate();
+                $inTime = $entry->getInTime();
+                $outTime = $entry->getOutTime();
+                $effectedUserId = $entry->getUserId();
+
+                $effectedUser = new userModel();
+                $account = $effectedUser->userInfo($effectedUserId);
 
-                //Check if validated
-                if($this->validated($id))
+                //Check for admin account delete
+                if($accountLevel >= 900)
                 {
-                    $sql = "DELETE FROM timeEntries WHERE id = '".$this->db->real_escape_string($id)."' AND userId = '".$this->db->real_escape_string($userId)."'";
+                    $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))
                     {
+                        $audit = new auditModel();
+                        $audit->setUserId($account['id']);
+                        $audit->setAction('Admin Entry Remove');
+                        $audit->setItem($user->getUsername()." removed entry for ".$fullDate." In Time: ".$inTime." Out Time: ".$outTime."");
+                        $audit->save();
+
                         return true;
                     }
                 }
+                else
+                {
+                    //Check if validated
+                    if($this->validated($id))
+                    {
+                        $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;
+                        }
+                    }
+                }
             }
         }
 
@@ -589,5 +638,45 @@
             }
 
         }
+
+        function adminSave()
+        {
+            if(isset($this->userId))
+            {
+                //Check for current account.
+                $currentUser = new userModel();
+                if($this->userId != $currentUser->getId())
+                {
+                    $inTime = strtotime($this->getDate()." ".$this->getInTime());
+                    $outTime = strtotime($this->getDate()." ".$this->getOutTime());
+
+                    $sql = "
+                  INSERT INTO timeEntries
+                  (userId,inTime,outTime,lessTime,codeId,batchId)
+                  VALUES (
+                  '".$this->db->real_escape_string($this->userId)."',
+                  '".$this->db->real_escape_string($inTime)."',
+                  '".$this->db->real_escape_string($outTime)."',
+                  '".$this->db->real_escape_string($this->lessTime)."',
+                  '".$this->db->real_escape_string($this->codeId)."',
+                  '".$this->db->real_escape_string("ADMIN ADD")."'
+                  )
+                ";
+
+                    if($this->db->query($sql))
+                    {
+                        $user = new userModel();
+
+                        $audit = new auditModel();
+                        $audit->setUserId($this->userId);
+                        $audit->setAction('Admin Entry Add');
+                        $audit->setItem($user->getUsername()." added entry for ".$this->getDate().". In Time: ".$this->inTime."/Out Time: ".$this->outTime."");
+                        $audit->save();
+
+                        return true;
+                    }
+                }
+            }
+        }
 	}
 ?>

+ 1 - 1
application/models/timesheetModel.php

@@ -381,7 +381,7 @@
 			}
 		}
 
-		/* TODO depricate
+		/* TODO deprecate
 		function payPeriodCalculatedTotals($startDate, $endDate)
 		{
 			//Get user ID from Auth

+ 218 - 0
application/models/unlockModel.php

@@ -0,0 +1,218 @@
+<?php
+
+class unlockModel extends Staple_Model
+{
+    private $db;
+    private $username;
+    private $errors;
+
+    private $id;
+    private $date;
+    private $userId;
+
+    /**
+     * @return mixed
+     */
+    public function getId()
+    {
+        return $this->id;
+    }
+
+    /**
+     * @param mixed $id
+     */
+    public function setId($id)
+    {
+        $this->id = $id;
+    }
+
+    /**
+     * @return mixed
+     */
+    public function getDate()
+    {
+        $d = new DateTime();
+        $d->setTimestamp($this->date);
+        return $d->format('Y-m-d');
+    }
+
+    /**
+     * @param mixed $date
+     */
+    public function setDate($date)
+    {
+        $date = strtotime($date);
+        $d = new DateTime();
+        $d->setTimestamp($date);
+        $this->date = $d->format('U');
+    }
+
+    /**
+     * @return mixed
+     */
+    public function getUserId()
+    {
+        return $this->userId;
+    }
+
+    /**
+     * @param mixed $userId
+     */
+    public function setUserId($userId)
+    {
+        $this->userId = $userId;
+    }
+
+    /**
+     * @return mixed
+     */
+    public function getErrors()
+    {
+        return $this->errors;
+    }
+
+    /**
+     * @param mixed $errors
+     */
+    public function setErrors($errors)
+    {
+        $this->errors = $errors;
+    }
+
+
+
+    function __construct()
+    {
+        $this->db = Staple_DB::get();
+        $auth = Staple_Auth::get();
+        $this->username = $auth->getAuthId();
+    }
+
+    function load($uid)
+    {
+        $sql = "SELECT * FROM overrideDates WHERE userId = '".$this->db->real_escape_string($uid)."' ORDER BY date ASC";
+
+        if($this->db->query($sql)->fetch_row() > 0)
+        {
+            $query = $this->db->query($sql);
+
+            while($result = $query->fetch_assoc())
+            {
+                $data[] = $result;
+            }
+            return $data;
+        }
+    }
+
+    function save()
+    {
+        if(isset($this->date) && !isset($this->id))
+        {
+            $user = new userModel();
+            if($this->getUserId() != $user->getId())
+            {
+                //Check if date is in the currect pay period.
+                $timesheet = new timesheetModel(date('Y'),date('m'));
+                if($this->date < $timesheet->getStartDateTimeString())
+                {
+                    //Check for existing date
+                    $sql = "SELECT id FROM overrideDates WHERE date = '".$this->db->real_escape_string($this->date)."' AND userId = '".$this->db->real_escape_string($this->userId)."'";
+                    if($this->db->query($sql)->num_rows == 0)
+                    {
+                        //Check for already existing time entry
+                        $sql = "SELECT FROM_UNIXTIME(inTime,'%Y-%m-%d') AS date FROM timeEntries WHERE userId = '".$this->db->real_escape_string($this->userId)."'";
+
+                        $query = $this->db->query($sql);
+                        $matchDates = 0;
+                        while($result = $query->fetch_assoc())
+                        {
+                            $date = new DateTime();
+                            $date->setTimestamp($this->date);
+                            $submitDate = $date->format('Y-m-d');
+                            if($result['date'] == $submitDate)
+                            {
+                                $matchDates++;
+                            }
+                        }
+
+                        if($matchDates == 0)
+                        {
+                            $sql = "
+                              INSERT INTO overrideDates (date, userId) VALUES ('".$this->db->real_escape_string($this->date)."','".$this->db->real_escape_string($this->userId)."')
+                            ";
+
+                            if($this->db->query($sql))
+                            {
+                                $audit = new auditModel();
+                                $audit->setUserId($this->userId);
+                                $audit->setAction('Date unlock');
+                                $audit->setItem($this->username." unlocked date ".$this->getDate());
+                                $audit->save();
+
+                                return True;
+                            }
+                        }
+                        else
+                        {
+                            $this->errors[] = 'Time entry already exists for this date.';
+                        }
+                    }
+                    else
+                    {
+                        $this->errors[] = 'Unlock already submitted for this date.';
+                    }
+                }
+                else
+                {
+                    $this->errors[]  = "Date cannot be part of the current pay period.";
+                }
+            }
+            else
+            {
+                $this->errors[] = "Cannot unlock time entires for your own timesheet.";
+            }
+        }
+    }
+
+    function unlock($id)
+    {
+        $sql = "
+            SELECT userId FROM timeEntries WHERE id = '".$this->db->real_escape_string($id)."';
+        ";
+
+        if($this->db->query($sql)->num_rows > 0)
+        {
+            $query = $this->db->query($sql);
+            $result = $query->fetch_assoc();
+            $userId = $result['userId'];
+
+            $user = new userModel();
+            $user = $user->userInfo($userId);
+            $userId = $user['id'];
+            $batchId = $user['batchId'];
+
+            //Check if it's for the same user.
+            $currentUser = new userModel();
+            if($currentUser->getId() != $userId)
+            {
+                $sql = "
+                UPDATE timeEntries SET batchId = '".$this->db->real_escape_string($batchId)."' WHERE id = '".$this->db->real_escape_string($id)."'
+                ";
+
+                if($this->db->query($sql))
+                {
+                    $audit = new auditModel();
+                    $audit->setUserId($userId);
+                    $audit->setAction('Single unlock');
+                    $audit->setItem($this->username." unlocked time entry ". $id);
+                    $audit->save();
+
+                    return true;
+                }
+            }
+
+        }
+    }
+}
+
+?>

+ 1 - 0
application/models/userModel.php

@@ -195,6 +195,7 @@
 
 		function listAll()
 		{
+			$userId = $this->id;
 			$sql = "SELECT id, username, firstName, lastName, authLevel, batchId, supervisorId, type FROM accounts ORDER BY type DESC, lastName ASC, firstName ASC";
 			if($this->db->query($sql)->num_rows > 0)
 			{

+ 1 - 1
application/models/weeklyReportModel.php

@@ -77,7 +77,7 @@ class weeklyReportModel extends Staple_Model
         $ret['start']['year'] = $dto->format('Y');
 
         //Week End
-        $dto->modify('+5 days')->setTime(23,59,59);
+        $dto->modify('+6 days')->setTime(23,59,59);
         $ret['end']['unix'] = $dto->format('U');
         $ret['end']['formatted'] = $dto->format('Y-m-d');
         $ret['end']['dayName'] = $dto->format('l');

+ 2 - 2
application/views/audit/index.phtml

@@ -49,9 +49,9 @@
                 <thead>
                 <tr>
                     <th>Time Stamp</th>
-                    <th>Account</th>
+                    <th>Account Effected</th>
                     <th>Action</th>
-                    <th>Item</th>
+                    <th>Details</th>
                 </tr>
                 </thead>
                 <tbody>

+ 13 - 3
application/views/index/index.phtml

@@ -27,10 +27,20 @@
                 <div class='small-12 columns text-center'>
                     <h2>".$this->week['total']."</h2>
                 </div>
-            </div>
-        ";
+                ";
+
+                if($this->unlockedTimes > 0)
+                {
+                    echo "
+                        <div class='row'>
+                            <div class='small-12 column text-center'>
+                                <a class='button radius success' href=\"".$this->link(array('timesheet','unlocked'))."\"><i class='fa fa-calendar'></i> Submit time for previous pay period</a>
+                            </div>
+                        </div>
+                    ";
+                }
+        echo "</div></div>";
 
-        echo "</div>";
         echo "<div class='section'>";
 
         if($this->timesheet->totals['Total Time'] > 0)

+ 19 - 5
application/views/reports/index.phtml

@@ -5,16 +5,20 @@
         </div>
     </div>
     <div class="row">
-        <div class="small-6 columns">
+        <div class="small-4 columns">
             <ul class="button-group radius left">
-                <li><a class="button small" href="<?php echo $this->link(array('reports','weekly')) ?>">Week Report</a></li>
+                <li><a class="button small" href="<?php echo $this->link(array('reports','weekly')) ?>"><i class="fa fa-file"></i> Week Report</a></li>
             </ul>
         </div>
-        <div class="small-6 columns">
-            <ul class="button-group radius right">
+        <div class="small-8 columns">
+            <ul class="button-group round right">
+                <li><a class="button small secondary" href="<?php echo $this->link(array('reports',$this->year, $this->previousMonth))?> "><i class="fa fa-caret-left"></i> Previous</a></li>
+                <li><a class="button small secondary" href="<?php echo $this->link(array('reports',$this->year, $this->nextMonth))?> ">Next <i class="fa fa-caret-right"></i></a></li>
+                <li><a class="button small secondary" data-reveal-id="yearForm" href="#"><i class="fa fa-calendar"></i> Change Year</a></li>
                 <li><a id="showAll" class="button small secondary" href="#"><i class="fa fa-eye"></i> Show All</a></li>
                 <li><a id="hideAll" class="button small secondary" href="#"><i class="fa fa-eye-slash"></i> Hide All</a></li>
             </ul>
+
         </div>
     </div>
     <div class="row">
@@ -51,7 +55,7 @@
                 $totalVacation = 0;
                 $totalSick = 0;
 
-                foreach($timesheet as $entry)
+                foreach($timesheet as $key=>$entry)
                 {
                     echo "
                         <tr>
@@ -71,6 +75,11 @@
                         echo "<i class=\"fa fa-close red\"></i>";
                     }
 
+                    if($this->accountLevel >= 900)
+                    {
+                        echo " | <a href=\"".$this->link(array('timesheet','remove',$key))."\"><i class=\"fa fa-trash\"></i></a>";
+                    }
+
                     echo "</td>
                         </tr>
                     ";
@@ -140,6 +149,11 @@
         </div>
     </div>
 </div>
+<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->yearForm ?>
+    <a class="close-reveal-modal" aria-label="Close">&#215;</a>
+</div>
 
 <script>
     $(function() {

+ 99 - 0
application/views/reports/unlock.phtml

@@ -0,0 +1,99 @@
+<div class="section">
+    <div class="row">
+        <div class="small-12 columns">
+            <h2><i class="fa fa-unlock"></i> Time Unlock</h2>
+        </div>
+    </div>
+    <div class="row">
+        <div class="small-12 columns">
+            <hr>
+            <h3>Current Pay Period Entry Unlock</h3>
+            <?php
+                if(count($this->accounts->timesheets) > 0)
+                {
+                    foreach($this->accounts->timesheets as $account=>$timesheet)
+                    {
+                        if(count($timesheet) > 0)
+                        {
+                            $validatedTotal = 0;
+                            foreach($timesheet as $entry)
+                            {
+                                if($entry['validated'] == 1)
+                                {
+                                    $validatedTotal++;
+                                }
+                            }
+
+                            echo "<h4 class='timeTitle'>$account <i class='fa fa-chevron-down right'></i></h4>";
+                            echo "<div class='wrapper hide'>";
+                            if($validatedTotal > 0)
+                            {
+                                echo "
+                                    <table width='100%'>
+                                        <tr>
+                                               <th>Date</th>
+                                               <th>Start Time</th>
+                                               <th>End Time</th>
+                                               <th>Code</th>
+                                               <th>Action</th>
+                                        </tr>
+                                ";
+
+                                foreach($timesheet as $id=>$entry)
+                                {
+                                    if($entry['validated'] == 1)
+                                    {
+                                        echo "
+                                        <tr>
+                                            <td>".$entry['date']."</td>
+                                            <td>".date("g:i A",$entry['inTime'])."</td>
+                                            <td>".date("g:i A",$entry['outTime'])."</td>
+                                            <td>".$entry['code']."</td>
+                                            <td><a href=\"".$this->link(array('reports','unlockid',$id))."\"><i class='fa fa-unlock-alt'></i> Unlock</td>
+                                        </tr>
+                                        ";
+                                    }
+                                }
+                            }
+                            else
+                            {
+                                echo "<div class='text-center'>No validated time submitted for this pay period.</div>";
+                            }
+                            echo "</table></div> <!-- end wrapper -->";
+                        }
+                    }
+                }
+            ?>
+        </div>
+    </div>
+</div>
+
+<script>
+    $(function() {
+        $( "#date" ).datepicker({
+            numberOfMonths: 2,
+            showWeek: true,
+            showButtonPanel: true
+        });
+
+        $(".timeTitle").click(function() {
+            $(this).next(".wrapper").slideToggle("slow");
+            $(this).find("i").toggleClass("fa-chevron-up fa-chevron-down")
+            return false;
+        });
+
+        $("#hideAll").click(function() {
+            $(".wrapper").slideUp();
+            $(".timeTitle").find("i").removeClass("fa-chevron-up")
+            $(".timeTitle").find("i").addClass("fa-chevron-down")
+            return false;
+        });
+
+        $("#showAll").click(function() {
+            $(".wrapper").slideDown();
+            $(".timeTitle").find("i").removeClass("fa-chevron-down")
+            $(".timeTitle").find("i").addClass("fa-chevron-up")
+            return false;
+        });
+    });
+</script>

+ 18 - 0
application/views/reports/unlockid.phtml

@@ -0,0 +1,18 @@
+<div class="section">
+    <div class="row">
+        <div class="small-12 columns">
+            <h1><i class="fa fa-unlock"></i> Time Unlock</h1>
+        </div>
+    </div>
+    <div class="row">
+        <div class="small-12 columns text-center">
+            <div class="panel">
+            <?php echo $this->message ?>
+            </div>
+        </div>
+        <div class="small-12 columns text-center">
+            <a class="button secondary" href="<?php echo $this->link(array('reports','unlock')) ?>">Back</a>
+        </div>
+    </div>
+</div>
+

+ 13 - 8
application/views/reports/weekly.phtml

@@ -15,6 +15,17 @@
                     echo "
                         <div class='row'>
                             <div class='small-6 columns'>
+
+                            </div>
+                            <div class='small-6 columns'>
+                                <a class='button secondary radius right' href='".$this->link(array('reports','weekly'))."'>Back</a>
+                            </div>
+                        </div>
+
+                    <table width=\"100%\">
+                        <thead>
+                        <tr>
+                            <th colspan='2' class='text-center'>
                                 <h3>".$this->account['firstName']." ".$this->account['lastName']." (";
 
                                     if($this->account['type'] == "part")
@@ -27,14 +38,8 @@
                                     }
 
                                 echo")</h3>
-                            </div>
-                            <div class='small-6 columns'>
-                                <a class='button secondary radius right' href='".$this->link(array('reports','weekly'))."'>Back</a>
-                            </div>
-                        </div>
-
-                    <table width=\"100%\">
-                        <thead>
+                            </th>
+                        </tr>
                         <tr>
                             <th width='50%'>Week</th>
                             <th width='50%'>Hours Worked</th>

+ 1 - 0
application/views/timesheet/admininsert.phtml

@@ -0,0 +1 @@
+<?php echo $this->form ?>

+ 12 - 0
application/views/timesheet/unlocked.phtml

@@ -0,0 +1,12 @@
+<div class="section">
+    <div class="row">
+        <div class="small-12">
+            <h2>Previous Timesheet Entries</h2>
+        </div>
+    </div>
+    <div class="row">
+        <div class="small-12">
+            <?php echo $this->form ?>
+        </div>
+    </div>
+</div>

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 0 - 0
public/style/app.css


La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 0 - 0
public/style/app.css.map


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

@@ -1466,19 +1466,31 @@ $primary-color: #315476;
 // 31. Tabs
 // - - - - - - - - - - - - - - - - - - - - - - - - -
 
+.tabs {
+  border:1px #eaeaea solid;
+  background-color:$secondary-color;
+}
+
+.tabs-content {
+  border-color:#eaeaea;
+  border-style:solid;
+  border-width:0px 1px 1px 1px;
+}
+
 // $include-html-tabs-classes: $include-html-classes;
 
 // $tabs-navigation-padding: rem-calc(16);
-// $tabs-navigation-bg-color: $silver;
-// $tabs-navigation-active-bg-color: $white;
+$tabs-navigation-bg-color: $secondary-color;
+$tabs-navigation-active-bg-color: #fff;
 // $tabs-navigation-hover-bg-color: scale-color($tabs-navigation-bg-color, $lightness: -6%);
 // $tabs-navigation-font-color: $jet;
-// $tabs-navigation-active-font-color: $tabs-navigation-font-color;
+ //$tabs-navigation-active-font-color: #fff;
 // $tabs-navigation-font-size: rem-calc(16);
 // $tabs-navigation-font-family: $body-font-family;
 
 // $tabs-content-margin-bottom: rem-calc(24);
 // $tabs-content-padding: ($column-gutter/2);
+  $tabs-content-padding:10px;
 
 // $tabs-vertical-navigation-margin-bottom: 1.25rem;
 

Algunos archivos no se mostraron porque demasiados archivos cambiaron en este cambio