/**
  * Set default values for the form. Note that in edit/view mode
  * the default values are retrieved from the database
  *
  *
  * @return void
  */
 public function setDefaultValues()
 {
     //parent::setDefaultValues();
     $defaults = array();
     if (isset($this->_id)) {
         $defaults = CRM_Member_BAO_Membership::getMembershipBlock($this->_id);
     }
     $defaults['member_is_active'] = $defaults['is_active'];
     // Set Display Minimum Fee default to true if we are adding a new membership block
     if (!isset($defaults['id'])) {
         $defaults['display_min_fee'] = 1;
     } else {
         $this->assign('membershipBlockId', $defaults['id']);
     }
     if ($this->_id && ($priceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $this->_id, 3, 1))) {
         $defaults['member_price_set_id'] = $priceSetId;
         $this->_memPriceSetId = $priceSetId;
     } else {
         // for membership_types
         // if ( isset( $defaults['membership_types'] ) ) {
         $priceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $this->_id, 3);
         $this->assign('isQuick', 1);
         $this->_memPriceSetId = $priceSetId;
         $pFIDs = array();
         if ($priceSetId) {
             CRM_Core_DAO::commonRetrieveAll('CRM_Price_DAO_PriceField', 'price_set_id', $priceSetId, $pFIDs, $return = array('html_type', 'name', 'label'));
             foreach ($pFIDs as $pid => $pValue) {
                 if ($pValue['html_type'] == 'Radio' && $pValue['name'] == 'membership_amount') {
                     $defaults['mem_price_field_id'] = $pValue['id'];
                     $defaults['membership_type_label'] = $pValue['label'];
                 }
             }
             if (!empty($defaults['mem_price_field_id'])) {
                 $options = array();
                 $priceFieldOptions = CRM_Price_BAO_PriceFieldValue::getValues($defaults['mem_price_field_id'], $options, 'id', 1);
                 foreach ($options as $k => $v) {
                     $newMembershipType[$v['membership_type_id']] = 1;
                     if (!empty($defaults['auto_renew'])) {
                         $defaults["auto_renew_" . $v['membership_type_id']] = $defaults['auto_renew'][$v['membership_type_id']];
                     }
                 }
                 $defaults['membership_type'] = $newMembershipType;
             }
         }
     }
     return $defaults;
 }
Example #2
0
 /**
  * Set default values for the form.
  *
  * For edit/view mode the default values are retrieved from the database.
  */
 public function setDefaultValues()
 {
     $parentDefaults = parent::setDefaultValues();
     $eventId = $this->_id;
     $params = array();
     $defaults = array();
     if (isset($eventId)) {
         $params = array('id' => $eventId);
     }
     CRM_Event_BAO_Event::retrieve($params, $defaults);
     if (isset($eventId)) {
         $price_set_id = CRM_Price_BAO_PriceSet::getFor('civicrm_event', $eventId, NULL, 1);
         if ($price_set_id) {
             $defaults['price_set_id'] = $price_set_id;
         } else {
             $priceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_event', $eventId, NULL);
             if ($priceSetId) {
                 if ($isQuick = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $priceSetId, 'is_quick_config')) {
                     $this->assign('isQuick', $isQuick);
                     $priceField = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', $priceSetId, 'id', 'price_set_id');
                     $options = array();
                     $priceFieldOptions = CRM_Price_BAO_PriceFieldValue::getValues($priceField, $options, 'weight', TRUE);
                     $defaults['price_field_id'] = $priceField;
                     $countRow = 0;
                     foreach ($options as $optionId => $optionValue) {
                         $countRow++;
                         $defaults['value'][$countRow] = CRM_Utils_Money::format($optionValue['amount'], NULL, '%a');
                         $defaults['label'][$countRow] = $optionValue['label'];
                         $defaults['name'][$countRow] = $optionValue['name'];
                         $defaults['weight'][$countRow] = $optionValue['weight'];
                         $defaults['price_field_value'][$countRow] = $optionValue['id'];
                         if ($optionValue['is_default']) {
                             $defaults['default'] = $countRow;
                         }
                     }
                 }
             }
         }
     }
     //check if discounted
     $discountedEvent = CRM_Core_BAO_Discount::getOptionGroup($this->_id, 'civicrm_event');
     if (!empty($discountedEvent)) {
         $defaults['is_discount'] = $i = 1;
         $totalLables = $maxSize = $defaultDiscounts = array();
         foreach ($discountedEvent as $optionGroupId) {
             $defaults['discount_price_set'][] = $optionGroupId;
             $name = $defaults["discount_name[{$i}]"] = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $optionGroupId, 'title');
             list($defaults["discount_start_date[{$i}]"]) = CRM_Utils_Date::setDateDefaults(CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Discount', $optionGroupId, 'start_date', 'price_set_id'));
             list($defaults["discount_end_date[{$i}]"]) = CRM_Utils_Date::setDateDefaults(CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Discount', $optionGroupId, 'end_date', 'price_set_id'));
             $defaultDiscounts[] = CRM_Price_BAO_PriceSet::getSetDetail($optionGroupId);
             $i++;
         }
         //avoid moving up value of lable when some labels don't
         //have a value ,fixed for CRM-3088
         $rowCount = 1;
         foreach ($defaultDiscounts as $val) {
             $discountFields = current($val);
             $discountFields = current($discountFields['fields']);
             foreach ($discountFields['options'] as $discountFieldsval) {
                 $defaults['discounted_label'][$discountFieldsval['weight']] = $discountFieldsval['label'];
                 $defaults['discounted_value'][$discountFieldsval['weight']][$rowCount] = CRM_Utils_Money::format($discountFieldsval['amount'], NULL, '%a');
                 $defaults['discount_option_id'][$rowCount][$discountFieldsval['weight']] = $discountFieldsval['id'];
                 if (!empty($discountFieldsval['is_default'])) {
                     $defaults['discounted_default'] = $discountFieldsval['weight'];
                 }
             }
             $rowCount++;
         }
         //CRM-12970
         ksort($defaults['discounted_value']);
         ksort($defaults['discounted_label']);
         $rowCount = 1;
         foreach ($defaults['discounted_label'] as $key => $value) {
             if ($key != $rowCount) {
                 $defaults['discounted_label'][$rowCount] = $value;
                 $defaults['discounted_value'][$rowCount] = $defaults['discounted_value'][$key];
                 unset($defaults['discounted_value'][$key]);
                 unset($defaults['discounted_label'][$key]);
                 foreach ($defaults['discount_option_id'] as &$optionIds) {
                     if (array_key_exists($key, $optionIds)) {
                         $optionIds[$rowCount] = $optionIds[$key];
                         unset($optionIds[$key]);
                     }
                 }
             }
             $rowCount++;
         }
         $this->set('discountSection', 1);
         $this->buildQuickForm();
     } elseif (!empty($defaults['label'])) {
         //if Regular Fees are present in DB and event fee page is in update mode
         $defaults['discounted_label'] = $defaults['label'];
     } elseif (!empty($this->_submitValues['label'])) {
         //if event is newly created, use submitted values for
         //discount labels
         if (is_array($this->_submitValues['label'])) {
             $k = 1;
             foreach ($this->_submitValues['label'] as $value) {
                 if ($value) {
                     $defaults['discounted_label'][$k] = $value;
                     $k++;
                 }
             }
         }
     }
     $defaults['id'] = $eventId;
     if (!empty($totalLables)) {
         $maxKey = count($totalLables) - 1;
         if (isset($maxKey) && !empty($totalLables[$maxKey]['value'])) {
             foreach ($totalLables[$maxKey]['value'] as $i => $v) {
                 if ($totalLables[$maxKey]['amount_id'][$i] == CRM_Utils_Array::value('default_discount_fee_id', $defaults)) {
                     $defaults['discounted_default'] = $i;
                     break;
                 }
             }
         }
     }
     if (!isset($defaults['discounted_default'])) {
         $defaults['discounted_default'] = 1;
     }
     if (!isset($defaults['is_monetary'])) {
         $defaults['is_monetary'] = 1;
     }
     if (!isset($defaults['fee_label'])) {
         $defaults['fee_label'] = ts('Event Fee(s)');
     }
     if (!isset($defaults['pay_later_text']) || empty($defaults['pay_later_text'])) {
         $defaults['pay_later_text'] = ts('I will send payment by check');
     }
     $this->_showHide = new CRM_Core_ShowHideBlocks();
     if (!$defaults['is_monetary']) {
         $this->_showHide->addHide('event-fees');
     }
     if (isset($defaults['price_set_id'])) {
         $this->_showHide->addHide('map-field');
     }
     $this->_showHide->addToTemplate();
     $this->assign('inDate', $this->_inDate);
     if (!empty($defaults['payment_processor'])) {
         $defaults['payment_processor'] = str_replace(CRM_Core_DAO::VALUE_SEPARATOR, ',', $defaults['payment_processor']);
     }
     return $defaults;
 }
Example #3
0
 /**
  * Browse all price fields.
  *
  * @param null
  *
  * @return void
  * @access public
  */
 function browse()
 {
     $customOption = array();
     CRM_Price_BAO_PriceFieldValue::getValues($this->_fid, $customOption);
     $config = CRM_Core_Config::singleton();
     $financialType = CRM_Contribute_PseudoConstant::financialType();
     foreach ($customOption as $id => $values) {
         $action = array_sum(array_keys($this->actionLinks()));
         if (CRM_Utils_Array::value('financial_type_id', $values)) {
             $customOption[$id]['financial_type_id'] = $financialType[$values['financial_type_id']];
         }
         // update enable/disable links depending on price_field properties.
         if ($this->_isSetReserved) {
             $action -= CRM_Core_Action::UPDATE + CRM_Core_Action::DELETE + CRM_Core_Action::DISABLE + CRM_Core_Action::ENABLE;
         } else {
             if ($values['is_active']) {
                 $action -= CRM_Core_Action::ENABLE;
             } else {
                 $action -= CRM_Core_Action::DISABLE;
             }
         }
         if (CRM_Utils_Array::value('is_default', $customOption[$id])) {
             $customOption[$id]['is_default'] = '<img src="' . $config->resourceBase . 'i/check.gif" />';
         } else {
             $customOption[$id]['is_default'] = '';
         }
         $customOption[$id]['order'] = $customOption[$id]['weight'];
         $customOption[$id]['action'] = CRM_Core_Action::formLink(self::actionLinks(), $action, array('oid' => $id, 'fid' => $this->_fid, 'sid' => $this->_sid));
     }
     // Add order changing widget to selector
     $returnURL = CRM_Utils_System::url('civicrm/admin/price/field/option', "action=browse&reset=1&fid={$this->_fid}&sid={$this->_sid}");
     $filter = "price_field_id = {$this->_fid}";
     CRM_Utils_Weight::addOrder($customOption, 'CRM_Price_DAO_PriceFieldValue', 'id', $returnURL, $filter);
     $this->assign('customOption', $customOption);
     $this->assign('sid', $this->_sid);
 }
 /**
  * Validate the priceset
  *
  * @param int $priceSetId , array $fields
  *
  * retrun the error string
  *
  * @param $fields
  * @param $error
  * @param bool $allowNoneSelection
  *
  * @access public
  * @static
  */
 public static function priceSetValidation($priceSetId, $fields, &$error, $allowNoneSelection = FALSE)
 {
     // check for at least one positive
     // amount price field should be selected.
     $priceField = new CRM_Price_DAO_PriceField();
     $priceField->price_set_id = $priceSetId;
     $priceField->find();
     $priceFields = array();
     if ($allowNoneSelection) {
         $noneSelectedPriceFields = array();
     }
     while ($priceField->fetch()) {
         $key = "price_{$priceField->id}";
         if ($allowNoneSelection) {
             if (array_key_exists($key, $fields)) {
                 if ($fields[$key] == 0 && !$priceField->is_required) {
                     $noneSelectedPriceFields[] = $priceField->id;
                 }
             }
         }
         if (!empty($fields[$key])) {
             $priceFields[$priceField->id] = $fields[$key];
         }
     }
     if (!empty($priceFields)) {
         // we should has to have positive amount.
         $sql = "\nSELECT  id, html_type\nFROM  civicrm_price_field\nWHERE  id IN (" . implode(',', array_keys($priceFields)) . ')';
         $fieldDAO = CRM_Core_DAO::executeQuery($sql);
         $htmlTypes = array();
         while ($fieldDAO->fetch()) {
             $htmlTypes[$fieldDAO->id] = $fieldDAO->html_type;
         }
         $selectedAmounts = array();
         foreach ($htmlTypes as $fieldId => $type) {
             $options = array();
             CRM_Price_BAO_PriceFieldValue::getValues($fieldId, $options);
             if (empty($options)) {
                 continue;
             }
             if ($type == 'Text') {
                 foreach ($options as $opId => $option) {
                     $selectedAmounts[$opId] = $priceFields[$fieldId] * $option['amount'];
                     break;
                 }
             } elseif (is_array($fields["price_{$fieldId}"])) {
                 foreach (array_keys($fields["price_{$fieldId}"]) as $opId) {
                     $selectedAmounts[$opId] = $options[$opId]['amount'];
                 }
             } elseif (in_array($fields["price_{$fieldId}"], array_keys($options))) {
                 $selectedAmounts[$fields["price_{$fieldId}"]] = $options[$fields["price_{$fieldId}"]]['amount'];
             }
         }
         list($componentName) = explode(':', $fields['_qf_default']);
         // now we have all selected amount in hand.
         $totalAmount = array_sum($selectedAmounts);
         if ($totalAmount < 0) {
             $error['_qf_default'] = ts('%1 amount can not be less than zero. Please select the options accordingly.', array(1 => $componentName));
         }
     } else {
         if ($allowNoneSelection) {
             if (empty($noneSelectedPriceFields)) {
                 $error['_qf_default'] = ts('Please select at least one option from price set.');
             }
         } else {
             $error['_qf_default'] = ts('Please select at least one option from price set.');
         }
     }
 }
Example #5
0
 /**
  * Submit function.
  *
  * This is the guts of the postProcess made also accessible to the test suite.
  *
  * @param array $params
  *   Submitted values.
  */
 public function submit($params)
 {
     //carry campaign from profile.
     if (array_key_exists('contribution_campaign_id', $params)) {
         $params['campaign_id'] = $params['contribution_campaign_id'];
     }
     $params['currencyID'] = CRM_Core_Config::singleton()->defaultCurrency;
     $is_quick_config = 0;
     if (!empty($params['priceSetId'])) {
         $is_quick_config = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config');
         if ($is_quick_config) {
             $priceField = new CRM_Price_DAO_PriceField();
             $priceField->price_set_id = $params['priceSetId'];
             $priceField->orderBy('weight');
             $priceField->find();
             $priceOptions = array();
             while ($priceField->fetch()) {
                 CRM_Price_BAO_PriceFieldValue::getValues($priceField->id, $priceOptions);
                 if (($selectedPriceOptionID = CRM_Utils_Array::value("price_{$priceField->id}", $params)) != FALSE && $selectedPriceOptionID > 0) {
                     switch ($priceField->name) {
                         case 'membership_amount':
                             $this->_params['selectMembership'] = $params['selectMembership'] = CRM_Utils_Array::value('membership_type_id', $priceOptions[$selectedPriceOptionID]);
                             $this->set('selectMembership', $params['selectMembership']);
                         case 'contribution_amount':
                             $params['amount'] = $selectedPriceOptionID;
                             if ($priceField->name == 'contribution_amount' || $priceField->name == 'membership_amount' && CRM_Utils_Array::value('is_separate_payment', $this->_membershipBlock) == 0) {
                                 $this->_values['amount'] = CRM_Utils_Array::value('amount', $priceOptions[$selectedPriceOptionID]);
                             }
                             $this->_values[$selectedPriceOptionID]['value'] = CRM_Utils_Array::value('amount', $priceOptions[$selectedPriceOptionID]);
                             $this->_values[$selectedPriceOptionID]['label'] = CRM_Utils_Array::value('label', $priceOptions[$selectedPriceOptionID]);
                             $this->_values[$selectedPriceOptionID]['amount_id'] = CRM_Utils_Array::value('id', $priceOptions[$selectedPriceOptionID]);
                             $this->_values[$selectedPriceOptionID]['weight'] = CRM_Utils_Array::value('weight', $priceOptions[$selectedPriceOptionID]);
                             break;
                         case 'other_amount':
                             $params['amount_other'] = $selectedPriceOptionID;
                             break;
                     }
                 }
             }
         }
     }
     if (!empty($this->_ccid) && !empty($this->_pendingAmount)) {
         $params['amount'] = $this->_pendingAmount;
     } else {
         // from here on down, $params['amount'] holds a monetary value (or null) rather than an option ID
         $params['amount'] = self::computeAmount($params, $this->_values);
     }
     $params['separate_amount'] = $params['amount'];
     $memFee = NULL;
     if (!empty($params['selectMembership'])) {
         if (empty($this->_membershipTypeValues)) {
             $this->_membershipTypeValues = CRM_Member_BAO_Membership::buildMembershipTypeValues($this, (array) $params['selectMembership']);
         }
         $membershipTypeValues = $this->_membershipTypeValues[$params['selectMembership']];
         $memFee = $membershipTypeValues['minimum_fee'];
         if (!$params['amount'] && !$this->_separateMembershipPayment) {
             $params['amount'] = $memFee ? $memFee : 0;
         }
     }
     //If the membership & contribution is used in contribution page & not separate payment
     $fieldId = $memPresent = $membershipLabel = $fieldOption = $is_quick_config = NULL;
     $proceFieldAmount = 0;
     if (property_exists($this, '_separateMembershipPayment') && $this->_separateMembershipPayment == 0) {
         $is_quick_config = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config');
         if ($is_quick_config) {
             foreach ($this->_priceSet['fields'] as $fieldKey => $fieldVal) {
                 if ($fieldVal['name'] == 'membership_amount' && !empty($params['price_' . $fieldKey])) {
                     $fieldId = $fieldVal['id'];
                     $fieldOption = $params['price_' . $fieldId];
                     $proceFieldAmount += $fieldVal['options'][$this->_submitValues['price_' . $fieldId]]['amount'];
                     $memPresent = TRUE;
                 } else {
                     if (!empty($params['price_' . $fieldKey]) && $memPresent && ($fieldVal['name'] == 'other_amount' || $fieldVal['name'] == 'contribution_amount')) {
                         $fieldId = $fieldVal['id'];
                         if ($fieldVal['name'] == 'other_amount') {
                             $proceFieldAmount += $this->_submitValues['price_' . $fieldId];
                         } elseif ($fieldVal['name'] == 'contribution_amount' && $this->_submitValues['price_' . $fieldId] > 0) {
                             $proceFieldAmount += $fieldVal['options'][$this->_submitValues['price_' . $fieldId]]['amount'];
                         }
                         unset($params['price_' . $fieldId]);
                         break;
                     }
                 }
             }
         }
     }
     if (!isset($params['amount_other'])) {
         $this->set('amount_level', CRM_Utils_Array::value('amount_level', $params));
     }
     if (!empty($this->_ccid)) {
         $this->set('lineItem', $this->_lineItem);
     } elseif ($priceSetId = CRM_Utils_Array::value('priceSetId', $params)) {
         $lineItem = array();
         $is_quick_config = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $priceSetId, 'is_quick_config');
         if ($is_quick_config) {
             foreach ($this->_values['fee'] as $key => &$val) {
                 if ($val['name'] == 'other_amount' && $val['html_type'] == 'Text' && !empty($params['price_' . $key])) {
                     // Clean out any currency symbols.
                     $params['price_' . $key] = CRM_Utils_Rule::cleanMoney($params['price_' . $key]);
                     if ($params['price_' . $key] != 0) {
                         foreach ($val['options'] as $optionKey => &$options) {
                             $options['amount'] = CRM_Utils_Array::value('price_' . $key, $params);
                             break;
                         }
                     }
                     $params['price_' . $key] = 1;
                     break;
                 }
             }
         }
         $component = '';
         if ($this->_membershipBlock) {
             $component = 'membership';
         }
         CRM_Price_BAO_PriceSet::processAmount($this->_values['fee'], $params, $lineItem[$priceSetId], $component);
         if ($params['tax_amount']) {
             $this->set('tax_amount', $params['tax_amount']);
         }
         if ($proceFieldAmount) {
             $lineItem[$params['priceSetId']][$fieldOption]['unit_price'] = $proceFieldAmount;
             $lineItem[$params['priceSetId']][$fieldOption]['line_total'] = $proceFieldAmount;
             if (isset($lineItem[$params['priceSetId']][$fieldOption]['tax_amount'])) {
                 $proceFieldAmount += $lineItem[$params['priceSetId']][$fieldOption]['tax_amount'];
             }
             if (!$this->_membershipBlock['is_separate_payment']) {
                 //require when separate membership not used
                 $params['amount'] = $proceFieldAmount;
             }
         }
         $this->set('lineItem', $lineItem);
     }
     if ($params['amount'] != 0 && ($this->_values['is_pay_later'] && empty($this->_paymentProcessor) && !array_key_exists('hidden_processor', $params) || CRM_Utils_Array::value('payment_processor_id', $params) == 0)) {
         $params['is_pay_later'] = 1;
     } else {
         $params['is_pay_later'] = 0;
     }
     // Would be nice to someday understand the point of this set.
     $this->set('is_pay_later', $params['is_pay_later']);
     // assign pay later stuff
     $this->_params['is_pay_later'] = CRM_Utils_Array::value('is_pay_later', $params, FALSE);
     $this->assign('is_pay_later', $params['is_pay_later']);
     if ($params['is_pay_later']) {
         $this->assign('pay_later_text', $this->_values['pay_later_text']);
         $this->assign('pay_later_receipt', $this->_values['pay_later_receipt']);
     }
     if ($this->_membershipBlock['is_separate_payment'] && !empty($params['separate_amount'])) {
         $this->set('amount', $params['separate_amount']);
     } else {
         $this->set('amount', $params['amount']);
     }
     // generate and set an invoiceID for this transaction
     $invoiceID = md5(uniqid(rand(), TRUE));
     $this->set('invoiceID', $invoiceID);
     $params['invoiceID'] = $invoiceID;
     $params['description'] = ts('Online Contribution') . ': ' . (!empty($this->_pcpInfo['title']) ? $this->_pcpInfo['title'] : $this->_values['title']);
     $params['button'] = $this->controller->getButtonName();
     // required only if is_monetary and valid positive amount
     // @todo it seems impossible for $memFee to be greater than 0 & $params['amount'] not to
     // be & by requiring $memFee down here we make it harder to do a sensible refactoring of the function
     // above (ie. extract the amount in a small function).
     if ($this->_values['is_monetary'] && !empty($this->_paymentProcessor) && ((double) $params['amount'] > 0.0 || $memFee > 0.0)) {
         // The concept of contributeMode is deprecated - as should be the 'is_monetary' setting.
         $this->setContributeMode();
         // Really this setting of $this->_params & params within it should be done earlier on in the function
         // probably the values determined here should be reused in confirm postProcess as there is no opportunity to alter anything
         // on the confirm page. However as we are dealing with a stable release we go as close to where it is used
         // as possible.
         // In general the form has a lack of clarity of the logic of why things are set on the form in some cases &
         // the logic around when $this->_params is used compared to other params arrays.
         $this->_params = array_merge($params, $this->_params);
         $this->setRecurringMembershipParams();
         if ($this->_paymentProcessor && $this->_paymentProcessor['object']->supports('preApproval')) {
             $this->handlePreApproval($this->_params);
         }
     }
 }
Example #6
0
 /**
  * This method will create the lineItem array required for
  * processAmount method
  *
  * @param int $fid
  *   Price set field id.
  * @param array $params
  *   Reference to form values.
  * @param array $fields
  *   Reference to array of fields belonging.
  *                          to the price set used for particular event
  * @param array $values
  *   Reference to the values array(.
  *   this is
  *                          lineItem array)
  *
  * @return void
  */
 public static function format($fid, &$params, &$fields, &$values)
 {
     if (empty($params["price_{$fid}"])) {
         return;
     }
     $optionIDs = implode(',', array_keys($params["price_{$fid}"]));
     //lets first check in fun parameter,
     //since user might modified w/ hooks.
     $options = array();
     if (array_key_exists('options', $fields)) {
         $options = $fields['options'];
     } else {
         CRM_Price_BAO_PriceFieldValue::getValues($fid, $options, 'weight', TRUE);
     }
     $fieldTitle = CRM_Utils_Array::value('label', $fields);
     if (!$fieldTitle) {
         $fieldTitle = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', $fid, 'label');
     }
     foreach ($params["price_{$fid}"] as $oid => $qty) {
         $price = $options[$oid]['amount'];
         // lets clean the price in case it is not yet cleant
         // CRM-10974
         $price = CRM_Utils_Rule::cleanMoney($price);
         $participantsPerField = CRM_Utils_Array::value('count', $options[$oid], 0);
         $values[$oid] = array('price_field_id' => $fid, 'price_field_value_id' => $oid, 'label' => CRM_Utils_Array::value('label', $options[$oid]), 'field_title' => $fieldTitle, 'description' => CRM_Utils_Array::value('description', $options[$oid]), 'qty' => $qty, 'unit_price' => $price, 'line_total' => $qty * $price, 'participant_count' => $qty * $participantsPerField, 'max_value' => CRM_Utils_Array::value('max_value', $options[$oid]), 'membership_type_id' => CRM_Utils_Array::value('membership_type_id', $options[$oid]), 'membership_num_terms' => CRM_Utils_Array::value('membership_num_terms', $options[$oid]), 'auto_renew' => CRM_Utils_Array::value('auto_renew', $options[$oid]), 'html_type' => $fields['html_type'], 'financial_type_id' => CRM_Utils_Array::value('financial_type_id', $options[$oid]), 'tax_amount' => CRM_Utils_Array::value('tax_amount', $options[$oid]));
         if ($values[$oid]['membership_type_id'] && empty($values[$oid]['auto_renew'])) {
             $values[$oid]['auto_renew'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $values[$oid]['membership_type_id'], 'auto_renew');
         }
     }
 }
Example #7
0
 /**
  * Browse all price fields.
  *
  * @return void
  */
 public function browse()
 {
     $customOption = array();
     CRM_Price_BAO_PriceFieldValue::getValues($this->_fid, $customOption);
     // CRM-15378 - check if these price options are in an Event price set
     $isEvent = FALSE;
     $extendComponentId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_sid, 'extends', 'id');
     $allComponents = explode(CRM_Core_DAO::VALUE_SEPARATOR, $extendComponentId);
     $eventComponentId = CRM_Core_Component::getComponentID('CiviEvent');
     if (in_array($eventComponentId, $allComponents)) {
         $isEvent = TRUE;
     }
     $config = CRM_Core_Config::singleton();
     $financialType = CRM_Contribute_PseudoConstant::financialType();
     $taxRate = CRM_Core_PseudoConstant::getTaxRates();
     // display taxTerm for priceFields
     $invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
     $taxTerm = CRM_Utils_Array::value('tax_term', $invoiceSettings);
     $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
     $getTaxDetails = FALSE;
     foreach ($customOption as $id => $values) {
         $action = array_sum(array_keys($this->actionLinks()));
         // Adding the required fields in the array
         if (isset($taxRate[$values['financial_type_id']])) {
             $customOption[$id]['tax_rate'] = $taxRate[$values['financial_type_id']];
             if ($invoicing && isset($customOption[$id]['tax_rate'])) {
                 $getTaxDetails = TRUE;
             }
             $taxAmount = CRM_Contribute_BAO_Contribution_Utils::calculateTaxAmount($customOption[$id]['amount'], $customOption[$id]['tax_rate']);
             $customOption[$id]['tax_amount'] = $taxAmount['tax_amount'];
         }
         if (!empty($values['financial_type_id'])) {
             $customOption[$id]['financial_type_id'] = $financialType[$values['financial_type_id']];
         }
         // update enable/disable links depending on price_field properties.
         if ($this->_isSetReserved) {
             $action -= CRM_Core_Action::UPDATE + CRM_Core_Action::DELETE + CRM_Core_Action::DISABLE + CRM_Core_Action::ENABLE;
         } else {
             if ($values['is_active']) {
                 $action -= CRM_Core_Action::ENABLE;
             } else {
                 $action -= CRM_Core_Action::DISABLE;
             }
         }
         if (!empty($customOption[$id]['is_default'])) {
             $customOption[$id]['is_default'] = '<img src="' . $config->resourceBase . 'i/check.gif" />';
         } else {
             $customOption[$id]['is_default'] = '';
         }
         $customOption[$id]['order'] = $customOption[$id]['weight'];
         $customOption[$id]['action'] = CRM_Core_Action::formLink(self::actionLinks(), $action, array('oid' => $id, 'fid' => $this->_fid, 'sid' => $this->_sid), ts('more'), FALSE, 'priceFieldValue.row.actions', 'PriceFieldValue', $id);
     }
     // Add order changing widget to selector
     $returnURL = CRM_Utils_System::url('civicrm/admin/price/field/option', "action=browse&reset=1&fid={$this->_fid}&sid={$this->_sid}");
     $filter = "price_field_id = {$this->_fid}";
     CRM_Utils_Weight::addOrder($customOption, 'CRM_Price_DAO_PriceFieldValue', 'id', $returnURL, $filter);
     $this->assign('taxTerm', $taxTerm);
     $this->assign('getTaxDetails', $getTaxDetails);
     $this->assign('customOption', $customOption);
     $this->assign('sid', $this->_sid);
     $this->assign('isEvent', $isEvent);
 }
Example #8
0
 /**
  * Set default values for the form. Note that in edit/view mode
  * the default values are retrieved from the database
  *
  *
  * @return array
  */
 public function setDefaultValues()
 {
     $defaults = parent::setDefaultValues();
     if (empty($defaults['pay_later_text'])) {
         $defaults['pay_later_text'] = ts('I will send payment by check');
     }
     if (!empty($defaults['amount_block_is_active'])) {
         if ($priceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $this->_id, NULL)) {
             if ($isQuick = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $priceSetId, 'is_quick_config')) {
                 $this->assign('isQuick', $isQuick);
                 //$priceField = CRM_Core_DAO::getFieldValue( 'CRM_Price_DAO_PriceField', $priceSetId, 'id', 'price_set_id' );
                 $options = $pFIDs = array();
                 $priceFieldParams = array('price_set_id' => $priceSetId);
                 $priceFields = CRM_Core_DAO::commonRetrieveAll('CRM_Price_DAO_PriceField', 'price_set_id', $priceSetId, $pFIDs, $return = array('html_type', 'name', 'is_active', 'label'));
                 foreach ($priceFields as $priceField) {
                     if ($priceField['id'] && $priceField['html_type'] == 'Radio' && $priceField['name'] == 'contribution_amount') {
                         $defaults['price_field_id'] = $priceField['id'];
                         $priceFieldOptions = CRM_Price_BAO_PriceFieldValue::getValues($priceField['id'], $options, 'id', 1);
                         if (empty($priceFieldOptions)) {
                             continue;
                         }
                         $countRow = 0;
                         $defaults['amount_label'] = $priceField['label'];
                         foreach ($options as $optionId => $optionValue) {
                             $countRow++;
                             $defaults['value'][$countRow] = $optionValue['amount'];
                             $defaults['label'][$countRow] = CRM_Utils_Array::value('label', $optionValue);
                             $defaults['name'][$countRow] = CRM_Utils_Array::value('name', $optionValue);
                             $defaults['weight'][$countRow] = $optionValue['weight'];
                             $defaults["price_field_value"][$countRow] = $optionValue['id'];
                             if ($optionValue['is_default']) {
                                 $defaults['default'] = $countRow;
                             }
                         }
                     } elseif ($priceField['id'] && $priceField['html_type'] == 'Text' && ($priceField['name'] = 'other_amount' && $priceField['is_active'])) {
                         $defaults['price_field_other'] = $priceField['id'];
                         if (!isset($defaults['amount_label'])) {
                             $defaults['amount_label'] = $priceField['label'];
                         }
                     }
                 }
             }
         }
         if (empty($defaults['amount_label'])) {
             $defaults['amount_label'] = ts('Contribution Amount');
         }
         if (!empty($defaults['value']) && is_array($defaults['value'])) {
             // CRM-4038: fix value display
             foreach ($defaults['value'] as &$amount) {
                 $amount = trim(CRM_Utils_Money::format($amount, ' '));
             }
         }
     }
     // fix the display of the monetary value, CRM-4038
     if (isset($defaults['min_amount'])) {
         $defaults['min_amount'] = CRM_Utils_Money::format($defaults['min_amount'], NULL, '%a');
     }
     if (isset($defaults['max_amount'])) {
         $defaults['max_amount'] = CRM_Utils_Money::format($defaults['max_amount'], NULL, '%a');
     }
     if (!empty($defaults['payment_processor'])) {
         $defaults['payment_processor'] = array_fill_keys(explode(CRM_Core_DAO::VALUE_SEPARATOR, $defaults['payment_processor']), '1');
     }
     return $defaults;
 }
Example #9
0
 /**
  * Process the form submission.
  */
 public function postProcess()
 {
     $config = CRM_Core_Config::singleton();
     // we first reset the confirm page so it accepts new values
     $this->controller->resetPage('Confirm');
     // get the submitted form values.
     $params = $this->controller->exportValues($this->_name);
     //carry campaign from profile.
     if (array_key_exists('contribution_campaign_id', $params)) {
         $params['campaign_id'] = $params['contribution_campaign_id'];
     }
     if (!empty($params['onbehalfof_id'])) {
         $params['organization_id'] = $params['onbehalfof_id'];
     }
     $params['currencyID'] = $config->defaultCurrency;
     if (!empty($params['priceSetId'])) {
         $is_quick_config = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config');
         if ($is_quick_config) {
             $priceField = new CRM_Price_DAO_PriceField();
             $priceField->price_set_id = $params['priceSetId'];
             $priceField->orderBy('weight');
             $priceField->find();
             $priceOptions = array();
             while ($priceField->fetch()) {
                 CRM_Price_BAO_PriceFieldValue::getValues($priceField->id, $priceOptions);
                 if ($selectedPriceOptionID = CRM_Utils_Array::value("price_{$priceField->id}", $params)) {
                     switch ($priceField->name) {
                         case 'membership_amount':
                             $this->_params['selectMembership'] = $params['selectMembership'] = CRM_Utils_Array::value('membership_type_id', $priceOptions[$selectedPriceOptionID]);
                             $this->set('selectMembership', $params['selectMembership']);
                             if (CRM_Utils_Array::value('is_separate_payment', $this->_membershipBlock) == 0) {
                                 $this->_values['amount'] = CRM_Utils_Array::value('amount', $priceOptions[$selectedPriceOptionID]);
                             }
                             break;
                         case 'contribution_amount':
                             $params['amount'] = $selectedPriceOptionID;
                             $this->_values['amount'] = CRM_Utils_Array::value('amount', $priceOptions[$selectedPriceOptionID]);
                             $this->_values[$selectedPriceOptionID]['value'] = CRM_Utils_Array::value('amount', $priceOptions[$selectedPriceOptionID]);
                             $this->_values[$selectedPriceOptionID]['label'] = CRM_Utils_Array::value('label', $priceOptions[$selectedPriceOptionID]);
                             $this->_values[$selectedPriceOptionID]['amount_id'] = CRM_Utils_Array::value('id', $priceOptions[$selectedPriceOptionID]);
                             $this->_values[$selectedPriceOptionID]['weight'] = CRM_Utils_Array::value('weight', $priceOptions[$selectedPriceOptionID]);
                             break;
                         case 'other_amount':
                             $params['amount_other'] = $selectedPriceOptionID;
                             break;
                     }
                 }
             }
         }
     }
     if ($this->_values['is_pay_later'] && empty($this->_paymentProcessor) && !array_key_exists('hidden_processor', $params) || !empty($params['payment_processor_id']) && $params['payment_processor_id'] == 0) {
         $params['is_pay_later'] = 1;
     } else {
         $params['is_pay_later'] = 0;
     }
     $this->set('is_pay_later', $params['is_pay_later']);
     // assign pay later stuff
     $this->_params['is_pay_later'] = CRM_Utils_Array::value('is_pay_later', $params, FALSE);
     $this->assign('is_pay_later', $params['is_pay_later']);
     if ($params['is_pay_later']) {
         $this->assign('pay_later_text', $this->_values['pay_later_text']);
         $this->assign('pay_later_receipt', $this->_values['pay_later_receipt']);
     }
     // from here on down, $params['amount'] holds a monetary value (or null) rather than an option ID
     $params['amount'] = self::computeAmount($params, $this->_values);
     $params['separate_amount'] = $params['amount'];
     $memFee = NULL;
     if (!empty($params['selectMembership'])) {
         if (!empty($this->_membershipTypeValues)) {
             $membershipTypeValues = $this->_membershipTypeValues[$params['selectMembership']];
         } else {
             $membershipTypeValues = CRM_Member_BAO_Membership::buildMembershipTypeValues($this, $params['selectMembership']);
         }
         $memFee = $membershipTypeValues['minimum_fee'];
         if (!$params['amount'] && !$this->_separateMembershipPayment) {
             $params['amount'] = $memFee ? $memFee : 0;
         }
     }
     //If the membership & contribution is used in contribution page & not separate payment
     $fieldId = $memPresent = $membershipLabel = $fieldOption = $is_quick_config = NULL;
     $proceFieldAmount = 0;
     if (property_exists($this, '_separateMembershipPayment') && $this->_separateMembershipPayment == 0) {
         $is_quick_config = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config');
         if ($is_quick_config) {
             foreach ($this->_priceSet['fields'] as $fieldKey => $fieldVal) {
                 if ($fieldVal['name'] == 'membership_amount' && !empty($params['price_' . $fieldKey])) {
                     $fieldId = $fieldVal['id'];
                     $fieldOption = $params['price_' . $fieldId];
                     $proceFieldAmount += $fieldVal['options'][$this->_submitValues['price_' . $fieldId]]['amount'];
                     $memPresent = TRUE;
                 } else {
                     if (!empty($params['price_' . $fieldKey]) && $memPresent && ($fieldVal['name'] == 'other_amount' || $fieldVal['name'] == 'contribution_amount')) {
                         $fieldId = $fieldVal['id'];
                         if ($fieldVal['name'] == 'other_amount') {
                             $proceFieldAmount += $this->_submitValues['price_' . $fieldId];
                         } elseif ($fieldVal['name'] == 'contribution_amount' && $this->_submitValues['price_' . $fieldId] > 0) {
                             $proceFieldAmount += $fieldVal['options'][$this->_submitValues['price_' . $fieldId]]['amount'];
                         }
                         unset($params['price_' . $fieldId]);
                         break;
                     }
                 }
             }
         }
     }
     if (!isset($params['amount_other'])) {
         $this->set('amount_level', CRM_Utils_Array::value('amount_level', $params));
     }
     if ($priceSetId = CRM_Utils_Array::value('priceSetId', $params)) {
         $lineItem = array();
         $is_quick_config = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $priceSetId, 'is_quick_config');
         if ($is_quick_config) {
             foreach ($this->_values['fee'] as $key => &$val) {
                 if ($val['name'] == 'other_amount' && $val['html_type'] == 'Text' && !empty($params['price_' . $key])) {
                     // Clean out any currency symbols.
                     $params['price_' . $key] = CRM_Utils_Rule::cleanMoney($params['price_' . $key]);
                     if ($params['price_' . $key] != 0) {
                         foreach ($val['options'] as $optionKey => &$options) {
                             $options['amount'] = CRM_Utils_Array::value('price_' . $key, $params);
                             break;
                         }
                     }
                     $params['price_' . $key] = 1;
                     break;
                 }
             }
         }
         $component = '';
         if ($this->_membershipBlock) {
             $component = 'membership';
         }
         CRM_Price_BAO_PriceSet::processAmount($this->_values['fee'], $params, $lineItem[$priceSetId], $component);
         if ($params['tax_amount']) {
             $this->set('tax_amount', $params['tax_amount']);
         }
         if ($proceFieldAmount) {
             $lineItem[$params['priceSetId']][$fieldOption]['unit_price'] = $proceFieldAmount;
             $lineItem[$params['priceSetId']][$fieldOption]['line_total'] = $proceFieldAmount;
             if (isset($lineItem[$params['priceSetId']][$fieldOption]['tax_amount'])) {
                 $proceFieldAmount += $lineItem[$params['priceSetId']][$fieldOption]['tax_amount'];
             }
             if (!$this->_membershipBlock['is_separate_payment']) {
                 //require when separate membership not used
                 $params['amount'] = $proceFieldAmount;
             }
         }
         $this->set('lineItem', $lineItem);
     }
     if ($this->_membershipBlock['is_separate_payment'] && !empty($params['separate_amount'])) {
         $this->set('amount', $params['separate_amount']);
     } else {
         $this->set('amount', $params['amount']);
     }
     // generate and set an invoiceID for this transaction
     $invoiceID = md5(uniqid(rand(), TRUE));
     $this->set('invoiceID', $invoiceID);
     // required only if is_monetary and valid positive amount
     if ($this->_values['is_monetary'] && is_array($this->_paymentProcessor) && ((double) $params['amount'] > 0.0 || $memFee > 0.0)) {
         // default mode is direct
         $this->set('contributeMode', 'direct');
         if ($this->_paymentProcessor && $this->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_BUTTON) {
             //get the button name
             $buttonName = $this->controller->getButtonName();
             if (in_array($buttonName, array($this->_expressButtonName, $this->_expressButtonName . '_x', $this->_expressButtonName . '_y')) && empty($params['is_pay_later'])) {
                 $this->handlePaypalExpress($invoiceID, $params);
             }
         } elseif ($this->_paymentProcessor && $this->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_NOTIFY) {
             $this->set('contributeMode', 'notify');
         }
     }
     // should we skip the confirm page?
     if (empty($this->_values['is_confirm_enabled'])) {
         // call the post process hook for the main page before we switch to confirm
         $this->postProcessHook();
         // build the confirm page
         $confirmForm =& $this->controller->_pages['Confirm'];
         $confirmForm->preProcess();
         $confirmForm->buildQuickForm();
         // the confirmation page is valid
         $data =& $this->controller->container();
         $data['valid']['Confirm'] = 1;
         // confirm the contribution
         // mainProcess calls the hook also
         $confirmForm->mainProcess();
         $qfKey = $this->controller->_key;
         // redirect to thank you page
         CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contribute/transact', "_qf_ThankYou_display=1&qfKey={$qfKey}", TRUE, NULL, FALSE));
     }
 }
Example #10
0
 /**
  * Process the form submission.
  */
 public function postProcess()
 {
     $config = CRM_Core_Config::singleton();
     // we first reset the confirm page so it accepts new values
     $this->controller->resetPage('Confirm');
     // get the submitted form values.
     $params = $this->controller->exportValues($this->_name);
     //carry campaign from profile.
     if (array_key_exists('contribution_campaign_id', $params)) {
         $params['campaign_id'] = $params['contribution_campaign_id'];
     }
     if (!empty($params['onbehalfof_id'])) {
         $params['organization_id'] = $params['onbehalfof_id'];
     }
     $params['currencyID'] = $config->defaultCurrency;
     if (!empty($params['priceSetId'])) {
         $is_quick_config = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config');
         if ($is_quick_config) {
             $priceField = new CRM_Price_DAO_PriceField();
             $priceField->price_set_id = $params['priceSetId'];
             $priceField->orderBy('weight');
             $priceField->find();
             $priceOptions = array();
             while ($priceField->fetch()) {
                 CRM_Price_BAO_PriceFieldValue::getValues($priceField->id, $priceOptions);
                 if ($selectedPriceOptionID = CRM_Utils_Array::value("price_{$priceField->id}", $params)) {
                     switch ($priceField->name) {
                         case 'membership_amount':
                             $this->_params['selectMembership'] = $params['selectMembership'] = CRM_Utils_Array::value('membership_type_id', $priceOptions[$selectedPriceOptionID]);
                             $this->set('selectMembership', $params['selectMembership']);
                             if (CRM_Utils_Array::value('is_separate_payment', $this->_membershipBlock) == 0) {
                                 $this->_values['amount'] = CRM_Utils_Array::value('amount', $priceOptions[$selectedPriceOptionID]);
                             }
                             break;
                         case 'contribution_amount':
                             $params['amount'] = $selectedPriceOptionID;
                             $this->_values['amount'] = CRM_Utils_Array::value('amount', $priceOptions[$selectedPriceOptionID]);
                             $this->_values[$selectedPriceOptionID]['value'] = CRM_Utils_Array::value('amount', $priceOptions[$selectedPriceOptionID]);
                             $this->_values[$selectedPriceOptionID]['label'] = CRM_Utils_Array::value('label', $priceOptions[$selectedPriceOptionID]);
                             $this->_values[$selectedPriceOptionID]['amount_id'] = CRM_Utils_Array::value('id', $priceOptions[$selectedPriceOptionID]);
                             $this->_values[$selectedPriceOptionID]['weight'] = CRM_Utils_Array::value('weight', $priceOptions[$selectedPriceOptionID]);
                             break;
                         case 'other_amount':
                             $params['amount_other'] = $selectedPriceOptionID;
                             break;
                     }
                 }
             }
         }
     }
     if ($this->_values['is_pay_later'] && empty($this->_paymentProcessor) && !array_key_exists('hidden_processor', $params) || !empty($params['payment_processor_id']) && $params['payment_processor_id'] == 0) {
         $params['is_pay_later'] = 1;
     } else {
         $params['is_pay_later'] = 0;
     }
     $this->set('is_pay_later', $params['is_pay_later']);
     // assign pay later stuff
     $this->_params['is_pay_later'] = CRM_Utils_Array::value('is_pay_later', $params, FALSE);
     $this->assign('is_pay_later', $params['is_pay_later']);
     if ($params['is_pay_later']) {
         $this->assign('pay_later_text', $this->_values['pay_later_text']);
         $this->assign('pay_later_receipt', $this->_values['pay_later_receipt']);
     }
     // from here on down, $params['amount'] holds a monetary value (or null) rather than an option ID
     $params['amount'] = self::computeAmount($params, $this->_values);
     $params['separate_amount'] = $params['amount'];
     $memFee = NULL;
     if (!empty($params['selectMembership'])) {
         if (!empty($this->_membershipTypeValues)) {
             $membershipTypeValues = $this->_membershipTypeValues[$params['selectMembership']];
         } else {
             $membershipTypeValues = CRM_Member_BAO_Membership::buildMembershipTypeValues($this, (array) $params['selectMembership']);
         }
         $memFee = $membershipTypeValues['minimum_fee'];
         if (!$params['amount'] && !$this->_separateMembershipPayment) {
             $params['amount'] = $memFee ? $memFee : 0;
         }
     }
     //If the membership & contribution is used in contribution page & not separate payment
     $fieldId = $memPresent = $membershipLabel = $fieldOption = $is_quick_config = NULL;
     $proceFieldAmount = 0;
     if (property_exists($this, '_separateMembershipPayment') && $this->_separateMembershipPayment == 0) {
         $is_quick_config = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config');
         if ($is_quick_config) {
             foreach ($this->_priceSet['fields'] as $fieldKey => $fieldVal) {
                 if ($fieldVal['name'] == 'membership_amount' && !empty($params['price_' . $fieldKey])) {
                     $fieldId = $fieldVal['id'];
                     $fieldOption = $params['price_' . $fieldId];
                     $proceFieldAmount += $fieldVal['options'][$this->_submitValues['price_' . $fieldId]]['amount'];
                     $memPresent = TRUE;
                 } else {
                     if (!empty($params['price_' . $fieldKey]) && $memPresent && ($fieldVal['name'] == 'other_amount' || $fieldVal['name'] == 'contribution_amount')) {
                         $fieldId = $fieldVal['id'];
                         if ($fieldVal['name'] == 'other_amount') {
                             $proceFieldAmount += $this->_submitValues['price_' . $fieldId];
                         } elseif ($fieldVal['name'] == 'contribution_amount' && $this->_submitValues['price_' . $fieldId] > 0) {
                             $proceFieldAmount += $fieldVal['options'][$this->_submitValues['price_' . $fieldId]]['amount'];
                         }
                         unset($params['price_' . $fieldId]);
                         break;
                     }
                 }
             }
         }
     }
     if (!isset($params['amount_other'])) {
         $this->set('amount_level', CRM_Utils_Array::value('amount_level', $params));
     }
     if ($priceSetId = CRM_Utils_Array::value('priceSetId', $params)) {
         $lineItem = array();
         $is_quick_config = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $priceSetId, 'is_quick_config');
         if ($is_quick_config) {
             foreach ($this->_values['fee'] as $key => &$val) {
                 if ($val['name'] == 'other_amount' && $val['html_type'] == 'Text' && !empty($params['price_' . $key])) {
                     // Clean out any currency symbols.
                     $params['price_' . $key] = CRM_Utils_Rule::cleanMoney($params['price_' . $key]);
                     if ($params['price_' . $key] != 0) {
                         foreach ($val['options'] as $optionKey => &$options) {
                             $options['amount'] = CRM_Utils_Array::value('price_' . $key, $params);
                             break;
                         }
                     }
                     $params['price_' . $key] = 1;
                     break;
                 }
             }
         }
         $component = '';
         if ($this->_membershipBlock) {
             $component = 'membership';
         }
         CRM_Price_BAO_PriceSet::processAmount($this->_values['fee'], $params, $lineItem[$priceSetId], $component);
         if ($params['tax_amount']) {
             $this->set('tax_amount', $params['tax_amount']);
         }
         if ($proceFieldAmount) {
             $lineItem[$params['priceSetId']][$fieldOption]['unit_price'] = $proceFieldAmount;
             $lineItem[$params['priceSetId']][$fieldOption]['line_total'] = $proceFieldAmount;
             if (isset($lineItem[$params['priceSetId']][$fieldOption]['tax_amount'])) {
                 $proceFieldAmount += $lineItem[$params['priceSetId']][$fieldOption]['tax_amount'];
             }
             if (!$this->_membershipBlock['is_separate_payment']) {
                 //require when separate membership not used
                 $params['amount'] = $proceFieldAmount;
             }
         }
         $this->set('lineItem', $lineItem);
     }
     if ($this->_membershipBlock['is_separate_payment'] && !empty($params['separate_amount'])) {
         $this->set('amount', $params['separate_amount']);
     } else {
         $this->set('amount', $params['amount']);
     }
     // generate and set an invoiceID for this transaction
     $invoiceID = md5(uniqid(rand(), TRUE));
     $this->set('invoiceID', $invoiceID);
     $params['invoiceID'] = $invoiceID;
     $params['description'] = ts('Online Contribution') . ': ' . ($this->_pcpInfo['title'] ? $this->_pcpInfo['title'] : $this->_values['title']);
     // required only if is_monetary and valid positive amount
     if ($this->_values['is_monetary'] && is_array($this->_paymentProcessor) && ((double) $params['amount'] > 0.0 || $memFee > 0.0)) {
         $this->setContributeMode();
         if ($this->_paymentProcessor && $this->_paymentProcessor['object']->supports('preApproval')) {
             $this->handlePreApproval($params);
         }
     }
     if (empty($this->_values['is_confirm_enabled'])) {
         $this->skipToThankYouPage();
     }
 }