2 +--------------------------------------------------------------------+
3 | CiviCRM version 4.4 |
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC (c) 2004-2013 |
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="crm-submit-buttons">
30 <a accesskey="N" href="{crmURL p='civicrm/financial/batch' q="reset=1&action=add&context=$batchStatus"}" id="newBatch" class="button"><span><div class="icon add-icon"></div>{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" 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 Instrument{/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').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'},
103 {sClass:'crm-batch-total right'},
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 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 $('.crm-editable', '#crm-batch-selector').crmEditable();
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},
174 switch (op) {{/literal}
176 var msg = '<h3>{ts escape="js"}Are you sure you want to re-open:{/ts}</h3>';
179 var msg = '<h3>{ts escape="js"}Are you sure you want to delete:{/ts}</h3>';
182 var msg = '<h3>{ts escape="js"}Are you sure you want to close:{/ts}</h3>';
185 var msg = '<h3>{ts escape="js"}Export:{/ts}</h3>\
187 <label>{ts escape="js"}Format:{/ts}</label>\
188 <select class="export-format">\
189 <option value="IIF">IIF</option>\
190 <option value="CSV">CSV</option>\
195 msg += listRecords(records, op == 'close' || op == 'export');
196 $('#enableDisableStatusMsg').show().html(msg);
199 {/literal}"{ts escape='js'}Cancel{/ts}"{literal}: function() {
200 $(this).dialog("close");
202 {/literal}"{ts escape='js'}OK{/ts}{literal}": function() {
203 saveRecords(records, op);
204 $(this).dialog("close");
211 function listRecords(records, compareValues) {
214 for (var i in records) {
215 var $tr = $('tr[data-id=' + records[i] + ']');
216 txt += '<li>' + $('.crmf-title', $tr).text();
218 $('.actual-value.crm-error', $tr).each(function() {
220 var $th = $tr.closest('table').find('th').eq($(this).closest('td').index());
221 var $expected = $(this).siblings('.expected-value');
222 var label = $th.text();
223 var actual = $(this).text();
224 var expected = $expected.text();
225 txt += {/literal}'<div class="messages crm-error"><strong>' +
226 label + ' {ts escape="js"}mismatch.{/ts}</strong><br />{ts escape="js"}Expected{/ts}: ' + expected + '<br />{ts escape="js"}Current Total{/ts}: ' + actual + '</div>'{literal};
233 txt += {/literal}'<div class="messages status">{ts escape="js"}Click OK to override and update expected values.{/ts}</div>'{literal}
238 function saveRecords(records, op) {
239 if (op == 'export') {
240 return exportRecords(records);
242 var postUrl = CRM.url('civicrm/ajax/rest', 'className=CRM_Financial_Page_AJAX&fnName=assignRemove');
243 //post request and get response
244 $.post(postUrl, {records: records, recordBAO: 'CRM_Batch_BAO_Batch', op: op, key: {/literal}"{crmKey name='civicrm/ajax/ar'}"{literal}},
246 //this is custom status set when record update success.
247 if (response.status == 'record-updated-success') {
248 CRM.alert(listRecords(records), op == 'delete' ? {/literal}'{ts escape="js"}Deleted{/ts}' : '{ts escape="js"}Updated{/ts}'{literal}, 'success');
249 batchSelector.fnDraw();
252 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');
255 'json').error(serverError);
258 function exportRecords(records) {
259 var query = {'batch_id': records, 'export_format': $('select.export-format').val()};
260 var exportUrl = CRM.url('civicrm/financial/batch/export', 'reset=1');
261 // jQuery redirect expects all query args as an object, so extract them from crm url
262 var urlParts = exportUrl.split('?');
263 $.each(urlParts[1].split('&'), function(key, val) {
264 var q = val.split('=');
267 $().redirect(urlParts[0], query, 'GET');
268 setTimeout(function() {batchSelector.fnDraw();}, 4000);
271 function validateOp(records, op) {
274 var notAllowed = [1, 5];
277 var notAllowed = [2, 5];
280 var notAllowed = [5];
285 var len = records.length;
289 var status = $('tr[data-id='+records[i]+']').data('status_id');
290 if ($.inArray(status, notAllowed) >= 0) {
291 $('#check_' + records[i] + ':checked').prop('checked', false).change();
292 invalid[status] = invalid[status] || [];
293 invalid[status].push(records[i]);
294 records.splice(i, 1);
301 for (status in invalid) {
303 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);
304 CRM.alert(msg, {/literal}'{ts escape="js"}Cannot{/ts} '{literal} + $("#batch_update option[value=" + op + "]").text());
309 function serverError() {
310 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');
313 $('#Go').click(function() {
314 var op = $("#batch_update").val();
316 CRM.alert({/literal}'{ts escape="js"}Please select an action from the menu.{/ts}', '{ts escape="js"}No Action Selected{/ts}'{literal});
318 else if (!$("input.select-row:checked").length) {
319 CRM.alert({/literal}'{ts escape="js"}Please select one or more batches for this action.{/ts}', '{ts escape="js"}No Batches Selected{/ts}'{literal});
323 $("input.select-row:checked").each(function() {
324 records.push($(this).attr('id').replace('check_', ''));
326 editRecords(records, op);
331 $('#crm-container').on('click', 'a.action-item[href="#"]', function(event) {
332 event.stopImmediatePropagation();
333 editRecords([$(this).closest('tr').attr('data-id')], $(this).attr('rel'));