diff --git a/application/migrations/sqlscripts/3.4.0_database_optimizations.sql b/application/migrations/sqlscripts/3.4.0_database_optimizations.sql index 335e38c96..38b2e40f1 100644 --- a/application/migrations/sqlscripts/3.4.0_database_optimizations.sql +++ b/application/migrations/sqlscripts/3.4.0_database_optimizations.sql @@ -8,7 +8,7 @@ ALTER TABLE `ospos_attribute_definitions` ADD INDEX(`definition_name`); ALTER TABLE `ospos_attribute_definitions` ADD INDEX(`definition_type`); #opsos_attribute_links table -ALTER TABLE `ospos_attribute_links` ADD UNIQUE INDEX `attribute_links_uq2` (`item_id`, `receiving_id`, `sale_id`, `definition_id`, `attribute_id`); +ALTER TABLE `ospos_attribute_links` ADD UNIQUE INDEX `attribute_links_uq2` (`item_id`,`sale_id`,`receiving_id`,`definition_id`,`attribute_id`); #ospos_cash_up table ALTER TABLE `ospos_cash_up` MODIFY `deleted` tinyint(1) DEFAULT 0 NOT NULL; @@ -23,12 +23,10 @@ ALTER TABLE `ospos_customers` ADD INDEX(`company_name`); #ospos_customers_packages table ALTER TABLE `ospos_customers_packages` MODIFY `deleted` tinyint(1) DEFAULT 0 NOT NULL; -ALTER TABLE `ospos_customers_packages` ADD INDEX(`deleted`); #ospos_dinner_tables table ALTER TABLE `ospos_dinner_tables` MODIFY `deleted` tinyint(1) DEFAULT 0 NOT NULL; ALTER TABLE `ospos_dinner_tables` ADD INDEX(`status`); -ALTER TABLE `ospos_dinner_tables` ADD INDEX(`deleted`); #ospos_employees table DROP INDEX `person_id` ON `ospos_employees`; @@ -52,8 +50,8 @@ ALTER TABLE `ospos_giftcards` MODIFY `deleted` tinyint(1) DEFAULT 0 NOT NULL; ALTER TABLE `ospos_items` MODIFY `deleted` tinyint(1) DEFAULT 0 NOT NULL; ALTER TABLE `ospos_items` MODIFY `stock_type` tinyint(1) DEFAULT 0 NOT NULL; ALTER TABLE `ospos_items` MODIFY `item_type` tinyint(1) DEFAULT 0 NOT NULL; -ALTER TABLE `ospos_items` ADD INDEX(`deleted`); -ALTER TABLE `ospos_items` ADD INDEX(`item_type`); +ALTER TABLE `ospos_items` ADD INDEX(`deleted`, `item_type`); +ALTER TABLE `ospos_items` ADD INDEX(`PRIMARY`, `deleted`); ALTER TABLE `ospos_items` ADD UNIQUE INDEX `items_uq1` (`supplier_id`, `item_id`, `deleted`, `item_type`); #ospos_item_kits table @@ -62,6 +60,9 @@ ALTER TABLE `ospos_item_kits` MODIFY `price_option` tinyint(1) DEFAULT 0 NOT NUL ALTER TABLE `ospos_item_kits` MODIFY `print_option` tinyint(1) DEFAULT 0 NOT NULL; ALTER TABLE `ospos_item_kits` ADD INDEX(`name`,`description`); +#ospos_item_quantities table +ALTER TABLE `ospos_item_quantities` ADD INDEX(`PRIMARY`,`item_id`,`location_id`); + #ospos_people table ALTER TABLE `ospos_people` ADD INDEX(`first_name`, `last_name`, `email`, `phone_number`); @@ -97,7 +98,8 @@ DROP INDEX `person_id` ON `ospos_suppliers`; ALTER TABLE `ospos_suppliers` MODIFY `deleted` tinyint(1) DEFAULT 0 NOT NULL; ALTER TABLE `ospos_suppliers` MODIFY `category` tinyint(1) NOT NULL; ALTER TABLE `ospos_suppliers` ADD PRIMARY KEY(`person_id`); -ALTER TABLE `ospos_suppliers` ADD INDEX(`category`); +ALTER TABLE `ospos_suppliers` ADD INDEX(`category`); +ALTER TABLE `ospos_suppliers` ADD INDEX(`company_name`, `deleted`); #ospos_tax_categories table ALTER TABLE `ospos_tax_categories` MODIFY `deleted` tinyint(1) DEFAULT 0 NOT NULL; diff --git a/application/models/Item.php b/application/models/Item.php index 21d0d6246..83528037f 100644 --- a/application/models/Item.php +++ b/application/models/Item.php @@ -46,7 +46,7 @@ class Item extends CI_Model $this->db->where('item_id !=', (int) $item_id); } - return ($this->db->get()->num_rows() >= 1); + return $this->db->get()->num_rows() >= 1; } /* @@ -577,7 +577,6 @@ class Item extends CI_Model $this->db->select('category'); $this->db->from('items'); $this->db->where('deleted', $filters['is_deleted']); - $this->db->where_in('item_type', $non_kit); // standard, exclude kit items since kits will be picked up later $this->db->distinct(); $this->db->like('category', $search); $this->db->order_by('category', 'asc'); @@ -592,7 +591,6 @@ class Item extends CI_Model $this->db->like('company_name', $search); // restrict to non deleted companies only if is_deleted is FALSE $this->db->where('deleted', $filters['is_deleted']); - $this->db->where_in('item_type', $non_kit); // standard, exclude kit items since kits will be picked up later $this->db->distinct(); $this->db->order_by('company_name', 'asc'); foreach($this->db->get()->result() as $row) @@ -604,7 +602,6 @@ class Item extends CI_Model $this->db->select($this->get_search_suggestion_format('item_id, name, pack_name, description')); $this->db->from('items'); $this->db->where('deleted', $filters['is_deleted']); - $this->db->where_in('item_type', $non_kit); // standard, exclude kit items since kits will be picked up later $this->db->like('description', $search); $this->db->order_by('description', 'asc'); foreach($this->db->get()->result() as $row) @@ -620,15 +617,15 @@ class Item extends CI_Model if($filters['search_custom'] != FALSE) { $this->db->from('attribute_links'); - $this->db->join('attribute_links.attribute_id = attribute_values.attribute_id'); + $this->db->join('attribute_values','attribute_links.attribute_id = attribute_values.attribute_id'); $this->db->join('attribute_definitions', 'attribute_definitions.definition_id = attribute_links.definition_id'); $this->db->like('attribute_value', $search); $this->db->where('definition_type', TEXT); $this->db->where('deleted', $filters['is_deleted']); - $this->db->where_in('item_type', $non_kit); // standard, exclude kit items since kits will be picked up later + foreach($this->db->get()->result() as $row) { - $suggestions[] = array('value' => $row->item_id, 'label' => get_search_suggestion_label($row)); + $suggestions[] = array('value' => $row->item_id, 'label' => $this->get_search_suggestion_label($row)); } } }