CRM-17991: Fix Safari JS bug in COntribution popups (affects softcredits, pledges).
[civicrm-core.git] / templates / CRM / Contribute / Form / Contribution.tpl
1 {*
2 +--------------------------------------------------------------------+
3 | CiviCRM version 4.7 |
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC (c) 2004-2016 |
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}
44 {ts 1=$displayName 2=$contributionMode|upper}Use this form to {if $payNow} edit {else} submit a new {/if} contribution on behalf of %1. <strong>A
45 %2 transaction will be submitted</strong> using the selected payment processor.{/ts}
46 {else}
47 {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}
48 {/if}
49 </div>
50 {/if}
51 {if $action eq 8}
52 <div class="messages status no-popup">
53 <div class="icon inform-icon"></div>
54 {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}
55 </div>
56 {else}
57 {if $newCredit AND $action EQ 1 AND $contributionMode EQ null}
58 <div class="action-link css_right crm-link-credit-card-mode">
59 {if $contactId}
60 {capture assign=ccModeLink}{crmURL p='civicrm/contact/view/contribution' q="reset=1&action=add&cid=`$contactId`&context=`$context`&mode=live"}{/capture}
61 {else}
62 {capture assign=ccModeLink}{crmURL p='civicrm/contact/view/contribution' q="reset=1&action=add&context=standalone&mode=live"}{/capture}
63 {/if}
64 <a class="open-inline-noreturn action-item crm-hover-button" href="{$ccModeLink}">&raquo; {ts}submit credit card contribution{/ts}</a>
65 </div>
66 {/if}
67 <div class="crm-submit-buttons">
68 {include file="CRM/common/formButtons.tpl"}
69 </div>
70 {if $isOnline}{assign var=valueStyle value=" class='view-value'"}{else}{assign var=valueStyle value=""}{/if}
71 <table class="form-layout-compressed">
72 {if $context neq 'standalone'}
73 <tr>
74 <td class="font-size12pt label"><strong><strong>{ts}Contributor{/ts}</strong></td><td class="font-size12pt"><strong>{$displayName}</strong></td>
75 </tr>
76 {else}
77 <td class="label">{$form.contact_id.label}</td>
78 <td>{$form.contact_id.html}</td>
79 {/if}
80 {if $contributionMode}
81 <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>
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}
158 {if $email and $outBound_option != 2}
159 <tr class="crm-contribution-form-block-is_email_receipt">
160 <td class="label">{$form.is_email_receipt.label}</td>
161 <td>{$form.is_email_receipt.html}&nbsp; <span class="description">{ts 1=$email}Automatically email a receipt for this contribution to %1?{/ts}</span>
162 </td>
163 </tr>
164 {elseif $context eq 'standalone' and $outBound_option != 2 }
165 <tr id="email-receipt" style="display:none;" class="crm-contribution-form-block-is_email_receipt"><td class="label">{$form.is_email_receipt.label}</td><td>{$form.is_email_receipt.html} <span class="description">{ts}Automatically email a receipt for this contribution to {/ts}<span id="email-address"></span>?</span></td></tr>
166 {/if}
167 <tr id="fromEmail" style="display:none;" >
168 <td class="label">{$form.from_email_address.label}</td>
169 <td>{$form.from_email_address.html}</td>
170 </tr>
171 <tr id="receiptDate" class="crm-contribution-form-block-receipt_date">
172 <td class="label">{$form.receipt_date.label}</td>
173 <td>{include file="CRM/common/jcalendar.tpl" elementName=receipt_date}<br />
174 <span class="description">{ts}Date that a receipt was sent to the contributor.{/ts}</span>
175 </td>
176 </tr>
177 {/if}
178 {if !$contributionMode || $payNow}
179 <tr class="crm-contribution-form-block-contribution_status_id">
180 <td class="label">{$form.contribution_status_id.label}</td>
181 <td>{$form.contribution_status_id.html}
182 {if $contribution_status_id eq 2}{if $is_pay_later }: {ts}Pay Later{/ts} {else}: {ts}Incomplete Transaction{/ts}{/if}{/if}
183 </td>
184 <td>
185 {if $contactId && $contribID && $contributionMode EQ null && $contribution_status_id eq 2}
186 {capture assign=payNowLink}{crmURL p='civicrm/contact/view/contribution' q="reset=1&action=update&id=`$contribID`&cid=`$contactId`&context=`$context`&mode=live"}{/capture}
187 <a class="open-inline action-item crm-hover-button" href="{$payNowLink}">&raquo; {ts}Pay with Credit Card{/ts}</a>
188 {/if}
189 </td>
190 </tr>
191 {/if}
192
193 {if !$contributionMode}
194 {* Cancellation / Refunded fields are hidden unless contribution status is set to Cancelled or Refunded*}
195 <tr id="cancelInfo" class="crm-contribution-form-block-cancelInfo">
196 <td>&nbsp;</td>
197 <td><fieldset><legend>{ts}Cancellation or Refund Information{/ts}</legend>
198 <table class="form-layout-compressed">
199 <tr id="cancelDate" class="crm-contribution-form-block-cancel_date">
200 <td class="label">{$form.cancel_date.label}</td>
201 <td>
202 {if $hideCalendar neq true}
203 {include file="CRM/common/jcalendar.tpl" elementName=cancel_date}
204 {else}
205 {$form.cancel_date.value|crmDate}
206 {/if}
207 </td>
208 </tr>
209 <tr id="cancelDescription" class="crm-contribution-form-block-cancel_reason">
210 <td class="label">&nbsp;</td>
211 <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>
212 </tr>
213 <tr id="cancelReason">
214 <td class="label" style="vertical-align: top;">{$form.cancel_reason.label}</td>
215 <td>{$form.cancel_reason.html}</td>
216 </tr>
217 <tr id="refundTrxnID">
218 <td class="label" style="vertical-align: top;">{$form.refund_trxn_id.label}</td>
219 <td>{$form.refund_trxn_id.html}</td>
220 </tr>
221 </table>
222 </fieldset>
223 </td>
224 </tr>
225 {/if}
226 {if $form.revenue_recognition_date && !$payNow}
227 <tr class="crm-contribution-form-block-revenue_recognition_date">
228 <td class="label">{$form.revenue_recognition_date.label}</td>
229 <td>{$form.revenue_recognition_date.html}</td>
230 </tr>
231 {/if}
232 </table>
233
234 {include file='CRM/Core/BillingBlockWrapper.tpl'}
235
236 <!-- start of soft credit -->
237 {if !$payNow}
238 <div class="crm-accordion-wrapper crm-accordion_title-accordion crm-accordion-processed {if $noSoftCredit}collapsed{/if}" id="softCredit">
239 <div class="crm-accordion-header">
240 {ts}Soft Credit{/ts}&nbsp;{help id="id-soft_credit"}
241 </div>
242 <div class="crm-accordion-body">
243 <table class="form-layout-compressed">
244 <tr class="crm-contribution-form-block-soft_credit_to">
245 <td colspan="2">
246 {include file="CRM/Contribute/Form/SoftCredit.tpl"}
247 </td>
248 </tr>
249 </table>
250 </div>
251 </div>
252 {/if}
253 <!-- end of soft credit -->
254
255 <!-- start of PCP -->
256 {if $siteHasPCPs && !$payNow}
257 <div class="crm-accordion-wrapper crm-accordion_title-accordion crm-accordion-processed {if $noPCP}collapsed{/if}" id="softCredit">
258 <div class="crm-accordion-header">
259 {ts}Personal Campaign Page{/ts}&nbsp;{help id="id-pcp"}
260 </div>
261 <div class="crm-accordion-body">
262 <table class="form-layout-compressed">
263 <tr class="crm-contribution-pcp-block crm-contribution-form-block-pcp_made_through_id">
264 <td class="label">{$form.pcp_made_through_id.label}</td>
265 <td>
266 {$form.pcp_made_through_id.html} &nbsp;
267 <div class="description">{ts}Search for the Personal Campaign Page by the fund-raiser's last name or email address.{/ts}</div>
268
269 <div class="spacer"></div>
270 <div class="crm-contribution-form-block-pcp_details">
271 <table class="crm-contribution-form-table-credit_to_pcp">
272 <tr id="pcpDisplayRollID" class="crm-contribution-form-block-pcp_display_in_roll">
273 <td class="label">{$form.pcp_display_in_roll.label}</td>
274 <td>{$form.pcp_display_in_roll.html}</td>
275 </tr>
276 <tr id="nickID" class="crm-contribution-form-block-pcp_roll_nickname">
277 <td class="label">{$form.pcp_roll_nickname.label}</td>
278 <td>{$form.pcp_roll_nickname.html|crmAddClass:big}<br/>
279 <div class="description">{ts}Name or nickname contributor wants to be displayed in the Honor Roll. Enter "Anonymous" for anonymous contributions.{/ts}</div>
280 </td>
281 </tr>
282 <tr id="personalNoteID" class="crm-contribution-form-block-pcp_personal_note">
283 <td class="label" style="vertical-align: top">{$form.pcp_personal_note.label}</td>
284 <td>
285 {$form.pcp_personal_note.html}
286 <div
287 class="description">{ts}Personal message submitted by contributor for display in the Honor Roll.{/ts}</div>
288 </td>
289 </tr>
290 </table>
291 </div>
292 </td>
293 </tr>
294 </table>
295 </div>
296 </div>
297 {include file="CRM/Contribute/Form/PCP.js.tpl"}
298 {/if}
299 <!-- end of PCP -->
300
301 {if !$contributionMode}
302 <div class="crm-accordion-wrapper crm-accordion_title-accordion crm-accordion-processed" id="paymentDetails_Information">
303 <div class="crm-accordion-header">
304 {ts}Payment Details{/ts}
305 </div>
306 <div class="crm-accordion-body">
307 <table class="form-layout-compressed" >
308 <tr class="crm-contribution-form-block-receive_date">
309 <td class="label">{$form.receive_date.label}</td>
310 <td {$valueStyle}>{include file="CRM/common/jcalendar.tpl" elementName=receive_date}<br />
311 <span class="description">{ts}The date this contribution was received.{/ts}</span>
312 </td>
313 </tr>
314 <tr class="crm-contribution-form-block-payment_instrument_id">
315 <td class="label">{$form.payment_instrument_id.label}</td>
316 <td {$valueStyle}>{$form.payment_instrument_id.html} {help id="payment_instrument_id"}</td>
317 </td>
318 </tr>
319 {if $showCheckNumber || !$isOnline}
320 <tr id="checkNumber" class="crm-contribution-form-block-check_number">
321 <td class="label">{$form.check_number.label}</td>
322 <td>{$form.check_number.html}</td>
323 </tr>
324 {/if}
325 <tr class="crm-contribution-form-block-trxn_id">
326 <td class="label">{$form.trxn_id.label}</td>
327 <td {$valueStyle}>{$form.trxn_id.html} {help id="id-trans_id"}</td>
328 </tr>
329 {if $email and $outBound_option != 2}
330 <tr class="crm-contribution-form-block-is_email_receipt">
331 <td class="label">
332 {$form.is_email_receipt.label}</td><td>{$form.is_email_receipt.html}&nbsp;
333 <span class="description">{ts 1=$email}Automatically email a receipt for this payment to %1?{/ts}</span>
334 </td>
335 </tr>
336 {elseif $context eq 'standalone' and $outBound_option != 2 }
337 <tr id="email-receipt" style="display:none;" class="crm-contribution-form-block-is_email_receipt">
338 <td class="label">{$form.is_email_receipt.label}</td>
339 <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>
340 </td>
341 </tr>
342 {/if}
343 <tr id="receiptDate" class="crm-contribution-form-block-receipt_date">
344 <td class="label">{$form.receipt_date.label}</td>
345 <td>{include file="CRM/common/jcalendar.tpl" elementName=receipt_date}<br />
346 <span class="description">{ts}Date that a receipt was sent to the contributor.{/ts}</span>
347 </td>
348 </tr>
349 <tr id="fromEmail" class="crm-contribution-form-block-receipt_date" style="display:none;">
350 <td class="label">{$form.from_email_address.label}</td>
351 <td>{$form.from_email_address.html}</td>
352 </tr>
353 </table>
354 </div>
355 </div>
356 {/if}
357
358 {if !$payNow}
359 <div id="customData" class="crm-contribution-form-block-customData"></div>
360 {/if}
361
362 {*include custom data js file*}
363 {include file="CRM/common/customData.tpl"}
364
365 {literal}
366 <script type="text/javascript">
367 CRM.$(function($) {
368 {/literal}
369 CRM.buildCustomData( '{$customDataType}' );
370 {if $customDataSubType}
371 CRM.buildCustomData( '{$customDataType}', {$customDataSubType} );
372 {/if}
373
374 {if $buildPriceSet}{literal}buildAmount( );{/literal}{/if}
375 {literal}
376 });
377
378 // bind first click of accordion header to load crm-accordion-body with snippet
379 // everything else taken care of by cj().crm-accordions()
380 CRM.$(function($) {
381 cj('#adjust-option-type').hide();
382 cj('.crm-ajax-accordion .crm-accordion-header').one('click', function() {
383 loadPanes(cj(this).attr('id'));
384 });
385 cj('.crm-ajax-accordion:not(.collapsed) .crm-accordion-header').each(function(index) {
386 loadPanes(cj(this).attr('id'));
387 });
388 });
389 // load panes function calls for snippet based on id of crm-accordion-header
390 function loadPanes( id ) {
391 var url = "{/literal}{crmURL p='civicrm/contact/view/contribution' q='snippet=4&formType=' h=0}{literal}" + id;
392 {/literal}
393 {if $contributionMode}
394 url = url + "&mode={$contributionMode}";
395 {/if}
396 {if $qfKey}
397 url = url + "&qfKey={$qfKey}";
398 {/if}
399 {literal}
400 if (! cj('div.'+id).html()) {
401 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}...';
402 cj('div.'+id).html(loading);
403 cj.ajax({
404 url : url,
405 success: function(data) { cj('div.'+id).html(data).trigger('crmLoad'); }
406 });
407 }
408 }
409
410 var url = "{/literal}{$dataUrl}{literal}";
411
412 {/literal}
413 {if $context eq 'standalone' and $outBound_option != 2 }
414 {literal}
415 CRM.$(function($) {
416
417 var $form = $("form.{/literal}{$form.formClass}{literal}");
418 $("#contact_id", $form).change(checkEmail);
419 checkEmail( );
420
421 function checkEmail( ) {
422 var data = $("#contact_id", $form).select2('data');
423 if (data && data.extra && data.extra.email && data.extra.email.length) {
424 $("#email-receipt", $form).show();
425 $("#email-address", $form).html(data.extra.email);
426 }
427 else {
428 $("#email-receipt", $form).hide();
429 }
430 }
431
432 showHideByValue( 'is_email_receipt', '', 'receiptDate', 'table-row', 'radio', true);
433 showHideByValue( 'is_email_receipt', '', 'fromEmail', 'table-row', 'radio', false );
434 });
435
436 {/literal}
437 {/if}
438 </script>
439
440 <div class="accordion ui-accordion ui-widget ui-helper-reset">
441 {* Additional Detail / Honoree Information / Premium Information *}
442 {foreach from=$allPanes key=paneName item=paneValue}
443
444 <div class="crm-accordion-wrapper crm-ajax-accordion crm-{$paneValue.id}-accordion {if $paneValue.open neq 'true'}collapsed{/if}">
445 <div class="crm-accordion-header" id="{$paneValue.id}">
446
447 {$paneName}
448 </div><!-- /.crm-accordion-header -->
449 <div class="crm-accordion-body">
450
451 <div class="{$paneValue.id}"></div>
452 </div><!-- /.crm-accordion-body -->
453 </div><!-- /.crm-accordion-wrapper -->
454
455 {/foreach}
456 </div>
457
458 {/if}
459 <br />
460 <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
461 </div>
462
463 {literal}
464 <script type="text/javascript">
465 function verify( ) {
466 if (cj('#is_email_receipt').prop('checked' )) {
467 var ok = confirm( '{/literal}{ts escape='js'}Click OK to save this contribution record AND send a receipt to the contributor now{/ts}{literal}.' );
468 if (!ok) {
469 return false;
470 }
471 }
472 }
473 </script>
474 {/literal}
475
476 {if $action neq 8}
477 {literal}
478 <script type="text/javascript">
479 CRM.$(function($) {
480 checkEmailDependancies( );
481 cj('#is_email_receipt').click( function( ) {
482 checkEmailDependancies( );
483 });
484 });
485
486 function checkEmailDependancies( ) {
487 if (cj('#is_email_receipt').prop('checked' )) {
488 cj('#fromEmail').show( );
489 cj('#receiptDate').hide( );
490 }
491 else {
492 cj('#fromEmail').hide( );
493 cj('#receiptDate').show( );
494 }
495 }
496
497 {/literal}{if !$contributionMode}{literal}
498 CRM.$(function($) {
499 showHideCancelInfo($('#contribution_status_id'));
500
501 $('#contribution_status_id').change(function() {
502 showHideCancelInfo($('#contribution_status_id'));
503 });
504
505 function showHideCancelInfo(obj) {
506 var cancelInfo_show_ids = [{/literal}{$cancelInfo_show_ids}{literal}];
507 if (cancelInfo_show_ids.indexOf(obj.val()) > -1) {
508 $('#cancelInfo').show( );
509 $('#total_amount').attr('readonly', true);
510 }
511 else {
512 $("#cancel_date").val('');
513 $("#cancel_reason").val('');
514 $('#cancelInfo').hide( );
515 $("#total_amount").removeAttr('readonly');
516 }
517 }
518 });
519
520 {/literal}{/if}{literal}
521 </script>
522 {/literal}
523 {if !$contributionMode}
524 {include file="CRM/common/showHideByFieldValue.tpl"
525 trigger_field_id ="payment_instrument_id"
526 trigger_value = '4'
527 target_element_id ="checkNumber"
528 target_element_type ="table-row"
529 field_type ="select"
530 invert = 0
531 }
532 {/if}
533 {/if} {* not delete mode if*}
534
535 {/if} {* closing of main custom data if *}
536
537 {literal}
538 <script type="text/javascript">
539
540 {/literal}
541
542 // load form during form rule.
543 {if $buildPriceSet}{literal}buildAmount( );{/literal}{/if}
544
545 {literal}
546
547 // CRM-16451: set financial type of 'Price Set' in back office contribution
548 // instead of selecting manually
549 function buildAmount( priceSetId, financialtypeIds ) {
550 if (!priceSetId) priceSetId = cj("#price_set_id").val( );
551 var fname = '#priceset';
552 if (!priceSetId) {
553 // hide price set fields.
554 cj(fname).hide( );
555
556 // show/hide price set amount and total amount.
557 cj("#totalAmountORPriceSet").show( );
558 cj("#totalAmount").show( );
559 var choose = "{/literal}{ts}Choose price set{/ts}{literal}";
560 cj("#price_set_id option[value='']").html( choose );
561
562 cj('label[for="total_amount"]').text('{/literal}{ts}Total Amount{/ts}{literal}');
563 cj(".crm-contribution-form-block-financial_type_id").show();
564 cj("#financial_type_id option[value='']").attr('selected', true);
565
566 //we might want to build recur block.
567 if (cj("#is_recur")) buildRecurBlock( null );
568 return;
569 }
570
571 //don't allow recurring w/ priceset.
572 if ( cj( "#is_recur" ) && cj( 'input:radio[name="is_recur"]:checked').val( ) ) {
573 //reset the values of recur block.
574 cj("#installments").val('');
575 cj("#frequency_interval").val('');
576 cj('input:radio[name="is_recur"]')[0].checked = true;
577 cj("#recurringPaymentBlock").hide( );
578 }
579
580 var dataUrl = {/literal}"{crmURL h=0 q='snippet=4'}"{literal} + '&priceSetId=' + priceSetId;
581
582 var response = cj.ajax({
583 url: dataUrl,
584 async: false
585 }).responseText;
586
587 cj( fname ).show( ).html( response ).trigger('crmLoad');
588 // freeze total amount text field.
589 cj( "#total_amount").val('');
590
591 cj( "#totalAmountORPriceSet" ).hide( );
592 cj( "#totalAmount").hide( );
593 var manual = "{/literal}{ts}Manual contribution amount{/ts}{literal}";
594 cj("#price_set_id option[value='']").html( manual );
595
596 cj('label[for="total_amount"]').text('{/literal}{ts}Price Sets{/ts}{literal}');
597 cj("#financial_type_id option[value="+financialtypeIds[priceSetId]+"]").prop('selected', true);
598 cj(".crm-contribution-form-block-financial_type_id").css("display", "none");
599 }
600
601 function adjustPayment( ) {
602 cj('#adjust-option-type').show();
603 cj("#total_amount").removeAttr("READONLY");
604 cj("#total_amount").css('background-color', '#ffffff');
605 }
606
607 {/literal}{if $processorSupportsFutureStartDate}{literal}
608 cj ('input:radio[name="is_recur"]').click( function( ) {
609 showStartDate( );
610 });
611
612 showStartDate( );
613
614 function showStartDate( ) {
615 if (cj( 'input:radio[name="is_recur"]:checked').val( ) == 0 ) {
616 cj('#start_date').hide( );
617 }
618 else {
619 cj('#start_date').show( );
620 }
621 }
622
623 {/literal}{/if}{literal}
624 var thousandMarker = "{/literal}{$config->monetaryThousandSeparator}{literal}";
625 var separator = "{/literal}{$config->monetaryDecimalPoint}{literal}";
626
627 cj('#fee_amount').change( function() {
628 var totalAmount = cj('#total_amount').val().replace(thousandMarker,'').replace(separator,'.');
629 var feeAmount = cj('#fee_amount').val().replace(thousandMarker,'').replace(separator,'.');
630 var netAmount = totalAmount - feeAmount;
631 if (totalAmount) {
632 cj('#net_amount').val(CRM.formatMoney(netAmount, true));
633 }
634 });
635
636 cj("#financial_type_id").on("change",function(){
637 cj('#total_amount').trigger("change");
638 })
639
640 cj("#currency").on("change",function(){
641 cj('#total_amount').trigger("change");
642 })
643
644 {/literal}{if $taxRates && $invoicing}{literal}
645 CRM.$(function($) {
646 $('#total_amount').on("change",function(event) {
647 if (event.handled !== true) {
648 var freezeFinancialType = '{/literal}{$freezeFinancialType}{literal}';
649 if (!freezeFinancialType) {
650 var financialType = $('#financial_type_id').val();
651 var taxRates = '{/literal}{$taxRates}{literal}';
652 taxRates = JSON.parse(taxRates);
653 var currencies = '{/literal}{$currencies}{literal}';
654 currencies = JSON.parse(currencies);
655 var currencySelect = $('#currency').val();
656 var currencySymbol = currencies[currencySelect];
657 var re= /\((.*?)\)/g;
658 for(m = re.exec(currencySymbol); m; m = re.exec(currencySymbol)){
659 currencySymbol = m[1];
660 }
661 var taxRate = taxRates[financialType];
662 if (!taxRate) {
663 taxRate = 0;
664 cj("#totalTaxAmount").hide( );
665 } else {
666 cj("#totalTaxAmount").show( );
667 }
668 var totalAmount = $('#total_amount').val();
669 // replace all thousandMarker and change the separator to a dot
670 totalAmount = totalAmount.replace(thousandMarker,'').replace(separator,'.');
671
672 var totalTaxAmount = '{/literal}{$totalTaxAmount}{literal}';
673 var taxAmount = (taxRate/100)*totalAmount;
674 taxAmount = isNaN (taxAmount) ? 0:taxAmount;
675 var totalTaxAmount = taxAmount + Number(totalAmount);
676 totalTaxAmount = formatMoney( totalTaxAmount, 2, separator, thousandMarker );
677
678 $("#totalTaxAmount" ).html('Amount with tax : <span id="currencySymbolShow">' + currencySymbol + '</span> '+ totalTaxAmount);
679 }
680 event.handled = true;
681 }
682 return false;
683 });
684
685 $('#total_amount').trigger("change");
686 });
687 {/literal}{/if}{literal}
688
689 CRM.$(function($) {
690 $('#price_set_id').click(function() {
691 if( $('#price_set_id').val() ) {
692 $('#totalAmountBlock').hide();
693 }
694 else {
695 $('#totalAmountBlock').show();
696 }
697 });
698 });
699
700 function formatMoney (amount, c, d, t){
701 var n = amount,
702 c = isNaN(c = Math.abs(c)) ? 2 : c,
703 d = d == undefined ? "," : d,
704 t = t == undefined ? "." : t, s = n < 0 ? "-" : "",
705 i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "",
706 j = (j = i.length) > 3 ? j % 3 : 0;
707 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) : "");
708 };
709 </script>
710 {/literal}