From fd7abdceb9b1b12a1df4ef4dbe03fb1a3773e060 Mon Sep 17 00:00:00 2001 From: Pradeep Nayak Date: Wed, 16 Apr 2014 00:40:52 +0530 Subject: [PATCH] -- removed hardcoded values, added sql upgrade script to handle civicrm_batch.status_id, CRM-14191 ---------------------------------------- * CRM-14191: There are 3 options with value=0 in option group "batch_status" https://issues.civicrm.org/jira/browse/CRM-14191 --- CRM/Batch/Form/Batch.php | 2 +- CRM/Batch/Form/Entry.php | 2 +- CRM/Batch/Page/AJAX.php | 2 +- CRM/Financial/Form/Export.php | 2 +- CRM/Financial/Form/Search.php | 9 ++++--- CRM/Upgrade/Incremental/sql/4.4.5.mysql.tpl | 27 ++++++++++++++++++--- 6 files changed, 32 insertions(+), 12 deletions(-) diff --git a/CRM/Batch/Form/Batch.php b/CRM/Batch/Form/Batch.php index 6f506097ff..7f9aed5b48 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'] = 3; + $params['status_id'] = CRM_Core_OptionGroup::getValue('batch_status','Data Entry');; $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 ecc6043df9..c2c7fd9148 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' => 2, + 'status_id' => CRM_Core_OptionGroup::getValue('batch_status','Closed'), 'total' => $params['actualBatchTotal'], ); diff --git a/CRM/Batch/Page/AJAX.php b/CRM/Batch/Page/AJAX.php index 810c41e124..5c38d70dea 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'] = 3; + $params['status_id'] = CRM_Core_OptionGroup::getValue('batch_status','Data Entry'); } $params['context'] = $context; diff --git a/CRM/Financial/Form/Export.php b/CRM/Financial/Form/Export.php index 341d2965ca..8acd959e6b 100644 --- a/CRM/Financial/Form/Export.php +++ b/CRM/Financial/Form/Export.php @@ -109,7 +109,7 @@ class CRM_Financial_Form_Export extends CRM_Core_Form { $session = CRM_Core_Session::singleton(); $session->replaceUserContext(CRM_Utils_System::url('civicrm/financial/financialbatches', - "reset=1&batchStatus=5")); + "reset=1&batchStatus={$this->_exportStatusId}")); } /** diff --git a/CRM/Financial/Form/Search.php b/CRM/Financial/Form/Search.php index b9c0c63472..61806a546e 100644 --- a/CRM/Financial/Form/Search.php +++ b/CRM/Financial/Form/Search.php @@ -55,16 +55,17 @@ class CRM_Financial_Form_Search extends CRM_Core_Form { $attributes = CRM_Core_DAO::getAttribute('CRM_Batch_DAO_Batch'); $attributes['total']['class'] = $attributes['item_count']['class'] = 'number'; $this->add('text', 'title', ts('Batch Name'), $attributes['title']); - + + $batchStatus = CRM_Core_PseudoConstant::get('CRM_Batch_DAO_Batch', 'status_id', array('labelColumn' => 'name')); $this->add( 'select', 'status_id', ts('Batch Status'), array( '' => ts('- any -' ), - 1 => ts('Open'), - 2 => ts('Closed'), - 5 => ts('Exported'), + array_search('Open', $batchStatus) => ts('Open'), + array_search('Closed', $batchStatus) => ts('Closed'), + array_search('Exported', $batchStatus) => ts('Exported'), ), false ); diff --git a/CRM/Upgrade/Incremental/sql/4.4.5.mysql.tpl b/CRM/Upgrade/Incremental/sql/4.4.5.mysql.tpl index 5c57e2f1a7..96cad6f5e0 100644 --- a/CRM/Upgrade/Incremental/sql/4.4.5.mysql.tpl +++ b/CRM/Upgrade/Incremental/sql/4.4.5.mysql.tpl @@ -3,15 +3,34 @@ SELECT @option_group_id_batch_status := max(id) from civicrm_option_group where name = 'batch_status'; SELECT @weight := MAX(value) FROM civicrm_option_value WHERE option_group_id = @option_group_id_batch_status; -UPDATE civicrm_option_value +UPDATE civicrm_option_value SET value = (Select @weight := @weight +1), weight = @weight -where option_group_id = @option_group_id_batch_status AND name IN ('Data Entry', 'Reopened', 'Exported') AND value = 0 ORDER BY id; +WHERE option_group_id = @option_group_id_batch_status AND name IN ('Data Entry', 'Reopened', 'Exported') AND value = 0 ORDER BY id; SELECT @option_group_id_batch_modes := max(id) from civicrm_option_group where name = 'batch_mode'; SELECT @weights := MAX(value) FROM civicrm_option_value WHERE option_group_id = @option_group_id_batch_modes; -UPDATE civicrm_option_value +UPDATE civicrm_option_value SET value = (Select @weights := @weights +1), weight = @weights -where option_group_id = @option_group_id_batch_modes AND name IN ('Manual Batch', 'Automatic Batch') AND value = 0; \ No newline at end of file +WHERE option_group_id = @option_group_id_batch_modes AND name IN ('Manual Batch', 'Automatic Batch') AND value = 0; + +SELECT @manual_mode_id := MAX(value) FROM civicrm_option_value WHERE option_group_id = @option_group_id_batch_modes AND name = 'Manual Batch'; +UPDATE civicrm_batch SET mode_id = @manual_mode_id WHERE (mode_id IS NULL OR mode_id = 0) AND type_id IS NULL; + +SELECT @data_entry_status_id := MAX(value) FROM civicrm_option_value WHERE option_group_id = @option_group_id_batch_status AND name = 'Data Entry'; +UPDATE civicrm_batch SET status_id = @data_entry_status_id WHERE status_id = 3 AND type_id IS NOT NULL; + +SELECT @exported_status_id := MAX(value) FROM civicrm_option_value WHERE option_group_id = @option_group_id_batch_status AND name = 'Exported'; +UPDATE civicrm_navigation SET url = CONCAT('civicrm/financial/financialbatches?reset=1&batchStatus=', @exported_status_id) WHERE name = 'Exported Batches'; + +-- update status_id to Exported +SELECT @export_activity_type := max(value) FROM civicrm_option_value cov +INNER JOIN civicrm_option_group cog ON cog.id = cov.option_group_id +WHERE cog.name = 'activity_type' AND cov.name = 'Export Accounting Batch'; + +UPDATE civicrm_batch cb +INNER JOIN civicrm_activity ca ON ca.source_record_id = cb.id +SET cb.status_id = @exported_status_id +WHERE cb.status_id = 0 AND ca.activity_type_id = @export_activity_type; \ No newline at end of file -- 2.25.1