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