Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | {* |
2 | +--------------------------------------------------------------------+ | |
1188c7a8 | 3 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 4 | | | |
1188c7a8 TO |
5 | | This work is published under the GNU AGPLv3 license with some | |
6 | | permitted exceptions and without any warranty. For full license | | |
7 | | and copyright information, see https://civicrm.org/licensing | | |
6a488035 TO |
8 | +--------------------------------------------------------------------+ |
9 | *} | |
10 | {* this template is used for adding/editing/deleting memberships for a contact *} | |
abdb0d27 | 11 | {if $isRecur} |
6a488035 | 12 | <div class="messages status no-popup"> |
34d6cec4 | 13 | {icon icon="fa-info-circle"}{/icon} |
abdb0d27 | 14 | <p>{ts}This membership is set to renew automatically {if $endDate}on {$endDate|crmDate}{/if}. Please be aware that any changes that you make here may not be reflected in the payment processor. Please ensure that you alter the related subscription at the payment processor.{/ts}</p> |
4c98c2ab | 15 | {if $cancelAutoRenew}<p>{ts 1=$cancelAutoRenew}To stop the automatic renewal: |
abdb0d27 WM |
16 | <a href="%1">Cancel auto-renew</a> |
17 | {/ts}</p>{/if} | |
6a488035 TO |
18 | </div> |
19 | {/if} | |
20 | <div class="spacer"></div> | |
39082712 | 21 | {if $priceSetId} |
6a488035 TO |
22 | {include file="CRM/Price/Form/PriceSet.tpl" context="standalone" extends="Membership"} |
23 | {literal} | |
24 | <script type="text/javascript"> | |
3cc60a06 | 25 | CRM.$(function($) { |
ae8f569f | 26 | var membershipValues = []; |
6a488035 TO |
27 | {/literal}{foreach from=$optionsMembershipTypes item=memType key=opId}{literal} |
28 | membershipValues[{/literal}{$opId}{literal}] = {/literal}{$memType}{literal}; | |
29 | {/literal}{/foreach}{literal} | |
30 | processMembershipPriceset(membershipValues, {/literal}{$autoRenewOption}{literal}, 1); | |
31 | {/literal}{if !$membershipMode}{literal} | |
32 | enableAmountSection({/literal}{$contributionType}{literal}); | |
33 | {/literal}{/if}{literal} | |
34 | }); | |
35 | </script> | |
36 | {/literal} | |
37 | {else} | |
38 | {if $membershipMode == 'test' } | |
39 | {assign var=registerMode value="TEST"} | |
40 | {elseif $membershipMode == 'live'} | |
41 | {assign var=registerMode value="LIVE"} | |
42 | {/if} | |
43 | {if !$emailExists and $action neq 8 and $context neq 'standalone'} | |
44 | <div class="messages status no-popup"> | |
34d6cec4 | 45 | {icon icon="fa-info-circle"}{/icon} |
6a488035 TO |
46 | <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> |
47 | </div> | |
48 | {/if} | |
6a488035 | 49 | {if $membershipMode} |
f6eedce7 | 50 | <div class="help"> |
6a488035 TO |
51 | {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} |
52 | </div> | |
53 | {/if} | |
54 | <div class="crm-block crm-form-block crm-membership-form-block"> | |
67121256 PN |
55 | {if $newCredit AND $action EQ 1 AND $membershipMode EQ null} |
56 | <div class="action-link css_right crm-link-credit-card-mode"> | |
57 | {if $contactId} | |
58 | {capture assign=ccModeLink}{crmURL p='civicrm/contact/view/membership' q="reset=1&action=add&cid=`$contactId`&context=`$context`&mode=live"}{/capture} | |
59 | {else} | |
60 | {capture assign=ccModeLink}{crmURL p='civicrm/contact/view/membership' q="reset=1&action=add&context=standalone&mode=live"}{/capture} | |
61 | {/if} | |
13a3d214 | 62 | <a class="open-inline-noreturn action-item crm-hover-button" href="{$ccModeLink}"><i class="crm-i fa-credit-card" aria-hidden="true"></i> {ts}submit credit card membership{/ts}</a> |
67121256 PN |
63 | </div> |
64 | {/if} | |
6a488035 TO |
65 | <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="top"}</div> |
66 | {if $action eq 8} | |
67 | <div class="messages status no-popup"> | |
34d6cec4 | 68 | {icon icon="fa-info-circle"}{/icon} |
59c798c9 | 69 | {$deleteMessage} |
6a488035 TO |
70 | </div> |
71 | {else} | |
72 | <table class="form-layout-compressed"> | |
ac0ef1dc | 73 | <tr class="crm-membership-form-contact-id"> |
74 | <td class="label">{$form.contact_id.label}</td> | |
75 | <td>{$form.contact_id.html}</td> | |
76 | </tr> | |
6a488035 TO |
77 | <tr class="crm-membership-form-block-membership_type_id"> |
78 | <td class="label">{$form.membership_type_id.label}</td> | |
595ae4d0 WM |
79 | <td id="mem_type_id-readonly"> |
80 | <span id="membership_type_id_0-readonly"></span> : <span id="membership_type_id_1-readonly"></span> | |
81 | <span id="mem-type-override"> | |
82 | <a href="#" class="crm-hover-button action-item override-mem-type" id="show-mem-type"> | |
83 | {ts}Override organization and type{/ts} | |
84 | </a> | |
85 | {help id="override_membership_type"} | |
86 | </span> | |
87 | </td> | |
88 | <td id="mem_type_id-editable"><span id='mem_type_id'>{$form.membership_type_id.html}</span> | |
6a488035 TO |
89 | {if $hasPriceSets} |
90 | <span id='totalAmountORPriceSet'> {ts}OR{/ts}</span> | |
91 | <span id='selectPriceSet'>{$form.price_set_id.html}</span> | |
92 | {if $buildPriceSet && $priceSet} | |
93 | <div id="priceset"><br/>{include file="CRM/Price/Form/PriceSet.tpl" extends="Membership"}</div> | |
94 | {else} | |
95 | <div id="priceset" class="hiddenElement"></div> | |
96 | {/if} | |
97 | {/if} | |
98 | {if $member_is_test} {ts}(test){/ts}{/if}<br /> | |
5384bd2f | 99 | <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 |
100 | </td> |
101 | </tr> | |
102 | <tr id="maxRelated" class="crm-membership-form-block-max_related"> | |
103 | <td class="label">{$form.max_related.label}</td> | |
104 | <td>{$form.max_related.html}<br /> | |
a67d7de7 | 105 | <span class="description">{ts}Maximum number of related memberships (leave blank for unlimited).{/ts} <span id="eligibleRelated"></span></span> |
6a488035 TO |
106 | </td> |
107 | </tr> | |
108 | {if $action eq 1} | |
109 | <tr id="num_terms_row" class="crm-membership-form-block-num_terms"> | |
110 | <td class="label">{$form.num_terms.label}</td> | |
111 | <td> {$form.num_terms.html}<br /> | |
112 | <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> | |
113 | </td> | |
114 | </tr> | |
115 | {/if} | |
116 | <tr class="crm-membership-form-block-source"> | |
117 | <td class="label">{$form.source.label}</td> | |
118 | <td> {$form.source.html}<br /> | |
119 | <span class="description">{ts}Source of this membership. This value is searchable.{/ts}</span></td> | |
120 | </tr> | |
121 | ||
122 | {* CRM-7362 --add campaign to membership *} | |
123 | {include file="CRM/Campaign/Form/addCampaignToComponent.tpl" | |
124 | campaignTrClass="crm-membership-form-block-campaign_id"} | |
125 | ||
59c798c9 | 126 | <tr class="crm-membership-form-block-join_date"><td class="label">{$form.join_date.label}</td><td>{$form.join_date.html} |
6a488035 TO |
127 | <br /> |
128 | <span class="description">{ts}When did this contact first become a member?{/ts}</span></td></tr> | |
59c798c9 | 129 | <tr class="crm-membership-form-block-start_date"><td class="label">{$form.start_date.label}</td><td>{$form.start_date.html} |
6a488035 TO |
130 | <br /> |
131 | <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> | |
132 | <tr class="crm-membership-form-block-end_date"><td class="label">{$form.end_date.label}</td> | |
e4444728 DG |
133 | <td id="end-date-readonly"> |
134 | {$endDate|crmDate} | |
135 | <a href="#" class="crm-hover-button action-item override-date" id="show-end-date"> | |
580eab37 | 136 | {ts}Override end date{/ts} |
e4444728 DG |
137 | </a> |
138 | {help id="override_end_date"} | |
139 | </td> | |
140 | <td id="end-date-editable"> | |
59c798c9 | 141 | {$form.end_date.html} |
6a488035 | 142 | <br /> |
e4444728 DG |
143 | <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> |
144 | </td> | |
145 | </tr> | |
378ea9fc | 146 | {if !$membershipMode} |
e136f704 O |
147 | <tr> |
148 | <td class="label">{$form.is_override.label} {help id="id-status-override"}</td> | |
149 | <td> | |
150 | <span id="is-override">{$form.is_override.html}</span> | |
151 | <span id="status-override-end-date">{$form.status_override_end_date.html}</span> | |
152 | </td> | |
153 | </tr> | |
6a488035 TO |
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 /> | |
e136f704 | 163 | <span class="description">{ts}When <strong>Status Override</strong> is active, the selected status will remain in force (it will NOT be subject to membership status rules) until it is cancelled or become inactive.{/ts}</span></td></tr> |
6a488035 | 164 | {/if} |
186a737c EM |
165 | |
166 | {if $accessContribution and !$membershipMode AND ($action neq 2 or (!$rows.0.contribution_id AND !$softCredit) or $onlinePendingContributionId)} | |
6a488035 TO |
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> | |
b58b2053 | 174 | {/if} |
c3ec2f80 | 175 | {include file="CRM/Member/Form/MembershipCommon.tpl"} |
8c80f3f9 | 176 | {if $emailExists and $isEmailEnabledForSite} |
6a488035 | 177 | <tr id="send-receipt" class="crm-membership-form-block-send_receipt"> |
cbc5bc5c WM |
178 | <td class="label">{$form.send_receipt.label}</td> |
179 | <td> | |
180 | {$form.send_receipt.html}<br /> | |
181 | <span class="description"> | |
182 | {ts 1=$emailExists}Automatically email a membership confirmation and receipt to %1? OR if the payment is from a different contact, this email will only go to them.{/ts} | |
183 | <span class="auto-renew-text">{ts}For auto-renewing memberships the emails are sent when each payment is received{/ts}</span> | |
184 | </span> | |
185 | </td> | |
6a488035 | 186 | </tr> |
cbc5bc5c | 187 | {elseif $context eq 'standalone' and $isEmailEnabledForSite} |
6a488035 | 188 | <tr id="email-receipt" style="display:none;"> |
cbc5bc5c WM |
189 | <td class="label">{$form.send_receipt.label}</td> |
190 | <td> | |
191 | {$form.send_receipt.html}<br /> | |
192 | <span class="description"> | |
193 | {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} | |
194 | <span class="auto-renew-text">{ts}For auto-renewing memberships the emails are sent when each payment is received{/ts}</span> | |
195 | </span> | |
196 | </td> | |
6a488035 TO |
197 | </tr> |
198 | {/if} | |
beac1417 | 199 | <tr id="fromEmail" style="display: none" class="crm-contactEmail-form-block-fromEmailAddress crm-email-element"> |
6a488035 | 200 | <td class="label">{$form.from_email_address.label}</td> |
beac1417 | 201 | <td>{$form.from_email_address.html} {help id="id-from_email" file="CRM/Contact/Form/Task/Email.hlp" isAdmin=$isAdmin}</td> |
6a488035 TO |
202 | </tr> |
203 | <tr id='notice' style="display:none;"> | |
186a737c | 204 | <td class="label">{$form.receipt_text.label}</td> |
6a488035 | 205 | <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> |
186a737c | 206 | {$form.receipt_text.html|crmAddClass:huge}</td> |
6a488035 TO |
207 | </tr> |
208 | </table> | |
67bb6495 | 209 | {include file="CRM/common/customDataBlock.tpl"} |
6a488035 | 210 | {if $accessContribution and $action eq 2 and $rows.0.contribution_id} |
eb3cfcd6 | 211 | <div class="crm-accordion-wrapper"> |
64c1e6ea | 212 | <div class="crm-accordion-header">{ts}Related Contributions{/ts}</div> |
669fc25e CR |
213 | <div class="crm-accordion-body"> |
214 | {include file="CRM/Contribute/Form/Selector.tpl" context="Search"} | |
215 | <script type="text/javascript"> | |
216 | var membershipID = {$entityID}; | |
217 | var contactID = {$contactId}; | |
218 | {literal} | |
219 | CRM.$(function($) { | |
220 | CRM.loadPage( | |
221 | CRM.url( | |
222 | 'civicrm/membership/recurring-contributions', | |
223 | { | |
224 | reset: 1, | |
225 | membershipID: membershipID, | |
226 | cid: contactID | |
227 | }, | |
228 | 'back' | |
229 | ), | |
230 | { | |
231 | target : '#membership-recurring-contributions', | |
232 | dialog : false | |
233 | } | |
234 | ); | |
235 | }); | |
236 | {/literal} | |
237 | </script> | |
238 | <div id="membership-recurring-contributions"></div> | |
239 | </div> | |
eb3cfcd6 | 240 | </div> |
241 | {/if} | |
242 | {if $softCredit} | |
243 | <div class="crm-accordion-wrapper"> | |
64c1e6ea | 244 | <div class="crm-accordion-header">{ts}Related Soft Contributions{/ts}</div> |
eb3cfcd6 | 245 | <div class="crm-accordion-body">{include file="CRM/Contribute/Page/ContributionSoft.tpl" context="membership"}</div> |
246 | </div> | |
6a488035 TO |
247 | {/if} |
248 | {/if} | |
249 | ||
6a488035 TO |
250 | <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div> |
251 | </div> <!-- end form-block --> | |
252 | ||
253 | {if $action neq 8} {* Jscript additions not need for Delete action *} | |
254 | {if $accessContribution and !$membershipMode AND ($action neq 2 or !$rows.0.contribution_id or $onlinePendingContributionId)} | |
255 | ||
256 | {include file="CRM/common/showHideByFieldValue.tpl" | |
257 | trigger_field_id ="record_contribution" | |
258 | trigger_value ="" | |
259 | target_element_id ="recordContribution" | |
260 | target_element_type ="table-row" | |
261 | field_type ="radio" | |
262 | invert = 0 | |
263 | } | |
6a488035 TO |
264 | {/if} |
265 | ||
266 | {literal} | |
267 | <script type="text/javascript"> | |
2c407361 CW |
268 | function setPaymentBlock(mode, checkboxEvent) { |
269 | var memType = parseInt(cj('#membership_type_id_1').val( )); | |
270 | var isPriceSet = 0; | |
2b339b18 | 271 | var existingAmount = {/literal}{if !empty($onlinePendingContributionId)}1{else}0{/if}{literal}; |
2c407361 CW |
272 | |
273 | if ( cj('#price_set_id').length > 0 && cj('#price_set_id').val() ) { | |
274 | isPriceSet = 1; | |
275 | } | |
276 | ||
277 | if ( !memType || isPriceSet ) { | |
278 | return; | |
279 | } | |
280 | ||
281 | var allMemberships = {/literal}{$allMembershipInfo}{literal}; | |
2b339b18 | 282 | if (!mode) { |
2c407361 CW |
283 | //check the record_contribution checkbox if membership is a paid one |
284 | {/literal}{if $action eq 1}{literal} | |
285 | if (!checkboxEvent) { | |
286 | if (allMemberships[memType]['total_amount_numeric'] > 0) { | |
287 | cj('#record_contribution').prop('checked','checked'); | |
288 | cj('#recordContribution').show(); | |
289 | } | |
290 | else { | |
291 | cj('#record_contribution').prop('checked', false); | |
292 | cj('#recordContribution').hide(); | |
293 | } | |
294 | } | |
295 | {/literal}{/if}{literal} | |
296 | } | |
297 | ||
298 | // skip this for test and live modes because financial type is set automatically | |
299 | cj("#financial_type_id").val(allMemberships[memType]['financial_type_id']); | |
300 | var term = cj('#num_terms').val(); | |
8838f818 CW |
301 | var taxRates = {/literal}{$taxRates}{literal}; |
302 | var taxTerm = {/literal}{$taxTerm|@json_encode}{literal}; | |
6f87cd8d | 303 | var taxRate = taxRates[allMemberships[memType]['financial_type_id']]; |
9d3a6f9f | 304 | var currency = {/literal}{$currency_symbol|@json_encode}{literal}; |
4f7df658 EM |
305 | var taxAmount = (taxRate/100)*allMemberships[memType]['total_amount_numeric']; |
306 | taxAmount = isNaN (taxAmount) ? 0:taxAmount; | |
307 | if (term) { | |
6f87cd8d PB |
308 | if (!taxRate) { |
309 | var feeTotal = allMemberships[memType]['total_amount_numeric'] * term; | |
310 | } | |
311 | else { | |
4f7df658 EM |
312 | var feeTotal = Number((taxRate/100) * (allMemberships[memType]['total_amount_numeric'] * term))+Number |
313 | (allMemberships[memType]['total_amount_numeric'] * term ); | |
6f87cd8d | 314 | } |
7f92cfa9 | 315 | cj("#total_amount").val(CRM.formatMoney(feeTotal, true)); |
2c407361 CW |
316 | } |
317 | else { | |
2b339b18 | 318 | if (taxRate) { |
6f87cd8d | 319 | var feeTotal = parseFloat(Number((taxRate/100) * allMemberships[memType]['total_amount'])+Number(allMemberships[memType]['total_amount_numeric'])).toFixed(2); |
2b339b18 | 320 | cj("#total_amount").val(CRM.formatMoney(feeTotal, true)); |
6f87cd8d PB |
321 | } |
322 | else { | |
2b339b18 EM |
323 | var feeTotal = allMemberships[memType]['total_amount']; |
324 | if (!existingAmount) { | |
325 | // CRM-16680 don't set amount if there is an existing contribution. | |
326 | cj("#total_amount").val(allMemberships[memType]['total_amount']); | |
327 | } | |
6f87cd8d | 328 | } |
2c407361 | 329 | } |
fea51901 | 330 | var taxMessage = taxRate!=undefined ? 'Includes '+taxTerm+' amount of '+currency+' '+taxAmount:''; |
46611472 | 331 | cj('.totaltaxAmount').html(taxMessage); |
2c407361 CW |
332 | } |
333 | ||
334 | ||
3cc60a06 | 335 | CRM.$(function($) { |
6a488035 TO |
336 | var mode = {/literal}'{$membershipMode}'{literal}; |
337 | if ( !mode ) { | |
338 | // Offline form (mode = false) has the record_contribution checkbox | |
339 | cj('#record_contribution').click( function( ) { | |
8539f25d | 340 | if ( cj(this).prop('checked') ) { |
6a488035 TO |
341 | cj('#recordContribution').show( ); |
342 | setPaymentBlock( false, true); | |
343 | } | |
344 | else { | |
345 | cj('#recordContribution').hide( ); | |
346 | } | |
347 | }); | |
348 | } | |
349 | ||
350 | cj('#membership_type_id_1').change( function( ) { | |
351 | setPaymentBlock(mode); | |
352 | }); | |
353 | cj('#num_terms').change( function( ) { | |
354 | setPaymentBlock(mode); | |
355 | }); | |
356 | setPaymentBlock(mode); | |
357 | ||
358 | // show/hide different contact section | |
359 | setDifferentContactBlock(); | |
360 | cj('#is_different_contribution_contact').change( function() { | |
361 | setDifferentContactBlock(); | |
362 | }); | |
186a737c | 363 | |
595ae4d0 WM |
364 | // give option to override membership type for auto-renew memberships - dev/core#1331 |
365 | {/literal} | |
366 | {if $isRecur} | |
367 | cj('#membership_type_id_0-readonly').text(cj('#membership_type_id_0 option:selected').text()); | |
368 | cj('#membership_type_id_1-readonly').text(cj('#membership_type_id_1 option:selected').text()); | |
369 | cj('#mem_type_id-readonly').show(); | |
370 | cj('#mem_type_id-editable').hide(); | |
371 | {else} | |
372 | cj('#mem_type_id-readonly').hide(); | |
373 | cj('#mem_type_id-editable').show(); | |
374 | {/if} | |
375 | {literal} | |
376 | ||
377 | cj('#show-mem-type').click( function( e ) { | |
378 | e.preventDefault(); | |
379 | cj('#mem_type_id-readonly').hide(); | |
380 | cj('#mem_type_id-editable').show(); | |
381 | }); | |
382 | ||
e4444728 DG |
383 | // give option to override end-date for auto-renew memberships |
384 | {/literal} | |
385 | {if $isRecur && $endDate} | |
386 | cj('#end-date-readonly').show(); | |
387 | cj('#end-date-editable').hide(); | |
388 | {else} | |
389 | cj('#end-date-readonly').hide(); | |
390 | cj('#end-date-editable').show(); | |
391 | {/if} | |
392 | {literal} | |
393 | ||
394 | cj('#show-end-date').click( function( e ) { | |
395 | e.preventDefault(); | |
396 | cj('#end-date-readonly').hide(); | |
397 | cj('#end-date-editable').show(); | |
398 | }); | |
399 | ||
6a488035 TO |
400 | }); |
401 | ||
402 | function setDifferentContactBlock( ) { | |
403 | // show/hide different contact section | |
8539f25d | 404 | if ( cj('#is_different_contribution_contact').prop('checked') ) { |
6a488035 TO |
405 | cj('#record-different-contact').show(); |
406 | } | |
407 | else { | |
408 | cj('#record-different-contact').hide(); | |
409 | } | |
410 | } | |
186a737c | 411 | |
8c80f3f9 | 412 | function showEmailOptions() { |
413 | {/literal} | |
414 | // @todo emailExists refers to the primary contact for the page. | |
415 | // elsewhere some script determines if there is a paying contact the | |
416 | // email should go to instead (e.g gift membership). This should be checked for here | |
417 | // and that merged into that code as currently behaviour is inconsistent. | |
fa9a2fb7 SM |
418 | var emailExists = {$emailExists|json_encode}; |
419 | var isStandalone = {if $context == 'standalone'}true{else}false{/if}; | |
5817a4e7 | 420 | var isEmailEnabledForSite = {if $isEmailEnabledForSite}true{else}false{/if}; |
6a488035 | 421 | |
8c80f3f9 | 422 | {literal} |
423 | var isEmailable = (isEmailEnabledForSite && (emailExists || isStandalone)); | |
6a488035 | 424 | |
8c80f3f9 | 425 | if (isEmailable && cj('#send_receipt').prop('checked') && !cj('#auto_renew').prop('checked')) { |
426 | // Hide extra message and from email for recurring as they cannot be stored until use. | |
427 | cj('#notice').show(); | |
428 | cj('#fromEmail').show(); | |
429 | } | |
430 | else { | |
431 | cj('#notice').hide(); | |
432 | cj('#fromEmail').hide(); | |
433 | } | |
434 | } | |
435 | </script> | |
6a488035 TO |
436 | <script type="text/javascript"> |
437 | ||
438 | {/literal}{if !$membershipMode}{literal} | |
e136f704 O |
439 | cj( "#is_override" ).change(function() { |
440 | showHideMemberStatus(); | |
441 | }); | |
442 | ||
6a488035 TO |
443 | showHideMemberStatus(); |
444 | function showHideMemberStatus() { | |
e136f704 O |
445 | var isOverride = cj( "#is_override" ).val(); |
446 | switch (isOverride) { | |
447 | case '0': | |
448 | cj('#memberStatus').hide(); | |
449 | cj('#memberStatus_show').show(); | |
450 | cj('#status-override-end-date').hide(); | |
451 | break; | |
452 | case '1': | |
453 | cj('#memberStatus').show(); | |
454 | cj('#memberStatus_show').hide(); | |
455 | cj('#status-override-end-date').hide(); | |
456 | break; | |
457 | case '2': | |
458 | cj('#memberStatus').show(); | |
459 | cj('#memberStatus_show').hide(); | |
460 | cj('#status-override-end-date').show(); | |
461 | break; | |
462 | default : | |
463 | cj('#memberStatus').hide( ); | |
464 | cj('#memberStatus_show').show( ); | |
465 | cj('#status-override-end-date').hide(); | |
466 | break; | |
6a488035 TO |
467 | } |
468 | } | |
469 | {/literal}{/if} | |
1ed3da9e | 470 | |
8c80f3f9 | 471 | {if $context eq 'standalone' and $isEmailEnabledForSite } |
6a488035 | 472 | {literal} |
3cc60a06 | 473 | CRM.$(function($) { |
b50fdacc | 474 | var $form = $("form.{/literal}{$form.formClass}{literal}"); |
74dd0d90 | 475 | $("#contact_id", $form).change(checkEmail); |
6a488035 | 476 | checkEmail( ); |
6a488035 | 477 | |
74dd0d90 CW |
478 | function checkEmail( ) { |
479 | var data = $("#contact_id", $form).select2('data'); | |
480 | if (data && data.extra && data.extra.email && data.extra.email.length) { | |
481 | $("#email-receipt", $form).show(); | |
482 | if ($("#send_receipt", $form).is(':checked')) { | |
483 | $("#notice", $form).show(); | |
6a488035 | 484 | } |
74dd0d90 CW |
485 | $("#email-address", $form).html(data.extra.email); |
486 | } | |
487 | else { | |
488 | $("#email-receipt, #notice", $form).hide(); | |
489 | } | |
6a488035 | 490 | } |
74dd0d90 | 491 | }); |
6a488035 | 492 | |
6a488035 TO |
493 | {/literal} |
494 | {/if} | |
495 | ||
496 | {literal} | |
497 | //keep read only always checked. | |
3cc60a06 | 498 | CRM.$(function($) { |
b50fdacc | 499 | var $form = $("form.{/literal}{$form.formClass}{literal}"); |
6a488035 TO |
500 | var allowAutoRenew = {/literal}'{$allowAutoRenew}'{literal}; |
501 | var alreadyAutoRenew = {/literal}'{$alreadyAutoRenew}'{literal}; | |
502 | if ( allowAutoRenew || alreadyAutoRenew ) { | |
74dd0d90 CW |
503 | $( "#auto_renew" ).click(function( ) { |
504 | if ( $(this).attr( 'readonly' ) ) { | |
505 | $(this).prop('checked', true ); | |
6a488035 | 506 | } |
8c80f3f9 | 507 | showEmailOptions(); |
6a488035 TO |
508 | }); |
509 | } | |
74dd0d90 CW |
510 | |
511 | {/literal} | |
512 | {if !empty($existingContactMemberships)} | |
513 | ||
514 | var alert, memberorgs = {$existingContactMemberships|@json_encode}; | |
515 | ||
516 | {literal} | |
517 | $("select[name='membership_type_id[0]']").change(checkExistingMemOrg); | |
518 | ||
519 | ||
520 | ||
521 | function checkExistingMemOrg () { | |
522 | alert && alert.close && alert.close(); | |
523 | var selectedorg = $("select[name='membership_type_id[0]']").val(); | |
524 | if (selectedorg in memberorgs) { | |
525 | var andEndDate = '', | |
526 | endDate = memberorgs[selectedorg].membership_end_date, | |
527 | org = $('option:selected', "select[name='membership_type_id[0]']").text(); | |
528 | if (endDate) { | |
ec2b84a1 CW |
529 | andEndDate = '{/literal}{ts escape='js' 1='%1'}and end date of %1{/ts}{literal}'; |
530 | andEndDate = ' ' + ts(andEndDate, {1:endDate}); | |
74dd0d90 CW |
531 | } |
532 | ||
533 | alert = CRM.alert( | |
534 | // Mixing client-side variables with a translated string in smarty is awkward! | |
824530a5 | 535 | ts({/literal}'{ts escape='js'}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}) |
74dd0d90 | 536 | + '<ul><li><a href="' + memberorgs[selectedorg].renewUrl + '">' |
ec2b84a1 | 537 | + {/literal}'{ts escape='js'}Renew the existing membership instead{/ts}' |
74dd0d90 CW |
538 | + '</a></li><li><a href="' + memberorgs[selectedorg].membershipTab + '">' |
539 | + '{ts escape='js'}View all existing and / or expired memberships for this contact{/ts}'{literal} | |
540 | + '</a></li></ul>', | |
ec2b84a1 | 541 | '{/literal}{ts escape='js'}Duplicate Membership?{/ts}{literal}', 'alert'); |
74dd0d90 CW |
542 | } |
543 | } | |
544 | checkExistingMemOrg(); | |
545 | {/literal} | |
546 | {/if} | |
547 | ||
548 | {literal} | |
549 | ||
6a488035 TO |
550 | }); |
551 | {/literal} | |
552 | ||
553 | {if $membershipMode or $action eq 2} | |
38f6574d | 554 | buildAutoRenew( null, null, '{$membershipMode}'); |
555 | {/if} | |
8c80f3f9 | 556 | {literal} |
557 | function buildAutoRenew( membershipType, processorId, mode ) { | |
6a488035 TO |
558 | var action = {/literal}'{$action}'{literal}; |
559 | ||
560 | //for update lets hide it when not already recurring. | |
8838f818 | 561 | if (action == 2) { |
6a488035 | 562 | //user can't cancel auto renew by unchecking. |
8838f818 CW |
563 | if (cj("#auto_renew").prop('checked')) { |
564 | cj("#auto_renew").attr('readonly', true); | |
6a488035 TO |
565 | } |
566 | else { | |
567 | cj("#autoRenew").hide( ); | |
568 | } | |
569 | } | |
570 | ||
571 | //we should do all auto renew for cc memberships. | |
8838f818 CW |
572 | if (!mode) { |
573 | return; | |
574 | } | |
6a488035 TO |
575 | |
576 | //get the required values in case missing. | |
8838f818 CW |
577 | if (!processorId) { |
578 | processorId = cj( '#payment_processor_id' ).val( ); | |
579 | } | |
580 | if (!membershipType) { | |
581 | membershipType = parseInt( cj('#membership_type_id_1').val( ) ); | |
582 | } | |
6a488035 TO |
583 | |
584 | //we don't have both required values. | |
8838f818 CW |
585 | if (!processorId || !membershipType) { |
586 | cj("#auto_renew").prop('checked', false); | |
587 | cj("#autoRenew").hide(); | |
8c80f3f9 | 588 | showEmailOptions(); |
6a488035 TO |
589 | return; |
590 | } | |
591 | ||
592 | var recurProcessors = {/literal}{$recurProcessor}{literal}; | |
593 | var autoRenewOptions = {/literal}{$autoRenewOptions}{literal}; | |
594 | var currentOption = autoRenewOptions[membershipType]; | |
595 | ||
8838f818 | 596 | if (!currentOption || !recurProcessors[processorId]) { |
8539f25d | 597 | cj("#auto_renew").prop('checked', false ); |
8c80f3f9 | 598 | cj("#autoRenew").hide(); |
6a488035 TO |
599 | return; |
600 | } | |
601 | ||
8838f818 CW |
602 | if (currentOption == 1) { |
603 | cj("#autoRenew").show(); | |
604 | if (cj("#auto_renew").attr('readonly')) { | |
605 | cj("#auto_renew").prop('checked', false).removeAttr('readonly'); | |
6a488035 TO |
606 | } |
607 | } | |
608 | else if ( currentOption == 2 ) { | |
8838f818 CW |
609 | cj("#autoRenew").show(); |
610 | cj("#auto_renew").prop('checked', true).attr('readonly', true); | |
6a488035 TO |
611 | } |
612 | else { | |
8838f818 | 613 | cj("#auto_renew").prop('checked', false); |
6a488035 TO |
614 | cj("#autoRenew").hide( ); |
615 | } | |
8c80f3f9 | 616 | showEmailOptions(); |
6a488035 | 617 | } |
6a488035 | 618 | |
8838f818 | 619 | var customDataType = {/literal}{$customDataType|@json_encode}{literal}; |
6a488035 TO |
620 | |
621 | // load form during form rule. | |
622 | {/literal}{if $buildPriceSet}{literal} | |
8838f818 CW |
623 | cj("#totalAmountORPriceSet, #mem_type_id, #num_terms_row, .crm-membership-form-block-financial_type_id-mode").hide(); |
624 | cj('#total_amount').attr("readonly", true); | |
6a488035 TO |
625 | {/literal}{/if}{literal} |
626 | ||
627 | function buildAmount( priceSetId ) { | |
8838f818 CW |
628 | if (!priceSetId) { |
629 | priceSetId = cj("#price_set_id").val(); | |
630 | } | |
6a488035 TO |
631 | var fname = '#priceset'; |
632 | if ( !priceSetId ) { | |
633 | cj('#membership_type_id_1').val(0); | |
62e185a9 | 634 | CRM.buildCustomData(customDataType, null); |
6a488035 TO |
635 | |
636 | // hide price set fields. | |
637 | cj( fname ).hide( ); | |
638 | ||
639 | // show/hide price set amount and total amount. | |
640 | cj( "#mem_type_id").show( ); | |
8838f818 | 641 | var choose = "{/literal}{ts escape='js'}Choose price set{/ts}{literal}"; |
5384bd2f | 642 | cj("#price_set_id option[value='']").html( choose ); |
6a488035 TO |
643 | cj( "#totalAmountORPriceSet" ).show( ); |
644 | cj('#total_amount').removeAttr("readonly"); | |
645 | cj( "#num_terms_row").show( ); | |
5a9c4d4a | 646 | cj(".crm-membership-form-block-financial_type_id-mode").show(); |
6a488035 TO |
647 | |
648 | {/literal}{if $allowAutoRenew}{literal} | |
8838f818 CW |
649 | cj('#autoRenew').hide(); |
650 | cj("#auto_renew").removeAttr('readOnly').prop('checked', false ); | |
6a488035 TO |
651 | {/literal}{/if}{literal} |
652 | return; | |
653 | } | |
654 | ||
8838f818 | 655 | cj( "#total_amount" ).val('').attr("readonly", true); |
6a488035 TO |
656 | |
657 | var dataUrl = {/literal}"{crmURL h=0 q='snippet=4'}"{literal} + '&priceSetId=' + priceSetId; | |
658 | ||
659 | var response = cj.ajax({ | |
660 | url: dataUrl, | |
661 | async: false | |
662 | }).responseText; | |
663 | ||
664 | cj( fname ).show( ).html( response ); | |
665 | // freeze total amount text field. | |
666 | ||
667 | cj( "#totalAmountORPriceSet" ).hide( ); | |
668 | cj( "#mem_type_id" ).hide( ); | |
8838f818 | 669 | var manual = "{/literal}{ts escape='js'}Manual membership and price{/ts}{literal}"; |
5384bd2f | 670 | cj("#price_set_id option[value='']").html( manual ); |
6a488035 | 671 | cj( "#num_terms_row" ).hide( ); |
5a9c4d4a | 672 | cj(".crm-membership-form-block-financial_type_id-mode").hide(); |
6a488035 TO |
673 | } |
674 | ||
675 | buildMaxRelated(cj('#membership_type_id_1', false).val()); | |
676 | ||
677 | function buildMaxRelated( memType, setDefault ) { | |
678 | var allMemberships = {/literal}{$allMembershipInfo}{literal}; | |
679 | ||
680 | if ((memType > 0) && (allMemberships[memType]['has_related'])) { | |
681 | if (setDefault) cj('#max_related').val(allMemberships[memType]['max_related']); | |
682 | cj('#maxRelated').show(); | |
f1d5011f CW |
683 | var cid = {/literal}{if $contactID}{$contactID}{else}null{/if}{literal}; |
684 | if (cid) { | |
685 | CRM.api('relationship', 'getcount', {contact_id: cid, membership_type_id: memType}, { | |
c9c41397 | 686 | success: function(result) { |
ec2b84a1 CW |
687 | var relatable; |
688 | if (result.result === 0) { | |
689 | relatable = '{/literal}{ts escape='js'}No contacts are currently eligible to inherit this relationship.{/ts}{literal}'; | |
c9c41397 | 690 | } |
ec2b84a1 CW |
691 | else if (result.result === 1) { |
692 | relatable = '{/literal}{ts escape='js'}One contact is currently eligible to inherit this relationship.{/ts}{literal}'; | |
c9c41397 | 693 | } |
ec2b84a1 CW |
694 | else { |
695 | relatable = '{/literal}{ts escape='js' 1='%1'}%1 contacts are currently eligible to inherit this relationship.{/ts}{literal}'; | |
696 | relatable = ts(relatable, {1: result}); | |
697 | } | |
a67d7de7 | 698 | cj('#eligibleRelated').text(relatable); |
c9c41397 | 699 | } |
700 | }); | |
701 | } | |
6a488035 TO |
702 | } else { |
703 | cj('#max_related').val(''); | |
704 | cj('#maxRelated').hide(); | |
705 | } | |
706 | } | |
707 | ||
ae8f569f CW |
708 | var lastMembershipTypes = []; |
709 | var optionsMembershipTypes = []; | |
6a488035 TO |
710 | |
711 | // function to load custom data for selected membership types through priceset | |
712 | function processMembershipPriceset( membershipValues, autoRenewOption, reload ) { | |
ae8f569f | 713 | var currentMembershipType = []; |
6a488035 TO |
714 | var count = 0; |
715 | var loadCustomData = 0; | |
716 | if ( membershipValues ) { | |
717 | optionsMembershipTypes = membershipValues; | |
718 | } | |
719 | ||
720 | if ( reload ) { | |
ae8f569f | 721 | lastMembershipTypes = []; |
6a488035 TO |
722 | {/literal}{if $allowAutoRenew}{literal} |
723 | cj('#autoRenew').hide(); | |
724 | var autoRenew = cj("#auto_renew"); | |
8838f818 CW |
725 | autoRenew.removeAttr('readOnly').prop('checked', false ); |
726 | if (autoRenewOption == 1) { | |
6a488035 TO |
727 | cj('#autoRenew').show(); |
728 | } | |
8838f818 CW |
729 | else if (autoRenewOption == 2) { |
730 | autoRenew.attr('readOnly', true).prop('checked', true ); | |
6a488035 TO |
731 | cj('#autoRenew').show(); |
732 | } | |
733 | {/literal}{/if}{literal} | |
734 | } | |
735 | ||
736 | cj("input,#priceset select,#priceset").each(function () { | |
737 | if ( cj(this).attr('price') ) { | |
738 | switch( cj(this).attr('type') ) { | |
739 | case 'checkbox': | |
8539f25d | 740 | if ( cj(this).prop('checked') ) { |
6a488035 TO |
741 | eval( 'var option = ' + cj(this).attr('price') ) ; |
742 | var ele = option[0]; | |
743 | var memTypeId = optionsMembershipTypes[ele]; | |
744 | if ( memTypeId && cj.inArray(optionsMembershipTypes[ele], currentMembershipType) == -1 ) { | |
745 | currentMembershipType[count] = memTypeId; | |
746 | count++; | |
747 | } | |
748 | } | |
749 | if ( reload ) { | |
750 | cj(this).click( function( ) { | |
751 | processMembershipPriceset(); | |
752 | }); | |
753 | } | |
754 | break; | |
755 | ||
756 | case 'radio': | |
8539f25d | 757 | if ( cj(this).prop('checked') && cj(this).val() ) { |
6a488035 TO |
758 | var memTypeId = optionsMembershipTypes[cj(this).val()]; |
759 | if ( memTypeId && cj.inArray(memTypeId, currentMembershipType) == -1 ) { | |
760 | currentMembershipType[count] = memTypeId; | |
761 | count++; | |
762 | } | |
763 | } | |
764 | if ( reload ) { | |
765 | cj(this).click( function( ) { | |
766 | processMembershipPriceset(); | |
767 | }); | |
768 | } | |
769 | break; | |
770 | ||
771 | case 'select-one': | |
772 | if ( cj(this).val( ) ) { | |
773 | var memTypeId = optionsMembershipTypes[cj(this).val()]; | |
774 | if ( memTypeId && cj.inArray(memTypeId, currentMembershipType) == -1 ) { | |
775 | currentMembershipType[count] = memTypeId; | |
776 | count++; | |
777 | } | |
778 | } | |
779 | if ( reload ) { | |
780 | cj(this).change( function( ) { | |
781 | processMembershipPriceset(); | |
782 | }); | |
783 | } | |
784 | break; | |
785 | } | |
786 | } | |
787 | }); | |
788 | ||
789 | for( i in currentMembershipType ) { | |
790 | if ( cj.inArray(currentMembershipType[i], lastMembershipTypes) == -1 ) { | |
791 | loadCustomData = 1; | |
792 | break; | |
793 | } | |
794 | } | |
795 | ||
796 | if ( !loadCustomData ) { | |
797 | for( i in lastMembershipTypes) { | |
798 | if ( cj.inArray(lastMembershipTypes[i], currentMembershipType) == -1 ) { | |
799 | loadCustomData = 1; | |
800 | break; | |
801 | } | |
802 | } | |
803 | } | |
804 | ||
805 | lastMembershipTypes = currentMembershipType; | |
806 | ||
807 | // load custom data only if change in membership type selection | |
808 | if ( !loadCustomData ) { | |
809 | return; | |
810 | } | |
811 | ||
812 | subTypeNames = currentMembershipType.join(','); | |
813 | if ( subTypeNames.length < 1 ) { | |
4929bbc2 | 814 | subTypeNames = null; |
6a488035 TO |
815 | } |
816 | ||
62e185a9 | 817 | CRM.buildCustomData(customDataType, subTypeNames); |
6a488035 TO |
818 | } |
819 | ||
820 | function enableAmountSection( setContributionType ) { | |
8539f25d | 821 | if ( !cj('#record_contribution').prop('checked') ) { |
6a488035 TO |
822 | cj('#record_contribution').click( ); |
823 | cj('#recordContribution').show( ); | |
824 | } | |
825 | if ( setContributionType ) { | |
826 | cj('#financial_type_id').val(setContributionType); | |
827 | } | |
828 | } | |
829 | </script> | |
830 | {/literal} | |
831 | {/if} {* closing of delete check if *} | |
832 | {/if}{* closing of custom data if *} |