private function getEmployeeById($id)
 {
     $sup = new Employee();
     $sup->Load("id = ?", array($id));
     if ($sup->id != $id) {
         LogManager::getInstance()->info("Employee not found");
         return null;
     }
     return $sup;
 }
Esempio n. 2
0
 private function getEmployeeById($id)
 {
     $sup = new Employee();
     $sup->Load("id = ?", array($id));
     if ($sup->id != $id) {
         error_log("Employee not found");
         return null;
     }
     return $sup;
 }
 public function getRecentAttendanceEntries($limit)
 {
     $shift = intval(SettingsManager::getInstance()->getSetting("Attendance: Shift (Minutes)"));
     $attendance = new Attendance();
     $attendanceToday = $attendance->Find("1 = 1 order by in_time desc limit " . $limit, array());
     $attendanceData = array();
     $employees = array();
     foreach ($attendanceToday as $atEntry) {
         $entry = new stdClass();
         $entry->id = $atEntry->employee;
         $dayArr = explode(" ", $atEntry->in_time);
         $day = $dayArr[0];
         if ($atEntry->out_time == "0000-00-00 00:00:00" || empty($atEntry->out_time)) {
             if (strtotime($atEntry->in_time) < time() + $shift * 60 && $day == date("Y-m-d")) {
                 $entry->status = "Clocked In";
                 $entry->statusId = 0;
                 $entry->color = 'green';
                 $employee = new Employee();
                 $employee->Load("id = ?", array($entry->id));
                 $entry->employee = $employee->first_name . " " . $employee->last_name;
                 $employees[$entry->id] = $entry;
             }
         }
         if (!isset($employees[$entry->id])) {
             $employee = new Employee();
             $employee->Load("id = ?", array($entry->id));
             if ($day == date("Y-m-d")) {
                 $entry->status = "Clocked Out";
                 $entry->statusId = 1;
                 $entry->color = 'yellow';
             } else {
                 $entry->status = "Not Clocked In";
                 $entry->statusId = 2;
                 $entry->color = 'gray';
             }
             $entry->employee = $employee->first_name . " " . $employee->last_name;
             $employees[$entry->id] = $entry;
         }
     }
     return array_values($employees);
 }
 public function getData($report, $request)
 {
     $employeeCache = array();
     $employeeList = array();
     if (!empty($request['employee'])) {
         $employeeList = json_decode($request['employee'], true);
     }
     if (in_array("NULL", $employeeList)) {
         $employeeList = array();
     }
     $employee_query = "";
     if (!empty($employeeList)) {
         $employee_query = "employee in (" . implode(",", $employeeList) . ") and ";
     }
     $timeSheet = new EmployeeTimeSheet();
     if ($request['status'] != "NULL") {
         $timeSheets = $timeSheet->Find($employee_query . "status = ? and date_start >= ? and date_end <= ?", array($request['status'], $request['date_start'], $request['date_end']));
     } else {
         $timeSheets = $timeSheet->Find($employee_query . "date_start >= ? and date_end <= ?", array($request['date_start'], $request['date_end']));
     }
     if (!$timeSheets) {
         LogManager::getInstance()->info($timeSheet->ErrorMsg());
     }
     $reportData = array();
     $reportData[] = array("Employee ID", "Employee", "Name", "Start", "End", "Total Time", "Status");
     foreach ($timeSheets as $ts) {
         $employee = $employeeCache[$ts->employee];
         if (empty($employee)) {
             $employee = new Employee();
             $employee->Load("id = ?", array($ts->employee));
             if (empty($employee->id)) {
                 continue;
             }
             $employeeCache[$employee->id] = $employee;
         }
         $reportData[] = array($employee->employee_id, $employee->first_name . " " . $employee->last_name, date("F j, Y", strtotime($ts->date_start)) . " - " . date("F j, Y", strtotime($ts->date_end)), $ts->date_start, $ts->date_end, $ts->getTotalTime(), $ts->status);
     }
     return $reportData;
 }
Esempio n. 5
0
 public function sendEmailFromNotification($notification)
 {
     $toEmail = null;
     $user = new User();
     $user->Load("id = ?", array($notification->toUser));
     if (!empty($user->email)) {
         $name = "User";
         $employee = new Employee();
         $employee->Load("id = ?", array($user->employee));
         if ($employee->id == $user->employee && !empty($employee->id)) {
             $name = $employee->first_name;
         }
         $action = json_decode($notification->action);
         $emailBody = file_get_contents(APP_BASE_PATH . '/templates/email/notificationEmail.html');
         $emailBody = str_replace("#_user_#", $name, $emailBody);
         $emailBody = str_replace("#_message_#", $notification->message, $emailBody);
         if ($action->type == "url") {
             $emailBody = str_replace("#_url_#", CLIENT_BASE_URL . "?" . $action->url, $emailBody);
         }
         $this->sendEmail('IceHrm Notification from ' . $notification->type, $user->email, $emailBody, array(), array(), array());
     }
 }
Esempio n. 6
0
 public function getCurrentEmployeeTimeZone()
 {
     $cemp = $this->getCurrentProfileId();
     if (empty($cemp)) {
         return NULL;
     }
     $emp = new Employee();
     $emp->Load("id = ?", array($cemp));
     if (empty($emp->id) || empty($emp->department)) {
         return NULL;
     }
     $dept = new CompanyStructure();
     $dept->Load("id = ?", array($emp->department));
     return $dept->timezone;
 }
 public function getLeaveDaysReadonly($req)
 {
     $leaveId = $req->leave_id;
     $leaveLogs = array();
     $employeeLeave = new EmployeeLeave();
     $employeeLeave->Load("id = ?", array($leaveId));
     $currentLeavePeriodResp = $this->getCurrentLeavePeriod($employeeLeave->date_start, $employeeLeave->date_end);
     if ($currentLeavePeriodResp->getStatus() != IceResponse::SUCCESS) {
         return new IceResponse(IceResponse::ERROR, $currentLeavePeriodResp->getData());
     } else {
         $currentLeavePeriod = $currentLeavePeriodResp->getData();
     }
     $employee = $this->baseService->getElement('Employee', $employeeLeave->employee, null, true);
     $rule = $this->getLeaveRule($employee, $employeeLeave->leave_type, $currentLeavePeriod);
     $currentLeavePeriodResp = $this->getCurrentLeavePeriod($employeeLeave->date_start, $employeeLeave->date_end);
     if ($currentLeavePeriodResp->getStatus() != IceResponse::SUCCESS) {
         return new IceResponse(IceResponse::ERROR, $currentLeavePeriodResp->getData());
     } else {
         $currentLeavePeriod = $currentLeavePeriodResp->getData();
     }
     $leaveMatrix = $this->getAvailableLeaveMatrixForEmployeeLeaveType($employee, $currentLeavePeriod, $employeeLeave->leave_type);
     $leaves = array();
     $leaves['totalLeaves'] = floatval($leaveMatrix[0]);
     $leaves['pendingLeaves'] = floatval($leaveMatrix[1]);
     $leaves['approvedLeaves'] = floatval($leaveMatrix[2]);
     $leaves['rejectedLeaves'] = floatval($leaveMatrix[3]);
     $leaves['cancelRequestedLeaves'] = floatval($leaveMatrix[5]);
     $leaves['availableLeaves'] = $leaves['totalLeaves'] - $leaves['pendingLeaves'] - $leaves['approvedLeaves'] - $leaves['cancelRequestedLeaves'];
     $leaves['attachment'] = $employeeLeave->attachment;
     $employeeLeaveDay = new EmployeeLeaveDay();
     $days = $employeeLeaveDay->Find("employee_leave = ?", array($leaveId));
     $employeeLeaveLog = new EmployeeLeaveLog();
     $logsTemp = $employeeLeaveLog->Find("employee_leave = ? order by created", array($leaveId));
     foreach ($logsTemp as $empLeaveLog) {
         $t = array();
         $t['time'] = $empLeaveLog->created;
         $t['status_from'] = $empLeaveLog->status_from;
         $t['status_to'] = $empLeaveLog->status_to;
         $t['time'] = $empLeaveLog->created;
         $userName = null;
         if (!empty($empLeaveLog->user_id)) {
             $lgUser = new User();
             $lgUser->Load("id = ?", array($empLeaveLog->user_id));
             if ($lgUser->id == $empLeaveLog->user_id) {
                 if (!empty($lgUser->employee)) {
                     $lgEmployee = new Employee();
                     $lgEmployee->Load("id = ?", array($lgUser->employee));
                     $userName = $lgEmployee->first_name . " " . $lgEmployee->last_name;
                 } else {
                     $userName = $lgUser->userName;
                 }
             }
         }
         if (!empty($userName)) {
             $t['note'] = $empLeaveLog->data . " (by: " . $userName . ")";
         } else {
             $t['note'] = $empLeaveLog->data;
         }
         $leaveLogs[] = $t;
     }
     return new IceResponse(IceResponse::SUCCESS, array($days, $leaves, $leaveId, $employeeLeave, $leaveLogs));
 }
Esempio n. 8
0
 public function getData($report, $req)
 {
     error_log(json_encode($report));
     error_log(json_encode($req));
     $employeeTimeEntry = new EmployeeTimeEntry();
     $timeEntryList = $employeeTimeEntry->Find("employee = ? and date(date_start) >= ? and  date(date_end) <= ?", array($req['employee'], $req['date_start'], $req['date_end']));
     $seconds = 0;
     $graphTimeArray = array();
     foreach ($timeEntryList as $entry) {
         $seconds = strtotime($entry->date_end) - strtotime($entry->date_start);
         $key = date("Y-m-d", strtotime($entry->date_end));
         if (isset($graphTimeArray[$key])) {
             $graphTimeArray[$key] += $seconds;
         } else {
             $graphTimeArray[$key] = $seconds;
         }
     }
     //$minutes = (int)($seconds/60);
     //Find Attendance Entries
     $attendance = new Attendance();
     $atteandanceList = $attendance->Find("employee = ? and date(in_time) >= ? and  date(out_time) <= ? and in_time < out_time", array($req['employee'], $req['date_start'], $req['date_end']));
     $seconds = 0;
     $graphAttendanceArray = array();
     $firstTimeInArray = array();
     $lastTimeOutArray = array();
     foreach ($atteandanceList as $entry) {
         $seconds = strtotime($entry->out_time) - strtotime($entry->in_time);
         $key = date("Y-m-d", strtotime($entry->in_time));
         if (isset($graphAttendanceArray[$key])) {
             $graphAttendanceArray[$key] += $seconds;
             $lastTimeOutArray[$key] = $entry->out_time;
         } else {
             $graphAttendanceArray[$key] = $seconds;
             $firstTimeInArray[$key] = $entry->in_time;
             $lastTimeOutArray[$key] = $entry->out_time;
         }
     }
     /////////////////////////////////////////
     $employeeObject = new Employee();
     $employeeObject->Load("id = ?", array($req['employee']));
     $reportData = array();
     //$reportData[] = array($employeeObject->first_name." ".$employeeObject->last_name,"","","","");
     $reportData[] = array("Date", "First Punch-In Time", "Last Punch-Out Time", "Time in Office", "Time in Timesheets");
     //Iterate date range
     $interval = DateInterval::createFromDateString('1 day');
     $period = new DatePeriod(new DateTime($req['date_start']), $interval, new DateTime($req['date_end']));
     foreach ($period as $dt) {
         $dataRow = array();
         $key = $dt->format("Y-m-d");
         $dataRow[] = $key;
         if (isset($firstTimeInArray[$key])) {
             $dataRow[] = $firstTimeInArray[$key];
         } else {
             $dataRow[] = "Not Found";
         }
         if (isset($lastTimeOutArray[$key])) {
             $dataRow[] = $lastTimeOutArray[$key];
         } else {
             $dataRow[] = "Not Found";
         }
         if (isset($graphAttendanceArray[$key])) {
             $dataRow[] = round($graphAttendanceArray[$key] / 3600, 2);
         } else {
             $dataRow[] = 0;
         }
         if (isset($graphTimeArray[$key])) {
             $dataRow[] = round($graphTimeArray[$key] / 3600, 2);
         } else {
             $dataRow[] = 0;
         }
         $reportData[] = $dataRow;
     }
     return $reportData;
 }
 public function reCalculateAllSalary()
 {
     $allEmployees = new Employee();
     $allEmployees = $allEmployees->Find('');
     foreach ($allEmployees as $allEmployee) {
         $id = $allEmployee->id;
         $user = new User();
         $user = $user->Find('employee = ?', array($id));
         $readOnly = '';
         $readOnlyButton = '';
         if ($user[0]->username == 'HRManager') {
             $readOnly = 'readonly';
             $readOnlyButton = 'display:none;';
         }
         $employee = new Employee();
         $employee = $employee->Find("id = ?", array($id));
         $salary = $employee[0]->salary;
         $jobTitle = $employee[0]->job_title;
         $location = $employee[0]->work_location;
         $payGrade = new JobTitles();
         $payGrade = $payGrade->Find('id = ?', array($jobTitle));
         $payGrade = $payGrade[0]->grade;
         $leaves = new LeaveType();
         $leaves = $leaves->Find('location = ?', array($location));
         $vacations = $this->getTotalVacation($id, $salary);
         if (!$vacations) {
             $vacations = 0;
         }
         $attendaceTotal = $this->getTotalLateCost($id, $salary);
         $loans = $this->getTotalLoans($id);
         $taxes = $this->getTotalTaxes($salary);
         $allowances = $this->getTotalGradeAllowances($payGrade);
         $exptionalLoans = $this->getTotalExptionalLoans($id);
         $loansTotal = $loans + $exptionalLoans;
         $totalPalenties = $loansTotal + $allowances + $taxes + $attendaceTotal + $vacations;
         $overTimeTotal = $this->getTotalOverTimeCost($id, $salary);
         $totalCompunctions = $overTimeTotal;
         $final = $salary + $totalCompunctions - $totalPalenties;
         $updatedemployee = new Employee();
         $updatedemployee->Load('id = ?', array($id));
         $updatedemployee->gross_salary = $final;
         $updatedemployee->Save();
     }
     print_r(1);
     exit;
 }
Esempio n. 10
0
 public function sendEmployeeEmails($emailList, $subject)
 {
     foreach ($emailList as $employeeId => $emailData) {
         $ccList = array();
         if (SettingsManager::getInstance()->getSetting('Notifications: Copy Document Expiry Emails to Manager') == '1') {
             $employee = new Employee();
             $employee->Load("id = ?", array($employeeId));
             if (!empty($employee->supervisor)) {
                 $supperuser = BaseService::getInstance()->getUserFromProfileId($employee->supervisor);
                 if (!empty($supperuser)) {
                     $ccList[] = $supperuser->email;
                 }
             }
         }
         $user = BaseService::getInstance()->getUserFromProfileId($employeeId);
         if (!empty($user) && !empty($user->email)) {
             $email = new IceEmail();
             $email->subject = $subject;
             $email->toEmail = $user->email;
             $email->template = $emailData;
             $email->params = '[]';
             $email->cclist = json_encode($ccList);
             $email->bcclist = '[]';
             $email->status = 'Pending';
             $email->created = date('Y-m-d H:i:s');
             $email->updated = date('Y-m-d H:i:s');
             $ok = $email->Save();
             if (!$ok) {
                 LogManager::getInstance()->error("Error Saving Email: " . $email->ErrorMsg());
             }
         }
     }
 }