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