Exemple #1
0
 public function action_delete($id = null)
 {
     is_null($id) and Response::redirect('Survey_Question');
     if ($survey_question = Model_Survey_Question::find($id)) {
         $survey_question->delete();
         Session::set_flash('success', 'Deleted survey_question #' . $id);
     } else {
         Session::set_flash('error', 'Could not delete survey_question #' . $id);
     }
     Response::redirect('survey/question');
 }
Exemple #2
0
 public function get_validate($apiKey = null)
 {
     $apiCheck = \Crm\Portal\Portal_Check::api_key($apiKey);
     if ($apiCheck === false) {
         $this->response(array('status' => 'FAIL', 'message' => 'Invalid API Key has been used, please contact your IT support!'));
     } else {
         $allFields = TRUE;
         $missingFields = array();
         $surveyChoice = $apiCheck->survey;
         $surveyQuestions = \Model_Survey_Question::query()->where('survey_id', $surveyChoice)->where('required', '1')->get();
         $allSurveyQuestions = \Model_Survey_Question::query()->where('survey_id', $surveyChoice)->get();
         foreach ($surveyQuestions as $surveyRequired) {
             $requiredFields[] = 'form-q' . $surveyRequired->id;
         }
         foreach ($allSurveyQuestions as $surveyQuestions) {
             $questionFields[] = 'form-q' . $surveyQuestions->id;
         }
         // Check and make a list of any missing fields
         foreach ($requiredFields as $field) {
             if (is_null(Input::get($field, null)) || strlen(Input::get($field, null)) < 1 && !is_integer(Input::get($field, null)) || Input::get($field, null) == "-- Select") {
                 $allFields = FALSE;
                 $missingFields[] = $field;
             }
         }
         // If we have everything we need then we do our logic
         if ($allFields) {
             // Get the client type from the given questions
             $questionPassOn = array();
             foreach ($questionFields as $singleQuestion) {
                 $questionPassOn[$singleQuestion] = Input::get($singleQuestion, null);
                 $questionPassOn[str_replace('form-q', 'form-e', $singleQuestion)] = Input::get(str_replace('form-q', 'form-e', $singleQuestion), null);
             }
             \log::write('PPI-DEBUG', \Format::forge($_GET)->to_json());
             $clientType = \Crm\Portal\Portal_Check::choice($questionPassOn, $_GET, $apiKey);
             // If we can decide on a client type
             if (!is_null($clientType)) {
                 $this->response(array('client_type' => $clientType));
             } else {
                 $this->response(array('status' => 'FAIL', 'message' => 'No client type could be decided. Please complete ALL the given questions.'));
             }
         } else {
             $this->response(array('status' => 'FAIL', 'code' => '101', 'message' => 'Not all required fields were submitted! Missing fields are ' . implode(", ", $missingFields), 'missing_fields' => $missingFields));
         }
     }
 }
 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');
 }
Exemple #4
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;
 }