$ugdf->Save(); } $ulf = new UserListFactory(); $ulf->getSearchByCompanyIdAndArrayCriteria($current_company->getId(), $filter_data); if ($ulf->getRecordCount() > 0) { foreach ($ulf as $u_obj) { $filter_data['user_ids'][] = $u_obj->getId(); } if (isset($filter_data['year']) and isset($filter_data['user_ids'])) { //Get all pay period IDs in year. if (isset($filter_data['year'])) { $year_epoch = mktime(0, 0, 0, 1, 1, $filter_data['year']); Debug::Text(' Year: ' . TTDate::getDate('DATE+TIME', $year_epoch), __FILE__, __LINE__, __METHOD__, 10); } $pself = new PayStubEntryListFactory(); $pself->getReportByCompanyIdAndUserIdAndTransactionStartDateAndTransactionEndDate($current_company->getId(), $filter_data['user_ids'], TTDate::getBeginYearEpoch($year_epoch), TTDate::getEndYearEpoch($year_epoch)); $report_columns = $static_columns; foreach ($pself as $pse_obj) { $user_id = $pse_obj->getColumn('user_id'); $pay_stub_entry_name_id = $pse_obj->getColumn('pay_stub_entry_name_id'); $raw_rows[$user_id][$pay_stub_entry_name_id] = $pse_obj->getColumn('amount'); } //var_dump($raw_rows); if (isset($raw_rows)) { $ulf = new UserListFactory(); $utlf = new UserTitleListFactory(); $title_options = $utlf->getByCompanyIdArray($current_company->getId()); $uglf = new UserGroupListFactory(); $group_options = $uglf->getArrayByNodes(FastTree::FormatArray($uglf->getByCompanyIdArray($current_company->getId()), 'no_tree_text', TRUE)); $blf = new BranchListFactory(); $branch_options = $blf->getByCompanyIdArray($current_company->getId());
if (isset($filter_data['user_ids']) and isset($filter_data['year'])) { if (isset($filter_data['year'])) { $year_epoch = mktime(0, 0, 0, 1, 1, $filter_data['year']); Debug::Text(' Year: ' . TTDate::getDate('DATE+TIME', $year_epoch), __FILE__, __LINE__, __METHOD__, 10); } $pseallf = TTnew('PayStubEntryAccountLinkListFactory'); $pseallf->getByCompanyId($current_company->getId()); if ($pseallf->getRecordCount() > 0) { $pseal_obj = $pseallf->getCurrent(); } // //Get all data for the form. // //Get Pay Periods in date range. $pplf = TTnew('PayPeriodListFactory'); $pplf->getByCompanyIdAndTransactionStartDateAndTransactionEndDate($current_company->getId(), TTDate::getBeginYearEpoch($year_epoch), TTDate::getEndYearEpoch($year_epoch)); if ($pplf->getRecordCount() > 0) { foreach ($pplf as $pp_obj) { $pay_period_ids[] = $pp_obj->getID(); } } $report_columns = $static_columns; $pself = TTnew('PayStubEntryListFactory'); $pself->getReportByCompanyIdAndUserIdAndPayPeriodId($current_company->getId(), $filter_data['user_ids'], $pay_period_ids); foreach ($pself as $pse_obj) { $user_id = $pse_obj->getColumn('user_id'); $pay_stub_entry_name_id = $pse_obj->getColumn('pay_stub_entry_name_id'); $raw_rows[$user_id][$pay_stub_entry_name_id] = $pse_obj->getColumn('amount'); } //var_dump($raw_rows); //
function getOtherEntryNamesByUserIdAndPayStubIdAndYear($user_id, $pay_stub_id, $year = NULL, $where = NULL, $order = NULL) { if ($user_id == '') { return FALSE; } if ($pay_stub_id == '') { return FALSE; } if ($year == '') { $year = TTDate::getTime(); } $begin_year_epoch = TTDate::getBeginYearEpoch($year); $pplf = new PayPeriodListFactory(); $pslf = new PayStubListFactory(); //$psenlf = new PayStubEntryNameListFactory(); $psealf = new PayStubEntryAccountListFactory(); $ph = array('transaction_date' => $this->db->BindTimeStamp($begin_year_epoch), 'user_id' => $user_id, 'pay_stub_id' => $pay_stub_id); //Make sure we don't include entries that have a sum of 0. //This is YTD for the EMPLOYEES... So it should always be when they are paid. $query = ' select distinct(pay_stub_entry_name_id) from ' . $this->getTable() . ' as a, ' . $pslf->getTable() . ' as b, ' . $psealf->getTable() . ' as c where a.pay_stub_id = b.id AND a.pay_stub_entry_name_id = c.id AND b.pay_period_id in (select id from ' . $pplf->getTable() . ' as y where y.pay_period_schedule_id = ( select pay_period_schedule_id from ' . $pplf->getTable() . ' as z where z.id = b.pay_period_id ) AND y.transaction_date >= ? AND y.deleted=0) AND b.user_id = ? AND c.type_id in (10,20,30) AND a.pay_stub_entry_name_id NOT IN ( select distinct(pay_stub_entry_name_id) from ' . $this->getTable() . ' as x WHERE x.pay_stub_id = ?) AND a.deleted = 0 AND b.deleted = 0 GROUP BY pay_stub_entry_name_id HAVING sum(amount) > 0'; $query .= $this->getWhereSQL($where); $query .= $this->getSortSQL($order); $result = $this->rs = $this->db->GetCol($query, $ph); return $result; }
function createPayPeriods() { $max_pay_periods = 29; $ppslf = new PayPeriodScheduleListFactory(); $ppslf->getById($this->pay_period_schedule_id); if ($ppslf->getRecordCount() > 0) { $pps_obj = $ppslf->getCurrent(); for ($i = 0; $i < $max_pay_periods; $i++) { if ($i == 0) { //$end_date = TTDate::getBeginYearEpoch( strtotime('01-Jan-07') ); $end_date = TTDate::getBeginYearEpoch(time()); } else { $end_date = $end_date + 86400 * 14; } Debug::Text('I: ' . $i . ' End Date: ' . TTDate::getDate('DATE+TIME', $end_date), __FILE__, __LINE__, __METHOD__, 10); $pps_obj->createNextPayPeriod($end_date, 86400 * 3600); } } return TRUE; }
function isUniqueName($name) { //BindDate() causes a deprecated error if date_stamp is not set, so just return TRUE so we can throw a invalid date error elsewhere instead. //This also causes it so we can never have a invalid date and invalid name validation errors at the same time. if ($this->getDateStamp() == '') { return TRUE; } //When a holiday gets moved back/forward due to falling on weekend, it can throw off the check to see if the holiday //appears in the same year. For example new years 01-Jan-2011 gets moved to 31-Dec-2010, its in the same year //as the previous New Years day or 01-Jan-2010, so this check fails. // //I think this can only happen with New Years, or other holidays that fall within two days of the new year. //So exclude the first three days of the year to allow for weekend adjustments. $ph = array('policy_id' => $this->getHolidayPolicyID(), 'name' => $name, 'start_date1' => $this->db->BindDate(TTDate::getBeginYearEpoch($this->getDateStamp()) + 86400 * 3), 'end_date1' => $this->db->BindDate(TTDate::getEndYearEpoch($this->getDateStamp())), 'start_date2' => $this->db->BindDate($this->getDateStamp() - 86400 * 15), 'end_date2' => $this->db->BindDate($this->getDateStamp() + 86400 * 15)); $query = 'select id from ' . $this->getTable() . ' where holiday_policy_id = ? AND name = ? AND ( ( date_stamp >= ? AND date_stamp <= ? ) OR ( date_stamp >= ? AND date_stamp <= ? ) ) AND deleted=0'; $name_id = $this->db->GetOne($query, $ph); Debug::Arr($name_id, 'Unique Name: ' . $name, __FILE__, __LINE__, __METHOD__, 10); if ($name_id === FALSE) { return TRUE; } else { if ($name_id == $this->getId()) { return TRUE; } } return FALSE; }
function testCalendarAccrualD() { global $dd; $hire_date = $this->getUserObject($this->user_id)->getHireDate(); $current_epoch = TTDate::getBeginYearEpoch($hire_date + 86400 * 365 * 2); $accrual_policy_id = $this->createAccrualPolicy($this->company_id, 50); $dd->createPolicyGroup($this->company_id, NULL, NULL, NULL, NULL, NULL, NULL, array($this->user_id), NULL, array($accrual_policy_id)); $this->calcAccrualTime($this->company_id, $accrual_policy_id, TTDate::getBeginYearEpoch($current_epoch), TTDate::getEndYearEpoch($current_epoch)); $accrual_balance = $this->getCurrentAccrualBalance($this->user_id, $accrual_policy_id); $this->assertEquals($accrual_balance, 80 * 3600); }
function createPayStubAmendments($epoch = NULL) { //Get all recurring pay stub amendments and generate single pay stub amendments if appropriate. if ($epoch == '') { $epoch = TTDate::getTime(); } $ulf = new UserListFactory(); Debug::text('Recurring PS Amendment ID: ' . $this->getId() . ' Frequency: ' . $this->getFrequency(), __FILE__, __LINE__, __METHOD__, 10); $this->StartTransaction(); $tmp_user_ids = $this->getUser(); if ($tmp_user_ids[0] == -1) { $ulf->getByCompanyIdAndStatus($this->getCompany(), 10); foreach ($ulf as $user_obj) { $user_ids[] = $user_obj->getId(); } unset($user_obj); } else { $user_ids = $this->getUser(); } unset($tmp_user_ids); Debug::text('Total User IDs: ' . count($user_ids), __FILE__, __LINE__, __METHOD__, 10); if (is_array($user_ids) and count($user_ids) > 0) { //Make the PS amendment duplicate check start/end date separate //Make the PS amendment effective date separate. switch ($this->getFrequency()) { case 10: //Get all open pay periods $pplf = new PayPeriodListFactory(); //FIXME: Get all non-closed pay periods AFTER the start date. $pplf->getByUserIdListAndNotStatusAndStartDateAndEndDate($user_ids, 20, $this->getStartDate(), $this->getEndDate()); //All non-closed pay periods Debug::text('Found Open Pay Periods: ' . $pplf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10); foreach ($pplf as $pay_period_obj) { Debug::text('Working on Pay Period: ' . $pay_period_obj->getId(), __FILE__, __LINE__, __METHOD__, 10); //If near the end of a pay period, or a pay period is already ended, add PS amendment if //it does not already exist. if ($epoch >= $pay_period_obj->getEndDate() and $this->checkTimeFrame($epoch)) { Debug::text('After end of pay period.', __FILE__, __LINE__, __METHOD__, 10); $psalf = new PayStubAmendmentListFactory(); //Loop through each user of this Pay Period Schedule adding PS amendments if they don't already exist. $pay_period_schedule_users = $pay_period_obj->getPayPeriodScheduleObject()->getUser(); Debug::text(' Pay Period Schedule Users: ' . count($pay_period_schedule_users), __FILE__, __LINE__, __METHOD__, 10); foreach ($pay_period_schedule_users as $user_id) { //Make sure schedule user is in the PS amendment user list and user is active. Debug::text(' Pay Period Schedule User: '******' Recurring PS Amendment Selected Users: ', __FILE__, __LINE__, __METHOD__,10); if ($ulf->getById($user_id)->getCurrent()->getStatus() == 10 and in_array($user_id, $user_ids)) { //Check to see if the amendment was added already. if ($psalf->getByUserIdAndRecurringPayStubAmendmentIdAndStartDateAndEndDate($user_id, $this->getId(), $pay_period_obj->getStartDate(), $pay_period_obj->getEndDate())->getRecordCount() == 0) { //No amendment, good to insert one Debug::text('Inserting Recurring PS Amendment for User: '******'Recurring PS Amendment already inserted for User: '******'Skipping User because they are INACTIVE or are not on the Recurring PS Amendment User List - ID: ' . $user_id, __FILE__, __LINE__, __METHOD__, 10); //continue; } } } else { Debug::text('Not in TimeFrame, not inserting amendments: Epoch: ' . $epoch . ' Pay Period End Date: ' . $pay_period_obj->getEndDate(), __FILE__, __LINE__, __METHOD__, 10); } } break; case 30: //Weekly //Weekly case 40: //Monthly //Monthly case 70: //Annually switch ($this->getFrequency()) { case 30: $trigger_date = TTDate::getDateOfNextDayOfWeek(TTDate::getBeginWeekEpoch($epoch), $this->getStartDate()); $start_date = TTDate::getBeginWeekEpoch($epoch); $end_date = TTDate::getEndWeekEpoch($epoch); break; case 40: $trigger_date = TTDate::getDateOfNextDayOfMonth(TTDate::getBeginMonthEpoch($epoch), $this->getStartDate()); //$monthly_date = TTDate::getDateOfNextDayOfMonth( TTDate::getBeginMonthEpoch($epoch), $this->getStartDate() ); $start_date = TTDate::getBeginMonthEpoch($epoch); $end_date = TTDate::getEndMonthEpoch($epoch); break; case 70: $trigger_date = TTDate::getDateOfNextYear($this->getStartDate()); $start_date = TTDate::getBeginYearEpoch($epoch); $end_date = TTDate::getEndYearEpoch($epoch); break; } Debug::text('Trigger Date: ' . TTDate::getDate('DATE', $trigger_date), __FILE__, __LINE__, __METHOD__, 10); if ($epoch >= $trigger_date and $this->checkTimeFrame($epoch)) { Debug::text('After end of pay period.', __FILE__, __LINE__, __METHOD__, 10); foreach ($user_ids as $user_id) { //Make sure schedule user is in the PS amendment user list and user is active. if ($ulf->getById($user_id)->getCurrent()->getStatus() != 10 and !in_array($user_id, $user_ids)) { Debug::text('Skipping User because they are INACTIVE or are not on the Recurring PS Amendment User List - ID: ' . $user_id, __FILE__, __LINE__, __METHOD__, 10); continue; } $psalf = new PayStubAmendmentListFactory(); if ($psalf->getByUserIdAndRecurringPayStubAmendmentIdAndStartDateAndEndDate($user_id, $this->getId(), $start_date, $end_date)->getRecordCount() == 0) { //No amendment, good to insert one Debug::text('Inserting Recurring PS Amendment for User: '******'Recurring PS Amendment already inserted for User: ' . $user_id, __FILE__, __LINE__, __METHOD__, 10); } } } break; } } //$this->FailTransaction(); $this->CommitTransaction(); return TRUE; }
public static function getTimePeriodDates($time_period, $epoch = NULL, $user_obj = NULL, $params = NULL) { $time_period = Misc::trimSortPrefix($time_period); if ($epoch == NULL or $epoch == '' or !is_numeric($epoch)) { $epoch = self::getTime(); } $start_week_day = 0; if (is_object($user_obj)) { $user_prefs = $user_obj->getUserPreferenceObject(); if (is_object($user_prefs)) { $start_week_day = $user_prefs->getStartWeekDay(); } } switch ($time_period) { case 'custom_date': //Params must pass start_date/end_date if (isset($params['start_date'])) { $start_date = TTDate::getBeginDayEpoch($params['start_date']); } if (isset($params['end_date'])) { $end_date = TTDate::getEndDayEpoch($params['end_date']); } break; case 'custom_time': //Params must pass start_date/end_date if (isset($params['start_date'])) { $start_date = $params['start_date']; } if (isset($params['end_date'])) { $end_date = $params['end_date']; } break; case 'custom_pay_period': //Params must pass pay_period_ids if (isset($params['pay_period_id'])) { $pay_period_ids = (array) $params['pay_period_id']; } break; case 'today': $start_date = TTDate::getBeginDayEpoch($epoch); $end_date = TTDate::getEndDayEpoch($epoch); break; case 'yesterday': $start_date = TTDate::getBeginDayEpoch(TTDate::getMiddleDayEpoch($epoch) - 86400); $end_date = TTDate::getEndDayEpoch(TTDate::getMiddleDayEpoch($epoch) - 86400); break; case 'last_24_hours': $start_date = $epoch - 86400; $end_date = $epoch; break; case 'last_48_hours': $start_date = $epoch - 86400 * 2; $end_date = $epoch; break; case 'last_72_hours': $start_date = $epoch - 86400 * 3; $end_date = $epoch; break; case 'this_week': $start_date = TTDate::getBeginWeekEpoch($epoch, $start_week_day); $end_date = TTDate::getEndWeekEpoch($epoch, $start_week_day); break; case 'last_week': $start_date = TTDate::getBeginWeekEpoch(TTDate::getMiddleDayEpoch($epoch) - 86400 * 7, $start_week_day); $end_date = TTDate::getEndWeekEpoch(TTDate::getMiddleDayEpoch($epoch) - 86400 * 7, $start_week_day); break; case 'last_2_weeks': $start_date = TTDate::getBeginWeekEpoch(TTDate::getMiddleDayEpoch($epoch) - 86400 * 14, $start_week_day); $end_date = TTDate::getEndWeekEpoch(TTDate::getMiddleDayEpoch($epoch) - 86400 * 7, $start_week_day); break; case 'last_7_days': $start_date = TTDate::getBeginDayEpoch(TTDate::getMiddleDayEpoch($epoch) - 86400 * 7); $end_date = TTDate::getEndDayEpoch(TTDate::getMiddleDayEpoch($epoch) - 86400); break; case 'last_14_days': $start_date = TTDate::getBeginDayEpoch(TTDate::getMiddleDayEpoch($epoch) - 86400 * 14); $end_date = TTDate::getEndDayEpoch(TTDate::getMiddleDayEpoch($epoch) - 86400); break; //Params must be passed if more than one pay period schedule exists. //Params must be passed if more than one pay period schedule exists. case 'no_pay_period': case 'this_pay_period': case 'last_pay_period': Debug::text('Time Period for Pay Period Schedule selected...', __FILE__, __LINE__, __METHOD__, 10); //Make sure user_obj is set. if (!is_object($user_obj)) { Debug::text('User Object was not passsed...', __FILE__, __LINE__, __METHOD__, 10); break; } if (!isset($params['pay_period_schedule_id'])) { $params['pay_period_schedule_id'] = NULL; } $pay_period_ids = array(); //Since we allow multiple pay_period schedules to be selected, we have to return pay_period_ids, not start/end dates. if ($time_period == 'this_pay_period') { Debug::text('this_pay_period', __FILE__, __LINE__, __METHOD__, 10); $pplf = TTnew('PayPeriodListFactory'); $pplf->getThisPayPeriodByCompanyIdAndPayPeriodScheduleIdAndDate($user_obj->getCompany(), $params['pay_period_schedule_id'], time()); if ($pplf->getRecordCount() > 0) { foreach ($pplf as $pp_obj) { $pay_period_ids[] = $pp_obj->getId(); } } } elseif ($time_period == 'last_pay_period') { Debug::text('last_pay_period', __FILE__, __LINE__, __METHOD__, 10); $pplf = TTnew('PayPeriodListFactory'); $pplf->getLastPayPeriodByCompanyIdAndPayPeriodScheduleIdAndDate($user_obj->getCompany(), $params['pay_period_schedule_id'], time()); if ($pplf->getRecordCount() > 0) { foreach ($pplf as $pp_obj) { $pay_period_ids[] = $pp_obj->getId(); } } } else { Debug::text('no_pay_period', __FILE__, __LINE__, __METHOD__, 10); } Debug::Arr($pay_period_ids, 'Pay Period IDs: ', __FILE__, __LINE__, __METHOD__, 10); if (count($pay_period_ids) == 0) { unset($pay_period_ids); } break; case 'this_month': $start_date = TTDate::getBeginMonthEpoch($epoch); $end_date = TTDate::getEndMonthEpoch($epoch); break; case 'last_month': $start_date = TTDate::getBeginMonthEpoch(TTDate::getBeginMonthEpoch($epoch) - 86400); $end_date = TTDate::getEndMonthEpoch(TTDate::getBeginMonthEpoch($epoch) - 86400); break; case 'last_2_months': $start_date = TTDate::getBeginMonthEpoch(TTDate::getBeginMonthEpoch($epoch) - 86400 * 32); $end_date = TTDate::getEndMonthEpoch(TTDate::getBeginMonthEpoch($epoch) - 86400); break; case 'last_30_days': $start_date = TTDate::getBeginDayEpoch(TTDate::getMiddleDayEpoch($epoch) - 86400 * 30); $end_date = TTDate::getEndDayEpoch(TTDate::getMiddleDayEpoch($epoch) - 86400); break; case 'last_45_days': $start_date = TTDate::getBeginDayEpoch(TTDate::getMiddleDayEpoch($epoch) - 86400 * 45); $end_date = TTDate::getEndDayEpoch(TTDate::getMiddleDayEpoch($epoch) - 86400); break; case 'last_60_days': $start_date = TTDate::getBeginDayEpoch(TTDate::getMiddleDayEpoch($epoch) - 86400 * 60); $end_date = TTDate::getEndDayEpoch(TTDate::getMiddleDayEpoch($epoch) - 86400); break; case 'this_quarter': $quarter = TTDate::getYearQuarter($epoch); $quarter_dates = TTDate::getYearQuarters($epoch, $quarter); //Debug::Arr($quarter_dates, 'Quarter Dates: Quarter: '. $quarter, __FILE__, __LINE__, __METHOD__,10); $start_date = $quarter_dates['start']; $end_date = $quarter_dates['end']; break; case 'last_quarter': $quarter = TTDate::getYearQuarter($epoch) - 1; if ($quarter == 0) { $quarter = 4; $epoch = TTDate::getBeginYearEpoch() - 86400; //Need to jump back into the previous year. } $quarter_dates = TTDate::getYearQuarters($epoch, $quarter); $start_date = $quarter_dates['start']; $end_date = $quarter_dates['end']; break; case 'last_90_days': $start_date = TTDate::getBeginDayEpoch(TTDate::getMiddleDayEpoch($epoch) - 86400 * 90); $end_date = TTDate::getEndDayEpoch(TTDate::getMiddleDayEpoch($epoch) - 86400); break; case 'this_year_1st_quarter': $quarter = 1; $quarter_dates = TTDate::getYearQuarters($epoch, $quarter); $start_date = $quarter_dates['start']; $end_date = $quarter_dates['end']; break; case 'this_year_2nd_quarter': $quarter = 2; $quarter_dates = TTDate::getYearQuarters($epoch, $quarter); $start_date = $quarter_dates['start']; $end_date = $quarter_dates['end']; break; case 'this_year_3rd_quarter': $quarter = 3; $quarter_dates = TTDate::getYearQuarters($epoch, $quarter); $start_date = $quarter_dates['start']; $end_date = $quarter_dates['end']; break; case 'this_year_4th_quarter': $quarter = 4; $quarter_dates = TTDate::getYearQuarters($epoch, $quarter); $start_date = $quarter_dates['start']; $end_date = $quarter_dates['end']; break; case 'last_year_1st_quarter': $quarter = 1; $quarter_dates = TTDate::getYearQuarters(TTDate::getBeginYearEpoch($epoch) - 86400, $quarter); $start_date = $quarter_dates['start']; $end_date = $quarter_dates['end']; break; case 'last_year_2nd_quarter': $quarter = 2; $quarter_dates = TTDate::getYearQuarters(TTDate::getBeginYearEpoch($epoch) - 86400, $quarter); $start_date = $quarter_dates['start']; $end_date = $quarter_dates['end']; break; case 'last_year_3rd_quarter': $quarter = 3; $quarter_dates = TTDate::getYearQuarters(TTDate::getBeginYearEpoch($epoch) - 86400, $quarter); $start_date = $quarter_dates['start']; $end_date = $quarter_dates['end']; break; case 'last_year_4th_quarter': $quarter = 4; $quarter_dates = TTDate::getYearQuarters(TTDate::getBeginYearEpoch($epoch) - 86400, $quarter); $start_date = $quarter_dates['start']; $end_date = $quarter_dates['end']; break; case 'last_3_months': $end_date = TTDate::getEndDayEpoch(TTDate::getMiddleDayEpoch($epoch) - 86400); $start_date = mktime(0, 0, 0, TTDate::getMonth($end_date) - 3, TTDate::getDayOfMonth($end_date), TTDate::getYear($end_date)); break; case 'last_6_months': $end_date = TTDate::getEndDayEpoch(TTDate::getMiddleDayEpoch($epoch) - 86400); $start_date = mktime(0, 0, 0, TTDate::getMonth($end_date) - 6, TTDate::getDayOfMonth($end_date), TTDate::getYear($end_date)); break; case 'last_9_months': $end_date = TTDate::getEndDayEpoch(TTDate::getMiddleDayEpoch($epoch) - 86400); $start_date = mktime(0, 0, 0, TTDate::getMonth($end_date) - 9, TTDate::getDayOfMonth($end_date), TTDate::getYear($end_date)); break; case 'last_12_months': $end_date = TTDate::getEndDayEpoch(TTDate::getMiddleDayEpoch($epoch) - 86400); $start_date = mktime(0, 0, 0, TTDate::getMonth($end_date), TTDate::getDayOfMonth($end_date), TTDate::getYear($end_date) - 1); break; case 'last_18_months': $end_date = TTDate::getEndDayEpoch(TTDate::getMiddleDayEpoch($epoch) - 86400); $start_date = mktime(0, 0, 0, TTDate::getMonth($end_date) - 18, TTDate::getDayOfMonth($end_date), TTDate::getYear($end_date)); break; case 'last_24_months': $end_date = TTDate::getEndDayEpoch(TTDate::getMiddleDayEpoch($epoch) - 86400); $start_date = mktime(0, 0, 0, TTDate::getMonth($end_date) - 24, TTDate::getDayOfMonth($end_date), TTDate::getYear($end_date)); break; case 'this_year': $start_date = TTDate::getBeginYearEpoch($epoch); $end_date = TTDate::getEndYearEpoch($epoch); break; case 'last_year': $start_date = TTDate::getBeginYearEpoch(TTDate::getBeginYearEpoch($epoch) - 86400); $end_date = TTDate::getEndYearEpoch(TTDate::getBeginYearEpoch($epoch) - 86400); break; case 'last_2_years': $end_date = TTDate::getEndYearEpoch(TTDate::getBeginYearEpoch($epoch) - 86400); $start_date = mktime(0, 0, 0, TTDate::getMonth($end_date), TTDate::getDayOfMonth($end_date), TTDate::getYear($end_date) - 2); break; case 'last_3_years': $end_date = TTDate::getEndYearEpoch(TTDate::getBeginYearEpoch($epoch) - 86400); $start_date = mktime(0, 0, 0, TTDate::getMonth($end_date), TTDate::getDayOfMonth($end_date), TTDate::getYear($end_date) - 3); break; case 'last_5_years': $end_date = TTDate::getEndYearEpoch(TTDate::getBeginYearEpoch($epoch) - 86400); $start_date = mktime(0, 0, 0, TTDate::getMonth($end_date), TTDate::getDayOfMonth($end_date), TTDate::getYear($end_date) - 5); break; case 'to_yesterday': //"Up To" means we need to use the end time of the day we go up to. $start_date = TTDate::getBeginYearEpoch(TTDate::getBeginYearEpoch(31564800) - 86400); $end_date = TTDate::getBeginDayEpoch(TTDate::getMiddleDayEpoch($epoch) - 86400) - 1; break; case 'to_today': $start_date = TTDate::getBeginYearEpoch(TTDate::getBeginYearEpoch(31564800) - 86400); $end_date = TTDate::getBeginDayEpoch(TTDate::getMiddleDayEpoch($epoch)) - 1; break; case 'to_this_week': $start_date = TTDate::getBeginYearEpoch(TTDate::getBeginYearEpoch(31564800) - 86400); $end_date = TTDate::getBeginWeekEpoch($epoch, $start_week_day) - 1; break; case 'to_last_week': $start_date = TTDate::getBeginYearEpoch(TTDate::getBeginYearEpoch(31564800) - 86400); $end_date = TTDate::getBeginWeekEpoch(TTDate::getMiddleDayEpoch($epoch) - 86400 * 7, $start_week_day) - 1; break; case 'to_7_days': $start_date = TTDate::getBeginYearEpoch(TTDate::getBeginYearEpoch(31564800) - 86400); $end_date = TTDate::getBeginDayEpoch(TTDate::getMiddleDayEpoch($epoch) - 86400 * 7) - 1; break; case 'to_14_days': $start_date = TTDate::getBeginYearEpoch(TTDate::getBeginYearEpoch(31564800) - 86400); $end_date = TTDate::getBeginDayEpoch(TTDate::getMiddleDayEpoch($epoch) - 86400 * 14) - 1; break; case 'to_last_pay_period': case 'to_this_pay_period': Debug::text('Time Period for Pay Period Schedule selected...', __FILE__, __LINE__, __METHOD__, 10); //Make sure user_obj is set. if (!is_object($user_obj)) { Debug::text('User Object was not passsed...', __FILE__, __LINE__, __METHOD__, 10); break; } if (!isset($params['pay_period_schedule_id'])) { $params['pay_period_schedule_id'] = NULL; } $end_date = FALSE; //Since we allow multiple pay_period schedules to be selected, we have to return pay_period_ids, not start/end dates. if ($time_period == 'to_this_pay_period') { Debug::text('to_this_pay_period', __FILE__, __LINE__, __METHOD__, 10); $pplf = TTnew('PayPeriodListFactory'); $pplf->getThisPayPeriodByCompanyIdAndPayPeriodScheduleIdAndDate($user_obj->getCompany(), $params['pay_period_schedule_id'], time()); if ($pplf->getRecordCount() > 0) { foreach ($pplf as $pp_obj) { if ($end_date == FALSE or $pp_obj->getStartDate() < $end_date) { $end_date = $pp_obj->getStartDate(); } } } } elseif ($time_period == 'to_last_pay_period') { Debug::text('to_last_pay_period', __FILE__, __LINE__, __METHOD__, 10); $pplf = TTnew('PayPeriodListFactory'); $pplf->getLastPayPeriodByCompanyIdAndPayPeriodScheduleIdAndDate($user_obj->getCompany(), $params['pay_period_schedule_id'], time()); if ($pplf->getRecordCount() > 0) { foreach ($pplf as $pp_obj) { if ($end_date == FALSE or $pp_obj->getStartDate() < $end_date) { $end_date = $pp_obj->getStartDate(); } } } } $start_date = TTDate::getBeginYearEpoch(TTDate::getBeginYearEpoch(31564800) - 86400); $end_date = $end_date - 1; break; case 'to_last_month': $start_date = TTDate::getBeginYearEpoch(TTDate::getBeginYearEpoch(31564800) - 86400); $end_date = TTDate::getBeginMonthEpoch(TTDate::getBeginMonthEpoch($epoch) - 86400) - 1; break; case 'to_this_month': $start_date = TTDate::getBeginYearEpoch(TTDate::getBeginYearEpoch(31564800) - 86400); $end_date = TTDate::getBeginMonthEpoch($epoch) - 1; break; case 'to_30_days': $start_date = TTDate::getBeginYearEpoch(TTDate::getBeginYearEpoch(31564800) - 86400); $end_date = TTDate::getBeginDayEpoch(TTDate::getMiddleDayEpoch($epoch) - 86400 * 30) - 1; break; case 'to_45_days': $start_date = TTDate::getBeginYearEpoch(TTDate::getBeginYearEpoch(31564800) - 86400); $end_date = TTDate::getBeginDayEpoch(TTDate::getMiddleDayEpoch($epoch) - 86400 * 45) - 1; break; case 'to_60_days': $start_date = TTDate::getBeginYearEpoch(TTDate::getBeginYearEpoch(31564800) - 86400); $end_date = TTDate::getBeginDayEpoch(TTDate::getMiddleDayEpoch($epoch) - 86400 * 60) - 1; break; case 'to_last_quarter': $quarter = TTDate::getYearQuarter($epoch) - 1; if ($quarter == 0) { $quarter = 4; $epoch = TTDate::getBeginYearEpoch() - 86400; //Need to jump back into the previous year. } $quarter_dates = TTDate::getYearQuarters($epoch, $quarter); $start_date = TTDate::getBeginYearEpoch(TTDate::getBeginYearEpoch(31564800) - 86400); $end_date = $quarter_dates['start'] - 1; break; case 'to_this_quarter': $quarter = TTDate::getYearQuarter($epoch); $quarter_dates = TTDate::getYearQuarters($epoch, $quarter); $start_date = TTDate::getBeginYearEpoch(TTDate::getBeginYearEpoch(31564800) - 86400); $end_date = $quarter_dates['start'] - 1; break; case 'to_90_days': $start_date = TTDate::getBeginYearEpoch(TTDate::getBeginYearEpoch(31564800) - 86400); $end_date = TTDate::getBeginDayEpoch(TTDate::getMiddleDayEpoch($epoch) - 86400 * 90) - 1; break; case 'to_this_year': $start_date = TTDate::getBeginYearEpoch(TTDate::getBeginYearEpoch(31564800) - 86400); $end_date = TTDate::getBeginYearEpoch($epoch) - 1; break; case 'to_last_year': $start_date = TTDate::getBeginYearEpoch(TTDate::getBeginYearEpoch(31564800) - 86400); $end_date = TTDate::getBeginYearEpoch(TTDate::getBeginYearEpoch($epoch) - 86400) - 1; break; case 'tomorrow': $start_date = TTDate::getBeginDayEpoch(TTDate::getMiddleDayEpoch($epoch) + 86400); $end_date = TTDate::getEndDayEpoch(TTDate::getMiddleDayEpoch($epoch) + 86400); break; case 'next_24_hours': $start_date = $epoch; $end_date = $epoch + 86400; break; case 'next_48_hours': $start_date = $epoch; $end_date = $epoch + 86400 * 2; break; case 'next_72_hours': $start_date = $epoch; $end_date = $epoch + 86400 * 3; break; case 'next_week': $start_date = TTDate::getBeginWeekEpoch(TTDate::getMiddleDayEpoch($epoch) + 86400 * 7, $start_week_day); $end_date = TTDate::getEndWeekEpoch(TTDate::getMiddleDayEpoch($epoch) + 86400 * 7, $start_week_day); break; case 'next_2_weeks': $start_date = TTDate::getBeginWeekEpoch(TTDate::getMiddleDayEpoch($epoch) + 86400 * 7, $start_week_day); $end_date = TTDate::getEndWeekEpoch(TTDate::getMiddleDayEpoch($epoch) + 86400 * 14, $start_week_day); break; case 'next_7_days': $start_date = TTDate::getBeginDayEpoch(TTDate::getMiddleDayEpoch($epoch) + 86400); $end_date = TTDate::getEndDayEpoch(TTDate::getMiddleDayEpoch($epoch) + 86400 * 7); break; case 'next_14_days': $start_date = TTDate::getBeginDayEpoch(TTDate::getMiddleDayEpoch($epoch) + 86400); $end_date = TTDate::getEndDayEpoch(TTDate::getMiddleDayEpoch($epoch) + 86400 * 14); break; case 'next_month': $start_date = TTDate::getBeginMonthEpoch(TTDate::getEndMonthEpoch($epoch) + 86400); $end_date = TTDate::getEndMonthEpoch(TTDate::getEndMonthEpoch($epoch) + 86400); break; case 'next_2_months': $start_date = TTDate::getBeginMonthEpoch(TTDate::getEndMonthEpoch($epoch) + 86400); $end_date = TTDate::getEndMonthEpoch(TTDate::getEndMonthEpoch($epoch) + 86400 * 32); break; case 'next_30_days': $start_date = TTDate::getBeginDayEpoch(TTDate::getMiddleDayEpoch($epoch) + 86400); $end_date = TTDate::getEndDayEpoch(TTDate::getMiddleDayEpoch($epoch) + 86400 * 30); break; case 'next_45_days': $start_date = TTDate::getBeginDayEpoch(TTDate::getMiddleDayEpoch($epoch) + 86400); $end_date = TTDate::getEndDayEpoch(TTDate::getMiddleDayEpoch($epoch) + 86400 * 45); break; case 'next_60_days': $start_date = TTDate::getBeginDayEpoch(TTDate::getMiddleDayEpoch($epoch) + 86400); $end_date = TTDate::getEndDayEpoch(TTDate::getMiddleDayEpoch($epoch) + 86400 * 60); break; case 'next_quarter': $quarter = TTDate::getYearQuarter($epoch) + 1; if ($quarter == 5) { $quarter = 1; $epoch = TTDate::getEndYearEpoch() + 86400; //Need to jump back into the previous year. } $quarter_dates = TTDate::getYearQuarters($epoch, $quarter); $start_date = $quarter_dates['start']; $end_date = $quarter_dates['end']; break; case 'next_90_days': $start_date = TTDate::getBeginDayEpoch(TTDate::getMiddleDayEpoch($epoch) + 86400); $end_date = TTDate::getEndDayEpoch(TTDate::getMiddleDayEpoch($epoch) + 86400 * 90); break; case 'next_3_months': $start_date = TTDate::getEndDayEpoch(TTDate::getMiddleDayEpoch($epoch) + 86400); $end_date = mktime(0, 0, 0, TTDate::getMonth($start_date) + 3, TTDate::getDayOfMonth($start_date), TTDate::getYear($start_date)); break; case 'next_6_months': $start_date = TTDate::getEndDayEpoch(TTDate::getMiddleDayEpoch($epoch) + 86400); $end_date = mktime(0, 0, 0, TTDate::getMonth($start_date) + 6, TTDate::getDayOfMonth($start_date), TTDate::getYear($start_date)); break; case 'next_9_months': $start_date = TTDate::getEndDayEpoch(TTDate::getMiddleDayEpoch($epoch) + 86400); $end_date = mktime(0, 0, 0, TTDate::getMonth($start_date) + 9, TTDate::getDayOfMonth($start_date), TTDate::getYear($start_date)); break; case 'next_12_months': $start_date = TTDate::getEndDayEpoch(TTDate::getMiddleDayEpoch($epoch) + 86400); $end_date = mktime(0, 0, 0, TTDate::getMonth($start_date) + 12, TTDate::getDayOfMonth($start_date), TTDate::getYear($start_date)); break; case 'next_18_months': $start_date = TTDate::getEndDayEpoch(TTDate::getMiddleDayEpoch($epoch) + 86400); $end_date = mktime(0, 0, 0, TTDate::getMonth($start_date) + 18, TTDate::getDayOfMonth($start_date), TTDate::getYear($start_date)); break; case 'next_24_months': $start_date = TTDate::getEndDayEpoch(TTDate::getMiddleDayEpoch($epoch) + 86400); $end_date = mktime(0, 0, 0, TTDate::getMonth($start_date) + 24, TTDate::getDayOfMonth($start_date), TTDate::getYear($start_date)); break; case 'next_year': $start_date = TTDate::getBeginYearEpoch(TTDate::getEndYearEpoch($epoch) + 86400); $end_date = TTDate::getEndYearEpoch(TTDate::getEndYearEpoch($epoch) + 86400); break; case 'next_2_years': $start_date = TTDate::getEndYearEpoch(TTDate::getEndYearEpoch($epoch) + 86400); $end_date = mktime(0, 0, 0, TTDate::getMonth($start_date), TTDate::getDayOfMonth($start_date), TTDate::getYear($start_date) + 2); break; case 'next_3_years': $start_date = TTDate::getEndYearEpoch(TTDate::getEndYearEpoch($epoch) + 86400); $end_date = mktime(0, 0, 0, TTDate::getMonth($start_date), TTDate::getDayOfMonth($start_date), TTDate::getYear($start_date) + 3); break; case 'next_5_years': $start_date = TTDate::getEndYearEpoch(TTDate::getEndYearEpoch($epoch) + 86400); $end_date = mktime(0, 0, 0, TTDate::getMonth($start_date), TTDate::getDayOfMonth($start_date), TTDate::getYear($start_date) + 5); break; case 'all_years': $start_date = TTDate::getBeginYearEpoch(TTDate::getBeginYearEpoch(31564800) - 86400); $end_date = TTDate::getEndYearEpoch(time() + 86400 * (365 * 2)); break; default: break; } if (isset($start_date) and isset($end_date)) { //Debug::text('Period: '. $time_period .' Start: '. TTDate::getDate('DATE+TIME', $start_date ) .'('.$start_date.') End: '. TTDate::getDate('DATE+TIME', $end_date ) .'('.$end_date.')', __FILE__, __LINE__, __METHOD__,10); return array('start_date' => $start_date, 'end_date' => $end_date); } elseif (isset($pay_period_ids)) { //Debug::text('Period: '. $time_period .' returning just pay_period_ids...', __FILE__, __LINE__, __METHOD__,10); return array('pay_period_id' => $pay_period_ids); } return FALSE; }
function isUniqueName($name) { $ph = array('policy_id' => $this->getHolidayPolicyID(), 'name' => $name, 'start_date1' => $this->db->BindDate(TTDate::getBeginYearEpoch($this->getDateStamp())), 'end_date1' => $this->db->BindDate(TTDate::getEndYearEpoch($this->getDateStamp())), 'start_date2' => $this->db->BindDate($this->getDateStamp() - 86400 * 15), 'end_date2' => $this->db->BindDate($this->getDateStamp() + 86400 * 15)); $query = 'select id from ' . $this->getTable() . ' where holiday_policy_id = ? AND name = ? AND ( ( date_stamp >= ? AND date_stamp <= ? ) OR ( date_stamp >= ? AND date_stamp <= ? ) ) AND deleted=0'; $name_id = $this->db->GetOne($query, $ph); Debug::Arr($name_id, 'Unique Name: ' . $name, __FILE__, __LINE__, __METHOD__, 10); if ($name_id === FALSE) { return TRUE; } else { if ($name_id == $this->getId()) { return TRUE; } } return FALSE; }
function _getData($format = NULL) { $this->tmp_data = array('pay_stub_entry' => array()); $columns = $this->getColumnDataConfig(); $filter_data = $this->getFilterConfig(); $form_data = $this->formatFormConfig(); require_once Environment::getBasePath() . '/classes/payroll_deduction/PayrollDeduction.class.php'; $pd_obj = new PayrollDeduction('US', 'WA'); //State doesn't matter. $pd_obj->setDate($filter_data['end_date']); $social_security_wage_limit = $pd_obj->getSocialSecurityMaximumEarnings(); $medicare_additional_threshold_limit = $pd_obj->getMedicareAdditionalEmployerThreshold(); Debug::Text('Social Security Wage Limit: ' . $social_security_wage_limit . ' Medicare Threshold: ' . $medicare_additional_threshold_limit . ' Date: ' . TTDate::getDate('DATE', $filter_data['end_date']), __FILE__, __LINE__, __METHOD__, 10); //Need to get totals up to the beginning of this quarter so we can determine if any employees have exceeded the social security limit. $pself = TTnew('PayStubEntryListFactory'); $ytd_filter_data = $filter_data; $ytd_filter_data['end_date'] = $ytd_filter_data['start_date'] - 1; $ytd_filter_data['start_date'] = TTDate::getBeginYearEpoch($ytd_filter_data['start_date']); $pself->getAPIReportByCompanyIdAndArrayCriteria($this->getUserObject()->getCompany(), $ytd_filter_data); //Debug::Arr($ytd_filter_data, 'YTD Filter Data: Row Count: '. $pself->getRecordCount(), __FILE__, __LINE__, __METHOD__,10); if ($pself->getRecordCount() > 0) { foreach ($pself as $pse_obj) { $user_id = $pse_obj->getColumn('user_id'); //Make sure we don't add this to the unique user_id list. //Always use middle day epoch, otherwise multiple entries could exist for the same day. $date_stamp = TTDate::getMiddleDayEpoch(TTDate::strtotime($pse_obj->getColumn('pay_stub_transaction_date'))); $branch = $pse_obj->getColumn('default_branch'); $department = $pse_obj->getColumn('default_department'); $pay_stub_entry_name_id = $pse_obj->getPayStubEntryNameId(); if (!isset($this->tmp_data['pay_stub_entry'][$user_id][$date_stamp])) { $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp] = array('pay_period_start_date' => strtotime($pse_obj->getColumn('pay_stub_start_date')), 'pay_period_end_date' => strtotime($pse_obj->getColumn('pay_stub_end_date')), 'pay_period_transaction_date' => strtotime($pse_obj->getColumn('pay_stub_transaction_date')), 'pay_period' => strtotime($pse_obj->getColumn('pay_stub_transaction_date'))); } if (isset($this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['psen_ids'][$pay_stub_entry_name_id])) { $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['psen_ids'][$pay_stub_entry_name_id] = bcadd($this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['psen_ids'][$pay_stub_entry_name_id], $pse_obj->getColumn('amount')); } else { $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['psen_ids'][$pay_stub_entry_name_id] = $pse_obj->getColumn('amount'); } } if (isset($this->tmp_data['pay_stub_entry']) and is_array($this->tmp_data['pay_stub_entry'])) { foreach ($this->tmp_data['pay_stub_entry'] as $user_id => $data_a) { foreach ($data_a as $date_stamp => $data_b) { if (!isset($this->tmp_data['ytd_pay_stub_entry'][$user_id]['social_security_wages'])) { $this->tmp_data['ytd_pay_stub_entry'][$user_id]['social_security_wages'] = 0; } $this->tmp_data['ytd_pay_stub_entry'][$user_id]['social_security_wages'] += Misc::calculateMultipleColumns($data_b['psen_ids'], $form_data['social_security_wages']['include_pay_stub_entry_account'], $form_data['social_security_wages']['exclude_pay_stub_entry_account']); //Include tips in this amount as well. $this->tmp_data['ytd_pay_stub_entry'][$user_id]['social_security_wages'] += Misc::calculateMultipleColumns($data_b['psen_ids'], $form_data['social_security_tips']['include_pay_stub_entry_account'], $form_data['social_security_tips']['exclude_pay_stub_entry_account']); //Handle additional medicare wages in excess of 200,000 if (!isset($this->tmp_data['ytd_pay_stub_entry'][$user_id]['medicare_wages'])) { $this->tmp_data['ytd_pay_stub_entry'][$user_id]['medicare_wages'] = 0; } $this->tmp_data['ytd_pay_stub_entry'][$user_id]['medicare_wages'] += Misc::calculateMultipleColumns($data_b['psen_ids'], $form_data['medicare_wages']['include_pay_stub_entry_account'], $form_data['medicare_wages']['exclude_pay_stub_entry_account']); } } } //Debug::Arr($this->tmp_data['ytd_pay_stub_entry'], 'YTD Tmp Raw Data: ', __FILE__, __LINE__, __METHOD__,10); } unset($pse_obj, $user_id, $date_stamp, $branch, $department, $pay_stub_entry_name_id, $this->tmp_data['pay_stub_entry']); //Get just the data for the quarter now. $pself->getAPIReportByCompanyIdAndArrayCriteria($this->getUserObject()->getCompany(), $filter_data); if ($pself->getRecordCount() > 0) { foreach ($pself as $pse_obj) { $user_id = $this->user_ids[] = $pse_obj->getColumn('user_id'); //Always use middle day epoch, otherwise multiple entries could exist for the same day. $date_stamp = TTDate::getMiddleDayEpoch(TTDate::strtotime($pse_obj->getColumn('pay_stub_transaction_date'))); $branch = $pse_obj->getColumn('default_branch'); $department = $pse_obj->getColumn('default_department'); $pay_stub_entry_name_id = $pse_obj->getPayStubEntryNameId(); if (!isset($this->tmp_data['pay_stub_entry'][$user_id][$date_stamp])) { $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp] = array('pay_period_start_date' => strtotime($pse_obj->getColumn('pay_stub_start_date')), 'pay_period_end_date' => strtotime($pse_obj->getColumn('pay_stub_end_date')), 'pay_period_transaction_date' => strtotime($pse_obj->getColumn('pay_stub_transaction_date')), 'pay_period' => strtotime($pse_obj->getColumn('pay_stub_transaction_date'))); } if (isset($this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['psen_ids'][$pay_stub_entry_name_id])) { $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['psen_ids'][$pay_stub_entry_name_id] = bcadd($this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['psen_ids'][$pay_stub_entry_name_id], $pse_obj->getColumn('amount')); } else { $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['psen_ids'][$pay_stub_entry_name_id] = $pse_obj->getColumn('amount'); } } if (isset($this->tmp_data['pay_stub_entry']) and is_array($this->tmp_data['pay_stub_entry'])) { foreach ($this->tmp_data['pay_stub_entry'] as $user_id => $data_a) { foreach ($data_a as $date_stamp => $data_b) { $quarter_month = TTDate::getYearQuarterMonthNumber($date_stamp); //Debug::Text('Quarter Month: '. $quarter_month .' Epoch: '. TTDate::getDate('DATE', $date_stamp), __FILE__, __LINE__, __METHOD__,10); $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['wages'] = Misc::calculateMultipleColumns($data_b['psen_ids'], $form_data['wages']['include_pay_stub_entry_account'], $form_data['wages']['exclude_pay_stub_entry_account']); $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['income_tax'] = Misc::calculateMultipleColumns($data_b['psen_ids'], $form_data['income_tax']['include_pay_stub_entry_account'], $form_data['income_tax']['exclude_pay_stub_entry_account']); //FIXME: If employees are excluded from Social Security, it will still include total wages //resulting in the 941 form being incorrect in its calculation. //Add Form Setup tab field to select the Social Security tax/deductions? //However there can often be two of them, is just the employee one enough? We could use the employees and include/exclude accounts from that at least then. $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['social_security_wages'] = Misc::calculateMultipleColumns($data_b['psen_ids'], $form_data['social_security_wages']['include_pay_stub_entry_account'], $form_data['social_security_wages']['exclude_pay_stub_entry_account']); //Handle social security wage limit. if (!isset($this->tmp_data['ytd_pay_stub_entry'][$user_id]['social_security_wages'])) { $this->tmp_data['ytd_pay_stub_entry'][$user_id]['social_security_wages'] = 0; } if ($this->tmp_data['ytd_pay_stub_entry'][$user_id]['social_security_wages'] < $social_security_wage_limit) { $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['social_security_wages'] = Misc::calculateMultipleColumns($data_b['psen_ids'], $form_data['social_security_wages']['include_pay_stub_entry_account'], $form_data['social_security_wages']['exclude_pay_stub_entry_account']); $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['social_security_tips'] = Misc::calculateMultipleColumns($data_b['psen_ids'], $form_data['social_security_tips']['include_pay_stub_entry_account'], $form_data['social_security_tips']['exclude_pay_stub_entry_account']); if ($this->tmp_data['ytd_pay_stub_entry'][$user_id]['social_security_wages'] + $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['social_security_wages'] + $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['social_security_tips'] > $social_security_wage_limit) { $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['social_security_wages'] = $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['social_security_wages'] - ($this->tmp_data['ytd_pay_stub_entry'][$user_id]['social_security_wages'] + $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['social_security_wages'] + $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['social_security_tips'] - $social_security_wage_limit); $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['social_security_tips'] = 0; $this->tmp_data['ytd_pay_stub_entry'][$user_id]['social_security_wages'] = $social_security_wage_limit; } else { $this->tmp_data['ytd_pay_stub_entry'][$user_id]['social_security_wages'] += $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['social_security_wages']; $this->tmp_data['ytd_pay_stub_entry'][$user_id]['social_security_wages'] += $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['social_security_tips']; } } else { $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['social_security_wages'] = 0; $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['social_security_tips'] = 0; } $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['medicare_wages'] = Misc::calculateMultipleColumns($data_b['psen_ids'], $form_data['medicare_wages']['include_pay_stub_entry_account'], $form_data['medicare_wages']['exclude_pay_stub_entry_account']); $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['medicare_additional_wages'] = 0; //Handle medicare additional wage limit, only consider wages earned above the threshold to be "medicare_additional_wages" if (!isset($this->tmp_data['ytd_pay_stub_entry'][$user_id]['medicare_wages'])) { $this->tmp_data['ytd_pay_stub_entry'][$user_id]['medicare_wages'] = 0; } if ($this->tmp_data['ytd_pay_stub_entry'][$user_id]['medicare_wages'] > $medicare_additional_threshold_limit) { $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['medicare_additional_wages'] = $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['medicare_wages']; } else { if ($this->tmp_data['ytd_pay_stub_entry'][$user_id]['medicare_wages'] + $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['medicare_wages'] > $medicare_additional_threshold_limit) { $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['medicare_additional_wages'] = $this->tmp_data['ytd_pay_stub_entry'][$user_id]['medicare_wages'] + $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['medicare_wages'] - $medicare_additional_threshold_limit; } else { $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['medicare_additional_wages'] = 0; } } //Debug::Text('User ID: '. $user_id .' DateStamp: '. $date_stamp .' YTD Medicare Additional Wages: '. $this->tmp_data['ytd_pay_stub_entry'][$user_id]['medicare_wages'] .' This Pay Stub: '. $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['medicare_additional_wages'], __FILE__, __LINE__, __METHOD__,10); $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['sick_wages'] = Misc::calculateMultipleColumns($data_b['psen_ids'], $form_data['sick_wages']['include_pay_stub_entry_account'], $form_data['sick_wages']['exclude_pay_stub_entry_account']); $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['eic'] = Misc::calculateMultipleColumns($data_b['psen_ids'], $form_data['eic']['include_pay_stub_entry_account'], $form_data['eic']['exclude_pay_stub_entry_account']); //Separate data used for reporting, grouping, sorting, from data specific used for the Form. if (!isset($this->form_data['pay_period'][$quarter_month][$date_stamp])) { $this->form_data['pay_period'][$quarter_month][$date_stamp] = Misc::preSetArrayValues(array(), array('l2', 'l3', 'l5a', 'l5b', 'l5c', 'l5d', 'l7', 'l9', 'l5a2', 'l5b2', 'l5c2', 'l5d', 'l8', 'l10'), 0); } $this->form_data['pay_period'][$quarter_month][$date_stamp]['l2'] += $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['wages']; $this->form_data['pay_period'][$quarter_month][$date_stamp]['l3'] += $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['income_tax']; $this->form_data['pay_period'][$quarter_month][$date_stamp]['l5a'] += $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['social_security_wages']; $this->form_data['pay_period'][$quarter_month][$date_stamp]['l5b'] += $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['social_security_tips']; $this->form_data['pay_period'][$quarter_month][$date_stamp]['l5c'] += $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['medicare_wages']; $this->form_data['pay_period'][$quarter_month][$date_stamp]['l5d'] += $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['medicare_additional_wages']; //$this->form_data['pay_period'][$quarter_month][$date_stamp]['l9'] += $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['eic']; $this->form_data['pay_period'][$quarter_month][$date_stamp]['l5f'] = 0; //Not implemented currently. //Calculated fields, make sure we don't use += on these. $this->form_data['pay_period'][$quarter_month][$date_stamp]['l5a2'] = bcmul($this->form_data['pay_period'][$quarter_month][$date_stamp]['l5a'], $this->getF941Object()->social_security_rate); $this->form_data['pay_period'][$quarter_month][$date_stamp]['l5b2'] = bcmul($this->form_data['pay_period'][$quarter_month][$date_stamp]['l5b'], $this->getF941Object()->social_security_rate); $this->form_data['pay_period'][$quarter_month][$date_stamp]['l5c2'] = bcmul($this->form_data['pay_period'][$quarter_month][$date_stamp]['l5c'], $this->getF941Object()->medicare_rate); $this->form_data['pay_period'][$quarter_month][$date_stamp]['l5d2'] = bcmul($this->form_data['pay_period'][$quarter_month][$date_stamp]['l5d'], $this->getF941Object()->medicare_additional_rate); $this->form_data['pay_period'][$quarter_month][$date_stamp]['l5e'] = bcadd($this->form_data['pay_period'][$quarter_month][$date_stamp]['l5a2'], bcadd($this->form_data['pay_period'][$quarter_month][$date_stamp]['l5b2'], bcadd($this->form_data['pay_period'][$quarter_month][$date_stamp]['l5c2'], $this->form_data['pay_period'][$quarter_month][$date_stamp]['l5d2']))); $this->form_data['pay_period'][$quarter_month][$date_stamp]['l6'] = bcadd($this->form_data['pay_period'][$quarter_month][$date_stamp]['l3'], bcadd($this->form_data['pay_period'][$quarter_month][$date_stamp]['l5e'], $this->form_data['pay_period'][$quarter_month][$date_stamp]['l5f'])); //Calculate amounts for Schedule B. $this->form_data['pay_period'][$quarter_month][$date_stamp]['l10'] = $this->form_data['pay_period'][$quarter_month][$date_stamp]['l6']; //Add L6 -> L9 if they are implemented later. } } //Total all pay periods by month_id if (isset($this->form_data['pay_period'])) { foreach ($this->form_data['pay_period'] as $month_id => $pp_data) { $this->form_data['quarter'][$month_id] = Misc::ArrayAssocSum($pp_data, NULL, 8); } //Total all quarters. if (isset($this->form_data['quarter'])) { $this->form_data['total'] = Misc::ArrayAssocSum($this->form_data['quarter'], NULL, 6); } } } } $this->user_ids = array_unique($this->user_ids); //Used to get the total number of employees. //Debug::Arr($this->user_ids, 'User IDs: ', __FILE__, __LINE__, __METHOD__,10); Debug::Arr($this->form_data, 'Form Raw Data: ', __FILE__, __LINE__, __METHOD__, 10); //Debug::Arr($this->tmp_data, 'Tmp Raw Data: ', __FILE__, __LINE__, __METHOD__,10); //Get user data for joining. $ulf = TTnew('UserListFactory'); $ulf->getAPISearchByCompanyIdAndArrayCriteria($this->getUserObject()->getCompany(), $filter_data); Debug::Text(' User Total Rows: ' . $ulf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10); $this->getProgressBarObject()->start($this->getAMFMessageID(), $ulf->getRecordCount(), NULL, TTi18n::getText('Retrieving Data...')); foreach ($ulf as $key => $u_obj) { $this->tmp_data['user'][$u_obj->getId()] = (array) $u_obj->getObjectAsArray($this->getColumnDataConfig()); $this->getProgressBarObject()->set($this->getAMFMessageID(), $key); } //Debug::Arr($this->tmp_data['user'], 'User Raw Data: ', __FILE__, __LINE__, __METHOD__,10); return TRUE; }
//Check for default saved report first. $ugdlf->getByUserIdAndScriptAndDefault($current_user->getId(), $_SERVER['SCRIPT_NAME']); if ($ugdlf->getRecordCount() > 0) { Debug::Text('Found Default Report!', __FILE__, __LINE__, __METHOD__, 10); $ugd_obj = $ugdlf->getCurrent(); $filter_data = $ugd_obj->getData(); $generic_data['id'] = $ugd_obj->getId(); } else { Debug::Text('Default Settings!', __FILE__, __LINE__, __METHOD__, 10); //Default selections $filter_data['user_status_ids'] = array(-1); $filter_data['branch_ids'] = array(-1); $filter_data['department_ids'] = array(-1); $filter_data['user_title_ids'] = array(-1); $filter_data['group_ids'] = array(-1); $filter_data['transaction_start_date'] = TTDate::getBeginYearEpoch(); $filter_data['transaction_end_date'] = TTDate::getEndYearEpoch(); } } $ulf = new UserListFactory(); $all_array_option = array('-1' => TTi18n::gettext('-- All --')); //Get include employee list. $ulf->getByCompanyId($current_company->getId()); $user_options = $ulf->getArrayByListFactory($ulf, FALSE, TRUE); $filter_data['src_include_user_options'] = Misc::arrayDiffByKey((array) $filter_data['include_user_ids'], $user_options); $filter_data['selected_include_user_options'] = Misc::arrayIntersectByKey((array) $filter_data['include_user_ids'], $user_options); //Get exclude employee list $exclude_user_options = Misc::prependArray($all_array_option, $ulf->getArrayByListFactory($ulf, FALSE, TRUE)); $filter_data['src_exclude_user_options'] = Misc::arrayDiffByKey((array) $filter_data['exclude_user_ids'], $user_options); $filter_data['selected_exclude_user_options'] = Misc::arrayIntersectByKey((array) $filter_data['exclude_user_ids'], $user_options); //Get employee status list.