Beispiel #1
0
 public function resolveTimesheet($submissionPeriodId = null)
 {
     if ($this->getTimesheetId() == null) {
         $timesheetObj = new Timesheet();
         $timesheetSubmissionPeriodObj = new TimesheetSubmissionPeriod();
         if ($submissionPeriodId != null) {
             $timesheetSubmissionPeriodObj->setTimesheetPeriodId($submissionPeriodId);
         }
         $timesheetSubmissionPeriods = $timesheetSubmissionPeriodObj->fetchTimesheetSubmissionPeriods();
         $startTime = $this->getStartTime();
         if (!isset($startTime)) {
             $startTime = $this->getReportedDate();
         }
         $currTime = strtotime($startTime);
         $day = date('N', $currTime);
         $diff = $timesheetSubmissionPeriods[0]->getStartDay() - $day;
         if ($diff > 0) {
             $diff = $diff - 7;
         }
         $sign = $diff < 0 ? "" : "+";
         $timesheetObj->setStartDate(date('Y-m-d', strtotime("{$sign}{$diff} day", $currTime)));
         $diff = $timesheetSubmissionPeriods[0]->getEndDay() - $day;
         if (0 > $diff) {
             $diff = $diff + 7;
         }
         $sign = $diff < 0 ? "" : "+";
         $timesheetObj->setEndDate(date('Y-m-d', strtotime("{$sign}{$diff} day", $currTime)) . " 23:59:59");
         $timesheetObj->setTimesheetPeriodId($timesheetSubmissionPeriods[0]->getTimesheetPeriodId());
         $timesheetObj->setEmployeeId($this->getEmployeeId());
         $timesheets = $timesheetObj->fetchTimesheets();
         if (!$timesheets || !$timesheets[0]) {
             $timesheetObj->setStatus(Timesheet::TIMESHEET_STATUS_NOT_SUBMITTED);
             $timesheetObj->addTimesheet();
             $timesheetObj->setTimesheetId(null);
             $timesheets = $timesheetObj->fetchTimesheets();
         }
         $this->setTimesheetId($timesheets[0]->getTimesheetId());
     }
 }
Beispiel #2
0
 /**
  * Build the object with fetched records
  *
  * @access private
  * @return Timesheet[] array of timesheets
  */
 private function _buildObjArr($result)
 {
     $objArr = null;
     while ($row = mysql_fetch_assoc($result)) {
         $tmpTimeArr = new Timesheet();
         $tmpTimeArr->setTimesheetId($row[self::TIMESHEET_DB_FIELD_TIMESHEET_ID]);
         $tmpTimeArr->setEmployeeId($row[self::TIMESHEET_DB_FIELD_EMPLOYEE_ID]);
         $tmpTimeArr->setTimesheetPeriodId($row[self::TIMESHEET_DB_FIELD_TIMESHEET_PERIOD_ID]);
         $tmpTimeArr->setStartDate(date('Y-m-d', strtotime($row[self::TIMESHEET_DB_FIELD_START_DATE])));
         $tmpTimeArr->setEndDate(date('Y-m-d', strtotime($row[self::TIMESHEET_DB_FIELD_END_DATE])));
         $tmpTimeArr->setStatus($row[self::TIMESHEET_DB_FIELD_STATUS]);
         $tmpTimeArr->setComment($row[self::TIMESHEET_DB_FIELD_COMMENT]);
         $objArr[] = $tmpTimeArr;
     }
     return $objArr;
 }
 public function createTimesheets($startDate, $employeeId)
 {
     $datesInTheCurrenTimesheetPeriod = $this->getTimesheetPeriodService()->getDefinedTimesheetPeriod($startDate);
     $timesheetStartingDate = $datesInTheCurrenTimesheetPeriod[0];
     $endDate = end($datesInTheCurrenTimesheetPeriod);
     $timesheet = $this->getTimesheetByStartDateAndEmployeeId($timesheetStartingDate, $employeeId);
     if ($timesheet == null) {
         if ($this->checkForOverlappingTimesheets($timesheetStartingDate, $endDate, $employeeId) == 0) {
             $statusValuesArray['state'] = 1;
         } else {
             $accessFlowStateMachineService = new AccessFlowStateMachineService();
             $tempNextState = $accessFlowStateMachineService->getNextState(WorkflowStateMachine::FLOW_TIME_TIMESHEET, Timesheet::STATE_INITIAL, "SYSTEM", WorkflowStateMachine::TIMESHEET_ACTION_CREATE);
             $timesheet = new Timesheet();
             $timesheet->setState($tempNextState);
             $timesheet->setStartDate($timesheetStartingDate);
             $timesheet->setEndDate($endDate);
             $timesheet->setEmployeeId($employeeId);
             $timesheet = $this->saveTimesheet($timesheet);
             $statusValuesArray['state'] = 2;
             $statusValuesArray['startDate'] = $timesheetStartingDate;
         }
     } else {
         $statusValuesArray['state'] = 3;
     }
     return $statusValuesArray;
 }
Beispiel #4
0
 /**
  * Testing for saving a timesheet for newly made timesheets
  */
 public function testSaveTimesheetWithNewTimesheet()
 {
     TestDataService::truncateTables(array('Timesheet'));
     $timesheet = new Timesheet();
     $timesheet->setState("CREATED");
     $timesheet->setEmployeeId(200);
     $timesheet->setStartDate("2011-04-07");
     $timesheet->setEndDate("2011-04-14");
     $savedNewTimesheet = $this->timesheetDao->saveTimesheet($timesheet);
     $this->assertNotNull($savedNewTimesheet->getTimesheetId());
     $this->assertEquals($savedNewTimesheet->getState(), "CREATED");
     $this->assertEquals($savedNewTimesheet->getStartDate(), "2011-04-07");
 }
Beispiel #5
0
 /**
  * Create and return a timesheet object with given parameters.
  */
 private function _getTimesheet($timesheetId, $employeeId, $timesheetPeriodId, $startDate, $endDate, $status)
 {
     $timesheet = new Timesheet();
     $timesheet->setTimesheetId($timesheetId);
     $timesheet->setTimesheetId($timesheetPeriodId);
     $timesheet->setEmployeeId($employeeId);
     $timesheet->setStartDate($startDate);
     $timesheet->setEndDate($endDate);
     $timesheet->setStatus($status);
     return $timesheet;
 }