/** * Pack out a referral to a PPI client. * * @access public * @param mixed $referral_id * @return void */ public function post_create_client($referral_id) { // First, we must save the updated data // Need to make sure that if we are a 0 referral_id then we create a new referral. list($referral, $referral_id) = Controller_Crm_Ppi::save_current_post($referral_id); // Now create the client $referralData = $referral->values(); $clientID = ClientClass::createClient($referralData); \log::write('Msg', 'Create Client: ' . (int) $clientID, 'post_create_client'); if ($clientID > 0) { // -- Create a PPI account for the client // -------------------------------------- $referralData['clientID'] = $clientID; $ppiClientID = \Crm\Ppi\Ppi_class::createPpiClient($referralData); $ppiReference = \Crm\Ppi\Ppi_class::forge($ppiClientID); // -- Create a partner if details have been supplied // ------------------------------------------------- $partnerDetails = $referral->loadData(); if (isset($partnerDetails['partner']) && is_array($partnerDetails['partner'])) { $partnerDetails['partner']['clientID'] = $clientID; \Crm\PartnerClass::createPartner($partnerDetails['partner']); } $referral->setDisposition(5); list($driver, $user_id) = \Auth::get_user_id(); $thisUser = \Model_User::find($user_id); \Log::write('Dispo', $thisUser->name . ' created a client from referral ID ' . $referral_id, 'Controller_Crm_Ppi::post_create_client()'); $referralDetails = \DB::query("SELECT data FROM crm_referrals WHERE id='" . $referral_id . "';", \DB::select())->execute()->as_array(); $data = unserialize($referralDetails[0]['data']); $letterConfig = \Crm\Ppi\Ppi_class::loadLettersList((int) $referralData['company_id']); if ((int) $referralData['company_id'] == 1) { $timeSlot = 1; } else { if ((int) $referralData['company_id'] == 3) { $timeSlot = 2; } } // -- Persolvo Letters \Crm\Letter\Pack::forge($clientID, null, array(array('id' => $letterConfig['ppi_welcome_letter'], 'qty' => 1, 'tray_id' => 2)))->setOutputFilename('ppi_pack_coverletter_' . $clientID . '.pdf')->printLetter(2, 40)->timeSlot($timeSlot)->create(); $pack = array(array('id' => $letterConfig['ppi_form_of_authority'], 'qty' => count($data['creditors']) > 0 ? count($data['creditors']) : 3, 'tray_id' => 1), array('id' => $letterConfig['recommand_a_friend'], 'qty' => 1, 'tray_id' => 1), array('id' => $letterConfig['terms_and_conditions_GAB'], 'qty' => 1, 'tray_id' => 1), array('id' => $letterConfig['terms_and_conditions_CUSTOMER'], 'qty' => 1, 'tray_id' => 1)); if ((int) $referralData['company_id'] == 3) { $pack[] = array('id' => $letterConfig['ipad_questionnaire'], 'qty' => 1, 'tray_id' => 1); } \Crm\Letter\Pack::forge($clientID, null, $pack)->setOutputFilename('ppi_pack_' . $clientID . '.pdf')->printLetter()->timeSlot($timeSlot)->create(); \DB::query("UPDATE crm_ppi_clients SET pack_sent_date = NOW() WHERE client_id=" . $clientID . ";")->execute(); // -- Set Correspondence to Pack Out // --------------------------------- $correspondence = \Crm\Ppi\Ppi_correspondence::forge($clientID); $correspondence->saveNew(0, 1, 1, 0, 'Client Created and Pack Sent Out'); $this->response(array('status' => 'SUCCESS', 'referralID' => $referral_id, 'clientID' => $clientID, 'ppiID' => $ppiClientID)); } else { $this->response(array('status' => 'FAIL', 'message' => 'No Client could be created. Oh dear!')); } }
public static function createReferral($data = array()) { // -- Create a new Referral // ------------------------ if (count($data) <= 0) { return; } // -- Save Referral // ---------------- #$data['user_id'] = $this->_user_id; $referralID = \Referrals_model::createReferral($data); $Referral = self::forge($referralID); // -- Set Disposition to Referred // ------------------------------ $Referral->setDisposition(22); // -- Set the Disposition HERE // --------------------------- // -- Check for duplicates in the referrals // ---------------------------------------- $duplications = array(); $duplications = \Referrals_model::duplicationCheck($data); // -- Loop through the duplicates so we can find if this is a client // ----------------------------------------------------------------- if (count($duplications) > 0) { // ------------------------------------------------------------------------ // -- Duplication referral found, this could be ok as the lead could be -- // -- for a different company or for a different product -- // ------------------------------------------------------------------------ // -- Search for the client // ------------------------ $dataSearch = array(); isset($data['forename']) ? $dataSearch['forename'] = $data['forename'] : false; isset($data['surname']) ? $dataSearch['surname'] = $data['surname'] : false; isset($data['street_and_number']) ? $dataSearch['street_and_number'] = $data['street_and_number'] : false; isset($data['post_code']) ? $dataSearch['post_code'] = $data['post_code'] : false; isset($data['tel_home']) ? $dataSearch['tel_home'] = $data['tel_home'] : false; isset($data['tel_work']) ? $dataSearch['tel_work'] = $data['tel_work'] : false; isset($data['tel_mobile']) ? $dataSearch['tel_mobile'] = $data['tel_mobile'] : false; $clients = array(); $DuplicateClient = \ClientClass::duplicateCheck($dataSearch); if (is_object($DuplicateClient)) { // -- Client found with the same details, now check to see if they already have the same product // --------------------------------------------------------------------------------------------- $clientProducts = array(); $clientProducts = $DuplicateClient->clientProducts((int) $data['product_id']); if (count($clientProducts) > 0) { // -- Client found to have a product with one of the companies, so return the list to the agent // -------------------------------------------------------------------------------------------- // -- Set Disposition to Referred // ------------------------------ $Referral->setDisposition(15); print_r($clientProducts); } } else { // -- Lead doesn't exist yet as a Client, so return the Referral ID for product account creation // --------------------------------------------------------------------------------------------- $Referral->sendForConsolidation(); } } else { // -- First time referred, so send stright to consolidation // -------------------------------------------------------- $Referral->sendForConsolidation(); } }
public function post_search() { // -- Search for a Client // ---------------------- $this->template->title = 'Client Search'; $data['titles'] = ClientClass::titleList(); $data['countries'] = ClientClass::countryList(); if (isset($_POST)) { $seachValues = array(); foreach ($_POST as $key => $value) { if ($value != '' && $key != 'Search') { $seachValues[$key] = $value; } } // -- Return search results // ------------------------ $results = array(); $results = \ClientModel::clientSearch($seachValues); // -- If results returned, then loop through and assign them to an array; // ---------------------------------------------------------------------- if (!empty($results) > 0) { $clients = array(); foreach ($results as $result) { $clients[] = ClientClass::forge($result['id']); } } } $this->template->content = View::forge(static::$_viewPath . '/index.php', $data); }