3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
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 * @internal param array $ids the array that holds all the db ids
55 * @return object CRM_Price_BAO_PriceField object
59 static function &add(&$params) {
60 $priceFieldBAO = new CRM_Price_BAO_PriceField();
62 $priceFieldBAO->copyValues($params);
64 if ($id = CRM_Utils_Array
::value('id', $params)) {
65 $priceFieldBAO->id
= $id;
68 $priceFieldBAO->save();
69 return $priceFieldBAO;
73 * takes an associative array and creates a price field object
75 * This function is invoked from within the web form layer and also from the api layer
77 * @param array $params (reference) an assoc array of name/value pairs
79 * @return object CRM_Price_DAO_PriceField object
83 static function create(&$params) {
84 $transaction = new CRM_Core_Transaction();
86 $priceField = self
::add($params);
88 if (is_a($priceField, 'CRM_Core_Error')) {
89 $transaction->rollback();
93 $options = $optionsIds = array();
94 $maxIndex = CRM_Price_Form_Field
::NUM_OPTION
;
96 if ($priceField->html_type
== 'Text') {
99 $fieldValue = new CRM_Price_DAO_PriceFieldValue();
100 $fieldValue->price_field_id
= $priceField->id
;
102 // update previous field values( if any )
103 if ($fieldValue->find(TRUE)) {
104 $optionsIds['id'] = $fieldValue->id
;
107 $defaultArray = array();
108 if ($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 * Takes a bunch of params that are needed to match certain criteria and
170 * retrieves the relevant objects. Typically the valid params are only
171 * contact_id. We'll tweak this function to be more full featured over a period
172 * of time. This is the inverse function of create. It also stores all the retrieved
173 * values in the default array
175 * @param array $params (reference ) an assoc array of name/value pairs
176 * @param array $defaults (reference ) an assoc array to hold the flattened values
178 * @return object CRM_Price_DAO_PriceField object
182 static function retrieve(&$params, &$defaults) {
183 return CRM_Core_DAO
::commonRetrieve('CRM_Price_DAO_PriceField', $params, $defaults);
187 * update the is_active flag in the db
189 * @param int $id Id of the database record
190 * @param boolean $is_active Value we want to set the is_active field
192 * @return Object DAO object on sucess, null otherwise
197 static function setIsActive($id, $is_active) {
198 return CRM_Core_DAO
::setFieldValue('CRM_Price_DAO_PriceField', $id, 'is_active', $is_active);
202 * Get the field title.
204 * @param int $id id of field.
206 * @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 object $qf form object (reference)
220 * @param string $elementName name of the custom field
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 $feezeOptions
230 * @internal param bool $search true if used for search else false
234 public static function addQuickFormElement(&$qf,
240 $fieldOptions = NULL,
241 $feezeOptions = array()
244 $field = new CRM_Price_DAO_PriceField();
245 $field->id
= $fieldId;
246 if (!$field->find(TRUE)) {
247 /* FIXME: failure! */
252 if (isset($qf->_mode
) && empty($qf->_mode
)) {
255 elseif (isset($qf->_values
)) {
256 $is_pay_later = CRM_Utils_Array
::value( 'is_pay_later', $qf->_values
);
259 $otherAmount = $qf->get('values');
260 $config = CRM_Core_Config
::singleton();
261 $currencySymbol = CRM_Core_DAO
::getFieldValue('CRM_Financial_DAO_Currency',$config->defaultCurrency
,'symbol','name');
262 $qf->assign('currencySymbol', $currencySymbol);
263 // get currency name for price field and option attributes
264 $currencyName = $config->defaultCurrency
;
266 if (!isset($label)) {
267 $label = (!empty($qf->_membershipBlock
) && $field->name
== 'contribution_amount') ?
ts('Additional Contribution') : $field->label
;
270 if ($field->name
== 'contribution_amount') {
271 $qf->_contributionAmount
= 1;
274 if (isset($qf->_online
) && $qf->_online
) {
275 $useRequired = FALSE;
278 $customOption = $fieldOptions;
279 if (!is_array($customOption)) {
280 $customOption = CRM_Price_BAO_PriceField
::getOptions($field->id
, $inactiveNeeded);
284 $valueFieldName = 'amount';
286 $displayOpt = CRM_Contribute_BAO_Contribution
::getContributionSettings();
287 $displayOpt = $displayOpt['tax_display_settings'];
288 switch ($field->html_type
) {
290 $optionKey = key($customOption);
291 $count = CRM_Utils_Array
::value('count', $customOption[$optionKey], '');
292 $max_value = CRM_Utils_Array
::value('max_value', $customOption[$optionKey], '');
294 if (CRM_Utils_Array
::value('tax_amount', $customOption[$optionKey])) {
295 $taxAmount = $customOption[$optionKey]['tax_amount'];
296 $qf->assign('displayOpt', $displayOpt);
298 $priceVal = implode($seperator, array($customOption[$optionKey][$valueFieldName] +
$taxAmount, $count, $max_value));
301 if (!empty($qf->_quickConfig
) && !empty($qf->_contributionAmount
)) {
302 foreach($fieldOptions as &$fieldOption) {
303 if ($fieldOption['name'] == 'other_amount') {
304 $fieldOption['label'] = $fieldOption['label'] . ' ' . $currencySymbol;
307 $qf->assign('priceset', $elementName);
308 $extra = array('onclick' => 'useAmountOther();');
311 if (!empty($qf->_membershipBlock
) && !empty($qf->_quickConfig
) && $field->name
== 'other_amount' && empty($qf->_contributionAmount
)) {
314 elseif (!empty($fieldOptions[$optionKey]['label'])) { //check for label.
315 $label = $fieldOptions[$optionKey]['label'];
318 $element = &$qf->add('text', $elementName, $label,
320 array('price' => json_encode(array($optionKey, $priceVal)),
324 $useRequired && $field->is_required
327 $qf->add( 'text', 'txt-'.$elementName, $label, array( 'size' => '4'));
331 if (in_array($optionKey, $feezeOptions)) {
336 if (!empty($qf->_quickConfig
)) {
337 $message = ts('Please enter a valid amount.');
341 $message = ts('%1 must be an integer (whole number).', array(1 => $label));
342 $type = 'positiveInteger';
344 // integers will have numeric rule applied to them.
345 $qf->addRule($elementName, $message, $type);
351 if (!empty($qf->_quickConfig
) && !empty($qf->_contributionAmount
)) {
352 $qf->assign('contriPriceset', $elementName);
355 foreach ($customOption as $opId => $opt) {
357 if ($field->is_display_amounts
) {
358 $opt['label'] = !empty($opt['label']) ?
$opt['label'] : '';
359 if (CRM_Utils_Array
::value('tax_amount', $opt)) {
360 $taxAmount = $opt['tax_amount'];
361 if ($displayOpt == 'Do_not_show') {
362 $opt['label'] = '<span class="crm-price-amount-amount">' . CRM_Utils_Money
::format($opt[$valueFieldName] +
$taxAmount) . '</span> <span class="crm-price-amount-label">' . $opt['label'] . '</span>';
364 else if ($displayOpt == 'Inclusive') {
365 $opt['label'] = '<span class="crm-price-amount-amount">' . CRM_Utils_Money
::format($opt[$valueFieldName] +
$taxAmount) . '</span> <span class="crm-price-amount-label">' . $opt['label'] . '</span>';
366 $opt['label'] .= '<span class="crm-price-amount-label"> (includes '.round($opt['tax_rate'],2).'% VAT - ' . CRM_Utils_Money
::format($taxAmount) . ')</span>';
369 $opt['label'] = '<span class="crm-price-amount-amount">' . CRM_Utils_Money
::format($opt[$valueFieldName]) . '</span> <span class="crm-price-amount-label">' . $opt['label'] . '</span>';
370 $opt['label'] .= '<span class="crm-price-amount-label"> + '.round($opt['tax_rate'],2).'% VAT - ' . CRM_Utils_Money
::format($taxAmount) . '</span>';
374 $opt['label'] = '<span class="crm-price-amount-amount">' . CRM_Utils_Money
::format($opt[$valueFieldName]) . '</span> <span class="crm-price-amount-label">' . $opt['label'] . '</span>';
377 $count = CRM_Utils_Array
::value('count', $opt, '');
378 $max_value = CRM_Utils_Array
::value('max_value', $opt, '');
379 $priceVal = implode($seperator, array($opt[$valueFieldName] +
$taxAmount, $count, $max_value));
380 $extra = array('price' => json_encode(array($elementName, $priceVal)),
381 'data-amount' => $opt[$valueFieldName],
382 'data-currency' => $currencyName,
384 if (!empty($qf->_quickConfig
) && $field->name
== 'contribution_amount') {
385 $extra +
= array('onclick' => 'clearAmountOther();');
387 elseif (!empty($qf->_quickConfig
) && $field->name
== 'membership_amount') {
389 'onclick' => "return showHideAutoRenew({$opt['membership_type_id']});",
390 'membership-type' => $opt['membership_type_id'],
392 $qf->assign('membershipFieldID',$field->id
);
395 $choice[$opId] = $qf->createElement('radio', NULL, '', $opt['label'], $opt['id'], $extra);
398 $qf->add( 'text', 'txt-'.$elementName, $label, array( 'size' => '4'));
402 if (in_array($opId, $feezeOptions)) {
403 $choice[$opId]->freeze();
406 if (!empty($qf->_membershipBlock
) && $field->name
== 'contribution_amount') {
407 $choice[] = $qf->createElement('radio', NULL, '', ts('No thank you'), '-1',
409 'onclick' => 'clearAmountOther();',
414 if (!$field->is_required
) {
416 if (!empty($otherAmount['is_allow_other_amount']) && $field->name
== 'contribution_amount') {
417 $none = ts('Other Amount');
419 elseif (!empty($qf->_membershipBlock
) && empty($qf->_membershipBlock
['is_required']) && $field->name
== 'membership_amount') {
420 $none = ts('No thank you');
423 $none = ts('- none -');
426 $choice[] = $qf->createElement('radio', NULL, '', $none, '0',
427 array('price' => json_encode(array($elementName, '0')))
431 $element = &$qf->addGroup($choice, $elementName, $label);
433 // make contribution field required for quick config when membership block is enabled
434 if (($field->name
== 'membership_amount' ||
$field->name
== 'contribution_amount')
435 && !empty($qf->_membershipBlock
) && !$field->is_required
) {
436 $useRequired = $field->is_required
= TRUE;
439 if ($useRequired && $field->is_required
) {
440 $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required');
445 $selectOption = $allowedOptions = $priceVal = array();
447 foreach ($customOption as $opt) {
449 $count = CRM_Utils_Array
::value('count', $opt, '');
450 $max_value = CRM_Utils_Array
::value('max_value', $opt, '');
452 if ($field->is_display_amounts
) {
453 $opt['label'] .= ' - ';
454 if (CRM_Utils_Array
::value('tax_amount', $opt)) {
455 $taxAmount = $opt['tax_amount'];
456 if ($displayOpt == 'Do_not_show') {
457 $opt['label'] .= CRM_Utils_Money
::format($opt[$valueFieldName] +
$taxAmount);
459 else if ($displayOpt == 'Inclusive') {
460 $opt['label'] .= CRM_Utils_Money
::format($opt[$valueFieldName] +
$taxAmount);
461 $opt['label'] .= '<span class="crm-price-amount-label"> (includes '.round($opt['tax_rate'],2).'% VAT - ' . CRM_Utils_Money
::format($taxAmount) . ')</span>';
464 $opt['label'] .= CRM_Utils_Money
::format($opt[$valueFieldName]);
465 $opt['label'] .= '<span class="crm-price-amount-label"> + '.round($opt['tax_rate'],2).'% VAT - ' . CRM_Utils_Money
::format($taxAmount) . '</span>';
469 $opt['label'] .= CRM_Utils_Money
::format($opt[$valueFieldName]);
472 $selectOption[$opt['id']] = $opt['label'];
473 $priceVal[$opt['id']] = implode($seperator, array($opt[$valueFieldName] +
$taxAmount, $count, $max_value));
475 if (!in_array($opt['id'], $feezeOptions)) {
476 $allowedOptions[] = $opt['id'];
479 $qf->add( 'text', 'txt-'.$elementName, $label, array( 'size' => '4'));
482 $element = &$qf->add('select', $elementName, $label,
484 '' => ts('- select -')) +
$selectOption,
485 $useRequired && $field->is_required
,
486 array('price' => json_encode($priceVal))
490 $button = substr($qf->controller
->getButtonName(), -4);
491 if (!empty($feezeOptions) && $button != 'skip') {
492 $qf->addRule($elementName, ts('Sorry, this option is currently sold out.'), 'regex', "/" . implode('|', $allowedOptions) . "/");
499 foreach ($customOption as $opId => $opt) {
501 $count = CRM_Utils_Array
::value('count', $opt, '');
502 $max_value = CRM_Utils_Array
::value('max_value', $opt, '');
504 if ($field->is_display_amounts
) {
505 $opt['label'] .= ' - ';
506 if (CRM_Utils_Array
::value('tax_amount', $opt)) {
507 $taxAmount = $opt['tax_amount'];
508 if ($displayOpt == 'Do_not_show') {
509 $opt['label'] .= CRM_Utils_Money
::format($opt[$valueFieldName] +
$taxAmount);
511 else if ($displayOpt == 'Inclusive') {
512 $opt['label'] .= CRM_Utils_Money
::format($opt[$valueFieldName] +
$taxAmount);
513 $opt['label'] .= '<span class="crm-price-amount-label"> (includes '.round($opt['tax_rate'],2).'% VAT - ' . CRM_Utils_Money
::format($taxAmount) . ')</span>';
516 $opt['label'] .= CRM_Utils_Money
::format($opt[$valueFieldName]);
517 $opt['label'] .= '<span class="crm-price-amount-label"> + '.round($opt['tax_rate'],2).'% VAT - ' . CRM_Utils_Money
::format($taxAmount) . '</span>';
521 $opt['label'] .= CRM_Utils_Money
::format($opt[$valueFieldName]);
524 $priceVal = implode($seperator, array($opt[$valueFieldName] +
$taxAmount, $count, $max_value));
525 $check[$opId] = &$qf->createElement('checkbox', $opt['id'], NULL, $opt['label'],
526 array('price' => json_encode(array($opt['id'], $priceVal)),
527 'data-amount' => $opt[$valueFieldName],
528 'data-currency' => $currencyName,
532 $txtcheck[$opId] =& $qf->createElement( 'text', $opId, $opt['label'], array( 'size' => '4' ) );
533 $qf->addGroup($txtcheck, 'txt-'.$elementName, $label);
536 if (in_array($opId, $feezeOptions)) {
537 $check[$opId]->freeze();
540 $element = &$qf->addGroup($check, $elementName, $label);
541 if ($useRequired && $field->is_required
) {
542 $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required');
546 if (isset($qf->_online
) && $qf->_online
) {
552 * Retrieve a list of options for the specified field
554 * @param int $fieldId price field ID
555 * @param bool $inactiveNeeded include inactive options
556 * @param bool $reset ignore stored values\
558 * @return array array of options
560 public static function getOptions($fieldId, $inactiveNeeded = FALSE, $reset = FALSE) {
561 static $options = array();
563 if ($reset ||
empty($options[$fieldId])) {
565 CRM_Price_BAO_PriceFieldValue
::getValues($fieldId, $values, 'weight', !$inactiveNeeded);
566 $options[$fieldId] = $values;
567 $taxRates = CRM_Core_PseudoConstant
::getTaxRates();
569 // ToDo - Code for Hook Invoke
571 foreach ($options[$fieldId] as $priceFieldId => $priceFieldValues) {
572 if (array_key_exists($priceFieldValues['financial_type_id'], $taxRates)) {
573 $options[$fieldId][$priceFieldId]['tax_rate'] = $taxRates[$priceFieldValues['financial_type_id']];
574 $taxAmount = self
::calculateTaxAmount($priceFieldValues['amount'], $options[$fieldId][$priceFieldId]['tax_rate']);
575 $options[$fieldId][$priceFieldId]['tax_amount'] = round($taxAmount['tax_amount'],2);
580 return $options[$fieldId];
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
619 public static function deleteField($id) {
620 $field = new CRM_Price_DAO_PriceField();
623 if ($field->find(TRUE)) {
624 // delete the options for this field
625 CRM_Price_BAO_PriceFieldValue
::deleteValues($id);
627 // reorder the weight before delete
628 $fieldValues = array('price_set_id' => $field->price_set_id
);
630 CRM_Utils_Weight
::delWeight('CRM_Price_DAO_PriceField', $field->id
, $fieldValues);
632 // now delete the field
633 return $field->delete();
639 static function &htmlTypes() {
640 static $htmlTypes = NULL;
643 'Text' => ts('Text / Numeric Quantity'),
644 'Select' => ts('Select'),
645 'Radio' => ts('Radio'),
646 'CheckBox' => ts('CheckBox'),
653 * Validate the priceset
655 * @param int $priceSetId , array $fields
657 * retrun the error string
661 * @param bool $allowNoneSelection
667 public static function priceSetValidation($priceSetId, $fields, &$error, $allowNoneSelection = FALSE) {
668 // check for at least one positive
669 // amount price field should be selected.
670 $priceField = new CRM_Price_DAO_PriceField();
671 $priceField->price_set_id
= $priceSetId;
674 $priceFields = array();
676 if ($allowNoneSelection) {
677 $noneSelectedPriceFields = array();
680 while ($priceField->fetch()) {
681 $key = "price_{$priceField->id}";
683 if ($allowNoneSelection) {
684 if (array_key_exists($key, $fields)) {
685 if ($fields[$key] == 0 && !$priceField->is_required
) {
686 $noneSelectedPriceFields[] = $priceField->id
;
691 if (!empty($fields[$key])) {
692 $priceFields[$priceField->id
] = $fields[$key];
696 if (!empty($priceFields)) {
697 // we should has to have positive amount.
700 FROM civicrm_price_field
701 WHERE id IN (" . implode(',', array_keys($priceFields)) . ')';
702 $fieldDAO = CRM_Core_DAO
::executeQuery($sql);
703 $htmlTypes = array();
704 while ($fieldDAO->fetch()) {
705 $htmlTypes[$fieldDAO->id
] = $fieldDAO->html_type
;
708 $selectedAmounts = array();
710 foreach ($htmlTypes as $fieldId => $type) {
712 CRM_Price_BAO_PriceFieldValue
::getValues($fieldId, $options);
714 if (empty($options)) {
718 if ($type == 'Text') {
719 foreach ($options as $opId => $option) {
720 $selectedAmounts[$opId] = $priceFields[$fieldId] * $option['amount'];
724 elseif (is_array($fields["price_{$fieldId}"])) {
725 foreach (array_keys($fields["price_{$fieldId}"]) as $opId) {
726 $selectedAmounts[$opId] = $options[$opId]['amount'];
729 elseif (in_array($fields["price_{$fieldId}"], array_keys($options))) {
730 $selectedAmounts[$fields["price_{$fieldId}"]] = $options[$fields["price_{$fieldId}"]]['amount'];
734 list($componentName) = explode(':', $fields['_qf_default']);
735 // now we have all selected amount in hand.
736 $totalAmount = array_sum($selectedAmounts);
737 if ($totalAmount < 0) {
738 $error['_qf_default'] = ts('%1 amount can not be less than zero. Please select the options accordingly.', array(1 => $componentName));
742 if ($allowNoneSelection) {
743 if (empty($noneSelectedPriceFields)) {
744 $error['_qf_default'] = ts('Please select at least one option from price set.');
747 $error['_qf_default'] = ts('Please select at least one option from price set.');
753 * Calculate the tax amount based on given tax rate.
755 * @param float $amount amount of field.
756 * @param float $taxRate tax rate of selected financial account for field.
758 * @return array array of tax amount
764 public static function calculateTaxAmount($amount, $taxRate) {
765 $taxAmount = array();
766 $taxAmount['tax_amount'] = ($taxRate/100) * $amount;