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