I have a codeigniter app that my model sends out some stats for the current month to the front end. My code now seems very redundant but I don't know how to combine using Active Record queries. Hoping someone can show me a simplified version of below. Initially I get the month we're in (start and as of today). The only difference between the queries below is $this->db->where('leadStatus', 0). Can the 4 queries be somehow combined?
First gets all next gets current (0) next gets archived (1) and lastly leads that resulted in a deal (2)
function get_stats($data) {
date_default_timezone_set('America/Halifax');
$today = date("Y-m-t 23:59:59") ;
$monthStart = date('Y-m-01 00:00:00');
$parent_id = $data['parent_id'];
//leads all
$this->db->select('id');
$this->db->from('leads');
$this->db->where('parent_id', $parent_id);
$this->db->where('leadCreated >=', $monthStart);
$this->db->where('leadCreated <=', $today);
$query = $this->db->get();
$data['total_leads'] = $query->num_rows();
//leads current
$this->db->select('id');
$this->db->from('leads');
$this->db->where('parent_id', $parent_id);
$this->db->where('leadStatus', 0);
$this->db->where('leadCreated >=', $monthStart);
$this->db->where('leadCreated <=', $today);
$query = $this->db->get();
$data['leads_current'] = $query->num_rows();
//leads archived
$this->db->select('id');
$this->db->from('leads');
$this->db->where('parent_id', $parent_id);
$this->db->where('leadStatus', 1);
$this->db->where('leadCreated >=', $monthStart);
$this->db->where('leadCreated <=', $today);
$query = $this->db->get();
$data['leads_archived'] = $query->num_rows();
//leads sent to deal
$this->db->select('id');
$this->db->from('leads');
$this->db->where('parent_id', $parent_id);
$this->db->where('leadStatus', 2);
$this->db->where('leadCreated >=', $monthStart);
$this->db->where('leadCreated <=', $today);
$query = $this->db->get();
$data['leads_todeal'] = $query->num_rows();