Merge pull request #12385 from mattwire/test_transactions
[civicrm-core.git] / templates / CRM / Financial / Form / BatchTransaction.tpl
1 {*
2 +--------------------------------------------------------------------+
3 | CiviCRM version 5 |
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC (c) 2004-2018 |
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 batch transaction screen, assign/remove transactions to batch *}
27 {if in_array($batchStatus, array('Open', 'Reopened'))}
28 <div class="crm-form-block crm-search-form-block">
29 <div class="crm-accordion-wrapper crm-batch_transaction_search-accordion collapsed">
30 <div class="crm-accordion-header crm-master-accordion-header">
31 {ts}Edit Search Criteria{/ts}
32 </div>
33 <div class="crm-accordion-body">
34 <div id="searchForm" class="crm-block crm-form-block crm-contact-custom-search-activity-search-form-block">
35 <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="top"}</div>
36 <table class="form-layout-compressed">
37 <tr>
38 <td class="font-size12pt" colspan="2">
39 {$form.sort_name.label}<br>
40 {$form.sort_name.html|crmAddClass:'twenty'}
41 </td>
42 </tr>
43 <tr>
44 {if $form.contact_tags}
45 <td>
46 <label>{ts}Contributor Tag(s){/ts}</label><br>
47 {$form.contact_tags.html}
48 </td>
49 {else}
50 <td>&nbsp;</td>
51 {/if}
52 {if $form.group}
53 <td><label>{ts}Contributor Group(s){/ts}</label><br>
54 {$form.group.html}
55 </td>
56 {else}
57 <td>&nbsp;</td>
58 {/if}
59 </tr>
60 {include file="CRM/Contribute/Form/Search/Common.tpl"}
61 </table>
62 <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
63 </div>
64 </div>
65 </div>
66 </div>
67 {if in_array($batchStatus, array('Open', 'Reopened'))}
68 <div class="form-layout-compressed">{$form.trans_assign.html}&nbsp;{$form.submit.html}</div><br/>
69 {/if}
70 <div id="ltype">
71 <p></p>
72 <div class="form-item">
73 {strip}
74 <table id="crm-transaction-selector-assign-{$entityID}" cellpadding="0" cellspacing="0" border="0">
75 <thead>
76 <tr>
77 <th class="crm-transaction-checkbox">{if in_array($batchStatus, array('Open', 'Reopened'))}{$form.toggleSelect.html}{/if}</th>
78 <th class="crm-contact-type"></th>
79 <th class="crm-contact-name">{ts}Name{/ts}</th>
80 <th class="crm-amount">{ts}Amount{/ts}</th>
81 <th class="crm-trxnID">{ts}Trxn ID{/ts}</th>
82 <th class="crm-trxn_date">{ts}Payment/Transaction Date{/ts}</th>
83 <th class="crm-received">{ts}Contribution Date{/ts}</th>
84 <th class="crm-payment-method">{ts}Pay Method{/ts}</th>
85 <th class="crm-status">{ts}Status{/ts}</th>
86 <th class="crm-type">{ts}Financial Type{/ts}</th>
87 <th class="crm-transaction-links"></th>
88 </tr>
89 </thead>
90 </table>
91 {/strip}
92 </div>
93 </div>
94 {/if}
95
96 {literal}
97 <script type="text/javascript">
98 CRM.$(function($) {
99 CRM.$('#_qf_BatchTransaction_submit-top, #_qf_BatchTransaction_submit-bottom').click(function() {
100 CRM.$('.crm-batch_transaction_search-accordion:not(.collapsed)').crmAccordionToggle();
101 });
102 var batchStatus = {/literal}{$statusID}{literal};
103 {/literal}{if $validStatus}{literal}
104 // build transaction listing only for open/reopened batches
105 var paymentInstrumentID = {/literal}{if $paymentInstrumentID neq null}{$paymentInstrumentID}{else}'null'{/if}{literal};
106 if (paymentInstrumentID != 'null') {
107 buildTransactionSelectorAssign( true );
108 }
109 else {
110 buildTransactionSelectorAssign( false );
111 }
112 buildTransactionSelectorRemove();
113 CRM.$('#_qf_BatchTransaction_submit-bottom, #_qf_BatchTransaction_submit-top').click( function() {
114 buildTransactionSelectorAssign( true );
115 return false;
116 });
117
118 CRM.$("#trans_assign").prop('disabled',true);
119 CRM.$("#trans_remove").prop('disabled',true);
120 CRM.$('#crm-transaction-selector-assign-{/literal}{$entityID}{literal} #toggleSelect').click( function() {
121 enableActions('x');
122 });
123 CRM.$('#crm-transaction-selector-remove-{/literal}{$entityID}{literal} #toggleSelects').click( function() {
124 enableActions('y');
125 });
126 CRM.$('#Go').click( function() {
127 return selectAction("trans_assign","toggleSelect", "crm-transaction-selector-assign-{/literal}{$entityID}{literal} input[id^='mark_x_']");
128 });
129 CRM.$('#GoRemove').click( function() {
130 return selectAction("trans_remove","toggleSelects", "crm-transaction-selector-remove-{/literal}{$entityID}{literal} input[id^='mark_y_']");
131 });
132 CRM.$('#Go').click( function() {
133 if (CRM.$("#trans_assign" ).val() != "" && CRM.$("input[id^='mark_x_']").is(':checked')) {
134 bulkAssignRemove('Assign');
135 }
136 return false;
137 });
138 CRM.$('#GoRemove').click( function() {
139 if (CRM.$("#trans_remove" ).val() != "" && CRM.$("input[id^='mark_y_']").is(':checked')) {
140 bulkAssignRemove('Remove');
141 }
142 return false;
143 });
144 CRM.$("#crm-transaction-selector-assign-{/literal}{$entityID}{literal} input[id^='mark_x_']").click( function() {
145 enableActions('x');
146 });
147 CRM.$("#crm-transaction-selector-remove-{/literal}{$entityID}{literal} input[id^='mark_y_']").click( function() {
148 enableActions('y');
149 });
150
151 CRM.$("#crm-transaction-selector-assign-{/literal}{$entityID}{literal} #toggleSelect").click( function() {
152 toggleFinancialSelections('#toggleSelect', 'assign');
153 });
154 CRM.$("#crm-transaction-selector-remove-{/literal}{$entityID}{literal} #toggleSelects").click( function() {
155 toggleFinancialSelections('#toggleSelects', 'remove');
156 });
157 {/literal}{else}{literal}
158 buildTransactionSelectorRemove();
159 {/literal}{/if}{literal}
160 });
161
162 function enableActions( type ) {
163 if (type == 'x') {
164 CRM.$("#trans_assign").prop('disabled',false);
165 }
166 else {
167 CRM.$("#trans_remove").prop('disabled',false);
168 }
169 }
170
171 function toggleFinancialSelections(toggleID, toggleClass) {
172 var mark = 'x';
173 if (toggleClass == 'remove') {
174 mark = 'y';
175 }
176 if (CRM.$("#crm-transaction-selector-" + toggleClass + "-{/literal}{$entityID}{literal} " + toggleID).is(':checked')) {
177 CRM.$("#crm-transaction-selector-" + toggleClass + "-{/literal}{$entityID}{literal} input[id^='mark_" + mark + "_']").prop('checked',true);
178 }
179 else {
180 CRM.$("#crm-transaction-selector-" + toggleClass + "-{/literal}{$entityID}{literal} input[id^='mark_" + mark + "_']").prop('checked',false);
181 }
182 }
183
184 function buildTransactionSelectorAssign(filterSearch) {
185 var columns = '';
186 var sourceUrl = {/literal}'{crmURL p="civicrm/ajax/rest" h=0 q="className=CRM_Financial_Page_AJAX&fnName=getFinancialTransactionsList&snippet=4&context=financialBatch&entityID=$entityID&notPresent=1&statusID=$statusID"}'{literal};
187 if ( filterSearch ) {
188 sourceUrl = sourceUrl+"&search=1";
189 var ZeroRecordText = '<div class="status messages">{/literal}{ts escape="js"}None found.{/ts}{literal}</li></ul></div>';
190 }
191
192 crmBatchSelector1 = CRM.$('#crm-transaction-selector-assign-{/literal}{$entityID}{literal}').dataTable({
193 "bDestroy" : true,
194 "bFilter" : false,
195 "bAutoWidth" : false,
196 "lengthMenu": [ 10, 25, 50, 100, 250, 500, 1000, 2000 ],
197 "aaSorting" : [[5, 'desc']],
198 "aoColumns" : [
199 {sClass:'crm-transaction-checkbox', bSortable:false},
200 {sClass:'crm-contact-type', bSortable:false},
201 {sClass:'crm-contact-name'},
202 {sClass:'crm-amount'},
203 {sClass:'crm-trxnID'},
204 {sClass:'crm-trxn_date'},
205 {sClass:'crm-received'},
206 {sClass:'crm-payment-method'},
207 {sClass:'crm-status'},
208 {sClass:'crm-type'},
209 {sClass:'crm-transaction-links', bSortable:false}
210 ],
211 "bProcessing": true,
212 "asStripClasses" : [ "odd-row", "even-row" ],
213 "sPaginationType": "full_numbers",
214 "sDom" : '<"crm-datatable-pager-top"lfp>rt<"crm-datatable-pager-bottom"ip>',
215 "bServerSide": true,
216 "bJQueryUI": true,
217 "sAjaxSource": sourceUrl,
218 "iDisplayLength": 25,
219 "oLanguage": {
220 "sZeroRecords": ZeroRecordText,
221 "sProcessing": {/literal}"{ts escape='js'}Processing...{/ts}"{literal},
222 "sLengthMenu": {/literal}"{ts escape='js'}Show _MENU_ entries{/ts}"{literal},
223 "sInfo": {/literal}"{ts escape='js'}Showing _START_ to _END_ of _TOTAL_ entries{/ts}"{literal},
224 "sInfoEmpty": {/literal}"{ts escape='js'}Showing 0 to 0 of 0 entries{/ts}"{literal},
225 "sInfoFiltered": {/literal}"{ts escape='js'}(filtered from _MAX_ total entries){/ts}"{literal},
226 "sSearch": {/literal}"{ts escape='js'}Search:{/ts}"{literal},
227 "oPaginate": {
228 "sFirst": {/literal}"{ts escape='js'}First{/ts}"{literal},
229 "sPrevious": {/literal}"{ts escape='js'}Previous{/ts}"{literal},
230 "sNext": {/literal}"{ts escape='js'}Next{/ts}"{literal},
231 "sLast": {/literal}"{ts escape='js'}Last{/ts}"{literal}
232 }
233 },
234 "fnServerData": function ( sSource, aoData, fnCallback ) {
235 if ( filterSearch ) {
236 CRM.$('#searchForm :input').each(function() {
237 if (CRM.$(this).val()) {
238 aoData.push(
239 {name:CRM.$(this).attr('id'), value: CRM.$(this).val()}
240 );
241 CRM.$(':radio, :checkbox').each(function() {
242 if (CRM.$(this).is(':checked')) {
243 aoData.push( { name: CRM.$(this).attr('name'), value: CRM.$(this).val() } );
244 }
245 });
246 }
247 });
248 }
249 CRM.$.ajax({
250 "dataType": 'json',
251 "type": "POST",
252 "url": sSource,
253 "data": aoData,
254 "success": function(b) {
255 fnCallback(b);
256 toggleFinancialSelections('#toggleSelect', 'assign');
257 }
258 });
259 }
260 });
261
262 }
263
264 function buildTransactionSelectorRemove( ) {
265 var columns = '';
266 var sourceUrl = {/literal}'{crmURL p="civicrm/ajax/rest" h=0 q="className=CRM_Financial_Page_AJAX&fnName=getFinancialTransactionsList&snippet=4&context=financialBatch&entityID=$entityID&statusID=$statusID"}'{literal};
267
268 crmBatchSelector = CRM.$('#crm-transaction-selector-remove-{/literal}{$entityID}{literal}').dataTable({
269 "bDestroy" : true,
270 "bFilter" : false,
271 "bAutoWidth" : false,
272 "aaSorting" : [[5, 'desc']],
273 "aoColumns" : [
274 {sClass:'crm-transaction-checkbox', bSortable:false},
275 {sClass:'crm-contact-type', bSortable:false},
276 {sClass:'crm-contact-name'},
277 {sClass:'crm-amount'},
278 {sClass:'crm-trxnID'},
279 {sClass:'crm-trxn_date'},
280 {sClass:'crm-received'},
281 {sClass:'crm-payment-method'},
282 {sClass:'crm-status'},
283 {sClass:'crm-type'},
284 {sClass:'crm-transaction-links', bSortable:false}
285 ],
286 "bProcessing": true,
287 "asStripClasses" : [ "odd-row", "even-row" ],
288 "sPaginationType": "full_numbers",
289 "sDom" : '<"crm-datatable-pager-top"lfp>rt<"crm-datatable-pager-bottom"ip>',
290 "bServerSide": true,
291 "bJQueryUI": true,
292 "sAjaxSource": sourceUrl,
293 "iDisplayLength": 25,
294 "oLanguage": {
295 "sProcessing": {/literal}"{ts escape='js'}Processing...{/ts}"{literal},
296 "sLengthMenu": {/literal}"{ts escape='js'}Show _MENU_ entries{/ts}"{literal},
297 "sInfo": {/literal}"{ts escape='js'}Showing _START_ to _END_ of _TOTAL_ entries{/ts}"{literal},
298 "sInfoEmpty": {/literal}"{ts escape='js'}Showing 0 to 0 of 0 entries{/ts}"{literal},
299 "sInfoFiltered": {/literal}"{ts escape='js'}(filtered from _MAX_ total entries){/ts}"{literal},
300 "sSearch": {/literal}"{ts escape='js'}Search:{/ts}"{literal},
301 "oPaginate": {
302 "sFirst": {/literal}"{ts escape='js'}First{/ts}"{literal},
303 "sPrevious": {/literal}"{ts escape='js'}Previous{/ts}"{literal},
304 "sNext": {/literal}"{ts escape='js'}Next{/ts}"{literal},
305 "sLast": {/literal}"{ts escape='js'}Last{/ts}"{literal}
306 }
307 },
308 "fnServerData": function (sSource, aoData, fnCallback) {
309 CRM.$.ajax({
310 "dataType": 'json',
311 "type": "POST",
312 "url": sSource,
313 "data": aoData,
314 "success": function(b) {
315 fnCallback(b);
316 toggleFinancialSelections('#toggleSelects', 'remove');
317 }
318 });
319 }
320 });
321 }
322
323 function selectAction( id, toggleSelectId, checkId ) {
324 if (CRM.$("#"+ id ).is(':disabled')) {
325 return false;
326 }
327 else if (!CRM.$("#" + toggleSelectId).is(':checked') && !CRM.$("#" + checkId).is(':checked') && CRM.$("#" + id).val() != "") {
328 CRM.alert ({/literal}'{ts escape="js"}Please select one or more contributions for this action.{/ts}'{literal});
329 return false;
330 }
331 else if (CRM.$("#" + id).val() == "") {
332 CRM.alert ({/literal}'{ts escape="js"}Please select an action from the drop-down menu.{/ts}'{literal});
333 return false;
334 }
335 }
336
337 function bulkAssignRemove( action ) {
338 var postUrl = {/literal}"{crmURL p='civicrm/ajax/rest' h=0 q="className=CRM_Financial_Page_AJAX&fnName=bulkAssignRemove&entityID=$entityID" }"{literal};
339 var fids = [];
340 if (action == 'Assign') {
341 CRM.$("input[id^='mark_x_']:checked").each( function () {
342 var a = CRM.$(this).attr('id');
343 fids.push(a);
344 });
345 }
346 if (action == 'Remove') {
347 CRM.$("input[id^='mark_y_']:checked").each( function () {
348 var a = CRM.$(this).attr('id');
349 fids.push(a);
350 });
351 }
352 CRM.$.post(postUrl, { ID: fids, action:action }, function(data) {
353 //this is custom status set when record update success.
354 if (data.status == 'record-updated-success') {
355 buildTransactionSelectorAssign( true );
356 buildTransactionSelectorRemove();
357 batchSummary({/literal}{$entityID}{literal});
358 }
359 else {
360 CRM.alert(data.status);
361 }
362 }, 'json');
363 }
364 </script>
365 {/literal}