apollodec/Apollo/api/application/models/Calltracking_model.php
2017-11-22 14:47:04 +05:30

379 lines
14 KiB
PHP

<?php
/**
* Created by PhpStorm.
* User: karthi
* Date: 11/15/17
* Time: 5:49 PM
*/
defined('BASEPATH') OR exit('No direct script access allowed');
class Calltracking_model extends CI_Model {
/*
* get lead details
* @params mobile number,requestedby
* created by kms
* */
public function getLeadDetails($requestedBy=null,$mobileNumber=null)
{
$this->db->select('LD.LeadID,LD.LeadName,LD.MobileNumber,LD.IsNewEnquiry,LT.ActivityStatus,LT.AssignedTo,LT.StatusCode,US.UniversityID,US.UniversityName,CU.CourseID,CU.CourseName');
$this->db->from(LEAD_DETAILS.' as LD');
$this->db->join(LEAD_TRACKING.' as LT', 'LT.LeadID = LD.LeadID');
$this->db->join(UNIVERSITY.' as US', 'US.UniversityID = LT.University');
$this->db->join(COURSE.' as CU', 'CU.CourseID = LT.Course');
$this->db->where('LD.MobileNumber',$mobileNumber);
$leadDet=$this->db->get()->last_row();
$result_array = [];
if($leadDet){
$result_array['existLeadDetails']=$leadDet;
}
else{
$leadDet['LeadName']="";
$leadDet['MobileNumber']=$mobileNumber;
$leadDet['IsNewEnquiry']="1";
$leadDet['UniversityID']="";
$leadDet['UniversityName']="";
$leadDet['CourseID']="";
$leadDet['CourseName']="";
$leadDet['ActivityStatus']="";
$leadDet['AssignedTo']="";
$leadDet['StatusCode']="";
$result_array['existLeadDetails']=$leadDet;
}
// store lead,university and course details in comman array
$result_array['universityDetails']=$this->getUniversityDetails();
$result_array['activityDetails']=$this->getActivityDetails();
$result_array['statusDetails']=$this->getStatus();
$result_array['staffDetails']=$this->getStaff("1");
return $result_array;
}
/*
* get university details
* created by kms
* */
public function getUniversityDetails()
{
$this->db->select('UniversityID,UniversityName');
$this->db->order_by('UniversityID','ASC');
$unviversityDetails = $this->db->get(UNIVERSITY);
if($unviversityDetails->result()){
$result_university = array();
foreach ($unviversityDetails->result() as $row)
{
$university_array['universityStatus'] = true;
$university_array['universityID'] = $row->UniversityID;
$university_array['universityName'] = $row->UniversityName;
$university_array['courseDetails']= $this->getCourseDetails($row->UniversityID);
$result_university[]=$university_array;
}
}
else {
$university_array['universityStatus'] = false;
$university_array['message'] = "No records found!";
$university_array['universityID'] = "";
$university_array['universityName'] = "";
$university_array['courseDetails']= "";
$result_university[]=$university_array;
}
return $result_university;
}
/*
* get course details
* @params university id
* created by kms
* */
public function getCourseDetails($universityID=null)
{
$this->db->select('CourseID,CourseName');
$this->db->where('UniversityID',$universityID);
$this->db->order_by('CourseID','ASC');
$courseDetails = $this->db->get(COURSE);
return $courseDetails->result();
}
/*
* get activity details
* created by kms
* */
public function getActivityDetails()
{
$this->db->select('ListCode,ListName');
$this->db->where('ListGroup','2');
$this->db->order_by('ListCode','ASC');
$activity = $this->db->get(PICK_LIST_DETAILS);
return $activity->result();
}
/*
* get status details
* created by kms
* */
public function getStatus()
{
$this->db->select('ListCode,ListName');
$this->db->where('ListCode !=','S003');
$this->db->where('ListGroup','1');
$this->db->order_by('ListCode','ASC');
$status = $this->db->get(PICK_LIST_DETAILS);
return $status->result();
}
/*
* get staff details
* created by kms
*
* */
public function getStaff($status=null)
{
$this->db->select('LO.ID,ST.StaffID,ST.Firstname');
$this->db->from(LOGIN.' as LO');
$this->db->join(STAFF.' as ST', 'ST.StaffID = LO.StaffID');
$this->db->where('ST.IsActive',$status);
$staffDetails=$this->db->get();
if($staffDetails){
$result_staff = array();
foreach ($staffDetails->result() as $row)
{
$university_array['loginId'] = $row->ID;
$university_array['staffName'] = $row->StaffID.'-'.$row->Firstname;
$result_staff[]=$university_array;
}
}
else{
$result_staff[]="";
}
return $result_staff;
}
/*
* add lead details
* created by kms
* */
public function addleadDetails($lead_Details=null,$track_Details=null,$followup_Details=null)
{
$this->db->insert(LEAD_DETAILS, $lead_Details);
// this if for insert lead details
if($this->db->affected_rows() == '1'){
// get and store insert id from db
$track_Details['LeadID']=$this->db->insert_id();
$this->db->insert(LEAD_TRACKING, $track_Details);
// this if for insert tracking details
if($this->db->affected_rows() == '1'){
$followup_Details['TrackingID']=$this->db->insert_id();
$this->db->insert(LEAD_TRACKING_FOLLOWUP, $followup_Details);
// this if for insert follow up details
if($this->db->affected_rows() == '1'){
$result['leadStatus'] = true;
$result['message'] = "Successfully lead details added";
}
else{
$result['leadStatus'] = false;
$result['message'] = "Something went wrong.please try again";
}
}
else{
$result['leadStatus'] = false;
$result['message'] = "Something went wrong.please try again";
}
}
else {
$result['leadStatus'] = false;
$result['message'] = "Something went wrong.please try again";
}
return $result;
}
/*
* get all tracked details
* created by kms
* */
public function getTrackingDetails($search=null)
{
$this->db->select('LD.LeadID,LD.LeadName,LD.MobileNumber,LD.IsNewEnquiry,LT.TrackingID,LT.ActivityStatus,LT.AssignedTo,LT.StatusCode,US.UniversityID,US.UniversityName,CU.CourseID,CU.CourseName,ST.StaffID,ST.Firstname,PLD1.ListCode as statusListCode,PLD1.ListName as statusListName,PLD.ListCode,PLD.ListName');
$this->db->from(LEAD_DETAILS.' as LD');
$this->db->join(LEAD_TRACKING.' as LT', 'LT.LeadID = LD.LeadID');
$this->db->join(UNIVERSITY.' as US', 'US.UniversityID = LT.University');
$this->db->join(COURSE.' as CU', 'CU.CourseID = LT.Course');
$this->db->join(LOGIN.' as LO', 'LO.ID = LT.AssignedTo');
$this->db->join(STAFF.' as ST', 'ST.StaffID = LO.StaffID');
$this->db->join(PICK_LIST_DETAILS.' as PLD', 'PLD.ListCode = LT.ActivityStatus');
$this->db->join(PICK_LIST_DETAILS.' as PLD1', 'PLD1.ListCode = LT.StatusCode');
$leadDet=$this->db->get();
if($this->db->affected_rows()==0){
$result_array['trackingStatus']=false;
$result_array['trackingDetails']="";
}
else{
if($leadDet){
$result_array = array();
$result_array['trackingStatus']=true;
foreach ($leadDet->result() as $row)
{
$tracking_array["LeadID"]=$row->LeadID;
$tracking_array["LeadName"]=$row->LeadName;
$tracking_array["MobileNumber"]=$row->MobileNumber;
$tracking_array["IsNewEnquiry"]=$row->IsNewEnquiry;
$tracking_array["TrackingID"]=$row->TrackingID;
$tracking_array["ActivityStatus"]=$row->ActivityStatus;
$tracking_array["AssignedTo"]=$row->AssignedTo;
$tracking_array["Firstname"]=$row->Firstname;
$tracking_array["StatusCode"]=$row->StatusCode;
$tracking_array["statusListName"]=$row->statusListName;
$tracking_array["UniversityID"]=$row->UniversityID;
$tracking_array["UniversityName"]=$row->UniversityName;
$tracking_array["CourseID"]=$row->CourseID;
$tracking_array["CourseName"]=$row->CourseName;
$tracking_array["ListCode"]=$row->ListCode;
$tracking_array["ListName"]=$row->ListName;
// $tracking_array["followupDetails"]=$this->getTrackingFollowup($row->TrackingID);
$followupDetails=$this->getTrackingFollowup($row->TrackingID);
$tracking_array["followupDetails"]=$followupDetails[0]->FollowupOn;
$result[]=$tracking_array;
}
$result_array['trackingDetails']=$result;
$result_array['statusDetails']=$this->getStatus();
$result_array['trackingDetails']=$result;
}
}
return $result_array;
}
/*
* get tracking followup Details
* @params tracking id
* created by kms
* */
public function getTrackingFollowup($trackingId=null)
{
$this->db->select('InteractionId,TrackingID,FollowupOn,FollowupComments,CreatedOn');
$this->db->where('TrackingID',$trackingId);
$this->db->order_by('InteractionId','DESC');
$trackingDetails = $this->db->get(LEAD_TRACKING_FOLLOWUP);
return $trackingDetails->result();
}
/*
* update followup details
* created by kms
* */
public function updateFollowupDetails($updateDetails=null,$insertDetails=null)
{
$this->db->insert(LEAD_TRACKING_FOLLOWUP, $insertDetails);
// this if for insert follow up details
if($this->db->affected_rows() == '1'){
$this->db->where('TrackingID',$updateDetails['TrackingID']);
$upateStatus=$this->db->update(LEAD_TRACKING, $updateDetails);
$result['followupStatus'] = true;
$result['trackingID'] = $updateDetails['TrackingID'];
$result['message'] = "Successfully followup details added";
}
else{
$result['followupStatus'] = false;
$result['message'] = "Something went wrong.please try again";
}
return $result;
}
/*
* get tracking information when page is loading
* created by kms
* */
public function getLoadFollowupDetails($trackingID)
{
$this->db->select('LD.LeadID,LD.LeadName,LD.MobileNumber,LD.IsNewEnquiry,LT.TrackingID,LT.ActivityStatus,LT.AssignedTo,LT.StatusCode,US.UniversityID,US.UniversityName,CU.CourseID,CU.CourseName,ST.StaffID,ST.Firstname,PLD1.ListCode as statusListCode,PLD1.ListName as statusListName,PLD.ListCode,PLD.ListName');
$this->db->from(LEAD_DETAILS.' as LD');
$this->db->join(LEAD_TRACKING.' as LT', 'LT.LeadID = LD.LeadID');
$this->db->join(UNIVERSITY.' as US', 'US.UniversityID = LT.University');
$this->db->join(COURSE.' as CU', 'CU.CourseID = LT.Course');
$this->db->join(LOGIN.' as LO', 'LO.ID = LT.AssignedTo');
$this->db->join(STAFF.' as ST', 'ST.StaffID = LO.StaffID');
$this->db->join(PICK_LIST_DETAILS.' as PLD', 'PLD.ListCode = LT.ActivityStatus');
$this->db->join(PICK_LIST_DETAILS.' as PLD1', 'PLD1.ListCode = LT.StatusCode');
$this->db->where('LT.TrackingID',$trackingID['TrackingID']);
$leadDet=$this->db->get();
if($leadDet){
$result_array = array();
$result_array['followupStatus']=true;
foreach ($leadDet->result() as $row)
{
$tracking_array["LeadID"]=$row->LeadID;
$tracking_array["LeadName"]=$row->LeadName;
$tracking_array["MobileNumber"]=$row->MobileNumber;
$tracking_array["IsNewEnquiry"]=$row->IsNewEnquiry;
$tracking_array["TrackingID"]=$row->TrackingID;
$tracking_array["ActivityStatus"]=$row->ActivityStatus;
$tracking_array["AssignedTo"]=$row->AssignedTo;
$tracking_array["Firstname"]=$row->Firstname;
$tracking_array["StatusCode"]=$row->StatusCode;
$tracking_array["statusListName"]=$row->statusListName;
$tracking_array["UniversityID"]=$row->UniversityID;
$tracking_array["UniversityName"]=$row->UniversityName;
$tracking_array["CourseID"]=$row->CourseID;
$tracking_array["CourseName"]=$row->CourseName;
$tracking_array["ListCode"]=$row->ListCode;
$tracking_array["ListName"]=$row->ListName;
$tracking_array["followupDetails"]=$this->getTrackingFollowup($row->TrackingID);
$result[]=$tracking_array;
}
$result_array['trackingDetails']=$result;
$result_array['statusDetails']=$this->getStatus();
$result_array['trackingDetails']=$result;
}
else{
$result_array['followupStatus']=false;
$result_array['trackingDetails']="";
}
return $result_array;
}
}