Пример #1
0
 public function action_delete($id = null)
 {
     is_null($id) and Response::redirect('Survey_Response');
     if ($survey_response = Model_Survey_Response::find($id)) {
         $survey_response->delete();
         Session::set_flash('success', 'Deleted survey_response #' . $id);
     } else {
         Session::set_flash('error', 'Could not delete survey_response #' . $id);
     }
     Response::redirect('survey/response');
 }
Пример #2
0
 public static function generate_externals_report($introducer = null, $_startDate = null, $_endDate = null)
 {
     ini_set('memory_limit', '-1');
     $startDate = is_null($_startDate) ? date('Y-m-d') : $_startDate;
     $endDate = is_null($_endDate) ? date('Y-m-d') : $_endDate;
     $externalReferrals = \Model_Crmreferral::query();
     if (!is_null($introducer)) {
         if (is_array($introducer)) {
             $externalReferrals->where('introducer_id', "IN", $introducer);
         } else {
             $externalReferrals->where('introducer_id', (int) $introducer);
         }
     } else {
         return null;
     }
     if (!is_null($_endDate)) {
         $externalReferrals->where(DB::expr('DATE(referral_date)'), '>=', $startDate)->where(DB::expr('DATE(referral_date)'), '<=', $endDate);
     } else {
         $externalReferrals->where(DB::expr('DATE(referral_date)'), '=', $startDate);
     }
     $externalReferralResult = $externalReferrals->get();
     $allReferrals = array();
     foreach ($externalReferralResult as $referral) {
         $questionCount = 0;
         $responses = \Model_Survey_Response::query()->where('reference', $referral->id)->get();
         $responseList = array();
         foreach ($responses as $singleResponse) {
             if ($singleResponse->answer_id != 0) {
                 $questionCount++;
                 $responseList[$singleResponse->question_id] = array(Model_Survey_Question::find($singleResponse->question_id)->question, Model_Survey_Question_Answer::find($singleResponse->answer_id)->answer, $singleResponse->extra);
             }
         }
         // Check if the lead has been referred
         $thisCheck = Model_Survey_Lead_Dialler::query()->where('referral_id', $referral->id);
         if ($thisCheck->count() > 0) {
             $details = $thisCheck->get_one();
             $status = $details->type;
             $goDetails = \Goautodial\Model_Vicidial_List::find($details->dialler_id);
             $completed = array('DMPLUS', 'DR', 'PPICOM');
             $failed = array('PPICLM', 'DNC', 'DNCL', 'HUNGUP', 'TPS', 'NI', 'DNQ', 'DEC', 'ALLRDY', 'NP');
             if (in_array($goDetails->status, $completed)) {
                 $statusMessage = "Success. This referral continued with the " . $status . " package.";
             } else {
                 if (in_array($goDetails->status, $failed)) {
                     $statusMessage = "Unfortunately this referral did not continue with the " . $status . " package.";
                     $status .= "no";
                 } else {
                     $statusMessage = "Referral has qualified for " . $status . ". This status will change when we have more information.";
                 }
             }
         } else {
             if (strtotime("now -48 hours") < strtotime($referral->referral_date)) {
                 $status = null;
                 $statusMessage = "Referral has not yet been passed to the Consumer. Please wait, this will change.";
             } else {
                 $status = null;
                 $statusMessage = "Referral has not yet qualified for any services. This status may change in the future.";
             }
         }
         $allReferrals[] = array($referral->id, trim(ucwords(trim($referral->title) . " " . trim($referral->forename) . " " . trim($referral->surname))), $referral->introducer_agent_name, \Model_Call_Center::find($referral->introducer_id)->title, $referral->dialler_list_id, date("d/m/Y", strtotime($referral->referral_date)), date("H:i", strtotime($referral->referral_date)), $questionCount, $responseList, $status, $statusMessage);
     }
     //print_r($allReferrals);
     return $allReferrals;
 }
Пример #3
0
 public function sendForConsolidation($emailData = array())
 {
     // -- Send the referral for consolidation
     // --------------------------------------
     // -- Create an Email to send to the consolidators
     // -----------------------------------------------
     $Email = \Email::forge();
     // -- Address needs to be from the company the agent is with
     // ---------------------------------------------------------
     $Email->from('*****@*****.**', 'Hot Key Referral');
     // -- Needs to include the company the referral was sent from, with referral ID and lead name
     // ------------------------------------------------------------------------------------------
     $Email->subject('Hot Key Referral');
     // -- This needs to go to the address set in the companies table
     // -------------------------------------------------------------
     $Email->to(\Company_class::salesEmail($this->_values['company_id']));
     // -- Referral Details
     // -------------------
     $emailData['referralID'] = $this->_referralID;
     $emailData['introducer'] = $this->_values['introducerName'];
     $emailData['company'] = $this->_values['companyName'];
     $emailData['productName'] = $this->_values['productName'];
     $emailData['referralDate'] = $this->_values['referralDate'];
     $emailData['agent'] = $this->_values['introducer_agent_name'];
     $emailData['introducer'] = \Model_Call_Center::find($this->_values['introducer_id'])->title;
     // -- Lead Details
     // ---------------
     $emailData['leadName'] = $this->fullName();
     $emailData['leadAddress'] = $this->address();
     $emailData['telHome'] = $this->_values['tel_home'];
     $emailData['telWork'] = $this->_values['tel_work'];
     $emailData['telMobile'] = $this->_values['tel_mobile'];
     /* No Need to load Data now as we get it from the answers table
        $loadData = $this->loadData();
        $emailData['questions']   = $loadData['referralQuestions'];
        */
     $answerDetails = \Model_Survey_Response::query()->where('reference', $this->_referralID)->get();
     $emailQuestions = array();
     foreach ($answerDetails as $answers) {
         $question = \Model_Survey_Question::find($answers->question_id);
         $eQuestion = $question->question;
         $answer = \Model_Survey_Question_Answer::find($answers->answer_id);
         $eAnswer = $answer->answer;
         $extraAnswer = $answers->extra;
         $emailQuestions[] = array('question' => $eQuestion, 'answer' => $eAnswer, 'extra' => $extraAnswer);
     }
     $emailData['questions'] = $emailQuestions;
     $Email->html_body(\View::forge($this->_emailTemplateDir . 'referral.php', $emailData));
     // -- Send the Email out
     // ---------------------
     $Email->send();
     $tempReferralID = empty($emailData['debtsolvLeadID']) ? $this->_referralID : $emailData['debtsolvLeadID'];
     \Log::write('Info', 'New ' . $this->_values['productName'] . ' lead referred with the ID of ' . $tempReferralID . ' from ' . $this->_values['introducerName'] . '.', 'Crm_Referrals');
 }
Пример #4
0
 public static function choice($questions = null, $portal_form = null, $apiKey = null)
 {
     // Before anything, do a duplicate check
     $apiCheck = \Crm\Portal\Portal_Check::api_key($apiKey);
     $surveyChoice = $apiCheck->survey;
     $surveyDetails = \Model_Survey::find($surveyChoice);
     $collectOnly = true;
     if ($surveyDetails->type == 'CHOICE') {
         $collectOnly = false;
     } else {
         $collectOnly = true;
     }
     $dupes = \Crm\Referrals\Referrals_model::duplicationCheck(array('forename' => isset($portal_form['first_name']) ? $portal_form['first_name'] : null, 'surname' => isset($portal_form['last_name']) ? $portal_form['last_name'] : null, 'post_code' => isset($portal_form['postcode']) ? $portal_form['postcode'] : null, 'tel_home' => isset($portal_form['phone_number']) ? $portal_form['phone_number'] : null, 'tel_work' => null, 'tel_mobile' => isset($portal_form['alt_phone']) ? $portal_form['alt_phone'] : null));
     if (count($dupes) > 0) {
         // We have a duplicate so lets find out where it comes from
     } else {
         $noppi = true;
         $nodr = true;
     }
     $centerDetails = \Model_Call_Center::query()->where('api_key', $apiKey)->get_one();
     $clientID = \Crm\Referrals\Referrals_model::createReferral(array('user_id' => '', 'company_id' => 3, 'product_id' => 1, 'dialler_lead_id' => isset($portal_form['lead_id']) ? $portal_form['lead_id'] : null, 'dialler_list_id' => isset($portal_form['list']) ? $portal_form['list'] : null, 'dialler_list_name' => '', 'introducer_agent_name' => isset($portal_form['agent']) ? $portal_form['agent'] : null, 'disposition_id' => '', 'title' => isset($portal_form['title']) ? $portal_form['title'] : null, 'forename' => isset($portal_form['first_name']) ? $portal_form['first_name'] : null, 'surname' => isset($portal_form['last_name']) ? $portal_form['last_name'] : null, 'street_and_number' => isset($portal_form['address1']) ? $portal_form['address1'] : null, 'area' => isset($portal_form['address2']) ? $portal_form['address2'] : null, 'district' => isset($portal_form['address3']) ? $portal_form['address3'] : null, 'town' => isset($portal_form['city']) ? $portal_form['city'] : null, 'county' => isset($portal_form['state']) ? $portal_form['state'] : null, 'post_code' => isset($portal_form['postal_code']) ? $portal_form['postal_code'] : null, 'date_of_birth' => isset($portal_form['date_of_birth']) ? $portal_form['date_of_birth'] : null, 'tel_home' => isset($portal_form['phone_number']) ? $portal_form['phone_number'] : null, 'tel_work' => 0, 'tel_mobile' => isset($portal_form['alt_phone']) ? $portal_form['alt_phone'] : null, 'email' => isset($portal_form['email']) ? $portal_form['email'] : null, 'notes' => isset($portal_form['comments']) ? $portal_form['comments'] : null, 'introducer_id' => $centerDetails->id));
     \log::write('PPI-DEBUG', \Format::forge($questions)->to_json());
     foreach ($questions as $questionId => $questionAnswer) {
         if (substr($questionId, 0, 6) == "form-q") {
             $answers = new \Model_Survey_Response();
             $answers->reference = $clientID;
             $answers->question_id = (int) str_replace("form-q", "", $questionId);
             $answers->answer_id = !is_null($questionAnswer) ? $questionAnswer : "";
             $answers->extra = !is_null($questions['form-e' . (int) str_replace("form-q", "", $questionId)]) ? $questions['form-e' . (int) str_replace("form-q", "", $questionId)] : "-";
             $answers->save();
         }
     }
     if (!$collectOnly) {
         if ((int) $questions['form-q21'] == 126) {
             return array('type' => 'DNQ', 'reason' => 'being in an IVA or Declared Bankrupt.');
         } else {
             if ((int) $questions['form-q19'] == 123 and (int) $questions['form-q20'] == 125) {
                 // Get client ID from the PPI system
                 $Referral = \Crm\Referrals\Referrals_class::forge($clientID);
                 $saveData['referralQuestions'] = $questions;
                 $Referral->saveData($saveData);
                 $Referral->product_id = 1;
                 $Referral->company_id = 3;
                 $Referral->save();
                 $Referral = \Crm\Referrals\Referrals_class::forge($clientID);
                 $Referral->setDisposition(14);
                 $Referral->sendForConsolidation();
                 return array('type' => 'PPI', 'clientID' => $clientID);
             } else {
                 // Save details and get client ID from Debtsolv
                 $Debtsolv = \Crm\Referrals\Referrals_debtsolv_class::forge((int) $clientID);
                 $saveData['referralQuestions'] = $questions;
                 $Debtsolv->saveData($saveData);
                 $Debtsolv->product_id = 2;
                 $Debtsolv->company_id = 1;
                 $Debtsolv->save();
                 // Reload the referral
                 $Debtsolv = \Crm\Referrals\Referrals_debtsolv_class::forge((int) $clientID);
                 $client_ID = $Debtsolv->addNewLead();
                 $Debtsolv->setDisposition(25);
                 $Debtsolv->sendForDRConsolidation();
                 return array('type' => 'DR', 'clientID' => $client_ID);
             }
         }
     } else {
         return array('type' => 'DONE', 'clientID' => $client_ID);
     }
     return null;
 }