diff --git a/CRM/Member/Form/Membership.php b/CRM/Member/Form/Membership.php index 0086b47d7ef0..f82bd2897d8c 100644 --- a/CRM/Member/Form/Membership.php +++ b/CRM/Member/Form/Membership.php @@ -22,8 +22,6 @@ class CRM_Member_Form_Membership extends CRM_Member_Form { protected $_memType = NULL; - protected $_onlinePendingContributionId; - public $_mode; public $_contributeMode = 'direct'; @@ -276,16 +274,6 @@ public function preProcess() { // Add custom data to form CRM_Custom_Form_CustomData::addToForm($this, $this->_memType); - - // CRM-4395, get the online pending contribution id. - $this->_onlinePendingContributionId = NULL; - if (!$this->_mode && $this->_id && ($this->_action & CRM_Core_Action::UPDATE)) { - $this->_onlinePendingContributionId = CRM_Contribute_BAO_Contribution::checkOnlinePendingContribution($this->_id, - 'Membership' - ); - } - $this->assign('onlinePendingContributionId', $this->_onlinePendingContributionId); - $this->setPageTitle(ts('Membership')); } @@ -308,20 +296,15 @@ public function setDefaultValues() { $defaults['num_terms'] = 1; if (!empty($defaults['id'])) { - if ($this->_onlinePendingContributionId) { - $defaults['record_contribution'] = $this->_onlinePendingContributionId; - } - else { - $contributionId = CRM_Core_DAO::singleValueQuery(" - SELECT contribution_id - FROM civicrm_membership_payment - WHERE membership_id = $this->_id - ORDER BY contribution_id - DESC limit 1"); - - if ($contributionId) { - $defaults['record_contribution'] = $contributionId; - } + $contributionId = CRM_Core_DAO::singleValueQuery(" +SELECT contribution_id +FROM civicrm_membership_payment +WHERE membership_id = $this->_id +ORDER BY contribution_id +DESC limit 1"); + + if ($contributionId) { + $defaults['record_contribution'] = $contributionId; } } else { @@ -861,15 +844,6 @@ public static function formRule($params, $files, $self) { } } - // validate contribution status for 'Failed'. - if ($self->_onlinePendingContributionId && !empty($params['record_contribution']) && - (CRM_Utils_Array::value('contribution_status_id', $params) == - array_search('Failed', CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name')) - ) - ) { - $errors['contribution_status_id'] = ts('Please select a valid payment status before updating.'); - } - return empty($errors) ? TRUE : $errors; } @@ -975,9 +949,6 @@ public static function emailReceipt(&$form, &$formValues, &$membership, $customV if (!empty($formValues['contribution_id'])) { $form->assign('contributionID', $formValues['contribution_id']); } - elseif (isset($form->_onlinePendingContributionId)) { - $form->assign('contributionID', $form->_onlinePendingContributionId); - } if (!empty($formValues['contribution_status_id'])) { $form->assign('contributionStatusID', $formValues['contribution_status_id']); @@ -1252,16 +1223,14 @@ public function submit() { $params[$f] = $formValues[$f] ?? NULL; } - if (!$this->_onlinePendingContributionId) { - if (empty($formValues['source'])) { - $params['contribution_source'] = ts('%1 Membership: Offline signup (by %2)', [ - 1 => $membershipType, - 2 => $userName, - ]); - } - else { - $params['contribution_source'] = $formValues['source']; - } + if (empty($formValues['source'])) { + $params['contribution_source'] = ts('%1 Membership: Offline signup (by %2)', [ + 1 => $membershipType, + 2 => $userName, + ]); + } + else { + $params['contribution_source'] = $formValues['source']; } $completedContributionStatusId = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Completed'); @@ -1496,94 +1465,33 @@ public function submit() { } else { $params['action'] = $this->_action; - if ($this->_onlinePendingContributionId && !empty($formValues['record_contribution'])) { - - // update membership as well as contribution object, CRM-4395 - $params['contribution_id'] = $this->_onlinePendingContributionId; - $params['componentId'] = $params['id']; - $params['componentName'] = 'contribute'; - // Only available statuses are Pending and completed so cancel or failed is not possible here. - $result = CRM_Contribute_BAO_Contribution::transitionComponents($params, TRUE); - if (!empty($result) && !empty($params['contribution_id'])) { - $lineItem = []; - $lineItems = CRM_Price_BAO_LineItem::getLineItemsByContributionID($params['contribution_id']); - $itemId = key($lineItems); - $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', $lineItems[$itemId]['price_field_id'], 'price_set_id'); - - $lineItems[$itemId]['unit_price'] = $params['total_amount']; - $lineItems[$itemId]['line_total'] = $params['total_amount']; - $lineItems[$itemId]['id'] = $itemId; - $lineItem[$priceSetId] = $lineItems; - $contributionBAO = new CRM_Contribute_BAO_Contribution(); - $contributionBAO->id = $params['contribution_id']; - $contributionBAO->contact_id = $params['contact_id']; - $contributionBAO->find(); - CRM_Price_BAO_LineItem::processPriceSet($params['contribution_id'], $lineItem, $contributionBAO, 'civicrm_membership'); - - //create new soft-credit record, CRM-13981 - if ($softParams) { - $softParams['contribution_id'] = $params['contribution_id']; - while ($contributionBAO->fetch()) { - $softParams['currency'] = $contributionBAO->currency; - $softParams['amount'] = $contributionBAO->total_amount; - } - CRM_Contribute_BAO_ContributionSoft::add($softParams); - } + $count = 0; + foreach ($this->_memTypeSelected as $memType) { + if ($count && !empty($formValues['record_contribution']) && + ($relateContribution = CRM_Member_BAO_Membership::getMembershipContributionId($membership->id)) + ) { + $membershipTypeValues[$memType]['relate_contribution_id'] = $relateContribution; } - //carry updated membership object. - $membership = new CRM_Member_DAO_Membership(); - $membership->id = $this->_id; - $membership->find(TRUE); - - $cancelled = TRUE; - if ($membership->end_date) { - //display end date w/ status message. - $endDate = $membership->end_date; - - if (!in_array($membership->status_id, [ - // CRM-15475 - array_search('Cancelled', CRM_Member_PseudoConstant::membershipStatus(NULL, " name = 'Cancelled' ", 'name', FALSE, TRUE)), - array_search('Expired', CRM_Member_PseudoConstant::membershipStatus()), - ]) - ) { - $cancelled = FALSE; - } + // @todo figure out why recieve_date isn't being set right here. + if (empty($params['receive_date'])) { + $params['receive_date'] = date('Y-m-d H:i:s'); } - // suppress form values in template. - $this->assign('cancelled', $cancelled); - - $createdMemberships[] = $membership; - } - else { - $count = 0; - foreach ($this->_memTypeSelected as $memType) { - if ($count && !empty($formValues['record_contribution']) && - ($relateContribution = CRM_Member_BAO_Membership::getMembershipContributionId($membership->id)) - ) { - $membershipTypeValues[$memType]['relate_contribution_id'] = $relateContribution; - } - - // @todo figure out why recieve_date isn't being set right here. - if (empty($params['receive_date'])) { - $params['receive_date'] = date('Y-m-d H:i:s'); - } - $membershipParams = array_merge($params, $membershipTypeValues[$memType]); + $membershipParams = array_merge($params, $membershipTypeValues[$memType]); - if (!empty($softParams)) { - $membershipParams['soft_credit'] = $softParams; - } - // @todo stop passing $ids (membership and userId only are set above) - $membership = CRM_Member_BAO_Membership::create($membershipParams, $ids); - $params['contribution'] = $membershipParams['contribution'] ?? NULL; - unset($params['lineItems']); - // skip line item creation for next interation since line item(s) are already created. - $params['skipLineItem'] = TRUE; - - $this->_membershipIDs[] = $membership->id; - $createdMemberships[$memType] = $membership; - $count++; + if (!empty($softParams)) { + $membershipParams['soft_credit'] = $softParams; } + // @todo stop passing $ids (membership and userId only are set above) + $membership = CRM_Member_BAO_Membership::create($membershipParams, $ids); + $params['contribution'] = $membershipParams['contribution'] ?? NULL; + unset($params['lineItems']); + // skip line item creation for next interation since line item(s) are already created. + $params['skipLineItem'] = TRUE; + + $this->_membershipIDs[] = $membership->id; + $createdMemberships[$memType] = $membership; + $count++; } } $isRecur = $params['is_recur'] ?? NULL; diff --git a/templates/CRM/Member/Form/Membership.tpl b/templates/CRM/Member/Form/Membership.tpl index 78d49280a15e..3498abf6a092 100644 --- a/templates/CRM/Member/Form/Membership.tpl +++ b/templates/CRM/Member/Form/Membership.tpl @@ -163,9 +163,9 @@ {ts}When Status Override is active, the selected status will remain in force (it will NOT be subject to membership status rules) until it is cancelled or become inactive.{/ts} {/if} - {if $accessContribution and !$membershipMode AND ($action neq 2 or (!$rows.0.contribution_id AND !$softCredit) or $onlinePendingContributionId)} + {if $accessContribution and !$membershipMode AND ($action neq 2 or (!$rows.0.contribution_id AND !$softCredit))} - {if $onlinePendingContributionId}{ts}Update Payment Status{/ts}{else}{$form.record_contribution.label}{/if} + {$form.record_contribution.label} {$form.record_contribution.html}
{ts}Check this box to enter or update payment information. You will also be able to generate a customized receipt.{/ts} @@ -251,7 +251,7 @@ {if $action neq 8} {* Jscript additions not need for Delete action *} - {if $accessContribution and !$membershipMode AND ($action neq 2 or !$rows.0.contribution_id or $onlinePendingContributionId)} + {if $accessContribution and !$membershipMode AND ($action neq 2 or !$rows.0.contribution_id)} {include file="CRM/common/showHideByFieldValue.tpl" trigger_field_id ="record_contribution" @@ -268,7 +268,7 @@ function setPaymentBlock(mode, checkboxEvent) { var memType = parseInt(cj('#membership_type_id_1').val( )); var isPriceSet = 0; - var existingAmount = {/literal}{if !empty($onlinePendingContributionId)}1{else}0{/if}{literal}; + var existingAmount = 0; if ( cj('#price_set_id').length > 0 && cj('#price_set_id').val() ) { isPriceSet = 1; diff --git a/templates/CRM/Member/Form/MembershipCommon.tpl b/templates/CRM/Member/Form/MembershipCommon.tpl index d47aa3f5905c..ae2e4eb1d09f 100644 --- a/templates/CRM/Member/Form/MembershipCommon.tpl +++ b/templates/CRM/Member/Form/MembershipCommon.tpl @@ -1,5 +1,5 @@ {if !$membershipMode} - {if $accessContribution && ($action != 2 or (!$rows.0.contribution_id AND !$softCredit) or $onlinePendingContributionId)} + {if $accessContribution && ($action != 2 or (!$rows.0.contribution_id AND !$softCredit))}
{$form.is_different_contribution_contact.label}