2 +--------------------------------------------------------------------+
3 | CiviCRM version 4.6 |
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC (c) 2004-2014 |
6 +--------------------------------------------------------------------+
7 | This file is a part of CiviCRM. |
9 | CiviCRM is free software; you can copy, modify, and distribute it |
10 | under the terms of the GNU Affero General Public License |
11 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | CiviCRM is distributed in the hope that it will be useful, but |
14 | WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
16 | See the GNU Affero General Public License for more details. |
18 | You should have received a copy of the GNU Affero General Public |
19 | License and the CiviCRM Licensing Exception along |
20 | with this program; if not, contact CiviCRM LLC |
21 | at info[AT]civicrm[DOT]org. If you have questions about the |
22 | GNU Affero General Public License or the licensing of CiviCRM, |
23 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
24 +--------------------------------------------------------------------+
26 {if $noCalcValueDisplay neq 'false'}
27 <div id="pricesetTotal" class="crm-section section-pricesetTotal">
28 <div class="label" id="pricelabel"><label>
29 {if ( $extends eq 'Contribution' ) || ( $extends eq 'Membership' )}
30 {ts}Total Amount{/ts}{else}{ts}Total Fee(s){/ts}
31 {if $isAdditionalParticipants} {ts}for this participant{/ts}{/if}
33 <div class="content calc-value" id="pricevalue" ></div>
36 <script type="text/javascript">
40 var thousandMarker = '{/literal}{$config->monetaryThousandSeparator}{literal}';
41 var seperator = '{/literal}{$config->monetaryDecimalPoint}{literal}';
42 var symbol = '{/literal}{$currencySymbol}{literal}';
44 var priceSet = price = Array( );
45 cj("input,#priceset select,#priceset").each(function () {
47 if ( cj(this).attr('price') ) {
48 var eleType = cj(this).attr('type');
49 if ( this.tagName == 'SELECT' ) {
50 eleType = 'select-one';
56 //default calcution of element.
57 eval( 'var option = ' + cj(this).attr('price') ) ;
59 optionPart = option[1].split(optionSep);
60 addprice = parseFloat( optionPart[0] );
62 if( cj(this).prop('checked') ) {
64 price[ele] += addprice;
67 //event driven calculation of element.
68 cj(this).click( function(){
70 if ( cj(this).prop('checked') ) {
72 price[ele] += addprice;
75 price[ele] -= addprice;
84 //default calcution of element.
85 eval( 'var option = ' + cj(this).attr('price') );
87 optionPart = option[1].split(optionSep);
88 addprice = parseFloat( optionPart[0] );
93 if( cj(this).prop('checked') ) {
94 totalfee = parseFloat(totalfee) + addprice - parseFloat(price[ele]);
95 price[ele] = addprice;
98 //event driven calculation of element.
99 cj(this).click( function(){
100 totalfee = parseFloat(totalfee) + addprice - parseFloat(price[ele]);
101 price[ele] = addprice;
110 //default calcution of element.
111 calculateText( this );
113 //event driven calculation of element.
114 cj(this).bind( 'keyup', function() { calculateText( this );
115 }).bind( 'blur' , function() { calculateText( this );
122 //default calcution of element.
123 var ele = cj(this).attr('id');
124 if ( ! price[ele] ) {
127 eval( 'var selectedText = ' + cj(this).attr('price') );
129 if ( cj(this).val( ) ) {
130 optionPart = selectedText[cj(this).val( )].split(optionSep);
131 addprice = parseFloat( optionPart[0] );
135 totalfee = parseFloat(totalfee) + addprice - parseFloat(price[ele]);
136 price[ele] = addprice;
139 //event driven calculation of element.
140 cj(this).change( function() {
141 var ele = cj(this).attr('id');
142 if ( ! price[ele] ) {
145 eval( 'var selectedText = ' + cj(this).attr('price') );
148 if ( cj(this).val( ) ) {
149 optionPart = selectedText[cj(this).val( )].split(optionSep);
150 addprice = parseFloat( optionPart[0] );
154 totalfee = parseFloat(totalfee) + addprice - parseFloat(price[ele]);
155 price[ele] = addprice;
157 totalfee = parseFloat(totalfee) - parseFloat(price[ele]);
158 price[ele] = parseFloat('0');
168 //calculation for text box.
169 function calculateText( object ) {
170 var textval = parseFloat( cj(object).val() );
172 eval( 'var option = '+ cj(object).attr('price') );
174 if ( ! price[ele] ) {
177 optionPart = option[1].split(optionSep);
178 addprice = parseFloat( optionPart[0] );
179 var curval = textval * addprice;
180 if ( textval >= 0 ) {
181 totalfee = parseFloat(totalfee) + curval - parseFloat(price[ele]);
185 totalfee = parseFloat(totalfee) - parseFloat(price[ele]);
186 price[ele] = parseFloat('0');
191 {if $displayOveride neq 'true'}
193 //display calculated amount
194 function display( totalfee ) {
195 // totalfee is monetary, round it to 2 decimal points so it can
196 // go as a float - CRM-13491
197 totalfee = Math.round(totalfee*100)/100;
198 var totalEventFee = formatMoney( totalfee, 2, seperator, thousandMarker);
199 document.getElementById('pricevalue').innerHTML = "<b>"+symbol+"</b> "+totalEventFee;
200 scriptfee = totalfee;
202 cj('#total_amount').val( totalfee );
203 cj('#pricevalue').data('raw-total', totalfee).trigger('change');
205 ( totalfee < 0 ) ? cj('table#pricelabel').addClass('disabled') : cj('table#pricelabel').removeClass('disabled');
206 if (typeof skipPaymentMethod == 'function') {
213 //money formatting/localization
214 function formatMoney (amount, c, d, t) {
216 c = isNaN(c = Math.abs(c)) ? 2 : c,
217 d = d == undefined ? "," : d,
218 t = t == undefined ? "." : t, s = n < 0 ? "-" : "",
219 i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "",
220 j = (j = i.length) > 3 ? j % 3 : 0;
221 return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");