Merge pull request #6471 from eileenmcnaughton/master
[civicrm-core.git] / CRM / Financial / Form / FinancialAccount.php
index d5878d37439fd3d9c7e2000d5e61cd5164a607e5..df77d7d9420473022c10dd22710896b9f17310bf 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014                                |
+ | Copyright CiviCRM LLC (c) 2004-2015                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
  | GNU Affero General Public License or the licensing of CiviCRM,     |
  | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
  +--------------------------------------------------------------------+
-*/
+ */
 
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2014
+ * @copyright CiviCRM LLC (c) 2004-2015
  * $Id$
  *
  */
@@ -40,7 +40,7 @@
 class CRM_Financial_Form_FinancialAccount extends CRM_Contribute_Form {
 
   /**
-   * Flag if its a AR account type
+   * Flag if its a AR account type.
    *
    * @var boolean
    */
@@ -48,7 +48,7 @@ class CRM_Financial_Form_FinancialAccount extends CRM_Contribute_Form {
 
 
   /**
-   * Set variables up before form is built
+   * Set variables up before form is built.
    *
    * @return void
    */
@@ -63,7 +63,8 @@ class CRM_Financial_Form_FinancialAccount extends CRM_Contribute_Form {
       $financialAccountType = CRM_Core_PseudoConstant::accountOptionValues('financial_account_type');
       if ($financialAccount->financial_account_type_id == array_search('Asset', $financialAccountType)
         && strtolower($financialAccount->account_type_code) == 'ar'
-        && !CRM_Financial_BAO_FinancialAccount::getARAccounts($this->_id, array_search('Asset', $financialAccountType))) {
+        && !CRM_Financial_BAO_FinancialAccount::getARAccounts($this->_id, array_search('Asset', $financialAccountType))
+      ) {
         $this->_isARFlag = TRUE;
         if ($this->_action & CRM_Core_Action::DELETE) {
           $msg = ts("The selected financial account cannot be deleted because at least one Accounts Receivable type account is required (to ensure that accounting transactions are in balance).");
@@ -74,12 +75,12 @@ class CRM_Financial_Form_FinancialAccount extends CRM_Contribute_Form {
   }
 
   /**
-   * Build the form object
+   * Build the form object.
    *
    * @return void
    */
-  public function buildQuickForm( ) {
-    parent::buildQuickForm( );
+  public function buildQuickForm() {
+    parent::buildQuickForm();
     $this->setPageTitle(ts('Financial Account'));
 
     if ($this->_action & CRM_Core_Action::DELETE) {
@@ -95,7 +96,10 @@ class CRM_Financial_Form_FinancialAccount extends CRM_Contribute_Form {
     $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->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?'));
@@ -119,36 +123,36 @@ class CRM_Financial_Form_FinancialAccount extends CRM_Contribute_Form {
     }
 
     if ($this->_action == CRM_Core_Action::UPDATE &&
-      CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialAccount', $this->_id, 'is_reserved')) {
+      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
+   * Global validation rules for the form.
    *
-   * @param $values
+   * @param array $values
+   *   posted values of the form
    * @param $files
    * @param $self
    *
-   * @internal param array $fields posted values of the form
-   *
-   * @return array list of errors to be posted back to the form
-   * @static
+   * @return array
+   *   list of errors to be posted back to the form
    */
-  public static function formRule( $values, $files, $self ) {
-    $errorMsg = array( );
+  public static function formRule($values, $files, $self) {
+    $errorMsg = array();
     $financialAccountTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('financial_account_type', NULL, " AND v.name LIKE 'Liability' "));
     if (isset($values['is_tax'])) {
-      if ($values['financial_account_type_id'] !=  $financialAccountTypeId) {
+      if ($values['financial_account_type_id'] != $financialAccountTypeId) {
         $errorMsg['financial_account_type_id'] = ts('Taxable accounts should have Financial Account Type set to Liability.');
       }
       if (CRM_Utils_Array::value('tax_rate', $values) == NULL) {
         $errorMsg['tax_rate'] = ts('Please enter value for tax rate');
       }
     }
-    if ((CRM_Utils_Array::value('tax_rate', $values) != NULL))  {
+    if ((CRM_Utils_Array::value('tax_rate', $values) != NULL)) {
       if ($values['tax_rate'] < 0 || $values['tax_rate'] >= 100) {
         $errorMsg['tax_rate'] = ts('Tax Rate Should be between 0 - 100');
       }
@@ -157,8 +161,8 @@ class CRM_Financial_Form_FinancialAccount extends CRM_Contribute_Form {
       if (!(isset($values['is_tax']))) {
         $relationshipId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Sales Tax Account is' "));
         $params = array(
-          'financial_account_id'  => $self->_id,
-          'account_relationship'=> $relationshipId
+          'financial_account_id' => $self->_id,
+          'account_relationship' => $relationshipId,
         );
         $result = CRM_Financial_BAO_FinancialTypeAccount::retrieve($params, $defaults);
         if ($result) {
@@ -166,7 +170,7 @@ class CRM_Financial_Form_FinancialAccount extends CRM_Contribute_Form {
         }
       }
     }
-    return CRM_Utils_Array::crmIsEmptyArray( $errorMsg ) ? true : $errorMsg;
+    return CRM_Utils_Array::crmIsEmptyArray($errorMsg) ? TRUE : $errorMsg;
   }
 
   /**
@@ -185,17 +189,17 @@ class CRM_Financial_Form_FinancialAccount extends CRM_Contribute_Form {
   }
 
   /**
-   * Process the form submission
+   * Process the form submission.
    *
    * @return void
    */
   public function postProcess() {
     if ($this->_action & CRM_Core_Action::DELETE) {
       CRM_Financial_BAO_FinancialAccount::del($this->_id);
-      CRM_Core_Session::setStatus( ts('Selected Financial Account has been deleted.') );
+      CRM_Core_Session::setStatus(ts('Selected Financial Account has been deleted.'));
     }
     else {
-      $ids = array( );
+      $ids = array();
       // store the submitted values in an array
       $params = $this->exportValues();