Merge remote-tracking branch 'upstream/4.3' into 4.3-master-2013-05-21-13-15-18
[civicrm-core.git] / CRM / Financial / Form / FinancialAccount.php
index 1279e7340bf0fd8d385564622d6f4fbaadfacc68..c418a31580c99f6fc83732a0c9917f0ec79fef5a 100644 (file)
@@ -1,5 +1,4 @@
 <?php
-
 /*
  +--------------------------------------------------------------------+
  | CiviCRM version 4.3                                                |
@@ -36,7 +35,7 @@
 
 /**
  * This class generates form components for Financial Account
- * 
+ *
  */
 class CRM_Financial_Form_FinancialAccount extends CRM_Contribute_Form {
 
@@ -92,13 +91,13 @@ class CRM_Financial_Form_FinancialAccount extends CRM_Contribute_Form {
     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']);
@@ -108,11 +107,13 @@ class CRM_Financial_Form_FinancialAccount extends CRM_Contribute_Form {
     $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::accountOptionValues('financial_account_type');
     if (!empty($financialAccountType)) {
       $element = $this->add('select', 'financial_account_type_id', ts('Financial Account Type'),
@@ -123,14 +124,14 @@ class CRM_Financial_Form_FinancialAccount extends CRM_Contribute_Form {
         $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);
   }
-  
+
   /**
    * global validation rules for the form
    *
@@ -149,7 +150,7 @@ class CRM_Financial_Form_FinancialAccount extends CRM_Contribute_Form {
     }
     return CRM_Utils_Array::crmIsEmptyArray( $errorMsg ) ? true : $errorMsg;
   }
-  
+
   /**
    * This function sets the default values for the form.
    * the default values are retrieved from the database
@@ -166,7 +167,7 @@ class CRM_Financial_Form_FinancialAccount extends CRM_Contribute_Form {
     }
     return $defaults;
   }
-  
+
   /**
    * Function to process the form
    *
@@ -182,11 +183,11 @@ class CRM_Financial_Form_FinancialAccount extends CRM_Contribute_Form {
       $ids = array( );
       // store the submitted values in an array
       $params = $this->exportValues();
-      
+
       if ($this->_action & CRM_Core_Action::UPDATE) {
         $ids['contributionType'] = $this->_id;
       }
-      
+
       $contributionType = CRM_Financial_BAO_FinancialAccount::add($params, $ids);
       CRM_Core_Session::setStatus(ts('The Financial Account \'%1\' has been saved.', array(1 => $contributionType->name)));
     }