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