Merge remote-tracking branch 'upstream/4.5' into 4.5-master-2014-10-14-11-24-52
[civicrm-core.git] / templates / CRM / Member / Form / Membership.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 memberships for a contact *}
27 {if $cancelAutoRenew}
28 <div class="messages status no-popup">
29 <div class="icon inform-icon"></div>
30 <p>{ts 1=$cancelAutoRenew}This membership is set to renew automatically {if $endDate}on {$endDate|crmDate}{/if}. You will need to cancel the auto-renew option if you want to modify the Membership Type, End Date or Membership Status. <a href="%1">Click here</a> if you want to cancel the automatic renewal option.{/ts}</p>
31 </div>
32 {/if}
33 <div class="spacer"></div>
34 {if $cdType }
35 {include file="CRM/Custom/Form/CustomData.tpl"}
36 {elseif $priceSetId}
37 {include file="CRM/Price/Form/PriceSet.tpl" context="standalone" extends="Membership"}
38 {literal}
39 <script type="text/javascript">
40 CRM.$(function($) {
41 var membershipValues = [];
42 {/literal}{foreach from=$optionsMembershipTypes item=memType key=opId}{literal}
43 membershipValues[{/literal}{$opId}{literal}] = {/literal}{$memType}{literal};
44 {/literal}{/foreach}{literal}
45 processMembershipPriceset(membershipValues, {/literal}{$autoRenewOption}{literal}, 1);
46 {/literal}{if !$membershipMode}{literal}
47 enableAmountSection({/literal}{$contributionType}{literal});
48 {/literal}{/if}{literal}
49 });
50 </script>
51 {/literal}
52 {else}
53 {if $membershipMode == 'test' }
54 {assign var=registerMode value="TEST"}
55 {elseif $membershipMode == 'live'}
56 {assign var=registerMode value="LIVE"}
57 {/if}
58 {if !$emailExists and $action neq 8 and $context neq 'standalone'}
59 <div class="messages status no-popup">
60 <div class="icon inform-icon"></div>
61 <p>{ts}You will not be able to send an automatic email receipt for this Membership because there is no email address recorded for this contact. If you want a receipt to be sent when this Membership is recorded, click Cancel and then click Edit from the Summary tab to add an email address before recording the Membership.{/ts}</p>
62 </div>
63 {/if}
64 {if $membershipMode}
65 <div id="help">
66 {ts 1=$displayName 2=$registerMode}Use this form to submit Membership Record on behalf of %1. <strong>A %2 transaction will be submitted</strong> using the selected payment processor.{/ts}
67 </div>
68 {/if}
69 <div class="crm-block crm-form-block crm-membership-form-block">
70 <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="top"}</div>
71 {if $action eq 8}
72 <div class="messages status no-popup">
73 <div class="icon inform-icon"></div>&nbsp;
74 <span class="font-red bold">{ts}WARNING: Deleting this membership will also delete any related payment (contribution) records.{/ts} {ts}This action cannot be undone.{/ts}</span>
75 <p>{ts}Consider modifying the membership status instead if you want to maintain an audit trail and avoid losing payment data. You can set the status to Cancelled by editing the membership and clicking the Status Override checkbox.{/ts}</p>
76 <p>{ts}Click 'Delete' if you want to continue.{/ts}</p>
77 </div>
78 {else}
79 <table class="form-layout-compressed">
80 {if $context neq 'standalone'}
81 <tr>
82 <td class="font-size12pt label"><strong>{ts}Member{/ts}</strong></td><td class="font-size12pt"><strong>{$displayName}</strong></td>
83 </tr>
84 {else}
85 <td class="label">{$form.contact_id.label}</td>
86 <td>{$form.contact_id.html}</td>
87 {/if}
88 {if $membershipMode}
89 <tr><td class="label">{$form.payment_processor_id.label}</td><td>{$form.payment_processor_id.html}</td></tr>
90 {/if}
91 <tr class="crm-membership-form-block-membership_type_id">
92 <td class="label">{$form.membership_type_id.label}</td>
93 <td><span id='mem_type_id'>{$form.membership_type_id.html}</span>
94 {if $hasPriceSets}
95 <span id='totalAmountORPriceSet'> {ts}OR{/ts}</span>
96 <span id='selectPriceSet'>{$form.price_set_id.html}</span>
97 {if $buildPriceSet && $priceSet}
98 <div id="priceset"><br/>{include file="CRM/Price/Form/PriceSet.tpl" extends="Membership"}</div>
99 {else}
100 <div id="priceset" class="hiddenElement"></div>
101 {/if}
102 {/if}
103 {if $member_is_test} {ts}(test){/ts}{/if}<br />
104 <span class="description">{ts}Select Membership Organization and then Membership Type.{/ts}{if $hasPriceSets} {ts}Alternatively, you can use a price set.{/ts}{/if}</span>
105 </td>
106 </tr>
107 <tr id="maxRelated" class="crm-membership-form-block-max_related">
108 <td class="label">{$form.max_related.label}</td>
109 <td>{$form.max_related.html}<br />
110 <span class="description">{ts}Maximum number of related memberships (leave blank for unlimited).{/ts}</span>
111 </td>
112 </tr>
113 {if $action eq 1}
114 <tr id="num_terms_row" class="crm-membership-form-block-num_terms">
115 <td class="label">{$form.num_terms.label}</td>
116 <td>&nbsp;{$form.num_terms.html}<br />
117 <span class="description">{ts}Set the membership end date this many membership periods from now. Make sure the appropriate corresponding fee is entered below.{/ts}</span>
118 </td>
119 </tr>
120 {/if}
121 <tr class="crm-membership-form-block-source">
122 <td class="label">{$form.source.label}</td>
123 <td>&nbsp;{$form.source.html}<br />
124 <span class="description">{ts}Source of this membership. This value is searchable.{/ts}</span></td>
125 </tr>
126
127 {* CRM-7362 --add campaign to membership *}
128 {include file="CRM/Campaign/Form/addCampaignToComponent.tpl"
129 campaignTrClass="crm-membership-form-block-campaign_id"}
130
131 <tr class="crm-membership-form-block-join_date"><td class="label">{$form.join_date.label}</td><td>{include file="CRM/common/jcalendar.tpl" elementName=join_date}
132 <br />
133 <span class="description">{ts}When did this contact first become a member?{/ts}</span></td></tr>
134 <tr class="crm-membership-form-block-start_date"><td class="label">{$form.start_date.label}</td><td>{include file="CRM/common/jcalendar.tpl" elementName=start_date}
135 <br />
136 <span class="description">{ts}First day of current continuous membership period. Start Date will be automatically set based on Membership Type if you don't select a date.{/ts}</span></td></tr>
137 <tr class="crm-membership-form-block-end_date"><td class="label">{$form.end_date.label}</td>
138 <td>{if $isRecur && $endDate}{$endDate|crmDate}{else}{include file="CRM/common/jcalendar.tpl" elementName=end_date}{/if}
139 <br />
140 <span class="description">{ts}Latest membership period expiration date. End Date will be automatically set based on Membership Type if you don't select a date.{/ts}</span></td></tr>
141 {if !empty($form.auto_renew)}
142 <tr id="autoRenew" class="crm-membership-form-block-auto_renew">
143 <td class="label"> {$form.auto_renew.label} {help id="id-auto_renew" file="CRM/Member/Form/Membership.hlp" action=$action} </td>
144 <td> {$form.auto_renew.html} </td>
145 </tr>
146 {/if}
147 {if !$membershipMode}
148 <tr><td class="label">{$form.is_override.label} {help id="id-status-override"}</td><td>{$form.is_override.html}</td></tr>
149 {/if}
150
151 {if ! $membershipMode}
152 {* Show read-only Status block - when action is UPDATE and is_override is FALSE *}
153 <tr id="memberStatus_show">
154 {if $action eq 2}
155 <td class="label">{$form.status_id.label}</td><td class="view-value">{$membershipStatus}</td>
156 {/if}
157 </tr>
158
159 {* Show editable status field when is_override is TRUE *}
160 <tr id="memberStatus"><td class="label">{$form.status_id.label}</td><td>{$form.status_id.html}<br />
161 <span class="description">{ts}If <strong>Status Override</strong> is checked, the selected status will remain in force (it will NOT be modified by the automated status update script).{/ts}</span></td></tr>
162
163 {elseif $membershipMode}
164 <tr class="crm-membership-form-block-financial_type_id-mode">
165 <td class="label">{$form.financial_type_id.label}</td>
166 <td>{$form.financial_type_id.html}<br />
167 <span class="description">{ts}Select the appropriate financial type for this payment.{/ts}</span></td>
168 </tr>
169 <tr class="crm-membership-form-block-total_amount">
170 <td class="label">{$form.total_amount.label}</td>
171 <td>{$form.total_amount.html}<br />
172 <span class="description">{ts}Membership payment amount.{/ts}</span></td>
173 </tr>
174 <tr class="crm-membership-form-block-contribution-contact">
175 <td class="label">{$form.is_different_contribution_contact.label}</td>
176 <td>{$form.is_different_contribution_contact.html}&nbsp;&nbsp;{help id="id-contribution_contact"}</td>
177 </tr>
178 <tr id="record-different-contact">
179 <td>&nbsp;</td>
180 <td>
181 <table class="compressed">
182 <tr class="crm-membership-form-block-soft-credit-type">
183 {*CRM-15366*}
184 <td class="label">{$form.soft_credit_type_id.label}</td>
185 <td>{$form.soft_credit_type_id.html}</td>
186 </tr>
187 <tr class="crm-membership-form-block-soft-credit-contact-id">
188 <td class="label">{$form.soft_credit_contact_id.label}</td>
189 <td>{$form.soft_credit_contact_id.html}</td>
190 </tr>
191 </table>
192 </td>
193 </tr>
194 <tr class="crm-membership-form-block-billing">
195 <td colspan="2">
196 {include file='CRM/Core/BillingBlock.tpl'}
197 </td>
198 </tr>
199 {/if}
200 {if $accessContribution and ! $membershipMode AND ($action neq 2 or (!$rows.0.contribution_id AND !$softCredit) or $onlinePendingContributionId)}
201 <tr id="contri">
202 <td class="label">{if $onlinePendingContributionId}{ts}Update Payment Status{/ts}{else}{$form.record_contribution.label}{/if}</td>
203 <td>{$form.record_contribution.html}<br />
204 <span class="description">{ts}Check this box to enter or update payment information. You will also be able to generate a customized receipt.{/ts}</span></td>
205 </tr>
206 <tr class="crm-membership-form-block-record_contribution"><td colspan="2">
207 <fieldset id="recordContribution"><legend>{ts}Membership Payment and Receipt{/ts}</legend>
208 <table>
209 <tr class="crm-membership-form-block-contribution-contact">
210 <td class="label">{$form.is_different_contribution_contact.label}</td>
211 <td>{$form.is_different_contribution_contact.html}&nbsp;&nbsp;{help id="id-contribution_contact"}</td>
212 </tr>
213 <tr id="record-different-contact">
214 <td>&nbsp;</td>
215 <td>
216 <table class="compressed">
217 <tr class="crm-membership-form-block-soft-credit-type">
218 <td class="label">{$form.soft_credit_type_id.label}</td>
219 <td>{$form.soft_credit_type_id.html}</td>
220 </tr>
221 <tr class="crm-membership-form-block-soft-credit-contact-id">
222 <td class="label">{$form.soft_credit_contact_id.label}</td>
223 <td>{$form.soft_credit_contact_id.html}</td>
224 </tr>
225 </table>
226 </td>
227 </tr>
228 <tr class="crm-membership-form-block-financial_type_id">
229 <td class="label">{$form.financial_type_id.label}</td>
230 <td>{$form.financial_type_id.html}<br />
231 <span class="description">{ts}Select the appropriate financial type for this payment.{/ts}</span></td>
232 </tr>
233 <tr class="crm-membership-form-block-total_amount">
234 <td class="label">{$form.total_amount.label}</td>
235 <td>{$form.total_amount.html}<br />
236 <span class="description">{ts}Membership payment amount. A contribution record will be created for this amount.{/ts}</span></td>
237 </tr>
238 <tr class="crm-membership-form-block-receive_date">
239 <td class="label">{$form.receive_date.label}</td>
240 <td>{include file="CRM/common/jcalendar.tpl" elementName=receive_date}</td>
241 </tr>
242 <tr class="crm-membership-form-block-payment_instrument_id">
243 <td class="label">{$form.payment_instrument_id.label}<span class="marker"> *</span></td>
244 <td>{$form.payment_instrument_id.html} {help id="payment_instrument_id" file="CRM/Contribute/Page/Tab.hlp"}</td>
245 </tr>
246 <tr id="checkNumber" class="crm-membership-form-block-check_number">
247 <td class="label">{$form.check_number.label}</td>
248 <td>{$form.check_number.html|crmAddClass:six}</td>
249 </tr>
250 {if $action neq 2 }
251 <tr class="crm-membership-form-block-trxn_id">
252 <td class="label">{$form.trxn_id.label}</td>
253 <td>{$form.trxn_id.html}</td>
254 </tr>
255 {/if}
256 <tr class="crm-membership-form-block-contribution_status_id">
257 <td class="label">{$form.contribution_status_id.label}</td>
258 <td>{$form.contribution_status_id.html}</td>
259 </tr>
260 </table>
261 </fieldset>
262 </td></tr>
263 {else}
264 <div class="spacer"></div>
265 {/if}
266
267 {if $emailExists and $outBound_option != 2 }
268 <tr id="send-receipt" class="crm-membership-form-block-send_receipt">
269 <td class="label">{$form.send_receipt.label}</td><td>{$form.send_receipt.html}<br />
270 <span class="description">{ts 1=$emailExists}Automatically email a membership confirmation and receipt to %1?{/ts}</span></td>
271 </tr>
272 {elseif $context eq 'standalone' and $outBound_option != 2 }
273 <tr id="email-receipt" style="display:none;">
274 <td class="label">{$form.send_receipt.label}</td><td>{$form.send_receipt.html}<br />
275 <span class="description">{ts}Automatically email a membership confirmation and receipt to {/ts}<span id="email-address"></span>?</span></td>
276 </tr>
277 {/if}
278 <tr id="fromEmail" style="display:none;">
279 <td class="label">{$form.from_email_address.label}</td>
280 <td>{$form.from_email_address.html}</td>
281 </tr>
282 <tr id='notice' style="display:none;">
283 <td class="label">{$form.receipt_text_signup.label}</td>
284 <td class="html-adjust"><span class="description">{ts}If you need to include a special message for this member, enter it here. Otherwise, the confirmation email will include the standard receipt message configured under System Message Templates.{/ts}</span>
285 {$form.receipt_text_signup.html|crmAddClass:huge}</td>
286 </tr>
287 </table>
288 <div id="customData"></div>
289 {*include custom data js file*}
290 {include file="CRM/common/customData.tpl"}
291 {literal}
292 <script type="text/javascript">
293 CRM.$(function($) {
294 {/literal}
295 CRM.buildCustomData( '{$customDataType}' );
296 {if $customDataSubType}
297 CRM.buildCustomData( '{$customDataType}', {$customDataSubType} );
298 {/if}
299 {literal}
300 });
301 </script>
302 {/literal}
303 {if $accessContribution and $action eq 2 and $rows.0.contribution_id}
304 <div class="crm-accordion-wrapper">
305 <div class="crm-accordion-header">{ts}Related Contributions{/ts}</div>
306 <div class="crm-accordion-body">{include file="CRM/Contribute/Form/Selector.tpl" context="Search"}</div>
307 </div>
308 {/if}
309 {if $softCredit}
310 <div class="crm-accordion-wrapper">
311 <div class="crm-accordion-header">{ts}Related Soft Contributions{/ts}</div>
312 <div class="crm-accordion-body">{include file="CRM/Contribute/Page/ContributionSoft.tpl" context="membership"}</div>
313 </div>
314 {/if}
315 {/if}
316
317 <div class="spacer"></div>
318 <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
319 </div> <!-- end form-block -->
320
321 {if $action neq 8} {* Jscript additions not need for Delete action *}
322 {if $accessContribution and !$membershipMode AND ($action neq 2 or !$rows.0.contribution_id or $onlinePendingContributionId)}
323
324 {include file="CRM/common/showHideByFieldValue.tpl"
325 trigger_field_id ="record_contribution"
326 trigger_value =""
327 target_element_id ="recordContribution"
328 target_element_type ="table-row"
329 field_type ="radio"
330 invert = 0
331 }
332 {include file="CRM/common/showHideByFieldValue.tpl"
333 trigger_field_id ="payment_instrument_id"
334 trigger_value = '4'
335 target_element_id ="checkNumber"
336 target_element_type ="table-row"
337 field_type ="select"
338 invert = 0
339 }
340 {/if}
341
342 {literal}
343 <script type="text/javascript">
344
345 function setPaymentBlock(mode, checkboxEvent) {
346 var memType = parseInt(cj('#membership_type_id_1').val( ));
347 var isPriceSet = 0;
348
349 if ( cj('#price_set_id').length > 0 && cj('#price_set_id').val() ) {
350 isPriceSet = 1;
351 }
352
353 if ( !memType || isPriceSet ) {
354 return;
355 }
356
357 var allMemberships = {/literal}{$allMembershipInfo}{literal};
358 if ( !mode ) {
359 //check the record_contribution checkbox if membership is a paid one
360 {/literal}{if $action eq 1}{literal}
361 if (!checkboxEvent) {
362 if (allMemberships[memType]['total_amount_numeric'] > 0) {
363 cj('#record_contribution').prop('checked','checked');
364 cj('#recordContribution').show();
365 }
366 else {
367 cj('#record_contribution').prop('checked', false);
368 cj('#recordContribution').hide();
369 }
370 }
371 {/literal}{/if}{literal}
372 }
373
374 // skip this for test and live modes because financial type is set automatically
375 cj("#financial_type_id").val(allMemberships[memType]['financial_type_id']);
376 var term = cj('#num_terms').val();
377 var taxRates = '{/literal}{$taxRates}{literal}';
378 var taxRates = JSON.parse(taxRates);
379 var taxRate = taxRates[allMemberships[memType]['financial_type_id']];
380
381 if ( term ) {
382 if (!taxRate) {
383 var feeTotal = allMemberships[memType]['total_amount_numeric'] * term;
384 }
385 else {
386 var feeTotal = Number((taxRate/100) * (allMemberships[memType]['total_amount_numeric'] * term))+Number(allMemberships[memType]['total_amount_numeric'] * term );
387 }
388 cj("#total_amount").val( feeTotal.toFixed(2) );
389 }
390 else {
391 if (taxRate) {
392 var feeTotal = parseFloat(Number((taxRate/100) * allMemberships[memType]['total_amount'])+Number(allMemberships[memType]['total_amount_numeric'])).toFixed(2);
393 cj("#total_amount").val( feeTotal );
394 }
395 else {
396 cj("#total_amount").val( allMemberships[memType]['total_amount'] );
397 }
398 }
399 }
400
401
402 CRM.$(function($) {
403 var mode = {/literal}'{$membershipMode}'{literal};
404 if ( !mode ) {
405 // Offline form (mode = false) has the record_contribution checkbox
406 cj('#record_contribution').click( function( ) {
407 if ( cj(this).prop('checked') ) {
408 cj('#recordContribution').show( );
409 setPaymentBlock( false, true);
410 }
411 else {
412 cj('#recordContribution').hide( );
413 }
414 });
415 }
416
417 cj('#membership_type_id_1').change( function( ) {
418 setPaymentBlock(mode);
419 });
420 cj('#num_terms').change( function( ) {
421 setPaymentBlock(mode);
422 });
423 setPaymentBlock(mode);
424
425 // show/hide different contact section
426 setDifferentContactBlock();
427 cj('#is_different_contribution_contact').change( function() {
428 setDifferentContactBlock();
429 });
430 });
431
432 function setDifferentContactBlock( ) {
433 // show/hide different contact section
434 if ( cj('#is_different_contribution_contact').prop('checked') ) {
435 cj('#record-different-contact').show();
436 }
437 else {
438 cj('#record-different-contact').hide();
439 }
440 }
441 </script>
442 {/literal}
443
444 {if ($emailExists and $outBound_option != 2) OR $context eq 'standalone' }
445 {include file="CRM/common/showHideByFieldValue.tpl"
446 trigger_field_id ="send_receipt"
447 trigger_value =""
448 target_element_id ="notice"
449 target_element_type ="table-row"
450 field_type ="radio"
451 invert = 0
452 }
453 {include file="CRM/common/showHideByFieldValue.tpl"
454 trigger_field_id ="send_receipt"
455 trigger_value =""
456 target_element_id ="fromEmail"
457 target_element_type ="table-row"
458 field_type ="radio"
459 invert = 0
460 }
461 {/if}
462 {literal}
463
464 <script type="text/javascript">
465
466 {/literal}{if !$membershipMode}{literal}
467 showHideMemberStatus();
468 function showHideMemberStatus() {
469 if ( cj( "#is_override" ).prop('checked' ) ) {
470 cj('#memberStatus').show( );
471 cj('#memberStatus_show').hide( );
472 }
473 else {
474 cj('#memberStatus').hide( );
475 cj('#memberStatus_show').show( );
476 }
477 }
478 {/literal}{/if}
479
480 {if $context eq 'standalone' and $outBound_option != 2 }
481 {literal}
482 CRM.$(function($) {
483 var $form = $("form.{/literal}{$form.formClass}{literal}");
484 $("#contact_id", $form).change(checkEmail);
485 checkEmail( );
486
487 function checkEmail( ) {
488 var data = $("#contact_id", $form).select2('data');
489 if (data && data.extra && data.extra.email && data.extra.email.length) {
490 $("#email-receipt", $form).show();
491 if ($("#send_receipt", $form).is(':checked')) {
492 $("#notice", $form).show();
493 }
494 $("#email-address", $form).html(data.extra.email);
495 }
496 else {
497 $("#email-receipt, #notice", $form).hide();
498 }
499 }
500 });
501
502 {/literal}
503 {/if}
504
505 {literal}
506 //keep read only always checked.
507 CRM.$(function($) {
508 var $form = $("form.{/literal}{$form.formClass}{literal}");
509 var allowAutoRenew = {/literal}'{$allowAutoRenew}'{literal};
510 var alreadyAutoRenew = {/literal}'{$alreadyAutoRenew}'{literal};
511 if ( allowAutoRenew || alreadyAutoRenew ) {
512 $( "#auto_renew" ).click(function( ) {
513 if ( $(this).attr( 'readonly' ) ) {
514 $(this).prop('checked', true );
515 }
516 });
517 }
518
519 {/literal}
520 {if !empty($existingContactMemberships)}
521
522 var alert, memberorgs = {$existingContactMemberships|@json_encode};
523
524 {literal}
525 $("select[name='membership_type_id[0]']").change(checkExistingMemOrg);
526
527
528
529 function checkExistingMemOrg () {
530 alert && alert.close && alert.close();
531 var selectedorg = $("select[name='membership_type_id[0]']").val();
532 if (selectedorg in memberorgs) {
533 var andEndDate = '',
534 endDate = memberorgs[selectedorg].membership_end_date,
535 org = $('option:selected', "select[name='membership_type_id[0]']").text();
536 if (endDate) {
537 andEndDate = ' ' + ts("and end date of %1", {1:endDate});
538 }
539
540 alert = CRM.alert(
541 // Mixing client-side variables with a translated string in smarty is awkward!
542 ts({/literal}'{ts escape='js' 1='%1' 2='%2' 3='%3' 4='%4'}This contact has an existing %1 membership at %2 with %3 status%4.{/ts}'{literal}, {1:memberorgs[selectedorg].membership_type, 2: org, 3: memberorgs[selectedorg].membership_status, 4: andEndDate})
543 + '<ul><li><a href="' + memberorgs[selectedorg].renewUrl + '">'
544 + {/literal}'{ts escape='js''}Renew the existing membership instead{/ts}'
545 + '</a></li><li><a href="' + memberorgs[selectedorg].membershipTab + '">'
546 + '{ts escape='js'}View all existing and / or expired memberships for this contact{/ts}'{literal}
547 + '</a></li></ul>',
548 ts('Duplicate Membership?'), 'alert');
549 }
550 }
551 checkExistingMemOrg();
552 {/literal}
553 {/if}
554
555 {literal}
556
557 });
558 {/literal}
559
560 {if $membershipMode or $action eq 2}
561 {literal}
562
563 buildAutoRenew( null, null );
564
565 function buildAutoRenew( membershipType, processorId ) {
566 var mode = {/literal}'{$membershipMode}'{literal};
567 var action = {/literal}'{$action}'{literal};
568
569 //for update lets hide it when not already recurring.
570 if ( action == 2 ) {
571 //user can't cancel auto renew by unchecking.
572 if ( cj("#auto_renew").prop('checked' ) ) {
573 cj("#auto_renew").attr( 'readonly', true );
574 }
575 else {
576 cj("#autoRenew").hide( );
577 }
578 }
579
580 //we should do all auto renew for cc memberships.
581 if ( !mode ) return;
582
583 //get the required values in case missing.
584 if ( !processorId ) processorId = cj( '#payment_processor_id' ).val( );
585 if ( !membershipType ) membershipType = parseInt( cj('#membership_type_id_1').val( ) );
586
587 //we don't have both required values.
588 if ( !processorId || !membershipType ) {
589 cj("#auto_renew").prop('checked', false );
590 cj("#autoRenew").hide( );
591 return;
592 }
593
594 var recurProcessors = {/literal}{$recurProcessor}{literal};
595 var autoRenewOptions = {/literal}{$autoRenewOptions}{literal};
596 var currentOption = autoRenewOptions[membershipType];
597
598 if ( !currentOption || !recurProcessors[processorId] ) {
599 cj("#auto_renew").prop('checked', false );
600 cj("#autoRenew").hide( );
601 return;
602 }
603
604 if ( currentOption == 1 ) {
605 cj("#autoRenew").show( );
606 if ( cj("#auto_renew").attr( 'readonly' ) ) {
607 cj("#auto_renew").prop('checked', false );
608 cj("#auto_renew").removeAttr( 'readonly' );
609 }
610 }
611 else if ( currentOption == 2 ) {
612 cj("#autoRenew").show( );
613 cj("#auto_renew").prop('checked', true );
614 cj("#auto_renew").attr( 'readonly', true );
615 }
616 else {
617 cj("#auto_renew").prop('checked', false );
618 cj("#autoRenew").hide( );
619 }
620
621 //play w/ receipt option.
622 if ( cj("#auto_renew").prop('checked' ) ) {
623 cj("#notice").hide( );
624 cj("#send_receipt").prop('checked', false );
625 cj("#send-receipt").hide( );
626 }
627 else {
628 cj("#send-receipt").show( );
629 if ( cj("#send_receipt").prop('checked' ) ) {
630 cj("#notice").show( );
631 }
632 }
633 }
634 {/literal}
635 {/if}
636
637 {literal}
638 function buildReceiptANDNotice( ) {
639 if ( cj("#auto_renew").prop('checked' ) ) {
640 cj("#notice").hide( );
641 cj("#send-receipt").hide( );
642 }
643 else {
644 cj("#send-receipt").show( );
645 if ( cj("#send_receipt").prop('checked' ) ) {
646 cj("#notice").show( );
647 }
648 }
649 }
650
651 var customDataType = '{/literal}{$customDataType}{literal}';
652
653 // load form during form rule.
654 {/literal}{if $buildPriceSet}{literal}
655 cj( "#totalAmountORPriceSet" ).hide( );
656 cj( "#mem_type_id" ).hide( );
657 cj('#total_amount').attr("readonly", true);
658 cj( "#num_terms_row" ).hide( );
659 cj(".crm-membership-form-block-financial_type_id-mode").hide();
660 {/literal}{/if}{literal}
661
662 function buildAmount( priceSetId ) {
663 if ( !priceSetId ) {
664 priceSetId = cj("#price_set_id").val( );
665 }
666 var fname = '#priceset';
667 if ( !priceSetId ) {
668 cj('#membership_type_id_1').val(0);
669 CRM.buildCustomData(customDataType, 'null' );
670
671 // hide price set fields.
672 cj( fname ).hide( );
673
674 // show/hide price set amount and total amount.
675 cj( "#mem_type_id").show( );
676 var choose = "{/literal}{ts}Choose price set{/ts}{literal}";
677 cj("#price_set_id option[value='']").html( choose );
678 cj( "#totalAmountORPriceSet" ).show( );
679 cj('#total_amount').removeAttr("readonly");
680 cj( "#num_terms_row").show( );
681 cj(".crm-membership-form-block-financial_type_id-mode").show();
682
683 {/literal}{if $allowAutoRenew}{literal}
684 cj('#autoRenew').hide();
685 var autoRenew = cj("#auto_renew");
686 autoRenew.removeAttr( 'readOnly' );
687 autoRenew.prop('checked', false );
688 {/literal}{/if}{literal}
689 return;
690 }
691
692 cj( "#total_amount" ).val( '' );
693 cj('#total_amount').attr("readonly", true);
694
695 var dataUrl = {/literal}"{crmURL h=0 q='snippet=4'}"{literal} + '&priceSetId=' + priceSetId;
696
697 var response = cj.ajax({
698 url: dataUrl,
699 async: false
700 }).responseText;
701
702 cj( fname ).show( ).html( response );
703 // freeze total amount text field.
704
705 cj( "#totalAmountORPriceSet" ).hide( );
706 cj( "#mem_type_id" ).hide( );
707 var manual = "{/literal}{ts}Manual membership and price{/ts}{literal}";
708 cj("#price_set_id option[value='']").html( manual );
709 cj( "#num_terms_row" ).hide( );
710 cj(".crm-membership-form-block-financial_type_id-mode").hide();
711 }
712
713 buildMaxRelated(cj('#membership_type_id_1', false).val());
714
715 function buildMaxRelated( memType, setDefault ) {
716 var allMemberships = {/literal}{$allMembershipInfo}{literal};
717
718 if ((memType > 0) && (allMemberships[memType]['has_related'])) {
719 if (setDefault) cj('#max_related').val(allMemberships[memType]['max_related']);
720 cj('#maxRelated').show();
721 var cid = {/literal}{if $contactID}{$contactID}{else}null{/if}{literal};
722 if (cid) {
723 CRM.api('relationship', 'getcount', {contact_id: cid, membership_type_id: memType}, {
724 success: function(result) {
725 var relatable = ' ' + result.result + ts(' contacts are ');
726 if(result.result === 0) {
727 relatable = ts(' No contacts are ');
728 }
729 if(result.result === 1) {
730 relatable = ts(' One contact is ');
731 }
732
733 var others = relatable + ts('currently eligible to inherit this relationship.');
734 cj('#max_related').siblings('.description').append(others);
735 }
736 });
737 }
738 } else {
739 cj('#max_related').val('');
740 cj('#maxRelated').hide();
741 }
742 }
743
744 var lastMembershipTypes = [];
745 var optionsMembershipTypes = [];
746
747 // function to load custom data for selected membership types through priceset
748 function processMembershipPriceset( membershipValues, autoRenewOption, reload ) {
749 var currentMembershipType = [];
750 var count = 0;
751 var loadCustomData = 0;
752 if ( membershipValues ) {
753 optionsMembershipTypes = membershipValues;
754 }
755
756 if ( reload ) {
757 lastMembershipTypes = [];
758 {/literal}{if $allowAutoRenew}{literal}
759 cj('#autoRenew').hide();
760 var autoRenew = cj("#auto_renew");
761 autoRenew.removeAttr( 'readOnly' );
762 autoRenew.prop('checked', false );
763 if ( autoRenewOption == 1 ) {
764 cj('#autoRenew').show();
765 }
766 else if ( autoRenewOption == 2 ) {
767 autoRenew.attr( 'readOnly', true );
768 autoRenew.prop('checked', true );
769 cj('#autoRenew').show();
770 }
771 {/literal}{/if}{literal}
772 }
773
774 cj("input,#priceset select,#priceset").each(function () {
775 if ( cj(this).attr('price') ) {
776 switch( cj(this).attr('type') ) {
777 case 'checkbox':
778 if ( cj(this).prop('checked') ) {
779 eval( 'var option = ' + cj(this).attr('price') ) ;
780 var ele = option[0];
781 var memTypeId = optionsMembershipTypes[ele];
782 if ( memTypeId && cj.inArray(optionsMembershipTypes[ele], currentMembershipType) == -1 ) {
783 currentMembershipType[count] = memTypeId;
784 count++;
785 }
786 }
787 if ( reload ) {
788 cj(this).click( function( ) {
789 processMembershipPriceset();
790 });
791 }
792 break;
793
794 case 'radio':
795 if ( cj(this).prop('checked') && cj(this).val() ) {
796 var memTypeId = optionsMembershipTypes[cj(this).val()];
797 if ( memTypeId && cj.inArray(memTypeId, currentMembershipType) == -1 ) {
798 currentMembershipType[count] = memTypeId;
799 count++;
800 }
801 }
802 if ( reload ) {
803 cj(this).click( function( ) {
804 processMembershipPriceset();
805 });
806 }
807 break;
808
809 case 'select-one':
810 if ( cj(this).val( ) ) {
811 var memTypeId = optionsMembershipTypes[cj(this).val()];
812 if ( memTypeId && cj.inArray(memTypeId, currentMembershipType) == -1 ) {
813 currentMembershipType[count] = memTypeId;
814 count++;
815 }
816 }
817 if ( reload ) {
818 cj(this).change( function( ) {
819 processMembershipPriceset();
820 });
821 }
822 break;
823 }
824 }
825 });
826
827 for( i in currentMembershipType ) {
828 if ( cj.inArray(currentMembershipType[i], lastMembershipTypes) == -1 ) {
829 loadCustomData = 1;
830 break;
831 }
832 }
833
834 if ( !loadCustomData ) {
835 for( i in lastMembershipTypes) {
836 if ( cj.inArray(lastMembershipTypes[i], currentMembershipType) == -1 ) {
837 loadCustomData = 1;
838 break;
839 }
840 }
841 }
842
843 lastMembershipTypes = currentMembershipType;
844
845 // load custom data only if change in membership type selection
846 if ( !loadCustomData ) {
847 return;
848 }
849
850 subTypeNames = currentMembershipType.join(',');
851 if ( subTypeNames.length < 1 ) {
852 subTypeNames = 'null';
853 }
854
855 CRM.buildCustomData( customDataType, subTypeNames );
856 }
857
858 function enableAmountSection( setContributionType ) {
859 if ( !cj('#record_contribution').prop('checked') ) {
860 cj('#record_contribution').click( );
861 cj('#recordContribution').show( );
862 }
863 if ( setContributionType ) {
864 cj('#financial_type_id').val(setContributionType);
865 }
866 }
867 </script>
868 {/literal}
869 {/if} {* closing of delete check if *}
870 {/if}{* closing of custom data if *}