Fix attribute values in items (#68)

This commit is contained in:
jekkos
2018-09-09 22:23:34 +02:00
committed by jekkos
parent 3c21b8ff5a
commit 9e7543a41a
3 changed files with 24 additions and 5 deletions

View File

@@ -388,7 +388,9 @@ function get_item_data_row($item)
$item->name .= NAME_SEPARATOR . $item->pack_name;
}
return array_merge(array (
$definition_names = $CI->Attribute->get_definitions_by_flags(Attribute::SHOW_IN_ITEMS);
$result = array (
'items.item_id' => $item->item_id,
'item_number' => $item->item_number,
'name' => $item->name,
@@ -407,7 +409,17 @@ function get_item_data_row($item)
),
'edit' => anchor($controller_name."/view/$item->item_id", '<span class="glyphicon glyphicon-edit"></span>',
array('class' => 'modal-dlg', 'data-btn-submit' => $CI->lang->line('common_submit'), 'title' => $CI->lang->line($controller_name.'_update'))
), explode(',', (property_exists($item, 'attribute_values')) ? $item->attribute_values : "")));
));
$attribute_values = explode(',', (property_exists($item, 'attribute_values')) ? $item->attribute_values : "");
foreach($definition_names as $definition_id => $definition_name)
{
$result[$definition_name] = array_shift($attribute_values);
}
return $result;
}

View File

@@ -16,7 +16,7 @@ CREATE TABLE IF NOT EXISTS `ospos_attribute_values` (
`attribute_value` VARCHAR(45) NULL,
`attribute_datetime` DATETIME NULL,
PRIMARY KEY (`attribute_id`)
) ENGINE = InnoDB DEFAULT CHARSET=utf8_general_ci;
) ENGINE = InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `ospos_attribute_links` (
@@ -31,7 +31,7 @@ CREATE TABLE IF NOT EXISTS `ospos_attribute_links` (
KEY `sale_id` (`sale_id`),
KEY `receiving_id` (`receiving_id`),
UNIQUE `attribute_links_uq1` (`attribute_id`, `definition_id`, `item_id`, `sale_id`, `receiving_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8_general_ci;
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE `ospos_attribute_definitions`

View File

@@ -280,10 +280,13 @@ class Item extends CI_Model
public function get_info($item_id)
{
$this->db->select('items.*');
$this->db->select('GROUP_CONCAT(attribute_value SEPARATOR \'|\') AS attribute_values');
$this->db->select('suppliers.company_name');
$this->db->from('items');
$this->db->join('suppliers', 'suppliers.person_id = items.supplier_id', 'left');
$this->db->where('item_id', $item_id);
$this->db->join('attribute_links', 'attribute_links.item_id = items.item_id', 'left');
$this->db->join('attribute_values', 'attribute_links.attribute_id = attribute_values.attribute_id', 'left');
$this->db->where('items.item_id', $item_id);
$query = $this->db->get();
@@ -375,13 +378,17 @@ class Item extends CI_Model
{
$this->db->select('items.*');
$this->db->select('company_name');
$this->db->select('GROUP_CONCAT(attribute_value SEPARATOR \'|\') AS attribute_values');
$this->db->select('category');
$this->db->select('quantity');
$this->db->from('items');
$this->db->join('suppliers', 'suppliers.person_id = items.supplier_id', 'left');
$this->db->join('item_quantities', 'item_quantities.item_id = items.item_id', 'left');
$this->db->join('attribute_links', 'attribute_links.item_id = items.item_id', 'left');
$this->db->join('attribute_values', 'attribute_links.attribute_id = attribute_values.attribute_id', 'left');
$this->db->where('location_id', $location_id);
$this->db->where_in('items.item_id', $item_ids);
$this->db->group_by('items.item_id');
return $this->db->get();
}