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 (reference) an assoc array of name/value pairs
53 * @return CRM_Price_BAO_PriceField object
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 (reference) an assoc array of name/value pairs
76 * @return CRM_Price_DAO_PriceField object
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];
149 } elseif (!empty($params['financial_type_id'])) {
150 $options['financial_type_id'] = $params['financial_type_id'];
153 if ($opIds = CRM_Utils_Array
::value('option_id', $params)) {
154 if ($opId = CRM_Utils_Array
::value($index, $opIds)) {
155 $optionsIds['id'] = $opId;
157 $optionsIds['id'] = NULL;
160 CRM_Price_BAO_PriceFieldValue
::create($options, $optionsIds);
164 $transaction->commit();
169 * Fetch object based on array of properties
171 * @param array $params (reference ) an assoc array of name/value pairs
172 * @param array $defaults (reference ) an assoc array to hold the flattened values
174 * @return CRM_Price_DAO_PriceField object
177 public static function retrieve(&$params, &$defaults) {
178 return CRM_Core_DAO
::commonRetrieve('CRM_Price_DAO_PriceField', $params, $defaults);
182 * Update the is_active flag in the db
184 * @param int $id Id of the database record
185 * @param boolean $is_active Value we want to set the is_active field
187 * @return Object DAO object on sucess, null otherwise
191 public static function setIsActive($id, $is_active) {
192 return CRM_Core_DAO
::setFieldValue('CRM_Price_DAO_PriceField', $id, 'is_active', $is_active);
195 public static function freezeIfEnabled(&$element, $fieldOptions) {
196 if (!empty($fieldOptions['is_full'])) {
203 * Get the field title.
205 * @param int $id id of field.
207 * @return string name
212 public static function getTitle($id) {
213 return CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceField', $id, 'label');
217 * This function for building custom fields
219 * @param CRM_Core_Form $qf form object (reference)
220 * @param string $elementName name of the custom field
221 * @param int $fieldId
222 * @param boolean $inactiveNeeded
223 * @param boolean $useRequired true if required else false
224 * @param string $label label for custom field
226 * @param null $fieldOptions
227 * @param array $freezeOptions
230 * @internal param bool $search true if used for search else false
233 public static function addQuickFormElement(&$qf,
239 $fieldOptions = NULL,
240 $freezeOptions = array()
243 $field = new CRM_Price_DAO_PriceField();
244 $field->id
= $fieldId;
245 if (!$field->find(TRUE)) {
246 /* FIXME: failure! */
251 if (isset($qf->_mode
) && empty($qf->_mode
)) {
254 elseif (isset($qf->_values
)) {
255 $is_pay_later = CRM_Utils_Array
::value( 'is_pay_later', $qf->_values
);
258 $otherAmount = $qf->get('values');
259 $config = CRM_Core_Config
::singleton();
260 $currencySymbol = CRM_Core_DAO
::getFieldValue('CRM_Financial_DAO_Currency',$config->defaultCurrency
,'symbol','name');
261 $qf->assign('currencySymbol', $currencySymbol);
262 // get currency name for price field and option attributes
263 $currencyName = $config->defaultCurrency
;
265 if (!isset($label)) {
266 $label = (!empty($qf->_membershipBlock
) && $field->name
== 'contribution_amount') ?
ts('Additional Contribution') : $field->label
;
269 if ($field->name
== 'contribution_amount') {
270 $qf->_contributionAmount
= 1;
273 if (isset($qf->_online
) && $qf->_online
) {
274 $useRequired = FALSE;
277 $customOption = $fieldOptions;
278 if (!is_array($customOption)) {
279 $customOption = CRM_Price_BAO_PriceField
::getOptions($field->id
, $inactiveNeeded);
283 $valueFieldName = 'amount';
285 $invoiceSettings = CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::CONTRIBUTE_PREFERENCES_NAME
, 'contribution_invoice_settings');
286 $taxTerm = CRM_Utils_Array
::value('tax_term', $invoiceSettings);
287 $displayOpt = CRM_Utils_Array
::value('tax_display_settings', $invoiceSettings);
288 $invoicing = CRM_Utils_Array
::value('invoicing', $invoiceSettings);
289 switch ($field->html_type
) {
291 $optionKey = key($customOption);
292 $count = CRM_Utils_Array
::value('count', $customOption[$optionKey], '');
293 $max_value = CRM_Utils_Array
::value('max_value', $customOption[$optionKey], '');
294 $taxAmount = CRM_Utils_Array
::value('tax_amount', $customOption[$optionKey]);
295 if (isset($taxAmount) && $displayOpt && $invoicing) {
296 $qf->assign('displayOpt', $displayOpt);
297 $qf->assign('taxTerm', $taxTerm);
298 $qf->assign('invoicing', $invoicing);
300 $priceVal = implode($seperator, array($customOption[$optionKey][$valueFieldName] +
$taxAmount, $count, $max_value));
303 if (!empty($qf->_quickConfig
) && !empty($qf->_contributionAmount
)) {
304 foreach($fieldOptions as &$fieldOption) {
305 if ($fieldOption['name'] == 'other_amount') {
306 $fieldOption['label'] = $fieldOption['label'] . ' ' . $currencySymbol;
309 $qf->assign('priceset', $elementName);
310 $extra = array('onclick' => 'useAmountOther();');
313 if (!empty($qf->_membershipBlock
) && !empty($qf->_quickConfig
) && $field->name
== 'other_amount' && empty($qf->_contributionAmount
)) {
316 elseif (!empty($fieldOptions[$optionKey]['label'])) { //check for label.
317 $label = $fieldOptions[$optionKey]['label'];
320 $element = &$qf->add('text', $elementName, $label,
322 array('price' => json_encode(array($optionKey, $priceVal)),
326 $useRequired && $field->is_required
329 $qf->add( 'text', 'txt-'.$elementName, $label, array( 'size' => '4'));
332 // CRM-6902 - Add "max" option for a price set field
333 if (in_array($optionKey, $freezeOptions)) {
334 self
::freezeIfEnabled($element, $freezeOptions);
335 // CRM-14696 - Improve display for sold out price set options
336 $element->setLabel($label . ' <span class="sold-out-option">' . ts('Sold out') . '</span>');
340 if (!empty($qf->_quickConfig
)) {
341 $message = ts('Please enter a valid amount.');
345 $message = ts('%1 must be a number (with or without decimal point).', array(1 => $label));
348 // integers will have numeric rule applied to them.
349 $qf->addRule($elementName, $message, $type);
355 if (!empty($qf->_quickConfig
) && !empty($qf->_contributionAmount
)) {
356 $qf->assign('contriPriceset', $elementName);
359 foreach ($customOption as $opId => $opt) {
360 $taxAmount = CRM_Utils_Array
::value('tax_amount', $opt);
361 if ($field->is_display_amounts
) {
362 $opt['label'] = !empty($opt['label']) ?
$opt['label'] . ' - ' : '';
363 if (isset($taxAmount) && $invoicing) {
364 if ($displayOpt == 'Do_not_show') {
365 $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>';
367 else if ($displayOpt == 'Inclusive') {
368 $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>';
369 $opt['label'] .= '<span class="crm-price-amount-tax"> (includes ' . $taxTerm . ' of ' . CRM_Utils_Money
::format($opt['tax_amount']) . ')</span>';
372 $opt['label'] = '<span class="crm-price-amount-label">' . $opt['label'] . '</span>' . '<span class="crm-price-amount-amount">' . CRM_Utils_Money
::format($opt[$valueFieldName]) . '</span>';
373 $opt['label'] .= '<span class="crm-price-amount-tax"> + '. CRM_Utils_Money
::format($opt['tax_amount']) . ' ' . $taxTerm . '</span>';
377 $opt['label'] = '<span class="crm-price-amount-label">' . $opt['label'] . '</span>' . '<span class="crm-price-amount-amount">' . CRM_Utils_Money
::format($opt[$valueFieldName]) . '</span>';
380 $count = CRM_Utils_Array
::value('count', $opt, '');
381 $max_value = CRM_Utils_Array
::value('max_value', $opt, '');
382 $priceVal = implode($seperator, array($opt[$valueFieldName] +
$taxAmount, $count, $max_value));
383 $extra = array('price' => json_encode(array($elementName, $priceVal)),
384 'data-amount' => $opt[$valueFieldName],
385 'data-currency' => $currencyName,
387 if (!empty($qf->_quickConfig
) && $field->name
== 'contribution_amount') {
388 $extra +
= array('onclick' => 'clearAmountOther();');
390 elseif (!empty($qf->_quickConfig
) && $field->name
== 'membership_amount') {
392 'onclick' => "return showHideAutoRenew({$opt['membership_type_id']});",
393 'membership-type' => $opt['membership_type_id'],
395 $qf->assign('membershipFieldID',$field->id
);
398 $choice[$opId] = $qf->createElement('radio', NULL, '', $opt['label'], $opt['id'], $extra);
401 $qf->add( 'text', 'txt-'.$elementName, $label, array( 'size' => '4'));
404 // CRM-6902 - Add "max" option for a price set field
405 if (in_array($opId, $freezeOptions)) {
406 self
::freezeIfEnabled($choice[$opId], $customOption[$opId]);
407 // CRM-14696 - Improve display for sold out price set options
408 $choice[$opId]->setText('<span class="sold-out-option">' . $choice[$opId]->getText() . ' (' . ts('Sold out') . ')</span>');
411 if (!empty($qf->_membershipBlock
) && $field->name
== 'contribution_amount') {
412 $choice[] = $qf->createElement('radio', NULL, '', ts('No thank you'), '-1',
414 'onclick' => 'clearAmountOther();',
419 if (!$field->is_required
) {
421 if (!empty($otherAmount['is_allow_other_amount']) && $field->name
== 'contribution_amount') {
422 $none = ts('Other Amount');
424 elseif (!empty($qf->_membershipBlock
) && empty($qf->_membershipBlock
['is_required']) && $field->name
== 'membership_amount') {
425 $none = ts('No thank you');
428 $none = ts('- none -');
431 $choice[] = $qf->createElement('radio', NULL, '', $none, '0',
432 array('price' => json_encode(array($elementName, '0')))
436 $element = &$qf->addGroup($choice, $elementName, $label);
438 // make contribution field required for quick config when membership block is enabled
439 if (($field->name
== 'membership_amount' ||
$field->name
== 'contribution_amount')
440 && !empty($qf->_membershipBlock
) && !$field->is_required
) {
441 $useRequired = $field->is_required
= TRUE;
444 if ($useRequired && $field->is_required
) {
445 $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required');
450 $selectOption = $allowedOptions = $priceVal = array();
452 foreach ($customOption as $opt) {
453 $taxAmount = CRM_Utils_Array
::value('tax_amount', $opt);
454 $count = CRM_Utils_Array
::value('count', $opt, '');
455 $max_value = CRM_Utils_Array
::value('max_value', $opt, '');
457 if ($field->is_display_amounts
) {
458 $opt['label'] .= ' - ';
459 if (isset($taxAmount) && $invoicing) {
460 $opt['label'] = $opt['label'] . self
::getTaxLabel($opt, $valueFieldName, $displayOpt, $taxTerm);
463 $opt['label'] = $opt['label'] . CRM_Utils_Money
::format($opt[$valueFieldName]);
467 $selectOption[$opt['id']] = $opt['label'];
468 $priceVal[$opt['id']] = implode($seperator, array($opt[$valueFieldName] +
$taxAmount, $count, $max_value));
470 if (!in_array($opt['id'], $freezeOptions)) {
471 $allowedOptions[] = $opt['id'];
473 // CRM-14696 - Improve display for sold out price set options
475 $opt['label'] = $opt['label'] . ' (' . ts('Sold out') . ')';
478 $selectOption[$opt['id']] = $opt['label'];
481 $qf->add( 'text', 'txt-'.$elementName, $label, array( 'size' => '4'));
485 $element = &$qf->add('select', $elementName, $label,
487 '' => ts('- select -')) +
$selectOption,
488 $useRequired && $field->is_required
,
489 array('price' => json_encode($priceVal))
492 // CRM-6902 - Add "max" option for a price set field
493 $button = substr($qf->controller
->getButtonName(), -4);
494 if (!empty($freezeOptions) && $button != 'skip') {
495 $qf->addRule($elementName, ts('Sorry, this option is currently sold out.'), 'regex', "/" . implode('|', $allowedOptions) . "/");
502 foreach ($customOption as $opId => $opt) {
503 $taxAmount = CRM_Utils_Array
::value('tax_amount', $opt);
504 $count = CRM_Utils_Array
::value('count', $opt, '');
505 $max_value = CRM_Utils_Array
::value('max_value', $opt, '');
507 if ($field->is_display_amounts
) {
508 $opt['label'] = '<span class="crm-price-amount-label">' . $opt['label'] . '</span> - ';
509 if (isset($taxAmount) && $invoicing) {
510 $opt['label'] .= self
::getTaxLabel($opt, $valueFieldName, $displayOpt, $taxTerm);
513 $opt['label'] .= CRM_Utils_Money
::format($opt[$valueFieldName]);
516 $priceVal = implode($seperator, array($opt[$valueFieldName] +
$taxAmount, $count, $max_value));
517 $check[$opId] = &$qf->createElement('checkbox', $opt['id'], NULL, $opt['label'],
518 array('price' => json_encode(array($opt['id'], $priceVal)),
519 'data-amount' => $opt[$valueFieldName],
520 'data-currency' => $currencyName,
524 $txtcheck[$opId] =& $qf->createElement( 'text', $opId, $opt['label'], array( 'size' => '4' ) );
525 $qf->addGroup($txtcheck, 'txt-'.$elementName, $label);
527 // CRM-6902 - Add "max" option for a price set field
528 if (in_array($opId, $freezeOptions)) {
529 self
::freezeIfEnabled($check[$opId], $customOption[$opId]);
530 // CRM-14696 - Improve display for sold out price set options
531 $check[$opId]->setText('<span class="sold-out-option">' . $check[$opId]->getText() . ' (' . ts('Sold out') . ')</span>');
534 $element = &$qf->addGroup($check, $elementName, $label);
535 if ($useRequired && $field->is_required
) {
536 $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required');
540 if (isset($qf->_online
) && $qf->_online
) {
546 * Retrieve a list of options for the specified field
548 * @param int $fieldId price field ID
549 * @param bool $inactiveNeeded include inactive options
550 * @param bool $reset ignore stored values\
552 * @return array array of options
554 public static function getOptions($fieldId, $inactiveNeeded = FALSE, $reset = FALSE) {
555 static $options = array();
557 if ($reset ||
empty($options[$fieldId])) {
559 CRM_Price_BAO_PriceFieldValue
::getValues($fieldId, $values, 'weight', !$inactiveNeeded);
560 $options[$fieldId] = $values;
561 $taxRates = CRM_Core_PseudoConstant
::getTaxRates();
563 // ToDo - Code for Hook Invoke
565 foreach ($options[$fieldId] as $priceFieldId => $priceFieldValues) {
566 if (isset($priceFieldValues['financial_type_id']) && array_key_exists($priceFieldValues['financial_type_id'], $taxRates)) {
567 $options[$fieldId][$priceFieldId]['tax_rate'] = $taxRates[$priceFieldValues['financial_type_id']];
568 $taxAmount = CRM_Contribute_BAO_Contribution_Utils
::calculateTaxAmount($priceFieldValues['amount'], $options[$fieldId][$priceFieldId]['tax_rate']);
569 $options[$fieldId][$priceFieldId]['tax_amount'] = round($taxAmount['tax_amount'],2);
574 return $options[$fieldId];
578 * @param $optionLabel
583 public static function getOptionId($optionLabel, $fid) {
584 if (!$optionLabel ||
!$fid) {
588 $optionGroupName = "civicrm_price_field.amount.{$fid}";
592 option_value.id as id
594 civicrm_option_value option_value,
595 civicrm_option_group option_group
597 option_group.name = %1
598 AND option_group.id = option_value.option_group_id
599 AND option_value.label = %2";
601 $dao = CRM_Core_DAO
::executeQuery($query, array(1 => array($optionGroupName, 'String'), 2 => array($optionLabel, 'String')));
603 while ($dao->fetch()) {
609 * Delete the price set field.
611 * @param int $id Field Id
618 public static function deleteField($id) {
619 $field = new CRM_Price_DAO_PriceField();
622 if ($field->find(TRUE)) {
623 // delete the options for this field
624 CRM_Price_BAO_PriceFieldValue
::deleteValues($id);
626 // reorder the weight before delete
627 $fieldValues = array('price_set_id' => $field->price_set_id
);
629 CRM_Utils_Weight
::delWeight('CRM_Price_DAO_PriceField', $field->id
, $fieldValues);
631 // now delete the field
632 return $field->delete();
641 public static function &htmlTypes() {
642 static $htmlTypes = NULL;
645 'Text' => ts('Text / Numeric Quantity'),
646 'Select' => ts('Select'),
647 'Radio' => ts('Radio'),
648 'CheckBox' => ts('CheckBox'),
655 * Validate the priceset
657 * @param int $priceSetId , array $fields
659 * retrun the error string
663 * @param bool $allowNoneSelection
668 public static function priceSetValidation($priceSetId, $fields, &$error, $allowNoneSelection = FALSE) {
669 // check for at least one positive
670 // amount price field should be selected.
671 $priceField = new CRM_Price_DAO_PriceField();
672 $priceField->price_set_id
= $priceSetId;
675 $priceFields = array();
677 if ($allowNoneSelection) {
678 $noneSelectedPriceFields = array();
681 while ($priceField->fetch()) {
682 $key = "price_{$priceField->id}";
684 if ($allowNoneSelection) {
685 if (array_key_exists($key, $fields)) {
686 if ($fields[$key] == 0 && !$priceField->is_required
) {
687 $noneSelectedPriceFields[] = $priceField->id
;
692 if (!empty($fields[$key])) {
693 $priceFields[$priceField->id
] = $fields[$key];
697 if (!empty($priceFields)) {
698 // we should has to have positive amount.
701 FROM civicrm_price_field
702 WHERE id IN (" . implode(',', array_keys($priceFields)) . ')';
703 $fieldDAO = CRM_Core_DAO
::executeQuery($sql);
704 $htmlTypes = array();
705 while ($fieldDAO->fetch()) {
706 $htmlTypes[$fieldDAO->id
] = $fieldDAO->html_type
;
709 $selectedAmounts = array();
711 foreach ($htmlTypes as $fieldId => $type) {
713 CRM_Price_BAO_PriceFieldValue
::getValues($fieldId, $options);
715 if (empty($options)) {
719 if ($type == 'Text') {
720 foreach ($options as $opId => $option) {
721 $selectedAmounts[$opId] = $priceFields[$fieldId] * $option['amount'];
725 elseif (is_array($fields["price_{$fieldId}"])) {
726 foreach (array_keys($fields["price_{$fieldId}"]) as $opId) {
727 $selectedAmounts[$opId] = $options[$opId]['amount'];
730 elseif (in_array($fields["price_{$fieldId}"], array_keys($options))) {
731 $selectedAmounts[$fields["price_{$fieldId}"]] = $options[$fields["price_{$fieldId}"]]['amount'];
735 list($componentName) = explode(':', $fields['_qf_default']);
736 // now we have all selected amount in hand.
737 $totalAmount = array_sum($selectedAmounts);
738 if ($totalAmount < 0) {
739 $error['_qf_default'] = ts('%1 amount can not be less than zero. Please select the options accordingly.', array(1 => $componentName));
743 if ($allowNoneSelection) {
744 if (empty($noneSelectedPriceFields)) {
745 $error['_qf_default'] = ts('Please select at least one option from price set.');
748 $error['_qf_default'] = ts('Please select at least one option from price set.');
754 * Generate the label for price fields based on tax display setting option on CiviContribute Component Settings page.
757 * @param string $valueFieldName amount
758 * @param string $displayOpt tax display setting option
760 * @return string $label tax label for custom field
765 public static function getTaxLabel($opt, $valueFieldName, $displayOpt, $taxTerm) {
766 if ($displayOpt == 'Do_not_show') {
767 $label = CRM_Utils_Money
::format($opt[$valueFieldName] +
$opt['tax_amount']);
769 else if ($displayOpt == 'Inclusive') {
770 $label = CRM_Utils_Money
::format($opt[$valueFieldName] +
$opt['tax_amount']);
771 $label .= '<span class="crm-price-amount-tax"> (includes ' . $taxTerm . ' of ' . CRM_Utils_Money
::format($opt['tax_amount']) . ')</span>';
774 $label = CRM_Utils_Money
::format($opt[$valueFieldName]);
775 $label .= '<span class="crm-price-amount-tax"> + '. CRM_Utils_Money
::format($opt['tax_amount']) . ' ' . $taxTerm . '</span>';