示例#1
0
 /**
  * Get the financial account for the item associated with the new transaction.
  *
  * @param array $params
  * @param CRM_Financial_BAO_FinancialItem $prevFinancialItem
  *
  * @return int
  */
 public static function getFinancialAccountForStatusChangeTrxn($params, $prevFinancialItem)
 {
     if (!empty($params['financial_account_id'])) {
         return $params['financial_account_id'];
     }
     $contributionStatus = CRM_Contribute_PseudoConstant::contributionStatus($params['contribution_status_id'], 'name');
     $preferredAccountsRelationships = array('Refunded' => 'Credit/Contra Revenue Account is', 'Chargeback' => 'Chargeback Account is');
     if (in_array($contributionStatus, array_keys($preferredAccountsRelationships))) {
         $financialTypeID = !empty($params['financial_type_id']) ? $params['financial_type_id'] : $params['prevContribution']->financial_type_id;
         return CRM_Financial_BAO_FinancialAccount::getFinancialAccountForFinancialTypeByRelationship($financialTypeID, $preferredAccountsRelationships[$contributionStatus]);
     }
     return $prevFinancialItem->financial_account_id;
 }
 /**
  * Test getting financial account for a given financial Type with a particular relationship.
  */
 public function testGetFinancialAccountByFinancialTypeAndRelationshipCustomAddedRefunded()
 {
     $financialAccount = $this->callAPISuccess('FinancialAccount', 'create', array('name' => 'Refund Account', 'is_active' => TRUE));
     $this->callAPISuccess('EntityFinancialAccount', 'create', array('entity_id' => 2, 'entity_table' => 'civicrm_financial_type', 'account_relationship' => 'Credit/Contra Revenue Account is', 'financial_account_id' => 'Refund Account'));
     $this->assertEquals($financialAccount['id'], CRM_Financial_BAO_FinancialAccount::getFinancialAccountForFinancialTypeByRelationship(2, 'Credit/Contra Revenue Account is'));
 }