function setAccrualPolicy($id) { $id = trim($id); $aplf = new AccrualPolicyListFactory(); if ($id == 0 or $this->Validator->isResultSetWithRows('over_time_policy', $aplf->getByID($id), TTi18n::gettext('Selected Accrual Policy is invalid'))) { $this->data['accrual_policy_id'] = $id; return TRUE; } return FALSE; }
function setAccrualPolicyID($id) { $id = trim($id); if ($id == '' or empty($id)) { $id = NULL; } $aplf = new AccrualPolicyListFactory(); if ($id == NULL or $this->Validator->isResultSetWithRows('accrual_policy', $aplf->getByID($id), TTi18n::gettext('Accrual Policy is invalid'))) { $this->data['accrual_policy_id'] = $id; return TRUE; } return FALSE; }
$user_options = $ulf->getByCompanyIDArray($current_company->getId(), FALSE, TRUE); $otplf = new OverTimePolicyListFactory(); $over_time_policy_options = Misc::prependArray($none_array_option, $otplf->getByCompanyIDArray($current_company->getId(), FALSE)); $pplf = new PremiumPolicyListFactory(); $premium_policy_options = Misc::prependArray($none_array_option, $pplf->getByCompanyIDArray($current_company->getId(), FALSE)); $riplf = new RoundIntervalPolicyListFactory(); $round_interval_policy_options = Misc::prependArray($none_array_option, $riplf->getByCompanyIDArray($current_company->getId(), FALSE)); $mplf = new MealPolicyListFactory(); $meal_options = Misc::prependArray($none_array_option, $mplf->getByCompanyIdArray($current_company->getId(), FALSE)); $bplf = new BreakPolicyListFactory(); $break_options = Misc::prependArray($none_array_option, $bplf->getByCompanyIdArray($current_company->getId(), FALSE)); $epclf = new ExceptionPolicyControlListFactory(); $exception_options = Misc::prependArray($none_array_option, $epclf->getByCompanyIdArray($current_company->getId(), FALSE)); $hplf = new HolidayPolicyListFactory(); $holiday_policy_options = Misc::prependArray($none_array_option, $hplf->getByCompanyIdArray($current_company->getId(), FALSE)); $aplf = new AccrualPolicyListFactory(); $aplf->getByCompanyIdAndTypeID($current_company->getId(), array(20, 30)); //Calendar and Hour based. $accrual_options = Misc::prependArray($none_array_option, $aplf->getArrayByListFactory($aplf, FALSE)); //Select box options; $data['user_options'] = $user_options; $data['over_time_policy_options'] = $over_time_policy_options; $data['premium_policy_options'] = $premium_policy_options; $data['round_interval_policy_options'] = $round_interval_policy_options; $data['accrual_policy_options'] = $accrual_options; $data['meal_options'] = $meal_options; $data['break_options'] = $break_options; $data['exception_options'] = $exception_options; $data['holiday_policy_options'] = $holiday_policy_options; if (isset($data['user_ids']) and is_array($data['user_ids'])) { $tmp_user_options = $user_options;
$otpf->Save(); Redirect::Page(URLBuilder::getURL(NULL, 'OverTimePolicyList.php')); break; } default: if (isset($id)) { BreadCrumb::setCrumb($title); $otplf = new OverTimePolicyListFactory(); $otplf->getByIdAndCompanyID($id, $current_company->getID()); foreach ($otplf as $otp_obj) { //Debug::Arr($station,'Department', __FILE__, __LINE__, __METHOD__,10); $data = array('id' => $otp_obj->getId(), 'name' => $otp_obj->getName(), 'type_id' => $otp_obj->getType(), 'trigger_time' => $otp_obj->getTriggerTime(), 'rate' => Misc::removeTrailingZeros($otp_obj->getRate()), 'wage_group_id' => $otp_obj->getWageGroup(), 'accrual_rate' => Misc::removeTrailingZeros($otp_obj->getAccrualRate()), 'accrual_policy_id' => $otp_obj->getAccrualPolicyID(), 'pay_stub_entry_account_id' => $otp_obj->getPayStubEntryAccountId(), 'created_date' => $otp_obj->getCreatedDate(), 'created_by' => $otp_obj->getCreatedBy(), 'updated_date' => $otp_obj->getUpdatedDate(), 'updated_by' => $otp_obj->getUpdatedBy(), 'deleted_date' => $otp_obj->getDeletedDate(), 'deleted_by' => $otp_obj->getDeletedBy()); } } elseif ($action != 'submit') { $data = array('trigger_time' => 0, 'rate' => '1.00', 'accrual_rate' => '1.00'); } $aplf = new AccrualPolicyListFactory(); $accrual_options = $aplf->getByCompanyIDArray($current_company->getId(), TRUE); $psealf = new PayStubEntryAccountListFactory(); $pay_stub_entry_options = $psealf->getByCompanyIdAndStatusIdAndTypeIdArray($current_company->getId(), 10, array(10, 20, 30, 50)); $wglf = new WageGroupListFactory(); $data['wage_group_options'] = $wglf->getArrayByListFactory($wglf->getByCompanyId($current_company->getId()), TRUE); //Select box options; $data['type_options'] = $otpf->getOptions('type'); $data['accrual_options'] = $accrual_options; $data['pay_stub_entry_options'] = $pay_stub_entry_options; $smarty->assign_by_ref('data', $data); break; } $smarty->assign_by_ref('otpf', $otpf); $smarty->display('policy/EditOverTimePolicy.tpl');
function getByCompanyIdArray($company_id, $include_blank = TRUE) { $aplf = new AccrualPolicyListFactory(); $aplf->getByCompanyId($company_id); if ($include_blank == TRUE) { $list[0] = TTi18n::gettext('-- None --'); } foreach ($aplf as $ap_obj) { $list[$ap_obj->getID()] = $ap_obj->getName(); } if (isset($list)) { return $list; } return FALSE; }
//$apf->FailTransaction(); if (isset($ap_id) and isset($data['recalculate']) and $data['recalculate'] == 1) { Debug::Text('Recalculating Accruals...', __FILE__, __LINE__, __METHOD__, 10); if (isset($data['recalculate_start_date']) and isset($data['recalculate_end_date']) and $data['recalculate_start_date'] < $data['recalculate_end_date']) { Redirect::Page(URLBuilder::getURL(array('action' => 'recalculate_accrual_policy', 'data' => array('accrual_policy_id' => $ap_id, 'start_date' => $data['recalculate_start_date'], 'end_date' => $data['recalculate_end_date']), 'next_page' => urlencode(URLBuilder::getURL(NULL, '../policy/AccrualPolicyList.php'))), '../progress_bar/ProgressBarControl.php'), FALSE); } } Redirect::Page(URLBuilder::getURL(NULL, 'AccrualPolicyList.php')); break; } } $apf->FailTransaction(); default: if (isset($id)) { BreadCrumb::setCrumb($title); $aplf = new AccrualPolicyListFactory(); $apmlf = new AccrualPolicyMilestoneListFactory(); $aplf->getByIdAndCompanyID($id, $current_company->getID()); if ($aplf->getRecordCount() > 0) { $apmlf->getByAccrualPolicyId($id); if ($apmlf->getRecordCount() > 0) { foreach ($apmlf as $apm_obj) { $milestone_rows[$apm_obj->getId()] = array('id' => $apm_obj->getId(), 'length_of_service' => $apm_obj->getLengthOfService(), 'length_of_service_unit_id' => $apm_obj->getLengthOfServiceUnit(), 'accrual_rate' => $apm_obj->getAccrualRate(), 'maximum_time' => $apm_obj->getMaximumTime()); } } else { $milestone_rows[-1] = array('id' => -1, 'length_of_service' => 0, 'accrual_rate' => 0, 'minimum_time' => 0, 'maximum_time' => 0); } foreach ($aplf as $ap_obj) { //Debug::Arr($station,'Department', __FILE__, __LINE__, __METHOD__,10); $data = array('id' => $ap_obj->getId(), 'name' => $ap_obj->getName(), 'type_id' => $ap_obj->getType(), 'enable_pay_stub_balance_display' => $ap_obj->getEnablePayStubBalanceDisplay(), 'apply_frequency_id' => $ap_obj->getApplyFrequency(), 'apply_frequency_month' => $ap_obj->getApplyFrequencyMonth(), 'apply_frequency_day_of_month' => $ap_obj->getApplyFrequencyDayOfMonth(), 'apply_frequency_day_of_week' => $ap_obj->getApplyFrequencyDayOfWeek(), 'milestone_rollover_hire_date' => $ap_obj->getMilestoneRolloverHireDate(), 'milestone_rollover_month' => $ap_obj->getMilestoneRolloverMonth(), 'milestone_rollover_day_of_month' => $ap_obj->getMilestoneRolloverDayOfMonth(), 'minimum_employed_days' => $ap_obj->getMinimumEmployedDays(), 'recalculate_start_date' => TTDate::getBeginMonthEpoch(time()), 'recalculate_end_date' => TTDate::getEndMonthEpoch(time()), 'milestone_rows' => $milestone_rows, 'created_date' => $ap_obj->getCreatedDate(), 'created_by' => $ap_obj->getCreatedBy(), 'updated_date' => $ap_obj->getUpdatedDate(), 'updated_by' => $ap_obj->getUpdatedBy(), 'deleted_date' => $ap_obj->getDeletedDate(), 'deleted_by' => $ap_obj->getDeletedBy()); }
$aplf = new AccrualPolicyListFactory(); foreach ($ids as $id) { $aplf->getByIdAndCompanyId($id, $current_company->getId()); $aplf->StartTransaction(); foreach ($aplf as $ap_obj) { $ap_obj->setDeleted($delete); if ($ap_obj->isValid()) { $ap_obj->Save(); } } $aplf->CommitTransaction(); } Redirect::Page(URLBuilder::getURL(NULL, 'AccrualPolicyList.php')); break; default: $aplf = new AccrualPolicyListFactory(); $aplf->getByCompanyId($current_company->getId()); $pager = new Pager($aplf); $type_options = $aplf->getOptions('type'); $show_no_policy_group_notice = FALSE; foreach ($aplf as $ap_obj) { if ((int) $ap_obj->getColumn('assigned_policy_groups') == 0) { $show_no_policy_group_notice = TRUE; } $policies[] = array('id' => $ap_obj->getId(), 'name' => $ap_obj->getName(), 'type_id' => $ap_obj->getType(), 'type' => $type_options[$ap_obj->getType()], 'assigned_policy_groups' => (int) $ap_obj->getColumn('assigned_policy_groups'), 'deleted' => $ap_obj->getDeleted()); } $smarty->assign_by_ref('policies', $policies); $smarty->assign_by_ref('show_no_policy_group_notice', $show_no_policy_group_notice); $smarty->assign_by_ref('sort_column', $sort_column); $smarty->assign_by_ref('sort_order', $sort_order); $smarty->assign_by_ref('paging_data', $pager->getPageVariables());
//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::getBeginDayEpoch($data['start_date']); $end_date = TTDate::getBeginDayEpoch($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 = new AccrualPolicyFactory(); $aplf = new 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()); $x = 0; for ($i = $start_date; $i < $end_date; $i += 86400) { Debug::Text('Recalculating Accruals for Date: ' . TTDate::getDate('DATE+TIME', $i), __FILE__, __LINE__, __METHOD__, 10); $ap_obj->addAccrualPolicyTime($i, $offset); $progress_bar->setValue(Misc::calculatePercent($x, $total_days)); $progress_bar->display(); $x++; } //$aplf->FailTransaction(); $aplf->CommitTransaction();
AccrualBalanceFactory::calcBalance($user_id, $accrual_policy_id); $alf->CommitTransaction(); Redirect::Page(URLBuilder::getURL(NULL, 'ViewUserAccrualList.php')); break; default: $alf = new AccrualListFactory(); $alf->getByCompanyIdAndUserIdAndAccrualPolicyID($current_company->getId(), $user_id, $accrual_policy_id, $current_user_prefs->getItemsPerPage(), $page, NULL, $sort_array); $pager = new Pager($alf); $type_options = $alf->getOptions('type'); foreach ($alf as $a_obj) { $date_stamp = $a_obj->getColumn('date_stamp'); if ($date_stamp != '') { $date_stamp = TTDate::strtotime($date_stamp); } $accruals[] = array('id' => $a_obj->getId(), 'user_id' => $a_obj->getUser(), 'accrual_policy_id' => $a_obj->getAccrualPolicyId(), 'type_id' => $a_obj->getType(), 'type' => $type_options[$a_obj->getType()], 'user_date_total_id' => $a_obj->getUserDateTotalId(), 'user_date_total_date_stamp' => $date_stamp, 'time_stamp' => $a_obj->getTimeStamp(), 'amount' => $a_obj->getAmount(), 'deleted' => $a_obj->getDeleted()); } $smarty->assign_by_ref('accruals', $accruals); $ulf = new UserListFactory(); $user_obj = $ulf->getById($user_id)->getCurrent(); $aplf = new AccrualPolicyListFactory(); $accrual_policy_obj = $aplf->getById($accrual_policy_id)->getCurrent(); $smarty->assign_by_ref('user_id', $user_id); $smarty->assign_by_ref('user_full_name', $user_obj->getFullName()); $smarty->assign_by_ref('accrual_policy_id', $accrual_policy_id); $smarty->assign_by_ref('accrual_policy', $accrual_policy_obj->getName()); $smarty->assign_by_ref('sort_column', $sort_column); $smarty->assign_by_ref('sort_order', $sort_order); $smarty->assign_by_ref('paging_data', $pager->getPageVariables()); break; } $smarty->display('accrual/ViewUserAccrualList.tpl');
function getAbsencePolicyData($absence_policy_id) { global $current_company; if (!is_object($current_company)) { return FALSE; } $aplf = new AbsencePolicyListFactory(); $aplf->getByIdAndCompanyId($absence_policy_id, $current_company->getId()); if ($aplf->getRecordCount() > 0) { $ap_obj = $aplf->getCurrent(); $ap_data = $ap_obj->getObjectAsArray(); $aplf = new AccrualPolicyListFactory(); $aplf->getByIdAndCompanyId($ap_obj->getAccrualPolicyID(), $current_company->getId()); if ($aplf->getRecordCount() > 0) { $ap_data['accrual_policy_name'] = $aplf->getCurrent()->getName(); } else { $ap_data['accrual_policy_name'] = 'None'; } return $ap_data; } return FALSE; }
$user_id = $filter_user_id; } else { $user_id = $current_user->getId(); $filter_user_id = $current_user->getId(); } } else { $filter_user_id = $user_id = $current_user->getId(); } $filter_data = NULL; //Get user object $ulf->getByIdAndCompanyID($user_id, $current_company->getId()); if ($ulf->getRecordCount() > 0) { $user_obj = $ulf->getCurrent(); $ablf->getByUserIdAndCompanyId($user_id, $current_company->getId(), $current_user_prefs->getItemsPerPage(), $page, NULL, $sort_array); $pager = new Pager($ablf); $aplf = new AccrualPolicyListFactory(); $accrual_policy_options = $aplf->getByCompanyIDArray($current_company->getId()); foreach ($ablf as $ab_obj) { $accruals[] = array('id' => $ab_obj->getId(), 'user_id' => $ab_obj->getUser(), 'accrual_policy_id' => $ab_obj->getAccrualPolicyId(), 'accrual_policy' => $accrual_policy_options[$ab_obj->getAccrualPolicyId()], 'balance' => $ab_obj->getBalance(), 'deleted' => $ab_obj->getDeleted()); } $smarty->assign_by_ref('accruals', $accruals); $hlf = new HierarchyListFactory(); $permission_children_ids = $hlf->getHierarchyChildrenByCompanyIdAndUserIdAndObjectTypeID($current_company->getId(), $current_user->getId()); Debug::Arr($permission_children_ids, 'Permission Children Ids:', __FILE__, __LINE__, __METHOD__, 10); if ($permission->Check('accrual', 'view') == FALSE) { if ($permission->Check('accrual', 'view_child')) { $filter_data['permission_children_ids'] = $permission_children_ids; } if ($permission->Check('accrual', 'view_own')) { $filter_data['permission_children_ids'][] = $current_user->getId(); }
function getProjectedAbsencePolicyBalance($absence_policy_id, $user_id, $epoch, $amount, $previous_amount = 0) { if ($absence_policy_id == '') { return $this->returnHandler(FALSE); } if ($user_id == '') { return $this->returnHandler(FALSE); } $epoch = TTDate::parseDateTime($epoch); $aplf = TTnew('AbsencePolicyListFactory'); $aplf->getByIdAndCompanyId($absence_policy_id, $this->getCurrentCompanyObject()->getId()); if ($aplf->getRecordCount() > 0) { $ap_obj = $aplf->getCurrent(); if ($ap_obj->getAccrualPolicyID() != '') { $acplf = new AccrualPolicyListFactory(); $acplf->getById($ap_obj->getAccrualPolicyID()); if ($acplf->getRecordCount() > 0) { $acp_obj = $acplf->getCurrent(); $ulf = TTnew('UserListFactory'); $ulf->getByIDAndCompanyID($user_id, $this->getCurrentCompanyObject()->getId()); if ($ulf->getRecordCount() == 1) { $u_obj = $ulf->getCurrent(); return $this->returnHandler($acp_obj->getAccrualBalanceWithProjection($u_obj, $epoch, $amount, $previous_amount)); } } } } return $this->returnHandler(FALSE); }
if (!$permission->Check('report', 'enabled') or !$permission->Check('report', 'view_accrual_balance_summary')) { $permission->Redirect(FALSE); //Redirect } $smarty->assign('title', TTi18n::gettext($title = 'Accrual Balance Summary Report')); // See index.php /* * Get FORM variables */ extract(FormVariables::GetVariables(array('action', 'generic_data', 'filter_data'))); URLBuilder::setURL($_SERVER['SCRIPT_NAME'], array('filter_data' => $filter_data)); $static_columns = array('-1000-full_name' => TTi18n::gettext('Full Name'), '-1002-employee_number' => TTi18n::gettext('Employee #'), '-1010-title' => TTi18n::gettext('Title'), '-1020-province' => TTi18n::gettext('Province/State'), '-1030-country' => TTi18n::gettext('Country'), '-1039-group' => TTi18n::gettext('Group'), '-1040-default_branch' => TTi18n::gettext('Default Branch'), '-1050-default_department' => TTi18n::gettext('Default Department')); $columns = array('-1060-total_balance' => TTi18n::gettext('Total Balance')); $columns = Misc::prependArray($static_columns, $columns); //Get all accrual policies. $aplf = new AccrualPolicyListFactory(); $aplf->getByCompanyId($current_company->getId()); if ($aplf->getRecordCount() > 0) { foreach ($aplf as $ap_obj) { $ap_columns['accrual_policy-' . $ap_obj->getId()] = $ap_obj->getName(); } $columns = array_merge($columns, $ap_columns); } $filter_data = Misc::preSetArrayValues($filter_data, array('include_user_ids', 'exclude_user_ids', 'user_status_ids', 'group_ids', 'branch_ids', 'department_ids', 'user_title_ids', 'pay_period_ids', 'column_ids'), array()); $permission_children_ids = array(); if ($permission->Check('accrual', 'view') == FALSE) { $hlf = new HierarchyListFactory(); $permission_children_ids = $hlf->getHierarchyChildrenByCompanyIdAndUserIdAndObjectTypeID($current_company->getId(), $current_user->getId()); Debug::Arr($permission_children_ids, 'Permission Children Ids:', __FILE__, __LINE__, __METHOD__, 10); if ($permission->Check('accrual', 'view_child') == FALSE) { $permission_children_ids = array();
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 = new AccrualFactory(); $af->setUser($this->getUserDateObject()->getUser()); $af->setAccrualPolicyID($accrual_policy_id); $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 = new AccrualFactory(); $af->setUser($this->getUserDateObject()->getUser()); $af->setAccrualPolicyID($accrual_policy_id); $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, __FILE__, __LINE__, __METHOD__, 10); if ($accrual_policy_id > 0) { $af = new AccrualFactory(); $af->setUser($this->getUserDateObject()->getUser()); $af->setAccrualPolicyID($accrual_policy_id); $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 = new 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 = new 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); } } /* //FIXME: Figure a better way to re-calculate accrual policies assigned to absences to update accrual balances if ( $this->getEnableCalcAccrualPolicy() == TRUE ) { Debug::text('Recalculating Accruals assigned to absence policies...', __FILE__, __LINE__, __METHOD__, 10); $udtlf = new UserDateTotalListFactory(); $udtlf->getByUserDateIdAndStatus( $this->getUserDateID(), 30 ); //Absences only if ( $udtlf->getRecordCount() > 0 ) { foreach( $udtlf as $udt_obj ) { $accrual_policy_id = $udt_obj->getAbsencePolicyObject()->getAccrualPolicyID(); Debug::text('Absence Accrual Policy ID: '. $accrual_policy_id, __FILE__, __LINE__, __METHOD__, 10); if ( $accrual_policy_id > 0 AND $this->getTotalTime() > 0 ) { $af = new AccrualFactory(); $af->setUser( $this->getUserDateObject()->getUser() ); $af->setAccrualPolicyID( $accrual_policy_id ); $af->setType(20); $af->setUserDateTotalID( $udt_obj->getID() ); $af->setAmount( bcmul( $udt_obj->getTotalTime(), -1 ) ); $af->setEnableCalcBalance(TRUE); if ( $af->isValid() ) { $af->Save(); } } } } } else { Debug::text('NOT Recalculating Accruals assigned to absence policies...', __FILE__, __LINE__, __METHOD__, 10); } */ return TRUE; }
*/ /* * Adds time to employee accruals based on calendar milestones * This file should run once a day. * */ require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'global.inc.php'; require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'CLI.inc.php'; //Debug::setVerbosity(11); $current_epoch = TTDate::getTime(); //$current_epoch = strtotime('28-Dec-07 1:00 AM'); $offset = 86400 - 3600 * 2; //22hrs of variance. Must be less than 24hrs which is how often this script runs. $clf = new CompanyListFactory(); $clf->getAll(); if ($clf->getRecordCount() > 0) { foreach ($clf as $c_obj) { if ($c_obj->getStatus() != 30) { $aplf = new AccrualPolicyListFactory(); $aplf->getByCompanyIdAndTypeId($c_obj->getId(), array(20, 30)); //Include hour based accruals so rollover adjustments can be calculated. if ($aplf->getRecordCount() > 0) { foreach ($aplf as $ap_obj) { $ap_obj->addAccrualPolicyTime($current_epoch, $offset); } } } } } Debug::writeToLog(); Debug::Display();
* $Date: 2006-12-06 14:58:53 -0800 (Wed, 06 Dec 2006) $ */ /* * Adds time to employee accruals based on calendar milestones * This file should run once a day. * */ require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'global.inc.php'; require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'CLI.inc.php'; //Debug::setVerbosity(11); $current_epoch = TTDate::getTime(); //$current_epoch = strtotime('28-Dec-07 1:00 AM'); $offset = 86400 - 3600 * 2; //22hrs of variance. Must be less than 24hrs which is how often this script runs. $clf = new CompanyListFactory(); $clf->getAll(); if ($clf->getRecordCount() > 0) { foreach ($clf as $c_obj) { if ($c_obj->getStatus() != 30) { $aplf = new AccrualPolicyListFactory(); $aplf->getByCompanyIdAndTypeId($c_obj->getId(), 20); if ($aplf->getRecordCount() > 0) { foreach ($aplf as $ap_obj) { $ap_obj->addAccrualPolicyTime($current_epoch, $offset); } } } } } Debug::writeToLog(); Debug::Display();