<?php
class Dashboard_model extends CI_Model
{
public function __construct()
{
parent::__construct();
}
public function getResult()
{
$array = $result->result_array();
return $array;
}
public function countGround()
{
$this->db->where('email', $_SESSION['email']);
$this->db->select('*');
$result = $this->db->get('subscription_register');
return $result->num_rows();
}
public function subs_type()
{
$this->db->where('subscription_register.email', $_SESSION['email']);
$this->db->select([
'subscription_register.*',
'subscription_register.id AS user_id',
'subscription_register.subscription_type',
'subscription_register.t_and_c',
'product_master.product_name',
'GROUP_CONCAT(DISTINCT subscription_register.choose_type ORDER BY subscription_register.choose_type ASC) AS choose_type',
'country.country_name',
'GROUP_CONCAT(DISTINCT user_item_access.category_id ORDER BY user_item_access.category_id ASC) AS category_ids',
'GROUP_CONCAT(DISTINCT user_item_access.item_id ORDER BY user_item_access.item_id ASC) AS item_ids'
]);
$this->db->from('subscription_register');
$this->db->join('product_master', 'product_master.product_id = subscription_register.subscription_type', 'inner');
$this->db->join('user_item_access', 'user_item_access.user_id = subscription_register.id', 'left');
$this->db->join('country', 'country.country_id = subscription_register.country', 'left');
$this->db->group_by('subscription_register.id'); // Group by user ID
$query = $this->db->get();
return $query->result_array(); // Directly return results
}
//get from subaciption log
public function subs_types()
{
$this->db->where('user_id', $_SESSION['id']);
$this->db->where('entry_type', 'tenure');
$this->db->select('subscription_type,subscription_period,initial_start_date,initial_end_date,entry_type,is_checked');
$this->db->join('product_master', 'product_master.product_id = subscription_change_log.subscription_type', 'inner');
$result = $this->db->get('subscription_change_log');
return $result->result_array();
}
public function cat_id()
{
$this->db->select('*');
$this->db->where('cat_status', '1');
$result = $this->db->get('tbl_item_cat');
return $result->result_array();
}
public function cat_fetch_partial()
{
$this->db->where('cat_status', '1');
$this->db->select('*');
$this->db->join('partial_web_access', 'partial_web_access.product_name = tbl_item_cat.id', 'inner');
$result = $this->db->get('tbl_item_cat');
// echo $this->db->last_query();
// die;
return $result->result_array();
}
public function pending()
{
$this->db->where('email', $_SESSION['email']);
$this->db->select('*');
$result = $this->db->get('subscription_register');
return $result->num_rows();
}
public function category_name_duplicate()
{
$this->db->select('*');
$this->db->order_by('id', 'ASC');
$this->db->group_by('category_name');
$result = $this->db->get('tbl_item_cat');
$array = $result->result_array();
return $array;
}
public function check_cir_report($subscriber_id)
{
$this->db->select("*");
$this->db->from('cir_reports');
$this->db->where('subscribe_month', date('F'));
$this->db->where('subscribe_year', date('Y'));
$this->db->where("find_in_set($subscriber_id,subscriber_id)<> 0");
$query = $this->db->get();
return $query->result();
}
public function check_lite_cir_report($subscriber_id)
{
$this->db->select("*");
$this->db->from('lite_cir_reports');
$this->db->where('subscribe_month', date('F'));
$this->db->where('subscribe_year', date('Y'));
$this->db->where("find_in_set($subscriber_id,subscriber_id)<> 0");
$query = $this->db->get();
return $query->result();
}
public function check_forcast_report($subscriber_id)
{
$this->db->select("*");
$this->db->from('forcast_reports');
$this->db->where('subscribe_month', date('F'));
$this->db->where('subscribe_year', date('Y'));
$this->db->where("find_in_set($subscriber_id,subscriber_id)<> 0");
$query = $this->db->get();
return $query->result();
}
// public function cir_report($register_start_date, $register_end_date)
// {
// // Convert input dates to 'Y-m-d' format
// $start_date = date('Y-m-d', strtotime($register_start_date));
// $end_date = date('Y-m-d', strtotime($register_end_date));
// // Ensure the end date is inclusive by adding a day
// $end_date = date('Y-m-d', strtotime($end_date . ' +1 day'));
// // Build the query
// $this->db->select("*");
// $this->db->from('cir_reports');
// $this->db->where("DATE(last_updation) >=", $start_date);
// $this->db->where("DATE(last_updation) <", $end_date);
// $this->db->order_by('id', 'DESC');
// // Execute the query
// $query = $this->db->get();
// return $query->result();
// }
public function get_initial_dates($user_id)
{
// Select only the initial start date and initial end date fields
$this->db->select('initial_start_date, initial_end_date');
// Get records from the subscription_change_log table where user_id matches the provided ID
$this->db->where('user_id', $user_id);
$this->db->where('entry_type', 'tenure');
// Execute the query
$query = $this->db->get('subscription_change_log');
// Return the result as an array of objects
return $query->result_array();
}
public function cir_report($periods)
{
if (!is_array($periods) || empty($periods)) {
return []; // Return an empty result or handle the error as needed
}
// Initialize the query
$this->db->select("*");
$this->db->from('cir_reports');
// Start grouping the OR conditions
$this->db->group_start();
foreach ($periods as $period) {
// Ensure the dates are formatted properly
$start_date = date('Y-m-d', strtotime($period['initial_start_date']));
$end_date = date('Y-m-d', strtotime($period['initial_end_date'])); // End date is inclusive
// Add each period's condition to the query using BETWEEN
$this->db->or_group_start(); // Start a new OR group for this period
$this->db->where("DATE(last_updation) BETWEEN '$start_date' AND '$end_date'");
$this->db->group_end(); // End this OR group
}
$this->db->group_end(); // End the grouping of all OR conditions
// Order the results by ID in descending order
$this->db->order_by('id', 'DESC');
// Execute the query
$query = $this->db->get();
return $query->result();
}
public function lite_cir_report($periods)
{
if (!is_array($periods) || empty($periods)) {
return []; // Return an empty result or handle the error as needed
}
// Initialize the query
$this->db->select("*");
$this->db->from('lite_cir_reports');
// Start grouping the OR conditions
$this->db->group_start();
foreach ($periods as $period) {
// Ensure the dates are formatted properly
$start_date = date('Y-m-d', strtotime($period['initial_start_date']));
$end_date = date('Y-m-d', strtotime($period['initial_end_date'])); // End date is inclusive
// Add each period's condition to the query using BETWEEN
$this->db->or_group_start(); // Start a new OR group for this period
$this->db->where("DATE(last_updation) BETWEEN '$start_date' AND '$end_date'");
$this->db->group_end(); // End this OR group
}
$this->db->group_end(); // End the grouping of all OR conditions
// Order the results by ID in descending order
$this->db->order_by('id', 'DESC');
// Execute the query
$query = $this->db->get();
return $query->result();
}
public function forcast_report($periods)
{
if (!is_array($periods) || empty($periods)) {
return []; // Return an empty result or handle the error as needed
}
// Initialize the query
$this->db->select("*");
$this->db->from('forcast_reports');
// Start grouping the OR conditions
$this->db->group_start();
foreach ($periods as $period) {
// Ensure the dates are formatted properly
$start_date = date('Y-m-d', strtotime($period['initial_start_date']));
$end_date = date('Y-m-d', strtotime($period['initial_end_date'])); // End date is inclusive
// Add each period's condition to the query using BETWEEN
$this->db->or_group_start(); // Start a new OR group for this period
$this->db->where("DATE(last_updation) BETWEEN '$start_date' AND '$end_date'");
$this->db->group_end(); // End this OR group
}
$this->db->group_end(); // End the grouping of all OR conditions
// Order the results by ID in descending order
$this->db->order_by('id', 'DESC');
// Execute the query
$query = $this->db->get();
return $query->result();
}
// public function forcast_report($register_start_date, $register_end_date)
// {
// $start_date = date('Y-m-d', strtotime($register_start_date));
// $end_date = date('Y-m-d', strtotime($register_end_date));
// // Ensure the end date is inclusive by adding a day
// $end_date = date('Y-m-d', strtotime($end_date . ' +1 day'));
// $this->db->select("*");
// $this->db->from('forcast_reports');
// $this->db->where("DATE(last_updation) >=", $start_date);
// $this->db->where("DATE(last_updation) <", $end_date);
// $this->db->order_by('id', 'DESC');
// $query = $this->db->get();
// return $query->result();
// }
// public function cir_report()
// {
// $this->db->select("*");
// $this->db->from('cir_reports');
// $this->db->order_by('id','ASC');
// $query = $this->db->get();
// return $query->result();
// }
} |