public function viewDetailSchedule()
 {
     $employees = Employee::getAllEmployees();
     $schedule = Schedule::getSchedule($_GET['id']);
     $db = Database::getInstance();
     $sql = "Select employee.firstName, employee.lastName, day.shiftDate, day.startTime, day.id as day_id from day left join week on day.weekId = week.id left join employee on week.empId = employee.id\n\t\t\t\t\tWHERE day.shiftDate >= :start AND day.shiftDate <= :end ORDER BY employee.firstName, day.shiftDate;   ";
     $result = $db->prepare($sql);
     $result->execute(array(":start" => $schedule['startDate'], ":end" => date('Y-m-d', strtotime("+6 day", strtotime($schedule['startDate'])))));
     $allEmpSchedule = $result->fetchAll(PDO::FETCH_ASSOC);
     require_once 'views/schedule_detail_view.php';
 }
Пример #2
0
 public static function createDays($schId)
 {
     $db = Database::getInstance();
     $weekId = Week::getLastId();
     $schedule = Schedule::getSchedule($schId);
     $sql = "INSERT INTO day (weekId, startTime, shiftDate) VALUES (:weekId, :startTime, :shiftDate)";
     for ($i = 0; $i < 7; $i++) {
         $shift = date('Y-m-d', strToTime("+" . $i . " days", strToTime($schedule['startDate'])));
         $result = $db->prepare($sql);
         $result->execute(array(":weekId" => $weekId, ":startTime" => null, ":shiftDate" => $shift));
     }
 }
Пример #3
0
 /**
  * Save the user, both in the DB and in the session
  *
  */
 function save(Schedule $schedule, $userID)
 {
     $userID = $this->clean($userID);
     // Remove all the hours of the user
     $query = 'DELETE * FROM ' . self::TABLE_SCHEDULE . ' WHERE userID = ' . $userID;
     $this->getDB()->query($query);
     // Add all the new hours
     foreach ($schedule->getSchedule() as $day => $hours) {
         foreach ($hours as $h) {
             $save = array('userID' => $userID, 'day' => $day, 'hour' => $h);
             $this->getDB()->insert(self::TABLE_SCHEDULE, $save);
         }
     }
 }
Пример #4
0
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;
    $nightShiftStartTimeThreshold = 5;
    //It should be bigger;
    //get schedule
    //Check if there is assign schedule today
    //if ( $hasSchedule && strtotime($getSchedule[0]->start_time) !== strtotime('00:00:00')) {
    if ($hasSchedule && strtotime($getSchedule[0]->start_time) !== '') {
        $hasTodaySchedule = true;
    } else {
        //check workShift table default schedule if no schedule in the schedule table
        $hasTodaySchedule = false;
    }
    //Computation Setting
Пример #5
0
 /**
  * Executes the SQL statements to get the spotter information
  *
  * @param String $query the SQL query
  * @param String $limit the limit query
  * @return Array the spotter information
  *
  */
 public function getDataFromDB($query, $params = array(), $limitQuery = '')
 {
     global $globalSquawkCountry, $globalIVAO;
     $Image = new Image();
     $Schedule = new Schedule();
     $ACARS = new ACARS();
     if (!isset($globalIVAO)) {
         $globalIVAO = FALSE;
     }
     date_default_timezone_set('UTC');
     if (!is_string($query)) {
         return false;
     }
     if ($limitQuery != "") {
         if (!is_string($limitQuery)) {
             return false;
         }
     }
     try {
         $sth = $this->db->prepare($query . $limitQuery);
         $sth->execute($params);
     } catch (PDOException $e) {
         printf("Invalid query : %s\nWhole query: %s\n", $e->getMessage(), $query . $limitQuery);
         exit;
     }
     //	$num_rows = count($sth->fetchAll());
     $num_rows = 0;
     $spotter_array = array();
     $temp_array = array();
     while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
         $num_rows++;
         $temp_array = array();
         if (isset($row['spotter_live_id'])) {
             $temp_array['spotter_id'] = $row['spotter_live_id'];
         } elseif (isset($row['spotter_archive_id'])) {
             $temp_array['spotter_id'] = $row['spotter_archive_id'];
         } else {
             $temp_array['spotter_id'] = $row['spotter_id'];
         }
         $temp_array['flightaware_id'] = $row['flightaware_id'];
         if (isset($row['modes'])) {
             $temp_array['modes'] = $row['modes'];
         }
         $temp_array['ident'] = $row['ident'];
         if (isset($row['registration']) && $row['registration'] != '') {
             $temp_array['registration'] = $row['registration'];
         } elseif (isset($temp_array['modes'])) {
             $temp_array['registration'] = $this->getAircraftRegistrationBymodeS($temp_array['modes']);
         } else {
             $temp_array['registration'] = '';
         }
         $temp_array['aircraft_type'] = $row['aircraft_icao'];
         $temp_array['departure_airport'] = $row['departure_airport_icao'];
         $temp_array['arrival_airport'] = $row['arrival_airport_icao'];
         $temp_array['latitude'] = $row['latitude'];
         $temp_array['longitude'] = $row['longitude'];
         /*
         if (Connection->tableExists('countries')) {
         	$country_info = Spotter->getCountryFromLatitudeLongitude($temp_array['latitude'],$temp_array['longitude']);
         	if (is_array($country_info) && isset($country_info['name']) && isset($country_info['iso2'])) {
         	    $temp_array['country'] = $country_info['name'];
         	    $temp_array['country_iso2'] = $country_info['iso2'];
         	}
         }
         */
         $temp_array['waypoints'] = $row['waypoints'];
         if (isset($row['route_stop'])) {
             $temp_array['route_stop'] = $row['route_stop'];
             if ($row['route_stop'] != '') {
                 $allroute = explode(' ', $row['route_stop']);
                 foreach ($allroute as $route) {
                     $route_airport_array = $this->getAllAirportInfo($route);
                     if (isset($route_airport_array[0]['name'])) {
                         $route_stop_details['airport_name'] = $route_airport_array[0]['name'];
                         $route_stop_details['airport_city'] = $route_airport_array[0]['city'];
                         $route_stop_details['airport_country'] = $route_airport_array[0]['country'];
                         $route_stop_details['airport_icao'] = $route_airport_array[0]['icao'];
                         $temp_array['route_stop_details'][] = $route_stop_details;
                     }
                 }
             }
         }
         $temp_array['altitude'] = $row['altitude'];
         $temp_array['heading'] = $row['heading'];
         $heading_direction = $this->parseDirection($row['heading']);
         if (isset($heading_direction[0]['direction_fullname'])) {
             $temp_array['heading_name'] = $heading_direction[0]['direction_fullname'];
         }
         $temp_array['ground_speed'] = $row['ground_speed'];
         $temp_array['image'] = "";
         $temp_array['image_thumbnail'] = "";
         $temp_array['image_source'] = "";
         $temp_array['image_copyright'] = "";
         if (isset($row['highlight'])) {
             $temp_array['highlight'] = $row['highlight'];
         } else {
             $temp_array['highlight'] = '';
         }
         $dateArray = $this->parseDateString($row['date']);
         if ($dateArray['seconds'] < 10) {
             $temp_array['date'] = "a few seconds ago";
         } elseif ($dateArray['seconds'] >= 5 && $dateArray['seconds'] < 30) {
             $temp_array['date'] = "half a minute ago";
         } elseif ($dateArray['seconds'] >= 30 && $dateArray['seconds'] < 60) {
             $temp_array['date'] = "about a minute ago";
         } elseif ($dateArray['minutes'] < 5) {
             $temp_array['date'] = "a few minutes ago";
         } elseif ($dateArray['minutes'] >= 5 && $dateArray['minutes'] < 60) {
             $temp_array['date'] = "about " . $dateArray['minutes'] . " minutes ago";
         } elseif ($dateArray['hours'] < 2) {
             $temp_array['date'] = "about an hour ago";
         } elseif ($dateArray['hours'] >= 2 && $dateArray['hours'] < 24) {
             $temp_array['date'] = "about " . $dateArray['hours'] . " hours ago";
         } else {
             $temp_array['date'] = date("M j Y, g:i a", strtotime($row['date'] . " UTC"));
         }
         $temp_array['date_minutes_past'] = $dateArray['minutes'];
         $temp_array['date_iso_8601'] = date("c", strtotime($row['date'] . " UTC"));
         $temp_array['date_rfc_2822'] = date("r", strtotime($row['date'] . " UTC"));
         $temp_array['date_unix'] = strtotime($row['date'] . " UTC");
         if (isset($row['aircraft_name']) && $row['aircraft_name'] != '' && isset($row['aircraft_shadow']) && $row['aircraft_shadow'] != '') {
             $temp_array['aircraft_name'] = $row['aircraft_name'];
             $temp_array['aircraft_manufacturer'] = $row['aircraft_manufacturer'];
             if (isset($row['aircraft_shadow'])) {
                 $temp_array['aircraft_shadow'] = $row['aircraft_shadow'];
             }
         } else {
             $aircraft_array = $this->getAllAircraftInfo($row['aircraft_icao']);
             if (count($aircraft_array) > 0) {
                 $temp_array['aircraft_name'] = $aircraft_array[0]['type'];
                 $temp_array['aircraft_manufacturer'] = $aircraft_array[0]['manufacturer'];
                 if ($aircraft_array[0]['aircraft_shadow'] != NULL) {
                     $temp_array['aircraft_shadow'] = $aircraft_array[0]['aircraft_shadow'];
                 } else {
                     $temp_array['aircraft_shadow'] = 'default.png';
                 }
             } else {
                 $temp_array['aircraft_shadow'] = 'default.png';
                 $temp_array['aircraft_name'] = 'N/A';
                 $temp_array['aircraft_manufacturer'] = 'N/A';
             }
         }
         if (!isset($row['airline_name']) || $row['airline_name'] == '') {
             $airline_array = array();
             if (!is_numeric(substr($row['ident'], 0, 3))) {
                 if (is_numeric(substr($row['ident'], 2, 1))) {
                     $airline_array = $this->getAllAirlineInfo(substr($row['ident'], 0, 2));
                 } elseif (is_numeric(substr($row['ident'], 3, 1))) {
                     $airline_array = $this->getAllAirlineInfo(substr($row['ident'], 0, 3));
                 } else {
                     $airline_array = $this->getAllAirlineInfo('NA');
                 }
             } else {
                 $airline_array = $this->getAllAirlineInfo('NA');
             }
             if (count($airline_array) > 0) {
                 $temp_array['airline_icao'] = $airline_array[0]['icao'];
                 $temp_array['airline_iata'] = $airline_array[0]['iata'];
                 $temp_array['airline_name'] = $airline_array[0]['name'];
                 $temp_array['airline_country'] = $airline_array[0]['country'];
                 $temp_array['airline_callsign'] = $airline_array[0]['callsign'];
                 $temp_array['airline_type'] = $airline_array[0]['type'];
             }
         } else {
             $temp_array['airline_icao'] = $row['airline_icao'];
             if (isset($row['airline_iata'])) {
                 $temp_array['airline_iata'] = $row['airline_iata'];
             } else {
                 $temp_array['airline_iata'] = '';
             }
             $temp_array['airline_name'] = $row['airline_name'];
             $temp_array['airline_country'] = $row['airline_country'];
             if (isset($row['airline_callsign'])) {
                 $temp_array['airline_callsign'] = $row['airline_callsign'];
             } else {
                 $temp_array['airline_callsign'] = 'N/A';
             }
             $temp_array['airline_type'] = $row['airline_type'];
         }
         if (isset($temp_array['airline_iata']) && $temp_array['airline_iata'] != '') {
             $acars_array = $ACARS->getLiveAcarsData($temp_array['airline_iata'] . substr($temp_array['ident'], 3));
             //$acars_array = ACARS->getLiveAcarsData('BA40YL');
             if (count($acars_array) > 0) {
                 $temp_array['acars'] = $acars_array;
                 //print_r($acars_array);
             }
         }
         if ($temp_array['registration'] != "" || $globalIVAO && $temp_array['aircraft_type'] != '') {
             if ($globalIVAO) {
                 if (isset($temp_array['airline_icao'])) {
                     $image_array = $Image->getSpotterImage('', $temp_array['aircraft_type'], $temp_array['airline_icao']);
                 } else {
                     $image_array = $Image->getSpotterImage('', $temp_array['aircraft_type']);
                 }
             } else {
                 $image_array = $Image->getSpotterImage($temp_array['registration']);
             }
             if (count($image_array) > 0) {
                 $temp_array['image'] = $image_array[0]['image'];
                 $temp_array['image_thumbnail'] = $image_array[0]['image_thumbnail'];
                 $temp_array['image_source'] = $image_array[0]['image_source'];
                 $temp_array['image_source_website'] = $image_array[0]['image_source_website'];
                 if ($temp_array['image_source_website'] == '' && $temp_array['image_source'] == 'planespotters') {
                     $planespotter_url_array = explode("_", $temp_array['image']);
                     $planespotter_id = str_replace(".jpg", "", $planespotter_url_array[1]);
                     $temp_array['image_source_website'] = 'http://www.planespotters.net/Aviation_Photos/photo.show?id=' . $planespotter_id;
                 }
                 $temp_array['image_copyright'] = $image_array[0]['image_copyright'];
             }
         }
         if (!isset($globalIVAO) || !$globalIVAO) {
             $schedule_array = $Schedule->getSchedule($temp_array['ident']);
             //print_r($schedule_array);
             if (count($schedule_array) > 0) {
                 if ($schedule_array['departure_airport_icao'] != '') {
                     $row['departure_airport_icao'] = $schedule_array['departure_airport_icao'];
                     $temp_array['departure_airport'] = $row['departure_airport_icao'];
                 }
                 if ($schedule_array['arrival_airport_icao'] != '') {
                     $row['arrival_airport_icao'] = $schedule_array['arrival_airport_icao'];
                     $temp_array['arrival_airport'] = $row['arrival_airport_icao'];
                 }
                 $temp_array['departure_airport_time'] = $schedule_array['departure_airport_time'];
                 $temp_array['arrival_airport_time'] = $schedule_array['arrival_airport_time'];
             }
         }
         //if ($row['departure_airport_icao'] != '' && $row['departure_airport_name'] == '') {
         if ($row['departure_airport_icao'] != '') {
             $departure_airport_array = $this->getAllAirportInfo($row['departure_airport_icao']);
             if (!isset($departure_airport_array[0]['name'])) {
                 $departure_airport_array = $this->getAllAirportInfo('NA');
             }
             /*
             } elseif ($row['departure_airport_name'] != '') {
             	$temp_array['departure_airport_name'] = $row['departure_airport_name'];
             	$temp_array['departure_airport_city'] = $row['departure_airport_city'];
             	$temp_array['departure_airport_country'] = $row['departure_airport_country'];
             	$temp_array['departure_airport_icao'] = $row['departure_airport_icao'];
             */
         } else {
             $departure_airport_array = $this->getAllAirportInfo('NA');
         }
         if (isset($departure_airport_array[0]['name'])) {
             $temp_array['departure_airport_name'] = $departure_airport_array[0]['name'];
             $temp_array['departure_airport_city'] = $departure_airport_array[0]['city'];
             $temp_array['departure_airport_country'] = $departure_airport_array[0]['country'];
             $temp_array['departure_airport_iata'] = $departure_airport_array[0]['iata'];
             $temp_array['departure_airport_icao'] = $departure_airport_array[0]['icao'];
             $temp_array['departure_airport_latitude'] = $departure_airport_array[0]['latitude'];
             $temp_array['departure_airport_longitude'] = $departure_airport_array[0]['longitude'];
             $temp_array['departure_airport_altitude'] = $departure_airport_array[0]['altitude'];
         }
         /*
         if (isset($row['departure_airport_time'])) {
         	$temp_array['departure_airport_time'] = $row['departure_airport_time'];
         }
         */
         if ($row['arrival_airport_icao'] != '') {
             $arrival_airport_array = $this->getAllAirportInfo($row['arrival_airport_icao']);
             if (count($arrival_airport_array) == 0) {
                 $arrival_airport_array = $this->getAllAirportInfo('NA');
             }
         } else {
             $arrival_airport_array = $this->getAllAirportInfo('NA');
         }
         if (isset($arrival_airport_array[0]['name'])) {
             $temp_array['arrival_airport_name'] = $arrival_airport_array[0]['name'];
             $temp_array['arrival_airport_city'] = $arrival_airport_array[0]['city'];
             $temp_array['arrival_airport_country'] = $arrival_airport_array[0]['country'];
             $temp_array['arrival_airport_iata'] = $arrival_airport_array[0]['iata'];
             $temp_array['arrival_airport_icao'] = $arrival_airport_array[0]['icao'];
             $temp_array['arrival_airport_latitude'] = $arrival_airport_array[0]['latitude'];
             $temp_array['arrival_airport_longitude'] = $arrival_airport_array[0]['longitude'];
             $temp_array['arrival_airport_altitude'] = $arrival_airport_array[0]['altitude'];
         }
         /*
         if (isset($row['arrival_airport_time'])) {
         	$temp_array['arrival_airport_time'] = $row['arrival_airport_time'];
         }
         */
         if (isset($row['pilot_id']) && $row['pilot_id'] != '') {
             $temp_array['pilot_id'] = $row['pilot_id'];
         }
         if (isset($row['pilot_name']) && $row['pilot_name'] != '') {
             $temp_array['pilot_name'] = $row['pilot_name'];
         }
         if (isset($row['squawk'])) {
             $temp_array['squawk'] = $row['squawk'];
             if ($row['squawk'] != '' && isset($temp_array['country_iso2'])) {
                 $temp_array['squawk_usage'] = $this->getSquawkUsage($row['squawk'], $temp_array['country_iso2']);
                 if ($temp_array['squawk_usage'] == '' && isset($globalSquawkCountry)) {
                     $temp_array['squawk_usage'] = $this->getSquawkUsage($row['squawk'], $globalSquawkCountry);
                 }
             } elseif ($row['squawk'] != '' && isset($globalSquawkCountry)) {
                 $temp_array['squawk_usage'] = $this->getSquawkUsage($row['squawk'], $globalSquawkCountry);
             }
         }
         $temp_array['query_number_rows'] = $num_rows;
         $spotter_array[] = $temp_array;
     }
     if ($num_rows == 0) {
         return array();
     }
     $spotter_array[0]['query_number_rows'] = $num_rows;
     return $spotter_array;
 }
Пример #6
0
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]);
 }
Пример #8
0
 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));
     }
 }
Пример #9
0
function getSchedule($team)
{
    $schedule = new Schedule();
    echo $schedule->getSchedule($team);
}
Пример #10
0
<?php

$schedule = new Schedule();
if (!$schedule->isEnabled()) {
    throw new NotFoundException('Schedule is disabled');
}
header('Content-Type: application/json');
if ($conference->isClosed()) {
    echo '{}';
} else {
    echo json_encode($schedule->getSchedule(), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
}