CRM-20272 Added Credit Card Type field for Contribution Summary report
authorEdsel <edsel.lopez@jmaconsulting.biz>
Fri, 10 Feb 2017 14:30:09 +0000 (20:00 +0530)
committerEdsel <edsel.lopez@jmaconsulting.biz>
Thu, 16 Mar 2017 06:42:26 +0000 (12:12 +0530)
----------------------------------------
* CRM-19997: Add Credit card type fields in contribution related reports
  https://issues.civicrm.org/jira/browse/CRM-19997

CRM-20272 Added credit card type field for contribution summary report

----------------------------------------
* CRM-20272: Add credit card type field for Contribution Summary Report
  https://issues.civicrm.org/jira/browse/CRM-20272

CRM-20272 Fixed function to read from card type rather than credit card type

----------------------------------------
* CRM-20272: Add credit card type field for Contribution Summary Report
  https://issues.civicrm.org/jira/browse/CRM-20272

CRM-20272 Fixed report to read from card type rather than credit card type

----------------------------------------
* CRM-20272: Add credit card type field for Contribution Summary Report
  https://issues.civicrm.org/jira/browse/CRM-20272

CRM-20272 Removed entity financial trxn column in favour of hardcoded alias

----------------------------------------
* CRM-20272: Add credit card type field for Contribution Summary Report
  https://issues.civicrm.org/jira/browse/CRM-20272

CRM/Report/Form.php
CRM/Report/Form/Contribute/Summary.php

index 0e2c28a008b085fcbfa30b53b851700fcf86390c..6b25b697361d124d4695ce9f605b9d301e40040b 100644 (file)
@@ -4893,4 +4893,23 @@ LEFT JOIN civicrm_contact {$field['alias']} ON {$field['alias']}.id = {$this->_a
     }
   }
 
+  /**
+   * Get all labels for credit card type rows in report.
+   *
+   * @param string $creditCardTypes
+   *   comma separated option values of option group "credit_card_type".
+   */
+  public function getGroupCreditCardType($creditCardTypes) {
+    $cardTypes = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_FinancialTrxn', 'card_type');
+    $types = explode(',', $creditCardTypes);
+    $labels = array();
+    foreach ($types as $value) {
+      $label = CRM_Utils_Array::value($value, $cardTypes);
+      if (!in_array($label, $labels)) {
+        $labels[] = $label;
+      }
+    }
+    return implode(', ', array_filter($labels));
+  }
+
 }
index 9b59afb436717bb07cc3295e7f8be4ef7b3e0ef0..dde477e7d823f1c4f39f5a25fe7f5f95ebfb17ac 100644 (file)
@@ -226,6 +226,24 @@ class CRM_Report_Form_Contribute_Summary extends CRM_Report_Form {
           ),
         ),
       ),
+      'civicrm_financial_trxn' => array(
+        'dao' => 'CRM_Financial_DAO_FinancialTrxn',
+        'fields' => array(
+          'card_type' => array(
+            'title' => ts('Credit Card Type'),
+            'dbAlias' => 'GROUP_CONCAT(financial_trxn_civireport.card_type SEPARATOR ",")',
+          ),
+        ),
+        'filters' => array(
+          'card_type' => array(
+            'title' => ts('Credit Card Type'),
+            'operatorType' => CRM_Report_Form::OP_MULTISELECT,
+            'options' => CRM_Core_PseudoConstant::get('CRM_Financial_DAO_FinancialTrxn', 'card_type'),
+            'default' => NULL,
+            'type' => CRM_Utils_Type::T_STRING,
+          ),
+        ),
+      ),
       'civicrm_batch' => array(
         'dao' => 'CRM_Batch_DAO_EntityBatch',
         'grouping' => 'contri-fields',
@@ -514,6 +532,15 @@ class CRM_Report_Form_Contribute_Summary extends CRM_Report_Form {
           ON ({$this->_aliases['civicrm_batch']}.entity_id = eft.financial_trxn_id
           AND {$this->_aliases['civicrm_batch']}.entity_table = 'civicrm_financial_trxn')";
     }
+
+    // for credit card type
+    if ($this->isTableSelected('civicrm_financial_trxn')) {
+      $this->_from .= "\n LEFT JOIN civicrm_entity_financial_trxn eftcc
+                    ON ({$this->_aliases['civicrm_contribution']}.id = eftcc.entity_id AND
+                        eftcc.entity_table = 'civicrm_contribution')
+              LEFT JOIN civicrm_financial_trxn {$this->_aliases['civicrm_financial_trxn']}
+                    ON {$this->_aliases['civicrm_financial_trxn']}.id = eftcc.financial_trxn_id";
+    }
   }
 
   /**
@@ -938,6 +965,11 @@ ROUND(AVG({$this->_aliases['civicrm_contribution_soft']}.amount), 2) as civicrm_
         $entryFound = TRUE;
       }
 
+      if (!empty($row['civicrm_financial_trxn_card_type'])) {
+        $rows[$rowNum]['civicrm_financial_trxn_card_type'] = $this->getGroupCreditCardType($row['civicrm_financial_trxn_card_type']);
+        $entryFound = TRUE;
+      }
+
       // If using campaigns, convert campaign_id to campaign title
       if (array_key_exists('civicrm_contribution_campaign_id', $row)) {
         if ($value = $row['civicrm_contribution_campaign_id']) {