From d7b01136e3cbf12d7877be28f2d578e5f684f505 Mon Sep 17 00:00:00 2001 From: VangelisP Date: Wed, 25 Apr 2018 12:38:20 +0200 Subject: [PATCH] Extends the query to include contacts that might have no contributions --- sumfields.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sumfields.php b/sumfields.php index da00f1e..1a30726 100644 --- a/sumfields.php +++ b/sumfields.php @@ -470,11 +470,11 @@ function sumfields_generate_data_based_on_current_data($session = NULL) { foreach ($temp_sql as $table => $data) { // Calculate data and insert into temp table - $query = "INSERT INTO `{$data['temp_table']}` SELECT contact_id, " + $query = "INSERT INTO `{$data['temp_table']}` SELECT IFNULL(contact_id,c.id) as contact_id, " . implode(",\n", $data['triggers']) . " FROM `$table` AS t2 " - . "JOIN civicrm_contact AS c ON t2.contact_id = c.id "; - $query .= ' GROUP BY contact_id'; + . "RIGHT OUTER JOIN civicrm_contact AS c ON t2.contact_id = c.id "; + $query .= ' GROUP BY IFNULL(contact_id,c.id)'; CRM_Core_DAO::executeQuery($query); // Move temp data into custom field table