diff --git a/application/controllers/items.php b/application/controllers/items.php index 5624527e5..028c01519 100644 --- a/application/controllers/items.php +++ b/application/controllers/items.php @@ -20,9 +20,11 @@ class Items extends Secure_area implements iData_controller $lines_per_page = $this->Appconfig->get('lines_per_page'); $items = $this->Item->get_all($stock_location, $lines_per_page, $limit_from); $data['links'] = $this->_initialize_pagination($this->Item, $lines_per_page, $limit_from); - - $start_of_time = date($this->config->item('dateformat'), 0); + + // assume year 2010 as starting date for OSPOS + $start_of_time = date($this->config->item('dateformat'), mktime(0,0,0,1,1,2010)); $today = date($this->config->item('dateformat')); + $start_date = $this->input->post('start_date') != NULL ? $this->input->post('start_date', TRUE) : $start_of_time; $start_date_formatter = date_create_from_format($this->config->item('dateformat'), $start_date); $end_date = $this->input->post('end_date') != NULL ? $this->input->post('end_date', TRUE) : $today; @@ -54,8 +56,10 @@ class Items extends Secure_area implements iData_controller $limit_from = $this->input->post('limit_from'); $lines_per_page = $this->Appconfig->get('lines_per_page'); - $start_of_time = date($this->config->item('dateformat'), 0); + // assume year 2010 as starting date for OSPOS + $start_of_time = date($this->config->item('dateformat'), mktime(0,0,0,1,1,2010)); $today = date($this->config->item('dateformat')); + $start_date = $this->input->post('start_date') != NULL ? $this->input->post('start_date', TRUE) : $start_of_time; $start_date_formatter = date_create_from_format($this->config->item('dateformat'), $start_date); $end_date = $this->input->post('end_date') != NULL ? $this->input->post('end_date', TRUE) : $today; diff --git a/application/models/item.php b/application/models/item.php index e961e4d2c..f01f39adb 100644 --- a/application/models/item.php +++ b/application/models/item.php @@ -39,6 +39,8 @@ class Item extends CI_Model */ function get_found_rows($search, $filters) { + // don't fecth all the table for a row counting function + $this->db->select('items.name'); $this->db->from('items'); $this->db->join('suppliers', 'suppliers.person_id = items.supplier_id', 'left'); $this->db->join('inventory', 'inventory.trans_items = items.item_id'); @@ -59,7 +61,7 @@ class Item extends CI_Model { $this->db->where("(name LIKE '%" . $this->db->escape_like_str($search) . "%' OR " . "item_number LIKE '" . $this->db->escape_like_str($search) . "%' OR " . - $this->db->dbprefix('items').".item_id LIKE '" . $this->db->escape_like_str($search) . "%' OR " . + "items.item_id LIKE '" . $this->db->escape_like_str($search) . "%' OR " . "company_name LIKE '" . $this->db->escape_like_str($search) . "%' OR " . "category LIKE '%" . $this->db->escape_like_str($search) . "%')"); } @@ -96,7 +98,8 @@ class Item extends CI_Model { $this->db->where('items.description', ''); } - + + // avoid duplicate entry with same name because of invetory reporting multiple changes on the same item in the same date range $this->db->group_by('items.name'); return $this->db->get()->num_rows(); @@ -127,7 +130,7 @@ class Item extends CI_Model { $this->db->where("(name LIKE '%" . $this->db->escape_like_str($search) . "%' OR " . "item_number LIKE '" . $this->db->escape_like_str($search) . "%' OR " . - $this->db->dbprefix('items').".item_id LIKE '" . $this->db->escape_like_str($search) . "%' OR " . + "items.item_id LIKE '" . $this->db->escape_like_str($search) . "%' OR " . "company_name LIKE '" . $this->db->escape_like_str($search) . "%' OR " . "category LIKE '%" . $this->db->escape_like_str($search) . "%')"); } @@ -165,7 +168,10 @@ class Item extends CI_Model $this->db->where('items.description', ''); } + // avoid duplicate entry with same name because of invetory reporting multiple changes on the same item in the same date range $this->db->group_by('items.name'); + + // order by name of item $this->db->order_by('items.name', 'asc'); if ($rows > 0)