Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

report#47 Report Bookkeeping add time field for date filter. #18268

Merged
merged 2 commits into from
Aug 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CRM/Report/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
69 changes: 25 additions & 44 deletions CRM/Report/Form/Contribute/Bookkeeping.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,8 @@ 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],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we removing receipt_date?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re-added receipt_date

'receive_date' => ['operatorType' => CRM_Report_Form::OP_DATETIME],
'receipt_date' => ['operatorType' => CRM_Report_Form::OP_DATETIME],
'contribution_source' => [
'title' => ts('Source'),
'name' => 'source',
Expand All @@ -317,6 +317,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',
],
Expand Down Expand Up @@ -364,7 +365,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' => [
Expand All @@ -383,6 +384,7 @@ public function __construct() {
],
'order_bys' => [
'payment_instrument_id' => ['title' => ts('Payment Method')],
'trxn_date' => ['title' => ts('Transaction Date')],
],
],
'civicrm_entity_financial_trxn' => [
Expand Down Expand Up @@ -516,52 +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;

$clause = $this->dateClause($field['name'], $relative, $from, $to, $field['type']);
}
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() {
Expand Down