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 getTimeEntries($req) { $employee = $this->baseService->getElement('Employee', $this->getCurrentProfileId(), null, true); $timeSheetEntry = new EmployeeTimeEntry(); $list = $timeSheetEntry->Find("timesheet = ? order by date_start", array($req->id)); $mappingStr = $req->sm; $map = json_decode($mappingStr); if (!$list) { LogManager::getInstance()->info($timeSheetEntry->ErrorMsg()); } if (!empty($mappingStr)) { $list = $this->baseService->populateMapping($list, $map); } return new IceResponse(IceResponse::SUCCESS, $list); }
public function getTotalTime() { $start = $this->date_start . " 00:00:00"; $end = $this->date_end . " 23:59:59"; $timeEntry = new EmployeeTimeEntry(); $list = $timeEntry->Find("employee = ? and ((date_start >= ? and date_start <= ?) or (date_end >= ? and date_end <= ?))", array($this->employee, $start, $end, $start, $end)); $seconds = 0; foreach ($list as $entry) { $secondsTemp = strtotime($entry->date_end) - strtotime($entry->date_start); if ($secondsTemp < 0) { $secondsTemp = 0; } $seconds += $secondsTemp; } $totMinutes = round($seconds / 60); $minutes = $totMinutes % 60; $hours = ($totMinutes - $minutes) / 60; return CalendarTools::addLeadingZero($hours) . ":" . CalendarTools::addLeadingZero($minutes); }
public function getLastTimeSheetHours($req) { $timeSheet = new EmployeeTimeSheet(); $timeSheet->Load("employee = ? order by date_end desc limit 1", array($this->getCurrentProfileId())); if (empty($timeSheet->employee)) { return new IceResponse(IceResponse::SUCCESS, "0:00"); } $timeSheetEntry = new EmployeeTimeEntry(); $list = $timeSheetEntry->Find("timesheet = ?", array($timeSheet->id)); $seconds = 0; foreach ($list as $entry) { $seconds += strtotime($entry->date_end) - strtotime($entry->date_start); } $minutes = (int) ($seconds / 60); $rem = $minutes % 60; $hours = ($minutes - $rem) / 60; if ($rem < 10) { $rem = "0" . $rem; } return new IceResponse(IceResponse::SUCCESS, $hours . ":" . $rem); }
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; }
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); Nguon::SetDatabaseAdapter($dbLocal); LoaiNgay::SetDatabaseAdapter($dbLocal); NVState::SetDatabaseAdapter($dbLocal); NhanVien::SetDatabaseAdapter($dbLocal); NhuCauTuyenDung::SetDatabaseAdapter($dbLocal); $baseService = new BaseService();
public function getTimeUtilization($req) { if (empty($req->start)) { $req->start = date("Y-m-01"); } if (empty($req->end)) { $req->end = date("Y-m-t", strtotime($req->start)); } //Find Time Entries $employeeTimeEntry = new EmployeeTimeEntry(); if (empty($req->employee)) { $timeEntryList = $employeeTimeEntry->Find("date(date_start) >= ? and date(date_end) <= ?", array($req->start, $req->end)); } else { $timeEntryList = $employeeTimeEntry->Find("employee = ? and date(date_start) >= ? and date(date_end) <= ?", array($req->employee, $req->start, $req->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(); if (empty($req->employee)) { $atteandanceList = $attendance->Find("date(in_time) >= ? and date(out_time) <= ? and in_time < out_time", array($req->start, $req->end)); } else { $atteandanceList = $attendance->Find("employee = ? and date(in_time) >= ? and date(out_time) <= ? and in_time < out_time", array($req->employee, $req->start, $req->end)); } $seconds = 0; $graphAttendanceArray = 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; } else { $graphAttendanceArray[$key] = $seconds; } } $data = array(); $data[] = array("key" => "Hours in Attendance", "values" => array()); $data[] = array("key" => "Hours Worked", "values" => array()); //Iterate date range $interval = DateInterval::createFromDateString('1 day'); $period = new DatePeriod(new DateTime($req->start), $interval, new DateTime($req->end)); foreach ($period as $dt) { $key = $dt->format("Y-m-d"); if (isset($graphAttendanceArray[$key])) { $data[0]['values'][] = array("x" => $key, "y" => round($graphAttendanceArray[$key] / 3600, 2)); } else { $data[0]['values'][] = array("x" => $key, "y" => 0); } if (isset($graphTimeArray[$key])) { $data[1]['values'][] = array("x" => $key, "y" => round($graphTimeArray[$key] / 3600, 2)); } else { $data[1]['values'][] = array("x" => $key, "y" => 0); } } /* //Test data for($i = 1; $i<31; $i++){ $data[0]['values'][] = array("x"=>$i, "y"=>rand(2,9)); $data[1]['values'][] = array("x"=>$i, "y"=>rand(2,8)); } */ return new IceResponse(IceResponse::SUCCESS, $data); }