}
Debug::Arr($ids, 'Selected Objects', __FILE__, __LINE__, __METHOD__, 10);
$action = Misc::findSubmitButton();
switch ($action) {
    case 'add':
        Redirect::Page(URLBuilder::getURL(NULL, 'EditRecurringPayStubAmendment.php', FALSE));
        break;
    case 'delete' or 'undelete':
        if (strtolower($action) == 'delete') {
            $delete = TRUE;
        } 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) {
 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;
 }
if (isset($pay_stub_amendment_data)) {
    if ($pay_stub_amendment_data['start_date'] != '') {
        $pay_stub_amendment_data['start_date'] = TTDate::parseDateTime($pay_stub_amendment_data['start_date']);
    }
    if ($pay_stub_amendment_data['end_date'] != '') {
        $pay_stub_amendment_data['end_date'] = TTDate::parseDateTime($pay_stub_amendment_data['end_date']);
    }
}
$rpsaf = new RecurringPayStubAmendmentFactory();
$action = Misc::findSubmitButton();
$action = strtolower($action);
switch ($action) {
    case 'recalculate':
        //Debug::setVerbosity(11);
        $rpsalf = new RecurringPayStubAmendmentListFactory();
        $rpsalf->getById($pay_stub_amendment_data['id']);
        if ($rpsalf->getRecordCount() > 0) {
            $rpsa_obj = $rpsalf->getCurrent();
            $rpsa_obj->createPayStubAmendments();
        }
        Redirect::Page(URLBuilder::getURL(NULL, 'RecurringPayStubAmendmentList.php'));
        break;
    case 'submit':
        Debug::Text('Submit!', __FILE__, __LINE__, __METHOD__, 10);
        $rpsaf->setId($pay_stub_amendment_data['id']);
        $rpsaf->setCompany($current_company->getId());
        $rpsaf->setStatus($pay_stub_amendment_data['status_id']);
        $rpsaf->setName($pay_stub_amendment_data['name']);
        $rpsaf->setDescription($pay_stub_amendment_data['description']);
        $rpsaf->setStartDate($pay_stub_amendment_data['start_date']);
        if ($pay_stub_amendment_data['end_date'] != '') {