From 9cc96227daccd3de68cf27fa63f1c0e59c9662d4 Mon Sep 17 00:00:00 2001 From: monishdeb Date: Wed, 15 Apr 2015 15:00:34 +0530 Subject: [PATCH] Improvement and bug fixes --- CRM/Contribute/Form/Contribution/Confirm.php | 3 +++ CRM/Contribute/Form/Contribution/ThankYou.php | 4 ++++ CRM/Contribute/Form/ContributionPage/Amount.php | 9 +++++++-- CRM/Member/BAO/Membership.php | 12 +++++++----- CRM/Member/Form/MembershipBlock.php | 14 ++++++++++++++ .../CRM/Contribute/Form/Contribution/Confirm.tpl | 2 +- .../Form/Contribution/MembershipBlock.tpl | 10 ---------- .../CRM/Contribute/Form/Contribution/ThankYou.tpl | 2 +- templates/CRM/Price/Form/PriceSet.tpl | 14 +++++++++++++- 9 files changed, 50 insertions(+), 20 deletions(-) diff --git a/CRM/Contribute/Form/Contribution/Confirm.php b/CRM/Contribute/Form/Contribution/Confirm.php index f5fbd395f7..7896a9ddaf 100644 --- a/CRM/Contribute/Form/Contribution/Confirm.php +++ b/CRM/Contribute/Form/Contribution/Confirm.php @@ -505,6 +505,9 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr $params['selectMembership'], FALSE ); + if (!empty($params['auto_renew'])) { + $this->assign('auto_renew', TRUE); + } } else { $this->assign('membershipBlock', FALSE); diff --git a/CRM/Contribute/Form/Contribution/ThankYou.php b/CRM/Contribute/Form/Contribution/ThankYou.php index aff8eb276b..07973821ab 100644 --- a/CRM/Contribute/Form/Contribution/ThankYou.php +++ b/CRM/Contribute/Form/Contribution/ThankYou.php @@ -182,6 +182,10 @@ class CRM_Contribute_Form_Contribution_ThankYou extends CRM_Contribute_Form_Cont TRUE, NULL ); + + if (!empty($params['auto_renew'])) { + $this->assign('auto_renew', TRUE); + } } $this->_separateMembershipPayment = $this->get('separateMembershipPayment'); diff --git a/CRM/Contribute/Form/ContributionPage/Amount.php b/CRM/Contribute/Form/ContributionPage/Amount.php index 6354c8695b..4fc80a3ec2 100644 --- a/CRM/Contribute/Form/ContributionPage/Amount.php +++ b/CRM/Contribute/Form/ContributionPage/Amount.php @@ -316,8 +316,13 @@ SELECT id //CRM-16165, Don't allow reccuring contribution if membership block contain any renewable membership option $membershipTypes = unserialize($membershipBlock->membership_types); - if (!empty($fields['is_recur']) && !empty($membershipTypes) && count(array_filter($membershipTypes)) != 0) { - $errors['is_recur'] = ts('You cannot enable both Recurring Contributions and Auto-renew memberships on the same online contribution page.'); + if (!empty($fields['is_recur']) && !empty($membershipTypes)) { + if (!$membershipBlock->is_separate_payment) { + $errors['is_recur'] = ts('You need to enable Separate Membership Payment when online contribution page is configured for both Membership and Recurring Contribution.'); + } + elseif (count(array_filter($membershipTypes)) != 0) { + $errors['is_recur'] = ts('You cannot enable both Recurring Contributions and Auto-renew memberships on the same online contribution page.'); + } } } diff --git a/CRM/Member/BAO/Membership.php b/CRM/Member/BAO/Membership.php index ae92c41e6c..d5cc3ca677 100644 --- a/CRM/Member/BAO/Membership.php +++ b/CRM/Member/BAO/Membership.php @@ -2248,7 +2248,11 @@ INNER JOIN civicrm_contact contact ON ( contact.id = membership.contact_id AND // irrespective of the value, CRM-2888 $tempParams['cms_create_account'] = 0; - $pending = $form->_params['is_pay_later'] ? (($minimumFee > 0.0) ? TRUE : FALSE) : FALSE; + //CRM-16165, scenarios are + // 1) If contribution is_pay_later and if contribution amount is > 0.0 we set pending = TRUE, vice-versa FALSE + // 2) If not pay later but auto-renewal membership is chosen then pending = TRUE as it later triggers + // pending recurring contribution, vice-versa FALSE + $pending = $form->_params['is_pay_later'] ? (($minimumFee > 0.0) ? TRUE : FALSE) : (!empty($form->_params['auto_renew']) ? TRUE : FALSE); //set this variable as we are not creating pledge for //separate membership payment contribution. @@ -2341,11 +2345,9 @@ INNER JOIN civicrm_contact contact ON ( contact.id = membership.contact_id AND //@todo this is a BAO function & should not inspect the form - the form should do this // & pass required params to the BAO if (CRM_Utils_Array::value('minimum_fee', $membershipTypeDetails) > 0.0) { - if (((isset($form->_contributeMode) && $form->_contributeMode == 'notify') || !empty($form->_params['is_pay_later']) || - (!empty($form->_params['is_recur']) && $form->_contributeMode == 'direct' - ) + if (((isset($form->_contributeMode) && $form->_contributeMode == 'notify') || !empty($form->_params['is_pay_later']) ) && - (($form->_values['is_monetary'] && $form->_amount > 0.0) || !empty($form->_params['separate_membership_payment']) || + (($form->_values['is_monetary'] && $form->_amount > 0.0) || CRM_Utils_Array::value('record_contribution', $form->_params) ) ) { diff --git a/CRM/Member/Form/MembershipBlock.php b/CRM/Member/Form/MembershipBlock.php index 13f92b6ab1..1103a75524 100644 --- a/CRM/Member/Form/MembershipBlock.php +++ b/CRM/Member/Form/MembershipBlock.php @@ -289,6 +289,7 @@ class CRM_Member_Form_MembershipBlock extends CRM_Contribute_Form_ContributionPa } else { $membershipType = array_values($params['membership_type']); + $isRecur = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $contributionPageId, 'is_recur'); if (array_sum($membershipType) == 0) { $errors['membership_type'] = ts('Please select at least one Membership Type to include in the Membership section of this page.'); } @@ -296,6 +297,19 @@ class CRM_Member_Form_MembershipBlock extends CRM_Contribute_Form_ContributionPa // for CRM-13079 $errors['membership_type'] = ts('You cannot select more than %1 choices. For more complex functionality, please use a Price Set.', array(1 => CRM_Price_Form_Field::NUM_OPTION)); } + elseif ($isRecur) { + if (empty($params['is_separate_payment']) && array_sum($membershipType) != 0) { + $errors['is_separate_payment'] = ts('You need to enable Separate Membership Payment when online contribution page is configured for both Membership and Recurring Contribution'); + } + elseif (!empty($params['is_separate_payment'])) { + foreach ($params['membership_type'] as $mt => $dontCare) { + if (!empty($params["auto_renew_$mt"])) { + $errors["auto_renew_$mt"] = ts('You cannot enable both Recurring Contributions and Auto-renew memberships on the same online contribution page'); + break; + } + } + } + } } //for CRM-1302 diff --git a/templates/CRM/Contribute/Form/Contribution/Confirm.tpl b/templates/CRM/Contribute/Form/Contribution/Confirm.tpl index e7bc1fc6e0..8035b33f94 100644 --- a/templates/CRM/Contribute/Form/Contribution/Confirm.tpl +++ b/templates/CRM/Contribute/Form/Contribution/Confirm.tpl @@ -91,7 +91,7 @@ {/if} {if $is_recur} - {if $membershipBlock} {* Auto-renew membership confirmation *} + {if !empty($auto_renew)} {* Auto-renew membership confirmation *} {crmRegion name="contribution-confirm-recur-membership"}
{ts 1=$frequency_interval 2=$frequency_unit}I want this membership to be renewed automatically every %1 %2(s).{/ts}

diff --git a/templates/CRM/Contribute/Form/Contribution/MembershipBlock.tpl b/templates/CRM/Contribute/Form/Contribution/MembershipBlock.tpl index db94098f63..f634cf76e1 100644 --- a/templates/CRM/Contribute/Form/Contribution/MembershipBlock.tpl +++ b/templates/CRM/Contribute/Form/Contribution/MembershipBlock.tpl @@ -67,16 +67,6 @@ {/if} {include file="CRM/Price/Form/PriceSet.tpl" extends="Membership"} -
-
-
-
- {if isset($form.auto_renew) } - {$form.auto_renew.html} {$form.auto_renew.label} - {/if} -
-
-
{elseif $lineItem and $priceSetID AND !$is_quick_config} diff --git a/templates/CRM/Contribute/Form/Contribution/ThankYou.tpl b/templates/CRM/Contribute/Form/Contribution/ThankYou.tpl index 8af73578d4..311bd5c57f 100644 --- a/templates/CRM/Contribute/Form/Contribution/ThankYou.tpl +++ b/templates/CRM/Contribute/Form/Contribution/ThankYou.tpl @@ -133,7 +133,7 @@ {* Recurring contribution / pledge information *} {if $is_recur} - {if $membershipBlock} {* Auto-renew membership confirmation *} + {if !empty($auto_renew)} {* Auto-renew membership confirmation *} {crmRegion name="contribution-thankyou-recur-membership"}
{if $frequency_interval > 1} diff --git a/templates/CRM/Price/Form/PriceSet.tpl b/templates/CRM/Price/Form/PriceSet.tpl index 7734c8a9d5..f735fdbc80 100644 --- a/templates/CRM/Price/Form/PriceSet.tpl +++ b/templates/CRM/Price/Form/PriceSet.tpl @@ -60,8 +60,20 @@
{$element.help_post}
{/if} -
+ {if !empty($extends) && $extends eq "Membership"} +
+
+
+
+ {if isset($form.auto_renew) } + {$form.auto_renew.html} {$form.auto_renew.label} + {/if} +
+
+
+ {/if} +
{else} {assign var="element_name" value="price_"|cat:$field_id} -- 2.25.1