function setPayStubAmendment($id)
 {
     $id = trim($id);
     Debug::text('PS Amendment ID: ' . $id, __FILE__, __LINE__, __METHOD__, 10);
     $psalf = new PayStubAmendmentListFactory();
     $result = $psalf->getById($id);
     if ($this->Validator->isResultSetWithRows('pay_stub_amendment_id', $result, TTi18n::gettext('Invalid Pay Stub Amendment Id'))) {
         //Debug::text('TRUE: '. $id .' -: '. $result->getCurrent()->getId() , __FILE__, __LINE__, __METHOD__,10);
         $this->data['pay_stub_amendment_id'] = $result->getCurrent()->getId();
         return TRUE;
     }
     return FALSE;
 }
 function handlePayStubAmendmentStatuses()
 {
     //Mark all PS amendments as 'PAID' if this status is paid.
     //Mark as NEW if the PS is deleted?
     if ($this->getStatus() == 40) {
         $ps_amendment_status_id = 55;
         //PAID
     } else {
         $ps_amendment_status_id = 52;
         //INUSE
     }
     //Loop through each entry in current pay stub, if they have
     //a PS amendment ID assigned to them, change the status.
     if (is_array($this->tmp_data['current_pay_stub'])) {
         foreach ($this->tmp_data['current_pay_stub'] as $entry_arr) {
             if (isset($entry_arr['pay_stub_amendment_id']) and $entry_arr['pay_stub_amendment_id'] != '') {
                 Debug::Text('aFound PS Amendments to change status on...', __FILE__, __LINE__, __METHOD__, 10);
                 $ps_amendment_ids[] = $entry_arr['pay_stub_amendment_id'];
             }
         }
         unset($entry_arr);
     } elseif ($this->getStatus() != 10) {
         //Instead of loading the current pay stub entries, just run a query instead.
         $pself = new PayStubEntryListFactory();
         $pself->getByPayStubId($this->getId());
         foreach ($pself as $pay_stub_entry_obj) {
             if ($pay_stub_entry_obj->getPayStubAmendment() != FALSE) {
                 Debug::Text('bFound PS Amendments to change status on...', __FILE__, __LINE__, __METHOD__, 10);
                 $ps_amendment_ids[] = $pay_stub_entry_obj->getPayStubAmendment();
             }
         }
     }
     if (isset($ps_amendment_ids) and is_array($ps_amendment_ids)) {
         Debug::Text('cFound PS Amendments to change status on...', __FILE__, __LINE__, __METHOD__, 10);
         foreach ($ps_amendment_ids as $ps_amendment_id) {
             //Set PS amendment status to match Pay stub.
             $psalf = new PayStubAmendmentListFactory();
             $psalf->getById($ps_amendment_id);
             if ($psalf->getRecordCount() == 1) {
                 Debug::Text('Changing Status of PS Amendment: ' . $ps_amendment_id, __FILE__, __LINE__, __METHOD__, 10);
                 $ps_amendment_obj = $psalf->getCurrent();
                 $ps_amendment_obj->setStatus($ps_amendment_status_id);
                 $ps_amendment_obj->Save();
                 unset($ps_amendment_obj);
             }
             unset($psalf);
         }
         unset($ps_amendment_ids);
     }
     return TRUE;
 }
}
Debug::Text('Action: ' . $action, __FILE__, __LINE__, __METHOD__, 10);
switch ($action) {
    case 'add':
        Redirect::Page(URLBuilder::getURL(array('user_id' => $filter_user_id), 'EditPayStubAmendment.php', FALSE));
        break;
    case 'delete':
    case 'undelete':
        if (strtolower($action) == 'delete') {
            $delete = TRUE;
        } else {
            $delete = FALSE;
        }
        $psalf = new PayStubAmendmentListFactory();
        foreach ($ids as $id) {
            $psalf->getById($id);
            foreach ($psalf as $pay_stub_amendment) {
                //Only delete PS amendments NOT in the paid status.
                if ($pay_stub_amendment->getStatus() != 55) {
                    $pay_stub_amendment->setDeleted($delete);
                    $pay_stub_amendment->Save();
                }
            }
        }
        unset($pay_stub_amendment);
        Redirect::Page(URLBuilder::getURL(NULL, 'PayStubAmendmentList.php', TRUE));
        break;
    case 'search_form_delete':
    case 'search_form_update':
    case 'search_form_save':
    case 'search_form_clear':