3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
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 object
57 public static function add(&$params) {
58 $priceFieldBAO = new CRM_Price_BAO_PriceField();
60 $priceFieldBAO->copyValues($params);
62 if ($id = CRM_Utils_Array
::value('id', $params)) {
63 $priceFieldBAO->id
= $id;
66 $priceFieldBAO->save();
67 return $priceFieldBAO;
71 * Takes an associative array and creates a price field object
73 * This function is invoked from within the web form layer and also from the api layer
75 * @param array $params
76 * (reference) an assoc array of name/value pairs.
78 * @return CRM_Price_DAO_PriceField object
81 public static function create(&$params) {
82 if (empty($params['id']) && empty($params['name'])) {
83 $params['name'] = strtolower(CRM_Utils_String
::munge($params['label'], '_', 242));
85 $transaction = new CRM_Core_Transaction();
87 $priceField = self
::add($params);
89 if (is_a($priceField, 'CRM_Core_Error')) {
90 $transaction->rollback();
94 $optionsIds = array();
95 $maxIndex = CRM_Price_Form_Field
::NUM_OPTION
;
97 if ($priceField->html_type
== 'Text') {
100 $fieldValue = new CRM_Price_DAO_PriceFieldValue();
101 $fieldValue->price_field_id
= $priceField->id
;
103 // update previous field values( if any )
104 if ($fieldValue->find(TRUE)) {
105 $optionsIds['id'] = $fieldValue->id
;
108 $defaultArray = array();
109 //html type would be empty in update scenario not sure what would happen ...
110 if (!empty($params['html_type']) && $params['html_type'] == 'CheckBox' && isset($params['default_checkbox_option'])) {
111 $tempArray = array_keys($params['default_checkbox_option']);
112 foreach ($tempArray as $v) {
113 if ($params['option_amount'][$v]) {
114 $defaultArray[$v] = 1;
119 if (!empty($params['default_option'])) {
120 $defaultArray[$params['default_option']] = 1;
124 for ($index = 1; $index <= $maxIndex; $index++
) {
125 if (array_key_exists('option_amount', $params) &&
126 array_key_exists($index, $params['option_amount']) &&
127 (CRM_Utils_Array
::value($index, CRM_Utils_Array
::value('option_label', $params)) ||
!empty($params['is_quick_config'])) &&
128 !CRM_Utils_System
::isNull($params['option_amount'][$index])
131 'price_field_id' => $priceField->id
,
132 'label' => trim($params['option_label'][$index]),
133 'name' => CRM_Utils_String
::munge($params['option_label'][$index], '_', 64),
134 'amount' => CRM_Utils_Rule
::cleanMoney(trim($params['option_amount'][$index])),
135 'count' => CRM_Utils_Array
::value($index, CRM_Utils_Array
::value('option_count', $params), NULL),
136 'max_value' => CRM_Utils_Array
::value($index, CRM_Utils_Array
::value('option_max_value', $params), NULL),
137 'description' => CRM_Utils_Array
::value($index, CRM_Utils_Array
::value('option_description', $params), NULL),
138 'membership_type_id' => CRM_Utils_Array
::value($index, CRM_Utils_Array
::value('membership_type_id', $params), NULL),
139 'weight' => $params['option_weight'][$index],
141 'is_default' => CRM_Utils_Array
::value($params['option_weight'][$index], $defaultArray) ?
$defaultArray[$params['option_weight'][$index]] : 0,
142 'membership_num_terms' => NULL,
145 if ($options['membership_type_id']) {
146 $options['membership_num_terms'] = CRM_Utils_Array
::value($index, CRM_Utils_Array
::value('membership_num_terms', $params), 1);
149 if (CRM_Utils_Array
::value($index, CRM_Utils_Array
::value('option_financial_type_id', $params))) {
150 $options['financial_type_id'] = $params['option_financial_type_id'][$index];
152 elseif (!empty($params['financial_type_id'])) {
153 $options['financial_type_id'] = $params['financial_type_id'];
156 if ($opIds = CRM_Utils_Array
::value('option_id', $params)) {
157 if ($opId = CRM_Utils_Array
::value($index, $opIds)) {
158 $optionsIds['id'] = $opId;
161 $optionsIds['id'] = NULL;
164 CRM_Price_BAO_PriceFieldValue
::create($options, $optionsIds);
168 $transaction->commit();
173 * Fetch object based on array of properties
175 * @param array $params
176 * (reference ) an assoc array of name/value pairs.
177 * @param array $defaults
178 * (reference ) an assoc array to hold the flattened values.
180 * @return CRM_Price_DAO_PriceField object
183 public static function retrieve(&$params, &$defaults) {
184 return CRM_Core_DAO
::commonRetrieve('CRM_Price_DAO_PriceField', $params, $defaults);
188 * Update the is_active flag in the db
191 * Id of the database record.
192 * @param bool $is_active
193 * Value we want to set the is_active field.
195 * @return Object DAO object on sucess, null otherwise
199 public static function setIsActive($id, $is_active) {
200 return CRM_Core_DAO
::setFieldValue('CRM_Price_DAO_PriceField', $id, 'is_active', $is_active);
203 public static function freezeIfEnabled(&$element, $fieldOptions) {
204 if (!empty($fieldOptions['is_full'])) {
211 * Get the field title.
216 * @return string name
221 public static function getTitle($id) {
222 return CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceField', $id, 'label');
226 * This function for building custom fields
228 * @param CRM_Core_Form $qf
229 * Form object (reference).
230 * @param string $elementName
231 * Name of the custom field.
232 * @param int $fieldId
233 * @param bool $inactiveNeeded
234 * @param bool $useRequired
235 * True if required else false.
236 * @param string $label
237 * Label for custom field.
239 * @param null $fieldOptions
240 * @param array $freezeOptions
243 * @internal param bool $search true if used for search else false
246 public static function addQuickFormElement(
253 $fieldOptions = NULL,
254 $freezeOptions = array()
257 $field = new CRM_Price_DAO_PriceField();
258 $field->id
= $fieldId;
259 if (!$field->find(TRUE)) {
260 /* FIXME: failure! */
265 if (isset($qf->_mode
) && empty($qf->_mode
)) {
268 elseif (isset($qf->_values
)) {
269 $is_pay_later = CRM_Utils_Array
::value('is_pay_later', $qf->_values
);
272 $otherAmount = $qf->get('values');
273 $config = CRM_Core_Config
::singleton();
274 $currencySymbol = CRM_Core_DAO
::getFieldValue('CRM_Financial_DAO_Currency',$config->defaultCurrency
,'symbol','name');
275 $qf->assign('currencySymbol', $currencySymbol);
276 // get currency name for price field and option attributes
277 $currencyName = $config->defaultCurrency
;
279 if (!isset($label)) {
280 $label = (!empty($qf->_membershipBlock
) && $field->name
== 'contribution_amount') ?
ts('Additional Contribution') : $field->label
;
283 if ($field->name
== 'contribution_amount') {
284 $qf->_contributionAmount
= 1;
287 if (isset($qf->_online
) && $qf->_online
) {
288 $useRequired = FALSE;
291 $customOption = $fieldOptions;
292 if (!is_array($customOption)) {
293 $customOption = CRM_Price_BAO_PriceField
::getOptions($field->id
, $inactiveNeeded);
297 $valueFieldName = 'amount';
299 $invoiceSettings = CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::CONTRIBUTE_PREFERENCES_NAME
, 'contribution_invoice_settings');
300 $taxTerm = CRM_Utils_Array
::value('tax_term', $invoiceSettings);
301 $displayOpt = CRM_Utils_Array
::value('tax_display_settings', $invoiceSettings);
302 $invoicing = CRM_Utils_Array
::value('invoicing', $invoiceSettings);
303 switch ($field->html_type
) {
305 $optionKey = key($customOption);
306 $count = CRM_Utils_Array
::value('count', $customOption[$optionKey], '');
307 $max_value = CRM_Utils_Array
::value('max_value', $customOption[$optionKey], '');
308 $taxAmount = CRM_Utils_Array
::value('tax_amount', $customOption[$optionKey]);
309 if (isset($taxAmount) && $displayOpt && $invoicing) {
310 $qf->assign('displayOpt', $displayOpt);
311 $qf->assign('taxTerm', $taxTerm);
312 $qf->assign('invoicing', $invoicing);
314 $priceVal = implode($seperator, array($customOption[$optionKey][$valueFieldName] +
$taxAmount, $count, $max_value));
317 if (!empty($qf->_quickConfig
) && !empty($qf->_contributionAmount
)) {
318 foreach ($fieldOptions as &$fieldOption) {
319 if ($fieldOption['name'] == 'other_amount') {
320 $fieldOption['label'] = $fieldOption['label'] . ' ' . $currencySymbol;
323 $qf->assign('priceset', $elementName);
324 $extra = array('onclick' => 'useAmountOther();');
327 if (!empty($qf->_membershipBlock
) && !empty($qf->_quickConfig
) && $field->name
== 'other_amount' && empty($qf->_contributionAmount
)) {
330 elseif (!empty($fieldOptions[$optionKey]['label'])) { //check for label.
331 $label = $fieldOptions[$optionKey]['label'];
334 $element = &$qf->add('text', $elementName, $label,
336 array('price' => json_encode(array($optionKey, $priceVal)),
340 $useRequired && $field->is_required
343 $qf->add('text', 'txt-'.$elementName, $label, array('size' => '4'));
346 // CRM-6902 - Add "max" option for a price set field
347 if (in_array($optionKey, $freezeOptions)) {
348 self
::freezeIfEnabled($element, $freezeOptions);
349 // CRM-14696 - Improve display for sold out price set options
350 $element->setLabel($label . ' <span class="sold-out-option">' . ts('Sold out') . '</span>');
354 if (!empty($qf->_quickConfig
)) {
355 $message = ts('Please enter a valid amount.');
359 $message = ts('%1 must be a number (with or without decimal point).', array(1 => $label));
362 // integers will have numeric rule applied to them.
363 $qf->addRule($elementName, $message, $type);
369 if (!empty($qf->_quickConfig
) && !empty($qf->_contributionAmount
)) {
370 $qf->assign('contriPriceset', $elementName);
373 foreach ($customOption as $opId => $opt) {
374 $taxAmount = CRM_Utils_Array
::value('tax_amount', $opt);
375 if ($field->is_display_amounts
) {
376 $opt['label'] = !empty($opt['label']) ?
$opt['label'] . ' - ' : '';
377 if (isset($taxAmount) && $invoicing) {
378 if ($displayOpt == 'Do_not_show') {
379 $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>';
381 elseif ($displayOpt == 'Inclusive') {
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>';
383 $opt['label'] .= '<span class="crm-price-amount-tax"> (includes ' . $taxTerm . ' of ' . CRM_Utils_Money
::format($opt['tax_amount']) . ')</span>';
386 $opt['label'] = '<span class="crm-price-amount-label">' . $opt['label'] . '</span>' . '<span class="crm-price-amount-amount">' . CRM_Utils_Money
::format($opt[$valueFieldName]) . '</span>';
387 $opt['label'] .= '<span class="crm-price-amount-tax"> + ' . CRM_Utils_Money
::format($opt['tax_amount']) . ' ' . $taxTerm . '</span>';
391 $opt['label'] = '<span class="crm-price-amount-label">' . $opt['label'] . '</span>' . '<span class="crm-price-amount-amount">' . CRM_Utils_Money
::format($opt[$valueFieldName]) . '</span>';
394 $count = CRM_Utils_Array
::value('count', $opt, '');
395 $max_value = CRM_Utils_Array
::value('max_value', $opt, '');
396 $priceVal = implode($seperator, array($opt[$valueFieldName] +
$taxAmount, $count, $max_value));
397 $extra = array('price' => json_encode(array($elementName, $priceVal)),
398 'data-amount' => $opt[$valueFieldName],
399 'data-currency' => $currencyName,
401 if (!empty($qf->_quickConfig
) && $field->name
== 'contribution_amount') {
402 $extra +
= array('onclick' => 'clearAmountOther();');
404 elseif (!empty($qf->_quickConfig
) && $field->name
== 'membership_amount') {
406 'onclick' => "return showHideAutoRenew({$opt['membership_type_id']});",
407 'membership-type' => $opt['membership_type_id'],
409 $qf->assign('membershipFieldID',$field->id
);
412 $choice[$opId] = $qf->createElement('radio', NULL, '', $opt['label'], $opt['id'], $extra);
415 $qf->add('text', 'txt-'.$elementName, $label, array('size' => '4'));
418 // CRM-6902 - Add "max" option for a price set field
419 if (in_array($opId, $freezeOptions)) {
420 self
::freezeIfEnabled($choice[$opId], $customOption[$opId]);
421 // CRM-14696 - Improve display for sold out price set options
422 $choice[$opId]->setText('<span class="sold-out-option">' . $choice[$opId]->getText() . ' (' . ts('Sold out') . ')</span>');
425 if (!empty($qf->_membershipBlock
) && $field->name
== 'contribution_amount') {
426 $choice[] = $qf->createElement('radio', NULL, '', ts('No thank you'), '-1',
428 'onclick' => 'clearAmountOther();',
433 if (!$field->is_required
) {
435 if (!empty($otherAmount['is_allow_other_amount']) && $field->name
== 'contribution_amount') {
436 $none = ts('Other Amount');
438 elseif (!empty($qf->_membershipBlock
) && empty($qf->_membershipBlock
['is_required']) && $field->name
== 'membership_amount') {
439 $none = ts('No thank you');
442 $none = ts('- none -');
445 $choice[] = $qf->createElement('radio', NULL, '', $none, '0',
446 array('price' => json_encode(array($elementName, '0')))
450 $element = &$qf->addGroup($choice, $elementName, $label);
452 // make contribution field required for quick config when membership block is enabled
453 if (($field->name
== 'membership_amount' ||
$field->name
== 'contribution_amount')
454 && !empty($qf->_membershipBlock
) && !$field->is_required
) {
455 $useRequired = $field->is_required
= TRUE;
458 if ($useRequired && $field->is_required
) {
459 $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required');
464 $selectOption = $allowedOptions = $priceVal = array();
466 foreach ($customOption as $opt) {
467 $taxAmount = CRM_Utils_Array
::value('tax_amount', $opt);
468 $count = CRM_Utils_Array
::value('count', $opt, '');
469 $max_value = CRM_Utils_Array
::value('max_value', $opt, '');
471 if ($field->is_display_amounts
) {
472 $opt['label'] .= ' - ';
473 if (isset($taxAmount) && $invoicing) {
474 $opt['label'] = $opt['label'] . self
::getTaxLabel($opt, $valueFieldName, $displayOpt, $taxTerm);
477 $opt['label'] = $opt['label'] . CRM_Utils_Money
::format($opt[$valueFieldName]);
481 $selectOption[$opt['id']] = $opt['label'];
482 $priceVal[$opt['id']] = implode($seperator, array($opt[$valueFieldName] +
$taxAmount, $count, $max_value));
484 if (!in_array($opt['id'], $freezeOptions)) {
485 $allowedOptions[] = $opt['id'];
487 // CRM-14696 - Improve display for sold out price set options
489 $opt['label'] = $opt['label'] . ' (' . ts('Sold out') . ')';
492 $selectOption[$opt['id']] = $opt['label'];
495 $qf->add('text', 'txt-'.$elementName, $label, array('size' => '4'));
499 $element = &$qf->add('select', $elementName, $label,
501 '' => ts('- select -')) +
$selectOption,
502 $useRequired && $field->is_required
,
503 array('price' => json_encode($priceVal))
506 // CRM-6902 - Add "max" option for a price set field
507 $button = substr($qf->controller
->getButtonName(), -4);
508 if (!empty($freezeOptions) && $button != 'skip') {
509 $qf->addRule($elementName, ts('Sorry, this option is currently sold out.'), 'regex', "/" . implode('|', $allowedOptions) . "/");
516 foreach ($customOption as $opId => $opt) {
517 $taxAmount = CRM_Utils_Array
::value('tax_amount', $opt);
518 $count = CRM_Utils_Array
::value('count', $opt, '');
519 $max_value = CRM_Utils_Array
::value('max_value', $opt, '');
521 if ($field->is_display_amounts
) {
522 $opt['label'] = '<span class="crm-price-amount-label">' . $opt['label'] . '</span> - ';
523 if (isset($taxAmount) && $invoicing) {
524 $opt['label'] .= self
::getTaxLabel($opt, $valueFieldName, $displayOpt, $taxTerm);
527 $opt['label'] .= CRM_Utils_Money
::format($opt[$valueFieldName]);
530 $priceVal = implode($seperator, array($opt[$valueFieldName] +
$taxAmount, $count, $max_value));
531 $check[$opId] = &$qf->createElement('checkbox', $opt['id'], NULL, $opt['label'],
532 array('price' => json_encode(array($opt['id'], $priceVal)),
533 'data-amount' => $opt[$valueFieldName],
534 'data-currency' => $currencyName,
538 $txtcheck[$opId] =& $qf->createElement('text', $opId, $opt['label'], array('size' => '4'));
539 $qf->addGroup($txtcheck, 'txt-' . $elementName, $label);
541 // CRM-6902 - Add "max" option for a price set field
542 if (in_array($opId, $freezeOptions)) {
543 self
::freezeIfEnabled($check[$opId], $customOption[$opId]);
544 // CRM-14696 - Improve display for sold out price set options
545 $check[$opId]->setText('<span class="sold-out-option">' . $check[$opId]->getText() . ' (' . ts('Sold out') . ')</span>');
548 $element = &$qf->addGroup($check, $elementName, $label);
549 if ($useRequired && $field->is_required
) {
550 $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required');
554 if (isset($qf->_online
) && $qf->_online
) {
560 * Retrieve a list of options for the specified field
562 * @param int $fieldId
564 * @param bool $inactiveNeeded
565 * Include inactive options.
567 * Ignore stored values\.
569 * @return array array of options
571 public static function getOptions($fieldId, $inactiveNeeded = FALSE, $reset = FALSE) {
572 static $options = array();
574 if ($reset ||
empty($options[$fieldId])) {
576 CRM_Price_BAO_PriceFieldValue
::getValues($fieldId, $values, 'weight', !$inactiveNeeded);
577 $options[$fieldId] = $values;
578 $taxRates = CRM_Core_PseudoConstant
::getTaxRates();
580 // ToDo - Code for Hook Invoke
582 foreach ($options[$fieldId] as $priceFieldId => $priceFieldValues) {
583 if (isset($priceFieldValues['financial_type_id']) && array_key_exists($priceFieldValues['financial_type_id'], $taxRates)) {
584 $options[$fieldId][$priceFieldId]['tax_rate'] = $taxRates[$priceFieldValues['financial_type_id']];
585 $taxAmount = CRM_Contribute_BAO_Contribution_Utils
::calculateTaxAmount($priceFieldValues['amount'], $options[$fieldId][$priceFieldId]['tax_rate']);
586 $options[$fieldId][$priceFieldId]['tax_amount'] = round($taxAmount['tax_amount'],2);
591 return $options[$fieldId];
595 * @param $optionLabel
600 public static function getOptionId($optionLabel, $fid) {
601 if (!$optionLabel ||
!$fid) {
605 $optionGroupName = "civicrm_price_field.amount.{$fid}";
609 option_value.id as id
611 civicrm_option_value option_value,
612 civicrm_option_group option_group
614 option_group.name = %1
615 AND option_group.id = option_value.option_group_id
616 AND option_value.label = %2";
618 $dao = CRM_Core_DAO
::executeQuery($query, array(1 => array($optionGroupName, 'String'), 2 => array($optionLabel, 'String')));
620 while ($dao->fetch()) {
626 * Delete the price set field.
636 public static function deleteField($id) {
637 $field = new CRM_Price_DAO_PriceField();
640 if ($field->find(TRUE)) {
641 // delete the options for this field
642 CRM_Price_BAO_PriceFieldValue
::deleteValues($id);
644 // reorder the weight before delete
645 $fieldValues = array('price_set_id' => $field->price_set_id
);
647 CRM_Utils_Weight
::delWeight('CRM_Price_DAO_PriceField', $field->id
, $fieldValues);
649 // now delete the field
650 return $field->delete();
659 public static function &htmlTypes() {
660 static $htmlTypes = NULL;
663 'Text' => ts('Text / Numeric Quantity'),
664 'Select' => ts('Select'),
665 'Radio' => ts('Radio'),
666 'CheckBox' => ts('CheckBox'),
673 * Validate the priceset
675 * @param int $priceSetId
678 * retrun the error string
682 * @param bool $allowNoneSelection
687 public static function priceSetValidation($priceSetId, $fields, &$error, $allowNoneSelection = FALSE) {
688 // check for at least one positive
689 // amount price field should be selected.
690 $priceField = new CRM_Price_DAO_PriceField();
691 $priceField->price_set_id
= $priceSetId;
694 $priceFields = array();
696 if ($allowNoneSelection) {
697 $noneSelectedPriceFields = array();
700 while ($priceField->fetch()) {
701 $key = "price_{$priceField->id}";
703 if ($allowNoneSelection) {
704 if (array_key_exists($key, $fields)) {
705 if ($fields[$key] == 0 && !$priceField->is_required
) {
706 $noneSelectedPriceFields[] = $priceField->id
;
711 if (!empty($fields[$key])) {
712 $priceFields[$priceField->id
] = $fields[$key];
716 if (!empty($priceFields)) {
717 // we should has to have positive amount.
720 FROM civicrm_price_field
721 WHERE id IN (" . implode(',', array_keys($priceFields)) . ')';
722 $fieldDAO = CRM_Core_DAO
::executeQuery($sql);
723 $htmlTypes = array();
724 while ($fieldDAO->fetch()) {
725 $htmlTypes[$fieldDAO->id
] = $fieldDAO->html_type
;
728 $selectedAmounts = array();
730 foreach ($htmlTypes as $fieldId => $type) {
732 CRM_Price_BAO_PriceFieldValue
::getValues($fieldId, $options);
734 if (empty($options)) {
738 if ($type == 'Text') {
739 foreach ($options as $opId => $option) {
740 $selectedAmounts[$opId] = $priceFields[$fieldId] * $option['amount'];
744 elseif (is_array($fields["price_{$fieldId}"])) {
745 foreach (array_keys($fields["price_{$fieldId}"]) as $opId) {
746 $selectedAmounts[$opId] = $options[$opId]['amount'];
749 elseif (in_array($fields["price_{$fieldId}"], array_keys($options))) {
750 $selectedAmounts[$fields["price_{$fieldId}"]] = $options[$fields["price_{$fieldId}"]]['amount'];
754 list($componentName) = explode(':', $fields['_qf_default']);
755 // now we have all selected amount in hand.
756 $totalAmount = array_sum($selectedAmounts);
757 if ($totalAmount < 0) {
758 $error['_qf_default'] = ts('%1 amount can not be less than zero. Please select the options accordingly.', array(1 => $componentName));
762 if ($allowNoneSelection) {
763 if (empty($noneSelectedPriceFields)) {
764 $error['_qf_default'] = ts('Please select at least one option from price set.');
768 $error['_qf_default'] = ts('Please select at least one option from price set.');
774 * Generate the label for price fields based on tax display setting option on CiviContribute Component Settings page.
777 * @param string $valueFieldName
779 * @param string $displayOpt
780 * Tax display setting option.
782 * @return string $label tax label for custom field
787 public static function getTaxLabel($opt, $valueFieldName, $displayOpt, $taxTerm) {
788 if ($displayOpt == 'Do_not_show') {
789 $label = CRM_Utils_Money
::format($opt[$valueFieldName] +
$opt['tax_amount']);
791 elseif ($displayOpt == 'Inclusive') {
792 $label = CRM_Utils_Money
::format($opt[$valueFieldName] +
$opt['tax_amount']);
793 $label .= '<span class="crm-price-amount-tax"> (includes ' . $taxTerm . ' of ' . CRM_Utils_Money
::format($opt['tax_amount']) . ')</span>';
796 $label = CRM_Utils_Money
::format($opt[$valueFieldName]);
797 $label .= '<span class="crm-price-amount-tax"> + ' . CRM_Utils_Money
::format($opt['tax_amount']) . ' ' . $taxTerm . '</span>';