From 89d18ebd3a63ad6c2e256bd81aa6c500f58d4625 Mon Sep 17 00:00:00 2001 From: Pradeep Nayak Date: Wed, 15 Jun 2016 20:54:19 +0530 Subject: [PATCH] CRM-16189, fixed code to export reopen batches ---------------------------------------- * CRM-16189: Improve support for Accrual Method bookkeeping https://issues.civicrm.org/jira/browse/CRM-16189 --- CRM/Financial/Form/BatchTransaction.php | 23 +++++++++++++++---- .../CRM/Financial/Form/BatchTransaction.tpl | 17 +++++++------- .../CRM/Financial/Page/BatchTransaction.tpl | 6 ++--- 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/CRM/Financial/Form/BatchTransaction.php b/CRM/Financial/Form/BatchTransaction.php index e3e35a2391..dcf1cec387 100644 --- a/CRM/Financial/Form/BatchTransaction.php +++ b/CRM/Financial/Form/BatchTransaction.php @@ -44,6 +44,12 @@ class CRM_Financial_Form_BatchTransaction extends CRM_Contribute_Form { */ protected $_batchStatusId; + /** + * Batch status name. + * @string + */ + protected $_batchStatus; + public function preProcess() { // This reuses some styles from search forms CRM_Core_Resources::singleton()->addStyleFile('civicrm', 'css/searchForm.css', 1, 'html-header'); @@ -52,7 +58,14 @@ class CRM_Financial_Form_BatchTransaction extends CRM_Contribute_Form { $this->assign('entityID', self::$_entityID); if (isset(self::$_entityID)) { $this->_batchStatusId = CRM_Core_DAO::getFieldValue('CRM_Batch_BAO_Batch', self::$_entityID, 'status_id'); + $batchStatuses = CRM_Core_PseudoConstant::get('CRM_Batch_DAO_Batch', 'status_id', array('labelColumn' => 'name', 'condition' => " v.value={$this->_batchStatusId}")); + $this->_batchStatus = $batchStatuses[$this->_batchStatusId]; $this->assign('statusID', $this->_batchStatusId); + $this->assign('batchStatus', $this->_batchStatus); + $this->assign('validStatus', FALSE); + if (in_array($this->_batchStatus, array('Open', 'Reopened'))) { + $this->assign('validStatus', TRUE); + } $batchTitle = CRM_Core_DAO::getFieldValue('CRM_Batch_BAO_Batch', self::$_entityID, 'title'); CRM_Utils_System::setTitle(ts('Accounting Batch - %1', array(1 => $batchTitle))); @@ -76,12 +89,12 @@ class CRM_Financial_Form_BatchTransaction extends CRM_Contribute_Form { * Build the form object. */ public function buildQuickForm() { - if ($this->_batchStatusId == 2) { + if ($this->_batchStatus == 'Closed') { $this->add('submit', 'export_batch', ts('Export Batch')); } - // do not build rest of form unless it is open batch - if ($this->_batchStatusId != 1) { + // do not build rest of form unless it is open/reopened batch + if (!in_array($this->_batchStatus, array('Open', 'Reopened'))) { return; } @@ -158,8 +171,8 @@ class CRM_Financial_Form_BatchTransaction extends CRM_Contribute_Form { } public function setDefaultValues() { - // do not setdefault unless it is open batch - if ($this->_batchStatusId != 1) { + // do not setdefault unless it is open/reopened batch + if (!in_array($this->_batchStatus, array('Open', 'Reopened'))) { return; } if (isset(self::$_entityID)) { diff --git a/templates/CRM/Financial/Form/BatchTransaction.tpl b/templates/CRM/Financial/Form/BatchTransaction.tpl index a7a966218c..046842cf1e 100644 --- a/templates/CRM/Financial/Form/BatchTransaction.tpl +++ b/templates/CRM/Financial/Form/BatchTransaction.tpl @@ -24,7 +24,7 @@ +--------------------------------------------------------------------+ *} {* this template is used for batch transaction screen, assign/remove transactions to batch *} -{if $statusID eq 1} +{if in_array($batchStatus, array('Open', 'Reopened'))}
-{if $statusID eq 1} +{if in_array($batchStatus, array('Open', 'Reopened'))}
{$form.trans_assign.html} {$form.submit.html}

{/if}
@@ -69,7 +69,7 @@ - + @@ -94,8 +94,8 @@ CRM.$(function($) { CRM.$('.crm-batch_transaction_search-accordion:not(.collapsed)').crmAccordionToggle(); }); var batchStatus = {/literal}{$statusID}{literal}; - // build transaction listing only for open batches - if (batchStatus == 1) { + {/literal}{if $validStatus}{literal} + // build transaction listing only for open/reopened batches var paymentInstrumentID = {/literal}{if $paymentInstrumentID neq null}{$paymentInstrumentID}{else}'null'{/if}{literal}; if (paymentInstrumentID != 'null') { buildTransactionSelectorAssign( true ); @@ -158,10 +158,9 @@ CRM.$(function($) { CRM.$("#crm-transaction-selector-remove-{/literal}{$entityID}{literal} input[id^='mark_y_']").prop('checked',false); } }); - } - else { + {/literal}{else}{literal} buildTransactionSelectorRemove(); - } + {/literal}{/if}{literal} }); function enableActions( type ) { diff --git a/templates/CRM/Financial/Page/BatchTransaction.tpl b/templates/CRM/Financial/Page/BatchTransaction.tpl index 4932ebd0b0..7045dcf46f 100644 --- a/templates/CRM/Financial/Page/BatchTransaction.tpl +++ b/templates/CRM/Financial/Page/BatchTransaction.tpl @@ -42,9 +42,9 @@
{if $statusID eq 1}{$form.toggleSelect.html}{/if}{if in_array($batchStatus, array('Open', 'Reopened'))}{$form.toggleSelect.html}{/if} {ts}Name{/ts} {ts}Amount{/ts}
-
{if $statusID eq 1}{$form.close_batch.html}{/if} {$form.export_batch.html}
+
{if in_array($batchStatus, array('Open', 'Reopened'))}{$form.close_batch.html}{/if} {$form.export_batch.html}
-{if $statusID eq 1} {* Add / remove transactions only allowed for Open batches *} +{if in_array($batchStatus, array('Open', 'Reopened'))} {* Add / remove transactions only allowed for Open/Reopened batches *}
{$form.trans_remove.html} {$form.rSubmit.html}

{/if} @@ -55,7 +55,7 @@ - + -- 2.25.1
{if $statusID eq 1}{$form.toggleSelects.html}{/if}{if in_array($batchStatus, array('Open', 'Reopened'))}{$form.toggleSelects.html}{/if} {ts}Name{/ts} {ts}Amount{/ts}