CRM-16189, fixed code to export reopen batches
authorPradeep Nayak <pradpnayak@gmail.com>
Wed, 15 Jun 2016 15:24:19 +0000 (20:54 +0530)
committerPradeep Nayak <pradpnayak@gmail.com>
Fri, 1 Jul 2016 14:06:09 +0000 (19:36 +0530)
----------------------------------------
* CRM-16189: Improve support for Accrual Method bookkeeping
  https://issues.civicrm.org/jira/browse/CRM-16189

CRM/Financial/Form/BatchTransaction.php
templates/CRM/Financial/Form/BatchTransaction.tpl
templates/CRM/Financial/Page/BatchTransaction.tpl

index e3e35a239171c7a1a184036b0ee1d3477a9d1a3e..dcf1cec387df375ae5ed332a346feafd4b334d61 100644 (file)
@@ -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)) {
index a7a966218cf2a19b5660656c9908f589114f38b7..046842cf1e597d7c3339c186bf35a101dda88452 100644 (file)
@@ -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'))}
 <div class="crm-form-block crm-search-form-block">
   <div class="crm-accordion-wrapper crm-batch_transaction_search-accordion collapsed">
     <div class="crm-accordion-header crm-master-accordion-header">
           {/if}
           {include file="CRM/Contribute/Form/Search/Common.tpl"}
         </table>
-        <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="botttom"}</div>
+       <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
       </div>
     </div>
   </div>
 </div>
-{if $statusID eq 1}
+{if in_array($batchStatus, array('Open', 'Reopened'))}
 <div class="form-layout-compressed">{$form.trans_assign.html}&nbsp;{$form.submit.html}</div><br/>
 {/if}
 <div id="ltype">
@@ -69,7 +69,7 @@
     <table id="crm-transaction-selector-assign-{$entityID}" cellpadding="0" cellspacing="0" border="0">
       <thead>
       <tr>
-        <th class="crm-transaction-checkbox">{if $statusID eq 1}{$form.toggleSelect.html}{/if}</th>
+        <th class="crm-transaction-checkbox">{if in_array($batchStatus, array('Open', 'Reopened'))}{$form.toggleSelect.html}{/if}</th>
         <th class="crm-contact-type"></th>
         <th class="crm-contact-name">{ts}Name{/ts}</th>
         <th class="crm-amount">{ts}Amount{/ts}</th>
@@ -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 ) {
index 4932ebd0b0c44f2bc00eff3237e39832138c8ffc..7045dcf46f0520da05d25f0f40cff5455b47c47d 100644 (file)
@@ -42,9 +42,9 @@
   </tbody>
 </table>
 
-<div class="crm-submit-buttons">{if $statusID eq 1}{$form.close_batch.html}{/if} {$form.export_batch.html}</div>
+<div class="crm-submit-buttons">{if in_array($batchStatus, array('Open', 'Reopened'))}{$form.close_batch.html}{/if} {$form.export_batch.html}</div>
 
-{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 *}
   <br /><div class="form-layout-compressed">{$form.trans_remove.html}&nbsp;{$form.rSubmit.html}</div><br/>
 {/if}
 
@@ -55,7 +55,7 @@
     <table id="crm-transaction-selector-remove-{$entityID}" cellpadding="0" cellspacing="0" border="0">
       <thead>
         <tr>
-          <th class="crm-transaction-checkbox">{if $statusID eq 1}{$form.toggleSelects.html}{/if}</th>
+          <th class="crm-transaction-checkbox">{if in_array($batchStatus, array('Open', 'Reopened'))}{$form.toggleSelects.html}{/if}</th>
           <th class="crm-contact-type"></th>
           <th class="crm-contact-name">{ts}Name{/ts}</th>
           <th class="crm-amount">{ts}Amount{/ts}</th>