Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move CRM_Core_BAO_FinancialTrxn to CRM_Financial_BAO_FinancialTrxn #22400

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions CRM/Contribute/BAO/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -1022,10 +1022,10 @@ protected static function getContributionTransactionInformation($contributionId,
$statuses = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'label');

while ($resultDAO->fetch()) {
$paidByLabel = CRM_Core_PseudoConstant::getLabel('CRM_Core_BAO_FinancialTrxn', 'payment_instrument_id', $resultDAO->payment_instrument_id);
$paidByName = CRM_Core_PseudoConstant::getName('CRM_Core_BAO_FinancialTrxn', 'payment_instrument_id', $resultDAO->payment_instrument_id);
$paidByLabel = CRM_Core_PseudoConstant::getLabel('CRM_Financial_BAO_FinancialTrxn', 'payment_instrument_id', $resultDAO->payment_instrument_id);
$paidByName = CRM_Core_PseudoConstant::getName('CRM_Financial_BAO_FinancialTrxn', 'payment_instrument_id', $resultDAO->payment_instrument_id);
if ($resultDAO->card_type_id) {
$creditCardType = CRM_Core_PseudoConstant::getLabel('CRM_Core_BAO_FinancialTrxn', 'card_type_id', $resultDAO->card_type_id);
$creditCardType = CRM_Core_PseudoConstant::getLabel('CRM_Financial_BAO_FinancialTrxn', 'card_type_id', $resultDAO->card_type_id);
$pantruncation = '';
if ($resultDAO->pan_truncation) {
$pantruncation = ": {$resultDAO->pan_truncation}";
Expand Down Expand Up @@ -1263,7 +1263,7 @@ public static function deleteContribution($id) {
$participantId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $id, 'participant_id', 'contribution_id');

// delete any related entity_financial_trxn, financial_trxn and financial_item records.
CRM_Core_BAO_FinancialTrxn::deleteFinancialTrxn($id);
CRM_Financial_BAO_FinancialTrxn::deleteFinancialTrxn($id);

if ($participantId) {
CRM_Price_BAO_LineItem::deleteLineItems($participantId, 'civicrm_participant');
Expand Down Expand Up @@ -3076,7 +3076,7 @@ public static function isSubscriptionCancelled($contributionId) {
* Contribution object, line item array and params for trxn.
*
*
* @return null|\CRM_Core_BAO_FinancialTrxn
* @return null|\CRM_Financial_BAO_FinancialTrxn
*/
public static function recordFinancialAccounts(&$params) {
$skipRecords = $return = FALSE;
Expand Down Expand Up @@ -3238,7 +3238,7 @@ public static function recordFinancialAccounts(&$params) {
$params['prevContribution']->financial_type_id, $accountRelationship);
}
else {
$lastFinancialTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($params['prevContribution']->id, 'DESC');
$lastFinancialTrxnId = CRM_Financial_BAO_FinancialTrxn::getFinancialTrxnId($params['prevContribution']->id, 'DESC');
if (!empty($lastFinancialTrxnId['financialTrxnId'])) {
$params['trxnParams']['to_financial_account_id'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialTrxn', $lastFinancialTrxnId['financialTrxnId'], 'to_financial_account_id');
}
Expand All @@ -3250,7 +3250,7 @@ public static function recordFinancialAccounts(&$params) {
$line['financial_type_id'] = $params['financial_type_id'];
}
}
CRM_Core_BAO_FinancialTrxn::createDeferredTrxn(CRM_Utils_Array::value('line_item', $params), $params['contribution'], TRUE, 'changeFinancialType');
CRM_Financial_BAO_FinancialTrxn::createDeferredTrxn(CRM_Utils_Array::value('line_item', $params), $params['contribution'], TRUE, 'changeFinancialType');
/* $params['trxnParams']['to_financial_account_id'] = $trxnParams['to_financial_account_id']; */
$params['financial_account_id'] = $newFinancialAccount;
$params['total_amount'] = $params['trxnParams']['total_amount'] = $params['trxnParams']['net_amount'] = $trxnParams['total_amount'];
Expand All @@ -3259,7 +3259,7 @@ public static function recordFinancialAccounts(&$params) {
$params['trxnParams']['fee_amount'] = $params['fee_amount'];
}
CRM_Contribute_BAO_FinancialProcessor::updateFinancialAccounts($params);
CRM_Core_BAO_FinancialTrxn::createDeferredTrxn(CRM_Utils_Array::value('line_item', $params), $params['contribution'], TRUE);
CRM_Financial_BAO_FinancialTrxn::createDeferredTrxn(CRM_Utils_Array::value('line_item', $params), $params['contribution'], TRUE);
$params['trxnParams']['to_financial_account_id'] = $trxnParams['to_financial_account_id'];
$updated = TRUE;
$params['deferred_financial_account_id'] = $newFinancialAccount;
Expand All @@ -3281,7 +3281,7 @@ public static function recordFinancialAccounts(&$params) {
$callUpdateFinancialAccounts = CRM_Contribute_BAO_FinancialProcessor::updateFinancialAccountsOnContributionStatusChange($params);
if ($callUpdateFinancialAccounts) {
CRM_Contribute_BAO_FinancialProcessor::updateFinancialAccounts($params, 'changedStatus');
CRM_Core_BAO_FinancialTrxn::createDeferredTrxn(CRM_Utils_Array::value('line_item', $params), $params['contribution'], TRUE, 'changedStatus');
CRM_Financial_BAO_FinancialTrxn::createDeferredTrxn(CRM_Utils_Array::value('line_item', $params), $params['contribution'], TRUE, 'changedStatus');
}
$updated = TRUE;
}
Expand All @@ -3296,7 +3296,7 @@ public static function recordFinancialAccounts(&$params) {
$params['trxnParams']['check_number'] = $params['check_number'] ?? NULL;

if (CRM_Contribute_BAO_FinancialProcessor::isPaymentInstrumentChange($params, $pendingStatus)) {
$updated = CRM_Core_BAO_FinancialTrxn::updateFinancialAccountsOnPaymentInstrumentChange($params);
$updated = CRM_Financial_BAO_FinancialTrxn::updateFinancialAccountsOnPaymentInstrumentChange($params);
}

//if Change contribution amount
Expand All @@ -3310,7 +3310,7 @@ public static function recordFinancialAccounts(&$params) {
//Update Financial Records
$params['trxnParams']['from_financial_account_id'] = NULL;
CRM_Contribute_BAO_FinancialProcessor::updateFinancialAccounts($params, 'changedAmount');
CRM_Core_BAO_FinancialTrxn::createDeferredTrxn(CRM_Utils_Array::value('line_item', $params), $params['contribution'], TRUE, 'changedAmount');
CRM_Financial_BAO_FinancialTrxn::createDeferredTrxn(CRM_Utils_Array::value('line_item', $params), $params['contribution'], TRUE, 'changedAmount');
$updated = TRUE;
}

Expand All @@ -3322,7 +3322,7 @@ public static function recordFinancialAccounts(&$params) {
// the data fix scenario.
// CRM-17751.
if (isset($params['refund_trxn_id'])) {
$refundIDs = CRM_Core_BAO_FinancialTrxn::getRefundTransactionIDs($params['id']);
$refundIDs = CRM_Financial_BAO_FinancialTrxn::getRefundTransactionIDs($params['id']);
if (!empty($refundIDs['financialTrxnId']) && $refundIDs['trxn_id'] != $params['refund_trxn_id']) {
civicrm_api3('FinancialTrxn', 'create', [
'id' => $refundIDs['financialTrxnId'],
Expand All @@ -3332,7 +3332,7 @@ public static function recordFinancialAccounts(&$params) {
}
$cardType = $params['card_type_id'] ?? NULL;
$panTruncation = $params['pan_truncation'] ?? NULL;
CRM_Core_BAO_FinancialTrxn::updateCreditCardDetails($params['contribution']->id, $panTruncation, $cardType);
CRM_Financial_BAO_FinancialTrxn::updateCreditCardDetails($params['contribution']->id, $panTruncation, $cardType);
}
}

Expand All @@ -3342,7 +3342,7 @@ public static function recordFinancialAccounts(&$params) {
CRM_Contribute_BAO_FinancialProcessor::recordAlwaysAccountsReceivable($trxnParams, $params);
$trxnParams['pan_truncation'] = $params['pan_truncation'] ?? NULL;
$trxnParams['card_type_id'] = $params['card_type_id'] ?? NULL;
$return = $financialTxn = CRM_Core_BAO_FinancialTrxn::create($trxnParams);
$return = $financialTxn = CRM_Financial_BAO_FinancialTrxn::create($trxnParams);
$params['entity_id'] = $financialTxn->id;
}
}
Expand All @@ -3364,7 +3364,7 @@ public static function recordFinancialAccounts(&$params) {

// when a fee is charged
if (!empty($params['fee_amount']) && (empty($params['prevContribution']) || $params['contribution']->fee_amount != $params['prevContribution']->fee_amount) && $skipRecords) {
CRM_Core_BAO_FinancialTrxn::recordFees($params);
CRM_Financial_BAO_FinancialTrxn::recordFees($params);
}

if (!empty($params['prevContribution']) && $entityTable == 'civicrm_participant'
Expand Down Expand Up @@ -3597,10 +3597,10 @@ public static function getPaymentInfo($id, $component = 'contribution', $getTrxn

// The balance used to be calculated this way - we really want to remove this 'oldCalculation'
// but need to unpick the whole trxn_id it's returning first.
$oldCalculation = CRM_Core_BAO_FinancialTrxn::getBalanceTrxnAmt($contributionId);
$oldCalculation = CRM_Financial_BAO_FinancialTrxn::getBalanceTrxnAmt($contributionId);
$baseTrxnId = !empty($oldCalculation['trxn_id']) ? $oldCalculation['trxn_id'] : NULL;
if (!$baseTrxnId) {
$baseTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contributionId);
$baseTrxnId = CRM_Financial_BAO_FinancialTrxn::getFinancialTrxnId($contributionId);
$baseTrxnId = $baseTrxnId['financialTrxnId'];
}
$total = CRM_Price_BAO_LineItem::getLineTotal($contributionId);
Expand Down Expand Up @@ -3651,7 +3651,7 @@ public static function getContributionBalance($contributionId, $contributionTota

return (float) CRM_Utils_Money::subtractCurrencies(
$contributionTotal,
CRM_Core_BAO_FinancialTrxn::getTotalPayments($contributionId, TRUE),
CRM_Financial_BAO_FinancialTrxn::getTotalPayments($contributionId, TRUE),
CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $contributionId, 'currency')
);
}
Expand Down
6 changes: 3 additions & 3 deletions CRM/Contribute/BAO/FinancialProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public static function updateFinancialAccounts(&$params, $context = NULL) {
$params['trxnParams']['total_amount'] = $params['trxnParams']['net_amount'] = ($params['total_amount'] - $params['prevContribution']->total_amount);
}

$trxn = CRM_Core_BAO_FinancialTrxn::create($params['trxnParams']);
$trxn = CRM_Financial_BAO_FinancialTrxn::create($params['trxnParams']);
// @todo we should stop passing $params by reference - splitting this out would be a step towards that.
$params['entity_id'] = $trxn->id;

Expand Down Expand Up @@ -312,7 +312,7 @@ public static function updateFinancialAccountsOnContributionStatusChange(&$param
$params['trxnParams']['currency'] = CRM_Utils_Array::value('currency', $params, $params['prevContribution']->currency);

$transactionIDs[] = CRM_Contribute_BAO_FinancialProcessor::recordAlwaysAccountsReceivable($params['trxnParams'], $params);
$trxn = CRM_Core_BAO_FinancialTrxn::create($params['trxnParams']);
$trxn = CRM_Financial_BAO_FinancialTrxn::create($params['trxnParams']);
// @todo we should stop passing $params by reference - splitting this out would be a step towards that.
$params['entity_id'] = $transactionIDs[] = $trxn->id;

Expand Down Expand Up @@ -393,7 +393,7 @@ public static function recordAlwaysAccountsReceivable(&$trxnParams, $contributio
$params['to_financial_account_id'] = $arAccountId;
$params['status_id'] = array_search('Pending', $contributionStatuses);
$params['is_payment'] = FALSE;
$trxn = CRM_Core_BAO_FinancialTrxn::create($params);
$trxn = CRM_Financial_BAO_FinancialTrxn::create($params);
$trxnParams['from_financial_account_id'] = $params['to_financial_account_id'];
return $trxn->id;
}
Expand Down
4 changes: 2 additions & 2 deletions CRM/Contribute/Form/AbstractEditPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ public function buildValuesAndAssignOnline_Note_Type($id, &$values) {

//Check if this is an online transaction (financial_trxn.payment_processor_id NOT NULL)
$this->_online = FALSE;
$fids = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($id);
$fids = CRM_Financial_BAO_FinancialTrxn::getFinancialTrxnId($id);
if (!empty($fids['financialTrxnId'])) {
$this->_online = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialTrxn', $fids['financialTrxnId'], 'payment_processor_id');
}
Expand Down Expand Up @@ -581,7 +581,7 @@ public static function formatCreditCardDetails(&$params) {
$params['month'] = CRM_Core_Payment_Form::getCreditCardExpirationMonth($params);
}
if (!empty($params['credit_card_type'])) {
$params['card_type_id'] = CRM_Core_PseudoConstant::getKey('CRM_Core_BAO_FinancialTrxn', 'card_type_id', $params['credit_card_type']);
$params['card_type_id'] = CRM_Core_PseudoConstant::getKey('CRM_Financial_BAO_FinancialTrxn', 'card_type_id', $params['credit_card_type']);
}
if (!empty($params['credit_card_number']) && empty($params['pan_truncation'])) {
$params['pan_truncation'] = substr($params['credit_card_number'], -4);
Expand Down
2 changes: 1 addition & 1 deletion CRM/Contribute/Form/AdditionalInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public static function processPremium($params, $contributionID, $premiumID = NUL
$premiumParams['oldPremium']['product_id'] = $ContributionProduct->product_id;
$premiumParams['oldPremium']['contribution_id'] = $ContributionProduct->contribution_id;
}
CRM_Core_BAO_FinancialTrxn::createPremiumTrxn($premiumParams);
CRM_Financial_BAO_FinancialTrxn::createPremiumTrxn($premiumParams);
}
}

Expand Down
2 changes: 1 addition & 1 deletion CRM/Contribute/Form/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ public function setDefaultValues() {
// Historically not 'Cancelled' hence not using CRM_Contribute_BAO_Contribution::isContributionStatusNegative.
['Refunded', 'Chargeback']
)) {
$defaults['refund_trxn_id'] = CRM_Core_BAO_FinancialTrxn::getRefundTransactionTrxnID($this->_id);
$defaults['refund_trxn_id'] = CRM_Financial_BAO_FinancialTrxn::getRefundTransactionTrxnID($this->_id);
}
else {
$defaults['refund_trxn_id'] = $defaults['trxn_id'] ?? NULL;
Expand Down
2 changes: 1 addition & 1 deletion CRM/Contribute/Form/Contribution/Confirm.php
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,7 @@ protected function postProcessPremium($premiumParams, $contribution) {
'financial_type_id' => $params['financial_type_id'],
'contributionId' => $contribution->id,
];
CRM_Core_BAO_FinancialTrxn::createPremiumTrxn($trxnParams);
CRM_Financial_BAO_FinancialTrxn::createPremiumTrxn($trxnParams);
}
}
elseif ($selectProduct === 'no_thanks') {
Expand Down
4 changes: 2 additions & 2 deletions CRM/Contribute/Form/ContributionBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -802,9 +802,9 @@ public function assignPaymentFields() {
}
elseif ($paymentField === 'credit_card_type') {
$this->assign('credit_card_type', CRM_Core_PseudoConstant::getLabel(
'CRM_Core_BAO_FinancialTrxn',
'CRM_Financial_BAO_FinancialTrxn',
'card_type_id',
CRM_Core_PseudoConstant::getKey('CRM_Core_BAO_FinancialTrxn', 'card_type_id', $this->_params['credit_card_type'])
CRM_Core_PseudoConstant::getKey('CRM_Financial_BAO_FinancialTrxn', 'card_type_id', $this->_params['credit_card_type'])
));
}
else {
Expand Down
4 changes: 2 additions & 2 deletions CRM/Contribute/Form/ContributionView.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function preProcess() {
}

// get received into i.e to_financial_account_id from last trxn
$financialTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($values['contribution_id'], 'DESC');
$financialTrxnId = CRM_Financial_BAO_FinancialTrxn::getFinancialTrxnId($values['contribution_id'], 'DESC');
$values['to_financial_account'] = '';
if (!empty($financialTrxnId['financialTrxnId'])) {
$values['to_financial_account_id'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialTrxn', $financialTrxnId['financialTrxnId'], 'to_financial_account_id');
Expand Down Expand Up @@ -151,7 +151,7 @@ public function preProcess() {
$values['campaign'] = $campaigns[$campaignId];
}
if ($values['contribution_status'] == 'Refunded') {
$this->assign('refund_trxn_id', CRM_Core_BAO_FinancialTrxn::getRefundTransactionTrxnID($id));
$this->assign('refund_trxn_id', CRM_Financial_BAO_FinancialTrxn::getRefundTransactionTrxnID($id));
}

// assign values to the template
Expand Down
2 changes: 1 addition & 1 deletion CRM/Contribute/Form/Task/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ public static function printPDF($contribIDs, &$params, $contactIds) {
$dueDatePeriodSetting = Civi::settings()->get('invoice_due_date_period');
$dueDate = date('F j, Y', strtotime($contributionReceiveDate . "+" . $dueDateSetting . "" . $dueDatePeriodSetting));

$amountPaid = CRM_Core_BAO_FinancialTrxn::getTotalPayments($contribID, TRUE);
$amountPaid = CRM_Financial_BAO_FinancialTrxn::getTotalPayments($contribID, TRUE);
$amountDue = ($input['amount'] - $amountPaid);

// retrieving the subtotal and sum of same tax_rate
Expand Down
Loading