Merge pull request #1839 from dlobo/CRM-13633
[civicrm-core.git] / CRM / Contribute / Form / Contribution.php
index 98f661b8f30254e6fd47da5776d9194db3774058..fc31ea359b959ef7e1982375ff408fe42792f81e 100644 (file)
@@ -318,7 +318,7 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
       $billingDefaults = $this->getProfileDefaults('Billing', $this->_contactID);
       $defaults = array_merge($defaults, $billingDefaults);
 
-      // now fix all state country selectors (FIXME: what does this do ?? dgg)
+      // now fix all state country selectors, set correct state based on country
       CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults);
     }
 
@@ -930,17 +930,9 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
     }
 
     //FIXME FOR NEW DATA FLOW http://wiki.civicrm.org/confluence/display/CRM/CiviAccounts+4.3+Data+Flow
-    if (CRM_Utils_Array::value('fee_amount', $fields)) {
-      $financialAccount = array();
-      CRM_Core_PseudoConstant::populate($financialAccount,
-        'CRM_Financial_DAO_EntityFinancialAccount',
-        $all = TRUE,
-        $retrieve = 'financial_account_id',
-        $filter = NULL,
-        " account_relationship = 5 AND entity_id = {$fields['financial_type_id']} ");
-      if (!current($financialAccount)) {
-        $errors['financial_type_id'] = ts("Financial Account of account relationship of 'Expense Account is' is not configured for this Financial Type");
-      }
+     if (CRM_Utils_Array::value('fee_amount', $fields) 
+      && $financialType = CRM_Contribute_BAO_Contribution::validateFinancialType($fields['financial_type_id'])) {
+      $errors['financial_type_id'] = ts("Financial Account of account relationship of 'Expense Account is' is not configured for Financial Type : ") . $financialType;  
     }
 
     $errors = array_merge($errors, $softErrors);
@@ -1029,8 +1021,10 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
       }
       $lineItems[$itemId]['unit_price'] = $lineItems[$itemId]['line_total'] = CRM_Utils_Rule::cleanMoney(CRM_Utils_Array::value('total_amount', $submittedValues));
       // 10117 update th line items for participants
-      $this->_priceSetId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', $lineItems[$itemId]['price_field_id'], 'price_set_id');
-      $lineItem[$this->_priceSetId] = $lineItems;
+      if (!empty($lineItems[$itemId]['price_field_id'])) {
+        $this->_priceSetId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', $lineItems[$itemId]['price_field_id'], 'price_set_id');
+        $lineItem[$this->_priceSetId] = $lineItems;
+      }
     }
     $isQuickConfig = 0;
     if ($this->_priceSetId && CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config')) {