Merge pull request #12639 from aniesshsethh/issue_314
[civicrm-core.git] / templates / CRM / Pledge / Form / Pledge.tpl
1 {*
2 +--------------------------------------------------------------------+
3 | CiviCRM version 5 |
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC (c) 2004-2019 |
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 pledge *}
27 {if $showAdditionalInfo and $formType }
28 {include file="CRM/Contribute/Form/AdditionalInfo/$formType.tpl"}
29 {else}
30 {if !$email and $action neq 8 and $context neq 'standalone'}
31 <div class="messages status no-popup">
32 <div class="icon inform-icon"></div>
33 <p>{ts}You will not be able to send an acknowledgment for this pledge because there is no email address recorded for this contact. If you want a acknowledgment to be sent when this pledge is recorded, click Cancel and then click Edit from the Summary tab to add an email address before recording the pledge.{/ts}</p>
34 </div>
35 {/if}
36 {if $action EQ 2}
37 {* Check if current Total Pledge Amount is different from original pledge amount. *}
38 {math equation="x / y" x=$amount y=$installments format="%.2f" assign="currentInstallment"}
39 {* Check if current Total Pledge Amount is different from original pledge amount. *}
40 {if $currentInstallment NEQ $eachPaymentAmount}
41 {assign var=originalPledgeAmount value=`$installments*$eachPaymentAmount`}
42 {/if}
43 {/if}
44 <div class="crm-block crm-form-block crm-pledge-form-block">
45 <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="top"}</div>
46 {if $action eq 8}
47 <div class="messages status no-popup">
48 <div class="icon inform-icon"></div>&nbsp;
49 <span class="font-red bold">{ts}WARNING: Deleting this pledge will also delete any related pledge payments.{/ts} {ts}This action cannot be undone.{/ts}</span>
50 <p>{ts}Consider cancelling the pledge instead if you want to maintain an audit trail and avoid losing payment data. To set the pledge status to Cancelled and cancel any not-yet-paid pledge payments, first click Cancel on this form. Then click the more &gt; link from the pledge listing, and select the Cancel action.{/ts}</p>
51 </div>
52 {else}
53 <table class="form-layout-compressed">
54 {if $context eq 'standalone'}
55 <tr class="crm-pledge-form-contact-id">
56 <td class="label">{$form.contact_id.label}</td>
57 <td>{$form.contact_id.html}</td>
58 </tr>
59 {else}
60 <tr class="crm-pledge-form-block-displayName">
61 <td class="font-size12pt right"><strong>{ts}Pledge by{/ts}</strong></td>
62 <td class="font-size12pt"><strong>{$displayName}</strong></td>
63 </tr>
64 {/if}
65 <tr class="crm-pledge-form-block-amount">
66 <td class="label">{$form.amount.label}</td>
67 <td>
68 <span>{$form.currency.html|crmAddClass:eight}&nbsp;{$form.amount.html|crmAddClass:eight}</span>
69 {if $originalPledgeAmount}<div class="messages status no-popup"><div class="icon inform-icon"></div>&nbsp;{ts 1=$originalPledgeAmount|crmMoney:$currency} Pledge total has changed due to payment adjustments. Original pledge amount was %1.{/ts}</div>{/if}
70 </td>
71 </tr>
72 <tr class="crm-pledge-form-block-installments">
73 <td class="label">{$form.installments.label}</td>
74 <td>{$form.installments.html} {ts}installments of{/ts}
75 <span class='currency-symbol'>
76 {if $action eq 1 or $isPending}
77 {$form.eachPaymentAmount.html|crmMoney:$currency}
78 {elseif $action eq 2 and !$isPending}
79 {$eachPaymentAmount|crmMoney:$currency}
80 {/if}
81 </span>&nbsp;{ts}every{/ts}&nbsp;{$form.frequency_interval.html}&nbsp;{$form.frequency_unit.html}
82 </td>
83 </tr>
84 <tr class="crm-pledge-form-block-frequency_day">
85 <td class="label nowrap">{$form.frequency_day.label}</td>
86 <td>{$form.frequency_day.html} {ts}day of the period{/ts}<br />
87 <span class="description">{ts}This applies to weekly, monthly and yearly payments.{/ts}</span>
88 </td>
89 </tr>
90 <tr class="crm-pledge-form-block-create_date">
91 <td class="label">{$form.create_date.label}</td>
92 <td>
93 {$form.create_date.html}<br />
94 <span class="description">{ts}Date when pledge was made by the contributor.{/ts}</span>
95 </td>
96 </tr>
97
98 <tr class="crm-pledge-form-block-start_date">
99 <td class="label">{$form.start_date.label}</td>
100 <td>
101 {$form.start_date.html}<br />
102 <span class="description">{ts}Date of first pledge payment.{/ts}</span>
103 </td>
104 </tr>
105
106 {if $email and $outBound_option != 2}
107 {if $form.is_acknowledge }
108 <tr class="crm-pledge-form-block-is_acknowledge">
109 <td class="label">{$form.is_acknowledge.label}</td>
110 <td>{$form.is_acknowledge.html}<br />
111 <span class="description">{ts 1=$email}Automatically email an acknowledgment of this pledge to %1?{/ts}</span>
112 </td>
113 </tr>
114 {/if}
115 {elseif $context eq 'standalone' and $outBound_option != 2 }
116 <tr id="acknowledgment-receipt" style="display:none;">
117 <td class="label">{$form.is_acknowledge.label}</td>
118 <td>
119 {$form.is_acknowledge.html} <span class="description">{ts 1='<span id="email-address"></span>'}Automatically email an acknowledgment of this pledge to %1?{/ts}</span>
120 </td>
121 </tr>
122 {/if}
123 <tr id="fromEmail" style="display:none;">
124 <td class="label">{$form.from_email_address.label}</td>
125 <td>{$form.from_email_address.html} {help id="id-from_email" file="CRM/Contact/Form/Task/Email.hlp" isAdmin=$isAdmin}</td>
126 </tr>
127 <tr id="acknowledgeDate">
128 <td class="label" class="crm-pledge-form-block-acknowledge_date">{$form.acknowledge_date.label}</td>
129 <td>
130 {$form.acknowledge_date.html}<br />
131 <span class="description">{ts}Date when an acknowledgment of the pledge was sent.{/ts}</span>
132 </td>
133 </tr>
134 <tr class="crm-pledge-form-block-financial_type_id">
135 <td class="label">{$form.financial_type_id.label}</td>
136 <td>{$form.financial_type_id.html}<br />
137 <span class="description">{ts}Sets the default financial type for payments against this pledge.{/ts}</span>
138 </td>
139 </tr>
140
141 {* CRM-7362 --add campaign *}
142 {include file="CRM/Campaign/Form/addCampaignToComponent.tpl"
143 campaignTrClass="crm-pledge-form-block-campaign_id"}
144
145 <tr class="crm-pledge-form-block-contribution_page_id">
146 <td class="label">{$form.contribution_page_id.label}</td>
147 <td>{$form.contribution_page_id.html}<br />
148 <span class="description">{ts}Select an Online Contribution page that the user can access to make self-service pledge payments. (Only Online Contribution pages configured to include the Pledge option are listed.){/ts}</span>
149 </td>
150 </tr>
151
152 <tr class="crm-pledge-form-block-status">
153 <td class="label"><label>{ts}Pledge Status{/ts}</label></td>
154 <td class="view-value">{$status}<br />
155 <span class="description">{ts}Pledges are "Pending" until the first payment is received. Once a payment is received, status is "In Progress" until all scheduled payments are completed. Overdue pledges are ones with payment(s) past due.{/ts}</span>
156 </td>
157 </tr>
158 <tr>
159 <td colspan=2>{include file="CRM/Custom/Form/CustomData.tpl"}</td>
160 </tr>
161 </table>
162 {literal}
163 <script type="text/javascript">
164 // bind first click of accordion header to load crm-accordion-body with snippet
165 // everything else taken care of by $().crm-accordions()
166 CRM.$(function($) {
167 $('.crm-ajax-accordion .crm-accordion-header').one('click', function() {
168 loadPanes($(this).attr('id'));
169 });
170 $('#currency').on('change', function() {
171 replaceCurrency($('#currency option:selected').text());
172 });
173 $('.crm-ajax-accordion:not(.collapsed) .crm-accordion-header').each(function(index) {
174 loadPanes($(this).attr('id'));
175 });
176
177 function replaceCurrency(val) {
178 var symbol = '';
179 var eachPaymentAmout = $('#eachPaymentAmount');
180 var pos = val.indexOf("(") + 1;
181 if (pos) {
182 symbol = val.slice(pos, val.lastIndexOf(")"));
183 }
184 $('.currency-symbol').text(symbol).append("&nbsp;").append(eachPaymentAmout);
185 }
186
187 // load panes function calls for snippet based on id of crm-accordion-header
188 function loadPanes( id ) {
189 var url = "{/literal}{crmURL p='civicrm/contact/view/pledge' q='snippet=4&formType=' h=0}{literal}" + id;
190 {/literal}
191 {if $contributionMode}
192 url = url + "&mode={$contributionMode}";
193 {/if}
194 {literal}
195 if ( ! $('div.'+id).html() ) {
196 var loading = '<img src="{/literal}{$config->resourceBase}i/loading.gif{literal}" alt="{/literal}{ts escape='js'}loading{/ts}{literal}" />&nbsp;{/literal}{ts escape='js'}Loading{/ts}{literal}...';
197 $('div.'+id).html(loading);
198 $.ajax({
199 url : url,
200 success: function(data) { $('div.'+id).html(data).trigger('crmLoad'); }
201 });
202 }
203 }
204 });
205 </script>
206 {/literal}
207
208
209 <div class="accordion ui-accordion ui-widget ui-helper-reset">
210 {foreach from=$allPanes key=paneName item=paneValue}
211 <div class="crm-accordion-wrapper crm-ajax-accordion crm-{$paneValue.id}-accordion {if $paneValue.open neq 'true'}collapsed{/if}">
212 <div class="crm-accordion-header" id="{$paneValue.id}">
213 {$paneName}
214 </div><!-- /.crm-accordion-header -->
215 <div class="crm-accordion-body">
216 <div class="{$paneValue.id}"></div>
217 </div><!-- /.crm-accordion-body -->
218 </div><!-- /.crm-accordion-wrapper -->
219
220 {/foreach}
221 </div>
222 {/if} {* not delete mode if*}
223
224 <br />
225 <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
226 </div>
227 {literal}
228 <script type="text/javascript">
229
230 function verify( ) {
231 if (cj('#is_acknowledge').is(':checked')) {
232 var emailAddress = '{/literal}{$email}{literal}';
233 if ( !emailAddress ) {
234 var emailAddress = cj('#email-address').html();
235 }
236 var message = '{/literal}{ts escape="js" 1="%1"}Click OK to save this Pledge record AND send an acknowledgment to %1 now.{/ts}{literal}';
237 return confirm(ts(message, {1: emailAddress}));
238 }
239 }
240
241 function calculatedPaymentAmount( ) {
242 var thousandMarker = {/literal}{crmSetting name="monetaryThousandSeparator" group="CiviCRM Localization"}{literal};
243 var seperator = '{/literal}{$config->monetaryDecimalPoint}{literal}';
244 var amount = document.getElementById("amount").value;
245 // replace all thousandMarker and change the seperator to a dot
246 amount = amount.replace(thousandMarker,'').replace(seperator,'.');
247 var installments = document.getElementById("installments").value;
248 if ( installments != '' && installments != NaN) {
249 amount = amount/installments;
250 var installmentAmount = formatMoney( amount, 2, seperator, thousandMarker );
251 document.getElementById("eachPaymentAmount").value = installmentAmount;
252 }
253 }
254
255 function formatMoney (amount, c, d, t){
256 var n = amount,
257 c = isNaN(c = Math.abs(c)) ? 2 : c,
258 d = d == undefined ? "," : d,
259 t = t == undefined ? "." : t, s = n < 0 ? "-" : "",
260 i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "",
261 j = (j = i.length) > 3 ? j % 3 : 0;
262 return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
263 };
264
265 {/literal}
266 {if $context eq 'standalone' and $outBound_option != 2 }
267 {literal}
268 CRM.$(function($) {
269 var $form = $("form.{/literal}{$form.formClass}{literal}");
270 $("#contact_id", $form).change(checkEmail);
271 checkEmail( );
272
273 function checkEmail( ) {
274 var data = $("#contact_id", $form).select2('data');
275 if (data && data.extra && data.extra.email && data.extra.email.length) {
276 $("#acknowledgment-receipt", $form).show();
277 $("#email-address", $form).html(data.extra.email);
278 }
279 else {
280 $("#acknowledgment-receipt", $form).hide();
281 }
282 }
283
284 showHideByValue( 'is_acknowledge', '', 'acknowledgeDate', 'table-row', 'radio', true);
285 showHideByValue( 'is_acknowledge', '', 'fromEmail', 'table-row', 'radio', false );
286 });
287
288 {/literal}
289 {/if}
290 </script>
291
292 {if $email and $outBound_option != 2}
293 {include file="CRM/common/showHideByFieldValue.tpl"
294 trigger_field_id ="is_acknowledge"
295 trigger_value =""
296 target_element_id ="acknowledgeDate"
297 target_element_type ="table-row"
298 field_type ="radio"
299 invert = 1
300 }
301 {include file="CRM/common/showHideByFieldValue.tpl"
302 trigger_field_id ="is_acknowledge"
303 trigger_value =""
304 target_element_id ="fromEmail"
305 target_element_type ="table-row"
306 field_type ="radio"
307 invert = 0
308 }
309 {/if}
310 {/if}
311 {* closing of main custom data if *}