Commit 92e088c9 authored by Pradeep Nayak's avatar Pradeep Nayak

CRM-20588, code cleanup

----------------------------------------
* CRM-20588: Pre and Post hook for Batch
  https://issues.civicrm.org/jira/browse/CRM-20588
parent ac648bfc
......@@ -51,24 +51,16 @@ class CRM_Batch_BAO_Batch extends CRM_Batch_DAO_Batch {
* Create a new batch.
*
* @param array $params
* @param array $ids
* Associated array of ids.
* @param string $context
* String.
*
* @return object
* $batch batch object
*/
public static function create(&$params, $ids = NULL, $context = NULL) {
public static function create(&$params) {
if (empty($params['id'])) {
$params['name'] = CRM_Utils_String::titleToVar($params['title']);
}
$batch = new CRM_Batch_DAO_Batch();
$batch->copyValues($params);
if ($context == 'financialBatch' && !empty($ids['batchID'])) {
$batch->id = $ids['batchID'];
}
$batch->save();
return $batch;
......
......@@ -167,12 +167,11 @@ class CRM_Financial_Form_Export extends CRM_Core_Form {
$batchParams['modified_id'] = $session->get('userID');
$batchParams['status_id'] = $this->_exportStatusId;
$ids = array();
foreach ($batchIds as $batchId) {
$batchParams['id'] = $ids['batchID'] = $batchId;
$batchParams['id'] = $batchId;
// Update totals
$batchParams = array_merge($batchParams, $totals[$batchId]);
CRM_Batch_BAO_Batch::create($batchParams, $ids, 'financialBatch');
CRM_Batch_BAO_Batch::create($batchParams);
}
CRM_Batch_BAO_Batch::exportFinancialBatch($batchIds, $this->_exportFormat);
......
......@@ -196,11 +196,9 @@ class CRM_Financial_Form_FinancialBatch extends CRM_Contribute_Form {
*/
public function postProcess() {
$session = CRM_Core_Session::singleton();
$ids = array();
$params = $this->exportValues();
$batchStatus = CRM_Core_PseudoConstant::get('CRM_Batch_DAO_Batch', 'status_id');
if ($this->_id) {
$ids['batchID'] = $this->_id;
$params['id'] = $this->_id;
}
......@@ -228,7 +226,7 @@ class CRM_Financial_Form_FinancialBatch extends CRM_Contribute_Form {
$activityTypeName = 'Edit Batch';
}
$batch = CRM_Batch_BAO_Batch::create($params, $ids, 'financialBatch');
$batch = CRM_Batch_BAO_Batch::create($params);
$activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, FALSE, FALSE, 'name');
......
......@@ -183,7 +183,6 @@ class CRM_Financial_Page_AJAX {
if ($recordClass[0] == 'CRM' && count($recordClass) >= 3) {
foreach ($records as $recordID) {
$params = array();
$ids = NULL;
switch ($op) {
case 'assign':
case 'remove':
......@@ -207,14 +206,12 @@ class CRM_Financial_Page_AJAX {
$params = $totals[$recordID];
case 'reopen':
$status = $op == 'close' ? 'Closed' : 'Reopened';
$ids['batchID'] = $recordID;
$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');
$params['modified_id'] = $session->get('userID');
$params['id'] = $recordID;
$context = "financialBatch";
break;
case 'export':
......@@ -223,17 +220,11 @@ class CRM_Financial_Page_AJAX {
case 'delete':
$params = $recordID;
$context = "financialBatch";
break;
}
if (method_exists($recordBAO, $methods[$op]) & !empty($params)) {
if (isset($context)) {
$updated = call_user_func_array(array($recordBAO, $methods[$op]), array(&$params, $ids, $context));
}
else {
$updated = call_user_func_array(array($recordBAO, $methods[$op]), array(&$params, $ids));
}
$updated = call_user_func_array(array($recordBAO, $methods[$op]), array(&$params));
if ($updated) {
$redirectStatus = $updated->status_id;
if ($batchStatus[$updated->status_id] == "Reopened") {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment