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