/**
  * 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
 /**
  * Retrive entity financial trxn details.
  *
  * @param array $params
  *   (reference ) an assoc array of name/value pairs.
  * @param bool $maxId
  *   To retrive max id.
  *
  * @return array
  */
 public static function retrieveEntityFinancialTrxn($params, $maxId = FALSE)
 {
     $financialItem = new CRM_Financial_DAO_EntityFinancialTrxn();
     $financialItem->copyValues($params);
     //retrieve last entry from civicrm_entity_financial_trxn
     if ($maxId) {
         $financialItem->orderBy('id DESC');
         $financialItem->limit(1);
     }
     $financialItem->find();
     while ($financialItem->fetch()) {
         $financialItems[$financialItem->id] = array('id' => $financialItem->id, 'entity_table' => $financialItem->entity_table, 'entity_id' => $financialItem->entity_id, 'financial_trxn_id' => $financialItem->financial_trxn_id, 'amount' => $financialItem->amount);
     }
     if (!empty($financialItems)) {
         return $financialItems;
     } else {
         return NULL;
     }
 }