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