2 +--------------------------------------------------------------------+
3 | Copyright CiviCRM LLC. All rights reserved. |
5 | This work is published under the GNU AGPLv3 license with some |
6 | permitted exceptions and without any warranty. For full license |
7 | and copyright information, see https://civicrm.org/licensing |
8 +--------------------------------------------------------------------+
11 {assign var='hideTotal' value=$quickConfig+$noCalcValueDisplay}
13 <div id="pricesetTotal" class="crm-section section-pricesetTotal">
14 <div id="pricelabel" class="label {if $hideTotal}hiddenElement{/if}">
15 {if ($extends eq 'Contribution') || ($extends eq 'Membership')}
16 <span id='amount_sum_label'>{ts}Total Amount{/ts}</span>
18 <span id='amount_sum_label'>{ts}Total Fee(s){/ts}{if $isAdditionalParticipants} {ts}for this participant{/ts}{/if}</span>
21 <div class="content calc-value" {if $hideTotal}style="display:none;"{/if} id="pricevalue"></div>
24 <script type="text/javascript">
27 var thousandMarker = '{/literal}{$config->monetaryThousandSeparator}{literal}';
28 var separator = '{/literal}{$config->monetaryDecimalPoint}{literal}';
29 var symbol = '{/literal}{$currencySymbol}{literal}';
32 // Recalculate the total fees based on user selection
33 cj("#priceset [price]").each(function () {
34 var elementType = cj(this).attr('type');
35 if (this.tagName == 'SELECT') {
36 elementType = 'select-one';
41 cj(this).click(function(){
42 calculateCheckboxLineItemValue(this);
43 display(calculateTotalFee());
45 calculateCheckboxLineItemValue(this);
49 cj(this).click( function(){
50 calculateRadioLineItemValue(this);
51 display(calculateTotalFee());
53 calculateRadioLineItemValue(this);
57 cj(this).bind( 'keyup', function() {
59 }).bind( 'blur' , function() {
62 //default calculation of element.
67 calculateSelectLineItemValue(this);
69 cj(this).change(function() {
70 calculateSelectLineItemValue(this);
71 display(calculateTotalFee());
76 display(calculateTotalFee());
80 * Calculate the value of the line item for a radio value.
82 function calculateCheckboxLineItemValue(priceElement) {
83 eval( 'var option = ' + cj(priceElement).attr('price') ) ;
84 optionPart = option[1].split(optionSep);
85 price = parseFloat(0);
86 if (cj(priceElement).prop('checked')) {
87 price = parseFloat(optionPart[0]);
89 cj(priceElement).data('line_raw_total', price);
93 * Calculate the value of the line item for a radio value.
95 function calculateRadioLineItemValue(priceElement) {
96 eval( 'var option = ' + cj(priceElement).attr('price') );
97 optionPart = option[1].split(optionSep);
98 var lineTotal = parseFloat(optionPart[0]);
99 cj(priceElement).data('line_raw_total', lineTotal);
100 var radionGroupName = cj(priceElement).attr("name");
101 // Reset all unchecked options to having a data value of 0.
102 cj('input[name=' + radionGroupName + ']:radio:unchecked').each(
104 cj(this).data('line_raw_total', 0);
110 * Calculate the value of the line item for a select value.
112 function calculateSelectLineItemValue(priceElement) {
113 eval( 'var selectedText = ' + cj(priceElement).attr('price') );
114 var price = parseFloat('0');
115 var option = cj(priceElement).val();
117 optionPart = selectedText[option].split(optionSep);
118 price = parseFloat(optionPart[0]);
120 cj(priceElement).data('line_raw_total', price);
124 * Calculate the value of the line item for a text box.
126 function calculateText(priceElement) {
127 //CRM-16034 - comma acts as decimal in price set text pricing
128 //CRM-19937 - dollar sign easy mistake to make by users.
129 var textval = parseFloat(cj(priceElement).val().replace(thousandMarker, '').replace(symbol, ''));
131 if (isNaN(textval)) {
132 textval = parseFloat(0);
134 eval('var option = '+ cj(priceElement).attr('price'));
135 optionPart = option[1].split(optionSep);
136 addprice = parseFloat(optionPart[0]);
137 var curval = textval * addprice;
138 cj(priceElement).data('line_raw_total', curval);
139 display(calculateTotalFee());
143 * Calculate the total fee for the visible priceset.
145 function calculateTotalFee() {
147 cj("#priceset [price]").each(function () {
148 totalFee = totalFee + cj(this).data('line_raw_total');
154 * Display calculated amount.
156 function display(totalfee) {
157 // totalfee is monetary, round it to 2 decimal points so it can
158 // go as a float - CRM-13491
159 totalfee = Math.round(totalfee*100)/100;
160 var totalFormattedFee = symbol + ' ' + CRM.formatMoney(totalfee, true);
161 cj('#pricevalue').html(totalFormattedFee);
163 cj('#total_amount').val( totalfee );
164 cj('#pricevalue').data('raw-total', totalfee).trigger('change');
167 cj('table#pricelabel').addClass('disabled');
170 cj('table#pricelabel').removeClass('disabled');
173 if (typeof skipPaymentMethod == 'function') {
174 // Advice to anyone who, like me, feels hatred towards this if construct ... if you remove the if you
175 // get an error on participant 2 of a event that requires approval & permits multiple registrants.