Hi Ken, than ks for this very useful tutorial. I followed this and worked very nice, however not quite how I wanted it to work so I hope Im not overstepping my mark but would like to suggest a couple changes, including making it upgrade safe.
First of all, as of version 5.2, to make my version Upgrade safe, copy the /modules/calls/dashlets/MyCallsDashlet folder to /custom/modules/calls/dashlets/ (If the calls or dashlets folder dont exist in custom/modules, then mkdir them or just create them). The key to getting your changes upgrade safe is to then edit /custom/modules/calls/dashlets/MyCallsDashlet/MyCallsDashlet.php on line 47 or so to this:
PHP Code:
require('custom/modules/Calls/Dashlets/MyCallsDashlet/MyCallsDashlet.data.php');
We will assume that all changes are being made in Custom directory now.
Anyways, one of the issues I had with your implementation was that if the lead or contacts Parent was an account, the account name would show up with the accounts number, and not nescessarily the name of the lead or contact himself. So I wrote the following code to mimic what you were trying to do, and goes in the same section in the Process function:
PHP Code:
//Define the DB object to use
global $db;
foreach($this->lvs->data['data'] as $rowNum => $row) {
/* Code Edit Start */
/* SQL to get the relevant details we need for the contact in the current call.*/
$LeadsContactsSQL = "Select 'Lead' as ContType, leads.id, leads.salutation, leads.first_name, leads.last_name, leads.account_name, coalesce(leads.phone_work, leads.phone_other) as phone
from calls_leads inner join calls on calls_leads.call_id = calls.id Inner join leads on calls_leads.lead_id = leads.id where calls.id = '" . $this->lvs->data['data'][$rowNum]['ID'] . "'
union
Select 'Contact' as ContType, contacts.id, contacts.salutation, contacts.first_name, contacts.last_name,
(Select accounts.name from accounts inner join accounts_contacts on accounts.id = accounts_contacts.account_id where accounts_contacts.contact_id = '" . $this->lvs->data['data'][$rowNum]['ID'] . "') as account_name, coalesce(contacts.phone_work, contacts.phone_other) as phone
from calls_contacts inner join calls on calls_contacts.call_id = calls.id Inner join contacts on calls_contacts.contact_id = contacts.id
where calls.id = '" . $this->lvs->data['data'][$rowNum]['ID'] . "'";
$LeadsContactDetails = $db->query($LeadsContactsSQL);
$ContactDetailsArr = mysqli_fetch_assoc($LeadsContactDetails);
$ContactDetails = $ContactDetailsArr['first_name'] . " " . $ContactDetailsArr['last_name'] . "</a> (" ;
if($ContactDetailsArr['account_name'] == ''){
If ($this->lvs->data['data'][$rowNum]['PARENT_NAME'] == $ContactDetailsArr['first_name'] . " " . $ContactDetailsArr['last_name']){
$ContactDetails = $ContactDetails . "No Account";
}else{
$ContactDetails = $ContactDetails . $this->lvs->data['data'][$rowNum]['PARENT_NAME'] ;
}
}else{
$ContactDetails = $ContactDetails . $ContactDetailsArr['account_name'] ;
}
$ContactDetails = $ContactDetails . ")<br />Ph: " . $ContactDetailsArr['phone'];
$this->lvs->data['data'][$rowNum]['PARENT_NAME'] = $ContactDetails;
:
Again, this may not be perfect, but Ive been pulling hair on this site for ages trying to get my head around how to customise Sugar, so this is my first attempt. Any and all criticisms welcomed. Particularily I would like to know if there is a better way to get the data I searched for with the adhoc query, seems a bit "hackey" to have to do it like that. Im sure there is a better way.
S
Bookmarks