function findPayPeriod() { Debug::Text('Attempting to find Pay Period for Start Date: ' . $this->getDateStamp(), __FILE__, __LINE__, __METHOD__, 10); if ($this->getDateStamp() > 0 and $this->getUser() > 0) { //FIXME: With MySQL since it doesn't handle timezones very well I think we need to //get the timezone of the payperiod schedule for this user, and set the timezone to that //before we go searching for a pay period, otherwise the wrong payperiod might be returned. //This might happen when the MySQL server is in one timezone (ie: CST) and the pay period //schedule is set to another timezone (ie: PST) //This could severely slow down a lot of operations though, so make this specific to MySQL only. $pplf = new PayPeriodListFactory(); $pplf->getByUserIdAndEndDate($this->getUser(), $this->getDateStamp()); $pay_period = $pplf->getCurrent(); Debug::Text('Pay Period Id: ' . $pay_period->getId(), __FILE__, __LINE__, __METHOD__, 10); if ($pay_period->getId() !== FALSE) { return $pay_period->getId(); } } Debug::Text('Attempt failed: ', __FILE__, __LINE__, __METHOD__, 10); return FALSE; }
function getPayStubId() { //Find which pay period this effective date belongs too $pplf = new PayPeriodListFactory(); $pplf->getByUserIdAndEndDate($this->getUser(), $this->getEffectiveDate()); if ($pplf->getRecordCount() > 0) { $pp_obj = $pplf->getCurrent(); Debug::text('Found Pay Period ID: ' . $pp_obj->getId(), __FILE__, __LINE__, __METHOD__, 10); //Percent PS amendments can't work on advances. $pslf = new PayStubListFactory(); $pslf->getByUserIdAndPayPeriodIdAndAdvance($this->getUser(), $pp_obj->getId(), FALSE); if ($pslf->getRecordCount() > 0) { $ps_obj = $pslf->getCurrent(); Debug::text('Found Pay Stub for this effective date: ' . $ps_obj->getId(), __FILE__, __LINE__, __METHOD__, 10); return $ps_obj->getId(); } } return FALSE; }
function reCalculate() { //Re-generate final pay stub //get current pay period based off their last day of work $pplf = new PayPeriodListFactory(); $pay_period_id = $pplf->getByUserIdAndEndDate($this->getUser(), $this->getLastDate())->getCurrent()->getId(); Debug::Text('Pay Period ID: ' . $pay_period_id, __FILE__, __LINE__, __METHOD__, 10); if (is_numeric($pay_period_id) == FALSE) { UserGenericStatusFactory::queueGenericStatus($this->getUserObject()->getFullName(TRUE) . ' - ' . TTi18n::gettext('Pay Stub'), 10, TTi18n::gettext('Pay Period is invalid!'), NULL); return FALSE; } if ($this->getEnableGeneratePayStub() == TRUE) { //Find out if a pay stub is already generated for the pay period we are currently in. //If it is, delete it so we can start from fresh $pslf = new PayStubListFactory(); $pslf->getByUserIdAndPayPeriodId($this->getUser(), $pay_period_id); foreach ($pslf as $pay_stub) { Debug::Text('Found Pay Stub ID: ' . $pay_stub->getId(), __FILE__, __LINE__, __METHOD__, 10); //Do not delete PAID pay stubs! if ($pay_stub->getStatus() == 10) { Debug::Text('Last Pay Stub Exists: ' . $pay_stub->getId(), __FILE__, __LINE__, __METHOD__, 10); $pay_stub->setDeleted(TRUE); $pay_stub->Save(); } } //FIXME: Make sure user isn't already in-active! Otherwise pay stub won't generate. //Check if pay stub is already generated as well, if it is, and marked paid, then //we can't re-generate it, we need to skip this step. Debug::Text('Calculating Pay Stub...', __FILE__, __LINE__, __METHOD__, 10); $cps = new CalculatePayStub(); $cps->setUser($this->getUser()); $cps->setPayPeriod($pay_period_id); $cps->calculate(); Debug::Text('Done Calculating Pay Stub', __FILE__, __LINE__, __METHOD__, 10); } else { UserGenericStatusFactory::queueGenericStatus($this->getUserObject()->getFullName(TRUE), 20, TTi18n::gettext('Not generating final pay stub!'), NULL); } //FIXME: Alert the user if they don't have enough information in TimeTrex to get accurate values. //Get insurable hours, earnings, and vacation pay now that the final pay stub is generated $ugdlf = new UserGenericDataListFactory(); $ugdlf->getByCompanyIdAndScriptAndDefault($this->getUserObject()->getCompany(), $this->getTable()); if ($ugdlf->getRecordCount() > 0) { Debug::Text('Found Company Form Setup!', __FILE__, __LINE__, __METHOD__, 10); $ugd_obj = $ugdlf->getCurrent(); $setup_data = $ugd_obj->getData(); } unset($ugd_obj); if (isset($setup_data)) { //var_dump($setup_data); if (isset($setup_data['insurable_earnings_psea_ids'])) { $insurable_earnings_psea_ids = $setup_data['insurable_earnings_psea_ids']; } else { //Fall back to Total Gross. $insurable_earnings_psea_ids = $this->getPayStubEntryAccountLinkObject()->getTotalGross(); } } //Find out the date of how far back we have to go to get insurable values. //Insurable Hours $insurable_hours_start_date = $this->getInsurablePayPeriodStartDate($this->getInsurableHoursReportPayPeriods()); //Insurable hours dont include stats!Just get total signed in hours. //If someone has just a negative bank time balance, those are NOT insurable. $udtlf = new UserDateTotalListFactory(); $worked_total_time = $udtlf->getWorkedTimeSumByUserIDAndStartDateAndEndDate($this->getUser(), $insurable_hours_start_date, $this->getLastDate()); Debug::text('Worked Total Time: ' . $worked_total_time, __FILE__, __LINE__, __METHOD__, 10); $total_hours = Misc::MoneyFormat(TTDate::getHours($worked_total_time), FALSE); Debug::Text('Total Insurable Hours: ' . $total_hours, __FILE__, __LINE__, __METHOD__, 10); $insurable_earnings_start_date = $this->getInsurablePayPeriodStartDate($this->getInsurableEarningsReportPayPeriods()); $pself = new PayStubEntryListFactory(); $total_earnings = $this->getTotalInsurableEarnings(); //$total_earnings = $pself->getAmountSumByUserIdAndEntryNameIdAndStartDateAndEndDate( $this->getUser(), $insurable_earnings_psea_ids, $insurable_earnings_start_date, $this->getLastDate(), 0 ); //$total_earnings = $total_earnings['amount']; //Note, this includes the current pay stub we just generated Debug::Text('Total Insurable Earnings: ' . $total_earnings, __FILE__, __LINE__, __METHOD__, 10); UserGenericStatusFactory::queueGenericStatus($this->getUserObject()->getFullName(TRUE) . ' - ' . TTi18n::gettext('Record of Employment'), 30, TTi18n::gettext('Insurable Hours:') . ' ' . $total_hours . ' ' . TTi18n::gettext('Insurable Earnings:') . ' ' . $total_earnings, NULL); //ReSave these if ($this->getId() != '') { $rlf = new ROEListFactory(); $rlf->getById($this->getId()); if ($rlf->getRecordCount() > 0) { $roe_obj = $rlf->getCurrent(); $roe_obj->setInsurableHours($total_hours); $roe_obj->setInsurableEarnings($total_earnings); if ($roe_obj->isValid()) { $roe_obj->Save(); } } } 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; }
*/ $hlf = new HolidayListFactory(); $holiday_array = $hlf->getArrayByPolicyGroupUserId($user_id, $start_date, $end_date); //var_dump($holiday_array); /* Get pay period locked days */ if (isset($pay_period_obj) and is_object($pay_period_obj)) { foreach ($calendar_array as $cal_arr) { if ($cal_arr['epoch'] >= $pay_period_obj->getStartDate() and $cal_arr['epoch'] <= $pay_period_obj->getEndDate()) { //Debug::text('Current Pay Period: '. TTDate::getDate('DATE+TIME', $cal_arr['epoch'] ), __FILE__, __LINE__, __METHOD__,10); $pay_period_locked_rows[$cal_arr['epoch']] = $pay_period_obj->getIsLocked(); } else { //Debug::text('Diff Pay Period...', __FILE__, __LINE__, __METHOD__,10); //FIXME: Add some caching here perhaps? $pplf->getByUserIdAndEndDate($user_id, $cal_arr['epoch']); if ($pplf->getRecordCount() > 0) { $tmp_pay_period_obj = $pplf->getCurrent(); $pay_period_locked_rows[$cal_arr['epoch']] = $tmp_pay_period_obj->getIsLocked(); } else { //Debug::text(' Did not Found rows...', __FILE__, __LINE__, __METHOD__,10); //Allow them to edit payperiods in future. $pay_period_locked_rows[$cal_arr['epoch']] = FALSE; } } } unset($tmp_pay_period_obj); } //var_dump($pay_period_locked_rows); /* Get TimeSheet verification
if (!isset($first_date) or $first_date == '') { $first_date = $user_obj->getHireDate(); } Debug::Text('First Date: ' . TTDate::getDate('DATE+TIME', $first_date), __FILE__, __LINE__, __METHOD__, 10); //Get last shift worked (not scheduled) $plf->getLastPunchByUserId($user_id); if ($plf->getRecordCount() > 0) { $punch_obj = $plf->getCurrent(); $last_date = $punch_obj->getPunchControlObject()->getUserDateObject()->getDateStamp(); } else { $last_date = TTDate::getTime(); } Debug::Text('Last Punch Date: ' . TTDate::getDate('DATE+TIME', $last_date), __FILE__, __LINE__, __METHOD__, 10); //Get pay period of last shift workd $plf = new PayPeriodListFactory(); $pay_period_obj = $plf->getByUserIdAndEndDate($user_id, $last_date)->getCurrent(); $pay_period_type_id = FALSE; if (is_object($pay_period_obj->getPayPeriodScheduleObject())) { $pay_period_type_id = $pay_period_obj->getPayPeriodScheduleObject()->getType(); } $roe_data = array('user_id' => $user_id, 'pay_period_type_id' => $pay_period_type_id, 'first_date' => $first_date, 'last_date' => $last_date, 'pay_period_end_date' => $pay_period_obj->getEndDate()); } //Select box options; $roe_data['code_options'] = $roef->getOptions('code'); $ppsf = new PayPeriodScheduleFactory(); $roe_data['pay_period_type_options'] = $ppsf->getOptions('type'); unset($roe_data['pay_period_type_options'][5]); $user_options = UserListFactory::getByCompanyIdArray($current_company->getId(), FALSE); $smarty->assign_by_ref('user_options', $user_options); //PSEA accounts $psealf = new PayStubEntryAccountListFactory();
foreach ($slf as $s_obj) { //Debug::Arr($station,'Department', __FILE__, __LINE__, __METHOD__,10); $data = array('id' => $s_obj->getId(), 'user_date_id' => $s_obj->getUserDateId(), 'user_id' => $s_obj->getUserDateObject()->getUser(), 'user_full_name' => $s_obj->getUserDateObject()->getUserObject()->getFullName(), 'date_stamp' => $s_obj->getUserDateObject()->getDateStamp(), 'status_id' => $s_obj->getStatus(), 'start_time' => $s_obj->getStartTime(), 'parsed_start_time' => $s_obj->getStartTime(), 'end_time' => $s_obj->getEndTime(), 'parsed_end_time' => $s_obj->getEndTime(), 'total_time' => $s_obj->getTotalTime(), 'schedule_policy_id' => $s_obj->getSchedulePolicyID(), 'absence_policy_id' => $s_obj->getAbsencePolicyID(), 'branch_id' => $s_obj->getBranch(), 'department_id' => $s_obj->getDepartment(), 'job_id' => $s_obj->getJob(), 'job_item_id' => $s_obj->getJobItem(), 'pay_period_is_locked' => $s_obj->getUserDateObject()->getPayPeriodObject()->getIsLocked(), 'created_date' => $s_obj->getCreatedDate(), 'created_by' => $s_obj->getCreatedBy(), 'updated_date' => $s_obj->getUpdatedDate(), 'updated_by' => $s_obj->getUpdatedBy(), 'deleted_date' => $s_obj->getDeletedDate(), 'deleted_by' => $s_obj->getDeletedBy(), 'is_owner' => $permission->isOwner($s_obj->getUserDateObject()->getUserObject()->getCreatedBy(), $s_obj->getUserDateObject()->getUserObject()->getId()), 'is_child' => $permission->isChild($s_obj->getUserDateObject()->getUserObject()->getId(), $permission_children_ids)); } } elseif ($action != 'submit') { Debug::Text(' ID was NOT passed: ' . $id, __FILE__, __LINE__, __METHOD__, 10); //Get user full name if ($user_id != '') { $ulf = new UserListFactory(); $user_obj = $ulf->getById($user_id)->getCurrent(); $user_full_name = $user_obj->getFullName(); $user_default_branch = $user_obj->getDefaultBranch(); $user_default_department = $user_obj->getDefaultDepartment(); $user_date_id = UserDateFactory::getUserDateID($user_id, $date_stamp); $pplf = new PayPeriodListFactory(); $pplf->getByUserIdAndEndDate($user_id, $date_stamp); if ($pplf->getRecordCount() > 0) { $pay_period_is_locked = $pplf->getCurrent()->getIsLocked(); } else { $pay_period_is_locked = FALSE; } } else { $user_id = NULL; $user_date_id = NULL; $user_full_name = NULL; $user_default_branch = NULL; $user_default_department = NULL; $pay_period_is_locked = FALSE; } if (!is_numeric($start_time)) { $start_time = strtotime('08:00 AM');