Merge pull request #12923 from vinuvarshith/scheduled-reminders-error-fix
[civicrm-core.git] / templates / CRM / Financial / Page / BatchTransaction.tpl
1 {*
2 +--------------------------------------------------------------------+
3 | CiviCRM version 5 |
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC (c) 2004-2019 |
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
27 <div id="enableDisableStatusMsg" class="crm-container" style="display:none;"></div>
28 <table id="batch-summary" cellpadding="0" cellspacing="0" border="0" class="report crm-batch_summary">
29 <thead class="sticky">
30 <tr>
31 {foreach from=$columnHeaders item=head}
32 <th>{$head}</th>
33 {/foreach}
34 </tr>
35 </thead>
36 <tbody>
37 <tr>
38 {foreach from=$columnHeaders item=head key=rowKey}
39 <td id="row_{$rowKey}" class="even-row"></td>
40 {/foreach}
41 </tr>
42 </tbody>
43 </table>
44
45 <div class="crm-submit-buttons">{if in_array($batchStatus, array('Open', 'Reopened'))}{$form.close_batch.html}{/if} {$form.export_batch.html}</div>
46
47 {if in_array($batchStatus, array('Open', 'Reopened'))} {* Add / remove transactions only allowed for Open/Reopened batches *}
48 <br /><div class="form-layout-compressed">{$form.trans_remove.html}&nbsp;{$form.rSubmit.html}</div><br/>
49 {/if}
50
51 <div id="ltype">
52 <p></p>
53 <div class="form-item">
54 {strip}
55 <table id="crm-transaction-selector-remove-{$entityID}" cellpadding="0" cellspacing="0" border="0">
56 <thead>
57 <tr>
58 <th class="crm-transaction-checkbox">{if in_array($batchStatus, array('Open', 'Reopened'))}{$form.toggleSelects.html}{/if}</th>
59 <th class="crm-contact-type"></th>
60 <th class="crm-contact-name">{ts}Name{/ts}</th>
61 <th class="crm-amount">{ts}Amount{/ts}</th>
62 <th class="crm-trxnID">{ts}Trxn ID{/ts}</th>
63 <th class="crm-trxn_date">{ts}Payment/Transaction Date{/ts}</th>
64 <th class="crm-received">{ts}Contribution Date{/ts}</th>
65 <th class="crm-payment-method">{ts}Pay Method{/ts}</th>
66 <th class="crm-status">{ts}Status{/ts}</th>
67 <th class="crm-type">{ts}Type{/ts}</th>
68 <th class="crm-transaction-links"></th>
69 </tr>
70 </thead>
71 </table>
72 {/strip}
73 </div>
74 </div>
75 <br/>
76 {include file="CRM/Financial/Form/BatchTransaction.tpl"}
77
78 {literal}
79 <script type="text/javascript">
80 CRM.$(function($) {
81 var entityID = {/literal}{$entityID}{literal};
82 batchSummary(entityID);
83 CRM.$('#close_batch').click( function() {
84 assignRemove(entityID, 'close');
85 return false;
86 });
87 CRM.$('#export_batch').click( function() {
88 assignRemove(entityID, 'export');
89 return false;
90 });
91 });
92 function assignRemove(recordID, op) {
93 var recordBAO = 'CRM_Batch_BAO_Batch';
94 if (op == 'assign' || op == 'remove') {
95 recordBAO = 'CRM_Batch_BAO_EntityBatch';
96 }
97 var entityID = {/literal}"{$entityID}"{literal};
98 if (op == 'close' || op == 'export') {
99 var mismatch = checkMismatch();
100 }
101 else {
102 CRM.$('#mark_x_' + recordID).closest('tr').block({message: {/literal}'{ts escape="js"}Updating{/ts}'{literal}});
103 }
104 if (op == 'close' || (op == 'export' && mismatch.length)) {
105 CRM.$("#enableDisableStatusMsg").dialog({
106 title: {/literal}'{ts escape="js"}Close Batch{/ts}'{literal},
107 modal: true,
108 open:function() {
109 if (op == 'close') {
110 var msg = {/literal}'{ts escape="js"}Are you sure you want to close this batch?{/ts}'{literal};
111 }
112 else {
113 var msg = {/literal}'{ts escape="js"}Are you sure you want to close and export this batch?{/ts}'{literal};
114 }
115 CRM.$('#enableDisableStatusMsg').show().html(msg + mismatch);
116 },
117 buttons: {
118 {/literal}"{ts escape='js'}Cancel{/ts}"{literal}: function() {
119 CRM.$(this).dialog("close");
120 },
121 {/literal}"{ts escape='js'}OK{/ts}"{literal}: function() {
122 CRM.$(this).dialog("close");
123 saveRecord(recordID, op, recordBAO, entityID);
124 }
125 }
126 });
127 }
128 else {
129 saveRecord(recordID, op, recordBAO, entityID);
130 }
131 }
132
133 function noServerResponse() {
134 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');
135 }
136
137 function saveRecord(recordID, op, recordBAO, entityID) {
138 if (op == 'export') {
139 window.location.href = CRM.url('civicrm/financial/batch/export', {reset: 1, id: recordID, status: 1});
140 return;
141 }
142 var postUrl = {/literal}"{crmURL p='civicrm/ajax/rest' h=0 q='className=CRM_Financial_Page_AJAX&fnName=assignRemove'}"{literal};
143 //post request and get response
144 CRM.$.post( postUrl, { records: [recordID], recordBAO: recordBAO, op:op, entityID:entityID, key: {/literal}"{crmKey name='civicrm/ajax/ar'}"{literal} }, function( html ){
145 //this is custom status set when record update success.
146 if (html.status == 'record-updated-success') {
147 if (op == 'close') {
148 window.location.href = CRM.url('civicrm/financial/financialbatches', 'reset=1&batchStatus=2');
149 }
150 else {
151 buildTransactionSelectorAssign( true );
152 buildTransactionSelectorRemove();
153 batchSummary(entityID);
154 }
155 }
156 else {
157 CRM.alert(html.status);
158 }
159 },
160 'json').error(noServerResponse);
161 }
162
163 function batchSummary(entityID) {
164 var postUrl = {/literal}"{crmURL p='civicrm/ajax/rest' h=0 q='className=CRM_Financial_Page_AJAX&fnName=getBatchSummary'}"{literal};
165 //post request and get response
166 CRM.$.post( postUrl, {batchID: entityID}, function(html) {
167 CRM.$.each(html, function(i, val) {
168 CRM.$("#row_" + i).html(val);
169 });
170 },
171 'json');
172 }
173
174 function checkMismatch() {
175 var txt = '';
176 var enteredItem = CRM.$("#row_item_count").text();
177 var assignedItem = CRM.$("#row_assigned_item_count").text();
178 var enteredTotal = CRM.$("#row_total").text();
179 var assignedTotal = CRM.$("#row_assigned_total").text();
180 if (enteredItem != "" && enteredItem != assignedItem) {
181 txt = '{/literal}<div class="messages crm-error"><strong>Item Count mismatch:</strong><br/>{ts escape="js"}Expected{/ts}:' + enteredItem +'<br/>{ts escape="js"}Current Total{/ts}:' + assignedItem + '</div>{literal}';
182 }
183 if (enteredTotal != "" && enteredTotal != assignedTotal) {
184 txt += '{/literal}<div class="messages crm-error"><strong>Total Amount mismatch</strong><br/>{ts escape="js"}Expected{/ts}:' + enteredTotal +'<br/>{ts escape="js"}Current Total{/ts}:' + assignedTotal + '</div>{literal}';
185 }
186 if (txt.length) {
187 txt += {/literal}'<div class="messages status">{ts escape="js"}Click OK to override and update expected values.{/ts}</div>'{literal}
188 }
189 return txt;
190 }
191 </script>
192 {/literal}