| 1 | {* |
| 2 | +--------------------------------------------------------------------+ |
| 3 | | CiviCRM version 4.5 | |
| 4 | +--------------------------------------------------------------------+ |
| 5 | | Copyright CiviCRM LLC (c) 2004-2014 | |
| 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 $statusID eq 1}{$form.close_batch.html}{/if} {$form.export_batch.html}</div> |
| 46 | |
| 47 | {if $statusID eq 1} {* Add / remove transactions only allowed for Open batches *} |
| 48 | <br /><div class="form-layout-compressed">{$form.trans_remove.html} {$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 $statusID eq 1}{$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-received">{ts}Received{/ts}</th> |
| 64 | <th class="crm-payment-method">{ts}Pay Method{/ts}</th> |
| 65 | <th class="crm-status">{ts}Status{/ts}</th> |
| 66 | <th class="crm-type">{ts}Type{/ts}</th> |
| 67 | <th class="crm-transaction-links"></th> |
| 68 | </tr> |
| 69 | </thead> |
| 70 | </table> |
| 71 | {/strip} |
| 72 | </div> |
| 73 | </div> |
| 74 | <br/> |
| 75 | {include file="CRM/Financial/Form/BatchTransaction.tpl"} |
| 76 | |
| 77 | {literal} |
| 78 | <script type="text/javascript"> |
| 79 | CRM.$(function($) { |
| 80 | var entityID = {/literal}{$entityID}{literal}; |
| 81 | batchSummary(entityID); |
| 82 | CRM.$('#close_batch').click( function() { |
| 83 | assignRemove(entityID, 'close'); |
| 84 | return false; |
| 85 | }); |
| 86 | CRM.$('#export_batch').click( function() { |
| 87 | assignRemove(entityID, 'export'); |
| 88 | return false; |
| 89 | }); |
| 90 | }); |
| 91 | function assignRemove(recordID, op) { |
| 92 | var recordBAO = 'CRM_Batch_BAO_Batch'; |
| 93 | var entityID = {/literal}"{$entityID}"{literal}; |
| 94 | if (op == 'close' || op == 'export') { |
| 95 | var mismatch = checkMismatch(); |
| 96 | } |
| 97 | else { |
| 98 | CRM.$('#mark_x_' + recordID).closest('tr').block({message: {/literal}'{ts escape="js"}Updating{/ts}'{literal}}); |
| 99 | } |
| 100 | if (op == 'close' || (op == 'export' && mismatch.length)) { |
| 101 | CRM.$("#enableDisableStatusMsg").dialog({ |
| 102 | title: {/literal}'{ts escape="js"}Close Batch{/ts}'{literal}, |
| 103 | modal: true, |
| 104 | open:function() { |
| 105 | if (op == 'close') { |
| 106 | var msg = {/literal}'{ts escape="js"}Are you sure you want to close this batch?{/ts}'{literal}; |
| 107 | } |
| 108 | else { |
| 109 | var msg = {/literal}'{ts escape="js"}Are you sure you want to close and export this batch?{/ts}'{literal}; |
| 110 | } |
| 111 | CRM.$('#enableDisableStatusMsg').show().html(msg + mismatch); |
| 112 | }, |
| 113 | buttons: { |
| 114 | {/literal}"{ts escape='js'}Cancel{/ts}"{literal}: function() { |
| 115 | CRM.$(this).dialog("close"); |
| 116 | }, |
| 117 | {/literal}"{ts escape='js'}OK{/ts}"{literal}: function() { |
| 118 | CRM.$(this).dialog("close"); |
| 119 | saveRecord(recordID, op, recordBAO, entityID); |
| 120 | } |
| 121 | } |
| 122 | }); |
| 123 | } |
| 124 | else { |
| 125 | saveRecord(recordID, op, recordBAO, entityID); |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | function noServerResponse() { |
| 130 | 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'); |
| 131 | } |
| 132 | |
| 133 | function saveRecord(recordID, op, recordBAO, entityID) { |
| 134 | if (op == 'export') { |
| 135 | window.location.href = CRM.url('civicrm/financial/batch/export', {reset: 1, id: recordID, status: 1}); |
| 136 | return; |
| 137 | } |
| 138 | var postUrl = {/literal}"{crmURL p='civicrm/ajax/rest' h=0 q='className=CRM_Financial_Page_AJAX&fnName=assignRemove'}"{literal}; |
| 139 | //post request and get response |
| 140 | CRM.$.post( postUrl, { records: [recordID], recordBAO: recordBAO, op:op, entityID:entityID, key: {/literal}"{crmKey name='civicrm/ajax/ar'}"{literal} }, function( html ){ |
| 141 | //this is custom status set when record update success. |
| 142 | if (html.status == 'record-updated-success') { |
| 143 | if (op == 'close') { |
| 144 | window.location.href = CRM.url('civicrm/financial/financialbatches', 'reset=1&batchStatus=2'); |
| 145 | } |
| 146 | else { |
| 147 | buildTransactionSelectorAssign( true ); |
| 148 | buildTransactionSelectorRemove(); |
| 149 | batchSummary(entityID); |
| 150 | } |
| 151 | } |
| 152 | else { |
| 153 | CRM.alert(html.status); |
| 154 | } |
| 155 | }, |
| 156 | 'json').error(noServerResponse); |
| 157 | } |
| 158 | |
| 159 | function batchSummary(entityID) { |
| 160 | var postUrl = {/literal}"{crmURL p='civicrm/ajax/rest' h=0 q='className=CRM_Financial_Page_AJAX&fnName=getBatchSummary'}"{literal}; |
| 161 | //post request and get response |
| 162 | CRM.$.post( postUrl, {batchID: entityID}, function(html) { |
| 163 | CRM.$.each(html, function(i, val) { |
| 164 | CRM.$("#row_" + i).html(val); |
| 165 | }); |
| 166 | }, |
| 167 | 'json'); |
| 168 | } |
| 169 | |
| 170 | function checkMismatch() { |
| 171 | var txt = ''; |
| 172 | var enteredItem = CRM.$("#row_item_count").text(); |
| 173 | var assignedItem = CRM.$("#row_assigned_item_count").text(); |
| 174 | var enteredTotal = CRM.$("#row_total").text(); |
| 175 | var assignedTotal = CRM.$("#row_assigned_total").text(); |
| 176 | if (enteredItem != "" && enteredItem != assignedItem) { |
| 177 | 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}'; |
| 178 | } |
| 179 | if (enteredTotal != "" && enteredTotal != assignedTotal) { |
| 180 | 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}'; |
| 181 | } |
| 182 | if (txt.length) { |
| 183 | txt += {/literal}'<div class="messages status">{ts escape="js"}Click OK to override and update expected values.{/ts}</div>'{literal} |
| 184 | } |
| 185 | return txt; |
| 186 | } |
| 187 | </script> |
| 188 | {/literal} |