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];
151 } elseif (!empty($params['financial_type_id'])) {
152 $options['financial_type_id'] = $params['financial_type_id'];
155 if ($opIds = CRM_Utils_Array
::value('option_id', $params)) {
156 if ($opId = CRM_Utils_Array
::value($index, $opIds)) {
157 $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 object
181 public static function retrieve(&$params, &$defaults) {
182 return CRM_Core_DAO
::commonRetrieve('CRM_Price_DAO_PriceField', $params, $defaults);
186 * Update the is_active flag in the db
189 * Id of the database record.
190 * @param bool $is_active
191 * Value we want to set the is_active field.
193 * @return Object DAO object on sucess, null otherwise
197 public static function setIsActive($id, $is_active) {
198 return CRM_Core_DAO
::setFieldValue('CRM_Price_DAO_PriceField', $id, 'is_active', $is_active);
201 public static function freezeIfEnabled(&$element, $fieldOptions) {
202 if (!empty($fieldOptions['is_full'])) {
209 * Get the field title.
214 * @return string name
219 public static function getTitle($id) {
220 return CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceField', $id, 'label');
224 * This function for building custom fields
226 * @param CRM_Core_Form $qf
227 * Form object (reference).
228 * @param string $elementName
229 * Name of the custom field.
230 * @param int $fieldId
231 * @param bool $inactiveNeeded
232 * @param bool $useRequired
233 * True if required else false.
234 * @param string $label
235 * Label for custom field.
237 * @param null $fieldOptions
238 * @param array $freezeOptions
241 * @internal param bool $search true if used for search else false
244 public static function addQuickFormElement(&$qf,
250 $fieldOptions = NULL,
251 $freezeOptions = array()
254 $field = new CRM_Price_DAO_PriceField();
255 $field->id
= $fieldId;
256 if (!$field->find(TRUE)) {
257 /* FIXME: failure! */
262 if (isset($qf->_mode
) && empty($qf->_mode
)) {
265 elseif (isset($qf->_values
)) {
266 $is_pay_later = CRM_Utils_Array
::value( 'is_pay_later', $qf->_values
);
269 $otherAmount = $qf->get('values');
270 $config = CRM_Core_Config
::singleton();
271 $currencySymbol = CRM_Core_DAO
::getFieldValue('CRM_Financial_DAO_Currency',$config->defaultCurrency
,'symbol','name');
272 $qf->assign('currencySymbol', $currencySymbol);
273 // get currency name for price field and option attributes
274 $currencyName = $config->defaultCurrency
;
276 if (!isset($label)) {
277 $label = (!empty($qf->_membershipBlock
) && $field->name
== 'contribution_amount') ?
ts('Additional Contribution') : $field->label
;
280 if ($field->name
== 'contribution_amount') {
281 $qf->_contributionAmount
= 1;
284 if (isset($qf->_online
) && $qf->_online
) {
285 $useRequired = FALSE;
288 $customOption = $fieldOptions;
289 if (!is_array($customOption)) {
290 $customOption = CRM_Price_BAO_PriceField
::getOptions($field->id
, $inactiveNeeded);
294 $valueFieldName = 'amount';
296 $invoiceSettings = CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::CONTRIBUTE_PREFERENCES_NAME
, 'contribution_invoice_settings');
297 $taxTerm = CRM_Utils_Array
::value('tax_term', $invoiceSettings);
298 $displayOpt = CRM_Utils_Array
::value('tax_display_settings', $invoiceSettings);
299 $invoicing = CRM_Utils_Array
::value('invoicing', $invoiceSettings);
300 switch ($field->html_type
) {
302 $optionKey = key($customOption);
303 $count = CRM_Utils_Array
::value('count', $customOption[$optionKey], '');
304 $max_value = CRM_Utils_Array
::value('max_value', $customOption[$optionKey], '');
305 $taxAmount = CRM_Utils_Array
::value('tax_amount', $customOption[$optionKey]);
306 if (isset($taxAmount) && $displayOpt && $invoicing) {
307 $qf->assign('displayOpt', $displayOpt);
308 $qf->assign('taxTerm', $taxTerm);
309 $qf->assign('invoicing', $invoicing);
311 $priceVal = implode($seperator, array($customOption[$optionKey][$valueFieldName] +
$taxAmount, $count, $max_value));
314 if (!empty($qf->_quickConfig
) && !empty($qf->_contributionAmount
)) {
315 foreach($fieldOptions as &$fieldOption) {
316 if ($fieldOption['name'] == 'other_amount') {
317 $fieldOption['label'] = $fieldOption['label'] . ' ' . $currencySymbol;
320 $qf->assign('priceset', $elementName);
321 $extra = array('onclick' => 'useAmountOther();');
324 if (!empty($qf->_membershipBlock
) && !empty($qf->_quickConfig
) && $field->name
== 'other_amount' && empty($qf->_contributionAmount
)) {
327 elseif (!empty($fieldOptions[$optionKey]['label'])) { //check for label.
328 $label = $fieldOptions[$optionKey]['label'];
331 $element = &$qf->add('text', $elementName, $label,
333 array('price' => json_encode(array($optionKey, $priceVal)),
337 $useRequired && $field->is_required
340 $qf->add( 'text', 'txt-'.$elementName, $label, array( 'size' => '4'));
343 // CRM-6902 - Add "max" option for a price set field
344 if (in_array($optionKey, $freezeOptions)) {
345 self
::freezeIfEnabled($element, $freezeOptions);
346 // CRM-14696 - Improve display for sold out price set options
347 $element->setLabel($label . ' <span class="sold-out-option">' . ts('Sold out') . '</span>');
351 if (!empty($qf->_quickConfig
)) {
352 $message = ts('Please enter a valid amount.');
356 $message = ts('%1 must be a number (with or without decimal point).', array(1 => $label));
359 // integers will have numeric rule applied to them.
360 $qf->addRule($elementName, $message, $type);
366 if (!empty($qf->_quickConfig
) && !empty($qf->_contributionAmount
)) {
367 $qf->assign('contriPriceset', $elementName);
370 foreach ($customOption as $opId => $opt) {
371 $taxAmount = CRM_Utils_Array
::value('tax_amount', $opt);
372 if ($field->is_display_amounts
) {
373 $opt['label'] = !empty($opt['label']) ?
$opt['label'] . ' - ' : '';
374 if (isset($taxAmount) && $invoicing) {
375 if ($displayOpt == 'Do_not_show') {
376 $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>';
378 else if ($displayOpt == 'Inclusive') {
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>';
380 $opt['label'] .= '<span class="crm-price-amount-tax"> (includes ' . $taxTerm . ' of ' . CRM_Utils_Money
::format($opt['tax_amount']) . ')</span>';
383 $opt['label'] = '<span class="crm-price-amount-label">' . $opt['label'] . '</span>' . '<span class="crm-price-amount-amount">' . CRM_Utils_Money
::format($opt[$valueFieldName]) . '</span>';
384 $opt['label'] .= '<span class="crm-price-amount-tax"> + '. CRM_Utils_Money
::format($opt['tax_amount']) . ' ' . $taxTerm . '</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>';
391 $count = CRM_Utils_Array
::value('count', $opt, '');
392 $max_value = CRM_Utils_Array
::value('max_value', $opt, '');
393 $priceVal = implode($seperator, array($opt[$valueFieldName] +
$taxAmount, $count, $max_value));
394 $extra = array('price' => json_encode(array($elementName, $priceVal)),
395 'data-amount' => $opt[$valueFieldName],
396 'data-currency' => $currencyName,
398 if (!empty($qf->_quickConfig
) && $field->name
== 'contribution_amount') {
399 $extra +
= array('onclick' => 'clearAmountOther();');
401 elseif (!empty($qf->_quickConfig
) && $field->name
== 'membership_amount') {
403 'onclick' => "return showHideAutoRenew({$opt['membership_type_id']});",
404 'membership-type' => $opt['membership_type_id'],
406 $qf->assign('membershipFieldID',$field->id
);
409 $choice[$opId] = $qf->createElement('radio', NULL, '', $opt['label'], $opt['id'], $extra);
412 $qf->add( 'text', 'txt-'.$elementName, $label, array( 'size' => '4'));
415 // CRM-6902 - Add "max" option for a price set field
416 if (in_array($opId, $freezeOptions)) {
417 self
::freezeIfEnabled($choice[$opId], $customOption[$opId]);
418 // CRM-14696 - Improve display for sold out price set options
419 $choice[$opId]->setText('<span class="sold-out-option">' . $choice[$opId]->getText() . ' (' . ts('Sold out') . ')</span>');
422 if (!empty($qf->_membershipBlock
) && $field->name
== 'contribution_amount') {
423 $choice[] = $qf->createElement('radio', NULL, '', ts('No thank you'), '-1',
425 'onclick' => 'clearAmountOther();',
430 if (!$field->is_required
) {
432 if (!empty($otherAmount['is_allow_other_amount']) && $field->name
== 'contribution_amount') {
433 $none = ts('Other Amount');
435 elseif (!empty($qf->_membershipBlock
) && empty($qf->_membershipBlock
['is_required']) && $field->name
== 'membership_amount') {
436 $none = ts('No thank you');
439 $none = ts('- none -');
442 $choice[] = $qf->createElement('radio', NULL, '', $none, '0',
443 array('price' => json_encode(array($elementName, '0')))
447 $element = &$qf->addGroup($choice, $elementName, $label);
449 // make contribution field required for quick config when membership block is enabled
450 if (($field->name
== 'membership_amount' ||
$field->name
== 'contribution_amount')
451 && !empty($qf->_membershipBlock
) && !$field->is_required
) {
452 $useRequired = $field->is_required
= TRUE;
455 if ($useRequired && $field->is_required
) {
456 $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required');
461 $selectOption = $allowedOptions = $priceVal = array();
463 foreach ($customOption as $opt) {
464 $taxAmount = CRM_Utils_Array
::value('tax_amount', $opt);
465 $count = CRM_Utils_Array
::value('count', $opt, '');
466 $max_value = CRM_Utils_Array
::value('max_value', $opt, '');
468 if ($field->is_display_amounts
) {
469 $opt['label'] .= ' - ';
470 if (isset($taxAmount) && $invoicing) {
471 $opt['label'] = $opt['label'] . self
::getTaxLabel($opt, $valueFieldName, $displayOpt, $taxTerm);
474 $opt['label'] = $opt['label'] . CRM_Utils_Money
::format($opt[$valueFieldName]);
478 $selectOption[$opt['id']] = $opt['label'];
479 $priceVal[$opt['id']] = implode($seperator, array($opt[$valueFieldName] +
$taxAmount, $count, $max_value));
481 if (!in_array($opt['id'], $freezeOptions)) {
482 $allowedOptions[] = $opt['id'];
484 // CRM-14696 - Improve display for sold out price set options
486 $opt['label'] = $opt['label'] . ' (' . ts('Sold out') . ')';
489 $selectOption[$opt['id']] = $opt['label'];
492 $qf->add( 'text', 'txt-'.$elementName, $label, array( 'size' => '4'));
496 $element = &$qf->add('select', $elementName, $label,
498 '' => ts('- select -')) +
$selectOption,
499 $useRequired && $field->is_required
,
500 array('price' => json_encode($priceVal))
503 // CRM-6902 - Add "max" option for a price set field
504 $button = substr($qf->controller
->getButtonName(), -4);
505 if (!empty($freezeOptions) && $button != 'skip') {
506 $qf->addRule($elementName, ts('Sorry, this option is currently sold out.'), 'regex', "/" . implode('|', $allowedOptions) . "/");
513 foreach ($customOption as $opId => $opt) {
514 $taxAmount = CRM_Utils_Array
::value('tax_amount', $opt);
515 $count = CRM_Utils_Array
::value('count', $opt, '');
516 $max_value = CRM_Utils_Array
::value('max_value', $opt, '');
518 if ($field->is_display_amounts
) {
519 $opt['label'] = '<span class="crm-price-amount-label">' . $opt['label'] . '</span> - ';
520 if (isset($taxAmount) && $invoicing) {
521 $opt['label'] .= self
::getTaxLabel($opt, $valueFieldName, $displayOpt, $taxTerm);
524 $opt['label'] .= CRM_Utils_Money
::format($opt[$valueFieldName]);
527 $priceVal = implode($seperator, array($opt[$valueFieldName] +
$taxAmount, $count, $max_value));
528 $check[$opId] = &$qf->createElement('checkbox', $opt['id'], NULL, $opt['label'],
529 array('price' => json_encode(array($opt['id'], $priceVal)),
530 'data-amount' => $opt[$valueFieldName],
531 'data-currency' => $currencyName,
535 $txtcheck[$opId] =& $qf->createElement( 'text', $opId, $opt['label'], array( 'size' => '4' ) );
536 $qf->addGroup($txtcheck, 'txt-'.$elementName, $label);
538 // CRM-6902 - Add "max" option for a price set field
539 if (in_array($opId, $freezeOptions)) {
540 self
::freezeIfEnabled($check[$opId], $customOption[$opId]);
541 // CRM-14696 - Improve display for sold out price set options
542 $check[$opId]->setText('<span class="sold-out-option">' . $check[$opId]->getText() . ' (' . ts('Sold out') . ')</span>');
545 $element = &$qf->addGroup($check, $elementName, $label);
546 if ($useRequired && $field->is_required
) {
547 $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required');
551 if (isset($qf->_online
) && $qf->_online
) {
557 * Retrieve a list of options for the specified field
559 * @param int $fieldId
561 * @param bool $inactiveNeeded
562 * Include inactive options.
564 * Ignore stored values\.
566 * @return array array of options
568 public static function getOptions($fieldId, $inactiveNeeded = FALSE, $reset = FALSE) {
569 static $options = array();
571 if ($reset ||
empty($options[$fieldId])) {
573 CRM_Price_BAO_PriceFieldValue
::getValues($fieldId, $values, 'weight', !$inactiveNeeded);
574 $options[$fieldId] = $values;
575 $taxRates = CRM_Core_PseudoConstant
::getTaxRates();
577 // ToDo - Code for Hook Invoke
579 foreach ($options[$fieldId] as $priceFieldId => $priceFieldValues) {
580 if (isset($priceFieldValues['financial_type_id']) && array_key_exists($priceFieldValues['financial_type_id'], $taxRates)) {
581 $options[$fieldId][$priceFieldId]['tax_rate'] = $taxRates[$priceFieldValues['financial_type_id']];
582 $taxAmount = CRM_Contribute_BAO_Contribution_Utils
::calculateTaxAmount($priceFieldValues['amount'], $options[$fieldId][$priceFieldId]['tax_rate']);
583 $options[$fieldId][$priceFieldId]['tax_amount'] = round($taxAmount['tax_amount'],2);
588 return $options[$fieldId];
592 * @param $optionLabel
597 public static function getOptionId($optionLabel, $fid) {
598 if (!$optionLabel ||
!$fid) {
602 $optionGroupName = "civicrm_price_field.amount.{$fid}";
606 option_value.id as id
608 civicrm_option_value option_value,
609 civicrm_option_group option_group
611 option_group.name = %1
612 AND option_group.id = option_value.option_group_id
613 AND option_value.label = %2";
615 $dao = CRM_Core_DAO
::executeQuery($query, array(1 => array($optionGroupName, 'String'), 2 => array($optionLabel, 'String')));
617 while ($dao->fetch()) {
623 * Delete the price set field.
633 public static function deleteField($id) {
634 $field = new CRM_Price_DAO_PriceField();
637 if ($field->find(TRUE)) {
638 // delete the options for this field
639 CRM_Price_BAO_PriceFieldValue
::deleteValues($id);
641 // reorder the weight before delete
642 $fieldValues = array('price_set_id' => $field->price_set_id
);
644 CRM_Utils_Weight
::delWeight('CRM_Price_DAO_PriceField', $field->id
, $fieldValues);
646 // now delete the field
647 return $field->delete();
656 public static function &htmlTypes() {
657 static $htmlTypes = NULL;
660 'Text' => ts('Text / Numeric Quantity'),
661 'Select' => ts('Select'),
662 'Radio' => ts('Radio'),
663 'CheckBox' => ts('CheckBox'),
670 * Validate the priceset
672 * @param int $priceSetId
675 * retrun the error string
679 * @param bool $allowNoneSelection
684 public static function priceSetValidation($priceSetId, $fields, &$error, $allowNoneSelection = FALSE) {
685 // check for at least one positive
686 // amount price field should be selected.
687 $priceField = new CRM_Price_DAO_PriceField();
688 $priceField->price_set_id
= $priceSetId;
691 $priceFields = array();
693 if ($allowNoneSelection) {
694 $noneSelectedPriceFields = array();
697 while ($priceField->fetch()) {
698 $key = "price_{$priceField->id}";
700 if ($allowNoneSelection) {
701 if (array_key_exists($key, $fields)) {
702 if ($fields[$key] == 0 && !$priceField->is_required
) {
703 $noneSelectedPriceFields[] = $priceField->id
;
708 if (!empty($fields[$key])) {
709 $priceFields[$priceField->id
] = $fields[$key];
713 if (!empty($priceFields)) {
714 // we should has to have positive amount.
717 FROM civicrm_price_field
718 WHERE id IN (" . implode(',', array_keys($priceFields)) . ')';
719 $fieldDAO = CRM_Core_DAO
::executeQuery($sql);
720 $htmlTypes = array();
721 while ($fieldDAO->fetch()) {
722 $htmlTypes[$fieldDAO->id
] = $fieldDAO->html_type
;
725 $selectedAmounts = array();
727 foreach ($htmlTypes as $fieldId => $type) {
729 CRM_Price_BAO_PriceFieldValue
::getValues($fieldId, $options);
731 if (empty($options)) {
735 if ($type == 'Text') {
736 foreach ($options as $opId => $option) {
737 $selectedAmounts[$opId] = $priceFields[$fieldId] * $option['amount'];
741 elseif (is_array($fields["price_{$fieldId}"])) {
742 foreach (array_keys($fields["price_{$fieldId}"]) as $opId) {
743 $selectedAmounts[$opId] = $options[$opId]['amount'];
746 elseif (in_array($fields["price_{$fieldId}"], array_keys($options))) {
747 $selectedAmounts[$fields["price_{$fieldId}"]] = $options[$fields["price_{$fieldId}"]]['amount'];
751 list($componentName) = explode(':', $fields['_qf_default']);
752 // now we have all selected amount in hand.
753 $totalAmount = array_sum($selectedAmounts);
754 if ($totalAmount < 0) {
755 $error['_qf_default'] = ts('%1 amount can not be less than zero. Please select the options accordingly.', array(1 => $componentName));
759 if ($allowNoneSelection) {
760 if (empty($noneSelectedPriceFields)) {
761 $error['_qf_default'] = ts('Please select at least one option from price set.');
764 $error['_qf_default'] = ts('Please select at least one option from price set.');
770 * Generate the label for price fields based on tax display setting option on CiviContribute Component Settings page.
773 * @param string $valueFieldName
775 * @param string $displayOpt
776 * Tax display setting option.
778 * @return string $label tax label for custom field
783 public static function getTaxLabel($opt, $valueFieldName, $displayOpt, $taxTerm) {
784 if ($displayOpt == 'Do_not_show') {
785 $label = CRM_Utils_Money
::format($opt[$valueFieldName] +
$opt['tax_amount']);
787 else if ($displayOpt == 'Inclusive') {
788 $label = CRM_Utils_Money
::format($opt[$valueFieldName] +
$opt['tax_amount']);
789 $label .= '<span class="crm-price-amount-tax"> (includes ' . $taxTerm . ' of ' . CRM_Utils_Money
::format($opt['tax_amount']) . ')</span>';
792 $label = CRM_Utils_Money
::format($opt[$valueFieldName]);
793 $label .= '<span class="crm-price-amount-tax"> + '. CRM_Utils_Money
::format($opt['tax_amount']) . ' ' . $taxTerm . '</span>';