Merge pull request #10797 from agileware/CIVICRM-230
[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 href='#' 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 $contributionMode}
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 {if $showCheckNumber || !$isOnline}
259 <tr id="checkNumber" class="crm-contribution-form-block-check_number">
260 <td class="label">{$form.check_number.label}</td>
261 <td>{$form.check_number.html}</td>
262 </tr>
263 {/if}
264 <tr class="crm-contribution-form-block-trxn_id">
265 <td class="label">{$form.trxn_id.label}</td>
266 <td {$valueStyle}>{$form.trxn_id.html} {help id="id-trans_id"}</td>
267 </tr>
268 </table>
269 </fieldset>
270 {/if}
271
272 {include file='CRM/Core/BillingBlockWrapper.tpl'}
273
274 <!-- start of soft credit -->
275 {if !$payNow}
276 <div class="crm-accordion-wrapper crm-accordion_title-accordion crm-accordion-processed {if $noSoftCredit}collapsed{/if}" id="softCredit">
277 <div class="crm-accordion-header">
278 {ts}Soft Credit{/ts}&nbsp;{help id="id-soft_credit"}
279 </div>
280 <div class="crm-accordion-body">
281 <table class="form-layout-compressed">
282 <tr class="crm-contribution-form-block-soft_credit_to">
283 <td colspan="2">
284 {include file="CRM/Contribute/Form/SoftCredit.tpl"}
285 </td>
286 </tr>
287 </table>
288 </div>
289 </div>
290 {/if}
291 <!-- end of soft credit -->
292
293 <!-- start of PCP -->
294 {if $siteHasPCPs && !$payNow}
295 <div class="crm-accordion-wrapper crm-accordion_title-accordion crm-accordion-processed {if $noPCP}collapsed{/if}" id="softCredit">
296 <div class="crm-accordion-header">
297 {ts}Personal Campaign Page{/ts}&nbsp;{help id="id-pcp"}
298 </div>
299 <div class="crm-accordion-body">
300 <table class="form-layout-compressed">
301 <tr class="crm-contribution-pcp-block crm-contribution-form-block-pcp_made_through_id">
302 <td class="label">{$form.pcp_made_through_id.label}</td>
303 <td>
304 {$form.pcp_made_through_id.html} &nbsp;
305 <div class="description">{ts}Search for the Personal Campaign Page by the fund-raiser's last name or email address.{/ts}</div>
306
307 <div class="spacer"></div>
308 <div class="crm-contribution-form-block-pcp_details">
309 <table class="crm-contribution-form-table-credit_to_pcp">
310 <tr id="pcpDisplayRollID" class="crm-contribution-form-block-pcp_display_in_roll">
311 <td class="label">{$form.pcp_display_in_roll.label}</td>
312 <td>{$form.pcp_display_in_roll.html}</td>
313 </tr>
314 <tr id="nickID" class="crm-contribution-form-block-pcp_roll_nickname">
315 <td class="label">{$form.pcp_roll_nickname.label}</td>
316 <td>{$form.pcp_roll_nickname.html|crmAddClass:big}<br/>
317 <div class="description">{ts}Name or nickname contributor wants to be displayed in the Honor Roll. Enter "Anonymous" for anonymous contributions.{/ts}</div>
318 </td>
319 </tr>
320 <tr id="personalNoteID" class="crm-contribution-form-block-pcp_personal_note">
321 <td class="label" style="vertical-align: top">{$form.pcp_personal_note.label}</td>
322 <td>
323 {$form.pcp_personal_note.html}
324 <div
325 class="description">{ts}Personal message submitted by contributor for display in the Honor Roll.{/ts}</div>
326 </td>
327 </tr>
328 </table>
329 </div>
330 </td>
331 </tr>
332 </table>
333 </div>
334 </div>
335 {include file="CRM/Contribute/Form/PCP.js.tpl"}
336 {/if}
337 <!-- end of PCP -->
338
339 {if !$payNow}
340 <div id="customData" class="crm-contribution-form-block-customData"></div>
341 {/if}
342
343 {*include custom data js file*}
344 {include file="CRM/common/customData.tpl"}
345
346 {literal}
347 <script type="text/javascript">
348 CRM.$(function($) {
349 {/literal}
350 CRM.buildCustomData( '{$customDataType}' );
351 {if $customDataSubType}
352 CRM.buildCustomData( '{$customDataType}', {$customDataSubType} );
353 {/if}
354
355 {if $buildPriceSet}{literal}buildAmount( );{/literal}{/if}
356 {literal}
357 });
358
359 // bind first click of accordion header to load crm-accordion-body with snippet
360 // everything else taken care of by cj().crm-accordions()
361 CRM.$(function($) {
362 cj('#adjust-option-type').hide();
363 cj('.crm-ajax-accordion .crm-accordion-header').one('click', function() {
364 loadPanes(cj(this).attr('id'));
365 });
366 cj('.crm-ajax-accordion:not(.collapsed) .crm-accordion-header').each(function(index) {
367 loadPanes(cj(this).attr('id'));
368 });
369 });
370 // load panes function calls for snippet based on id of crm-accordion-header
371 function loadPanes( id ) {
372 var url = "{/literal}{crmURL p='civicrm/contact/view/contribution' q='snippet=4&formType=' h=0}{literal}" + id;
373 {/literal}
374 {if $contributionMode}
375 url = url + "&mode={$contributionMode}";
376 {/if}
377 {if $qfKey}
378 url = url + "&qfKey={$qfKey}";
379 {/if}
380 {literal}
381 if (! cj('div.'+id).html()) {
382 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}...';
383 cj('div.'+id).html(loading);
384 cj.ajax({
385 url : url,
386 success: function(data) { cj('div.'+id).html(data).trigger('crmLoad'); }
387 });
388 }
389 }
390
391 var url = "{/literal}{$dataUrl}{literal}";
392
393 {/literal}
394 {if $context eq 'standalone' and $outBound_option != 2 }
395 {literal}
396 CRM.$(function($) {
397
398 var $form = $("form.{/literal}{$form.formClass}{literal}");
399 $("#contact_id", $form).change(checkEmail);
400 checkEmail( );
401
402 function checkEmail( ) {
403 var data = $("#contact_id", $form).select2('data');
404 if (data && data.extra && data.extra.email && data.extra.email.length) {
405 $("#email-receipt", $form).show();
406 $("#email-address", $form).html(data.extra.email);
407 }
408 else {
409 $("#email-receipt", $form).hide();
410 }
411 }
412
413 showHideByValue( 'is_email_receipt', '', 'receiptDate', 'table-row', 'radio', true);
414 showHideByValue( 'is_email_receipt', '', 'fromEmail', 'table-row', 'radio', false );
415 });
416
417 {/literal}
418 {/if}
419 </script>
420
421 <div class="accordion ui-accordion ui-widget ui-helper-reset">
422 {* Additional Detail / Honoree Information / Premium Information *}
423 {foreach from=$allPanes key=paneName item=paneValue}
424
425 <div class="crm-accordion-wrapper crm-ajax-accordion crm-{$paneValue.id}-accordion {if $paneValue.open neq 'true'}collapsed{/if}">
426 <div class="crm-accordion-header" id="{$paneValue.id}">
427
428 {$paneName}
429 </div><!-- /.crm-accordion-header -->
430 <div class="crm-accordion-body">
431
432 <div class="{$paneValue.id}"></div>
433 </div><!-- /.crm-accordion-body -->
434 </div><!-- /.crm-accordion-wrapper -->
435
436 {/foreach}
437 </div>
438
439 {/if}
440 <br />
441 <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
442 </div>
443
444 {literal}
445 <script type="text/javascript">
446 function verify( ) {
447 if (cj('#is_email_receipt').prop('checked' )) {
448 var ok = confirm( '{/literal}{ts escape='js'}Click OK to save this contribution record AND send a receipt to the contributor now{/ts}{literal}.' );
449 if (!ok) {
450 return false;
451 }
452 }
453 }
454 </script>
455 {/literal}
456
457 {if $action neq 8}
458 {literal}
459 <script type="text/javascript">
460 CRM.$(function($) {
461 var $form = $('form.{/literal}{$form.formClass}{literal}');
462 checkEmailDependancies();
463 $('#is_email_receipt', $form).click(function() {
464 checkEmailDependancies();
465 });
466
467 function checkEmailDependancies( ) {
468 if ($('#is_email_receipt', $form).prop('checked')) {
469 $('#fromEmail', $form).show();
470 $('#receiptDate', $form).hide();
471 }
472 else {
473 $('#fromEmail', $form).hide();
474 $('#receiptDate', $form).show();
475 }
476 }
477 {/literal}{if !$contributionMode}{literal}
478 showHideCancelInfo($('#contribution_status_id', $form));
479
480 $('#contribution_status_id', $form).change(function() {
481 showHideCancelInfo($('#contribution_status_id', $form));
482 });
483
484 function showHideCancelInfo(obj) {
485 var cancelInfo_show_ids = [{/literal}{$cancelInfo_show_ids}{literal}];
486 if (cancelInfo_show_ids.indexOf(obj.val()) > -1) {
487 $('#cancelInfo', $form).show();
488 $('#total_amount', $form).attr('readonly', true);
489 }
490 else {
491 $("#cancel_date", $form).val('');
492 $("#cancel_reason", $form).val('');
493 $('#cancelInfo', $form).hide();
494 $("#total_amount", $form).removeAttr('readonly');
495 }
496 }
497 {/literal}{/if}
498 });
499 </script>
500 {if !$contributionMode}
501 {crmAPI var="checkVal" entity="OptionValue" action="getvalue" version="3" option_group_id="payment_instrument" name="Check" return="value"}
502 {include file="CRM/common/showHideByFieldValue.tpl"
503 trigger_field_id ="payment_instrument_id"
504 trigger_value = $checkVal
505 target_element_id ="checkNumber"
506 target_element_type ="table-row"
507 field_type ="select"
508 invert = 0
509 }
510 {/if}
511 {/if} {* not delete mode if*}
512
513 {/if} {* closing of main custom data if *}
514
515 {literal}
516 <script type="text/javascript">
517
518 {/literal}
519
520 // load form during form rule.
521 {if $buildPriceSet}{literal}buildAmount( );{/literal}{/if}
522
523 {literal}
524
525 // CRM-16451: set financial type of 'Price Set' in back office contribution
526 // instead of selecting manually
527 function buildAmount( priceSetId, financialtypeIds ) {
528 if (!priceSetId) priceSetId = cj("#price_set_id").val( );
529 var fname = '#priceset';
530 if (!priceSetId) {
531 // hide price set fields.
532 cj(fname).hide( );
533
534 // show/hide price set amount and total amount.
535 cj("#totalAmountORPriceSet").show( );
536 cj("#totalAmount").show( );
537 var choose = "{/literal}{ts}Choose price set{/ts}{literal}";
538 cj("#price_set_id option[value='']").html( choose );
539
540 cj('label[for="total_amount"]').text('{/literal}{ts}Total Amount{/ts}{literal}');
541 cj(".crm-contribution-form-block-financial_type_id").show();
542 cj("#financial_type_id option[value='']").attr('selected', true);
543
544 //we might want to build recur block.
545 if (cj("#is_recur")) buildRecurBlock( null );
546 return;
547 }
548
549 //don't allow recurring w/ priceset.
550 if ( cj( "#is_recur" ) && cj( 'input:radio[name="is_recur"]:checked').val( ) ) {
551 //reset the values of recur block.
552 cj("#installments").val('');
553 cj("#frequency_interval").val('');
554 cj('input:radio[name="is_recur"]')[0].checked = true;
555 cj("#recurringPaymentBlock").hide( );
556 }
557
558 var dataUrl = {/literal}"{crmURL h=0 q='snippet=4'}"{literal} + '&priceSetId=' + priceSetId;
559
560 var response = cj.ajax({
561 url: dataUrl,
562 async: false
563 }).responseText;
564
565 cj( fname ).show( ).html( response ).trigger('crmLoad');
566 // freeze total amount text field.
567 cj( "#total_amount").val('');
568
569 cj( "#totalAmountORPriceSet" ).hide( );
570 cj( "#totalAmount").hide( );
571 var manual = "{/literal}{ts}Manual contribution amount{/ts}{literal}";
572 cj("#price_set_id option[value='']").html( manual );
573
574 cj('label[for="total_amount"]').text('{/literal}{ts}Price Sets{/ts}{literal}');
575 if (financialtypeIds) {
576 cj("#financial_type_id option[value="+financialtypeIds[priceSetId]+"]").prop('selected', true);
577 }
578 cj(".crm-contribution-form-block-financial_type_id").css("display", "none");
579 }
580
581 function adjustPayment( ) {
582 cj('#adjust-option-type').show();
583 cj("#total_amount").removeAttr("READONLY");
584 cj("#total_amount").css('background-color', '#ffffff');
585 }
586
587 {/literal}{if $processorSupportsFutureStartDate}{literal}
588 cj ('input:radio[name="is_recur"]').click( function( ) {
589 showStartDate( );
590 });
591
592 showStartDate( );
593
594 function showStartDate( ) {
595 if (cj( 'input:radio[name="is_recur"]:checked').val( ) == 0 ) {
596 cj('#start_date').hide( );
597 }
598 else {
599 cj('#start_date').show( );
600 }
601 }
602
603 {/literal}{/if}{literal}
604 var thousandMarker = "{/literal}{$config->monetaryThousandSeparator}{literal}";
605 var separator = "{/literal}{$config->monetaryDecimalPoint}{literal}";
606
607 cj('#fee_amount').change( function() {
608 var totalAmount = cj('#total_amount').val().replace(thousandMarker,'').replace(separator,'.');
609 var feeAmount = cj('#fee_amount').val().replace(thousandMarker,'').replace(separator,'.');
610 var netAmount = totalAmount - feeAmount;
611 if (totalAmount) {
612 cj('#net_amount').val(CRM.formatMoney(netAmount, true));
613 }
614 });
615
616 cj("#financial_type_id").on("change",function(){
617 cj('#total_amount').trigger("change");
618 })
619
620 cj("#currency").on("change",function(){
621 cj('#total_amount').trigger("change");
622 })
623
624 {/literal}{if $taxRates && $invoicing}{literal}
625 CRM.$(function($) {
626 $('#total_amount').on("change",function(event) {
627 if (event.handled !== true) {
628 var freezeFinancialType = '{/literal}{$freezeFinancialType}{literal}';
629 if (!freezeFinancialType) {
630 var financialType = $('#financial_type_id').val();
631 var taxRates = '{/literal}{$taxRates}{literal}';
632 taxRates = JSON.parse(taxRates);
633 var currencies = '{/literal}{$currencies}{literal}';
634 currencies = JSON.parse(currencies);
635 var currencySelect = $('#currency').val();
636 var currencySymbol = currencies[currencySelect];
637 var re= /\((.*?)\)/g;
638 for(m = re.exec(currencySymbol); m; m = re.exec(currencySymbol)){
639 currencySymbol = m[1];
640 }
641 var taxRate = taxRates[financialType];
642 if (!taxRate) {
643 taxRate = 0;
644 cj("#totalTaxAmount").hide( );
645 } else {
646 cj("#totalTaxAmount").show( );
647 }
648 var totalAmount = $('#total_amount').val();
649 // replace all thousandMarker and change the separator to a dot
650 totalAmount = totalAmount.replace(thousandMarker,'').replace(separator,'.');
651
652 var totalTaxAmount = '{/literal}{$totalTaxAmount}{literal}';
653 var taxAmount = (taxRate/100)*totalAmount;
654 taxAmount = isNaN (taxAmount) ? 0:taxAmount;
655 var totalTaxAmount = taxAmount + Number(totalAmount);
656 totalTaxAmount = formatMoney( totalTaxAmount, 2, separator, thousandMarker );
657
658 $("#totalTaxAmount" ).html('Amount with tax : <span id="currencySymbolShow">' + currencySymbol + '</span> '+ totalTaxAmount);
659 }
660 event.handled = true;
661 }
662 return false;
663 });
664
665 $('#total_amount').trigger("change");
666 });
667 {/literal}{/if}{literal}
668
669 CRM.$(function($) {
670 $('#price_set_id').click(function() {
671 if( $('#price_set_id').val() ) {
672 $('#totalAmountBlock').hide();
673 }
674 else {
675 $('#totalAmountBlock').show();
676 }
677 });
678 });
679
680 function formatMoney (amount, c, d, t){
681 var n = amount,
682 c = isNaN(c = Math.abs(c)) ? 2 : c,
683 d = d == undefined ? "," : d,
684 t = t == undefined ? "." : t, s = n < 0 ? "-" : "",
685 i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "",
686 j = (j = i.length) > 3 ? j % 3 : 0;
687 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) : "");
688 };
689 </script>
690 {/literal}