public function fetch_child_catalogs($parent_id) { if ($this->CI->is_super_user()) { return $this->get_result('product_catalog', '*', array('parent' => $parent_id)); } $user_id = get_current_user_id(); $codes = fetch_current_system_codes(); if (in_array('sale', $codes)) { $sale_cat_ids = $this->CI->product_model->fetch_all_sale_catalog_ids($user_id); } $lower_priority_users = $this->CI->user_model->fetch_lower_priority_users_by_system_code('purchase'); $lower_priority_user_ids = array(); foreach ($lower_priority_users as $user) { $lower_priority_user_ids[] = $user->u_id; } $lower_priority_user_ids[] = get_current_user_id(); if (is_array($codes) && in_array('finance', $codes)) { return $this->get_result('product_catalog', '*', array('parent' => $parent_id)); } if (in_array('purchase', $codes)) { $this->db->from('product_catalog'); $this->db->where(array('parent' => $parent_id)); $this->db->where_in('(product_catalog.purchaser_id', $lower_priority_user_ids); $this->db->or_where('product_catalog.purchaser_id = -1)'); $query = $this->db->get(); return $query->result(); } if (in_array('sale', $codes)) { if (empty($sale_cat_ids)) { return array(); } $this->db->from('product_catalog'); $this->db->where('parent', $parent_id); $this->db->where_in('id', $sale_cat_ids); $query = $this->db->get(); return $query->result(); } return $this->get_result('product_catalog', '*', array('parent' => $parent_id)); }
public function fetch_to_be_edit_products() { $lower_priority_users = $this->CI->user_model->fetch_lower_priority_users_by_system_code('purchase'); $lower_priority_user_ids = array(); foreach ($lower_priority_users as $user) { $lower_priority_user_ids[] = $user->u_id; } $lower_priority_user_ids[] = get_current_user_id(); $codes = fetch_current_system_codes(); $status = fetch_status_id('sale_status', 'in_stock'); $cat_ids = array(); $cat_id = $this->CI->session->userdata('current_catalog_id'); if (!isset($this->CI->product_catalog_model)) { $this->CI->load->model('product_catalog_model'); } if ($cat_id != -1 && $cat_id != FALSE) { $cat_ids = array($cat_id); } $cat_ids = array_merge($cat_ids, $this->CI->product_catalog_model->fetch_all_child_catalog_ids($cat_id)); $this->db->select('product_basic.sku, product_basic.id as pid, product_basic.name_cn, product_basic.name_en, product_basic.updated_date,product_basic.*,user.name'); $this->db->from('product_basic'); $this->db->join('user', 'user.id = product_basic.purchaser_id', 'LEFT'); if (!$this->CI->is_super_user() && in_array('purchase', $codes)) { $this->db->where("(product_basic.market_model = '' "); $this->db->or_where('product_basic.box_contain_number = 0 '); $this->db->or_where('product_basic.box_total_weight = 0 '); $this->db->or_where('product_basic.box_length = 0 '); $this->db->or_where('product_basic.box_width = 0 '); $this->db->or_where('product_basic.box_height = 0 '); $this->db->or_where("product_basic.min_stock_number = '' )"); } if (!$this->CI->is_super_user() && in_array('shipping', $codes)) { $this->db->where("product_basic.packing_material = 0 "); } if (!empty($cat_ids)) { $this->db->where_in('catalog_id', $cat_ids); if (!$this->CI->is_super_user() && in_array('purchase', $codes)) { //$this->db->where_in('product_basic.purchaser_id', $lower_priority_user_ids); } } else { if (!$this->CI->is_super_user() && in_array('purchase', $codes)) { //$this->db->where_in('product_basic.purchaser_id', $lower_priority_user_ids); } if (!$this->CI->is_super_user() && in_array('sale', $codes)) { return array(); } } $this->db->distinct(); $this->db->order_by('product_basic.updated_date', 'DESC'); $this->db->limit(5); $query = $this->db->get(); return $query->result(); }