From 2aaedeaae3b0b7b0c99d7ed04bcf83ae837a30b3 Mon Sep 17 00:00:00 2001 From: Sunil Pawar Date: Fri, 28 Aug 2020 09:38:52 +0530 Subject: [PATCH] added custom clause under whereClause and removed where function from bookkeeping, re-added receipt_date --- CRM/Report/Form.php | 4 +- CRM/Report/Form/Contribute/Bookkeeping.php | 64 +++++++--------------- 2 files changed, 24 insertions(+), 44 deletions(-) diff --git a/CRM/Report/Form.php b/CRM/Report/Form.php index d202b84561..aaf8bb15fd 100644 --- a/CRM/Report/Form.php +++ b/CRM/Report/Form.php @@ -5937,7 +5937,9 @@ LEFT JOIN civicrm_contact {$field['alias']} ON {$field['alias']}.id = {$this->_a $relative = $this->_params["{$fieldName}_relative"] ?? NULL; $from = $this->_params["{$fieldName}_from"] ?? NULL; $to = $this->_params["{$fieldName}_to"] ?? NULL; - return $this->dateClause($field['dbAlias'], $relative, $from, $to, $field['type']); + $fromTime = $this->_params["{$fieldName}_from_time"] ?? NULL; + $toTime = $this->_params["{$fieldName}_to_time"] ?? NULL; + return $this->dateClause($field['dbAlias'], $relative, $from, $to, $field['type'], $fromTime, $toTime); } } else { diff --git a/CRM/Report/Form/Contribute/Bookkeeping.php b/CRM/Report/Form/Contribute/Bookkeeping.php index 70c7a4d857..06f89ab8c9 100644 --- a/CRM/Report/Form/Contribute/Bookkeeping.php +++ b/CRM/Report/Form/Contribute/Bookkeeping.php @@ -301,6 +301,7 @@ class CRM_Report_Form_Contribute_Bookkeeping extends CRM_Report_Form { 'type' => CRM_Utils_Type::T_INT, ], 'receive_date' => ['operatorType' => CRM_Report_Form::OP_DATETIME], + 'receipt_date' => ['operatorType' => CRM_Report_Form::OP_DATETIME], 'contribution_source' => [ 'title' => ts('Source'), 'name' => 'source', @@ -517,54 +518,31 @@ class CRM_Report_Form_Contribute_Bookkeeping extends CRM_Report_Form { } } - public function where() { - foreach ($this->_columns as $tableName => $table) { - if (array_key_exists('filters', $table)) { - foreach ($table['filters'] as $fieldName => $field) { - $clause = NULL; - if (in_array($fieldName, [ - 'credit_accounting_code', - 'credit_name', - 'credit_contact_id', - ])) { - $field['dbAlias'] = "CASE + /** + * overriding to modify dbAlias for few fields. + * + * @param array $field Field specifications + * @param string $op Query operator (not an exact match to sql) + * @param mixed $value + * @param float $min + * @param float $max + * + * @return null|string + */ + public function whereClause(&$field, $op, $value, $min, $max) { + if ($field['alias'] == 'financial_account_civireport_credit' && + in_array($field['name'], ['accounting_code', 'id', 'contact_id']) + ) { + $field['dbAlias'] = "CASE WHEN financial_trxn_civireport.from_financial_account_id IS NOT NULL THEN financial_account_civireport_credit_1.{$field['name']} ELSE financial_account_civireport_credit_2.{$field['name']} END"; - } - if (CRM_Utils_Array::value('type', $field) & CRM_Utils_Type::T_DATE) { - $relative = $this->_params["{$fieldName}_relative"] ?? NULL; - $from = $this->_params["{$fieldName}_from"] ?? NULL; - $to = $this->_params["{$fieldName}_to"] ?? NULL; - $fromTime = $this->_params["{$fieldName}_from_time"] ?? NULL; - $toTime = $this->_params["{$fieldName}_to_time"] ?? NULL; - - $clause = $this->dateClause($field['name'], $relative, $from, $to, $field['type'], $fromTime, $toTime); - } - else { - $op = $this->_params["{$fieldName}_op"] ?? NULL; - if ($op) { - $clause = $this->whereClause($field, - $op, - CRM_Utils_Array::value("{$fieldName}_value", $this->_params), - CRM_Utils_Array::value("{$fieldName}_min", $this->_params), - CRM_Utils_Array::value("{$fieldName}_max", $this->_params) - ); - } - } - if (!empty($clause)) { - $clauses[] = $clause; - } - } - } - } - if (empty($clauses)) { - $this->_where = 'WHERE ( 1 )'; - } - else { - $this->_where = 'WHERE ' . implode(' AND ', $clauses); } + + $clause = parent::whereClause($field, $op, $value, $min, $max); + + return $clause; } public function postProcess() { -- 2.25.1