From 2d818e4af07011578b01965657be3e7ebebbcf48 Mon Sep 17 00:00:00 2001 From: Pradeep Nayak Date: Wed, 16 Apr 2014 02:55:34 +0530 Subject: [PATCH] -- removed hardcoded values and handled reopened status. CRM-14191 ---------------------------------------- * CRM-14191: https://issues.civicrm.org/jira/browse/CRM-14191 --- CRM/Batch/BAO/Batch.php | 32 ++++++++++++++++++++++---------- CRM/Batch/Form/Batch.php | 2 +- CRM/Batch/Form/Entry.php | 2 +- CRM/Batch/Page/AJAX.php | 2 +- CRM/Financial/Page/AJAX.php | 4 ++-- 5 files changed, 27 insertions(+), 15 deletions(-) diff --git a/CRM/Batch/BAO/Batch.php b/CRM/Batch/BAO/Batch.php index f41fbc3518..5ef02fed17 100644 --- a/CRM/Batch/BAO/Batch.php +++ b/CRM/Batch/BAO/Batch.php @@ -191,9 +191,14 @@ class CRM_Batch_BAO_Batch extends CRM_Batch_DAO_Batch { // get batch totals for open batches $fetchTotals = array(); + $batchStatus = CRM_Core_PseudoConstant::get('CRM_Batch_DAO_Batch', 'status_id', array('labelColumn' => 'name')); + $batchStatus = array( + array_search('Open', $batchStatus), + array_search('Reopened', $batchStatus), + ); if ($params['context'] == 'financialBatch') { foreach ($batches as $id => $batch) { - if ($batch['status_id'] == 1) { + if (in_array($batch['status_id'], $batchStatus)) { $fetchTotals[] = $id; } } @@ -270,6 +275,7 @@ class CRM_Batch_BAO_Batch extends CRM_Batch_DAO_Batch { $batchTypes = CRM_Core_PseudoConstant::get('CRM_Batch_DAO_Batch', 'type_id'); $batchStatus = CRM_Core_PseudoConstant::get('CRM_Batch_DAO_Batch', 'status_id'); + $batchStatusByName = CRM_Core_PseudoConstant::get('CRM_Batch_DAO_Batch', 'status_id', array('labelColumn' => 'name')); $paymentInstrument = CRM_Contribute_PseudoConstant::paymentInstrument(); $results = array(); @@ -279,7 +285,7 @@ class CRM_Batch_BAO_Batch extends CRM_Batch_DAO_Batch { CRM_Core_DAO::storeValues($object, $values); $action = array_sum(array_keys($newLinks)); - if ($values['status_id'] == 2 && $params['context'] != 'financialBatch') { + if ($values['status_id'] == array_search('Closed', $batchStatusByName) && $params['context'] != 'financialBatch') { $newLinks = array(); } elseif ($params['context'] == 'financialBatch') { @@ -291,14 +297,14 @@ class CRM_Batch_BAO_Batch extends CRM_Batch_DAO_Batch { "' value='1' data-status_id='" . $values['status_id']."' class='select-row'>"; - switch ($values['status_id']) { - case '1': + switch ($batchStatusByName[$values['status_id']]) { + case 'Open': CRM_Utils_Array::remove($newLinks, 'reopen', 'download'); break; - case '2': + case 'Closed': CRM_Utils_Array::remove($newLinks, 'close', 'edit', 'download'); break; - case '5': + case 'Exported': CRM_Utils_Array::remove($newLinks, 'close', 'edit', 'reopen', 'export'); } } @@ -312,7 +318,7 @@ class CRM_Batch_BAO_Batch extends CRM_Batch_DAO_Batch { $values['payment_instrument'] = $paymentInstrument[$object->payment_instrument_id]; } $tokens = array('id' => $object->id, 'status' => $values['status_id']); - if ($values['status_id'] == CRM_Core_OptionGroup::getValue('batch_status', 'Exported')) { + if ($values['status_id'] == array_search('Exported', $batchStatusByName)) { $aid = CRM_Core_OptionGroup::getValue('activity_type','Export Accounting Batch'); $activityParams = array('source_record_id' => $object->id, 'activity_type_id' => $aid); $exportActivity = CRM_Activity_BAO_Activity::retrieve($activityParams, $val); @@ -354,8 +360,9 @@ class CRM_Batch_BAO_Batch extends CRM_Batch_DAO_Batch { public static function whereClause($params) { $clauses = array(); // Exclude data-entry batches + $batchStatus = CRM_Core_PseudoConstant::get('CRM_Batch_DAO_Batch', 'status_id', array('labelColumn' => 'name')); if (empty($params['status_id'])) { - $clauses[] = 'batch.status_id <> 3'; + $clauses[] = 'batch.status_id <> ' . array_search('Data Entry', $batchStatus); } $fields = array( @@ -378,7 +385,12 @@ class CRM_Batch_BAO_Batch extends CRM_Batch_DAO_Batch { $clauses[] = "$table.$field = '$value'"; } elseif ($value) { - $clauses[] = "$table.$field = $value"; + if ($field == 'status_id' && $value == array_search('Open', $batchStatus)) { + $clauses[] = "$table.$field IN ($value," . array_search('Reopened', $batchStatus) . ')'; + } + else { + $clauses[] = "$table.$field = $value"; + } } } } @@ -470,7 +482,7 @@ class CRM_Batch_BAO_Batch extends CRM_Batch_DAO_Batch { * excluding batches with data entry in progress */ static function getBatches() { - $dataEntryStatusId = CRM_Core_OptionGroup::getValue('batch_status','Data Entry'); + $dataEntryStatusId = CRM_Core_OptionGroup::getValue('batch_status','Data Entry', 'name'); $query = "SELECT id, title FROM civicrm_batch WHERE item_count >= 1 diff --git a/CRM/Batch/Form/Batch.php b/CRM/Batch/Form/Batch.php index 7f9aed5b48..6af38ca1d2 100644 --- a/CRM/Batch/Form/Batch.php +++ b/CRM/Batch/Form/Batch.php @@ -124,7 +124,7 @@ class CRM_Batch_Form_Batch extends CRM_Admin_Form { } // always create with data entry status - $params['status_id'] = CRM_Core_OptionGroup::getValue('batch_status','Data Entry');; + $params['status_id'] = CRM_Core_OptionGroup::getValue('batch_status','Data Entry', 'name'); $batch = CRM_Batch_BAO_Batch::create($params); // redirect to batch entry page. diff --git a/CRM/Batch/Form/Entry.php b/CRM/Batch/Form/Entry.php index c2c7fd9148..eb44b8d9d4 100644 --- a/CRM/Batch/Form/Entry.php +++ b/CRM/Batch/Form/Entry.php @@ -370,7 +370,7 @@ class CRM_Batch_Form_Entry extends CRM_Core_Form { $paramValues = array( 'id' => $this->_batchId, // close status - 'status_id' => CRM_Core_OptionGroup::getValue('batch_status','Closed'), + 'status_id' => CRM_Core_OptionGroup::getValue('batch_status', 'Closed', 'name'), 'total' => $params['actualBatchTotal'], ); diff --git a/CRM/Batch/Page/AJAX.php b/CRM/Batch/Page/AJAX.php index 5c38d70dea..b932d0bf37 100644 --- a/CRM/Batch/Page/AJAX.php +++ b/CRM/Batch/Page/AJAX.php @@ -88,7 +88,7 @@ class CRM_Batch_Page_AJAX { if ($context != 'financialBatch') { // data entry status batches - $params['status_id'] = CRM_Core_OptionGroup::getValue('batch_status','Data Entry'); + $params['status_id'] = CRM_Core_OptionGroup::getValue('batch_status','Data Entry', 'name'); } $params['context'] = $context; diff --git a/CRM/Financial/Page/AJAX.php b/CRM/Financial/Page/AJAX.php index 73b0f0e409..3138aa2c7b 100644 --- a/CRM/Financial/Page/AJAX.php +++ b/CRM/Financial/Page/AJAX.php @@ -214,9 +214,9 @@ class CRM_Financial_Page_AJAX { // Update totals when closing a batch $params = $totals[$recordID]; case 'reopen': - $status = $op == 'close' ? 'Closed' : 'Open'; + $status = $op == 'close' ? 'Closed' : 'Reopened'; $ids['batchID'] = $recordID; - $batchStatus = CRM_Core_PseudoConstant::get('CRM_Batch_DAO_Batch', 'status_id'); + $batchStatus = CRM_Core_PseudoConstant::get('CRM_Batch_DAO_Batch', 'status_id', array('labelColumn' => 'name')); $params['status_id'] = CRM_Utils_Array::key($status, $batchStatus); $session = CRM_Core_Session::singleton(); $params['modified_date'] = date('YmdHis'); -- 2.25.1