/**
  * Build the form object.
  *
  * @return void
  */
 public function buildQuickForm()
 {
     parent::buildQuickForm();
     $this->setPageTitle(ts('Financial Batch'));
     if (isset($this->_id)) {
         $this->_title = CRM_Core_DAO::getFieldValue('CRM_Batch_DAO_Batch', $this->_id, 'title');
         CRM_Utils_System::setTitle($this->_title . ' - ' . ts('Accounting Batch'));
         $this->assign('batchTitle', $this->_title);
         $contactID = CRM_Core_DAO::getFieldValue('CRM_Batch_DAO_Batch', $this->_id, 'created_id');
         $contactName = CRM_Contact_BAO_Contact::displayName($contactID);
         $this->assign('contactName', $contactName);
     }
     $this->applyFilter('__ALL__', 'trim');
     $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'isDefault' => TRUE), array('type' => 'next', 'name' => ts('Save and New'), 'subName' => 'new'), array('type' => 'cancel', 'name' => ts('Cancel'))));
     if ($this->_action & CRM_Core_Action::UPDATE && $this->_id) {
         $batchStatus = CRM_Core_PseudoConstant::get('CRM_Batch_DAO_Batch', 'status_id');
         //unset exported status
         $exportedStatusId = CRM_Utils_Array::key('Exported', $batchStatus);
         unset($batchStatus[$exportedStatusId]);
         $this->add('select', 'status_id', ts('Batch Status'), array('' => ts('- select -')) + $batchStatus, TRUE);
         $this->freeze(array('status_id'));
     }
     $attributes = CRM_Core_DAO::getAttribute('CRM_Batch_DAO_Batch');
     $this->add('text', 'title', ts('Batch Name'), $attributes['name'], TRUE);
     $this->add('textarea', 'description', ts('Description'), $attributes['description']);
     $this->add('select', 'payment_instrument_id', ts('Payment Method'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument(), FALSE);
     $this->add('text', 'total', ts('Total Amount'), $attributes['total']);
     $this->add('text', 'item_count', ts('Number of Transactions'), $attributes['item_count']);
     $this->addFormRule(array('CRM_Financial_Form_FinancialBatch', 'formRule'), $this);
 }
 /**
  * Function to build the form
  *
  * @return void
  * @access public
  */
 public function buildQuickForm()
 {
     parent::buildQuickForm();
     $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
     if ($this->_id) {
         $this->_title = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialType', $this->_id, 'name');
         CRM_Utils_System::setTitle($this->_title . ' - ' . ts('Financial Type'));
     }
     if ($this->_action & CRM_Core_Action::DELETE) {
         return;
     }
     $this->applyFilter('__ALL__', 'trim');
     $this->add('text', 'name', ts('Name'), CRM_Core_DAO::getAttribute('CRM_Financial_DAO_FinancialType', 'name'), TRUE);
     $this->add('text', 'description', ts('Description'), CRM_Core_DAO::getAttribute('CRM_Financial_DAO_FinancialType', 'description'));
     $this->add('checkbox', 'is_deductible', ts('Tax-Deductible?'), CRM_Core_DAO::getAttribute('CRM_Financial_DAO_FinancialType', 'is_deductible'));
     $this->add('checkbox', 'is_active', ts('Enabled?'), CRM_Core_DAO::getAttribute('CRM_Financial_DAO_FinancialType', 'is_active'));
     $this->add('checkbox', 'is_reserved', ts('Reserved?'), CRM_Core_DAO::getAttribute('CRM_Financial_DAO_FinancialType', 'is_reserved'));
     if ($this->_action == CRM_Core_Action::UPDATE) {
         $this->assign('aid', $this->_id);
     }
     if ($this->_action == CRM_Core_Action::UPDATE && CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialType', $this->_id, 'is_reserved', 'vid')) {
         $this->freeze(array('is_active'));
     }
     //$this->addFormRule( array( 'CRM_Financial_Form_FinancialType', 'formRule'), $this );
 }
 /**
  * Build the form object.
  *
  * @return void
  */
 public function buildQuickForm()
 {
     parent::buildQuickForm();
     $this->setPageTitle(ts('Financial Type'));
     $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
     if ($this->_id) {
         $this->_title = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialType', $this->_id, 'name');
     }
     if ($this->_action & CRM_Core_Action::DELETE) {
         return;
     }
     $this->applyFilter('__ALL__', 'trim');
     $this->add('text', 'name', ts('Name'), CRM_Core_DAO::getAttribute('CRM_Financial_DAO_FinancialType', 'name'), TRUE);
     $this->add('text', 'description', ts('Description'), CRM_Core_DAO::getAttribute('CRM_Financial_DAO_FinancialType', 'description'));
     $this->add('checkbox', 'is_deductible', ts('Tax-Deductible?'), CRM_Core_DAO::getAttribute('CRM_Financial_DAO_FinancialType', 'is_deductible'));
     $this->add('checkbox', 'is_active', ts('Enabled?'), CRM_Core_DAO::getAttribute('CRM_Financial_DAO_FinancialType', 'is_active'));
     $this->add('checkbox', 'is_reserved', ts('Reserved?'), CRM_Core_DAO::getAttribute('CRM_Financial_DAO_FinancialType', 'is_reserved'));
     if ($this->_action == CRM_Core_Action::UPDATE) {
         $this->assign('aid', $this->_id);
     }
     if ($this->_action == CRM_Core_Action::UPDATE && CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialType', $this->_id, 'is_reserved', 'vid')) {
         $this->freeze(array('is_active'));
     }
     $this->addRule('name', ts('A financial type with this name already exists. Please select another name.'), 'objectExists', array('CRM_Financial_DAO_FinancialType', $this->_id));
 }
 /**
  * Build the form object.
  */
 public function buildQuickForm()
 {
     parent::buildQuickForm();
     $this->setPageTitle(ts('Premium Product'));
     if ($this->_action & CRM_Core_Action::PREVIEW) {
         CRM_Contribute_BAO_Premium::buildPremiumPreviewBlock($this, $this->_id);
         return;
     }
     if ($this->_action & CRM_Core_Action::DELETE) {
         return;
     }
     $this->applyFilter('__ALL__', 'trim');
     $this->add('text', 'name', ts('Name'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Product', 'name'), TRUE);
     $this->addRule('name', ts('A product with this name already exists. Please select another name.'), 'objectExists', array('CRM_Contribute_DAO_Product', $this->_id));
     $this->add('text', 'sku', ts('SKU'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Product', 'sku'));
     $this->add('textarea', 'description', ts('Description'), 'rows=3, cols=60');
     $image['image'] = $this->createElement('radio', NULL, NULL, ts('Upload from my computer'), 'image', 'onclick="add_upload_file_block(\'image\');');
     $image['thumbnail'] = $this->createElement('radio', NULL, NULL, ts('Display image and thumbnail from these locations on the web:'), 'thumbnail', 'onclick="add_upload_file_block(\'thumbnail\');');
     $image['default_image'] = $this->createElement('radio', NULL, NULL, ts('Use default image'), 'default_image', 'onclick="add_upload_file_block(\'default\');');
     $image['noImage'] = $this->createElement('radio', NULL, NULL, ts('Do not display an image'), 'noImage', 'onclick="add_upload_file_block(\'noImage\');');
     $this->addGroup($image, 'imageOption', ts('Premium Image'));
     $this->addRule('imageOption', ts('Please select an option for the premium image.'), 'required');
     $this->addElement('text', 'imageUrl', ts('Image URL'));
     $this->addElement('text', 'thumbnailUrl', ts('Thumbnail URL'));
     $this->add('file', 'uploadFile', ts('Image File Name'), 'onChange="select_option();"');
     $this->add('text', 'price', ts('Market Value'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Product', 'price'), TRUE);
     $this->addRule('price', ts('Please enter the Market Value for this product.'), 'money');
     $this->add('text', 'cost', ts('Actual Cost of Product'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Product', 'cost'));
     $this->addRule('price', ts('Please enter the Actual Cost of Product.'), 'money');
     $this->add('text', 'min_contribution', ts('Minimum Contribution Amount'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Product', 'min_contribution'), TRUE);
     $this->addRule('min_contribution', ts('Please enter a monetary value for the Minimum Contribution Amount.'), 'money');
     $this->add('textarea', 'options', ts('Options'), 'rows=3, cols=60');
     $this->add('select', 'period_type', ts('Period Type'), array('' => '- select -', 'rolling' => 'Rolling', 'fixed' => 'Fixed'));
     $this->add('text', 'fixed_period_start_day', ts('Fixed Period Start Day'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Product', 'fixed_period_start_day'));
     $this->add('Select', 'duration_unit', ts('Duration Unit'), array('' => '- select period -') + CRM_Core_SelectValues::getPremiumUnits());
     $this->add('text', 'duration_interval', ts('Duration'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Product', 'duration_interval'));
     $this->add('Select', 'frequency_unit', ts('Frequency Unit'), array('' => '- select period -') + CRM_Core_SelectValues::getPremiumUnits());
     $this->add('text', 'frequency_interval', ts('Frequency'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Product', 'frequency_interval'));
     //Financial Type CRM-11106
     $financialType = CRM_Contribute_PseudoConstant::financialType();
     $premiumFinancialType = array();
     CRM_Core_PseudoConstant::populate($premiumFinancialType, 'CRM_Financial_DAO_EntityFinancialAccount', $all = TRUE, $retrieve = 'entity_id', $filter = NULL, 'account_relationship = 8');
     $costFinancialType = array();
     CRM_Core_PseudoConstant::populate($costFinancialType, 'CRM_Financial_DAO_EntityFinancialAccount', $all = TRUE, $retrieve = 'entity_id', $filter = NULL, 'account_relationship = 7');
     $productFinancialType = array_intersect($costFinancialType, $premiumFinancialType);
     foreach ($financialType as $key => $financialTypeName) {
         if (!in_array($key, $productFinancialType)) {
             unset($financialType[$key]);
         }
     }
     if (count($financialType)) {
         $this->assign('financialType', $financialType);
     }
     $this->add('select', 'financial_type_id', ts('Financial Type'), array('' => ts('- select -')) + $financialType);
     $this->add('checkbox', 'is_active', ts('Enabled?'));
     $this->addFormRule(array('CRM_Contribute_Form_ManagePremiums', 'formRule'));
     $this->addButtons(array(array('type' => 'upload', 'name' => ts('Save'), 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
     $this->assign('productId', $this->_id);
 }
 /**
  * Function to build the form
  *
  * @return None
  * @access public
  */
 function buildQuickForm()
 {
     parent::buildQuickForm();
     $this->applyFilter('__ALL__', 'trim');
     $this->add('text', 'api_username', ts('API Username'), array('size' => 30, 'maxlen' => 30), true);
     $this->add('text', 'api_subject', ts('API Subject'), array('size' => 30, 'maxlen' => 30));
     $environment = array('live' => 'live', 'sandbox' => 'sandbox', 'beta-sandbox' => 'beta-sandbox');
     $this->add('select', 'api_environment', ts('API Environment'), $environment, true);
     $this->add('file', 'uploadFile', ts('API SSL Certificate'), "size=30 maxlength=60", true);
     $this->addRule('uploadFile', ts('File size should be less than 8192 bytes'), 'maxfilesize', 8192);
     $this->addRule('uploadFile', ts('A valid file must be uploaded.'), 'uploadedfile');
     $this->addButtons(array(array('type' => 'upload', 'name' => ts('Save'), 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel'))));
 }
 /**
  * Build the form object.
  */
 public function buildQuickForm()
 {
     parent::buildQuickForm();
     $this->setPageTitle(ts('Financial Account'));
     if ($this->_action & CRM_Core_Action::DELETE) {
         return;
     }
     $this->applyFilter('__ALL__', 'trim');
     $attributes = CRM_Core_DAO::getAttribute('CRM_Financial_DAO_FinancialAccount');
     $this->add('text', 'name', ts('Name'), $attributes['name'], TRUE);
     $this->addRule('name', ts('A financial type with this name already exists. Please select another name.'), 'objectExists', array('CRM_Financial_DAO_FinancialAccount', $this->_id));
     $this->add('text', 'description', ts('Description'), $attributes['description']);
     $this->add('text', 'accounting_code', ts('Accounting Code'), $attributes['accounting_code']);
     $elementAccounting = $this->add('text', 'account_type_code', ts('Account Type Code'), $attributes['account_type_code']);
     $this->addEntityRef('contact_id', ts('Owner'), array('api' => array('params' => array('contact_type' => 'Organization')), 'create' => TRUE));
     $this->add('text', 'tax_rate', ts('Tax Rate'), $attributes['tax_rate']);
     $this->add('checkbox', 'is_deductible', ts('Tax-Deductible?'));
     $elementActive = $this->add('checkbox', 'is_active', ts('Enabled?'));
     $this->add('checkbox', 'is_tax', ts('Is Tax?'));
     $element = $this->add('checkbox', 'is_default', ts('Default?'));
     // CRM-12470 freeze is default if is_default is set
     if ($this->_id && CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialAccount', $this->_id, 'is_default')) {
         $element->freeze();
     }
     //CRM-16189
     if (CRM_Contribute_BAO_Contribution::checkContributeSettings('financial_account_bal_enable')) {
         $this->add('text', 'opening_balance', ts('Opening Balance'), $attributes['opening_balance']);
         $this->add('text', 'current_period_opening_balance', ts('Current Period Opening Balance'), $attributes['current_period_opening_balance']);
         $financialAccountType = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_FinancialAccount', 'financial_account_type_id', array('labelColumn' => 'name'));
         $limitedAccount = array(array_search('Asset', $financialAccountType), array_search('Liability', $financialAccountType));
         $this->assign('limitedAccount', json_encode($limitedAccount));
     }
     $financialAccountType = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_FinancialAccount', 'financial_account_type_id');
     if (!empty($financialAccountType)) {
         $element = $this->add('select', 'financial_account_type_id', ts('Financial Account Type'), array('' => '- select -') + $financialAccountType, TRUE, array('class' => 'crm-select2 huge'));
         if ($this->_isARFlag) {
             $element->freeze();
             $elementAccounting->freeze();
             $elementActive->freeze();
         } elseif ($this->_id && CRM_Financial_BAO_FinancialAccount::validateFinancialAccount($this->_id)) {
             $element->freeze();
         }
     }
     if ($this->_action == CRM_Core_Action::UPDATE && CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialAccount', $this->_id, 'is_reserved')) {
         $this->freeze(array('name', 'description', 'is_active'));
     }
     $this->addFormRule(array('CRM_Financial_Form_FinancialAccount', 'formRule'), $this);
 }
 /**
  * Function to build the form
  *
  * @return None
  * @access public
  */
 function buildQuickForm()
 {
     parent::buildQuickForm();
     if ($this->_action & CRM_CORE_ACTION_DELETE) {
         return;
     }
     $this->applyFilter('__ALL__', 'trim');
     $this->add('text', 'name', ts('Name'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_PaymentInstrument', 'name'));
     $this->addRule('name', ts('Please enter a valid Payment Instrument name.'), 'required');
     $this->addRule('name', ts('Name already exists in Database.'), 'objectExists', array('CRM_Contribute_DAO_PaymentInstrument', $this->_id));
     $this->add('text', 'description', ts('Description'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_PaymentInstrument', 'description'));
     $this->add('checkbox', 'is_active', ts('Enabled?'));
     if ($this->_action == CRM_CORE_ACTION_UPDATE && CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_PaymentInstrument', $this->_id, 'is_reserved')) {
         $this->freeze(array('name', 'description', 'is_active'));
     }
 }
 /**
  * Function to build the form
  *
  * @return None
  * @access public
  */
 public function buildQuickForm()
 {
     parent::buildQuickForm();
     if ($this->_action & CRM_Core_Action::DELETE) {
         return;
     }
     $this->applyFilter('__ALL__', 'trim');
     $this->add('text', 'name', ts('Name'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionType', 'name'), TRUE);
     $this->addRule('name', ts('A contribution type with this name already exists. Please select another name.'), 'objectExists', array('CRM_Contribute_DAO_ContributionType', $this->_id));
     $this->add('text', 'description', ts('Description'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionType', 'description'));
     $this->add('text', 'accounting_code', ts('Accounting Code'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionType', 'accounting_code'));
     $this->add('checkbox', 'is_deductible', ts('Tax-deductible?'));
     $this->add('checkbox', 'is_active', ts('Enabled?'));
     if ($this->_action == CRM_Core_Action::UPDATE && CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionType', $this->_id, 'is_reserved')) {
         $this->freeze(array('name', 'description', 'is_active'));
     }
 }
 /**
  * Function to build the form
  *
  * @return void
  * @access public
  */
 public function buildQuickForm()
 {
     parent::buildQuickForm();
     $dataURL = CRM_Utils_System::url('civicrm/ajax/rest', 'className=CRM_Contact_Page_AJAX&fnName=getContactList&json=1&context=contact&org=1', FALSE, NULL, FALSE);
     $this->assign('dataURL', $dataURL);
     if ($this->_action & CRM_Core_Action::DELETE) {
         return;
     }
     $this->applyFilter('__ALL__', 'trim');
     $attributes = CRM_Core_DAO::getAttribute('CRM_Financial_DAO_FinancialAccount');
     $this->add('text', 'name', ts('Name'), $attributes['name'], TRUE);
     $this->addRule('name', ts('A financial type with this name already exists. Please select another name.'), 'objectExists', array('CRM_Financial_DAO_FinancialAccount', $this->_id));
     $this->add('text', 'description', ts('Description'), $attributes['description']);
     $this->add('text', 'accounting_code', ts('Accounting Code'), $attributes['accounting_code']);
     $elementAccounting = $this->add('text', 'account_type_code', ts('Account Type Code'), $attributes['account_type_code']);
     $this->add('text', 'contact_name', ts('Owner'), $attributes['name']);
     $this->add('hidden', 'contact_id', '', array('id' => 'contact_id'));
     $this->add('text', 'tax_rate', ts('Tax Rate'), $attributes['tax_rate']);
     $this->add('checkbox', 'is_deductible', ts('Tax-Deductible?'));
     $elementActive = $this->add('checkbox', 'is_active', ts('Enabled?'));
     $this->add('checkbox', 'is_tax', ts('Is Tax?'));
     $element = $this->add('checkbox', 'is_default', ts('Default?'));
     // CRM-12470 freeze is default if is_default is set
     if ($this->_id && CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialAccount', $this->_id, 'is_default')) {
         $element->freeze();
     }
     $financialAccountType = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_FinancialAccount', 'financial_account_type_id');
     if (!empty($financialAccountType)) {
         $element = $this->add('select', 'financial_account_type_id', ts('Financial Account Type'), array('' => '- select -') + $financialAccountType, TRUE);
         if ($this->_isARFlag) {
             $element->freeze();
             $elementAccounting->freeze();
             $elementActive->freeze();
         }
     }
     if ($this->_action == CRM_Core_Action::UPDATE && CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialAccount', $this->_id, 'is_reserved')) {
         $this->freeze(array('name', 'description', 'is_active'));
     }
     $this->addFormRule(array('CRM_Financial_Form_FinancialAccount', 'formRule'), $this);
 }
 /**
  * Build the form object.
  */
 public function buildQuickForm()
 {
     if ($this->_batchStatus == 'Closed') {
         $this->add('submit', 'export_batch', ts('Export Batch'));
     }
     // do not build rest of form unless it is open/reopened batch
     if (!in_array($this->_batchStatus, array('Open', 'Reopened'))) {
         return;
     }
     parent::buildQuickForm();
     $this->add('submit', 'close_batch', ts('Close Batch'));
     $this->add('submit', 'export_batch', ts('Close & Export Batch'));
     // text for sort_name
     $this->addElement('text', 'sort_name', ts('Contributor Name or Email'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
     $this->_group = CRM_Core_PseudoConstant::nestedGroup();
     // multiselect for groups
     if ($this->_group) {
         $this->add('select', 'group', ts('Groups'), $this->_group, FALSE, array('id' => 'group', 'multiple' => 'multiple', 'class' => 'crm-select2'));
     }
     $contactTags = CRM_Core_BAO_Tag::getTags();
     if ($contactTags) {
         $this->add('select', 'contact_tags', ts('Tags'), $contactTags, FALSE, array('id' => 'contact_tags', 'multiple' => 'multiple', 'class' => 'crm-select2'));
     }
     CRM_Contribute_BAO_Query::buildSearchForm($this);
     $this->addElement('checkbox', 'toggleSelects', NULL, NULL);
     $this->add('select', 'trans_remove', ts('Task'), array('' => ts('- actions -')) + array('Remove' => ts('Remove from Batch')));
     $this->add('submit', 'rSubmit', ts('Go'), array('class' => 'crm-form-submit', 'id' => 'GoRemove'));
     self::$_entityID = CRM_Utils_Request::retrieve('bid', 'Positive');
     $this->addButtons(array(array('type' => 'submit', 'name' => ts('Search'), 'isDefault' => TRUE)));
     $this->addElement('checkbox', 'toggleSelect', NULL, NULL);
     $this->add('select', 'trans_assign', ts('Task'), array('' => ts('- actions -')) + array('Assign' => ts('Assign to Batch')));
     $this->add('submit', 'submit', ts('Go'), array('class' => 'crm-form-submit', 'id' => 'Go'));
     $this->applyFilter('__ALL__', 'trim');
     $this->addElement('hidden', 'batch_id', self::$_entityID);
     $this->add('text', 'name', ts('Batch Name'));
 }
 /**
  * Function to build the form
  *
  * @return void
  * @access public
  */
 public function buildQuickForm()
 {
     if ($this->_action & CRM_Core_Action::DELETE) {
         $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete Financial Account Type'), 'spacing' => '         ', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
         return;
     }
     parent::buildQuickForm();
     if (isset($this->_id)) {
         $params = array('id' => $this->_id);
         CRM_Financial_BAO_FinancialTypeAccount::retrieve($params, $defaults);
         $this->setDefaults($defaults);
         $financialAccountTitle = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialAccount', $defaults['financial_account_id'], 'name');
     }
     $this->applyFilter('__ALL__', 'trim');
     if ($this->_action == CRM_Core_Action::UPDATE) {
         $this->assign('aid', $this->_id);
         //hidden field to catch the group id in profile
         $this->add('hidden', 'financial_type_id', $this->_aid);
         //hidden field to catch the field id in profile
         $this->add('hidden', 'account_type_id', $this->_id);
     }
     $AccountTypeRelationship = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship');
     if (!empty($AccountTypeRelationship)) {
         $element = $this->add('select', 'account_relationship', ts('Financial Account Relationship'), array('select' => '- select -') + $AccountTypeRelationship, TRUE);
     }
     if ($this->_isARFlag) {
         $element->freeze();
     }
     if ($this->_action == CRM_Core_Action::ADD) {
         if (!empty($this->_submitValues['account_relationship']) || !empty($this->_submitValues['financial_account_id'])) {
             $financialAccountType = array('5' => 5, '3' => 1, '1' => 3, '6' => 1, '7' => 4, '8' => 1, '9' => 3);
             $financialAccountType = CRM_Utils_Array::value($this->_submitValues['account_relationship'], $financialAccountType);
             $result = CRM_Contribute_PseudoConstant::financialAccount(NULL, $financialAccountType);
             $financialAccountSelect = array('' => ts('- select -')) + $result;
         } else {
             $financialAccountSelect = array('select' => ts('- select -')) + CRM_Contribute_PseudoConstant::financialAccount();
         }
     }
     if ($this->_action == CRM_Core_Action::UPDATE) {
         $financialAccountType = array('5' => 5, '3' => 1, '1' => 3, '6' => 1, '7' => 4, '8' => 1, '9' => 3);
         $financialAccountType = $financialAccountType[$this->_defaultValues['account_relationship']];
         $result = CRM_Contribute_PseudoConstant::financialAccount(NULL, $financialAccountType);
         $financialAccountSelect = array('' => ts('- select -')) + $result;
     }
     $this->add('select', 'financial_account_id', ts('Financial Account'), $financialAccountSelect, TRUE);
     $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'isDefault' => TRUE), array('type' => 'next', 'name' => ts('Save and New'), 'subName' => 'new'), array('type' => 'cancel', 'name' => ts('Cancel'))));
     $this->addFormRule(array('CRM_Financial_Form_FinancialTypeAccount', 'formRule'), $this);
 }