public function init()
 {
     //Add Employee time sheets if it is not already created for current week
     $empId = $this->getCurrentEmployeeId();
     if (date('w', strtotime("now")) == 0) {
         $start = date("Y-m-d", strtotime("now"));
     } else {
         $start = date("Y-m-d", strtotime("last Sunday"));
     }
     if (date('w', strtotime("now")) == 6) {
         $end = date("Y-m-d", strtotime("now"));
     } else {
         $end = date("Y-m-d", strtotime("next Saturday"));
     }
     $timeSheet = new EmployeeTimeSheet();
     $timeSheet->Load("employee = ? and date_start = ? and date_end = ?", array($empId, $start, $end));
     if ($timeSheet->date_start == $start && $timeSheet->employee == $empId) {
     } else {
         if (!empty($empId)) {
             $timeSheet->employee = $empId;
             $timeSheet->date_start = $start;
             $timeSheet->date_end = $end;
             $timeSheet->status = "Pending";
             $ok = $timeSheet->Save();
             if (!$ok) {
                 error_log("Error creating time sheet : " . $timeSheet->ErrorMsg());
             }
         }
     }
     //Generate missing timesheets
 }
 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;
 }
 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);
 }