/**
  * Takes an associative array and creates a financial transaction object.
  *
  * @param array $params
  *   (reference ) an assoc array of name/value pairs.
  *
  * @param string $trxnEntityTable
  *   Entity_table.
  *
  * @return CRM_Core_BAO_FinancialTrxn
  */
 public static function create(&$params, $trxnEntityTable = NULL)
 {
     $trxn = new CRM_Financial_DAO_FinancialTrxn();
     $trxn->copyValues($params);
     if (!CRM_Utils_Rule::currencyCode($trxn->currency)) {
         $trxn->currency = CRM_Core_Config::singleton()->defaultCurrency;
     }
     $trxn->save();
     // save to entity_financial_trxn table
     $entityFinancialTrxnParams = array('entity_table' => "civicrm_contribution", 'financial_trxn_id' => $trxn->id, 'amount' => $params['total_amount'], 'currency' => $trxn->currency);
     if (!empty($trxnEntityTable)) {
         $entityFinancialTrxnParams['entity_table'] = $trxnEntityTable['entity_table'];
         $entityFinancialTrxnParams['entity_id'] = $trxnEntityTable['entity_id'];
     } else {
         $entityFinancialTrxnParams['entity_id'] = $params['contribution_id'];
     }
     $entityTrxn = new CRM_Financial_DAO_EntityFinancialTrxn();
     $entityTrxn->copyValues($entityFinancialTrxnParams);
     $entityTrxn->save();
     return $trxn;
 }
Exemple #2
0
 /**
  * Takes an associative array and creates a entity financial transaction object.
  *
  * @param array $params
  *   (reference ) an assoc array of name/value pairs.
  *
  * @return CRM_Core_BAO_FinancialTrxn
  */
 public static function createEntityTrxn($params)
 {
     $entity_trxn = new CRM_Financial_DAO_EntityFinancialTrxn();
     $entity_trxn->copyValues($params);
     $entity_trxn->save();
     return $entity_trxn;
 }