function setRecurringPayStubAmendment($id)
 {
     $id = trim($id);
     $rpsalf = new RecurringPayStubAmendmentListFactory();
     if ($id != 0 or $this->Validator->isResultSetWithRows('recurring_ps_amendment', $rpsalf->getByID($id), TTi18n::gettext('Recurring PS Amendment is invalid'))) {
         $this->data['recurring_ps_amendment_id'] = $id;
         return TRUE;
     }
     return FALSE;
 }
 * of this program must display Appropriate Legal Notices, as required under
 * Section 5 of the GNU Affero General Public License version 3.
 *
 * In accordance with Section 7(b) of the GNU Affero General Public License
 * version 3, these Appropriate Legal Notices must retain the display of the
 * "Powered by TimeTrex" logo. If the display of the logo is not reasonably
 * feasible for technical reasons, the Appropriate Legal Notices must display
 * the words "Powered by TimeTrex".
 ********************************************************************************/
/*
 * $Revision: 1396 $
 * $Id: AddRecurringPayStubAmendment.php 1396 2007-11-07 16:49:35Z ipso $
 * $Date: 2007-11-07 08:49:35 -0800 (Wed, 07 Nov 2007) $
 */
/*
 * Adds all recurring PS amendments
 * This file should be run once a day.
 *
 */
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'global.inc.php';
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'CLI.inc.php';
$epoch = TTDate::getTime();
//Get all recurring PS amendments by company, loop through each one.
$rpsalf = new RecurringPayStubAmendmentListFactory();
$rpsalf->getByStatusAndStartDate(50, $epoch);
foreach ($rpsalf as $recurring_ps_amendment_obj) {
    Debug::text('Recurring PS Amendment ID: ' . $recurring_ps_amendment_obj->getID(), __FILE__, __LINE__, __METHOD__, 10);
    $recurring_ps_amendment_obj->createPayStubAmendments($epoch);
}
Debug::writeToLog();
Debug::Display();
 function setRecurringPayStubAmendmentId($id)
 {
     $id = trim($id);
     $rpsalf = new RecurringPayStubAmendmentListFactory();
     $result = $rpsalf->getById($id)->getCurrent();
     if ($id == NULL or $this->Validator->isResultSetWithRows('recurring_ps_amendment_id', $result, TTi18n::gettext('Invalid Recurring Pay Stub Amendment ID'))) {
         $this->data['recurring_ps_amendment_id'] = $result->getId();
         return TRUE;
     }
     return FALSE;
 }
        } else {
            $delete = FALSE;
        }
        $rpsalf = new RecurringPayStubAmendmentListFactory();
        foreach ($ids as $id) {
            $rpsalf->getById($id);
            foreach ($rpsalf as $recurring_pay_stub_amendment) {
                $recurring_pay_stub_amendment->setDeleted($delete);
                $recurring_pay_stub_amendment->Save();
            }
        }
        unset($recurring_pay_stub_amendment);
        Redirect::Page(URLBuilder::getURL(NULL, 'RecurringPayStubAmendmentList.php', FALSE));
        break;
    default:
        URLBuilder::setURL(NULL, array('sort_column' => $sort_column, 'sort_order' => $sort_order));
        $rpsalf = new RecurringPayStubAmendmentListFactory();
        $rpsalf->getByCompanyId($current_company->getId(), $current_user_prefs->getItemsPerPage(), $page, NULL, $sort_array);
        $pager = new Pager($rpsalf);
        $psealf = new PayStubEntryAccountListFactory();
        foreach ($rpsalf as $recurring_pay_stub_amendment) {
            $recurring_pay_stub_amendments[] = array('id' => $recurring_pay_stub_amendment->GetId(), 'name' => $recurring_pay_stub_amendment->getName(), 'description' => $recurring_pay_stub_amendment->getDescription(), 'status' => Option::getByKey($recurring_pay_stub_amendment->getStatus(), $recurring_pay_stub_amendment->getOptions('status')), 'frequency' => Option::getByKey($recurring_pay_stub_amendment->getFrequency(), $recurring_pay_stub_amendment->getOptions('frequency')), 'pay_stub_entry_name' => $psealf->getById($recurring_pay_stub_amendment->getPayStubEntryNameId())->getCurrent()->getName(), 'deleted' => $recurring_pay_stub_amendment->getDeleted());
        }
        $smarty->assign_by_ref('recurring_pay_stub_amendments', $recurring_pay_stub_amendments);
        $smarty->assign_by_ref('sort_column', $sort_column);
        $smarty->assign_by_ref('sort_order', $sort_order);
        $smarty->assign_by_ref('paging_data', $pager->getPageVariables());
        $smarty->assign_by_ref('user_id', $user_id);
        break;
}
$smarty->display('pay_stub_amendment/RecurringPayStubAmendmentList.tpl');
     $rpsaf->setPayStubAmendmentDescription($pay_stub_amendment_data['ps_amendment_description']);
     if ($rpsaf->isValid()) {
         $rpsaf->Save(FALSE);
         if (isset($pay_stub_amendment_data['user_ids'])) {
             $rpsaf->setUser($pay_stub_amendment_data['user_ids']);
         } else {
             $rpsaf->setUser(array());
         }
         $rpsaf->Save();
         Redirect::Page(URLBuilder::getURL(NULL, 'RecurringPayStubAmendmentList.php'));
         break;
     }
 default:
     BreadCrumb::setCrumb($title);
     if (isset($id)) {
         $rpsalf = new RecurringPayStubAmendmentListFactory();
         //$uwlf->GetByUserIdAndCompanyId($current_user->getId(), $current_company->getId() );
         $rpsalf->GetById($id);
         foreach ($rpsalf as $recurring_pay_stub_amendment) {
             //Debug::Arr($station,'Department', __FILE__, __LINE__, __METHOD__,10);
             //$user_id = $recurring_pay_stub_amendment->getUser();
             $amount_type_id = 10;
             if ($recurring_pay_stub_amendment->getPercentAmount() > 0) {
                 $amount_type_id = 20;
             }
             $pay_stub_amendment_data = array('id' => $recurring_pay_stub_amendment->getId(), 'company_id' => $recurring_pay_stub_amendment->getCompany(), 'status_id' => $recurring_pay_stub_amendment->getStatus(), 'name' => $recurring_pay_stub_amendment->getName(), 'description' => $recurring_pay_stub_amendment->getDescription(), 'start_date' => $recurring_pay_stub_amendment->getStartDate(), 'end_date' => $recurring_pay_stub_amendment->getEndDate(), 'frequency_id' => $recurring_pay_stub_amendment->getFrequency(), 'user_ids' => $recurring_pay_stub_amendment->getUser(), 'type_id' => $recurring_pay_stub_amendment->getType(), 'pay_stub_entry_name_id' => $recurring_pay_stub_amendment->getPayStubEntryNameId(), 'amount_type_id' => $amount_type_id, 'rate' => $recurring_pay_stub_amendment->getRate(), 'units' => $recurring_pay_stub_amendment->getUnits(), 'amount' => $recurring_pay_stub_amendment->getAmount(), 'percent_amount' => $recurring_pay_stub_amendment->getPercentAmount(), 'percent_amount_entry_name_id' => $recurring_pay_stub_amendment->getPercentAmountEntryNameId(), 'ps_amendment_description' => $recurring_pay_stub_amendment->getPayStubAmendmentDescription(), 'created_date' => $recurring_pay_stub_amendment->getCreatedDate(), 'created_by' => $recurring_pay_stub_amendment->getCreatedBy(), 'updated_date' => $recurring_pay_stub_amendment->getUpdatedDate(), 'updated_by' => $recurring_pay_stub_amendment->getUpdatedBy(), 'deleted_date' => $recurring_pay_stub_amendment->getDeletedDate(), 'deleted_by' => $recurring_pay_stub_amendment->getDeletedBy());
         }
     } else {
         if ($pay_stub_amendment_data['start_date'] == '') {
             $pay_stub_amendment_data['start_date'] = TTDate::getTime();
         }
 $pager = new Pager($psalf);
 $psealf = new PayStubEntryAccountListFactory();
 $pay_stub_entry_name_options = $psealf->getByCompanyIdAndStatusIdAndTypeIdArray($current_company->getId(), 10, array(10, 20, 30, 50, 60, 65));
 //Get pay periods
 $pplf->getByCompanyId($current_company->getId());
 $pay_period_options = $pplf->getArrayByListFactory($pplf, FALSE, TRUE);
 $utlf = new UserTitleListFactory();
 $utlf->getByCompanyId($current_company->getId());
 $title_options = $utlf->getArrayByListFactory($utlf, FALSE, TRUE);
 $blf = new BranchListFactory();
 $blf->getByCompanyId($current_company->getId());
 $branch_options = $blf->getArrayByListFactory($blf, FALSE, TRUE);
 $dlf = new DepartmentListFactory();
 $dlf->getByCompanyId($current_company->getId());
 $department_options = $dlf->getArrayByListFactory($dlf, FALSE, TRUE);
 $rpsalf = new RecurringPayStubAmendmentListFactory();
 $rpsalf->getByCompanyId($current_company->getId());
 $recurring_ps_amendment_options = $rpsalf->getArrayByListFactory($rpsalf, FALSE, TRUE);
 $uglf = new UserGroupListFactory();
 $group_options = $uglf->getArrayByNodes(FastTree::FormatArray($uglf->getByCompanyIdArray($current_company->getId()), 'TEXT', TRUE));
 foreach ($psalf as $psa_obj) {
     $user_obj = $ulf->getById($psa_obj->getUser())->getCurrent();
     if ($psa_obj->getType() == 10) {
         $amount = $psa_obj->getAmount();
     } else {
         $amount = $psa_obj->getPercentAmount() . '%';
     }
     $pay_stub_amendments[] = array('id' => $psa_obj->getId(), 'user_id' => $psa_obj->getUser(), 'first_name' => $user_obj->getFirstName(), 'middle_name' => $user_obj->getMiddleName(), 'last_name' => $user_obj->getLastName(), 'status_id' => $psa_obj->getStatus(), 'status' => Option::getByKey($psa_obj->getStatus(), $psa_obj->getOptions('status')), 'type_id' => $psa_obj->getType(), 'type' => Option::getByKey($psa_obj->getType(), $psa_obj->getOptions('type')), 'effective_date' => TTDate::getDate('DATE', $psa_obj->getEffectiveDate()), 'pay_stub_account_name' => Option::getByKey($psa_obj->getPayStubEntryNameId(), $pay_stub_entry_name_options), 'amount' => $amount, 'rate' => $psa_obj->getRate(), 'units' => $psa_obj->getUnits(), 'description' => $psa_obj->getDescription(), 'authorized' => $psa_obj->getAuthorized(), 'ytd_adjustment' => Misc::HumanBoolean($psa_obj->getYTDAdjustment()), 'deleted' => $psa_obj->getDeleted());
 }
 $all_array_option = array('-1' => TTi18n::gettext('-- Any --'));
 $ulf->getSearchByCompanyIdAndArrayCriteria($current_company->getId(), $filter_data);