select(' leads.*, kyc_entity_type.name as entity_type, policy_type.policy_type, user_profiles.first_name as salse_person_name, ( SELECT COUNT(*) AS qcr_count FROM rfq WHERE type = 2 AND is_active = 1 and lead_id = leads.id ) AS qcr_count, ( SELECT COUNT(*) AS rfq_count FROM rfq WHERE type = 1 AND is_active = 1 and lead_id = leads.id ) AS rfq_count ') ->join('kyc_entity_type', 'leads.entity_type_id = kyc_entity_type.id', 'left') ->join('user_profiles', 'leads.salse_person_id = user_profiles.id', 'left') ->join('policy_type', 'leads.policy_type_id = policy_type.id', 'left') ->where('leads.is_active', 1) ->orderBy('id', 'desc') ->findAll(); } public function getLeadForInsertClientList($type = null, $client_id = null) { $query = $this->db->table('leads') ->select('leads.*, user_profiles.first_name as user_name') ->join('user_profiles', 'leads.created_by = user_profiles.id') ->where('leads.is_active', 1) ->where('leads.status', 'won') ->where("leads.proposel_data IS NOT NULL AND leads.proposel_data <> ''") ->where("(leads.is_client_created = '' OR leads.is_client_created IS NULL)"); if ($type) { $query->where('leads.lead_type', $type); } if ($client_id) { $query->where('leads.client_id', $client_id); } $result = $query->get()->getResultArray(); return $result; } }