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 getLeavesForMeAndSubordinates($req) { $map = json_decode('{"employee":["Employee","id","first_name+last_name"],"leave_type":["LeaveType","id","name"]}'); $employee = $this->baseService->getElement('Employee', $this->getCurrentProfileId(), null, true); $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(); $leaveType = new LeaveType(); $leaveTypesTemp = $leaveType->Find("1=1"); $leaveTypes = array(); foreach ($leaveTypesTemp as $leaveType) { $leaveTypes[$leaveType->name] = $leaveType; } foreach ($list as $leave) { $data[] = $this->leaveToEvent($leave, $leaveTypes); } $holiday = new HoliDay(); $holidays = $holiday->Find("1=1", array()); foreach ($holidays as $holiday) { $data[] = $this->holidayToEvent($holiday); } echo json_encode($data); exit; }
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, ""); }
public function changeLeaveStatus($req){ //$employee = $this->baseService->getElement('Employee',$this->getCurrentEmployeeId()); $employeeLeave = new EmployeeLeave(); $employeeLeave->Load("id = ?",array($req->id)); if($employeeLeave->id != $req->id){ return new IceResponse(IceResponse::ERROR,"Leave not found"); } if($this->user->user_level != 'Admin'){ return new IceResponse(IceResponse::ERROR,"Only an admin can do this"); } $oldLeaveStatus = $employeeLeave->status; $employeeLeave->status = $req->status; $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()); } $employee = $this->getEmployeeById($employeeLeave->employee); if($oldLeaveStatus != $employeeLeave->status){ $this->sendLeaveStatusChangedEmail($employee, $employeeLeave); } $this->baseService->audit(IceConstants::AUDIT_ACTION, "Leave status changed \ from:".$oldLeaveStatus."\ to:".$employeeLeave->status." \ id:".$employeeLeave->id); $currentEmpId = $this->getCurrentProfileId(); if(!empty($currentEmpId)){ $employee = $this->baseService->getElement('Employee',$currentEmpId); 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,""); }
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 changeLeaveStatus($req) { //$employee = $this->baseService->getElement('Employee',$this->getCurrentEmployeeId()); $employeeLeave = new EmployeeLeave(); $employeeLeave->Load("id = ?", array($req->id)); if ($employeeLeave->id != $req->id) { return new IceResponse(IceResponse::ERROR, "Leave not found"); } if ($this->user->user_level != 'Admin') { return new IceResponse(IceResponse::ERROR, "Only an admin can do this"); } $employeeLeave->status = $req->status; $ok = $employeeLeave->Save(); if (!$ok) { error_log($employeeLeave->ErrorMsg()); } return new IceResponse(IceResponse::SUCCESS, ""); }
public function getSubEmployeeLeaves($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); $employeeLeave = new EmployeeLeave(); $list = $employeeLeave->Find("employee in (" . $subordinatesIds . ")", array()); if (!$list) { LogManager::getInstance()->info($employeeLeave->ErrorMsg()); } if (!empty($mappingStr)) { $list = $this->baseService->populateMapping($list, $map); } return new IceResponse(IceResponse::SUCCESS, $list); }