public function getLeavesForMeAndSubordinates($req){ $shareCalendar = $this->baseService->settingsManager->getSetting("Leave: Share Calendar to Whole Company"); $map = json_decode('{"employee":["Employee","id","first_name+last_name"],"leave_type":["LeaveType","id","name"]}'); $employee = $this->baseService->getElement('Employee',$this->getCurrentProfileId(),null,true); if($shareCalendar != "1"){ $subordinate = new Employee(); $subordinates = $subordinate->Find("supervisor = ?",array($employee->id)); $subordinatesIds = $employee->id; foreach($subordinates as $sub){ if($subordinatesIds != ""){ $subordinatesIds.=","; } $subordinatesIds.=$sub->id; } $employeeLeave = new EmployeeLeave(); $startDate = date("Y-m-d H:i:s",$req->start); $endDate = date("Y-m-d H:i:s",$req->end); $list = $employeeLeave->Find("employee in (".$subordinatesIds.") and status in ('Approved','Pending') and ((date_start >= ? and date_start <= ? ) or (date_end >= ? and date_end <= ?))",array($startDate,$endDate,$startDate,$endDate)); }else{ $employeeLeave = new EmployeeLeave(); $startDate = date("Y-m-d H:i:s",$req->start); $endDate = date("Y-m-d H:i:s",$req->end); $list = $employeeLeave->Find("status in ('Approved','Pending') and ((date_start >= ? and date_start <= ? ) or (date_end >= ? and date_end <= ?))",array($startDate,$endDate,$startDate,$endDate)); } if(!$list){ LogManager::getInstance()->info($employeeLeave->ErrorMsg()); } if(!empty($map)){ $list = $this->baseService->populateMapping($list,$map); } $data = array(); foreach($list as $leave){ $data[] = $this->leaveToEvent($leave); } $holiday = new HoliDay(); $holidays = $holiday->Find("1=1",array()); foreach($holidays as $holiday){ $data[] = $this->holidayToEvent($holiday); } echo json_encode($data); exit(); }
public function getData($report, $req) { $leaveActionManager = new LeavesActionManager(); $department = $req['department']; $employeeId = $req['employee']; if (($employeeId == "NULL" || empty($employeeId)) && ($department == "NULL" || empty($department))) { $emp = new Employee(); $employees = $emp->Find("status = 'Active'", array()); } else { if ($employeeId != "NULL" && !empty($employeeId)) { $emp = new Employee(); $employees = $emp->Find("id = ?", array($employeeId)); } else { $emp = new Employee(); $employees = $emp->Find("department = ? and status = 'Active'", array($department)); } } $reportData = array(); $reportData[] = array("Employee ID", "Employee", "Leave Type", "Pending", "Approved", "Rejected", "Canceled", "Available", "To be Accrued", "Carried Forward from Previous Years"); foreach ($employees as $employee) { $leaveEntitlements = $leaveActionManager->getEntitlementByEmployee($employee)->getObject(); foreach ($leaveEntitlements as $leaveEntitlement) { $reportData[] = array($employee->employee_id, $employee->first_name . " " . $employee->last_name, $leaveEntitlement['name'], $leaveEntitlement['pendingLeaves'], $leaveEntitlement['approvedLeaves'], $leaveEntitlement['rejectedLeaves'], $leaveEntitlement['cancelRequestedLeaves'], $leaveEntitlement['availableLeaves'], $leaveEntitlement['tobeAccrued'], $leaveEntitlement['carriedForward']); } } return $reportData; }
public function get($req) { $profileId = $this->getCurrentProfileId(); $subordinate = new Employee(); $subordinatesCount = $subordinate->Count("supervisor = ? and id = ?", array($profileId, $req->id)); if ($this->user->user_level == 'Admin' || $subordinatesCount > 0) { $id = $req->id; } if (empty($id)) { $id = $profileId; } $employee = $this->baseService->getElement('Employee', $id, $req->map, true); $subordinate = new Employee(); $subordinates = $subordinate->Find("supervisor = ?", array($employee->id)); $employee->subordinates = $subordinates; $fs = FileService::getInstance(); $employee = $fs->updateProfileImage($employee); if (!empty($employee->birthday)) { $employee->birthday = date("F jS, Y", strtotime($employee->birthday)); } if (!empty($employee->driving_license_exp_date)) { $employee->driving_license_exp_date = date("F jS, Y", strtotime($employee->driving_license_exp_date)); } if (!empty($employee->joined_date)) { $employee->joined_date = date("F jS, Y", strtotime($employee->joined_date)); } $employeeEmergencyContacts = new EmergencyContact(); $employeeEmergencyContacts = $employeeEmergencyContacts->Find("employee = ?", array($id)); $employee->EmergencyContacts = $employeeEmergencyContacts; if (empty($employee->id)) { return new IceResponse(IceResponse::ERROR, $employee); } return new IceResponse(IceResponse::SUCCESS, array($employee, $this->getCurrentProfileId(), $this->user->employee)); }
public function get($req) { $employee = $this->baseService->getElement('Employee', $this->getCurrentEmployeeId(), $req->map, true); $subordinate = new Employee(); $subordinates = $subordinate->Find("supervisor = ?", array($employee->id)); $employee->subordinates = $subordinates; $fs = new FileService(); $employee = $fs->updateEmployeeImage($employee); if (!empty($employee->birthday)) { $employee->birthday = date("F jS, Y", strtotime($employee->birthday)); } if (!empty($employee->driving_license_exp_date)) { $employee->driving_license_exp_date = date("F jS, Y", strtotime($employee->driving_license_exp_date)); } if (!empty($employee->joined_date)) { $employee->joined_date = date("F jS, Y", strtotime($employee->joined_date)); } if (empty($employee->id)) { return new IceResponse(IceResponse::ERROR, $employee); } return new IceResponse(IceResponse::SUCCESS, $employee); }
public function getSubEmployeeTimeSheets($req) { $employee = $this->baseService->getElement('Employee', $this->getCurrentProfileId(), null, true); $subordinate = new Employee(); $subordinates = $subordinate->Find("supervisor = ?", array($employee->id)); $subordinatesIds = ""; foreach ($subordinates as $sub) { if ($subordinatesIds != "") { $subordinatesIds .= ","; } $subordinatesIds .= $sub->id; } $subordinatesIds .= ""; $mappingStr = $req->sm; $map = json_decode($mappingStr); $timeSheet = new EmployeeTimeSheet(); $list = $timeSheet->Find("employee in (" . $subordinatesIds . ")", array()); if (!$list) { LogManager::getInstance()->info($timeSheet->ErrorMsg()); } if (!empty($mappingStr)) { $list = $this->baseService->populateMapping($list, $map); } return new IceResponse(IceResponse::SUCCESS, $list); }
public function changeLeaveStatus($req) { $employee = $this->baseService->getElement('Employee', $this->getCurrentProfileId(), null, true); $subordinate = new Employee(); $subordinates = $subordinate->Find("supervisor = ?", array($employee->id)); $subordinatesIds = array(); foreach ($subordinates as $sub) { $subordinatesIds[] = $sub->id; } $employeeLeave = new EmployeeLeave(); $employeeLeave->Load("id = ?", array($req->id)); if ($employeeLeave->id != $req->id) { return new IceResponse(IceResponse::ERROR, "Leave not found"); } if (!in_array($employeeLeave->employee, $subordinatesIds) && $this->user->user_level != 'Admin') { return new IceResponse(IceResponse::ERROR, "This leave does not belong to any of your subordinates"); } $oldLeaveStatus = $employeeLeave->status; $employeeLeave->status = $req->status; if ($oldLeaveStatus == $req->status) { return new IceResponse(IceResponse::SUCCESS, ""); } $ok = $employeeLeave->Save(); if (!$ok) { LogManager::getInstance()->info($employeeLeave->ErrorMsg()); return new IceResponse(IceResponse::ERROR, "Error occured while saving leave infomation. Please contact admin"); } $employeeLeaveLog = new EmployeeLeaveLog(); $employeeLeaveLog->employee_leave = $employeeLeave->id; $employeeLeaveLog->user_id = $this->baseService->getCurrentUser()->id; $employeeLeaveLog->status_from = $oldLeaveStatus; $employeeLeaveLog->status_to = $employeeLeave->status; $employeeLeaveLog->created = date("Y-m-d H:i:s"); $employeeLeaveLog->data = isset($req->reason) ? $req->reason : ""; $ok = $employeeLeaveLog->Save(); if (!$ok) { LogManager::getInstance()->info($employeeLeaveLog->ErrorMsg()); } if (!empty($this->emailSender) && $oldLeaveStatus != $employeeLeave->status) { $leavesEmailSender = new LeavesEmailSender($this->emailSender, $this); $leavesEmailSender->sendLeaveStatusChangedEmail($employee, $employeeLeave); } $this->baseService->audit(IceConstants::AUDIT_ACTION, "Leave status changed \\ from:" . $oldLeaveStatus . "\\ to:" . $employeeLeave->status . " \\ id:" . $employeeLeave->id); if ($employeeLeave->status != "Pending") { $notificationMsg = "Your leave has been {$employeeLeave->status} by " . $employee->first_name . " " . $employee->last_name; if (!empty($req->reason)) { $notificationMsg .= " (Note:" . $req->reason . ")"; } } $this->baseService->notificationManager->addNotification($employeeLeave->employee, $notificationMsg, '{"type":"url","url":"g=modules&n=leaves&m=module_Leaves#tabEmployeeLeaveApproved"}', IceConstants::NOTIFICATION_LEAVE); return new IceResponse(IceResponse::SUCCESS, ""); }
foreach ($filter as $k => $v) { $countFilterQuery .= " and " . $k . "=?"; $countFilterQueryData[] = $v; } } } if (in_array($table, $baseService->userTables) && !$skipEmployeeRestriction && !$isSubOrdinates) { $cemp = $baseService->getCurrentEmployeeId(); $sql = "Select count(id) as count from " . $obj->_table . " where employee = ? " . $countFilterQuery; array_unshift($countFilterQueryData, $cemp); $rowCount = $obj->DB()->Execute($sql, $countFilterQueryData); } else { if ($isSubOrdinates) { $cemp = $baseService->getCurrentEmployeeId(); $subordinate = new Employee(); $subordinates = $subordinate->Find("supervisor = ?", array($cemp)); $subordinatesIds = ""; foreach ($subordinates as $sub) { if ($subordinatesIds != "") { $subordinatesIds .= ","; } $subordinatesIds .= $sub->id; } $subordinatesIds .= ""; $sql = "Select count(id) as count from " . $obj->_table . " where employee in (" . $subordinatesIds . ") " . $countFilterQuery; $rowCount = $obj->DB()->Execute($sql, $countFilterQueryData); } else { $sql = "Select count(id) as count from " . $obj->_table; if (!empty($countFilterQuery)) { $sql .= " where 1=1 " . $countFilterQuery; }
public function Find($whereOrderBy, $bindarr = false, $pkeysArr = false, $extra = array()) { $shift = intval(SettingsManager::getInstance()->getSetting("Attendance: Shift (Minutes)")); $employee = new Employee(); $data = array(); $employees = $employee->Find("1=1"); $attendance = new Attendance(); $attendanceToday = $attendance->Find("date(in_time) = ?", array(date("Y-m-d"))); $attendanceData = array(); //Group by employee foreach ($attendanceToday as $attendance) { if (isset($attendanceData[$attendance->employee])) { $attendanceData[$attendance->employee][] = $attendance; } else { $attendanceData[$attendance->employee] = array($attendance); } } foreach ($employees as $employee) { $entry = new stdClass(); $entry->id = $employee->id; $entry->employee = $employee->id; if (isset($attendanceData[$employee->id])) { $attendanceEntries = $attendanceData[$employee->id]; foreach ($attendanceEntries as $atEntry) { if ($atEntry->out_time == "0000-00-00 00:00:00" || empty($atEntry->out_time)) { if (strtotime($atEntry->in_time) < time() + $shift * 60) { $entry->status = "Clocked In"; $entry->statusId = 0; } } } if (empty($entry->status)) { $entry->status = "Clocked Out"; $entry->statusId = 1; } } else { $entry->status = "Not Clocked In"; $entry->statusId = 2; } $data[] = $entry; } function cmp($a, $b) { return $a->statusId - $b->statusId; } usort($data, "cmp"); return $data; }
public function changeLeaveStatus($req) { $employee = $this->baseService->getElement('Employee', $this->getCurrentEmployeeId()); $subordinate = new Employee(); $subordinates = $subordinate->Find("supervisor = ?", array($employee->id)); $subordinatesIds = array(); foreach ($subordinates as $sub) { $subordinatesIds[] = $sub->id; } $employeeLeave = new EmployeeLeave(); $employeeLeave->Load("id = ?", array($req->id)); if ($employeeLeave->id != $req->id) { return new IceResponse(IceResponse::ERROR, "Leave not found"); } if (!in_array($employeeLeave->employee, $subordinatesIds) && $this->user->user_level != 'Admin') { return new IceResponse(IceResponse::ERROR, "This leave does not belong to any of your subordinates"); } $employeeLeave->status = $req->status; $ok = $employeeLeave->Save(); if (!$ok) { error_log($employeeLeave->ErrorMsg()); } if (!empty($this->emailSender)) { $leavesEmailSender = new LeavesEmailSender($this->emailSender, $this); $leavesEmailSender->sendLeaveStatusChangedEmail($employee, $employeeLeave); } return new IceResponse(IceResponse::SUCCESS, ""); }
public function setCurrentAdminEmployee($employeeId) { if (!function_exists('saveSessionObject')) { include APP_BASE_PATH . "include.common.php"; } if ($employeeId == "-1") { saveSessionObject('admin_current_employee', null); return; } if ($this->currentUser->user_level == 'Admin') { saveSessionObject('admin_current_employee', $employeeId); } else { if ($this->currentUser->user_level == 'Manager') { $subordinate = new Employee(); $subordinates = $subordinate->Find("supervisor = ?", array($this->currentUser->employee)); $subFound = false; foreach ($subordinates as $sub) { if ($sub->id == $employeeId) { $subFound = true; break; } } if (!$subFound) { return; } saveSessionObject('admin_current_employee', $employeeId); } } }