* functions.
*
* @param array $params
- * @param string $context
*
* @return bool[]
* Return indicates whether the updateFinancialAccounts function should continue & whether this is a refund.
*/
- private static function updateFinancialAccountsOnContributionStatusChange(&$params, $context) {
+ private static function updateFinancialAccountsOnContributionStatusChange(&$params) {
$previousContributionStatus = CRM_Contribute_PseudoConstant::contributionStatus($params['prevContribution']->contribution_status_id, 'name');
$currentContributionStatus = CRM_Core_PseudoConstant::getName('CRM_Contribute_BAO_Contribution', 'contribution_status_id', $params['contribution']->contribution_status_id);
) {
return [FALSE, $isARefund];
}
- if ($context == 'changedStatus') {
- if ($previousContributionStatus == 'Completed'
- && (self::isContributionStatusNegative($params['contribution']->contribution_status_id))
- ) {
- $isARefund = TRUE;
+
+ if ($previousContributionStatus == 'Completed'
+ && (self::isContributionStatusNegative($params['contribution']->contribution_status_id))
+ ) {
+ $isARefund = TRUE;
+ // @todo we should stop passing $params by reference - splitting this out would be a step towards that.
+ $params['trxnParams']['total_amount'] = -$params['total_amount'];
+ if (empty($params['contribution']->creditnote_id)) {
+ $creditNoteId = self::createCreditNoteId();
+ CRM_Core_DAO::setFieldValue('CRM_Contribute_DAO_Contribution', $params['contribution']->id, 'creditnote_id', $creditNoteId);
+ }
+ }
+ elseif (($previousContributionStatus == 'Pending'
+ && $params['prevContribution']->is_pay_later) || $previousContributionStatus == 'In Progress'
+ ) {
+ $financialTypeID = CRM_Utils_Array::value('financial_type_id', $params) ? $params['financial_type_id'] : $params['prevContribution']->financial_type_id;
+ $arAccountId = CRM_Contribute_PseudoConstant::getRelationalFinancialAccount($financialTypeID, 'Accounts Receivable Account is');
+
+ if ($currentContributionStatus == 'Cancelled') {
// @todo we should stop passing $params by reference - splitting this out would be a step towards that.
+ $params['trxnParams']['to_financial_account_id'] = $arAccountId;
$params['trxnParams']['total_amount'] = -$params['total_amount'];
if (empty($params['contribution']->creditnote_id)) {
$creditNoteId = self::createCreditNoteId();
CRM_Core_DAO::setFieldValue('CRM_Contribute_DAO_Contribution', $params['contribution']->id, 'creditnote_id', $creditNoteId);
}
}
- elseif (($previousContributionStatus == 'Pending'
- && $params['prevContribution']->is_pay_later) || $previousContributionStatus == 'In Progress'
- ) {
- $financialTypeID = CRM_Utils_Array::value('financial_type_id', $params) ? $params['financial_type_id'] : $params['prevContribution']->financial_type_id;
- $arAccountId = CRM_Contribute_PseudoConstant::getRelationalFinancialAccount($financialTypeID, 'Accounts Receivable Account is');
-
- if ($currentContributionStatus == 'Cancelled') {
- // @todo we should stop passing $params by reference - splitting this out would be a step towards that.
- $params['trxnParams']['to_financial_account_id'] = $arAccountId;
- $params['trxnParams']['total_amount'] = -$params['total_amount'];
- if (empty($params['contribution']->creditnote_id)) {
- $creditNoteId = self::createCreditNoteId();
- CRM_Core_DAO::setFieldValue('CRM_Contribute_DAO_Contribution', $params['contribution']->id, 'creditnote_id', $creditNoteId);
- }
- }
- else {
- // @todo we should stop passing $params by reference - splitting this out would be a step towards that.
- $params['trxnParams']['from_financial_account_id'] = $arAccountId;
- }
+ else {
+ // @todo we should stop passing $params by reference - splitting this out would be a step towards that.
+ $params['trxnParams']['from_financial_account_id'] = $arAccountId;
}
+ }
- if (($previousContributionStatus == 'Pending'
- || $previousContributionStatus == 'In Progress')
- && ($currentContributionStatus == 'Completed')
- ) {
- if (empty($params['line_item'])) {
- //CRM-15296
- //@todo - check with Joe regarding this situation - payment processors create pending transactions with no line items
- // when creating recurring membership payment - there are 2 lines to comment out in contributonPageTest if fixed
- // & this can be removed
- return [FALSE, $isARefund];
- }
- // @todo we should stop passing $params by reference - splitting this out would be a step towards that.
- // This is an update so original currency if none passed in.
- $params['trxnParams']['currency'] = CRM_Utils_Array::value('currency', $params, $params['prevContribution']->currency);
+ if (($previousContributionStatus == 'Pending'
+ || $previousContributionStatus == 'In Progress')
+ && ($currentContributionStatus == 'Completed')
+ ) {
+ if (empty($params['line_item'])) {
+ //CRM-15296
+ //@todo - check with Joe regarding this situation - payment processors create pending transactions with no line items
+ // when creating recurring membership payment - there are 2 lines to comment out in contributonPageTest if fixed
+ // & this can be removed
+ return [FALSE, $isARefund];
+ }
+ // @todo we should stop passing $params by reference - splitting this out would be a step towards that.
+ // This is an update so original currency if none passed in.
+ $params['trxnParams']['currency'] = CRM_Utils_Array::value('currency', $params, $params['prevContribution']->currency);
- self::recordAlwaysAccountsReceivable($params['trxnParams'], $params);
- $trxn = CRM_Core_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'] = self::$_trxnIDs[] = $trxn->id;
- $query = "UPDATE civicrm_financial_item SET status_id = %1 WHERE entity_id = %2 and entity_table = 'civicrm_line_item'";
- $sql = "SELECT id, amount FROM civicrm_financial_item WHERE entity_id = %1 and entity_table = 'civicrm_line_item'";
+ self::recordAlwaysAccountsReceivable($params['trxnParams'], $params);
+ $trxn = CRM_Core_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'] = self::$_trxnIDs[] = $trxn->id;
+ $query = "UPDATE civicrm_financial_item SET status_id = %1 WHERE entity_id = %2 and entity_table = 'civicrm_line_item'";
+ $sql = "SELECT id, amount FROM civicrm_financial_item WHERE entity_id = %1 and entity_table = 'civicrm_line_item'";
- $entityParams = [
- 'entity_table' => 'civicrm_financial_item',
- ];
- foreach ($params['line_item'] as $fieldId => $fields) {
- foreach ($fields as $fieldValueId => $lineItemDetails) {
- $fparams = [
- 1 => [
- CRM_Core_PseudoConstant::getKey('CRM_Financial_BAO_FinancialItem', 'status_id', 'Paid'),
- 'Integer',
- ],
- 2 => [$lineItemDetails['id'], 'Integer'],
- ];
- CRM_Core_DAO::executeQuery($query, $fparams);
- $fparams = [
- 1 => [$lineItemDetails['id'], 'Integer'],
- ];
- $financialItem = CRM_Core_DAO::executeQuery($sql, $fparams);
- while ($financialItem->fetch()) {
- $entityParams['entity_id'] = $financialItem->id;
- $entityParams['amount'] = $financialItem->amount;
- foreach (self::$_trxnIDs as $tID) {
- $entityParams['financial_trxn_id'] = $tID;
- CRM_Financial_BAO_FinancialItem::createEntityTrxn($entityParams);
- }
+ $entityParams = [
+ 'entity_table' => 'civicrm_financial_item',
+ ];
+ foreach ($params['line_item'] as $fieldId => $fields) {
+ foreach ($fields as $fieldValueId => $lineItemDetails) {
+ $fparams = [
+ 1 => [
+ CRM_Core_PseudoConstant::getKey('CRM_Financial_BAO_FinancialItem', 'status_id', 'Paid'),
+ 'Integer',
+ ],
+ 2 => [$lineItemDetails['id'], 'Integer'],
+ ];
+ CRM_Core_DAO::executeQuery($query, $fparams);
+ $fparams = [
+ 1 => [$lineItemDetails['id'], 'Integer'],
+ ];
+ $financialItem = CRM_Core_DAO::executeQuery($sql, $fparams);
+ while ($financialItem->fetch()) {
+ $entityParams['entity_id'] = $financialItem->id;
+ $entityParams['amount'] = $financialItem->amount;
+ foreach (self::$_trxnIDs as $tID) {
+ $entityParams['financial_trxn_id'] = $tID;
+ CRM_Financial_BAO_FinancialItem::createEntityTrxn($entityParams);
}
}
}
- return [FALSE, $isARefund];
}
+ return [FALSE, $isARefund];
}
return [TRUE, $isARefund];
}
$isARefund = FALSE;
if ($context == 'changedStatus') {
- list($continue, $isARefund) = self::updateFinancialAccountsOnContributionStatusChange($params, $context);
+ list($continue, $isARefund) = self::updateFinancialAccountsOnContributionStatusChange($params);
// @todo - it may be that this is always false & the parent function is just a confusing wrapper for the child fn.
if (!$continue) {
return;