QILL, Overall Results Counter, Export duplicate bug, Moving/renaming amount column...
authorDeepak Srivastava <deepak.srivastava.0303@gmail.com>
Thu, 6 Mar 2014 12:34:49 +0000 (18:04 +0530)
committerDeepak Srivastava <deepak.srivastava.0303@gmail.com>
Thu, 6 Mar 2014 12:34:49 +0000 (18:04 +0530)
CRM/Contribute/BAO/Query.php
CRM/Contribute/Selector/Search.php
CRM/Export/BAO/Export.php
templates/CRM/Contribute/Form/Selector.tpl

index 092726307c763ba70afcb7024230e5f6834f4ed8..db981c061c3fd324af971864df9fc020a7458a4d 100644 (file)
@@ -143,7 +143,7 @@ class CRM_Contribute_BAO_Query {
 
     // LCD 716
     if (!empty($query->_returnProperties['contribution_soft_credit_name'])) {
-      $query->_select['contribution_soft_credit_name'] = "civicrm_contact_d.display_name as contribution_soft_credit_name";
+      $query->_select['contribution_soft_credit_name'] = "civicrm_contact_d.sort_name as contribution_soft_credit_name";
       $query->_element['contribution_soft_credit_name'] = 1;
 
       // also include contact id. Will help build hyperlinks
@@ -372,7 +372,7 @@ class CRM_Contribute_BAO_Query {
           $query->_tables['civicrm_contribution_soft'] = $query->_whereTables['civicrm_contribution_soft'] = 1;
         } else if ($value == 'both_related') {
           $query->_where[$grouping][] = "contribution_search_scredit_combined.filter_id IS NOT NULL";
-          $query->_qill[$grouping][] = ts('Contributions OR Soft Credits? - Both But Related');
+          $query->_qill[$grouping][] = ts('Contributions OR Soft Credits? - Soft Credits with related Hard Credit');
           $query->_tables['civicrm_contribution'] = $query->_whereTables['civicrm_contribution'] = 1;
           $query->_tables['civicrm_contribution_soft'] = $query->_whereTables['civicrm_contribution_soft'] = 1;
         } else if ($value == 'both') {
@@ -405,7 +405,7 @@ class CRM_Contribute_BAO_Query {
           $scTypes = $value;
           $names[] = $softCreditTypes[$value];
         }
-        $query->_qill[$grouping][]  = ts('Contribution Status %1', array(1 => $op)) . " '" . implode("' " . ts('or') . " '", $names) . "'";
+        $query->_qill[$grouping][]  = ts('Soft Credit Type %1', array(1 => $op)) . " '" . implode("' " . ts('or') . " '", $names) . "'";
         $query->_where[$grouping][] = 
           CRM_Contact_BAO_Query::buildClause(
             "civicrm_contribution_soft.soft_credit_type_id",
@@ -806,11 +806,14 @@ class CRM_Contribute_BAO_Query {
     if (in_array(self::$_contribOrSoftCredit, 
       array("only_scredits", "both_related", "both"))) {
         if (!$tempTableFilled) {
+          // build a temp table which is union of contributions and soft credits
+          // note: group-by in first part ensures uniqueness in counts
           $tempQuery = "
             CREATE TEMPORARY TABLE IF NOT EXISTS contribution_search_scredit_combined AS 
                SELECT con.id as id, con.contact_id, cso.id as filter_id, NULL as scredit_id 
                  FROM civicrm_contribution con
-            LEFT JOIN civicrm_contribution_soft cso ON con.id = cso.contribution_id 
+            LEFT JOIN civicrm_contribution_soft cso ON con.id = cso.contribution_id
+             GROUP BY id, contact_id, scredit_id
             UNION ALL
                SELECT scredit.contribution_id as id, scredit.contact_id, scredit.id as filter_id, scredit.id as scredit_id 
                  FROM civicrm_contribution_soft as scredit";
@@ -822,6 +825,18 @@ class CRM_Contribute_BAO_Query {
     return FALSE;
   }
 
+  static function softCreditReturnProperties($isExportMode = False) {
+    $properties = array(
+      'contribution_soft_credit_name'   => 1,
+      'contribution_soft_credit_amount' => 1,
+      'contribution_soft_credit_type'   => 1,
+    );
+    if ($isExportMode) {
+      $properties['contribution_soft_credit_contribution_id'] = 1;
+    }
+    return $properties;
+  }
+
   static function defaultReturnProperties($mode, $includeCustomFields = TRUE) {
     $properties = NULL;
     if ($mode & CRM_Contact_BAO_Query::MODE_CONTRIBUTE) {
@@ -864,14 +879,7 @@ class CRM_Contribute_BAO_Query {
         'contribution_campaign_id' => 1,
       );
       if (self::isSoftCreditOptionEnabled()) {
-        $properties = array_merge(
-          $properties, array(
-            'contribution_soft_credit_name'   => 1,
-            'contribution_soft_credit_amount' => 1,
-            'contribution_soft_credit_type'   => 1,
-            'contribution_soft_credit_contribution_id' => 1,
-          )
-        );
+        $properties = array_merge($properties, self::softCreditReturnProperties());
       }
       if ($includeCustomFields) {
         // also get all the custom contribution properties
@@ -988,7 +996,7 @@ class CRM_Contribute_BAO_Query {
     $options = array(
       'only_contribs' => ts('Contributions Only'),
       'only_scredits' => ts('Soft Credits Only'),
-      'both_related'  => ts('Both But Related'),
+      'both_related'  => ts('Soft Credits with related Hard Credit'),
       'both'          => ts('Both'),
     );
     $form->add('select', 'contribution_or_softcredits', ts('Contributions OR Soft Credits?'), $options, FALSE, array('class' => "crm-select2"));
index 1301561e425a2f27fb5a8ee4ff7b15728243045c..44ed3df808aa4855bfa9ccd7845c171113402c87 100644 (file)
@@ -307,6 +307,10 @@ class CRM_Contribute_Selector_Search extends CRM_Core_Selector_Base implements C
    * @return int   the total number of rows for this action
    */
   function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
+    if ($this->_includeSoftCredits) {
+      // especial sort order when rows include soft credits
+      $sort = "civicrm_contribution.receive_date DESC, civicrm_contribution.id, civicrm_contribution_soft.id";
+    }
     $result = $this->_query->searchQuery($offset, $rowCount, $sort,
       FALSE, FALSE,
       FALSE, FALSE,
@@ -440,42 +444,60 @@ class CRM_Contribute_Selector_Search extends CRM_Core_Selector_Base implements C
   public function &getColumnHeaders($action = NULL, $output = NULL) {
     self::$_columnHeaders = array(
       array(
-        'name' => ts('Amount'),
+        'name' => $this->_includeSoftCredits ? ts('Contribution Amount') : ts('Amount'),
         'sort' => 'total_amount',
         'direction' => CRM_Utils_Sort::DONTCARE,
       ),
-      array(
-        'name' => ts('Type'),
-        'sort'      => 'financial_type_id',
-        'direction' => CRM_Utils_Sort::DONTCARE,
-      ),
-      array(
-        'name' => ts('Source'),
-        'sort' => 'contribution_source',
-        'direction' => CRM_Utils_Sort::DONTCARE,
-      ),
-      array(
-        'name' => ts('Received'),
-        'sort' => 'receive_date',
-        'direction' => CRM_Utils_Sort::DESCENDING,
-      ),
-      array(
-        'name' => ts('Thank-you Sent'),
-        'sort' => 'thankyou_date',
-        'direction' => CRM_Utils_Sort::DONTCARE,
-      ),
-      array(
-        'name' => ts('Status'),
-        'sort' => 'contribution_status_id',
-        'direction' => CRM_Utils_Sort::DONTCARE,
-      ),
-      array(
-        'name' => ts('Premium'),
-        'sort' => 'product_name',
-        'direction' => CRM_Utils_Sort::DONTCARE,
-      ),
     );
-
+    if ($this->_includeSoftCredits) {
+      self::$_columnHeaders = 
+        array_merge(
+          self::$_columnHeaders, 
+          array(
+            array(
+              'name' => ts('Soft Credit Amount'),
+              'sort' => 'contribution_soft_credit_amount',
+              'direction' => CRM_Utils_Sort::DONTCARE,
+            )
+          )
+        );
+    }
+    self::$_columnHeaders = 
+      array_merge(
+        self::$_columnHeaders, 
+        array(
+          array(
+            'name' => ts('Type'),
+            'sort'      => 'financial_type_id',
+            'direction' => CRM_Utils_Sort::DONTCARE,
+          ),
+          array(
+            'name' => ts('Source'),
+            'sort' => 'contribution_source',
+            'direction' => CRM_Utils_Sort::DONTCARE,
+          ),
+          array(
+            'name' => ts('Received'),
+            'sort' => 'receive_date',
+            'direction' => CRM_Utils_Sort::DESCENDING,
+          ),
+          array(
+            'name' => ts('Thank-you Sent'),
+            'sort' => 'thankyou_date',
+            'direction' => CRM_Utils_Sort::DONTCARE,
+          ),
+          array(
+            'name' => ts('Status'),
+            'sort' => 'contribution_status_id',
+            'direction' => CRM_Utils_Sort::DONTCARE,
+          ),
+          array(
+            'name' => ts('Premium'),
+            'sort' => 'product_name',
+            'direction' => CRM_Utils_Sort::DONTCARE,
+          ),
+        )
+      );
     if (!$this->_single) {
       $pre = array(
         array('desc' => ts('Contact Type')),
@@ -488,31 +510,29 @@ class CRM_Contribute_Selector_Search extends CRM_Core_Selector_Base implements C
       self::$_columnHeaders = array_merge($pre, self::$_columnHeaders);
     }
     if ($this->_includeSoftCredits) {
-      $softCreditColumns = 
-        array(
+      self::$_columnHeaders = 
+        array_merge(
+          self::$_columnHeaders, 
           array(
-            'name' => ts('Soft Credit For'),
-            'sort' => 'contribution_soft_credit_name',
-            'direction' => CRM_Utils_Sort::DONTCARE,
-          ),
-          array(
-            'name' => ts('Soft Credit Amount'),
-            'sort' => 'contribution_soft_credit_amount',
-            'direction' => CRM_Utils_Sort::DONTCARE,
-          ),
-          array(
-            'name' => ts('Soft Credit Type'),
-            'sort' => 'contribution_soft_credit_type',
-            'direction' => CRM_Utils_Sort::DONTCARE,
-          ),
+            array(
+              'name' => ts('Soft Credit For'),
+              'sort' => 'contribution_soft_credit_name',
+              'direction' => CRM_Utils_Sort::DONTCARE,
+            ),
+            array(
+              'name' => ts('Soft Credit Type'),
+              'sort' => 'contribution_soft_credit_type',
+              'direction' => CRM_Utils_Sort::ASCENDING,
+            ),
+          )
         );
-      self::$_columnHeaders = array_merge(self::$_columnHeaders, $softCreditColumns);
     }
-    self::$_columnHeaders = array_merge(
-      self::$_columnHeaders, array(
-        array('desc' => ts('Actions'))
-      )
-    );
+    self::$_columnHeaders = 
+      array_merge(
+        self::$_columnHeaders, array(
+          array('desc' => ts('Actions'))
+        )
+      );
     return self::$_columnHeaders;
   }
 
index 4c28c8694191adcd3f8a0530d44bf96ded812803..0ba5b3fce75c247328fe859ca4f4da32d6728b86 100644 (file)
@@ -309,11 +309,11 @@ class CRM_Export_BAO_Export {
       if ($queryMode != CRM_Contact_BAO_Query::MODE_CONTACTS) {
         $componentReturnProperties = CRM_Contact_BAO_Query::defaultReturnProperties($queryMode);
         if ($queryMode == CRM_Contact_BAO_Query::MODE_CONTRIBUTE) {
-          // Following is not automatically populated because contribution search doesn't require them by default
-          $componentReturnProperties['contribution_soft_credit_name']   = 1;
-          $componentReturnProperties['contribution_soft_credit_amount'] = 1;
-          $componentReturnProperties['contribution_soft_credit_type']   = 1;
-          $componentReturnProperties['contribution_soft_credit_contribution_id']  = 1;
+          // soft credit columns are not automatically populated, because contribution search doesn't require them by default
+          $componentReturnProperties = 
+            array_merge(
+              $componentReturnProperties, 
+              CRM_Contribute_BAO_Query::softCreditReturnProperties());
         }
         $returnProperties = array_merge($returnProperties, $componentReturnProperties);
 
@@ -562,9 +562,10 @@ INSERT INTO {$componentTable} SELECT distinct gc.contact_id FROM civicrm_group_c
 
     switch ($exportMode) {
       case CRM_Export_Form_Select::CONTRIBUTE_EXPORT:
-        if (!CRM_Contribute_BAO_Query::isSoftCreditOptionEnabled()) {
-          // apply group-by only when no soft credit columns are included
-          $groupBy = 'GROUP BY civicrm_contribution.id';
+        $groupBy = 'GROUP BY civicrm_contribution.id';
+        if (CRM_Contribute_BAO_Query::isSoftCreditOptionEnabled()) {
+          // especial group by  when soft credit columns are included
+          $groupBy = 'GROUP BY contribution_search_scredit_combined.id, contribution_search_scredit_combined.scredit_id';
         }
         break;
 
index 7b341377d7a4a78183ba4d335112f99fe05b699a..838345074bb80fa049ffacfe0317930f30d35637 100644 (file)
     <td>{$row.contact_type}</td>
       <td><a href="{crmURL p='civicrm/contact/view' q="reset=1&cid=`$row.contact_id`"}">{$row.sort_name}</a></td>
     {/if}
-    <td class="right bold crm-contribution-amount"><span class="nowrap">{$row.total_amount|crmMoney:$row.currency}</span> {if $row.amount_level }<br /> ({$row.amount_level}){/if}
-    {if $row.contribution_recur_id}
-     <br /> {ts}(Recurring Contribution){/ts}
+    {if $row.contribution_soft_credit_amount}
+      <td class="right bold crm-contribution-amount">&nbsp;</td>
+    {else}
+      <td class="right bold crm-contribution-amount"><span class="nowrap">{$row.total_amount|crmMoney:$row.currency}</span> {if $row.amount_level }<br /> ({$row.amount_level}){/if}
+      {if $row.contribution_recur_id}
+       <br /> {ts}(Recurring Contribution){/ts}
+      {/if}
+      </td>
+    {/if}
+    {if $softCreditColumns}
+      <td class="right bold crm-contribution-soft_credit_amount"><span class="nowrap">{$row.contribution_soft_credit_amount|crmMoney:$row.currency}</span></td>
     {/if}
-    </td>
     <td class="crm-contribution-type crm-contribution-type_{$row.financial_type_id} crm-financial-type crm-financial-type_{$row.financial_type_id}">{$row.financial_type}</td>
     <td class="crm-contribution-source">{$row.contribution_source}</td>
     <td class="crm-contribution-receive_date">{$row.receive_date|crmDate}</td>
@@ -79,8 +86,7 @@
     </td>
     <td class="crm-contribution-product_name">{$row.product_name}</td>
     {if $softCreditColumns}
-    <td class="crm-contribution-soft_credit_name"><a href="{crmURL p='civicrm/contact/view' q="reset=1&cid=`$row.contribution_soft_credit_contact_id`"}">{$row.contribution_soft_credit_name}</a></td>
-      <td class="right bold crm-contribution-soft_credit_amount"><span class="nowrap">{$row.contribution_soft_credit_amount|crmMoney:$row.currency}</span></td>
+      <td class="crm-contribution-soft_credit_name"><a href="{crmURL p='civicrm/contact/view' q="reset=1&cid=`$row.contribution_soft_credit_contact_id`"}">{$row.contribution_soft_credit_name}</a></td>
       <td class="crm-contribution-soft_credit_type">{$row.contribution_soft_credit_type}</td>
     {/if}
     <td>{$row.action|replace:'xx':$row.contribution_id}</td>