From 50f8ceb16e35e785abe073712c93b6b9a5613590 Mon Sep 17 00:00:00 2001 From: "deb.monish" Date: Fri, 4 Aug 2017 16:37:29 +0530 Subject: [PATCH] additional fixes --- CRM/Contribute/BAO/Contribution.php | 4 +-- CRM/Core/BAO/FinancialTrxn.php | 44 +++++++++++++---------------- CRM/Financial/Form/PaymentEdit.php | 3 +- CRM/Price/BAO/LineItem.php | 6 ++-- api/v3/FinancialTrxn.php | 7 +++-- 5 files changed, 30 insertions(+), 34 deletions(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 2c4256c218..9b6f189f0b 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -4177,7 +4177,7 @@ WHERE eft.financial_trxn_id IN ({$trxnId}, {$baseTrxnId['financialTrxnId']}) 'name' => "", '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, ) ); } diff --git a/CRM/Core/BAO/FinancialTrxn.php b/CRM/Core/BAO/FinancialTrxn.php index b2db2603bd..e14c607ec1 100644 --- a/CRM/Core/BAO/FinancialTrxn.php +++ b/CRM/Core/BAO/FinancialTrxn.php @@ -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'])) { diff --git a/CRM/Financial/Form/PaymentEdit.php b/CRM/Financial/Form/PaymentEdit.php index 9a5b21c297..368de6c553 100644 --- a/CRM/Financial/Form/PaymentEdit.php +++ b/CRM/Financial/Form/PaymentEdit.php @@ -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 * diff --git a/CRM/Price/BAO/LineItem.php b/CRM/Price/BAO/LineItem.php index 066da4aa1a..81ea647c01 100644 --- a/CRM/Price/BAO/LineItem.php +++ b/CRM/Price/BAO/LineItem.php @@ -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", diff --git a/api/v3/FinancialTrxn.php b/api/v3/FinancialTrxn.php index 5e5958b1f9..23f19807cc 100644 --- a/api/v3/FinancialTrxn.php +++ b/api/v3/FinancialTrxn.php @@ -39,10 +39,11 @@ * @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'); } /** -- 2.25.1