/**
  * Get default holiday data for creating new holidayes.
  * @return array
  */
 function getHolidayDefaultData()
 {
     $company_obj = $this->getCurrentCompanyObject();
     Debug::Text('Getting holiday default data...', __FILE__, __LINE__, __METHOD__, 10);
     $data = array('company_id' => $company_obj->getId(), 'date_stamp' => TTDate::getAPIDate('DATE', TTDate::getTime()));
     return $this->returnHandler($data);
 }
 /**
  * Get default recurring_schedule_control data for creating new recurring_schedule_controles.
  * @return array
  */
 function getRecurringScheduleControlDefaultData()
 {
     $company_obj = $this->getCurrentCompanyObject();
     Debug::Text('Getting recurring_schedule_control default data...', __FILE__, __LINE__, __METHOD__, 10);
     $data = array('company_id' => $company_obj->getId(), 'start_week' => 1, 'start_date' => TTDate::getAPIDate('DATE', TTDate::getBeginWeekEpoch(TTDate::getTime())), 'end_date' => NULL);
     return $this->returnHandler($data);
 }
Exemple #3
0
    function getData()
    {
        global $cache;
        $country = $this->getCountry();
        $epoch = $this->getDate();
        $federal_status = $this->getFederalFilingStatus();
        if ($federal_status == '') {
            $federal_status = 10;
        }
        if ($epoch == NULL or $epoch == '') {
            $epoch = TTDate::getTime();
        }
        $cache_id = $country . $epoch . $federal_status;
        if (is_string($cache->get($cache_id, $this->table))) {
            $this->income_tax_rates = unserialize($cache->get($cache_id, $this->table));
        } else {
            $this->income_tax_rates = FALSE;
        }
        if ($this->income_tax_rates === FALSE) {
            $query = 'select country,state,district,status,income,rate,constant,effective_date
						from ' . $this->table . '
						where
								(
								effective_date = ( 	select effective_date
													from ' . $this->table . '
													where effective_date <= ' . $epoch . '
														AND country = ' . $this->db->qstr($country) . '
													ORDER BY effective_date DESC
													LIMIT 1)
								)
							AND
							( country = ' . $this->db->qstr($country) . ')
						ORDER BY effective_date desc, income asc, rate asc
					';
            //Debug::text('Query: '. $query , __FILE__, __LINE__, __METHOD__, 10);
            try {
                $rs = $this->db->Execute($query);
            } catch (Exception $e) {
                throw new DBError($e);
            }
            $rs = $rs->GetRows();
            $prev_income = 0;
            $prev_rate = 0;
            $prev_constant = 0;
            foreach ($rs as $key => $arr) {
                $type = 'federal';
                $this->income_tax_rates[$type][] = array('prev_income' => trim($prev_income), 'income' => trim($arr['income']), 'prev_rate' => bcdiv(trim($prev_rate), 100), 'rate' => bcdiv(trim($arr['rate']), 100), 'prev_constant' => trim($prev_constant), 'constant' => trim($arr['constant']));
                $prev_income = $arr['income'];
                $prev_rate = $arr['rate'];
                $prev_constant = $arr['constant'];
            }
            if (isset($arr)) {
                Debug::text('bUsing values from: ' . TTDate::getDate('DATE+TIME', $arr['effective_date']), __FILE__, __LINE__, __METHOD__, 10);
            }
            //var_dump($this->income_tax_rates);
            $cache->save(serialize($this->income_tax_rates), $cache_id, $this->table);
        }
        return $this;
    }
 /**
  * Get all necessary dates for building the TimeSheet in a single call, this is mainly as a performance optimization.
  * @param array $data filter data
  * @return array
  */
 function getTimeSheetDates($base_date)
 {
     $epoch = TTDate::parseDateTime($base_date);
     if ($epoch == '') {
         $epoch = TTDate::getTime();
     }
     $start_date = TTDate::getBeginWeekEpoch($epoch, $this->getCurrentUserPreferenceObject()->getStartWeekDay());
     $end_date = TTDate::getEndWeekEpoch($epoch, $this->getCurrentUserPreferenceObject()->getStartWeekDay());
     $retarr = array('base_date' => $epoch, 'start_date' => $start_date, 'end_date' => $end_date, 'base_display_date' => TTDate::getAPIDate('DATE', $epoch), 'start_display_date' => TTDate::getAPIDate('DATE', $start_date), 'end_display_date' => TTDate::getAPIDate('DATE', $end_date));
     return $retarr;
 }
 /**
  * Get all necessary dates for building the schedule in a single call, this is mainly as a performance optimization.
  * @param array $data filter data
  * @return array
  */
 function getScheduleDates($base_date, $type, $strict = TRUE)
 {
     $epoch = TTDate::parseDateTime($base_date);
     if ($epoch == '') {
         $epoch = TTDate::getTime();
     }
     if ($type == '') {
         $type = 'week';
     }
     switch (strtolower($type)) {
         case 'day':
             if ($strict == TRUE) {
                 $start_date = TTDate::getBeginDayEpoch($epoch);
                 $end_date = TTDate::getEndDayEpoch($epoch);
             } else {
                 $start_date = TTDate::getBeginDayEpoch($epoch);
                 $end_date = TTDate::getBeginDayEpoch(TTDate::getMiddleDayEpoch($epoch) + 86400);
             }
             break;
         case 'week':
             if ($strict == TRUE) {
                 $start_date = TTDate::getBeginWeekEpoch($epoch, $this->getCurrentUserPreferenceObject()->getStartWeekDay());
                 $end_date = TTDate::getEndWeekEpoch($epoch, $this->getCurrentUserPreferenceObject()->getStartWeekDay());
             } else {
                 $start_date = TTDate::getBeginDayEpoch($epoch);
                 $end_date = TTDate::getBeginDayEpoch(TTDate::getMiddleDayEpoch($epoch) + 7 * 86400);
             }
             break;
         case 'month':
             if ($strict == TRUE) {
                 $start_date = TTDate::getBeginWeekEpoch(TTDate::getBeginMonthEpoch($epoch), $this->getCurrentUserPreferenceObject()->getStartWeekDay());
                 $end_date = TTDate::getEndWeekEpoch(TTDate::getEndMonthEpoch($epoch), $this->getCurrentUserPreferenceObject()->getStartWeekDay());
             } else {
                 $start_date = TTDate::getBeginDayEpoch($epoch);
                 $end_date = TTDate::getBeginDayEpoch(TTDate::getMiddleDayEpoch($epoch) + 30 * 86400);
             }
             break;
         case 'year':
             if ($strict == TRUE) {
                 $start_date = TTDate::getBeginWeekEpoch(TTDate::getBeginMonthEpoch($epoch), $this->getCurrentUserPreferenceObject()->getStartWeekDay());
                 $end_date = TTDate::getEndWeekEpoch(TTDate::getEndMonthEpoch(TTDate::getEndMonthEpoch($epoch) + 86400 * 2), $this->getCurrentUserPreferenceObject()->getStartWeekDay());
             } else {
                 $start_date = TTDate::getBeginDayEpoch($epoch);
                 $end_date = TTDate::getBeginDayEpoch(TTDate::getMiddleDayEpoch($epoch) + 62 * 86400);
             }
             break;
     }
     $retarr = array('base_date' => $epoch, 'start_date' => $start_date, 'end_date' => $end_date, 'base_display_date' => TTDate::getAPIDate('DATE', $epoch), 'start_display_date' => TTDate::getAPIDate('DATE', $start_date), 'end_display_date' => TTDate::getAPIDate('DATE', $end_date));
     Debug::Arr($retarr, 'Schedule Dates: Base Date: ' . $base_date . ' Type: ' . $type . ' Strict: ' . (int) $strict, __FILE__, __LINE__, __METHOD__, 10);
     return $retarr;
 }
    static function setCrumb($name, $url = NULL)
    {
        global $db, $current_user;
        //
        // If bread crumbs "seem" like they are getting overwritten, make sure the
        // setCrumb function is being called ONLY in the default section of the switch statement. NOT THE TOP.
        //
        if ($url == '') {
            $url = $_SERVER['REQUEST_URI'];
        }
        if (!is_object($current_user)) {
            return FALSE;
        }
        Debug::text('Dropping Bread Crumb: ' . $name . ' URL: ' . $url, __FILE__, __LINE__, __METHOD__, 10);
        $ph = array('user_id' => $current_user->getId(), 'name' => $name);
        //Determine if we should update or insert bread crumb.
        $query = 'select name
					FROM bread_crumb
					WHERE user_id = ?
						AND name = ?
					LIMIT 1';
        try {
            $rs = $db->Execute($query, $ph);
        } catch (Exception $e) {
            throw new DBError($e);
        }
        if ($rs->RecordCount() == 1) {
            $ph = array('url' => $url, 'created_date' => TTDate::getTime(), 'user_id' => $current_user->getId(), 'name' => $name);
            $query = 'UPDATE bread_crumb
						SET		url = ?,
								created_date = ?
						WHERE	user_id = ?
							AND name = ?';
        } else {
            $ph = array('user_id' => $current_user->getId(), 'name' => $name, 'url' => $url, 'created_date' => TTDate::getTime());
            $query = 'insert into bread_crumb (user_id,name,url,created_date)
							VALUES(
									?,
									?,
									?,
									?
								)';
        }
        try {
            $db->Execute($query, $ph);
        } catch (Exception $e) {
            throw new DBError($e);
        }
        return TRUE;
    }
         $psaf->FailTransaction();
     }
 default:
     BreadCrumb::setCrumb($title);
     if (isset($id)) {
         $psalf = TTnew('PayStubAmendmentListFactory');
         //$uwlf->GetByUserIdAndCompanyId($current_user->getId(), $current_company->getId() );
         $psalf->GetById($id);
         foreach ($psalf as $pay_stub_amendment) {
             //Debug::Arr($station,'Department', __FILE__, __LINE__, __METHOD__,10);
             $user_id = $pay_stub_amendment->getUser();
             $pay_stub_amendment_data = array('id' => $pay_stub_amendment->getId(), 'filter_user_id' => $pay_stub_amendment->getUser(), 'pay_stub_entry_name_id' => $pay_stub_amendment->getPayStubEntryNameId(), 'status_id' => $pay_stub_amendment->getStatus(), 'effective_date' => $pay_stub_amendment->getEffectiveDate(), 'type_id' => $pay_stub_amendment->getType(), 'rate' => $pay_stub_amendment->getRate(), 'units' => $pay_stub_amendment->getUnits(), 'amount' => $pay_stub_amendment->getAmount(), 'percent_amount' => $pay_stub_amendment->getPercentAmount(), 'percent_amount_entry_name_id' => $pay_stub_amendment->getPercentAmountEntryNameId(), 'description' => $pay_stub_amendment->getDescription(), 'private_description' => $pay_stub_amendment->getPrivateDescription(), 'authorized' => $pay_stub_amendment->getAuthorized(), 'ytd_adjustment' => $pay_stub_amendment->getYTDAdjustment(), 'created_date' => $pay_stub_amendment->getCreatedDate(), 'created_by' => $pay_stub_amendment->getCreatedBy(), 'updated_date' => $pay_stub_amendment->getUpdatedDate(), 'updated_by' => $pay_stub_amendment->getUpdatedBy(), 'deleted_date' => $pay_stub_amendment->getDeletedDate(), 'deleted_by' => $pay_stub_amendment->getDeletedBy());
         }
     } else {
         if ($pay_stub_amendment_data['effective_date'] == '') {
             $pay_stub_amendment_data['effective_date'] = TTDate::getTime();
             $pay_stub_amendment_data['user_id'] = $user_id;
         }
     }
     //Select box options;
     $status_options_filter = array(50);
     if (isset($pay_stub_amendment) and $pay_stub_amendment->getStatus() == 55) {
         $status_options_filter = array(55);
     } elseif (isset($pay_stub_amendment) and $pay_stub_amendment->getStatus() == 52) {
         $status_options_filter = array(52);
     }
     if (!isset($pay_stub_amendment_data['filter_user_id'])) {
         $pay_stub_amendment_data['filter_user_id'] = array();
     }
     $ulf = TTnew('UserListFactory');
     $ulf->getSearchByCompanyIdAndArrayCriteria($current_company->getId(), NULL);
Exemple #8
0
 * $Revision: 8337 $
 * $Id: cron.php 8337 2012-11-20 04:40:27Z ipso $
 * $Date: 2012-11-19 20:40:27 -0800 (Mon, 19 Nov 2012) $
 */
/*
 * Cron replica
 * Run this script every minute from the real cron.
 *
 */
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'global.inc.php';
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'CLI.inc.php';
if (isset($config_vars['other']['installer_enabled']) and $config_vars['other']['installer_enabled'] == TRUE) {
    Debug::text('CRON: Installer is enabled, skipping cron jobs for now...', __FILE__, __LINE__, __METHOD__, 0);
} else {
    //$current_epoch = strtotime('28-Mar-08 1:30 PM');
    $current_epoch = TTDate::getTime();
    $executed_jobs = 0;
    $cjlf = new CronJobListFactory();
    $job_arr = $cjlf->getArrayByListFactory($cjlf->getAll());
    $total_jobs = count($job_arr);
    foreach ($job_arr as $job_id => $job_name) {
        //Get each cronjob row again individually incase the status has changed.
        $cjlf = new CronJobListFactory();
        $cjlf->getById($job_id);
        //Let Execute determine if job is running or not so it can find orphans.
        if ($cjlf->getRecordCount() > 0) {
            foreach ($cjlf as $cjf_obj) {
                //Debug::text('Checking if Job ID: '. $job_id .' is scheduled to run...', __FILE__, __LINE__, __METHOD__, 0);
                if ($cjf_obj->isScheduledToRun($current_epoch) == TRUE) {
                    $executed_jobs++;
                    $cjf_obj->Execute($config_vars['path']['php_cli'], dirname(__FILE__));
 function createPayStubAmendments($epoch = NULL)
 {
     //Get all recurring pay stub amendments and generate single pay stub amendments if appropriate.
     if ($epoch == '') {
         $epoch = TTDate::getTime();
     }
     $ulf = TTnew('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 = TTnew('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. Start Date: ' . TTDate::getDate('DATE+TIME', $pay_period_obj->getStartDate()) . ' End Date: ' . TTDate::getDate('DATE+TIME', $pay_period_obj->getEndDate()), __FILE__, __LINE__, __METHOD__, 10);
                         $psalf = TTnew('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: '******'PayStubAmendmentFactory');
                                     $psaf->setUser($user_id);
                                     $psaf->setStatus(50);
                                     $psaf->setType($this->getType());
                                     $psaf->setRecurringPayStubAmendmentId($this->getId());
                                     $psaf->setPayStubEntryNameId($this->getPayStubEntryNameId());
                                     if ($this->getType() == 10) {
                                         $psaf->setRate($this->getRate());
                                         $psaf->setUnits($this->getUnits());
                                         $psaf->setAmount($this->getAmount());
                                     } else {
                                         $psaf->setPercentAmount($this->getPercentAmount());
                                         $psaf->setPercentAmountEntryNameID($this->getPercentAmountEntryNameId());
                                     }
                                     $psaf->setDescription($this->getPayStubAmendmentDescription());
                                     $psaf->setEffectiveDate(TTDate::getBeginDayEpoch($pay_period_obj->getEndDate()));
                                     if ($psaf->isValid()) {
                                         $psaf->Save();
                                     }
                                 } else {
                                     //Amendment already inserted!
                                     Debug::text('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(), $epoch);
                         //$start_date = TTDate::getBeginYearEpoch($epoch);
                         //$end_date = TTDate::getEndYearEpoch($epoch);
                         $start_date = TTDate::getBeginDayEpoch($epoch - 86400 * 365);
                         $end_date = TTDate::getEndDayEpoch($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('Within timeframe... Start Date: ' . TTDate::getDate('DATE+TIME', $start_date) . ' End Date: ' . TTDate::getDate('DATE+TIME', $end_date), __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 = TTnew('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: '******'PayStubAmendmentFactory');
                             $psaf->setUser($user_id);
                             $psaf->setStatus(50);
                             $psaf->setType($this->getType());
                             $psaf->setRecurringPayStubAmendmentId($this->getId());
                             $psaf->setPayStubEntryNameId($this->getPayStubEntryNameId());
                             if ($this->getType() == 10) {
                                 $psaf->setRate($this->getRate());
                                 $psaf->setUnits($this->getUnits());
                                 $psaf->setAmount($this->getAmount());
                             } else {
                                 $psaf->setPercentAmount($this->getPercentAmount());
                                 $psaf->setPercentAmountEntryNameID($this->getPercentAmountEntryNameId());
                             }
                             $psaf->setDescription($this->getDescription());
                             $psaf->setEffectiveDate(TTDate::getBeginDayEpoch($trigger_date));
                             if ($psaf->isValid()) {
                                 $psaf->Save();
                             }
                         } else {
                             //Amendment already inserted!
                             Debug::text('Recurring PS Amendment already inserted for User: ' . $user_id, __FILE__, __LINE__, __METHOD__, 10);
                         }
                     }
                 }
                 break;
         }
     }
     //$this->FailTransaction();
     $this->CommitTransaction();
     return TRUE;
 }
 function calculateLastDate($user_id)
 {
     $plf = TTnew('PunchListFactory');
     $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);
     return $last_date;
 }
    }
    if ($permission->Check('schedule', 'view_own')) {
        $permission_children_ids[] = $current_user->getId();
    }
    $filter_data['permission_children_ids'] = $permission_children_ids;
}
$do = Misc::findSubmitButton('do');
switch ($do) {
    case 'view_schedule':
    default:
        $user_ids = array();
        if ($filter_data['start_date'] != '' and $filter_data['show_days'] != '') {
            $start_date = $filter_data['start_date'] = TTDate::getBeginDayEpoch(TTDate::parseDateTime($filter_data['start_date']));
            $end_date = $filter_data['end_date'] = $start_date + ($filter_data['show_days'] * 86400 - 3601);
        } else {
            $start_date = $filter_data['start_date'] = TTDate::getBeginWeekEpoch(TTDate::getTime(), $current_user_prefs->getStartWeekDay());
            $end_date = $filter_data['end_date'] = $start_date + $filter_data['show_days'] * (86400 - 3601);
        }
        Debug::text(' Start Date: ' . TTDate::getDate('DATE+TIME', $start_date) . ' End Date: ' . TTDate::getDate('DATE+TIME', $end_date), __FILE__, __LINE__, __METHOD__, 10);
        $sf = TTnew('ScheduleFactory');
        $raw_schedule_shifts = $sf->getScheduleArray($filter_data);
        if (is_array($raw_schedule_shifts)) {
            foreach ($raw_schedule_shifts as $day_epoch => $day_schedule_shifts) {
                foreach ($day_schedule_shifts as $day_schedule_shift) {
                    $user_ids[] = $day_schedule_shift['user_id'];
                    $day_schedule_shift['is_owner'] = $permission->isOwner($day_schedule_shift['user_created_by'], $day_schedule_shift['user_id']);
                    $day_schedule_shift['is_child'] = $permission->isChild($day_schedule_shift['user_id'], $permission_children_ids);
                    $tmp_schedule_shifts[$day_epoch][$day_schedule_shift['branch']][$day_schedule_shift['department']][] = $day_schedule_shift;
                    if ($day_schedule_shift['status_id'] == 10) {
                        //Working
                        if (isset($schedule_shift_totals[$day_epoch]['total_time'])) {
Exemple #12
0
 //Debug::setVerbosity(11);
 Debug::Text('Generate Pay Stubs!', __FILE__, __LINE__, __METHOD__, 10);
 if (!$permission->Check('pay_period_schedule', 'enabled') or !($permission->Check('pay_period_schedule', 'edit') or $permission->Check('pay_period_schedule', 'edit_own'))) {
     $permission->Redirect(FALSE);
     //Redirect
 }
 if (!is_array($pay_period_ids)) {
     $pay_period_ids = array($pay_period_ids);
 }
 TTLog::addEntry($current_company->getId(), 500, TTi18n::gettext('Recalculating Company Pay Stubs for Pay Periods:') . ' ' . implode(',', $pay_period_ids), $current_user->getId(), 'pay_stub');
 $init_progress_bar = TRUE;
 foreach ($pay_period_ids as $pay_period_id) {
     Debug::text('Pay Period ID: ' . $pay_period_id, __FILE__, __LINE__, __METHOD__, 10);
     $pplf = TTnew('PayPeriodListFactory');
     $pplf->getByIdAndCompanyId($pay_period_id, $current_company->getId());
     $epoch = TTDate::getTime();
     foreach ($pplf as $pay_period_obj) {
         Debug::text('Pay Period Schedule ID: ' . $pay_period_obj->getPayPeriodSchedule(), __FILE__, __LINE__, __METHOD__, 10);
         if ($pay_period_obj->isPreviousPayPeriodClosed() == TRUE) {
             //Grab all users for pay period
             $ppsulf = TTnew('PayPeriodScheduleUserListFactory');
             $ppsulf->getByPayPeriodScheduleId($pay_period_obj->getPayPeriodSchedule());
             $total_pay_stubs = $ppsulf->getRecordCount();
             //echo "Total Pay Stubs: $total_pay_stubs - ". ceil(100 / $total_pay_stubs) ."<Br>\n";
             if ($init_progress_bar == TRUE) {
                 //InitProgressBar( ceil(100 / $total_pay_stubs) );
                 InitProgressBar();
                 $init_progress_bar = FALSE;
             }
             $progress_bar->setValue(0);
             $progress_bar->display();
    function getPayPeriodReportByUserIdAndEntryNameIdAndStartDateAndEndDate($id, $entry_name_id, $start_date = NULL, $end_date = NULL, $exclude_id = NULL, $where = NULL, $order = NULL)
    {
        if ($id == '') {
            return FALSE;
        }
        if ($entry_name_id == '') {
            return FALSE;
        }
        if ($start_date == '') {
            $start_date = 0;
        }
        if ($end_date == '') {
            $end_date = TTDate::getTime();
        }
        $ppf = new PayPeriodFactory();
        $ppsuf = new PayPeriodScheduleUserFactory();
        $psf = new PayStubFactory();
        $uf = new UserFactory();
        $ph = array('start_date' => $this->db->BindTimeStamp($start_date), 'end_date' => $this->db->BindTimeStamp($end_date), 'user_id' => $id, 'exclude_id' => (int) $exclude_id);
        //Include pay periods with no pay stubs for ROEs.
        $query = '
					select 	x.id as pay_period_id,
							y.id as user_id,
							x.start_date as pay_period_start_date,
							x.end_date as pay_period_end_date,
							x.transaction_date as pay_period_transaction_date,
							tmp.amount as amount,
							tmp.units as units
					from 	' . $ppf->getTable() . ' x
						LEFT JOIN ' . $uf->getTable() . ' as y ON x.company_id = y.company_id
						LEFT JOIN 	(
										select 	b.user_id as user_id,
												b.pay_period_id as pay_period_id,
												sum(amount) as amount,
												sum(units) as units
										from	' . $this->getTable() . ' as a,
												' . $psf->getTable() . ' as b,
												' . $ppf->getTable() . ' as c
										where	a.pay_stub_id = b.id
											AND b.pay_period_id = c.id
											AND c.start_date >= ?
											AND c.start_date < ?
											AND b.user_id = ?
											AND a.id != ?
											AND	a.pay_stub_entry_name_id in (' . $this->getListSQL($entry_name_id, $ph) . ')
											AND ( a.deleted = 0 AND b.deleted = 0 AND c.deleted = 0 )
										group by b.user_id,b.pay_period_id
									) as tmp ON y.id = tmp.user_id AND x.id = tmp.pay_period_id ';
        $ph[] = $id;
        $ph[] = $this->db->BindTimeStamp($start_date);
        $ph[] = $this->db->BindTimeStamp($end_date);
        $query .= '
					where y.id = ?
						AND x.start_date >= ?
						AND x.start_date < ?
						AND x.deleted = 0
				';
        $query .= $this->getWhereSQL($where);
        $query .= $this->getSortSQL($order, FALSE);
        Debug::Text('Query: ' . $query, __FILE__, __LINE__, __METHOD__, 10);
        $query .= $this->getWhereSQL($where);
        $query .= $this->getSortSQL($order);
        $this->rs = $this->db->Execute($query, $ph);
        return $this;
    }
 static function releaseAllAccruals($user_id, $effective_date = NULL)
 {
     Debug::Text('Release 100% of all accruals!', __FILE__, __LINE__, __METHOD__, 10);
     if ($user_id == '') {
         return FALSE;
     }
     if ($effective_date == '') {
         $effective_date = TTDate::getTime();
     }
     Debug::Text('Effective Date: ' . TTDate::getDate('DATE+TIME', $effective_date), __FILE__, __LINE__, __METHOD__, 10);
     $ulf = new UserListFactory();
     $ulf->getById($user_id);
     if ($ulf->getRecordCount() > 0) {
         $user_obj = $ulf->getCurrent();
     } else {
         return FALSE;
     }
     //Get all PSE acccount accruals
     $psealf = new PayStubEntryAccountListFactory();
     $psealf->getByCompanyIdAndStatusIdAndTypeId($user_obj->getCompany(), 10, 50);
     if ($psealf->getRecordCount() > 0) {
         $ulf->StartTransaction();
         foreach ($psealf as $psea_obj) {
             //Get PSE account that affects this accrual.
             $psealf_tmp = new PayStubEntryAccountListFactory();
             $psealf_tmp->getByCompanyIdAndAccrualId($user_obj->getCompany(), $psea_obj->getId());
             if ($psealf_tmp->getRecordCount() > 0) {
                 $release_account_id = $psealf_tmp->getCurrent()->getId();
                 $psaf = new PayStubAmendmentFactory();
                 $psaf->setStatus(50);
                 //Active
                 $psaf->setType(20);
                 //Percent
                 $psaf->setUser($user_obj->getId());
                 $psaf->setPayStubEntryNameId($release_account_id);
                 $psaf->setPercentAmount(100);
                 $psaf->setPercentAmountEntryNameId($psea_obj->getId());
                 $psaf->setEffectiveDate($effective_date);
                 $psaf->setDescription('Release Accrual Balance');
                 if ($psaf->isValid()) {
                     Debug::Text('Release Accrual Is Valid!!: ', __FILE__, __LINE__, __METHOD__, 10);
                     $psaf->Save();
                 }
             } else {
                 Debug::Text('No Release Account for this Accrual!!', __FILE__, __LINE__, __METHOD__, 10);
             }
         }
         //$ulf->FailTransaction();
         $ulf->CommitTransaction();
     } else {
         Debug::Text('No Accruals to release...', __FILE__, __LINE__, __METHOD__, 10);
     }
     return FALSE;
 }
 function _outputPDFForm($format = NULL)
 {
     $show_background = TRUE;
     if ($format == 'pdf_form_print' or $format == 'pdf_form_print_government' or $format == 'efile') {
         $show_background = FALSE;
     }
     Debug::Text('Generating Form... Format: ' . $format, __FILE__, __LINE__, __METHOD__, 10);
     $setup_data = $this->getFormConfig();
     $filter_data = $this->getFilterConfig();
     //Debug::Arr($filter_data, 'Filter Data: ', __FILE__, __LINE__, __METHOD__,10);
     $current_company = $this->getUserObject()->getCompanyObject();
     if (!is_object($current_company)) {
         Debug::Text('Invalid company object...', __FILE__, __LINE__, __METHOD__, 10);
         return FALSE;
     }
     $current_user = $this->getUserObject();
     if (!is_object($current_user)) {
         Debug::Text('Invalid user object...', __FILE__, __LINE__, __METHOD__, 10);
         return FALSE;
     }
     if ($format == 'efile_xml') {
         $return1040 = $this->getRETURN1040Object();
         // Ceate the all needed data for Return1040.xsd at here.
         $return1040->return_created_timestamp = TTDate::getDBTimeStamp(TTDate::getTime(), FALSE);
         $return1040->year = TTDate::getYear($filter_data['end_date']);
         $return1040->tax_period_begin_date = TTDate::getDate('Y-m-d', TTDate::getBeginDayEpoch($filter_data['start_date']));
         $return1040->tax_period_end__date = TTDate::getDate('Y-m-d', TTDate::getEndDayEpoch($filter_data['end_date']));
         $return1040->software_id = '';
         $return1040->originator_efin = '';
         $return1040->originator_type_code = '';
         $return1040->pin_type_code = '';
         $return1040->jurat_disclosure_code = '';
         $return1040->pin_entered_by = '';
         $return1040->signature_date = TTDate::getDate('Y-m-d', TTDate::getTime());
         $return1040->return_type = '';
         $return1040->ssn = '';
         $return1040->name = (isset($setup_data['company_name']) and $setup_data['company_name'] != '') ? $setup_data['company_name'] : $current_company->getName();
         $return1040->name_control = '';
         $return1040->address1 = (isset($setup_data['address1']) and $setup_data['address1'] != '') ? $setup_data['address1'] : $current_company->getAddress1() . ' ' . $current_company->getAddress2();
         $return1040->city = (isset($setup_data['city']) and $setup_data['city'] != '') ? $setup_data['city'] : $current_company->getCity();
         $return1040->state = (isset($setup_data['province']) and ($setup_data['province'] != '' and $setup_data['province'] != 0)) ? $setup_data['province'] : $current_company->getProvince();
         $return1040->zip_code = (isset($setup_data['postal_code']) and $setup_data['postal_code'] != '') ? $setup_data['postal_code'] : $current_company->getPostalCode();
         $return1040->ip_address = '';
         $return1040->ip_date = TTDate::getDate('Y-m-d', TTDate::getTime());
         $return1040->ip_time = TTDate::getDate('H:i:s', TTDate::getTime());
         $return1040->timezone = TTDate::getTimeZone();
         $this->getFormObject()->addForm($return1040);
     }
     $this->sortFormData();
     //Make sure forms are sorted.
     $fw2 = $this->getFW2Object();
     $fw2->setDebug(FALSE);
     //if ( $format == 'efile' ) {
     //	$fw2->setDebug(TRUE);
     //}
     $fw2->setShowBackground($show_background);
     if (stristr($format, 'government')) {
         $form_type = 'government';
     } else {
         $form_type = 'employee';
     }
     Debug::Text('Form Type: ' . $form_type, __FILE__, __LINE__, __METHOD__, 10);
     $fw2->setType($form_type);
     $fw2->year = TTDate::getYear($filter_data['end_date']);
     //Add support for the user to manually set this data in the setup_data. That way they can use multiple tax IDs for different employees, all beit manually.
     $fw2->ein = (isset($setup_data['ein']) and $setup_data['ein'] != '') ? $setup_data['ein'] : $current_company->getBusinessNumber();
     $fw2->name = (isset($setup_data['name']) and $setup_data['name'] != '') ? $setup_data['name'] : $this->getUserObject()->getFullName();
     $fw2->trade_name = (isset($setup_data['company_name']) and $setup_data['company_name'] != '') ? $setup_data['company_name'] : $current_company->getName();
     $fw2->company_address1 = (isset($setup_data['address1']) and $setup_data['address1'] != '') ? $setup_data['address1'] : $current_company->getAddress1() . ' ' . $current_company->getAddress2();
     $fw2->company_city = (isset($setup_data['city']) and $setup_data['city'] != '') ? $setup_data['city'] : $current_company->getCity();
     $fw2->company_state = (isset($setup_data['province']) and ($setup_data['province'] != '' and $setup_data['province'] != 0)) ? $setup_data['province'] : $current_company->getProvince();
     $fw2->company_zip_code = (isset($setup_data['postal_code']) and $setup_data['postal_code'] != '') ? $setup_data['postal_code'] : $current_company->getPostalCode();
     $fw2->efile_user_id = (isset($setup_data['efile_user_id']) and $setup_data['efile_user_id'] != '') ? $setup_data['efile_user_id'] : NULL;
     $fw2->efile_state = (isset($setup_data['efile_state']) and $setup_data['efile_state'] != '') ? $setup_data['efile_state'] : 0;
     $fw2->contact_name = $current_user->getFullName();
     $fw2->contact_phone = $current_user->getWorkPhone();
     $fw2->contact_phone_ext = $current_user->getWorkPhoneExt();
     $fw2->contact_email = $current_user->getWorkEmail();
     if (isset($this->form_data) and count($this->form_data) > 0) {
         $i = 0;
         $n = 1;
         foreach ((array) $this->form_data as $row) {
             if (!isset($row['user_id'])) {
                 Debug::Text('User ID not set!', __FILE__, __LINE__, __METHOD__, 10);
                 continue;
             }
             $ulf = TTnew('UserListFactory');
             $ulf->getById((int) $row['user_id']);
             if ($ulf->getRecordCount() == 1) {
                 $user_obj = $ulf->getCurrent();
                 $ee_data = array('control_number' => $n, 'first_name' => $user_obj->getFirstName(), 'middle_name' => $user_obj->getMiddleName(), 'last_name' => $user_obj->getLastName(), 'address1' => $user_obj->getAddress1(), 'address2' => $user_obj->getAddress2(), 'city' => $user_obj->getCity(), 'state' => $user_obj->getProvince(), 'employment_province' => $user_obj->getProvince(), 'zip_code' => $user_obj->getPostalCode(), 'ssn' => $user_obj->getSIN(), 'employee_number' => $user_obj->getEmployeeNumber(), 'l1' => $row['l1'], 'l2' => $row['l2'], 'l3' => $row['l3'], 'l4' => $row['l4'], 'l5' => $row['l5'], 'l6' => $row['l6'], 'l7' => $row['l7'], 'l8' => $row['l8'], 'l10' => $row['l10'], 'l11' => $row['l11'], 'l12a_code' => NULL, 'l12a' => NULL, 'l12b_code' => NULL, 'l12b' => NULL, 'l12c_code' => NULL, 'l12c' => NULL, 'l12d_code' => NULL, 'l12d' => NULL, 'l14a_name' => NULL, 'l14a' => NULL, 'l14b_name' => NULL, 'l14b' => NULL, 'l14c_name' => NULL, 'l14c' => NULL, 'l14d_name' => NULL, 'l14d' => NULL);
                 if ($row['l12a'] > 0 and isset($setup_data['l12a_code']) and $setup_data['l12a_code'] != '') {
                     $ee_data['l12a_code'] = $setup_data['l12a_code'];
                     $ee_data['l12a'] = $row['l12a'];
                 }
                 if ($row['l12b'] > 0 and isset($setup_data['l12b_code']) and $setup_data['l12b_code'] != '') {
                     $ee_data['l12b_code'] = $setup_data['l12b_code'];
                     $ee_data['l12b'] = $row['l12b'];
                 }
                 if ($row['l12c'] > 0 and isset($setup_data['l12c_code']) and $setup_data['l12c_code'] != '') {
                     $ee_data['l12c_code'] = $setup_data['l12c_code'];
                     $ee_data['l12c'] = $row['l12c'];
                 }
                 if ($row['l12d'] > 0 and isset($setup_data['l12d_code']) and $setup_data['l12d_code'] != '') {
                     $ee_data['l12d_code'] = $setup_data['l12d_code'];
                     $ee_data['l12d'] = $row['l12d'];
                 }
                 if ($row['l14a'] > 0 and isset($setup_data['l14a_name']) and $setup_data['l14a_name'] != '') {
                     $ee_data['l14a_name'] = $setup_data['l14a_name'];
                     $ee_data['l14a'] = $row['l14a'];
                 }
                 if ($row['l14b'] > 0 and isset($setup_data['l14b_name']) and $setup_data['l14b_name'] != '') {
                     $ee_data['l14b_name'] = $setup_data['l14b_name'];
                     $ee_data['l14b'] = $row['l14b'];
                 }
                 if ($row['l14c'] > 0 and isset($setup_data['l14c_name']) and $setup_data['l14c_name'] != '') {
                     $ee_data['l14c_name'] = $setup_data['l14c_name'];
                     $ee_data['l14c'] = $row['l14c'];
                 }
                 if ($row['l14d'] > 0 and isset($setup_data['l14d_name']) and $setup_data['l14d_name'] != '') {
                     $ee_data['l14d_name'] = $setup_data['l14d_name'];
                     $ee_data['l14d'] = $row['l14d'];
                 }
                 foreach (range('a', 'z') as $z) {
                     //State income tax
                     if (isset($row['l16' . $z])) {
                         if (isset($setup_data['state'][$row['l15' . $z . '_state']])) {
                             $ee_data['l15' . $z . '_state_id'] = $setup_data['state'][$row['l15' . $z . '_state']]['state_id'];
                         }
                         $ee_data['l15' . $z . '_state'] = $row['l15' . $z . '_state'];
                         $ee_data['l16' . $z] = $row['l16' . $z];
                         $ee_data['l17' . $z] = $row['l17' . $z];
                     } else {
                         $ee_data['l15' . $z . '_state_id'] = NULL;
                         $ee_data['l15' . $z . '_state'] = NULL;
                         $ee_data['l16' . $z] = NULL;
                         $ee_data['l17' . $z] = NULL;
                     }
                     //District income tax
                     if (isset($row['l18' . $z])) {
                         $ee_data['l18' . $z] = $row['l18' . $z];
                         $ee_data['l19' . $z] = $row['l19' . $z];
                         $ee_data['l20' . $z] = $row['l20' . $z];
                     } else {
                         $ee_data['l18' . $z] = NULL;
                         $ee_data['l19' . $z] = NULL;
                         $ee_data['l20' . $z] = NULL;
                     }
                 }
                 $fw2->addRecord($ee_data);
                 unset($ee_data);
                 $i++;
                 $n++;
             }
         }
     }
     $this->getFormObject()->addForm($fw2);
     if ($form_type == 'government') {
         //Handle W3
         $fw3 = $this->getFW3Object();
         $fw3->setShowBackground($show_background);
         $fw3->year = $fw2->year;
         $fw3->ein = $fw2->ein;
         $fw3->name = $fw2->name;
         $fw3->trade_name = $fw2->trade_name;
         $fw3->company_address1 = $fw2->company_address1;
         $fw3->company_address2 = $fw2->company_address2;
         $fw3->company_city = $fw2->company_city;
         $fw3->company_state = $fw2->company_state;
         $fw3->company_zip_code = $fw2->company_zip_code;
         $fw3->contact_name = $current_user->getFullName();
         $fw3->contact_phone = $current_user->getWorkPhoneExt() != '' ? $current_user->getWorkPhone() . 'x' . $current_user->getWorkPhoneExt() : $current_user->getWorkPhone();
         $fw3->contact_email = $current_user->getWorkEmail();
         $fw3->kind_of_payer = '941';
         $fw3->kind_of_employer = 'none';
         //$fw3->third_party_sick_pay = TRUE;
         if (isset($setup_data['state'][$fw2->company_state]) and isset($setup_data['state'][$fw2->company_state]['state_id']) and $setup_data['state'][$fw2->company_state]['state_id'] != '') {
             $fw3->state_id1 = $setup_data['state'][$fw2->company_state]['state_id'];
         }
         $fw3->lc = count($this->form_data);
         $fw3->control_number = $fw3->lc + 1;
         //$fw3->ld = '1234568';
         $total_row = Misc::ArrayAssocSum($this->form_data);
         //Debug::Arr($total_row, 'Total Row Data: ', __FILE__, __LINE__, __METHOD__,10);
         if (is_array($total_row)) {
             $fw3->l1 = $total_row['l1'];
             $fw3->l2 = $total_row['l2'];
             $fw3->l3 = $total_row['l3'];
             $fw3->l4 = $total_row['l4'];
             $fw3->l5 = $total_row['l5'];
             $fw3->l6 = $total_row['l6'];
             $fw3->l7 = $total_row['l7'];
             $fw3->l8 = $total_row['l8'];
             $fw3->l10 = $total_row['l10'];
             $fw3->l11 = $total_row['l11'];
             foreach (range('a', 'z') as $z) {
                 //State income tax
                 if (isset($total_row['l16' . $z])) {
                     $fw3->l16 += $total_row['l16' . $z];
                     $fw3->l17 += $total_row['l17' . $z];
                 }
                 //District income tax
                 if (isset($total_row['l18' . $z])) {
                     $fw3->l18 += $total_row['l18' . $z];
                     $fw3->l19 += $total_row['l19' . $z];
                 }
             }
         }
         $this->getFormObject()->addForm($fw3);
     }
     if ($format == 'efile') {
         $output_format = 'EFILE';
         if ($fw2->getDebug() == TRUE) {
             $file_name = 'w2_efile_' . date('Y_m_d') . '.csv';
         } else {
             $file_name = 'w2_efile_' . date('Y_m_d') . '.txt';
         }
         $mime_type = 'applications/octet-stream';
         //Force file to download.
     } elseif ($format == 'efile_xml') {
         $output_format = 'XML';
         $file_name = 'w2_efile_' . date('Y_m_d') . '.xml';
         $mime_type = 'applications/octet-stream';
         //Force file to download.
     } else {
         $output_format = 'PDF';
         $file_name = $this->file_name;
         $mime_type = $this->file_mime_type;
     }
     $output = $this->getFormObject()->output($output_format);
     return array('file_name' => $file_name, 'mime_type' => $mime_type, 'data' => $output);
 }
 function setAckDate($epoch = NULL)
 {
     $epoch = trim($epoch);
     if ($epoch == NULL) {
         $epoch = TTDate::getTime();
     }
     if ($this->Validator->isDate('ack_date', $epoch, TTi18n::gettext('Invalid Acknowledge Date'))) {
         $this->data['ack_date'] = $epoch;
         return TRUE;
     }
     return FALSE;
 }
 public function getYear($epoch = NULL)
 {
     if ($epoch == NULL) {
         $epoch = TTDate::getTime();
     }
     return date('Y', $epoch);
 }
Exemple #18
0
    function getData()
    {
        global $cache;
        $country = $this->getCountry();
        $province = $this->getProvince();
        $epoch = $this->getDate();
        if ($epoch == NULL or $epoch == '') {
            //$year = date('Y');
            $epoch = TTDate::getTime();
        }
        Debug::text('bUsing (' . $province . ') values from: ' . TTDate::getDate('DATE+TIME', $epoch), __FILE__, __LINE__, __METHOD__, 10);
        $cache_id = $country . $province . $epoch;
        if (is_string($cache->get($cache_id, $this->table))) {
            $this->income_tax_rates = unserialize($cache->get($cache_id, $this->table));
            Debug::text('Using Cached Income Tax Data!', __FILE__, __LINE__, __METHOD__, 10);
        } else {
            $this->income_tax_rates = FALSE;
        }
        if ($this->income_tax_rates === FALSE) {
            //There were issues with this query when provincial taxes were updated but not federal
            //We need to basically make a union query that queries the latest federal taxes separate
            //from the provincial
            $query = 'select country,province,income,rate,constant,effective_date
						from ' . $this->table . '
						where
								(
								effective_date = ( 	select effective_date
													from ' . $this->table . '
													where effective_date <= ' . $epoch . '
														AND country = ' . $this->db->qstr($country) . '
														AND province is NULL
													ORDER BY effective_date DESC
													LIMIT 1)
								)
							AND
							( country = ' . $this->db->qstr($country) . '
									and province is NULL)
							OR
								(
								effective_date = ( 	select effective_date
													from ' . $this->table . '
													where effective_date <= ' . $epoch . '
														AND country = ' . $this->db->qstr($country) . '
														AND province = ' . $this->db->qstr($province) . '
													ORDER BY effective_date DESC
													LIMIT 1)
								)
							AND
							( country = ' . $this->db->qstr($country) . '
									and province = ' . $this->db->qstr($province) . ')
						ORDER BY province desc, income asc, rate asc
					';
            //Debug::text('Query: '. $query , __FILE__, __LINE__, __METHOD__,10);
            try {
                $rs = $this->db->Execute($query);
            } catch (Exception $e) {
                throw new DBError($e);
            }
            $rs = $rs->GetRows();
            foreach ($rs as $key => $arr) {
                if ($arr['province'] == NULL) {
                    $type = 'federal';
                } else {
                    $type = 'provincial';
                }
                $this->income_tax_rates[$type][] = array('income' => trim($arr['income']), 'rate' => bcdiv(trim($arr['rate']), 100), 'constant' => trim($arr['constant']));
            }
            Debug::text('bUsing values from: ' . TTDate::getDate('DATE+TIME', $arr['effective_date']), __FILE__, __LINE__, __METHOD__, 10);
            //var_dump($this->income_tax_rates);
            $cache->save(serialize($this->income_tax_rates), $cache_id, $this->table);
        }
        return $this;
    }
 function setStatusDate($epoch = NULL)
 {
     $epoch = trim($epoch);
     if ($epoch == NULL) {
         $epoch = TTDate::getTime();
     }
     if ($this->Validator->isDate('status_date', $epoch, TTi18n::gettext('Incorrect Date'))) {
         $this->data['status_date'] = $epoch;
         return TRUE;
     }
     return FALSE;
 }
Exemple #20
0
    function getData()
    {
        global $cache;
        $country = $this->getCountry();
        $state = $this->getProvince();
        $district = $this->getDistrict();
        $epoch = $this->getDate();
        $federal_status = $this->getFederalFilingStatus();
        if ($federal_status == '') {
            $federal_status = 10;
        }
        $state_status = $this->getStateFilingStatus();
        if ($state_status == '') {
            $state_status = 10;
        }
        $district_status = $this->getDistrictFilingStatus();
        if ($epoch == NULL or $epoch == '') {
            //$year = date('Y');
            $epoch = TTDate::getTime();
        }
        Debug::text('bUsing (' . $state . '/' . $district . ') values from: ' . TTDate::getDate('DATE+TIME', $epoch), __FILE__, __LINE__, __METHOD__, 10);
        $cache_id = $country . $state . $district . $epoch . $federal_status . $state_status . $district_status;
        if (is_string($cache->get($cache_id, $this->table))) {
            $this->income_tax_rates = unserialize($cache->get($cache_id, $this->table));
        } else {
            $this->income_tax_rates = FALSE;
        }
        if ($this->income_tax_rates === FALSE) {
            //There were issues with this query when provincial taxes were updated but not federal
            //We need to basically make a union query that queries the latest federal taxes separate
            //from the provincial
            $query = 'select country,state,district,status,income,rate,constant,effective_date
						from ' . $this->table . '
						where
								(
								effective_date = ( 	select effective_date
													from ' . $this->table . '
													where effective_date <= ' . $epoch . '
														AND country = ' . $this->db->qstr($country) . '
														AND state is NULL
														AND ( status = 0
															OR status = ' . $federal_status . ' )
													ORDER BY effective_date DESC
													LIMIT 1) )
							AND
							( ( country = ' . $this->db->qstr($country) . '
									and state is NULL
									and ( status = 0 OR status = ' . $federal_status . ') ) )
							OR
								(
								effective_date = ( 	select effective_date
													from ' . $this->table . '
													where effective_date <= ' . $epoch . '
														AND country = ' . $this->db->qstr($country) . '
														AND state = ' . $this->db->qstr($state) . '
														AND ( status = 0
															OR status = ' . $state_status . ' )
													ORDER BY effective_date DESC
													LIMIT 1) )
							AND
							( country = ' . $this->db->qstr($country) . '
									and state = ' . $this->db->qstr($state) . '
									and district is NULL
									and ( status = 0 OR status = ' . $state_status . ') )
							OR
								(
								effective_date = ( 	select effective_date
													from ' . $this->table . '
													where effective_date <= ' . $epoch . '
														AND country = ' . $this->db->qstr($country) . '
														AND state = ' . $this->db->qstr($state) . '
														AND district = ' . $this->db->qstr($district) . '
														AND ( status = 0
															OR status = ' . $district_status . ' )
													ORDER BY effective_date DESC
													LIMIT 1) )
							AND
							( country = ' . $this->db->qstr($country) . '
									and state = ' . $this->db->qstr($state) . '
									and district = ' . $this->db->qstr($district) . '
									and ( status = 0 OR status = ' . $district_status . ') )
						ORDER BY state desc, district desc, income asc, rate asc';
            //Debug::text('Query: '. $query , __FILE__, __LINE__, __METHOD__,10);
            try {
                $rs = $this->db->Execute($query);
            } catch (Exception $e) {
                throw new DBError($e);
            }
            $rows = $rs->GetRows();
            $prev_income = 0;
            $prev_rate = 0;
            $prev_constant = 0;
            foreach ($rows as $key => $arr) {
                if ($arr['district'] != NULL) {
                    $type = 'district';
                } elseif ($arr['state'] != NULL) {
                    $type = 'state';
                } else {
                    $type = 'federal';
                }
                $this->income_tax_rates[$type][] = array('prev_income' => trim($prev_income), 'income' => trim($arr['income']), 'prev_rate' => bcdiv(trim($prev_rate), 100), 'rate' => bcdiv(trim($arr['rate']), 100), 'prev_constant' => trim($prev_constant), 'constant' => trim($arr['constant']));
                $prev_income = $arr['income'];
                $prev_rate = $arr['rate'];
                $prev_constant = $arr['constant'];
            }
            if (isset($this->income_tax_rates)) {
                foreach ($this->income_tax_rates as $type => $brackets) {
                    $i = 0;
                    $total_brackets = count($brackets) - 1;
                    foreach ($brackets as $key => $bracket_data) {
                        if ($i == 0) {
                            $first = TRUE;
                        } else {
                            $first = FALSE;
                        }
                        if ($i == $total_brackets) {
                            $last = TRUE;
                        } else {
                            $last = FALSE;
                        }
                        $this->income_tax_rates[$type][$key]['first'] = $first;
                        $this->income_tax_rates[$type][$key]['last'] = $last;
                        $i++;
                    }
                }
            }
            if (isset($arr)) {
                Debug::text('bUsing values from: ' . TTDate::getDate('DATE+TIME', $arr['effective_date']), __FILE__, __LINE__, __METHOD__, 10);
            }
            //var_dump($this->income_tax_rates);
            $cache->save(serialize($this->income_tax_rates), $cache_id, $this->table);
        }
        return $this;
    }
Exemple #21
0
     $pclf->getById($punch_control_id);
     if ($pclf->getRecordCount() > 0) {
         $pc_obj = $pclf->getCurrent();
         if ($date_stamp == NULL) {
             $date_stamp = $pc_obj->getUserDateObject()->getDateStamp();
         }
         $pc_data = array('id' => $pc_obj->getId(), 'user_id' => $pc_obj->getUserDateObject()->getUser(), 'user_full_name' => $pc_obj->getUserDateObject()->getUserObject()->getFullName(), 'date_stamp' => $date_stamp, 'user_date_id' => $pc_obj->getUserDateObject()->getId(), 'time_stamp' => $time_stamp, 'branch_id' => $pc_obj->getBranch(), 'department_id' => $pc_obj->getDepartment(), 'job_id' => $pc_obj->getJob(), 'job_item_id' => $pc_obj->getJobItem(), 'quantity' => (double) $pc_obj->getQuantity(), 'bad_quantity' => (double) $pc_obj->getBadQuantity(), 'note' => $pc_obj->getNote(), 'other_id1' => $pc_obj->getOtherID1(), 'other_id2' => $pc_obj->getOtherID2(), 'other_id3' => $pc_obj->getOtherID3(), 'other_id4' => $pc_obj->getOtherID4(), 'other_id5' => $pc_obj->getOtherID5(), 'status_id' => $status_id);
     }
 } elseif ($user_id != '') {
     Debug::Text(' User ID was passed: ' . $user_id . ' Date Stamp: ' . $date_stamp, __FILE__, __LINE__, __METHOD__, 10);
     //Don't guess too much. If they click a day to add a punch. Make sure that punch is on that day.
     if (isset($date_stamp) and $date_stamp != '') {
         $time_stamp = $date_stamp + 3600 * 12;
         //Noon
     } else {
         $time_stamp = TTDate::getBeginDayEpoch(TTDate::getTime()) + 3600 * 12;
         //Noon
     }
     /*
     if ( isset($date_stamp) AND $date_stamp != '' ) {
     	$epoch = $date_stamp;
     } else {
     	$epoch = TTDate::getTime();
     }
     //Get previous punch, and default timestamp to that.
     $plf = new PunchListFactory();
     $plf->getPreviousPunchByUserIDAndEpoch( $user_id, $epoch );
     if ( $plf->getRecordCount() > 0 ) {
     	Debug::Text(' Found Previous punch: ', __FILE__, __LINE__, __METHOD__,10);
     	$prev_punch_obj = $plf->getCurrent();
     	$time_stamp = $prev_punch_obj->getTimeStamp()+3600;
Exemple #22
0
                    if ($e_obj->getColumn('severity_id') == 25) {
                        $exceptions['high'] = $e_obj->getColumn('count');
                    }
                    if ($e_obj->getColumn('severity_id') == 30) {
                        $exceptions['critical'] = $e_obj->getColumn('count');
                    }
                }
            } else {
                Debug::Text(' No Exceptions!', __FILE__, __LINE__, __METHOD__, 10);
            }
            //Get all pending requests
            $pending_requests = 0;
            $rlf = TTnew('RequestListFactory');
            $rlf->getSumByPayPeriodIdAndStatus($pay_period_obj->getId(), 30);
            if ($rlf->getRecordCount() > 0) {
                $pending_requests = $rlf->getCurrent()->getColumn('total');
            }
            $pay_period_data['pending_requests'] = $pending_requests;
            //Count how many punches are in this pay period.
            $plf = TTnew('PunchListFactory');
            $pay_period_data['total_punches'] = $plf->getByPayPeriodId($pay_period_id)->getRecordCount();
            Debug::Text(' Total Punches: ' . $pay_period_data['total_punches'], __FILE__, __LINE__, __METHOD__, 10);
        }
        //var_dump($pay_period_data);
        $smarty->assign_by_ref('exceptions', $exceptions);
        $smarty->assign_by_ref('pay_period_data', $pay_period_data);
        $smarty->assign_by_ref('current_epoch', TTDate::getTime());
        break;
}
$smarty->assign_by_ref('ppf', $ppf);
$smarty->display('payperiod/ViewPayPeriod.tpl');
    function getAPILastWageSearchByCompanyIdAndArrayCriteria($company_id, $filter_data, $limit = NULL, $page = NULL, $where = NULL, $order = NULL)
    {
        if ($company_id == '') {
            return FALSE;
        }
        if (!is_array($order)) {
            //Use Filter Data ordering if its set.
            if (isset($filter_data['sort_column']) and $filter_data['sort_order']) {
                $order = array(Misc::trimSortPrefix($filter_data['sort_column']) => $filter_data['sort_order']);
            }
        }
        if (!isset($filter_data['effective_date'])) {
            $filter_data['effective_date'] = TTDate::getTime();
        }
        if (isset($filter_data['include_user_id'])) {
            $filter_data['user_id'] = $filter_data['include_user_id'];
        }
        if (isset($filter_data['exclude_user_id'])) {
            $filter_data['exclude_id'] = $filter_data['exclude_user_id'];
        }
        $additional_order_fields = array('wage_group');
        if ($order == NULL) {
            $order = array('effective_date' => 'desc', 'wage_group_id' => 'asc', 'type_id' => 'asc');
            $strict = FALSE;
        } else {
            //Always sort by last name,first name after other columns
            if (!isset($order['effective_date'])) {
                $order['effective_date'] = 'desc';
            }
            $strict = TRUE;
        }
        //Debug::Arr($order,'Order Data:', __FILE__, __LINE__, __METHOD__,10);
        //Debug::Arr($filter_data,'Filter Data:', __FILE__, __LINE__, __METHOD__,10);
        $uf = new UserFactory();
        $bf = new BranchFactory();
        $df = new DepartmentFactory();
        $ugf = new UserGroupFactory();
        $utf = new UserTitleFactory();
        $cf = new CurrencyFactory();
        $wgf = new WageGroupFactory();
        $ph = array('effective_date' => $this->db->BindTimeStamp($filter_data['effective_date']), 'company_id' => $company_id);
        /*
        		$query = '
        					select a.*
        					from '. $this->getTable() .' as a,
        						(
        						select 	z.user_id, max(effective_date) as effective_date
        						from	'. $this->getTable() .' as z
        						where
        							z.effective_date <= ?
        							AND z.wage_group_id = 0
        							AND z.user_id in ('. $this->getListSQL( $user_id, $ph ) .')
        							AND ( z.deleted = 0 )
        						GROUP BY z.user_id
        						) as b,
        						'. $uf->getTable() .' as c
        					WHERE a.user_id = b.user_id
        						AND a.effective_date = b.effective_date
        						AND a.user_id = c.id
        						AND ( c.deleted = 0	AND a.deleted = 0)
        				';
        */
        $query = '
					select 	a.*,
							CASE WHEN a.wage_group_id = 0 THEN \'' . TTi18n::getText('-Default-') . '\' ELSE ab.name END as wage_group,
							b.first_name as first_name,
							b.last_name as last_name,
							b.country as country,
							b.province as province,

							c.id as default_branch_id,
							c.name as default_branch,
							d.id as default_department_id,
							d.name as default_department,
							e.id as group_id,
							e.name as user_group,
							f.id as title_id,
							f.name as title,
							g.id as currency_id,
							g.iso_code as iso_code,

							y.first_name as created_by_first_name,
							y.middle_name as created_by_middle_name,
							y.last_name as created_by_last_name,
							z.first_name as updated_by_first_name,
							z.middle_name as updated_by_middle_name,
							z.last_name as updated_by_last_name
					from 	(
								select 	uwf.user_id as user_id, uwf.wage_group_id as wage_group_id, max(effective_date) as effective_date
								from	' . $this->getTable() . ' as uwf
								where uwf.effective_date <= ? AND uwf.deleted = 0
								GROUP BY uwf.wage_group_id, uwf.user_id
							) as uwf_b

						LEFT JOIN ' . $this->getTable() . ' as a ON ( a.user_id = uwf_b.user_id AND a.wage_group_id = uwf_b.wage_group_id AND a.effective_date = uwf_b.effective_date )

						LEFT JOIN ' . $wgf->getTable() . ' as ab ON ( a.wage_group_id = ab.id AND ab.deleted = 0 )
						LEFT JOIN ' . $uf->getTable() . ' as b ON ( a.user_id = b.id AND b.deleted = 0 )

						LEFT JOIN ' . $bf->getTable() . ' as c ON ( b.default_branch_id = c.id AND c.deleted = 0)
						LEFT JOIN ' . $df->getTable() . ' as d ON ( b.default_department_id = d.id AND d.deleted = 0)
						LEFT JOIN ' . $ugf->getTable() . ' as e ON ( b.group_id = e.id AND e.deleted = 0 )
						LEFT JOIN ' . $utf->getTable() . ' as f ON ( b.title_id = f.id AND f.deleted = 0 )
						LEFT JOIN ' . $cf->getTable() . ' as g ON ( b.currency_id = g.id AND g.deleted = 0 )


						LEFT JOIN ' . $uf->getTable() . ' as y ON ( a.created_by = y.id AND y.deleted = 0 )
						LEFT JOIN ' . $uf->getTable() . ' as z ON ( a.updated_by = z.id AND z.deleted = 0 )
					where	b.company_id = ?
					';
        if (isset($filter_data['permission_children_ids']) and isset($filter_data['permission_children_ids'][0]) and !in_array(-1, (array) $filter_data['permission_children_ids'])) {
            $query .= ' AND a.user_id in (' . $this->getListSQL($filter_data['permission_children_ids'], $ph) . ') ';
        }
        if (isset($filter_data['id']) and isset($filter_data['id'][0]) and !in_array(-1, (array) $filter_data['id'])) {
            $query .= ' AND a.id in (' . $this->getListSQL($filter_data['id'], $ph) . ') ';
        }
        if (isset($filter_data['exclude_id']) and isset($filter_data['exclude_id'][0]) and !in_array(-1, (array) $filter_data['exclude_id'])) {
            $query .= ' AND a.id not in (' . $this->getListSQL($filter_data['exclude_id'], $ph) . ') ';
        }
        if (isset($filter_data['user_id']) and isset($filter_data['user_id'][0]) and !in_array(-1, (array) $filter_data['user_id'])) {
            $query .= ' AND a.user_id in (' . $this->getListSQL($filter_data['user_id'], $ph) . ') ';
        }
        if (isset($filter_data['type_id']) and isset($filter_data['type_id'][0]) and !in_array(-1, (array) $filter_data['type_id'])) {
            $query .= ' AND a.type_id in (' . $this->getListSQL($filter_data['type_id'], $ph) . ') ';
        }
        if (isset($filter_data['wage_group_id']) and isset($filter_data['wage_group_id'][0]) and !in_array(-1, (array) $filter_data['wage_group_id'])) {
            $query .= ' AND a.wage_group_id in (' . $this->getListSQL($filter_data['wage_group_id'], $ph) . ') ';
        }
        if (isset($filter_data['status_id']) and isset($filter_data['status_id'][0]) and !in_array(-1, (array) $filter_data['status_id'])) {
            $query .= ' AND b.status_id in (' . $this->getListSQL($filter_data['status_id'], $ph) . ') ';
        }
        if (isset($filter_data['group_id']) and isset($filter_data['group_id'][0]) and !in_array(-1, (array) $filter_data['group_id'])) {
            if (isset($filter_data['include_subgroups']) and (bool) $filter_data['include_subgroups'] == TRUE) {
                $uglf = new UserGroupListFactory();
                $filter_data['group_id'] = $uglf->getByCompanyIdAndGroupIdAndSubGroupsArray($company_id, $filter_data['group_id'], TRUE);
            }
            $query .= ' AND b.group_id in (' . $this->getListSQL($filter_data['group_id'], $ph) . ') ';
        }
        if (isset($filter_data['default_branch_id']) and isset($filter_data['default_branch_id'][0]) and !in_array(-1, (array) $filter_data['default_branch_id'])) {
            $query .= ' AND b.default_branch_id in (' . $this->getListSQL($filter_data['default_branch_id'], $ph) . ') ';
        }
        if (isset($filter_data['default_department_id']) and isset($filter_data['default_department_id'][0]) and !in_array(-1, (array) $filter_data['default_department_id'])) {
            $query .= ' AND b.default_department_id in (' . $this->getListSQL($filter_data['default_department_id'], $ph) . ') ';
        }
        if (isset($filter_data['title_id']) and isset($filter_data['title_id'][0]) and !in_array(-1, (array) $filter_data['title_id'])) {
            $query .= ' AND b.title_id in (' . $this->getListSQL($filter_data['title_id'], $ph) . ') ';
        }
        if (isset($filter_data['country']) and isset($filter_data['country'][0]) and !in_array(-1, (array) $filter_data['country'])) {
            $query .= ' AND b.country in (' . $this->getListSQL($filter_data['country'], $ph) . ') ';
        }
        if (isset($filter_data['province']) and isset($filter_data['province'][0]) and !in_array(-1, (array) $filter_data['province']) and !in_array('00', (array) $filter_data['province'])) {
            $query .= ' AND b.province in (' . $this->getListSQL($filter_data['province'], $ph) . ') ';
        }
        $query .= isset($filter_data['created_by']) ? $this->getWhereClauseSQL(array('a.created_by', 'y.first_name', 'y.last_name'), $filter_data['created_by'], 'user_id_or_name', $ph) : NULL;
        $query .= isset($filter_data['updated_by']) ? $this->getWhereClauseSQL(array('a.updated_by', 'z.first_name', 'z.last_name'), $filter_data['updated_by'], 'user_id_or_name', $ph) : NULL;
        $query .= '
						AND a.deleted = 0
					';
        $query .= $this->getWhereSQL($where);
        $query .= $this->getSortSQL($order, $strict, $additional_order_fields);
        $this->ExecuteSQL($query, $ph, $limit, $page);
        return $this;
    }
 function startingUpgrade($station_id)
 {
     Debug::text('Starting Upgrade for Station ID: ' . $station_id . ' Date: ' . TTDate::getDate('DATE+TIME', TTDate::getTime()), __FILE__, __LINE__, __METHOD__, 10);
     return TRUE;
 }
Exemple #25
0
     if (!($data['start_full_time_stamp'] != '' and $data['end_full_time_stamp'] != '' and $data['start_full_time_stamp'] >= time() - 86400 * 365 and $data['end_full_time_stamp'] <= time() + 86400 * 365)) {
         $sf->Validator->isTrue('date_stamp', FALSE, TTi18n::getText('Start or End dates are invalid'));
     }
     if ($sf->Validator->isValid()) {
         Redirect::Page(URLBuilder::getURL(array('action' => 'add_mass_schedule', 'filter_user_id' => $filter_user_id, 'data' => $data), '../progress_bar/ProgressBarControl.php'));
     }
 default:
     if ($action != 'submit' and !is_array($data)) {
         Debug::Text(' ID was NOT passed: ' . $id, __FILE__, __LINE__, __METHOD__, 10);
         $user_id = NULL;
         $user_date_id = NULL;
         $user_full_name = NULL;
         $user_default_branch = NULL;
         $user_default_department = NULL;
         $pay_period_is_locked = FALSE;
         $time_stamp = $start_date_stamp = $end_date_stamp = TTDate::getBeginDayEpoch(TTDate::getTime()) + 3600 * 12;
         //Noon
         $data = array('start_date_stamp' => $start_date_stamp, 'end_date_stamp' => $end_date_stamp, 'start_time' => strtotime('08:00 AM'), 'parsed_start_time' => strtotime('08:00 AM'), 'end_time' => strtotime('05:00 PM'), 'parsed_end_time' => strtotime('05:00 PM'), 'total_time' => 3600 * 9, 'branch_id' => $user_default_branch, 'department_id' => $user_default_department, 'dow' => array(1 => TRUE, 2 => TRUE, 3 => TRUE, 4 => TRUE, 5 => TRUE));
     }
     //var_dump($data);
     $ulf = TTnew('UserListFactory');
     $ulf->getSearchByCompanyIdAndArrayCriteria($current_company->getId(), $filter_data);
     $src_user_options = UserListFactory::getArrayByListFactory($ulf, FALSE, FALSE);
     $user_options = Misc::arrayDiffByKey((array) $filter_user_id, $src_user_options);
     $filter_user_options = Misc::arrayIntersectByKey((array) $filter_user_id, $src_user_options);
     $prepend_array_option = array(0 => '--', -1 => TTi18n::gettext('-- Default --'));
     $splf = TTnew('SchedulePolicyListFactory');
     $schedule_policy_options = $splf->getByCompanyIdArray($current_company->getId());
     $aplf = TTnew('AbsencePolicyListFactory');
     $absence_policy_options = $aplf->getByCompanyIdArray($current_company->getId());
     $blf = TTnew('BranchListFactory');
 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;
 }
     }
     //var_dump($rows);
     foreach ($filter_data['column_ids'] as $column_key) {
         $filter_columns[Misc::trimSortPrefix($column_key)] = $columns[$column_key];
     }
     if ($action == 'export') {
         if (isset($rows) and isset($filter_columns)) {
             Debug::Text('Exporting as CSV', __FILE__, __LINE__, __METHOD__, 10);
             $data = Misc::Array2CSV($rows, $filter_columns);
             Misc::FileDownloadHeader('report.csv', 'application/csv', strlen($data));
             echo $data;
         } else {
             echo TTi18n::gettext("No Data To Export!") . "<br>\n";
         }
     } else {
         $smarty->assign_by_ref('generated_time', TTDate::getTime());
         $smarty->assign_by_ref('pay_period_options', $pay_period_options);
         $smarty->assign_by_ref('filter_data', $filter_data);
         $smarty->assign_by_ref('columns', $filter_columns);
         $smarty->assign_by_ref('rows', $rows);
         $smarty->display('report/TimesheetSummaryReport.tpl');
     }
     break;
 case 'delete':
 case 'save':
     Debug::Text('Action: ' . $action, __FILE__, __LINE__, __METHOD__, 10);
     $generic_data['id'] = UserGenericDataFactory::reportFormDataHandler($action, $filter_data, $generic_data, URLBuilder::getURL(NULL, $_SERVER['SCRIPT_NAME']));
     unset($generic_data['name']);
 default:
     BreadCrumb::setCrumb($title);
     if ($action == 'load') {
 function generatePayStubs($pay_period_ids, $user_ids = NULL, $enable_correction = FALSE)
 {
     global $profiler;
     Debug::Text('Generate Pay Stubs!', __FILE__, __LINE__, __METHOD__, 10);
     if (!$this->getPermissionObject()->Check('pay_period_schedule', 'enabled') or !($this->getPermissionObject()->Check('pay_period_schedule', 'edit') or $this->getPermissionObject()->Check('pay_period_schedule', 'edit_own'))) {
         return $this->getPermissionObject()->PermissionDenied();
     }
     if (!is_array($pay_period_ids)) {
         $pay_period_ids = array($pay_period_ids);
     }
     if ($user_ids !== NULL and !is_array($user_ids) and $user_ids > 0) {
         $user_ids = array($user_ids);
     } elseif (is_array($user_ids) and isset($user_ids[0]) and $user_ids[0] == 0) {
         $user_ids = NULL;
     }
     foreach ($pay_period_ids as $pay_period_id) {
         Debug::text('Pay Period ID: ' . $pay_period_id, __FILE__, __LINE__, __METHOD__, 10);
         $pplf = TTnew('PayPeriodListFactory');
         $pplf->getByIdAndCompanyId($pay_period_id, $this->getCurrentCompanyObject()->getId());
         $epoch = TTDate::getTime();
         foreach ($pplf as $pay_period_obj) {
             Debug::text('Pay Period Schedule ID: ' . $pay_period_obj->getPayPeriodSchedule(), __FILE__, __LINE__, __METHOD__, 10);
             if ($pay_period_obj->isPreviousPayPeriodClosed() == TRUE) {
                 //Grab all users for pay period
                 $ppsulf = TTnew('PayPeriodScheduleUserListFactory');
                 if (is_array($user_ids) and count($user_ids) > 0) {
                     Debug::text('Generating pay stubs for specific users...', __FILE__, __LINE__, __METHOD__, 10);
                     TTLog::addEntry($this->getCurrentCompanyObject()->getId(), 500, TTi18n::gettext('Calculating Company Pay Stubs for Pay Period') . ': ' . $pay_period_id, $this->getCurrentUserObject()->getId(), 'pay_stub');
                     //Notice
                     $ppsulf->getByCompanyIDAndPayPeriodScheduleIdAndUserID($this->getCurrentCompanyObject()->getId(), $pay_period_obj->getPayPeriodSchedule(), $user_ids);
                 } else {
                     TTLog::addEntry($this->getCurrentCompanyObject()->getId(), 500, TTi18n::gettext('Calculating Employee Pay Stub for Pay Period') . ': ' . $pay_period_id, $this->getCurrentUserObject()->getId(), 'pay_stub');
                     $ppsulf->getByCompanyIDAndPayPeriodScheduleId($this->getCurrentCompanyObject()->getId(), $pay_period_obj->getPayPeriodSchedule());
                 }
                 $total_pay_stubs = $ppsulf->getRecordCount();
                 $this->getProgressBarObject()->start($this->getAMFMessageID(), $total_pay_stubs, NULL, TTi18n::getText('Generating Paystubs...'));
                 //Delete existing pay stub. Make sure we only
                 //delete pay stubs that are the same as what we're creating.
                 $pslf = TTnew('PayStubListFactory');
                 $pslf->getByPayPeriodId($pay_period_obj->getId());
                 foreach ($pslf as $pay_stub_obj) {
                     if (is_array($user_ids) and count($user_ids) > 0 and in_array($pay_stub_obj->getUser(), $user_ids) == FALSE) {
                         continue;
                         //Only generating pay stubs for individual employees, skip ones not in the list.
                     }
                     Debug::text('Existing Pay Stub: ' . $pay_stub_obj->getId(), __FILE__, __LINE__, __METHOD__, 10);
                     //Check PS End Date to match with PP End Date
                     //So if an ROE was generated, it won't get deleted when they generate all other Pay Stubs
                     //later on.
                     if ($pay_stub_obj->getStatus() <= 25 and $pay_stub_obj->getTainted() === FALSE and TTDate::getMiddleDayEpoch($pay_stub_obj->getEndDate()) == TTDate::getMiddleDayEpoch($pay_period_obj->getEndDate())) {
                         Debug::text('Deleting pay stub: ' . $pay_stub_obj->getId(), __FILE__, __LINE__, __METHOD__, 10);
                         $pay_stub_obj->setDeleted(TRUE);
                         $pay_stub_obj->Save();
                     } else {
                         Debug::text('Pay stub does not need regenerating, or it is LOCKED! ID: ' . $pay_stub_obj->getID() . ' Status: ' . $pay_stub_obj->getStatus() . ' Tainted: ' . (int) $pay_stub_obj->getTainted() . ' Pay Stub End Date: ' . $pay_stub_obj->getEndDate() . ' Pay Period End Date: ' . $pay_period_obj->getEndDate(), __FILE__, __LINE__, __METHOD__, 10);
                     }
                 }
                 $i = 1;
                 foreach ($ppsulf as $pay_period_schdule_user_obj) {
                     Debug::text('Pay Period User ID: ' . $pay_period_schdule_user_obj->getUser(), __FILE__, __LINE__, __METHOD__, 10);
                     Debug::text('Total Pay Stubs: ' . $total_pay_stubs . ' - ' . ceil(1 / (100 / $total_pay_stubs)), __FILE__, __LINE__, __METHOD__, 10);
                     $profiler->startTimer('Calculating Pay Stub');
                     //Calc paystubs.
                     $cps = new CalculatePayStub();
                     $cps->setEnableCorrection((bool) $enable_correction);
                     $cps->setUser($pay_period_schdule_user_obj->getUser());
                     $cps->setPayPeriod($pay_period_obj->getId());
                     $cps->calculate();
                     unset($cps);
                     $profiler->stopTimer('Calculating Pay Stub');
                     $this->getProgressBarObject()->set($this->getAMFMessageID(), $i);
                     //sleep(1); /////////////////////////////// FOR TESTING ONLY //////////////////
                     $i++;
                 }
                 unset($ppsulf);
                 $this->getProgressBarObject()->stop($this->getAMFMessageID());
             } else {
                 UserGenericStatusFactory::queueGenericStatus(TTi18n::gettext('ERROR'), 10, TTi18n::gettext('Pay period prior to %1 is not closed, please close all previous pay periods and try again...', array(TTDate::getDate('DATE', $pay_period_obj->getStartDate()) . ' -> ' . TTDate::getDate('DATE', $pay_period_obj->getEndDate()))), NULL);
             }
         }
     }
     if (UserGenericStatusFactory::isStaticQueue() == TRUE) {
         $ugsf = TTnew('UserGenericStatusFactory');
         $ugsf->setUser($this->getCurrentUserObject()->getId());
         $ugsf->setBatchID($ugsf->getNextBatchId());
         $ugsf->setQueue(UserGenericStatusFactory::getStaticQueue());
         $ugsf->saveQueue();
         $user_generic_status_batch_id = $ugsf->getBatchID();
     } else {
         $user_generic_status_batch_id = FALSE;
     }
     unset($ugsf);
     return $this->returnHandler(TRUE, TRUE, FALSE, FALSE, FALSE, $user_generic_status_batch_id);
 }
            $request_id = $rf->Save();
            $rf->CommitTransaction();
            //$rf->FailTransaction();
            //Redirect::Page( URLBuilder::getURL( array('refresh' => FALSE ), '../CloseWindow.php') );
            Redirect::Page(URLBuilder::getURL(array('refresh' => TRUE), '../CloseWindow.php'));
        }
        $rf->FailTransaction();
    default:
        if ((int) $id > 0) {
            Debug::Text(' ID was passed: ' . $id, __FILE__, __LINE__, __METHOD__, 10);
            $rlf = new RequestListFactory();
            $rlf->getByIDAndCompanyID($id, $current_company->getId());
            foreach ($rlf as $r_obj) {
                //Debug::Arr($station,'Department', __FILE__, __LINE__, __METHOD__,10);
                $data = array('id' => $r_obj->getId(), 'user_date_id' => $r_obj->getId(), 'user_id' => $r_obj->getUserDateObject()->getUser(), 'user_full_name' => $r_obj->getUserDateObject()->getUserObject()->getFullName(), 'date_stamp' => $r_obj->getUserDateObject()->getDateStamp(), 'type_id' => $r_obj->getType(), 'status_id' => $r_obj->getStatus(), 'created_date' => $r_obj->getCreatedDate(), 'created_by' => $r_obj->getCreatedBy(), 'updated_date' => $r_obj->getUpdatedDate(), 'updated_by' => $r_obj->getUpdatedBy(), 'deleted_date' => $r_obj->getDeletedDate(), 'deleted_by' => $r_obj->getDeletedBy());
            }
        } elseif ($action != 'submit') {
            Debug::Text(' ID was NOT passed: ' . $id, __FILE__, __LINE__, __METHOD__, 10);
            //UserID has to be set at minimum
            $data = array('user_id' => $current_user->getId(), 'user_full_name' => $current_user->getFullName(), 'date_stamp' => TTDate::getTime());
        } else {
            $data['user_full_name'] = $current_user->getFullName();
        }
        //Select box options;
        $data['status_options'] = $rf->getOptions('status');
        $data['type_options'] = $rf->getOptions('type');
        $smarty->assign_by_ref('data', $data);
        break;
}
$smarty->assign_by_ref('rf', $rf);
$smarty->display('request/EditRequest.tpl');
    function getByUserIdListAndNotStatusAndStartDateAndEndDate($user_ids, $status_ids, $start_date, $end_date, $where = NULL, $order = NULL)
    {
        /*
        $key = Option::getByValue($status, $this->getOptions('status') );
        if ($key !== FALSE) {
        	$status = $key;
        }
        */
        if ($user_ids == '') {
            return FALSE;
        }
        if ($status_ids == '') {
            return FALSE;
        }
        if ($start_date == '') {
            return FALSE;
        }
        if ($end_date == '') {
            $end_date = TTDate::getTime() + 86400 * 355;
            //Only check ahead one year of open pay periods.
        }
        $ppsf = new PayPeriodScheduleFactory();
        $ppsuf = new PayPeriodScheduleUserFactory();
        $ph = array();
        $user_ids_sql = $this->getListSQL($user_ids, $ph);
        $ph['start_date'] = $this->db->BindTimeStamp($start_date);
        $ph['end_date'] = $this->db->BindTimeStamp($end_date);
        //Start Date arg should be greater then pay period END DATE.
        //So recurring PS amendments start_date can fall anywhere in the pay period and still get applied.
        $query = '
					select 	a.*
					from	' . $this->getTable() . ' as a
					where 	a.pay_period_schedule_id in
						( select distinct(x.pay_period_schedule_id)
							from
									' . $ppsuf->getTable() . ' as x,
									' . $ppsf->getTable() . ' as z
							where x.user_id in ( ' . $user_ids_sql . ' )
								AND z.deleted=0)
						AND a.end_date >= ?
						AND a.start_date <= ?
						AND a.status_id not in ( ' . $this->getListSQL($status_ids, $ph) . ' )
						AND a.deleted=0';
        $query .= $this->getWhereSQL($where);
        $query .= $this->getSortSQL($order);
        $this->rs = $this->db->Execute($query, $ph);
        return $this;
    }