Merge pull request #10024 from rnao/fix-mem-cancel-activity
[civicrm-core.git] / CRM / Report / Form / Contribute / Lybunt.php
index ce1a06c7c0944b2ef42e25eaee397e4d67bcf7dd..93bcf8ec56a367408d166fb5328309ebe8be9ea4 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 4.7                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2016                                |
+ | Copyright CiviCRM LLC (c) 2004-2017                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -28,7 +28,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2016
+ * @copyright CiviCRM LLC (c) 2004-2017
  */
 class CRM_Report_Form_Contribute_Lybunt extends CRM_Report_Form {
 
@@ -248,6 +248,26 @@ class CRM_Report_Form_Contribute_Lybunt extends CRM_Report_Form {
         ),
       ),
     );
+    $this->_columns += array(
+      '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,
+          ),
+        ),
+      ),
+    );
 
     // If we have a campaign, build out the relevant elements
     if ($campaignEnabled && !empty($this->activeCampaigns)) {
@@ -358,6 +378,8 @@ class CRM_Report_Form_Contribute_Lybunt extends CRM_Report_Form {
       $this->selectivelyAddLocationTablesJoinsToFilterQuery();
     }
 
+    // for credit card type
+    $this->addFinancialTrxnFromClause();
   }
 
   /**
@@ -556,7 +578,7 @@ class CRM_Report_Form_Contribute_Lybunt extends CRM_Report_Form {
     $this->contactTempTable = 'civicrm_report_temp_lybunt_c_' . date('Ymd_') . uniqid();
     $this->limit();
     $getContacts = "
-      CREATE TEMPORARY TABLE $this->contactTempTable
+      CREATE TEMPORARY TABLE $this->contactTempTable {$this->_databaseAttributes}
       SELECT SQL_CALC_FOUND_ROWS {$this->_aliases['civicrm_contact']}.id as cid {$this->_from} {$this->_where}
       GROUP BY {$this->_aliases['civicrm_contact']}.id";
     $this->executeReportQuery($getContacts);
@@ -581,6 +603,7 @@ class CRM_Report_Form_Contribute_Lybunt extends CRM_Report_Form {
    */
   public function buildQuery($applyLimit = TRUE) {
     $this->buildGroupTempTable();
+    $this->buildPermissionClause();
     // Calling where & select before FROM allows us to build temp tables to use in from.
     $this->where();
     $this->select();
@@ -733,6 +756,11 @@ class CRM_Report_Form_Contribute_Lybunt extends CRM_Report_Form {
         $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) {