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 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 getInitData($req)
 {
     $data = array();
     $employees = new Employee();
     $data['numberOfEmployees'] = $employees->Count("1 = 1");
     $company = new CompanyStructure();
     $data['numberOfCompanyStuctures'] = $company->Count("1 = 1");
     $user = new User();
     $data['numberOfUsers'] = $user->Count("1 = 1");
     $project = new Project();
     $data['numberOfProjects'] = $project->Count("status = 'Active'");
     $attendance = new Attendance();
     $data['numberOfAttendanceLastWeek'] = $attendance->Count("in_time > '" . date("Y-m-d H:i:s", strtotime("-1 week")) . "'");
     if (empty($data['numberOfAttendanceLastWeek'])) {
         $data['numberOfAttendanceLastWeek'] = 0;
     }
     $empLeave = new EmployeeLeave();
     $data['numberOfLeaves'] = $empLeave->Count("date_start > '" . date("Y-m-d") . "'");
     $timeEntry = new EmployeeTimeEntry();
     $data['numberOfAttendanceLastWeek'] = $timeEntry->Count("in_time > '" . date("Y-m-d H:i:s", strtotime("-1 week")) . "'");
     $candidate = new Candidate();
     $data['numberOfCandidates'] = $candidate->Count("1 = 1");
     $job = new Job();
     $data['numberOfJobs'] = $job->Count("status = 'Active'");
     $course = new Course();
     $data['numberOfCourses'] = $course->Count("1 = 1");
     return new IceResponse(IceResponse::SUCCESS, $data);
 }
 public function getPendingLeaves($req)
 {
     $lam = new LeavesActionManager();
     $leavePeriod = $lam->getCurrentLeavePeriod(date("Y-m-d H:i:s"), date("Y-m-d H:i:s"));
     $leave = new EmployeeLeave();
     $pendingLeaves = $leave->Find("status = ? and employee = ?", array("Pending", $this->getCurrentProfileId()));
     return new IceResponse(IceResponse::SUCCESS, count($pendingLeaves));
 }
 /**
  * Bind data to the view.
  *
  * @param  View  $view
  * @return void
  */
 public function compose(View $view)
 {
     $user = $this->user;
     $travelOrderCount = TravelOrder::filed()->where('recommending_approval', $this->user->employee->id)->count();
     $regularLeaveCount = EmployeeLeave::where('recommending_approval', $user->employee->id)->filed()->count();
     $specialLeaveCount = EmployeeSpecialLeave::where('recommending_approval', $user->employee->id)->filed()->count();
     $view->with(compact('user', 'travelOrderCount', 'regularLeaveCount', 'specialLeaveCount'));
 }
 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);
 }
Exemple #11
0
 public function addEmployeeLeave(EmployeeLeave $l)
 {
     $this->collEmployeeLeaves[] = $l;
     $l->setEmployeeLevel($this);
 }
Employee::SetDatabaseAdapter($dbLocal);
User::SetDatabaseAdapter($dbLocal);
EmployeeSkill::SetDatabaseAdapter($dbLocal);
EmployeeEducation::SetDatabaseAdapter($dbLocal);
EmployeeCertification::SetDatabaseAdapter($dbLocal);
EmployeeLanguage::SetDatabaseAdapter($dbLocal);
EmergencyContact::SetDatabaseAdapter($dbLocal);
EmployeeDependent::SetDatabaseAdapter($dbLocal);
EmployeeImmigration::SetDatabaseAdapter($dbLocal);
EmployeeSalary::SetDatabaseAdapter($dbLocal);
LeaveType::SetDatabaseAdapter($dbLocal);
LeavePeriod::SetDatabaseAdapter($dbLocal);
WorkDay::SetDatabaseAdapter($dbLocal);
HoliDay::SetDatabaseAdapter($dbLocal);
LeaveRule::SetDatabaseAdapter($dbLocal);
EmployeeLeave::SetDatabaseAdapter($dbLocal);
EmployeeLeaveDay::SetDatabaseAdapter($dbLocal);
File::SetDatabaseAdapter($dbLocal);
Client::SetDatabaseAdapter($dbLocal);
Project::SetDatabaseAdapter($dbLocal);
EmployeeTimeSheet::SetDatabaseAdapter($dbLocal);
EmployeeTimeEntry::SetDatabaseAdapter($dbLocal);
EmployeeProject::SetDatabaseAdapter($dbLocal);
Document::SetDatabaseAdapter($dbLocal);
EmployeeDocument::SetDatabaseAdapter($dbLocal);
CompanyLoan::SetDatabaseAdapter($dbLocal);
EmployeeCompanyLoan::SetDatabaseAdapter($dbLocal);
Setting::SetDatabaseAdapter($dbLocal);
ChiNhanh::SetDatabaseAdapter($dbLocal);
Ca::SetDatabaseAdapter($dbLocal);
BoPhan::SetDatabaseAdapter($dbLocal);