~eventum-developers/eventum/trunk

« back to all changes in this revision

Viewing changes to lib/eventum/class.issue.php

  • Committer: Bryan Alsdorf
  • Date: 2013-08-23 03:50:34 UTC
  • mto: (4033.1.168 eventum-skysql)
  • mto: This revision was merged to the branch mainline in revision 4660.
  • Revision ID: bryan@montyprogram.com-20130823035034-7f5r3pt1xg0xnnhk
Initial commit of CRM migration

Show diffs side-by-side

added added

removed removed

Lines of Context:
96
96
        if (count($categories) > 0) {
97
97
            $headings[] = 'Category';
98
98
        }
99
 
        if (Customer::hasCustomerIntegration($prj_id)) {
 
99
        if (CRM::hasCustomerIntegration($prj_id)) {
100
100
            $headings[] = 'Customer';
101
101
        }
102
102
        $headings[] = 'Status';
261
261
    /**
262
262
     * Returns the contract ID associated with the given issue ID.
263
263
     *
264
 
     * @access  public
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
267
266
     */
268
 
    function getContractID($issue_id)
 
267
    public static function getContractID($issue_id)
269
268
    {
270
269
        static $returns;
271
270
 
1467
1466
        }
1468
1467
 
1469
1468
        if ($send_notification) {
1470
 
            if (Customer::hasCustomerIntegration($prj_id)) {
 
1469
            if (CRM::hasCustomerIntegration($prj_id)) {
 
1470
                $crm = CRM::getInstance($prj_id);
1471
1471
                // send a special confirmation email when customer issues are closed
1472
1472
                $stmt = "SELECT
1473
1473
                            iss_customer_contact_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);
 
1480
                    try {
 
1481
                        $contact = $crm->getContact($customer_contact_id);
 
1482
                        $contact->notifyIssueClosed($issue_id, $reason);
 
1483
                    } catch (CRMException $e) {}
1481
1484
                }
1482
1485
            }
1483
1486
            // send notifications for the issue being closed
1728
1731
            }
1729
1732
 
1730
1733
            // if there is customer integration, mark last customer action
1731
 
            if ((Customer::hasCustomerIntegration($prj_id)) && (User::getRoleByUser($usr_id, $prj_id) == User::getRoleID('Customer'))) {
 
1734
            if ((CRM::hasCustomerIntegration($prj_id)) && (User::getRoleByUser($usr_id, $prj_id) == User::getRoleID('Customer'))) {
1732
1735
                self::recordLastCustomerAction($issue_id);
1733
1736
            }
1734
1737
 
2044
2047
            'msg_id' => $msg_id,
2045
2048
        );
2046
2049
 
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);
 
2052
            try {
 
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);
2054
2057
 
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;
2063
 
            }
 
2068
            } catch (CRMException $e) {}
2064
2069
        } else {
2065
2070
            $customer_id = false;
2066
2071
        }
2082
2087
 
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'];
2088
2093
        }
2097
2102
        // only assign the issue to an user if the associated customer has any technical account managers
2098
2103
        $users = array();
2099
2104
        $has_TAM = false;
2100
 
        if ((Customer::hasCustomerIntegration($prj_id)) && (count($managers) > 0)) {
 
2105
        if ((CRM::hasCustomerIntegration($prj_id)) && (count($managers) > 0)) {
2101
2106
            foreach ($managers as $manager) {
2102
2107
                if ($manager['cam_type'] == 'intpart') {
2103
2108
                    continue;
2182
2187
 
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()));
2207
2213
 
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'];
2212
2220
            }
2218
2226
                }
2219
2227
            }
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'];
2224
2232
            }
2233
2241
        // only assign the issue to an user if the associated customer has any technical account managers
2234
2242
        $users = array();
2235
2243
        $has_TAM = false;
2236
 
        if ((Customer::hasCustomerIntegration($prj_id)) && (count($managers) > 0)) {
 
2244
        if ((CRM::hasCustomerIntegration($prj_id)) && (count($managers) > 0)) {
2237
2245
            foreach ($managers as $manager) {
2238
2246
                if ($manager['cam_type'] == 'intpart') {
2239
2247
                    continue;
2327
2335
        }
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);
2335
2344
            }
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);
 
2350
                        try {
 
2351
                            $notification_contact = $crm->getContactByEmail($notification_email);
 
2352
                            $notification_contact->notifyNewIssue($issue_id);
 
2353
                        } catch (ContactNotFoundException $e) {}
2343
2354
                    }
2344
2355
                }
2345
2356
            }
2409
2420
            $stmt .= "iss_sta_id=" . Misc::escapeInteger($initial_status) . ",";
2410
2421
        }
2411
2422
 
2412
 
        if (Customer::hasCustomerIntegration($prj_id)) {
 
2423
        if (CRM::hasCustomerIntegration($prj_id)) {
2413
2424
            $stmt .= "
2414
2425
                    iss_customer_id='". Misc::escapeString($data['customer']) . "',";
2415
2426
            if (!empty($data['contract'])) {
2975
2986
            } else {
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());
2989
 
                        } else {
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']);
 
2991
                    try {
 
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());
 
3006
                            } else {
 
3007
                                $res['overdue_first_response_time'] = Date_Helper::getFormattedDateDiff(Date_Helper::getCurrentUnixTimestampGMT(), $first_response_deadline);
 
3008
                            }
2991
3009
                        }
 
3010
                    } catch (CRMException $e) {
 
3011
                        // TODOCRM: Log exception?
2992
3012
                    }
2993
3013
                }
2994
3014
                $res['iss_original_description'] = $res["iss_description"];