CRM-20889: Toggle check_number field on backoffice form as payment form fields
[civicrm-core.git] / templates / CRM / Contribute / Form / Contribution.tpl
CommitLineData
6a488035
TO
1{*
2 +--------------------------------------------------------------------+
2c4c49ca 3 | CiviCRM version 4.7 |
6a488035 4 +--------------------------------------------------------------------+
2a73d3b0 5 | Copyright CiviCRM LLC (c) 2004-2017 |
6a488035
TO
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
39082712 28{if $priceSetId}
6a488035
TO
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}
b58b2053 33 {include file="CRM/Contribute/Form/AdditionalInfo/Payment.tpl"}
6a488035
TO
34 <div class="crm-block crm-form-block crm-contribution-form-block">
35
6a488035
TO
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}
f6eedce7 42 <div class="help">
c1642a52 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}
6a488035 49 {else}
33af228e 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}
6a488035
TO
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}
6a488035 60 {if $newCredit AND $action EQ 1 AND $contributionMode EQ null}
540ea9be 61 <div class="action-link css_right crm-link-credit-card-mode">
6a488035
TO
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}
5fffbbe4 67 <a class="open-inline-noreturn action-item crm-hover-button" href="{$ccModeLink}">&raquo; {ts}submit credit card contribution{/ts}</a>
540ea9be 68 </div>
6a488035 69 {/if}
540ea9be
CW
70 <div class="crm-submit-buttons">
71 {include file="CRM/common/formButtons.tpl"}
6a488035
TO
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}
ccec9d6b
CW
80 <td class="label">{$form.contact_id.label}</td>
81 <td>{$form.contact_id.html}</td>
6a488035 82 {/if}
6a488035
TO
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>
17d83f50 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}
6a488035 106
73a5902f 107 {if $ppID}{ts}<a class='action-item crm-hover-button' onclick='adjustPayment();'>adjust payment amount</a>{/ts}{help id="adjust-payment-amount"}{/if}
17d83f50 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}
6a488035
TO
113 </td>
114 </tr>
115
17d83f50 116 {if $buildRecurBlock && !$payNow}
6a488035
TO
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
17d83f50 157 {if !$contributionMode || $payNow}
6a488035
TO
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>
b9a90a9c 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}
c6218cbd 166 <a class="open-inline action-item crm-hover-button" href="{$payNowLink}">&raquo; {ts}Pay with Credit Card{/ts}</a>
b9a90a9c 167 {/if}
168 </td>
6a488035 169 </tr>
29cb4724 170 {/if}
6a488035 171
29cb4724 172 {if !$contributionMode}
6a488035
TO
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}
d32858b8 184 {$form.cancel_date.value|crmDate}
6a488035
TO
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>
ce22fda6 194 <td>{$form.cancel_reason.html}</td>
6a488035 195 </tr>
99cdd94d 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>
6a488035
TO
200 </table>
201 </fieldset>
202 </td>
203 </tr>
b3f1d256 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>
6a488035 210 {/if}
17d83f50 211 {if $form.revenue_recognition_date && !$payNow}
46d173ef
PN
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}
af11a25a 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>
9580e4a2 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}
6a488035 245 </table>
a5399a39 246
950d9669 247 {if !$contributionMode}
a55e39e9 248 <fieldset class="payment-details_group">
249 <legend>
250 {ts}Payment Details{/ts}
251 </legend>
950d9669 252 <table class="form-layout-compressed" >
950d9669 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>
950d9669 258 <tr class="crm-contribution-form-block-trxn_id">
259 <td class="label">{$form.trxn_id.label}</td>
260 <td {$valueStyle}>{$form.trxn_id.html} {help id="id-trans_id"}</td>
261 </tr>
950d9669 262 </table>
a55e39e9 263 </fieldset>
950d9669 264 {/if}
265
52912b1f 266 {include file='CRM/Core/BillingBlockWrapper.tpl'}
a5399a39 267
96cfe0d7 268 <!-- start of soft credit -->
b9a90a9c 269 {if !$payNow}
270 <div class="crm-accordion-wrapper crm-accordion_title-accordion crm-accordion-processed {if $noSoftCredit}collapsed{/if}" id="softCredit">
271 <div class="crm-accordion-header">
272 {ts}Soft Credit{/ts}&nbsp;{help id="id-soft_credit"}
273 </div>
274 <div class="crm-accordion-body">
275 <table class="form-layout-compressed">
276 <tr class="crm-contribution-form-block-soft_credit_to">
277 <td colspan="2">
278 {include file="CRM/Contribute/Form/SoftCredit.tpl"}
279 </td>
280 </tr>
281 </table>
282 </div>
b6545333 283 </div>
b9a90a9c 284 {/if}
b6545333 285 <!-- end of soft credit -->
286
287 <!-- start of PCP -->
b9a90a9c 288 {if $siteHasPCPs && !$payNow}
00a1afe2 289 <div class="crm-accordion-wrapper crm-accordion_title-accordion crm-accordion-processed {if $noPCP}collapsed{/if}" id="softCredit">
b6545333 290 <div class="crm-accordion-header">
291 {ts}Personal Campaign Page{/ts}&nbsp;{help id="id-pcp"}
292 </div>
293 <div class="crm-accordion-body">
294 <table class="form-layout-compressed">
295 <tr class="crm-contribution-pcp-block crm-contribution-form-block-pcp_made_through_id">
6bb107ce 296 <td class="label">{$form.pcp_made_through_id.label}</td>
96cfe0d7 297 <td>
6bb107ce 298 {$form.pcp_made_through_id.html} &nbsp;
d4abe802 299 <div class="description">{ts}Search for the Personal Campaign Page by the fund-raiser's last name or email address.{/ts}</div>
96cfe0d7 300
301 <div class="spacer"></div>
b6545333 302 <div class="crm-contribution-form-block-pcp_details">
96cfe0d7 303 <table class="crm-contribution-form-table-credit_to_pcp">
304 <tr id="pcpDisplayRollID" class="crm-contribution-form-block-pcp_display_in_roll">
305 <td class="label">{$form.pcp_display_in_roll.label}</td>
306 <td>{$form.pcp_display_in_roll.html}</td>
307 </tr>
308 <tr id="nickID" class="crm-contribution-form-block-pcp_roll_nickname">
309 <td class="label">{$form.pcp_roll_nickname.label}</td>
310 <td>{$form.pcp_roll_nickname.html|crmAddClass:big}<br/>
d4abe802 311 <div class="description">{ts}Name or nickname contributor wants to be displayed in the Honor Roll. Enter "Anonymous" for anonymous contributions.{/ts}</div>
96cfe0d7 312 </td>
313 </tr>
314 <tr id="personalNoteID" class="crm-contribution-form-block-pcp_personal_note">
315 <td class="label" style="vertical-align: top">{$form.pcp_personal_note.label}</td>
316 <td>
317 {$form.pcp_personal_note.html}
d4abe802
CW
318 <div
319 class="description">{ts}Personal message submitted by contributor for display in the Honor Roll.{/ts}</div>
96cfe0d7 320 </td>
321 </tr>
322 </table>
323 </div>
324 </td>
325 </tr>
b6545333 326 </table>
327 </div>
96cfe0d7 328 </div>
d4abe802 329 {include file="CRM/Contribute/Form/PCP.js.tpl"}
b6545333 330 {/if}
331 <!-- end of PCP -->
332
b9a90a9c 333 {if !$payNow}
334 <div id="customData" class="crm-contribution-form-block-customData"></div>
335 {/if}
6a488035
TO
336
337 {*include custom data js file*}
338 {include file="CRM/common/customData.tpl"}
339
340 {literal}
341 <script type="text/javascript">
3cc60a06 342 CRM.$(function($) {
6a488035
TO
343 {/literal}
344 CRM.buildCustomData( '{$customDataType}' );
345 {if $customDataSubType}
346 CRM.buildCustomData( '{$customDataType}', {$customDataSubType} );
347 {/if}
291f6bec 348
96cfe0d7 349 {if $buildPriceSet}{literal}buildAmount( );{/literal}{/if}
6a488035
TO
350 {literal}
351 });
352
353 // bind first click of accordion header to load crm-accordion-body with snippet
354 // everything else taken care of by cj().crm-accordions()
3cc60a06 355 CRM.$(function($) {
6a488035
TO
356 cj('#adjust-option-type').hide();
357 cj('.crm-ajax-accordion .crm-accordion-header').one('click', function() {
358 loadPanes(cj(this).attr('id'));
359 });
360 cj('.crm-ajax-accordion:not(.collapsed) .crm-accordion-header').each(function(index) {
361 loadPanes(cj(this).attr('id'));
362 });
363 });
364 // load panes function calls for snippet based on id of crm-accordion-header
365 function loadPanes( id ) {
366 var url = "{/literal}{crmURL p='civicrm/contact/view/contribution' q='snippet=4&formType=' h=0}{literal}" + id;
367 {/literal}
368 {if $contributionMode}
369 url = url + "&mode={$contributionMode}";
370 {/if}
371 {if $qfKey}
372 url = url + "&qfKey={$qfKey}";
373 {/if}
374 {literal}
375 if (! cj('div.'+id).html()) {
376 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}...';
377 cj('div.'+id).html(loading);
378 cj.ajax({
379 url : url,
b22f0cad 380 success: function(data) { cj('div.'+id).html(data).trigger('crmLoad'); }
6a488035
TO
381 });
382 }
383 }
384
385 var url = "{/literal}{$dataUrl}{literal}";
386
6a488035
TO
387 {/literal}
388 {if $context eq 'standalone' and $outBound_option != 2 }
389 {literal}
3cc60a06 390 CRM.$(function($) {
ae8f569f 391
b50fdacc 392 var $form = $("form.{/literal}{$form.formClass}{literal}");
ae8f569f 393 $("#contact_id", $form).change(checkEmail);
6a488035 394 checkEmail( );
ae8f569f
CW
395
396 function checkEmail( ) {
397 var data = $("#contact_id", $form).select2('data');
398 if (data && data.extra && data.extra.email && data.extra.email.length) {
399 $("#email-receipt", $form).show();
400 $("#email-address", $form).html(data.extra.email);
401 }
402 else {
403 $("#email-receipt", $form).hide();
404 }
405 }
406
6a488035
TO
407 showHideByValue( 'is_email_receipt', '', 'receiptDate', 'table-row', 'radio', true);
408 showHideByValue( 'is_email_receipt', '', 'fromEmail', 'table-row', 'radio', false );
409 });
410
6a488035
TO
411 {/literal}
412 {/if}
413 </script>
414
415 <div class="accordion ui-accordion ui-widget ui-helper-reset">
416 {* Additional Detail / Honoree Information / Premium Information *}
417 {foreach from=$allPanes key=paneName item=paneValue}
418
419 <div class="crm-accordion-wrapper crm-ajax-accordion crm-{$paneValue.id}-accordion {if $paneValue.open neq 'true'}collapsed{/if}">
420 <div class="crm-accordion-header" id="{$paneValue.id}">
421
422 {$paneName}
423 </div><!-- /.crm-accordion-header -->
424 <div class="crm-accordion-body">
425
426 <div class="{$paneValue.id}"></div>
427 </div><!-- /.crm-accordion-body -->
428 </div><!-- /.crm-accordion-wrapper -->
429
430 {/foreach}
431 </div>
432
433 {/if}
434<br />
435<div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
436</div>
437
438 {literal}
439 <script type="text/javascript">
440 function verify( ) {
8539f25d 441 if (cj('#is_email_receipt').prop('checked' )) {
6a488035
TO
442 var ok = confirm( '{/literal}{ts escape='js'}Click OK to save this contribution record AND send a receipt to the contributor now{/ts}{literal}.' );
443 if (!ok) {
444 return false;
445 }
446 }
447 }
6a488035
TO
448 </script>
449 {/literal}
450
451 {if $action neq 8}
452 {literal}
453 <script type="text/javascript">
3cc60a06 454 CRM.$(function($) {
27439cc1
CW
455 var $form = $('form.{/literal}{$form.formClass}{literal}');
456 checkEmailDependancies();
457 $('#is_email_receipt', $form).click(function() {
458 checkEmailDependancies();
6a488035 459 });
950d9669 460
27439cc1
CW
461 function checkEmailDependancies( ) {
462 if ($('#is_email_receipt', $form).prop('checked')) {
463 $('#fromEmail', $form).show();
464 $('#receiptDate', $form).hide();
465 }
466 else {
467 $('#fromEmail', $form).hide();
468 $('#receiptDate', $form).show();
469 }
6a488035 470 }
0de07a13 471 {/literal}{if !$contributionMode}{literal}
472 showHideCancelInfo($('#contribution_status_id', $form));
950d9669 473
0de07a13 474 $('#contribution_status_id', $form).change(function() {
475 showHideCancelInfo($('#contribution_status_id', $form));
476 });
950d9669 477
0de07a13 478 function showHideCancelInfo(obj) {
479 var cancelInfo_show_ids = [{/literal}{$cancelInfo_show_ids}{literal}];
480 if (cancelInfo_show_ids.indexOf(obj.val()) > -1) {
481 $('#cancelInfo', $form).show();
482 $('#total_amount', $form).attr('readonly', true);
483 }
484 else {
485 $("#cancel_date", $form).val('');
486 $("#cancel_reason", $form).val('');
487 $('#cancelInfo', $form).hide();
488 $("#total_amount", $form).removeAttr('readonly');
489 }
27439cc1 490 }
0de07a13 491 {/literal}{/if}
4a3ed839 492 });
96cfe0d7 493 </script>
6a488035
TO
494 {/if} {* not delete mode if*}
495
6a488035
TO
496{/if} {* closing of main custom data if *}
497
498{literal}
499<script type="text/javascript">
6a488035
TO
500
501{/literal}
502
503// load form during form rule.
504{if $buildPriceSet}{literal}buildAmount( );{/literal}{/if}
505
6a488035 506{literal}
6a488035 507
6a3d8d2d
WA
508// CRM-16451: set financial type of 'Price Set' in back office contribution
509// instead of selecting manually
510function buildAmount( priceSetId, financialtypeIds ) {
511 if (!priceSetId) priceSetId = cj("#price_set_id").val( );
6a488035
TO
512 var fname = '#priceset';
513 if (!priceSetId) {
514 // hide price set fields.
515 cj(fname).hide( );
516
517 // show/hide price set amount and total amount.
518 cj("#totalAmountORPriceSet").show( );
519 cj("#totalAmount").show( );
d65f6a99
AH
520 var choose = "{/literal}{ts}Choose price set{/ts}{literal}";
521 cj("#price_set_id option[value='']").html( choose );
6a488035 522
6a3d8d2d
WA
523 cj('label[for="total_amount"]').text('{/literal}{ts}Total Amount{/ts}{literal}');
524 cj(".crm-contribution-form-block-financial_type_id").show();
525 cj("#financial_type_id option[value='']").attr('selected', true);
526
6a488035
TO
527 //we might want to build recur block.
528 if (cj("#is_recur")) buildRecurBlock( null );
529 return;
530 }
531
532 //don't allow recurring w/ priceset.
533 if ( cj( "#is_recur" ) && cj( 'input:radio[name="is_recur"]:checked').val( ) ) {
534 //reset the values of recur block.
535 cj("#installments").val('');
536 cj("#frequency_interval").val('');
537 cj('input:radio[name="is_recur"]')[0].checked = true;
538 cj("#recurringPaymentBlock").hide( );
539 }
540
541 var dataUrl = {/literal}"{crmURL h=0 q='snippet=4'}"{literal} + '&priceSetId=' + priceSetId;
542
543 var response = cj.ajax({
544 url: dataUrl,
545 async: false
546 }).responseText;
547
b22f0cad 548 cj( fname ).show( ).html( response ).trigger('crmLoad');
6a488035
TO
549 // freeze total amount text field.
550 cj( "#total_amount").val('');
551
552 cj( "#totalAmountORPriceSet" ).hide( );
553 cj( "#totalAmount").hide( );
d65f6a99
AH
554 var manual = "{/literal}{ts}Manual contribution amount{/ts}{literal}";
555 cj("#price_set_id option[value='']").html( manual );
6a3d8d2d
WA
556
557 cj('label[for="total_amount"]').text('{/literal}{ts}Price Sets{/ts}{literal}');
8860e13b
PN
558 if (financialtypeIds) {
559 cj("#financial_type_id option[value="+financialtypeIds[priceSetId]+"]").prop('selected', true);
560 }
6a3d8d2d 561 cj(".crm-contribution-form-block-financial_type_id").css("display", "none");
6a488035
TO
562}
563
564function adjustPayment( ) {
565 cj('#adjust-option-type').show();
566 cj("#total_amount").removeAttr("READONLY");
567 cj("#total_amount").css('background-color', '#ffffff');
568}
569
570{/literal}{if $processorSupportsFutureStartDate}{literal}
571cj ('input:radio[name="is_recur"]').click( function( ) {
572 showStartDate( );
573});
574
575showStartDate( );
576
577function showStartDate( ) {
578 if (cj( 'input:radio[name="is_recur"]:checked').val( ) == 0 ) {
579 cj('#start_date').hide( );
580 }
581 else {
582 cj('#start_date').show( );
583 }
584}
585
586{/literal}{/if}{literal}
01096c1b 587var thousandMarker = "{/literal}{$config->monetaryThousandSeparator}{literal}";
588var separator = "{/literal}{$config->monetaryDecimalPoint}{literal}";
589
6a488035 590cj('#fee_amount').change( function() {
01096c1b 591 var totalAmount = cj('#total_amount').val().replace(thousandMarker,'').replace(separator,'.');
592 var feeAmount = cj('#fee_amount').val().replace(thousandMarker,'').replace(separator,'.');
593 var netAmount = totalAmount - feeAmount;
594 if (totalAmount) {
a4f7ae9b 595 cj('#net_amount').val(CRM.formatMoney(netAmount, true));
6a488035
TO
596 }
597});
6daab7fa 598
599cj("#financial_type_id").on("change",function(){
600 cj('#total_amount').trigger("change");
601})
602
049db839 603cj("#currency").on("change",function(){
cce6ec9f 604 cj('#total_amount').trigger("change");
049db839 605})
606
95f2107c 607{/literal}{if $taxRates && $invoicing}{literal}
95f2107c 608CRM.$(function($) {
ebd51731
PB
609 $('#total_amount').on("change",function(event) {
610 if (event.handled !== true) {
b6f65362 611 var freezeFinancialType = '{/literal}{$freezeFinancialType}{literal}';
612 if (!freezeFinancialType) {
613 var financialType = $('#financial_type_id').val();
614 var taxRates = '{/literal}{$taxRates}{literal}';
615 taxRates = JSON.parse(taxRates);
616 var currencies = '{/literal}{$currencies}{literal}';
617 currencies = JSON.parse(currencies);
618 var currencySelect = $('#currency').val();
619 var currencySymbol = currencies[currencySelect];
620 var re= /\((.*?)\)/g;
621 for(m = re.exec(currencySymbol); m; m = re.exec(currencySymbol)){
622 currencySymbol = m[1];
623 }
7f7fa13a 624 var taxRate = taxRates[financialType];
b6f65362 625 if (!taxRate) {
626 taxRate = 0;
b5527a9a
DG
627 cj("#totalTaxAmount").hide( );
628 } else {
161a2fe7 629 cj("#totalTaxAmount").show( );
7f7fa13a 630 }
b6f65362 631 var totalAmount = $('#total_amount').val();
01096c1b 632 // replace all thousandMarker and change the separator to a dot
633 totalAmount = totalAmount.replace(thousandMarker,'').replace(separator,'.');
b6f65362 634
7f7fa13a
EM
635 var totalTaxAmount = '{/literal}{$totalTaxAmount}{literal}';
636 var taxAmount = (taxRate/100)*totalAmount;
637 taxAmount = isNaN (taxAmount) ? 0:taxAmount;
638 var totalTaxAmount = taxAmount + Number(totalAmount);
01096c1b 639 totalTaxAmount = formatMoney( totalTaxAmount, 2, separator, thousandMarker );
b6f65362 640
7f7fa13a 641 $("#totalTaxAmount" ).html('Amount with tax : <span id="currencySymbolShow">' + currencySymbol + '</span> '+ totalTaxAmount);
7b1ea4bd 642 }
ebd51731
PB
643 event.handled = true;
644 }
645 return false;
646 });
647
648 $('#total_amount').trigger("change");
95f2107c
PB
649});
650{/literal}{/if}{literal}
651
ebd51731
PB
652CRM.$(function($) {
653 $('#price_set_id').click(function() {
7f7fa13a 654 if( $('#price_set_id').val() ) {
ebd51731 655 $('#totalAmountBlock').hide();
95f2107c
PB
656 }
657 else {
ebd51731 658 $('#totalAmountBlock').show();
95f2107c
PB
659 }
660 });
661});
b6f65362 662
663function formatMoney (amount, c, d, t){
664 var n = amount,
665 c = isNaN(c = Math.abs(c)) ? 2 : c,
666 d = d == undefined ? "," : d,
667 t = t == undefined ? "." : t, s = n < 0 ? "-" : "",
668 i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "",
669 j = (j = i.length) > 3 ? j % 3 : 0;
670return 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) : "");
671};
6a488035
TO
672</script>
673{/literal}