*/ private function months() { return ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12']; } /** * Getting the year of the orders (paid_status = 1) * @return array */ public function getOrderYear() { $result = $this->where('paid_status', 1)->findAll(); $return_data = array_map(function($v) { return date('Y', strtotime($v['date_time'])); }, $result); return array_values(array_unique($return_data)); } /** * Getting the order reports based on the year and months * @param mixed $year * @return array */ public function getOrderData($year) { if ($year) { $months = $this->months(); // Fetch orders with paid_status = 1 $result = $this->where('paid_status', 1)->findAll(); $final_data = []; foreach ($months as $month) { $get_mon_year = $year . '-' . $month; $final_data[$get_mon_year] = []; foreach ($result as $v) { $month_year = date('Y-m', strtotime($v['date_time'])); if ($get_mon_year == $month_year) { $final_data[$get_mon_year][] = $v; } } } // die(var_dump($final_data)); return $final_data; } return []; } }