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); //
break; case 'recalculate_paystub_ytd': //Debug::setVerbosity(11); Debug::Text('Recalculating Pay Stub YTDs!', __FILE__, __LINE__, __METHOD__, 10); Debug::Text('Pay Stub ID: ' . $pay_stub_ids, __FILE__, __LINE__, __METHOD__, 10); $init_progress_bar = TRUE; //Just need the pay_stub_id of the modified pay stub. $pslf = TTnew('PayStubListFactory'); $pslf->StartTransaction(); if (is_array($pay_stub_ids)) { foreach ($pay_stub_ids as $pay_stub_id) { $pslf->getByIdAndCompanyIdAndIgnoreDeleted($pay_stub_id, $current_company->getId()); if ($pslf->getRecordCount() > 0) { $main_ps_obj = $pslf->getCurrent(); //Get all pay stubs NEWER then this one. $pslf->getByUserIdAndStartDateAndEndDate($main_ps_obj->getUser(), $main_ps_obj->getTransactionDate(), TTDate::getEndYearEpoch($main_ps_obj->getTransactionDate())); $total_pay_stubs = $pslf->getRecordCount(); if ($total_pay_stubs > 0) { if ($init_progress_bar == TRUE) { InitProgressBar(); $init_progress_bar = FALSE; } $progress_bar->setValue(0); $progress_bar->display(); $x = 1; foreach ($pslf as $ps_obj) { Debug::Text('ReCalculating Pay Stub ID: ' . $ps_obj->getId(), __FILE__, __LINE__, __METHOD__, 10); $ps_obj->reCalculatePayStubYTD($ps_obj->getId()); $progress_bar->setValue(Misc::calculatePercent($x, $total_pay_stubs)); $progress_bar->display(); $x++;
function getCurrentPayPeriodNumber($epoch = NULL, $end_date_epoch = NULL) { //EPOCH MUST BE TRANSACTION DATE!!! //End Date Epoch must be END DATE of pay period //Don't return pay period number if its a manual schedule. if ($this->getType() == 5) { return FALSE; } //FIXME: Turn this query in to a straight count(*) query for even more speed. if ($epoch == NULL or $epoch == '') { $epoch = TTDate::getTime(); } //Debug::text('Epoch: '. TTDate::getDate('DATE+TIME',$epoch) .' - End Date Epoch: '. TTDate::getDate('DATE+TIME',$end_date_epoch) , __FILE__, __LINE__, __METHOD__, 10); /* //FIXME: If a company starts with TimeTrex half way through the year, this will be incorrect. //Because it only counts pay periods that exist, not pay periods that WOULD have existed. $pplf = new PayPeriodListFactory(); $pplf->getByPayPeriodScheduleIdAndStartTransactionDateAndEndTransactionDate( $this->getId(), TTDate::getBeginYearEpoch( $epoch ), $epoch ); $retval = $pplf->getRecordCount(); Debug::text('Current Pay Period: '. $retval , __FILE__, __LINE__, __METHOD__, 10); */ //Half Fixed method here. We cache the results so to speed it up, but there still might be a faster way to do this. //FIXME: Perhaps some type of hybrid system like the above unless they have less then a years worth of //pay periods, then use this method below? $id = $this->getId() . $epoch . $end_date_epoch; $retval = $this->getCache($id); if ($retval === FALSE) { //FIXME: I'm sure there is a quicker way to do this. $next_transaction_date = 0; $next_end_date = $end_date_epoch; $end_year_epoch = TTDate::getEndYearEpoch($epoch); $i = 0; while ($next_transaction_date <= $end_year_epoch and $i < 100) { //Debug::text('I: '. $i .' Looping: Transaction Date: '. TTDate::getDate('DATE+TIME',$next_transaction_date) .' - End Year Epoch: '. TTDate::getDate('DATE+TIME',$end_year_epoch) , __FILE__, __LINE__, __METHOD__, 10); $this->getNextPayPeriod($next_end_date); $next_transaction_date = $this->getNextTransactionDate(); $next_end_date = $this->getNextEndDate(); if ($next_transaction_date <= $end_year_epoch) { $i++; } } Debug::text('i: ' . $i, __FILE__, __LINE__, __METHOD__, 10); $retval = $this->getAnnualPayPeriods() - $i; Debug::text('Current Pay Period: ' . $retval, __FILE__, __LINE__, __METHOD__, 10); //Cache results $this->saveCache($retval, $id); } return $retval; }
$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());
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 reCalculateYTD() { //Get all pay stubs NEWER then this one. $pslf = new PayStubListFactory(); $pslf->getByUserIdAndStartDateAndEndDate($this->getUser(), $this->getTransactionDate(), TTDate::getEndYearEpoch($this->getTransactionDate())); $total_pay_stubs = $pslf->getRecordCount(); if ($total_pay_stubs > 0) { $pslf->StartTransaction(); foreach ($pslf as $ps_obj) { $this->reCalculatePayStubYTD($ps_obj->getId()); } $pslf->CommitTransaction(); } else { Debug::Text('No Newer Pay Stubs found!', __FILE__, __LINE__, __METHOD__, 10); } 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 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; }
$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. $user_status_options = Misc::prependArray($all_array_option, $ulf->getOptions('status'));