From 77682973a0587ca56b8c4bce2c534aa6513aff89 Mon Sep 17 00:00:00 2001 From: jekkos Date: Wed, 5 Sep 2018 18:57:45 +0200 Subject: [PATCH] Enable attributes in items table (#68) --- application/controllers/Items.php | 5 ++++- application/helpers/tabular_helper.php | 11 +++++++++-- application/models/Attribute.php | 2 +- application/models/Item.php | 10 ++++++++-- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/application/controllers/Items.php b/application/controllers/Items.php index 5eab7920a..be843fc00 100644 --- a/application/controllers/Items.php +++ b/application/controllers/Items.php @@ -45,6 +45,8 @@ class Items extends Secure_Controller $this->item_lib->set_item_location($this->input->get('stock_location')); + $definition_names = $this->Attribute->get_definitions_by_flags(Attribute::SHOW_IN_ITEMS); + $filters = array('start_date' => $this->input->get('start_date'), 'end_date' => $this->input->get('end_date'), 'stock_location_id' => $this->item_lib->get_item_location(), @@ -54,7 +56,8 @@ class Items extends Secure_Controller 'no_description' => FALSE, 'search_custom' => FALSE, 'is_deleted' => FALSE, - 'temporary' => FALSE); + 'temporary' => FALSE, + 'definition_ids' => array_keys($definition_names)); // check if any filter is set in the multiselect dropdown $filledup = array_fill_keys($this->input->get('filters'), TRUE); diff --git a/application/helpers/tabular_helper.php b/application/helpers/tabular_helper.php index a89a449d9..3fb7044a0 100644 --- a/application/helpers/tabular_helper.php +++ b/application/helpers/tabular_helper.php @@ -321,6 +321,8 @@ function get_items_manage_table_headers() { $CI =& get_instance(); + $definition_names = $CI->Attribute->get_definitions_by_flags(Attribute::SHOW_IN_ITEMS); + $headers = array( array('items.item_id' => $CI->lang->line('common_id')), array('item_number' => $CI->lang->line('items_item_number')), @@ -336,6 +338,11 @@ function get_items_manage_table_headers() array('stock' => '') ); + foreach($definition_names as $definition_id => $definition_name) + { + $headers[] = array($definition_name => $definition_name); + } + return transform_headers($headers); } @@ -381,7 +388,7 @@ function get_item_data_row($item) $item->name .= NAME_SEPARATOR . $item->pack_name; } - return array ( + return array_merge(array ( 'items.item_id' => $item->item_id, 'item_number' => $item->item_number, 'name' => $item->name, @@ -400,7 +407,7 @@ function get_item_data_row($item) ), 'edit' => anchor($controller_name."/view/$item->item_id", '', array('class' => 'modal-dlg', 'data-btn-submit' => $CI->lang->line('common_submit'), 'title' => $CI->lang->line($controller_name.'_update')) - )); + ), explode(',', $item->attribute_values))); } diff --git a/application/models/Attribute.php b/application/models/Attribute.php index d2d38fe5f..12b98fbe8 100644 --- a/application/models/Attribute.php +++ b/application/models/Attribute.php @@ -13,7 +13,7 @@ const DEFINITION_TYPES = [GROUP, DROPDOWN, TEXT, DATETIME]; class Attribute extends CI_Model { - //const SHOW_IN_ITEMS = 1; + const SHOW_IN_ITEMS = 1; const SHOW_IN_SALES = 2; const SHOW_IN_RECEIVINGS = 4; diff --git a/application/models/Item.php b/application/models/Item.php index d0042f643..deedb74f6 100644 --- a/application/models/Item.php +++ b/application/models/Item.php @@ -180,18 +180,24 @@ class Item extends CI_Model $this->db->like('name', $search); $this->db->or_like('item_number', $search); $this->db->or_like('items.item_id', $search); - $this->db->or_like('definition_name', $search); $this->db->or_like('company_name', $search); $this->db->or_like('items.category', $search); $this->db->group_end(); } else { + $this->db->like('attribute_value', $search); $this->db->join('attribute_links', 'attribute_links.item_id = items.item_id'); $this->db->join('attribute_values', 'attribute_links.attribute_id = attribute_values.attribute_id'); - $this->db->like('attribute_value', $search); } } + else if (count($filters['definition_ids']) > 0) + { + $this->db->select('GROUP_CONCAT(attribute_value) AS attribute_values'); + $this->db->join('attribute_links', 'attribute_links.item_id = items.item_id AND attribute_links.receiving_id IS NULL AND attribute_links.sale_id IS NULL AND definition_id IN (' . implode(',', $filters['definition_ids']) . ')', 'left'); + $this->db->join('attribute_values', 'attribute_values.attribute_id = attribute_links.attribute_id', 'left'); + $this->db->order_by('definition_id'); + } $this->db->where('items.deleted', $filters['is_deleted']);