Exemplo n.º 1
0
 /**
  * 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;
 }
Exemplo n.º 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;
     }
 }
Exemplo n.º 3
0
 /**
  * Returns the list of fields that can be exported
  *
  * @param bool $prefix
  *
  * @return array
  */
 static function &export($prefix = false)
 {
     if (!self::$_export) {
         self::$_export = array();
         $fields = self::fields();
         foreach ($fields as $name => $field) {
             if (CRM_Utils_Array::value('export', $field)) {
                 if ($prefix) {
                     self::$_export['entity_financial_trxn'] =& $fields[$name];
                 } else {
                     self::$_export[$name] =& $fields[$name];
                 }
             }
         }
     }
     return self::$_export;
 }
 /**
  * check method create()
  */
 function testCreate()
 {
     $firstName = 'Shane';
     $lastName = 'Whatson';
     $params = array('first_name' => $firstName, 'last_name' => $lastName, 'contact_type' => 'Individual');
     $contact = CRM_Contact_BAO_Contact::add($params);
     $price = 100.0;
     $cParams = array('contact_id' => $contact->id, 'total_amount' => $price, 'financial_type_id' => 1, 'is_active' => 1, 'skipLineItem' => 1);
     $defaults = array();
     $contribution = CRM_Contribute_BAO_Contribution::add($cParams, $defaults);
     $lParams = array('entity_id' => $contribution->id, 'entity_table' => 'civicrm_contribution', 'price_field_id' => 1, 'qty' => 1, 'label' => 'Contribution Amount', 'unit_price' => $price, 'line_total' => $price, 'price_field_value_id' => 1, 'financial_type_id' => 1);
     $lineItem = CRM_Price_BAO_LineItem::create($lParams);
     $fParams = array('contact_id' => $contact->id, 'description' => 'Contribution Amount', 'amount' => $price, 'financial_account_id' => 1, 'status_id' => 1, 'transaction_date' => date('YmdHis'), 'entity_id' => $lineItem->id, 'entity_table' => 'civicrm_line_item');
     CRM_Financial_BAO_FinancialItem::create($fParams);
     $entityTrxn = new CRM_Financial_DAO_EntityFinancialTrxn();
     $entityTrxn->entity_table = 'civicrm_contribution';
     $entityTrxn->entity_id = $contribution->id;
     $entityTrxn->amount = $price;
     if ($entityTrxn->find(TRUE)) {
         $entityId = $entityTrxn->entity_id;
     }
     $result = $this->assertDBNotNull('CRM_Financial_DAO_FinancialItem', $lineItem->id, 'amount', 'entity_id', 'Database check on added financial item record.');
     $this->assertEquals($result, $price, 'Verify Amount for Financial Item');
     $entityResult = $this->assertDBNotNull('CRM_Financial_DAO_EntityFinancialTrxn', $entityId, 'amount', 'entity_id', 'Database check on added entity financial trxn record.');
     $this->assertEquals($entityResult, $price, 'Verify Amount for Financial Item');
 }