Example #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());
     }
 }
Example #2
0
 /**
  * Validates given array of time events.
  * This function acts as a second level of validation. The time events
  * should have been validated in client side javascript as well.
  *
  * @param array $timeEventArray Array of time event objects to validate.
  * @return mixed true if validate success, error string if not.
  */
 public function validateTimeEvents($timeEventArray)
 {
     $timesheetArray = array();
     foreach ($timeEventArray as $timeEvent) {
         $timesheetId = $timeEvent->getTimesheetId();
         if (empty($timesheetId)) {
             return self::NO_TIMESHEET_FAILURE;
         }
         if (isset($timesheetArray[$timesheetId])) {
             $timesheet = $timesheetArray[$timesheetId];
         } else {
             $tmpSheet = new Timesheet();
             $tmpSheet->setTimesheetId($timesheetId);
             $sheets = $tmpSheet->fetchTimesheets();
             if (empty($sheets) || !is_object($sheets[0])) {
                 return self::NO_TIMESHEET_FAILURE;
             }
             $timesheet = $sheets[0];
         }
         $timesheetArray[$timesheetId] = $timesheet;
         $result = $this->validateTimeEvent($timeEvent, $timesheet);
         if (!($result === true)) {
             return $result;
         }
     }
     return true;
 }