2 +--------------------------------------------------------------------+
3 | CiviCRM version 4.5 |
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC (c) 2004-2014 |
6 +--------------------------------------------------------------------+
7 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
26 {* this template is used for adding/editing/deleting memberships for a contact *}
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>
33 <div class="spacer"></div>
35 {include file="CRM/Custom/Form/CustomData.tpl"}
37 {include file="CRM/Price/Form/PriceSet.tpl" context="standalone" extends="Membership"}
39 <script type="text/javascript">
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}
53 {if $membershipMode == 'test' }
54 {assign var=registerMode value="TEST"}
55 {elseif $membershipMode == 'live'}
56 {assign var=registerMode value="LIVE"}
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>
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}
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>
72 <div class="messages status no-popup">
73 <div class="icon inform-icon"></div>
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>
79 <table class="form-layout-compressed">
80 {if $context neq 'standalone'}
82 <td class="font-size12pt label"><strong>{ts}Member{/ts}</strong></td><td class="font-size12pt"><strong>{$displayName}</strong></td>
85 <td class="label">{$form.contact_id.label}</td>
86 <td>{$form.contact_id.html}</td>
89 <tr><td class="label">{$form.payment_processor_id.label}</td><td>{$form.payment_processor_id.html}</td></tr>
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>
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>
100 <div id="priceset" class="hiddenElement"></div>
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>
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>
114 <tr id="num_terms_row" class="crm-membership-form-block-num_terms">
115 <td class="label">{$form.num_terms.label}</td>
116 <td> {$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>
121 <tr class="crm-membership-form-block-source">
122 <td class="label">{$form.source.label}</td>
123 <td> {$form.source.html}<br />
124 <span class="description">{ts}Source of this membership. This value is searchable.{/ts}</span></td>
127 {* CRM-7362 --add campaign to membership *}
128 {include file="CRM/Campaign/Form/addCampaignToComponent.tpl"
129 campaignTrClass="crm-membership-form-block-campaign_id"}
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}
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}
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}
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>
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>
151 {if ! $membershipMode}
152 {* Show read-only Status block - when action is UPDATE and is_override is FALSE *}
153 <tr id="memberStatus_show">
155 <td class="label">{$form.status_id.label}</td><td class="view-value">{$membershipStatus}</td>
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>
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>
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>
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} {help id="id-contribution_contact"}</td>
178 <tr id="record-different-contact">
181 <table class="compressed">
182 <tr class="crm-membership-form-block-soft-credit-type">
184 <td class="label">{$form.soft_credit_type_id.label}</td>
185 <td>{$form.soft_credit_type_id.html}</td>
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>
194 <tr class="crm-membership-form-block-billing">
196 {include file='CRM/Core/BillingBlock.tpl'}
200 {if $accessContribution and ! $membershipMode AND ($action neq 2 or (!$rows.0.contribution_id AND !$softCredit) or $onlinePendingContributionId)}
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>
206 <tr class="crm-membership-form-block-record_contribution"><td colspan="2">
207 <fieldset id="recordContribution"><legend>{ts}Membership Payment and Receipt{/ts}</legend>
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} {help id="id-contribution_contact"}</td>
213 <tr id="record-different-contact">
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>
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>
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>
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>
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>
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>
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>
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>
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>
264 <div class="spacer"></div>
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>
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>
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>
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>
288 <div id="customData"></div>
289 {*include custom data js file*}
290 {include file="CRM/common/customData.tpl"}
292 <script type="text/javascript">
295 CRM.buildCustomData( '{$customDataType}' );
296 {if $customDataSubType}
297 CRM.buildCustomData( '{$customDataType}', {$customDataSubType} );
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>
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>
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 -->
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)}
324 {include file="CRM/common/showHideByFieldValue.tpl"
325 trigger_field_id ="record_contribution"
327 target_element_id ="recordContribution"
328 target_element_type ="table-row"
332 {include file="CRM/common/showHideByFieldValue.tpl"
333 trigger_field_id ="payment_instrument_id"
335 target_element_id ="checkNumber"
336 target_element_type ="table-row"
343 <script type="text/javascript">
345 function setPaymentBlock(mode, checkboxEvent) {
346 var memType = parseInt(cj('#membership_type_id_1').val( ));
349 if ( cj('#price_set_id').length > 0 && cj('#price_set_id').val() ) {
353 if ( !memType || isPriceSet ) {
357 var allMemberships = {/literal}{$allMembershipInfo}{literal};
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();
367 cj('#record_contribution').prop('checked', false);
368 cj('#recordContribution').hide();
371 {/literal}{/if}{literal}
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']];
383 var feeTotal = allMemberships[memType]['total_amount_numeric'] * term;
386 var feeTotal = Number((taxRate/100) * (allMemberships[memType]['total_amount_numeric'] * term))+Number(allMemberships[memType]['total_amount_numeric'] * term );
388 cj("#total_amount").val( feeTotal.toFixed(2) );
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 );
396 cj("#total_amount").val( allMemberships[memType]['total_amount'] );
403 var mode = {/literal}'{$membershipMode}'{literal};
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);
412 cj('#recordContribution').hide( );
417 cj('#membership_type_id_1').change( function( ) {
418 setPaymentBlock(mode);
420 cj('#num_terms').change( function( ) {
421 setPaymentBlock(mode);
423 setPaymentBlock(mode);
425 // show/hide different contact section
426 setDifferentContactBlock();
427 cj('#is_different_contribution_contact').change( function() {
428 setDifferentContactBlock();
432 function setDifferentContactBlock( ) {
433 // show/hide different contact section
434 if ( cj('#is_different_contribution_contact').prop('checked') ) {
435 cj('#record-different-contact').show();
438 cj('#record-different-contact').hide();
444 {if ($emailExists and $outBound_option != 2) OR $context eq 'standalone' }
445 {include file="CRM/common/showHideByFieldValue.tpl"
446 trigger_field_id ="send_receipt"
448 target_element_id ="notice"
449 target_element_type ="table-row"
453 {include file="CRM/common/showHideByFieldValue.tpl"
454 trigger_field_id ="send_receipt"
456 target_element_id ="fromEmail"
457 target_element_type ="table-row"
464 <script type="text/javascript">
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( );
474 cj('#memberStatus').hide( );
475 cj('#memberStatus_show').show( );
480 {if $context eq 'standalone' and $outBound_option != 2 }
483 var $form = $("form.{/literal}{$form.formClass}{literal}");
484 $("#contact_id", $form).change(checkEmail);
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();
494 $("#email-address", $form).html(data.extra.email);
497 $("#email-receipt, #notice", $form).hide();
506 //keep read only always checked.
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 );
520 {if !empty($existingContactMemberships)}
522 var alert, memberorgs = {$existingContactMemberships|@json_encode};
525 $("select[name='membership_type_id[0]']").change(checkExistingMemOrg);
529 function checkExistingMemOrg () {
530 alert && alert.close && alert.close();
531 var selectedorg = $("select[name='membership_type_id[0]']").val();
532 if (selectedorg in memberorgs) {
534 endDate = memberorgs[selectedorg].membership_end_date,
535 org = $('option:selected', "select[name='membership_type_id[0]']").text();
537 andEndDate = ' ' + ts("and end date of %1", {1:endDate});
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}
548 ts('Duplicate Membership?'), 'alert');
551 checkExistingMemOrg();
560 {if $membershipMode or $action eq 2}
563 buildAutoRenew( null, null );
565 function buildAutoRenew( membershipType, processorId ) {
566 var mode = {/literal}'{$membershipMode}'{literal};
567 var action = {/literal}'{$action}'{literal};
569 //for update lets hide it when not already recurring.
571 //user can't cancel auto renew by unchecking.
572 if ( cj("#auto_renew").prop('checked' ) ) {
573 cj("#auto_renew").attr( 'readonly', true );
576 cj("#autoRenew").hide( );
580 //we should do all auto renew for cc memberships.
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( ) );
587 //we don't have both required values.
588 if ( !processorId || !membershipType ) {
589 cj("#auto_renew").prop('checked', false );
590 cj("#autoRenew").hide( );
594 var recurProcessors = {/literal}{$recurProcessor}{literal};
595 var autoRenewOptions = {/literal}{$autoRenewOptions}{literal};
596 var currentOption = autoRenewOptions[membershipType];
598 if ( !currentOption || !recurProcessors[processorId] ) {
599 cj("#auto_renew").prop('checked', false );
600 cj("#autoRenew").hide( );
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' );
611 else if ( currentOption == 2 ) {
612 cj("#autoRenew").show( );
613 cj("#auto_renew").prop('checked', true );
614 cj("#auto_renew").attr( 'readonly', true );
617 cj("#auto_renew").prop('checked', false );
618 cj("#autoRenew").hide( );
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( );
628 cj("#send-receipt").show( );
629 if ( cj("#send_receipt").prop('checked' ) ) {
630 cj("#notice").show( );
638 function buildReceiptANDNotice( ) {
639 if ( cj("#auto_renew").prop('checked' ) ) {
640 cj("#notice").hide( );
641 cj("#send-receipt").hide( );
644 cj("#send-receipt").show( );
645 if ( cj("#send_receipt").prop('checked' ) ) {
646 cj("#notice").show( );
651 var customDataType = '{/literal}{$customDataType}{literal}';
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}
662 function buildAmount( priceSetId ) {
664 priceSetId = cj("#price_set_id").val( );
666 var fname = '#priceset';
668 cj('#membership_type_id_1').val(0);
669 CRM.buildCustomData(customDataType, 'null' );
671 // hide price set fields.
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();
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}
692 cj( "#total_amount" ).val( '' );
693 cj('#total_amount').attr("readonly", true);
695 var dataUrl = {/literal}"{crmURL h=0 q='snippet=4'}"{literal} + '&priceSetId=' + priceSetId;
697 var response = cj.ajax({
702 cj( fname ).show( ).html( response );
703 // freeze total amount text field.
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();
713 buildMaxRelated(cj('#membership_type_id_1', false).val());
715 function buildMaxRelated( memType, setDefault ) {
716 var allMemberships = {/literal}{$allMembershipInfo}{literal};
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};
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 ');
729 if(result.result === 1) {
730 relatable = ts(' One contact is ');
733 var others = relatable + ts('currently eligible to inherit this relationship.');
734 cj('#max_related').siblings('.description').append(others);
739 cj('#max_related').val('');
740 cj('#maxRelated').hide();
744 var lastMembershipTypes = [];
745 var optionsMembershipTypes = [];
747 // function to load custom data for selected membership types through priceset
748 function processMembershipPriceset( membershipValues, autoRenewOption, reload ) {
749 var currentMembershipType = [];
751 var loadCustomData = 0;
752 if ( membershipValues ) {
753 optionsMembershipTypes = membershipValues;
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();
766 else if ( autoRenewOption == 2 ) {
767 autoRenew.attr( 'readOnly', true );
768 autoRenew.prop('checked', true );
769 cj('#autoRenew').show();
771 {/literal}{/if}{literal}
774 cj("input,#priceset select,#priceset").each(function () {
775 if ( cj(this).attr('price') ) {
776 switch( cj(this).attr('type') ) {
778 if ( cj(this).prop('checked') ) {
779 eval( 'var option = ' + cj(this).attr('price') ) ;
781 var memTypeId = optionsMembershipTypes[ele];
782 if ( memTypeId && cj.inArray(optionsMembershipTypes[ele], currentMembershipType) == -1 ) {
783 currentMembershipType[count] = memTypeId;
788 cj(this).click( function( ) {
789 processMembershipPriceset();
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;
803 cj(this).click( function( ) {
804 processMembershipPriceset();
810 if ( cj(this).val( ) ) {
811 var memTypeId = optionsMembershipTypes[cj(this).val()];
812 if ( memTypeId && cj.inArray(memTypeId, currentMembershipType) == -1 ) {
813 currentMembershipType[count] = memTypeId;
818 cj(this).change( function( ) {
819 processMembershipPriceset();
827 for( i in currentMembershipType ) {
828 if ( cj.inArray(currentMembershipType[i], lastMembershipTypes) == -1 ) {
834 if ( !loadCustomData ) {
835 for( i in lastMembershipTypes) {
836 if ( cj.inArray(lastMembershipTypes[i], currentMembershipType) == -1 ) {
843 lastMembershipTypes = currentMembershipType;
845 // load custom data only if change in membership type selection
846 if ( !loadCustomData ) {
850 subTypeNames = currentMembershipType.join(',');
851 if ( subTypeNames.length < 1 ) {
852 subTypeNames = 'null';
855 CRM.buildCustomData( customDataType, subTypeNames );
858 function enableAmountSection( setContributionType ) {
859 if ( !cj('#record_contribution').prop('checked') ) {
860 cj('#record_contribution').click( );
861 cj('#recordContribution').show( );
863 if ( setContributionType ) {
864 cj('#financial_type_id').val(setContributionType);
869 {/if} {* closing of delete check if *}
870 {/if}{* closing of custom data if *}