added custom clause under whereClause and removed where function from bookkeeping...
authorSunil Pawar <sunil@skvare.com>
Fri, 28 Aug 2020 04:08:52 +0000 (09:38 +0530)
committerSunil Pawar <sunil@skvare.com>
Fri, 28 Aug 2020 04:08:52 +0000 (09:38 +0530)
CRM/Report/Form.php
CRM/Report/Form/Contribute/Bookkeeping.php

index d202b845611e96f7c86c13feee7c0357f8c91fd4..aaf8bb15fd2f57656f0eba86adc208ed8541e427 100644 (file)
@@ -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 {
index 70c7a4d857ce9c0a8f8251853d634355ab4e0bc9..06f89ab8c959ab10f3b892059bb996e391281fd2 100644 (file)
@@ -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() {