3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2015
37 * Business objects for managing price fields.
40 class CRM_Price_BAO_PriceField
extends CRM_Price_DAO_PriceField
{
45 * Takes an associative array and creates a price field object.
47 * the function extract all the params it needs to initialize the create a
48 * price field object. the params array could contain additional unused name/value
51 * @param array $params
52 * (reference) an assoc array of name/value pairs.
54 * @return CRM_Price_BAO_PriceField
56 public static function add(&$params) {
57 $priceFieldBAO = new CRM_Price_BAO_PriceField();
59 $priceFieldBAO->copyValues($params);
61 if ($id = CRM_Utils_Array
::value('id', $params)) {
62 $priceFieldBAO->id
= $id;
65 $priceFieldBAO->save();
66 return $priceFieldBAO;
70 * Takes an associative array and creates a price field object.
72 * This function is invoked from within the web form layer and also from the api layer
74 * @param array $params
75 * (reference) an assoc array of name/value pairs.
77 * @return CRM_Price_DAO_PriceField
79 public static function create(&$params) {
80 if (empty($params['id']) && empty($params['name'])) {
81 $params['name'] = strtolower(CRM_Utils_String
::munge($params['label'], '_', 242));
83 $transaction = new CRM_Core_Transaction();
85 $priceField = self
::add($params);
87 if (is_a($priceField, 'CRM_Core_Error')) {
88 $transaction->rollback();
92 $optionsIds = array();
93 $maxIndex = CRM_Price_Form_Field
::NUM_OPTION
;
95 if ($priceField->html_type
== 'Text') {
98 $fieldValue = new CRM_Price_DAO_PriceFieldValue();
99 $fieldValue->price_field_id
= $priceField->id
;
101 // update previous field values( if any )
102 if ($fieldValue->find(TRUE)) {
103 $optionsIds['id'] = $fieldValue->id
;
106 $defaultArray = array();
107 //html type would be empty in update scenario not sure what would happen ...
108 if (!empty($params['html_type']) && $params['html_type'] == 'CheckBox' && isset($params['default_checkbox_option'])) {
109 $tempArray = array_keys($params['default_checkbox_option']);
110 foreach ($tempArray as $v) {
111 if ($params['option_amount'][$v]) {
112 $defaultArray[$v] = 1;
117 if (!empty($params['default_option'])) {
118 $defaultArray[$params['default_option']] = 1;
122 for ($index = 1; $index <= $maxIndex; $index++
) {
123 if (array_key_exists('option_amount', $params) &&
124 array_key_exists($index, $params['option_amount']) &&
125 (CRM_Utils_Array
::value($index, CRM_Utils_Array
::value('option_label', $params)) ||
!empty($params['is_quick_config'])) &&
126 !CRM_Utils_System
::isNull($params['option_amount'][$index])
129 'price_field_id' => $priceField->id
,
130 'label' => trim($params['option_label'][$index]),
131 'name' => CRM_Utils_String
::munge($params['option_label'][$index], '_', 64),
132 'amount' => CRM_Utils_Rule
::cleanMoney(trim($params['option_amount'][$index])),
133 'count' => CRM_Utils_Array
::value($index, CRM_Utils_Array
::value('option_count', $params), NULL),
134 'max_value' => CRM_Utils_Array
::value($index, CRM_Utils_Array
::value('option_max_value', $params), NULL),
135 'description' => CRM_Utils_Array
::value($index, CRM_Utils_Array
::value('option_description', $params), NULL),
136 'membership_type_id' => CRM_Utils_Array
::value($index, CRM_Utils_Array
::value('membership_type_id', $params), NULL),
137 'weight' => $params['option_weight'][$index],
139 'is_default' => CRM_Utils_Array
::value($params['option_weight'][$index], $defaultArray) ?
$defaultArray[$params['option_weight'][$index]] : 0,
140 'membership_num_terms' => NULL,
143 if ($options['membership_type_id']) {
144 $options['membership_num_terms'] = CRM_Utils_Array
::value($index, CRM_Utils_Array
::value('membership_num_terms', $params), 1);
147 if (CRM_Utils_Array
::value($index, CRM_Utils_Array
::value('option_financial_type_id', $params))) {
148 $options['financial_type_id'] = $params['option_financial_type_id'][$index];
150 elseif (!empty($params['financial_type_id'])) {
151 $options['financial_type_id'] = $params['financial_type_id'];
154 if ($opIds = CRM_Utils_Array
::value('option_id', $params)) {
155 if ($opId = CRM_Utils_Array
::value($index, $opIds)) {
156 $optionsIds['id'] = $opId;
159 $optionsIds['id'] = NULL;
162 CRM_Price_BAO_PriceFieldValue
::create($options, $optionsIds);
166 $transaction->commit();
171 * Fetch object based on array of properties.
173 * @param array $params
174 * (reference ) an assoc array of name/value pairs.
175 * @param array $defaults
176 * (reference ) an assoc array to hold the flattened values.
178 * @return CRM_Price_DAO_PriceField
180 public static function retrieve(&$params, &$defaults) {
181 return CRM_Core_DAO
::commonRetrieve('CRM_Price_DAO_PriceField', $params, $defaults);
185 * Update the is_active flag in the db.
188 * Id of the database record.
189 * @param bool $is_active
190 * Value we want to set the is_active field.
193 * DAO object on success, null otherwise.
195 public static function setIsActive($id, $is_active) {
196 return CRM_Core_DAO
::setFieldValue('CRM_Price_DAO_PriceField', $id, 'is_active', $is_active);
200 * Freeze form if the event is full.
203 * @param $fieldOptions
207 public static function freezeIfEnabled(&$element, $fieldOptions) {
208 if (!empty($fieldOptions['is_full'])) {
215 * Get the field title.
224 public static function getTitle($id) {
225 return CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceField', $id, 'label');
229 * This function for building custom fields.
231 * @param CRM_Core_Form $qf
232 * Form object (reference).
233 * @param string $elementName
234 * Name of the custom field.
235 * @param int $fieldId
236 * @param bool $inactiveNeeded
237 * @param bool $useRequired
238 * True if required else false.
239 * @param string $label
240 * Label for custom field.
242 * @param null $fieldOptions
243 * @param array $freezeOptions
246 * @internal param bool $search true if used for search else false
248 public static function addQuickFormElement(
255 $fieldOptions = NULL,
256 $freezeOptions = array()
259 $field = new CRM_Price_DAO_PriceField();
260 $field->id
= $fieldId;
261 if (!$field->find(TRUE)) {
262 /* FIXME: failure! */
267 if (isset($qf->_mode
) && empty($qf->_mode
)) {
270 elseif (isset($qf->_values
)) {
271 $is_pay_later = CRM_Utils_Array
::value('is_pay_later', $qf->_values
);
274 $otherAmount = $qf->get('values');
275 $config = CRM_Core_Config
::singleton();
276 $currencySymbol = CRM_Core_DAO
::getFieldValue('CRM_Financial_DAO_Currency', $config->defaultCurrency
, 'symbol', 'name');
277 $qf->assign('currencySymbol', $currencySymbol);
278 // get currency name for price field and option attributes
279 $currencyName = $config->defaultCurrency
;
281 if (!isset($label)) {
282 $label = (!empty($qf->_membershipBlock
) && $field->name
== 'contribution_amount') ?
ts('Additional Contribution') : $field->label
;
285 if ($field->name
== 'contribution_amount') {
286 $qf->_contributionAmount
= 1;
289 if (isset($qf->_online
) && $qf->_online
) {
290 $useRequired = FALSE;
293 $customOption = $fieldOptions;
294 if (!is_array($customOption)) {
295 $customOption = CRM_Price_BAO_PriceField
::getOptions($field->id
, $inactiveNeeded);
299 $valueFieldName = 'amount';
301 $invoiceSettings = CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::CONTRIBUTE_PREFERENCES_NAME
, 'contribution_invoice_settings');
302 $taxTerm = CRM_Utils_Array
::value('tax_term', $invoiceSettings);
303 $displayOpt = CRM_Utils_Array
::value('tax_display_settings', $invoiceSettings);
304 $invoicing = CRM_Utils_Array
::value('invoicing', $invoiceSettings);
305 switch ($field->html_type
) {
307 $optionKey = key($customOption);
308 $count = CRM_Utils_Array
::value('count', $customOption[$optionKey], '');
309 $max_value = CRM_Utils_Array
::value('max_value', $customOption[$optionKey], '');
310 $taxAmount = CRM_Utils_Array
::value('tax_amount', $customOption[$optionKey]);
311 if (isset($taxAmount) && $displayOpt && $invoicing) {
312 $qf->assign('displayOpt', $displayOpt);
313 $qf->assign('taxTerm', $taxTerm);
314 $qf->assign('invoicing', $invoicing);
316 $priceVal = implode($seperator, array(
317 $customOption[$optionKey][$valueFieldName] +
$taxAmount,
323 if (!empty($qf->_membershipBlock
) && !empty($qf->_quickConfig
) && $field->name
== 'other_amount' && empty($qf->_contributionAmount
)) {
326 elseif (!empty($fieldOptions[$optionKey]['label'])) {
328 $label = $fieldOptions[$optionKey]['label'];
329 if (!empty($qf->_quickConfig
) && !empty($qf->_contributionAmount
) && strtolower($fieldOptions[$optionKey]['name']) == 'other_amount') {
330 $label .= ' ' . $currencySymbol;
331 $qf->assign('priceset', $elementName);
332 $extra = array('onclick' => 'useAmountOther();');
336 $element = &$qf->add('text', $elementName, $label,
339 'price' => json_encode(array($optionKey, $priceVal)),
343 $useRequired && $field->is_required
346 $qf->add('text', 'txt-' . $elementName, $label, array('size' => '4'));
349 // CRM-6902 - Add "max" option for a price set field
350 if (in_array($optionKey, $freezeOptions)) {
351 self
::freezeIfEnabled($element, $fieldOptions[$optionKey]);
352 // CRM-14696 - Improve display for sold out price set options
353 $element->setLabel($label . ' <span class="sold-out-option">' . ts('Sold out') . '</span>');
357 if (!empty($qf->_quickConfig
)) {
358 $message = ts('Please enter a valid amount.');
362 $message = ts('%1 must be a number (with or without decimal point).', array(1 => $label));
365 // integers will have numeric rule applied to them.
366 $qf->addRule($elementName, $message, $type);
372 if (!empty($qf->_quickConfig
) && !empty($qf->_contributionAmount
)) {
373 $qf->assign('contriPriceset', $elementName);
376 foreach ($customOption as $opId => $opt) {
377 $taxAmount = CRM_Utils_Array
::value('tax_amount', $opt);
378 if ($field->is_display_amounts
) {
379 $opt['label'] = !empty($opt['label']) ?
$opt['label'] . ' - ' : '';
380 if (isset($taxAmount) && $invoicing) {
381 if ($displayOpt == 'Do_not_show') {
382 $opt['label'] = '<span class="crm-price-amount-label">' . $opt['label'] . '</span>' . '<span class="crm-price-amount-amount">' . CRM_Utils_Money
::format($opt[$valueFieldName] +
$taxAmount) . '</span>';
384 elseif ($displayOpt == 'Inclusive') {
385 $opt['label'] = '<span class="crm-price-amount-label">' . $opt['label'] . '</span>' . '<span class="crm-price-amount-amount">' . CRM_Utils_Money
::format($opt[$valueFieldName] +
$taxAmount) . '</span>';
386 $opt['label'] .= '<span class="crm-price-amount-tax"> (includes ' . $taxTerm . ' of ' . CRM_Utils_Money
::format($opt['tax_amount']) . ')</span>';
389 $opt['label'] = '<span class="crm-price-amount-label">' . $opt['label'] . '</span>' . '<span class="crm-price-amount-amount">' . CRM_Utils_Money
::format($opt[$valueFieldName]) . '</span>';
390 $opt['label'] .= '<span class="crm-price-amount-tax"> + ' . CRM_Utils_Money
::format($opt['tax_amount']) . ' ' . $taxTerm . '</span>';
394 $opt['label'] = '<span class="crm-price-amount-label">' . $opt['label'] . '</span>' . '<span class="crm-price-amount-amount">' . CRM_Utils_Money
::format($opt[$valueFieldName]) . '</span>';
397 $count = CRM_Utils_Array
::value('count', $opt, '');
398 $max_value = CRM_Utils_Array
::value('max_value', $opt, '');
399 $priceVal = implode($seperator, array($opt[$valueFieldName] +
$taxAmount, $count, $max_value));
401 'price' => json_encode(array($elementName, $priceVal)),
402 'data-amount' => $opt[$valueFieldName],
403 'data-currency' => $currencyName,
404 'data-price-field-values' => json_encode($customOption),
406 if (!empty($qf->_quickConfig
) && $field->name
== 'contribution_amount') {
407 $extra +
= array('onclick' => 'clearAmountOther();');
409 elseif (!empty($qf->_quickConfig
) && $field->name
== 'membership_amount') {
411 'onclick' => "return showHideAutoRenew({$opt['membership_type_id']});",
412 'membership-type' => $opt['membership_type_id'],
414 $qf->assign('membershipFieldID', $field->id
);
417 $choice[$opId] = $qf->createElement('radio', NULL, '', $opt['label'], $opt['id'], $extra);
420 $qf->add('text', 'txt-' . $elementName, $label, array('size' => '4'));
423 // CRM-6902 - Add "max" option for a price set field
424 if (in_array($opId, $freezeOptions)) {
425 self
::freezeIfEnabled($choice[$opId], $customOption[$opId]);
426 // CRM-14696 - Improve display for sold out price set options
427 $choice[$opId]->setText('<span class="sold-out-option">' . $choice[$opId]->getText() . ' (' . ts('Sold out') . ')</span>');
430 if (!empty($qf->_membershipBlock
) && $field->name
== 'contribution_amount') {
431 $choice[] = $qf->createElement('radio', NULL, '', ts('No thank you'), '-1',
433 'onclick' => 'clearAmountOther();',
438 if (!$field->is_required
) {
440 if (!empty($otherAmount['is_allow_other_amount']) && $field->name
== 'contribution_amount') {
441 $none = ts('Other Amount');
443 elseif (!empty($qf->_membershipBlock
) && empty($qf->_membershipBlock
['is_required']) && $field->name
== 'membership_amount') {
444 $none = ts('No thank you');
447 $none = ts('- none -');
450 $choice[] = $qf->createElement('radio', NULL, '', $none, '0',
451 array('price' => json_encode(array($elementName, '0')))
455 $element = &$qf->addGroup($choice, $elementName, $label);
457 // make contribution field required for quick config when membership block is enabled
458 if (($field->name
== 'membership_amount' ||
$field->name
== 'contribution_amount')
459 && !empty($qf->_membershipBlock
) && !$field->is_required
461 $useRequired = $field->is_required
= TRUE;
464 if ($useRequired && $field->is_required
) {
465 $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required');
470 $selectOption = $allowedOptions = $priceVal = array();
472 foreach ($customOption as $opt) {
473 $taxAmount = CRM_Utils_Array
::value('tax_amount', $opt);
474 $count = CRM_Utils_Array
::value('count', $opt, '');
475 $max_value = CRM_Utils_Array
::value('max_value', $opt, '');
477 if ($field->is_display_amounts
) {
478 $opt['label'] .= ' - ';
479 if (isset($taxAmount) && $invoicing) {
480 $opt['label'] = $opt['label'] . self
::getTaxLabel($opt, $valueFieldName, $displayOpt, $taxTerm);
483 $opt['label'] = $opt['label'] . CRM_Utils_Money
::format($opt[$valueFieldName]);
487 $priceVal[$opt['id']] = implode($seperator, array($opt[$valueFieldName] +
$taxAmount, $count, $max_value));
489 if (!in_array($opt['id'], $freezeOptions)) {
490 $allowedOptions[] = $opt['id'];
492 // CRM-14696 - Improve display for sold out price set options
494 $opt['id'] = 'crm_disabled_opt-' . $opt['id'];
495 $opt['label'] = $opt['label'] . ' (' . ts('Sold out') . ')';
498 $selectOption[$opt['id']] = $opt['label'];
501 $qf->add('text', 'txt-' . $elementName, $label, array('size' => '4'));
505 $element = &$qf->add('select', $elementName, $label,
507 '' => ts('- select -'),
509 $useRequired && $field->is_required
,
510 array('price' => json_encode($priceVal), 'class' => 'crm-select2', 'data-price-field-values' => json_encode($customOption))
513 // CRM-6902 - Add "max" option for a price set field
514 $button = substr($qf->controller
->getButtonName(), -4);
515 if (!empty($freezeOptions) && $button != 'skip') {
516 $qf->addRule($elementName, ts('Sorry, this option is currently sold out.'), 'regex', "/" . implode('|', $allowedOptions) . "/");
523 foreach ($customOption as $opId => $opt) {
524 $taxAmount = CRM_Utils_Array
::value('tax_amount', $opt);
525 $count = CRM_Utils_Array
::value('count', $opt, '');
526 $max_value = CRM_Utils_Array
::value('max_value', $opt, '');
528 if ($field->is_display_amounts
) {
529 $opt['label'] = '<span class="crm-price-amount-label">' . $opt['label'] . '</span> - ';
530 if (isset($taxAmount) && $invoicing) {
531 $opt['label'] .= self
::getTaxLabel($opt, $valueFieldName, $displayOpt, $taxTerm);
534 $opt['label'] .= CRM_Utils_Money
::format($opt[$valueFieldName]);
537 $priceVal = implode($seperator, array($opt[$valueFieldName] +
$taxAmount, $count, $max_value));
538 $check[$opId] = &$qf->createElement('checkbox', $opt['id'], NULL, $opt['label'],
540 'price' => json_encode(array($opt['id'], $priceVal)),
541 'data-amount' => $opt[$valueFieldName],
542 'data-currency' => $currencyName,
546 $txtcheck[$opId] =& $qf->createElement('text', $opId, $opt['label'], array('size' => '4'));
547 $qf->addGroup($txtcheck, 'txt-' . $elementName, $label);
549 // CRM-6902 - Add "max" option for a price set field
550 if (in_array($opId, $freezeOptions)) {
551 self
::freezeIfEnabled($check[$opId], $customOption[$opId]);
552 // CRM-14696 - Improve display for sold out price set options
553 $check[$opId]->setText('<span class="sold-out-option">' . $check[$opId]->getText() . ' (' . ts('Sold out') . ')</span>');
556 $element = &$qf->addGroup($check, $elementName, $label);
557 if ($useRequired && $field->is_required
) {
558 $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required');
562 if (isset($qf->_online
) && $qf->_online
) {
568 * Retrieve a list of options for the specified field.
570 * @param int $fieldId
572 * @param bool $inactiveNeeded
573 * Include inactive options.
575 * Discard stored values.
580 public static function getOptions($fieldId, $inactiveNeeded = FALSE, $reset = FALSE) {
581 static $options = array();
584 // This would happen if the function was only called to clear the cache.
585 if (empty($fieldId)) {
590 if (empty($options[$fieldId])) {
592 CRM_Price_BAO_PriceFieldValue
::getValues($fieldId, $values, 'weight', !$inactiveNeeded);
593 $options[$fieldId] = $values;
594 $taxRates = CRM_Core_PseudoConstant
::getTaxRates();
596 // ToDo - Code for Hook Invoke
598 foreach ($options[$fieldId] as $priceFieldId => $priceFieldValues) {
599 if (isset($priceFieldValues['financial_type_id']) && array_key_exists($priceFieldValues['financial_type_id'], $taxRates)) {
600 $options[$fieldId][$priceFieldId]['tax_rate'] = $taxRates[$priceFieldValues['financial_type_id']];
601 $taxAmount = CRM_Contribute_BAO_Contribution_Utils
::calculateTaxAmount($priceFieldValues['amount'], $options[$fieldId][$priceFieldId]['tax_rate']);
602 $options[$fieldId][$priceFieldId]['tax_amount'] = $taxAmount['tax_amount'];
607 return $options[$fieldId];
611 * @param $optionLabel
616 public static function getOptionId($optionLabel, $fid) {
617 if (!$optionLabel ||
!$fid) {
621 $optionGroupName = "civicrm_price_field.amount.{$fid}";
625 option_value.id as id
627 civicrm_option_value option_value,
628 civicrm_option_group option_group
630 option_group.name = %1
631 AND option_group.id = option_value.option_group_id
632 AND option_value.label = %2";
634 $dao = CRM_Core_DAO
::executeQuery($query, array(
635 1 => array($optionGroupName, 'String'),
636 2 => array($optionLabel, 'String'),
639 while ($dao->fetch()) {
645 * Delete the price set field.
653 public static function deleteField($id) {
654 $field = new CRM_Price_DAO_PriceField();
657 if ($field->find(TRUE)) {
658 // delete the options for this field
659 CRM_Price_BAO_PriceFieldValue
::deleteValues($id);
661 // reorder the weight before delete
662 $fieldValues = array('price_set_id' => $field->price_set_id
);
664 CRM_Utils_Weight
::delWeight('CRM_Price_DAO_PriceField', $field->id
, $fieldValues);
666 // now delete the field
667 return $field->delete();
676 public static function &htmlTypes() {
677 static $htmlTypes = NULL;
680 'Text' => ts('Text / Numeric Quantity'),
681 'Select' => ts('Select'),
682 'Radio' => ts('Radio'),
683 'CheckBox' => ts('CheckBox'),
690 * Validate the priceset.
692 * @param int $priceSetId
695 * retrun the error string
699 * @param bool $allowNoneSelection
702 public static function priceSetValidation($priceSetId, $fields, &$error, $allowNoneSelection = FALSE) {
703 // check for at least one positive
704 // amount price field should be selected.
705 $priceField = new CRM_Price_DAO_PriceField();
706 $priceField->price_set_id
= $priceSetId;
709 $priceFields = array();
711 if ($allowNoneSelection) {
712 $noneSelectedPriceFields = array();
715 while ($priceField->fetch()) {
716 $key = "price_{$priceField->id}";
718 if ($allowNoneSelection) {
719 if (array_key_exists($key, $fields)) {
720 if ($fields[$key] == 0 && !$priceField->is_required
) {
721 $noneSelectedPriceFields[] = $priceField->id
;
726 if (!empty($fields[$key])) {
727 $priceFields[$priceField->id
] = $fields[$key];
731 if (!empty($priceFields)) {
732 // we should has to have positive amount.
735 FROM civicrm_price_field
736 WHERE id IN (" . implode(',', array_keys($priceFields)) . ')';
737 $fieldDAO = CRM_Core_DAO
::executeQuery($sql);
738 $htmlTypes = array();
739 while ($fieldDAO->fetch()) {
740 $htmlTypes[$fieldDAO->id
] = $fieldDAO->html_type
;
743 $selectedAmounts = array();
745 foreach ($htmlTypes as $fieldId => $type) {
747 CRM_Price_BAO_PriceFieldValue
::getValues($fieldId, $options);
749 if (empty($options)) {
753 if ($type == 'Text') {
754 foreach ($options as $opId => $option) {
755 $selectedAmounts[$opId] = $priceFields[$fieldId] * $option['amount'];
759 elseif (is_array($fields["price_{$fieldId}"])) {
760 foreach (array_keys($fields["price_{$fieldId}"]) as $opId) {
761 $selectedAmounts[$opId] = $options[$opId]['amount'];
764 elseif (in_array($fields["price_{$fieldId}"], array_keys($options))) {
765 $selectedAmounts[$fields["price_{$fieldId}"]] = $options[$fields["price_{$fieldId}"]]['amount'];
769 list($componentName) = explode(':', $fields['_qf_default']);
770 // now we have all selected amount in hand.
771 $totalAmount = array_sum($selectedAmounts);
772 if ($totalAmount < 0) {
773 $error['_qf_default'] = ts('%1 amount can not be less than zero. Please select the options accordingly.', array(1 => $componentName));
777 if ($allowNoneSelection) {
778 if (empty($noneSelectedPriceFields)) {
779 $error['_qf_default'] = ts('Please select at least one option from price set.');
783 $error['_qf_default'] = ts('Please select at least one option from price set.');
789 * Generate the label for price fields based on tax display setting option on CiviContribute Component Settings page.
792 * @param string $valueFieldName
794 * @param string $displayOpt
795 * Tax display setting option.
797 * @param string $taxTerm
800 * Tax label for custom field.
802 public static function getTaxLabel($opt, $valueFieldName, $displayOpt, $taxTerm) {
803 if ($displayOpt == 'Do_not_show') {
804 $label = CRM_Utils_Money
::format($opt[$valueFieldName] +
$opt['tax_amount']);
806 elseif ($displayOpt == 'Inclusive') {
807 $label = CRM_Utils_Money
::format($opt[$valueFieldName] +
$opt['tax_amount']);
808 $label .= '<span class="crm-price-amount-tax"> (includes ' . $taxTerm . ' of ' . CRM_Utils_Money
::format($opt['tax_amount']) . ')</span>';
811 $label = CRM_Utils_Money
::format($opt[$valueFieldName]);
812 $label .= '<span class="crm-price-amount-tax"> + ' . CRM_Utils_Money
::format($opt['tax_amount']) . ' ' . $taxTerm . '</span>';