public function action_delete($id = null) { if ($call_center = Model_Call_Center::find($id)) { $call_center->delete(); Session::set_flash('success', 'Deleted call_center #' . $id); } else { Session::set_flash('error', 'Could not delete call_center #' . $id); } Response::redirect('call/center'); }
public function action_senior($center = null) { if (Auth::has_access('reports.all_centers')) { $view_all = TRUE; } else { $view_all = FALSE; } $all_call_centers = Model_Call_Center::find('all'); $this->template->title = 'Senior Leaderboard'; $this->template->content = View::forge('leaderboard/senior', array('view_all' => $view_all, 'all_call_centers' => $all_call_centers, 'center' => $center, 'url' => !is_null($center) ? '/reports/get_senior_report/' . $center . '.json' : '/reports/get_senior_report.json')); }
public function addNewLead() { // -- Create a new array the matches the Debtsolv API // -------------------------------------------------- $data = array(); $data = $this->_values; if (count($data) <= 0) { return; } $debtsolvData = array(); $debtsolvData['title'] = $data['title']; $debtsolvData['first_name'] = $data['forename']; $debtsolvData['last_name'] = $data['surname']; $debtsolvData['address1'] = $data['street_and_number']; $debtsolvData['address2'] = $data['area']; $debtsolvData['city'] = $data['town']; $debtsolvData['county'] = $data['county']; $debtsolvData['postal_code'] = $data['post_code']; $debtsolvData['email'] = $data['email']; $debtsolvData['comments'] = $data['notes']; $debtsolvData['LeadID'] = 0; $debtsolvData['LeadRef2'] = \Model_Call_Center::find($data['introducer_id'])->shortcode; // -- Needs to be short code from the company $debtsolvData['phone_number'] = $data['tel_home']; $debtsolvData['alt_phone'] = $data['tel_mobile']; $debtsolvData['AgentID'] = $this->userInfo('username'); $debtsolvData['AgentFullName'] = $this->userInfo('name'); // -- Set ListID Get the call centre ID and set the ListID // ------------------------------------------------------- $listID = 99999; switch ($data['introducer_id']) { case 5: // -- SixEleven // ------------ $listID = 'Sixeleven'; break; case 6: // --RJ High // --------- $listID = 'RJ5'; break; } $debtsolvData['ListID'] = $listID; // -- This needs to be changed to the call centres list in Debtsolv $this->clientID = $this->send('add_new_lead', $debtsolvData); // -- Update the call result to referred (900) // ------------------------------------------- if ($this->clientID > 0) { $this->updateCallResult(900); } $this->_values['debtsolvLeadID'] = $this->clientID; return $this->clientID; }
public static function choice($questions = null, $portal_form = null, $apiKey = null) { // Before anything, do a duplicate check $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::find()->where('api_key', $apiKey)->get_one(); $clientID = \Crm\Referrals\Referrals_model::createReferral(array('user_id' => '', 'company_id' => 1, 'product_id' => 1, 'dialler_lead_id' => isset($portal_form['lead_id']) ? $portal_form['lead_id'] : null, 'dialler_list_id' => isset($portal_form['list_id']) ? $portal_form['list_id'] : null, 'dialler_list_name' => '', '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)); if (Portal_Check::values_to_bool($questions['form-q5']) === true) { return array('type' => 'DNQ', 'reason' => 'being in an IVA or Declared Bankrupt.'); } else { if (Portal_Check::values_to_bool($questions['form-q3']) === false and Portal_Check::values_to_bool($questions['form-q4']) === false) { // 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); } } return null; }
public function action_disposition() { $this->template->title = "PPI Disposition Report"; if (\Auth::has_access('reports.all_centers')) { $center = \Input::post('center'); $view_all = TRUE; } else { $view_all = FALSE; list($driver, $user_id) = \Auth::get_user_id(); $this_user = \Model_User::find($user_id); $center = $this_user->call_center_id; } $all_call_centers = \Model_Call_Center::find('all'); $hourlyStatsReport = array('Referrals' => \Crm\Reports\Model_Ppi::perPeriod('referral', $center, \Input::post('startdate'), \Input::post('enddate')), 'Pack Outs' => \Crm\Reports\Model_Ppi::perPeriod('packOut', $center, \Input::post('startdate'), \Input::post('enddate')), 'Pack In' => \Crm\Reports\Model_Ppi::perPeriod('packIn', $center, \Input::post('startdate'), \Input::post('enddate'))); $quickView = array(array('No Contacts' => count(\Crm\Reports\Model_Ppi::simpleStats('noContact', $center, \Input::post('startdate'), \Input::post('enddate'))), 'Referrals' => count(\Crm\Reports\Model_Ppi::simpleStats('referral', $center, \Input::post('startdate'), \Input::post('enddate'))), 'Pack Outs' => count(\Crm\Reports\Model_Ppi::simpleStats('packOut', $center, \Input::post('startdate'), \Input::post('enddate'))), 'Pack Ins' => count(\Crm\Reports\Model_Ppi::packIns($center, \Input::post('startdate'), \Input::post('enddate'))))); $report = Report\Create::forge(array('hourlyStats' => array('reportResults' => $hourlyStatsReport, 'displayType' => 'chart'), 'noContacts' => array('reportResults' => \Crm\Reports\Model_Ppi::simpleStats('noContact', $center, \Input::post('startdate'), \Input::post('enddate')), 'options' => array('class' => 'zebra-striped datatable')), 'referrals' => array('reportResults' => \Crm\Reports\Model_Ppi::simpleStats('referral', $center, \Input::post('startdate'), \Input::post('enddate')), 'options' => array('class' => 'zebra-striped datatable')), 'packOuts' => array('reportResults' => \Crm\Reports\Model_Ppi::simpleStats('packOut', $center, \Input::post('startdate'), \Input::post('enddate')), 'options' => array('class' => 'zebra-striped datatable')), 'packIns' => array('reportResults' => \Crm\Reports\Model_Ppi::packIns($center, \Input::post('startdate'), \Input::post('enddate')), 'options' => array('class' => 'zebra-striped datatable')), 'quickView' => array('reportResults' => $quickView, 'options' => array('direction' => 'vertical'))), 3600); $this->template->content = View::forge(static::$_viewPath . 'ppi/disposition.php', array('reports' => $report->generate(), 'all_call_centers' => $all_call_centers, 'center' => $center, 'start_date' => \Input::post('startdate'), 'end_date' => \Input::post('enddate'), 'view_all' => $view_all)); }
public function action_edit($id = null) { is_null($id) and Response::redirect('Staff'); $staff = Model_Staff::find($id); $val = Model_Staff::validate('edit'); if ($val->run()) { $staff->first_name = Input::post('first_name'); $staff->last_name = Input::post('last_name'); $staff->intranet_id = Input::post('intranet_id'); $staff->dialler_id = Input::post('dialler_id'); $staff->debtsolv_id = Input::post('debtsolv_id'); $staff->network_id = Input::post('network_id'); $staff->center_id = Input::post('center_id'); $staff->department_id = Input::post('department_id'); $staff->active = Input::post('active'); if ($staff->save()) { Session::set_flash('success', 'Updated staff #' . $id); Response::redirect('staff'); } else { Session::set_flash('error', 'Could not update staff #' . $id); } } else { if (Input::method() == 'POST') { $staff->first_name = $val->validated('first_name'); $staff->last_name = $val->validated('last_name'); $staff->intranet_id = $val->validated('intranet_id'); $staff->dialler_id = $val->validated('dialler_id'); $staff->debtsolv_id = $val->validated('debtsolv_id'); $staff->network_id = $val->validated('network_id'); $staff->center_id = $val->validated('center_id'); $staff->department_id = $val->validated('department_id'); $staff->active = $val->validated('active'); Session::set_flash('error', $val->error()); } $this->template->set_global('staff', $staff, false); } $departments = Model_Staff_Department::find('all'); $centers = Model_Call_Center::find('all'); $this->template->set_global('departments', $departments, false); $this->template->set_global('centers', $centers, false); $this->template->title = "Staffs"; $this->template->content = View::forge('staff/edit'); }
public function addNewLead() { // -- Create a new array the matches the Debtsolv API // -------------------------------------------------- $portal_form = array(); $portal_form = $this->_values; if (count($portal_form) <= 0) { return 0; } $debtsolvData = array(); $debtsolvData['title'] = isset($portal_form['title']) ? $portal_form['title'] : ''; $debtsolvData['first_name'] = isset($portal_form['first_name']) ? $portal_form['first_name'] : ''; $debtsolvData['last_name'] = isset($portal_form['last_name']) ? $portal_form['last_name'] : ''; $debtsolvData['address1'] = isset($portal_form['address1']) ? $portal_form['address1'] : ''; $debtsolvData['address2'] = isset($portal_form['address2']) ? $portal_form['address2'] : ''; $debtsolvData['city'] = isset($portal_form['city']) ? $portal_form['city'] : ''; $debtsolvData['county'] = isset($portal_form['state']) ? $portal_form['state'] : ''; $debtsolvData['postal_code'] = isset($portal_form['postal_code']) ? $portal_form['postal_code'] : ''; $debtsolvData['email'] = isset($portal_form['email']) ? $portal_form['email'] : ''; $debtsolvData['comments'] = isset($portal_form['comments']) ? $portal_form['comments'] : ''; $debtsolvData['LeadID'] = (int) $portal_form['lead_id']; $debtsolvData['LeadRef2'] = \Model_Call_Center::find($portal_form['introducer_id'])->shortcode; // -- Needs to be short code from the company $debtsolvData['phone_number'] = isset($portal_form['phone_number']) ? $portal_form['phone_number'] : ''; $debtsolvData['alt_phone'] = isset($portal_form['alt_phone']) ? $portal_form['alt_phone'] : ''; $debtsolvData['AgentID'] = isset($portal_form['AgentID']) ? $portal_form['AgentID'] : ''; $debtsolvData['AgentFullName'] = isset($portal_form['agent']) ? $portal_form['agent'] : ''; #$this->userInfo('name'); $debtsolvData['ListID'] = isset($portal_form['list']) ? $portal_form['list'] : '0'; // -- This needs to be changed to the call centres list in Debtsolv $debtsolvData['ListName'] = isset($portal_form['ListName']) ? $portal_form['ListName'] : ''; $this->clientID = $this->send('add_new_lead', $debtsolvData); // -- Update the call result to referred (900) // ------------------------------------------- if ($this->clientID > 0) { $this->updateCallResult(900); // -- Test #$this->updateCallResult(2040); } $this->_values['debtsolvLeadID'] = $this->clientID; return $this->clientID; }
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'); }
public function action_edit($id = null) { is_null($id) and Response::redirect('Dialler_Campaign'); $dialler_campaign = Model_Dialler_Campaign::find($id); $val = Model_Dialler_Campaign::validate('edit'); if ($val->run()) { $dialler_campaign->campaign_title = Input::post('campaign_title'); $dialler_campaign->campaign_name = Input::post('campaign_name'); $dialler_campaign->campaign_description = Input::post('campaign_description'); $dialler_campaign->call_center_id = Input::post('call_center_id'); if ($dialler_campaign->save()) { Session::set_flash('success', 'Updated dialler_campaign #' . $id); Response::redirect('dialler/campaign'); } else { Session::set_flash('error', 'Could not update dialler_campaign #' . $id); } } else { if (Input::method() == 'POST') { $dialler_campaign->campaign_title = $val->validated('campaign_title'); $dialler_campaign->campaign_name = $val->validated('campaign_name'); $dialler_campaign->campaign_description = $val->validated('campaign_description'); $dialler_campaign->call_center_id = $val->validated('call_center_id'); Session::set_flash('error', $val->error()); } $this->template->set_global('dialler_campaign', $dialler_campaign, false); } $this->template->set_global('call_centers', Arr::assoc_to_keyval(Model_Call_Center::find('all'), 'id', 'title'), false); $this->template->title = "Dialler_campaigns"; $this->template->content = View::forge('dialler/campaign/edit'); }
public function action_disposition() { if (Auth::has_access('reports.all_centers')) { $center = $this->param('center'); $view_all = TRUE; } else { $view_all = FALSE; list($driver, $user_id) = Auth::get_user_id(); $this_user = Model_User::find($user_id); $call_center = Model_Call_Center::find($this_user->call_center_id); if (is_null($call_center->shortcode)) { $this->response(array('status' => 'FAIL', 'message' => 'You do not have access to the disposition report.')); } else { $center = $call_center->shortcode; } } $start_date = $this->param('startdate'); $end_date = $this->param('enddate'); $all_call_centers = Model_Call_Center::find('all'); $report_url = "/reports/dispositions"; $report_url .= !is_null($center) ? "/center/" . $center : ""; $report_url .= !is_null($start_date) ? "/" . $start_date : ""; $report_url .= !is_null($end_date) ? "/" . $end_date : ""; $report_url .= ".json"; $this->template->title = 'Reports » Disposition'; $this->template->content = View::forge('reports/disposition', array('view_all' => $view_all, 'all_call_centers' => $all_call_centers, 'center' => $center, 'start_date' => $start_date, 'end_date' => $end_date, 'report_url' => $report_url)); }
/** * User needs to create a referral from scratch. * * @access public * @return void */ public function action_create() { $creditorList = Creditor_class::loadCreditorList(); $debtList = \Crm\Ppi\Ppi_class::getDebtList(); $centers = \Model_Call_Center::find('all'); $this->template->title = "Add Referral"; $this->template->content = View::forge(static::$_viewPath . '/create.php', array('creditorList' => $creditorList, 'debtList' => $debtList, 'introducers' => $centers)); }
public function get_save($apiKey, $surveyID = 0) { // -- Check API Key // ---------------- $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 { if ((int) $surveyID == 0) { $this->response(array('status' => 'FAIL', 'message' => 'Invalid Survey ID, please contact your IT support!')); } else { // -- Save the Lead Details // ------------------------ $centerDetails = \Model_Call_Center::query()->where('api_key', $apiKey)->get_one(); $Debtsolv = new Debtsolv(); $Debtsolv->data(\Input::get()); $Debtsolv->data(array('introducer_id' => $centerDetails->id)); $leadpoolID = 0; $leadpoolID = $Debtsolv->addNewLead(); if ((int) $leadpoolID > 0) { $responseLogID = 0; $responseLogID = ScriptForms::saveFormData($leadpoolID, 0, 0, 1, $surveyID, \Input::get('scriptForm')); $Survey = new ScriptForms($surveyID); // -- Save the Survey Results // -------------------------- #if(ScriptForms::saveFormData($leadpoolID, 0, 0, 0, $surveyID, \Input::get('scriptForm')) === true) // -- Save the Product Recommendations // ----------------------------------- $Survey->saveResponseProducts((int) $responseLogID); if ($responseLogID > 0) { // -- All Saved and Done. Now send an email // ---------------------------------------- $callCentre = \Model_Call_Center::query()->where('api_key', $apiKey)->get_one(); $Email = \Email::forge(); $Email->from('*****@*****.**', 'Money Management Services'); $Email->to('*****@*****.**'); $Email->subject($leadpoolID . ' - New Survey Result'); $Email->html_body(\View::forge('email', array('leadDetails' => \Input::get(), 'leadpoolID' => $leadpoolID, 'recommendedProducts' => $Survey->getProductsRecomendations((int) $responseLogID), 'scriptForm' => ScriptForms::loadResponse($leadpoolID, 0, 1), 'centre' => $callCentre->title, 'agent' => \Input::get('agent'), 'pitchScript' => \Input::get('surveyName')))); $Email->send(); /* try { $Email->send(); } catch(\EmailSendingFailedException $e) { $this->response(array( 'status' => 'SUCCESS', 'message' => 'Survey Saved (Failed to send email)', 'results' => $Survey->getProductsRecomendations((int)$responseLogID), 'leadpoolID' => $leadpoolID, )); } */ $this->response(array('status' => 'SUCCESS', 'message' => 'This Survey has been received.', 'results' => $Survey->getProductsRecomendations((int) $responseLogID), 'leadpoolID' => $leadpoolID)); } else { $this->response(array('status' => 'FAIL', 'message' => 'Failed to save survey results. Debtsolv Lead ID is ' . $leadpoolID)); } } else { $this->response(array('status' => 'FAIL', 'message' => 'Failed to save to Debtsolv')); } } } }
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; }