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
247 public static function addQuickFormElement(
254 $fieldOptions = NULL,
255 $freezeOptions = array()
258 $field = new CRM_Price_DAO_PriceField();
259 $field->id
= $fieldId;
260 if (!$field->find(TRUE)) {
261 /* FIXME: failure! */
266 if (isset($qf->_mode
) && empty($qf->_mode
)) {
269 elseif (isset($qf->_values
)) {
270 $is_pay_later = CRM_Utils_Array
::value('is_pay_later', $qf->_values
);
273 $otherAmount = $qf->get('values');
274 $config = CRM_Core_Config
::singleton();
275 $currencySymbol = CRM_Core_DAO
::getFieldValue('CRM_Financial_DAO_Currency', $config->defaultCurrency
, 'symbol', 'name');
276 $qf->assign('currencySymbol', $currencySymbol);
277 // get currency name for price field and option attributes
278 $currencyName = $config->defaultCurrency
;
280 if (!isset($label)) {
281 $label = (!empty($qf->_membershipBlock
) && $field->name
== 'contribution_amount') ?
ts('Additional Contribution') : $field->label
;
284 if ($field->name
== 'contribution_amount') {
285 $qf->_contributionAmount
= 1;
288 if (isset($qf->_online
) && $qf->_online
) {
289 $useRequired = FALSE;
292 $customOption = $fieldOptions;
293 if (!is_array($customOption)) {
294 $customOption = CRM_Price_BAO_PriceField
::getOptions($field->id
, $inactiveNeeded);
298 $valueFieldName = 'amount';
300 $invoiceSettings = Civi
::settings()->get('contribution_invoice_settings');
301 $taxTerm = CRM_Utils_Array
::value('tax_term', $invoiceSettings);
302 $displayOpt = CRM_Utils_Array
::value('tax_display_settings', $invoiceSettings);
303 $invoicing = CRM_Utils_Array
::value('invoicing', $invoiceSettings);
304 switch ($field->html_type
) {
306 $optionKey = key($customOption);
307 $count = CRM_Utils_Array
::value('count', $customOption[$optionKey], '');
308 $max_value = CRM_Utils_Array
::value('max_value', $customOption[$optionKey], '');
309 $taxAmount = CRM_Utils_Array
::value('tax_amount', $customOption[$optionKey]);
310 if (isset($taxAmount) && $displayOpt && $invoicing) {
311 $qf->assign('displayOpt', $displayOpt);
312 $qf->assign('taxTerm', $taxTerm);
313 $qf->assign('invoicing', $invoicing);
315 $priceVal = implode($seperator, array(
316 $customOption[$optionKey][$valueFieldName] +
$taxAmount,
322 if (!empty($qf->_membershipBlock
) && !empty($qf->_quickConfig
) && $field->name
== 'other_amount' && empty($qf->_contributionAmount
)) {
325 elseif (!empty($fieldOptions[$optionKey]['label'])) {
327 $label = $fieldOptions[$optionKey]['label'];
328 if (!empty($qf->_quickConfig
) && !empty($qf->_contributionAmount
) && strtolower($fieldOptions[$optionKey]['name']) == 'other_amount') {
329 $label .= ' ' . $currencySymbol;
330 $qf->assign('priceset', $elementName);
331 $extra = array('onclick' => 'useAmountOther();');
335 $element = &$qf->add('text', $elementName, $label,
338 'price' => json_encode(array($optionKey, $priceVal)),
342 $useRequired && $field->is_required
345 $qf->add('text', 'txt-' . $elementName, $label, array('size' => '4'));
348 // CRM-6902 - Add "max" option for a price set field
349 if (in_array($optionKey, $freezeOptions)) {
350 self
::freezeIfEnabled($element, $fieldOptions[$optionKey]);
351 // CRM-14696 - Improve display for sold out price set options
352 $element->setLabel($label . ' <span class="sold-out-option">' . ts('Sold out') . '</span>');
356 if (!empty($qf->_quickConfig
)) {
357 $message = ts('Please enter a valid amount.');
361 $message = ts('%1 must be a number (with or without decimal point).', array(1 => $label));
364 // integers will have numeric rule applied to them.
365 $qf->addRule($elementName, $message, $type);
371 if (!empty($qf->_quickConfig
) && !empty($qf->_contributionAmount
)) {
372 $qf->assign('contriPriceset', $elementName);
375 foreach ($customOption as $opId => $opt) {
376 $taxAmount = CRM_Utils_Array
::value('tax_amount', $opt);
377 if ($field->is_display_amounts
) {
378 $opt['label'] = !empty($opt['label']) ?
$opt['label'] . ' - ' : '';
379 if (isset($taxAmount) && $invoicing) {
380 if ($displayOpt == 'Do_not_show') {
381 $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>';
383 elseif ($displayOpt == 'Inclusive') {
384 $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>';
385 $opt['label'] .= '<span class="crm-price-amount-tax"> (includes ' . $taxTerm . ' of ' . CRM_Utils_Money
::format($opt['tax_amount']) . ')</span>';
388 $opt['label'] = '<span class="crm-price-amount-label">' . $opt['label'] . '</span>' . '<span class="crm-price-amount-amount">' . CRM_Utils_Money
::format($opt[$valueFieldName]) . '</span>';
389 $opt['label'] .= '<span class="crm-price-amount-tax"> + ' . CRM_Utils_Money
::format($opt['tax_amount']) . ' ' . $taxTerm . '</span>';
393 $opt['label'] = '<span class="crm-price-amount-label">' . $opt['label'] . '</span>' . '<span class="crm-price-amount-amount">' . CRM_Utils_Money
::format($opt[$valueFieldName]) . '</span>';
396 $count = CRM_Utils_Array
::value('count', $opt, '');
397 $max_value = CRM_Utils_Array
::value('max_value', $opt, '');
398 $priceVal = implode($seperator, array($opt[$valueFieldName] +
$taxAmount, $count, $max_value));
400 'price' => json_encode(array($elementName, $priceVal)),
401 'data-amount' => $opt[$valueFieldName],
402 'data-currency' => $currencyName,
403 'data-price-field-values' => json_encode($customOption),
405 if (!empty($qf->_quickConfig
) && $field->name
== 'contribution_amount') {
406 $extra +
= array('onclick' => 'clearAmountOther();');
408 elseif (!empty($qf->_quickConfig
) && $field->name
== 'membership_amount') {
410 'onclick' => "return showHideAutoRenew({$opt['membership_type_id']});",
411 'membership-type' => $opt['membership_type_id'],
413 $qf->assign('membershipFieldID', $field->id
);
416 $choice[$opId] = $qf->createElement('radio', NULL, '', $opt['label'], $opt['id'], $extra);
419 $qf->add('text', 'txt-' . $elementName, $label, array('size' => '4'));
422 // CRM-6902 - Add "max" option for a price set field
423 if (in_array($opId, $freezeOptions)) {
424 self
::freezeIfEnabled($choice[$opId], $customOption[$opId]);
425 // CRM-14696 - Improve display for sold out price set options
426 $choice[$opId]->setText('<span class="sold-out-option">' . $choice[$opId]->getText() . ' (' . ts('Sold out') . ')</span>');
429 if (!empty($qf->_membershipBlock
) && $field->name
== 'contribution_amount') {
430 $choice[] = $qf->createElement('radio', NULL, '', ts('No thank you'), '-1',
432 'price' => json_encode(array($elementName, '0|0')),
433 'data-currency' => $currencyName,
434 'onclick' => 'clearAmountOther();',
439 if (!$field->is_required
) {
441 if (!empty($otherAmount['is_allow_other_amount']) && $field->name
== 'contribution_amount') {
442 $none = ts('Other Amount');
444 elseif (!empty($qf->_membershipBlock
) && empty($qf->_membershipBlock
['is_required']) && $field->name
== 'membership_amount') {
445 $none = ts('No thank you');
448 $none = ts('- none -');
451 $choice[] = $qf->createElement('radio', NULL, '', $none, '0',
452 array('price' => json_encode(array($elementName, '0')))
456 $element = &$qf->addGroup($choice, $elementName, $label);
458 // make contribution field required for quick config when membership block is enabled
459 if (($field->name
== 'membership_amount' ||
$field->name
== 'contribution_amount')
460 && !empty($qf->_membershipBlock
) && !$field->is_required
462 $useRequired = $field->is_required
= TRUE;
465 if ($useRequired && $field->is_required
) {
466 $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required');
471 $selectOption = $allowedOptions = $priceVal = array();
473 foreach ($customOption as $opt) {
474 $taxAmount = CRM_Utils_Array
::value('tax_amount', $opt);
475 $count = CRM_Utils_Array
::value('count', $opt, '');
476 $max_value = CRM_Utils_Array
::value('max_value', $opt, '');
478 if ($field->is_display_amounts
) {
479 $opt['label'] .= ' - ';
480 if (isset($taxAmount) && $invoicing) {
481 $opt['label'] = $opt['label'] . self
::getTaxLabel($opt, $valueFieldName, $displayOpt, $taxTerm);
484 $opt['label'] = $opt['label'] . CRM_Utils_Money
::format($opt[$valueFieldName]);
488 $priceVal[$opt['id']] = implode($seperator, array($opt[$valueFieldName] +
$taxAmount, $count, $max_value));
490 if (!in_array($opt['id'], $freezeOptions)) {
491 $allowedOptions[] = $opt['id'];
493 // CRM-14696 - Improve display for sold out price set options
495 $opt['id'] = 'crm_disabled_opt-' . $opt['id'];
496 $opt['label'] = $opt['label'] . ' (' . ts('Sold out') . ')';
499 $selectOption[$opt['id']] = $opt['label'];
502 $qf->add('text', 'txt-' . $elementName, $label, array('size' => '4'));
506 $element = &$qf->add('select', $elementName, $label,
508 '' => ts('- select -'),
510 $useRequired && $field->is_required
,
511 array('price' => json_encode($priceVal), 'class' => 'crm-select2', 'data-price-field-values' => json_encode($customOption))
514 // CRM-6902 - Add "max" option for a price set field
515 $button = substr($qf->controller
->getButtonName(), -4);
516 if (!empty($freezeOptions) && $button != 'skip') {
517 $qf->addRule($elementName, ts('Sorry, this option is currently sold out.'), 'regex', "/" . implode('|', $allowedOptions) . "/");
524 foreach ($customOption as $opId => $opt) {
525 $taxAmount = CRM_Utils_Array
::value('tax_amount', $opt);
526 $count = CRM_Utils_Array
::value('count', $opt, '');
527 $max_value = CRM_Utils_Array
::value('max_value', $opt, '');
529 if ($field->is_display_amounts
) {
530 $opt['label'] = '<span class="crm-price-amount-label">' . $opt['label'] . '</span> - ';
531 if (isset($taxAmount) && $invoicing) {
532 $opt['label'] .= self
::getTaxLabel($opt, $valueFieldName, $displayOpt, $taxTerm);
535 $opt['label'] .= CRM_Utils_Money
::format($opt[$valueFieldName]);
538 $priceVal = implode($seperator, array($opt[$valueFieldName] +
$taxAmount, $count, $max_value));
539 $check[$opId] = &$qf->createElement('checkbox', $opt['id'], NULL, $opt['label'],
541 'price' => json_encode(array($opt['id'], $priceVal)),
542 'data-amount' => $opt[$valueFieldName],
543 'data-currency' => $currencyName,
547 $txtcheck[$opId] =& $qf->createElement('text', $opId, $opt['label'], array('size' => '4'));
548 $qf->addGroup($txtcheck, 'txt-' . $elementName, $label);
550 // CRM-6902 - Add "max" option for a price set field
551 if (in_array($opId, $freezeOptions)) {
552 self
::freezeIfEnabled($check[$opId], $customOption[$opId]);
553 // CRM-14696 - Improve display for sold out price set options
554 $check[$opId]->setText('<span class="sold-out-option">' . $check[$opId]->getText() . ' (' . ts('Sold out') . ')</span>');
557 $element = &$qf->addGroup($check, $elementName, $label);
558 if ($useRequired && $field->is_required
) {
559 $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required');
563 if (isset($qf->_online
) && $qf->_online
) {
569 * Retrieve a list of options for the specified field.
571 * @param int $fieldId
573 * @param bool $inactiveNeeded
574 * Include inactive options.
576 * Discard stored values.
581 public static function getOptions($fieldId, $inactiveNeeded = FALSE, $reset = FALSE) {
582 static $options = array();
585 // This would happen if the function was only called to clear the cache.
586 if (empty($fieldId)) {
591 if (empty($options[$fieldId])) {
593 CRM_Price_BAO_PriceFieldValue
::getValues($fieldId, $values, 'weight', !$inactiveNeeded);
594 $options[$fieldId] = $values;
595 $taxRates = CRM_Core_PseudoConstant
::getTaxRates();
597 // ToDo - Code for Hook Invoke
599 foreach ($options[$fieldId] as $priceFieldId => $priceFieldValues) {
600 if (isset($priceFieldValues['financial_type_id']) && array_key_exists($priceFieldValues['financial_type_id'], $taxRates)) {
601 $options[$fieldId][$priceFieldId]['tax_rate'] = $taxRates[$priceFieldValues['financial_type_id']];
602 $taxAmount = CRM_Contribute_BAO_Contribution_Utils
::calculateTaxAmount($priceFieldValues['amount'], $options[$fieldId][$priceFieldId]['tax_rate']);
603 $options[$fieldId][$priceFieldId]['tax_amount'] = $taxAmount['tax_amount'];
608 return $options[$fieldId];
612 * @param $optionLabel
617 public static function getOptionId($optionLabel, $fid) {
618 if (!$optionLabel ||
!$fid) {
622 $optionGroupName = "civicrm_price_field.amount.{$fid}";
626 option_value.id as id
628 civicrm_option_value option_value,
629 civicrm_option_group option_group
631 option_group.name = %1
632 AND option_group.id = option_value.option_group_id
633 AND option_value.label = %2";
635 $dao = CRM_Core_DAO
::executeQuery($query, array(
636 1 => array($optionGroupName, 'String'),
637 2 => array($optionLabel, 'String'),
640 while ($dao->fetch()) {
646 * Delete the price set field.
654 public static function deleteField($id) {
655 $field = new CRM_Price_DAO_PriceField();
658 if ($field->find(TRUE)) {
659 // delete the options for this field
660 CRM_Price_BAO_PriceFieldValue
::deleteValues($id);
662 // reorder the weight before delete
663 $fieldValues = array('price_set_id' => $field->price_set_id
);
665 CRM_Utils_Weight
::delWeight('CRM_Price_DAO_PriceField', $field->id
, $fieldValues);
667 // now delete the field
668 return $field->delete();
677 public static function &htmlTypes() {
678 static $htmlTypes = NULL;
681 'Text' => ts('Text / Numeric Quantity'),
682 'Select' => ts('Select'),
683 'Radio' => ts('Radio'),
684 'CheckBox' => ts('CheckBox'),
691 * Validate the priceset.
693 * @param int $priceSetId
696 * retrun the error string
700 * @param bool $allowNoneSelection
703 public static function priceSetValidation($priceSetId, $fields, &$error, $allowNoneSelection = FALSE) {
704 // check for at least one positive
705 // amount price field should be selected.
706 $priceField = new CRM_Price_DAO_PriceField();
707 $priceField->price_set_id
= $priceSetId;
710 $priceFields = array();
712 if ($allowNoneSelection) {
713 $noneSelectedPriceFields = array();
716 while ($priceField->fetch()) {
717 $key = "price_{$priceField->id}";
719 if ($allowNoneSelection) {
720 if (array_key_exists($key, $fields)) {
721 if ($fields[$key] == 0 && !$priceField->is_required
) {
722 $noneSelectedPriceFields[] = $priceField->id
;
727 if (!empty($fields[$key])) {
728 $priceFields[$priceField->id
] = $fields[$key];
732 if (!empty($priceFields)) {
733 // we should has to have positive amount.
736 FROM civicrm_price_field
737 WHERE id IN (" . implode(',', array_keys($priceFields)) . ')';
738 $fieldDAO = CRM_Core_DAO
::executeQuery($sql);
739 $htmlTypes = array();
740 while ($fieldDAO->fetch()) {
741 $htmlTypes[$fieldDAO->id
] = $fieldDAO->html_type
;
744 $selectedAmounts = array();
746 foreach ($htmlTypes as $fieldId => $type) {
748 CRM_Price_BAO_PriceFieldValue
::getValues($fieldId, $options);
750 if (empty($options)) {
754 if ($type == 'Text') {
755 foreach ($options as $opId => $option) {
756 $selectedAmounts[$opId] = $priceFields[$fieldId] * $option['amount'];
760 elseif (is_array($fields["price_{$fieldId}"])) {
761 foreach (array_keys($fields["price_{$fieldId}"]) as $opId) {
762 $selectedAmounts[$opId] = $options[$opId]['amount'];
765 elseif (in_array($fields["price_{$fieldId}"], array_keys($options))) {
766 $selectedAmounts[$fields["price_{$fieldId}"]] = $options[$fields["price_{$fieldId}"]]['amount'];
770 list($componentName) = explode(':', $fields['_qf_default']);
771 // now we have all selected amount in hand.
772 $totalAmount = array_sum($selectedAmounts);
773 if ($totalAmount < 0) {
774 $error['_qf_default'] = ts('%1 amount can not be less than zero. Please select the options accordingly.', array(1 => $componentName));
778 if ($allowNoneSelection) {
779 if (empty($noneSelectedPriceFields)) {
780 $error['_qf_default'] = ts('Please select at least one option from price set.');
784 $error['_qf_default'] = ts('Please select at least one option from price set.');
790 * Generate the label for price fields based on tax display setting option on CiviContribute Component Settings page.
793 * @param string $valueFieldName
795 * @param string $displayOpt
796 * Tax display setting option.
798 * @param string $taxTerm
801 * Tax label for custom field.
803 public static function getTaxLabel($opt, $valueFieldName, $displayOpt, $taxTerm) {
804 if ($displayOpt == 'Do_not_show') {
805 $label = CRM_Utils_Money
::format($opt[$valueFieldName] +
$opt['tax_amount']);
807 elseif ($displayOpt == 'Inclusive') {
808 $label = CRM_Utils_Money
::format($opt[$valueFieldName] +
$opt['tax_amount']);
809 $label .= '<span class="crm-price-amount-tax"> (includes ' . $taxTerm . ' of ' . CRM_Utils_Money
::format($opt['tax_amount']) . ')</span>';
812 $label = CRM_Utils_Money
::format($opt[$valueFieldName]);
813 $label .= '<span class="crm-price-amount-tax"> + ' . CRM_Utils_Money
::format($opt['tax_amount']) . ' ' . $taxTerm . '</span>';