CRM-20278 Added credit card type field to top donor report
authorEdsel <edsel.lopez@jmaconsulting.biz>
Wed, 15 Feb 2017 10:37:48 +0000 (16:07 +0530)
committerdeb.monish <monish.deb@jmaconsulting.biz>
Fri, 24 Mar 2017 06:34:30 +0000 (12:04 +0530)
----------------------------------------
* CRM-19997: Add Credit card type fields in contribution related reports
  https://issues.civicrm.org/jira/browse/CRM-19997

CRM/Report/Form/Contribute/TopDonor.php

index 2a33d66158456234ef8ffa6859093cd017fcf351..856807efb40a337d9d803c7e5343e3db9a456fca 100644 (file)
@@ -162,6 +162,24 @@ class CRM_Report_Form_Contribute_TopDonor 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_Financial_DAO_FinancialTrxn::buildOptions('card_type'),
+            'default' => NULL,
+            'type' => CRM_Utils_Type::T_STRING,
+          ),
+        ),
+      ),
       'civicrm_email' => array(
         'dao' => 'CRM_Core_DAO_Email',
         'fields' => array(
@@ -290,6 +308,10 @@ class CRM_Report_Form_Contribute_TopDonor extends CRM_Report_Form {
              LEFT  JOIN civicrm_phone  {$this->_aliases['civicrm_phone']}
                          ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_phone']}.contact_id AND
                             {$this->_aliases['civicrm_phone']}.is_primary = 1";
+
+    // for credit card type
+    $this->addFinancialTrxnFromClause();
+
     $this->addAddressFromClause();
   }
 
@@ -494,6 +516,11 @@ ORDER BY civicrm_contribution_total_amount_sum DESC
           $entryFound = TRUE;
         }
 
+        if (!empty($row['civicrm_financial_trxn_card_type'])) {
+          $rows[$rowNum]['civicrm_financial_trxn_card_type'] = $this->getLabels($row['civicrm_financial_trxn_card_type'], 'CRM_Financial_DAO_FinancialTrxn', 'card_type');
+          $entryFound = TRUE;
+        }
+
         // skip looking further in rows, if first row itself doesn't
         // have the column we need
         if (!$entryFound) {