Merge pull request #6003 from yashodha/CRM-16661
[civicrm-core.git] / templates / CRM / Member / Form / Membership.tpl
CommitLineData
6a488035
TO
1{*
2 +--------------------------------------------------------------------+
39de6fd5 3 | CiviCRM version 4.6 |
6a488035 4 +--------------------------------------------------------------------+
e7112fa7 5 | Copyright CiviCRM LLC (c) 2004-2015 |
6a488035
TO
6 +--------------------------------------------------------------------+
7 | This file is a part of CiviCRM. |
8 | |
9 | CiviCRM is free software; you can copy, modify, and distribute it |
10 | under the terms of the GNU Affero General Public License |
11 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
12 | |
13 | CiviCRM is distributed in the hope that it will be useful, but |
14 | WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
16 | See the GNU Affero General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU Affero General Public |
19 | License and the CiviCRM Licensing Exception along |
20 | with this program; if not, contact CiviCRM LLC |
21 | at info[AT]civicrm[DOT]org. If you have questions about the |
22 | GNU Affero General Public License or the licensing of CiviCRM, |
23 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
24 +--------------------------------------------------------------------+
25*}
26{* this template is used for adding/editing/deleting 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">
3cc60a06 40 CRM.$(function($) {
ae8f569f 41 var membershipValues = [];
6a488035
TO
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}
6a488035
TO
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>
4c7aa1f7 84 {else}
4c7aa1f7
CW
85 <td class="label">{$form.contact_id.label}</td>
86 <td>{$form.contact_id.html}</td>
6a488035
TO
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 />
5384bd2f 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>
6a488035
TO
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>
e4444728
DG
138 <td id="end-date-readonly">
139 {$endDate|crmDate}
140 <a href="#" class="crm-hover-button action-item override-date" id="show-end-date">
141 {ts}Over-ride end date{/ts}
142 </a>
143 {help id="override_end_date"}
144 </td>
145 <td id="end-date-editable">
146 {include file="CRM/common/jcalendar.tpl" elementName=end_date}
6a488035 147 <br />
e4444728
DG
148 <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>
149 </td>
150 </tr>
378ea9fc
CW
151 {if !empty($form.auto_renew)}
152 <tr id="autoRenew" class="crm-membership-form-block-auto_renew">
153 <td class="label"> {$form.auto_renew.label} {help id="id-auto_renew" file="CRM/Member/Form/Membership.hlp" action=$action} </td>
154 <td> {$form.auto_renew.html} </td>
155 </tr>
156 {/if}
157 {if !$membershipMode}
158 <tr><td class="label">{$form.is_override.label} {help id="id-status-override"}</td><td>{$form.is_override.html}</td></tr>
6a488035
TO
159 {/if}
160
161 {if ! $membershipMode}
162 {* Show read-only Status block - when action is UPDATE and is_override is FALSE *}
163 <tr id="memberStatus_show">
164 {if $action eq 2}
165 <td class="label">{$form.status_id.label}</td><td class="view-value">{$membershipStatus}</td>
166 {/if}
167 </tr>
168
169 {* Show editable status field when is_override is TRUE *}
170 <tr id="memberStatus"><td class="label">{$form.status_id.label}</td><td>{$form.status_id.html}<br />
171 <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>
172
173 {elseif $membershipMode}
5a9c4d4a
PN
174 <tr class="crm-membership-form-block-financial_type_id-mode">
175 <td class="label">{$form.financial_type_id.label}</td>
176 <td>{$form.financial_type_id.html}<br />
177 <span class="description">{ts}Select the appropriate financial type for this payment.{/ts}</span></td>
178 </tr>
6a488035
TO
179 <tr class="crm-membership-form-block-total_amount">
180 <td class="label">{$form.total_amount.label}</td>
181 <td>{$form.total_amount.html}<br />
46611472 182 <span class="description">{ts}Membership payment amount.{/ts}</span><div class="totaltaxAmount"></div></td>
6a488035 183 </tr>
d80dbc14 184 <tr class="crm-membership-form-block-contribution-contact">
185 <td class="label">{$form.is_different_contribution_contact.label}</td>
186 <td>{$form.is_different_contribution_contact.html}&nbsp;&nbsp;{help id="id-contribution_contact"}</td>
187 </tr>
188 <tr id="record-different-contact">
189 <td>&nbsp;</td>
190 <td>
191 <table class="compressed">
192 <tr class="crm-membership-form-block-soft-credit-type">
87d0f881 193 {*CRM-15366*}
396e62d8 194 <td class="label">{$form.soft_credit_type_id.label}</td>
195 <td>{$form.soft_credit_type_id.html}</td>
d80dbc14 196 </tr>
197 <tr class="crm-membership-form-block-soft-credit-contact-id">
198 <td class="label">{$form.soft_credit_contact_id.label}</td>
199 <td>{$form.soft_credit_contact_id.html}</td>
200 </tr>
201 </table>
202 </td>
203 </tr>
6a488035
TO
204 <tr class="crm-membership-form-block-billing">
205 <td colspan="2">
206 {include file='CRM/Core/BillingBlock.tpl'}
207 </td>
208 </tr>
209 {/if}
8a80e619 210 {if $accessContribution and ! $membershipMode AND ($action neq 2 or (!$rows.0.contribution_id AND !$softCredit) or $onlinePendingContributionId)}
6a488035
TO
211 <tr id="contri">
212 <td class="label">{if $onlinePendingContributionId}{ts}Update Payment Status{/ts}{else}{$form.record_contribution.label}{/if}</td>
213 <td>{$form.record_contribution.html}<br />
214 <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>
215 </tr>
216 <tr class="crm-membership-form-block-record_contribution"><td colspan="2">
217 <fieldset id="recordContribution"><legend>{ts}Membership Payment and Receipt{/ts}</legend>
d80dbc14 218 <table>
6a488035
TO
219 <tr class="crm-membership-form-block-contribution-contact">
220 <td class="label">{$form.is_different_contribution_contact.label}</td>
221 <td>{$form.is_different_contribution_contact.html}&nbsp;&nbsp;{help id="id-contribution_contact"}</td>
222 </tr>
223 <tr id="record-different-contact">
224 <td>&nbsp;</td>
225 <td>
226 <table class="compressed">
4c7aa1f7 227 <tr class="crm-membership-form-block-soft-credit-type">
133e2c99 228 <td class="label">{$form.soft_credit_type_id.label}</td>
229 <td>{$form.soft_credit_type_id.html}</td>
6a488035 230 </tr>
4c7aa1f7
CW
231 <tr class="crm-membership-form-block-soft-credit-contact-id">
232 <td class="label">{$form.soft_credit_contact_id.label}</td>
233 <td>{$form.soft_credit_contact_id.html}</td>
6a488035
TO
234 </tr>
235 </table>
236 </td>
d80dbc14 237 </tr>
6a488035
TO
238 <tr class="crm-membership-form-block-financial_type_id">
239 <td class="label">{$form.financial_type_id.label}</td>
240 <td>{$form.financial_type_id.html}<br />
241 <span class="description">{ts}Select the appropriate financial type for this payment.{/ts}</span></td>
242 </tr>
243 <tr class="crm-membership-form-block-total_amount">
244 <td class="label">{$form.total_amount.label}</td>
245 <td>{$form.total_amount.html}<br />
46611472 246 <span class="description">{ts}Membership payment amount. A contribution record will be created for this amount.{/ts}</span><div class="totaltaxAmount"></div></td>
6a488035
TO
247 </tr>
248 <tr class="crm-membership-form-block-receive_date">
249 <td class="label">{$form.receive_date.label}</td>
250 <td>{include file="CRM/common/jcalendar.tpl" elementName=receive_date}</td>
251 </tr>
252 <tr class="crm-membership-form-block-payment_instrument_id">
d96cf288 253 <td class="label">{$form.payment_instrument_id.label}<span class="marker"> *</span></td>
d20225bb 254 <td>{$form.payment_instrument_id.html} {help id="payment_instrument_id" file="CRM/Contribute/Page/Tab.hlp"}</td>
6a488035
TO
255 </tr>
256 <tr id="checkNumber" class="crm-membership-form-block-check_number">
257 <td class="label">{$form.check_number.label}</td>
258 <td>{$form.check_number.html|crmAddClass:six}</td>
259 </tr>
260 {if $action neq 2 }
261 <tr class="crm-membership-form-block-trxn_id">
262 <td class="label">{$form.trxn_id.label}</td>
263 <td>{$form.trxn_id.html}</td>
264 </tr>
265 {/if}
266 <tr class="crm-membership-form-block-contribution_status_id">
267 <td class="label">{$form.contribution_status_id.label}</td>
268 <td>{$form.contribution_status_id.html}</td>
269 </tr>
270 </table>
271 </fieldset>
272 </td></tr>
273 {else}
274 <div class="spacer"></div>
275 {/if}
276
277 {if $emailExists and $outBound_option != 2 }
278 <tr id="send-receipt" class="crm-membership-form-block-send_receipt">
279 <td class="label">{$form.send_receipt.label}</td><td>{$form.send_receipt.html}<br />
280 <span class="description">{ts 1=$emailExists}Automatically email a membership confirmation and receipt to %1?{/ts}</span></td>
281 </tr>
282 {elseif $context eq 'standalone' and $outBound_option != 2 }
283 <tr id="email-receipt" style="display:none;">
284 <td class="label">{$form.send_receipt.label}</td><td>{$form.send_receipt.html}<br />
285 <span class="description">{ts}Automatically email a membership confirmation and receipt to {/ts}<span id="email-address"></span>?</span></td>
286 </tr>
287 {/if}
288 <tr id="fromEmail" style="display:none;">
289 <td class="label">{$form.from_email_address.label}</td>
290 <td>{$form.from_email_address.html}</td>
291 </tr>
292 <tr id='notice' style="display:none;">
293 <td class="label">{$form.receipt_text_signup.label}</td>
294 <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>
295 {$form.receipt_text_signup.html|crmAddClass:huge}</td>
296 </tr>
297 </table>
298 <div id="customData"></div>
299 {*include custom data js file*}
300 {include file="CRM/common/customData.tpl"}
301 {literal}
302 <script type="text/javascript">
3cc60a06 303 CRM.$(function($) {
6a488035
TO
304 {/literal}
305 CRM.buildCustomData( '{$customDataType}' );
306 {if $customDataSubType}
307 CRM.buildCustomData( '{$customDataType}', {$customDataSubType} );
308 {/if}
309 {literal}
310 });
311 </script>
312 {/literal}
313 {if $accessContribution and $action eq 2 and $rows.0.contribution_id}
eb3cfcd6 314 <div class="crm-accordion-wrapper">
64c1e6ea 315 <div class="crm-accordion-header">{ts}Related Contributions{/ts}</div>
eb3cfcd6 316 <div class="crm-accordion-body">{include file="CRM/Contribute/Form/Selector.tpl" context="Search"}</div>
317 </div>
318 {/if}
319 {if $softCredit}
320 <div class="crm-accordion-wrapper">
64c1e6ea 321 <div class="crm-accordion-header">{ts}Related Soft Contributions{/ts}</div>
eb3cfcd6 322 <div class="crm-accordion-body">{include file="CRM/Contribute/Page/ContributionSoft.tpl" context="membership"}</div>
323 </div>
6a488035
TO
324 {/if}
325 {/if}
326
327 <div class="spacer"></div>
328 <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
329 </div> <!-- end form-block -->
330
331 {if $action neq 8} {* Jscript additions not need for Delete action *}
332 {if $accessContribution and !$membershipMode AND ($action neq 2 or !$rows.0.contribution_id or $onlinePendingContributionId)}
333
334 {include file="CRM/common/showHideByFieldValue.tpl"
335 trigger_field_id ="record_contribution"
336 trigger_value =""
337 target_element_id ="recordContribution"
338 target_element_type ="table-row"
339 field_type ="radio"
340 invert = 0
341 }
342 {include file="CRM/common/showHideByFieldValue.tpl"
343 trigger_field_id ="payment_instrument_id"
344 trigger_value = '4'
345 target_element_id ="checkNumber"
346 target_element_type ="table-row"
347 field_type ="select"
348 invert = 0
349 }
350 {/if}
351
352 {literal}
353 <script type="text/javascript">
2c407361
CW
354 function setPaymentBlock(mode, checkboxEvent) {
355 var memType = parseInt(cj('#membership_type_id_1').val( ));
356 var isPriceSet = 0;
357
358 if ( cj('#price_set_id').length > 0 && cj('#price_set_id').val() ) {
359 isPriceSet = 1;
360 }
361
362 if ( !memType || isPriceSet ) {
363 return;
364 }
365
366 var allMemberships = {/literal}{$allMembershipInfo}{literal};
367 if ( !mode ) {
368 //check the record_contribution checkbox if membership is a paid one
369 {/literal}{if $action eq 1}{literal}
370 if (!checkboxEvent) {
371 if (allMemberships[memType]['total_amount_numeric'] > 0) {
372 cj('#record_contribution').prop('checked','checked');
373 cj('#recordContribution').show();
374 }
375 else {
376 cj('#record_contribution').prop('checked', false);
377 cj('#recordContribution').hide();
378 }
379 }
380 {/literal}{/if}{literal}
381 }
382
383 // skip this for test and live modes because financial type is set automatically
384 cj("#financial_type_id").val(allMemberships[memType]['financial_type_id']);
385 var term = cj('#num_terms').val();
6f87cd8d 386 var taxRates = '{/literal}{$taxRates}{literal}';
46611472 387 var taxTerm = '{/literal}{$taxTerm}{literal}';
6f87cd8d
PB
388 var taxRates = JSON.parse(taxRates);
389 var taxRate = taxRates[allMemberships[memType]['financial_type_id']];
46611472 390 var currency = '{/literal}{$currency}{literal}';
fea51901 391 var taxAmount = (taxRate/100)*allMemberships[memType]['total_amount_numeric'];
392 taxAmount = isNaN (taxAmount) ? 0:taxAmount;
2c407361 393 if ( term ) {
6f87cd8d
PB
394 if (!taxRate) {
395 var feeTotal = allMemberships[memType]['total_amount_numeric'] * term;
396 }
397 else {
7f7fa13a 398 var feeTotal = Number((taxRate/100) * (allMemberships[memType]['total_amount_numeric'] * term))+Number(allMemberships[memType]['total_amount_numeric'] * term );
6f87cd8d 399 }
7f92cfa9 400 cj("#total_amount").val(CRM.formatMoney(feeTotal, true));
2c407361
CW
401 }
402 else {
7f7fa13a 403 if (taxRate) {
6f87cd8d 404 var feeTotal = parseFloat(Number((taxRate/100) * allMemberships[memType]['total_amount'])+Number(allMemberships[memType]['total_amount_numeric'])).toFixed(2);
7f92cfa9 405 cj("#total_amount").val(CRM.formatMoney(feeTotal, true));
6f87cd8d
PB
406 }
407 else {
46611472 408 var feeTotal = allMemberships[memType]['total_amount'];
7f7fa13a 409 cj("#total_amount").val( allMemberships[memType]['total_amount'] );
6f87cd8d 410 }
2c407361 411 }
fea51901 412 var taxMessage = taxRate!=undefined ? 'Includes '+taxTerm+' amount of '+currency+' '+taxAmount:'';
46611472 413 cj('.totaltaxAmount').html(taxMessage);
2c407361
CW
414 }
415
416
3cc60a06 417 CRM.$(function($) {
6a488035
TO
418 var mode = {/literal}'{$membershipMode}'{literal};
419 if ( !mode ) {
420 // Offline form (mode = false) has the record_contribution checkbox
421 cj('#record_contribution').click( function( ) {
8539f25d 422 if ( cj(this).prop('checked') ) {
6a488035
TO
423 cj('#recordContribution').show( );
424 setPaymentBlock( false, true);
425 }
426 else {
427 cj('#recordContribution').hide( );
428 }
429 });
430 }
431
432 cj('#membership_type_id_1').change( function( ) {
433 setPaymentBlock(mode);
434 });
435 cj('#num_terms').change( function( ) {
436 setPaymentBlock(mode);
437 });
438 setPaymentBlock(mode);
439
440 // show/hide different contact section
441 setDifferentContactBlock();
442 cj('#is_different_contribution_contact').change( function() {
443 setDifferentContactBlock();
444 });
e4444728
DG
445
446 // give option to override end-date for auto-renew memberships
447 {/literal}
448 {if $isRecur && $endDate}
449 cj('#end-date-readonly').show();
450 cj('#end-date-editable').hide();
451 {else}
452 cj('#end-date-readonly').hide();
453 cj('#end-date-editable').show();
454 {/if}
455 {literal}
456
457 cj('#show-end-date').click( function( e ) {
458 e.preventDefault();
459 cj('#end-date-readonly').hide();
460 cj('#end-date-editable').show();
461 });
462
6a488035
TO
463 });
464
465 function setDifferentContactBlock( ) {
466 // show/hide different contact section
8539f25d 467 if ( cj('#is_different_contribution_contact').prop('checked') ) {
6a488035
TO
468 cj('#record-different-contact').show();
469 }
470 else {
471 cj('#record-different-contact').hide();
472 }
473 }
e4444728 474
6a488035
TO
475 </script>
476 {/literal}
477
478 {if ($emailExists and $outBound_option != 2) OR $context eq 'standalone' }
479 {include file="CRM/common/showHideByFieldValue.tpl"
480 trigger_field_id ="send_receipt"
481 trigger_value =""
482 target_element_id ="notice"
483 target_element_type ="table-row"
484 field_type ="radio"
485 invert = 0
486 }
487 {include file="CRM/common/showHideByFieldValue.tpl"
488 trigger_field_id ="send_receipt"
489 trigger_value =""
490 target_element_id ="fromEmail"
491 target_element_type ="table-row"
492 field_type ="radio"
493 invert = 0
494 }
495 {/if}
496 {literal}
497
498 <script type="text/javascript">
499
500 {/literal}{if !$membershipMode}{literal}
501 showHideMemberStatus();
502 function showHideMemberStatus() {
8539f25d 503 if ( cj( "#is_override" ).prop('checked' ) ) {
6a488035
TO
504 cj('#memberStatus').show( );
505 cj('#memberStatus_show').hide( );
506 }
507 else {
508 cj('#memberStatus').hide( );
509 cj('#memberStatus_show').show( );
510 }
511 }
512 {/literal}{/if}
1ed3da9e 513
6a488035
TO
514 {if $context eq 'standalone' and $outBound_option != 2 }
515 {literal}
3cc60a06 516 CRM.$(function($) {
b50fdacc 517 var $form = $("form.{/literal}{$form.formClass}{literal}");
74dd0d90 518 $("#contact_id", $form).change(checkEmail);
6a488035 519 checkEmail( );
6a488035 520
74dd0d90
CW
521 function checkEmail( ) {
522 var data = $("#contact_id", $form).select2('data');
523 if (data && data.extra && data.extra.email && data.extra.email.length) {
524 $("#email-receipt", $form).show();
525 if ($("#send_receipt", $form).is(':checked')) {
526 $("#notice", $form).show();
6a488035 527 }
74dd0d90
CW
528 $("#email-address", $form).html(data.extra.email);
529 }
530 else {
531 $("#email-receipt, #notice", $form).hide();
532 }
6a488035 533 }
74dd0d90 534 });
6a488035 535
6a488035
TO
536 {/literal}
537 {/if}
538
539 {literal}
540 //keep read only always checked.
3cc60a06 541 CRM.$(function($) {
b50fdacc 542 var $form = $("form.{/literal}{$form.formClass}{literal}");
6a488035
TO
543 var allowAutoRenew = {/literal}'{$allowAutoRenew}'{literal};
544 var alreadyAutoRenew = {/literal}'{$alreadyAutoRenew}'{literal};
545 if ( allowAutoRenew || alreadyAutoRenew ) {
74dd0d90
CW
546 $( "#auto_renew" ).click(function( ) {
547 if ( $(this).attr( 'readonly' ) ) {
548 $(this).prop('checked', true );
6a488035
TO
549 }
550 });
551 }
74dd0d90
CW
552
553 {/literal}
554 {if !empty($existingContactMemberships)}
555
556 var alert, memberorgs = {$existingContactMemberships|@json_encode};
557
558 {literal}
559 $("select[name='membership_type_id[0]']").change(checkExistingMemOrg);
560
561
562
563 function checkExistingMemOrg () {
564 alert && alert.close && alert.close();
565 var selectedorg = $("select[name='membership_type_id[0]']").val();
566 if (selectedorg in memberorgs) {
567 var andEndDate = '',
568 endDate = memberorgs[selectedorg].membership_end_date,
569 org = $('option:selected', "select[name='membership_type_id[0]']").text();
570 if (endDate) {
ec2b84a1
CW
571 andEndDate = '{/literal}{ts escape='js' 1='%1'}and end date of %1{/ts}{literal}';
572 andEndDate = ' ' + ts(andEndDate, {1:endDate});
74dd0d90
CW
573 }
574
575 alert = CRM.alert(
576 // Mixing client-side variables with a translated string in smarty is awkward!
577 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})
578 + '<ul><li><a href="' + memberorgs[selectedorg].renewUrl + '">'
ec2b84a1 579 + {/literal}'{ts escape='js'}Renew the existing membership instead{/ts}'
74dd0d90
CW
580 + '</a></li><li><a href="' + memberorgs[selectedorg].membershipTab + '">'
581 + '{ts escape='js'}View all existing and / or expired memberships for this contact{/ts}'{literal}
582 + '</a></li></ul>',
ec2b84a1 583 '{/literal}{ts escape='js'}Duplicate Membership?{/ts}{literal}', 'alert');
74dd0d90
CW
584 }
585 }
586 checkExistingMemOrg();
587 {/literal}
588 {/if}
589
590 {literal}
591
6a488035
TO
592 });
593 {/literal}
594
595 {if $membershipMode or $action eq 2}
596 {literal}
597
598 buildAutoRenew( null, null );
599
600 function buildAutoRenew( membershipType, processorId ) {
601 var mode = {/literal}'{$membershipMode}'{literal};
602 var action = {/literal}'{$action}'{literal};
603
604 //for update lets hide it when not already recurring.
605 if ( action == 2 ) {
606 //user can't cancel auto renew by unchecking.
8539f25d 607 if ( cj("#auto_renew").prop('checked' ) ) {
6a488035
TO
608 cj("#auto_renew").attr( 'readonly', true );
609 }
610 else {
611 cj("#autoRenew").hide( );
612 }
613 }
614
615 //we should do all auto renew for cc memberships.
616 if ( !mode ) return;
617
618 //get the required values in case missing.
619 if ( !processorId ) processorId = cj( '#payment_processor_id' ).val( );
620 if ( !membershipType ) membershipType = parseInt( cj('#membership_type_id_1').val( ) );
621
622 //we don't have both required values.
623 if ( !processorId || !membershipType ) {
8539f25d 624 cj("#auto_renew").prop('checked', false );
6a488035
TO
625 cj("#autoRenew").hide( );
626 return;
627 }
628
629 var recurProcessors = {/literal}{$recurProcessor}{literal};
630 var autoRenewOptions = {/literal}{$autoRenewOptions}{literal};
631 var currentOption = autoRenewOptions[membershipType];
632
633 if ( !currentOption || !recurProcessors[processorId] ) {
8539f25d 634 cj("#auto_renew").prop('checked', false );
6a488035
TO
635 cj("#autoRenew").hide( );
636 return;
637 }
638
639 if ( currentOption == 1 ) {
640 cj("#autoRenew").show( );
641 if ( cj("#auto_renew").attr( 'readonly' ) ) {
8539f25d 642 cj("#auto_renew").prop('checked', false );
6a488035
TO
643 cj("#auto_renew").removeAttr( 'readonly' );
644 }
645 }
646 else if ( currentOption == 2 ) {
647 cj("#autoRenew").show( );
8539f25d 648 cj("#auto_renew").prop('checked', true );
6a488035
TO
649 cj("#auto_renew").attr( 'readonly', true );
650 }
651 else {
8539f25d 652 cj("#auto_renew").prop('checked', false );
6a488035
TO
653 cj("#autoRenew").hide( );
654 }
655
656 //play w/ receipt option.
8539f25d 657 if ( cj("#auto_renew").prop('checked' ) ) {
6a488035 658 cj("#notice").hide( );
8539f25d 659 cj("#send_receipt").prop('checked', false );
6a488035
TO
660 cj("#send-receipt").hide( );
661 }
662 else {
663 cj("#send-receipt").show( );
8539f25d 664 if ( cj("#send_receipt").prop('checked' ) ) {
6a488035
TO
665 cj("#notice").show( );
666 }
667 }
668 }
669 {/literal}
670 {/if}
671
672 {literal}
673 function buildReceiptANDNotice( ) {
8539f25d 674 if ( cj("#auto_renew").prop('checked' ) ) {
6a488035
TO
675 cj("#notice").hide( );
676 cj("#send-receipt").hide( );
677 }
678 else {
679 cj("#send-receipt").show( );
8539f25d 680 if ( cj("#send_receipt").prop('checked' ) ) {
6a488035
TO
681 cj("#notice").show( );
682 }
683 }
684 }
685
686 var customDataType = '{/literal}{$customDataType}{literal}';
687
688 // load form during form rule.
689 {/literal}{if $buildPriceSet}{literal}
690 cj( "#totalAmountORPriceSet" ).hide( );
691 cj( "#mem_type_id" ).hide( );
692 cj('#total_amount').attr("readonly", true);
693 cj( "#num_terms_row" ).hide( );
5a9c4d4a 694 cj(".crm-membership-form-block-financial_type_id-mode").hide();
6a488035
TO
695 {/literal}{/if}{literal}
696
697 function buildAmount( priceSetId ) {
698 if ( !priceSetId ) {
96cfe0d7 699 priceSetId = cj("#price_set_id").val( );
6a488035
TO
700 }
701 var fname = '#priceset';
702 if ( !priceSetId ) {
703 cj('#membership_type_id_1').val(0);
704 CRM.buildCustomData(customDataType, 'null' );
705
706 // hide price set fields.
707 cj( fname ).hide( );
708
709 // show/hide price set amount and total amount.
710 cj( "#mem_type_id").show( );
5384bd2f
AH
711 var choose = "{/literal}{ts}Choose price set{/ts}{literal}";
712 cj("#price_set_id option[value='']").html( choose );
6a488035
TO
713 cj( "#totalAmountORPriceSet" ).show( );
714 cj('#total_amount').removeAttr("readonly");
715 cj( "#num_terms_row").show( );
5a9c4d4a 716 cj(".crm-membership-form-block-financial_type_id-mode").show();
6a488035
TO
717
718 {/literal}{if $allowAutoRenew}{literal}
719 cj('#autoRenew').hide();
720 var autoRenew = cj("#auto_renew");
721 autoRenew.removeAttr( 'readOnly' );
8539f25d 722 autoRenew.prop('checked', false );
6a488035
TO
723 {/literal}{/if}{literal}
724 return;
725 }
726
727 cj( "#total_amount" ).val( '' );
728 cj('#total_amount').attr("readonly", true);
729
730 var dataUrl = {/literal}"{crmURL h=0 q='snippet=4'}"{literal} + '&priceSetId=' + priceSetId;
731
732 var response = cj.ajax({
733 url: dataUrl,
734 async: false
735 }).responseText;
736
737 cj( fname ).show( ).html( response );
738 // freeze total amount text field.
739
740 cj( "#totalAmountORPriceSet" ).hide( );
741 cj( "#mem_type_id" ).hide( );
5384bd2f
AH
742 var manual = "{/literal}{ts}Manual membership and price{/ts}{literal}";
743 cj("#price_set_id option[value='']").html( manual );
6a488035 744 cj( "#num_terms_row" ).hide( );
5a9c4d4a 745 cj(".crm-membership-form-block-financial_type_id-mode").hide();
6a488035
TO
746 }
747
748 buildMaxRelated(cj('#membership_type_id_1', false).val());
749
750 function buildMaxRelated( memType, setDefault ) {
751 var allMemberships = {/literal}{$allMembershipInfo}{literal};
752
753 if ((memType > 0) && (allMemberships[memType]['has_related'])) {
754 if (setDefault) cj('#max_related').val(allMemberships[memType]['max_related']);
755 cj('#maxRelated').show();
f1d5011f
CW
756 var cid = {/literal}{if $contactID}{$contactID}{else}null{/if}{literal};
757 if (cid) {
758 CRM.api('relationship', 'getcount', {contact_id: cid, membership_type_id: memType}, {
c9c41397 759 success: function(result) {
ec2b84a1
CW
760 var relatable;
761 if (result.result === 0) {
762 relatable = '{/literal}{ts escape='js'}No contacts are currently eligible to inherit this relationship.{/ts}{literal}';
c9c41397 763 }
ec2b84a1
CW
764 else if (result.result === 1) {
765 relatable = '{/literal}{ts escape='js'}One contact is currently eligible to inherit this relationship.{/ts}{literal}';
c9c41397 766 }
ec2b84a1
CW
767 else {
768 relatable = '{/literal}{ts escape='js' 1='%1'}%1 contacts are currently eligible to inherit this relationship.{/ts}{literal}';
769 relatable = ts(relatable, {1: result});
770 }
771 cj('#max_related').siblings('.description').append(' ' + relatable);
c9c41397 772 }
773 });
774 }
6a488035
TO
775 } else {
776 cj('#max_related').val('');
777 cj('#maxRelated').hide();
778 }
779 }
780
ae8f569f
CW
781 var lastMembershipTypes = [];
782 var optionsMembershipTypes = [];
6a488035
TO
783
784 // function to load custom data for selected membership types through priceset
785 function processMembershipPriceset( membershipValues, autoRenewOption, reload ) {
ae8f569f 786 var currentMembershipType = [];
6a488035
TO
787 var count = 0;
788 var loadCustomData = 0;
789 if ( membershipValues ) {
790 optionsMembershipTypes = membershipValues;
791 }
792
793 if ( reload ) {
ae8f569f 794 lastMembershipTypes = [];
6a488035
TO
795 {/literal}{if $allowAutoRenew}{literal}
796 cj('#autoRenew').hide();
797 var autoRenew = cj("#auto_renew");
798 autoRenew.removeAttr( 'readOnly' );
8539f25d 799 autoRenew.prop('checked', false );
6a488035
TO
800 if ( autoRenewOption == 1 ) {
801 cj('#autoRenew').show();
802 }
803 else if ( autoRenewOption == 2 ) {
804 autoRenew.attr( 'readOnly', true );
8539f25d 805 autoRenew.prop('checked', true );
6a488035
TO
806 cj('#autoRenew').show();
807 }
808 {/literal}{/if}{literal}
809 }
810
811 cj("input,#priceset select,#priceset").each(function () {
812 if ( cj(this).attr('price') ) {
813 switch( cj(this).attr('type') ) {
814 case 'checkbox':
8539f25d 815 if ( cj(this).prop('checked') ) {
6a488035
TO
816 eval( 'var option = ' + cj(this).attr('price') ) ;
817 var ele = option[0];
818 var memTypeId = optionsMembershipTypes[ele];
819 if ( memTypeId && cj.inArray(optionsMembershipTypes[ele], currentMembershipType) == -1 ) {
820 currentMembershipType[count] = memTypeId;
821 count++;
822 }
823 }
824 if ( reload ) {
825 cj(this).click( function( ) {
826 processMembershipPriceset();
827 });
828 }
829 break;
830
831 case 'radio':
8539f25d 832 if ( cj(this).prop('checked') && cj(this).val() ) {
6a488035
TO
833 var memTypeId = optionsMembershipTypes[cj(this).val()];
834 if ( memTypeId && cj.inArray(memTypeId, currentMembershipType) == -1 ) {
835 currentMembershipType[count] = memTypeId;
836 count++;
837 }
838 }
839 if ( reload ) {
840 cj(this).click( function( ) {
841 processMembershipPriceset();
842 });
843 }
844 break;
845
846 case 'select-one':
847 if ( cj(this).val( ) ) {
848 var memTypeId = optionsMembershipTypes[cj(this).val()];
849 if ( memTypeId && cj.inArray(memTypeId, currentMembershipType) == -1 ) {
850 currentMembershipType[count] = memTypeId;
851 count++;
852 }
853 }
854 if ( reload ) {
855 cj(this).change( function( ) {
856 processMembershipPriceset();
857 });
858 }
859 break;
860 }
861 }
862 });
863
864 for( i in currentMembershipType ) {
865 if ( cj.inArray(currentMembershipType[i], lastMembershipTypes) == -1 ) {
866 loadCustomData = 1;
867 break;
868 }
869 }
870
871 if ( !loadCustomData ) {
872 for( i in lastMembershipTypes) {
873 if ( cj.inArray(lastMembershipTypes[i], currentMembershipType) == -1 ) {
874 loadCustomData = 1;
875 break;
876 }
877 }
878 }
879
880 lastMembershipTypes = currentMembershipType;
881
882 // load custom data only if change in membership type selection
883 if ( !loadCustomData ) {
884 return;
885 }
886
887 subTypeNames = currentMembershipType.join(',');
888 if ( subTypeNames.length < 1 ) {
889 subTypeNames = 'null';
890 }
891
892 CRM.buildCustomData( customDataType, subTypeNames );
893 }
894
895 function enableAmountSection( setContributionType ) {
8539f25d 896 if ( !cj('#record_contribution').prop('checked') ) {
6a488035
TO
897 cj('#record_contribution').click( );
898 cj('#recordContribution').show( );
899 }
900 if ( setContributionType ) {
901 cj('#financial_type_id').val(setContributionType);
902 }
903 }
904 </script>
905 {/literal}
906 {/if} {* closing of delete check if *}
907{/if}{* closing of custom data if *}