Пример #1
0
 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;
 }
Пример #2
0
 /**
  * Saves the data posted and returns the referral.
  * 
  * @access public
  * @static
  * @param mixed $referral_id (default: null)
  * @return void
  */
 public static function save_current_post($referral_id = null)
 {
     // If we don't already have a referral id then we create a new referral
     if ($referral_id == 0 || is_null($referral_id)) {
         list($driver, $user_id) = Auth::get_user_id();
         $thisUser = \Model_User::find($user_id);
         \Log::write('Dispo', $thisUser->name . ' tried to create a NEW Referral', 'Controller_Crm_Ppi::save_current_post()');
         $clientID = \Crm\Referrals\Referrals_model::createReferral(array('user_id' => $user_id, 'company_id' => Input::post('company'), 'product_id' => 1, 'dialler_lead_id' => null, 'dialler_list_id' => null, 'dialler_list_name' => '', 'disposition_id' => '', 'title' => Input::post('referral_title'), 'forename' => Input::post('referral_forename'), 'surname' => Input::post('referral_surname'), 'street_and_number' => Input::post('referral_street_and_number'), 'area' => Input::post('referral_area'), 'district' => Input::post('referral_district'), 'town' => Input::post('referral_town'), 'county' => Input::post('referral_county'), 'post_code' => Input::post('referral_post_code'), 'date_of_birth' => Input::post('referral_date_of_birth'), 'tel_home' => Input::post('referral_tel_home'), 'tel_work' => Input::post('referral_tel_work'), 'tel_mobile' => Input::post('referral_tel_mobile'), 'email' => Input::post('referral_email'), 'notes' => Input::post('referral_notes'), 'introducer_id' => Input::post('introducer')));
         // -- Add a partner
         // ----------------
         if (Input::post('add_partner') == 'on') {
             $saveData['partner'] = array('title' => Input::post('referral_partner_title'), 'forename' => Input::post('referral_partner_forename'), 'surname' => Input::post('referral_partner_surname'), 'street_and_number' => Input::post('referral_partner_street_and_number'), 'area' => Input::post('referral_partner_area'), 'district' => Input::post('referral_partner_district'), 'town' => Input::post('referral_partner_town'), 'county' => Input::post('referral_partner_county'), 'post_code' => Input::post('referral_partner_post_code'), 'date_of_birth' => Input::post('referral_partner_date_of_birth'), 'tel_home' => Input::post('referral_partner_tel_home'), 'tel_work' => Input::post('referral_partner_tel_work'), 'tel_mobile' => Input::post('referral_partner_tel_mobile'), 'email' => Input::post('referral_partner_email'), 'notes' => Input::post('referral_partner_notes'));
         }
         \Log::write('Dispo', $thisUser->name . ' created a new client with the ID of ' . $clientID, 'Controller_Crm_Ppi::save_current_post()');
         $referral_id = $clientID;
     }
     $referral = Referrals_class::forge($referral_id);
     $creditorInformation = array();
     foreach ($_POST as $key => $value) {
         if (\Str::starts_with($key, "referral_")) {
             $dbKey = str_replace('referral_', '', $key);
             if ($dbKey == "date_of_birth") {
                 $referral->{$dbKey} = date("Y-m-d", strtotime($value));
             } else {
                 $referral->{$dbKey} = $value;
             }
         } else {
             if (\Str::starts_with($key, "creditor_")) {
                 $creditorType = str_replace('creditor_', '', $key);
                 $creditorInfo = explode("_", $creditorType);
                 $creditorNumber = (int) $creditorInfo[0];
                 $creditorString = str_replace($creditorNumber . '_', '', $key);
                 $creditorInformation[$creditorNumber][$creditorString] = $value;
             }
         }
     }
     $saveData['creditors'] = $creditorInformation;
     $referral->saveData($saveData);
     $referral->save();
     $referral = Referrals_class::forge($referral_id);
     return array($referral, $referral_id);
 }
Пример #3
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;
 }