262
262
* Returns the contract ID associated with the given issue ID.
265
264
* @param integer $issue_id The issue ID
266
* @return integer The customer ID associated with the issue
265
* @return integer The contract ID associated with the issue
268
function getContractID($issue_id)
267
public static function getContractID($issue_id)
1477
1477
iss_id=$issue_id";
1478
1478
$customer_contact_id = DB_Helper::getInstance()->getOne($stmt);
1479
1479
if (!empty($customer_contact_id)) {
1480
Customer::notifyIssueClosed($prj_id, $issue_id, $customer_contact_id, $send_notification, $resolution_id, $status_id, $reason);
1481
$contact = $crm->getContact($customer_contact_id);
1482
$contact->notifyIssueClosed($issue_id, $reason);
1483
} catch (CRMException $e) {}
1483
1486
// send notifications for the issue being closed
2044
2047
'msg_id' => $msg_id,
2047
if (Customer::hasCustomerIntegration($prj_id)) {
2048
list($customer_id, $customer_contact_id) = Customer::getCustomerIDByEmails($prj_id, array($sender_email));
2049
if (!empty($customer_id)) {
2050
$contact = Customer::getContactDetails($prj_id, $customer_contact_id);
2050
if (CRM::hasCustomerIntegration($prj_id)) {
2051
$crm = CRM::getInstance($prj_id);
2053
$contact = $crm->getContactByEmail($sender_email);
2051
2054
// overwrite the reporter with the customer contact
2052
$reporter = User::getUserIDByContactID($customer_contact_id);
2055
$reporter = User::getUserIDByContactID($contact->getContactID());
2053
2056
$contact_timezone = Date_Helper::getPreferredTimezone($reporter);
2055
$data['customer'] = $customer_id;
2056
$data['contact'] = $customer_contact_id;
2057
# $data['contract'] = // XXX missing
2058
// Just use first contract / customer for now.
2059
$contract = $contact->getContracts(array('active'=>true))[0];
2060
$data['customer'] = $contract->getCustomerID();
2061
$data['contact'] = $contact->getContactID();
2062
$data['contract'] = $contract->getContractID();
2058
2063
$data['contact_person_lname'] = $contact['last_name'];
2059
2064
$data['contact_person_fname'] = $contact['first_name'];
2060
2065
$data['contact_email'] = $sender_email;
2061
2066
$data['contact_phone'] = $contact['phone'];
2062
2067
$data['contact_timezone'] = $contact_timezone;
2068
} catch (CRMException $e) {}
2065
2070
$customer_id = false;
2083
2088
$emails = array();
2084
2089
// if there are any technical account managers associated with this customer, add these users to the notification list
2085
$managers = Customer::getAccountManagers($prj_id, $data['customer']);
2090
$managers = CRM::getAccountManagers($prj_id, $data['customer']);
2086
2091
foreach ($managers as $manager) {
2087
2092
$emails[] = $manager['usr_email'];
2183
2188
// if we are creating an issue for a customer, put the
2184
2189
// main customer contact as the reporter for it
2185
if (Customer::hasCustomerIntegration($prj_id)) {
2190
if (CRM::hasCustomerIntegration($prj_id)) {
2191
$crm = CRM::getInstance($prj_id);
2186
2192
$contact_usr_id = User::getUserIDByContactID($data['contact']);
2187
2193
if (empty($contact_usr_id)) {
2188
2194
$contact_usr_id = $usr_id;
2206
2212
History::add($issue_id, Auth::getUserID(), History::getTypeID('issue_opened'), 'Issue opened by ' . User::getFullName(Auth::getUserID()));
2208
2214
$emails = array();
2209
if (Customer::hasCustomerIntegration($prj_id)) {
2215
if (CRM::hasCustomerIntegration($prj_id)) {
2216
$customer = $crm->getCustomer($data['customer']);
2217
$contract = $crm->getContract($data['contract']);
2210
2218
if (!empty($data['contact_extra_emails']) && count($data['contact_extra_emails']) > 0) {
2211
2219
$emails = $data['contact_extra_emails'];
2220
2228
// if there are any technical account managers associated with this customer, add these users to the notification list
2221
$managers = Customer::getAccountManagers($prj_id, $data['customer']);
2229
$managers = $customer->getEventumAccountManagers();
2222
2230
foreach ($managers as $manager) {
2223
2231
$emails[] = $manager['usr_email'];
2328
2336
// also send a special confirmation email to the customer contact
2329
2337
if ((@$data['notify_customer'] == 'yes') && (!empty($data['contact']))) {
2338
$contact = $contract->getContact($data['contact']);
2330
2339
// also need to pass the list of sender emails already notified,
2331
2340
// so we can avoid notifying the same person again
2332
2341
$contact_email = User::getEmailByContactID($data['contact']);
2333
2342
if (@!in_array($contact_email, $recipients)) {
2334
Customer::notifyCustomerIssue($prj_id, $issue_id, $data['contact']);
2343
$contact->notifyNewIssue($issue_id);
2336
2345
// now check for additional emails in contact_extra_emails
2337
2346
if (@count($data['contact_extra_emails']) > 0) {
2338
2347
$notification_emails = $data['contact_extra_emails'];
2339
2348
foreach($notification_emails as $notification_email) {
2340
2349
if (@!in_array($notification_email, $recipients)) {
2341
$notification_contact_id = User::getCustomerContactID(User::getUserIDByEmail($notification_email));
2342
Customer::notifyCustomerIssue($prj_id, $issue_id, $notification_contact_id);
2351
$notification_contact = $crm->getContactByEmail($notification_email);
2352
$notification_contact->notifyNewIssue($issue_id);
2353
} catch (ContactNotFoundException $e) {}
2976
2987
$created_date_ts = Date_Helper::getUnixTimestamp($res['iss_created_date'], Date_Helper::getDefaultTimezone());
2977
2988
// get customer information, if any
2978
if ((!empty($res['iss_customer_id'])) && (Customer::hasCustomerIntegration($res['iss_prj_id']))) {
2979
$res['customer_business_hours'] = Customer::getBusinessHours($res['iss_prj_id'], $res['iss_customer_id']);
2980
$res['contact_local_time'] = Date_Helper::getFormattedDate(Date_Helper::getCurrentDateGMT(), $res['iss_contact_timezone']);
2981
$res['customer_info'] = Customer::getDetails($res['iss_prj_id'], $res['iss_customer_id'], false, $res['iss_customer_contract_id'], $res['iss_customer_contact_id']);
2982
$res['redeemed_incidents'] = Customer::getRedeemedIncidentDetails($res['iss_prj_id'], $res['iss_id']);
2983
$max_first_response_time = Customer::getMaximumFirstResponseTime($res['iss_prj_id'], $res['iss_customer_id'], $res['iss_customer_contract_id']);
2984
$res['max_first_response_time'] = Misc::getFormattedTime($max_first_response_time / 60);
2985
if (empty($res['iss_first_response_date'])) {
2986
$first_response_deadline = $created_date_ts + $max_first_response_time;
2987
if (Date_Helper::getCurrentUnixTimestampGMT() <= $first_response_deadline) {
2988
$res['max_first_response_time_left'] = Date_Helper::getFormattedDateDiff($first_response_deadline, Date_Helper::getCurrentUnixTimestampGMT());
2990
$res['overdue_first_response_time'] = Date_Helper::getFormattedDateDiff(Date_Helper::getCurrentUnixTimestampGMT(), $first_response_deadline);
2989
if ((!empty($res['iss_customer_id'])) && (CRM::hasCustomerIntegration($res['iss_prj_id']))) {
2990
$crm = CRM::getInstance($res['iss_prj_id']);
2992
$customer = $crm->getCustomer($res['iss_customer_id']);
2993
$contract = $crm->getContract($res['iss_customer_contract_id']);
2994
$res['contact_local_time'] = Date_Helper::getFormattedDate(Date_Helper::getCurrentDateGMT(), $res['iss_contact_timezone']);
2995
$res['customer'] = $customer;
2996
$res['contract'] = $contract;
2997
$res['contact'] = $crm->getContact($res['iss_customer_contact_id']);
2998
// TODOCRM: Deal with incidents
2999
// $res['redeemed_incidents'] = Customer::getRedeemedIncidentDetails($res['iss_prj_id'], $res['iss_id']);
3000
$max_first_response_time = $contract->getMaximumFirstResponseTime($issue_id);
3001
$res['max_first_response_time'] = Misc::getFormattedTime($max_first_response_time / 60);
3002
if (empty($res['iss_first_response_date'])) {
3003
$first_response_deadline = $created_date_ts + $max_first_response_time;
3004
if (Date_Helper::getCurrentUnixTimestampGMT() <= $first_response_deadline) {
3005
$res['max_first_response_time_left'] = Date_Helper::getFormattedDateDiff($first_response_deadline, Date_Helper::getCurrentUnixTimestampGMT());
3007
$res['overdue_first_response_time'] = Date_Helper::getFormattedDateDiff(Date_Helper::getCurrentUnixTimestampGMT(), $first_response_deadline);
3010
} catch (CRMException $e) {
3011
// TODOCRM: Log exception?
2994
3014
$res['iss_original_description'] = $res["iss_description"];