Merge pull request #10687 from JMAConsulting/CRM-20898
[civicrm-core.git] / templates / CRM / Contribute / Form / Contribution.tpl
1 {*
2 +--------------------------------------------------------------------+
3 | CiviCRM version 4.7 |
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC (c) 2004-2017 |
6 +--------------------------------------------------------------------+
7 | This file is a part of CiviCRM. |
8 | |
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. |
12 | |
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. |
17 | |
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 +--------------------------------------------------------------------+
25 *}
26 {* this template is used for adding/editing/deleting contributions and pledge payments *}
27
28 {if $priceSetId}
29 {include file="CRM/Price/Form/PriceSet.tpl" context="standalone" extends="Contribution"}
30 {elseif $showAdditionalInfo and $formType }
31 {include file="CRM/Contribute/Form/AdditionalInfo/$formType.tpl"}
32 {else}
33 {include file="CRM/Contribute/Form/AdditionalInfo/Payment.tpl"}
34 <div class="crm-block crm-form-block crm-contribution-form-block">
35
36 {if !$email and $action neq 8 and $context neq 'standalone'}
37 <div class="messages status no-popup">
38 <div class="icon inform-icon"></div>&nbsp;{ts}You will not be able to send an automatic email receipt for this contribution because there is no email address recorded for this contact. If you want a receipt to be sent when this contribution is recorded, click Cancel and then click Edit from the Summary tab to add an email address before recording the contribution.{/ts}
39 </div>
40 {/if}
41 {if $contributionMode}
42 <div class="help">
43 {if $contactId && $payNow}
44 {ts 1=$displayName 2=$contributionMode|upper}Use this form to edit a contribution on behalf of %1. <strong>A
45 %2 transaction will be submitted</strong> using the selected payment processor.{/ts}
46 {elseif $contactId}
47 {ts 1=$displayName 2=$contributionMode|upper}Use this form to submit a new contribution on behalf of %1. <strong>A
48 %2 transaction will be submitted</strong> using the selected payment processor.{/ts}
49 {else}
50 {ts 1=$displayName 2=$contributionMode|upper}Use this form to submit a new contribution. <strong>A %2 transaction will be submitted</strong> using the selected payment processor.{/ts}
51 {/if}
52 </div>
53 {/if}
54 {if $action eq 8}
55 <div class="messages status no-popup">
56 <div class="icon inform-icon"></div>
57 {ts}WARNING: Deleting this contribution will result in the loss of the associated financial transactions (if any).{/ts} {ts}Do you want to continue?{/ts}
58 </div>
59 {else}
60 {if $newCredit AND $action EQ 1 AND $contributionMode EQ null}
61 <div class="action-link css_right crm-link-credit-card-mode">
62 {if $contactId}
63 {capture assign=ccModeLink}{crmURL p='civicrm/contact/view/contribution' q="reset=1&action=add&cid=`$contactId`&context=`$context`&mode=live"}{/capture}
64 {else}
65 {capture assign=ccModeLink}{crmURL p='civicrm/contact/view/contribution' q="reset=1&action=add&context=standalone&mode=live"}{/capture}
66 {/if}
67 <a class="open-inline-noreturn action-item crm-hover-button" href="{$ccModeLink}">&raquo; {ts}submit credit card contribution{/ts}</a>
68 </div>
69 {/if}
70 <div class="crm-submit-buttons">
71 {include file="CRM/common/formButtons.tpl"}
72 </div>
73 {if $isOnline}{assign var=valueStyle value=" class='view-value'"}{else}{assign var=valueStyle value=""}{/if}
74 <table class="form-layout-compressed">
75 {if $context neq 'standalone'}
76 <tr>
77 <td class="font-size12pt label"><strong><strong>{ts}Contributor{/ts}</strong></td><td class="font-size12pt"><strong>{$displayName}</strong></td>
78 </tr>
79 {else}
80 <td class="label">{$form.contact_id.label}</td>
81 <td>{$form.contact_id.html}</td>
82 {/if}
83 <tr class="crm-contribution-form-block-contribution_type_id crm-contribution-form-block-financial_type_id">
84 <td class="label">{$form.financial_type_id.label}</td><td{$valueStyle}>{$form.financial_type_id.html}&nbsp;
85 {if $is_test}
86 {ts}(test){/ts}
87 {/if} {help id="id-financial_type"}
88 </td>
89 </tr>
90 {if $action eq 2 and $lineItem and !$defaultContribution}
91 <tr>
92 <td class="label">{ts}Contribution Amount{/ts}</td>
93 <td>{include file="CRM/Price/Page/LineItem.tpl" context="Contribution"}</td>
94 </tr>
95 {else}
96 <tr class="crm-contribution-form-block-total_amount">
97 <td class="label">{$form.total_amount.label}</td>
98 <td {$valueStyle}>
99 <span id='totalAmount'>{$form.currency.html|crmAddClass:eight}&nbsp;{$form.total_amount.html|crmAddClass:eight}</span>
100 {if !$payNow}
101 {if $hasPriceSets}
102 <span id='totalAmountORPriceSet'> {ts}OR{/ts}</span>
103 <span id='selectPriceSet'>{$form.price_set_id.html}</span>
104 <div id="priceset" class="hiddenElement"></div>
105 {/if}
106
107 {if $ppID}{ts}<a class='action-item crm-hover-button' onclick='adjustPayment();'>adjust payment amount</a>{/ts}{help id="adjust-payment-amount"}{/if}
108 <div id="totalAmountBlock">
109 {if $hasPriceSets}<span class="description">{ts}Alternatively, you can use a price set.{/ts}</span>{/if}
110 <div id="totalTaxAmount" class="label"></div>
111 </div>
112 {/if}
113 </td>
114 </tr>
115
116 {if $buildRecurBlock && !$payNow}
117 <tr id='recurringPaymentBlock' class='hiddenElement'>
118 <td></td>
119 <td>
120 <strong>{$form.is_recur.html} {ts}every{/ts}
121 &nbsp;{$form.frequency_interval.html}
122 &nbsp;{$form.frequency_unit.html}&nbsp;
123 {ts}for{/ts}
124 &nbsp;{$form.installments.html}
125 &nbsp;{$form.installments.label}
126 </strong>
127 <br />
128 <span class="description">
129 {ts}Your recurring contribution will be processed automatically for the number of installments you specify. You can leave the number of installments blank if you want to make an open-ended commitment. In either case, you can choose to cancel at any time. You will receive an email receipt for each recurring contribution. The receipts will include a link you can use if you decide to modify or cancel your future contributions.{/ts}
130 </span>
131 </td>
132 </tr>
133 {/if}
134
135 <tr id="adjust-option-type" class="crm-contribution-form-block-option_type">
136 <td class="label"></td><td {$valueStyle}>{$form.option_type.html}</td>
137 </tr>
138 {/if}
139 {if $contributionMode && $processorSupportsFutureStartDate}
140 <tr id='start_date' class="crm-contribution-form-block-receive_date">
141 <td class="label">{ts}Start Date{/ts}</td>
142 <td {$valueStyle}>{if $hideCalender neq true}{include file="CRM/common/jcalendar.tpl" elementName=receive_date}{else}{$receive_date|crmDate}{/if}<br />
143 <span class="description">{ts}You can set a start date for recurring contributions and the first payment will be on that date. For a single post-dated contribution you must select recurring and choose one installment{/ts}</span>
144 </td>
145 </tr>
146 {/if}
147
148 <tr class="crm-contribution-form-block-source">
149 <td class="label">{$form.source.label}</td>
150 <td {$valueStyle}>{$form.source.html|crmAddClass:huge} {help id="id-contrib_source"}
151 </td>
152 </tr>
153
154 {* CRM-7362 --add campaign to contributions *}
155 {include file="CRM/Campaign/Form/addCampaignToComponent.tpl" campaignTrClass="crm-contribution-form-block-campaign_id"}
156
157 {if !$contributionMode || $payNow}
158 <tr class="crm-contribution-form-block-contribution_status_id">
159 <td class="label">{$form.contribution_status_id.label}</td>
160 <td>{$form.contribution_status_id.html}
161 {if $contribution_status_id eq 2}{if $is_pay_later }: {ts}Pay Later{/ts} {else}: {ts}Incomplete Transaction{/ts}{/if}{/if}
162 </td>
163 <td>
164 {if $contactId && $contribID && $contributionMode EQ null && $contribution_status_id eq 2}
165 {capture assign=payNowLink}{crmURL p='civicrm/contact/view/contribution' q="reset=1&action=update&id=`$contribID`&cid=`$contactId`&context=`$context`&mode=live"}{/capture}
166 <a class="open-inline action-item crm-hover-button" href="{$payNowLink}">&raquo; {ts}Pay with Credit Card{/ts}</a>
167 {/if}
168 </td>
169 </tr>
170 {/if}
171
172 {if !$contributionMode}
173 {* Cancellation / Refunded fields are hidden unless contribution status is set to Cancelled or Refunded*}
174 <tr id="cancelInfo" class="crm-contribution-form-block-cancelInfo">
175 <td>&nbsp;</td>
176 <td><fieldset><legend>{ts}Cancellation or Refund Information{/ts}</legend>
177 <table class="form-layout-compressed">
178 <tr id="cancelDate" class="crm-contribution-form-block-cancel_date">
179 <td class="label">{$form.cancel_date.label}</td>
180 <td>
181 {if $hideCalendar neq true}
182 {include file="CRM/common/jcalendar.tpl" elementName=cancel_date}
183 {else}
184 {$form.cancel_date.value|crmDate}
185 {/if}
186 </td>
187 </tr>
188 <tr id="cancelDescription" class="crm-contribution-form-block-cancel_reason">
189 <td class="label">&nbsp;</td>
190 <td class="description">{ts}Enter the cancellation or refunded date, or you can skip this field and the cancellation date or refunded date will be automatically set to TODAY.{/ts}</td>
191 </tr>
192 <tr id="cancelReason">
193 <td class="label" style="vertical-align: top;">{$form.cancel_reason.label}</td>
194 <td>{$form.cancel_reason.html}</td>
195 </tr>
196 <tr id="refundTrxnID">
197 <td class="label" style="vertical-align: top;">{$form.refund_trxn_id.label}</td>
198 <td>{$form.refund_trxn_id.html}</td>
199 </tr>
200 </table>
201 </fieldset>
202 </td>
203 </tr>
204 <tr class="crm-contribution-form-block-receive_date">
205 <td class="label">{$form.receive_date.label}</td>
206 <td {$valueStyle}>{include file="CRM/common/jcalendar.tpl" elementName=receive_date}<br />
207 <span class="description">{ts}The date this contribution was received.{/ts}</span>
208 </td>
209 </tr>
210 {/if}
211 {if $form.revenue_recognition_date && !$payNow}
212 <tr class="crm-contribution-form-block-revenue_recognition_date">
213 <td class="label">{$form.revenue_recognition_date.label}</td>
214 <td>{$form.revenue_recognition_date.html}</td>
215 </tr>
216 {/if}
217
218 {if $email and $outBound_option != 2}
219 <tr class="crm-contribution-form-block-is_email_receipt">
220 <td class="label">{$form.is_email_receipt.label}</td>
221 <td>{$form.is_email_receipt.html}&nbsp;
222 <span class="description">{ts 1=$email}Automatically email a receipt for this payment to %1?{/ts}</span>
223 </td>
224 </tr>
225 {elseif $context eq 'standalone' and $outBound_option != 2 }
226 <tr id="email-receipt" style="display:none;" class="crm-contribution-form-block-is_email_receipt">
227 <td class="label">{$form.is_email_receipt.label}</td>
228 <td>{$form.is_email_receipt.html} <span class="description">{ts}Automatically email a receipt for this payment to {/ts}<span id="email-address"></span>?</span>
229 </td>
230 </tr>
231 {/if}
232 <tr id="fromEmail" class="crm-contribution-form-block-receipt_date" style="display:none;">
233 <td class="label">{$form.from_email_address.label}</td>
234 <td>{$form.from_email_address.html}</td>
235 </tr>
236 <tr id="receiptDate" class="crm-contribution-form-block-receipt_date">
237 <td class="label">{$form.receipt_date.label}</td>
238 <td>{include file="CRM/common/jcalendar.tpl" elementName=receipt_date}<br />
239 <span class="description">{ts}Date that a receipt was sent to the contributor.{/ts}</span>
240 </td>
241 </tr>
242 {if $form.payment_processor_id}
243 <tr class="crm-contribution-form-block-payment_processor_id"><td class="label nowrap">{$form.payment_processor_id.label}<span class="crm-marker"> * </span></td><td>{$form.payment_processor_id.html}</td></tr>
244 {/if}
245 </table>
246
247 {if !$contributionMode}
248 <fieldset class="payment-details_group">
249 <legend>
250 {ts}Payment Details{/ts}
251 </legend>
252 <table class="form-layout-compressed" >
253 <tr class="crm-contribution-form-block-payment_instrument_id">
254 <td class="label">{$form.payment_instrument_id.label}</td>
255 <td {$valueStyle}>{$form.payment_instrument_id.html} {help id="payment_instrument_id"}</td>
256 </td>
257 </tr>
258 <tr class="crm-contribution-form-block-trxn_id">
259 <td class="label">{$form.trxn_id.label}</td>
260 <td {$valueStyle}>{$form.trxn_id.html} {help id="id-trans_id"}</td>
261 </tr>
262 </table>
263 </fieldset>
264 {/if}
265
266 {include file='CRM/Core/BillingBlockWrapper.tpl'}
267
268 <!-- start of soft credit -->
269 {if !$payNow}
270 <div class="crm-accordion-wrapper crm-accordion_title-accordion crm-accordion-processed {if $noSoftCredit}collapsed{/if}" id="softCredit">
271 <div class="crm-accordion-header">
272 {ts}Soft Credit{/ts}&nbsp;{help id="id-soft_credit"}
273 </div>
274 <div class="crm-accordion-body">
275 <table class="form-layout-compressed">
276 <tr class="crm-contribution-form-block-soft_credit_to">
277 <td colspan="2">
278 {include file="CRM/Contribute/Form/SoftCredit.tpl"}
279 </td>
280 </tr>
281 </table>
282 </div>
283 </div>
284 {/if}
285 <!-- end of soft credit -->
286
287 <!-- start of PCP -->
288 {if $siteHasPCPs && !$payNow}
289 <div class="crm-accordion-wrapper crm-accordion_title-accordion crm-accordion-processed {if $noPCP}collapsed{/if}" id="softCredit">
290 <div class="crm-accordion-header">
291 {ts}Personal Campaign Page{/ts}&nbsp;{help id="id-pcp"}
292 </div>
293 <div class="crm-accordion-body">
294 <table class="form-layout-compressed">
295 <tr class="crm-contribution-pcp-block crm-contribution-form-block-pcp_made_through_id">
296 <td class="label">{$form.pcp_made_through_id.label}</td>
297 <td>
298 {$form.pcp_made_through_id.html} &nbsp;
299 <div class="description">{ts}Search for the Personal Campaign Page by the fund-raiser's last name or email address.{/ts}</div>
300
301 <div class="spacer"></div>
302 <div class="crm-contribution-form-block-pcp_details">
303 <table class="crm-contribution-form-table-credit_to_pcp">
304 <tr id="pcpDisplayRollID" class="crm-contribution-form-block-pcp_display_in_roll">
305 <td class="label">{$form.pcp_display_in_roll.label}</td>
306 <td>{$form.pcp_display_in_roll.html}</td>
307 </tr>
308 <tr id="nickID" class="crm-contribution-form-block-pcp_roll_nickname">
309 <td class="label">{$form.pcp_roll_nickname.label}</td>
310 <td>{$form.pcp_roll_nickname.html|crmAddClass:big}<br/>
311 <div class="description">{ts}Name or nickname contributor wants to be displayed in the Honor Roll. Enter "Anonymous" for anonymous contributions.{/ts}</div>
312 </td>
313 </tr>
314 <tr id="personalNoteID" class="crm-contribution-form-block-pcp_personal_note">
315 <td class="label" style="vertical-align: top">{$form.pcp_personal_note.label}</td>
316 <td>
317 {$form.pcp_personal_note.html}
318 <div
319 class="description">{ts}Personal message submitted by contributor for display in the Honor Roll.{/ts}</div>
320 </td>
321 </tr>
322 </table>
323 </div>
324 </td>
325 </tr>
326 </table>
327 </div>
328 </div>
329 {include file="CRM/Contribute/Form/PCP.js.tpl"}
330 {/if}
331 <!-- end of PCP -->
332
333 {if !$payNow}
334 <div id="customData" class="crm-contribution-form-block-customData"></div>
335 {/if}
336
337 {*include custom data js file*}
338 {include file="CRM/common/customData.tpl"}
339
340 {literal}
341 <script type="text/javascript">
342 CRM.$(function($) {
343 {/literal}
344 CRM.buildCustomData( '{$customDataType}' );
345 {if $customDataSubType}
346 CRM.buildCustomData( '{$customDataType}', {$customDataSubType} );
347 {/if}
348
349 {if $buildPriceSet}{literal}buildAmount( );{/literal}{/if}
350 {literal}
351 });
352
353 // bind first click of accordion header to load crm-accordion-body with snippet
354 // everything else taken care of by cj().crm-accordions()
355 CRM.$(function($) {
356 cj('#adjust-option-type').hide();
357 cj('.crm-ajax-accordion .crm-accordion-header').one('click', function() {
358 loadPanes(cj(this).attr('id'));
359 });
360 cj('.crm-ajax-accordion:not(.collapsed) .crm-accordion-header').each(function(index) {
361 loadPanes(cj(this).attr('id'));
362 });
363 });
364 // load panes function calls for snippet based on id of crm-accordion-header
365 function loadPanes( id ) {
366 var url = "{/literal}{crmURL p='civicrm/contact/view/contribution' q='snippet=4&formType=' h=0}{literal}" + id;
367 {/literal}
368 {if $contributionMode}
369 url = url + "&mode={$contributionMode}";
370 {/if}
371 {if $qfKey}
372 url = url + "&qfKey={$qfKey}";
373 {/if}
374 {literal}
375 if (! cj('div.'+id).html()) {
376 var loading = '<img src="{/literal}{$config->resourceBase}i/loading.gif{literal}" alt="{/literal}{ts escape='js'}loading{/ts}{literal}" />&nbsp;{/literal}{ts escape='js'}Loading{/ts}{literal}...';
377 cj('div.'+id).html(loading);
378 cj.ajax({
379 url : url,
380 success: function(data) { cj('div.'+id).html(data).trigger('crmLoad'); }
381 });
382 }
383 }
384
385 var url = "{/literal}{$dataUrl}{literal}";
386
387 {/literal}
388 {if $context eq 'standalone' and $outBound_option != 2 }
389 {literal}
390 CRM.$(function($) {
391
392 var $form = $("form.{/literal}{$form.formClass}{literal}");
393 $("#contact_id", $form).change(checkEmail);
394 checkEmail( );
395
396 function checkEmail( ) {
397 var data = $("#contact_id", $form).select2('data');
398 if (data && data.extra && data.extra.email && data.extra.email.length) {
399 $("#email-receipt", $form).show();
400 $("#email-address", $form).html(data.extra.email);
401 }
402 else {
403 $("#email-receipt", $form).hide();
404 }
405 }
406
407 showHideByValue( 'is_email_receipt', '', 'receiptDate', 'table-row', 'radio', true);
408 showHideByValue( 'is_email_receipt', '', 'fromEmail', 'table-row', 'radio', false );
409 });
410
411 {/literal}
412 {/if}
413 </script>
414
415 <div class="accordion ui-accordion ui-widget ui-helper-reset">
416 {* Additional Detail / Honoree Information / Premium Information *}
417 {foreach from=$allPanes key=paneName item=paneValue}
418
419 <div class="crm-accordion-wrapper crm-ajax-accordion crm-{$paneValue.id}-accordion {if $paneValue.open neq 'true'}collapsed{/if}">
420 <div class="crm-accordion-header" id="{$paneValue.id}">
421
422 {$paneName}
423 </div><!-- /.crm-accordion-header -->
424 <div class="crm-accordion-body">
425
426 <div class="{$paneValue.id}"></div>
427 </div><!-- /.crm-accordion-body -->
428 </div><!-- /.crm-accordion-wrapper -->
429
430 {/foreach}
431 </div>
432
433 {/if}
434 <br />
435 <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
436 </div>
437
438 {literal}
439 <script type="text/javascript">
440 function verify( ) {
441 if (cj('#is_email_receipt').prop('checked' )) {
442 var ok = confirm( '{/literal}{ts escape='js'}Click OK to save this contribution record AND send a receipt to the contributor now{/ts}{literal}.' );
443 if (!ok) {
444 return false;
445 }
446 }
447 }
448 </script>
449 {/literal}
450
451 {if $action neq 8}
452 {literal}
453 <script type="text/javascript">
454 CRM.$(function($) {
455 var $form = $('form.{/literal}{$form.formClass}{literal}');
456 checkEmailDependancies();
457 $('#is_email_receipt', $form).click(function() {
458 checkEmailDependancies();
459 });
460
461 function checkEmailDependancies( ) {
462 if ($('#is_email_receipt', $form).prop('checked')) {
463 $('#fromEmail', $form).show();
464 $('#receiptDate', $form).hide();
465 }
466 else {
467 $('#fromEmail', $form).hide();
468 $('#receiptDate', $form).show();
469 }
470 }
471 {/literal}{if !$contributionMode}{literal}
472 showHideCancelInfo($('#contribution_status_id', $form));
473
474 $('#contribution_status_id', $form).change(function() {
475 showHideCancelInfo($('#contribution_status_id', $form));
476 });
477
478 function showHideCancelInfo(obj) {
479 var cancelInfo_show_ids = [{/literal}{$cancelInfo_show_ids}{literal}];
480 if (cancelInfo_show_ids.indexOf(obj.val()) > -1) {
481 $('#cancelInfo', $form).show();
482 $('#total_amount', $form).attr('readonly', true);
483 }
484 else {
485 $("#cancel_date", $form).val('');
486 $("#cancel_reason", $form).val('');
487 $('#cancelInfo', $form).hide();
488 $("#total_amount", $form).removeAttr('readonly');
489 }
490 }
491 {/literal}{/if}
492 });
493 </script>
494 {/if} {* not delete mode if*}
495
496 {/if} {* closing of main custom data if *}
497
498 {literal}
499 <script type="text/javascript">
500
501 {/literal}
502
503 // load form during form rule.
504 {if $buildPriceSet}{literal}buildAmount( );{/literal}{/if}
505
506 {literal}
507
508 // CRM-16451: set financial type of 'Price Set' in back office contribution
509 // instead of selecting manually
510 function buildAmount( priceSetId, financialtypeIds ) {
511 if (!priceSetId) priceSetId = cj("#price_set_id").val( );
512 var fname = '#priceset';
513 if (!priceSetId) {
514 // hide price set fields.
515 cj(fname).hide( );
516
517 // show/hide price set amount and total amount.
518 cj("#totalAmountORPriceSet").show( );
519 cj("#totalAmount").show( );
520 var choose = "{/literal}{ts}Choose price set{/ts}{literal}";
521 cj("#price_set_id option[value='']").html( choose );
522
523 cj('label[for="total_amount"]').text('{/literal}{ts}Total Amount{/ts}{literal}');
524 cj(".crm-contribution-form-block-financial_type_id").show();
525 cj("#financial_type_id option[value='']").attr('selected', true);
526
527 //we might want to build recur block.
528 if (cj("#is_recur")) buildRecurBlock( null );
529 return;
530 }
531
532 //don't allow recurring w/ priceset.
533 if ( cj( "#is_recur" ) && cj( 'input:radio[name="is_recur"]:checked').val( ) ) {
534 //reset the values of recur block.
535 cj("#installments").val('');
536 cj("#frequency_interval").val('');
537 cj('input:radio[name="is_recur"]')[0].checked = true;
538 cj("#recurringPaymentBlock").hide( );
539 }
540
541 var dataUrl = {/literal}"{crmURL h=0 q='snippet=4'}"{literal} + '&priceSetId=' + priceSetId;
542
543 var response = cj.ajax({
544 url: dataUrl,
545 async: false
546 }).responseText;
547
548 cj( fname ).show( ).html( response ).trigger('crmLoad');
549 // freeze total amount text field.
550 cj( "#total_amount").val('');
551
552 cj( "#totalAmountORPriceSet" ).hide( );
553 cj( "#totalAmount").hide( );
554 var manual = "{/literal}{ts}Manual contribution amount{/ts}{literal}";
555 cj("#price_set_id option[value='']").html( manual );
556
557 cj('label[for="total_amount"]').text('{/literal}{ts}Price Sets{/ts}{literal}');
558 if (financialtypeIds) {
559 cj("#financial_type_id option[value="+financialtypeIds[priceSetId]+"]").prop('selected', true);
560 }
561 cj(".crm-contribution-form-block-financial_type_id").css("display", "none");
562 }
563
564 function adjustPayment( ) {
565 cj('#adjust-option-type').show();
566 cj("#total_amount").removeAttr("READONLY");
567 cj("#total_amount").css('background-color', '#ffffff');
568 }
569
570 {/literal}{if $processorSupportsFutureStartDate}{literal}
571 cj ('input:radio[name="is_recur"]').click( function( ) {
572 showStartDate( );
573 });
574
575 showStartDate( );
576
577 function showStartDate( ) {
578 if (cj( 'input:radio[name="is_recur"]:checked').val( ) == 0 ) {
579 cj('#start_date').hide( );
580 }
581 else {
582 cj('#start_date').show( );
583 }
584 }
585
586 {/literal}{/if}{literal}
587 var thousandMarker = "{/literal}{$config->monetaryThousandSeparator}{literal}";
588 var separator = "{/literal}{$config->monetaryDecimalPoint}{literal}";
589
590 cj('#fee_amount').change( function() {
591 var totalAmount = cj('#total_amount').val().replace(thousandMarker,'').replace(separator,'.');
592 var feeAmount = cj('#fee_amount').val().replace(thousandMarker,'').replace(separator,'.');
593 var netAmount = totalAmount - feeAmount;
594 if (totalAmount) {
595 cj('#net_amount').val(CRM.formatMoney(netAmount, true));
596 }
597 });
598
599 cj("#financial_type_id").on("change",function(){
600 cj('#total_amount').trigger("change");
601 })
602
603 cj("#currency").on("change",function(){
604 cj('#total_amount').trigger("change");
605 })
606
607 {/literal}{if $taxRates && $invoicing}{literal}
608 CRM.$(function($) {
609 $('#total_amount').on("change",function(event) {
610 if (event.handled !== true) {
611 var freezeFinancialType = '{/literal}{$freezeFinancialType}{literal}';
612 if (!freezeFinancialType) {
613 var financialType = $('#financial_type_id').val();
614 var taxRates = '{/literal}{$taxRates}{literal}';
615 var taxTerm = '{/literal}{$taxTerm}{literal}';
616 taxRates = JSON.parse(taxRates);
617 var currencies = '{/literal}{$currencies}{literal}';
618 currencies = JSON.parse(currencies);
619 var currencySelect = $('#currency').val();
620 var currencySymbol = currencies[currencySelect];
621 var re= /\((.*?)\)/g;
622 for(m = re.exec(currencySymbol); m; m = re.exec(currencySymbol)){
623 currencySymbol = m[1];
624 }
625 var taxRate = taxRates[financialType];
626 if (!taxRate) {
627 taxRate = 0;
628 cj("#totalTaxAmount").hide( );
629 } else {
630 cj("#totalTaxAmount").show( );
631 }
632 var totalAmount = $('#total_amount').val();
633 // replace all thousandMarker and change the separator to a dot
634 totalAmount = totalAmount.replace(thousandMarker,'').replace(separator,'.');
635
636 var totalTaxAmount = '{/literal}{$totalTaxAmount}{literal}';
637 var taxAmount = (taxRate/100)*totalAmount;
638 taxAmount = isNaN (taxAmount) ? 0:taxAmount;
639 var totalTaxAmount = taxAmount + Number(totalAmount);
640 totalTaxAmount = formatMoney( totalTaxAmount, 2, separator, thousandMarker );
641 $("#totalTaxAmount" ).html('{/literal}{ts 1=$taxTerm}Amount with %1 :{/ts}{literal} <span id="currencySymbolShow">' + currencySymbol + '</span> '+ totalTaxAmount);
642 }
643 event.handled = true;
644 }
645 return false;
646 });
647
648 $('#total_amount').trigger("change");
649 });
650 {/literal}{/if}{literal}
651
652 CRM.$(function($) {
653 $('#price_set_id').click(function() {
654 if( $('#price_set_id').val() ) {
655 $('#totalAmountBlock').hide();
656 }
657 else {
658 $('#totalAmountBlock').show();
659 }
660 });
661 });
662
663 function formatMoney (amount, c, d, t){
664 var n = amount,
665 c = isNaN(c = Math.abs(c)) ? 2 : c,
666 d = d == undefined ? "," : d,
667 t = t == undefined ? "." : t, s = n < 0 ? "-" : "",
668 i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "",
669 j = (j = i.length) > 3 ? j % 3 : 0;
670 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) : "");
671 };
672 </script>
673 {/literal}