2 +--------------------------------------------------------------------+
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC (c) 2004-2019 |
6 +--------------------------------------------------------------------+
7 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
27 {* Financial search component. *}
28 <div id="enableDisableStatusMsg" class="crm-container" style="display:none"></div>
29 <div class="action-link">
30 <a accesskey="N" href="{crmURL p='civicrm/financial/batch' q="reset=1&action=add&context=$batchStatus"}" id="newBatch" class="button"><span><i class="crm-i fa-plus-circle"></i> {ts}New Accounting Batch{/ts}</span></a>
32 <div class="crm-form-block crm-search-form-block">
33 <div class="crm-accordion-wrapper crm-activity_search-accordion">
34 <div class="crm-accordion-header">
35 {ts}Filter Results{/ts}
37 <div class="crm-accordion-body">
38 <div id="financial-search-form" class="crm-block crm-form-block">
39 <table class="form-layout-compressed">
40 {* Loop through all defined search criteria fields (defined in the buildForm() function). *}
41 {foreach from=$elements item=element}
42 <tr class="crm-financial-search-form-block-{$element}">
43 <td class="label">{$form.$element.label}</td>
44 <td>{$form.$element.html}</td>
52 <div class="form-layout-compressed">{$form.batch_update.html} {$form.submit.html}</div><br/>
53 <table id="crm-batch-selector-{$batchStatus}" class="row-highlight">
56 <th class="crm-batch-checkbox">{$form.toggleSelect.html}</th>
57 <th class="crm-batch-name">{ts}Batch Name{/ts}</th>
58 <th class="crm-batch-payment_instrument">{ts}Payment Method{/ts}</th>
59 <th class="crm-batch-item_count">{ts}Item Count{/ts}</th>
60 <th class="crm-batch-total">{ts}Total Amount{/ts}</th>
61 <th class="crm-batch-status">{ts}Status{/ts}</th>
62 <th class="crm-batch-created_by">{ts}Created By{/ts}</th>
67 {include file="CRM/Form/validate.tpl"}
69 <script type="text/javascript">
73 $("#batch_update").prop('disabled', false);
75 $('#financial-search-form :input')
77 if (!$(this).hasClass('crm-inline-error')) {
78 batchSelector.fnDraw();
81 .keypress(function(event) {
82 if (event.which == 13) {
83 event.preventDefault();
90 function buildBatchSelector() {
91 var ZeroRecordText = {/literal}'<div class="status messages">{ts escape="js"}No Accounting Batches match your search criteria.{/ts}</div>'{literal};
92 var sourceUrl = {/literal}'{crmURL p="civicrm/ajax/batchlist" h=0 q="snippet=4&context=financialBatch"}'{literal};
94 batchSelector = $('#crm-batch-selector-{/literal}{$batchStatus}{literal}').dataTable({
99 {sClass:'crm-batch-checkbox', bSortable:false},
100 {sClass:'crm-batch-name'},
101 {sClass:'crm-batch-payment_instrument'},
102 {sClass:'crm-batch-item_count right', bSortable:false},
103 {sClass:'crm-batch-total right', bSortable:false},
104 {sClass:'crm-batch-status'},
105 {sClass:'crm-batch-created_by'},
106 {sClass:'crm-batch-links', bSortable:false},
109 "asStripClasses" : ["odd-row", "even-row"],
110 "sPaginationType": "full_numbers",
111 "sDom" : '<"crm-datatable-pager-top"lfp>rt<"crm-datatable-pager-bottom"ip>',
114 "sAjaxSource": sourceUrl,
115 "iDisplayLength": 25,
117 "sZeroRecords": ZeroRecordText,
118 "sProcessing": {/literal}"{ts escape='js'}Processing...{/ts}"{literal},
119 "sLengthMenu": {/literal}"{ts escape='js'}Show _MENU_ entries{/ts}"{literal},
120 "sInfo": {/literal}"{ts escape='js'}Showing _START_ to _END_ of _TOTAL_ entries{/ts}"{literal},
121 "sInfoEmpty": {/literal}"{ts escape='js'}Showing 0 to 0 of 0 entries{/ts}"{literal},
122 "sInfoFiltered": {/literal}"{ts escape='js'}(filtered from _MAX_ total entries) {/ts}"{literal},
123 "sSearch": {/literal}"{ts escape='js'}Search:{/ts}"{literal},
125 "sFirst": {/literal}"{ts escape='js'}First{/ts}"{literal},
126 "sPrevious": {/literal}"{ts escape='js'}Previous{/ts}"{literal},
127 "sNext": {/literal}"{ts escape='js'}Next{/ts}"{literal},
128 "sLast": {/literal}"{ts escape='js'}Last{/ts}"{literal}
131 "fnServerParams": function (aoData) {
132 $('#financial-search-form :input').each(function() {
135 {name:$(this).attr('id'), value: $(this).val()}
140 $("#crm-batch-selector-{/literal}{$batchStatus}{literal} input.select-row:checked").each(function() {
141 checkedRows.push('#' + $(this).attr('id'));
144 "fnRowCallback": function(nRow, aData, iDisplayIndex, iDisplayIndexFull) {
145 var box = $(aData[0]);
146 var id = box.attr('id').replace('check_', '');
147 $(nRow).addClass('crm-entity').attr('data-entity', 'batch').attr('data-id', id).attr('data-status_id', box.attr('data-status_id'));
148 $('td:eq(1)', nRow).wrapInner('<div class="crm-editable crmf-title" />');
151 "fnDrawCallback": function(oSettings) {
152 $(this).trigger('crmLoad');
153 $("#toggleSelect").prop('checked', false);
154 if (checkedRows.length) {
155 $(checkedRows.join(',')).prop('checked', true).change();
161 function editRecords(records, op) {
162 records = validateOp(records, op);
163 if (records.length) {
164 $("#enableDisableStatusMsg").dialog({
165 title: {/literal}'{ts escape="js"}Confirm Changes{/ts}'{literal},
168 switch (op) {{/literal}
170 var msg = '<h3>{ts escape="js"}Are you sure you want to re-open:{/ts}</h3>';
173 var msg = '<h3>{ts escape="js"}Are you sure you want to delete:{/ts}</h3>';
176 var msg = '<h3>{ts escape="js"}Are you sure you want to close:{/ts}</h3>';
179 var msg = '<h3>{ts escape="js"}Export:{/ts}</h3>\
181 <label>{ts escape="js"}Format:{/ts}</label>\
182 <select class="export-format">\
183 <option value="IIF">IIF</option>\
184 <option value="CSV">CSV</option>\
189 msg += listRecords(records, op == 'close' || op == 'export');
190 $('#enableDisableStatusMsg').show().html(msg);
193 {/literal}"{ts escape='js'}Cancel{/ts}"{literal}: function() {
194 $(this).dialog("close");
196 {/literal}"{ts escape='js'}OK{/ts}{literal}": function() {
197 saveRecords(records, op);
198 $(this).dialog("close");
205 function listRecords(records, compareValues) {
208 for (var i in records) {
209 var $tr = $('tr[data-id=' + records[i] + ']');
210 txt += '<li>' + $('.crmf-title', $tr).text();
212 $('.actual-value.crm-error', $tr).each(function() {
214 var $th = $tr.closest('table').find('th').eq($(this).closest('td').index());
215 var $expected = $(this).siblings('.expected-value');
216 var label = $th.text();
217 var actual = $(this).text();
218 var expected = $expected.text();
219 txt += {/literal}'<div class="messages crm-error"><strong>' +
220 label + ' {ts escape="js"}mismatch.{/ts}</strong><br />{ts escape="js"}Expected{/ts}: ' + expected + '<br />{ts escape="js"}Current Total{/ts}: ' + actual + '</div>'{literal};
227 txt += {/literal}'<div class="messages status">{ts escape="js"}Click OK to override and update expected values.{/ts}</div>'{literal}
232 function saveRecords(records, op) {
233 if (op == 'export') {
234 return exportRecords(records);
236 var postUrl = CRM.url('civicrm/ajax/rest', 'className=CRM_Financial_Page_AJAX&fnName=assignRemove');
237 //post request and get response
238 $.post(postUrl, {records: records, recordBAO: 'CRM_Batch_BAO_Batch', op: op, key: {/literal}"{crmKey name='civicrm/ajax/ar'}"{literal}},
240 //this is custom status set when record update success.
241 if (response.status == 'record-updated-success') {
243 window.location.href = CRM.url('civicrm/financial/financialbatches', 'reset=1&batchStatus=' + response.status_id);
244 CRM.alert(listRecords(records), op == 'delete' ? {/literal}'{ts escape="js"}Deleted{/ts}' : '{ts escape="js"}Updated{/ts}'{literal}, 'success');
247 CRM.alert({/literal}'{ts escape="js"}An error occurred while processing your request.{/ts}', $("#batch_update option[value=" + op + "]").text() + ' {ts escape="js"}Error{/ts}'{literal}, 'error');
250 'json').error(serverError);
253 function exportRecords(records) {
254 var query = {'batch_id': records, 'export_format': $('select.export-format').val()};
255 var exportUrl = CRM.url('civicrm/financial/batch/export', 'reset=1');
256 // jQuery redirect expects all query args as an object, so extract them from crm url
257 var urlParts = exportUrl.split('?');
258 $.each(urlParts[1].split('&'), function(key, val) {
259 var q = val.split('=');
262 $().redirect(urlParts[0], query, 'GET');
263 setTimeout(function() {batchSelector.fnDraw();}, 4000);
266 function validateOp(records, op) {
269 var notAllowed = [1, 5];
272 var notAllowed = [2, 5];
275 var notAllowed = [5];
280 var len = records.length;
284 var status = $('tr[data-id='+records[i]+']').data('status_id');
285 if ($.inArray(status, notAllowed) >= 0) {
286 $('#check_' + records[i] + ':checked').prop('checked', false).change();
287 invalid[status] = invalid[status] || [];
288 invalid[status].push(records[i]);
289 records.splice(i, 1);
296 for (status in invalid) {
298 var msg = (i.length == 1 ? {/literal}'{ts escape="js"}This record already has the status{/ts}' : '{ts escape="js"}The following records already have the status{/ts}'{literal}) + ' ' + $('tr[data-id='+i[0]+'] .crm-batch-status').text() + ':' + listRecords(i);
299 CRM.alert(msg, {/literal}'{ts escape="js"}Cannot{/ts} '{literal} + $("#batch_update option[value=" + op + "]").text());
304 function serverError() {
305 CRM.alert({/literal}'{ts escape="js"}No response from the server. Check your internet connection and try reloading the page.{/ts}', '{ts escape="js"}Network Error{/ts}'{literal}, 'error');
308 $('#Go').click(function() {
309 var op = $("#batch_update").val();
311 CRM.alert({/literal}'{ts escape="js"}Please select an action from the menu.{/ts}', '{ts escape="js"}No Action Selected{/ts}'{literal});
313 else if (!$("input.select-row:checked").length) {
314 CRM.alert({/literal}'{ts escape="js"}Please select one or more batches for this action.{/ts}', '{ts escape="js"}No Batches Selected{/ts}'{literal});
318 $("input.select-row:checked").each(function() {
319 records.push($(this).attr('id').replace('check_', ''));
321 editRecords(records, op);
326 $('#crm-container').on('click', 'a.action-item[href="#"]', function(event) {
327 event.stopImmediatePropagation();
328 editRecords([$(this).closest('tr').attr('data-id')], $(this).attr('rel'));