static function reCalculateDay($user_date_id, $enable_exception = FALSE, $enable_premature_exceptions = FALSE, $enable_future_exceptions = TRUE, $enable_holidays = FALSE)
 {
     Debug::text('Re-calculating User Date ID: ' . $user_date_id . ' Enable Exception: ' . (int) $enable_exception, __FILE__, __LINE__, __METHOD__, 10);
     $udtf = TTnew('UserDateTotalFactory');
     //Make sure we wrap this in a transaction in case its called directly and an error occurs, the first thing that happens
     //is system entries are deleted, so we need to be able to recover from that.
     $udtf->StartTransaction();
     $udtf->setUserDateId($user_date_id);
     $udtf->calcSystemTotalTime();
     if ($enable_holidays == TRUE) {
         $holiday_user_date_ids = $udtf->getHolidayUserDateIDs();
         if (is_array($holiday_user_date_ids)) {
             foreach ($holiday_user_date_ids as $holiday_user_date_id) {
                 Debug::Text('reCalculating Holiday...', __FILE__, __LINE__, __METHOD__, 10);
                 if ($user_date_id != $holiday_user_date_id) {
                     //Don't recalculate the same day twice.
                     UserDateTotalFactory::reCalculateDay($holiday_user_date_id, FALSE, FALSE, FALSE, FALSE);
                 }
             }
         }
         unset($holiday_user_date_ids, $holiday_user_date_id);
     }
     if (!isset(self::$calc_exception) and $enable_exception == TRUE) {
         ExceptionPolicyFactory::calcExceptions($user_date_id, $enable_premature_exceptions, $enable_future_exceptions);
     }
     $udtf->CommitTransaction();
     return TRUE;
 }
 static function reCalculateDay($user_date_id, $enable_exception = FALSE, $enable_premature_exceptions = FALSE, $enable_future_exceptions = TRUE, $enable_holidays = FALSE)
 {
     Debug::text('Re-calculating User Date ID: ' . $user_date_id . ' Enable Exception: ' . (int) $enable_exception, __FILE__, __LINE__, __METHOD__, 10);
     $udtf = new UserDateTotalFactory();
     $udtf->setUserDateId($user_date_id);
     $udtf->calcSystemTotalTime();
     if ($enable_holidays == TRUE) {
         $holiday_user_date_ids = $udtf->getHolidayUserDateIDs();
         //var_dump($holiday_user_date_ids);
         if (is_array($holiday_user_date_ids)) {
             foreach ($holiday_user_date_ids as $holiday_user_date_id) {
                 Debug::Text('reCalculating Holiday...', __FILE__, __LINE__, __METHOD__, 10);
                 UserDateTotalFactory::reCalculateDay($holiday_user_date_id, FALSE, FALSE, FALSE, FALSE);
             }
         }
         unset($holiday_user_date_ids, $holiday_user_date_id);
     }
     if (!isset(self::$calc_exception) and $enable_exception == TRUE) {
         ExceptionPolicyFactory::calcExceptions($user_date_id, $enable_premature_exceptions, $enable_future_exceptions);
     }
     return TRUE;
 }
 function postSave()
 {
     //If status is pending auth (55=declined) delete all authorization history, because they could be re-verifying.
     if ($this->getCurrentUser() != FALSE and $this->getStatus() == 55) {
         $alf = TTnew('AuthorizationListFactory');
         $alf->getByObjectTypeAndObjectId(90, $this->getId());
         if ($alf->getRecordCount() > 0) {
             foreach ($alf as $a_obj) {
                 //Delete the record outright for now, as marking it as deleted causes transaction issues
                 //and it never gets committed.
                 $a_obj->Delete();
             }
         }
     }
     $time_sheet_verification_type_id = $this->getVerificationType();
     if ($time_sheet_verification_type_id > 10) {
         //10 = Disabled
         $authorize_timesheet = FALSE;
         if ($time_sheet_verification_type_id == 20) {
             //Employee Only
             $authorize_timesheet = TRUE;
         } elseif ($time_sheet_verification_type_id == 30) {
             //Superior Only
             if ($this->getStatus() == 30 and $this->getCurrentUser() != FALSE) {
                 //Check on CurrentUser so we don't loop indefinitely through AuthorizationFactory.
                 Debug::Text(' aAuthorizing TimeSheet as superior...', __FILE__, __LINE__, __METHOD__, 10);
                 $authorize_timesheet = TRUE;
             }
         } elseif ($time_sheet_verification_type_id == 40) {
             //Superior & Employee
             if ($this->getStatus() == 30 and $this->getCurrentUser() != FALSE and $this->getCurrentUser() != $this->getUser()) {
                 //Check on CurrentUser so we don't loop indefinitely through AuthorizationFactory.
                 Debug::Text(' bAuthorizing TimeSheet as superior...', __FILE__, __LINE__, __METHOD__, 10);
                 $authorize_timesheet = TRUE;
             }
         }
         if ($authorize_timesheet == TRUE) {
             $af = TTnew('AuthorizationFactory');
             $af->setCurrentUser($this->getCurrentUser());
             $af->setObjectType('timesheet');
             $af->setObject($this->getId());
             $af->setAuthorized(TRUE);
             if ($af->isValid()) {
                 $af->Save();
             }
         } else {
             Debug::Text('Not authorizing timesheet...', __FILE__, __LINE__, __METHOD__, 10);
         }
         if ($authorize_timesheet == TRUE or $this->getAuthorized() == TRUE) {
             //Recalculate exceptions on the last day of pay period to remove any TimeSheet Not Verified exceptions.
             //Get user_date_id.
             if (is_object($this->getPayPeriodObject())) {
                 $udlf = new UserDateListFactory();
                 $udlf->getByUserIdAndDate($this->getUser(), $this->getPayPeriodObject()->getEndDate());
                 if ($udlf->getRecordCount() > 0) {
                     Debug::Text('Recalculating exceptions on last day of pay period... Date: ' . $this->getPayPeriodObject()->getEndDate(), __FILE__, __LINE__, __METHOD__, 10);
                     ExceptionPolicyFactory::calcExceptions($udlf->getCurrent()->getID(), FALSE, FALSE);
                 }
             } else {
                 Debug::Text('No Pay Period found...', __FILE__, __LINE__, __METHOD__, 10);
             }
         } else {
             Debug::Text('Not recalculating last day of pay period...', __FILE__, __LINE__, __METHOD__, 10);
         }
     } else {
         Debug::Text('TimeSheet Verification is disabled...', __FILE__, __LINE__, __METHOD__, 10);
     }
     return TRUE;
 }
示例#4
0
$execution_time = time();
//Calculate exceptions just for today and yesterday, because some shifts may start late in the day and need to be handled first thing in the morning.
//Make sure we also go one day in the future too, since the servers can be PST and if its 11:00PM, it will stop at midnight for that day, so
//shifts that would have already started in a different timezone (say EST) will not receive exceptions until we have moved into the next day for PST (3hrs late)
$start_date = TTDate::getBeginDayEpoch(TTDate::getMiddleDayEpoch($execution_time) - 86400);
$end_date = TTDate::getEndDayEpoch(TTDate::getMiddleDayEpoch($execution_time) + 86400);
$udlf = new UserDateListFactory();
//Use optimized query to speed this process up significantly.
$udlf->getMidDayExceptionsByStartDateAndEndDateAndPayPeriodStatus($start_date, $end_date, array(10, 12, 15, 30));
Debug::text(' calcQuickExceptions: Start Date: ' . TTDate::getDate('DATE+TIME', $start_date) . ' End Date: ' . TTDate::getDate('DATE+TIME', $end_date) . ' User Date Rows: ' . $udlf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 5);
if ($udlf->getRecordCount() > 0) {
    $i = 0;
    foreach ($udlf as $ud_obj) {
        $user_obj_prefs = $ud_obj->getUserObject()->getUserPreferenceObject();
        if (is_object($user_obj_prefs)) {
            $user_obj_prefs->setTimeZonePreferences();
        } else {
            //Use system timezone.
            TTDate::setTimeZone();
        }
        Debug::text('(' . $i . '). User: '******' Date: ' . TTDate::getDate('DATE+TIME', $ud_obj->getDateStamp()) . ' User Date ID: ' . $ud_obj->getId(), __FILE__, __LINE__, __METHOD__, 5);
        //Calculate pre-mature exceptions, so pre-mature Missing Out Punch exceptions arn't made active until they are ready.
        //Don't calculate future exceptions though.
        ExceptionPolicyFactory::calcExceptions($ud_obj->getId(), TRUE, FALSE);
        TTDate::setTimeZone();
        $i++;
    }
}
Debug::text(' calcQuickExceptions: Done', __FILE__, __LINE__, __METHOD__, 5);
Debug::writeToLog();
Debug::Display();