From b81ee58c34328955f2d01d8125c190aabb8cf493 Mon Sep 17 00:00:00 2001 From: Pradeep Nayak Date: Sat, 1 Feb 2014 23:45:03 +0530 Subject: [PATCH] -- CRM-13968, Added code to handle transaction for In progress contribution status ---------------------------------------- * CRM-13968: Contributions with "In Progress" status can't be edited and saved http://issues.civicrm.org/jira/browse/CRM-13968 --- CRM/Contribute/BAO/Contribution.php | 24 +++++++++++++----------- CRM/Financial/BAO/FinancialItem.php | 4 +++- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index ed0794a816..ead2d13f0c 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -2526,7 +2526,8 @@ WHERE contribution_id = %1 "; if (CRM_Utils_Array::value('contribution_status_id', $params) != array_search('Failed', $contributionStatuses) && !(CRM_Utils_Array::value('contribution_status_id', $params) == array_search('Pending', $contributionStatuses) && !$params['contribution']->is_pay_later)) { $skipRecords = TRUE; - if (CRM_Utils_Array::value('contribution_status_id', $params) == array_search('Pending', $contributionStatuses)) { + $pendingStatus = array(array_search('Pending', $contributionStatuses), array_search('In Progress', $contributionStatuses)); + if (in_array(CRM_Utils_Array::value('contribution_status_id', $params), $pendingStatus)) { $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Accounts Receivable Account is' ")); $params['to_financial_account_id'] = CRM_Contribute_PseudoConstant::financialAccountType($params['financial_type_id'], $relationTypeId); } @@ -2583,7 +2584,7 @@ WHERE contribution_id = %1 "; $newFinancialAccount = CRM_Contribute_PseudoConstant::financialAccountType($params['financial_type_id'], $incomeTypeId); if ($oldFinancialAccount != $newFinancialAccount) { $params['total_amount'] = 0; - if ($params['contribution']->contribution_status_id == array_search('Pending', $contributionStatuses)) { + if (in_array($params['contribution']->contribution_status_id, $pendingStatus)) { $params['trxnParams']['to_financial_account_id'] = CRM_Contribute_PseudoConstant::financialAccountType( $params['prevContribution']->financial_type_id, $relationTypeId); } @@ -2622,7 +2623,7 @@ WHERE contribution_id = %1 "; //check if status is changed from Pending to Completed // do not update payment instrument changes for Pending to Completed if (!($params['contribution']->contribution_status_id == array_search('Completed', $contributionStatuses) && - $params['prevContribution']->contribution_status_id == array_search('Pending', $contributionStatuses))) { + in_array($params['prevContribution']->contribution_status_id, $pendingStatus))) { // for all other statuses create new financial records self::updateFinancialAccounts($params, 'changePaymentInstrument'); $params['total_amount'] = $params['trxnParams']['total_amount'] = $trxnParams['total_amount']; @@ -2713,8 +2714,9 @@ WHERE contribution_id = %1 "; $itemAmount = $trxnID = NULL; //get all the statuses $contributionStatus = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'); - if ($params['prevContribution']->contribution_status_id == array_search('Pending', $contributionStatus) && - $params['contribution']->contribution_status_id == array_search('Completed', $contributionStatus) + if (($params['prevContribution']->contribution_status_id == array_search('Pending', $contributionStatus) + || $params['prevContribution']->contribution_status_id == array_search('In Progress', $contributionStatus)) + && $params['contribution']->contribution_status_id == array_search('Completed', $contributionStatus) && $context == 'changePaymentInstrument') { return; } @@ -2727,12 +2729,11 @@ WHERE contribution_id = %1 "; if ($params['prevContribution']->contribution_status_id == array_search('Completed', $contributionStatus) && ($params['contribution']->contribution_status_id == array_search('Refunded', $contributionStatus) - || $params['contribution']->contribution_status_id == array_search('Cancelled', $contributionStatus))) { - + || $params['contribution']->contribution_status_id == array_search('Cancelled', $contributionStatus))) { $params['trxnParams']['total_amount'] = - $params['total_amount']; } - elseif ($params['prevContribution']->contribution_status_id == array_search('Pending', $contributionStatus) - && $params['prevContribution']->is_pay_later) { + elseif (($params['prevContribution']->contribution_status_id == array_search('Pending', $contributionStatus) + && $params['prevContribution']->is_pay_later) || $params['prevContribution']->contribution_status_id == array_search('In Progress', $contributionStatus)) { $financialTypeID = CRM_Utils_Array::value('financial_type_id', $params) ? $params['financial_type_id'] : $params['prevContribution']->financial_type_id; if ($params['contribution']->contribution_status_id == array_search('Cancelled', $contributionStatus)) { $params['trxnParams']['to_financial_account_id'] = NULL; @@ -2761,8 +2762,9 @@ WHERE contribution_id = %1 "; $params['entity_id'] = $trxn->id; if ($context == 'changedStatus') { - if (($params['prevContribution']->contribution_status_id == array_search('Pending', $contributionStatus)) && - ($params['contribution']->contribution_status_id == array_search('Completed', $contributionStatus))) { + if (($params['prevContribution']->contribution_status_id == array_search('Pending', $contributionStatus) + || $params['prevContribution']->contribution_status_id == array_search('In Progress', $contributionStatus)) + && ($params['contribution']->contribution_status_id == array_search('Completed', $contributionStatus))) { $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'"; diff --git a/CRM/Financial/BAO/FinancialItem.php b/CRM/Financial/BAO/FinancialItem.php index 5e618f3840..8eaa001019 100644 --- a/CRM/Financial/BAO/FinancialItem.php +++ b/CRM/Financial/BAO/FinancialItem.php @@ -79,10 +79,12 @@ class CRM_Financial_BAO_FinancialItem extends CRM_Financial_DAO_FinancialItem { static function add($lineItem, $contribution) { $contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'); $financialItemStatus = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_FinancialItem', 'status_id'); + $itemStatus = NULL; if ($contribution->contribution_status_id == array_search('Completed', $contributionStatuses)) { $itemStatus = array_search('Paid', $financialItemStatus); } - elseif ($contribution->contribution_status_id == array_search('Pending', $contributionStatuses)) { + elseif ($contribution->contribution_status_id == array_search('Pending', $contributionStatuses) + || $contribution->contribution_status_id == array_search('In Progress', $contributionStatuses)) { $itemStatus = array_search('Unpaid', $financialItemStatus); } $params = array( -- 2.25.1