Merge pull request #17441 from eileenmcnaughton/email2
[civicrm-core.git] / templates / CRM / Event / Form / ParticipantFeeSelection.tpl
1 {*
2 +--------------------------------------------------------------------+
3 | Copyright CiviCRM LLC. All rights reserved. |
4 | |
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 |
8 +--------------------------------------------------------------------+
9 *}
10 {* This template is used to change selections of fees for a participant *}
11 {literal}
12 <script type='text/javascript'>
13 function display(totalfee) {
14 {/literal}{if $optionFullTotalAmount}
15 totalfee += {$optionFullTotalAmount};{/if}
16 {literal};
17 // totalfee is monetary, round it to 2 decimal points so it can
18 // go as a float - CRM-13491
19 totalfee = Math.round(totalfee*100)/100;
20 // note : some variables used used here are global variables defined inside Calculate.tpl
21 var totalEventFee = formatMoney( totalfee, 2, seperator, thousandMarker);
22 cj('#pricevalue').html("<b>"+symbol+"</b> "+totalEventFee);
23 scriptfee = totalfee;
24 scriptarray = price;
25 cj('#total_amount').val(totalfee);
26 ( totalfee < 0 ) ? cj('table#pricelabel').addClass('disabled') : cj('table#pricelabel').removeClass('disabled');
27
28 // populate the balance amount div
29 // change the status selections according to updated selections
30 populatebalanceFee(totalfee, false);
31 }
32
33 function populatebalanceFee(updatedAmt, onlyStatusUpdate) {
34 // updatedAmt is: selected line total
35
36 // assign statuses
37 var partiallyPaid = {/literal}{$partiallyPaid}{literal};
38 var pendingRefund = {/literal}{$pendingRefund}{literal};
39 var participantStatus = {/literal}{$participantStatus}{literal};
40
41 // fee actually paid
42 var feePaid = {/literal}{$feePaid}{literal};
43
44 var updatedTotalLineTotal = updatedAmt;
45
46 {/literal}{if $totalLineTotal}{literal}
47 // line total of current participant stored in DB
48 var linetotal = {/literal}{$lineItemTotal}{literal};
49
50 // line total of all the participants
51 var totalLineTotal = {/literal}{$totalLineTotal}{literal};
52 updatedTotalLineTotal = totalLineTotal + (updatedAmt - linetotal);
53 {/literal}{/if}{literal}
54
55 // calculate the balance amount using total paid and updated amount
56 var balanceAmt = updatedTotalLineTotal - feePaid;
57
58 // change the status selections according to updated selections
59 if (balanceAmt > 0 && feePaid != 0) {
60 cj('#status_id').val(partiallyPaid);
61 }
62 else if(balanceAmt < 0) {
63 cj('#status_id').val(pendingRefund);
64 }
65 else {
66 cj('#status_id').val(participantStatus);
67 }
68
69 if (!onlyStatusUpdate) {
70 balanceAmt = formatMoney(balanceAmt, 2, seperator, thousandMarker);
71 cj('#balance-fee').text(symbol+" "+balanceAmt);
72 }
73 }
74
75 CRM.$(function($) {
76 var updatedFeeUnFormatted = $('#pricevalue').text();
77 var updatedAmt = parseFloat(updatedFeeUnFormatted.replace(/[^0-9-.]/g, ''));
78
79 populatebalanceFee(updatedAmt, true);
80 });
81
82 {/literal}
83 </script>
84 <h3>Change Registration Selections</h3>
85
86 <div class="crm-block crm-form-block crm-payment-form-block">
87 <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
88 {if !$email}
89 <div class="messages status no-popup">
90 <i class="crm-i fa-info-circle" aria-hidden="true"></i>&nbsp;{ts}You will not be able to send an automatic email receipt for this payment because there is no email address recorded for this contact. If you want a receipt to be sent when this payment is recorded, click Cancel and then click Edit from the Summary tab to add an email address before recording the payment.{/ts}
91 </div>
92 {/if}
93 <table class="form-layout">
94 <tr>
95 <td class="font-size12pt label"><strong>{ts}Participant{/ts}</strong></td><td class="font-size12pt"><strong>{$displayName}</strong></td>
96 </tr>
97 <tr>
98 <td class='label'>{ts}Event{/ts}</td><td>{$eventName}</td>
99 </tr>
100 <tr class="crm-participant-form-block-status_id">
101 <td class="label">{$form.status_id.label}</td>
102 <td>{$form.status_id.html}</td>
103 </tr>
104 {if $lineItem}
105 <tr class="crm-event-eventfees-form-block-line_items">
106 <td class="label">{ts}Current Selections{/ts}</td>
107 <td>{include file="CRM/Price/Page/LineItem.tpl" context="Event"}</td>
108 </tr>
109 {/if}
110 </table>
111
112 {if $priceSet.fields}
113 <fieldset id="priceset" class="crm-group priceset-group">
114 <table class='form-layout'>
115 <tr class="crm-event-eventfees-form-block-price_set_amount">
116 <td class="label" style="padding-top: 10px;">{$form.amount.label}</td>
117 <td class="view-value"><table class="form-layout">{include file="CRM/Price/Form/PriceSet.tpl" extends="Event" noCalcValueDisplay=0 context="participant"}</table></td>
118 </tr>
119 {if $paymentInfo}
120 <tr><td></td><td>
121 <div class='crm-section'>
122 <div class='label'>{ts}Updated Fee(s){/ts}</div><div id="pricevalue" class='content updated-fee'></div>
123 <div class='label'>{ts}Total Paid{/ts}</div>
124 <div class='content'>
125 {$paymentInfo.paid|crmMoney}<br/>
126 <a class="crm-hover-button action-item crm-popup medium-popup" href='{crmURL p="civicrm/payment" q="view=transaction&action=browse&cid=`$contactId`&id=`$paymentInfo.id`&component=`$paymentInfo.component`&context=transaction"}'><i class="crm-i fa-list-alt" aria-hidden="true"></i> {ts}view payments{/ts}</a>
127 </div>
128 <div class='label'><strong>{ts}Balance Owed{/ts}</strong></div><div class='content'><strong id='balance-fee'></strong></div>
129 </div>
130 {include file='CRM/Price/Form/Calculate.tpl' currencySymbol=$currencySymbol noCalcValueDisplay=1 displayOveride='true'}
131 {/if}
132 </table>
133 </fieldset>
134 {/if}
135 {if $email}
136 <fieldset id="email-receipt"><legend>{ts}Participant Confirmation{/ts}</legend>
137 <table class="form-layout" style="width:auto;">
138 <tr class="crm-event-eventfees-form-block-send_receipt">
139 <td class="label">{ts}Send Confirmation{/ts}</td>
140 <td>{$form.send_receipt.html}<br>
141 <span class="description">{ts 1=$email}Automatically email a confirmation to %1?{/ts}</span>
142 </td>
143 </tr>
144 <tr id="from-email" class="crm-event-eventfees-form-block-from_email_address">
145 <td class="label">{$form.from_email_address.label}</td>
146 <td>{$form.from_email_address.html} {help id="id-from_email" file="CRM/Contact/Form/Task/Email.hlp" isAdmin=$isAdmin}</td>
147 </tr>
148 <tr id='notice' class="crm-event-eventfees-form-block-receipt_text">
149 <td class="label">{$form.receipt_text.label}</td>
150 <td><span class="description">
151 {ts}Enter a message you want included at the beginning of the confirmation email. EXAMPLE: 'We have made the changes you requested to your registration.'{/ts}
152 </span><br />
153 {$form.receipt_text.html|crmAddClass:huge}
154 </td>
155 </tr>
156 </table>
157 </fieldset>
158 {/if}
159 <fieldset>
160 <table class="form-layout">
161 <tr class="crm-participant-form-block-note">
162 <td class="label">{$form.note.label}</td><td>{$form.note.html}</td>
163 </tr>
164 </table>
165 </fieldset>
166 <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
167 </div>
168 {if $email}
169 {include file="CRM/common/showHideByFieldValue.tpl"
170 trigger_field_id ="send_receipt"
171 trigger_value =""
172 target_element_id ="notice"
173 target_element_type ="table-row"
174 field_type ="radio"
175 invert = 0
176 }
177 {include file="CRM/common/showHideByFieldValue.tpl"
178 trigger_field_id ="send_receipt"
179 trigger_value =""
180 target_element_id ="from-email"
181 target_element_type ="table-row"
182 field_type ="radio"
183 invert = 0
184 }
185 {/if}
186 {literal}
187 <script type='text/javascript'>
188 CRM.$(function($) {
189 var $form = $('form.{/literal}{$form.formClass}{literal}');
190 cj('.total_amount-section').remove();
191
192 cj($form).submit(function(e) {
193 var partiallyPaid = {/literal}{$partiallyPaid}{literal};
194 var pendingRefund = {/literal}{$pendingRefund}{literal};
195 var statusId = cj('#status_id').val();
196 var statusLabel = cj('#status_id option:selected').text();
197 var balanceFee = cj('#balance-fee').text();
198
199 // fee actually paid
200 var feePaid = {/literal}{$feePaid}{literal};
201
202 balanceFee = parseFloat(balanceFee.replace(/[^0-9-.]/g, ''));
203
204 if ((balanceFee > 0 && feePaid != 0) && statusId != partiallyPaid) {
205 var result = confirm('Balance is owing for the updated selections. Expected participant status is \'Partially paid\'. Are you sure you want to set the participant status to ' + statusLabel + ' ? Click OK to continue, Cancel to change your entries.');
206 if (result == false) {
207 e.preventDefault();
208 }
209 }
210 else if ((balanceFee < 0 && feePaid != 0) && statusId != pendingRefund) {
211 var result = confirm('Balance is overpaid for the updated selections. Expected participant status is \'Pending refund\'. Are you sure you want to set the participant status to ' + statusLabel + ' ? Click OK to continue, Cancel to change your entries');
212 if (result == false) {
213 e.preventDefault();
214 }
215 }
216 });
217 });
218 </script>
219 {/literal}