public function run()
 {
     $faker = Faker::create();
     foreach (range(1, 10) as $index) {
         Workshift::create([]);
     }
 }
 public function parseEditData($postArr)
 {
     $tmpObj = new Workshift();
     if (!empty($postArr['txtShiftId']) && !empty($postArr['txtShiftName']) && !empty($postArr['txtHoursPerDay'])) {
         $tmpObj->setWorkshiftId($postArr['txtShiftId']);
         $tmpObj->setName($postArr['txtShiftName']);
         $tmpObj->setHoursPerDay($postArr['txtHoursPerDay']);
         $assignedEmployees = array();
         if (isset($postArr['cmbAssignedEmployees']) && is_array($postArr['cmbAssignedEmployees'])) {
             foreach ($postArr['cmbAssignedEmployees'] as $empNum) {
                 $assignedEmployees[] = $empNum;
             }
         }
     }
     return array($tmpObj, $assignedEmployees);
 }
 public function getEdit($id = false)
 {
     if (!$id) {
         return App::abort(404);
     }
     $item = Position::find($id);
     if (!$item) {
         return App::abort(404);
     }
     $departments = Department::whereNotNull("parent_id")->orderBy("name")->get();
     $roles = Positionrole::orderBy("name")->get();
     $positions = Position::select(["positions.id", "positions.name", "departments.name as department_name"])->leftjoin("departments", "departments.id", "=", "positions.department_id")->where("positions.id", "<>", $id)->orderBy("departments.name")->orderBy("positions.name")->take(100)->get();
     $workshifts = Workshift::all();
     $content = View::make("positions/edit", ["roles" => $roles, "positions" => $positions, "departments" => $departments, "item" => $item, "workshifts" => $workshifts]);
     return View::make("common/tpl", array("template" => $content));
 }
Exemple #4
0
 /**
  * Test method for deleteWorkshifts().
  */
 public function testDeleteWorkshifts()
 {
     // Parameter is not an array
     try {
         Workshift::deleteWorkshifts(null);
         $this->fail("null parameter allowed");
     } catch (WorkshiftException $e) {
         $this->assertEquals(WorkshiftException::INVALID_PARAMETER, $e->getCode());
     }
     try {
         Workshift::deleteWorkshifts(2);
         $this->fail("integer parameter allowed");
     } catch (WorkshiftException $e) {
         $this->assertEquals(WorkshiftException::INVALID_PARAMETER, $e->getCode());
     }
     // Empty array
     $idArray = array();
     try {
         Workshift::deleteWorkshifts($idArray);
         $this->fail("Empty array allowed");
     } catch (WorkshiftException $e) {
         $this->assertEquals(WorkshiftException::INVALID_PARAMETER, $e->getCode());
     }
     // array contains invalid ids
     $idArray = array(1, 2, -1, 4);
     try {
         Workshift::deleteWorkshifts($idArray);
         $this->fail("Invalid id's allowed");
     } catch (WorkshiftException $e) {
         $this->assertEquals(WorkshiftException::INVALID_ID, $e->getCode());
     }
     $this->assertTrue(mysql_query("INSERT INTO " . Workshift::WORKSHIFT_TABLE . " VALUES ('1' , 'Work shift 1', '5')"));
     $this->assertTrue(mysql_query("INSERT INTO " . Workshift::WORKSHIFT_TABLE . " VALUES ('2' , 'Work shift 2', '5')"));
     $this->assertTrue(mysql_query("INSERT INTO " . Workshift::WORKSHIFT_TABLE . " VALUES ('3' , 'Work shift 3', '5')"));
     $this->assertTrue(mysql_query("INSERT INTO " . Workshift::WORKSHIFT_TABLE . " VALUES ('4' , 'Work shift 4', '5')"));
     // array contains id's not in database
     $idArray = array(1, 2, 23);
     Workshift::deleteWorkshifts($idArray);
     $this->assertEquals(2, $this->_countRows(Workshift::WORKSHIFT_TABLE));
     $this->assertEquals(2, $this->_countRows(Workshift::WORKSHIFT_TABLE, "workshift_id IN (3, 4)"));
     $this->assertTrue(mysql_query("TRUNCATE TABLE `hs_hr_workshift`", $this->connection));
     $this->assertTrue(mysql_query("INSERT INTO " . Workshift::WORKSHIFT_TABLE . " VALUES ('1' , 'Work shift 1', '5')"));
     $this->assertTrue(mysql_query("INSERT INTO " . Workshift::WORKSHIFT_TABLE . " VALUES ('2' , 'Work shift 2', '5')"));
     $this->assertTrue(mysql_query("INSERT INTO " . Workshift::WORKSHIFT_TABLE . " VALUES ('3' , 'Work shift 3', '5')"));
     $this->assertTrue(mysql_query("INSERT INTO " . Workshift::WORKSHIFT_TABLE . " VALUES ('4' , 'Work shift 4', '5')"));
     // array contains valid ids
     $idArray = array(1, 2, 3);
     Workshift::deleteWorkshifts($idArray);
     $this->assertEquals(1, $this->_countRows(Workshift::WORKSHIFT_TABLE));
     $row = $this->_getWorkshift(4);
     $this->assertNotNull($row);
     $this->assertEquals("Work shift 4", $row['name']);
     $this->assertEquals(5, $row['hours_per_day']);
 }
Exemple #5
0
    //return View::make('admin.scheduling', ['employeeInfo' => $employeeInfo, 'getUserEmployee' => $getUserEmployee]);
    if (!empty($groups)) {
        if (strcmp(strtolower($groups->name), strtolower('Employee')) !== 0) {
            return View::make('admin.scheduling', ['employeeInfo' => $employeeInfo, 'getUserEmployee' => $getUserEmployee]);
        } else {
            //http://jsfiddle.net/umz8t/458/
            //http://stackoverflow.com/questions/16344354/how-to-make-blinking-flashing-text-with-css3
            echo '<body style="background-color:#000000;"><p style="text-align:center; font-size:75px; color:#00ff00;">_We are watching you (>_<)</p></body>';
        }
    }
}));
Route::post('/admin/scheduling/search/default/schedule/', array('as' => '', 'uses' => function () {
    //$data = Input::all();
    $data['employee_number'] = Input::get('employee_number');
    $employeeNumber = Employee::where('employee_number', '=', trim($data['employee_number']))->first();
    $defaultSchedules = Workshift::where('employee_id', '=', trim($employeeNumber->id))->get();
    $employeeId = Session::get('userEmployeeId');
    $employee = new Employee();
    $employeeInfo = $employee->getEmployeeInfoById($employeeId);
    $getUserEmployee = DB::table('users')->join('employees', 'users.employee_id', '=', 'employees.id')->join('users_groups', 'users_groups.user_id', '=', 'users.id')->join('groups', 'users_groups.group_id', '=', 'groups.id')->get();
    return View::make('admin.scheduling', ['employeeInfo' => $employeeInfo, 'getUserEmployee' => $getUserEmployee, 'defaultSchedules' => $defaultSchedules]);
    //return View::make('admin.scheduling', ['employeeInfo' => $employeeInfo, 'defaultSchedules' => $defaultSchedules]);
}));
Route::post('/admin/scheduling/upload/new/schedule', array('as' => 'adminUploadNewSchedule', 'uses' => 'EmployeesController@postShift'));
Route::post('/admin/scheduling/search/uploaded/schedule', array('as' => '', 'uses' => function () {
    $data = Input::all();
    //$data['employee_number'] = Input::get('employee_number');
    $employeeNumber = Employee::where('employee_number', '=', trim($data['employee_number']))->first();
    $uploadedSchedules = Schedule::where('employee_id', '=', trim($employeeNumber->id))->whereBetween('schedule_date', array($data["schedule_date_from"], $data["schedule_date_to"]))->get();
    $employeeId = Session::get('userEmployeeId');
    $employee = new Employee();
    */
    return Redirect::to('users/login');
});
// Show the login form
Route::get('/users/login', array('as' => 'usersLogin', 'uses' => 'UsersController@showLogin'));
// Process the login form
Route::post('/users/login', array('as' => 'processLogin', 'uses' => 'UsersController@doLogin'));
// Logging Out
Route::get('users/logout', array('uses' => 'UsersController@doLogout'));
Route::get('/employee/servertime', array('before' => 'auth', 'as' => 'updateServerTime', 'uses' => 'EmployeesController@updateServerTime'));
Route::get('/employee/serverdatetime', array('before' => 'auth', 'as' => 'getServerDateTime', 'uses' => 'EmployeesController@getServerDateTime'));
Route::get('/employee/clocking', array('before' => 'auth', 'as' => 'employeeTimesheet', 'uses' => 'EmployeesController@showEmployeeTimesheet'));
Route::post('/employee/clocking', array('as' => 'timeClocking', 'uses' => function () {
    $data = Input::all();
    echo Session::put('timeclocking', $data['timeclocking']);
    $workShift = new Workshift();
    $getWorkShift = $workShift->getWorkShiftByEmployeeId(Auth::user()->employee_id);
    $todayDate = date('Y-m-d');
    $holiday = new Holiday();
    $getHolidayByDate = $holiday->getHolidayByDate($todayDate);
    //var_dump($employeeClocking);
    //$employeeId = Auth::user()->employee_id;
    //$workShift = DB::table('work_shift')->where('employee_id', $employeeId)->get();
    $timesheet = new Timesheet();
    $getTimesheetById = $timesheet->getTimesheetById(Auth::user()->employee_id, date('Y-m-d'));
    $schedule = new Schedule();
    $hasSchedule = $schedule->checkSchedule(Auth::user()->employee_id, date('Y-m-d'));
    $getSchedule = $schedule->getSchedule(Auth::user()->employee_id, date('Y-m-d'));
    //Deduction Model
    $deduction = new Deduction();
    $hasNightShiftStartTimeThreshold = true;
@extends('layouts.admin.default')

@section('content')

<?php 
//Todo: Put this in the Workshift controller
$workShift = Workshift::all();
$schedule = array();
?>

<div class="page-container">

        <div class="row" style="padding-bottom:20px;">

          <div class="col-md-2 clearfix">

            <aside class="sidebar">
              <nav class="sidebar-nav">
                <ul id="menu">
                  <li>
                    <a href="{{ url('/admin/dashboard') }}">
                      <span class="sidebar-nav-item-icon fa fa-tachometer fa-lg"></span>                      
                      <span class="sidebar-nav-item">Dashboard</span>                      
                    </a>
                    
                  </li>
                  <li>
                    <a href="#">
                      <span class="sidebar-nav-item-icon fa fa-users fa-lg"></span>                      
                      <span class="sidebar-nav-item">Employees</span>                      
                    </a>
Exemple #8
0
 /**
  * Display leave information
  *
  * @param boolean $admin Show admin view or ess user view
  * @param Exception $exception Exception class (used to display any errors from previous apply/assign)
  */
 public function displayLeaveInfo($admin = false, $exception = null)
 {
     $authorizeObj = $this->authorize;
     if ($admin) {
         if ($authorizeObj->getIsAdmin() == 'Yes') {
             $empObj = new EmpInfo();
             $tmpObjs[0] = array(true);
         } else {
             if ($authorizeObj->isSupervisor()) {
                 $empRepToObj = new EmpRepTo();
                 $tmpObjs[0] = $empRepToObj->getEmpSubDetails($authorizeObj->getEmployeeId());
             }
         }
         $roles = array(authorize::AUTHORIZE_ROLE_ADMIN, authorize::AUTHORIZE_ROLE_SUPERVISOR);
         $role = $authorizeObj->firstRole($roles);
         $previousLeave = null;
         if (isset($_GET['id'])) {
             $leaveObj = new Leave();
             $previousLeaves = $leaveObj->retrieveLeave($_GET['id']);
             $previousLeave = $previousLeaves[0];
             if ($authorizeObj->getIsAdmin() != 'Yes' && $authorizeObj->isSupervisor() && !$authorizeObj->isTheSupervisor($previousLeave->getEmployeeId())) {
                 $previousLeave = null;
             }
         }
         $this->setId($_SESSION['empID']);
         $tmpObj = new LeaveType();
         $tmpObjs[1] = $tmpObj->fetchLeaveTypes();
         $tmpObjs[2] = $role;
         $tmpObjs[3] = $previousLeave;
         $tmpObjs['allEmpWorkshits'] = Workshift::getWorkshiftForAllEmployees();
     } else {
         $this->setId($_SESSION['empID']);
         $tmpObj = new LeaveQuota();
         $tmpObj->setYear(date('Y'));
         $tmpObjs[1] = $tmpObj->fetchLeaveQuota($this->getId());
         $workShift = Workshift::getWorkshiftForEmployee($this->getId());
         $shiftLength = isset($workShift) ? $workShift->getHoursPerDay() : Leave::LEAVE_LENGTH_FULL_DAY;
         $tmpObjs['shiftLength'] = $shiftLength;
     }
     $this->setObjLeave($tmpObjs);
     $path = "/templates/leave/leaveApply.php";
     if (!empty($exception)) {
         $tmpObjs['exception'] = $exception;
     }
     $template = new TemplateMerger($tmpObjs, $path);
     $template->display();
 }
 public function getRemove($id = false)
 {
     if (!$id) {
         return App::abort(404);
     }
     $item = Workshift::find($id);
     if (!$item) {
         return App::abort(404);
     }
     $item->delete();
     return Redirect::to("/structure/workshifts")->with("message", "Вариант смен удален");
 }
Exemple #10
0
 /**
  * Return array of workshift objects from the given results set
  * @return array Array of Workshift objects
  */
 private function _getWorkshiftsFromResults($results)
 {
     $workshiftArray = array();
     while ($row = mysql_fetch_array($results)) {
         $workshiftObj = new Workshift();
         $workshiftObj->setWorkshiftId($row[self::DB_FIELD_WORKSHIFT_ID]);
         $workshiftObj->setName($row[self::DB_FIELD_NAME]);
         $workshiftObj->setHoursPerDay($row[self::DB_FIELD_HOURS]);
         $workshiftArray[] = $workshiftObj;
     }
     return $workshiftArray;
 }
function getWorkHours($clockingIn, $clockingOut, $shiftEnd)
{
    $employeeId = Session::get('userEmployeeId');
    $userId = Session::get('userId');
    $schedule = new Schedule();
    $getSchedule = $schedule->getSchedule($employeeId, date('Y-m-d'));
    $workShift = new Workshift();
    $getWorkShiftByEmployeeId = $workShift->getWorkShiftByEmployeeId($employeeId);
    $setting = new Setting();
    $employeeSetting = $setting->getEmployeeSettingByEmployeeId($employeeId);
    if (!empty($getSchedule)) {
        $schedule['start_time'] = $getSchedule[0]->start_time;
        $schedule['end_time'] = $getSchedule[0]->end_time;
        $schedule['hours_per_day'] = $getSchedule[0]->hours_per_day;
        $halfOfhoursPerDay = $schedule['hours_per_day'] / 2;
        // e.g 8.00 without break
    } elseif (!empty($getWorkShiftByEmployeeId)) {
        $workShift['start_time'] = $getWorkShiftByEmployeeId[0]->start_time;
        $workShift['end_time'] = $getWorkShiftByEmployeeId[0]->end_time;
        $workShift['hours_per_day'] = $getWorkShiftByEmployeeId[0]->hours_per_day;
        $halfOfhoursPerDay = $workShift['hours_per_day'] / 2;
        // e.g 8.00 without break
    }
    if (!empty($employeeSetting->hours_per_day)) {
        $halfOfhoursPerDay = $employeeSetting->hours_per_day / 2;
        // e.g 8.00 without break
        $setting['break_time'] = $employeeSetting->break_time;
    }
    //$interval = getDateTimeDiffInterval($clockingIn, $shiftEnd);
    $interval = getDateTimeDiffInterval($clockingIn, $clockingOut);
    $days = $interval->format('%a');
    $days = (int) $days;
    if ($days !== 0) {
        $hhToDays = $days * 24;
        $hh = (int) $hhToDays;
    } else {
        $hh = (int) $interval->format('%h');
    }
    $mm = (int) $interval->format('%i');
    $ss = (int) $interval->format('%s');
    if ($setting['break_time'] === 1) {
        list($breakTimeHh, $breakTimeMm, $breakTimeSs) = explode(':', $setting['break_time']);
        $breakTime = getTimeToDecimalHours($breakTimeHh, $breakTimeMm, $breakTimeSs);
        $workHours = getTimeToDecimalHours($hh, $mm, $ss);
        //number_format($hours, 2);
        if ($workHours > $halfOfhoursPerDay) {
            $workHours = $workHours - $breakTime;
        } else {
            $workHours = getTimeToDecimalHours($hh, $mm, $ss);
        }
    } else {
        $workHours = getTimeToDecimalHours($hh, $mm, $ss);
        //number_format($hours, 2);
    }
    return number_format($workHours, 2);
}
 public function showAdminEmployeeTimesheet()
 {
     $employeeId = Session::get('userEmployeeId');
     //$employeeId = Auth::user()->employee_id;
     $currentDate = date('Y-m-d');
     $employee = new Employee();
     $employeeInfo = $employee->getEmployeeInfoById($employeeId);
     $workShift = new Workshift();
     $employeeWorkShift = $workShift->getWorkShiftByEmployeeId($employeeId);
     $timesheet = new Timesheet();
     $employeeTimesheet = $timesheet->getAllRows($employeeId);
     $getTimesheetById = $timesheet->getTimesheetById($employeeId, $currentDate);
     $timesheetPerMonth = $timesheet->getTimesheetPerMonth($employeeId, Session::get('dayDateArr'));
     $schedule = new Schedule();
     $checkSchedule = $schedule->checkSchedule($employeeId, $currentDate);
     $getSchedule = $schedule->getSchedule($employeeId, $currentDate);
     //Admin view
     return View::make('employees.admin.clocking', ['employeeInfo' => $employeeInfo, 'employeeWorkShift' => $employeeWorkShift, 'employeeTimesheet' => $employeeTimesheet, 'getTimesheetById' => $getTimesheetById, 'timesheetPerMonth' => $timesheetPerMonth]);
 }
 public function doLogin()
 {
     /**
      * @Todo: Server side validation
      */
     $employeeno = Input::get('employeeno');
     $password = Input::get('password');
     /*$data['employeeno'] = $employeeno;
     		$data['password'] = $password;
     
     		$rules = array(
     			'employee_number' => 'required',
     			'password' => 'required'			
     		);		
     
     		$validator = Validator::make($data, $rules);		
     
     	if ( $validator->fails() ) {
     
     		$messages = $validator->messages();
     
     	    return Redirect::to('users/login')->withErrors($validator);		
     
     	} else {*/
     /*$userdata = array(
           'employee_number'     	=> $employeeno,
           'password'  			=> $password
       );*/
     // Login credentials
     $credentials = array('employee_number' => $employeeno, 'password' => $password);
     try {
         // Authenticate the user
         $user = Sentry::authenticate($credentials, false);
         /*if($user){
         			
         			return Redirect::to('/employee/clocking');
         			
         		} else {
         			
         			return View::make('users.index'); //Return back to login page 	
         		
         		}*/
         //if ( Auth::attempt($userdata) ) {
         if ($user) {
             // validation successful!
             // redirect them to the secure section or whatever
             // return Redirect::to('secure');
             // for now we'll just echo success (even though echoing in a controller is bad)
             //echo 'SUCCESS!';
             //return $user->employee_id;
             Session::put('userEmployeeId', $user->employee_id);
             Session::put('userId', $user->id);
             Session::put('email', $user->email);
             $user['employeeId'] = $user->employee_id;
             /*$emplooyeeSetting = new Setting;	
             			$getEmployeeSettingByEmployeeId = $emplooyeeSetting->getEmployeeSettingByEmployeeId();
             
             			return dd($getEmployeeSettingByEmployeeId); //If no setting found the result will be NULL
             			break;*/
             $employee = new Employee();
             $employeeInfo = $employee->getEmployeeInfoById($user['employeeId']);
             $workShift = new Workshift();
             //$employeeWorkShift = $workShift->getWorkShiftByEmployeeId($user['employeeId']);
             //$dayOfTheWeek = date('l', strtotime($dayDate));
             //$getWorkShiftByDayOfTheWeek = $workShift->getWorkShiftByDayOfTheWeek($employeeInfo[0]->id, $dayOfTheWeek);
             $adminCutoff = new AdminCutoff();
             $adminCutoffConfig = new Cutoffsetting();
             $getAllCutoffSetting = $adminCutoffConfig->getAllCutoffSetting();
             $cutoff['id'] = $adminCutoff->getCutoffbyYearMonth()->id;
             $cutoff['year'] = $adminCutoff->getCutoffbyYearMonth()->year;
             $cutoff['month'] = $adminCutoff->getCutoffbyYearMonth()->month;
             $cutoff['type'] = $adminCutoff->getCutoffbyYearMonth()->cutoff_type;
             $cutoff['dateFrom'][1] = $adminCutoff->getCutoffbyYearMonth()->cutoff_date_from_1;
             $cutoff['dateTo'][1] = $adminCutoff->getCutoffbyYearMonth()->cutoff_date_to_1;
             $cutoff['dateFrom'][2] = $adminCutoff->getCutoffbyYearMonth()->cutoff_date_from_2;
             $cutoff['dateTo'][2] = $adminCutoff->getCutoffbyYearMonth()->cutoff_date_to_2;
             $cutoffConfig['cutoff_type'] = $getAllCutoffSetting[0]->cutoff_type;
             $cutoffConfig['cutoff_options'] = $getAllCutoffSetting[0]->cutoff_options;
             $currentDate = date('Y-m-d');
             $currentMonth = date('M');
             $currentCutoff = '';
             $getSchedule = '';
             if ($cutoff['type'] === 'Monthly') {
                 // Monthly
             } elseif ($cutoff['type'] === 'Semi Monthly') {
                 if ($cutoffConfig['cutoff_options'] === 1) {
                     // 1st and 2nd cutoff same within the month
                     // 1st and 2nd cutoff same within the month
                     //return 'debug.io';
                     //exit;
                     $currentDate = date('Y-m-d');
                     //1st CutOff - e.g 11-25
                     $startTime1 = strtotime($cutoff['dateFrom'][1]);
                     $endTime1 = strtotime($cutoff['dateTo'][1]);
                     // Loop between timestamps, 1 day at a time
                     //$cutoffArr1 = array();
                     $cutoffArr1[] = date('Y-m-d', $startTime1);
                     do {
                         $startTime1 = strtotime('+1 day', $startTime1);
                         $cutoffArr1[] = date('Y-m-d', $startTime1);
                     } while ($startTime1 < $endTime1);
                     //return $cutoffArr1;
                     if (in_array($currentDate, $cutoffArr1)) {
                         $currentCutoff = 1;
                     }
                     //2nd CutOff - e.g 26-10
                     $startTime2 = strtotime($cutoff['dateFrom'][2]);
                     $endTime2 = strtotime($cutoff['dateTo'][2]);
                     // Loop between timestamps, 1 day at a time
                     //$cutoffArr2 = array();
                     $cutoffArr2[] = date('Y-m-d', $startTime2);
                     do {
                         $startTime2 = strtotime('+1 day', $startTime2);
                         $cutoffArr2[] = date('Y-m-d', $startTime2);
                     } while ($startTime2 < $endTime2);
                     //return dd($cutoffArr2);
                     if (in_array($currentDate, $cutoffArr2)) {
                         $currentCutoff = 2;
                     }
                 } elseif ($cutoffConfig['cutoff_options'] === 2) {
                     // 2nd cutoff overlap next month
                     //http://stackoverflow.com/questions/10633879/current-date-minus-4-month
                     //http://stackoverflow.com/questions/8912780/get-the-last-day-of-the-month3455634556
                     //http://www.brightcherry.co.uk/scribbles/php-adding-and-subtracting-dates/
                     //http://stevekostrey.com/php-dates-add-and-subtract-months-really/
                     //$lastMonthDays = date('t', strtotime("-1 month"));
                     //$lastMonth = date('Y-m-d', strtotime("-". $lastMonthDays ."days"));
                     //$currentDate = strtotime('-1 month' , strtotime($currentDate));
                     //$currentDate = date('Y-m-d' , $$currentDate);
                     //1st CutOff - e.g 11-25
                     $startTime1 = strtotime($cutoff['dateFrom'][1]);
                     $endTime1 = strtotime($cutoff['dateTo'][1]);
                     // Loop between timestamps, 1 day at a time
                     //$cutoffArr1 = array();
                     $cutoffArr1[] = date('Y-m-d', $startTime1);
                     do {
                         $startTime1 = strtotime('+1 day', $startTime1);
                         $cutoffArr1[] = date('Y-m-d', $startTime1);
                     } while ($startTime1 < $endTime1);
                     if (in_array($currentDate, $cutoffArr1)) {
                         $currentCutoff = 1;
                     }
                     // /return $currentMonth.' - '.$cutoff['month'];
                     //$currentMonth
                     //$cutoff['month'] = $adminCutoff->getCutoffbyYearMonth()->month;
                     //$cutoff['type'] = $adminCutoff->getCutoffbyYearMonth()->cutoff_type;
                     //$cutoff['dateFrom'][1] = $adminCutoff->getCutoffbyYearMonth()->cutoff_date_from_1;
                     //$cutoff['dateTo'][1] = $adminCutoff->getCutoffbyYearMonth()->cutoff_date_to_1;
                     //$cutoff['dateFrom'][2] = $adminCutoff->getCutoffbyYearMonth()->cutoff_date_from_2;
                     //$cutoff['dateTo'][2] = $adminCutoff->getCutoffbyYearMonth()->cutoff_date_to_2;
                     if (strtotime($currentDate) !== strtotime($cutoff['dateFrom'][1]) || strtotime($currentDate) >= strtotime($cutoff['dateFrom'][1])) {
                         //$lastMonth = date('M', strtotime('-1 month'));
                         //$cutoff['month'] = $lastMonth;
                         /*$cutoff['dateFrom'][2] = strtotime('-1 month' , strtotime($cutoff['dateFrom'][2]));
                         						$cutoff['dateFrom'][2] = date('Y-m-d' , $cutoff['dateFrom'][2]);
                         
                         						$cutoff['dateTo'][2] = strtotime('-1 month' , strtotime($cutoff['dateTo'][2]));
                         						$cutoff['dateTo'][2] = date('Y-m-d' , $cutoff['dateTo'][2]);*/
                         $cutoff['dateFrom'][2] = $adminCutoff->getCutoffbyYearMonth()->cutoff_date_from_2;
                         $cutoff['dateTo'][2] = $adminCutoff->getCutoffbyYearMonth()->cutoff_date_to_2;
                         //return 'true';
                     }
                     //return strtotime($currentDate). ' - ' .strtotime($cutoff['dateFrom'][1]);
                     //die();
                     //2nd CutOff - e.g 26-10
                     $startTime2 = strtotime($cutoff['dateFrom'][2]);
                     $endTime2 = strtotime($cutoff['dateTo'][2]);
                     // Loop between timestamps, 1 day at a time
                     //$cutoffArr2 = array();
                     $cutoffArr2[] = date('Y-m-d', $startTime2);
                     do {
                         $startTime2 = strtotime('+1 day', $startTime2);
                         $cutoffArr2[] = date('Y-m-d', $startTime2);
                     } while ($startTime2 < $endTime2);
                     if (in_array($currentDate, $cutoffArr2)) {
                         $currentCutoff = 2;
                     }
                 }
             }
             /*return $currentCutoff;
             		die();*/
             //return dd( 'Current Cutoff: '. $currentCutoff.' From '.$cutoff['dateFrom'][2] .' - To:'. $cutoff['dateTo'][2] );
             //die();
             $schedule = new Schedule();
             $workShift = new Workshift();
             if ($currentCutoff === 1) {
                 ////1st CutOff - e.g 11-25
                 //Check employee timesheet table if has the current date.
                 $getDayDateResult = DB::table('employee_timesheet')->where('employee_id', $employeeInfo[0]->id)->where('daydate', $currentDate)->get();
                 if (empty($getDayDateResult)) {
                     foreach ($cutoffArr1 as $dayDate) {
                         //return dd(date('l', strtotime($dayDate)));
                         $dayOfTheWeek = date('l', strtotime($dayDate));
                         $checkSchedule = $schedule->checkSchedule($employeeInfo[0]->id, $dayDate);
                         $getSchedule = $schedule->getSchedule($employeeInfo[0]->id, $dayDate);
                         //$employeeWorkShift = $workShift->getWorkShiftByEmployeeId($employeeInfo[0]->id);
                         $getWorkShiftByDayOfTheWeek = $workShift->getWorkShiftByDayOfTheWeek($employeeInfo[0]->id, $dayOfTheWeek, 1);
                         if ($checkSchedule) {
                             $schedule['start_time'] = date('H:i:s', strtotime($getSchedule[0]->start_time));
                             $schedule['end_time'] = date('H:i:s', strtotime($getSchedule[0]->end_time));
                         } elseif (!$checkSchedule) {
                             if (!empty($getWorkShiftByDayOfTheWeek)) {
                                 $schedule['start_time'] = date('H:i:s', strtotime($getWorkShiftByDayOfTheWeek[0]->start_time));
                                 $schedule['end_time'] = date('H:i:s', strtotime($getWorkShiftByDayOfTheWeek[0]->end_time));
                             } else {
                                 $schedule['start_time'] = '';
                                 $schedule['end_time'] = '';
                             }
                         }
                         $timesheetId = DB::table('employee_timesheet')->insertGetId(array('employee_id' => $employeeInfo[0]->id, 'daydate' => $dayDate, 'schedule_in' => $schedule['start_time'], 'schedule_out' => $schedule['end_time'], 'night_shift_time_out' => 0, 'clocking_status' => 'open'));
                         for ($i = 1; $i <= 3; $i++) {
                             DB::table('overtime')->insert(array('employee_id' => $employeeInfo[0]->id, 'timesheet_id' => $timesheetId, 'seq_no' => $i, 'shift' => $i));
                         }
                         DB::table('employee_summary')->insert(array('employee_id' => $employeeInfo[0]->id, 'daydate' => $dayDate));
                     }
                 } else {
                     foreach ($cutoffArr1 as $dayDate) {
                         //return 'debug.io';
                         //return dd(date('l', strtotime($dayDate)));
                         $dayOfTheWeek = date('l', strtotime($dayDate));
                         $checkSchedule = $schedule->checkSchedule($employeeInfo[0]->id, $dayDate);
                         $getSchedule = $schedule->getSchedule($employeeInfo[0]->id, $dayDate);
                         //$employeeWorkShift = $workShift->getWorkShiftByEmployeeId($employeeInfo[0]->id);
                         $getWorkShiftByDayOfTheWeek = $workShift->getWorkShiftByDayOfTheWeek($employeeInfo[0]->id, $dayOfTheWeek, 1);
                         if ($checkSchedule) {
                             $schedule['start_time'] = date('H:i:s', strtotime($getSchedule[0]->start_time));
                             $schedule['end_time'] = date('H:i:s', strtotime($getSchedule[0]->end_time));
                         } elseif (!$checkSchedule) {
                             if (!empty($getWorkShiftByDayOfTheWeek)) {
                                 $schedule['start_time'] = date('H:i:s', strtotime($getWorkShiftByDayOfTheWeek[0]->start_time));
                                 $schedule['end_time'] = date('H:i:s', strtotime($getWorkShiftByDayOfTheWeek[0]->end_time));
                             } else {
                                 $schedule['start_time'] = '';
                                 $schedule['end_time'] = '';
                             }
                         }
                         DB::table('employee_timesheet')->where('employee_id', $employeeInfo[0]->id)->where('daydate', $dayDate)->update(array('schedule_in' => $schedule['start_time'], 'schedule_out' => $schedule['end_time']));
                     }
                 }
                 Session::put('debug', 'debug');
                 //echo Session::get('isLoginCheck');
                 Session::put('employeesInfo', $employeeInfo);
                 /*if( !empty($employeeWorkShift) ) {
                 			Session::put('employeeWorkShift', $employeeWorkShift); //check this out
                 		}*/
                 if (!empty($getWorkShiftByDayOfTheWeek)) {
                     Session::put('getWorkShiftByDayOfTheWeek', $getWorkShiftByDayOfTheWeek);
                     //check this out
                 }
                 Session::put('dayDateArr', $cutoffArr1);
                 return Redirect::route('employeeTimesheet');
             } elseif ($currentCutoff === 2) {
                 ////1st CutOff - e.g 26-10
                 //Check employee timesheet table if has the current date.
                 $getDayDateResult = DB::table('employee_timesheet')->where('employee_id', $employeeInfo[0]->id)->where('daydate', $currentDate)->get();
                 //return dd($getDayDateResult);
                 if (empty($getDayDateResult)) {
                     foreach ($cutoffArr2 as $dayDate) {
                         //return dd(date('l', strtotime($dayDate)));
                         $dayOfTheWeek = date('l', strtotime($dayDate));
                         $checkSchedule = $schedule->checkSchedule($employeeInfo[0]->id, $dayDate);
                         $getSchedule = $schedule->getSchedule($employeeInfo[0]->id, $dayDate);
                         //$employeeWorkShift = $workShift->getWorkShiftByEmployeeId($employeeInfo[0]->id);
                         $getWorkShiftByDayOfTheWeek = $workShift->getWorkShiftByDayOfTheWeek($employeeInfo[0]->id, $dayOfTheWeek, 1);
                         if ($checkSchedule) {
                             $schedule['start_time'] = date('H:i:s', strtotime($getSchedule[0]->start_time));
                             $schedule['end_time'] = date('H:i:s', strtotime($getSchedule[0]->end_time));
                         } elseif (!$checkSchedule) {
                             if (!empty($getWorkShiftByDayOfTheWeek)) {
                                 $schedule['start_time'] = date('H:i:s', strtotime($getWorkShiftByDayOfTheWeek[0]->start_time));
                                 $schedule['end_time'] = date('H:i:s', strtotime($getWorkShiftByDayOfTheWeek[0]->end_time));
                             } else {
                                 $schedule['start_time'] = '';
                                 $schedule['end_time'] = '';
                             }
                         }
                         $timesheetId = DB::table('employee_timesheet')->insertGetId(array('employee_id' => $employeeInfo[0]->id, 'daydate' => $dayDate, 'schedule_in' => $schedule['start_time'], 'schedule_out' => $schedule['end_time'], 'night_shift_time_out' => 0, 'clocking_status' => 'open'));
                         for ($i = 1; $i <= 3; $i++) {
                             DB::table('overtime')->insert(array('employee_id' => $employeeInfo[0]->id, 'timesheet_id' => $timesheetId, 'seq_no' => $i, 'shift' => $i));
                         }
                         DB::table('employee_summary')->insert(array('employee_id' => $employeeInfo[0]->id, 'daydate' => $dayDate));
                     }
                 } else {
                     foreach ($cutoffArr2 as $dayDate) {
                         //$getDayDateResult = DB::table('employee_timesheet')->where('employee_id', $employeeInfo[0]->id)->where('daydate', $currentDate)->get();
                         //return dd($getDayDateResult);
                         $dayOfTheWeek = date('l', strtotime($dayDate));
                         $checkSchedule = $schedule->checkSchedule($employeeInfo[0]->id, $dayDate);
                         $getSchedule = $schedule->getSchedule($employeeInfo[0]->id, $dayDate);
                         //$employeeWorkShift = $workShift->getWorkShiftByEmployeeId($employeeInfo[0]->id);
                         $getWorkShiftByDayOfTheWeek = $workShift->getWorkShiftByDayOfTheWeek($employeeInfo[0]->id, $dayOfTheWeek, 1);
                         if ($checkSchedule) {
                             $schedule['start_time'] = date('H:i:s', strtotime($getSchedule[0]->start_time));
                             $schedule['end_time'] = date('H:i:s', strtotime($getSchedule[0]->end_time));
                         } elseif (!$checkSchedule) {
                             if (!empty($getWorkShiftByDayOfTheWeek)) {
                                 $schedule['start_time'] = date('H:i:s', strtotime($getWorkShiftByDayOfTheWeek[0]->start_time));
                                 $schedule['end_time'] = date('H:i:s', strtotime($getWorkShiftByDayOfTheWeek[0]->end_time));
                             } else {
                                 $schedule['start_time'] = '';
                                 $schedule['end_time'] = '';
                             }
                         }
                         DB::table('employee_timesheet')->where('employee_id', $employeeInfo[0]->id)->where('daydate', $dayDate)->update(array('schedule_in' => $schedule['start_time'], 'schedule_out' => $schedule['end_time']));
                     }
                 }
                 Session::put('debug', 'debug');
                 //echo Session::get('isLoginCheck');
                 Session::put('employeesInfo', $employeeInfo);
                 /*if( !empty($employeeWorkShift) ) {
                 			Session::put('employeeWorkShift', $employeeWorkShift); //check this out
                 		}*/
                 if (!empty($getWorkShiftByDayOfTheWeek)) {
                     Session::put('getWorkShiftByDayOfTheWeek', $getWorkShiftByDayOfTheWeek);
                     //check this out
                 }
                 Session::put('dayDateArr', $cutoffArr2);
                 return Redirect::route('employeeTimesheet');
             }
             //return Redirect::route( 'employeeTimesheet');
         }
         /*else {        
         
         	        //validation not successful, send back to form 
         	    	return Redirect::to('users.index'); //Return back to login page
         
             	}*/
     } catch (Cartalyst\Sentry\Users\LoginRequiredException $e) {
         $getMessages = 'Login field is required.';
         return Redirect::to('users/login')->withErrors(array('login' => $getMessages));
     } catch (Cartalyst\Sentry\Users\PasswordRequiredException $e) {
         $getMessages = 'Password field is required.';
         return Redirect::to('users/login')->withErrors(array('login' => $getMessages));
     } catch (Cartalyst\Sentry\Users\WrongPasswordException $e) {
         $getMessages = 'Wrong password, try again.';
         return Redirect::to('users/login')->withErrors($getMessages);
     } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) {
         $getMessages = 'User was not found.';
         return Redirect::to('users/login')->withErrors(array('login' => $getMessages));
     } catch (Cartalyst\Sentry\Users\UserNotActivatedException $e) {
         $getMessages = 'User is not activated.';
         return Redirect::to('users/login')->withErrors(array('login' => $getMessages));
     }
 }
Exemple #14
0
 /**
  * View the worksheet edit page
  * @param int $id The workshift Id
  */
 public function viewEditWorkShift($id)
 {
     $path = "/templates/time/editWorkShift.php";
     try {
         $workshift = Workshift::getWorkshift($id);
         $objs[] = $workshift;
         $objs[] = $workshift->getAssignedEmployees();
         $objs[] = $workshift->getEmployeesWithoutWorkshift();
         $template = new TemplateMerger($objs, $path);
         $template->display();
     } catch (WorkshiftException $e) {
         switch ($e->getCode()) {
             case WorkshiftException::WORKSHIFT_NOT_FOUND:
                 $msg = 'INVALID_WORK_SHIFT_FAILURE';
                 break;
             default:
                 $msg = 'UNKNOWN_ERROR_FAILURE';
                 break;
         }
         $this->redirect($msg, '?timecode=Time&action=View_Work_Shifts');
     }
 }
 private function _isWorkshiftNameAvailable($workShift)
 {
     $flag = 0;
     $objs = Workshift::getWorkshifts();
     foreach ($objs as $workShiftSelect) {
         if (strtolower($workShiftSelect->getName()) == strtolower($workShift->getName())) {
             $flag = 1;
             break;
         }
     }
     if ($flag == 1) {
         return true;
     }
     return false;
 }
Exemple #16
0
 protected function _adjustLeaveLength()
 {
     $timeOff = $this->_timeOffLength($this->getLeaveDate());
     $shift = Leave::LEAVE_LENGTH_FULL_DAY;
     $workShift = Workshift::getWorkshiftForEmployee($this->getEmployeeId());
     if (isset($workShift)) {
         $shift = $workShift->getHoursPerDay();
     }
     $hours = $shift;
     $days = 1;
     if ($this->getLeaveLengthHours() != null) {
         $hours = $this->getLeaveLengthHours() - $timeOff * $shift;
         /* For handling leaves applied in half days: Begins
          * This assumes that employee request the leave in available working time
          * */
         if ($timeOff > 0 && $timeOff < 1) {
             if ($hours <= 0) {
                 $hours = $this->getLeaveLengthHours();
             } else {
                 $hours = $timeOff * $shift;
             }
         }
         /* For handling leaves applied in half days: Ends */
         $days = round($hours / $shift, 2);
     } else {
         if ($this->getLeaveLengthDays() != null) {
             $hours = ($this->getLeaveLengthDays() - $timeOff) * $shift;
             $days = round($hours / $shift, 2);
         }
     }
     if (0 > $hours) {
         $hours = 0;
     }
     if (0 > $days) {
         $days = 0;
     }
     $this->setLeaveLengthHours($hours);
     $this->setLeaveLengthDays($days);
 }