From 7adea59a09e5f8ca4f20619ad506b734855e3f74 Mon Sep 17 00:00:00 2001 From: Sunil Pawar Date: Thu, 27 Aug 2020 22:44:31 +0530 Subject: [PATCH 1/2] report#47 Report Bookkeeping add time field for date filter. --- CRM/Report/Form/Contribute/Bookkeeping.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/CRM/Report/Form/Contribute/Bookkeeping.php b/CRM/Report/Form/Contribute/Bookkeeping.php index f70c7d29d190..70c7a4d857ce 100644 --- a/CRM/Report/Form/Contribute/Bookkeeping.php +++ b/CRM/Report/Form/Contribute/Bookkeeping.php @@ -300,8 +300,7 @@ public function __construct() { 'operatorType' => CRM_Report_Form::OP_INT, 'type' => CRM_Utils_Type::T_INT, ], - 'receive_date' => ['operatorType' => CRM_Report_Form::OP_DATE], - 'receipt_date' => ['operatorType' => CRM_Report_Form::OP_DATE], + 'receive_date' => ['operatorType' => CRM_Report_Form::OP_DATETIME], 'contribution_source' => [ 'title' => ts('Source'), 'name' => 'source', @@ -317,6 +316,7 @@ public function __construct() { 'order_bys' => [ 'contribution_id' => ['title' => ts('Contribution #')], 'contribution_status_id' => ['title' => ts('Contribution Status')], + 'receive_date' => ['title' => ts('Date Received')], ], 'grouping' => 'contri-fields', ], @@ -364,7 +364,7 @@ public function __construct() { ], 'trxn_date' => [ 'title' => ts('Transaction Date'), - 'operatorType' => CRM_Report_Form::OP_DATE, + 'operatorType' => CRM_Report_Form::OP_DATETIME, 'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME, ], 'status_id' => [ @@ -383,6 +383,7 @@ public function __construct() { ], 'order_bys' => [ 'payment_instrument_id' => ['title' => ts('Payment Method')], + 'trxn_date' => ['title' => ts('Transaction Date')], ], ], 'civicrm_entity_financial_trxn' => [ @@ -536,8 +537,10 @@ public function where() { $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']); + $clause = $this->dateClause($field['name'], $relative, $from, $to, $field['type'], $fromTime, $toTime); } else { $op = $this->_params["{$fieldName}_op"] ?? NULL; From 2aaedeaae3b0b7b0c99d7ed04bcf83ae837a30b3 Mon Sep 17 00:00:00 2001 From: Sunil Pawar Date: Fri, 28 Aug 2020 09:38:52 +0530 Subject: [PATCH 2/2] 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 d202b845611e..aaf8bb15fd2f 100644 --- a/CRM/Report/Form.php +++ b/CRM/Report/Form.php @@ -5937,7 +5937,9 @@ protected function generateFilterClause($field, $fieldName) { $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 70c7a4d857ce..06f89ab8c959 100644 --- a/CRM/Report/Form/Contribute/Bookkeeping.php +++ b/CRM/Report/Form/Contribute/Bookkeeping.php @@ -301,6 +301,7 @@ public function __construct() { '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 @@ public function orderBy() { } } - 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() {