From 8567d0f8318fdac0c29830e4404fd91516a38900 Mon Sep 17 00:00:00 2001 From: Pradeep Nayak Date: Tue, 28 May 2013 21:58:55 +0530 Subject: [PATCH] --fixed for CRM-12649 ---------------------------------------- * CRM-12649: Restore the Select Discount Set option for back-office event registration when event has Discounts by Signup Date http://issues.civicrm.org/jira/browse/CRM-12649 --- CRM/Event/Form/EventFees.php | 139 +++++++------------------ CRM/Event/Form/Participant.php | 19 +--- CRM/Event/Form/Registration.php | 22 +++- templates/CRM/Event/Form/EventFees.tpl | 5 + 4 files changed, 64 insertions(+), 121 deletions(-) diff --git a/CRM/Event/Form/EventFees.php b/CRM/Event/Form/EventFees.php index c950afc4c6..1864f742ee 100644 --- a/CRM/Event/Form/EventFees.php +++ b/CRM/Event/Form/EventFees.php @@ -95,6 +95,7 @@ class CRM_Event_Form_EventFees { $discounts = array(); if (!empty($form->_values['discount'])) { foreach ($form->_values['discount'] as $key => $value) { + $value = current($value); $discounts[$key] = $value['name']; } } @@ -175,7 +176,38 @@ class CRM_Event_Form_EventFees { // $defaults[$form->_pId]['credit_card_exp_date'] = array( 'Y' => '2012', 'M' => '05' ); } - if ($priceSetId = CRM_Price_BAO_Set::getFor('civicrm_event', $form->_eventId)) { + + // if user has selected discount use that to set default + if (isset($form->_discountId)) { + $defaults[$form->_pId]['discount_id'] = $form->_discountId; + + //hack to set defaults for already selected discount value + if ($form->_action == CRM_Core_Action::UPDATE && !$form->_originalDiscountId) { + $form->_originalDiscountId = $defaults[$form->_pId]['discount_id']; + if ($form->_originalDiscountId) { + $defaults[$form->_pId]['discount_id'] = $form->_originalDiscountId; + } + } + $discountId = $form->_discountId; + } + else { + $discountId = CRM_Core_BAO_Discount::findSet($form->_eventId, 'civicrm_event'); + } + + if ($discountId) { + $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Core_BAO_Discount', $discountId, 'price_set_id'); + } + else { + $priceSetId = CRM_Price_BAO_Set::getFor('civicrm_event', $form->_eventId); + } + + if (($form->_action == CRM_Core_Action::ADD) && $form->_eventId && $discountId) { + // this case is for add mode, where we show discount automatically + $defaults[$form->_pId]['discount_id'] = $discountId; + } + + + if ($priceSetId) { // get price set default values, CRM-4090 if (in_array(get_class($form), array( @@ -189,6 +221,7 @@ class CRM_Event_Form_EventFees { $defaults[$form->_pId] = array_merge($defaults[$form->_pId], $priceSetValues); } } + if ($form->_action == CRM_Core_Action::ADD && CRM_Utils_Array::value('fields', $form->_priceSet)) { foreach ($form->_priceSet['fields'] as $key => $val) { foreach ($val['options'] as $keys => $values) { @@ -218,109 +251,6 @@ class CRM_Event_Form_EventFees { $form->assign('fee_amount', CRM_Utils_Array::value('fee_amount', $defaults[$form->_pId])); } } - else { - $optionGroupId = NULL; - - // if user has selected discount use that to set default - if (isset($form->_discountId)) { - $defaults[$form->_pId]['discount_id'] = $form->_discountId; - - //hack to set defaults for already selected discount value - if ($form->_action == CRM_Core_Action::UPDATE && !$form->_originalDiscountId) { - $form->_originalDiscountId = $defaults[$form->_pId]['discount_id']; - if ($form->_originalDiscountId) { - $optionGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Discount', - $form->_originalDiscountId, - 'option_group_id' - ); - $defaults[$form->_pId]['discount_id'] = $form->_originalDiscountId; - } - } - } - - if (($form->_action == CRM_Core_Action::ADD)) { - // this case is for add mode, where we show discount automatically - if (!isset($form->_discountId)) { - $discountId = CRM_Core_BAO_Discount::findSet($form->_eventId, 'civicrm_event'); - } - else { - $discountId = $form->_discountId; - } - - if ($form->_eventId && $discountId) { - $defaultDiscountId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', - $form->_eventId, - 'default_discount_fee_id' - ); - if ($defaultDiscountId) { - $discountKey = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', - $defaultDiscountId, - 'weight' - ); - } - - $defaults[$form->_pId]['discount_id'] = $discountId; - - $defaults[$form->_pId]['amount'] = key(array_slice($form->_values['discount'][$discountId], - $discountKey - 1, - $discountKey, - TRUE - )); - $optionGroupId = - CRM_Core_DAO::getFieldValue( - 'CRM_Core_DAO_Discount', - $discountId, - 'option_group_id' - ); - } - else { - if ($form->_eventId) { - $defaults[$form->_pId]['amount'] = - CRM_Core_DAO::getFieldValue( - 'CRM_Event_DAO_Event', - $form->_eventId, - 'default_fee_id' - ); - } - } - } - - if (CRM_Utils_Array::value('event_id', $defaults[$form->_pId]) - && ($form->_action == CRM_Core_Action::UPDATE || $form->_allowConfirmation) - ) { - if (!empty($form->_feeBlock)) { - $feeLevel = CRM_Utils_Array::value('fee_level', - $defaults[$form->_pId] - ); - $feeAmount = CRM_Utils_Array::value('fee_amount', - $defaults[$form->_pId] - ); - foreach ($form->_feeBlock as $amountId => $amountInfo) { - if ($amountInfo['label'] == $feeLevel && - $amountInfo['value'] == $feeAmount - ) { - $defaults[$form->_pId]['amount'] = $amountInfo['amount_id']; - } - - // if amount is not set do fuzzy matching - if (!isset($defaults[$form->_pId]['amount'])) { - // if only level use that - if ($amountInfo['label'] == $feeLevel) { - $defaults[$form->_pId]['amount'] = $amountInfo['amount_id']; - } - elseif (strpos($feeLevel, $amountInfo['label']) !== FALSE) { - $defaults[$form->_pId]['amount'] = $amountInfo['amount_id']; - } - elseif ($amountInfo['value'] == $feeAmount) { - // if amount matches use that - $defaults[$form->_pId]['amount'] = $amountInfo['amount_id']; - } - } - } - } - } - $form->assign('amountId', CRM_Utils_Array::value('amount', $defaults[$form->_pId])); - } //CRM-4453 if (CRM_Utils_Array::value('participant_fee_currency', $defaults[$form->_pId])) { @@ -472,6 +402,7 @@ SELECT id, html_type $discounts = array(); if (!empty($form->_values['discount'])) { foreach ($form->_values['discount'] as $key => $value) { + $value = current($value); $discounts[$key] = $value['name']; } diff --git a/CRM/Event/Form/Participant.php b/CRM/Event/Form/Participant.php index e69e7f5b4b..f79e29d43f 100644 --- a/CRM/Event/Form/Participant.php +++ b/CRM/Event/Form/Participant.php @@ -1080,22 +1080,9 @@ loadCampaign( {$this->_eID}, {$eventCampaigns} ); //lets carry currency, CRM-4453 $params['fee_currency'] = $config->defaultCurrency; - // fix for CRM-3088 - if ($discountId && - !empty($this->_values['discount'][$discountId]) - ) { - $params['amount_level'] = $this->_values['discount'][$discountId][$params['amount']]['label']; - $params['amount'] = $this->_values['discount'][$discountId][$params['amount']]['value']; - } - elseif (!isset($params['priceSetId']) && CRM_Utils_Array::value('amount', $params)) { - $params['amount_level'] = $this->_values['fee'][$params['amount']]['label']; - $params['amount'] = $this->_values['fee'][$params['amount']]['value']; - } - else { - CRM_Price_BAO_Set::processAmount($this->_values['fee'], - $params, $lineItem[0] - ); - } + CRM_Price_BAO_Set::processAmount($this->_values['fee'], + $params, $lineItem[0] + ); //CRM-11529 for quick config backoffice transactions //when financial_type_id is passed in form, update the //lineitems with the financial type selected in form diff --git a/CRM/Event/Form/Registration.php b/CRM/Event/Form/Registration.php index 56a1e1acdd..1ee9d041f7 100644 --- a/CRM/Event/Form/Registration.php +++ b/CRM/Event/Form/Registration.php @@ -735,6 +735,9 @@ class CRM_Event_Form_Registration extends CRM_Core_Form { // retrive all active price set fields. $discountId = CRM_Core_BAO_Discount::findSet($eventID, 'civicrm_event'); + if (property_exists($form, '_discountId') && $form->_discountId) { + $discountId = $form->_discountId; + } if ($discountId) { $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Core_BAO_Discount', $discountId, 'price_set_id'); $price = CRM_Price_BAO_Set::initSet($form, $eventID, 'civicrm_event', TRUE, $priceSetId); @@ -742,7 +745,24 @@ class CRM_Event_Form_Registration extends CRM_Core_Form { else { $price = CRM_Price_BAO_Set::initSet($form, $eventID, 'civicrm_event', TRUE); } - + + if (property_exists($form, '_context') && ($form->_context == 'standalone' + || $form->_context == 'participant')) { + $discountedEvent = CRM_Core_BAO_Discount::getOptionGroup($eventID, 'civicrm_event'); + if (is_array( $discountedEvent)) { + foreach ($discountedEvent as $key => $priceSetId) { + $priceSet = CRM_Price_BAO_Set::getSetDetail($priceSetId); + $priceSet = CRM_Utils_Array::value($priceSetId, $priceSet); + $form->_values['discount'][$key] = CRM_Utils_Array::value('fields', $priceSet); + $fieldID = key($form->_values['discount'][$key]); + $form->_values['discount'][$key][$fieldID]['name'] = CRM_Core_DAO::getFieldValue( + 'CRM_Price_DAO_Set', + $priceSetId, + 'title' + ); + } + } + } $eventFee = CRM_Utils_Array::value('fee', $form->_values); if (!is_array($eventFee) || empty($eventFee)) { $form->_values['fee'] = array(); diff --git a/templates/CRM/Event/Form/EventFees.tpl b/templates/CRM/Event/Form/EventFees.tpl index 4e981e3bdc..0d6cf65f0d 100644 --- a/templates/CRM/Event/Form/EventFees.tpl +++ b/templates/CRM/Event/Form/EventFees.tpl @@ -27,6 +27,11 @@ {if $paid} {* We retrieve this tpl when event is selected - keep it empty if event is not paid *} {if $priceSet} + {if $discount and $hasPayment} + + {elseif $form.discount_id.label} + + {/if} {if $action eq 2 and $hasPayment} {* Updating *} {if $lineItem} -- 2.25.1
  {ts}Discount Set{/ts}{$discount}
  {$form.discount_id.label}{$form.discount_id.html}