From 649603252d58fb4a1548dfca2d192fcb9cd0751b Mon Sep 17 00:00:00 2001
From: anonymoususer72041
<247563575+anonymoususer72041@users.noreply.github.com>
Date: Wed, 17 Dec 2025 14:15:00 +0100
Subject: [PATCH 1/3] Add consolidated contact activity stream to Company
details view
---
lib/ActivityEntries.php | 63 +++++++++++++++++++++++++++++++
modules/companies/CompaniesUI.php | 38 +++++++++++++++++++
modules/companies/Show.tpl | 34 +++++++++++++++++
3 files changed, 135 insertions(+)
diff --git a/lib/ActivityEntries.php b/lib/ActivityEntries.php
index aae547979..5d4fccd0b 100755
--- a/lib/ActivityEntries.php
+++ b/lib/ActivityEntries.php
@@ -492,6 +492,69 @@ public function getAllByDataItem($dataItemID, $dataItemType)
return $this->_db->getAllAssoc($sql);
}
+ /**
+ * Returns all activity entries for contacts belonging to a company.
+ *
+ * @param integer Company ID.
+ * @return resultset Activity entries data.
+ */
+ public function getAllByCompany($companyID)
+ {
+ $sql = sprintf(
+ "SELECT
+ activity.activity_id AS activityID,
+ activity.data_item_id AS dataItemID,
+ activity.joborder_id AS jobOrderID,
+ activity.notes AS notes,
+ DATE_FORMAT(
+ activity.date_created, '%%m-%%d-%%y (%%h:%%i %%p)'
+ ) AS dateCreated,
+ activity.date_created AS dateCreatedSort,
+ activity.type AS type,
+ activity_type.short_description AS typeDescription,
+ entered_by_user.first_name AS enteredByFirstName,
+ entered_by_user.last_name AS enteredByLastName,
+ contact.contact_id AS contactID,
+ contact.first_name AS contactFirstName,
+ contact.last_name AS contactLastName,
+ IF(
+ ISNULL(joborder.title),
+ 'General',
+ CONCAT(joborder.title, ' (', company.name, ')')
+ ) AS regarding,
+ joborder.title AS regardingJobTitle,
+ company.name AS regardingCompanyName
+ FROM
+ activity
+ LEFT JOIN user AS entered_by_user
+ ON activity.entered_by = entered_by_user.user_id
+ LEFT JOIN activity_type
+ ON activity.type = activity_type.activity_type_id
+ LEFT JOIN joborder
+ ON activity.joborder_id = joborder.joborder_id
+ LEFT JOIN company
+ ON joborder.company_id = company.company_id
+ INNER JOIN contact
+ ON activity.data_item_id = contact.contact_id
+ WHERE
+ contact.company_id = %s
+ AND
+ activity.data_item_type = %s
+ AND
+ activity.site_id = %s
+ AND
+ contact.site_id = %s
+ ORDER BY
+ dateCreatedSort ASC",
+ $this->_db->makeQueryInteger($companyID),
+ $this->_db->makeQueryInteger(DATA_ITEM_CONTACT),
+ $this->_db->makeQueryInteger($this->_siteID),
+ $this->_db->makeQueryInteger($this->_siteID)
+ );
+
+ return $this->_db->getAllAssoc($sql);
+ }
+
/**
* Returns all activity types and their descriptions.
*
diff --git a/modules/companies/CompaniesUI.php b/modules/companies/CompaniesUI.php
index 59c5f6435..633d7f42f 100755
--- a/modules/companies/CompaniesUI.php
+++ b/modules/companies/CompaniesUI.php
@@ -33,6 +33,7 @@
include_once(LEGACY_ROOT . '/lib/Companies.php');
include_once(LEGACY_ROOT . '/lib/Contacts.php');
include_once(LEGACY_ROOT . '/lib/JobOrders.php');
+include_once(LEGACY_ROOT . '/lib/ActivityEntries.php');
include_once(LEGACY_ROOT . '/lib/Attachments.php');
include_once(LEGACY_ROOT . '/lib/Export.php');
include_once(LEGACY_ROOT . '/lib/ListEditor.php');
@@ -414,6 +415,42 @@ private function show()
}
}
+ $activityEntries = new ActivityEntries($this->_siteID);
+ $activityRS = $activityEntries->getAllByCompany($companyID);
+ if (!empty($activityRS))
+ {
+ foreach ($activityRS as $rowIndex => $row)
+ {
+ if (empty($activityRS[$rowIndex]['notes']))
+ {
+ $activityRS[$rowIndex]['notes'] = '(No Notes)';
+ }
+
+ if (empty($activityRS[$rowIndex]['jobOrderID']) ||
+ empty($activityRS[$rowIndex]['regarding']))
+ {
+ $activityRS[$rowIndex]['regarding'] = 'General';
+ }
+
+ $activityRS[$rowIndex]['enteredByAbbrName'] = StringUtility::makeInitialName(
+ $activityRS[$rowIndex]['enteredByFirstName'],
+ $activityRS[$rowIndex]['enteredByLastName'],
+ false,
+ LAST_NAME_MAXLEN
+ );
+
+ $activityRS[$rowIndex]['contactFullName'] = trim(
+ $activityRS[$rowIndex]['contactFirstName'] . ' ' .
+ $activityRS[$rowIndex]['contactLastName']
+ );
+
+ if ($activityRS[$rowIndex]['contactFullName'] == '')
+ {
+ $activityRS[$rowIndex]['contactFullName'] = '(Unknown Contact)';
+ }
+ }
+ }
+
/* Add an MRU entry. */
$_SESSION['CATS']->getMRU()->addEntry(
DATA_ITEM_COMPANY, $companyID, $data['name']
@@ -446,6 +483,7 @@ private function show()
$this->_template->assign('contactsRSWC', $contactsRSWC);
$this->_template->assign('privledgedUser', $privledgedUser);
$this->_template->assign('companyID', $companyID);
+ $this->_template->assign('activityRS', $activityRS);
if (!eval(Hooks::get('CLIENTS_SHOW'))) return;
diff --git a/modules/companies/Show.tpl b/modules/companies/Show.tpl
index ff6100d6a..d46d8c72f 100755
--- a/modules/companies/Show.tpl
+++ b/modules/companies/Show.tpl
@@ -402,6 +402,40 @@ use OpenCATS\UI\QuickActionMenu;
+
+
+
+
+
Activity
+| Date | +Type | +Contact | +Entered By | +Regarding | +Notes | +
|---|---|---|---|---|---|
| _($activityData['dateCreated']); ?> | +_($activityData['typeDescription']); ?> | ++ + + _($activityData['contactFullName']); ?> + + + _($activityData['contactFullName']); ?> + + | +_($activityData['enteredByAbbrName']); ?> | +_($activityData['regarding']); ?> | +_($activityData['notes']); ?> | +