File: /home/cafsindia/crm_cafsindia_com/application/controllers/All_leads_bk17june2019.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
require_once("Secure_Controller.php");
class All_leads extends Secure_Controller{
public function __construct(){
parent::__construct('all_leads');
$this->load->model('All_leads_model');
$this->load->model('Customer');
}
public function index(){
if(!$this->Appconfig->isAppvalid()){
redirect('config');
}
$data['table_headers'] = $this->xss_clean(get_all_leads_table_headers());
// $data = "";
$this->load->view('all_leads/manage',$data);
}
public function search() //to get table row, its going to helpers/table_helper
{
$search = $this->input->get('search');
$limit = $this->input->get('limit');
$offset = $this->input->get('offset');
$sort = $this->input->get('sort');
$order = $this->input->get('order');
$filters = array('start_date' => $this->input->get('start_date'),
'end_date' => $this->input->get('end_date'),
'General_Insurance' => FALSE,
'Portfolio' => FALSE,
'Health_Insurance' => FALSE,
'Mutual_Funds' => FALSE,
'Term_Plan' => FALSE );
$filledup = array_fill_keys($this->input->get('filters'), TRUE);
$filters = array_merge($filters, $filledup);
$all_leads = $this->All_leads_model->search($search, $filters, $limit, $offset, $sort, $order);
$total_rows = $this->All_leads_model->get_found_rows($search, $filters);
$data_rows = array();
foreach($all_leads->result() as $leads){
$data_rows[] = $this->xss_clean(get_all_leads_data_row($leads, $this));
//$data_rows[] = get_all_leads_data_row($leads, $this);
}
echo json_encode(array('total' => $total_rows, 'rows' => $data_rows));
}
public function view($lead_id = -1){
$info = $this->All_leads_model->get_info($lead_id);
foreach(get_object_vars($info) as $property => $value)
{
$info->$property = $this->xss_clean($value);
}
$data['lead_info'] = $info;
$data['existing_lead'] = $this->All_leads_model->get_leads_custid($info->cust_id);
$met_info = $this->All_leads_model->get_met_log($lead_id);
$data['met_info'] = $met_info;
$type_info[""] = "---- Select Lead Type ----";
foreach($this->All_leads_model->get_lead_type() as $row){
$type_info[$this->xss_clean($row->lead_type_id)] = $this->xss_clean($row->lead_type);
}
$data['lead_type'] = $type_info;
$status_info[""] = "---- Select Lead Status ----";
foreach($this->All_leads_model->get_status() as $row){
$status_info[$this->xss_clean($row->status_id)] = $this->xss_clean($row->statusname);
}
$data['lead_status'] = $status_info;
$company_info[""] = "---- Select Company ----";
if($lead_id){
foreach($this->All_leads_model->get_all_company()->result_array() as $row){
$company_info[$this->xss_clean($row['vendor_id'])] = $this->xss_clean($row['vendorcompanyname']);
}
$data['company_info'] = $company_info;
}else{
foreach($this->All_leads_model->get_company()->result_array() as $row){
$company_info[$this->xss_clean($row['vendor_id'])] = $this->xss_clean($row['vendorcompanyname']);
}
$data['company_info'] = $company_info;
}
$product_info[""] = "---- Select Product ----";
if($lead_id){
foreach($this->All_leads_model->get_all_product()->result_array() as $row){
$product_info[$this->xss_clean($row['product_id'])] = $this->xss_clean($row['product_name']);
}
$data['product_info'] = $product_info;
}else{
foreach($this->All_leads_model->get_product()->result_array() as $row){
$product_info[$this->xss_clean($row['product_id'])] = $this->xss_clean($row['product_name']);
}
$data['product_info'] = $product_info;
}
$prospect_info[""] = "---- Select Prospect----";
foreach($this->All_leads_model->get_prospect()->result_array() as $row){
$prospect_info[$this->xss_clean($row['prospect_id'])] = $this->xss_clean($row['prospect_name']);
}
$data['prospect'] = $prospect_info;
$crm_info[""] = "---- Select CRM----";
foreach($this->All_leads_model->get_crm()->result_array() as $row){
$crm_info[$this->xss_clean($row['id'])] = $this->xss_clean($row['first_name']);
}
$data['crm_info'] = $crm_info;
$rm_info[""] = "---- Select RM----";
foreach($this->All_leads_model->get_rm()->result_array() as $row){
$rm_info[$this->xss_clean($row['id'])] = $this->xss_clean($row['first_name']);
}
$data['rm_info'] = $rm_info;
$re_info[""] = "---- Select Excecutive----";
foreach($this->All_leads_model->get_re()->result_array() as $row){
$re_info[$this->xss_clean($row['id'])] = $this->xss_clean($row['first_name']);
}
$data['re_info'] = $re_info;
$this->load->view("all_leads/form", $data);
}
public function view_login($cust_id)
{
$data['cust_info'] = $this->All_leads_model->cust_info($cust_id);
$data['family_info'] = $this->All_leads_model->get_view_family($cust_id);
$data['login_history'] = $this->All_leads_model->view_login($cust_id);
$this->load->view("all_leads/form_login", $data);
}
public function get_mobile($mobile){
$result = $this->All_leads_model->get_existing_data($mobile);
$count = $result->num_rows();
if($count === 1){
$cust_info = $result->row();
$cust_id = $cust_info->cust_id;
$lead_data = $this->All_leads_model->get_leads_custid($cust_id);
echo json_encode(array('status' =>"SUCCESS", 'cust_info' => $cust_info,'lead_data'=>$lead_data));
}else{
echo json_encode(array('status' =>"NEW", 'cust_info' => $cust_info,'lead_data'=>$lead_data));
}
}
/*
SAT - Inserts/updates a customer
*/
public function save($leads_info = -1)
{
$mobile = $this->input->post('cust_mobile');
$cust_id = $this->Customer->mob_exists($mobile);
if(!$cust_id){
$customer_data = array(
'cust_name' => $this->input->post('cust_name'),
'cust_mobile' => $this->input->post('cust_mobile'),
'cust_address' => $this->input->post('cust_address'),
'cust_email' => $this->input->post('cust_email'),
'created_by' => $this->session->userdata('emp_id'),
'created_date' => date('Y-m-d h:i:s'),
);
$cust_id = $this->Customer->lead_save_customer($customer_data, $mobile);
}
$lead_id = $this->All_leads_model->save_lead($cust_id, $leads_info);
$met_date = "";
$current_control = $this->session->userdata('emp_id');
$prospect_level = $this->input->post('prospect_level');
$role = $this->session->userdata('emp_role');
$rm_name = $this->input->post('rm_name');
$crm_name = $this->input->post('crm_name');
if(!$crm_name && $role === '3'){
$crm_name = $this->session->userdata('emp_id');
}
if($this->input->post('lead_status') === "4"){
$current_control = $this->session->userdata('teamleader');
}else
if($this->input->post('lead_status') === "10"){
$current_control = $this->session->userdata('teamleader');
}else
if(($this->input->post('lead_status') === "8") || ($this->input->post('lead_status') === "11") || ($this->input->post('prospect_level') === "4")){
$current_control = "MIS";
}
//Only for RM
if($this->input->post('lead_status') === "6"){
$current_control = $this->input->post('rm_name');
}
//Only for Postponed
if($this->input->post('lead_status') === "7"){
$current_control = $this->input->post('crm_name');
}
//Only for Prospect
if($this->input->post('lead_status') === "3"){
$prospect_level = '3';
}
if($this->input->post('lead_status') === "9"){
$met_date = $this->input->post('met_date');
}
//$generated_by = $this->input->post('generated_by');
if($role === "5"){
$rm_name = $this->input->post('hd_rm_name');
$crm_name = $this->input->post('hd_crm_name');
//$generated_by = $current_control;
}
if(($role === "6") && ($this->input->post('lead_status') === "5")){
$current_control = $this->input->post('crm_name1');
}
$lead_info_data = array(
'lead_id' => $lead_id,
'lead_type' => $this->input->post('lead_type'),
'category' => $this->session->userdata('emp_category'),
'company' => $this->input->post('vendorcompanyname'),
'product' => $this->input->post('product'),
'jfw' => $this->input->post('jfw'),
'jfw_rm' => $this->input->post('jfw_rm'),
'lead_status' => $this->input->post('lead_status'),
'prospect_level' => $prospect_level,
'ncd' => date('Y-m-d',strtotime($this->input->post('ncd'))),
'remarks' => $this->input->post('remarks'),
'expected_value' => $this->input->post('expected_value'),
'expected_login' => $this->input->post('expected_login'),
'crm_name' => $crm_name,
'rm_name' => $rm_name,
'generated_by' => $generated_by,
'reference' => $this->input->post('reference'),
'upsell_policy_no'=> $this->input->post('upsell_policy_no'),
'current_control' => $current_control,
'met_date' => date('Y-m-d',strtotime($met_date)),
're_name' => $this->input->post('re_name'),
'lead_mode' => '1',
);
//print_r($lead_info_data); die;
if($this->All_leads_model->save_lead_info($lead_info_data,$leads_info)){
$lead_info_data = $this->xss_clean($lead_info_data);
$cus_lead_id = $lead_info_data['lead_id'];
$cust_name = $this->All_leads_model->get_cust_name($cus_lead_id);
if($leads_info === -1){
echo json_encode(array('success' => TRUE, 'message' => "Lead Added for".' '.
$cust_name, 'id' => $lead_info_data['lead_id']));
}else {
//Existing custom
echo json_encode(array('success' => TRUE, 'message' => "Lead Updated for".' '.
$cust_name, 'id' => $leads_info));
}
//print_r($lead_info_data);
}else{
//failure
$lead_info_data = $this->xss_clean($lead_info_data);
echo json_encode(array('success' => FALSE, 'message' => $this->lang->line('lead_error_adding_updating').' '.
$cust_name, 'id' => -1));
}
}
public function get_row($lead_ids)
{
// echo "SAT :: $customer_ids"; die;
$lead_infos = $this->All_leads_model->get_multiple_info($lead_ids);
$result = array();
foreach($lead_infos as $lead_info)
{
$result[$lead_info->lead_id] = $this->xss_clean(get_item_data_row($lead_info, $this));
}
echo json_encode($result);
}
public function get_leadstatus($status){
$status = $this->All_leads_model->get_lead_status_byid($status)->row();
echo $status->statusname;
}
public function delete() {
$leads_to_delete = $this->xss_clean($this->input->post('ids'));
if($this->All_leads_model->delete_list($leads_to_delete)){
echo json_encode(array('success' => TRUE, 'message' => $this->lang->line('leads_successful_deleted').' '.
count($leads_to_delete).' '.leads));
}else{
echo json_encode(array('success' => FALSE, 'message' => $this->lang->line('leads_cannot_be_deleted')));
}
}
}
?>