Merge in 5.48
[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 !empty($showAdditionalInfo) and !empty($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 !empty($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 !empty($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 !empty($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 !empty($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}>{$form.receive_date.html}<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 (empty($is_template) && (!$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 {$form.cancel_date.html}
169 </td>
170 </tr>
171 <tr id="cancelDescription" class="crm-contribution-form-block-cancel_reason">
172 <td class="label">&nbsp;</td>
173 <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>
174 </tr>
175 <tr id="cancelReason">
176 <td class="label" style="vertical-align: top;">{$form.cancel_reason.label}</td>
177 <td>{$form.cancel_reason.html}</td>
178 </tr>
179 <tr id="refundTrxnID">
180 <td class="label" style="vertical-align: top;">{$form.refund_trxn_id.label}</td>
181 <td>{$form.refund_trxn_id.html}</td>
182 </tr>
183 </table>
184 </fieldset>
185 </td>
186 </tr>
187 {if empty($is_template)}
188 <tr class="crm-contribution-form-block-receive_date">
189 <td class="label">{$form.receive_date.label}</td>
190 <td>{$form.receive_date.html}<br />
191 <span class="description">{ts}The date this contribution was received.{/ts}</span>
192 </td>
193 </tr>
194 {/if}
195 {/if}
196 {if $form.revenue_recognition_date && !$payNow}
197 <tr class="crm-contribution-form-block-revenue_recognition_date">
198 <td class="label">{$form.revenue_recognition_date.label}</td>
199 <td>{$form.revenue_recognition_date.html}</td>
200 </tr>
201 {/if}
202
203 {if empty($is_template) and $email and $outBound_option != 2}
204 <tr class="crm-contribution-form-block-is_email_receipt">
205 <td class="label">{$form.is_email_receipt.label}</td>
206 <td>{$form.is_email_receipt.html}&nbsp;
207 <span class="description">{ts 1=$email}Automatically email a receipt for this payment to %1?{/ts}</span>
208 </td>
209 </tr>
210 {elseif empty($is_template) and $context eq 'standalone' and $outBound_option != 2 }
211 <tr id="email-receipt" style="display:none;" class="crm-contribution-form-block-is_email_receipt">
212 <td class="label">{$form.is_email_receipt.label}</td>
213 <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>
214 </td>
215 </tr>
216 {/if}
217 {if empty($is_template)}
218 <tr id="fromEmail" class="crm-contribution-form-block-receipt_date" style="display:none;">
219 <td class="label">{$form.from_email_address.label}</td>
220 <td>{$form.from_email_address.html} {help id="id-from_email" file="CRM/Contact/Form/Task/Help/Email/id-from_email.hlp"}</td>
221 </tr>
222 {/if}
223 {if empty($is_template)}
224 <tr id="receiptDate" class="crm-contribution-form-block-receipt_date">
225 <td class="label">{$form.receipt_date.label}</td>
226 <td>{$form.receipt_date.html}<br />
227 <span class="description">{ts}Date that a receipt was sent to the contributor.{/ts}</span>
228 </td>
229 </tr>
230 {/if}
231 {if !empty($form.payment_processor_id)}
232 <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>
233 {/if}
234 </table>
235
236 {if !$contributionMode && empty($is_template)}
237 <fieldset class="payment-details_group">
238 <legend>
239 {ts}Payment Details{/ts}
240 </legend>
241 {if $isUsePaymentBlock}
242 {include file="CRM/Contribute/Form/PaymentInfoBlock.tpl"}
243 {else}
244 <table class="form-layout-compressed" >
245 <tr class="crm-contribution-form-block-payment_instrument_id">
246 <td class="label">{$form.payment_instrument_id.label}</td>
247 <td {$valueStyle}>{$form.payment_instrument_id.html} {help id="payment_instrument_id"}</td>
248 </tr>
249 <tr class="crm-contribution-form-block-trxn_id">
250 <td class="label">{$form.trxn_id.label}</td>
251 <td {$valueStyle}>{$form.trxn_id.html} {help id="id-trans_id"}</td>
252 </tr>
253 </table>
254 {/if}
255 </fieldset>
256 {/if}
257
258 {if !$isUsePaymentBlock}
259 {include file='CRM/Core/BillingBlockWrapper.tpl'}
260 {/if}
261
262 <!-- start of soft credit -->
263 {if !$payNow}
264 <div class="crm-accordion-wrapper crm-accordion_title-accordion crm-accordion-processed {if $noSoftCredit}collapsed{/if}" id="softCredit">
265 <div class="crm-accordion-header">
266 {ts}Soft Credit{/ts}&nbsp;{help id="id-soft_credit"}
267 </div>
268 <div class="crm-accordion-body">
269 <table class="form-layout-compressed">
270 <tr class="crm-contribution-form-block-soft_credit_to">
271 <td colspan="2">
272 {include file="CRM/Contribute/Form/SoftCredit.tpl"}
273 </td>
274 </tr>
275 </table>
276 </div>
277 </div>
278 {/if}
279 <!-- end of soft credit -->
280
281 <!-- start of PCP -->
282 {if $siteHasPCPs && !$payNow}
283 <div class="crm-accordion-wrapper crm-accordion_title-accordion crm-accordion-processed {if $noPCP}collapsed{/if}" id="softCredit">
284 <div class="crm-accordion-header">
285 {ts}Personal Campaign Page{/ts}&nbsp;{help id="id-pcp"}
286 </div>
287 <div class="crm-accordion-body">
288 <table class="form-layout-compressed">
289 <tr class="crm-contribution-pcp-block crm-contribution-form-block-pcp_made_through_id">
290 <td class="label">{$form.pcp_made_through_id.label}</td>
291 <td>
292 {$form.pcp_made_through_id.html} &nbsp;
293 <div class="description">{ts}Search for the Personal Campaign Page by the fund-raiser's last name or email address.{/ts}</div>
294
295 <div class="spacer"></div>
296 <div class="crm-contribution-form-block-pcp_details">
297 <table class="crm-contribution-form-table-credit_to_pcp">
298 <tr id="pcpDisplayRollID" class="crm-contribution-form-block-pcp_display_in_roll">
299 <td class="label">{$form.pcp_display_in_roll.label}</td>
300 <td>{$form.pcp_display_in_roll.html}</td>
301 </tr>
302 <tr id="nickID" class="crm-contribution-form-block-pcp_roll_nickname">
303 <td class="label">{$form.pcp_roll_nickname.label}</td>
304 <td>{$form.pcp_roll_nickname.html|crmAddClass:big}<br/>
305 <div class="description">{ts}Name or nickname contributor wants to be displayed in the Honor Roll. Enter "Anonymous" for anonymous contributions.{/ts}</div>
306 </td>
307 </tr>
308 <tr id="personalNoteID" class="crm-contribution-form-block-pcp_personal_note">
309 <td class="label" style="vertical-align: top">{$form.pcp_personal_note.label}</td>
310 <td>
311 {$form.pcp_personal_note.html}
312 <div class="description">{ts}Personal message submitted by contributor for display in the Honor Roll.{/ts}</div>
313 </td>
314 </tr>
315 </table>
316 </div>
317 </td>
318 </tr>
319 </table>
320 </div>
321 </div>
322 {include file="CRM/Contribute/Form/PCP.js.tpl"}
323 {/if}
324 <!-- end of PCP -->
325
326 {if !$payNow}
327 {include file="CRM/common/customDataBlock.tpl"}
328 {/if}
329
330 {literal}
331 <script type="text/javascript">
332 CRM.$(function($) {
333 {/literal}
334 {if $buildPriceSet}{literal}buildAmount();{/literal}{/if}
335 {literal}
336
337 // bind first click of accordion header to load crm-accordion-body with snippet
338 // everything else taken care of by cj().crm-accordions()
339 cj('#adjust-option-type').hide();
340 cj('.crm-ajax-accordion .crm-accordion-header').one('click', function() {
341 loadPanes(cj(this).attr('id'));
342 });
343 cj('.crm-ajax-accordion:not(.collapsed) .crm-accordion-header').each(function(index) {
344 loadPanes(cj(this).attr('id'));
345 });
346 });
347
348 // load panes function calls for snippet based on id of crm-accordion-header
349 function loadPanes(id) {
350 var url = "{/literal}{crmURL p='civicrm/contact/view/contribution' q="snippet=4&id=`$entityID`&formType=" h=0}{literal}" + id;
351 {/literal}
352 {if $contributionMode}
353 url = url + "&mode={$contributionMode}";
354 {/if}
355 {if $qfKey}
356 url = url + "&qfKey={$qfKey}";
357 {/if}
358 {literal}
359 if (! cj('div.'+id).html()) {
360 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}...';
361 cj('div.'+id).html(loading);
362 cj.ajax({
363 url : url,
364 success: function(data) { cj('div.'+id).html(data).trigger('crmLoad'); }
365 });
366 }
367 }
368
369 var url = {/literal}{$dataUrl|@json_encode}{literal};
370
371 {/literal}
372 {if $context eq 'standalone' and $outBound_option != 2}
373 {literal}
374 CRM.$(function($) {
375
376 var $form = $("form.{/literal}{$form.formClass}{literal}");
377 $("#contact_id", $form).change(checkEmail);
378 checkEmail();
379
380 function checkEmail() {
381 var data = $("#contact_id", $form).select2('data');
382 if (data && data.extra && data.extra.email && data.extra.email.length) {
383 $("#email-receipt", $form).show();
384 $("#email-address", $form).html(data.extra.email);
385 }
386 else {
387 $("#email-receipt", $form).hide();
388 }
389 }
390
391 showHideByValue('is_email_receipt', '', 'receiptDate', 'table-row', 'radio', true);
392 showHideByValue('is_email_receipt', '', 'fromEmail', 'table-row', 'radio', false);
393 });
394
395 {/literal}
396 {/if}
397 </script>
398
399 <div class="accordion ui-accordion ui-widget ui-helper-reset">
400 {* Additional Detail / Honoree Information / Premium Information *}
401 {foreach from=$allPanes key=paneName item=paneValue}
402 <div class="crm-accordion-wrapper crm-ajax-accordion crm-{$paneValue.id}-accordion {if $paneValue.open neq 'true'}collapsed{/if}">
403 <div class="crm-accordion-header" id="{$paneValue.id}">{$paneName}</div>
404 <div class="crm-accordion-body">
405 <div class="{$paneValue.id}"></div>
406 </div><!-- /.crm-accordion-body -->
407 </div><!-- /.crm-accordion-wrapper -->
408 {/foreach}
409 </div>
410 {/if}
411 <br />
412 <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
413 </div>
414
415 {literal}
416 <script type="text/javascript">
417 function verify() {
418 if (cj('#is_email_receipt').prop('checked')) {
419 var ok = confirm('{/literal}{ts escape='js'}Click OK to save this contribution record AND send a receipt to the contributor now{/ts}{literal}.');
420 if (!ok) {
421 return false;
422 }
423 }
424 }
425 </script>
426 {/literal}
427
428 {if $action neq 8}
429 {literal}
430 <script type="text/javascript">
431 CRM.$(function($) {
432 var $form = $('form.{/literal}{$form.formClass}{literal}');
433 checkEmailDependancies();
434 $('#is_email_receipt', $form).click(function() {
435 checkEmailDependancies();
436 });
437
438 function checkEmailDependancies() {
439 if ($('#is_email_receipt', $form).prop('checked')) {
440 $('#fromEmail', $form).show();
441 $('#receiptDate', $form).hide();
442 }
443 else {
444 $('#fromEmail', $form).hide();
445 $('#receiptDate', $form).show();
446 }
447 }
448 {/literal}{if !$contributionMode}{literal}
449 showHideCancelInfo($('#contribution_status_id', $form));
450
451 $('#contribution_status_id', $form).change(function() {
452 showHideCancelInfo($('#contribution_status_id', $form));
453 });
454
455 function showHideCancelInfo(obj) {
456 var cancelInfo_show_ids = [{/literal}{$cancelInfo_show_ids|smarty:nodefaults}{literal}];
457 if (cancelInfo_show_ids.indexOf(obj.val()) > -1) {
458 $('#cancelInfo', $form).show();
459 $('#total_amount', $form).attr('readonly', true);
460 }
461 else {
462 $("#cancel_date", $form).val('');
463 $("#cancel_reason", $form).val('');
464 $('#cancelInfo', $form).hide();
465 $("#total_amount", $form).removeAttr('readonly');
466 }
467 }
468 {/literal}{/if}
469 });
470 </script>
471 {/if} {* not delete mode if*}
472 {/if} {* closing of main custom data if *}
473
474 {literal}
475 <script type="text/javascript">
476 {/literal}
477 // load form during form rule.
478 {if $buildPriceSet}{literal}buildAmount();{/literal}{/if}
479 {literal}
480
481 // CRM-16451: set financial type of 'Price Set' in back office contribution
482 // instead of selecting manually
483 function buildAmount(priceSetId, financialtypeIds) {
484 if (!priceSetId) { priceSetId = cj("#price_set_id").val(); }
485 var fname = '#priceset';
486 if (!priceSetId) {
487 // hide price set fields.
488 cj(fname).hide();
489
490 // show/hide price set amount and total amount.
491 cj("#totalAmountORPriceSet").show();
492 cj("#totalAmount").show();
493 var choose = "{/literal}{ts escape='js'}Choose price set{/ts}{literal}";
494 cj("#price_set_id option[value='']").html(choose);
495
496 cj('label[for="total_amount"]').text('{/literal}{ts escape='js'}Total Amount{/ts}{literal}');
497 cj(".crm-contribution-form-block-financial_type_id").show();
498 cj("#financial_type_id option[value='']").attr('selected', true);
499
500 //we might want to build recur block.
501 if (cj("#is_recur")) { buildRecurBlock(null); }
502 return;
503 }
504
505 //don't allow recurring w/ priceset.
506 if (cj("#is_recur") && cj('input:radio[name="is_recur"]:checked').val()) {
507 //reset the values of recur block.
508 cj("#installments").val('');
509 cj("#frequency_interval").val('');
510 cj('input:radio[name="is_recur"]')[0].checked = true;
511 cj("#recurringPaymentBlock").hide();
512 }
513
514 var dataUrl = {/literal}"{crmURL h=0 q='snippet=4'}"{literal} + '&priceSetId=' + priceSetId;
515
516 var response = cj.ajax({
517 url: dataUrl,
518 async: false
519 }).responseText;
520
521 cj(fname).show().html(response).trigger('crmLoad');
522 // freeze total amount text field.
523 cj( "#total_amount").val('');
524
525 cj( "#totalAmountORPriceSet" ).hide();
526 cj( "#totalAmount").hide();
527 var manual = "{/literal}{ts escape='js'}Manual contribution amount{/ts}{literal}";
528 cj("#price_set_id option[value='']").html(manual);
529
530 cj('label[for="total_amount"]').text('{/literal}{ts escape='js'}Price Sets{/ts}{literal}');
531 if (financialtypeIds) {
532 cj("#financial_type_id option[value="+financialtypeIds[priceSetId]+"]").prop('selected', true);
533 }
534 cj(".crm-contribution-form-block-financial_type_id").css("display", "none");
535 }
536
537 function adjustPayment() {
538 cj('#adjust-option-type').show();
539 cj("#total_amount").removeAttr("READONLY");
540 cj("#total_amount").css('background-color', '#ffffff');
541 }
542
543 {/literal}{if $processorSupportsFutureStartDate}{literal}
544 cj ('#is_recur').click(function() {
545 showStartDate();
546 });
547
548 showStartDate();
549
550 function showStartDate() {
551 if (!cj('#is_recur').is(':checked')) {
552 cj('#start_date').hide();
553 }
554 else {
555 cj('#start_date').show();
556 }
557 }
558
559 {/literal}{/if}{literal}
560 var thousandMarker = "{/literal}{$config->monetaryThousandSeparator}{literal}";
561 var separator = "{/literal}{$config->monetaryDecimalPoint}{literal}";
562
563 cj("#financial_type_id").on("change", function() {
564 cj('#total_amount').trigger("change");
565 })
566
567 cj("#currency").on("change", function() {
568 cj('#total_amount').trigger("change");
569 })
570
571 {/literal}{if $taxRates && $invoicing}{literal}
572 CRM.$(function($) {
573 $('#total_amount').on("change", function(event) {
574 if (event.handled !== true) {
575 var freezeFinancialType = '{/literal}{$freezeFinancialType}{literal}';
576 if (!freezeFinancialType) {
577 var financialType = $('#financial_type_id').val();
578 var taxRates = '{/literal}{$taxRates}{literal}';
579 var taxTerm = '{/literal}{$taxTerm}{literal}';
580 taxRates = JSON.parse(taxRates);
581 var currencies = '{/literal}{$currencies}{literal}';
582 currencies = JSON.parse(currencies);
583 var currencySelect = $('#currency').val();
584 var currencySymbol = currencies[currencySelect];
585 var re= /\((.*?)\)/g;
586 for(m = re.exec(currencySymbol); m; m = re.exec(currencySymbol)){
587 currencySymbol = m[1];
588 }
589 var taxRate = taxRates[financialType];
590 if (!taxRate) {
591 taxRate = 0;
592 cj("#totalTaxAmount").hide();
593 } else {
594 cj("#totalTaxAmount").show();
595 }
596 var totalAmount = $('#total_amount').val();
597 // replace all thousandMarker and change the separator to a dot
598 totalAmount = totalAmount.replace(thousandMarker,'').replace(separator,'.');
599
600 var taxAmount = (taxRate/100)*totalAmount;
601 taxAmount = isNaN (taxAmount) ? 0:taxAmount;
602 var totalTaxAmount = taxAmount + Number(totalAmount);
603 totalTaxAmount = formatMoney( totalTaxAmount, 2, separator, thousandMarker );
604 $("#totalTaxAmount" ).html('{/literal}{ts 1=$taxTerm}Amount with %1 :{/ts}{literal} <span id="currencySymbolShow">' + currencySymbol + '</span> '+ totalTaxAmount);
605 }
606 event.handled = true;
607 }
608 return false;
609 });
610
611 $('#total_amount').trigger("change");
612 });
613 {/literal}{/if}{literal}
614
615 CRM.$(function($) {
616 $('#price_set_id').click(function() {
617 if($('#price_set_id').val()) {
618 $('#totalAmountBlock').hide();
619 }
620 else {
621 $('#totalAmountBlock').show();
622 }
623 });
624 });
625
626 function formatMoney(amount, c, d, t) {
627 var n = amount,
628 c = isNaN(c = Math.abs(c)) ? 2 : c,
629 d = d == undefined ? "," : d,
630 t = t == undefined ? "." : t, s = n < 0 ? "-" : "",
631 i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "",
632 j = (j = i.length) > 3 ? j % 3 : 0;
633 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) : "");
634 };
635 </script>
636 {/literal}