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