Server : Apache/2.4.18 (Ubuntu) System : Linux canvaswebdesign 3.13.0-71-generic #114-Ubuntu SMP Tue Dec 1 02:34:22 UTC 2015 x86_64 User : oppastar ( 1041) PHP Version : 7.0.33-0ubuntu0.16.04.15 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, Directory : /var/www/laciasmara.com/public_html/shop/application/controllers/admin/ |
Upload File : |
<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); class Dashboard extends Admin_Controller { function __construct() { parent::__construct(); $this->load->model('user_m'); $this->load->model('order_m'); $this->load->model('log_m'); $this->load->model('statistic_m'); } // function index() // { // $this->data['subview'] = 'admin/index'; // $this->load->view('admin/templates/header', $this->data_header); // $this->load->view('admin/_layout_main', $this->data); // $this->load->view('admin/templates/footer'); // } function index() { $data['userdata'] = $this->session->userdata(); $data['role'] = $this->session->userdata('role'); $data['incoming_orders'] = $this->order_m->get_pending_order_count(); $data['need_to_confirm_orders'] = $this->order_m->get_need_to_confirm_order_count(); $data['incoming_retailer_orders'] = $this->order_m->get_pending_order_count(true); $data['processing_orders'] = $this->order_m->get_processing_order_count(); $data['processing_retailer_orders'] = $this->order_m->get_processing_order_count(true); $data['shipped_orders'] = $this->order_m->get_shipped_order_count(); $data['shipped_retailer_orders'] = $this->order_m->get_shipped_order_count(true); $data['delivered_orders'] = $this->order_m->get_delivered_order_count(); $data['finished_orders'] = $this->order_m->get_finished_order_count(); // Marketing $data['today_traffic'] = $this->statistic_m->get_today_traffic(); $data['today_unique_traffic'] = $this->statistic_m->get_today_unique_traffic(); $data['marketing_expenses'] = $this->statistic_m->get_marketing_expenses_by_product_sent(); // Statistik $data['today_revenue'] = $this->statistic_m->get_today_revenue(); $data['today_new_customer'] = $this->statistic_m->get_today_new_customer(); $data['today_buyers'] = $this->statistic_m->get_today_buyers_count(); // Hitung konversi pembeli $data['conversion_rate'] = ($data['today_traffic'] > 0) ? round(($data['today_buyers'] / $data['today_traffic']) * 100, 2) : 0; $data['best_selling'] = $this->statistic_m->get_best_selling_product(); // Data untuk statistik mingguan (7 hari terakhir) $weekly_labels = []; $weekly_current_data = []; $weekly_previous_data = []; // Memanggil model untuk mendapatkan data $current_week_revenue = $this->statistic_m->get_current_week_revenue(); $last_year_week_revenue = $this->statistic_m->get_last_year_week_revenue(); // Mengisi data untuk 7 hari terakhir for ($i = 6; $i >= 0; $i--) { $date = date('Y-m-d', strtotime("-$i days")); $weekly_labels[] = date('D', strtotime($date)); // Format: Sen, Sel, Rab, dsb // Data pendapatan hari ini $daily_revenue = $this->statistic_m->get_daily_revenue($date); $weekly_current_data[] = $daily_revenue; // Data pendapatan tahun lalu di tanggal yang sama $last_year_date = date('Y-m-d', strtotime("$date -1 year")); $last_year_daily_revenue = $this->statistic_m->get_daily_revenue($last_year_date); $weekly_previous_data[] = $last_year_daily_revenue; } $data['weekly_labels'] = $weekly_labels; $data['weekly_current_data'] = $weekly_current_data; $data['weekly_previous_data'] = $weekly_previous_data; $data['current_week_revenue'] = $current_week_revenue; $data['last_year_week_revenue'] = $last_year_week_revenue; $data['title'] = 'Dashboard Admin | Laciasmara'; $this->load->view('admin_new/layouts/header', $data); $this->load->view('admin_new/dashboard/index'); $this->load->view('admin_new/layouts/footer'); } public function get_product_analysis() { // Get tab parameter if any $tab = $this->input->get('tab', true) ?: 'terlaris'; switch ($tab) { case 'terlaris': $products = $this->get_top_selling_products(5); break; case 'underselling': $products = $this->get_underselling_products(5); break; case 'stock': $products = $this->get_low_stock_products(5); break; default: $products = $this->get_top_selling_products(5); } echo json_encode($products); } private function get_top_selling_products($limit = 5) { $this->db->select(' p.id_products, p.title, p.alias, pi.image, COUNT(od.product_id) as total_sold, COALESCE(SUM(s.stock), 0) as total_stock, b.brand as brand_title '); $this->db->from('orders_detail od'); $this->db->join('products p', 'od.product_id = p.id_products', 'left'); $this->db->join('orders o', 'od.orders_id = o.id_orders', 'left'); $this->db->join('customers c', 'o.customer_id = c.id_customers', 'left'); $this->db->join('product_details pd', 'p.id_products = pd.product_id', 'left'); $this->db->join('stock s', 'pd.id = s.id_product_detail', 'left'); $this->db->join('brands b', 'p.brand_id = b.id_brands', 'left'); $this->db->join('product_images pi', 'pi.product_details_id = pd.id AND pi.priority = 1 AND pi.status = 1', 'left'); $this->db->where('o.payment_status', 5); $this->db->where('c.reseller_id IS NULL'); $this->db->where('o.customer_id !=', 2615); $this->db->where('p.product_status', '1'); $this->db->where('p.deleted_at', null); $this->db->group_by('p.id_products'); $this->db->order_by('total_sold', 'DESC'); $this->db->limit($limit); $query = $this->db->get(); return $query->result(); } private function get_underselling_products($limit = 5) { $this->db->select(' p.id_products, p.title, p.alias, pi.image, COALESCE(COUNT(od.product_id), 0) as total_sold, COALESCE(SUM(s.stock), 0) as total_stock, b.brand as brand_title '); $this->db->from('products p'); $this->db->join('product_details pd', 'p.id_products = pd.product_id', 'left'); $this->db->join('stock s', 'pd.id = s.id_product_detail', 'left'); $this->db->join('orders_detail od', 'p.id_products = od.product_id', 'left'); $this->db->join('orders o', 'od.orders_id = o.id_orders AND o.payment_status = 5', 'left'); $this->db->join('brands b', 'p.brand_id = b.id_brands', 'left'); $this->db->join('product_images pi', 'pi.product_details_id = pd.id AND pi.priority = 1 AND pi.status = 1', 'left'); $this->db->where('p.product_status', '1'); $this->db->where('p.deleted_at', null); $this->db->where('s.stock >', 0); // Only products with stock available $this->db->group_by('p.id_products'); $this->db->order_by('total_sold', 'ASC'); // Order by least sold $this->db->limit($limit); $query = $this->db->get(); return $query->result(); } private function get_low_stock_products($limit = 5) { $this->db->select(' p.id_products, p.title, p.alias, pi.image, COALESCE(COUNT(od.product_id), 0) as total_sold, COALESCE(SUM(s.stock), 0) as total_stock, b.brand as brand_title '); $this->db->from('products p'); $this->db->join('product_details pd', 'p.id_products = pd.product_id', 'left'); $this->db->join('stock s', 'pd.id = s.id_product_detail', 'left'); $this->db->join('orders_detail od', 'p.id_products = od.product_id', 'left'); $this->db->join('orders o', 'od.orders_id = o.id_orders AND o.payment_status = 5', 'left'); $this->db->join('brands b', 'p.brand_id = b.id_brands', 'left'); $this->db->join('product_images pi', 'pi.product_details_id = pd.id AND pi.priority = 1 AND pi.status = 1', 'left'); $this->db->where('p.product_status', '1'); // Only active products $this->db->where('p.deleted_at', null); $this->db->group_by('p.id_products'); $this->db->having('total_stock < 5'); // Products with stock less than 5 $this->db->having('total_sold > 0'); // Only include products that have been sold $this->db->order_by('total_sold', 'DESC'); // Order by most sold first (to prioritize popular ones) $this->db->limit($limit); $query = $this->db->get(); return $query->result(); } public function count_notification() { $user_id = $this->session->userdata('user_id'); $count = $this->log_m->get_unread_count($user_id); header('Content-Type: application/json'); echo json_encode(['count' => $count]); } public function list_notification() { $user_id = $this->session->userdata('user_id'); $notifications = $this->log_m->get_notifications($user_id, 10); // Ambil 10 notifikasi terbaru header('Content-Type: application/json'); echo json_encode(['notifications' => $notifications]); } // Endpoint untuk menandai notifikasi sudah dibaca public function mark_read() { $notification_id = $this->input->post('notification_id'); $user_id = $this->session->userdata('user_id'); $success = $this->log_m->mark_as_read($notification_id, $user_id); header('Content-Type: application/json'); echo json_encode(['success' => $success, 'csrf_token' => $this->security->get_csrf_hash()]); } // Endpoint untuk menandai semua notifikasi sudah dibaca public function mark_all_read() { $user_id = $this->session->userdata('user_id'); $success = $this->log_m->mark_all_as_read($user_id); header('Content-Type: application/json'); echo json_encode(['success' => $success, 'csrf_token' => $this->security->get_csrf_hash()]); } function ajax_statistik() { //current date and time $now = date('Y-m-d H:i:s'); //1 week before $week_before = date("Y-m-d 00:00:00", strtotime('-1 week')); //1 month before $month_before = date("Y-m-d 00:00:00", strtotime('-1 month')); $current_year = date("Y-01-01 00:00:00"); //get visits $count_visit_day = $this->db->select('id')->from('visits')->where('date >=', date('Y-m-d 00:00:00'))->where('date <=', $now)->get()->num_rows(); $count_visit_week = $this->db->select('id')->from('visits')->where('date >=', $week_before)->where('date <=', $now)->get()->num_rows(); $count_visit_month = $this->db->select('id')->from('visits')->where('date >=', $month_before)->where('date <=', $now)->get()->num_rows(); $count_visit_thisyear = $this->db->select('id')->from('visits')->where('date >=', $current_year)->get()->num_rows(); //get visits by ip $count_visit_by_ip_day = $this->db->select('id')->from('visits')->where('date >=', date('Y-m-d 00:00:00'))->where('date <=', $now)->group_by('ip_address')->get()->num_rows(); $count_visit_by_ip_week = $this->db->select('id')->from('visits')->where('date >=', $week_before)->where('date <=', $now)->group_by('ip_address')->get()->num_rows(); $count_visit_by_ip_month = $this->db->select('id')->from('visits')->where('date >=', $month_before)->where('date <=', $now)->group_by('ip_address')->get()->num_rows(); $count_visit_by_ip_thisyear = $this->db->select('id')->from('visits')->where('date >=', $current_year)->where('date <=', $now)->group_by('ip_address')->get()->num_rows(); //get customers $count_customer_day = $this->db->select('id_customers')->from('customers')->where('join_date >=', date('Y-m-d 00:00:00'))->where('join_date <=', $now)->get()->num_rows(); $count_customer_week = $this->db->select('id_customers')->from('customers')->where('join_date >=', $week_before)->where('join_date <=', $now)->get()->num_rows(); $count_customer_month = $this->db->select('id_customers')->from('customers')->where('join_date >=', $month_before)->where('join_date <=', $now)->get()->num_rows(); $count_customer_thisyear = $this->db->select('id_customers')->from('customers')->where('join_date >=', $current_year)->where('join_date <=', $now)->get()->num_rows(); //get orders $order_day = $this->db->select('total_amount')->from('orders')->where('payment_status !=', 0)->where('order_date >=', date('Y-m-d 00:00:00'))->where('order_date <=', $now)->get()->result(); $count_order_day = 0; foreach ($order_day as $order) { $count_order_day = $count_order_day + $order->total_amount; } $order_week = $this->db->select('total_amount')->from('orders')->where('payment_status !=', 0)->where('order_date >=', $week_before)->where('order_date <=', $now)->get()->result(); $count_order_week = 0; foreach ($order_week as $order) { $count_order_week = $count_order_week + $order->total_amount; } $order_month = $this->db->select('total_amount')->from('orders')->where('payment_status !=', 0)->where('order_date >=', $month_before)->where('order_date <=', $now)->get()->result(); $count_order_month = 0; foreach ($order_month as $order) { $count_order_month = $count_order_month + $order->total_amount; } $order_thisyear = $this->db->select('total_amount')->from('orders')->where('payment_status !=', 0)->where('order_date >=', $current_year)->where('order_date <=', $now)->get()->result(); $count_order_thisyear = 0; foreach ($order_thisyear as $order) { $count_order_thisyear = $count_order_thisyear + $order->total_amount; } //get orders paid $included_status = array(5); $order_paid_day = $this->db->select('total_amount')->from('orders')->where_in('payment_status', $included_status)->where('order_date >=', date('Y-m-d 00:00:00'))->where('order_date <=', $now)->get()->result(); $count_order_paid_day = 0; foreach ($order_paid_day as $order) { $count_order_paid_day = $count_order_paid_day + $order->total_amount; } $order_paid_week = $this->db->select('total_amount')->from('orders')->where_in('payment_status', $included_status)->where('order_date >=', $week_before)->where('order_date <=', $now)->get()->result(); $count_order_paid_week = 0; foreach ($order_paid_week as $order) { $count_order_paid_week = $count_order_paid_week + $order->total_amount; } $order_paid_month = $this->db->select('total_amount')->from('orders')->where_in('payment_status', $included_status)->where('order_date >=', $month_before)->where('order_date <=', $now)->get()->result(); $count_order_paid_month = 0; foreach ($order_paid_month as $order) { $count_order_paid_month = $count_order_paid_month + $order->total_amount; } $order_paid_thisyear = $this->db->select('total_amount')->from('orders')->where_in('payment_status', $included_status)->where('order_date >=', $current_year)->where('order_date <=', $now)->get()->result(); $count_order_paid_thisyear = 0; foreach ($order_paid_thisyear as $order) { $count_order_paid_thisyear = $count_order_paid_thisyear + $order->total_amount; } //get value $val = $this->input->post('val'); //validate if ($val == 'week') { $count_visit = $count_visit_week; $count_customer = $count_customer_week; $count_visit_by_ip = $count_visit_by_ip_week; $count_order = $count_order_week; $count_order_paid = $count_order_paid_week; } else if ($val == 'month') { $count_visit = $count_visit_month; $count_customer = $count_customer_month; $count_visit_by_ip = $count_visit_by_ip_month; $count_order = $count_order_month; $count_order_paid = $count_order_paid_month; } else if ($val == 'thisyear') { $count_visit = $count_visit_thisyear; $count_customer = $count_customer_thisyear; $count_visit_by_ip = $count_visit_by_ip_thisyear; $count_order = $count_order_thisyear; $count_order_paid = $count_order_paid_thisyear; } else { $count_visit = $count_visit_day; $count_customer = $count_customer_day; $count_visit_by_ip = $count_visit_by_ip_day; $count_order = $count_order_day; $count_order_paid = $count_order_paid_day; } $data = array( 'count_visit' => $count_visit, 'count_customer' => $count_customer, 'count_visit_by_ip' => $count_visit_by_ip, 'count_order' => $count_order, 'count_order_paid' => $count_order_paid ); $this->load->view('ajax/ajax_get_statistik', $data); } }