function isActiveLengthOfService($u_obj, $epoch) { if ($this->getMinimumLengthOfServiceUnit() == 50 or $this->getMaximumLengthOfServiceUnit() == 50) { //Hour based length of service, get users hours up until this period. $worked_time = TTDate::getHours($this->getWorkedTimeByUserIdAndEndDate($u_obj->getId(), $epoch)); Debug::Text(' Worked Time: ' . $worked_time . 'hrs', __FILE__, __LINE__, __METHOD__, 10); } $employed_days = TTDate::getDays($epoch - $u_obj->getHireDate()); Debug::Text(' Employed Days: ' . $employed_days, __FILE__, __LINE__, __METHOD__, 10); $minimum_length_of_service_result = FALSE; $maximum_length_of_service_result = FALSE; //Check minimum length of service if ($this->getMinimumLengthOfService() == 0 or $this->getMinimumLengthOfServiceUnit() == 50 and $worked_time >= $this->getMinimumLengthOfService() or $this->getMinimumLengthOfServiceUnit() != 50 and $employed_days >= $this->getMinimumLengthOfServiceDays()) { $minimum_length_of_service_result = TRUE; } //Check maximum length of service. if ($this->getMaximumLengthOfService() == 0 or $this->getMaximumLengthOfServiceUnit() == 50 and $worked_time <= $this->getMaximumLengthOfService() or $this->getMaximumLengthOfServiceUnit() != 50 and $employed_days <= $this->getMaximumLengthOfServiceDays()) { $maximum_length_of_service_result = TRUE; } Debug::Text(' Min Result: : ' . (int) $minimum_length_of_service_result . ' Max Result: ' . (int) $maximum_length_of_service_result, __FILE__, __LINE__, __METHOD__, 10); if ($minimum_length_of_service_result == TRUE and $maximum_length_of_service_result == TRUE) { return TRUE; } return FALSE; }
function getNextPayPeriod($end_date = NULL) { if (!$this->Validator->isValid()) { return FALSE; } //Manual Pay Period Schedule, skip repeating... if ($this->getType() == 5) { return FALSE; } $pplf = new PayPeriodListFactory(); //Debug::text('PP Schedule ID: '. $this->getId(), __FILE__, __LINE__, __METHOD__, 10); //Debug::text('PP Schedule Name: '. $this->getName(), __FILE__, __LINE__, __METHOD__, 10); Debug::text('PP Schedule Type (' . $this->getType() . '): ' . Option::getByKey($this->getType(), $this->getOptions('type')), __FILE__, __LINE__, __METHOD__, 10); //Debug::text('Anchor Date: '. $this->getAnchorDate() ." - ". TTDate::getDate('DATE+TIME', $this->getAnchorDate() ), __FILE__, __LINE__, __METHOD__, 10); //Debug::text('Primary Date: '. $this->getPrimaryDate() ." - ". TTDate::getDate('DATE+TIME', $this->getPrimaryDate() ), __FILE__, __LINE__, __METHOD__, 10); //Debug::text('Secondary Date: '. $this->getSecondaryDate() ." - ". TTDate::getDate('DATE+TIME', $this->getPrimaryDate() ), __FILE__, __LINE__, __METHOD__, 10); $last_pay_period_is_new = FALSE; if ($end_date != '' and $end_date != 0) { Debug::text('End Date is set: ' . TTDate::getDate('DATE+TIME', $end_date), __FILE__, __LINE__, __METHOD__, 10); $last_pay_period_end_date = $end_date; } else { Debug::text('Checking for Previous pay periods...', __FILE__, __LINE__, __METHOD__, 10); //Get the last pay period schedule in the database. $pplf->getByPayPeriodScheduleId($this->getId(), NULL, NULL, NULL, array('start_date' => 'desc')); $last_pay_period = $pplf->getCurrent(); if ($last_pay_period->isNew()) { $last_pay_period_is_new = TRUE; Debug::text('No Previous pay periods...', __FILE__, __LINE__, __METHOD__, 10); //Do this so a rollover doesn't happen while we're calculating. //$last_pay_period_end_date = TTDate::getTime(); //This causes the pay period schedule to jump ahead one month. So set this to be beginning of the month. $last_pay_period_end_date = TTDate::getBeginMonthEpoch(); } else { Debug::text('Previous pay periods found... ID: ' . $last_pay_period->getId(), __FILE__, __LINE__, __METHOD__, 10); $last_pay_period_end_date = $last_pay_period->getEndDate(); } unset($last_pay_period, $pplf); } Debug::text('aLast Pay Period End Date: ' . TTDate::getDate('DATE+TIME', $last_pay_period_end_date) . ' (' . $last_pay_period_end_date . ')', __FILE__, __LINE__, __METHOD__, 10); //FIXME: This breaks having pay periods with different daily start times. //However, without it, I think DST breaks pay periods. //$last_pay_period_end_date = TTDate::getEndDayEpoch( $last_pay_period_end_date + 1 ) - 86400; $last_pay_period_end_date = TTDate::getEndDayEpoch($last_pay_period_end_date - 86400 / 2); Debug::text('bLast Pay Period End Date: ' . TTDate::getDate('DATE+TIME', $last_pay_period_end_date) . ' (' . $last_pay_period_end_date . ')', __FILE__, __LINE__, __METHOD__, 10); if ($this->getDayStartTime() != 0) { Debug::text('Daily Start Time is set, adjusting Last Pay Period End Date by: ' . TTDate::getHours($this->getDayStartTime()), __FILE__, __LINE__, __METHOD__, 10); //Next adjust last_pay_period_end_date (which becomes the start date) to DayStartTime because then there could be a gap if they //change this mid-schedule. The End Date will take care of it after the first pay period. $last_pay_period_end_date = TTDate::getTimeLockedDate(TTDate::getBeginDayEpoch($last_pay_period_end_date) + $this->getDayStartTime(), $last_pay_period_end_date); Debug::text('cLast Pay Period End Date: ' . TTDate::getDate('DATE+TIME', $last_pay_period_end_date) . ' (' . $last_pay_period_end_date . ')', __FILE__, __LINE__, __METHOD__, 10); } $insert_pay_period = 1; //deprecate primary pay periods. switch ($this->getType()) { case 10: //Weekly //Weekly case 20: //Bi-Weekly $last_pay_period_end_day_of_week = TTDate::getDayOfWeek($last_pay_period_end_date); Debug::text('Last Pay Period End Day Of Week: ' . $last_pay_period_end_day_of_week . ' Start Day Of Week: ' . $this->getStartDayOfWeek(), __LINE__, __METHOD__, 10); if ($last_pay_period_end_day_of_week != $this->getStartDayOfWeek()) { Debug::text('zTmp Pay Period End Date: ' . 'next ' . TTDate::getDayOfWeekByInt($this->getStartDayOfWeek()), __FILE__, __LINE__, __METHOD__, 10); //$tmp_pay_period_end_date = strtotime('next '. TTDate::getDayOfWeekByInt( $this->getStartDayOfWeek() ), $last_pay_period_end_date )-1; $tmp_pay_period_end_date = strtotime('next ' . TTDate::getDayOfWeekByInt($this->getStartDayOfWeek(), FALSE), $last_pay_period_end_date); //strtotime doesn't keep time when using "next", it resets it to midnight on the day, so we need to adjust for that. $tmp_pay_period_end_date = TTDate::getTimeLockedDate(TTDate::getBeginDayEpoch($tmp_pay_period_end_date) + $this->getDayStartTime(), $tmp_pay_period_end_date) - 1; } else { $tmp_pay_period_end_date = $last_pay_period_end_date; //This should fix a bug where if they are creating a new pay period schedule //starting on Monday with the anchor date of 01-Jul-08, it would start on 01-Jul-08 (Tue) //rather moving back to the Monday. if (TTDate::getDayOfMonth($tmp_pay_period_end_date) != TTDate::getDayOfMonth($tmp_pay_period_end_date + 1)) { Debug::text('Right on day boundary, minus an additional second to account for difference...', __FILE__, __LINE__, __METHOD__, 10); $tmp_pay_period_end_date--; } } Debug::text('aTmp Pay Period End Date: ' . TTDate::getDate('DATE+TIME', $tmp_pay_period_end_date) . ' (' . $tmp_pay_period_end_date . ')', __FILE__, __LINE__, __METHOD__, 10); $start_date = $tmp_pay_period_end_date + 1; if ($this->getType() == 10) { //Weekly $tmp_pay_period_end_date = TTDate::getMiddleDayEpoch($start_date) + 86400 * 7; //Add one week } elseif ($this->getType() == 20) { //Bi-Weekly $tmp_pay_period_end_date = TTDate::getMiddleDayEpoch($start_date) + 86400 * 14; //Add two weeks } //Use Begin Day Epoch to nullify DST issues. $end_date = TTDate::getBeginDayEpoch($tmp_pay_period_end_date) - 1; $transaction_date = TTDate::getMiddleDayEpoch(TTDate::getMiddleDayEpoch($end_date) + $this->getTransactionDate() * 86400); break; case 30: //Semi-monthly $tmp_last_pay_period_end_day_of_month = TTDate::getDayOfMonth($last_pay_period_end_date + 1); Debug::text('bLast Pay Period End Day Of Month: ' . $tmp_last_pay_period_end_day_of_month, __FILE__, __LINE__, __METHOD__, 10); if ($tmp_last_pay_period_end_day_of_month == $this->convertLastDayOfMonth($this->getPrimaryDayOfMonth())) { $insert_pay_period = 1; $primary = TRUE; } elseif ($tmp_last_pay_period_end_day_of_month == $this->convertLastDayOfMonth($this->getSecondaryDayOfMonth())) { $insert_pay_period = 2; $primary = FALSE; } else { Debug::text('Finding if Primary or Secondary is closest...', __FILE__, __LINE__, __METHOD__, 10); $primary_date_offset = TTDate::getDateOfNextDayOfMonth($last_pay_period_end_date, NULL, $this->convertLastDayOfMonth($this->getPrimaryDayOfMonth())) - $last_pay_period_end_date; $secondary_date_offset = TTDate::getDateOfNextDayOfMonth($last_pay_period_end_date, NULL, $this->convertLastDayOfMonth($this->getSecondaryDayOfMonth())) - $last_pay_period_end_date; Debug::text('Primary Date Offset: ' . TTDate::getDays($primary_date_offset) . ' Secondary Date Offset: ' . TTDate::getDays($secondary_date_offset), __FILE__, __LINE__, __METHOD__, 10); if ($primary_date_offset <= $secondary_date_offset) { $insert_pay_period = 1; $primary = TRUE; $last_pay_period_end_date = TTDate::getDateOfNextDayOfMonth($last_pay_period_end_date, NULL, $this->convertLastDayOfMonth($this->getPrimaryDayOfMonth())); } else { $insert_pay_period = 2; $primary = FALSE; $last_pay_period_end_date = TTDate::getDateOfNextDayOfMonth($last_pay_period_end_date, NULL, $this->convertLastDayOfMonth($this->getSecondaryDayOfMonth())); } $last_pay_period_end_date = TTDate::getBeginDayEpoch($last_pay_period_end_date); } unset($tmp_last_pay_period_end_day_of_month); Debug::text('cLast Pay Period End Date: ' . TTDate::getDate('DATE+TIME', $last_pay_period_end_date) . ' (' . $last_pay_period_end_date . ') Primary: ' . (int) $primary, __FILE__, __LINE__, __METHOD__, 10); $start_date = $last_pay_period_end_date + 1; if ($primary == TRUE) { $end_date = TTDate::getBeginDayEpoch(TTDate::getDateOfNextDayOfMonth($start_date, NULL, $this->convertLastDayOfMonth($this->getSecondaryDayOfMonth()))) - 1; $transaction_date = TTDate::getMiddleDayEpoch(TTDate::getDateOfNextDayOfMonth(TTDate::getMiddleDayEpoch($end_date), NULL, $this->convertLastDayOfMonth($this->getPrimaryTransactionDayOfMonth()))); } else { $end_date = TTDate::getBeginDayEpoch(TTDate::getDateOfNextDayOfMonth($start_date, NULL, $this->convertLastDayOfMonth($this->getPrimaryDayOfMonth()))) - 1; $transaction_date = TTDate::getMiddleDayEpoch(TTDate::getDateOfNextDayOfMonth(TTDate::getMiddleDayEpoch($end_date), NULL, $this->convertLastDayOfMonth($this->getSecondaryTransactionDayOfMonth()))); } break; case 50: //Monthly $start_date = $last_pay_period_end_date + 1; $end_date = TTDate::getDateOfNextDayOfMonth($start_date + 86400, NULL, $this->convertLastDayOfMonth($this->getPrimaryDayOfMonth())); //Use Begin Day Epoch to nullify DST issues. $end_date = TTDate::getBeginDayEpoch(TTDate::getBeginMinuteEpoch($end_date)) - 1; $transaction_date = TTDate::getMiddleDayEpoch(TTDate::getDateOfNextDayOfMonth($end_date, NULL, $this->convertLastDayOfMonth($this->getPrimaryTransactionDayOfMonth()))); break; } if ($this->getDayStartTime() != 0) { Debug::text('Daily Start Time is set, adjusting End Date by: ' . TTDate::getHours($this->getDayStartTime()) . ' Start Date: ' . TTDate::getDate('DATE+TIME', $start_date), __FILE__, __LINE__, __METHOD__, 10); //We already account for DayStartTime in weekly/bi-weekly start_date cases above, so skip applying it again here. if ($this->getType() != 10 and $this->getType() != 20) { $start_date = $start_date + $this->getDayStartTime(); } $end_date = $end_date + $this->getDayStartTime(); //Need to do this, otherwise transaction date could be earlier then end date. $transaction_date = $transaction_date + $this->getDayStartTime(); } Debug::text('aStart Date(' . $start_date . '): ' . TTDate::getDate('DATE+TIME', $start_date), __FILE__, __LINE__, __METHOD__, 10); Debug::text('aEnd Date(' . $end_date . '): ' . TTDate::getDate('DATE+TIME', $end_date), __FILE__, __LINE__, __METHOD__, 10); Debug::text('aPay Date(' . $transaction_date . '): ' . TTDate::getDate('DATE+TIME', $transaction_date), __FILE__, __LINE__, __METHOD__, 10); //Handle last day of the month flag for primary and secondary dates here if ($this->getType() == 30 and ($insert_pay_period == 1 and ($this->getPrimaryDayOfMonth() == 31 or $this->getPrimaryDayOfMonth() == -1) or $insert_pay_period == 2 and ($this->getSecondaryDayOfMonth() == 31 or $this->getSecondaryDayOfMonth() == -1)) or $this->getType() == 50 and ($this->getPrimaryDayOfMonth() == 31 or $this->getPrimaryDayOfMonth() == -1)) { Debug::text('Last day of the month set for start date: ', __FILE__, __LINE__, __METHOD__, 10); if ($this->getDayStartTime() > 0) { //Minus one day, THEN add daily start time, otherwise it will go past the month boundary $end_date = TTDate::getEndMonthEpoch($end_date) - 86400 + $this->getDayStartTime(); //End month epoch is 23:59:59, so don't minus one. } else { $end_date = TTDate::getEndMonthEpoch($end_date) + $this->getDayStartTime(); //End month epoch is 23:59:59, so don't minus one. } } //Handle "last day of the month" for transaction dates. if ($this->getPrimaryDayOfMonth() == 31 or $this->getPrimaryDayOfMonth() == -1) { //Debug::text('LDOM set for Primary: ', __FILE__, __LINE__, __METHOD__, 10); $transaction_date = TTDate::getEndMonthEpoch($transaction_date); } //Handle "always business day" flag for transaction dates here. if ($this->getTransactionDateBusinessDay() == TRUE) { $transaction_date = $this->getTransactionBusinessDay($transaction_date); } if ($transaction_date < $end_date) { $transaction_date = $end_date; } Debug::text('Start Date: ' . TTDate::getDate('DATE+TIME', $start_date), __FILE__, __LINE__, __METHOD__, 10); Debug::text('End Date: ' . TTDate::getDate('DATE+TIME', $end_date), __FILE__, __LINE__, __METHOD__, 10); Debug::text('Pay Date: ' . TTDate::getDate('DATE+TIME', $transaction_date), __FILE__, __LINE__, __METHOD__, 10); Debug::text("<br><br>\n\n", __FILE__, __LINE__, __METHOD__, 10); $this->next_start_date = $start_date; $this->next_end_date = $end_date; $this->next_transaction_date = $transaction_date; //Its a primary pay period if ($insert_pay_period == 1) { $this->next_primary = TRUE; } else { $this->next_primary = FALSE; } return TRUE; }
$ugsf->setUser($current_user->getId()); $ugsf->setBatchID($ugsf->getNextBatchId()); $ugsf->setQueue(UserGenericStatusFactory::getStaticQueue()); $ugsf->saveQueue(); $progress_bar->setValue(100); $progress_bar->display(); $next_page = URLBuilder::getURL(array('batch_id' => $ugsf->getBatchID(), 'batch_title' => 'Mass Schedule', 'batch_next_page' => urlencode(URLBuilder::getURL(array('data' => $data, 'filter_user_id' => $filter_user_id), '../schedule/AddMassSchedule.php'))), '../users/UserGenericStatusList.php'); } break; case 'recalculate_accrual_policy': //Debug::setVerbosity(11); if (isset($data['accrual_policy_id']) and isset($data['start_date']) and isset($data['end_date'])) { if ($data['start_date'] <= $data['end_date']) { $start_date = TTDate::getMiddleDayEpoch($data['start_date']); $end_date = TTDate::getMiddleDayEpoch($data['end_date']); $total_days = TTDate::getDays($end_date - $start_date); $offset = 86400 / 2; $init_progress_bar = TRUE; if ($init_progress_bar == TRUE) { InitProgressBar(); $init_progress_bar = FALSE; } $progress_bar->setValue(0); $progress_bar->display(); $apf = TTnew('AccrualPolicyFactory'); $aplf = TTnew('AccrualPolicyListFactory'); $aplf->getByIdAndCompanyId((int) $data['accrual_policy_id'], $current_company->getId()); if ($aplf->getRecordCount() > 0) { foreach ($aplf as $ap_obj) { $aplf->StartTransaction(); TTLog::addEntry($current_user->getId(), 500, 'Recalculate Accrual Policy: ' . $ap_obj->getName() . ' Start Date: ' . TTDate::getDate('TIME', $data['start_date']) . ' End Date: ' . TTDate::getDate('TIME', $data['end_date']) . ' Total Days: ' . round($total_days), $current_user->getId(), $ap_obj->getTable());
function detectPayPeriodScheduleSettings($type_id, $example_dates) { Debug::Arr($example_dates, 'Pay Period Type: ' . $type_id . ' Example Dates: ', __FILE__, __LINE__, __METHOD__, 10); if ($type_id == '') { $type_id = $this->getType(); } if (!is_array($example_dates)) { $example_dates = array(); } if (!isset($example_dates[0]['start_date']) or isset($example_dates[0]['start_date']) and $example_dates[0]['start_date'] == '') { Debug::Text('Example dates not specified properly, skipping...', __FILE__, __LINE__, __METHOD__, 10); return FALSE; } $this->setType($type_id); if (isset($example_dates[0]['start_date'])) { $this->setAnchorDate(TTDate::parseDateTime($example_dates[0]['start_date']) - 86400); //Anchor date one day before first start date. } $annual_pay_periods = $this->calcAnnualPayPeriods($type_id); switch ($type_id) { case 5: //Manual break; case 10: //Weekly //Weekly case 20: //BiWeekly //Need at least one example. foreach ($example_dates as $example_date) { $start_dow[] = TTDate::getDayOfWeek(TTDate::parseDateTime($example_date['start_date'])); $transaction_days[] = (int) round(TTDate::getDays(TTDate::parseDateTime($example_date['transaction_date']) - TTDate::parseDateTime($example_date['end_date']))); } Debug::Arr($start_dow, 'Start DOW: ', __FILE__, __LINE__, __METHOD__, 10); Debug::Arr($transaction_days, 'Transaction Days: ', __FILE__, __LINE__, __METHOD__, 10); //Get the most common values from arrays. $start_day_of_week = Misc::arrayCommonValue($start_dow); Debug::Arr($start_dow, 'Start Day Of Week: ' . $start_day_of_week . ' Start DOW Count: ', __FILE__, __LINE__, __METHOD__, 10); $transaction_date = Misc::arrayCommonValue($transaction_days); Debug::Arr($transaction_days, 'Transaction Date: ' . $transaction_date . ' Transaction Days Count: ', __FILE__, __LINE__, __METHOD__, 10); $this->setStartDayOfWeek($start_day_of_week); $this->setTransactionDate($transaction_date); break; case 30: //Semi-monthly //Need at least three examples? $i = 0; foreach ($example_dates as $example_date) { if ($i % 2 == 0) { $primary_start_dom[] = TTDate::getDayOfMonth(TTDate::parseDateTime($example_date['start_date'])); $primary_transaction_dom[] = TTDate::getDayOfMonth(TTDate::parseDateTime($example_date['transaction_date'])); } else { $secondary_start_dom[] = TTDate::getDayOfMonth(TTDate::parseDateTime($example_date['start_date'])); $secondary_transaction_dom[] = TTDate::getDayOfMonth(TTDate::parseDateTime($example_date['transaction_date'])); } $i++; } Debug::Arr($primary_start_dom, 'Primary Start DOM: ', __FILE__, __LINE__, __METHOD__, 10); Debug::Arr($primary_transaction_dom, 'Primary Transaction DOM: ', __FILE__, __LINE__, __METHOD__, 10); Debug::Arr($secondary_start_dom, 'Secondary Start DOM: ', __FILE__, __LINE__, __METHOD__, 10); Debug::Arr($secondary_transaction_dom, 'Secondary Transaction DOM: ', __FILE__, __LINE__, __METHOD__, 10); $primary_dom = Misc::arrayCommonValue($primary_start_dom); $primary_transaction_dom = Misc::arrayCommonValue($primary_transaction_dom); $secondary_dom = Misc::arrayCommonValue($secondary_start_dom); $secondary_transaction_dom = Misc::arrayCommonValue($secondary_transaction_dom); Debug::Text('Primary: ' . $primary_dom . ' Trans: ' . $primary_transaction_dom . ' Secondary: ' . $secondary_dom . ' Trans: ' . $secondary_transaction_dom, __FILE__, __LINE__, __METHOD__, 10); $this->setPrimaryDayOfMonth($primary_dom); $this->setSecondaryDayOfMonth($secondary_dom); $this->setPrimaryTransactionDayOfMonth($primary_transaction_dom); $this->setSecondaryTransactionDayOfMonth($secondary_transaction_dom); break; case 50: //Monthly //Need at least one example. foreach ($example_dates as $example_date) { $primary_start_dom[] = TTDate::getDayOfMonth(TTDate::parseDateTime($example_date['start_date'])); $primary_transaction_dom[] = TTDate::getDayOfMonth(TTDate::parseDateTime($example_date['transaction_date'])); } Debug::Arr($primary_start_dom, 'Primary Start DOM: ', __FILE__, __LINE__, __METHOD__, 10); Debug::Arr($primary_transaction_dom, 'Primary Transaction DOM: ', __FILE__, __LINE__, __METHOD__, 10); $primary_dom = Misc::arrayCommonValue($primary_start_dom); $primary_transaction_dom = Misc::arrayCommonValue($primary_transaction_dom); $this->setPrimaryDayOfMonth($primary_dom); $this->setPrimaryTransactionDayOfMonth($primary_transaction_dom); break; default: return FALSE; break; } Debug::Arr($this->data, 'PP Schedule Data: ', __FILE__, __LINE__, __METHOD__, 10); return TRUE; }
function calcAccrualTime($company_id, $accrual_policy_id, $start_date, $end_date) { $start_date = TTDate::getMiddleDayEpoch($start_date); $end_date = TTDate::getMiddleDayEpoch($end_date); $total_days = TTDate::getDays($end_date - $start_date); $offset = 79200; $apf = TTnew('AccrualPolicyFactory'); $aplf = TTnew('AccrualPolicyListFactory'); $aplf->getByIdAndCompanyId((int) $accrual_policy_id, $company_id); if ($aplf->getRecordCount() > 0) { foreach ($aplf as $ap_obj) { $aplf->StartTransaction(); $x = 0; for ($i = $start_date; $i < $end_date; $i += 86400) { Debug::Text('Recalculating Accruals for Date: ' . TTDate::getDate('DATE+TIME', TTDate::getBeginDayEpoch($i)), __FILE__, __LINE__, __METHOD__, 10); $ap_obj->addAccrualPolicyTime(TTDate::getBeginDayEpoch($i) + 7201, $offset); Debug::Text('----------------------------------', __FILE__, __LINE__, __METHOD__, 10); $x++; } $aplf->CommitTransaction(); } } return TRUE; }
function calcAccrualPolicyTime($u_obj, $epoch, $offset, $pps_obj, $pay_period_arr, $accrual_balance, $update_records = TRUE) { $retval = 0; Debug::Text('User: '******' Status: ' . $u_obj->getStatus() . ' Epoch: ' . TTDate::getDate('DATE+TIME', $epoch), __FILE__, __LINE__, __METHOD__, 10); //Make sure only active employees accrue time *after* their hire date. //Will this negative affect Employees who may be on leave? if ($u_obj->getStatus() == 10 and $epoch >= $u_obj->getHireDate() and ($this->getMinimumEmployedDays() == 0 or TTDate::getDays($epoch - $u_obj->getHireDate()) >= $this->getMinimumEmployedDays())) { Debug::Text(' User is active and has been employed long enough.', __FILE__, __LINE__, __METHOD__, 10); $annual_pay_periods = $pps_obj->getAnnualPayPeriods(); $in_apply_frequency_window = FALSE; $in_apply_rollover_window = FALSE; $pay_period_start_date = NULL; $accrual_amount = 0; if ($this->getType() == 30) { Debug::Text(' Accrual policy is hour based, real-time window.', __FILE__, __LINE__, __METHOD__, 10); //Hour based, apply frequency is real-time. $in_apply_frequency_window = TRUE; } else { if ($this->getApplyFrequency() == 10) { $pay_period_dates = $this->getPayPeriodDatesFromArray($pay_period_arr, $epoch - $offset); if (is_array($pay_period_dates)) { Debug::Text(' Pay Period Start Date: ' . TTDate::getDate('DATE+TIME', $pay_period_dates['start_date']) . ' End Date: ' . TTDate::getDate('DATE+TIME', $pay_period_dates['end_date']), __FILE__, __LINE__, __METHOD__, 10); if ($this->inApplyFrequencyWindow($epoch, $offset, $pay_period_dates['end_date']) == TRUE) { $in_apply_frequency_window = TRUE; $pay_period_start_date = $pay_period_dates['start_date']; //Used for inRolloverFrequencyWindow } else { Debug::Text(' User not in Apply Frequency Window: ', __FILE__, __LINE__, __METHOD__, 10); } } else { Debug::Arr($pay_period_dates, ' No Pay Period Dates Found.', __FILE__, __LINE__, __METHOD__, 10); } } elseif ($this->inApplyFrequencyWindow($epoch, $offset, NULL, $u_obj->getHireDate()) == TRUE) { Debug::Text(' User IS in NON-PayPeriod Apply Frequency Window.', __FILE__, __LINE__, __METHOD__, 10); $in_apply_frequency_window = TRUE; } else { Debug::Text(' User is not in Apply Frequency Window.', __FILE__, __LINE__, __METHOD__, 10); $in_apply_frequency_window = FALSE; } } if ($this->inRolloverFrequencyWindow($epoch, $offset, $u_obj->getHireDate(), $pay_period_start_date)) { Debug::Text(' In rollover window...', __FILE__, __LINE__, __METHOD__, 10); $in_apply_rollover_window = TRUE; } if ($in_apply_frequency_window == TRUE or $in_apply_rollover_window == TRUE) { $milestone_obj = $this->getActiveMilestoneObject($u_obj, $epoch); } if ($in_apply_rollover_window == TRUE and (isset($milestone_obj) and is_object($milestone_obj))) { //Have accrual balance passed in for optimization //$accrual_balance = $this->getCurrentAccrualBalance( $u_obj->getID(), $this->getId() ); //Handle maximum rollover adjustments before continuing. if ($accrual_balance > $milestone_obj->getRolloverTime()) { $rollover_accrual_adjustment = bcsub($milestone_obj->getRolloverTime(), $accrual_balance, 0); Debug::Text(' Adding rollover adjustment of: ' . $rollover_accrual_adjustment, __FILE__, __LINE__, __METHOD__, 10); //Check to make sure there isn't an identical entry already made. //Ignore rollover adjustment is another adjustment of any amount has been made on the same day. $alf = TTnew('AccrualListFactory'); if ($update_records == TRUE) { $alf->getByCompanyIdAndUserIdAndAccrualPolicyIDAndTypeIDAndTimeStamp($u_obj->getCompany(), $u_obj->getID(), $this->getId(), 60, TTDate::getMiddleDayEpoch($epoch)); } if ($alf->getRecordCount() == 0) { //Get effective date, try to use the current milestone rollover date to make things more clear. $current_milestone_rollover_date = $this->getCurrentMilestoneRolloverDate($epoch, $u_obj->getHireDate()); //If milestone rollover date comes after the current epoch, back date it by one year. if ($current_milestone_rollover_date > $epoch) { $current_milestone_rollover_date = mktime(0, 0, 0, TTDate::getMonth($current_milestone_rollover_date), TTDate::getDayOfMonth($current_milestone_rollover_date), TTDate::getYear($epoch) - 1); } if ($update_records == TRUE) { //Don't round to the nearest minute, as that can cause too much error on weekly frequencies. $af = TTnew('AccrualFactory'); $af->setUser($u_obj->getID()); $af->setType(60); //Rollover Adjustment $af->setAccrualPolicyID($this->getId()); $af->setAmount($rollover_accrual_adjustment); $af->setTimeStamp(TTDate::getMiddleDayEpoch($current_milestone_rollover_date)); $af->setEnableCalcBalance(TRUE); if ($af->isValid()) { $af->Save(); } } else { Debug::Text(' NOT UPDATING RECORDS...', __FILE__, __LINE__, __METHOD__, 10); $retval = $rollover_accrual_adjustment; } //Make sure we get updated balance after rollover adjustment was made. $accrual_balance += $rollover_accrual_adjustment; unset($current_milestone_rollover_date); } else { Debug::Text(' Found duplicate rollover accrual entry, skipping...', __FILE__, __LINE__, __METHOD__, 10); } } else { Debug::Text(' Balance hasnt exceeded rollover adjustment...', __FILE__, __LINE__, __METHOD__, 10); } unset($rollover_accrual_adjustment, $alf, $af); } if ($in_apply_frequency_window === TRUE) { if (isset($milestone_obj) and is_object($milestone_obj)) { Debug::Text(' Found Matching Milestone, Accrual Rate: (ID: ' . $milestone_obj->getId() . ') ' . $milestone_obj->getAccrualRate() . '/year', __FILE__, __LINE__, __METHOD__, 10); //Make sure we get updated balance after rollover adjustment was made. //Have accrual balance passed in for optimization //$accrual_balance = $this->getCurrentAccrualBalance( $u_obj->getID(), $this->getId() ); if ($accrual_balance < $milestone_obj->getMaximumTime()) { $accrual_amount = $this->calcAccrualAmount($milestone_obj, 0, $annual_pay_periods); if ($accrual_amount > 0) { $new_accrual_balance = bcadd($accrual_balance, $accrual_amount); //If Maximum time is set to 0, make that unlimited. if ($milestone_obj->getMaximumTime() > 0 and $new_accrual_balance > $milestone_obj->getMaximumTime()) { $accrual_amount = bcsub($milestone_obj->getMaximumTime(), $accrual_balance, 0); } Debug::Text(' Min/Max Adjusted Accrual Amount: ' . $accrual_amount . ' Limits: Min: ' . $milestone_obj->getMinimumTime() . ' Max: ' . $milestone_obj->getMaximumTime(), __FILE__, __LINE__, __METHOD__, 10); //Check to make sure there isn't an identical entry already made. $alf = TTnew('AccrualListFactory'); if ($update_records == TRUE) { $alf->getByCompanyIdAndUserIdAndAccrualPolicyIDAndTimeStampAndAmount($u_obj->getCompany(), $u_obj->getID(), $this->getId(), TTDate::getMiddleDayEpoch($epoch), $accrual_amount); } if ($alf->getRecordCount() == 0) { if ($update_records == TRUE) { Debug::Text(' UPDATING RECORDS...', __FILE__, __LINE__, __METHOD__, 10); //Round to nearest 1min $af = TTnew('AccrualFactory'); $af->setUser($u_obj->getID()); $af->setType(75); //Accrual Policy $af->setAccrualPolicyID($this->getId()); $af->setAmount($accrual_amount); $af->setTimeStamp(TTDate::getMiddleDayEpoch($epoch)); $af->setEnableCalcBalance(TRUE); if ($af->isValid()) { $af->Save(); } } else { Debug::Text(' NOT UPDATING RECORDS...', __FILE__, __LINE__, __METHOD__, 10); $retval += $accrual_amount; } } else { Debug::Text(' Found duplicate accrual entry, skipping...', __FILE__, __LINE__, __METHOD__, 10); } unset($accrual_amount, $accrual_balance, $new_accrual_balance); } else { Debug::Text(' Accrual Amount is 0...', __FILE__, __LINE__, __METHOD__, 10); } } else { Debug::Text(' Accrual Balance is outside Milestone Range. Skipping...', __FILE__, __LINE__, __METHOD__, 10); } } else { Debug::Text(' DID NOT Find Matching Milestone.', __FILE__, __LINE__, __METHOD__, 10); } unset($milestone_obj); } } else { Debug::Text(' User is not active (Status: ' . $u_obj->getStatus() . ') or has only been employed: ' . TTDate::getDays($epoch - $u_obj->getHireDate()) . ' Days, not enough. Hire Date: ' . TTDate::getDATE('DATE+TIME', $u_obj->getHireDate()), __FILE__, __LINE__, __METHOD__, 10); } if ($update_records == TRUE) { return TRUE; } else { Debug::Text('Retval: ' . $retval, __FILE__, __LINE__, __METHOD__, 10); return $retval; } }
function calcAccrualPolicy() { //FIXME: There is a minor bug for hour based accruals that if a milestone has a maximum limit, // and an employee recalculates there timesheet, and the limit is reached midweek, if its recalculated // again, the days that get the accrual time won't always be in order because the accrual balance is deleted // only for the day currently being calculated, so on Monday it will delete 1hr of accrual, but the balance will // still include Tue,Wed,Thu and the limit may already be reached. //We still need to calculate accruals even if the total time is 0, because we may want to override a //policy to 0hrs, and if we skip entries with TotalTime() == 0, the accruals won't be updated. if ($this->getDeleted() == FALSE) { Debug::text('Calculating Accrual Policies... Total Time: ' . $this->getTotalTime() . ' Date: ' . TTDate::getDate('DATE', $this->getUserDateObject()->getDateStamp()), __FILE__, __LINE__, __METHOD__, 10); //Calculate accrual policies assigned to other overtime/premium/absence policies //Debug::text('ID: '. $this->getId() .' Overtime Policy ID: '. (int)$this->getOverTimePolicyID() .' Premium Policy ID: '. (int)$this->getPremiumPolicyID() .' Absence Policy ID: '. (int)$this->getAbsencePolicyID(), __FILE__, __LINE__, __METHOD__, 10); //If overtime, premium or absence policy is an accrual, handle that now. if ($this->getOverTimePolicyID() != FALSE) { $accrual_policy_id = $this->getOverTimePolicyObject()->getAccrualPolicyID(); Debug::text('Over Time Accrual Policy ID: ' . $accrual_policy_id, __FILE__, __LINE__, __METHOD__, 10); if ($accrual_policy_id > 0) { Debug::text('Over Time Accrual Rate: ' . $this->getOverTimePolicyObject()->getAccrualRate() . ' Policy ID: ' . $this->getOverTimePolicyObject()->getAccrualPolicyID(), __FILE__, __LINE__, __METHOD__, 10); $af = TTnew('AccrualFactory'); $af->setUser($this->getUserDateObject()->getUser()); $af->setAccrualPolicyID($accrual_policy_id); $af->setTimeStamp($this->getUserDateObject()->getDateStamp()); $af->setUserDateTotalID($this->getID()); $accrual_amount = bcmul($this->getTotalTime(), $this->getOverTimePolicyObject()->getAccrualRate()); if ($accrual_amount > 0) { $af->setType(10); //Banked } else { $af->setType(20); //Used } $af->setAmount($accrual_amount); $af->setEnableCalcBalance(TRUE); if ($af->isValid()) { $af->Save(); } unset($accrual_amount); } else { Debug::text('Skipping Over Time Accrual Policy ID: ' . $accrual_policy_id, __FILE__, __LINE__, __METHOD__, 10); } } if ($this->getPremiumPolicyID() != FALSE) { $accrual_policy_id = $this->getPremiumPolicyObject()->getAccrualPolicyID(); Debug::text('Premium Accrual Policy ID: ' . $accrual_policy_id, __FILE__, __LINE__, __METHOD__, 10); if ($accrual_policy_id > 0) { $af = TTnew('AccrualFactory'); $af->setUser($this->getUserDateObject()->getUser()); $af->setAccrualPolicyID($accrual_policy_id); $af->setTimeStamp($this->getUserDateObject()->getDateStamp()); $af->setUserDateTotalID($this->getID()); $accrual_amount = bcmul($this->getTotalTime(), $this->getPremiumPolicyObject()->getAccrualRate()); if ($accrual_amount > 0) { $af->setType(10); //Banked } else { $af->setType(20); //Used } $af->setAmount($accrual_amount); $af->setEnableCalcBalance(TRUE); if ($af->isValid()) { $af->Save(); } unset($accrual_amount); } } if ($this->getAbsencePolicyID() != FALSE) { $accrual_policy_id = $this->getAbsencePolicyObject()->getAccrualPolicyID(); Debug::text('Absence Accrual Policy ID: ' . $accrual_policy_id . ' Absence Policy ID: ' . $this->getAbsencePolicyObject()->getID() . ' Absence Policy IDb: ' . $this->getAbsencePolicyID(), __FILE__, __LINE__, __METHOD__, 10); //Absence entry was modified, delete previous accrual entry and re-create it. $alf = TTnew('AccrualListFactory'); $alf->getByUserIdAndUserDateTotalID($this->getUserDateObject()->getUser(), $this->getID()); if ($alf->getRecordCount() > 0) { foreach ($alf as $af_obj) { Debug::text('Found existing accrual!! ID: ' . $af_obj->getID() . ' UserDateTotalID: ' . $this->getID(), __FILE__, __LINE__, __METHOD__, 10); $af_obj->setDeleted(TRUE); $af_obj->setEnableCalcBalance(TRUE); if ($af_obj->isValid()) { $af_obj->Save(); } } } unset($alf, $af_obj); if ($accrual_policy_id > 0) { $af = TTnew('AccrualFactory'); $af->setUser($this->getUserDateObject()->getUser()); $af->setAccrualPolicyID($accrual_policy_id); $af->setTimeStamp($this->getUserDateObject()->getDateStamp()); $af->setUserDateTotalID($this->getID()); //By default we withdraw from accrual policy, so if there is a negative rate, deposit instead. $accrual_amount = bcmul($this->getTotalTime(), bcmul($this->getAbsencePolicyObject()->getAccrualRate(), -1)); if ($accrual_amount > 0) { $af->setType(10); //Banked } else { $af->setType(20); //Used } $af->setAmount($accrual_amount); $af->setEnableCalcBalance(TRUE); if ($af->isValid()) { $af->Save(); } } } unset($af, $accrual_policy_id); //Calculate any hour based accrual policies. //if ( $this->getType() == 10 AND $this->getStatus() == 10 ) { if ($this->getStatus() == 10 and in_array($this->getType(), array(20, 30))) { //Calculate hour based accruals on regular/overtime only. $aplf = TTnew('AccrualPolicyListFactory'); $aplf->getByPolicyGroupUserIdAndType($this->getUserDateObject()->getUser(), 30); if ($aplf->getRecordCount() > 0) { Debug::text('Found Hour Based Accrual Policies to apply.', __FILE__, __LINE__, __METHOD__, 10); foreach ($aplf as $ap_obj) { if ($ap_obj->getMinimumEmployedDays() == 0 or TTDate::getDays($this->getUserDateObject()->getDateStamp() - $this->getUserDateObject()->getUserObject()->getHireDate()) >= $ap_obj->getMinimumEmployedDays()) { Debug::Text(' User has been employed long enough.', __FILE__, __LINE__, __METHOD__, 10); $milestone_obj = $ap_obj->getActiveMilestoneObject($this->getUserDateObject()->getUserObject(), $this->getUserDateObject()->getDateStamp()); $accrual_balance = $ap_obj->getCurrentAccrualBalance($this->getUserDateObject()->getUserObject()->getId(), $ap_obj->getId()); //If Maximum time is set to 0, make that unlimited. if (is_object($milestone_obj) and ($milestone_obj->getMaximumTime() == 0 or $accrual_balance < $milestone_obj->getMaximumTime())) { $accrual_amount = $ap_obj->calcAccrualAmount($milestone_obj, $this->getTotalTime(), 0); if ($accrual_amount > 0) { $new_accrual_balance = bcadd($accrual_balance, $accrual_amount); //If Maximum time is set to 0, make that unlimited. if ($milestone_obj->getMaximumTime() > 0 and $new_accrual_balance > $milestone_obj->getMaximumTime()) { $accrual_amount = bcsub($milestone_obj->getMaximumTime(), $accrual_balance, 4); } Debug::Text(' Min/Max Adjusted Accrual Amount: ' . $accrual_amount . ' Limits: Min: ' . $milestone_obj->getMinimumTime() . ' Max: ' . $milestone_obj->getMaximumTime(), __FILE__, __LINE__, __METHOD__, 10); $af = TTnew('AccrualFactory'); $af->setUser($this->getUserDateObject()->getUserObject()->getId()); $af->setType(75); //Accrual Policy $af->setAccrualPolicyID($ap_obj->getId()); $af->setUserDateTotalID($this->getID()); $af->setAmount($accrual_amount); $af->setTimeStamp($this->getUserDateObject()->getDateStamp()); $af->setEnableCalcBalance(TRUE); if ($af->isValid()) { $af->Save(); } unset($accrual_amount, $accrual_balance, $new_accrual_balance); } else { Debug::Text(' Accrual Amount is 0...', __FILE__, __LINE__, __METHOD__, 10); } } else { Debug::Text(' Accrual Balance is outside Milestone Range. Or no milestone found. Skipping...', __FILE__, __LINE__, __METHOD__, 10); } } else { Debug::Text(' User has only been employed: ' . TTDate::getDays($this->getUserDateObject()->getDateStamp() - $this->getUserDateObject()->getUserObject()->getHireDate()) . ' Days, not enough.', __FILE__, __LINE__, __METHOD__, 10); } } } else { Debug::text('No Hour Based Accrual Policies to apply.', __FILE__, __LINE__, __METHOD__, 10); } } else { Debug::text('No worked time on this day or not proper type/status, skipping hour based accrual policies...', __FILE__, __LINE__, __METHOD__, 10); } } return TRUE; }
function addAccrualPolicyTime($epoch = NULL, $offset = 79200, $daily_total_time = NULL) { //22hr offset if ($epoch == '') { $epoch = TTDate::getTime(); } Debug::Text('Accrual Policy ID: ' . $this->getId() . ' Current EPOCH: ' . TTDate::getDate('DATE+TIME', $epoch), __FILE__, __LINE__, __METHOD__, 10); $pglf = new PolicyGroupListFactory(); $pglf->StartTransaction(); $pglf->getSearchByCompanyIdAndArrayCriteria($this->getCompany(), array('accrual_policy_id' => array($this->getId()))); if ($pglf->getRecordCount() > 0) { Debug::Text('Found Policy Group...', __FILE__, __LINE__, __METHOD__, 10); foreach ($pglf as $pg_obj) { //Get all users assigned to this policy group. $policy_group_users = $pg_obj->getUser(); if (is_array($policy_group_users) and count($policy_group_users) > 0) { Debug::Text('Found Policy Group Users: ' . count($policy_group_users), __FILE__, __LINE__, __METHOD__, 10); foreach ($policy_group_users as $user_id) { Debug::Text('Policy Group User ID: ' . $user_id, __FILE__, __LINE__, __METHOD__, 10); //Get User Object $ulf = new UserListFactory(); $ulf->getByIDAndCompanyID($user_id, $this->getCompany()); if ($ulf->getRecordCount() == 1) { $u_obj = $ulf->getCurrent(); Debug::Text('User: '******' Status: ' . $u_obj->getStatus(), __FILE__, __LINE__, __METHOD__, 10); //Make sure only active employees accrue time. Will this negative affect //Employees who may be on leave? if ($u_obj->getStatus() == 10 and ($this->getMinimumEmployedDays() == 0 or TTDate::getDays($epoch - $u_obj->getHireDate()) >= $this->getMinimumEmployedDays())) { Debug::Text(' User is active and has been employed long enough.', __FILE__, __LINE__, __METHOD__, 10); $annual_pay_periods = 0; $in_apply_frequency_window = FALSE; $accrual_balance = 0; $accrual_amount = 0; if ($this->getType() == 30) { Debug::Text(' Accrual policy is hour based, real-time window.', __FILE__, __LINE__, __METHOD__, 10); //Hour based, apply frequency is real-time. $in_apply_frequency_window = TRUE; } else { if ($this->getApplyFrequency() == 10) { //Because of pay period frequencies, and users being assigned to different //pay period schedules we need to get the last pay period of each user individually. //This will return the pay period that just ended in the offset time. $pplf = new PayPeriodListFactory(); $pplf->getByUserIdAndEndDate($user_id, $epoch - $offset); if ($pplf->getRecordCount() > 0) { foreach ($pplf as $pp_obj) { Debug::Text(' Pay Period End Date: ' . TTDate::getDate('DATE+TIME', $pp_obj->getEndDate()), __FILE__, __LINE__, __METHOD__, 10); if ($this->inApplyFrequencyWindow($epoch, $offset, $pp_obj->getEndDate()) == TRUE) { $in_apply_frequency_window = TRUE; $annual_pay_periods = $pp_obj->getPayPeriodScheduleObject()->getAnnualPayPeriods(); break; } else { Debug::Text(' User not in Apply Frequency Window: ', __FILE__, __LINE__, __METHOD__, 10); } } } else { Debug::Text(' No Pay Period Found.', __FILE__, __LINE__, __METHOD__, 10); } } elseif ($this->inApplyFrequencyWindow($epoch, $offset) == TRUE) { Debug::Text(' User IS in NON-PayPeriod Apply Frequency Window.', __FILE__, __LINE__, __METHOD__, 10); $in_apply_frequency_window = TRUE; } else { Debug::Text(' User is not in Apply Frequency Window.', __FILE__, __LINE__, __METHOD__, 10); $in_apply_frequency_window = FALSE; } } if ($in_apply_frequency_window == TRUE) { $milestone_obj = $this->getActiveMilestoneObject($u_obj, $epoch); if (isset($milestone_obj) and is_object($milestone_obj)) { Debug::Text(' Found Matching Milestone, Accrual Rate: (ID: ' . $milestone_obj->getId() . ') ' . $milestone_obj->getAccrualRate() . '/year', __FILE__, __LINE__, __METHOD__, 10); $accrual_balance = $this->getCurrentAccrualBalance($user_id, $this->getId()); if ($accrual_balance < $milestone_obj->getMaximumTime()) { $accrual_amount = $this->calcAccrualAmount($milestone_obj, 0, $annual_pay_periods); if ($accrual_amount > 0) { $new_accrual_balance = bcadd($accrual_balance, $accrual_amount); //If Maximum time is set to 0, make that unlimited. if ($milestone_obj->getMaximumTime() > 0 and $new_accrual_balance > $milestone_obj->getMaximumTime()) { $accrual_amount = bcsub($milestone_obj->getMaximumTime(), $accrual_balance, 0); } Debug::Text(' Min/Max Adjusted Accrual Amount: ' . $accrual_amount . ' Limits: Min: ' . $milestone_obj->getMinimumTime() . ' Max: ' . $milestone_obj->getMaximumTime(), __FILE__, __LINE__, __METHOD__, 10); //Check to make sure there isn't an identical entry already made. $alf = new AccrualListFactory(); $alf->getByCompanyIdAndUserIdAndAccrualPolicyIDAndTimeStampAndAmount($u_obj->getCompany(), $user_id, $this->getId(), TTDate::getMiddleDayEpoch($epoch), $accrual_amount); if ($alf->getRecordCount() == 0) { //Round to nearest 1min $af = new AccrualFactory(); $af->setUser($user_id); $af->setType(75); //Accrual Policy $af->setAccrualPolicyID($this->getId()); $af->setAmount($accrual_amount); $af->setTimeStamp(TTDate::getMiddleDayEpoch($epoch)); $af->setEnableCalcBalance(TRUE); if ($af->isValid()) { $af->Save(); } } else { Debug::Text(' Found duplicate accrual entry, skipping...', __FILE__, __LINE__, __METHOD__, 10); } unset($accrual_amount, $accrual_balance, $new_accrual_balance); } else { Debug::Text(' Accrual Amount is 0...', __FILE__, __LINE__, __METHOD__, 10); } } else { Debug::Text(' Accrual Balance is outside Milestone Range. Skipping...', __FILE__, __LINE__, __METHOD__, 10); } } else { Debug::Text(' DID NOT Find Matching Milestone.', __FILE__, __LINE__, __METHOD__, 10); } unset($milestone_obj); } } else { Debug::Text(' User is not active (Status: ' . $u_obj->getStatus() . ') or has only been employed: ' . TTDate::getDays($epoch - $u_obj->getHireDate()) . ' Days, not enough.', __FILE__, __LINE__, __METHOD__, 10); } } else { Debug::Text('No User Found. Company ID: ' . $this->getCompany(), __FILE__, __LINE__, __METHOD__, 10); } } } } } $pglf->CommitTransaction(); return TRUE; }
function checkPasswordAge() { $c_obj = $this->getCompanyObject(); //Always add 1 to the PasswordMaximumAge so if its set to 0 by mistake it will still allow the user to login after changing their password. Debug::Text('Password Policy: Type: ' . $c_obj->getPasswordPolicyType() . '(' . $c_obj->getProductEdition() . ') Current Age: ' . TTDate::getDays(time() - $this->getPasswordUpdatedDate()) . '(' . $this->getPasswordUpdatedDate() . ') Maximum Age: ' . $c_obj->getPasswordMaximumAge() . ' days', __FILE__, __LINE__, __METHOD__, 10); if (PRODUCTION == TRUE and is_object($c_obj) and $c_obj->getPasswordPolicyType() == 1 and (int) $this->getPasswordUpdatedDate() < time() - ($c_obj->getPasswordMaximumAge() + 1) * 86400 and $c_obj->getProductEdition() > 10) { Debug::Text('Password Policy: Password exceeds maximum age, denying access...', __FILE__, __LINE__, __METHOD__, 10); return FALSE; } return TRUE; }
function getObjectAsArray($include_columns = NULL) { $variable_function_map = $this->getVariableToFunctionMap(); if (is_array($variable_function_map)) { foreach ($variable_function_map as $variable => $function_stub) { if ($include_columns == NULL or isset($include_columns[$variable]) and $include_columns[$variable] == TRUE) { $function = 'get' . $function_stub; switch ($variable) { case 'status': case 'ldap_authentication_type': case 'password_policy_type': $function = 'get' . $variable; if (method_exists($this, $function)) { $data[$variable] = Option::getByKey($this->{$function}(), $this->getOptions($variable)); } break; case 'product_edition': $data[$variable] = Option::getByKey($this->getProductEdition(), $this->getOptions($variable)); break; case 'industry': $data[$variable] = Option::getByKey($this->getIndustry(), $this->getOptions($variable)); break; case 'last_login_date': $data[$variable] = TTDate::getAPIDate('DATE+TIME', $this->getColumn($variable)); break; case 'total_active_days': case 'last_login_days': $data[$variable] = (int) TTDate::getDays((int) $this->getColumn($variable)); break; case 'this_month_min_active_users': case 'this_month_avg_active_users': case 'this_month_max_active_users': case 'last_month_min_active_users': case 'last_month_avg_active_users': case 'last_month_max_active_users': $data[$variable] = (int) $this->getColumn($variable); break; case 'name_metaphone': break; default: if (method_exists($this, $function)) { $data[$variable] = $this->{$function}(); } break; } } } $this->getCreatedAndUpdatedColumns($data, $include_columns); } return $data; }