$assocAccount = findSugarAccountByPhoneNumber($rawData['callerID']); if ($assocAccount != FALSE) { logLine("Found a matching account, relating to account instead of contact\n"); $beanID = $assocAccount['values']['id']; $beanType = $assocAccount['type']; $parentType = 'Accounts'; $parentID = $beanID; } else { $assoSugarObject = findSugarObjectByPhoneNumber($rawData['callerID']); $beanID = $assoSugarObject['values']['id']; $beanType = $assoSugarObject['type']; } } setRelationshipBetweenCallAndBean($callRecord['sweet']['id'], $beanType, $beanID); if ($beanType == "Contacts" && !empty($beanID)) { $assocAccount = findAccountForContact($beanID); if ($assocAccount) { $parentType = 'Accounts'; $parentID = $assocAccount; } } else { if ($beanType == "Accounts") { $parentType = "Accounts"; $parentID = $beanID; } } echo "! Call start was " . gmdate('Y-m-d H:i:s', $callStart) . "\n"; // // ... on success also update entry in Calls module // logLine(" (INBOUND) now updating record in /Calls/ id=" . $callRecord['sweet']['id'] . "...\n");
if ($callDurationRaw > 10) { $callStatus = "Held"; $callName = "Successfull call"; } else { $callStatus = "Missed"; $callName = sprintf("Failed call (%s) ", $e['Cause-txt']); $callDescription = "Missed/failed call\n"; $callDescription .= "------------------\n"; $callDescription .= sprintf(" %-20s : %-40s\n", "Caller ID", $rawData['callerID']); } // ** EXPERIMENTAL ** $assoSugarObject = findSugarObjectByPhoneNumber($rawData['callerID']); $parentID = NULL; $parentType = NULL; if ($assoSugarObject && $assoSugarObject['type'] == 'Contacts') { $assocAccount = findAccountForContact($assoSugarObject['values']['id']); if ($assocAccount) { $parentType = 'Accounts'; $parentID = $assocAccount; } } echo "! Call start was " . gmdate('Y-m-d H:i:s', $callStart) . "\n"; // // ... on success also update entry in Calls module // print "# SQL update successfull, now updating record in /Calls/...\n"; $soapResult = $soapClient->call('set_entry', array('session' => $soapSessionId, 'module_name' => 'Calls', 'name_value_list' => array(array('name' => 'id', 'value' => $callRecord['sweet']['id']), array('name' => 'name', 'value' => $callName), array('name' => 'duration_hours', 'value' => $callDurationHours), array('name' => 'duration_minutes', 'value' => $callDurationMinutes), array('name' => 'status', 'value' => $callStatus), array('name' => 'description', 'value' => $callDescription), array('name' => 'asterisk_caller_id_c', 'value' => $rawData['callerID']), array('name' => 'date_start', 'value' => gmdate('Y-m-d H:i:s', $callStart)), array('name' => 'parent_type', 'value' => $parentType), array('name' => 'parent_id', 'value' => $parentID), array('name' => 'assigned_user_id', 'value' => $assignedUser)))); // // Establish Relationship if possible // if ($assoSugarObject) {
// from a generic company number $accountId = findAccountByPhoneNumber($accountPhoneNumber); if ($accountId) { // Is a shared company phone, link to a company only $parentType = 'Accounts'; $parentID = $accountId; $assoSugarObject = false; // no contact } else { // Attempt to find a Contact an individual number $assoSugarObject = findContactByPhoneNumber($accountPhoneNumber); // Try to find a parent company $parentID = NULL; $parentType = NULL; if ($assoSugarObject && $assoSugarObject['type'] == 'Contacts') { $assocAccount = isset($assoSugarObject['values']['id']) ? findAccountForContact($assoSugarObject['values']['id']) : FALSE; if ($assocAccount) { $parentType = 'Accounts'; $parentID = $assocAccount; } } } echo "! Call start was " . gmdate('Y-m-d H:i:s', $callStart) . "\n"; // // ... on success also update entry in Calls module // print "# SQL update successfull, now updating record in /Calls/...\n"; $soapResult = $soapClient->call('set_entry', array('session' => $soapSessionId, 'module_name' => 'Calls', 'name_value_list' => array(array('name' => 'id', 'value' => $callRecord['sweet']['id']), array('name' => 'name', 'value' => $callName), array('name' => 'duration_hours', 'value' => $callDurationHours), array('name' => 'duration_minutes', 'value' => $callDurationMinutes), array('name' => 'duration_seconds', 'value' => $callDurationSeconds), array('name' => 'status', 'value' => $callStatus), array('name' => 'description', 'value' => $callDescription), array('name' => 'asterisk_caller_id_c', 'value' => $contactNum), array('name' => 'date_start', 'value' => gmdate('Y-m-d H:i:s', $callStart)), array('name' => 'parent_type', 'value' => $parentType), array('name' => 'parent_id', 'value' => $parentID), array('name' => 'assigned_user_id', 'value' => $assignedUser)))); // // Establish Relationship if possible //