additional fixes
authordeb.monish <monish.deb@jmaconsulting.biz>
Fri, 4 Aug 2017 11:07:29 +0000 (16:37 +0530)
committerdeb.monish <monish.deb@jmaconsulting.biz>
Fri, 4 Aug 2017 11:25:41 +0000 (16:55 +0530)
CRM/Contribute/BAO/Contribution.php
CRM/Core/BAO/FinancialTrxn.php
CRM/Financial/Form/PaymentEdit.php
CRM/Price/BAO/LineItem.php
api/v3/FinancialTrxn.php

index 2c4256c218e2f514c643afc94a9e09c34721a4e1..9b6f189f0b6cb997d2a288b8daf4872ca427afaa 100644 (file)
@@ -4177,7 +4177,7 @@ WHERE eft.financial_trxn_id IN ({$trxnId}, {$baseTrxnId['financialTrxnId']})
               'name' => "<i class='crm-i fa-pencil'></i>",
               'url' => 'civicrm/payment/edit',
               'class' => 'medium-popup',
-              'qs' => "reset=1&id=%%id%%&contri_id=%%contri_id%%",
+              'qs' => "reset=1&id=%%id%%&contribution_id=%%contribution_id%%",
               'title' => ts('Edit Payment'),
             ),
           );
@@ -4186,7 +4186,7 @@ WHERE eft.financial_trxn_id IN ({$trxnId}, {$baseTrxnId['financialTrxnId']})
             CRM_Core_Action::mask(array(CRM_Core_Permission::EDIT)),
             array(
               'id' => $resultDAO->id,
-              'contri_id' => $contributionId,
+              'contribution_id' => $contributionId,
             )
           );
         }
index b2db2603bd1392688ea2760ec7562230ad71c26e..e14c607ec1808a19ca3e86b28977b79cf082b7aa 100644 (file)
@@ -50,12 +50,12 @@ class CRM_Core_BAO_FinancialTrxn extends CRM_Financial_DAO_FinancialTrxn {
    * @param array $params
    *   (reference ) an assoc array of name/value pairs.
    *
-   * @param string $trxnEntityTable
-   *   Entity_table.
+   * @param array $ids
+   *   The array that holds all the DB ids.
    *
    * @return CRM_Core_BAO_FinancialTrxn
    */
-  public static function create(&$params, $trxnEntityTable = NULL) {
+  public static function create(&$params, $ids = array()) {
     $trxn = new CRM_Financial_DAO_FinancialTrxn();
     $trxn->copyValues($params);
 
@@ -63,28 +63,25 @@ class CRM_Core_BAO_FinancialTrxn extends CRM_Financial_DAO_FinancialTrxn {
       $trxn->currency = CRM_Core_Config::singleton()->defaultCurrency;
     }
 
-    $trxn->save();
+    //per http://wiki.civicrm.org/confluence/display/CRM/Database+layer we are moving away from $ids array
+    $financialTrxnID = CRM_Utils_Array::value('FinancialTrxn', $ids, CRM_Utils_Array::value('id', $params));
+    $trxn->id = $financialTrxnID;
 
-    // save to entity_financial_trxn table
-    $entityFinancialTrxnParams
-      = array(
-        'entity_table' => "civicrm_contribution",
-        'financial_trxn_id' => $trxn->id,
-        'amount' => $params['total_amount'],
-      );
+    $trxn->save();
 
-    if (!empty($trxnEntityTable)) {
-      $entityFinancialTrxnParams['entity_table'] = $trxnEntityTable['entity_table'];
-      $entityFinancialTrxnParams['entity_id'] = $trxnEntityTable['entity_id'];
-    }
-    elseif (!empty($params['entity_id']) && !empty($params['entity_table'])) {
-      $entityFinancialTrxnParams['entity_table'] = $params['entity_table'];
-      $entityFinancialTrxnParams['entity_id'] = $params['entity_id'];
-    }
-    else {
-      $entityFinancialTrxnParams['entity_id'] = $params['contribution_id'];
+    // we shoudn't proceed further to record related entity financial trxns if it's update
+    if ($financialTrxnID) {
+      return $trxn;
     }
 
+    // save to entity_financial_trxn table
+    $entityFinancialTrxnParams = array(
+      'entity_table' => CRM_Utils_Array::value('entity_table', $params, 'civicrm_contribution'),
+      'entity_id' => CRM_Utils_Array::value('entity_id', $params, CRM_Utils_Array::value('contribution_id', $params)),
+      'financial_trxn_id' => $trxn->id,
+      'amount' => $params['total_amount'],
+    );
+
     $entityTrxn = new CRM_Financial_DAO_EntityFinancialTrxn();
     $entityTrxn->copyValues($entityFinancialTrxnParams);
     $entityTrxn->save();
@@ -370,10 +367,9 @@ WHERE ceft.entity_id = %1";
         'total_amount' => CRM_Utils_Array::value('cost', $params) ? $params['cost'] : 0,
         'currency' => CRM_Utils_Array::value('currency', $params),
         'status_id' => array_search('Completed', $contributionStatuses),
+        'entity_id' => $params['contributionId'],
       );
-      $trxnEntityTable['entity_table'] = 'civicrm_contribution';
-      $trxnEntityTable['entity_id'] = $params['contributionId'];
-      CRM_Core_BAO_FinancialTrxn::create($financialtrxn, $trxnEntityTable);
+      CRM_Core_BAO_FinancialTrxn::create($financialtrxn);
     }
 
     if (!empty($params['oldPremium'])) {
index 9a5b21c297784170908b93c258985afb9ae71804..368de6c553b912525f0979c5c37184222f92955f 100644 (file)
@@ -67,7 +67,7 @@ class CRM_Financial_Form_PaymentEdit extends CRM_Core_Form {
     parent::preProcess();
     $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
     $this->assign('id', $this->_id);
-    $this->_contributionID = CRM_Utils_Request::retrieve('contri_id', 'Positive', $this);
+    $this->_contributionID = CRM_Utils_Request::retrieve('contribution_id', 'Positive', $this);
 
     $this->_values = civicrm_api3('FinancialTrxn', 'getsingle', array('id' => $this->_id));
     if (!empty($this->_values['payment_processor_id'])) {
@@ -177,7 +177,6 @@ class CRM_Financial_Form_PaymentEdit extends CRM_Core_Form {
     CRM_Core_Session::singleton()->pushUserContext(CRM_Utils_System::url(CRM_Utils_System::currentPath()));
   }
 
-
   /**
    * Wrapper function to process form submission
    *
index 066da4aa1a6e6de15c7f33d9bb348ea3bd66398b..81ea647c01bd479807bcd1d74ff616a95b408f2c 100644 (file)
@@ -727,11 +727,11 @@ WHERE li.contribution_id = %1";
         if (!empty($updateFinancialItemInfoValues['financialTrxn']) && ($contributionCompletedStatusID ==
           CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $contributionId, 'contribution_status_id'))
         ) {
-          $trxnTable = array(
+          $updateFinancialItemInfoValues = array_merge($updateFinancialItemInfoValues['financialTrxn'], array(
             'entity_id' => $newFinancialItem->id,
             'entity_table' => 'civicrm_financial_item',
-          );
-          $reverseTrxn = CRM_Core_BAO_FinancialTrxn::create($updateFinancialItemInfoValues['financialTrxn'], $trxnTable);
+          ));
+          $reverseTrxn = CRM_Core_BAO_FinancialTrxn::create($updateFinancialItemInfoValues['financialTrxn']);
           // record reverse entity financial trxn linked to membership's related contribution
           civicrm_api3('EntityFinancialTrxn', 'create', array(
             'entity_table' => "civicrm_contribution",
index 5e5958b1f94100bf9115264496582bf7aef6332f..23f19807cc152625a9327b684527cc84c827fe7e 100644 (file)
  * @return array
  */
 function civicrm_api3_financial_trxn_create($params) {
-  if (empty($params['contribution_id']) && (empty($params['entity_table']) && empty($params['entity_id']))) {
-    return civicrm_api3_create_error('Please provide finanical trxn entity details.');
+  if (empty($params['id']) && empty($params['contribution_id']) && empty($params['entity_id'])) {
+    throw new API_Exception("Mandatory key(s) missing from params array: both contribution_id and entity_id are missing");
   }
-  return _civicrm_api3_basic_create('CRM_Core_BAO_FinancialTrxn', $params);
+
+  return _civicrm_api3_basic_create('CRM_Core_BAO_FinancialTrxn', $params, 'FinancialTrxn');
 }
 
 /**