db->select('LD.LeadID,LD.LeadName,LD.MobileNumber,LD.IsNewEnquiry,LT.ActivityStatus,LT.AssignedTo,LT.StatusCode,LT.University,LT.Course'); $this->db->from(LEAD_DETAILS.' as LD'); $this->db->join(LEAD_TRACKING.' as LT', 'LT.LeadID = LD.LeadID'); $this->db->where('LD.MobileNumber',$mobileNumber); $leadDet=$this->db->get()->last_row(); $result_array = []; if($leadDet){ $result_array['existLeadDetails']=$leadDet; } else{ $this->db->select('ST.MobileNumber,ST.Firstname,US.UniversityName,CU.CourseName'); $this->db->from(STUDENTS.' as ST'); $this->db->join(STUDENTCOURSE.' as STC', 'ST.StudentID = STC.StudentID'); $this->db->join(UNIVERSITY.' as US', 'US.UniversityID = STC.UniversityID'); $this->db->join(COURSE.' as CU', 'CU.CourseID = STC.CourseID'); $this->db->where('ST.MobileNumber',$mobileNumber); $enrolledStudDet=$this->db->get()->last_row(); if($enrolledStudDet) { $leadDet['LeadName'] = $enrolledStudDet->Firstname; $leadDet['MobileNumber'] = $enrolledStudDet->MobileNumber; $leadDet['IsNewEnquiry'] = "1"; $leadDet['University'] = $enrolledStudDet->UniversityName; $leadDet['Course'] = $enrolledStudDet->CourseName; $leadDet['ActivityStatus'] = ""; $leadDet['AssignedTo'] = ""; $leadDet['StatusCode'] = ""; $result_array['existLeadDetails'] = $leadDet; } else{ $leadDet['LeadName'] = ""; $leadDet['MobileNumber'] = ""; $leadDet['IsNewEnquiry'] = "1"; $leadDet['University'] = ""; $leadDet['Course'] = ""; $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->where('IsActive','1'); $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 !=',REOPEN); $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,LT.University,LT.Course,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(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["UniversityName"]=$row->University; $tracking_array["CourseName"]=$row->Course; $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('LTF.InteractionId,LTF.TrackingID,LTF.FollowupOn,LTF.FollowupComments,DATE_FORMAT(LTF.CreatedOn, "%d-%m-%Y %h:%i %p") AS CreatedOn,ST.FirstName'); $this->db->from(LEAD_TRACKING_FOLLOWUP.' as LTF'); $this->db->join(LOGIN.' as LO', 'LO.ID = LTF.CreatedBy'); $this->db->join(STAFF.' as ST', 'ST.StaffID = LO.StaffID'); $this->db->where('TrackingID',$trackingId); $this->db->order_by('InteractionId','DESC'); $trackingDetails = $this->db->get(); 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,LT.University,LT.Course,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(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["UniversityName"]=$row->University; $tracking_array["CourseName"]=$row->Course; $tracking_array["ListCode"]=$row->ListCode; $tracking_array["ListName"]=$row->ListName; $tracking_array["followupDetails"]=$this->getTrackingFollowup($row->TrackingID); $tracking_array["collectTrackedID"]=$this->getStudentTrackedID($row->MobileNumber); $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; } /* * get student tracked id * @params mobile number * created by kms * */ public function getStudentTrackedID($stuMobile=null) { $this->db->distinct(); $this->db->select('LT.TrackingID,LT.LeadID,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(PICK_LIST_DETAILS.' as PLD', 'PLD.ListCode = LT.ActivityStatus'); $this->db->where('LD.MobileNumber',$stuMobile); $this->db->order_by('LT.TrackingID','ASC'); $studeTrackID = $this->db->get(); return $studeTrackID->result(); } /* * used to get dash board call track details * created by kms * */ public function getDashboardTrackingDetails($serach=null) { $now = new DateTime(); $now->setTimezone(new DateTimezone('Asia/Kolkata')); $todayFollowupDate=$now->format('d-m-Y'); $todayDateTime=$now->format('Y-m-d'); $follouwpDetails=$this->todayFollowupDetails($todayFollowupDate,CLOSE,'1'); if($follouwpDetails){ $result_array['todayStatus']=true; $result_array['todayFolloupDetails']=$follouwpDetails; } else{ $result_array['todayStatus']=false; $result_array['todayFolloupDetails']=""; } $follouwpPendingDetails=$this->todayFollowupDetails($todayFollowupDate,CLOSE,'2'); if($follouwpPendingDetails){ $result_array['todayPendingStatus']=true; $result_array['PendingFolloupDetails']=$follouwpPendingDetails; } else{ $result_array['todayPendingStatus']=false; $result_array['PendingFolloupDetails']=""; } $todayLeadDetails=$this->todayFollowupDetails($todayDateTime,OPEN,'3'); if($todayLeadDetails){ $result_array['todayLeadStatus']=true; $result_array['todayLeadDetails']=$todayLeadDetails; } else{ $result_array['todayLeadStatus']=false; $result_array['todayLeadDetails']=""; } return $result_array; } /* * get date wise followup details * @params date and status and check status * */ public function todayFollowupDetails($todayDate=null,$status=null,$check=null) { $this->db->distinct(); $this->db->select('LT.TrackingID'); $this->db->from(LEAD_DETAILS.' as LD'); $this->db->from(LEAD_TRACKING.' as LT', 'LT.LeadID = LD.LeadID'); $this->db->order_by('LT.TrackingID','ASC'); if($check!='3'){ $this->db->where('LT.StatusCode !=',$status); } else if($check=='2'){ $this->db->where('LT.StatusCode !=',$status); } else if($check=='3'){ $this->db->like('LD.CreatedOn', $todayDate, 'after'); } $leadDetails=$this->db->get(); if($leadDetails->result()){ $result_array = array(); foreach ($leadDetails->result() as $row){ $this->db->select('LTF.TrackingID,LTF.InteractionId'); $this->db->from(LEAD_TRACKING_FOLLOWUP.' as LTF'); $this->db->where('LTF.TrackingID',$row->TrackingID); $lastFollowpID=$this->db->get()->last_row(); // get last followup details date wise $this->db->distinct(); $this->db->select('LD.LeadName,LD.MobileNumber,LT.TrackingID,LT.LeadID,PLD.ListCode,PLD.ListName,LTF.FollowupOn,LT.StatusCode,PLD1.ListName as statusListName'); $this->db->from(LEAD_DETAILS.' as LD'); $this->db->join(LEAD_TRACKING.' as LT', 'LT.LeadID = LD.LeadID'); $this->db->join(LEAD_TRACKING_FOLLOWUP.' as LTF', 'LTF.TrackingID = LT.TrackingID'); $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('LTF.InteractionId',$lastFollowpID->InteractionId); // check today date based follwup details if($check=='1'){ $this->db->where('LTF.FollowupOn',$todayDate); $this->db->where('LT.StatusCode !=',$status); } // check today date based pending followp details else if($check=='2'){ // $this->db->where('LTF.FollowupOn >',$todayDate); $this->db->where('LT.StatusCode !=',$status); } else if($check=='3'){ $this->db->like('LD.CreatedOn', $todayDate, 'after'); } $trackDetails=$this->db->get(); if($trackDetails->result()){ foreach ($trackDetails->result() as $row1) { $tracking_array["LeadID"]=$row1->LeadID; $tracking_array["LeadName"]=$row1->LeadName; $tracking_array["MobileNumber"]=$row1->MobileNumber; $tracking_array["TrackingID"]=$row1->TrackingID; $tracking_array["FollowupOn"]=$row1->FollowupOn; $tracking_array["StatusCode"]=$row1->StatusCode; $tracking_array["statusListName"]=$row1->statusListName; $tracking_array["ListCode"]=$row1->ListCode; $tracking_array["ListName"]=$row1->ListName; $result[]=$tracking_array; } $result_array['trackingDetails']=$result; } } return $result_array; } else{ return false; } } /* * get all followup details * created by kms * */ public function getDashboardFollowupDetails($search=null) { $this->db->distinct(); $this->db->select('LT.TrackingID'); $this->db->from(LEAD_DETAILS.' as LD'); $this->db->from(LEAD_TRACKING.' as LT', 'LT.LeadID = LD.LeadID'); $this->db->order_by('LT.TrackingID','ASC'); $leadDetails=$this->db->get(); if($leadDetails->result()){ foreach ($leadDetails->result() as $row){ $this->db->select('LTF.TrackingID,LTF.InteractionId'); $this->db->from(LEAD_TRACKING_FOLLOWUP.' as LTF'); $this->db->where('LTF.TrackingID',$row->TrackingID); $lastFollowpID=$this->db->get()->last_row(); // get last followup details date wise $this->db->distinct(); $this->db->select('DATE_FORMAT(LTF.CreatedOn, "%d-%m-%Y") AS CreatedOn,LD.LeadName,LD.MobileNumber,LT.TrackingID,LT.LeadID,PLD.ListCode,PLD.ListName,LTF.FollowupOn,LT.StatusCode,PLD1.ListName as statusListName'); $this->db->from(LEAD_DETAILS.' as LD'); $this->db->join(LEAD_TRACKING.' as LT', 'LT.LeadID = LD.LeadID'); $this->db->join(LEAD_TRACKING_FOLLOWUP.' as LTF', 'LTF.TrackingID = LT.TrackingID'); $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('LTF.InteractionId',$lastFollowpID->InteractionId); $result[]=$this->db->get()->result(); } $result_array['details']=$result; $result_array['followupStatus']=true; return $result_array; } else{ $result_array['details']=""; $result_array['followupStatus']=false; } return $result_array; } }